Esempio n. 1
0
function show_post_by_category_controller($id)
{
    $category = cache_get('category_' . $id);
    if (!$category) {
        $Posts = many_to_many_model('posts', 'categories', ['t.status' => 'published', 'r.category_id' => $id]);
        $posts = [];
        foreach ($Posts as $Post) {
            $post = one_to_many_model('posts', 'medias', 'left outer', ['t1.id' => $Post['id']]);
            $posts[] = $post->fetch();
        }
        $categories = all_model('categories');
        cache_put('front.category', 'category_' . $id, compact('categories', 'posts'));
        return;
    } else {
        response('200 Ok');
        echo $category;
        return;
    }
    if (!empty($posts)) {
        response('200 Ok');
        view('front.category', compact('posts', 'categories'));
    } else {
        throw new RuntimeException('418');
    }
}
Esempio n. 2
0
/**
 * Saves a HTTP resonse to a cachefile
 * If caching is globally disabled ($config['IMDBage'] <= 0), file is not saved.
 *
 * @param  string $url  URL of the response
 * @param  mixed  $resp HTTP Response
 */
function putHTTPcache($url, $data)
{
    global $config;
    // for debugging purposes track there the request originated
    $data['source'] = $url;
    cache_put($url, $data, CACHE_HTML, $config['IMDBage'], true);
}
Esempio n. 3
0
 public function queryCache($sql, $cache_file)
 {
     try {
         $cache = cache_get($cache_file);
         if ($cache) {
             return $cache;
         }
         $this->queryCount++;
         $this->queryHistory[] = $sql;
         $content = PDO::query($sql)->fetchAll();
         if ($content) {
             cache_put($cache_file, $content);
         }
         return $content;
     } catch (Exception $e) {
         exit('<h3>Error while geting SQL query results!</h3><code>Code: ' . end($this->errorInfo()) . '</code><p><em>For more information check log file.</em></p>');
         // logger(array($e->getMessage, 'Treść zapytania: '.$sql), 'SQL');
     }
     //throw new Exception();
     //return array();
 }
Esempio n. 4
0
 public static function load0($file, $section = false, $lang = false)
 {
     if (!$lang) {
         $lang = LANG;
     }
     $output = cache_get('lang_' . $lang . '_' . md5($file) . '.txt');
     if ($output) {
         return $output;
     }
     if ($output = file_get_contents(ROOT . str_replace('*', $lang, $file))) {
         $output = parse_ini($output);
         cache_put('lang_' . $lang . '_' . md5($file) . '.txt', $output);
         return $output;
     } elseif ($output = cache_get('lang_en_' . md5($file) . '.txt')) {
         return $output;
     } elseif ($output = file_get_contents(ROOT . $file . '.en.ini')) {
         $output = parse_ini($output);
         cache_put('lang_en_' . md5($file) . '.txt', $output);
         return $output;
     } else {
         return false;
     }
     // print($file)
 }
Esempio n. 5
0
function fetch_library($userid)
{
    $stored = cache_fetch($userid, 'user');
    if ($stored !== false) {
        return $stored;
    }
    global $message;
    $codes = array();
    $db = getdb();
    if (!$db) {
        return $codes;
    }
    $sql = 'select now() as now, m.*, u.editable from ' . DB_TABLE . ' m, ' . DB_TABLE . '_users u where u.codeid = m.codeid and u.userid = \'' . $db->escape_string($userid) . '\' order by m.updated desc limit 100';
    $res = $db->query($sql);
    if ($res) {
        require_once 'mapbbcode.php';
        while ($row = $res->fetch_assoc()) {
            $item = array();
            $item['codeid'] = $row['codeid'];
            $item['editid'] = $row['editable'] ? $row['editid'] : '';
            $item['created'] = human_date($row['created'], $row['now']);
            $item['updated'] = human_date($row['updated'], $row['now']);
            $item['title'] = $row['title'];
            $item['stats'] = mapbbcode_stats($row['bbcode']);
            $codes[] = $item;
        }
        $res->free();
        cache_put($userid, 'user', $codes);
    } else {
        $message = 'Failed to retrieve user library: ' . $db->error;
    }
    return $codes;
}
Esempio n. 6
0
function get_lang($file)
{
    $lang = cache_get('lang_' . LANG . '_' . md5($file) . '.txt');
    if ($lang) {
        return $lang;
    }
    if ($lang = file_get_contents(ROOT . str_replace('*', LANG, $file))) {
        $content = parse_ini($lang);
        cache_put('lang_' . LANG . '_' . md5($file) . '.txt', $content);
        return $content;
    } elseif ($lang = cache_get('lang_en_' . md5($file) . '.txt')) {
        return lang;
    } elseif ($lang = file_get_contents(ROOT . $file . '.en.ini')) {
        $content = parse_ini($lang);
        cache_put('lang_en_' . md5($file) . '.txt', $content);
        return $content;
    } else {
        return false;
    }
    // print($file)
}
Esempio n. 7
0
 /**
  * Retrieve user by token.
  *
  * @author Morten Rugaard <*****@*****.**>
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function getUserByToken()
 {
     // Look up in cache and return if found
     if ($user = cache_get('api.masterToken', $this->getCacheParams())) {
         return $user;
     }
     $user = $this->getUserModel()->where($this->getTokenColumn('column'), $this->getTokenColumn('operator'), $this->getTokenColumn('value'))->first();
     // Add to cache
     cache_put('api.masterToken', $this->getCacheParams(), $user);
     return $user;
 }
Esempio n. 8
0
function get_data($codeid)
{
    if (!preg_match('/^[a-z]+$/', $codeid)) {
        return;
    }
    $data = cache_fetch($codeid, 'code');
    if ($data) {
        return $data;
    }
    $db = getdb();
    if (!$db) {
        return false;
    }
    $res = $db->query('select editid, title, bbcode from ' . DB_TABLE . " where codeid = '{$codeid}'");
    $assoc = $res->num_rows > 0 ? $res->fetch_assoc() : false;
    $res->free();
    cache_put($codeid, 'code', $assoc);
    cache_purge();
    // since we've accessed the db, why not purge the cache?
    return $assoc;
}
Esempio n. 9
0
 /**
  */
 function show_old()
 {
     // Path to project.conf.php
     $proj_conf_path = INCLUDE_PATH . "project_conf.php";
     if ($this->SHOW_CUR_SETTINGS && $_SESSION["admin_group"] == 1) {
         // Current settings
         $replace2 = ["rewrite_mode" => (int) conf("rewrite_mode"), "output_caching" => (int) conf("output_caching"), "language" => _prepare_html(strtoupper(conf("language"))), "charset" => _prepare_html(strtoupper(conf("charset"))), "admin_email" => _prepare_html(conf("admin_email")), "mail_debug" => (int) conf("mail_debug"), "site_enabled" => (int) conf("site_enabled"), "settings_link" => $this->_url_allowed("./?object=settings")];
         $cur_settings = tpl()->parse($_GET["object"] . "/cur_settings", $replace2);
     } else {
         $this->DISPLAY_STATS = false;
     }
     if ($this->SHOW_GENERAL_INFO && $_SESSION["admin_group"] == 1) {
         $replace3 = ["php_ver" => phpversion(), "mysql_serv_ver" => db()->get_server_version(), "mysql_host_info" => db()->get_host_info(), "db_name" => DB_NAME, "db_size" => $admin_statistics_array["db_size"], "project_dir_size" => $admin_statistics_array["project_dir_size"]];
         $general_info = tpl()->parse($_GET["object"] . "/general_info", $replace3);
     }
     if ($this->DISPLAY_STATS) {
         $admin_statistics_array = cache_get($this->CACHE_NAME, $this->ADMIN_HOME_CACHE_TIME);
     }
     if ($this->DISPLAY_STATS && empty($admin_statistics_array)) {
         // General info
         $db_size = 0;
         $Q = db()->query("SHOW TABLE STATUS FROM " . DB_NAME . "");
         while ($A = db()->fetch_assoc($Q)) {
             $db_size += $A["Data_length"];
         }
         $admin_statistics_array["db_size"] = common()->format_file_size($db_size);
         $admin_statistics_array["project_dir_size"] = common()->format_file_size(_class("dir")->dirsize(INCLUDE_PATH));
         // Statistics
         $A = db()->query_fetch_all("SELECT * FROM " . db('user_groups') . " WHERE active='1'");
         $sql_parts[] = "SELECT 'total_users' AS '0', COUNT(id) AS '1' FROM " . db('user') . " WHERE active='1'";
         foreach ((array) $A as $V1) {
             $sql_parts[] = "SELECT 'total_" . strtolower($V1["name"]) . "' AS '0', COUNT(id) AS '1' FROM " . db('user') . " WHERE `group`='" . $V1["id"] . "' AND active='1'";
         }
         $sql_parts2 = ["SELECT 'forum_topics' AS '0', COUNT(id) AS '1' FROM " . db('forum_topics') . " WHERE 1=1", "SELECT 'forum_posts' AS '0', COUNT(id) AS '1' FROM " . db('forum_posts') . " WHERE 1=1", "SELECT 'gallery_photos' AS '0', COUNT(id) AS '1' FROM " . db('gallery_photos') . " WHERE 1=1", "SELECT 'blog_posts' AS '0', COUNT(id) AS '1' FROM " . db('blog_posts') . " WHERE 1=1", "SELECT 'articles' AS '0', COUNT(id) AS '1' FROM " . db('articles_texts') . " WHERE 1=1"];
         $sql_parts = array_merge($sql_parts, $sql_parts2);
         $sql = "(\r\n" . implode("\r\n) UNION ALL (\r\n", $sql_parts) . "\r\n)";
         $B = db()->query_fetch_all($sql);
         foreach ((array) $B as $V) {
             $admin_statistics_array[$V[0]] = $V[1];
         }
         cache_put($this->CACHE_NAME, $admin_statistics_array);
     }
     if ($this->DISPLAY_STATS) {
         $statistics = tpl()->parse($_GET["object"] . "/statistics", $admin_statistics_array);
     }
     $replace = ["proj_conf_link" => file_exists($proj_conf_path) ? "./?object=file_manager&action=edit_item&f_=" . basename($proj_conf_path) . "&dir_name=" . urlencode(dirname($proj_conf_path)) : "", "current_date" => _format_date(time(), "long"), "my_id" => $_SESSION["admin_id"], "cur_settings" => $cur_settings, "general_info" => $general_info, "statistics" => $statistics, "cache_time" => ceil($this->ADMIN_HOME_CACHE_TIME / 60), "custom_content" => $this->_custom_content(), "custom_content" => $this->_custom_content(), "suggests" => $this->_show_suggesting_messages()];
     return tpl()->parse($_GET["object"] . "/main", $replace);
 }
Esempio n. 10
0
 /**
  * Retrieve user by token.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @return mixed|null
  */
 protected function getUserByToken()
 {
     // Look up in cache and return if found
     if ($user = cache_get('api.userToken', $this->getCacheParams())) {
         return $user;
     }
     // Look up in database
     $user = $this->generateQuery()->first();
     // Add to cache
     if ($user) {
         cache_put('api.userToken', $this->getCacheParams(), $user);
     }
     return $user;
 }