public function add_images_tags($the_content) { global $post; // php query class require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php'; $psp_meta = get_post_meta($post->ID, 'psp_meta', true); if (trim($the_content) != "") { $doc = pspphpQuery::newDocument($the_content); foreach (pspPQ('img') as $img) { // cache the img object $img = pspPQ($img); $url = $img->attr('src'); $image_name = ''; if (trim($url) != "") { $image_name = explode('.', end(explode('/', $url))); $image_name = $image_name[0]; } $alt = $img->attr('alt'); $title = $img->attr('title'); // setup the default settings $new_alt = isset($this->settings["image_alt"]) ? $this->settings["image_alt"] : ''; $new_title = isset($this->settings["image_title"]) ? $this->settings["image_title"] : ''; if (isset($this->settings['keep_default_alt']) && trim($this->settings['keep_default_alt']) != "") { $new_alt = $alt . ' ' . $new_alt; } if (isset($this->settings['keep_default_title']) && trim($this->settings['keep_default_title']) != "") { $new_title = $title . ' ' . $new_title; } // make the replacements foreach ($this->special_tags as $tag) { if ($tag == '{title}') { if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) { $new_alt = str_replace($tag, $post->post_title, $new_alt); } if (preg_match("/{$tag}/iu", $this->settings["image_title"])) { $new_title = str_replace($tag, $post->post_title, $new_title); } } elseif ($tag == '{image_name}') { if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) { $new_alt = str_replace($tag, $image_name, $new_alt); } if (preg_match("/{$tag}/iu", $this->settings["image_title"])) { $new_title = str_replace($tag, $image_name, $new_title); } } elseif ($tag == '{focus_keyword}' && isset($psp_meta['focus_keyword']) && trim($psp_meta['focus_keyword']) != "") { if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) { $new_alt = str_replace($tag, $psp_meta['focus_keyword'], $new_alt); } if (preg_match("/{$tag}/iu", $this->settings["image_title"])) { $new_title = str_replace($tag, $psp_meta['focus_keyword'], $new_title); } } elseif ($tag == '{nice_image_name}') { $image_name = preg_replace("/[^a-zA-Z0-9\\s]/", " ", $image_name); $image_name = preg_replace('/\\d{1,4}x\\d{1,4}/i', '', $image_name); if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) { $new_alt = str_replace($tag, $image_name, $new_alt); } if (preg_match("/{$tag}/iu", $this->settings["image_title"])) { $new_title = str_replace($tag, $image_name, $new_title); } } } // if the alt / title was changed if ($new_alt != $alt) { $img->attr('alt', trim($new_alt)); } if ($new_title != $title) { $img->attr('title', trim($new_title)); } } return do_shortcode($doc->html()); } else { return do_shortcode($the_content); } }
private function filter_item_video($content) { if (empty($this->video_include)) { return array(); } //$content = $this->strip_shortcode( $content ); // strip shortcodes! if (empty($content)) { return array(); } // validate content! // php query class require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php'; $doc = pspphpQuery::newDocument($content); $__founds = array(); // Video - wp shortcode! - treated in Just Plain Links! /*$regex_video = ' \[video(?:[^\]]+)? (http(?:s|v|vh|vp|a)?:\/\/(?:www\.)?[^\s"]+) \]\s*\[\/video\] '; $regex_video = '/'.$regex_video.'/ixum'; preg_match_all( $regex_video, $content, $wpvideos, PREG_SET_ORDER ); if ( !empty($wpvideos) ) { foreach ( $wpvideos as $match ) { if ( empty($match[1]) ) continue 1; $__founds[] = $match[1]; } }*/ // Embeds - wp shortcode! $regex_embeds = ' \\[embed(?:[^\\]]+)?\\] (http(?:s|v|vh|vp|a)?:\\/\\/(?:www\\.)?[^\\s"]+) \\[\\/embed\\] '; $regex_embeds = '/' . $regex_embeds . '/ixum'; preg_match_all($regex_embeds, $content, $embeds, PREG_SET_ORDER); if (!empty($embeds)) { foreach ($embeds as $match) { if (empty($match[1])) { continue 1; } $__founds[] = $match[1]; } } // Embeds - inside other objects! $embeds2 = $doc->find('embed'); foreach ($embeds2 as $tag) { $tag = pspPQ($tag); // cache the object // special cases! //if ( preg_match('/flickr\.com/iu', $tag->attr('src')) > 0 ) { // continue 1; //} $__founds[] = $tag->attr('src'); } // IFrames! $iframes = $doc->find('iframe'); foreach ($iframes as $tag) { $tag = pspPQ($tag); // cache the object $__founds[] = $tag->attr('src'); } // Objects! $objects = $doc->find('object'); foreach ($objects as $tag) { $tag = pspPQ($tag); // cache the object $tag = $tag->find('param'); $isSpecial = false; $specialVal = ''; foreach ($tag as $param) { $param = pspPQ($param); // cache the object if (in_array($param->attr('name'), array('src', 'movie'))) { // special cases! if (preg_match('/flickr\\.com/iu', $param->attr('value')) > 0) { $isSpecial = 'flickr.com'; //continue 1; } $__founds[] = $param->attr('value'); } if (in_array($param->attr('name'), array('flashvars'))) { if (preg_match('/photo_id=(\\d+)$/iu', $param->attr('value'), $flickrMatch) > 0) { $specialVal = $flickrMatch[1]; } } } if ($isSpecial !== false && !empty($specialVal)) { if ($isSpecial == 'flickr.com') { $__founds[] = "http://www.flickr.com/__flashvars__/{$specialVal}/"; } } } // Just Plain Links! $regex_links = ' \\s* (http(?:s|v|vh|vp|a)?:\\/\\/(?:www\\.)?[^\\s"]+) \\s* '; $regex_links = '/' . $regex_links . '/ixum'; preg_match_all($regex_links, $content, $links, PREG_SET_ORDER); if (!empty($links)) { foreach ($links as $match) { if (empty($match[1])) { continue 1; } $__founds[] = $match[1]; } } if (empty($__founds)) { return array(); } // validate founds! // clean duplicates! if (!empty($__founds)) { $__founds = array_values(array_unique($__founds)); } // allowed video providers $allowedVideoProviders = array(); if (is_array(self::$videoIdentifies) && !empty(self::$videoIdentifies)) { foreach (self::$videoIdentifies as $key => $val) { if (!in_array($key, (array) $this->video_include)) { continue 1; } $allowedVideoProviders["{$key}"] = $val; } } // go through found urls! $__images = array(); foreach ($__founds as $found) { $found = trim($found); if (preg_match('/^http/iu', $found) == 0) { $found = 'http:' . $found; } $parseUrl = parse_url($found); $host = $parseUrl['host']; if (!isset($host) || empty($host)) { continue 1; } if (is_array($allowedVideoProviders) && !empty($allowedVideoProviders)) { foreach ($allowedVideoProviders as $key => $val) { $pattern = '/' . $val['default'] . '/ixu'; //if ( $key != 'xyz' ) continue 1; if ($key == 'xyz') { //var_dump('<pre>', $pattern , '</pre>'); die('debug...'); } if (preg_match_all($pattern, $found, $matches, PREG_SET_ORDER)) { if ($key == 'xyz') { //var_dump('<pre>',$matches ,'</pre>'); } foreach ($matches as $match) { if ($key == 'localhost') { $__images["{$key}"][] = $found; continue 1; } if (empty($match[1])) { continue 1; } if ($key == 'blip' && in_array($match[1], array('api'))) { continue 1; } $__images["{$key}"][] = $match[1]; } } } // end foreach allowed providers! } } // end foreach main! // clean duplicates if (!empty($__images)) { foreach ($__images as $kk => $vv) { $__images["{$kk}"] = array_values(array_unique($__images["{$kk}"])); } } //var_dump('<pre>', $__images , '</pre>'); die('debug...'); return $__images; }