/** * 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']) { $images = $this->parseImages($current_item['content']); $current_item['images'] = $images[2]; //lista de url de imagenes $itemUrl = $this->getReadUrl($item->get_permalink()); if( $this->cfg['nonstatic'] ) { $current_item['images'] = NoNStatic :: imgfind($current_item,$campaign,$item ); } if( sizeof($current_item['images']) ) { // Si hay alguna imagen en el contenido trigger_error(__('Uploading images.', WPeMatico :: TEXTDOMAIN ),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) { trigger_error(__('Uploading image...', WPeMatico :: TEXTDOMAIN ).$imagen_src,E_USER_NOTICE); if($this->campaign['campaign_cancel_imgcache']) { if($this->cfg['gralnolinkimg'] || $this->campaign['campaign_nolinkimg']) $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 { //$imagen_src = str_replace('_s.','_n.', $imagen_src); //Trae la imagen grande en vez del thumb $imagen_src_real = $this->getRelativeUrl($itemUrl, $imagen_src); $bits = @file_get_contents($imagen_src_real); $name = str_replace(array(' ','%20'),'_',substr(strrchr($imagen_src, "/"),1)); $afile = wp_upload_bits( $name, NULL, $bits); if(!$afile['error']) { trigger_error($afile['url'],E_USER_NOTICE); $current_item['content'] = str_replace($imagen_src, $afile['url'], $current_item['content']); $img_new_url[] = $afile['url']; } else { // Si no la pudo subir intento con mi funcion trigger_error('wp_upload_bits error:'.print_r($afile,true).', trying custom function.',E_USER_WARNING); $upload_dir = wp_upload_dir(); $imagen_dst = $upload_dir['path'] . str_replace('/','',strrchr($imagen_src, '/')); $imagen_dst_url = $upload_dir['url']. '/' . str_replace('/','',strrchr($imagen_src, '/')); if(in_array(str_replace('.','',strrchr($imagen_dst, '.')),explode(',','jpg,gif,png,tif,bmp'))) { // -------- Controlo extensiones permitidas trigger_error('imagen_src='.$imagen_src.' <b>to</b> imagen_dst='.$imagen_dst.'<br>',E_USER_NOTICE); $newfile = $this->guarda_imagen($imagen_src_real, $imagen_dst); if($newfile) { $current_item['content'] = str_replace($imagen_src, $imagen_dst_url, $current_item['content']); $img_new_url[] = $imagen_dst_url; } else { if($this->cfg['gralnolinkimg'] || $this->campaign['campaign_nolinkimg']) $current_item['content'] = str_replace($imagen_src, '', $current_item['content']); // Si no quiere linkar las img al server borro el link de la imagen trigger_error('Upload file failed:'.$imagen_dst,E_USER_WARNING); } }else { trigger_error('Extension not allowed:'.$imagen_dst,E_USER_WARNING); } } } } $current_item['images'] = (array)$img_new_url; } // // Si hay alguna imagen en el contenido } return $current_item; } // item images
public static function tags_box($post) { global $post, $campaign_data, $cfg; $campaign_tags = @$campaign_data['campaign_tags']; ?> <?php if ($cfg['nonstatic']) { NoNStatic::protags($post); } ?> <p><b><?php echo '<label for="campaign_tags">' . __('Tags:', WPeMatico::TEXTDOMAIN) . '</label>'; ?> </b> <textarea style="" class="large-text" id="campaign_tags" name="campaign_tags"><?php echo stripslashes($campaign_tags); ?> </textarea><br /> <?php echo __('Enter comma separated list of Tags.', WPeMatico::TEXTDOMAIN); ?> </p> <?php if ($cfg['nonstatic']) { NoNStatic::protags1($post); } ?> <?php }
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 CheckFields() { // check required fields values before save post $cfg = get_option(WPeMatico::OPTION_KEY); $err_message = ""; //$post_data = $_POST; if (isset($_POST['campaign_wrd2cat'])) { $wrd2cat = array(); parse_str($_POST['campaign_wrd2cat'], $wrd2cat); $campaign_wrd2cat = @$wrd2cat['campaign_wrd2cat']; for ($id = 0; $id < count($campaign_wrd2cat); $id++) { $word = $campaign_wrd2cat['word'][$id]; $regex = $_POST['campaign_wrd2cat_regex'][$id] == 1 ? true : false; if (!empty($word)) { if ($regex) { if (false === @preg_match($word, '')) { $err_message = $err_message != "" ? $err_message . "<br />" : ""; $err_message .= sprintf(__('There\'s an error with the supplied RegEx expression in word: %s', WPeMatico::TEXTDOMAIN), '<span class="coderr">' . $word . '</span>'); } } } } } if (isset($_POST['campaign_word_origin'])) { $rewrites = array(); parse_str($_POST['campaign_word_origin'], $rewrites); $campaign_word_origin = @$rewrites['campaign_word_origin']; for ($id = 0; $id < count($campaign_word_origin); $id++) { $origin = $campaign_word_origin[$id]; $regex = $_POST['campaign_word_option_regex'][$id] == 1 ? true : false; if (!empty($origin)) { if ($regex) { if (false === @preg_match($origin, '')) { $err_message = $err_message != "" ? $err_message . "<br />" : ""; $err_message .= sprintf(__('There\'s an error with the supplied RegEx expression in ReWrite: %s', WPeMatico::TEXTDOMAIN), '<span class="coderr">' . $origin . '</span>'); } } } } } if (!isset($cfg['disablecheckfeeds']) || !$cfg['disablecheckfeeds']) { // Si no esta desactivado en settings // Si no hay ningun feed devuelve mensaje de error // Proceso los feeds sacando los que estan en blanco if (isset($_POST['campaign_feeds'])) { $feeds = array(); parse_str($_POST['campaign_feeds'], $feeds); $all_feeds = $feeds['campaign_feeds']; for ($id = 0; $id < count($all_feeds); $id++) { $feedname = $all_feeds[$id]; if (!empty($feedname)) { if (!isset($campaign_feeds)) { $campaign_feeds = array(); } $campaign_feeds[] = $feedname; } } } if (empty($campaign_feeds) || !isset($campaign_feeds)) { $err_message = $err_message != "" ? $err_message . "<br />" : ""; $err_message .= __('At least one feed URL must be filled.', WPeMatico::TEXTDOMAIN); } else { foreach ($campaign_feeds as $feed) { $pos = strpos($feed, ' '); // el feed no puede tener espacios en el medio if ($pos === false) { $simplepie = WPeMatico::fetchFeed($feed, true); if ($simplepie->error()) { $err_message = $err_message != "" ? $err_message . "<br />" : ""; $err_message .= sprintf(__('Feed %s could not be parsed. (SimplePie said: %s)', WPeMatico::TEXTDOMAIN), '<strong class="coderr">' . $feed . '</strong>', $simplepie->error()); } } else { $err_message = $err_message != "" ? $err_message . "<br />" : ""; $err_message .= sprintf(__('Feed %s could not be parsed because has an space in url.', WPeMatico::TEXTDOMAIN), '<strong class="coderr">' . $feed . '</strong>'); } } } } if ($cfg['nonstatic']) { $err_message = NoNStatic::Checkp($_POST, $err_message); } if ($err_message == "") { $err_message = "1"; } //NO ERROR die($err_message); // Return 1 si OK, else -> error string }
/** * 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 $item object SimplePie_Item object */ function Get_Item_images($current_item, $campaign, $feed, $item) { if ($this->cfg['imgcache'] || $campaign['campaign_imgcache']) { $images = $this->parseImages($current_item['content']); $current_item['images'] = $images[2]; //lista de url de imagenes if ($this->cfg['nonstatic']) { $current_item['images'] = NoNStatic::imgfind($current_item, $campaign, $item); } $current_item['images'] = array_values(array_unique($current_item['images'])); //$current_item['images'] = array_map('urldecode', $current_item['images'] ); } return $current_item; }