1 <?php
defined('IN_CMS') or die('No direct access allowed.');
6 function admin_menu() {
8 $prefix = Config
::get('application.admin_folder');
11 'Posts' => $prefix . '/posts',
12 'Pages' => $prefix . '/pages',
13 'Users' => $prefix . '/users',
14 'Metadata' => $prefix . '/metadata'
23 function parse_fields($str) {
24 $data = json_decode($str, true);
25 return is_array($data) ?
$data : array();
31 function theme_url($file = '') {
32 return Config
::get('application.base_url') . 'system/admin/theme/' . ltrim($file, '/');
35 function admin_url($url = '') {
36 return Url
::make(Config
::get('application.admin_folder') . '/' . ltrim($url, '/'));
42 function pluralise($amount, $str, $alt = '') {
43 return $amount === 1 ?
$str : $str . ($alt !== '' ?
$alt : 's');
46 function truncate($str, $limit = 10, $elipse = ' [...]') {
47 $words = preg_split('/\s+/', $str);
49 if(count($words) <= $limit) {
53 return implode(' ', array_slice($words, 0, $limit)) . $elipse;
59 function latest_version() {
60 // check we have curl support
61 if(Curl
::support() === false) {
65 // only run the version check once per session
66 if(($version = Session
::get('latest_version')) === false) {
67 // returns plain text string with version number or 0 on failure.
69 Session
::set('latest_version', $version);
75 function error_check() {
78 // Check for older versions
79 if(version_compare(VERSION
, ($version = latest_version()), '<')) {
80 $errors[] = 'Your version of Test CMS is out of date. Please <a href="http://google.com">download the latest version</a>.';
83 // do something useful with it
84 return count($errors) ?
$errors : false;
90 function execution_time() {
91 $miliseconds = microtime(true) - START
;
92 return round($miliseconds, 4);
96 function memory_usage() {
97 return memory_get_peak_usage(true) / 1024;
100 // database profile information
101 function db_profile() {
106 $html .= '<table id="debug_table" class="debug">';
107 $html .= '<thead><tr><th>SQL</th><th>Bindings</th><th>Rows</th><th>Time</th></th></thead>';
111 foreach(Db
::profile() as $row) {
112 $html .= '<tr><td>' . $row['sql'] . '</td><td>' . implode(', ', $row['binds']) . '</td><td>' . $row['rows'] . '</td><td>' . $row['time'] . '</td></tr>';
113 $total +
= $row['time'];
119 $html .= '<tr><td colspan="3"><strong>Query Time</strong></td><td>' . round($total, 4) . '</td></tr>';
120 $html .= '<tr><td colspan="3"><strong>Execution Time</strong></td><td>' . execution_time() . '</td></tr>';
121 $html .= '<tr><td colspan="3"><strong>Memory Usage</strong></td><td>' . memory_usage() . 'Kb</td></tr>';