"success", "warning" => "warning-msg", "error" => "error", "message" => "message", "static" => "static-msg"); # Auth check public static function check($permissions) { global $core; if ($core->blog && $core->auth->check($permissions,$core->blog->id)) { return; } if (session_id()) { $core->session->destroy(); } http::redirect(DC_AUTH_PAGE); } # Check super admin public static function checkSuper() { global $core; if (!$core->auth->isSuperAdmin()) { if (session_id()) { $core->session->destroy(); } http::redirect(DC_AUTH_PAGE); } } # Top of admin page public static function open($title='',$head='',$breadcrumb='',$options=array()) { global $core; # List of user's blogs if ($core->auth->getBlogCount() == 1 || $core->auth->getBlogCount() > 20) { $blog_box = '

'.__('Blog:').' '. html::escapeHTML($core->blog->name).''; if ($core->auth->getBlogCount() > 20) { $blog_box .= ' - '.__('Change blog').''; } $blog_box .= '

'; } else { $rs_blogs = $core->getBlogs(array('order'=>'LOWER(blog_name)','limit'=>20)); $blogs = array(); while ($rs_blogs->fetch()) { $blogs[html::escapeHTML($rs_blogs->blog_name.' - '.$rs_blogs->blog_url)] = $rs_blogs->blog_id; } $blog_box = '

'. $core->formNonce(). form::combo('switchblog',$blogs,$core->blog->id). '

'; } $safe_mode = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode']; # Display header('Content-Type: text/html; charset=UTF-8'); // Prevents Clickjacking as far as possible if (isset($options['x-frame-allow'])) { self::setXFrameOptions($options['x-frame-allow']); } else { self::setXFrameOptions(); } echo ''. ''."\n". "\n". ' '."\n". ' '."\n". ' '."\n". ' '."\n". ' '.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.''."\n". self::jsLoadIE7(). ' '."\n"; if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') { echo ' '."\n"; } $core->auth->user_prefs->addWorkspace('interface'); $user_ui_hide_std_favicon = $core->auth->user_prefs->interface->hide_std_favicon; if (!$user_ui_hide_std_favicon) { echo ''. ''; } echo self::jsCommon(). self::jsToggles(). $head; # --BEHAVIOR-- adminPageHTMLHead $core->callBehavior('adminPageHTMLHead'); echo "\n". ''."\n". ''."\n". ''; // end header echo '
'."\n". '
'. ''.__('Hide main menu').''. ''.__('Show main menu').''. '
'. '
'."\n". '
'."\n"; # Safe mode if ($safe_mode) { echo ''; } // Display breadcrumb (if given) before any error message echo $breadcrumb; if ($core->error->flag()) { echo '

'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'

'. $core->error->toHTML(). '
'; } // Display notices echo self::notices(); } public static function notices() { // return notices if any $res = ''; if (isset($_SESSION['notifications'])) { $notifications = $_SESSION['notifications']; foreach ($_SESSION['notifications'] as $notification) { $res .= self::getNotification($notification); } unset($_SESSION['notifications']); } return $res; } public static function addNotice($type,$message,$options=array()) { if (isset(self::$N_TYPES[$type])){ $class = self::$N_TYPES[$type]; } else { $class=$type; } if (isset($_SESSION['notifications']) && is_array($_SESSION['notifications'])) { $notifications = $_SESSION['notifications']; } else { $notifications = array(); } $n = array_merge($options,array('class' => $class,'ts' => time(), 'text' => $message)); if ($type != "static") { $notifications[] = $n; } else { array_unshift($notifications, $n); } $_SESSION['notifications'] = $notifications; } public static function addSuccessNotice($message,$options=array()) { self::addNotice("success",$message,$options); } public static function addWarningNotice($message,$options=array()) { self::addNotice("warning",$message,$options); } public static function addErrorNotice($message,$options=array()) { self::addNotice("error",$message,$options); } protected static function getNotification($n) { global $core; $tag = (isset($n['divtag'])&& $n['divtag'])?'div':'p'; $ts = ''; if (!isset($n['with_ts']) || ($n['with_ts'] == true)) { $ts = dt::str(__('[%H:%M:%S]'),$n['ts'],$core->auth->getInfo('user_tz')).' '; } $res = '<'.$tag.' class="'.$n['class'].'" role="alert">'.$ts.$n['text'].''; return $res; } public static function close() { global $core; if (!$GLOBALS['__resources']['ctxhelp']) { echo '

'.__('Global help').'

'; } $menu =& $GLOBALS['_menu']; echo "
\n". // End of #content "
\n". // End of #main ''."\n". // End of #main-menu "
\n"; // End of #wrapper echo ''."\n". ""."\n"; if (defined('DC_DEV') && DC_DEV === true) { echo self::debugInfo(); } echo ''; } public static function openPopup($title='',$head='',$breadcrumb='') { global $core; # Display header('Content-Type: text/html; charset=UTF-8'); // Prevents Clickjacking as far as possible header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+ echo ''. ''."\n". "\n". ' '."\n". ' '."\n". ' '.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.''."\n". ' '."\n". ' '."\n". self::jsLoadIE7(). ' '."\n"; if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') { echo ' '."\n"; } echo self::jsCommon(). self::jsToggles(). $head; # --BEHAVIOR-- adminPageHTMLHead $core->callBehavior('adminPageHTMLHead'); echo "\n". ''."\n". '

'.DC_VENDOR_NAME.'

'."\n"; echo '
'."\n". '
'."\n". '
'."\n"; // display breadcrumb if given echo $breadcrumb; if ($core->error->flag()) { echo ''; } } public static function closePopup() { echo "
\n". // End of #content "
\n". // End of #main "
\n". // End of #wrapper ''."\n". ''; } public static function breadcrumb($elements=null,$options=array()) { global $core; $with_home_link = isset($options['home_link'])?$options['home_link']:true; $hl = isset($options['hl'])?$options['hl']:true; $hl_pos = isset($options['hl_pos'])?$options['hl_pos']:-1; // First item of array elements should be blog's name, System or Plugins $res = '

'.($with_home_link ? ''.__('Go to dashboard').'' : ''); $index = 0; if ($hl_pos < 0) { $hl_pos = count($elements)+$hl_pos; } foreach ($elements as $element => $url) { if ($hl && $index == $hl_pos) { $element = sprintf('%s',$element); } $res .= ($with_home_link ? ($index == 1 ? ' : ' : ' › ') : ($index == 0 ? ' ' : ' › ')). ($url ? '' : '').$element.($url ? '' : ''); $index++; } $res .= '

'; return $res; } public static function message($msg,$timestamp=true,$div=false,$echo=true,$class='message') { global $core; $res = ''; if ($msg != '') { $res = ($div ? '
' : '').''. ($timestamp ? dt::str(__('[%H:%M:%S]'),null,$core->auth->getInfo('user_tz')).' ' : '').$msg. '

'.($div ? '
' : ''); if ($echo) { echo $res; } } return $res; } public static function success($msg,$timestamp=true,$div=false,$echo=true) { return self::message($msg,$timestamp,$div,$echo,"success"); } public static function warning($msg,$timestamp=true,$div=false,$echo=true) { return self::message($msg,$timestamp,$div,$echo,"warning-msg"); } private static function debugInfo() { $global_vars = implode(', ',array_keys($GLOBALS)); $res = '
'. '

memory usage: '.memory_get_usage().' ('.files::size(memory_get_usage()).')

'; if (function_exists('xdebug_get_profiler_filename')) { $res .= '

Elapsed time: '.xdebug_time_index().' seconds

'; $prof_file = xdebug_get_profiler_filename(); if ($prof_file) { $res .= '

Profiler file : '.xdebug_get_profiler_filename().'

'; } else { $prof_url = http::getSelfURI(); $prof_url .= (strpos($prof_url,'?') === false) ? '?' : '&'; $prof_url .= 'XDEBUG_PROFILE'; $res .= '

Trigger profiler

'; } /* xdebug configuration: zend_extension = /.../xdebug.so xdebug.auto_trace = On xdebug.trace_format = 0 xdebug.trace_options = 1 xdebug.show_mem_delta = On xdebug.profiler_enable = 0 xdebug.profiler_enable_trigger = 1 xdebug.profiler_output_dir = /tmp xdebug.profiler_append = 0 xdebug.profiler_output_name = timestamp */ } $res .= '

Global vars: '.$global_vars.'

'. '
'; return $res; } public static function help($page,$index='') { # Deprecated but we keep this for plugins. } public static function helpBlock() { global $core; $args = func_get_args(); $args = new ArrayObject($args); # --BEHAVIOR-- adminPageHelpBlock $GLOBALS['core']->callBehavior('adminPageHelpBlock',$args); if (empty($args)) { return; }; global $__resources; if (empty($__resources['help'])) { return; } $content = ''; foreach ($args as $v) { if (is_object($v) && isset($v->content)) { $content .= $v->content; continue; } if (!isset($__resources['help'][$v])) { continue; } $f = $__resources['help'][$v]; if (!file_exists($f) || !is_readable($f)) { continue; } $fc = file_get_contents($f); if (preg_match('|]*?>(.*?)|ms',$fc,$matches)) { $content .= $matches[1]; } else { $content .= $fc; } } if (trim($content) == '') { return; } // Set contextual help global flag $GLOBALS['__resources']['ctxhelp'] = true; echo '

'.__('Help about this page').'

'. $content. '
'. '
'; } public static function jsLoad($src) { $escaped_src = html::escapeHTML($src); if (!isset(self::$loaded_js[$escaped_src])) { self::$loaded_js[$escaped_src]=true; return ''."\n"; } } public static function jsVar($n,$v) { return $n." = '".html::escapeJS($v)."';\n"; } public static function jsToggles() { if($GLOBALS['core']->auth->user_prefs->toggles) { $unfolded_sections = explode(',',$GLOBALS['core']->auth->user_prefs->toggles->unfolded_sections); foreach ($unfolded_sections as $k=>&$v) { if ($v == '') { unset($unfolded_sections[$k]); } else { $v = "'".html::escapeJS($v)."':true"; } } } else { $unfolded_sections=array(); } return '\n"; } public static function jsCommon() { $mute_or_no = ''; if (empty($GLOBALS['core']->blog) || $GLOBALS['core']->blog->settings->system->jquery_migrate_mute) { $mute_or_no .= '\n"; } return self::jsLoad('js/jquery/jquery.js'). $mute_or_no. self::jsLoad('js/jquery/jquery-migrate-1.2.1.js'). self::jsLoad('js/jquery/jquery.biscuit.js'). self::jsLoad('js/jquery/jquery.bgFade.js'). self::jsLoad('js/common.js'). self::jsLoad('js/prelude.js'). '\n"; } public static function jsLoadIE7() { return ''."\n"; } public static function jsConfirmClose() { $args = func_get_args(); if (count($args) > 0) { foreach ($args as $k => $v) { $args[$k] = "'".html::escapeJS($v)."'"; } $args = implode(',',$args); } else { $args = ''; } return self::jsLoad('js/confirm-close.js'). '\n"; } public static function jsPageTabs($default=null) { if ($default) { $default = "'".html::escapeJS($default)."'"; } return self::jsLoad('js/jquery/jquery.pageTabs.js'). '\n". ''."\n"; } public static function jsModal() { return ''."\n". self::jsLoad('js/jquery/jquery.modal.js'). '\n"; } public static function jsColorPicker() { return ''."\n". self::jsLoad('js/jquery/jquery.farbtastic.js'). self::jsLoad('js/color-picker.js'); } public static function jsDatePicker() { return ''."\n". self::jsLoad('js/date-picker.js'). '\n"; } public static function jsToolBar() { # Deprecated but we keep this for plugins. } public static function jsUpload($params=array(),$base_url=null) { if (!$base_url) { $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/','',$_SERVER['REQUEST_URI']))).'/'; } $params = array_merge($params,array( 'sess_id='.session_id(), 'sess_uid='.$_SESSION['sess_browser_uid'], 'xd_check='.$GLOBALS['core']->getNonce() )); return '\n". self::jsLoad('js/jsUpload/vendor/jquery.ui.widget.js'). self::jsLoad('js/jsUpload/tmpl.js'). self::jsLoad('js/jsUpload/template-upload.js'). self::jsLoad('js/jsUpload/template-download.js'). self::jsLoad('js/jsUpload/load-image.js'). self::jsLoad('js/jsUpload/jquery.iframe-transport.js'). self::jsLoad('js/jsUpload/jquery.fileupload.js'). self::jsLoad('js/jsUpload/jquery.fileupload-process.js'). self::jsLoad('js/jsUpload/jquery.fileupload-resize.js'). self::jsLoad('js/jsUpload/jquery.fileupload-ui.js'); } public static function jsToolMan() { return ''. ''. ''. ''. ''. ''. ''; } public static function jsMetaEditor() { return ''; } public static function getPF($file) { return $GLOBALS['core']->adminurl->get('load.plugin.file',array('pf' => $file)); } public static function setXFrameOptions($origin=null) { if (self::$xframe_loaded) { return; } if ($origin !== null) { $url = parse_url($origin); header(sprintf('X-Frame-Options: %s', is_array($url)?("ALLOW-FROM ".$url['scheme'].'://'.$url['host']):'SAMEORIGIN')); } else { header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+ } self::$xframe_loaded = true; } }