Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • AdminDecorator
  • AdminIndexController
  • BlockController
  • BlockDecorator
  • ConfigBlock
  • ConfigController
  • ConfigOperation
  • Core
  • DeleteBlock
  • DeleteController
  • Document
  • DocumentDecorator
  • EditBlock
  • EditController
  • FormBlock
  • Hooks
  • InterlockBlock
  • Kses
  • ManageBlock
  • Module
  • Modules
  • StatsDecorator

Constants

  • OPERATION_SAVE_MODE
  • OPERATION_SAVE_MODE_CONTINUE
  • OPERATION_SAVE_MODE_DISPLAY
  • OPERATION_SAVE_MODE_LIST
  • OPERATION_SAVE_MODE_NEW

Functions

  • slugize
  • start
  • strip_stopwords
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee;
 13 
 14 use ICanBoogie\AuthenticationRequired;
 15 use ICanBoogie\I18n;
 16 
 17 /**
 18  * Extends the Module class with the following features:
 19  *
 20  * - Special handling for the 'edit', 'new' and 'configure' blocks.
 21  * - Inter-users edit lock on records.
 22  */
 23 class Module extends \ICanBoogie\Module
 24 {
 25     const OPERATION_CONFIG = 'config';
 26 
 27     /**
 28      * Returns the views defined by the module.
 29      *
 30      * Each _key/value_ pair defines a view, _key_ is its type, _value_ its definition:
 31      *
 32      * - (string) title: Title of the view. The title of the view is localized use the
 33      * "<module_flat_id>.view" scope.
 34      *
 35      * @return array[string]array
 36      */
 37     protected function lazy_get_views()
 38     {
 39         return array();
 40     }
 41 
 42     public function getBlock($name)
 43     {
 44         global $core;
 45 
 46         $args = func_get_args();
 47 
 48         $class_name = $this->resolve_block_class($name);
 49 
 50         if ($class_name)
 51         {
 52             array_shift($args);
 53 
 54             I18n::push_scope($this->flat_id);
 55             I18n::push_scope($this->flat_id . '.' . $name);
 56 
 57             try
 58             {
 59                 $block = new $class_name($this, array(), $args);
 60 
 61 //              $rendered_block = $block->render();
 62             }
 63             catch (\ICanBoogie\SecurityException $e)
 64             {
 65                 I18n::pop_scope();
 66                 I18n::pop_scope();
 67 
 68                 throw $e;
 69             }
 70             catch (\Exception $e)
 71             {
 72                 $block = \ICanBoogie\Debug::format_alert($e);
 73             }
 74 
 75             I18n::pop_scope();
 76             I18n::pop_scope();
 77 
 78             return $block;
 79         }
 80 
 81 //      \ICanBoogie\log_info("Block class not found for <q>$name</q> falling to callbacks.");
 82 
 83         return call_user_func_array((PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 2)) ? 'parent::' . __FUNCTION__ : array($this, 'parent::' . __FUNCTION__), $args);
 84     }
 85 
 86     protected function resolve_block_class($name)
 87     {
 88         $module = $this;
 89         $class_name = \ICanBoogie\camelize(\ICanBoogie\underscore($name)) . 'Block';
 90 
 91         while ($module)
 92         {
 93             $try = $module->descriptor[self::T_NAMESPACE] . '\\' . $class_name;
 94 
 95             if (class_exists($try, true))
 96             {
 97                 return $try;
 98             }
 99 
100             $module = $module->parent;
101         }
102     }
103 
104     private function create_activerecord_lock_name($key)
105     {
106         return "activerecord_locks.$this->flat_id.$key";
107     }
108 
109     /**
110      * Locks an activerecord.
111      *
112      * @param int $key
113      *
114      * @throws \Exception
115      * @return array|false
116      */
117     public function lock_entry($key, &$lock=null)
118     {
119         global $core;
120 
121         $user_id = $core->user_id;
122 
123         if (!$user_id)
124         {
125             throw new AuthenticationRequired();
126         }
127 
128         if (!$key)
129         {
130             throw new \InvalidArgumentException('The record key is required.');
131         }
132 
133         #
134         # is the node already locked by another user ?
135         #
136         $registry = $core->registry;
137 
138         $lock_name = $this->create_activerecord_lock_name($key);
139         $lock = json_decode($registry[$lock_name], true);
140         $lock_uid = $user_id;
141         $lock_until = null;
142 
143         $now = time();
144         $until = date('Y-m-d H:i:s', $now + 2 * 60);
145 
146         if ($lock)
147         {
148             $lock_uid = $lock['uid'];
149             $lock_until = $lock['until'];
150 
151             if ($now > strtotime($lock_until))
152             {
153                 #
154                 # Because the lock has expired we can claim it.
155                 #
156 
157                 $lock_uid = $user_id;
158             }
159             else if ($lock_uid != $user_id)
160             {
161                 return false;
162             }
163         }
164 
165         $lock = array
166         (
167             'uid' => $lock_uid,
168             'until' => $until
169         );
170 
171         $registry[$lock_name] = json_encode($lock);
172 
173         return true;
174     }
175 
176     public function unlock_entry($key)
177     {
178         global $core;
179 
180         $registry = $core->registry;
181 
182         $lock_name = $this->create_activerecord_lock_name($key);
183         $lock = json_decode($registry[$lock_name], true);
184 
185         if (!$lock)
186         {
187             return;
188         }
189 
190         if ($lock['uid'] != $core->user_id)
191         {
192             return false;
193         }
194 
195         unset($registry[$lock_name]);
196 
197         return true;
198     }
199 }
Autodoc API documentation generated by ApiGen 2.8.0