Esempio n. 1
0
 public static function assignAsLoop($loopCodename, $loop)
 {
     if (is_array($loop)) {
         $l = new TPLLoop($loopCodename);
         foreach ($loop as $loopItem) {
             $item = new TPLLoopItem();
             foreach ($loopItem as $key => $value) {
                 if ($key != 'conds') {
                     $item->add($key, $value);
                 } else {
                     foreach ($value as $key => $value) {
                         $item->cond($key, (bool) $value);
                     }
                 }
             }
             $l->append($item);
         }
         $l->pack();
     }
 }
Esempio n. 2
0
 private function fetchPosts($paginationObject, $category_slug = false, $browser = true)
 {
     $posts = new TPLLoop(TPL_LOOP_BLOG_POSTS);
     foreach ($paginationObject->fetch() as $post) {
         $i = new TPLLoopItem();
         $i->add('POST_LINK', str_replace(array('%slug', '%id'), array($post->post_slug, $post->post_id), CFG_URL_BLOG_POST));
         $i->add('CATEGORY_LINK', str_replace(array('%slug', '%id'), array($post->category_slug, $post->category_id), CFG_URL_BLOG_CATEGORY));
         $i->add('POST_ID', $post->post_id);
         $i->add('POST_SLUG', $post->post_slug);
         $i->add('POST_HEADER', $post->post_header);
         $i->add('POST_DATE', date(ESCMS_DATE_FORMAT, (int) $post->post_date));
         $i->add('POST_PROLOGUE', $post->post_prologue);
         $i->add('CATEGORY_ID', $post->category_id);
         $i->add('CATEGORY_SLUG', $post->category_slug);
         $i->add('CATEGORY_HEADER', $post->category_header);
         $i->add('COMMENTS_COUNT', $post->comments_count);
         $posts->append($i);
     }
     $posts->pack();
     if ($browser) {
         TPL::assignAsLoop(TPL_LOOP_BLOG_BROWSER, $paginationObject->getBrowser());
     }
 }
Esempio n. 3
0
 public static function log($exception = false)
 {
     if (!self::$enabled || count(self::$items) == 0) {
         return;
     }
     $o_dirpath = TPL::$dirpath;
     TPL::$dirpath = ESCMS_PATH_TPL . '.debug/';
     if (!$exception && !TPL::addTpl('errors')) {
         $items = array();
         foreach (self::$items as $exc) {
             $file = end(explode(dirname($_SERVER['SCRIPT_FILENAME']), $exc->getFile()));
             $line = $exc->getLine();
             if (end(explode('/', $file)) == 'debug.layer.php') {
                 $trace = current($exc->getTrace());
                 $file = end(explode(dirname($_SERVER['SCRIPT_FILENAME']), $trace['file']));
                 $line = $trace['line'];
             }
             $items[] = array('message' => preg_replace('# \\[<a href=\'(.*?)\'>(.*?)</a>\\]#s', '', $exc->getMessage()), 'file' => $file, 'line' => $exc->getLine());
         }
         Debug::dump($items, false);
     } else {
         TPL::add('DEBUG_ERRORS_COUNT', count(self::$items));
         TPL::add('DEBUG_TIMEOUT', $GLOBALS['time'] - microtime(true));
         $items = new TPLLoop('DEBUG_ITEMS');
         foreach (self::$items as $exc) {
             $file = end(explode(dirname($_SERVER['SCRIPT_FILENAME']), str_replace('\\', '/', $exc->getFile())));
             $line = $exc->getLine();
             $f = end(explode('/', $file));
             $trace = $exc->getTrace();
             //print_r($trace);continue;
             for ($i = 0; i < count($trace); ++$i) {
                 if (isset($trace[$i]['file'])) {
                     $e = end(explode(dirname($_SERVER['SCRIPT_FILENAME']), str_replace('\\', '/', $trace[$i]['file']), 2));
                     $e = str_replace('\\', '/', $e);
                     $ee = explode('/', $e);
                     if (!($ee[1] == 'app' && count($ee) > 3 && in_array($ee[2], array('layers', 'modules', 'lib')))) {
                         $file = $e;
                         $line = $trace[$i]['line'];
                         break;
                     }
                 }
             }
             $msg = $exc->getMessage();
             if (preg_match('#(\\w:+)\\(\\): (.*)#m', $msg, $arr)) {
                 $msg = '<tt>' . $arr[1] . '()</tt>: ' . $arr[2];
             }
             $i = new TPLLoopItem();
             $i->add('DEBUG_ITEM_FILE', $file);
             $i->add('DEBUG_ITEM_LINE', $line);
             $i->add('DEBUG_ITEM_MESSAGE', $msg);
             $lines = array();
             $count = 0;
             if ($o = @fopen('.' . $file, 'r')) {
                 $content = fread($o, filesize('.' . $file));
                 $e = explode("\n", $content);
                 $count = count($e);
                 array_unshift($e, '');
                 //Debug::dump($e);
                 switch ($line) {
                     case 0:
                         $range = array();
                         break;
                     case 1:
                         $range = range(1, 4);
                         break;
                     case 2:
                         $range = range(1, 5);
                         break;
                     case 3:
                         $range = range(1, 6);
                         break;
                     default:
                         $range = range($line - 3, $line + 3);
                         break;
                 }
                 foreach ($range as $id => $no) {
                     $noText = $no;
                     while (strlen($noText) != strlen($count)) {
                         $noText = '0' . $noText;
                     }
                     if ($no == $line) {
                         $lines[] = '</pre><pre class="errorline"> ' . $noText . '| ' . htmlspecialchars($e[$no]) . '</pre><pre>';
                     } else {
                         $lines[] = ' ' . $noText . '| ' . htmlspecialchars($e[$no]);
                     }
                 }
             }
             $i->add('DEBUG_ITEM_CODE', implode("\n", $lines));
             $items->append($i);
         }
         $items->pack();
         if ($exception) {
             $constants = get_defined_constants(true);
             //Debug::dump($constants);
             ksort($constants['user']);
             $items = new TPLLoop('DEBUG_CONSTANTS');
             foreach ($constants['user'] as $key => $value) {
                 $item = new TPLLoopItem();
                 $item->add('CONSTANT', $key);
                 $item->add('CONSTANT_VALUE', $value);
                 $items->append($item);
             }
             $items->pack();
         }
     }
     TPL::$dirpath = $o_dirpath;
 }
Esempio n. 4
0
 public function getOnlineUsers($count = 0, $groups = array(), $loop_key = 'ONLINE_USERS')
 {
     $sql = new SQLObject();
     $cfg = core::s('cfg');
     $query = "\r\nSELECT\r\n\t" . $sql->table('auth_users') . ".user_id AS user_id,\r\n\t" . $sql->table('auth_users') . ".user_username AS user_username,\r\n\t" . $sql->table('auth_users') . ".user_group_main AS user_group_main,\r\n\t" . $sql->table('auth_users') . ".session_last_time AS session_last_time,\r\n\t" . $sql->table('auth_groups') . ".group_name AS group_name\r\nFROM " . $sql->table('auth_users') . "\r\nLEFT JOIN " . $sql->table('auth_groups') . "\r\n\tON " . $sql->table('auth_users') . ".user_group_main = " . $sql->table('auth_groups') . ".group_id\r\nWHERE (session_last_time >= " . (time() - $cfg['etc']['core']['online_offset']);
     if ($groups) {
         $query .= " AND (";
         $i = 0;
         foreach ($groups as $group_id) {
             $query .= " user_groups LIKE '%" . $group_id . "%'";
             if ($i != count($groups) - 1) {
                 $query .= " AND";
             } else {
                 $query .= ")";
             }
             $i++;
         }
     }
     $query .= ") ORDER BY session_last_time DESC";
     if ($count) {
         $query .= " LIMIT 0," . (int) $count;
     }
     if (!$sql->query($query)) {
         TPL::cond($loop_key, false);
         core::s('tpl')->assignLoop($loop_key, array());
         echo $sql->error;
     } else {
         TPL::cond($loop_key, true);
         $users = new TPLLoop($loop_key);
         foreach ($sql->fetch() as $user) {
             $item = new TPLLoopItem();
             $item->add('USER_ID', $user->user_id);
             $item->add('USER_USERNAME', $user->user_username);
             $item->add('USER_GROUP', $user->user_group_main);
             $item->add('USER_SESSION_TIME_OFFSET', $this->getSessionTimeOffset($user->session_last_time));
             $item->cond('ADMIN', in_array(1, (array) $groups) || (int) $user->user_group_main == 1);
             $users->append($item);
         }
         $users->pack();
     }
 }