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

📄 collections_functions.php

📁 php网页设计
💻 PHP
📖 第 1 页 / 共 2 页
字号:
function get_themes($header)	{	# Return a list of themes under a given header (theme category).	return sql_query("select *,(select count(*) from collection_resource cr where cr.collection=c.ref) c from collection c  where c.theme='" . escape_check($header) . "' and c.public=1 order by c.name;");	}function get_smart_theme_headers()	{	# Returns a list of smart theme headers, which are basically fields with a 'smart theme name' set.	return sql_query("select ref,name,smart_theme_name from resource_type_field where length(smart_theme_name)>0 order by smart_theme_name");	}function get_smart_themes($field)	{	# Returns a list of smart themes (which are really field options).	# The results are filtered so that only field options that are in use are returned.		# Return raw options list	$options=explode(",",sql_value("select options value from resource_type_field where ref='$field'",""));		# Tidy list so it matches the storage format used for keywords.	# The translated version is fetched as each option will be indexed in the local language version of each option.	$options_base=array();	for ($n=0;$n<count($options);$n++) {$options_base[$n]=escape_check(trim(strtolower(i18n_get_translated($options[$n]))));}		# Return a list of keywords that are in use for this field	$inuse=sql_array("select distinct k.keyword value from keyword k join resource_keyword rk on k.ref=rk.keyword where 	resource_type_field='$field'");		# For each option, if it is in use, add it to the return list.	$return=array();	for ($n=0;$n<count($options);$n++)		{		#echo "<li>Looking for " . $options_base[$n] . " in " . join (",",$inuse);		if (in_array($options_base[$n],$inuse)) {$return[]=trim(i18n_get_translated($options[$n]));}		}	return $return;	}function email_collection($collection,$collectionname,$fromusername,$userlist,$message)	{	# Attempt to resolve all users in the string $userlist to user references.	# Add $collection to these user's 'My Collections' page	# Send them an e-mail linking to this collection	global $baseurl,$email_from,$applicationname,$lang;		if (trim($userlist)=="") {return ($lang["mustspecifyoneusername"]);}	$ulist=trim_array(explode(",",$userlist));	$emails=array();	$key_required=array();		for ($n=0;$n<count($ulist);$n++)		{		$uname=$ulist[$n];		$email=sql_value("select email value from user where username='" . escape_check($uname) . "'",'');		if ($email=='')			{			# Not a recognised user, if @ sign present, assume e-mail address specified			if (strpos($uname,"@")===false) {return($lang["couldnotmatchallusernames"]);}			$emails[$n]=$uname;			$key_required[$n]=true;			}		else			{			# Add e-mail address from user accunt			$emails[$n]=$email;			$key_required[$n]=false;			}		}	# Add the collection to the user's My Collections page	$urefs=sql_array("select ref value from user where username in ('" . join("','",$ulist) . "')");	if (count($urefs)>0) {sql_query("insert into user_collection(collection,user) values ($collection," . join("),(" . $collection . ",",$urefs) . ")");}			# Send an e-mail to each resolved user	$subject="$applicationname: $collectionname";	if ($message!="") {$message="\n\n" . $lang["message"] . ": " . str_replace(array("\\n","\\r","\\"),array("\n","\r",""),$message);}	for ($n=0;$n<count($emails);$n++)		{		$key="";		# Do we need to add an external access key for this user (e-mail specified rather than username)?		if ($key_required[$n])			{			$k=substr(md5(time()),0,10);			$r=get_collection_resources($collection);			for ($m=0;$m<count($r);$m++)				{				# Add the key to each resource in the collection				sql_query("insert into external_access_keys(resource,access_key) values ('" . $r[$m] . "','$k');");				}			$key="&k=". $k;			}		$body="$fromusername " . $lang["emailcollectionmessage"] . "$message\n\n" . $lang["clicklinkviewcollection"] . "\n\n" . $baseurl . 	"/?c=" . $collection . $key;		send_mail($emails[$n],$subject,$body);		}			# Return an empty string (all OK).	return "";	}function get_saved_searches($collection)	{	return sql_query("select * from collection_savedsearch where collection='$collection' order by created");	}function add_saved_search($collection)	{	sql_query("insert into collection_savedsearch(collection,search,restypes,archive) values ('$collection','" . getvalescaped("addsearch","") . "','" . getvalescaped("restypes","") . "','" . getvalescaped("archive","") . "')");	}function remove_saved_search($collection,$search)	{	sql_query("delete from collection_savedsearch where collection='$collection' and ref='$search'");	}function add_saved_search_items($collection)	{	$results=do_search(getvalescaped("addsearch",""), getvalescaped("restypes",""), "relevance", getvalescaped("archive",""));	for ($n=0;$n<count($results);$n++)		{		$resource=$results[$n]["ref"];		sql_query("delete from collection_resource where resource='$resource' and collection='$collection'");		sql_query("insert into collection_resource(resource,collection) values ('$resource','$collection')"); 		}	}function allow_multi_edit($collection)	{	# Returns true or false, can this collection be edited as a multi-edit?	# All the resources must be of the same type and status for this to work.		# Updated: 2008-01-21: Edit all now supports multiple types, so always return true.	return (true);		/*	$types=sql_query("select distinct r.resource_type from collection_resource c left join resource r on c.resource=r.ref where c.collection='$collection'");	if (count($types)!=1) {return false;}		$status=sql_query("select distinct r.archive from collection_resource c left join resource r on c.resource=r.ref where c.collection='$collection'");	if (count($status)!=1) {return false;}			return true;	*/	}function get_theme_image($theme)	{	$image=sql_value("select r.ref value from collection c join collection_resource cr on c.ref=cr.collection join resource r on cr.resource=r.ref where c.theme='" . escape_check($theme) . "' and r.has_image=1 order by r.hit_count desc limit 1",0);	if ($image==0) {return false;} else {return get_resource_path($image,"col",false);}	}function swap_collection_order($resource1,$resource2,$collection)	{	# Swaps the position of two resources within a collection.	$pos1=sql_value("select date_added value from collection_resource where collection='$collection' and resource='$resource1'",0);	$pos2=sql_value("select date_added value from collection_resource where collection='$collection' and resource='$resource2'",0);	sql_query("update collection_resource set date_added='$pos2' where resource='$resource1' and collection='$collection'");	sql_query("update collection_resource set date_added='$pos1' where resource='$resource2' and collection='$collection'");	}function get_collection_resource_comment($resource,$collection)	{	$data=sql_query("select * from collection_resource where collection='$collection' and resource='$resource'","");	return $data[0];	}	function save_collection_resource_comment($resource,$collection,$comment,$rating)	{	sql_query("update collection_resource set comment='$comment',rating='$rating' where resource='$resource' and collection='$collection'");	return true;	}function relate_to_collection($ref,$collection)		{	# Relates every resource in $collection to $ref		$colresources = get_collection_resources($collection);		sql_query("delete from resource_related where resource='$ref' and related in ('" . join("','",$colresources) . "')");  		sql_query("insert into resource_related(resource,related) values ($ref," . join("),(" . $ref . ",",$colresources) . ")");	}		function get_mycollection_name($userref)	{	# Fetches the next name for a new My Collection for the given user (My Collection 1, 2 etc.)	global $lang;	for ($n=2;$n<500;$n++)		{		$name=$lang["mycollection"] . " " . $n;		$ref=sql_value("select ref value from collection where user='$userref' and name='$name'",0);		if ($ref==0)			{			# No match!			return $name;			}		}	# Tried nearly 500 names(!) so just return a standard name 	return $lang["mycollection"];	}?>

⌨️ 快捷键说明

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