Пример #1
0
 public function render_cell($row)
 {
     $routes = \ICanBoogie\app()->routes;
     $edit_link = new A("Edit", $routes['admin:posts:edit']->format($row), ['class' => 'btn btn-primary']);
     $delete_link = new A("Delete", $routes['admin:posts:delete']->format($row), ['class' => 'btn btn-danger']);
     return $edit_link . ' ' . $delete_link;
 }
Пример #2
0
 public function __toString()
 {
     $collected = $this->get();
     #
     # cached ouput
     #
     try {
         if ($this->use_cache) {
             $recent = 0;
             $root = DOCUMENT_ROOT;
             foreach ($collected as $file) {
                 $recent = max($recent, filemtime($root . $file));
             }
             $cache = new FileCache([FileCache::T_REPOSITORY => \ICanBoogie\app()->config['repository.files'] . '/assets', FileCache::T_MODIFIED_TIME => $recent]);
             $key = sha1(implode(',', $collected)) . '.js';
             $rc = $cache->get($key, [$this, 'cache_construct'], [$collected]);
             if ($rc) {
                 return PHP_EOL . PHP_EOL . '<script type="text/javascript" src="' . $cache->repository . '/' . $key . '"></script>' . PHP_EOL . PHP_EOL;
             }
         }
     } catch (\Exception $e) {
         echo render_exception($e);
     }
     #
     # default output
     #
     $rc = '';
     foreach ($collected as $url) {
         $rc .= '<script type="text/javascript" src="' . escape($url) . '"></script>' . PHP_EOL;
     }
     return $rc;
 }
Пример #3
0
 /**
  * If the user is authenticated and the request path is "/admin" the request is redirected to
  * the dashboard.
  *
  * @param RouteDispatcher\BeforeDispatchEvent $event
  * @param RouteDispatcher $dispatcher
  */
 public static function before_routing_dispatcher_dispatch(RouteDispatcher\BeforeDispatchEvent $event, RouteDispatcher $dispatcher)
 {
     $app = \ICanBoogie\app();
     $path = $event->request->decontextualized_path;
     if ($path !== '/admin' || $app->user->is_guest || $app->user instanceof \Icybee\Modules\Members\Member) {
         return;
     }
     $event->response = new RedirectResponse($app->routes['admin:dashboard']);
 }
Пример #4
0
 protected function render($expression)
 {
     $app = \ICanBoogie\app();
     if (isset($app->routes[$expression])) {
         $route = $app->routes[$expression];
         return $route->url;
     }
     return $app->site->resolve_view_url($expression);
 }
Пример #5
0
 /**
  * Constructor.
  *
  * Creates the Javascript and CSS collectors.
  */
 public function __construct()
 {
     $use_cache = false;
     if (function_exists('ICanBoogie\\app')) {
         $use_cache = !empty(\ICanBoogie\app()->config['cache assets']);
     }
     $this->body = new Element('body');
     $this->js = new JSCollector($use_cache);
     $this->css = new CSSCollector($use_cache);
 }
Пример #6
0
 /**
  * Returns the application's module collection.
  *
  * @return ModuleCollection
  */
 private static function get_app_modules()
 {
     static $modules;
     if ($modules === null) {
         /* @var $app CoreBindings */
         $app = \ICanBoogie\app();
         $modules = $app->modules;
     }
     return $modules;
 }
Пример #7
0
 public static function request_context_get_user(\ICanBoogie\HTTP\Request\Context $context)
 {
     $app = \ICanBoogie\app();
     $user_id = $app->session->user_id;
     if ($user_id) {
         try {
             return $app->models['users'][$user_id];
         } catch (RecordNotFound $e) {
             $app->session->user_id = null;
         }
     }
     return new User();
 }
Пример #8
0
 protected function __construct()
 {
     $app = \ICanBoogie\app();
     if ($app->config['cache views']) {
         $collection = $app->vars['cached_views'];
         if (!$collection) {
             $collection = $this->collect($app);
             $app->vars['cached_views'] = $collection;
         }
     } else {
         $collection = $this->collect($app);
     }
     $this->collection = $collection;
 }
Пример #9
0
    public function __toString()
    {
        $collected = $this->get();
        try {
            if ($this->use_cache) {
                $recent = 0;
                $root = DOCUMENT_ROOT;
                foreach ($collected as $file) {
                    $recent = max($recent, filemtime($root . $file));
                }
                $cache = new FileCache([FileCache::T_REPOSITORY => \ICanBoogie\app()->config['repository.files'] . '/assets', FileCache::T_MODIFIED_TIME => $recent]);
                $key = sha1(implode(',', $collected)) . '.css';
                $rc = $cache->get($key, [$this, 'cache_construct'], [$collected]);
                if ($rc) {
                    $list = json_encode($collected);
                    return <<<EOT

<link type="text/css" href="{$cache->repository}/{$key}" rel="stylesheet" />

<script type="text/javascript">

var brickrouge_cached_css_assets = {$list};

</script>

EOT;
                }
            }
        } catch (\Exception $e) {
            echo render_exception($e);
        }
        #
        # default ouput
        #
        $rc = '';
        foreach ($collected as $url) {
            $rc .= '<link type="text/css" href="' . escape($url) . '" rel="stylesheet" />' . PHP_EOL;
        }
        return $rc;
    }
Пример #10
0
 /**
  * Creates an {@link Operation} instance from a module request.
  *
  * @param Request $request
  * @param string $module_id
  * @param string $operation_name
  *
  * @throws \Exception if the operation is not supported by the module.
  *
  * @return Operation
  */
 protected static function from_module_request(Request $request, $module_id, $operation_name)
 {
     $module = \ICanBoogie\app()->modules[$module_id];
     $class = self::resolve_operation_class($operation_name, $module);
     if (!$class) {
         throw new \Exception(format('The operation %operation is not supported by the module %module.', ['%module' => (string) $module, '%operation' => $operation_name]), 404);
     }
     return new $class($module);
 }
Пример #11
0
 /**
  * @return Application
  */
 private static function app()
 {
     return \ICanBoogie\app();
 }
Пример #12
0
 public function __construct()
 {
     $app = \ICanBoogie\app();
     $this->vars = $app->vars;
     $this->state = $app->config['cache views'];
 }
Пример #13
0
 public function alter_query_with_value(Query $query, $value)
 {
     $users = \ICanBoogie\app()->models['users']->select('id AS user_id, username');
     return $query->join($users, ['on' => 'user_id'])->and("post.user_id = ? OR username = ?", $value, $value);
 }
Пример #14
0
 function _doImages_reference_callback($matches)
 {
     // FIXME-20140921: Hook only support patron.markup, so we replaced a hack with another
     // waiting for a better solution.
     if (self::$images_reference_callback === null) {
         $hook = false;
         if (class_exists('Icybee\\Modules\\Images\\Hooks')) {
             $hook = 'Icybee\\Modules\\Images\\Hooks::textmark_images_reference';
         }
         self::$images_reference_callback = $hook;
     }
     if (self::$images_reference_callback !== false) {
         return $this->hashPart(call_user_func(self::$images_reference_callback, [], $this, $matches));
     }
     static $module;
     if (!$module) {
         $module = \ICanBoogie\app()->modules['images'];
     }
     //		echo l('<pre>in \1: \2</pre>', __FUNCTION__, $matches);
     $align = $matches[2];
     $alt = $matches[3];
     $id = $matches[4];
     # for shortcut links like ![this][].
     if (!$id) {
         $id = $alt;
     }
     $parts = explode(':', $id, 2);
     if (isset($parts[1])) {
         $entry = $module->model()->loadRange(0, 1, 'WHERE `' . $module->getConstant('TITLE') . '` = ? AND `' . $module->getConstant('ALBUM') . '` = ?', array($parts[1], $parts[0]))->fetchAndClose();
     } else {
         $entry = $module->model()->loadRange(0, 1, 'WHERE `slug` = ? OR `title` = ?', array($id, $id))->fetchAndClose();
     }
     if (!$entry) {
         $matches[2] = $matches[3];
         $matches[3] = $matches[4];
         return parent::_doImages_reference_callback($matches);
     }
     $params = array('src' => $entry->path, 'alt' => \ICanBoogie\escape($alt), 'width' => $entry->width, 'height' => $entry->height);
     if ($align) {
         switch ($align) {
             case '<':
                 $align = 'left';
                 break;
             case '=':
             case '|':
                 $align = 'middle';
                 break;
             case '>':
                 $align = 'right';
                 break;
         }
         $params['align'] = $align;
     }
     # the image has been found is the database
     return $this->hashPart($this->createElement('img', $params));
 }
Пример #15
0
 /**
  * Adds SEO properties to exported pages.
  *
  * @param Operation\ProcessEvent $event
  * @param Operation $operation
  */
 public static function on_operation_export(Operation\ProcessEvent $event, Operation $operation)
 {
     $records =& $event->rc;
     $keys = array_keys($records);
     $metas = \ICanBoogie\app()->models['registry/node']->where(array('targetid' => $keys, 'name' => array('document_title', 'description')))->all(\PDO::FETCH_NUM);
     foreach ($metas as $meta) {
         list($pageid, $property, $value) = $meta;
         $records[$pageid]->seo[$property] = $value;
     }
 }
Пример #16
0
 public function alter_query_with_value(Query $query, $value)
 {
     $categories = \ICanBoogie\app()->models['categories']->select('`id` AS category_id, `slug` AS category_slug');
     return $query->join($categories, ['on' => 'category_id'])->filter_by_category_slug($value);
 }
Пример #17
0
 public static function markup_category_home(array $args, \Patron\Engine $patron, $template)
 {
     $bind = \ICanBoogie\app()->models['categories']->order('name')->all;
     return $patron($template, $bind);
 }
Пример #18
0
 public static function markup_posts_latests(array $args, $engine, $template)
 {
     $bind = \ICanBoogie\app()->models['posts']->ordered->limit(5)->all;
     return $engine($template, $bind);
 }
Пример #19
0
 public static function markup_comments_submit(array $args, $engine, $template)
 {
     $form = new SubmitForm([SubmitForm::POST_ID => $args['post']->id, SubmitForm::VALUES => \ICanBoogie\app()->request->params]);
     return $template ? $engine($template, $form) : $form;
 }
Пример #20
0
 protected function resolve_model_tags($tags, $which)
 {
     $app = $this->app;
     #
     # The model may use another model, in which case the model to use is defined using a
     # string e.g. 'contents' or 'terms/nodes'
     #
     if (is_string($tags)) {
         $model_name = $tags;
         if ($model_name == 'inherit') {
             $class = get_parent_class($this);
             foreach ($app->modules->descriptors as $module_id => $descriptor) {
                 if ($class != $descriptor['class']) {
                     continue;
                 }
                 $model_name = $app->models[$module_id];
                 break;
             }
         }
         $tags = [Model::EXTENDING => $model_name];
     }
     #
     # defaults
     #
     $id = $this->id;
     $tags += [Model::CONNECTION => 'primary', Model::ID => $which == 'primary' ? $id : $id . '/' . $which, Model::EXTENDING => null];
     if (empty($tags[Model::NAME])) {
         $tags[Model::NAME] = ModuleCollection::format_model_name($id, $which);
     }
     #
     # relations
     #
     if (isset($tags[Model::EXTENDING])) {
         $extends =& $tags[Model::EXTENDING];
         if (is_string($extends)) {
             $extends = $this->app->models[$extends];
         }
         if (!$tags[Model::CLASSNAME]) {
             $tags[Model::CLASSNAME] = get_class($extends);
         }
     }
     #
     #
     #
     if (isset($tags[Model::IMPLEMENTING])) {
         $implements =& $tags[Model::IMPLEMENTING];
         foreach ($implements as &$implement) {
             if (isset($implement['model'])) {
                 list($implement_id, $implement_which) = explode('/', $implement['model']) + [1 => 'primary'];
                 if ($id == $implement_id && $which == $implement_which) {
                     throw new \RuntimeException(\ICanBoogie\format('Model %module/%model implements itself !', ['%module' => $id, '%model' => $which]));
                 }
                 $module = $implement_id == $id ? $this : \ICanBoogie\app()->modules[$implement_id];
                 $implement['table'] = $module->model($implement_which);
             } else {
                 if (is_string($implement['table'])) {
                     throw new \RuntimeException(\ICanBoogie\format('Model %model of module %module implements a table: %table', ['%model' => $which, '%module' => $id, '%table' => $implement['table']]));
                 }
             }
         }
     }
     #
     # default class, if none was defined.
     #
     if (empty($tags[Model::CLASSNAME])) {
         $tags[Model::CLASSNAME] = 'ICanBoogie\\ActiveRecord\\Model';
     }
     #
     # connection
     #
     $connection = $tags[Model::CONNECTION];
     if (!$connection instanceof Connection) {
         $tags[Model::CONNECTION] = $this->app->connections[$connection];
     }
     return $tags;
 }
Пример #21
0
 public function __construct()
 {
     $this->app = \ICanBoogie\app();
 }
Пример #22
0
 public static function setupBeforeClass()
 {
     self::$app = \ICanBoogie\app();
 }
Пример #23
0
 /**
  * Renders the specified view.
  *
  * @param array $args
  * @param mixed $engine
  * @param mixed $template
  *
  * @return mixed
  */
 public static function markup_call_view(array $args, $engine, $template)
 {
     return \ICanBoogie\app()->editors['view']->render($args['name'], $engine, $template);
 }
Пример #24
0
 public static function markup_cache_sidebar(array $args, $engine, $template)
 {
     $app = \ICanBoogie\app();
     $sidebar = $app->vars['cached_sidebar'];
     if (!$sidebar) {
         $app->vars['cached_sidebar'] = $sidebar = $engine($template);
     }
     return $sidebar;
 }