Example #1
0
 /**
  * Prepare and output any inline Javascript for the current page
  * @static
  */
 static function GetHead_InlineJS()
 {
     global $page, $linkPrefix, $GP_INLINE_VARS;
     ob_start();
     if (gpdebugjs) {
         if (is_string(gpdebugjs)) {
             $GP_INLINE_VARS['debugjs'] = 'send';
         } else {
             $GP_INLINE_VARS['debugjs'] = true;
         }
     }
     if (common::LoggedIn()) {
         $GP_INLINE_VARS += array('isadmin' => true, 'gpBLink' => common::HrefEncode($linkPrefix, false), 'post_nonce' => common::new_nonce('post', true));
         gpsession::GPUIVars();
     }
     if (count($GP_INLINE_VARS) > 0) {
         echo 'var ';
         $comma = '';
         foreach ($GP_INLINE_VARS as $key => $value) {
             echo $comma . $key . '=' . json_encode($value);
             $comma = ',';
         }
         echo ';';
     }
     $inline = ob_get_clean();
     if (!empty($inline)) {
         echo "\n<script>\n" . $inline . "\n</script>";
     }
     ob_start();
     echo $page->head_script;
     if (!empty($page->jQueryCode)) {
         echo '$(function(){';
         echo $page->jQueryCode;
         echo '});';
     }
     $inline = ob_get_clean();
     $inline = ltrim($inline);
     if (!empty($inline)) {
         echo "\n<script>\n" . $inline . "\n</script>\n";
     }
 }
Example #2
0
 /**
  * Set a session cookie
  * Attempt to use httponly if available
  *
  */
 function cookie($name, $value, $expires = false)
 {
     global $config, $dirPrefix;
     $cookiePath = '/';
     if (!empty($dirPrefix)) {
         $cookiePath = $dirPrefix;
     }
     $cookiePath = common::HrefEncode($cookiePath);
     if ($expires === false) {
         $expires = time() + 2592000;
     } elseif ($expires === true) {
         $expires = 0;
         //expire at end of session
     }
     if (version_compare(phpversion(), '5.2', '>=')) {
         setcookie($name, $value, $expires, $cookiePath, '', '', true);
     } else {
         setcookie($name, $value, $expires, $cookiePath);
     }
 }
Example #3
0
 /**
  * Get the full path of a physical file on the server
  * The query string component of a path should not be included but will be protected from being encoded
  *
  */
 static function GetDir($dir = '', $ampersands = false)
 {
     global $dirPrefix;
     $query = '';
     $pos = mb_strpos($dir, '?');
     if ($pos !== false) {
         $query = mb_substr($dir, $pos);
         $dir = mb_substr($dir, 0, $pos);
     }
     $dir = $dirPrefix . '/' . ltrim($dir, '/');
     return common::HrefEncode($dir, $ampersands) . $query;
 }
Example #4
0
 /**
  * Replace gpEasy content variables in $content
  *
  */
 static function TextContent(&$content)
 {
     self::$meta += array('modified' => '');
     //variables
     $vars = array('dirPrefix' => $GLOBALS['dirPrefix'], 'linkPrefix' => common::HrefEncode($GLOBALS['linkPrefix']), 'fileModTime' => self::$meta['modified'], 'title' => self::$title, 'label' => self::$label);
     $offset = 0;
     $i = 0;
     do {
         $i++;
         $pos = strpos($content, '$', $offset);
         if ($pos === false) {
             break;
         }
         //escaped?
         if ($pos > 0) {
             $prev_char = $content[$pos - 1];
             if ($prev_char == '\\') {
                 $offset = $pos + 1;
                 continue;
             }
         }
         $len = strspn($content, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $pos + 1);
         if ($len == 0) {
             $offset = $pos + 1;
             continue;
         }
         $var = substr($content, $pos + 1, $len);
         if (isset($vars[$var])) {
             $content = substr_replace($content, $vars[$var], $pos, $len + 1);
         }
         $offset = $pos + $len;
     } while (true);
     /* Testing old includes system ... this breaks editing */
     self::ReplaceContent($content);
     return $content;
 }
Example #5
0
 /**
  * Set a session cookie
  * Attempt to use httponly if available
  *
  */
 static function cookie($name, $value = '', $expires = false)
 {
     global $dirPrefix;
     $cookiePath = empty($dirPrefix) ? '/' : $dirPrefix;
     $cookiePath = common::HrefEncode($cookiePath, false);
     $secure = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
     $domain = self::ServerName();
     if (!$domain || strpos($domain, '.') === false) {
         $domain = '';
     }
     // expire if value is empty
     // cookies are set with either www removed from the domain or with an empty string
     if (empty($value)) {
         $expires = time() - 2592000;
         if ($domain) {
             setcookie($name, $value, $expires, $cookiePath, $domain, $secure, true);
             setcookie($name, $value, $expires, $cookiePath, $domain, false, true);
         }
         setcookie($name, $value, $expires, $cookiePath, '', $secure, true);
         setcookie($name, $value, $expires, $cookiePath, '', false, true);
         return;
     }
     // get expiration and set
     if ($expires === false) {
         $expires = time() + 2592000;
         //30 days
     } elseif ($expires === true) {
         $expires = 0;
         //expire at end of session
     }
     setcookie($name, $value, $expires, $cookiePath, $domain, $secure, true);
 }
Example #6
0
 /**
  * Prepare and output any inline Javascript for the current page
  * @static
  */
 function GetHead_InlineJS()
 {
     global $page, $linkPrefix;
     ob_start();
     if (gpdebugjs) {
         echo 'var debugjs=true;';
     }
     if (common::LoggedIn()) {
         echo 'var isadmin=true';
         echo ',gpBLink="' . common::HrefEncode($linkPrefix) . '"';
         //here because of index.php
         gpsession::GPUIVars();
         if (!admin_tools::CanRemoteInstall()) {
             echo ',gpRem=false';
         }
         echo ',post_nonce="' . common::new_nonce('post', true) . '"';
         echo ';';
         gpOutput::GP_STYLES();
     }
     echo $page->head_script;
     if (!empty($page->jQueryCode)) {
         echo '$(function(){';
         echo $page->jQueryCode;
         echo '});';
     }
     $inline = ob_get_clean();
     if (!empty($inline)) {
         echo "\n<script type=\"text/javascript\">/* <![CDATA[ */\n";
         echo $inline;
         echo "\n/* ]]> */</script>";
     }
 }
Example #7
0
 /**
  * Set a session cookie
  * Attempt to use httponly if available
  *
  */
 static function cookie($name, $value, $expires = false)
 {
     global $dirPrefix;
     $cookiePath = '/';
     if (!empty($dirPrefix)) {
         $cookiePath = $dirPrefix;
     }
     $cookiePath = common::HrefEncode($cookiePath, false);
     if ($expires === false) {
         $expires = time() + 2592000;
         //30 days
     } elseif ($expires === true) {
         $expires = 0;
         //expire at end of session
     }
     setcookie($name, $value, $expires, $cookiePath, '', false, true);
 }
Example #8
0
 /**
  * Get the full path of a physical file on the server
  * The query string component of a path should not be included but will be protected from being encoded
  *
  */
 function GetDir($dir = '', $ampersands = false)
 {
     global $dirPrefix;
     $query = '';
     if (strpos($dir, '?') !== false) {
         $list = explode('?', $dir, 2);
         $dir = $list[0];
         $query = '?' . $list[1];
     }
     $dir = $dirPrefix . '/' . ltrim($dir, '/');
     if ($ampersands) {
         $dir = common::ampersands($dir);
     }
     return common::HrefEncode($dir) . $query;
 }