Пример #1
0
/**
 * Dado um apelido, retornar a sua URL de sistema, se houver. 
 * Dado um sistema um retorno URL do seu alias, se tal pessoa existe. 
 * Caso contr�rio, retorna FALSE.
 *
 * @param $action
 * um dos seguintes valores:
 * - wipe: apaga um cache de apelidos.
 * - alias: retorna um apelido para dar ao URL do sistema de caminhos (se existir).
 * - source: retorna a URL do sistema para um apelido (se existir)
 * @param $path
 * O caminho para investigar o sistema de apelidos ou correspondentes URLs.
 * @param $path_language
 * Opcional codigo de linguagem para procurar um caminho nele. O padr�o � a linguagem
 * da p�gina.
 * se nenhum caminho for definido pela lingagem ent�o ser� buscado um caminho se a linguagem.
 *
 * @return
 * ou um caminho de sistema, um caminho do apelido, ou FALSE se nenhum caminho for encontrado.
 */
function lookup_path($action, $path = '', $path_language = '')
{
    global $language, $cfg;
    // $map é um array com a chave da linguagem, contendo arrays com os apelidos dos caminhos
    static $map = array(), $no_src = array(), $count = NULL;
    $path_language = $path_language ? $path_language : $language['language']->language;
    $mysql = new MYSQL($cfg);
    // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
    if (!isset($count)) {
        $sql = "SELECT COUNT(ID_PATH) FROM {url_alias}";
        $count = $mysql->dbResult($mysql->SqlSelect($sql));
    }
    if ($action == 'wipe') {
        $map = array();
        $no_src = array();
        $count = NULL;
    } elseif ($count > 0 && $path != '') {
        if ($action == 'alias') {
            if (isset($map[$path_language][$path])) {
                return $map[$path_language][$path];
            }
            // Obtenha o resultado mais adequado caindo para tr�s com alias sem linguagem
            $sql = "SELECT dst FROM {url_alias} WHERE src = '{$path}' AND language IN('{$path_language}', '') ORDER BY language DESC, ID_PATH DESC";
            $alias = $mysql->dbResult($mysql->SqlSelect($sql, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__));
            $map[$path_language][$path] = $alias;
            return $alias;
        } elseif ($action == 'source' && !isset($no_src[$path_language][$path])) {
            // procura no valor de  $path sem cachear $map
            $src = FALSE;
            if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
                // Obtenha o resultado mais adequado caindo para tr�s com alias sem linguagem
                $sql = "SELECT src FROM {url_alias} WHERE dst = '{$path}' AND language IN('{$path_language}', '') ORDER BY language DESC, ID_PATH DESC";
                $src = "";
                if ($src = $mysql->dbResult($mysql->SqlSelect($sql, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__))) {
                    $map[$path_language][$src] = $path;
                } else {
                    // We can't record anything into $map because we do not have a valid
                    // index and there is no need because we have not learned anything
                    // about any Drupal path. Thus cache to $no_src.
                    $no_src[$path_language][$path] = TRUE;
                }
            }
            return $src;
        }
    }
    return FALSE;
}
Пример #2
0
/**
 * Counts how many users have sessions. Can count either anonymous sessions or authenticated sessions.
 *
 * @param int $timestamp
 *   A Unix timestamp representing a point of time in the past.
 *   The default is 0, which counts all existing sessions.
 * @param boolean $anonymous
 *   TRUE counts only anonymous users.
 *   FALSE counts only authenticated users.
 * @return  int
 *   The number of users with sessions.
 */
function sess_count($timestamp = 0, $anonymous = true)
{
    global $cfg;
    $mysql = new MYSQL($cfg);
    $query = $anonymous ? ' AND ID_USER = 0' : ' AND ID_USER > 0';
    return $mysql->dbResult($mysql->SqlSelect('SELECT COUNT(ID_SESSION) AS count FROM {sessions} WHERE timestamp >= %d' . $query, $timestamp));
}
Пример #3
0
function getFilename($type, $name, $filename = NULL)
{
    global $cfg;
    static $files = array();
    $GLOBALS['files'] &= $files;
    $mysql = new MYSQL($cfg);
    if (!isset($files[$type])) {
        $files[$type] = array();
    }
    if (!empty($filename) && file_exists($filename)) {
        $files[$type][$name] = $filename;
    } elseif (isset($files[$type][$name])) {
        // nothing
    } elseif ($cfg['db_name'] && (($file = $mysql->dbResult($mysql->SqlSelect("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file))) {
        $files[$type][$name] = $file;
    } else {
        // Fallback to searching the filesystem if the database connection is
        // not established or the requested file is not found.
        $dir = $type == 'theme_engine' ? 'themes/engines' : "{$type}s";
        $file = $type == 'theme_engine' ? "{$name}.engine" : "{$name}.{$type}";
        $config = SITE_MODULOS;
        foreach (array("{$config}{$dir}/{$file}", "{$config}{$dir}/{$name}/{$file}", "{$dir}/{$file}", "{$dir}/{$name}/{$file}") as $file) {
            if (file_exists($file)) {
                $files[$type][$name] = $file;
                break;
            }
        }
    }
    if (isset($files[$type][$name])) {
        return $files[$type][$name];
    }
}
Пример #4
0
 private function is_denied($type, $mask)
 {
     $mysql = new MYSQL($this);
     $sql = "SELECT 1 FROM {$this->cfg[db_prefix]}access WHERE type = '%s' AND LOWER('%s') LIKE LOWER(mask) AND status = %d";
     return $mysql->dbResult($mysql->SqlSelect($mysql->db_query_range($sql, $type, $mask, 0, 0, 1), __FILE__, __LINE__)) && !$mysql->db_result($mysql->SqlSelect($mysql->db_query_range($sql, $type, $mask, 1, 0, 1), __FILE__, __LINE__));
 }