Exemple #1
0
 public function extensionManager($params)
 {
     // Check login
     if (!Core::hasAdminAccess()) {
         return Core::getLoginView($_SERVER['REDIRECT_URL']);
     }
     // View
     $view = new View();
     $view->setSource(Config::get('core.dir.views') . '/core/extension-manager.tpl.php');
     $extName = isset($params[0]) ? $params[0] : NULL;
     $method = isset($params[1]) ? $params[1] : NULL;
     // Get all available extensions
     $extensions = Extension::getAvailableList();
     if (!is_null($extName)) {
         $extensions = isset($extensions[$extName]) ? array($extName => $extensions[$extName]) : array();
     }
     $view->extensions = $extensions;
     // Perform action
     if (!is_null($method)) {
         // no-cache header
         header("Cache-Control: no-cache, must-revalidate");
         header("Expires: Mon, 01 Jan 1977 00:00:00 GMT");
         header("Content-Type: text/xml");
         $result = '<' . '?xml version="1.0"?' . ">\n";
         // Call the defined method, if it exists
         $ext = Extension::getExtensionByName($extName);
         if (method_exists($ext, $method)) {
             if ($returnValue = $ext->{$method}()) {
                 $result .= '<result code="0"><message><![CDATA[Success]]></message>';
                 $result .= '<returnValue><![CDATA[' . json_encode($returnValue) . ']]></returnValue>';
                 $result .= '</result>';
             } else {
                 $entries = SystemLog::getAll();
                 foreach ($entries as &$entry) {
                     $entry = array('typeString' => $entry->getTypeString(), 'message' => $entry->getMessage());
                 }
                 $result .= '<result code="1"><message><![CDATA[Call to ' . get_class($ext) . '::' . $method . '() failed.]]></message>';
                 $result .= '<returnValue><![CDATA[' . json_encode($entries) . ']]></returnValue>';
                 $result .= '</result>';
             }
         } else {
             $result .= '<result code="2"><message><![CDATA[Method ' . get_class($ext) . '::' . $method . '() does not exist.]]></message>';
             $result .= '<returnValue><![CDATA[]]></returnValue>';
             $result .= '</result>';
         }
         // Print result
         print $result;
         Core::shutdown();
     }
     // Result
     return $this->wrapper($view);
 }
Exemple #2
0
<?php

/*
# $Id: SystemLog.tpl 155 2007-09-17 10:48:30Z james $
*/
use Buan\SystemLog;
$systemLog = SystemLog::getAll();
if (count($systemLog) > 0) {
    echo '<ul>';
    foreach ($systemLog as $entry) {
        echo '<li>' . strtoupper($entry->getTypeString()) . ': ' . htmlspecialchars($entry->getMessage()) . '</li>';
    }
    echo '</ul>';
}
Exemple #3
0
 /**
  * @param string $actionCommand Action to invoke (lower-hyphenated format, ie. action-command)
  * @return View
  */
 public final function invokeAction($actionCommand)
 {
     // Convert the action name to the format used for class method names
     // (ie. ActionName)
     $actionMethodName = Inflector::actionCommand_actionMethod($actionCommand);
     // Disregard this invocation if the $actionMethodName is listed in the
     // $allPrivateMethods array
     if (in_array($actionMethodName, $this->allPrivateMethods)) {
         return $this->unknown($this->params, $actionMethodName);
     }
     // Invoke the method (ensuring it's "public"), or the 'unknown' method
     // if it doesn't exist
     if (method_exists($this, $actionMethodName)) {
         $r = new ReflectionClass($this);
         $m = $r->getMethod($actionMethodName);
         if (!$m->isPublic() || $m->getName() !== $actionMethodName) {
             SystemLog::add(['Attempting to call a non-public action method: %s', $actionMethodName], SystemLog::FATAL);
             return new View();
         } else {
             return $this->{$actionMethodName}($this->params);
         }
     } else {
         return $this->unknown($this->params, $actionCommand);
     }
 }
Exemple #4
0
 /**
  * This method allows you to execute any arbitrary SQL statement and the
  * results are returned as a PDOStatement, or FALSE if the query failed.
  *
  * If you want to use numeric parameters (ie. SELECT * FROM x WHERE y=?)
  * then pass $params as a normal 0-indexed array.
  * However, if you want to use named parameters
  * (ie. SELECT * FROM x WHERE y=:myparam), then send $params as a hash
  * key=>value pairs of ":param"=>"value".
  *
  * Really, you could just as easily use the PDO functions directly in your
  * code. This will give you more flexibilty with setting attributes, etc.
  * Just try to keep all database code within your Model or ModelManager
  * classes.
  *
  * @param string|\Buan\ModelCriteria The query to execute
  * @param array Parameters to bind to the query
  * @param string The DB connection through which the query will be executed
  * @return \PDOStatement
  * @throws \PDOException
  */
 public static function sqlQuery($sql, $params = [], $connection = null)
 {
     // Get the database connection
     if (is_null($connection)) {
         try {
             $connection = Database::getConnection('default');
         } catch (Exception $e) {
             SystemLog::add($e->getMessage(), SystemLog::WARNING);
             return false;
         }
     }
     // Execute the query
     try {
         if ($sql instanceof ModelCriteria) {
             $sql = $sql->sql();
             $stmt = $connection->prepare($sql->query);
             foreach ($sql->bindings as $binding) {
                 $stmt->bindValue($binding->parameter, $binding->value, $binding->dataType);
             }
             $stmt->execute();
         } else {
             if (count($params) > 0) {
                 $stmt = $connection->prepare($sql);
                 $stmt->execute($params);
             } else {
                 $stmt = $connection->query($sql);
             }
         }
         return $stmt;
     } catch (PDOException $e) {
         $dbg = debug_backtrace();
         $msg = $e->getMessage() . " (source: {$dbg[0]['file']} line {$dbg[0]['line']})";
         throw new PDOException($msg);
         return false;
     }
 }