public static function init() { self::$uri = plugin_dir_url(__FILE__); self::$dir = plugin_dir_path(__FILE__); self::$basen = plugin_basename(__FILE__); self::load_wpe_textdomain(); new self(TRUE); }
public static function check_campaigndata($campaigndata = array()) { if (empty($campaigndata['campaign_posttype']) or !is_string($campaigndata['campaign_posttype'])) { $campaigndata['campaign_posttype'] = 'publish'; } if (empty($campaigndata['campaign_customposttype']) or !is_string($campaigndata['campaign_customposttype'])) { $campaigndata['campaign_customposttype'] = 'post'; } if (!isset($campaigndata['activated']) or !is_bool($campaigndata['activated'])) { $campaigndata['activated'] = false; } if (!isset($campaigndata['campaign_feeddate']) or !is_bool($campaigndata['campaign_feeddate'])) { $campaigndata['campaign_feeddate'] = false; } if (!isset($campaigndata['campaign_feeds']) or !is_array($campaigndata['campaign_feeds'])) { $campaigndata['campaign_feeds'] = array(); } if (!isset($campaigndata['campaign_wrd2cat']) or !is_array($campaigndata['campaign_wrd2cat'])) { $campaigndata['campaign_wrd2cat'] = array('word' => array(''), 'regex' => array(false), 'w2ccateg' => array(''), 'cases' => array(false)); } if (!isset($campaigndata['campaign_rewrites']) or !is_array($campaigndata['campaign_rewrites'])) { $campaigndata['campaign_rewrites'] = array(); } //if (!isset($campaigndata['campaign_categories'])) if (!isset($campaigndata['campaign_categories']) or !is_array($campaigndata['campaign_categories'])) { $campaigndata['campaign_categories'] = array(); } if (!isset($campaigndata['campaign_tags']) or !is_string($campaigndata['campaign_tags'])) { $campaigndata['campaign_tags'] = ''; } if (!isset($campaigndata['campaign_autocats']) or !is_bool($campaigndata['campaign_autocats'])) { $campaigndata['campaign_autocats'] = false; } if (!isset($campaigndata['campaign_linktosource']) or !is_bool($campaigndata['campaign_linktosource'])) { $campaigndata['campaign_linktosource'] = false; } if (!isset($campaigndata['campaign_strip_links']) or !is_bool($campaigndata['campaign_strip_links'])) { $campaigndata['campaign_strip_links'] = false; } if (!isset($campaigndata['campaign_commentstatus']) or !is_string($campaigndata['campaign_commentstatus'])) { $campaigndata['campaign_commentstatus'] = 'open'; } if (!isset($campaigndata['campaign_allowpings'])) { // or !is_bool($campaigndata['campaign_allowpings'])) $campaigndata['campaign_allowpings'] = true; } if (!isset($campaigndata['campaign_woutfilter'])) { // or !is_bool($campaigndata['campaign_woutfilter'])) $campaigndata['campaign_woutfilter'] = false; } if (!isset($campaigndata['campaign_author'])) { // or !is_int($campaigndata['campaign_author'])) $campaigndata['campaign_author'] = 0; } if (!isset($campaigndata['campaign_max'])) { // or !is_int($campaigndata['campaign_max'])) $campaigndata['campaign_max'] = 10; } // *** Processed posts count if (!isset($campaigndata['postscount'])) { // or !is_int($campaigndata['postscount'])) $campaigndata['postscount'] = 0; } if (!isset($campaigndata['lastpostscount'])) { // or !is_int($campaigndata['lastpostscount'])) $campaigndata['lastpostscount'] = 0; } if (!isset($campaigndata['lastrun'])) { // or !is_int($campaigndata['lastrun'])) $campaigndata['lastrun'] = 0; } if (!isset($campaigndata['lastruntime'])) { // or !is_int($campaigndata['lastruntime'])) $campaigndata['lastruntime'] = 0; } // *** Campaign Images $campaigndata['campaign_imgcache'] = (!isset($campaigndata['campaign_imgcache']) or !is_bool($campaigndata['campaign_imgcache']) or !$campaigndata['campaign_imgcache'] == 1) ? false : true; $campaigndata['campaign_cancel_imgcache'] = (!isset($campaigndata['campaign_cancel_imgcache']) or !is_bool($campaigndata['campaign_cancel_imgcache']) or !$campaigndata['campaign_cancel_imgcache'] == 1) ? false : true; $campaigndata['campaign_nolinkimg'] = (!isset($campaigndata['campaign_nolinkimg']) or !is_bool($campaigndata['campaign_nolinkimg']) or !$campaigndata['campaign_nolinkimg'] == 1) ? false : true; $campaigndata['campaign_solo1ra'] = (!isset($campaigndata['campaign_solo1ra']) or !is_bool($campaigndata['campaign_solo1ra']) or !$campaigndata['campaign_solo1ra'] == 1) ? false : true; $campaigndata['default_img'] = (!isset($campaigndata['default_img']) or !is_bool($campaigndata['default_img']) or !$campaigndata['default_img'] == 1) ? false : true; if (!isset($campaigndata['default_img_url']) or !is_string($campaigndata['default_img_url'])) { $campaigndata['default_img_url'] = ''; } if (!isset($campaigndata['default_img_link']) or !is_string($campaigndata['default_img_link'])) { $campaigndata['default_img_link'] = ''; } if (!isset($campaigndata['default_img_title']) or !is_string($campaigndata['default_img_title'])) { $campaigndata['default_img_title'] = ''; } if (!isset($campaigndata['cron']) or !is_string($campaigndata['cron'])) { $campaigndata['cron'] = '0 3 * * *'; } if (!isset($campaigndata['cronnextrun']) or !is_numeric($campaigndata['cronnextrun'])) { $campaigndata['cronnextrun'] = WPeMatico::time_cron_next($campaigndata['cron']); } if (!isset($campaigndata['mailaddresslog'])) { $campaigndata['mailaddresslog'] = ''; } if (is_string($campaigndata['mailaddresslog']) && (false === ($pos = strpos($campaigndata['mailaddresslog'], '@')) or false === strpos($campaigndata['mailaddresslog'], '.', $pos))) { $campaigndata['mailaddresslog'] = ''; } //get_option('admin_email'); if (!isset($campaigndata['mailerroronly']) or !is_bool($campaigndata['mailerroronly'])) { $campaigndata['mailerroronly'] = true; } if (!isset($campaigndata['mailefilesize']) or !is_float($campaigndata['mailefilesize'])) { $campaigndata['mailefilesize'] = 0; } //if (!is_string($campaigndata['mailaddress']) or false === $pos=strpos($campaigndata['mailaddress'],'@') or false === strpos($campaigndata['mailaddress'],'.',$pos)) // $campaigndata['mailaddress']=''; if (!isset($campaigndata['campaign_enable_template']) or !is_bool($campaigndata['campaign_enable_template'])) { $campaigndata['campaign_enable_template'] = false; } return $campaigndata; }
static function save_quick_edit_post($post_id) { //wp_die('save_quick_edit_post'.print_r($_POST,1)); $slug = 'wpematico'; if (!isset($_POST['post_type']) || $slug !== $_POST['post_type']) { return $post_id; } if (!current_user_can('edit_post', $post_id)) { return $post_id; } $_POST += array("{$slug}_edit_nonce" => ''); if (!wp_verify_nonce($_POST["{$slug}_edit_nonce"], plugin_basename(__FILE__))) { wp_die('No verify nonce'); return; } $nivelerror = error_reporting(E_ERROR | E_WARNING | E_PARSE); $campaign = WPeMatico::get_campaign($post_id); $posdata = $_POST; //apply_filters('wpematico_check_campaigndata', $_POST ); //parse disabled checkfields that dont send any data $posdata['campaign_feeddate'] = !isset($posdata['campaign_feeddate']) || empty($posdata['campaign_feeddate']) ? false : $posdata['campaign_feeddate'] == 1 ? true : false; $posdata['campaign_allowpings'] = !isset($posdata['campaign_allowpings']) || empty($posdata['campaign_allowpings']) ? false : $posdata['campaign_allowpings'] == 1 ? true : false; $posdata['campaign_linktosource'] = !isset($posdata['campaign_linktosource']) || empty($posdata['campaign_linktosource']) ? false : $posdata['campaign_linktosource'] == 1 ? true : false; $posdata['campaign_strip_links'] = !isset($posdata['campaign_strip_links']) || empty($posdata['campaign_strip_links']) ? false : $posdata['campaign_strip_links'] == 1 ? true : false; $campaign = array_merge($campaign, $posdata); $campaign = apply_filters('wpematico_check_campaigndata', $campaign); error_reporting($nivelerror); WPeMatico::update_campaign($post_id, $campaign); return $post_id; }
$activated = $campaign['activated']; $cronnextrun = $campaign['cronnextrun']; if (!$activated) { continue; } if ($cronnextrun >= current_time('timestamp')) { if ($cfg['logexternalcron']) { @($file_handle = fopen($filedir . sanitize_file_name($post->post_title . ".txt.log"), "w+")); $msg = 'Running WPeMatico external WP-Cron' . "\n"; linelog($file_handle, $msg . PHP_EOL); echo $msg; $msg = $post->post_title . ' ' . "\n"; linelog($file_handle, $msg . PHP_EOL); echo $msg; } $msg = WPeMatico::wpematico_dojob($post->ID); if ($cfg['logexternalcron']) { $msg = strip_tags($msg); $msg .= "\n"; linelog($file_handle, $msg . PHP_EOL); echo '<pre>' . $msg . '</pre>'; } } } if ($cfg['logexternalcron'] && $file_handle != false) { $msg = ' Success !' . "\n"; linelog($file_handle, $msg . PHP_EOL); echo $msg; if ($file_handle !== FALSE) { fclose($file_handle); }
function custom_wpematico_column( $column, $post_id ) { $cfg = get_option( WPeMatico :: OPTION_KEY); $campaign_data = WPeMatico :: get_campaign ( $post_id ); switch ( $column ) { case 'status': echo $campaign_data['campaign_posttype']; break; case 'count': echo $campaign_data['postscount']; break; case 'next': $starttime = @$campaign_data['starttime']; //print_r($campaign_data); $activated = $campaign_data['activated']; if ($starttime>0) { $runtime=current_time('timestamp')-$starttime; // Aca agregar control de tiempo y sacarla de en ejecucion *********************************************************************** if(($cfg['campaign_timeout'] <= $runtime) && ($cfg['campaign_timeout']>0)) { $campaign_data['lastrun'] = $starttime; $campaign_data['lastruntime'] = ' <span style="color:red;">Timeout: '.$cfg['campaign_timeout'].'</span>'; $campaign_data['starttime'] = ''; $campaign_data['lastpostscount'] = 0; // posts procesados esta vez WPeMatico :: update_campaign($post_id, $campaign_data); //Save Campaign new data } echo __('Running since:', WPeMatico :: TEXTDOMAIN ).' '.$runtime.' '.__('sec.', WPeMatico :: TEXTDOMAIN ); } elseif ($activated) { //$campaign_data['cronnextrun']= WPeMatico :: time_cron_next($campaign_data['cron']); //set next run, ver por que no actualizae el cron $cronnextrun = $campaign_data['cronnextrun']; echo date_i18n(get_option('date_format'),$cronnextrun).'-'. date_i18n(get_option('time_format'),$cronnextrun); } else { echo __('Inactive', WPeMatico :: TEXTDOMAIN ); } break; case 'last': $lastrun = @$campaign_data['lastrun']; $lastruntime = @$campaign_data['lastruntime']; if ($lastrun) { echo date_i18n(get_option('date_format'),$lastrun).'-'. date_i18n(get_option('time_format'),$lastrun); if (isset($lastruntime)) echo '<br />'.__('Runtime:', WPeMatico :: TEXTDOMAIN ).' <span id="lastruntime">'.$lastruntime.'</span> '.__('sec.', WPeMatico :: TEXTDOMAIN ); } else { echo __('None', WPeMatico :: TEXTDOMAIN ); } break; } }
public static function options_box($post) { global $post, $campaign_data, $cfg, $helptip; $campaign_max = $campaign_data['campaign_max']; $campaign_feeddate = $campaign_data['campaign_feeddate']; $campaign_author = $campaign_data['campaign_author']; $campaign_linktosource = $campaign_data['campaign_linktosource']; $campaign_commentstatus = $campaign_data['campaign_commentstatus']; $campaign_allowpings = $campaign_data['campaign_allowpings']; $campaign_woutfilter = $campaign_data['campaign_woutfilter']; $campaign_strip_links = $campaign_data['campaign_strip_links']; ?> <div id="optionslayer" class="ibfix vtop"> <p> <input name="campaign_max" type="number" min="0" size="3" value="<?php echo $campaign_max; ?> " class="small-text" id="campaign_max"/> <label for="campaign_max"><?php echo __('Max items to create on each fetch.', WPeMatico::TEXTDOMAIN); ?> </label> <span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['itemfetch']; ?> "></span> </p> <p> <input class="checkbox" type="checkbox"<?php checked($campaign_feeddate, true); ?> name="campaign_feeddate" value="1" id="campaign_feeddate"/> <label for="campaign_feeddate"><?php echo __('Use feed item date.', WPeMatico::TEXTDOMAIN); ?> </label> <span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['itemdate']; ?> "></span> </p> <p> <input class="checkbox" type="checkbox"<?php checked($campaign_linktosource, true); ?> name="campaign_linktosource" value="1" id="campaign_linktosource"/> <label for="campaign_linktosource"><?php echo __('Post title links to source.', WPeMatico::TEXTDOMAIN); ?> </label> <span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['linktosource']; ?> "></span> <?php if ($cfg['disableccf']) { echo '<br /><small>' . __('Feature deactivated on Settings.', WPeMatico::TEXTDOMAIN) . '</small>'; } ?> </p> <p> <input class="checkbox" type="checkbox"<?php checked($campaign_strip_links, true); ?> name="campaign_strip_links" value="1" id="campaign_strip_links"/> <label for="campaign_strip_links"><?php echo __('Strip links from content.', WPeMatico::TEXTDOMAIN); ?> </label> <span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['striplinks']; ?> "></span> </p> <p> <input class="checkbox" type="checkbox"<?php checked($campaign_allowpings, true); ?> name="campaign_allowpings" value="1" id="campaign_allowpings"/> <label for="campaign_allowpings"><?php echo __('Pingbacks y trackbacks.', WPeMatico::TEXTDOMAIN); ?> </label> <span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['allowpings']; ?> "></span> </p> <p> <label for="campaign_commentstatus"><?php echo __('Discussion options:', WPeMatico::TEXTDOMAIN); ?> </label> <select id="campaign_commentstatus" name="campaign_commentstatus"> <option value="open"<?php echo $campaign_commentstatus == "open" || $campaign_commentstatus == "" ? 'SELECTED' : ''; ?> >Open</option> <option value="closed" <?php echo $campaign_commentstatus == "closed" ? 'SELECTED' : ''; ?> >Closed</option> <option value="registered_only" <?php echo $campaign_commentstatus == "registered_only" ? 'SELECTED' : ''; ?> >Registered only</option> </select> <span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['commentstatus']; ?> "></span> </p> <p> <label for="campaign_author"><?php echo __('Author:', WPeMatico::TEXTDOMAIN); ?> </label> <?php wp_dropdown_users(array('name' => 'campaign_author', 'selected' => $campaign_author)); ?> <span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['postsauthor']; ?> "></span> </p> <?php if ($cfg['woutfilter']) { ?> <p> <input class="checkbox" value="1" type="checkbox" <?php checked($campaign_woutfilter, true); ?> name="campaign_woutfilter" id="campaign_woutfilter" /> <label for="campaign_woutfilter"><?php echo __('Post Content Unfiltered.', WPeMatico::TEXTDOMAIN); ?> </label><span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['woutfilter']; ?> "></span> </p> <?php } ?> </div> <?php $activated = $campaign_data['activated']; $cron = $campaign_data['cron']; ?> <div id="schedulelayer" class="ibfix vtop"> <p> <input class="checkbox" value="1" type="checkbox" <?php checked($activated, true); ?> name="activated" id="activated" /> <label for="activated"><?php _e('Activate scheduling', WPeMatico::TEXTDOMAIN); ?> </label><span class="mya4_sprite infoIco help_tip" title="<?php echo $helptip['schedule']; ?> "></span> </p> <?php _e('Working as <a href="http://wikipedia.org/wiki/Cron" target="_blank">Cron</a> job schedule:', WPeMatico::TEXTDOMAIN); echo ' <i>' . $cron . '</i><br />'; _e('Next runtime:', WPeMatico::TEXTDOMAIN); echo ' ' . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), WPeMatico::time_cron_next($cron)); //_e('Next runtime:', WPeMatico :: TEXTDOMAIN ); echo ' '.date('D, M j Y H:i',WPeMatico :: time_cron_next($cron)); ?> <div id="cronboxes"> <?php @(list($cronstr['minutes'], $cronstr['hours'], $cronstr['mday'], $cronstr['mon'], $cronstr['wday']) = explode(' ', $cron, 5)); ?> <div> <b><?php _e('Minutes: ', 'wpematico'); ?> </b><br /> <?php if (strstr($cronstr['minutes'], '*/')) { $minutes = explode('/', $cronstr['minutes']); } else { $minutes = explode(',', $cronstr['minutes']); } ?> <select name="cronminutes[]" id="cronminutes" multiple="multiple"> <option value="*"<?php selected(in_array('*', $minutes, true), true, true); ?> ><?php _e('Any (*)', 'wpematico'); ?> </option> <?php for ($i = 0; $i < 60; $i = $i + 5) { echo "<option value=\"" . $i . "\"" . selected(in_array("{$i}", $minutes, true), true, false) . ">" . $i . "</option>"; } ?> </select> </div> <div> <b><?php _e('Hours:', 'wpematico'); ?> </b><br /> <?php if (strstr($cronstr['hours'], '*/')) { $hours = explode('/', $cronstr['hours']); } else { $hours = explode(',', $cronstr['hours']); } ?> <select name="cronhours[]" id="cronhours" multiple="multiple"> <option value="*"<?php selected(in_array('*', $hours, true), true, true); ?> ><?php _e('Any (*)', 'wpematico'); ?> </option> <?php for ($i = 0; $i < 24; $i++) { echo "<option value=\"" . $i . "\"" . selected(in_array("{$i}", $hours, true), true, false) . ">" . $i . "</option>"; } ?> </select> </div> <div> <b><?php _e('Days:', 'wpematico'); ?> </b><br /> <?php if (strstr($cronstr['mday'], '*/')) { $mday = explode('/', $cronstr['mday']); } else { $mday = explode(',', $cronstr['mday']); } ?> <select name="cronmday[]" id="cronmday" multiple="multiple"> <option value="*"<?php selected(in_array('*', $mday, true), true, true); ?> ><?php _e('Any (*)', 'wpematico'); ?> </option> <?php for ($i = 1; $i <= 31; $i++) { echo "<option value=\"" . $i . "\"" . selected(in_array("{$i}", $mday, true), true, false) . ">" . $i . "</option>"; } ?> </select> </div> <div> <b><?php _e('Months:', 'wpematico'); ?> </b><br /> <?php if (strstr($cronstr['mon'], '*/')) { $mon = explode('/', $cronstr['mon']); } else { $mon = explode(',', $cronstr['mon']); } ?> <select name="cronmon[]" id="cronmon" multiple="multiple"> <option value="*"<?php selected(in_array('*', $mon, true), true, true); ?> ><?php _e('Any (*)', 'wpematico'); ?> </option> <option value="1"<?php selected(in_array('1', $mon, true), true, true); ?> ><?php _e('January'); ?> </option> <option value="2"<?php selected(in_array('2', $mon, true), true, true); ?> ><?php _e('February'); ?> </option> <option value="3"<?php selected(in_array('3', $mon, true), true, true); ?> ><?php _e('March'); ?> </option> <option value="4"<?php selected(in_array('4', $mon, true), true, true); ?> ><?php _e('April'); ?> </option> <option value="5"<?php selected(in_array('5', $mon, true), true, true); ?> ><?php _e('May'); ?> </option> <option value="6"<?php selected(in_array('6', $mon, true), true, true); ?> ><?php _e('June'); ?> </option> <option value="7"<?php selected(in_array('7', $mon, true), true, true); ?> ><?php _e('July'); ?> </option> <option value="8"<?php selected(in_array('8', $mon, true), true, true); ?> ><?php _e('Augest'); ?> </option> <option value="9"<?php selected(in_array('9', $mon, true), true, true); ?> ><?php _e('September'); ?> </option> <option value="10"<?php selected(in_array('10', $mon, true), true, true); ?> ><?php _e('October'); ?> </option> <option value="11"<?php selected(in_array('11', $mon, true), true, true); ?> ><?php _e('November'); ?> </option> <option value="12"<?php selected(in_array('12', $mon, true), true, true); ?> ><?php _e('December'); ?> </option> </select> </div> <div> <b><?php _e('Weekday:', 'wpematico'); ?> </b><br /> <select name="cronwday[]" id="cronwday" multiple="multiple"> <?php if (strstr($cronstr['wday'], '*/')) { $wday = explode('/', $cronstr['wday']); } else { $wday = explode(',', $cronstr['wday']); } ?> <option value="*"<?php selected(in_array('*', $wday, true), true, true); ?> ><?php _e('Any (*)', 'wpematico'); ?> </option> <option value="0"<?php selected(in_array('0', $wday, true), true, true); ?> ><?php _e('Sunday'); ?> </option> <option value="1"<?php selected(in_array('1', $wday, true), true, true); ?> ><?php _e('Monday'); ?> </option> <option value="2"<?php selected(in_array('2', $wday, true), true, true); ?> ><?php _e('Tuesday'); ?> </option> <option value="3"<?php selected(in_array('3', $wday, true), true, true); ?> ><?php _e('Wednesday'); ?> </option> <option value="4"<?php selected(in_array('4', $wday, true), true, true); ?> ><?php _e('Thursday'); ?> </option> <option value="5"<?php selected(in_array('5', $wday, true), true, true); ?> ><?php _e('Friday'); ?> </option> <option value="6"<?php selected(in_array('6', $wday, true), true, true); ?> ><?php _e('Saturday'); ?> </option> </select> </div> <br class="clear" /> </div> </div> <?php }
public static function processAll() { $args = array('post_type' => 'wpematico', 'orderby' => 'ID', 'order' => 'ASC'); $campaignsid = get_posts($args); $msglogs = ""; foreach ($campaignsid as $campaignid) { @set_time_limit(0); $msglogs .= WPeMatico::wpematico_dojob($campaignid->ID); } return $msglogs; }
public static function save_campaigndata($post_id) { global $post; // Stop WP from clearing custom fields on autosave, and also during ajax requests (e.g. quick edit) and bulk edits. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || defined('DOING_AJAX') && DOING_AJAX || isset($_REQUEST['bulk_edit'])) { return $post_id; } if (!wp_verify_nonce(@$_POST['wpematico_nonce'], 'edit-campaign')) { return $post_id; } if ($post->post_type != 'wpematico') { return $post_id; } $nivelerror = error_reporting(E_ERROR | E_WARNING | E_PARSE); $cfg = get_option(WPeMatico::OPTION_KEY); $campaign = array(); $campaign = WPeMatico::get_campaign($post_id); $campaign['campaign_posttype'] = $_POST['campaign_posttype']; $campaign['campaign_customposttype'] = $_POST['campaign_customposttype']; $campaign['activated'] = $_POST['activated'] == 1 ? true : false; $campaign['campaign_feeddate'] = $_POST['campaign_feeddate'] == 1 ? true : false; $campaign['cron'] = WPeMatico::cron_string($_POST); $campaign['cronnextrun'] = WPeMatico::time_cron_next($campaign['cron']); // Direccion de e-mail donde enviar los logs $campaign['mailaddresslog'] = sanitize_email($_POST['mailaddresslog']); $campaign['mailerroronly'] = $_POST['mailerroronly'] == 1 ? true : false; // Process categories $campaign['campaign_autocats'] = $_POST['campaign_autocats'] == 1 ? true : false; // Primero proceso las categorias nuevas si las hay y las agrego al final del array # New categories if (isset($_POST['campaign_newcat'])) { foreach ($_POST['campaign_newcat'] as $k => $on) { $catname = $_POST['campaign_newcatname'][$k]; if (!empty($catname)) { //$_POST['campaign_categories'][] = wp_insert_category(array('cat_name' => $catname)); $arg = array('description' => "Auto Added by WPeMatico", 'parent' => "0"); $_POST['campaign_categories'][] = wp_insert_term($catname, "category", $arg); } } } # All: Las elegidas + las nuevas ya agregadas if (isset($_POST['campaign_categories'])) { $campaign['campaign_categories'] = (array) $_POST['campaign_categories']; } //if(isset($_POST['campaign_tags'])) { $campaign['campaign_tags'] = $_POST['campaign_tags']; //} #Proceso las Words to Category sacando los que estan en blanco //campaign_wrd2cat, campaign_wrd2cat_regex, campaign_wrd2cat_category if (isset($_POST['campaign_wrd2cat'])) { foreach ($_POST['campaign_wrd2cat'] as $id => $w2cword) { $word = addslashes($_POST['campaign_wrd2cat'][$id]); $regex = $_POST['campaign_wrd2cat_regex'][$id] == 1 ? true : false; $cases = $_POST['campaign_wrd2cat_cases'][$id] == 1 ? true : false; $w2ccateg = $_POST['campaign_wrd2cat_category'][$id]; if (!empty($word)) { if (!isset($campaign_wrd2cat)) { $campaign_wrd2cat = array(); } $campaign_wrd2cat['word'][] = $word; $campaign_wrd2cat['regex'][] = $regex; $campaign_wrd2cat['cases'][] = $cases; $campaign_wrd2cat['w2ccateg'][] = $w2ccateg; } } } $campaign['campaign_wrd2cat'] = (array) $campaign_wrd2cat; // Proceso los feeds sacando los que estan en blanco if (isset($_POST['campaign_feeds'])) { foreach ($_POST['campaign_feeds'] as $k => $on) { $feedname = $_POST['campaign_feeds'][$k]; if (!empty($feedname)) { if (!isset($campaign_feeds)) { $campaign_feeds = array(); } $campaign_feeds[] = $feedname; } } } // Jamas llegaria aca si no hay feeds por el check ajax $campaign['campaign_feeds'] = (array) $campaign_feeds; // *** Campaign Options $campaign['campaign_max'] = (int) $_POST['campaign_max']; $campaign['campaign_author'] = $_POST['campaign_author']; $campaign['campaign_linktosource'] = $_POST['campaign_linktosource'] == 1 ? true : false; $campaign['campaign_strip_links'] = $_POST['campaign_strip_links'] == 1 ? true : false; $campaign['campaign_commentstatus'] = $_POST['campaign_commentstatus']; $campaign['campaign_allowpings'] = $_POST['campaign_allowpings'] == 1 ? true : false; $campaign['campaign_woutfilter'] = $_POST['campaign_woutfilter'] == 1 ? true : false; // *** Campaign Images $campaign['campaign_imgcache'] = $_POST['campaign_imgcache'] == 1 ? true : false; $campaign['campaign_cancel_imgcache'] = $_POST['campaign_cancel_imgcache'] == 1 ? true : false; if ($cfg['imgcache']) { if ($campaign['campaign_cancel_imgcache']) { $campaign['campaign_imgcache'] = false; } } else { if ($campaign['campaign_imgcache']) { $campaign['campaign_cancel_imgcache'] = false; } } $campaign['campaign_nolinkimg'] = $_POST['campaign_nolinkimg'] == 1 ? true : false; $campaign['campaign_solo1ra'] = $_POST['campaign_solo1ra'] == 1 ? true : false; // *** Campaign Template $campaign['campaign_enable_template'] = $_POST['campaign_enable_template'] == 1 ? true : false; if (isset($_POST['campaign_template'])) { $campaign['campaign_template'] = $_POST['campaign_template']; } else { $campaign['campaign_enable_template'] = false; $campaign['campaign_template'] = ''; } // *** Campaign Rewrites // Proceso los rewrites sacando los que estan en blanco if (isset($_POST['campaign_word_origin'])) { foreach ($_POST['campaign_word_origin'] as $id => $rewrite) { $origin = addslashes($_POST['campaign_word_origin'][$id]); $regex = $_POST['campaign_word_option_regex'][$id] == 1 ? true : false; $title = $_POST['campaign_word_option_title'][$id] == 1 ? true : false; $rewrite = addslashes($_POST['campaign_word_rewrite'][$id]); $relink = addslashes($_POST['campaign_word_relink'][$id]); if (!empty($origin)) { if (!isset($campaign_rewrites)) { $campaign_rewrites = array(); } $campaign_rewrites['origin'][] = $origin; $campaign_rewrites['regex'][] = $regex; $campaign_rewrites['title'][] = $title; $campaign_rewrites['rewrite'][] = $rewrite; $campaign_rewrites['relink'][] = $relink; } } } $campaign['campaign_rewrites'] = (array) $campaign_rewrites; //***** Call nonstatic if ($cfg['nonstatic']) { $campaign = NoNStatic::save_data($campaign, $_POST); } // check and correct all fields $campaign = self::check_campaigndata($campaign); error_reporting($nivelerror); // Grabo la campaña add_post_meta($post_id, 'campaign_data', $campaign, true) or update_post_meta($post_id, 'campaign_data', $campaign); return $post_id; }
private function fetch_end() { $this->campaign['lastrun'] = $this->campaign['starttime']; $this->campaign['lastruntime'] = current_time('timestamp') - $this->campaign['starttime']; $this->campaign['starttime'] = ''; $this->campaign['postscount'] += $this->fetched_posts; // Suma los posts procesados $this->campaign['lastpostscount'] = $this->fetched_posts; // posts procesados esta vez foreach ($this->campaign['campaign_feeds'] as $feed) { // Grabo el ultimo hash de cada feed @($this->campaign[$feed]['lasthash'] = $this->lasthash[$feed]); // paraa chequear duplicados por el hash del permalink original } if ($this->cfg['nonstatic']) { $this->campaign = NoNStatic::ending($this->campaign, $this->fetched_posts); } WPeMatico::update_campaign($this->campaign_id, $this->campaign); //Save Campaign new data trigger_error(sprintf(__('Campaign fetched in %1s sec.', WPeMatico::TEXTDOMAIN), $this->campaign['lastruntime']), E_USER_NOTICE); }
public static function save_campaigndata($post_id) { global $post, $cfg; //wp_die('save_campaigndata<br>DOING_AUTOSAVE:'.DOING_AUTOSAVE.'<br>DOING_AJAX:'.DOING_AJAX.'<br>$_REQUEST[bulk_edit]:'.$_REQUEST['bulk_edit']); if (defined('DOING_AJAX') && DOING_AJAX || isset($_REQUEST['bulk_edit']) || isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save') { WPeMatico_Campaigns::save_quick_edit_post($post_id); //wp_die('save_campaigndata<br>DOING_AUTOSAVE:'.DOING_AUTOSAVE.'<br>DOING_AJAX:'.DOING_AJAX.'<br>$_REQUEST[bulk_edit]:'.$_REQUEST['bulk_edit']); return $post_id; } //http://news.google.com.pe/news?pz=1&cf=all&ned=es_pe&hl=es&output=rss if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || defined('DOING_AJAX') && DOING_AJAX || isset($_REQUEST['bulk_edit'])) { return $post_id; } if (!wp_verify_nonce(@$_POST['wpematico_nonce'], 'edit-campaign')) { return $post_id; } if ($post->post_type != 'wpematico') { return $post_id; } $nivelerror = error_reporting(E_ERROR | E_WARNING | E_PARSE); //$cfg = get_option(WPeMatico :: OPTION_KEY); // $campaign['cron'] = WPeMatico :: cron_string($_POST); $campaign = WPeMatico::get_campaign($post_id); $_POST['postscount'] = !isset($campaign['postscount']) ? 0 : (int) $campaign['postscount']; $_POST['lastpostscount'] = !isset($campaign['lastpostscount']) ? 0 : (int) $campaign['lastpostscount']; $_POST['lastrun'] = !isset($campaign['lastrun']) ? 0 : (int) $campaign['lastrun']; $_POST['lastruntime'] = !isset($campaign['lastruntime']) ? 0 : (int) $campaign['lastruntime']; $campaign = array(); $campaign = apply_filters('wpematico_check_campaigndata', $_POST); //***** Call nonstatic // if( $cfg['nonstatic'] ) { $campaign = NoNStatic :: save_data($campaign, $_POST); } error_reporting($nivelerror); if (has_filter('wpematico_presave_campaign')) { $campaign = apply_filters('wpematico_presave_campaign', $campaign); } // Grabo la campaña WPeMatico::update_campaign($post_id, $campaign); return $post_id; }
/** * Filters images, upload and replace on text item content * @param $current_item array Current post data to be saved * @param $campaign array Current campaign data * @param $feed object Feed database object * @param $item object SimplePie_Item object */ function Item_images(&$current_item, &$campaign, &$feed, &$item) { if ($this->cfg['imgcache'] || $campaign['campaign_imgcache']) { $itemUrl = $this->getReadUrl($item->get_permalink()); if (sizeof($current_item['images'])) { // Si hay alguna imagen en el contenido trigger_error('<b>' . __('Uploading images.', WPeMatico::TEXTDOMAIN) . '</b>', E_USER_NOTICE); //trigger_error(print_r($current_item['images'],true),E_USER_NOTICE); $img_new_url = array(); foreach ($current_item['images'] as $imagen_src) { if ($this->campaign['campaign_cancel_imgcache']) { if ($this->cfg['gralnolinkimg'] || $this->campaign['campaign_nolinkimg']) { trigger_error(__('Deleted media src=', WPeMatico::TEXTDOMAIN) . $imagen_src, E_USER_WARNING); $current_item['content'] = str_replace($imagen_src, '', $current_item['content']); // Si no quiere linkar las img al server borro el link de la imagen } } else { trigger_error(__('Uploading media...', WPeMatico::TEXTDOMAIN) . $imagen_src, E_USER_NOTICE); $imagen_src_real = $this->getRelativeUrl($itemUrl, $imagen_src); $imagen_src_real = apply_filters('wpematico_img_src_url', $imagen_src_real); $allowed = isset($this->cfg['allowed']) && !empty($this->cfg['allowed']) ? $this->cfg['allowed'] : 'jpg,gif,png,tif,bmp,jpeg'; $allowed = apply_filters('wpematico_allowext', $allowed); //Fetch and Store the Image ///////////////***************************************************************************************//////////////////////// $newimgname = sanitize_file_name(urlencode(basename($imagen_src_real))); // Primero intento con mi funcion mas rapida $upload_dir = wp_upload_dir(); $imagen_dst = trailingslashit($upload_dir['path']) . $newimgname; $imagen_dst_url = trailingslashit($upload_dir['url']) . $newimgname; if (in_array(str_replace('.', '', strrchr(strtolower($imagen_dst), '.')), explode(',', $allowed))) { // -------- Controlo extensiones permitidas trigger_error('Uploading media=' . $imagen_src . ' <b>to</b> imagen_dst=' . $imagen_dst . '', E_USER_NOTICE); $newfile = $this->guarda_imagen($imagen_src_real, $imagen_dst); if ($newfile) { //subió trigger_error('Uploaded media=' . $newfile, E_USER_NOTICE); $imagen_dst = $newfile; $imagen_dst_url = trailingslashit($upload_dir['url']) . basename($newfile); $current_item['content'] = str_replace($imagen_src, $imagen_dst_url, $current_item['content']); $img_new_url[] = $imagen_dst_url; } else { // falló -> intento con otros $bits = WPeMatico::wpematico_get_contents($imagen_src_real); $mirror = wp_upload_bits($newimgname, NULL, $bits); if (!$mirror['error']) { trigger_error($mirror['url'], E_USER_NOTICE); $current_item['content'] = str_replace($imagen_src, $mirror['url'], $current_item['content']); $img_new_url[] = $mirror['url']; } else { trigger_error('wp_upload_bits error:' . print_r($mirror, true) . '.', E_USER_WARNING); // Si no quiere linkar las img al server borro el link de la imagen trigger_error(__('Upload file failed:', WPeMatico::TEXTDOMAIN) . $imagen_dst, E_USER_WARNING); if ($this->cfg['gralnolinkimg'] || $this->campaign['campaign_nolinkimg']) { trigger_error(__('Deleted media src.', WPeMatico::TEXTDOMAIN), E_USER_WARNING); $current_item['content'] = str_replace($imagen_src, '', $current_item['content']); } } } } else { trigger_error(__('Extension not allowed:', WPeMatico::TEXTDOMAIN) . $imagen_dst, E_USER_WARNING); if ($this->cfg['gralnolinkimg'] || $this->campaign['campaign_nolinkimg']) { // Si no quiere linkar las img al server borro el link de la imagen trigger_error(__('Stripped src.', WPeMatico::TEXTDOMAIN), E_USER_WARNING); $current_item['content'] = str_replace($imagen_src, '', $current_item['content']); } } } } $current_item['images'] = (array) $img_new_url; } // // Si hay alguna imagen en el contenido } return $current_item; }
static function wpem_cron_callback() { $args = array('post_type' => 'wpematico', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1); $campaigns = get_posts($args); foreach ($campaigns as $post) { $campaign = WPeMatico::get_campaign($post->ID); $activated = $campaign['activated']; $cronnextrun = $campaign['cronnextrun']; if (!$activated) { continue; } if ($cronnextrun <= current_time('timestamp')) { WPeMatico::wpematico_dojob($post->ID); } } }