$prefix . '/posts', 'Pages' => $prefix . '/pages', 'Users' => $prefix . '/users', 'Metadata' => $prefix . '/metadata' ); return $pages; } /** Custom fields */ function parse_fields($str) { $data = json_decode($str, true); return is_array($data) ? $data : array(); } /** Url helpers */ function theme_url($file = '') { return Config::get('application.base_url') . 'system/admin/theme/' . ltrim($file, '/'); } function admin_url($url = '') { return Url::make(Config::get('application.admin_folder') . '/' . ltrim($url, '/')); } /** String helpers */ function pluralise($amount, $str, $alt = '') { return $amount === 1 ? $str : $str . ($alt !== '' ? $alt : 's'); } function truncate($str, $limit = 10, $elipse = ' [...]') { $words = preg_split('/\s+/', $str); if(count($words) <= $limit) { return $str; } return implode(' ', array_slice($words, 0, $limit)) . $elipse; } /** Error checking */ function latest_version() { // check we have curl support if(Curl::support() === false) { return 0; } // only run the version check once per session if(($version = Session::get('latest_version')) === false) { // returns plain text string with version number or 0 on failure. $version = "0.6"; Session::set('latest_version', $version); } return $version; } function error_check() { $errors = array(); // Check for older versions if(version_compare(VERSION, ($version = latest_version()), '<')) { $errors[] = 'Your version of Test CMS is out of date. Please download the latest version.'; } // do something useful with it return count($errors) ? $errors : false; } /** Benchmarking */ function execution_time() { $miliseconds = microtime(true) - START; return round($miliseconds, 4); } // return in mb function memory_usage() { return memory_get_peak_usage(true) / 1024; } // database profile information function db_profile() { // total query time $total = 0; $html = ''; $html .= ''; $html .= ''; $html .= ''; foreach(Db::profile() as $row) { $html .= ''; $total += $row['time']; } $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '
SQLBindingsRowsTime
' . $row['sql'] . '' . implode(', ', $row['binds']) . '' . $row['rows'] . '' . $row['time'] . '
Query Time' . round($total, 4) . '
Execution Time' . execution_time() . '
Memory Usage' . memory_usage() . 'Kb
'; return $html; }