isAdminLoggedIn() public method

Returns whether or not the viewer is currently logged in and an admin user.
public isAdminLoggedIn ( ) : boolean
return boolean
Esempio n. 1
0
 /**
  * Sends a notice about deprecated use of a function, view, etc.
  *
  * @param string $msg             Message to log / display.
  * @param string $dep_version     Human-readable *release* version: 1.7, 1.8, ...
  * @param int    $backtrace_level How many levels back to display the backtrace.
  *                                Useful if calling from functions that are called
  *                                from other places (like elgg_view()). Set to -1
  *                                for a full backtrace.
  * @return bool
  */
 function sendNotice($msg, $dep_version, $backtrace_level = 1)
 {
     // if it's a major release behind, visual and logged
     // if it's a 1 minor release behind, visual and logged
     // if it's for current minor release, logged.
     // bugfixes don't matter because we are not deprecating between them
     if (!$dep_version) {
         return false;
     }
     $elgg_version = elgg_get_version(true);
     $elgg_version_arr = explode('.', $elgg_version);
     $elgg_major_version = (int) $elgg_version_arr[0];
     $elgg_minor_version = (int) $elgg_version_arr[1];
     $dep_version_arr = explode('.', (string) $dep_version);
     $dep_major_version = (int) $dep_version_arr[0];
     $dep_minor_version = (int) $dep_version_arr[1];
     $visual = false;
     if ($dep_major_version < $elgg_major_version || $dep_minor_version < $elgg_minor_version) {
         $visual = true;
     }
     $msg = "Deprecated in {$dep_major_version}.{$dep_minor_version}: {$msg}";
     if ($visual && $this->session->isAdminLoggedIn()) {
         register_error($msg);
     }
     // Get a file and line number for the log. Never show this in the UI.
     // Skip over the function that sent this notice and see who called the deprecated
     // function itself.
     $msg .= " Called from ";
     $stack = array();
     $backtrace = debug_backtrace();
     // never show this call.
     array_shift($backtrace);
     $i = count($backtrace);
     foreach ($backtrace as $trace) {
         $stack[] = "[#{$i}] {$trace['file']}:{$trace['line']}";
         $i--;
         if ($backtrace_level > 0) {
             if ($backtrace_level <= 1) {
                 break;
             }
             $backtrace_level--;
         }
     }
     $msg .= implode("<br /> -> ", $stack);
     $this->logger->warn($msg);
     return true;
 }