function RecentImages_sub($ListImages, $slice, $offset, $i, $limit) { global $PTRevisited, $PTRLibrary; $attrList = array("src"); // Create a query object to retrieve posts $posts = get_posts('numberposts=' . $slice . '&offset=' . $offset); if (count($posts) < $slice) { $ListImages['endDB'] = true; } foreach ($posts as $post) { if ($i > $limit) { break; } setup_postdata($post); $content = apply_filters('the_content', get_the_content()); // Parse images $pattern = '/<img([^>]*)\\/>/si'; if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { // Skip wp smileys if (pt_stripos($match[0], 'class="wp-smiley"')) { continue; } if (pt_stripos($match[0], "class='wp-smiley'")) { continue; } if ($i > $limit) { break; } if (!$PTRLibrary->p_rel) { if (pt_stripos($match[0], 'rel="thumb"') === false && pt_stripos($match[0], "rel='thumb'") === false) { continue; } } else { if (pt_stripos($match[0], 'rel="nothumb"') !== false || pt_stripos($match[0], "rel='nothumb'") !== false) { continue; } } $m = str_replace(array("%", "|", "@", ")", "("), array("\\%", "\\|", "\\@", "\\)", "\\("), $match[0]); $pat = '%<a([^>]*).(jpg|jpeg|png|gif)([^>]*)\\>([^>]*)' . $m . '([^>]*)\\<\\/a>%si'; if (preg_match($pat, $content, $macgee)) { $ListAttr = pt_parseAtributes($macgee[0], array('href', 'title')); $ListImages['pic'][] = array($ListAttr['href'], $ListAttr['title']); $i++; unset($macgee); } else { $ListAttr = pt_parseAtributes($match[1], array('src', 'alt')); $ListImages['pic'][] = array($ListAttr['src'], $ListAttr['alt']); $i++; } } } } return $ListImages; }
function ReplaceLinks($content) { $attrList = array("src", "alt", "title", "align", "width", "height"); if (is_feed()) { return $content; } if (pt_stripos($content, 'rel="ptlink"') === false and pt_stripos($content, "rel='ptlink'") === false) { return $content; } $r_ID = rand(); // Replace thumbnail $pattern = '/<a(.*?)href=[\'|"](.*?)[\'|"](.*?)><img([^>]*)rel\\=[\'|"]ptlink[\'|"]([^>]*)\\/><\\/a>/i'; if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { $i = 1; foreach ($matches as $match) { $ListAttr = pt_parseAtributes($match[4] . $match[5], $attrList); $ListAttr['ext'] = substr(strrchr($ListAttr['src'], "."), 1); $ListAttr['img'] = substr($ListAttr['src'], 0, strlen($ListAttr['src']) - (strlen($ListAttr['ext']) + 1)); $ID = $r_ID . $i; $main_url = $match[2]; $thumb_url = $ListAttr['src']; if (POSTTHUMB_USE_HS) { if ($ListAttr['title'] == '') { $title = $ListAttr['title']; } else { $title = $ListAttr['alt']; } $h = new pt_highslide($main_url, $thumb_url, $title); $h->set_borders(get_pt_options('hsframe')); $h->set_href_text($match[8]); $h->set_bottom(__('Direct link to: ', 'post-thumb') . $title, $main_url); $h->set_size(get_pt_options('hs_width'), get_pt_options('hs_height'), get_pt_options('hsmargin')); $replacement = $h->highslide_link('iframe'); unset($h); } elseif (POSTTHUMB_USE_TB) { } $content = str_replace($match[0], $replacement, $content); $i++; } } return $content; }
function StorePostData($post) { global $wpdb; $p = new postThumb($post); $metaContent = $this->GetMetacontent($p->post_id); $post->post_content = $this->apply_filters($post->post_content); // Check metacontent if ($metaContent != '') { $pattern1 = '/youtube=\\((.*?)\\)(.*?)/i'; $pattern2 = '/MEDIA=([0-9]+%?)/i'; if (preg_match($pattern1, $metaContent, $match)) { $p->image = 'http://img.youtube.com/vi/' . $match[1] . '/0.jpg'; $p->media = $match[1]; } elseif (preg_match($pattern2, $metaContent, $match)) { $media = $wpdb->get_row("SELECT * FROM {$wpdb->wordtube} WHERE vid = {$match['1']} "); if ($media) { $p->image = htmlspecialchars(addslashes($media->image)); $p->media = htmlspecialchars(addslashes($media->file)); if (pt_is_flv($media->file)) { $p->vwidth = $media->width; $p->vheight = $media->height; } } } else { $p->image = $metaContent; } } // If no meta content detected if ($p->image == '') { // finds an image from the post content if (preg_match('@<img([^>]*)\\/>@si', $post->post_content, $matches)) { // put matches into recognizable vars $la = pt_parseAtributes($matches[0], array('src')); $p->image = $la['src']; // Prepare for RegEx $img_src = str_replace(array("%", "|", "@", ")", "("), array("\\%", "\\|", "\\@", "\\)", "\\("), $p->image); // detects if the image is already linked to a thumbnail $pattern = '%<a([^>]*).(jpg|jpeg|png|gif)([^>]*)\\>([^>]*)' . $img_src . '([^\\<]*)\\<\\/a>%si'; if (preg_match($pattern, $post->post_content, $matches)) { $la = pt_parseAtributes($matches[0], array('href')); $p->image = $la['href']; } // detects if the image is linked to an url $pattern = '%<a([^>]*)>([^>]*)' . $img_src . '([^<]*)\\<\\/a>%i'; if (preg_match($pattern, $post->post_content, $matches)) { $la = pt_parseAtributes($matches[0], array('href')); $p->image = $la['href']; } } // Search for wordTube MEDIA. Hope it won't change after that. Needs to be refreshed if it does. if ($this->settings['hs_wordtube'] == 'true') { $pattern = '/\\[MEDIA=([0-9]+%?)\\]/i'; if (preg_match($pattern, $post->post_content, $match)) { $media = $wpdb->get_row("SELECT * FROM {$wpdb->wordtube} WHERE vid = {$match['1']} "); if ($media) { $p->image = htmlspecialchars(addslashes($media->image)); $p->media = htmlspecialchars(addslashes($media->file)); if (pt_is_flv($media->file)) { $p->vwidth = $media->width; $p->vheight = $media->height; } } } } // Search for Youtube video. if ($this->settings['hs_youtube'] == 'true') { $pattern1 = '/\\[youtube=\\((.*?)\\)(.*?)\\]/i'; $pattern2 = '/\\<a(.*?)href="http:\\/\\/www\\.youtube\\.com\\/watch\\?v\\=(.*?)"(.*?)\\<\\/a>/i'; $pattern3 = '/\\<object([^>]*)>([^>]*)\\<param([^>]*)value=[\'|"]http:\\/\\/www.youtube.com\\/v\\/(.*?)[\'|"]\\>\\<\\/param>([^>]*)\\<param(.*?)\\<\\/object>/is'; if (preg_match($pattern1, $post->post_content, $match)) { $p->image = 'http://img.youtube.com/vi/' . $match[1] . '/0.jpg'; $p->media = $match[1]; } elseif (preg_match($pattern2, $post->post_content, $match)) { $p->image = 'http://img.youtube.com/vi/' . $match[2] . '/0.jpg'; $p->media = $match[2]; } elseif (preg_match($pattern3, $post->post_content, $match)) { $ytbID = explode('&', $match[4]); $p->image = 'http://img.youtube.com/vi/' . $ytbID[0] . '/0.jpg'; $p->media = $ytbID[0]; } } } if ($p->image != '') { // Retrieve categories. Again, this needs to be refreshed if categories change. $p->categories = $this->retrieveCategories($p->post_id); $this->savePost($p); } unset($p); }