Code: Select all
        function GetDefaultContent()
	{
		global $gCms;
		$db = &$gCms->db;
		$result = -1;
		$query = "SELECT content_id FROM ".cms_db_prefix()."content WHERE default_content = 1";
		$row = $db->GetRow($query);
		if ($row)
		{
			$result = $row['content_id'];
		}
		else
		{
			#Just get something...
			$query = "SELECT content_id FROM ".cms_db_prefix()."content";
			$row = $db->GetRow($query);
			if ($row)
			{
				$result = $row['content_id'];
			}
		}
		return $result;
	}
	// function to get the id of the default page
	function GetDefaultPageID()
	{
	  global $gCms;
	  $db = &$gCms->db;
	  $query = "SELECT * FROM ".cms_db_prefix()."content WHERE default_content = ?";
	  $row = $db->GetRow($query, array(1));
	  if ( !$row ) return false;
	  return $row['content_id'];
	}
	// function to map an alias to a page id
	// returns false if nothing cound be found.
	function GetPageIDFromAlias( $alias )
	{
	  global $gCms;
	  $db = &$gCms->db;
	  if (is_numeric($alias) && strpos($alias,'.') == FALSE && strpos($alias,',') == FALSE)
	    {
	      return $alias;
	    }
	  $params = array($alias);
	  $query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_alias = ?";
	  $row = $db->GetRow($query, $params);
	  if ( !$row)return false;
	  return $row['content_id'];
	}
	
	// function to map an alias to a page id
	// returns false if nothing cound be found.
	function GetPageAliasFromID( $id )
	{
	  global $gCms;
	  $db = &$gCms->db;
	  if (!is_numeric($alias) && strpos($alias,'.') == TRUE && strpos($alias,',') == TRUE)
	    {
	      return $id;
	    }
	  $params = array($id);
	  $query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_id = ?";
	  $row = $db->GetRow($query, $params);
	  if ( !$row)return false;
	  return $row['content_alias'];
	}
        	function CheckAliasError($alias, $content_id = -1)
	{
		global $gCms;
		$db = &$gCms->db;
		$error = FALSE;
		if (preg_match('/^\d+$/', $alias))
		{
			$error = lang('aliasnotaninteger');
		}
		else if (!preg_match('/^[\-\_\w]+$/', $alias))
		{
			$error = lang('aliasmustbelettersandnumbers');
		}
		else
		{
			$params = array($alias);
			$query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_alias = ?";
			if ($content_id > -1)
			{
				$query = " AND content_id != ?";
				array_push($params, $content_id);
			}
			$dbresult = $db->GetRow($query, $params);
			if ($dbresult) $error = lang('aliasalreadyused');
		}
		return $error;
	}
If i use admin listcontents with 390 pages this functions has a loop of total 62.790 !!!!
That it is what makes it so slow !!!

 ), you definitely miss a hierarchical data structure. To be able to detect what can be moved up or down, you have to create embedded loops, which are awful in terms of complexity.
), you definitely miss a hierarchical data structure. To be able to detect what can be moved up or down, you have to create embedded loops, which are awful in terms of complexity.