Location: PHPKode > projects > Tagging manager > version 1.02/includes/functions.php
<?php
/*  ============================================================
 *                              functions.php 
 *                              -------------------
 *     Date                 : 26 june 2006
 *     E-mail               : hide@address.com
 *
 *     Version              : 1.0 (26/06/2006 - 13:35)
 *
 *     This a free software 
 *     licensed under GPL (General public license)
 *
    ============================================================ */
/**
 * The main functions: changequery, to get a metaid-list, to get a taglist
 *
 * @version      1.0.0
 */
  
/**
 * Edit the Query portion of an url
 *
 * @param    string    $action    ethier a "+" or a "-" depending on what action you want to perform
 * @param    mixed    $var    array (+) or string (-)
 * @param    string    $uri    the URL to use. if this is left out, it uses $_SERVER['PHP_SELF']
 * @version      1.0.0
 */
function ChangeQuery($action, $var = NULL, $uri = NULL) {

       if (($action == "+" && ! is_array($var))
             ||
           ($action == "-" && $var == "")
             ||
           $var == NULL)
               return FALSE;

   if (is_null($uri)) {//Piece together uri string
       $beginning = $_SERVER['PHP_SELF'];
       $ending = ( isset($_SERVER['QUERY_STRING']) ) ? $_SERVER['QUERY_STRING'] : '';
   } else {
       $qstart = strpos($uri, '?');
       if ($qstart === false) {
           $beginning = $uri; //$ending is '' anyway
       } else {
           $beginning = substr($uri, 0, $qstart);
           $ending = substr($uri, $qstart);
       }
   }

   if (strlen($ending) > 0) {
       $vals = array();
       $ending = str_replace('?','', $ending);
       parse_str($ending, $vals);
               if ($action == "+")
                       $vals[$var[0]] = $var[1];
       $ending = '';
       $count = 0;
       foreach($vals as $k => $v) {
           if ($action == "-" && $k == $var) continue;
           if ($count > 0) { $ending .= '&'; }
           else { $count++; }
           $ending .= "$k=" . urlencode($v);
       }
   } else {
           $ending = $varName . '=' . urlencode($varVal);
   }

   $result = $beginning . '?' . $ending;

   return $result;
}

/**
 * Get a list of id's for the metadata
 *
 * @param    string   $str    		a WHERE search querie part
 * @param    number   $paging 		the start number of results
 * @param    number   $paglimit 	maximum amount of results per page (in config.php)
 * @version      1.0.0
 */
function urlIDs($str=null,$paging=0,$paglimit=30)
	{
		
		$idlist = array();
		$search = "SELECT DISTINCT tm_metadata.meta_id FROM `tm_metadata` 
												INNER JOIN tm_tags_metadata ON tm_tags_metadata.meta_id = tm_metadata.meta_id
                        INNER JOIN tm_tags ON tm_tags_metadata.tag_id = tm_tags.tag_id
                        INNER JOIN tm_taxonomy ON tm_metadata.taxonomy_id = tm_taxonomy.taxonomy_id
                        INNER JOIN tm_users ON tm_metadata.user_id = tm_users.user_id
                        $str ORDER BY `meta_id` DESC LIMIT $paging,$paglimit ";             
    //echo $search;       
    $i = new iter($search);                       
    while ($tags = $i->fetch()) {
		$idlist[]= $tags;
		}
		return $idlist;
	}

/**
 * Get a list of tags for a certain metaid
 *
 * @param    number   $meta_id 		the id where you want to get the tags from
 * @version      1.0.0
 */
function tagList($meta_id=null)
	{
		$taglist = array();
		if ($meta_id) {
		$i = new iter("SELECT * FROM `tm_tags`
                        INNER JOIN tm_tags_metadata ON tm_tags_metadata.tag_id = tm_tags.tag_id
                        WHERE tm_tags_metadata.meta_id = '$meta_id'"); 
                   
    while ($tags = $i->fetch()) {
		$tag_name = $tags->tag_name;
		$taglist[]= $tag_name;
		}
		$taglist = array_unique($taglist);
		}
		return $taglist;
}



?>
Return current item: Tagging manager