Exemplo n.º 1
0
 public function GetCurrentUser($pData = null)
 {
     $Components = Wob::_("Components");
     $Components->User->Set('Source', 'Component');
     $Current = $Components->User->Current();
     return $Current;
 }
Exemplo n.º 2
0
 /**
  * Get an ordered list of the available styles, using inheritance
  *
  * @access  public
  */
 public function GetStyles()
 {
     eval(GLOBALS);
     // Check if we've already loaded the styles.
     if (isset($this->_styles)) {
         return $this->_styles;
     }
     $paths = $this->_Config->GetPath();
     $extensions = explode(' ', $this->_Config->GetConfiguration('extensions', 'css'));
     $found = false;
     $base = $zApp->GetPath() . DS . 'themes';
     $styles = array();
     foreach ($extensions as $e => $extension) {
         foreach ($paths as $p => $path) {
             $directory = $zApp->GetPath() . '/themes/' . $path . '/styles/init/';
             $location = $path . '/styles/init/';
             // Directory does not exist, continue;
             if (!is_dir($directory)) {
                 continue;
             }
             // Get a list of all css files.
             $Storage = Wob::_('Storage');
             $files = $Storage->Scan($directory, $extension, true);
             // No styles found, continue
             if (count($files) < 1) {
                 continue;
             }
             $found = true;
             foreach ($files as $f => $file) {
                 $file = $location . $file;
                 $styles[] = $file;
             }
         }
     }
     $Router = Wob::_('Router');
     $foundation = $Router->Get('Foundation');
     foreach ($extensions as $e => $extension) {
         $foundation = str_replace('.php', '.' . $extension, $foundation);
         // Load the foundation styles
         $foundationStyle = null;
         foreach ($paths as $p => $path) {
             $file = ASD_PATH . 'themes/' . $path . '/styles/foundations' . $foundation;
             $url = $path . '/styles/foundations' . $foundation;
             if (file_exists($file)) {
                 $foundationStyle = $url;
             }
         }
     }
     if ($foundationStyle) {
         $styles[] = $foundationStyle;
     }
     return $styles;
 }
Exemplo n.º 3
0
 public function GetToken()
 {
     $Current = $this->Talk('User', 'Current');
     if (!$Current) {
         // User is not locally authenticated.
         $return['error'] = '403';
         $return['message'] = 'Forbidden';
         return $return;
     }
     $Secret = $Current->Secret;
     $Identity = $Current->Account;
     $Origin = ASD_DOMAIN;
     $Destination = ASD_DOMAIN;
     // 1. Check for existing, unexpired token.
     $tokensModel = new cModel("AuthorizationTokens");
     $Graph = Wob::_('Graph');
     // Create the callback function pointer for saving tokens.
     $fSaveToken = array($this, '_SaveToken');
     $fLoadToken = array($this, '_LoadToken');
     list($Token, $Expiration) = $Graph->Token($Identity, $Origin, $Destination, $pSecret, 24 * 60, $fSaveToken, $fLoadToken);
     $Date = Wob::_('Date');
     // Check for Created is > 24h ago.
     $createdStamp = time() - 60 * 60 * 24;
     $createdMysql = $Date->ToMysql($createdStamp);
     // Find a corresponding token which is less than 24 hours old.
     $tokensModel->Query('SELECT * FROM #__AuthorizationTokens');
     $criteria = array('Identity' => $Identity, 'Origin' => $Origin, 'Destination' => $Destination, 'Created' => '>>' . $createdMysql);
     $tokensModel->Retrieve($criteria);
     // 2. Create new token.
     if ($tokensModel->Get('Total') == 0) {
         $createdStamp = time();
         $expirationStamp = time() + 60 * 60 * 24;
         $createdMysql = $Date->ToMysql($createdStamp);
         $expirationMysql = $Date->ToMysql($expirationStamp);
         $Expiration = $Date->ToGraph($expirationStamp);
         # 1P =  hmac_sha512 ( Identity + Origin + Destination + Expiration, Secret );
         $String = $Identity . $Origin . $Destination . $Expiration;
         $Token = hash_hmac('sha512', $String, $Secret);
         $tokensModel->Set('Identity', $Identity);
         $tokensModel->Set('Origin', $Origin);
         $tokensModel->Set('Destination', $Destination);
         $tokensModel->Set('Created', $createdMysql);
         $tokensModel->Set('Token', $Token);
         $tokensModel->Set('Token', $Token);
         $tokensModel->Set('Host', $_SERVER['HTTP_HOST']);
         $tokensModel->Set('Address', $_SERVER['REMOTE_ADDR']);
         $tokensModel->Save();
     } else {
         $tokensModel->Fetch();
         $Token = $tokensModel->Get('Token');
         $Expiration = $Date->ToGraph(strtotime($tokensModel->Get('Created')) + 24 * 60 * 60);
     }
     // 3. Return the token.
     $return = array('account' => $Identity, 'origin' => $Origin, 'destination' => $Destination, 'token' => $Token, 'expiration' => $Expiration);
     return $return;
 }
Exemplo n.º 4
0
 /**
  * Shortcut to cComponents Talk method
  *
  * @access  public
  * @param string $pEvent Which event to trigger
  * @param array $pEvent Extra data to pass to event hook
  */
 public function Talk($pComponent, $pRequest)
 {
     $args = func_get_args();
     $Components = Wob::_('Components');
     $return = call_user_func_array(array($Components, 'Talk'), $args);
     return $return;
 }
Exemplo n.º 5
0
 public function EndSystemInitialize($pData = null)
 {
     $requestMethod = strtolower($this->GetSys("Request")->Method());
     $entry = $this->Get('Config')->GetConfiguration('entry', '/graph/');
     // Check if we're tunneling
     $this->_Tunnel();
     // Check if this is the proper entrypoint
     if (!($entryData = $this->_EntryPoint())) {
         return false;
     }
     $Domain = $entryData['Domain'];
     $URI = $entryData['URI'];
     $Parts = explode('/', $URI);
     $Request = Wob::_('Request');
     $Data = $Request->Get();
     $Signature = $this->GetSys('Request')->Get('Signature');
     // Split up the rest of the URI into "objects"
     if (count($Parts) > 3) {
         for ($p = 3; $p < count($Parts); $p++) {
             $Parameters[] = $Parts[$p];
         }
         $PartCount = count($Parameters) - 1;
         $last = $Parameters[$PartCount];
         $Parameters[$PartCount] = preg_replace('/\\.xml$/', '', $Parts[$p - 1]);
         $Parameters[$PartCount] = preg_replace('/\\.json$/', '', $Parameters[$PartCount]);
         if (!$Parameters[$PartCount]) {
             unset($Parameters[$PartCount]);
         }
         $Data = $Parameters;
     } else {
         if ($Parts[2]) {
             $last = $Parts[2];
             $Parts[2] = preg_replace('/\\.xml$/', '', $Parts[2]);
             $Parts[2] = preg_replace('/\\.json$/', '', $Parts[2]);
         } else {
             if ($Parts[1]) {
                 $last = $Parts[1];
                 $Parts[1] = preg_replace('/\\.xml$/', '', $Parts[1]);
                 $Parts[1] = preg_replace('/\\.json$/', '', $Parts[1]);
             }
         }
     }
     $sections = explode('.', $last);
     // Determine which format is being requested.
     $this->_Format = $this->_Format();
     $this->_Component = ucwords($Parts[1]);
     $this->_Method = ucwords($requestMethod) . ucwords($Parts[2]);
     // 1.  Check if the method exists.
     if (!$this->_ComponentMethodExists($this->_Component, $this->_Method) && $requestMethod != 'options') {
         // We cannot resolve to a component, error out.
         $this->_Error('404');
         exit;
     }
     // 2. Determine proper authorization.
     if (!$this->_CheckAccess($this->_Component, $this->_Method)) {
         // No access
         $this->_Error('403');
         exit;
     }
     $c = $this->_Component;
     $instance = $this->GetSys('Components')->{$c};
     $m = $this->_Method;
     $reflect = new ReflectionClass($instance);
     $className = $reflect->GetName();
     if ($method = $reflect->hasMethod($m)) {
         $method = $reflect->getMethod($m);
         $parameters = $method->getParameters();
         if ($method->GetDeclaringClass()->getName() != $className) {
             $this->_Error('403');
             exit;
         }
     } else {
         $method = null;
         $parameters = array();
     }
     // 3. Align the parameters.
     $RequestData = $Request->Get();
     $Params = $Data;
     $pnames = array();
     foreach ($parameters as $p => $parameter) {
         $pname = $parameter->GetName();
         if ($pname[0] == 'p' && ctype_upper($pname[1])) {
             // We're using $pParameter notation.  Remove the p.
             list($null, $name) = explode($pname[0], $pname, 2);
             $name = strtolower($name);
             if ($RequestData[$name]) {
                 if (!isset($Parameters[$p])) {
                     $Parameters[$p] = $RequestData[$name];
                 }
             }
         } else {
             // We're not using $pParameter notation
             $name = strtolower($pname);
             $Parameters[$p] = $RequestData[$name];
         }
         $pnames[$p] = $name;
     }
     // Check to make sure all necessary parameters are available.
     $return = array();
     foreach ($parameters as $p => $parameter) {
         if (!$parameter->IsOptional() && !isset($Parameters[$p])) {
             header('HTTP/1.1 412 Precondition Failed');
             $return['error'] = true;
             $return['message'][] = 'Field required: "' . $pnames[$p] . '"';
         }
     }
     // If we've found an error, exit.
     if ($return['error'] == true) {
         $this->Format($return);
         exit;
     }
     $this->_Parameters = (array) $Parameters;
     // Requesting information on methods
     if ($requestMethod == 'options') {
         if ($Parts[2]) {
             $this->_Options(ucwords($Parts[2]));
         } else {
             $this->_OptionsAll();
         }
     }
     // 4. Execute the component method.
     $this->_SetOriginInformation($instance);
     $return = call_user_func_array(array($instance, $this->_Method), $this->_Parameters);
     $this->Format($return);
     // Exit the framework completely
     exit;
 }
Exemplo n.º 6
0
 private function _ProcessScripts()
 {
     $scripts = $this->View->Find('script', 0)->outertext;
     $clients = $this->GetSys('Clients')->Get('Config')->GetPath();
     $foundation = $this->GetSys('Router')->Get('Foundation');
     list($foundation, $null) = explode('.php', $foundation);
     /*
      * Load all files in the init/ directory.
      */
     $extensions = explode(' ', $this->GetSys('Clients')->Get('Config')->GetConfiguration('extensions', 'js'));
     foreach ($extensions as $e => $extension) {
         foreach ($clients as $c => $client) {
             $directory = ASD_PATH . 'clients/' . $client . '/init/';
             if (!is_dir($directory)) {
                 continue;
             }
             $Storage = Wob::_('Storage');
             $files = $Storage->Scan($directory, $extension, $recursive = true);
             foreach ($files as $f => $file) {
                 $inits[$file] = $client;
             }
         }
     }
     /*
      * Load specific initialization files.
      */
     $explicitInits = $this->GetSys('Clients')->Get('Config')->GetConfiguration('init');
     foreach ($explicitInits as $i => $init) {
         $initPath = 'http://' . ASD_DOMAIN . '/clients/' . $client . '/' . $init;
         $finalPaths[] = $initPath;
     }
     foreach ($inits as $file => $client) {
         $initPath = 'http://' . ASD_DOMAIN . '/clients/' . $client . '/init/' . $file;
         $finalPaths[] = $initPath;
     }
     /*
      * Find the most relevant foundation-specific js file.
      */
     $foundationPath = null;
     foreach ($clients as $c => $client) {
         $foundationPath = 'http://' . ASD_DOMAIN . '/clients/' . $client . '/foundations/' . $foundation . '.js';
         $foundationLocation = ASD_PATH . 'clients/' . $client . '/foundations/' . $foundation . '.js';
         if (!file_exists($foundationLocation)) {
             continue;
         }
         $finalFoundationPath = $foundationPath;
     }
     if ($finalFoundationPath) {
         $finalPaths[] = $finalFoundationPath;
     }
     foreach ($finalPaths as $f => $final) {
         $script = new cHTML();
         $script->Load($scripts);
         $script->Find('script', 0)->src = $final;
         if (strstr($final, '.coffee')) {
             $script->Find('script', 0)->type = 'text/coffeescript';
         } else {
             $script->Find('script', 0)->type = 'text/javascript';
         }
         $this->View->Find('script', 0)->outertext .= $script->outertext . "\n";
     }
     $this->View->Reload();
     $this->View->Find('script', 0)->outertext = "";
     return true;
 }