Skip to content

Commit

Permalink
Merge branch 'master' of github.com:broadstreetads/broadstreet-wp
Browse files Browse the repository at this point in the history
  • Loading branch information
katzgrau committed Sep 8, 2021
2 parents d92c10b + 20b2adb commit 000caa6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 149 deletions.
2 changes: 1 addition & 1 deletion Broadstreet/Config.php
Expand Up @@ -140,4 +140,4 @@ private static function _getInstance()
}
}

define('BROADSTREET_VERSION', '1.41.3');
define('BROADSTREET_VERSION', '1.41.4');
85 changes: 5 additions & 80 deletions Broadstreet/Model.php
Expand Up @@ -11,78 +11,11 @@
*/
class Broadstreet_Model
{
public static function getPublishedDocument($document_id)
{
global $wpdb;

$table = self::getTableName('posts');

$sql = "SELECT *
FROM $table
WHERE ID = '$document_id'
AND post_status = 'publish'
LIMIT 1";

$posts = $wpdb->get_results($sql);

if(count($posts) == 0)
return false;
else
return $posts[0];
}

public static function getPublishedDocuments($page = 0, $per_page = 10)
{
global $wpdb;

$start = $page * $per_page;

$table = self::getTableName('posts');

$sql = "SELECT *
FROM $table
WHERE post_status = 'publish'
LIMIT $start, $per_page";

return $wpdb->get_results($sql);
}

public static function getPublishedPostCount()
{
global $wpdb;

$table = self::getTableName('posts');

$sql = "SELECT COUNT(*) AS 'count'
FROM $table
WHERE post_status = 'publish'";

$results = $wpdb->get_results($sql);

return $results[0]->count;
}

public static function getPostComments($post_id, $page = FALSE, $per_page = FALSE)
{
global $wpdb;

$table = self::getTableName('comments');

/* Process posts in batches of 20 from the db */
$sql = "SELECT comment_author, comment_content
FROM $table
WHERE comment_approved = '1'
AND comment_post_ID = '$post_id'";

if($page && $per_page)
{
$start = $page * $per_page;
$sql = "$sql LIMIT $start, $per_page";
}

return $wpdb->get_results($sql);
}

/**
* There is a more modern way to do this, but this is also used very infrequently.
* It's also pretty efficient: it grabs post meta at once so that a loop doesn't
* have to be used later
*/
public static function getPostMeta($post_ids = array(), $defaults = array())
{
if(count($post_ids) == 0) return array();
Expand All @@ -91,7 +24,6 @@ public static function getPostMeta($post_ids = array(), $defaults = array())

$table = self::getTableName('postmeta');

/* Process posts in batches of 20 from the db */
$sql = "SELECT post_id, meta_key, meta_value
FROM $table
WHERE post_id IN (".implode(',', $post_ids).")";
Expand All @@ -111,13 +43,6 @@ public static function getPostMeta($post_ids = array(), $defaults = array())
return $meta;
}

public static function getCategories()
{
global $wpdb;

$table = $this->getTableName('');
}

public static function getTableName($table_name)
{
global $wpdb;
Expand Down
66 changes: 0 additions & 66 deletions Broadstreet/Utility.php
Expand Up @@ -854,44 +854,6 @@ public static function getVendorBaseURL()
return self::getBroadstreetBaseURL() . 'Public/vendor/';
}

/**
* Close a connection with the client, but keep PHP execution alive.
* @param string $data Any data to send to the client/browser.
* @param int $time_limit
*/
public static function killConnectionAndContinue($data = '', $time_limit = 0)
{
ignore_user_abort(true);
set_time_limit($time_limit);

header("Connection: close");
header("Content-Length: " . strlen($data));
echo $data;
flush();
}

/**
* Check to see if a process with a given PID is running
* @param int $pid The PID of the process in question
* @return bool True if the process is running, false if not
*/
public static function isProcessRunning($pid)
{
$output = array();
exec('ps -A -o pid', $output);
$pid = intval($pid);

foreach($output as $running_pid)
{
if($pid == intval(trim($running_pid)))
{
return TRUE;
}
}

return FALSE;
}

/**
* Get the broadstreet zone cache
* @return array
Expand Down Expand Up @@ -1067,34 +1029,6 @@ public static function importImage($url, $post_id = 0, $desc = 'Business photo')
return wp_get_attachment_url( $id );
}

/**
* Get any reports / warnings / messages from the Broadstreet server.
* @return mized A string if a message was found, FALSE if not
*/
public static function getBroadstreetMessage()
{
return false;
//self::setOption(Broadstreet_Core::KEY_LAST_MESSAGE_DATE, time() - 60*60*13);
$date = self::getOption(Broadstreet_Core::KEY_LAST_MESSAGE_DATE);

if($date !== FALSE && ($date + 12*60*60) > time())
return self::getOption(Broadstreet_Core::KEY_LAST_MESSAGE);

$driver = Broadstreet_Config::get('driver');
$count = Broadstreet_Model::getPublishedPostCount();

$url = "http://broadstreetads.com/messages?d=$driver&c=$count";
$content = file_get_contents($url);

self::setOption(Broadstreet_Core::KEY_LAST_MESSAGE, $content);
self::setOption(Broadstreet_Core::KEY_LAST_MESSAGE_DATE, time());

if(strlen($content) == 0 || $content == "0")
return FALSE;

return $content;
}

public static function pageHasCategory($id) {
global $post;

Expand Down
2 changes: 1 addition & 1 deletion broadstreet.php
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Broadstreet
Plugin URI: http://broadstreetads.com
Description: Integrate Broadstreet business directory and adserving power into your site
Version: 1.41.3
Version: 1.41.4
Author: Broadstreet
Author URI: http://broadstreetads.com
*/
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Expand Up @@ -3,7 +3,7 @@ Contributors: Broadstreet
Tags: broadstreet,local,publishers,hyperlocal,independent,news,business,directory
Requires at least: 3.0
Tested up to: 5.7
Stable tag: 1.41.3
Stable tag: 1.41.4

Integrate Broadstreet adserving power into your site.

Expand Down

0 comments on commit 000caa6

Please sign in to comment.