Example #1
0
 /**
  * Top articles last 24 hours
  */
 public function getTop($limit)
 {
     global $config;
     $key = 'top100';
     if ($config['use_cron'] && ($cache = Cache::get($key))) {
         return array_slice($cache, 0, $limit);
     }
     $today = strtotime('today');
     $top100 = self::$dbh->getAll("SELECT url, count(*) AS hits FROM access_log WHERE view = 1 AND log_on > {$today} GROUP BY url ORDER BY hits DESC LIMIT 0,100");
     $objs = $cph = array();
     foreach ($top100 as &$top) {
         $obj = Ctrl::fetchData($top['url']);
         if (!is_object($obj) || !isset($obj->subject)) {
             continue;
         }
         $pub_on = $obj->pub_on < $today ? $today : $obj->pub_on;
         $live = $_SERVER['REQUEST_TIME'] - $pub_on;
         $obj->cph = $top['hits'] * 3600 / $live;
         // clicks per hour
         $objs[] = $obj;
         $cph[] = $obj->cph;
     }
     array_multisort($cph, SORT_DESC, $objs);
     return array_slice($objs, 0, $limit);
 }
Example #2
0
 public function __construct($set)
 {
     $this->set = $set;
     $this->cfg = $this->get_plg_cfg();
     $this->ModObj = new $this->cfg['mod']($set);
     parent::__construct($this->ModObj, $set, $this->get_plg_cfg(), $this->get_sort_field(), $this->get_filter());
 }
Example #3
0
 function __construct()
 {
     $this->referer = isset($_SESSION['error_uri']) ? $_SESSION['error_uri'] : '';
     $this->msg = isset($_SESSION['error_msg']) ? $_SESSION['error_msg'] : 'Error occured';
     unset($_SESSION['error_uri']);
     unset($_SESSION['error_msg']);
     Ctrl::$setCache = 0;
 }
 public function get_ref($params = [])
 {
     //echo '<pre>'; print_r($params); echo '</pre>'; exit;
     if (isset($params['_escaped_fragment_'])) {
         $file_name = substr($params['_escaped_fragment_'], 5);
         $context = ['page' => $file_name, 'link_style' => -1];
         $content = Template::render_doc_by_name('basic-ref', $context);
         Render::html($content);
     } else {
         Render::include_script("app/mdCode");
         parent::doc($params);
     }
 }
Example #5
0
 public function index()
 {
     $limit = isset($this->params[0]) ? $this->params[0] : 7;
     $news = $this->model->getNews($limit);
     $ret = array();
     foreach ($news as &$new) {
         $folder = Folder::getById($new['folder_id']);
         $uri = $folder->path . '/' . $new['slug'] . '.htm';
         $obj = Ctrl::fetchData($uri);
         if (!is_object($obj) || !isset($obj->subject)) {
             continue;
         }
         $ret[] = $obj;
     }
     return $ret;
 }
Example #6
0
 public function rss()
 {
     setlocale(LC_ALL, 'en_US');
     $limit = 10;
     $ret = array();
     foreach ($this->folder->subFolders as $s) {
         $path = Folder::path($s);
         $uri = $path . '/last/' . $limit;
         $ret += Ctrl::fetchData($uri);
     }
     krsort($ret);
     return array_splice($ret, 0, $limit);
 }
Example #7
0
 public function init()
 {
     Ctrl::$setCache = 0;
     $this->folder->config = array_merge(self::$config, $this->folder->config);
     $this->model = new $this->_model($this->folder);
 }
Example #8
0
 protected static function fetchContent(&$f, &$a, &$p, $main = false)
 {
     if (!$f->ctrl) {
         return array();
     }
     $ctrl = $f->ctrl . 'Controller';
     $C = new $ctrl($f, $a, $p);
     if (!method_exists($C, $a)) {
         self::$setCache = 0;
         self::$actionFound = 0;
         array_unshift($p, $a);
         $a = 'index';
     }
     $data = $C->{$a}();
     if (is_object($data) || is_array($data)) {
         if (is_array($data) && isset($data['total'])) {
             $total = $data['total'];
             $data = $data['data'];
         } else {
             $total = 0;
         }
         View::$frame = sprintf('tpl/%s%sframe.tpl.php', View::$theme, $f->path);
         $tpl = sprintf('tpl/%s%s/%s.tpl.php', View::$theme, $f->path, $a);
         $input = array('folder' => $f, 'params' => $p, 'data' => $data, 'total' => $total);
         $ret = View::render($tpl, $input);
         if ($main) {
             self::$data =& $data;
             if (User::$id && !in_array($a, array('add', 'edit', 'post')) && method_exists($C, 'panel')) {
                 $ret .= View::renderPanel($C->panel($data));
             }
         }
         return $ret;
     }
     if (strpos($data, '/') === 0 || strpos($data, 'http') === 0) {
         if (strpos($data, '/user/login') === 0 || strpos($data, '/error/denied') === 0) {
             $_SESSION['LOGIN_REFERER'] = $_SERVER['REQUEST_URI'];
         }
         self::redirect($data);
     }
     // anything else
     echo $data;
     die;
 }
Example #9
0
<?php

// Route resolver
// Load configs
require_once '../../config/config.inc.php';
ContentProcessor::pre();
Session::start();
SiteStructure::initialize();
Router::initialize();
Render::initialize();
// Resolve the incoming request
$parsed_request = Router::resolve($_SERVER['REQUEST_METHOD'], SiteStructure::get_request_uri());
if ($parsed_request) {
    Ctrl::process($parsed_request);
} else {
    Render::error_404();
}
Example #10
0
 public function init()
 {
     Ctrl::$setCache = 0;
     $this->model = new $this->_model($this->folder);
 }
Example #11
0
 public function __construct()
 {
     $this->doc_root = $_SERVER['DOCUMENT_ROOT'];
     //$this->request_path = $_SERVER['PATH_INFO'];
     $this->request_qs = $_SERVER['QUERY_STRING'];
     Ctrl::$CURRENT_CTRL = self::getClassName();
     spl_autoload_register(get_class($this) . '::my_autoloader');
 }
Example #12
0
include ROOT_DIR . '/app/config.php';
set_include_path(ROOT_DIR . '/lib/' . PATH_SEPARATOR . ROOT_DIR . '/app/controllers/' . PATH_SEPARATOR . ROOT_DIR . '/app/models/' . PATH_SEPARATOR . get_include_path());
ini_set('display_errors', '0');
set_magic_quotes_runtime(0);
setlocale(LC_ALL, 'id_ID');
if (isset($_GET['theme'])) {
    $config['theme'] =& $_GET['theme'];
}
// for m.namadomain.com
if (strpos($_SERVER['HTTP_HOST'], 'm.') === 0) {
    $config['theme'] = 'm';
}
// Include pear module before autoload
require 'Mail.php';
function __autoload($class)
{
    if (!$class) {
        return;
    }
    $lib = strtolower($class) . '.php';
    require $lib;
}
// Cache
Cache::init($config['cache']['backend'], $config['cache']['options']);
Session::start();
User::start();
require ROOT_DIR . '/lib/controller.php';
ob_start();
Ctrl::dispatch();
$html = str_replace(array('/[\\r\\n\\t]/', '/\\s{2,}/'), array(' ', ' '), ob_get_clean());
echo $html;
Example #13
0
 public static function fetch($uri, $setCache = true)
 {
     return Ctrl::fetch($uri, $setCache);
 }
Example #14
0
 public function send()
 {
     Ctrl::$setCache = 0;
     $article = $this->model->getBySlug($this->params[0]);
     View::$title = $article->subject . ' (Mail)';
     if (isset($_POST['submit'])) {
         if (!strstr($_POST['mailto'], '@') && !strstr($_POST['mailfrom'], '@') && !$_POST['from']) {
             $_SESSION['ERR_FORM'] = 'Nama dan semua alamat email harus diisi';
             return $article;
         }
         global $config;
         $mailfrom = $config['mail'];
         $headers['From'] = $_POST['mailfrom'];
         $headers['To'] = $_POST['mailto'];
         $headers['Subject'] = $config['site'] . ' - ' . $article->subject;
         $body = sprintf($config['mail']['send_body'], $_POST['from'], $_POST['mailfrom'], $_POST['msg'], $article->subject, $article->lead, $article->permalink);
         require_once 'Mail.php';
         $mail =& Mail::factory('sendmail', array('sendmail_path' => '/usr/sbin/sendmail'));
         $mail->send($_POST['mailto'], $headers, $body);
         $_SESSION['ERR_FORM'] = sprintf('Rekomendasi anda sudah dikirim ke %s. Anda dapat mengirim ke rekan yang lain.', $_POST['mailto']);
         $this->model->mailLog($article->permalink, $_POST);
     }
     return $article;
 }
Example #15
0
 public function init()
 {
     Ctrl::$setCache = 0;
 }