public function associate() { $provider = $this->request->param('provider'); if (empty($provider)) { throw new NotFoundException('Invalid provider'); } $this->set(compact('provider')); if ($this->request->data('confirm_association')) { $this->User->recursive = -1; $originalUser = $this->User->findById($this->Auth->user('id')); $this->Session->write('Socialites.originalUser', $originalUser); switch ($provider) { case 'twitter': $eventName = 'Socialites.oauthAuthorize'; $event = Croogo::dispatchEvent($eventName, $this); return $this->redirect(); break; default: $config = Configure::read('Socialites.Providers.' . $provider); $fqcn = Configure::read('SocialitesProviderRegistry.' . $provider); $Provider = new $fqcn($config); return $this->redirect($Provider->getAuthorizationUrl()); break; } } else { if (!$this->Auth->user('id')) { $this->Session->setFlash(__d('socialites', 'You are not logged in'), 'flash'); return $this->redirect($this->referer()); } } }
/** * Filter block shortcode in node body, eg [block:snippet] and replace it with * the block content * * @param CakeEvent $event * @return void */ public function filterBlockShortcode($event) { static $converter = null; if (!$converter) { $converter = new StringConverter(); } $View = $event->subject; $body = null; if (isset($event->data['content'])) { $body =& $event->data['content']; } elseif (isset($event->data['node'])) { $body =& $event->data['node'][key($event->data['node'])]['body']; } $parsed = $converter->parseString('block|b', $body, array('convertOptionsToArray' => true)); $regex = '/\\[(block|b):([A-Za-z0-9_\\-]*)(.*?)\\]/i'; foreach ($parsed as $blockAlias => $config) { $block = $View->Regions->block($blockAlias); preg_match_all($regex, $body, $matches); if (isset($matches[2][0])) { $replaceRegex = '/' . preg_quote($matches[0][0]) . '/'; $body = preg_replace($replaceRegex, $block, $body); } } Croogo::dispatchEvent('Helper.Layout.beforeFilter', $View, array('content' => &$body, 'options' => array())); }
public function admin_process() { $action = $this->request->data['Edition']['action']; $ids = array(); foreach ($this->request->data['Edition'] as $id => $value) { if ($id != 'action' && $value['id'] == 1) { $ids[] = $id; } } if (count($ids) == 0 || $action == null) { $this->Session->setFlash(__d('croogo', 'No items selected.'), 'default', array('class' => 'error')); $this->redirect(array('action' => 'index')); } $actionProcessed = $this->Edition->processAction($action, $ids); $eventName = 'Controller.Editions.after' . ucfirst($action); if ($actionProcessed) { switch ($action) { case 'delete': $messageFlash = __d('croogo', 'Edições excluidas!'); break; case 'publish': $messageFlash = __d('croogo', 'Edições publicadas!'); break; case 'unpublish': $messageFlash = __d('croogo', 'Edições despublicadas'); break; } $this->Session->setFlash($messageFlash, 'default', array('class' => 'success')); Croogo::dispatchEvent($eventName, $this, compact($ids)); } else { $this->Session->setFlash(__d('croogo', 'An error occurred.'), 'default', array('class' => 'error')); } $this->redirect(array('action' => 'index')); }
/** * Setup Link chooser values * * @return void */ public function onSetupLinkChooser($event) { $linkChoosers = array(); $linkChoosers['Images'] = array('title' => 'Images', 'description' => 'Attachments with an image mime type.', 'url' => array('plugin' => 'file_manager', 'controller' => 'attachments', 'action' => 'index', '?' => array('chooser_type' => 'image', 'chooser' => 1, 'KeepThis' => true, 'TB_iframe' => true, 'height' => 400, 'width' => 600))); $linkChoosers['Files'] = array('title' => 'Files', 'description' => 'Attachments with other mime types, ie. pdf, xls, doc, etc.', 'url' => array('plugin' => 'file_manager', 'controller' => 'attachments', 'action' => 'index', '?' => array('chooser_type' => 'file', 'chooser' => 1, 'KeepThis' => true, 'TB_iframe' => true, 'height' => 400, 'width' => 600))); Croogo::mergeConfig('Menus.linkChoosers', $linkChoosers); }
public function saveUrl($data) { $event = Croogo::dispatchEvent('Model.Node.beforeSaveNode', $this, compact('data')); $this->saveWithMeta($event->data['data']); $event = Croogo::dispatchEvent('Model.Node.afterSaveNode', $this, $event->data); return true; }
/** * Test [menu] shortcode */ public function testMenuShortcode() { $content = '[menu:blogroll]'; $this->View->viewVars['menus_for_layout']['blogroll'] = array('Menu' => array('id' => 6, 'title' => 'Blogroll', 'alias' => 'blogroll'), 'threaded' => array()); Croogo::dispatchEvent('Helper.Layout.beforeFilter', $this->View, array('content' => &$content)); $this->assertContains('menu-6', $content); $this->assertContains('class="menu"', $content); }
/** * Read configured Translate.models and hook the appropriate behaviors */ public static function translateModels() { $path = 'admin:true/plugin:translate/controller:translate/action:index/:id/'; foreach (Configure::read('Translate.models') as $model => $config) { Croogo::hookBehavior($model, 'Translate.CroogoTranslate', $config); Croogo::hookAdminRowAction(Inflector::pluralize($model) . '/admin_index', __d('croogo', 'Translate'), array($path . $model => array('title' => false, 'options' => array('icon' => 'translate', 'data-title' => __d('croogo', 'Translate'))))); } }
/** * initialize * * @param Controller $controller instance of controller * @return void */ public function initialize(Controller $controller) { $this->_controller = $controller; if ($this->_config('multiRole')) { Croogo::hookAdminTab('Users/admin_add', 'Roles', 'Acl.admin/roles'); Croogo::hookAdminTab('Users/admin_edit', 'Roles', 'Acl.admin/roles'); } }
/** * Test [vocabulary] shortcode */ public function testVocabularyShortcode() { $content = '[vocabulary:categories type="blog"]'; $this->View->viewVars['vocabularies_for_layout']['categories'] = array('Vocabulary' => array('id' => 1, 'title' => 'Categories', 'alias' => 'categories'), 'threaded' => array()); Croogo::dispatchEvent('Helper.Layout.beforeFilter', $this->View, array('content' => &$content)); $this->assertContains('vocabulary-1', $content); $this->assertContains('class="vocabulary"', $content); }
/** * Test [node] shortcode */ public function testNodeShortcode() { $content = '[node:recent_posts conditions="Node.type:blog" order="Node.id DESC" limit="5"]'; $this->View->viewVars['nodes_for_layout']['recent_posts'] = array(array('Node' => array('id' => 1, 'title' => 'Hello world', 'slug' => 'hello-world', 'type' => 'blog'))); Croogo::dispatchEvent('Helper.Layout.beforeFilter', $this->View, array('content' => &$content)); $this->assertContains('node-list-recent_posts', $content); $this->assertContains('class="node-list"', $content); }
/** * Hook admin tabs */ protected function _adminTabs() { $controller = Inflector::camelize($this->request->params['controller']); $title = __d('pltfrm', 'Webhosting product'); $element = 'Pltfrm.admin/node_webhosting_product_tab'; $options = array('elementData' => array('webhostingHostGroups' => array('aaaaa', 'ffffff', 'fdddd'))); Croogo::hookAdminTab("{$controller}/admin_add", $title, $element, $options); Croogo::hookAdminTab("{$controller}/admin_edit", $title, $element, $options); }
/** * Hook helper */ public function onBootstrapComplete($event) { foreach ((array) Configure::read('Wysiwyg.actions') as $action => $settings) { if (is_numeric($action)) { $action = $settings; } $actionE = explode('/', $action); Croogo::hookHelper($actionE['0'], 'Ckeditor.Ckeditor'); } }
/** * Setup Link chooser values * * @return void */ public function onSetupLinkChooser($event) { $Type = ClassRegistry::init('Taxonomy.Type'); $types = $Type->find('all', array('fields' => array('alias', 'title', 'description'))); $linkChoosers = array(); foreach ($types as $type) { $linkChoosers[$type['Type']['title']] = array('title' => $type['Type']['title'], 'description' => $type['Type']['description'], 'url' => array('plugin' => 'nodes', 'controller' => 'nodes', 'action' => 'index', '?' => array('type' => $type['Type']['alias'], 'chooser' => 1, 'KeepThis' => true, 'TB_iframe' => true, 'height' => 400, 'width' => 600))); } Croogo::mergeConfig('Menus.linkChoosers', $linkChoosers); }
/** * Hook admin tabs when type allows commenting */ protected function _adminTabs() { if (empty($this->_View->viewVars['type']['Type']['comment_status'])) { return; } $controller = Inflector::camelize($this->request->params['controller']); $title = __d('croogo', 'Comments'); $element = 'Comments.admin/comments_tab'; Croogo::hookAdminTab("{$controller}/admin_add", $title, $element); Croogo::hookAdminTab("{$controller}/admin_edit", $title, $element); }
public function beforeDelete($cascade = true) { if (!parent::beforeDelete($cascade)) { return false; } $Event = Croogo::dispatchEvent('FileStorage.beforeDelete', $this, array('cascade' => $cascade, 'adapter' => $this->field('adapter'))); if ($Event->isStopped()) { return false; } return true; }
/** * Hook admin tabs when $taxonomy is set */ protected function _adminTabs() { $controller = Inflector::camelize($this->request->params['controller']); if (empty($this->_View->viewVars['taxonomy']) || $controller == 'Terms') { return; } $title = __d('croogo', 'Terms'); $element = 'Taxonomy.admin/terms_tab'; Croogo::hookAdminTab("{$controller}/admin_add", $title, $element); Croogo::hookAdminTab("{$controller}/admin_edit", $title, $element); }
/** * Gets valid statuses based on type * * @param string $type Status type if applicable * @return array Array of statuses */ public function status($statusType = 'publishing', $accessType = 'public') { $values = $this->_defaultStatus($statusType); $data = compact('statusType', 'accessType', 'values'); $event = Croogo::dispatchEvent('Croogo.Status.status', null, $data); if (array_key_exists('values', $event->data)) { return $event->data['values']; } else { return $values; } }
/** * testDispatchHelperEvents */ public function testDispatchHelperEvents() { $eventNames = array('Helper.Layout.afterFilter', 'Helper.Layout.beforeFilter'); App::uses('View', 'View'); $View = new View(); foreach ($eventNames as $name) { $event = Croogo::dispatchEvent($name, $View); $this->assertTrue($event->result, sprintf('Event: %s', $name)); $this->assertInstanceOf('View', $event->subject()); } }
/** * test Croogo::hookApiComponent */ public function testHookApiComponent() { $hooks = Configure::read('Hook.controller_properties'); Configure::write('Hook.controller_properties', array()); Croogo::hookApiComponent('Example', 'Example.ExampleApi'); Croogo::hookApiComponent('Example', array('Users.UserApi' => array('priority' => 2))); $expected = array('Example' => array('_apiComponents' => array('Example.ExampleApi' => array('priority' => 8), 'Users.UserApi' => array('priority' => 2)))); $result = Configure::read('Hook.controller_properties'); $this->assertEquals($expected, $result); Configure::write('Hook.controller_properties', $hooks); }
/** * Hook admin tabs for controllers whom its primary model has MetaBehavior attached. */ protected function _adminTabs() { $Model = $this->_controller->{$this->_controller->modelClass}; if ($Model && !$Model->Behaviors->attached('Meta')) { return; } $controller = $this->_controller->name; $title = __d('croogo', 'Custom Fields'); $element = 'Meta.admin/meta_tab'; Croogo::hookAdminBox("{$controller}/admin_add", $title, $element); Croogo::hookAdminBox("{$controller}/admin_edit", $title, $element); }
/** * Hook admin menu element to set role parent */ protected function _setupRole() { $title = __d('croogo', 'Parent Role'); $element = 'Acl.admin/parent_role'; Croogo::hookAdminTab('Roles/admin_add', $title, $element); Croogo::hookAdminTab('Roles/admin_edit', $title, $element); $this->_controller->Role->bindAro(); $id = null; if (!empty($this->_controller->request->params['pass'][0])) { $id = $this->_controller->request->params['pass'][0]; } $this->_controller->set('parents', $this->_controller->Role->allowedParents($id)); }
/** * Constructor * * @access public */ public function __construct() { Croogo::applyHookProperties('Hook.controller_properties'); parent::__construct(); if ($this->name == 'CakeError') { $this->_set(Router::getPaths()); $this->params = Router::getParams(); $this->constructClasses(); $this->Component->initialize($this); $this->beforeFilter(); $this->Component->triggerCallback('startup', $this); } }
/** * Setup Link chooser values * * @return void */ public function onSetupLinkChooser($event) { $this->Vocabulary = ClassRegistry::init('Taxonomy.Vocabulary'); $vocabularies = $this->Vocabulary->find('all', array('joins' => array(array('table' => 'types_vocabularies', 'alias' => 'TypesVocabulary', 'conditions' => 'Vocabulary.id = TypesVocabulary.vocabulary_id'), array('table' => 'types', 'alias' => 'Type', 'conditions' => 'TypesVocabulary.type_id = Type.id')))); $linkChoosers = array(); foreach ($vocabularies as $vocabulary) { foreach ($vocabulary['Type'] as $type) { $title = $type['title'] . ' ' . $vocabulary['Vocabulary']['title']; $linkChoosers[$title] = array('description' => $vocabulary['Vocabulary']['description'], 'url' => array('plugin' => 'taxonomy', 'controller' => 'terms', 'action' => 'index', $vocabulary['Vocabulary']['id'], '?' => array('type' => $type['alias'], 'chooser' => 1, 'KeepThis' => true, 'TB_iframe' => true, 'height' => 400, 'width' => 600))); } } Croogo::mergeConfig('Menus.linkChoosers', $linkChoosers); }
public function transform($markdownText) { $environment = Environment::createCommonMarkEnvironment(); $beforeParseEvent = Croogo::dispatchEvent('Helper.Markdown.beforeMarkdownParse', $this->_View, array('environment' => $environment, 'markdown' => $markdownText)); $markdownText = $beforeParseEvent->data['markdown']; $environment = $beforeParseEvent->data['environment']; $parser = new DocParser($environment); $htmlRenderer = new HtmlRenderer($environment); $documentAST = $parser->parse($markdownText); $beforeRenderEvent = Croogo::dispatchEvent('Helper.Markdown.beforeMarkdownRender', $this->_View, array('ast' => $documentAST)); $documentAST = $beforeRenderEvent->data['ast']; $rendered = $htmlRenderer->renderBlock($documentAST); $afterRenderEvent = Croogo::dispatchEvent('Helper.Markdown.afterMarkdownRender', $this->_View, array('rendered' => $rendered)); return $afterRenderEvent->data['rendered']; }
/** * Test login succesfull event */ public function testLoginSuccessful() { $cookie = $this->autoLogin->readCookie('User'); $this->assertNull($cookie); $request = new CakeRequest(); $request->data = array('User' => array('username' => 'rchavik', 'password' => 'rchavik', 'remember' => true)); $this->controller->request = $request; $subject = $this->controller; $compare = $this->autoLogin->cookie($request); $_SERVER['REQUEST_METHOD'] = 'POST'; Croogo::dispatchEvent('Controller.Users.adminLoginSuccessful', $subject); $cookie = $this->autoLogin->readCookie('User'); $this->assertNotNull($cookie); $this->assertEquals($compare, $cookie); }
public function admin_restore_login() { $formerUser = $this->Session->read('Chameleon.User'); if (empty($formerUser)) { $this->Session->setFlash('Invalid request', 'flash', array('class' => 'error')); return $this->redirect('/'); } if ($this->Session->delete('Chameleon.User')) { Croogo::dispatchEvent('Controller.Users.adminLogoutSuccessful', $this); } Croogo::dispatchEvent('Controller.Chameleon.beforeAdminLogin', $this); if ($this->Auth->login($formerUser)) { Croogo::dispatchEvent('Controller.Users.adminLoginSuccessful', $this); return $this->redirect(Configure::read('Croogo.dashboardUrl')); } }
/** * afterConstruct * * called when Controller::__construct() is complete. * Override this method to perform class configuration/initialization that * needs to be performed earlier from Controller::beforeFilter(). * * You still need to call parent::afterConstruct() method to ensure correct * behavior. */ public function afterConstruct() { Croogo::applyHookProperties('Hook.controller_properties', $this); if (isset($this->request->params['admin'])) { $this->helpers[] = 'Croogo.Croogo'; if (empty($this->helpers['Html'])) { $this->helpers['Html'] = array('className' => 'Croogo.CroogoHtml'); } if (empty($this->helpers['Form'])) { $this->helpers['Form'] = array('className' => 'Croogo.CroogoForm'); } if (empty($this->helpers['Paginator'])) { $this->helpers['Paginator'] = array('className' => 'Croogo.CroogoPaginator'); } } }
/** * Gets the dashboard markup * * @return string */ public function dashboards() { $registered = Configure::read('Dashboards'); $userId = AuthComponent::user('id'); if (empty($userId)) { return ''; } $columns = array(CroogoDashboard::LEFT => array(), CroogoDashboard::RIGHT => array(), CroogoDashboard::FULL => array()); if (empty($this->Role)) { $this->Role = ClassRegistry::init('Users.Role'); $this->Role->Behaviors->attach('Croogo.Aliasable'); } $currentRole = $this->Role->byId($this->Layout->getRoleId()); $cssSetting = $this->Layout->themeSetting('css'); if (!empty($this->_View->viewVars['boxes_for_dashboard'])) { $boxesForLayout = Hash::combine($this->_View->viewVars['boxes_for_dashboard'], '{n}.DashboardsDashboard.alias', '{n}.DashboardsDashboard'); $dashboards = array(); $registeredUnsaved = array_diff_key($registered, $boxesForLayout); foreach ($boxesForLayout as $alias => $userBox) { if (isset($registered[$alias]) && $userBox['status']) { $dashboards[$alias] = array_merge($registered[$alias], $userBox); } } $dashboards = Hash::merge($dashboards, $registeredUnsaved); $dashboards = Hash::sort($dashboards, '{s}.weight', 'ASC'); } else { $dashboards = Hash::sort($registered, '{s}.weight', 'ASC'); } foreach ($dashboards as $alias => $dashboard) { if ($currentRole != 'admin' && !in_array($currentRole, $dashboard['access'])) { continue; } $opt = array('alias' => $alias, 'dashboard' => $dashboard); Croogo::dispatchEvent('Croogo.beforeRenderDashboard', $this->_View, compact('alias', 'dashboard')); $dashboardBox = $this->_View->element('Extensions.admin/dashboard', $opt); Croogo::dispatchEvent('Croogo.afterRenderDashboard', $this->_View, compact('alias', 'dashboard', 'dashboardBox')); if ($dashboard['column'] === false) { $dashboard['column'] = count($columns[0]) <= count($columns[1]) ? CroogoDashboard::LEFT : CroogoDashboard::RIGHT; } $columns[$dashboard['column']][] = $dashboardBox; } $dashboardTag = $this->settings['dashboardTag']; $columnDivs = array(0 => $this->Html->tag($dashboardTag, implode('', $columns[CroogoDashboard::LEFT]), array('class' => $cssSetting['dashboardLeft'] . ' ' . $cssSetting['dashboardClass'], 'id' => 'column-0')), 1 => $this->Html->tag($dashboardTag, implode('', $columns[CroogoDashboard::RIGHT]), array('class' => $cssSetting['dashboardRight'] . ' ' . $cssSetting['dashboardClass'], 'id' => 'column-1'))); $fullDiv = $this->Html->tag($dashboardTag, implode('', $columns[CroogoDashboard::FULL]), array('class' => $cssSetting['dashboardFull'] . ' ' . $cssSetting['dashboardClass'], 'id' => 'column-2')); return $this->Html->tag('div', $fullDiv, array('class' => $cssSetting['row'])) . $this->Html->tag('div', implode('', $columnDivs), array('class' => $cssSetting['row'])); }
public function register() { if (!$this->request->is('post')) { return; } $customerUserId = $this->CustomerUser->Customer->createWithUser($this->request->data); if (!$customerUserId) { Croogo::dispatchEvent('Controller.Users.registrationFailure', $this); $this->Session->setFlash(__d('croogo', 'The User could not be saved. Please, try again.'), 'flash', array('class' => 'error')); return; } $customerUser = $this->CustomerUser->find('first', array('conditions' => array('CustomerUser.id' => $customerUserId), 'recursive' => -1)); $user = $this->CustomerUser->User->read(null, $customerUser['CustomerUser']['user_id']); Croogo::dispatchEvent('Controller.Users.registrationSuccessful', $this); $this->_sendEmail(array(Configure::read('Site.title'), $this->_getSenderEmail()), $user['User']['email'], __d('croogo', '[%s] Please activate your account', Configure::read('Site.title')), 'Users.register', 'user activation', $this->theme, array('user' => $user)); $this->Session->setFlash(__d('croogo', 'You have successfully registered an account. An email has been sent with further instructions.'), 'flash', array('class' => 'success')); $this->redirect(array('plugin' => 'users', 'controller' => 'users', 'action' => 'login')); return; }
/** * initialize * * attaches Acl and RowLevelAcl behavior to the controller's primary model and * hook the appropriate admin tabs */ public function initialize(Controller $controller) { $this->_controller = $controller; $Model = $controller->{$controller->modelClass}; $Model->Behaviors->load('Acl', array('className' => 'Croogo.CroogoAcl', 'type' => 'controlled')); $Model->Behaviors->load('RowLevelAcl', array('className' => 'Acl.RowLevelAcl')); $name = $controller->name; $element = 'Acl.admin/row_acl'; if (!empty($this->settings['adminTabElement'])) { $element = $this->settings['adminTabElement']; } $adminTabActions = array('admin_add', 'admin_edit'); if (!empty($this->settings['adminTabActions'])) { $adminTabActions += $this->settings['adminTabActions']; } foreach ($adminTabActions as $action) { Croogo::hookAdminTab("{$name}/{$action}", __d('croogo', 'Permissions'), $element); } }