Пример #1
0
	/**
	 * Retrieve the banlists for the current forum.
	 *
	 * @param int $p_type
	 * @param boolean $p_isRegex
	 * @param string $p_matchString
	 * @param int $p_forumId
	 * @return array
	 */
	public static function GetBanItems($p_type = null, $p_isRegex = null,
	                                   $p_matchString = null, $p_forumId = null)
	{
		global $g_ado_db;
		global $PHORUM;

		$whereStr = "";
	    $constraints = array();
	    if (!is_null($p_type) && is_numeric($p_type)) {
	    	$constraints[] = "type = $p_type";
	    }
	    if (!is_null($p_isRegex) && is_bool($p_isRegex)) {
	    	$p_isRegex = $p_isRegex ? '1' : '0';
	    	$constraints[] = "pcre = $p_isRegex";
	    }
	    if (!is_null($p_matchString)) {
	    	$constraints[] = "string='".mysql_real_escape_string($p_matchString)."'";
	    }
	    if (!is_null($p_forumId) && is_numeric($p_forumId)) {
	    	if ($p_forumId > 0) {
	        	$constraints[] = "(forum_id = $p_forumId OR forum_id = 0)";
	    	}
	    }
	    if (count($constraints) > 0) {
	    	$whereStr = " WHERE ".implode(" AND ", $constraints);
	    }

	    $sql = "SELECT * FROM {$PHORUM['banlist_table']} $whereStr"
	    	  ." ORDER BY type, string";
	    $rows = $g_ado_db->GetAll($sql);
	    $retval = array();
		if (is_array($rows)) {
			foreach ($rows as $row) {
				$tmpObj = new Phorum_ban_item();
				$tmpObj->fetch($row);
				$retval[] = $tmpObj;
			}
		}
		return $retval;
	} // fn GetBanItems