Ejemplo n.º 1
0
 public function __construct($campaign_id)
 {
     global $wpdb, $campaign_log_message, $jobwarnings, $joberrors;
     $jobwarnings = 0;
     $joberrors = 0;
     @ini_set('safe_mode', 'Off');
     //disable safe mode
     @ini_set('ignore_user_abort', 'Off');
     //Set PHP ini setting
     ignore_user_abort(true);
     //user can't abort script (close windows or so.)
     $this->campaign_id = $campaign_id;
     //set campaign id
     $this->campaign = WPeMatico::get_campaign($this->campaign_id);
     //$this->fetched_posts = $this->campaign['postscount'];
     $this->cfg = get_option(WPeMatico::OPTION_KEY);
     // new actions
     if ((int) $this->cfg['throttle'] > 0) {
         add_action('wpematico_inserted_post', array('WPeMatico', 'throttling_inserted_post'));
     }
     //set function for PHP user defined error handling
     if (defined('WP_DEBUG') and WP_DEBUG) {
         set_error_handler('wpematico_joberrorhandler', E_ALL | E_STRICT);
     } else {
         set_error_handler('wpematico_joberrorhandler', E_ALL & ~E_NOTICE);
     }
     //Set job start settings
     $this->campaign['starttime'] = current_time('timestamp');
     //set start time for job
     $this->campaign['cronnextrun'] = WPeMatico::time_cron_next($this->campaign['cron']);
     //set next run
     $this->campaign['lastpostscount'] = 0;
     // Lo pone en 0 y lo asigna al final
     WPeMatico::update_campaign($this->campaign_id, $this->campaign);
     //Save start time data
     if (has_action('Wpematico_init_fetching')) {
         do_action('Wpematico_init_fetching', $this->campaign);
     }
     //check max script execution tme
     if (ini_get('safe_mode') or strtolower(ini_get('safe_mode')) == 'on' or ini_get('safe_mode') == '1') {
         trigger_error(sprintf(__('PHP Safe Mode is on!!! Max exec time is %1$d sec.', WPeMatico::TEXTDOMAIN), ini_get('max_execution_time')), E_USER_WARNING);
     }
     // check function for memorylimit
     if (!function_exists('memory_get_usage')) {
         ini_set('memory_limit', apply_filters('admin_memory_limit', '256M'));
         //Wordpress default
         trigger_error(sprintf(__('Memory limit set to %1$s ,because can not use PHP: memory_get_usage() function to dynamically increase the Memory!', WPeMatico::TEXTDOMAIN), ini_get('memory_limit')), E_USER_WARNING);
     }
     //run job parts
     $postcount = 0;
     $this->feeds = $this->campaign['campaign_feeds'];
     // --- Obtengo los feeds de la campaña
     foreach ($this->feeds as $feed) {
         $postcount += $this->processFeed($feed);
         #- ---- Proceso todos los feeds
     }
     $this->fetched_posts += $postcount;
     $this->fetch_end();
     // if everything ok call fetch_end  and end class
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**	************ACCION CLEAR: ABORT CAMPAIGN	 	*/
 function wpematico_clear_campaign()
 {
     if (!(isset($_GET['post']) || isset($_POST['post']) || isset($_REQUEST['action']) && 'wpematico_clear_campaign' == $_REQUEST['action'])) {
         wp_die(__('No campaign ID has been supplied!', WPeMatico::TEXTDOMAIN));
     }
     // Get the original post
     $id = isset($_GET['post']) ? $_GET['post'] : $_POST['post'];
     $campaign_data = WPeMatico::get_campaign($id);
     $campaign_data['cronnextrun'] = WPeMatico::time_cron_next($campaign_data['cron']);
     //set next run
     $campaign_data['stoptime'] = current_time('timestamp');
     $campaign_data['lastrun'] = $campaign_data['starttime'];
     $campaign_data['lastruntime'] = $campaign_data['stoptime'] - $campaign_data['starttime'];
     $campaign_data['starttime'] = '';
     WPeMatico::update_campaign($id, $campaign_data);
     WPeMatico::add_wp_notice(array('text' => __('Campaign cleared', WPeMatico::TEXTDOMAIN) . ' <b>' . get_the_title($id) . '</b>', 'below-h2' => false));
     // Redirect to the post list screen
     wp_redirect(admin_url('edit.php?post_type=wpematico'));
 }
    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 
    }
 /**
  * save campaign data
  * Required @param   integer  $post_id    Campaign ID to load
  * 		  @param   boolean  $getfromdb  if set to true run get_post($post_ID) and retuirn object post
  * 
  * @return an array with campaign data 
  **/
 public static function update_campaign($post_id, $campaign = array())
 {
     $campaign['cronnextrun'] = (int) WPeMatico::time_cron_next($campaign['cron']);
     add_post_meta($post_id, 'postscount', $campaign['postscount'], true) or update_post_meta($post_id, 'postscount', $campaign['postscount']);
     add_post_meta($post_id, 'cronnextrun', $campaign['cronnextrun'], true) or update_post_meta($post_id, 'cronnextrun', $campaign['cronnextrun']);
     add_post_meta($post_id, 'lastrun', $campaign['lastrun'], true) or update_post_meta($post_id, 'lastrun', $campaign['lastrun']);
     return add_post_meta($post_id, 'campaign_data', $campaign, true) or update_post_meta($post_id, 'campaign_data', $campaign);
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 /**
   * save campaign data
   * Required @param   integer  $post_id    Campaign ID to load
   * 		  @param   boolean  $getfromdb  if set to true run get_post($post_ID) and retuirn object post
   * 
   * @return an array with campaign data 
   **/	
	public function update_campaign( $post_id , $campaign = array() ) {
		$campaign['cronnextrun']= WPeMatico :: time_cron_next($campaign['cron']);
		
			// *** Campaign Rewrites	
		// Proceso los rewrites agrego slashes	
		if (isset($campaign['campaign_rewrites']['origin']))
			for ($i = 0; $i < count($campaign['campaign_rewrites']['origin']); $i++) {
				$campaign['campaign_rewrites']['origin'][$i] = addslashes($campaign['campaign_rewrites']['origin'][$i]);
				$campaign['campaign_rewrites']['rewrite'][$i] = addslashes($campaign['campaign_rewrites']['rewrite'][$i]);
				$campaign['campaign_rewrites']['relink'][$i] = addslashes($campaign['campaign_rewrites']['relink'][$i]);
			}
		if (isset($campaign['campaign_wrd2cat']['word']))
			for ($i = 0; $i < count($campaign['campaign_wrd2cat']['word']); $i++) {
				$campaign['campaign_wrd2cat']['word'][$i] = addslashes($campaign['campaign_wrd2cat']['word'][$i]);
			}
				
		return add_post_meta( $post_id, 'campaign_data', $campaign, true )  or
          update_post_meta( $post_id, 'campaign_data', $campaign );
		  
	}