/** * 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) { $cat_id = $this->getCampaignData($campaign->id, 'categories'); //$content_img = $this->wpo_get_post_image($cat_id[0]); //$content = '<img src="'.$content_img.'" alt="post_img" width="80" />'.$item->get_content(); $stuff = $item->get_content(); $images = WPOTools::parseImages($stuff); //echo '<pre>'; $thing = $item->get_enclosures(0); //print_r($thing); print_r($images); $limit = false; if ($limit) { $text = $this->string_limit_words(strip_tags($stuff), $this->get_feedmeta($feed - id, 'string_limit')); } else { $text = strip_tags($stuff); } if ('' == $text) { return 2; } $content = ''; // echo $item->get_title() . '<br /><pre>Images:<br />';print_r($images); if (sizeof($images[2]) > 0) { foreach ($images[2] as $img) { if (preg_match('/pheedo|feedburner|doubleclick|adnxs|openx/', $img)) { continue; } $tmp = getimagesize($img); if ($tmp[0] > 100 || $tmp[1] > 100) { //echo '<h1>'.$img.'</h1>'; $content .= '<img src="' . $img . '" alt="post_img" width="80" class="wpo-image" />'; $yes = true; break; } } } // echo '<br />Thing: <br />'; // print_r($thing); if (preg_match('/(jpg|png|gif)$/', $thing->link) && !$yes) { //print_r($thing); // echo " thing link "; $tmp = getimagesize($thing->link); if ($tmp[0] > 85 || $tmp[1] > 85) { $content .= '<img src="' . $thing->link . '" alt="post_img" width="80" class="sp-image" />'; $yes = true; } } if ($thing->thumbnails > 0 && !$yes) { //print_r($thing); // echo " thing thumb "; foreach ($thing->thumbnails as $link) { $tmp = getimagesize($link); if ($tmp[0] > 75 || $tmp[1] > 75) { $content .= '<img src="' . $link . '" alt="post_img" width="80" class="sp-thumb" />'; $yes = true; break; } } } if (!$yes) { //echo "default"; $img = $this->wpo_get_post_image($cat_id[0]); if ($img) { $content = '<img src="' . $img . '" alt="post_img" width="80" class="flick-image" />'; } } $content .= $text; // echo " content "; print_r($content); // echo '<pre>'; // die('bitch'); // Caching if (get_option('wpo_cacheimages') || $campaign->cacheimages) { $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']) ? '<a href="' . $rewrite['relink'] . '">' . $rewrite['rewrite'] . '</a>' : $rewrite['rewrite']; if ($rewrite['origin']['regex']) { $content = preg_replace($origin, $reword, $content); } else { $content = str_ireplace($origin, $reword, $content); } } elseif (isset($rewrite['relink'])) { $content = str_ireplace($origin, '<a href="' . $rewrite['relink'] . '">' . $origin . '</a>', $content); } } return $content; }
/** * 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) { $cat_id = $this->getCampaignData($campaign->id, 'categories'); //$content_img = $this->wpo_get_post_image($cat_id[0]); //$content = '<img src="'.$content_img.'" alt="post_img" width="80" />'.$item->get_content(); $images = WPOTools::parseImages($content); //echo '<pre>'; $thing = $item->get_enclosures(0); //print_r($thing); print_r($images); $text = $this->string_limit_words($item->get_content(), 300); if (sizeof($images[2]) > 0) { echo "tools"; $content = ''; $count = 0; foreach ($images[2] as $img) { $tmp = getimagesize($img); if ($tmp[0] < 100 || $tmp[1] < 100) { $img = $this->wpo_get_post_image($cat_id[0]); if ($img) { $content .= '<img src="' . $img . '" alt="post_img" width="80" />'; } break; } else { if ($count > 4) { $content .= '<img src"' . $img . '" alt="post_img" width="80" />'; break; } } $count++; } $content .= $text; } elseif (preg_match('/(jpg|png|gif)$/', $thing->link)) { //print_r($thing); //echo " thing link "; $content = ''; $tmp = getimagesize($thing->link); if ($tmp[0] < 75 || $tmp[1] < 75) { $img = $this->wpo_get_post_image($cat_id[0]); if ($img) { $content .= '<img src="' . $img . '" alt="post_img" width="80" />'; } } else { $content .= '<img src="' . $link . '" alt="post_img" width="80" />'; } $content .= $text; } elseif ($thing->thumbnails > 0 && isset($thing->thumbnails[0])) { //print_r($thing); echo " thing thumb "; $content = ''; // foreach ( $thing as $link ) { $tmp = getimagesize($thing->thumbnails[0]); if ($tmp[0] < 75 || $tmp[1] < 75) { $img = $this->wpo_get_post_image($cat_id[0]); if ($img) { $content .= '<img src="' . $img . '" alt="post_img" width="80" />'; } } else { $content .= '<img src="' . $link . '" alt="post_img" width="80" />'; } //} // } $content .= $text; } else { //echo "default"; $img = $this->wpo_get_post_image($cat_id[0]); if ($img) { $content = '<img src="' . $img . '" alt="post_img" width="80" />'; } $content .= $text; } //echo " content "; print_r($content); // echo '<pre>'; //die('bitch'); // Caching if (get_option('wpo_cacheimages') || $campaign->cacheimages) { $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']) ? '<a href="' . $rewrite['relink'] . '">' . $rewrite['rewrite'] . '</a>' : $rewrite['rewrite']; if ($rewrite['origin']['regex']) { $content = preg_replace($origin, $reword, $content); } else { $content = str_ireplace($origin, $reword, $content); } } elseif (isset($rewrite['relink'])) { $content = str_ireplace($origin, '<a href="' . $rewrite['relink'] . '">' . $origin . '</a>', $content); } } return $content; }
/** * 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']) ? '<a href="' . $rewrite['relink'] . '">' . $rewrite['rewrite'] . '</a>' : $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, '<a href="' . $rewrite['relink'] . '">' . $origin . '</a>', $content); } } } return $content; }