示例#1
0
 /**
  * Render the view and return the result.
  *
  * @return string
  */
 public function render()
 {
     // Start buffering
     ob_start();
     // Extract all variables into the local scope
     $__vars = $this->getView()->getVariables();
     extract($__vars, EXTR_REFS);
     unset($__vars);
     // Include PHP source template
     if ($this->getView()->getSource() === null) {
         // No external source template has been defined, so check the rawSource
         //if($this->rawSource!==NULL) {
         //	echo $this->rawSource;
         //}
     } else {
         if (is_file($this->getView()->getSource()) && (include $this->getView()->getSource())) {
             // Successfully included
         } else {
             SystemLog::add("View template source is missing: {$this->getView()->getSource()}", SystemLog::WARNING);
         }
     }
     // Read the output buffer
     $buffer = ob_get_clean();
     // Remove any UTF-8 BOM (Byte Order Mark) from the beginning of the buffer
     // This is required, at least, on child templates because otherwise the
     // BOM is displayed as a visible character in the output.
     $buffer = preg_replace("/^/", "", $buffer);
     // Result
     return $buffer;
 }
示例#2
0
 public function repos($params)
 {
     $view = new View();
     if (!Core::hasAdminAccess()) {
         return Core::getLoginView($view);
     }
     $view->setSource(Config::get('ext.acl.dir.views') . '/repos.tpl');
     if (isset($_GET['id'])) {
         $view->setSource(Config::get('ext.acl.dir.views') . '/repos.edit.tpl');
         $repo = Model::create('AclRepo');
         if ($_GET['id'] > 0) {
             $repo->id = (int) $_GET['id'];
             if (!$repo->getModelManager()->load($repo)) {
                 SystemLog::add(array('Failed to load repository #%s', $repo->id), SystemLog::WARNING);
                 $view->setSource(NULL);
                 return $view;
             }
         }
         // Save
         if (isset($_POST['name'])) {
             $repo->name = $_POST['name'];
             if ($repo->getModelManager()->save($repo)) {
                 SystemLog::add('Data saved!', SystemLog::INFO);
             } else {
                 SystemLog::add('Failed to save data.', SystemLog::WARNING);
             }
         } else {
             if (isset($_GET['remove']) && $repo->isInDatabase()) {
                 if ($repo->getModelManager()->delete($repo)) {
                     SystemLog::add('Data removed!', SystemLog::INFO);
                     $repo = Model::create('AclRepo');
                 } else {
                     SystemLog::add('Failed to remove data.', SystemLog::WARNING);
                 }
             }
         }
         // View
         $view->repo = $repo;
         return $view;
     }
     // View
     $view->repos = ModelManager::select('AclRepo');
     return $view;
 }
示例#3
0
文件: Core.php 项目: Nessworthy/buan
 /**
  * This method simply includes the given configuration files, which prepare the
  * application environment, and sets a few of it's own configuration variables.
  *
  * The first script, $configFile, should only perform the following tasks:
  * - Define settings via Config::set()
  * - Optionally define database connections and model relationships
  *
  * The second scripts, $bootstrap, is then free to do anything it wants.
  *
  * For a full list of required and optional config variable, see the bundled
  * "application/app/config.php"
  *
  * @param string $configFile Absolute path to the configuration file
  * @param string $bootstrap Absolute path to the bootstrap script
  * @return void
  */
 public static function configure($configFile, $bootstrap = null)
 {
     // Include configuration file
     if (include $configFile) {
         // Check for existence of some required settings and set defaults or halt
         $app = Config::get('app');
         if (!isset($app['docRoot'])) {
             SystemLog::add("You have not defined your application's document root in {$configFile}.", SystemLog::FATAL);
             Core::halt();
         }
         if (!isset($app['command']['urlPrefix'])) {
             $app['command']['urlPrefix'] = '';
         }
         if (!isset($app['command']['parameter']) || $app['command']['parameter'] === '') {
             $app['command']['parameter'] = 'do';
         }
         if (!isset($app['command']['default'])) {
             $app['command']['default'] = '';
         }
         if (!isset($app['dir']['ignored'])) {
             $app['dir']['ignored'] = ['.', '..', '.svn', 'cvs'];
         }
         if (!isset($app['domain'])) {
             $app['domain'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost';
         }
         if (!isset($app['password'])) {
             $app['password'] = rand(1000000, 9999999);
         }
         if (!isset($app['urlRoot'])) {
             $app['urlRoot'] = '';
         } else {
             if ($app['urlRoot'] !== '') {
                 $app['urlRoot'] = preg_replace("/^\\/*/", "/", preg_replace("/\\/+\$/", "", $app['urlRoot']));
             }
         }
         // Reassign filtered settings to Config
         Config::set('app', $app);
         // Ensure that any encoded forward slashes in the command URL remain
         // encoded
         if (isset($_SERVER['QUERY_STRING']) && preg_match("/" . $app['command']['parameter'] . "=([^&]*\\%2F[^&]*)/i", $_SERVER['QUERY_STRING'], $m) > 0) {
             $_REQUEST[$app['command']['parameter']] = $_GET[$app['command']['parameter']] = $m[1];
         }
         // Store the requested command
         $cp = Config::get('app.command.parameter');
         if (isset($_REQUEST[$cp])) {
             Config::set('app.command.requested', isset($_REQUEST[$cp]) ? $_REQUEST[$cp] : '');
         } else {
             if (isset($_SERVER['REQUEST_URI']) && preg_match("/^" . preg_quote($app['urlRoot'], '/') . "\\/index\\.php\\/(.+)\$/i", $_SERVER['REQUEST_URI'], $m)) {
                 Config::set('app.command.requested', $m[1]);
             } else {
                 Config::set('app.command.requested', '');
             }
         }
     } else {
         // Log and halt
         SystemLog::add("Cannot find an application configuration file (looking for {$configFile})", SystemLog::FATAL);
         Core::halt();
     }
     // Store the given application configuration file in the global Config so it
     // may be retrieved by other processes if needs be.
     Config::set('app.configFile', $configFile);
     // Include bootstrap script
     if ($bootstrap !== null && (include $bootstrap)) {
         // Success
     }
 }
示例#4
0
 public function uninstall()
 {
     // Get DB connection
     try {
         $DB = Database::getConnection();
     } catch (Exception $e) {
         SystemLog::add('This extension requires a database. (' . $e->getMessage() . ')', SystemLog::WARNING);
         return FALSE;
     }
     // Table definitions
     $tables = array('acl_repo', 'acl_role', 'acl_resource', 'acl_role_member', 'acl_type', 'acl_entry');
     // Create tables
     try {
         $DB->beginTransaction();
         foreach ($tables as $table) {
             if (!ModelManager::sqlQuery('DROP TABLE IF EXISTS ' . $table)) {
                 throw new PDOException("Invalid SQL");
             }
         }
         $DB->commit();
         return TRUE;
     } catch (PDOException $e) {
         SystemLog::add($e->getMessage(), SystemLog::WARNING);
         try {
             $DB->rollBack();
         } catch (PDOException $e) {
             SystemLog::add($e->getMessage(), SystemLog::WARNING);
         }
     }
     // Catch-all result
     return FALSE;
 }
示例#5
0
 public static function getRelation($modelSource, $modelTarget = null, $relationRef = null)
 {
     // Pass back ALL relationships
     if ($modelTarget === null) {
         $relations = [];
         $relationMap = isset(self::$relationships[$modelSource]) ? self::$relationships[$modelSource] : [];
         foreach ($relationMap as $k => $rel) {
             foreach ($rel as $r) {
                 $relations[] = $r;
             }
             reset(self::$relationships[$modelSource][$k]);
         }
         return $relations;
     }
     // First, check if we've got a direct relationship (works for 1:1, 1:M and M:1)
     if (isset(self::$relationships[$modelSource][$modelTarget])) {
         if ($relationRef === null) {
             $rel = count(self::$relationships[$modelSource][$modelTarget]) > 1 ? self::$relationships[$modelSource][$modelTarget] : current(self::$relationships[$modelSource][$modelTarget]);
             return $rel;
         } else {
             if (isset(self::$relationships[$modelSource][$modelTarget][$relationRef])) {
                 return self::$relationships[$modelSource][$modelTarget][$relationRef];
             } else {
                 if ($modelSource != $modelTarget) {
                     SystemLog::add("No relationship with reference '{$relationRef}' has been defined for {$modelSource}:{$modelTarget}", SystemLog::CORE);
                     return new ModelRelation(['modelSource' => $modelSource, 'modelTarget' => $modelTarget, 'cardinality' => ModelRelation::NONE]);
                 }
             }
         }
     }
     // Try to construct a M:M relationship
     /*if(isset(self::$relationships[$modelSource])) {
           $relationRef = $relationRef===NULL ? self::REF_DEFAULT : $relationRef;
           foreach(self::$relationships[$modelSource] as $linkModel=>$relation) {
               if(isset(self::$relationships[$linkModel][$modelTarget][$relationRef])) {
                   return self::$relationships[$modelSource][$modelTarget][$relationRef] = new ModelRelation(array(
                           'modelSource'=>$modelSource,
                           'modelTarget'=>$modelTarget,
                           'cardinality'=>ModelRelation::MANY_TO_MANY,
                           'modelLink'=>$linkModel,
                           'reference'=>$relationRef
                       ));
               }
           }
       }*/
     // If all else fails, return a ModelRelation with NONE cardinality
     SystemLog::add("No relationship has been defined for {$modelSource}:{$modelTarget}", SystemLog::CORE);
     return new ModelRelation(['modelSource' => $modelSource, 'modelTarget' => $modelTarget, 'cardinality' => ModelRelation::NONE]);
 }
示例#6
0
 public static final function getExtensionByName($extName)
 {
     // Vars
     $extClassName = Inflector::extensionName_extensionClass($extName);
     static $extensions = [];
     if (isset($extensions[$extName])) {
         return $extensions[$extName];
     }
     // Find the extension
     // Extensions in "app" will override the same extension in "core".
     $extFolders = ['app' => Config::get('app.dir.extensions'), 'core' => Config::get('core.dir.extensions')];
     foreach ($extFolders as $namespace => $extFolder) {
         if ($extFolder == '' || !file_exists("{$extFolder}/{$extName}") || in_array($extName, Config::get('app.dir.ignored'))) {
             continue;
         }
         if (!is_file("{$extFolder}/{$extName}/{$extClassName}.php")) {
             SystemLog::add('Extension "' . $extName . '" is missing a class definition.', SystemLog::WARNING);
         } else {
             if (!isset($extensions[$extName])) {
                 $extFilePath = sprintf('%s/%s/%s.php', $extFolder, $extName, $extClassName);
                 include_once $extFilePath;
                 $ext = new $extClassName($extName, $namespace);
                 $extensions[$extName] = $ext;
             }
         }
     }
     // Result
     return isset($extensions[$extName]) ? $extensions[$extName] : null;
 }
示例#7
0
文件: Model.php 项目: Nessworthy/buan
 /**
  * Sets this Model's PK value.
  * Persistent Models cannot have their primary key changed.
  *
  * This method will be automatically executed (via __set()) if the
  * primary-key field is altered directly. For example, if the PK is "id", then
  * the following are equivalent:
  *        $this->id = 5;
  *        $this->setPrimaryKeyValue(5);
  *
  * For a composite PK, there are two methods of setting the values for each
  * field involved in the key:
  *        $this->setPrimaryKeyValue(array(field1=>value, field2=>value));, or
  *        $this->setPrimaryKeyValue(field1, value);
  *        $this->setPrimaryKeyValue(field2, value);
  *
  * @param string|mixed See description above
  * @param mixed Value of specified composite key field
  * @return bool
  */
 public function setPrimaryKeyValue($arg1, $arg2 = null)
 {
     // Check that $this Model is not persistent.
     if ($this->isInDatabase()) {
         // TODO: What about the hasChanged flag? it was set to true by __set(), but we might need it false here.
         //	Maybe move this method's code to __set and have a special case "... if($fieldName=="id") { ... } ..."
         SystemLog::add("Attempting to reset primary-key on a persistent Model", SystemLog::WARNING);
         return false;
     } else {
         if (!$this->hasCompositePrimaryKey()) {
             $this->dbData[$this->getPrimaryKey()] = $arg1;
         } else {
             if (is_array($arg1)) {
                 // TODO: Should we ensure that all array keys in $arg1 are actually primary key fields?
                 foreach ($arg1 as $k => $v) {
                     $this->dbData[$k] = $v;
                 }
             } else {
                 if ($arg2 !== null) {
                     $this->dbData[$arg1] = $arg2;
                 } else {
                     // TODO: THROW exception? would be better
                 }
             }
         }
     }
     // Flag as changed
     $this->hasChanged(true);
     return true;
 }
示例#8
0
文件: View.php 项目: Nessworthy/buan
 /**
  * Returns the View stored in the specified slot, or an empty Buan\View if the
  * slot does not exist.
  *
  * @param string ID of the slot you want to retrieve
  * @return \View
  */
 public function getSlot($slotId)
 {
     if (isset($this->slots[$slotId])) {
         return $this->slots[$slotId];
     } else {
         SystemLog::add("There is no View object in slot \"{$slotId}\"", SystemLog::WARNING);
         return new View();
     }
 }