Example #1
0
 public static function output(&$txt, $ap = "")
 {
     $o = Core::$core->output;
     Http::mime(!empty(self::$o['app']->mimetype) ? self::$o['app']->mimetype : 'text/' . ($o ? $o : 'html'), false);
     if ($o) {
         $c = @glob('vendor/phppe/*/out/' . $o . '_header.php');
         if (!empty($c[0])) {
             include_once $c[0];
         } elseif ($o == 'html') {
             $P = empty(Core::$core->nopanel) && Core::$user->has('panel');
             $I = basename(__FILE__) . '/';
             if ($I == 'index.php/') {
                 $I = '';
             }
             $d = 'http' . (Core::$core->sec ? 's' : '') . '://' . Core::$core->base;
             echo "<!DOCTYPE HTML>\n<html lang='" . Core::$client->lang . "'" . (!empty(Core::$l['rtl']) ? " dir='rtl'" : '') . '>' . '<head><title>' . (!empty(self::$o['app']->title) ? self::$o['app']->title : (Core::$core->title ? Core::$core->title : 'PHPPE' . VERSION)) . '</title>' . "<base href='{$d}'/><meta charset='utf-8'/>\n<meta name='Generator' content='PHPPE" . VERSION . "'/>\n";
             foreach (array_merge(self::$hdr['meta'], !empty(self::$o['app']->meta) ? self::$o['app']->meta : []) as $k => $m) {
                 if (!is_array($m)) {
                     $m = [$m, "name"];
                 }
                 if ($k && !empty($m[0]) && !empty($m[1])) {
                     echo "<meta " . $m[1] . "='{$k}' content='" . htmlspecialchars($m[0]) . "'/>\n";
                 }
             }
             self::$hdr['link'][!empty(self::$o['app']->favicon) ? self::$o['app']->favicon : 'favicon.ico'] = 'shortcut icon';
             foreach (self::$hdr['link'] as $k => $m) {
                 if (!empty($m) && $m != 'js') {
                     echo "<link rel='{$m}' href='" . $k . "'/>\n";
                 }
             }
             $O = "<style media='all'>\n";
             $d = "@import url('%s');\n";
             $N = Core::$core->base . Core::$core->url . '/' . Core::$user->id . '/' . Core::$client->lang;
             $e = 'css';
             if ($P) {
                 $O .= sprintf($d, $I . "?cache={$e}");
             }
             if (!empty(self::$hdr['css'])) {
                 if (!empty(Cache::$mc) && empty(Core::$core->noaggr)) {
                     $n = sha1($N . "_{$e}");
                     if (empty(Cache::get("c_{$n}", true))) {
                         $da = '';
                         foreach (self::$hdr['css'] as $u => $v) {
                             if ($v && substr($v, -3) != 'php' && $u[0] != '?') {
                                 $da .= Assets::minify(file_get_contents($v), $e) . "\n";
                             }
                         }
                         Cache::set("c_{$n}", ['m' => "text/{$e}", 'd' => $da], 0, true);
                     }
                     $O .= sprintf($d, $I . "?cache={$n}");
                     foreach (self::$hdr['css'] as $u => $v) {
                         if ($v && ($u[0] == '?' || substr($v, -3) == 'php')) {
                             $O .= sprintf($d, ($u[0] == '?' ? '' : $I . "{$e}/") . $u);
                         }
                     }
                 } else {
                     foreach (self::$hdr['css'] as $u => $v) {
                         if ($v) {
                             $O .= sprintf($d, ($u[0] == '?' ? '' : $I . "{$e}/") . $u);
                         }
                     }
                 }
             }
             $O .= "</style>\n";
             echo "{$O}</head>\n<body>\n";
             if ($P) {
                 $H = " class='sub' style='visibility:hidden;' onmousemove='return pe_w();'";
                 $O = "<div id='pe_p'><a href='" . url('/') . "'><img src='{$I}?cache=logo' alt='PHPPE" . VERSION . "' style='margin:3px 10px -3px 10px;float:left;'></a><div class='menu'>";
                 $x = 0;
                 if (!empty(self::$menu)) {
                     foreach (self::$menu as $e => $L) {
                         @(list($ti, $a) = explode('@', $e));
                         if ($a && !Core::$user->has($a)) {
                             continue;
                         }
                         $a = 0;
                         if (is_array($L)) {
                             $l = $L[array_keys($L)[0]];
                         } else {
                             $l = $L;
                         }
                         $U = Core::$core->url;
                         if (substr($l, 0, strlen($U)) == $U) {
                             $a = 1;
                         } else {
                             $d = explode('/', $l);
                             if ((!empty($ap) ? $ap : Core::$core->app) == (!empty($d[0]) ? $d[0] : 'index')) {
                                 $a = 1;
                             }
                             unset($d);
                         }
                         if (is_array($L)) {
                             $O .= "<div id='pe_m{$x}'{$H}><ul>";
                             foreach ($L as $t => $l) {
                                 if ($t) {
                                     @(list($Y, $A) = explode('@', $t));
                                     if (empty($A) || Core::$user->has($A)) {
                                         $O .= "<li onclick=\"document.location.href='" . $I . "{$l}';\"><a href='" . $I . "{$l}'>" . htmlspecialchars(L($Y)) . '</a></li>';
                                     }
                                 }
                             }
                             $O .= "</ul></div><span class='menu_" . ($a ? 'a' : 'i') . "' onclick='return pe_p(\"pe_m{$x}\");'>" . htmlspecialchars(L($ti)) . '</span>';
                             ++$x;
                         } else {
                             $O .= "<span class='menu_" . ($a ? 'a' : 'i') . "'><a href='" . $I . "{$L}'>" . htmlspecialchars(L($ti)) . '</a></span>';
                         }
                     }
                 }
                 $O .= "</div><div class='stat'>";
                 foreach (Core::lib() as $d) {
                     if (method_exists($d, 'stat')) {
                         $O .= '<span>' . $d->stat() . '</span>';
                     }
                 }
                 $O .= "<div id='pe_l'{$H}><ul>";
                 if (!empty($_SESSION['pe_ls']) && count($_SESSION['pe_ls']) > 1) {
                     $d = $_SESSION['pe_ls'];
                 } else {
                     $D = @scandir('app/lang');
                     if (!is_array($D)) {
                         $D = [];
                     }
                     $d = @scandir('vendor/phppe/Core/lang');
                     if (is_array($d)) {
                         $D = array_unique($D + $d);
                     }
                     $d = [];
                     foreach ($D as $f) {
                         if (substr($f, -4) == '.php') {
                             $d[substr($f, 0, strlen($f) - 4)] = 1;
                         }
                     }
                     $_SESSION['pe_ls'] = $d;
                 }
                 foreach ($d as $k => $v) {
                     if ($k) {
                         $O .= "<li><a href='" . url() . "?lang={$k}'><img src='images/lang_{$k}.png' alt='{$k}' title='{$k}'>" . ($k != L($k) ? '&nbsp;' . L($k) : '') . '</a></li>';
                     }
                 }
                 $O .= '</ul></div>';
                 $k = Core::$client->lang;
                 $f = "images/lang_{$k}.png";
                 $c = !empty($_SESSION['pe_c']);
                 $O .= "<span onclick='return pe_p(\"pe_l\");'>" . (file_exists('vendor/phppe/Core/' . $f) ? "<img src='{$f}' height='10' alt='{$k}' title='{$k}'>" : $k) . '</span>' . "<div id='pe_u'{$H}><ul><li onclick='pe_p(\"\");if(typeof(users.profile)==\"function\")users.profile(this);else alert(\"" . L('Install PHPPE Pack') . "\");'>" . L('Profile') . '</li>' . (Core::$user->has('conf') ? "<li><a href='" . url() . '?conf=' . (1 - $c) . "'>" . ($c ? L('Lock') : L('Unlock')) . '</a></li>' : '') . "<li><a href='" . url('logout') . "'>" . L('Logout') . '</a></li></ul></div>' . "<span onclick='return pe_p(\"pe_u\");'>" . (!empty(Core::$user->name) ? Core::$user->name : '#' . Core::$user->id) . '</span></div></div>' . "<div style='height:32px !important;'></div>\n";
                 echo $O;
             }
         }
     }
     echo $txt;
     if ($o) {
         $c = @glob('vendor/phppe/*/out/' . $o . '_footer.php');
         if (!empty($c[0])) {
             include_once $c[0];
         } elseif ($o == 'html') {
             $d = '<script';
             $e = "</script>\n";
             $a = " src='" . $I . 'js/';
             $O = '';
             if (!empty(self::$hdr['jslib'])) {
                 if (!empty(Cache::$mc) && empty(Core::$core->noaggr)) {
                     $n = sha1($N . '_js');
                     if (empty(Cache::get("c_{$n}", true))) {
                         $da = '';
                         foreach (self::$hdr['jslib'] as $u => $v) {
                             if ($v && substr($v, -3) != 'php' && substr($u, 0, 4) != 'http') {
                                 $da .= Assets::minify(file_get_contents(substr($v, 2)), 'js') . "\n";
                             }
                         }
                         Cache::set("c_{$n}", ['m' => 'text/javascript', 'd' => $da], 0, true);
                     }
                     $O .= "{$d} src='{$I}js/?cache={$n}'>{$e}";
                     foreach (self::$hdr['jslib'] as $u => $v) {
                         if (substr($u, 0, 4) == 'http') {
                             $O .= "{$d} src='{$u}'>{$e}";
                         } elseif ($u[0] == '?' || substr($v, -3) == 'php') {
                             $O .= "{$d}{$a}{$u}'>{$e}";
                         }
                     }
                 } else {
                     foreach (self::$hdr['jslib'] as $u => $v) {
                         if (substr($u, 0, 4) == 'http') {
                             $O .= "{$d} src='{$u}'>{$e}";
                         } else {
                             $O .= "{$d}{$a}{$u}'>{$e}";
                         }
                     }
                 }
             }
             $c = 'users.js';
             $i = file_exists('vendor/phppe/Core/js/' . $c . '.php');
             if ($P && !isset(self::$hdr['jslib'][$c]) && $i) {
                 $O .= "{$d}{$a}{$c}'>{$e}";
             }
             $c = self::$hdr['js'];
             $a = '';
             if (!$i) {
                 $x = 'document.getElementById(';
                 $y = '.style.visibility';
                 $a = "pe_t=setTimeout(function(){pe_p('');},2000)";
                 $c['L(t)'] = "return t.replace(/_/g,' ');";
                 $c['pe_p(i)'] = "var o=i?{$x}i):i;if(pe_t!=null)clearTimeout(pe_t);if(pe_c&&pe_c!=i){$x}pe_c){$y}='hidden';pe_t=pe_c=null;if(o!=null&&o.style!=null){if(o{$y}=='visible')o{$y}='hidden';else{o{$y}='visible';pe_c=i;{$a};}}return false;";
                 $c['pe_w()'] = "if(pe_t!=null)clearTimeout(pe_t);{$a};return false;";
                 $a = ',pe_t,pe_c,pe_h=0';
             }
             if (!empty($c)) {
                 $O .= $d . ">\nvar pe_i=0,pe_ot=" . ($P ? 31 : 0) . "{$a};\n";
                 foreach ($c as $fu => $co) {
                     $O .= "function {$fu} {" . ($fu == "init()" ? "if(pe_i)return;pe_i=1;" . (Core::$core->runlevel > 2 ? "console.log('PE Plugins',pe);" : "") : "") . $co . "}\n";
                 }
                 if (!empty(self::$hdr['js']['init()'])) {
                     $O .= "document.addEventListener('DOMContentLoaded', init);window.addEventListener('load', init);setTimeout(init,100);";
                 }
                 $O .= $e;
             }
             $s = Core::started();
             $d = 'REQUEST_TIME_FLOAT';
             $T = !empty($_SERVER[$d]) ? $_SERVER[$d] : $s;
             echo "\n{$O}<!-- MONITORING: " . (Core::isError() ? 'ERROR' : (Core::$core->runlevel > 0 ? 'WARNING' : 'OK')) . ', page ' . sprintf("%.4f sec, db %.4f sec, server %.4f sec, mem %.4f mb%s -->\n</body>\n</html>\n", microtime(1) - $T, DS::bill(), $s - $T, memory_get_peak_usage() / 1024 / 1024, !empty(Cache::$mc) && empty(Core::$core->nocache) ? ', mc' : '');
         }
     }
     flush();
 }