Example #1
0
 /**
  * Returns the path to the JavaScript folder
  *
  * @param string $more File to be appended to the end of the result
  * @return string
  * @static
  */
 public static function Script($name)
 {
     return $name[0] == '/' || strpos($name, 'http://') === 0 ? $name : WebPath::Root(self::scripts . $name);
 }
Example #2
0
    /**	
    	PAGE START
    */
    function start()
    {
        if ($this->variables) {
            foreach ($this->variables as $key => $value) {
                ${$key} = $value;
            }
        }
        ?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<?php 
        foreach ($this->metaequiv as $n => $c) {
            ?>
	<meta http-equiv="<?php 
            echo $n;
            ?>
" content="<?php 
            echo $c;
            ?>
"><?php 
            echo "\n";
        }
        ?>
	<title><?php 
        echo $this->title;
        ?>
</title>
<?php 
        foreach ($this->metatags as $n => $c) {
            ?>
	<meta name="<?php 
            echo $n;
            ?>
" content="<?php 
            echo $c;
            ?>
"><?php 
            echo "\n";
        }
        foreach ($this->styles as $style) {
            ?>
	<link rel="stylesheet" href="<?php 
            echo WebPath::Stylesheet($style['file']);
            ?>
" type="text/css" <?php 
            if ($style['media']) {
                ?>
media="<?php 
                echo $style['media'];
                ?>
"<?php 
            }
            ?>
><?php 
            echo "\n";
        }
        foreach ($this->scripts as $file) {
            ?>
	<script src="<?php 
            echo WebPath::Script($file);
            ?>
" type="text/javascript" charset="utf-8"></script><?php 
            echo "\n";
        }
        foreach ($this->headcontent as $cont) {
            echo $cont, "\n";
        }
        ?>
</head>
<body class="<?php 
        echo implode(' ', $this->bodyclasses);
        ?>
" <?php 
        foreach ($this->bodytags as $a => $v) {
            echo "{$a}=\"{$v}\" ";
        }
        ?>
>
<?php 
    }
Example #3
0
 /**
  * Fires off a controller web request in the background. This is used for triggering long running actions that don't require the user waiting.
  *
  * @param string controllerPath The full url to execute.
  * @param array $post Optional post data to accompany the request
  * @static
  */
 public static function TriggerBackgroundTask($url, $post = null)
 {
     if ($url[0] != '/') {
         $url = "/{$url}";
     }
     $key = uniqid();
     $keypath = Path::Root("/cache/{$key}.srvskey");
     touch($keypath);
     if (!file_exists($keypath)) {
         throw new Exception("Background process could not be triggered, access key could not be written");
     }
     if (is_array($post)) {
         $post['SRVSKEY'] = $key;
     } else {
         $post = array('SRVSKEY' => $key);
     }
     //initiate the transaction.
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, WebPath::Absolute('/srvs' . $url));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 1);
     //end the request immediately (one second), execution will continue.
     curl_setopt($ch, CURLOPT_FAILONERROR, true);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
     if (curl_exec($ch) === false && file_exists($keypath)) {
         unlink($keypath);
         throw new Exception("Background process could not be triggered: " . curl_error($ch));
     }
     curl_close($ch);
 }
Example #4
0
 /**
  * Validates the current user's login credentials and redirects to the login form if they do not have access to the requested page.
  * This function is intended to be called at the top of any pages that require a user be logged in.
  *
  * @static
  * @param string $type Optional user type (part of the table schema) to test against.  Use this to validate admin users on admin only pages.
  * @access public
  */
 static function Validate()
 {
     if (!User::LoggedIn()) {
         $_SESSION['LoginRequest'] = WebPath::Me();
         $_SESSION['LoginMessage'] = "You must be logged-in to access that page.";
         Response::Redirect('/login/');
     } elseif (func_num_args()) {
         if (!User::Current()->isType(func_get_args())) {
             $page = new pErrorPage("You do not have permission to view this page.");
             //pErrorPage is a Page template for displaying errormessages.  This is a cleaner option to calling die() and stops page execution.
         }
     }
 }
Example #5
0
 /**
  * Sends a location header and terminates the controller, redirecting the browser to a new location.
  *
  * @param string URL to redirect to. Defaults to the current url if omitted.
  * @return void
  **/
 public static function Redirect($url = ".")
 {
     if ($url == '.') {
         $url = WebPath::Me();
     }
     header("Location: {$url}");
     Database::Disconnect();
     exit;
 }