コード例 #1
0
ファイル: ObjectWrapper.php プロジェクト: maximebf/cachecache
 public function __call($method, $args)
 {
     $id = md5($method . serialize($args) . serialize(get_object_vars($this->object)));
     if (($value = $this->backend->get($id)) === null) {
         $value = call_user_func_array(array($this->object, $method), $args);
         $this->backend->add($id, $value);
     }
     return $value;
 }
コード例 #2
0
ファイル: index.php プロジェクト: bacoda/Wikimedia-contrib
 /**
  * Construct an instance.
  * @param Backend $backend The backend framework.
  */
 public function __construct($backend)
 {
     // set values
     $this->db = $backend->GetDatabase();
     // parse query
     $this->dbname = $backend->get('wiki') ?: $backend->getRouteValue();
     $this->wiki = $backend->db->wikis->GetWiki($this->dbname);
     foreach ($this->presetGroups as $group => $logTypes) {
         if ($backend->get($group)) {
             $this->groups[$group] = $logTypes;
         }
     }
     // set defaults
     if (!$this->groups) {
         $this->groups = array('sysop' => $this->presetGroups['sysop']);
     }
 }
コード例 #3
0
ファイル: Cache.php プロジェクト: maximebf/cachecache
 /**
  * {@inheritDoc}
  */
 public function get($id, $default = null)
 {
     $id = $this->id($id);
     if (($value = $this->backend->get($id)) === null) {
         return $default;
     }
     return $value;
 }
コード例 #4
0
ファイル: Component.obj.php プロジェクト: jrgns/backend-php
 public static function getActive($refresh = false)
 {
     if (!defined('BACKEND_WITH_DATABASE') || !BACKEND_WITH_DATABASE) {
         //Return the core components
         return self::getCoreComponents();
     }
     $result = $refresh ? false : Backend::get('Component::active', false);
     if ($result) {
         return $result;
     }
     $component = new ComponentObj();
     list($query, $params) = $component->getSelectSQL(array('conditions' => '`active` = 1'));
     if ($query) {
         $query = new CustomQuery($query);
         $result = $query->fetchAll($params);
         Backend::add('Component::active', $result);
     }
     return $result;
 }
コード例 #5
0
ファイル: TableCtl.obj.php プロジェクト: jrgns/backend-php
 public function html_import($result)
 {
     switch (true) {
         case $result instanceof DBObject:
             if (!Backend::get('Sub Title')) {
                 Backend::add('Sub Title', 'Import');
                 Backend::add('Sub Title', 'Import ' . $result->getMeta('name'));
             }
             $template_file = array($result->getArea() . '.import.tpl.php', $result->getArea() . '/import.tpl.php');
             if (!Render::checkTemplateFile($template_file[0]) && !Render::checkTemplateFile($template_file[1])) {
                 $template_file = 'std_import.tpl.php';
             }
             Backend::addContent(Render::file($template_file, array('db_object' => $result)));
             break;
         case is_numeric($result) && $result >= 0:
             Backend::addSuccess($result . ' records imported');
             Controller::redirect('?q=' . Controller::$area . '/list');
             break;
         default:
             Controller::redirect();
             break;
     }
     return $result;
 }
コード例 #6
0
ファイル: GChartView.obj.php プロジェクト: jrgns/backend-php
 public static function hook_output($output)
 {
     //TODO Attach HTTP Error codes and descriptions to these errors
     if (!is_array($output)) {
         BackendError::add('Google Chart Error', 'Invalid Output');
         return false;
     }
     $type = array_key_exists('type', $output) ? $output['type'] : Backend::get('ChartType', 'simple_line');
     if (!method_exists('GChartView', $type)) {
         BackendError::add('Google Chart Error', 'Invalid Chart Type');
         return false;
     }
     if (!array_key_exists('data', $output)) {
         $output = array('data' => $output);
     }
     if (!is_array($output['data']) || !count($output['data'])) {
         BackendError::add('Google Chart Error', 'Invalid Output Data');
         return false;
     }
     $params = array();
     $title = array_key_exists('title', $output) ? $output['title'] : Backend::get('ChartTitle', false);
     if ($title) {
         $params['chtt'] = $title;
     }
     $url = self::$type($output, $params);
     if (Controller::$debug) {
         echo '<img src="' . $url . '">';
         var_dump($params);
         var_dump($output);
         $dont_kill = Controller::getVar('dont_kill');
         if (empty($dont_kill)) {
             die;
         }
     }
     $recache = Controller::getVar('recache') ? true : false;
     debug_header('Recache - ' . $recache);
     $image = curl_request($url, array(), array('cache' => $recache ? 1 : 60 * 60, 'bypass_ssl' => 1));
     if (Controller::$debug) {
         var_dump('Image:', $image);
     }
     if (!$image) {
         BackendError::add('Google Chart Error', 'Could not get image');
         return false;
     }
     $filename = Backend::get('ChartFilename', false);
     if (!$filename) {
         $filename = class_name(Controller::$area) . class_name(Controller::$action);
         if (Controller::$action == 'read' && !empty(Controller::$parameters[0])) {
             $filename .= Controller::$parameters[0];
         }
     }
     if (Controller::$debug) {
         var_dump('Filename:', $filename);
     }
     header('Content-Disposition: inline; filename="' . $filename . '.png"');
     return $image;
 }
コード例 #7
0
ファイル: Content.obj.php プロジェクト: jrgns/backend-php
 function html_display($content)
 {
     if ($content instanceof DBObject) {
         Backend::add('Sub Title', $content->array['title']);
         if ($content->array['from_file']) {
             //Move this to the object ??
             $filename = 'content/static/' . $content->array['name'] . '.html';
             $template = 'content/' . $content->array['name'] . '.tpl.php';
             if (Render::checkTemplateFile($template)) {
                 $content->object->body = Render::file($template);
             } else {
                 if (file_exists(SITE_FOLDER . '/' . $filename)) {
                     $content->object->body = file_get_contents(APP_FOLDER . '/' . $filename);
                 } else {
                     if (file_exists(APP_FOLDER . '/' . $filename)) {
                         $content->object->body = file_get_contents(APP_FOLDER . '/' . $filename);
                     } else {
                         if (file_exists(BACKEND_FOLDER . '/' . $filename)) {
                             $content->object->body = file_get_contents(BACKEND_FOLDER . '/' . $filename);
                             //SITE FOLDER too?
                         }
                     }
                 }
             }
         }
         $meta_desc = Backend::get('meta_description');
         if (empty($meta_desc)) {
             Backend::add('meta_description', plain(self::createPreview($content->object->body, false)));
         }
         $http_equiv = Backend::get('meta_http_equiv', array());
         $http_equiv['Last-Modified'] = $content->object->modified;
         Backend::add('meta_http_equiv', $http_equiv);
         if (!headers_sent()) {
             $max_age = ConfigValue::get('content.MaxAge', 86400);
             header('Last-Modified: ' . $content->object->modified);
             header('Expires: ' . gmdate('r', strtotime('+1 day')));
             header('Cache-Control: max-age=' . $max_age . ', must-revalidate');
             header('Pragma: cache');
         }
     }
     if (Backend::getDB('default')) {
         //TODO Make some of the content values (such as added and lastmodified) available
         //So you can add Last Modified on #lastmodified# to the content.
         $content = parent::html_display($content);
     }
     return $content;
 }
コード例 #8
0
ファイル: BackendUser.obj.php プロジェクト: jrgns/backend-php
    public static function userStats()
    {
        $msg = array();
        $query = new SelectQuery('BackendUser');
        $query->field('COUNT(*) AS `Total`, SUM(IF(TO_DAYS(NOW()) - TO_DAYS(`added`) < 7, 1, 0)) AS `New`')->filter('`active` = 1')->filter('`confirmed` = 1');
        if ($stats = $query->fetchAssoc()) {
            $msg[] = 'There are a total of ' . $stats['Total'] . ' **active** users,
of which ' . $stats['New'] . ' signed up in the last 7 days';
        }
        $query = new SelectQuery('BackendUser');
        $query->field('COUNT(*) AS `Total`, SUM(IF(TO_DAYS(NOW()) - TO_DAYS(`added`) < 7, 1, 0)) AS `New`')->filter('`active` = 1')->filter('`confirmed` = 1');
        if ($stats = $query->fetchAssoc()) {
            $msg[] = 'There are a total of ' . $stats['Total'] . ' **unconfirmed** users,
of which ' . $stats['New'] . ' signed up in the last 7 days';
        }
        $msg = implode(PHP_EOL . PHP_EOL, $msg);
        send_email(ConfigValue::get('author.Email', ConfigValue::get('application.Email', 'info@' . SITE_DOMAIN)), 'User stats for ' . Backend::get('Title'), $msg);
        return true;
    }
コード例 #9
0
ファイル: HtmlView.obj.php プロジェクト: jrgns/backend-php
 public static function addLastContent($to_print)
 {
     //Checking for ob_level > $this->ob_level, so we'll exit on the same number we started on
     $last = '';
     while (ob_get_level() > self::$ob_level) {
         //Ending the ob_start from __construct
         $last .= ob_get_clean();
     }
     $start = Backend::get('start');
     $time = microtime(true) - $start;
     $last = 'Generated on ' . date('Y-m-d H:i:s') . ' in ' . number_format($time, 4) . ' seconds' . $last;
     $to_print = str_replace('#Last Content#', $last, $to_print);
     return $to_print;
 }
コード例 #10
0
ファイル: CsvView.obj.php プロジェクト: jrgns/backend-php
 public static function hook_output($to_print)
 {
     $filename = Backend::get('CsvFilename', false);
     if (!$filename) {
         $filename = class_name(Controller::$area) . class_name(Controller::$action);
         if (Controller::$action == 'read' && !empty(Controller::$parameters[0])) {
             $filename .= Controller::$parameters[0];
         }
     }
     if (!Controller::$debug) {
         header('Content-Disposition: attachment; filename="' . $filename . '.csv"');
         header('Pragma: no-cache');
         header('Expires: 0');
     }
     switch (true) {
         //Output SelectQuery as CSV
         case $to_print instanceof SelectQuery:
         case $to_print instanceof CustomQuery:
             return self::outputQuery($to_print);
             break;
             //Output Array of Arrays as CSV
         //Output Array of Arrays as CSV
         case is_array($to_print):
             if (!($fp = fopen('php://temp', 'r+'))) {
                 Backend::addError('Could not open output file for CSV output');
                 return '';
             }
             $tmp = reset($to_print);
             $first = false;
             foreach ($to_print as $row) {
                 if (!is_array($row)) {
                     $row = array($row);
                 }
                 set_time_limit(30);
                 if (!$first) {
                     //fputcsv($fp, array_keys($row));
                     $first = true;
                 }
                 fputcsv($fp, $row);
             }
             //Get the file contents
             rewind($fp);
             ob_start();
             fpassthru($fp);
             fclose($fp);
             return ob_get_clean();
             break;
             //Output a DBObject. Try the list first, then the array | object
         //Output a DBObject. Try the list first, then the array | object
         case $to_print instanceof DBObject:
             if ($to_print->list) {
                 return self::outputList($to_print->list);
             } else {
                 if ($to_print->array || $to_print->db_object) {
                     $to_print = $to_print->array ? $to_print->array : (array) $to_print->db_object;
                     $to_print = array_filter($to_print, create_function('$var', 'return !is_array($var) && !is_object($var);'));
                     return self::outputList(array($to_print));
                 }
             }
             break;
             //Output a specified file as CSV
         //Output a specified file as CSV
         case is_string($to_print):
             if (is_readable($to_print)) {
                 $fp = fopen($to_print, 'r');
                 fpassthru($fp);
                 break;
             }
             //Output a string as CSV
         //Output a string as CSV
         default:
             return $to_print;
             break;
     }
 }
コード例 #11
0
ファイル: Controller.obj.php プロジェクト: jrgns/backend-php
 public static function check_reverse_map($what, $value)
 {
     $map = Backend::get($what . '_maps');
     if (is_array($map)) {
         $key = array_search($value, $map);
         if ($key) {
             $value = $key;
         }
     }
     return $value;
 }