children now separated) SimplePie updated to 1.1.1 Fixed broken cron command Fixed broken export on some systems Fixed broken redirect when resetting a campaign Everything now stored in GMT to avoid time issues. Gotten rid of NOW() functions in favor of WP time functions Fixed bug with validation upon deletion of feeds in existing campaigns Fixed bug with allow comments setting. Fixed bug with logs dates Fixed bug with double quote escaping (fixes campaign templates / rewrite html bugs) Username in options tab changed to a more handy select box. Interface now looks better on IE (d'oh) Added many help files Fixed annoying duplicates bug Fixed small bug in import with labels Fixed bug with categories in edit mode Fixed Tools post changes. Fixed issue with empty rewrite replacements Non-regex rewrite replacements now case insensitive. Fixed bugs with 'use feed date' option. Fixed footer copyright Fixed bad dates in 'view all' logs Log message field made text Fields changed to datetime format Clean logs function fixed r6: str_ireplace now works with arrays queries adjusted to work on all server configurations - 1.0RC4 Tables not deleted anymore upon installation Fixed SimplePie error report. Fixed small post content bug (not hidden by default) Fixed cron url Removed inverted quotes from queries Fixed notices in debug mode No error showing for campaigns w/o feeds fixed r1 MySQL incompatibility with query solved r2 Hostings with basedir restriction now don't show errors r3 Fixed date issue that might have caused potential duplication problems r4 Fixed cron job mysql query r5 Unlimited max items bug fixed. r6 Fixed cron job gmt times. */ # WP-o-Matic paths. With trailing slash. define('WPODIR', dirname(__FILE__) . '/'); define('WPOINC', WPODIR . 'inc/'); define('WPOTPL', WPOINC . 'admin/'); # Dependencies require_once( WPOINC . 'tools.class.php' ); class WPOMatic { # Internal var $version = '1.0RC4-6'; var $newsetup = false; # true if this version introduces setup changes var $sections = array('home', 'setup', 'list', 'add', 'edit', 'options', 'import', 'export', 'reset', 'delete', 'logs', 'testfeed', 'forcefetch'); var $campaign_structure = array('main' => array(), 'rewrites' => array(), 'categories' => array(), 'feeds' => array()); # __construct() function WPOMatic() { global $wpdb, $wp_version; # Table names init $this->db = array( 'campaign' => $wpdb->prefix . 'wpo_campaign', 'campaign_category' => $wpdb->prefix . 'wpo_campaign_category', 'campaign_feed' => $wpdb->prefix . 'wpo_campaign_feed', 'campaign_word' => $wpdb->prefix . 'wpo_campaign_word', 'campaign_post' => $wpdb->prefix . 'wpo_campaign_post', 'log' => $wpdb->prefix . 'wpo_log' ); # Are we running the new admin panel (2.5+) ? $this->newadmin = version_compare($wp_version, '2.5.0', '>='); # Is installed ? $this->installed = get_option('wpo_version'); $this->setup = get_option('wpo_setup'); # Actions add_action('activate_wp-o-matic/wpomatic.php', array(&$this, 'activate')); # Plugin activated add_action('deactivate_wp-o-matic/wpomatic.php', array(&$this, 'deactivate')); # Plugin deactivated add_action('init', array(&$this, 'init')); # Wordpress init add_action('admin_head', array(&$this, 'adminHead')); # Admin head add_action('admin_footer', array(&$this, 'adminWarning')); # Admin footer add_action('admin_menu', array(&$this, 'adminMenu')); # Admin menu creation # Ajax actions add_action('wp_ajax_delete-campaign', array(&$this, 'adminDelete')); add_action('wp_ajax_test-feed', array(&$this, 'adminTestfeed')); # Filters add_action('the_permalink', array(&$this, 'filterPermalink')); # WP-o-Matic URIs. Without trailing slash $this->optionsurl = get_option('siteurl') . '/wp-admin/options-general.php'; $this->adminurl = $this->optionsurl . '?page=wpomatic.php'; $this->pluginpath = get_option('siteurl') . '/wp-content/plugins/wp-o-matic'; $this->helpurl = $this->pluginpath . '/help.php?item='; $this->tplpath = $this->pluginpath . '/inc/admin'; $this->cachepath = ABSPATH . '/wp-content/uploads'; # Cron command / url $this->cron_url = $this->pluginpath . '/cron.php?code=' . get_option('wpo_croncode'); $this->cron_command = attribute_escape('*/20 * * * * '. $this->getCommand() . ' ' . $this->cron_url); } /** * Called when plugin is activated * * */ function activate($force_install = false) { global $wpdb; if(file_exists(ABSPATH . '/wp-admin/upgrade-functions.php')) require_once(ABSPATH . '/wp-admin/upgrade-functions.php'); else require_once(ABSPATH . '/wp-admin/includes/upgrade.php'); # Options WPOTools::addMissingOptions(array( 'wpo_log' => array(1, 'Log WP-o-Matic actions'), 'wpo_log_stdout' => array(0, 'Output logs to browser while a campaign is being processed'), 'wpo_unixcron' => array(WPOTools::isUnix(), 'Use unix-style cron'), 'wpo_croncode' => array(substr(md5(time()), 0, 8), 'Cron job password.'), 'wpo_cacheimages' => array(0, 'Cache all images. Overrides campaign options'), 'wpo_cachepath' => array('cache', 'Cache path relative to wpomatic directory') )); // only re-install if new version or uninstalled if($force_install || ! $this->installed || $this->installed != $this->version) { # wpo_campaign dbDelta( "CREATE TABLE {$this->db['campaign']} ( id int(11) unsigned NOT NULL auto_increment, title varchar(255) NOT NULL default '', active tinyint(1) default '1', slug varchar(250) default '', template MEDIUMTEXT default '', frequency int(5) default '180', feeddate tinyint(1) default '0', cacheimages tinyint(1) default '1', posttype enum('publish','draft','private') NOT NULL default 'publish', authorid int(11) default NULL, comment_status enum('open','closed','registered_only') NOT NULL default 'open', allowpings tinyint(1) default '1', dopingbacks tinyint(1) default '1', max smallint(3) default '10', linktosource tinyint(1) default '0', count int(11) default '0', lastactive datetime NOT NULL default '0000-00-00 00:00:00', created_on datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (id) );" ); # wpo_campaign_category dbDelta( "CREATE TABLE {$this->db['campaign_category']} ( id int(11) unsigned NOT NULL auto_increment, category_id int(11) NOT NULL, campaign_id int(11) NOT NULL, PRIMARY KEY (id) );" ); # wpo_campaign_feed dbDelta( "CREATE TABLE {$this->db['campaign_feed']} ( id int(11) unsigned NOT NULL auto_increment, campaign_id int(11) NOT NULL default '0', url varchar(255) NOT NULL default '', type varchar(255) NOT NULL default '', title varchar(255) NOT NULL default '', description varchar(255) NOT NULL default '', logo varchar(255) default '', count int(11) default '0', hash varchar(255) default '', lastactive datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (id) );" ); # wpo_campaign_post dbDelta( "CREATE TABLE {$this->db['campaign_post']} ( id int(11) unsigned NOT NULL auto_increment, campaign_id int(11) NOT NULL, feed_id int(11) NOT NULL, post_id int(11) NOT NULL, hash varchar(255) default '', PRIMARY KEY (id) );" ); # wpo_campaign_word dbDelta( "CREATE TABLE {$this->db['campaign_word']} ( id int(11) unsigned NOT NULL auto_increment, campaign_id int(11) NOT NULL, word varchar(255) NOT NULL default '', regex tinyint(1) default '0', rewrite tinyint(1) default '1', rewrite_to varchar(255) default '', relink varchar(255) default '', PRIMARY KEY (id) );" ); # wpo_log dbDelta( "CREATE TABLE {$this->db['log']} ( id int(11) unsigned NOT NULL auto_increment, message mediumtext NOT NULL default '', created_on datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (id) );" ); add_option('wpo_version', $this->version, 'Installed version log'); $this->installed = true; } } /** * Called when plugin is deactivated * * */ function deactivate() { } /** * Uninstalls * * */ function uninstall() { global $wpdb; foreach($this->db as $table) $wpdb->query("DROP TABLE {$table} "); // Delete options WPOTools::deleteOptions(array('wpo_log', 'wpo_log_stdout', 'wpo_unixcron', 'wpo_croncode', 'wpo_cacheimages', 'wpo_cachepath')); } /** * Checks that WP-o-Matic tables exist * * */ function tablesExist() { global $wpdb; foreach($this->db as $table) { if(! $wpdb->query("SELECT * FROM {$table}")) return false; } return true; } /** * Called when blog is initialized * * */ function init() { global $wpdb; if($this->installed) { if(! get_option('wpo_unixcron')) $this->processAll(); if(isset($_REQUEST['page'])) { if(isset($_REQUEST['campaign_add']) || isset($_REQUEST['campaign_edit'])) $this->adminCampaignRequest(); $this->adminExportProcess(); $this->adminInit(); } } } /** * Saves a log message to database * * * @param string $message Message to save */ function log($message) { global $wpdb; if(get_option('wpo_log_stdout')) echo $message; if(get_option('wpo_log')) { $message = $wpdb->escape($message); $time = current_time('mysql', true); $wpdb->query("INSERT INTO {$this->db['log']} (message, created_on) VALUES ('{$message}', '{$time}') "); } } /** * Called by cron.php to update the site * * */ function runCron($log = true) { $this->log('Running cron job'); $this->processAll(); } /** * Finds a suitable command to run cron * * @return string command **/ function getCommand() { $commands = array( @WPOTools::getBinaryPath('curl'), @WPOTools::getBinaryPath('wget'), @WPOTools::getBinaryPath('lynx', ' -dump'), @WPOTools::getBinaryPath('ftp') ); return WPOTools::pick($commands[0], $commands[1], $commands[2], $commands[3], '{wget or similar command here}'); } /** * Determines what the title has to link to * * @return string new text **/ function filterPermalink($url) { // if from admin panel if($this->admin) return $url; if(get_the_ID()) { $campaignid = (int) get_post_meta(get_the_ID(), 'wpo_campaignid', true); if($campaignid) { $campaign = $this->getCampaignById($campaignid); if($campaign->linktosource) return get_post_meta(get_the_ID(), 'wpo_sourcepermalink', true); } return $url; } } /** * Processes all campaigns * */ function processAll() { @set_time_limit(0); $campaigns = $this->getCampaigns('unparsed=1'); foreach($campaigns as $campaign) { $this->processCampaign($campaign); } } /** * Processes a campaign * * @param object $campaign Campaign database object * @return integer Number of processed items */ function processCampaign(&$campaign) { global $wpdb; @set_time_limit(0); ob_implicit_flush(); // Get campaign $campaign = is_numeric($campaign) ? $this->getCampaignById($campaign) : $campaign; // Log $this->log('Processing campaign ' . $campaign->title . ' (ID: ' . $campaign->id . ')'); // Get feeds $count = 0; $feeds = $this->getCampaignFeeds($campaign->id); foreach($feeds as $feed) $count += $this->processFeed($campaign, $feed); $wpdb->query(WPOTools::updateQuery($this->db['campaign'], array( 'count' => $campaign->count + $count, 'lastactive' => current_time('mysql', true) ), "id = {$campaign->id}")); return $count; } /** * Processes a feed * * @param $campaign object Campaign database object * @param $feed object Feed database object * @return The number of items added to database */ function processFeed(&$campaign, &$feed) { global $wpdb; @set_time_limit(0); // Log $this->log('Processing feed ' . $feed->title . ' (ID: ' . $feed->id . ')'); // Access the feed $simplepie = $this->fetchFeed($feed->url, false, $campaign->max); // Get posts (last is first) $items = array(); $count = 0; // Get all rows for this campaign all at once, BUT LIMITED to the last 30 posts $rows = $wpdb->get_results("SELECT * FROM {$this->db['campaign_post']} " . "WHERE campaign_id = {$campaign->id} AND feed_id = {$feed->id} ORDER BY post_id DESC LIMIT 30 "); foreach($simplepie->get_items() as $item) { if($feed->hash == $this->getItemHash($item)) { if($count == 0) $this->log('No new posts'); break; } // look to see if $item is a duplicate of an existing $rows row foreach($rows as $row) { if($row->hash == $this->getItemHash($item)) { $this->log('Filtering duplicate post'); break; } } $count++; array_unshift($items, $item); if($count == $campaign->max) { $this->log('Campaign fetch limit reached at ' . $campaign->max); break; } } // Processes post stack foreach($items as $item) { $this->processItem($campaign, $feed, $item); $lasthash = $this->getItemHash($item); } // If we have added items, let's update the hash if($count) { $wpdb->query(WPOTools::updateQuery($this->db['campaign_feed'], array( 'count' => $count, 'lastactive' => current_time('mysql', true), 'hash' => $lasthash ), "id = {$feed->id}")); $this->log( $count . ' posts added' ); } return $count; } /** * Processes an item * * @param $item object SimplePie_Item object */ function getItemHash($item) { return sha1($item->get_title() . $item->get_permalink()); } /** * Processes an item * * @param $campaign object Campaign database object * @param $feed object Feed database object * @param $item object SimplePie_Item object */ function processItem(&$campaign, &$feed, &$item) { global $wpdb; $this->log('Processing item'); // Item content $content = $this->parseItemContent($campaign, $feed, $item); // Item date if($campaign->feeddate && ($item->get_date('U') > (current_time('timestamp', 1) - $campaign->frequency) && $item->get_date('U') < current_time('timestamp', 1))) $date = $item->get_date('U'); else $date = null; // Categories $categories = $this->getCampaignData($campaign->id, 'categories'); // Meta $meta = array( 'wpo_campaignid' => $campaign->id, 'wpo_feedid' => $feed->id, 'wpo_sourcepermalink' => $item->get_permalink() ); // Create post $postid = $this->insertPost($wpdb->escape($item->get_title()), $wpdb->escape($content), $date, $categories, $campaign->posttype, $campaign->authorid, $campaign->allowpings, $campaign->comment_status, $meta); // If pingback/trackbacks if($campaign->dopingbacks) { $this->log('Processing item pingbacks'); require_once(ABSPATH . WPINC . '/comment.php'); pingback($content, $postid); } // Save post to log database $wpdb->query(WPOTools::insertQuery($this->db['campaign_post'], array( 'campaign_id' => $campaign->id, 'feed_id' => $feed->id, 'post_id' => $postid, 'hash' => $this->getItemHash($item) ))); } /** * Processes an item * * @param $campaign object Campaign database object * @param $feed object Feed database object * @param $item object SimplePie_Item object */ function isDuplicate(&$campaign, &$feed, &$item) { global $wpdb; $hash = $this->getItemHash($item); $row = $wpdb->get_row("SELECT * FROM {$this->db['campaign_post']} " . "WHERE campaign_id = {$campaign->id} AND feed_id = {$feed->id} AND hash = '$hash' "); return !! $row; } /** * Writes a post to blog * * * @param string $title Post title * @param string $content Post content * @param integer $timestamp Post timestamp * @param array $category Array of categories * @param string $status 'draft', 'published' or 'private' * @param integer $authorid ID of author. * @param boolean $allowpings Allow pings * @param boolean $comment_status 'open', 'closed', 'registered_only' * @param array $meta Meta key / values * @return integer Created post id */ function insertPost($title, $content, $timestamp = null, $category = null, $status = 'draft', $authorid = null, $allowpings = true, $comment_status = 'open', $meta = array()) { $date = ($timestamp) ? gmdate('Y-m-d H:i:s', $timestamp + (get_option('gmt_offset') * 3600)) : null; $postid = wp_insert_post(array( 'post_title' => $title, 'post_content' => $content, 'post_content_filtered' => $content, 'post_category' => $category, 'post_status' => $status, 'post_author' => $authorid, 'post_date' => $date, 'comment_status' => $comment_status, 'ping_status' => $allowpings )); foreach($meta as $key => $value) $this->insertPostMeta($postid, $key, $value); return $postid; } /** * insertPostMeta * * */ function insertPostMeta($postid, $key, $value) { global $wpdb; $result = $wpdb->query( "INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) " . " VALUES ('$postid','$key','$value') "); return $wpdb->insert_id; } /** * Parses an item content * * @param $campaign object Campaign database object * @param $feed object Feed database object * @param $item object SimplePie_Item object */ function parseItemContent(&$campaign, &$feed, &$item) { $content = $item->get_content(); // Caching if(get_option('wpo_cacheimages') || $campaign->cacheimages) { $images = WPOTools::parseImages($content); $urls = $images[2]; if(sizeof($urls)) { $this->log('Caching images'); foreach($urls as $url) { $newurl = $this->cacheRemoteImage($url); if($newurl) $content = str_replace($url, $newurl, $content); } } } // Template parse $vars = array( '{content}', '{title}', '{permalink}', '{feedurl}', '{feedtitle}', '{feedlogo}', '{campaigntitle}', '{campaignid}', '{campaignslug}' ); $replace = array( $content, $item->get_title(), $item->get_link(), $feed->url, $feed->title, $feed->logo, $campaign->title, $campaign->id, $campaign->slug ); $content = str_ireplace($vars, $replace, ($campaign->template) ? $campaign->template : '{content}'); // Rewrite $rewrites = $this->getCampaignData($campaign->id, 'rewrites'); foreach($rewrites as $rewrite) { $origin = $rewrite['origin']['search']; if(isset($rewrite['rewrite'])) { $reword = isset($rewrite['relink']) ? '' . $rewrite['rewrite'] . '' : $rewrite['rewrite']; if($rewrite['origin']['regex']) { $content = preg_replace($origin, $reword, $content); } else $content = str_ireplace($origin, $reword, $content); } else if(isset($rewrite['relink'])) $content = str_ireplace($origin, '' . $origin . '', $content); } return $content; } /** * Cache remote image * * @return string New url */ function cacheRemoteImage($url) { $time = current_time('timestamp'); $y = date("Y", $time); $m = date("m", $time); $d = date("d", $time); $subdir = "$y/$m/$d"; $contents = @file_get_contents($url); $filename = substr(md5(time()), 0, 5) . '_' . basename($url); $cachepath = $this->cachepath; $fullcachepath = $cachepath . '/' . $subdir; if ( !file_exists ($fullcachepath) ) { mkdir("$fullcachepath", 0777, TRUE); } if(is_writable($cachepath) && $contents) { file_put_contents($cachepath . '/' . $subdir . '/' . $filename, $contents); chmod("$fullcachepath/$filename", 0755); chown("$fullcachepath/$filename", "astrodispatch"); return get_option('siteurl') . '/wp-content/uploads/' . $subdir . '/' . $filename; } return false; } /** * Parses a feed with SimplePie * * @param boolean $stupidly_fast Set fast mode. Best for checks * @param integer $max Limit of items to fetch * @return SimplePie_Item Feed object **/ function fetchFeed($url, $stupidly_fast = false, $max = 0) { # SimplePie if(! class_exists('SimplePie')) require_once( WPOINC . 'simplepie/simplepie.class.php' ); $feed = new SimplePie(); $feed->enable_order_by_date(false); // thanks Julian Popov $feed->set_feed_url($url); $feed->set_item_limit($max); $feed->set_stupidly_fast($stupidly_fast); $feed->enable_cache(false); $feed->init(); $feed->handle_content_type(); return $feed; } /** * Returns all blog usernames (in form [user_login => display_name (user_login)] ) * * @return array $usernames **/ function getBlogUsernames() { $return = array(); $users = get_users_of_blog(); foreach($users as $user) { if($user->display_name == $user->user_login) $return[$user->user_login] = "{$user->display_name}"; else $return[$user->user_login] = "{$user->display_name} ({$user->user_login})"; } return $return; } /** * Returns all data for a campaign * * */ function getCampaignData($id, $section = null) { global $wpdb; $campaign = (array) $this->getCampaignById($id); if($campaign) { $campaign_data = $this->campaign_structure; // Main if(!$section || $section == 'main') { $campaign_data['main'] = array_merge($campaign_data['main'], $campaign); $userdata = get_userdata($campaign_data['main']['authorid']); $campaign_data['main']['author'] = $userdata->user_login; } // Categories if(!$section || $section == 'categories') { $categories = $wpdb->get_results("SELECT * FROM {$this->db['campaign_category']} WHERE campaign_id = $id"); foreach($categories as $category) $campaign_data['categories'][] = $category->category_id; } // Feeds if(!$section || $section == 'feeds') { $campaign_data['feeds']['edit'] = array(); $feeds = $this->getCampaignFeeds($id); foreach($feeds as $feed) $campaign_data['feeds']['edit'][$feed->id] = $feed->url; } // Rewrites if(!$section || $section == 'rewrites') { $rewrites = $wpdb->get_results("SELECT * FROM {$this->db['campaign_word']} WHERE campaign_id = $id"); foreach($rewrites as $rewrite) { $word = array('origin' => array('search' => $rewrite->word, 'regex' => $rewrite->regex), 'rewrite' => $rewrite->rewrite_to, 'relink' => $rewrite->relink); if(! $rewrite->rewrite) unset($word['rewrite']); if(empty($rewrite->relink)) unset($word['relink']); $campaign_data['rewrites'][] = $word; } } if($section) return $campaign_data[$section]; return $campaign_data; } return false; } /** * Retrieves logs from database * * */ function getLogs($args = '') { global $wpdb; extract(WPOTools::getQueryArgs($args, array('orderby' => 'created_on', 'ordertype' => 'DESC', 'limit' => null, 'page' => null, 'perpage' => null))); if(!is_null($page)) { if($page == 0) $page = 1; $page--; $start = $page * $perpage; $end = $start + $perpage; $limit = "LIMIT {$start}, {$end}"; } return $wpdb->get_results("SELECT * FROM {$this->db['log']} ORDER BY $orderby $ordertype $limit"); } /** * Retrieves a campaign by its id * * */ function getCampaignById($id) { global $wpdb; $id = intval($id); return $wpdb->get_row("SELECT * FROM {$this->db['campaign']} WHERE id = $id"); } /** * Retrieves a feed by its id * * */ function getFeedById($id) { global $wpdb; $id = intval($id); return $wpdb->get_row("SELECT * FROM {$this->db['campaign_feed']} WHERE id = $id"); } /** * Retrieves campaigns from database * * */ function getCampaigns($args = '') { global $wpdb; extract(WPOTools::getQueryArgs($args, array('fields' => '*', 'search' => '', 'orderby' => 'created_on', 'ordertype' => 'DESC', 'where' => '', 'unparsed' => false, 'limit' => null))); if(! empty($search)) $where .= " AND title LIKE '%{$search}%' "; if($unparsed) $where .= " AND active = 1 AND (frequency + UNIX_TIMESTAMP(lastactive)) < ". (current_time('timestamp', true) - get_option('gmt_offset') * 3600) . " "; $sql = "SELECT $fields FROM {$this->db['campaign']} WHERE 1 = 1 $where " . "ORDER BY $orderby $ordertype $limit"; return $wpdb->get_results($sql); } /** * Retrieves feeds for a certain campaign * * @param integer $id Campaign id */ function getCampaignFeeds($id) { global $wpdb; return $wpdb->get_results("SELECT * FROM {$this->db['campaign_feed']} WHERE campaign_id = $id"); } /** * Retrieves all WP posts for a certain campaign * * @param integer $id Campaign id */ function getCampaignPosts($id) { global $wpdb; return $wpdb->get_results("SELECT post_id FROM {$this->db['campaign_post']} WHERE campaign_id = $id "); } /** * Adds a feed by url and campaign id * * */ function addCampaignFeed($id, $feed) { global $wpdb; $simplepie = $this->fetchFeed($feed, true); $url = $wpdb->escape($simplepie->subscribe_url()); // If it already exists, ignore it if(! $wpdb->get_var("SELECT id FROM {$this->db['campaign_feed']} WHERE campaign_id = $id AND url = '$url' ")) { $wpdb->query(WPOTools::insertQuery($this->db['campaign_feed'], array('url' => $url, 'title' => $wpdb->escape($simplepie->get_title()), 'description' => $wpdb->escape($simplepie->get_description()), 'logo' => $wpdb->escape($simplepie->get_image_url()), 'campaign_id' => $id) )); return $wpdb->insert_id; } return false; } /** * Retrieves feeds from database * * @param mixed $args */ function getFeeds($args = '') { global $wpdb; extract(WPOTools::getQueryArgs($args, array('fields' => '*', 'campid' => '', 'join' => false, 'orderby' => 'created_on', 'ordertype' => 'DESC', 'limit' => null))); $sql = "SELECT $fields FROM {$this->db['campaign_feed']} cf "; if(!empty($join)) $sql .= "INNER JOIN {$this->db['campaign']} camp ON camp.id = cf.campaign_id "; if(!empty($campid)) $sql .= "WHERE cf.campaign_id = $campid"; return $wpdb->get_results($sql); } /** * Returns how many seconds left till reprocessing * * @return seconds **/ function getCampaignRemaining(&$campaign, $gmt = 0) { return mysql2date('U', $campaign->lastactive) + $campaign->frequency - current_time('timestamp', true) + ($gmt ? 0 : (get_option('gmt_offset') * 3600)); } /** * Called when WP-o-Matic admin pages initialize. * * */ function adminInit() { auth_redirect(); // force display of a certain section $this->section = ($this->setup) ? ((isset($_REQUEST['s']) && $_REQUEST['s']) ? $_REQUEST['s'] : $this->sections[0]) : 'setup'; if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) die('Please switch to Firefox / Safari'); wp_enqueue_script('prototype'); wp_enqueue_script('wpoadmin', $this->tplpath . '/admin.js', array('prototype'), $this->version); if($this->section == 'list') wp_enqueue_script('listman'); if(WPOTools::isAjax()) { $this->admin(); exit; } } /** * Called by admin-header.php * * @return void **/ function adminHead() { $this->admin = true; } /** * Shows a warning box for setup * * */ function adminWarning() { if(! $this->setup && $this->section != 'setup') { echo "
" . sprintf(__('Please click here to setup and configure WP-o-Matic.', 'wpomatic'), $this->adminurl . '&s=setup') . "