function set_time()
{
    global $language, $use_local_time;
    define('UTIME', time());
    define('MUTIME', getmicrotime());
    if ($use_local_time) {
        list($zone, $zonetime) = set_timezone(DEFAULT_LANG);
    } else {
        list($zone, $zonetime) = set_timezone($language);
        list($l_zone, $l_zonetime) = get_localtimezone();
        if ($l_zonetime != '' && $zonetime != $l_zonetime) {
            $zone = $l_zone;
            $zonetime = $l_zonetime;
        }
    }
    define('ZONE', $zone);
    define('ZONETIME', $zonetime);
}
Beispiel #2
0
}
require_once INCLUDES_DIR . "/helpers.php";
require_once INCLUDES_DIR . "/lib/gettext/gettext.php";
require_once INCLUDES_DIR . "/lib/gettext/streams.php";
require_once INCLUDES_DIR . "/lib/YAML.php";
require_once INCLUDES_DIR . "/lib/PasswordHash.php";
require_once INCLUDES_DIR . "/class/Config.php";
require_once INCLUDES_DIR . "/class/SQL.php";
require_once INCLUDES_DIR . "/class/Model.php";
require_once INCLUDES_DIR . "/model/User.php";
# Prepare the Config interface.
$config = Config::current();
# Atlantic/Reykjavik is 0 offset. Set it so the timezones() function is
# always accurate, even if the server has its own timezone settings.
$default_timezone = oneof(ini_get("date.timezone"), "Atlantic/Reykjavik");
set_timezone($default_timezone);
# Sanitize all input depending on magic_quotes_gpc's enabled status.
sanitize_input($_GET);
sanitize_input($_POST);
sanitize_input($_COOKIE);
sanitize_input($_REQUEST);
$protocol = (!empty($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== "off" or $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = $protocol . $_SERVER['HTTP_HOST'] . str_replace("/install.php", "", $_SERVER['REQUEST_URI']);
$index = parse_url($url, PHP_URL_PATH) ? "/" . trim(parse_url($url, PHP_URL_PATH), "/") . "/" : "/";
$htaccess = "<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase {$index}\nRewriteCond %{REQUEST_FILENAME} !-f\n" . "RewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^.+\$ index.php [L]\n</IfModule>";
$path = preg_quote($index, "/");
$htaccess_has_chyrp = (file_exists(MAIN_DIR . "/.htaccess") and preg_match("/<IfModule mod_rewrite\\.c>\n([\\s]*)RewriteEngine On\n([\\s]*)RewriteBase {$path}\n" . "([\\s]*)RewriteCond %\\{REQUEST_FILENAME\\} !-f\n([\\s]*)RewriteCond %\\{REQUEST_FILENAME\\}" . " !-d\n([\\s]*)RewriteRule \\^\\.\\+\\\$ index\\.php \\[L\\]\n([\\s]*)<\\/IfModule>/", file_get_contents(MAIN_DIR . "/.htaccess")));
$errors = array();
$installed = false;
if (file_exists(INCLUDES_DIR . "/config.yaml.php") and file_exists(MAIN_DIR . "/.htaccess")) {
    $sql = SQL::current(true);
Beispiel #3
0
# Set the error handler to exit on error if this is being run from the tester.
if (TESTER) {
    set_error_handler("error_panicker");
}
# Redirect to the installer if there is no config.
if (!file_exists(INCLUDES_DIR . "/config.yaml.php")) {
    redirect("install.php");
}
# Start the timer that keeps track of Chyrp's load time.
timer_start();
# Load the config settings.
$config = Config::current();
# Prepare the SQL interface.
$sql = SQL::current();
# Set the timezone for date(), etc.
set_timezone($config->timezone);
# Initialize connection to SQL server.
$sql->connect();
# Sanitize all input depending on magic_quotes_gpc's enabled status.
sanitize_input($_GET);
sanitize_input($_POST);
sanitize_input($_COOKIE);
sanitize_input($_REQUEST);
# Begin the session.
session();
# Set the locale for gettext.
set_locale($config->locale);
# Load the translation engine.
load_translator("chyrp", INCLUDES_DIR . "/locale/" . $config->locale . ".mo");
# Constant: PREVIEWING
# Is the user previewing a theme?
Beispiel #4
0
/**
 * Function: time_in_timezone
 * Returns the appropriate time() for representing a timezone.
 */
function time_in_timezone($timezone)
{
    $orig = get_timezone();
    set_timezone($timezone);
    $time = date("F jS, Y, g:i A");
    set_timezone($orig);
    return strtotime($time);
}
Beispiel #5
0
    $opt['debug'] = $opt['debug'] & ~DEBUG_SQLDEBUGGER;
}
if (($opt['debug'] & DEBUG_FORCE_TRANSLATE) != DEBUG_FORCE_TRANSLATE) {
    if (($opt['debug'] & DEBUG_TRANSLATE) == DEBUG_TRANSLATE && isset($_REQUEST['trans']) && $_REQUEST['trans'] == '1') {
        $opt['debug'] = $opt['debug'] | DEBUG_TEMPLATES;
    } else {
        $opt['debug'] = $opt['debug'] & ~DEBUG_TRANSLATE;
    }
}
require_once $opt['rootpath'] . 'lib2/errorhandler.inc.php';
configure_php();
require $opt['rootpath'] . 'lib2/cookie.class.php';
normalize_settings();
set_language();
set_usercountry();
set_timezone();
// set stylepath and langpath
if (isset($opt['template']['style'])) {
    if (strpos($opt['template']['style'], '.') !== false || strpos($opt['template']['style'], '/') !== false) {
        $opt['template']['style'] = $opt['template']['default']['style'];
    }
    if (!is_dir($opt['rootpath'] . 'templates2/' . $opt['template']['style'])) {
        $opt['template']['style'] = $opt['template']['default']['style'];
    }
} else {
    $opt['template']['style'] = $opt['template']['default']['style'];
}
$opt['stylepath'] = $opt['rootpath'] . 'templates2/' . $opt['template']['style'] . '/';
check_useragent();
/* setup smarty
 *
Beispiel #6
0
/**
 * Add a domain to the database
 *
 * A domain is name obligatory, so is an owner.
 * return values: true when succesful.
 *
 * Empty means templates dont have to be applied.
 *
 * This functions eats a template and by that it inserts various records.
 * first we start checking if something in an arpa record
 * remember to request nextID's from the database to be able to insert record.
 * if anything is invalid the function will error
 *
 * @param string $domain A domain name
 * @param int $owner Owner ID for domain
 * @param string $type Type of domain ['NATIVE','MASTER','SLAVE']
 * @param string $slave_master Master server hostname for domain
 * @param int|string $zone_template ID of zone template ['none' or int]
 *
 * @return boolean true on success
 */
function add_domain($domain, $owner, $type, $slave_master, $zone_template)
{
    if (do_hook('verify_permission', 'zone_master_add')) {
        $zone_master_add = "1";
    }
    if (do_hook('verify_permission', 'zone_slave_add')) {
        $zone_slave_add = "1";
    }
    // TODO: make sure only one is possible if only one is enabled
    if ($zone_master_add == "1" || $zone_slave_add == "1") {
        global $db;
        global $dns_ns1;
        global $dns_hostmaster;
        global $dns_ttl;
        global $db_type;
        if ($domain && $owner && $zone_template || preg_match('/in-addr.arpa/i', $domain) && $owner && $zone_template || $type == "SLAVE" && $domain && $owner && $slave_master) {
            $response = $db->query("INSERT INTO domains (name, type) VALUES (" . $db->quote($domain, 'text') . ", " . $db->quote($type, 'text') . ")");
            if (PEAR::isError($response)) {
                error($response->getMessage());
                return false;
            }
            if ($db_type == 'pgsql') {
                $domain_id = $db->lastInsertId('domains_id_seq');
            } else {
                $domain_id = $db->lastInsertId();
            }
            if (PEAR::isError($domain_id)) {
                error($domain_id->getMessage());
                return false;
            }
            $response = $db->query("INSERT INTO zones (domain_id, owner, zone_templ_id) VALUES (" . $db->quote($domain_id, 'integer') . ", " . $db->quote($owner, 'integer') . ", " . $db->quote($zone_template == "none" ? 0 : $zone_template, 'integer') . ")");
            if (PEAR::isError($response)) {
                error($response->getMessage());
                return false;
            }
            if ($type == "SLAVE") {
                $response = $db->query("UPDATE domains SET master = " . $db->quote($slave_master, 'text') . " WHERE id = " . $db->quote($domain_id, 'integer'));
                if (PEAR::isError($response)) {
                    error($response->getMessage());
                    return false;
                }
                return true;
            } else {
                $now = time();
                if ($zone_template == "none" && $domain_id) {
                    $ns1 = $dns_ns1;
                    $hm = $dns_hostmaster;
                    $ttl = $dns_ttl;
                    set_timezone();
                    $serial = date("Ymd");
                    $serial .= "00";
                    $query = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (" . $db->quote($domain_id, 'integer') . "," . $db->quote($domain, 'text') . "," . $db->quote($ns1 . ' ' . $hm . ' ' . $serial . ' 28800 7200 604800 86400', 'text') . "," . $db->quote('SOA', 'text') . "," . $db->quote($ttl, 'integer') . "," . $db->quote(0, 'integer') . "," . $db->quote($now, 'integer') . ")";
                    $response = $db->query($query);
                    if (PEAR::isError($response)) {
                        error($response->getMessage());
                        return false;
                    }
                    return true;
                } elseif ($domain_id && is_numeric($zone_template)) {
                    global $dns_ttl;
                    $templ_records = get_zone_templ_records($zone_template);
                    if ($templ_records != -1) {
                        foreach ($templ_records as $r) {
                            if (preg_match('/in-addr.arpa/i', $domain) && ($r["type"] == "NS" || $r["type"] == "SOA") || !preg_match('/in-addr.arpa/i', $domain)) {
                                $name = parse_template_value($r["name"], $domain);
                                $type = $r["type"];
                                $content = parse_template_value($r["content"], $domain);
                                $ttl = $r["ttl"];
                                $prio = intval($r["prio"]);
                                if (!$ttl) {
                                    $ttl = $dns_ttl;
                                }
                                $query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" . $db->quote($domain_id, 'integer') . "," . $db->quote($name, 'text') . "," . $db->quote($type, 'text') . "," . $db->quote($content, 'text') . "," . $db->quote($ttl, 'integer') . "," . $db->quote($prio, 'integer') . "," . $db->quote($now, 'integer') . ")";
                                $response = $db->query($query);
                                if (PEAR::isError($response)) {
                                    error($response->getMessage());
                                    return false;
                                }
                                if ($db_type == 'pgsql') {
                                    $record_id = $db->lastInsertId('records_id_seq');
                                } else {
                                    $record_id = $db->lastInsertId();
                                }
                                if (PEAR::isError($record_id)) {
                                    error($record_id->getMessage());
                                    return false;
                                }
                                $query = "INSERT INTO records_zone_templ (domain_id, record_id, zone_templ_id) VALUES (" . $db->quote($domain_id, 'integer') . "," . $db->quote($record_id, 'integer') . "," . $db->quote($r['zone_templ_id'], 'integer') . ")";
                                $response = $db->query($query);
                                if (PEAR::isError($response)) {
                                    error($response->getMessage());
                                    return false;
                                }
                            }
                        }
                    }
                    return true;
                } else {
                    error(sprintf(ERR_INV_ARGC, "add_domain", "could not create zone"));
                }
            }
        } else {
            error(sprintf(ERR_INV_ARG, "add_domain"));
        }
    } else {
        error(ERR_PERM_ADD_ZONE_MASTER);
        return false;
    }
}
Beispiel #7
0
function plugin_counter_get_count($page)
{
    global $vars;
    static $counters = array();
    static $default;
    static $localtime;
    if (!isset($localtime)) {
        list($zone, $zonetime) = set_timezone(DEFAULT_LANG);
        $localtime = UTIME + $zonetime;
    }
    if (!isset($default)) {
        $default = array('total' => 0, 'date' => gmdate('Y/m/d', $localtime), 'today' => 0, 'yesterday' => 0, 'ip' => '');
    }
    if (!is_page($page)) {
        return $default;
    }
    if (isset($counters[$page])) {
        return $counters[$page];
    }
    // Set default
    $counters[$page] = $default;
    $modify = FALSE;
    // Open
    $file = COUNTER_DIR . encode($page) . PLUGIN_COUNTER_SUFFIX;
    touch($file);
    $fp = fopen($file, 'r+') or die('counter.inc.php: Cannot open COUTER_DIR/' . basename($file));
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    rewind($fp);
    // Read
    foreach ($default as $key => $val) {
        // Update
        $counters[$page][$key] = rtrim(fgets($fp, 256));
        if (feof($fp)) {
            break;
        }
    }
    // Anothoer day?
    $remoteip = get_remoteip();
    if ($counters[$page]['date'] != $default['date']) {
        $modify = TRUE;
        $yesterday = gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime));
        $is_yesterday = $counters[$page]['date'] == gmdate('Y/m/d', $yesterday);
        $counters[$page]['ip'] = $remoteip;
        $counters[$page]['date'] = $default['date'];
        $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0;
        $counters[$page]['today'] = 1;
        $counters[$page]['total']++;
    } else {
        if ($counters[$page]['ip'] != $remoteip) {
            // Not the same host
            $modify = TRUE;
            $counters[$page]['ip'] = $remoteip;
            $counters[$page]['today']++;
            $counters[$page]['total']++;
        }
    }
    // Modify
    if ($modify && $vars['cmd'] == 'read') {
        rewind($fp);
        ftruncate($fp, 0);
        foreach (array_keys($default) as $key) {
            fputs($fp, $counters[$page][$key] . "\n");
        }
    }
    // Close
    @flock($fp, LOCK_UN);
    fclose($fp);
    return $counters[$page];
}
 function popular_metapages()
 {
     if ($this->options['popular'][1] === false) {
         return;
     }
     if (function_exists('set_timezone')) {
         // plus
         list($zone, $zonetime) = set_timezone(DEFAULT_LANG);
         $localtime = UTIME + $zonetime;
         $today = gmdate('Y/m/d', $localtime);
         $yesterday = gmdate('Y/m/d', gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime)));
     } else {
         $localtime = ZONETIME + UTIME;
         $today = get_date('Y/m/d');
         // == get_date('Y/m/d', UTIME) == date('Y/m/d, ZONETIME + UTIME);
         $yesterday = get_date('Y/m/d', mktime(0, 0, 0, date('m', $localtime), date('d', $localtime) - 1, date('Y', $localtime)));
     }
     foreach ($this->metapages as $i => $metapage) {
         $page = $metapage['page'];
         $lines = file(COUNTER_DIR . encode($page) . '.count');
         $lines = array_map('rtrim', $lines);
         list($total_count, $date, $today_count, $yesterday_count, $ip) = $lines;
         $popular = 0;
         switch ($this->options['popular'][1]) {
             case 'total':
                 $popular = $total_count;
                 break;
             case 'today':
                 if ($date == $today) {
                     $popular = $today_count;
                 }
                 break;
             case 'yesterday':
                 if ($date == $today) {
                     $popular = $yesterday_count;
                 } elseif ($date == $yesterday) {
                     $popular = $today_count;
                 }
                 break;
             case 'recent':
                 if ($date == $today) {
                     $popular = $today_count + $yesterday_count;
                 } elseif ($date == $yesterday) {
                     $popular = $today_count;
                 }
                 break;
         }
         if ($popular > 0) {
             $this->metapages[$i]['popular'] = $popular;
         } else {
             unset($this->metapages[$i]);
             // like popular plugin
         }
     }
 }
 /**
  * Get number of popular
  *
  * @access public
  * @static
  * @param string $page pagename
  * @param string $when 'total' or 'today' or 'yesterday' or 'recent'
  * @return int
  */
 function popular($page, $when)
 {
     static $localtime, $today, $yesterday;
     if (!isset($localtime)) {
         if (function_exists('set_timezone')) {
             // plus
             list($zone, $zonetime) = set_timezone(DEFAULT_LANG);
             $localtime = UTIME + $zonetime;
             $today = gmdate('Y/m/d', $localtime);
             $yesterday = gmdate('Y/m/d', gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime)));
         } else {
             $localtime = ZONETIME + UTIME;
             $today = get_date('Y/m/d');
             // == get_date('Y/m/d', UTIME) == date('Y/m/d, ZONETIME + UTIME);
             $yesterday = get_date('Y/m/d', mktime(0, 0, 0, date('m', $localtime), date('d', $localtime) - 1, date('Y', $localtime)));
         }
     }
     $counterfile = COUNTER_DIR . encode($page) . '.count';
     if (is_readable($counterfile)) {
         $lines = file($counterfile);
         $lines = array_map('rtrim', $lines);
         list($total_count, $date, $today_count, $yesterday_count, $ip) = $lines;
     } else {
         return 0;
     }
     $popular = 0;
     switch ($when) {
         case 'total':
             $popular = $total_count;
             break;
         case 'today':
             if ($date == $today) {
                 $popular = $today_count;
             }
             break;
         case 'yesterday':
             if ($date == $today) {
                 $popular = $yesterday_count;
             } elseif ($date == $yesterday) {
                 $popular = $today_count;
             }
             break;
         case 'recent':
             if ($date == $today) {
                 $popular = $today_count + $yesterday_count;
             } elseif ($date == $yesterday) {
                 $popular = $today_count;
             }
             break;
     }
     return $popular;
 }
Beispiel #10
0
    exit("Chyrp requires PHP 5.1.3 or greater. Installation cannot continue.");
}
require_once INCLUDES_DIR . "/helpers.php";
require_once INCLUDES_DIR . "/lib/gettext/gettext.php";
require_once INCLUDES_DIR . "/lib/gettext/streams.php";
require_once INCLUDES_DIR . "/lib/YAML.php";
require_once INCLUDES_DIR . "/lib/PasswordHash.php";
require_once INCLUDES_DIR . "/class/Config.php";
require_once INCLUDES_DIR . "/class/SQL.php";
require_once INCLUDES_DIR . "/class/Model.php";
require_once INCLUDES_DIR . "/model/User.php";
# Prepare the Config interface.
$config = Config::current();
# Atlantic/Reykjavik is 0 offset. Set it so the timezones() function is
# always accurate, even if the server has its own timezone settings.
set_timezone("Atlantic/Reykjavik");
# Sanitize all input depending on magic_quotes_gpc's enabled status.
sanitize_input($_GET);
sanitize_input($_POST);
sanitize_input($_COOKIE);
sanitize_input($_REQUEST);
$url = "http://" . $_SERVER['HTTP_HOST'] . str_replace("/install.php", "", $_SERVER['REQUEST_URI']);
$index = parse_url($url, PHP_URL_PATH) ? "/" . trim(parse_url($url, PHP_URL_PATH), "/") . "/" : "/";
$htaccess = "<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase {$index}\nRewriteCond %{REQUEST_FILENAME} !-f\n" . "RewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^.+\$ index.php [L]\n</IfModule>";
$path = preg_quote($index, "/");
$htaccess_has_chyrp = (file_exists(MAIN_DIR . "/.htaccess") and preg_match("/<IfModule mod_rewrite\\.c>\n([\\s]*)RewriteEngine On\n([\\s]*)RewriteBase {$path}\n" . "([\\s]*)RewriteCond %\\{REQUEST_FILENAME\\} !-f\n([\\s]*)RewriteCond %\\{REQUEST_FILENAME\\}" . " !-d\n([\\s]*)RewriteRule \\^\\.\\+\\\$ index\\.php \\[L\\]\n([\\s]*)<\\/IfModule>/", file_get_contents(MAIN_DIR . "/.htaccess")));
$errors = array();
$installed = false;
if (file_exists(INCLUDES_DIR . "/config.yaml.php") and file_exists(MAIN_DIR . "/.htaccess")) {
    $sql = SQL::current(true);
    if ($sql->connect(true) and !empty($config->url) and $sql->count("users")) {
Beispiel #11
0
function mapi_connect_proxy(&$options)
{
    global $last_error;
    global $connection_pool;
    global $pconnect_count;
    $merovingian_iter = 0;
    /**
     * When connecting, the function would first try to find a (persistent) link that's already
     * open with the same host, username and password. If one is found, an identifier for it will be returned
     * instead of opening a new connection.
     * TODO: move this check to mapi_connect() to deal with options arrays rewritten by redirects.
     */
    if ($options['persistent'] == TRUE) {
        if (count($connection_pool) > 0) {
            foreach ($connection_pool as $conn) {
                if ($conn["persistent"] == TRUE && $conn["dbname"] == $options['database'] && $conn['username'] == $options['username'] && ($conn["password"] == hash($options['hashfunc'], $options['password']) && $conn['host'] == $options['host']) && $conn['port'] == $options['port']) {
                    return $conn;
                }
            }
        }
    }
    $socket = mapi_open();
    if (mapi_connect($socket, $options, $merovingian_iter) == TRUE) {
        /* Connected */
        // Create a new connection instance and insert an entry in the connections table
        $id = mapi_generate_id();
        if ($options['lang'] == LANG_SQL) {
            /*
            	PHP requires a timezone to be specified in the configuration environment; if not specified
            	either in php.ini or via date_default_timezone_set(), a default is set 'Europe/Berlin'.
            
            	PHP complains in case we query the OS to get system's timezone (E_STRICT error).
            
            	To avoid unexpected behaviours and warnings at execution time we set a timezone on mserver
            	only if PHP interpreter is aware of it (php.ini contains a date.timezone entry).
            */
            if (ini_get("date.timezone")) {
                set_timezone($socket);
                // set the timezone according to the system's configuration
            }
            // export the reply size (max number of tuples returned at query executions)
            mapi_write($socket, format_command("reply_size " . REPLY_SIZE));
            if (strlen($response = mapi_read($socket)) > 0) {
                // something went wrong
                $last_error = $response;
                return FALSE;
            }
        } else {
            return FALSE;
        }
    } else {
        socket_close($socket);
        return FALSE;
    }
    $connection = array("id" => $id, "socket" => $socket, "host" => $options["host"], "port" => $options["port"], "dbname" => $options['database'], "username" => $options["username"], "password" => hash($options['hashfunc'], $options["password"]), "transactions" => array(), "persistent" => $options["persistent"], "lang" => $options['lang']);
    $connection_pool[] = $connection;
    return $connection;
}
function plugin_popular_convert()
{
    global $vars;
    //	global $_popular_plugin_frame, $_popular_plugin_today_frame;
    static $localtime;
    $_popular_plugin_frame_s = _('popular(%d)');
    $_popular_plugin_today_frame_s = _('today\'s(%d)');
    $_popular_plugin_yesterday_frame_s = _('yesterday\'s(%d)');
    $_popular_plugin_recent_frame_s = _('recent\'s(%d)');
    $_popular_plugin_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_frame_s);
    $_popular_plugin_today_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_today_frame_s);
    $_popular_plugin_yesterday_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_yesterday_frame_s);
    $_popular_plugin_recent_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_recent_frame_s);
    $view = 'total';
    $max = PLUGIN_POPULAR_DEFAULT;
    $except = '';
    if (!isset($localtime)) {
        list($zone, $zonetime) = set_timezone(DEFAULT_LANG);
        $localtime = UTIME + $zonetime;
    }
    $today = gmdate('Y/m/d', $localtime);
    // $yesterday = gmdate('Y/m/d', strtotime('yesterday', $localtime));
    $yesterday = gmdate('Y/m/d', gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime)));
    $array = func_get_args();
    switch (func_num_args()) {
        case 3:
            switch ($array[2]) {
                case 'today':
                case 'true':
                    $view = 'today';
                    break;
                case 'yesterday':
                    $view = 'yesterday';
                    break;
                case 'recent':
                    $view = 'recent';
                    break;
                case 'total':
                case 'false':
                default:
                    $view = 'total';
                    break;
            }
        case 2:
            $except = $array[1];
        case 1:
            $max = $array[0];
    }
    $counters = array();
    foreach (auth::get_existpages(COUNTER_DIR, '.count') as $file => $page) {
        if ($except != '' && ereg($except, $page) || is_cantedit($page) || check_non_list($page) || !is_page($page)) {
            continue;
        }
        $array = file(COUNTER_DIR . $file);
        $count = rtrim($array[0]);
        $date = rtrim($array[1]);
        $today_count = rtrim($array[2]);
        $yesterday_count = rtrim($array[3]);
        $counters['_' . $page] = 0;
        if ($view == 'today' or $view == 'recent') {
            // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
            // array_splice()によってキー値が変更されてしまうのを防ぐ
            // ため、キーに '_' を連結する
            if ($today == $date) {
                $counters['_' . $page] = $today_count;
            }
        }
        if ($view == 'yesterday' or $view == 'recent') {
            if ($today == $date) {
                $counters['_' . $page] += $yesterday_count;
            } elseif ($yesterday == $date) {
                $counters['_' . $page] += $today_count;
            }
        }
        if ($view == 'total') {
            $counters['_' . $page] = $count;
        }
        if ($counters['_' . $page] == 0) {
            unset($counters['_' . $page]);
        }
    }
    asort($counters, SORT_NUMERIC);
    // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
    $counters = array_reverse($counters, TRUE);
    // with array_splice()
    $counters = array_splice($counters, 0, $max);
    $items = '';
    if (!empty($counters)) {
        $items = '<ul class="popular_list">' . "\n";
        foreach ($counters as $page => $count) {
            $page = substr($page, 1);
            $s_page = htmlspecialchars($page);
            if ($page == $vars['page']) {
                // No need to link itself, notifies where you just read
                $pg_passage = get_pg_passage($page, FALSE);
                $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' . $s_page . '<span class="counter">(' . $count . ')</span></span></li>' . "\n";
            } else {
                $items .= ' <li>' . make_pagelink($page, $s_page . '<span class="counter">(' . $count . ')</span>') . '</li>' . "\n";
            }
        }
        $items .= '</ul>' . "\n";
    }
    switch ($view) {
        case 'today':
            $frame = $_popular_plugin_today_frame;
            break;
        case 'yesterday':
            $frame = $_popular_plugin_yesterday_frame;
            break;
        case 'recent':
            $frame = $_popular_plugin_recent_frame;
            break;
        case 'total':
        default:
            $frame = $_popular_plugin_frame;
            break;
    }
    return sprintf($frame, count($counters), $items);
}