function view()
 {
     // Grab the view to easily assign variables
     $view = $this->getView();
     // Get all warnings from Ajde_Dump::warn()
     if (Ajde_Dump::getWarnings()) {
         $view->assign('warn', Ajde_Dump::getWarnings());
     }
     // Get all dumps from Ajde_Dump::dump() [Aliased as a global function dump()]
     if (Ajde_Dump::getAll()) {
         $view->assign('dump', Ajde_Dump::getAll());
     }
     // Get request parameters
     $view->assign('request', Ajde::app()->getRequest());
     // Get Configuration stage
     $view->assign('configstage', Config::$stage);
     // Get database queries
     if (Ajde_Core_Autoloader::exists('Ajde_Db_PDO')) {
         $view->assign('database', Ajde_Db_PDO::getLog());
     }
     // Get language
     $view->assign('lang', Ajde_Lang::getInstance()->getLang());
     // Get session
     $view->assign('session', $_SESSION);
     // Get ACL
     if (Ajde_Core_Autoloader::exists('Ajde_Acl')) {
         $view->assign('acl', Ajde_Acl::getLog());
     }
     // Get the application timer
     Ajde::app()->endTimer(0);
     Ajde::app()->endTimer(Ajde::app()->getLastTimerKey());
     $view->assign('timers', Ajde::app()->getTimers());
     return $this->render();
 }
예제 #2
0
파일: Config.php 프로젝트: nabble/ajde
 /**
  * TODO.
  */
 public function __construct()
 {
     $this->repository = new Ajde_Config_Repository(CONFIG_DIR);
     if ($this->repository->get('security.secret') === '_RANDOM_12_16_OR_32_CHAR_STRING_') {
         Ajde_Dump::warn('Using unsafe secret: your app is insecure. See security.json');
     }
 }
예제 #3
0
 public function getModel($name)
 {
     // If during the session class definitions has changed, this will throw an exception.
     try {
         return unserialize($this->get($name));
     } catch (Exception $e) {
         Ajde_Dump::warn('Model definition changed during cookie period');
         return false;
     }
 }
예제 #4
0
 public function view()
 {
     // we want to display published nodes only
     if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
         Ajde::app()->getRequest()->set('filterPublished', true);
     }
     // get the current slug
     $slug = $this->getSlug();
     $node = new NodeModel();
     $node->loadBySlug($slug);
     $this->node = $node;
     if ($node->checkPublished() === false) {
         Ajde_Dump::warn('Previewing unpublished node');
     }
     // check if we have a hit
     if (!$node->hasLoaded()) {
         Ajde::app()->getResponse()->redirectNotFound();
     }
     Ajde_Event::trigger($this, 'onAfterNodeLoaded', [$node]);
     // update cache
     Ajde_Cache::getInstance()->updateHash($node->hash());
     Ajde_Cache::getInstance()->updateHash($node->getChildren()->hash());
     Ajde_Cache::getInstance()->addLastModified(strtotime($node->updated));
     // set title
     if (!Ajde::app()->getDocument()->hasNotEmpty('title')) {
         Ajde::app()->getDocument()->setTitle($node->getTitle());
     }
     // set summary
     if ($node->summary) {
         Ajde::app()->getDocument()->setDescription($node->summary);
     }
     // set author
     $node->loadParent('user');
     /** @var UserModel $owner */
     $owner = $node->getUser();
     Ajde::app()->getDocument()->setAuthor($owner->getFullname());
     // set template
     $nodetype = $node->getNodetype();
     $action = str_replace(' ', '_', strtolower($nodetype->get($nodetype->getDisplayField())));
     $this->setAction($action);
     // featured image
     if ($image = $node->featuredImage()) {
         Ajde::app()->getDocument()->setFeaturedImage($image);
     }
     // pass node to document, only first
     $layout = Ajde::app()->getDocument()->getLayout();
     if (!$layout->hasAssigned('node')) {
         $layout->assign('node', $node);
     }
     // pass node to view
     $this->getView()->assign('node', $node);
     // render the temnplate
     return $this->render();
 }
예제 #5
0
파일: Json.php 프로젝트: nabble/ajde
 public function getBody()
 {
     $body = json_encode($this->get('body'));
     if (config('app.debug')) {
         if (Ajde_Dump::getAll()) {
             foreach (Ajde_Dump::getAll() as $source => $var) {
                 //if ($var[1] === true) { $expand = true; }
                 $body .= "<pre class='xdebug-var-dump'>" . var_export($var[0], true) . '</pre>';
             }
         }
     }
     return $body;
 }
 public function view()
 {
     Ajde_Model::register($this);
     // Direct object creation and chaining only from PHP 5.3!
     // Use $blog = new BlogCollection() instead
     /* @var $samples SamplesCollection */
     $samples = SamplesCollection::create()->orderBy('sort', Ajde_Query::ORDER_ASC)->filter('published', 1);
     if ($this->hasId()) {
         $samples->addFilter(new Ajde_Filter_Where('id', Ajde_Filter::FILTER_EQUALS, $this->getId()));
     }
     $this->getView()->assign('samples', $samples);
     Ajde_Dump::warn('This is a test warning');
     Ajde::app()->getDocument()->setDescription("This is the samples module");
     return $this->render();
 }
예제 #7
0
 public function item()
 {
     // we want to display published nodes only
     if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
         Ajde::app()->getRequest()->set('filterPublished', true);
     }
     // get the current slug
     $slug = $this->getSlug();
     /* @var $product ProductModel */
     $product = new ProductModel();
     $product->loadBySlug($slug);
     $this->product = $product;
     if ($product->getPublished() === false) {
         Ajde_Dump::warn('Previewing unpublished product');
     }
     // check if we have a hit
     if (!$product->hasLoaded()) {
         Ajde::app()->getResponse()->redirectNotFound();
     }
     Ajde_Event::trigger($this, 'onAfterProductLoaded', [$product]);
     // update cache
     Ajde_Cache::getInstance()->updateHash($product->hash());
     Ajde_Cache::getInstance()->addLastModified(strtotime($product->updated));
     // set title
     if (!Ajde::app()->getDocument()->hasNotEmpty('title')) {
         Ajde::app()->getDocument()->setTitle($product->getTitle());
     }
     // set summary
     if ($product->content) {
         Ajde::app()->getDocument()->setDescription(Ajde_Component_String::trim(strip_tags($product->content), '100'));
     }
     // set author
     $product->loadParent('user');
     /** @var UserModel $owner */
     $owner = $product->getUser();
     Ajde::app()->getDocument()->setAuthor($owner->getFullname());
     // featured image
     if ($image = $product->featuredImage()) {
         Ajde::app()->getDocument()->setFeaturedImage($image);
     }
     // pass node to view
     $this->setAction('item');
     $this->getView()->assign('product', $product);
     // render the template
     return $this->render();
 }
예제 #8
0
 public function createHash($password)
 {
     // @see http://net.tutsplus.com/tutorials/php/understanding-hash-functions-and-keeping-passwords-safe/
     if (CRYPT_BLOWFISH !== 1) {
         Ajde_Dump::warn('BLOWFISH algorithm not available for hashing, using MD5 instead');
         // Use MD5
         $algo = '$1';
         $cost = '';
         $unique_salt = $this->generateSecret(12);
     } else {
         // Use BLOWFISH
         $algo = '$2a';
         $cost = '$10';
         $unique_salt = $this->generateSecret(22);
     }
     $hash = crypt($password, $algo . $cost . '$' . $unique_salt);
     if (empty($hash)) {
         // TODO:
         throw new Ajde_Exception('crypt() algorithm failed');
     }
     return $hash;
 }
예제 #9
0
 public static function trace(Exception $exception, $output = self::EXCEPTION_TRACE_HTML)
 {
     if (Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
         $output = self::EXCEPTION_TRACE_LOG;
     }
     if ($exception instanceof ErrorException) {
         $type = "PHP Error " . self::getErrorType($exception->getSeverity());
     } elseif ($exception instanceof Ajde_Exception) {
         $type = "Uncaught application exception" . ($exception->getCode() ? ' ' . $exception->getCode() : '');
     } else {
         $type = "Uncaught PHP exception " . $exception->getCode();
     }
     switch ($output) {
         case self::EXCEPTION_TRACE_HTML:
             if (ob_get_level()) {
                 ob_clean();
             }
             $traceMessage = '<ol reversed="reversed">';
             self::$firstApplicationFileExpanded = false;
             foreach ($exception->getTrace() as $item) {
                 $arguments = null;
                 if (!empty($item['args'])) {
                     ob_start();
                     var_dump($item['args']);
                     $dump = ob_get_clean();
                     $arguments = sprintf(' with arguments: %s', $dump);
                 }
                 $traceMessage .= sprintf("<li><em>%s</em>%s<strong>%s</strong><br/>in %s<br/>&nbsp;\n", !empty($item['class']) ? $item['class'] : '&lt;unknown class&gt;', !empty($item['type']) ? $item['type'] : '::', !empty($item['function']) ? $item['function'] : '&lt;unknown function&gt;', self::embedScript(issetor($item['file'], null), issetor($item['line'], null), $arguments, false));
                 $traceMessage .= '</li>';
             }
             $traceMessage .= '</ol>';
             $exceptionDocumentation = '';
             if ($exception instanceof Ajde_Exception && $exception->getCode()) {
                 $exceptionDocumentation = sprintf("<div style='margin-top: 4px;'><img src='//" . Config::get('site_root') . "public/images/_core/globe_16.png' style='vertical-align: bottom;' title='Primary key' width='16' height='16' /> <a href='%s'>Documentation on error %s</a>&nbsp;</div>", Ajde_Core_Documentation::getUrl($exception->getCode()), $exception->getCode());
             }
             $exceptionMessage = sprintf("<div style='background-color:#F1F1F1;background-image: url(\"//" . Config::get('site_root') . "public/images/_core/warning_48.png\"); background-repeat: no-repeat; background-position: 10px 10px; border: 1px solid silver; padding: 10px 10px 10px 70px;'><h3 style='margin:0;'>%s:</h3><h2 style='margin:0;'>%s</h2> Exception thrown in %s%s</div><h3>Trace:</h3>\n", $type, $exception->getMessage(), self::embedScript($exception->getFile(), $exception->getLine(), $arguments, false), $exceptionDocumentation);
             $exceptionDump = '';
             if (class_exists("Ajde_Dump")) {
                 if ($dumps = Ajde_Dump::getAll()) {
                     $exceptionDump .= '<h2>Dumps</h2>';
                     foreach ($dumps as $dump) {
                         ob_start();
                         var_dump($dump[0]);
                         $exceptionDump .= ob_get_clean();
                     }
                 }
             }
             $style = false;
             if (file_exists(MODULE_DIR . '_core/res/css/debugger/handler.css')) {
                 $style = file_get_contents(MODULE_DIR . '_core/res/css/debugger/handler.css');
             }
             if ($style === false) {
                 // For shutdown() call
                 $style = 'body {font: 13px sans-serif;} a {color: #005D9A;} a:hover {color: #9A0092;} h2 {color: #005D9A;} span > a {color: #9A0092;}';
             }
             $style = '<style>' . $style . '</style>';
             $message = $style . $exceptionDump . $exceptionMessage . $traceMessage;
             break;
         case self::EXCEPTION_TRACE_LOG:
             $message = 'Request ' . $_SERVER["REQUEST_URI"] . " triggered:" . PHP_EOL;
             $message .= sprintf("%s: %s in %s on line %s", $type, $exception->getMessage(), $exception->getFile(), $exception->getLine());
             foreach (array_reverse($exception->getTrace()) as $i => $line) {
                 $message .= PHP_EOL;
                 $message .= $i . '. ' . issetor($line['file']) . ' on line ' . issetor($line['line']);
             }
             break;
     }
     return $message;
 }
예제 #10
0
파일: Handler.php 프로젝트: nabble/ajde
 /**
  * @param Throwable $exception
  * @param int       $output
  *
  * @return string
  */
 public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
 {
     $simpleJsonTrace = false;
     if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
         $output = self::EXCEPTION_TRACE_LOG;
     }
     $type = self::getTypeDescription($exception);
     switch ($output) {
         case self::EXCEPTION_TRACE_HTML:
             if (ob_get_level()) {
                 ob_clean();
             }
             $traceMessage = '<ol reversed="reversed">';
             self::$firstApplicationFileExpanded = false;
             foreach ($exception->getTrace() as $item) {
                 $arguments = null;
                 if (!empty($item['args'])) {
                     ob_start();
                     var_dump($item['args']);
                     $dump = ob_get_clean();
                     $arguments = sprintf(' with arguments: %s', $dump);
                 }
                 $traceMessage .= sprintf("<li><code><em>%s</em>%s<strong>%s</strong></code><br/>in %s<br/>&nbsp;\n", !empty($item['class']) ? $item['class'] : '&lt;unknown class&gt;', !empty($item['type']) ? $item['type'] : '::', !empty($item['function']) ? $item['function'] : '&lt;unknown function&gt;', self::embedScript(issetor($item['file'], null), issetor($item['line'], null), $arguments, false));
                 $traceMessage .= '</li>';
             }
             $traceMessage .= '</ol>';
             $exceptionDocumentation = '';
             if ($exception instanceof Ajde_Exception && $exception->getCode()) {
                 $exceptionDocumentation = sprintf("<div style='margin-top: 4px;'><img src='" . config('app.rootUrl') . MEDIA_DIR . "_core/globe_16.png' style='vertical-align: bottom;' title='Primary key' width='16' height='16' /> <a href='%s'>Documentation on error %s</a>&nbsp;</div>", Ajde_Core_Documentation::getUrl($exception->getCode()), $exception->getCode());
             }
             $exceptionMessage = sprintf("<summary style='background-image: url(\"" . config('app.rootUrl') . MEDIA_DIR . "_core/warning_48.png\");'><h3 style='margin:0;'>%s:</h3><h2 style='margin:0;'>%s</h2> Exception thrown in %s%s</summary><h3>Trace:</h3>\n", $type, $exception->getMessage(), self::embedScript($exception->getFile(), $exception->getLine(), $arguments, false), $exceptionDocumentation);
             $exceptionDump = '';
             if (class_exists(Ajde_Dump::class)) {
                 if ($dumps = Ajde_Dump::getAll()) {
                     $exceptionDump .= '<h2>Dumps</h2>';
                     foreach ($dumps as $source => $dump) {
                         ob_start();
                         echo $source;
                         if (class_exists(Kint::class)) {
                             Kint::dump($dump[0]);
                         } else {
                             echo '<pre>';
                             var_dump($dump[0]);
                             echo '</pre>';
                         }
                         $exceptionDump .= ob_get_clean() . '<h2>Error message</h2>';
                     }
                 }
             }
             $style = false;
             if (file_exists(LOCAL_ROOT . CORE_DIR . MODULE_DIR . '_core/res/css/debugger/handler.css')) {
                 $style = file_get_contents(LOCAL_ROOT . CORE_DIR . MODULE_DIR . '_core/res/css/debugger/handler.css');
             }
             if ($style === false) {
                 // For shutdown() call
                 $style = 'body {font: 13px sans-serif;} a {color: #005D9A;} a:hover {color: #9A0092;} h2 {color: #005D9A;} span > a {color: #9A0092;}';
             }
             $style = '<style>' . $style . '</style>';
             $script = '<script>document.getElementsByTagName("base")[0].href="";</script>';
             if (Ajde::app()->getRequest()->isAjax()) {
                 $collapsed = $exceptionDump . $exceptionMessage . $traceMessage;
                 $header = '';
             } else {
                 $collapsed = '<div id="details">' . $exceptionDump . $exceptionMessage . $traceMessage . '</div>';
                 $header = '<header><h1><img src="' . config('app.rootUrl') . MEDIA_DIR . 'ajde-small.png">Something went wrong</h1><a href="javascript:history.go(-1);">Go back</a> <a href="#details">Show details</a></header>';
             }
             $message = $style . $script . $header . $collapsed;
             break;
         case self::EXCEPTION_TRACE_ONLY:
             $message = '';
             foreach (array_reverse($exception->getTrace()) as $i => $line) {
                 $message .= $i . '. ' . (isset($line['file']) ? $line['file'] : 'unknown file') . ' on line ' . (isset($line['line']) ? $line['line'] : 'unknown line');
                 $message .= PHP_EOL;
             }
             break;
         case self::EXCEPTION_TRACE_LOG:
             $message = 'UNCAUGHT EXCEPTION' . PHP_EOL;
             $message .= "\tRequest " . $_SERVER['REQUEST_URI'] . ' triggered:' . PHP_EOL;
             $message .= sprintf("\t%s: %s in %s on line %s", $type, $exception->getMessage(), $exception->getFile(), $exception->getLine());
             foreach (array_reverse($exception->getTrace()) as $i => $line) {
                 $message .= PHP_EOL;
                 $message .= "\t" . $i . '. ' . (isset($line['file']) ? $line['file'] : 'unknown file') . ' on line ' . (isset($line['line']) ? $line['line'] : 'unknown line');
             }
             break;
     }
     return $message;
 }
예제 #11
0
function dump($var, $collapse = false)
{
    Ajde_Dump::dump($var, $collapse);
}