public function __construct($args)
 {
     global $langmessage, $config, $contact_message_sent, $message_send_attempt;
     parent::__construct($args);
     $this->sent = $contact_message_sent;
     if (empty($config['toemail'])) {
         if (\gp\tool::LoggedIn()) {
             $url = \gp\tool::GetUrl('Admin_Configuration');
             msg($langmessage['enable_contact'], $url);
         }
         echo $langmessage['not_enabled'];
         return;
     }
     $cmd = \gp\tool::GetCommand();
     switch ($cmd) {
         case 'gp_send_message':
             if (!$message_send_attempt) {
                 $message_send_attempt = true;
                 if (!$this->sent && $this->SendMessage()) {
                     $this->sent = $contact_message_sent = true;
                     break;
                 }
             }
         default:
             break;
     }
     $this->ShowForm();
 }
Beispiel #2
0
 public function RunScript()
 {
     global $gp_index, $langmessage;
     $scriptinfo = self::GetScriptInfo($this->title);
     if ($scriptinfo === false) {
         switch ($this->title) {
             case 'Special_ExtraJS':
                 $this->ExtraJS();
                 //dies
         }
         $this->Error_404($this->title);
         return;
     }
     $this->gp_index = $gp_index[$this->title];
     $this->TitleInfo = $scriptinfo;
     if (!$this->CheckVisibility()) {
         return false;
     }
     //allow addons to affect page actions and how a page is displayed
     $cmd = \gp\tool::GetCommand();
     $cmd_after = \gp\tool\Plugins::Filter('PageRunScript', array($cmd));
     if ($cmd !== $cmd_after) {
         $cmd = $cmd_after;
         if ($cmd === 'return') {
             return;
         }
     }
     if (\gp\tool::LoggedIn() && \gp\admin\Tools::HasPermission('Admin_Menu')) {
         $this->cmds['RenameForm'] = '\\gp\\Page\\Rename::RenameForm';
         $this->cmds['RenameFile'] = '\\gp\\Page\\Rename::RenamePage';
         $this->cmds['ToggleVisibility'] = array('\\gp\\Page\\Visibility::TogglePage', 'DefaultDisplay');
         $this->cmds['ManageSections'] = '\\gp\\Page\\Edit::ManageSections';
     }
     $this->RunCommands($cmd);
 }
Beispiel #3
0
 /**
  * Handle the processing of multiple less files into css
  *
  * @return mixed Compiled css string or false
  *
  */
 static function ParseLess(&$less_files)
 {
     global $dataDir;
     $compiled = false;
     // don't use less if the memory limit is less than 64M
     $limit = @ini_get('memory_limit');
     if ($limit) {
         $limit = \gp\tool::getByteValue($limit);
         //if less than 64M, disable less compiler if we can't increase
         if ($limit < 67108864 && @ini_set('memory_limit', '96M') === false) {
             if (\gp\tool::LoggedIn()) {
                 msg('LESS compilation disabled. Please increase php\'s memory_limit');
             }
             return false;
             //if less than 96M, try to increase
         } elseif ($limit < 100663296) {
             @ini_set('memory_limit', '96M');
         }
     }
     //compiler options
     $options = array();
     //prepare the compiler
     includeFile('thirdparty/less.php/Less.php');
     $parser = new \Less_Parser($options);
     $import_dirs[$dataDir] = \gp\tool::GetDir('/');
     $parser->SetImportDirs($import_dirs);
     $parser->cache_method = 'php';
     $parser->SetCacheDir($dataDir . '/data/_cache');
     // combine files
     try {
         foreach ($less_files as $less) {
             //treat as less markup if there are newline characters
             if (strpos($less, "\n") !== false) {
                 $parser->Parse($less);
                 continue;
             }
             // handle relative and absolute paths
             if (!empty($dataDir) && strpos($less, $dataDir) === false) {
                 $relative = $less;
                 $less = $dataDir . '/' . ltrim($less, '/');
             } else {
                 $relative = substr($less, strlen($dataDir));
             }
             $parser->ParseFile($less, \gp\tool::GetDir(dirname($relative)));
         }
         $compiled = $parser->getCss();
     } catch (Exception $e) {
         if (\gp\tool::LoggedIn()) {
             msg('LESS Compile Failed: ' . $e->getMessage());
         }
         return false;
     }
     // significant difference in used memory 15,000,000 -> 6,000,000. Max still @ 15,000,000
     if (function_exists('gc_collect_cycles')) {
         gc_collect_cycles();
     }
     $less_files = $parser->allParsedFiles();
     return $compiled;
 }
Beispiel #4
0
 /**
  * Check the page's visibility
  *
  */
 function CheckVisibility()
 {
     global $gp_titles;
     if (isset($gp_titles[$this->gp_index]['vis'])) {
         $this->visibility = $gp_titles[$this->gp_index]['vis'];
     }
     if (!\gp\tool::LoggedIn() && $this->visibility) {
         $this->Error_404($this->title);
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Include the content of a page or gadget as specified in $data
  * @param array $data
  * @param string The included content
  */
 static function IncludeContent($data)
 {
     global $langmessage, $gp_index;
     if (isset($data['index'])) {
         $requested = \gp\tool::IndexToTitle($data['index']);
     } else {
         $requested = $data['content'];
     }
     if (empty($requested)) {
         return '<p>' . $langmessage['File Include'] . '</p>';
     }
     if (self::$title == $requested) {
         if (\gp\tool::LoggedIn()) {
             msg('Infinite loop detected: ' . htmlspecialchars($requested));
         }
         return;
     }
     if (isset($data['include_type'])) {
         $type = $data['include_type'];
     } else {
         $type = \gp\tool::SpecialOrAdmin($requested);
     }
     switch ($type) {
         case 'gadget':
             return self::IncludeGadget($requested);
         case 'special':
             return self::IncludeSpecial($requested);
         default:
             return self::IncludePage($requested);
     }
 }
Beispiel #6
0
defined('is_running') or define('is_running', true);
require_once 'common.php';
\gp\tool::EntryPoint(0);
/*
 *	Flow Control
 */
if (!empty($GLOBALS['config']['updating_message'])) {
    die($GLOBALS['config']['updating_message']);
}
$title = \gp\tool::WhichPage();
$type = \gp\tool::SpecialOrAdmin($title);
switch ($type) {
    case 'special':
        $page = new \gp\special\Page($title, $type);
        break;
    case 'admin':
        if (\gp\tool::LoggedIn()) {
            $page = new \gp\admin\Page($title, $type);
        } else {
            $page = new \gp\admin\Login($title, $type);
        }
        break;
    default:
        if (\gp\tool::LoggedIn()) {
            $page = new \gp\Page\Edit($title, $type);
        } else {
            $page = new \gp\Page($title, $type);
        }
        break;
}
\gp\tool\Output::RunOut();
Beispiel #7
0
 /**
  * Send content of all files in the $scripts array to the client
  *
  */
 static function SendScripts($scripts)
 {
     global $dataDir, $dirPrefix;
     self::Header();
     Header('Vary: Accept,Accept-Encoding');
     // for proxies
     $sent = array();
     $scripts = self::RemoveSent($scripts);
     //send all scripts
     foreach ($scripts as $script) {
         if (is_array($script)) {
             if (!empty($script['code'])) {
                 echo "\n\n/** Code **/\n\n";
                 echo $script['code'];
             }
             if (empty($script['file'])) {
                 continue;
             }
             $script = $script['file'];
         }
         //absolute paths don't need $dataDir
         $full_path = $script;
         if (!empty($dataDir) && strpos($script, $dataDir) !== 0) {
             //fix addon paths that use $addonRelativeCode
             if (!empty($dirPrefix) && strpos($script, $dirPrefix) === 0) {
                 $script = substr($script, strlen($dirPrefix));
             }
             $full_path = $dataDir . $script;
         }
         //only send each script once
         if (isset($sent[$full_path])) {
             continue;
         }
         $sent[$full_path] = true;
         if (!file_exists($full_path)) {
             if (\gp\tool::LoggedIn()) {
                 $msg = 'Admin Notice: The following file could not be found: \\n\\n' . $full_path;
                 echo 'if(isadmin){alert(' . json_encode($msg) . ');}';
             }
             continue;
         }
         echo "\n\n/** {$script} **/\n\n";
         readfile($full_path);
     }
 }
Beispiel #8
0
 public static function RunOut()
 {
     global $page;
     $page->RunScript();
     //prepare the admin content
     if (\gp\tool::LoggedIn()) {
         \gp\admin\Tools::AdminHtml();
     }
     //decide how to send the content
     self::Prep();
     switch (\gp\tool::RequestType()) {
         // <a data-cmd="admin_box">
         case 'flush':
             self::Flush();
             break;
             // remote request
             // file browser
         // remote request
         // file browser
         case 'body':
             \gp\tool::CheckTheme();
             self::BodyAsHTML();
             break;
         case 'admin':
             self::AdminHtml();
             break;
             // <a data-cmd="gpajax">
             // <a data-cmd="gpabox">
             // <input data-cmd="gpabox">
         // <a data-cmd="gpajax">
         // <a data-cmd="gpabox">
         // <input data-cmd="gpabox">
         case 'json':
             \gp\tool::CheckTheme();
             \gp\tool\Output\Ajax::Response();
             break;
         case 'content':
             self::Content();
             break;
         default:
             \gp\tool::CheckTheme();
             self::Template();
             break;
     }
     // if logged in, don't send 304 response
     if (\gp\tool::LoggedIn()) {
         //empty edit links if there isn't a layout
         if (!$page->gpLayout) {
             self::$editlinks = '';
         }
         return;
     }
     // attempt to send 304 response
     if ($page->fileModTime > 0) {
         global $wbMessageBuffer;
         $len = strlen(self::$head_content) + strlen(self::$head_js) + ob_get_length();
         if (count($wbMessageBuffer)) {
             $len += strlen(json_encode($wbMessageBuffer));
         }
         \gp\tool::Send304(\gp\tool::GenEtag($page->fileModTime, $len));
     }
 }
Beispiel #9
0
 /**
  * Get a list of existing titles similar to the requested page
  * @return array
  *
  */
 public function SimilarTitleArray($title)
 {
     global $gp_index, $gp_titles;
     $similar = array();
     $lower = str_replace(' ', '_', strtolower($title));
     $admin = \gp\tool::LoggedIn();
     foreach ($gp_index as $title => $index) {
         //skip private pages
         if (!$admin) {
             if (isset($gp_titles[$index]['vis'])) {
                 continue;
             }
         }
         similar_text($lower, strtolower($title), $percent);
         $similar[$title] = $percent;
     }
     arsort($similar);
     return $similar;
 }
Beispiel #10
0
 public function SearchPage($title, $index)
 {
     global $gp_menu, $gp_titles;
     //search hidden?
     if (!$this->search_hidden && !isset($gp_menu[$index])) {
         return;
     }
     //private pages
     if (!\gp\tool::LoggedIn()) {
         if (isset($gp_titles[$index]['vis'])) {
             return;
         }
     }
     $full_path = \gp\tool\Files::PageFile($title);
     $file_sections = \gp\tool\Files::Get($full_path, 'file_sections');
     if (!$file_sections) {
         return;
     }
     $content = \gp\tool\Output\Sections::Render($file_sections, $title, \gp\tool\Files::$last_stats);
     $label = \gp\tool::GetLabel($title);
     $this->FindString($content, $label, $title);
 }