Beispiel #1
0
 /**
  * Replace content variables in $content
  *
  */
 static function TextContent(&$content)
 {
     self::$meta += array('modified' => '');
     //variables
     $vars = array('dirPrefix' => $GLOBALS['dirPrefix'], 'linkPrefix' => \gp\tool::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;
 }
Beispiel #2
0
 /**
  * Set a session cookie
  * Attempt to use httponly if available
  *
  */
 public static function cookie($name, $value = '', $expires = false)
 {
     global $dirPrefix;
     $cookiePath = empty($dirPrefix) ? '/' : $dirPrefix;
     $cookiePath = \gp\tool::HrefEncode($cookiePath, false);
     $secure = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
     $domain = \gp\tool::ServerName(true);
     if (!$domain || strpos($domain, '.') === false) {
         $domain = '';
     }
     if (strpos($domain, ':') !== false) {
         $domain = substr($domain, 0, strrpos($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);
 }