⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flickr.php

📁 php 开发的内容管理系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/*
Plugin Name: .[XPress] Tags and Images
Plugin URI: http://xoopsforge.com/
Description: This plugin provides the XOOPS Tag input API as well as integration with Technorati tags and related Flickr images, to display related images to your post; Cache is enabled. Originated <a href="http://www.broobles.com/scripts/simpletags/">"SimpleTags" by Broobles</a> and <a href="http://ppleyard.org.uk/archives/2005/02/10/flickr-wordpress-plugin-release.html">"Flickr Related Images" by David Appleyard</a>
Version: 1.0
Author: D.J. (phppp)
Author URI: http://xoopsforge.com

 */
 
/*
Plugin Name: Flickr Images
Plugin URI: http://ppleyard.org.uk/archives/2005/02/10/flickr-wordpress-plugin-release.html
Description: This plugin provides integration with Flickr images, to find related images to your post
Version: 1.0
Author: David Appleyard
Author URI: http://davidappleyard.org.uk

For Installation Instructions, please visit:
http://ppleyard.org.uk/archives/2005/02/10/flickr-wordpress-plugin-release.html

 */

// Options 
$GLOBALS['flickr_maxheight'] = @get_option('flickr_maxheight');
// No optioins set
if(empty($GLOBALS['flickr_maxheight'])){ 
	$GLOBALS['flickr_cache'] = 60*60*24; // cache time: 24 hours
	$GLOBALS['flickr_maxrows'] = 2; // Maximum rows to display; 0 for no limit
	$GLOBALS['flickr_maxcols'] = 3; // images per row
	$GLOBALS['flickr_maxheight']=100; // in px
	$GLOBALS['flickr_maxwidth']=120; // in px
	$GLOBALS['flickr_display']=true;
	$GLOBALS['wptag_display']=true;
}else{
	$GLOBALS['flickr_cache'] = get_option('flickr_cache');
	$GLOBALS['flickr_maxrows'] = get_option('flickr_maxrows');
	$GLOBALS['flickr_maxcols'] = get_option('flickr_maxcols');
	$GLOBALS['flickr_maxwidth'] = get_option('flickr_maxwidth');
	$GLOBALS['flickr_display'] = get_option('flickr_display');
	$GLOBALS['wptag_display'] = get_option('wptag_display');
	/*
    $GLOBALS['wptag_url'] = get_option('wptag_url');
    $GLOBALS['wptag_title'] = get_option('wptag_title');
    $GLOBALS['wptag_tagpattern'] = get_option('wptag_tagpattern');
    $GLOBALS['wptag_tagspattern'] = get_option('wptag_tagspattern');
    */
}
$GLOBALS['wptag_url'] = "<a href='http://technorati.com/tag/%s' rel='tag' target='techno'>%s</a>";
//$GLOBALS['wptag_title'] = 'Technorati tags';
$GLOBALS['wptag_title'] = '<a href="http://technorati.com/tag/xoops" rel="tag"  title="Technorati tags" target="techno"><img src="'.XOOPS_URL.'/modules/wordpress/images/techno.gif" alt="Technorati tags" /></a>';
$GLOBALS['wptag_tagpattern'] = '/(<tag>(.*?)<\/tag>)/i';
$GLOBALS['wptag_tagspattern'] = '/(<tags>(.*?)<\/tags>)/i';


function flickr_fetchContent($url)
{
    if($data = flickr_fetchCURL($url)) {
	    return $data;
    }
    if($data = flickr_fetchSnoopy($url)) {
	    return $data;
    }
    $data = flickr_fetchFopen($url); 
    return $data;
}

function flickr_fetchSnoopy($url)
{
	include_once XOOPS_ROOT_PATH."/class/snoopy.php";
	$snoopy = new Snoopy;
	$data = "";
	if (@$snoopy->fetch($url)){
    	$data = (is_array($snoopy->results))?implode("\n",$snoopy->results):$snoopy->results;
	}
	return $data;
}

function flickr_fetchCURL($url)
{
    if (!function_exists('curl_init') ) return false;
    $ch = curl_init();    // initialize curl handle
    curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s
    $data = curl_exec($ch); // run the whole process
    curl_close($ch);
	return $data;
}

function flickr_fetchFopen($url)
{
	if(!$fp = @fopen ($url, 'r')) return false;
    $data = "";
    while (!feof($fp)) {
        $data .= fgets ($fp, 1024);
    }
    fclose($fp);
	return $data;
}

function &flickr_get_items($thepostid)
{
	require_once (ABSPATH . WPINC . '/rss-functions.php');
	
	$flickr_items = array();
    $tags = $GLOBALS['flickr_tags'];
	
    if(!is_array($tags) || count($tags)==0) return array();
    $rows = 0;
	foreach($tags as $tag){

		$feed = "http://flickr.com/services/feeds/photos_public.gne?tags=".urlencode(encoding_wp2rss($tag))."&format=rss_200";
		$rss = @fetch_rss($feed);
		if(empty($rss)) continue;
		$items = array();
		foreach($rss->items as $_item){
			if(preg_match("/\<img[\s]*src=\"(.*)\"[\s]+width=\"([0-9]+)[^0-9]*\"[\s]+height=\"([0-9]+)[^0-9]*\"[\s]+alt=\"(.*)\"/Ui", $_item['description'], $args)){
				$item["src"] = $args[1]; 
				$item["width"] = $args[2]; 
				$item["height"] = $args[3]; 
				$item["alt"] = $args[4];
			}else{
				continue;
			}
			$item['title'] = $_item['title'];
			$item['link'] = $_item['link'];
			$items[] = $item;
			unset($item);
		}
		unset($rss);
		
		if(count($items)){
			$keys =& flickr_rand_array(0, count($items)-1, $GLOBALS['flickr_maxcols']); 
			foreach($keys as $key){
				$_item =& $items[$key];
				if($_item["width"]>$GLOBALS['flickr_maxwidth']){
					$_item["height"] = $_item["height"] * ($GLOBALS['flickr_maxwidth']/$_item["width"]);
					$_item["width"] = $GLOBALS['flickr_maxwidth'];
				}
				if($_item["height"]>$GLOBALS['flickr_maxheight']){
					$_item["width"] = $_item["width"] * ($GLOBALS['flickr_maxheight']/$_item["height"]);
					$_item["height"] = $GLOBALS['flickr_maxheight'];
				}
				$title = $tag.": ".(empty($_item["title"])?$_item["alt"]:$_item["title"]);
				$title = encoding_rss2wp($title);
				$title = htmlspecialchars($title, ENT_QUOTES);
				$flickr_items[] ="<a href=\"".$_item["link"]."\" title=\"".$title."\" target=\"techno\"><img src=\"".$_item["src"]."\" alt=\"".$title."\" width=\"".intval($_item["width"])."px\" height=\"".intval($_item["height"])."px\" /></a>";
			}
			$rows ++;
		}
		
		if ( $GLOBALS['flickr_maxrows']>0 && $GLOBALS['flickr_maxrows'] <= $rows ) {
			break;
		}
	}

	return $flickr_items;
}

// from http://php.net/manual/en/function.rand.php
function &flickr_rand_array($min,$max,$num) {
	$ret = array();
	while (count($ret) < min($num, $max-$min+1)) {
		do {
			$a = rand($min,$max);
		}while (in_array($a,$ret));
		$ret[] = $a;
	}
	return($ret);
}

function flickr_clear_cache($thepostid = null){
	if(!empty($thepostid)){
		if(file_exists(XOOPS_CACHE_PATH."/wordpress.flickr.".$thepostid.".php")){
			unlink(XOOPS_CACHE_PATH."/wordpress.flickr.".$thepostid.".php");
			return;
		}
	}
	require_once(XOOPS_ROOT_PATH."/class/xoopslists.php");
	$files =& XoopsLists::getFileListAsArray(XOOPS_CACHE_PATH);
	foreach($files as $file => $name){
		if(preg_match("/^wordpress\.flickr\.[0-9]+\.php$/i", $name, $matches)){
			unlink(XOOPS_CACHE_PATH."/".$name);
		}
	}
	return true;
}

function flickr_get_cache($thepostid){
	$file_flickr = XOOPS_CACHE_PATH."/wordpress.flickr.".$thepostid.".php";
	$flickr_items = array();
	if(@include($file_flickr)){
		if(time() - $flickr["cache"] < $GLOBALS['flickr_cache']){
			$flickr_items = unserialize($flickr["items"]);
			$flickr_items = array_map("base64_decode", $flickr_items);
			return count($flickr_items)? $flickr_items : null;
		}
	}
	return $flickr_items;
}

function flickr_set_cache($thepostid, $flickr_items){
	$file_flickr = XOOPS_CACHE_PATH."/wordpress.flickr.".$thepostid.".php";
	if(!$fp = fopen($file_flickr,"w")) {
		return false;
	}
	$file_content = "<?php\n";
	$file_content .= "\t\$flickr[\"cache\"] = '".time()."';\n";
	$file_content .= "\t\$flickr[\"items\"] = '".serialize(array_map("base64_encode",$flickr_items))."';\n";
	$file_content .= "\treturn \$flickr;\n";
	$file_content .= "?>";
    fputs($fp, $file_content);
    fclose($fp);
    return true;
}

function flickr_update(){
	if(empty($_GET['update']) || empty($_GET['p'])) return;
	return flickr_clear_cache(empty($_GET['p']));
}

function flickrrelated($thepostid) {
	$thepostid = intval($thepostid);
	if(empty($thepostid)) return false;
    
    if(isset($GLOBALS['flickr_display']) && empty($GLOBALS['flickr_display'])){
	    return true;
    }

	$flickr_items = flickr_get_cache($thepostid);
	if($flickr_items === null) return false;
	if(count($flickr_items) == 0){
		$flickr_items = flickr_get_items($thepostid);
		flickr_set_cache($thepostid, $flickr_items);
	}
	if(count($flickr_items) ==0) return false;
  

	$QUERY_STRING_array=explode("&",xoops_getenv('QUERY_STRING'));
	$QUERY_STRING_new="";
	foreach ($QUERY_STRING_array as $QUERY){
		if(!empty($QUERY) && substr($QUERY,0, 7)!="update=") $QUERY_STRING_new .=$QUERY."&";
	}
	$QUERY_STRING_new = htmlSpecialChars($QUERY_STRING_new);

	$output = '<div class="flickr"><h3><a href="'.xoops_getenv('PHP_SELF')."?".$QUERY_STRING_new.'&amp;update=1" title="Click to refresh">Flickr Images</a></h3></div>'.
	'<table cellpadding="3"><tr>';
	$count = 0;
	foreach($flickr_items as $item){
		if($count >0 && ($count % $GLOBALS['flickr_maxcols'] == 0)){
			$output .="</tr><tr>";
		}
		$output .="<td>".$item."</td>";
		$count ++;
	}
	$output .='</tr></table><br />';
	
	echo $output;	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -