/** * Register a profile automatically if it not exists. * * @param string $result result row of authentication * @return void */ public function registerProfile($signal) { if (!Centurion_Auth::getInstance()->getProfile()) { $identity = Centurion_Auth::getInstance()->getIdentity(); Centurion_Db::getSingleton('user/profile')->insert(array('nickname' => $identity->username, 'user_id' => $identity->id)); } }
public function testDateFormatForDatePicker() { //Without time $date = new Zend_Date('1/12/2009', 'dd/MM/YYYY'); $form = new Cms_Form_Model_Flatpage(); $form->setDateFormat('dd/MM/yy'); $row = Centurion_Db::getSingleton('cms/flatpage')->createRow(); $row->published_at = $date->get('YYYY-MM-dd HH:mm:ss'); $form->setInstance($row); $expected = $date->get('dd/MM/yy'); $value = $form->getElement('published_at')->getValue(); $this->assertEquals($expected, $value); $values = $form->processValues($form->getValues()); $this->assertEquals($date->get('YYYY-MM-dd HH:mm:ss'), $values['published_at']); //With Time $date = new Zend_Date('1/12/2009 11:32', 'dd/MM/YYYY HH:mm'); $form = new Cms_Form_Model_Flatpage(); $form->setDateFormat('dd/MM/yy', 'hh:mm'); $row = Centurion_Db::getSingleton('cms/flatpage')->createRow(); $row->published_at = $date->get('YYYY-MM-dd HH:mm:ss'); $form->setInstance($row); $expected = $date->get('dd/MM/yy hh:mm'); $value = $form->getElement('published_at')->getValue(); $this->assertEquals($expected, $value); $values = $form->processValues($form->getValues()); $this->assertEquals($date->get('YYYY-MM-dd HH:mm:ss'), $values['published_at']); }
public static function getPx() { if (null == self::$_px) { self::$_px = Centurion_Db::getSingleton('media/file')->findOneByfile_id('88888888'); } return self::$_px; }
public function init() { $controller = $this->getActionController(); if (!($requestedLocale = $controller->getRequest()->getParam('language', false))) { $local = new Zend_Locale(); $requestedLocale = $local->getLanguage(); } if (is_array($requestedLocale)) { $requestedLocale = current($requestedLocale); } $requestedLocale = strtolower($requestedLocale); try { Centurion_Db::getSingleton('translation/language')->get(array('locale' => $requestedLocale)); } catch (Centurion_Db_Table_Row_Exception_DoesNotExist $e) { $requestedLocale = Translation_Traits_Common::getDefaultLanguage(); $requestedLocale = $requestedLocale->locale; } Zend_Registry::get('Zend_Translate')->setLocale($requestedLocale); Zend_Locale::setDefault($requestedLocale); Zend_Registry::set('Zend_Locale', $requestedLocale); $options = Centurion_Db_Table_Abstract::getDefaultFrontendOptions(); if (!isset($options['cache_id_prefix'])) { $options['cache_id_prefix'] = ''; } $options['cache_id_prefix'] = $requestedLocale . '_' . $options['cache_id_prefix']; Centurion_Db_Table_Abstract::setDefaultFrontendOptions($options); //TODO: fix this when in test unit environment if (!APPLICATION_ENV === 'testing') { $this->getActionController()->getFrontController()->getParam('bootstrap')->getResource('cachemanager')->addIdPrefix($requestedLocale . '_'); } if (Centurion_Config_Manager::get('translation.global_param')) { $this->getFrontController()->getRouter()->setGlobalParam('language', $requestedLocale); } }
public function __construct($options = array(), Centurion_Db_Table_Row_Abstract $instance = null) { $this->_model = Centurion_Db::getSingleton('cms/flatpage'); $this->_exclude = array('created_at', 'id', 'updated_at', 'mptt_lft', 'mptt_rgt', 'slug', 'mptt_level', 'mptt_tree_id', 'faltpage_type', 'cover_id', 'mptt_parent_id'); $this->_elementLabels = array('title' => $this->_translate('Title'), 'description' => $this->_translate('Description'), 'keywords' => $this->_translate('Keywords'), 'url' => $this->_translate('URL'), 'body' => $this->_translate('Content'), 'cover_id' => $this->_translate('Cover'), 'flatpage_template_id' => $this->_translate('Template'), 'mptt_parent_id' => $this->_translate('Parent'), 'published_at' => $this->_translate('Date to publish'), 'is_published' => $this->_translate('Is published'), 'order' => $this->_translate('Order'), 'route' => $this->_translate('Route')); parent::__construct($options, $instance); }
public function getAction() { $this->getHelper('layout')->disableLayout(); $this->getHelper('viewRenderer')->setNoRender(true); $media = $this->getInvokeArg('bootstrap')->getOption('media'); if (!(null != ($fileRow = $this->_getParam('file')) && $fileRow instanceof Media_Model_DbTable_Row_File)) { $mediaAdapter = Media_Model_Adapter::factory($media['adapter'], $media['params']); $id = bin2hex(Centurion_Inflector::urlDecode($this->_request->getParam('id'))); $key = bin2hex(Centurion_Inflector::urlDecode($this->_request->getParam('key'))); $fileRow = $this->_helper->getObjectOr404('media/file', array('id' => $id)); $this->forward404If(!$mediaAdapter->isValidKey($fileRow, $key, '', $media['key_lifetime'])); } $source = $media['uploads_dir'] . DIRECTORY_SEPARATOR . $fileRow->local_filename; if (null == $this->_getParam('noAdapter', null)) { $isSaved = $mediaAdapter->save($source, $fileRow->getRelativePath(null, false, true), true); if ($isSaved) { Centurion_Db::getSingleton('media/duplicate')->insert(array('file_id' => $fileRow->id, 'adapter' => $media['adapter'], 'params' => serialize($media['params']), 'dest' => $fileRow->getRelativePath(null, false, true))); return $this->getHelper('redirector')->gotoUrlAndExit($fileRow->getStaticUrl()); } } $offset = 24 * 60 * 60 * 365; $this->getResponse()->setHeader('Content-type', $fileRow->mime)->setHeader('Content-Length', filesize($source))->setHeader('Content-Disposition', sprintf('inline; filename="%s";', $fileRow->filename))->setHeader('Cache-Control', sprintf('max-age=%d, public', $offset))->setHeader('Expires', sprintf('%s GMT', gmdate('D, d M Y H:i:s', time() + $offset)))->sendHeaders(); while (@ob_end_flush()) { } $fp = fopen($source, 'rb'); fpassthru($fp); fclose($fp); $this->getResponse()->clearHeaders(); }
/** * Constructor * * @param array|Zend_Config $options Options * @param Centurion_Db_Table_Abstract $instance Instance attached to the form * @return void */ public function __construct($options = array(), Centurion_Db_Table_Row_Abstract $instance = null) { $this->_model = Centurion_Db::getSingleton('core/navigation'); $this->_exclude = array('mptt_parent_id'); $this->_elementLabels = array('label' => $this->_translate('Label'), 'module' => $this->_translate('Module name'), 'controller' => $this->_translate('Controller name'), 'action' => $this->_translate('Action name'), 'params' => $this->_translate('Params (json)'), 'route' => $this->_translate('Route name'), 'uri' => $this->_translate('URI'), 'is_visible' => $this->_translate('Visible?'), 'class' => $this->_translate('Stylesheet'), 'proxy' => $this->_translate('Proxy')); return parent::__construct($options, $instance); }
public function testModel() { try { $guidelineTable = Centurion_Db::getSingleton('cms/flatpage'); } catch (Centurion_Db_Exception $e) { $this->fail('Table does not exists'); } $this->assertTrue($guidelineTable->hasColumn('id')); $this->assertTrue($guidelineTable->hasColumn('title')); $this->assertTrue($guidelineTable->hasColumn('slug')); $this->assertTrue($guidelineTable->hasColumn('description')); $this->assertTrue($guidelineTable->hasColumn('keywords')); $this->assertTrue($guidelineTable->hasColumn('body')); $this->assertTrue($guidelineTable->hasColumn('url')); $this->assertTrue($guidelineTable->hasColumn('id')); $this->assertTrue($guidelineTable->hasColumn('flatpage_template_id')); $this->assertTrue($guidelineTable->hasColumn('published_at')); $this->assertTrue($guidelineTable->hasColumn('created_at')); $this->assertTrue($guidelineTable->hasColumn('updated_at')); $this->assertTrue($guidelineTable->hasColumn('is_published')); $this->assertTrue($guidelineTable->hasColumn('mptt_lft')); $this->assertTrue($guidelineTable->hasColumn('mptt_rgt')); $this->assertTrue($guidelineTable->hasColumn('mptt_level')); $this->assertTrue($guidelineTable->hasColumn('mptt_tree_id')); $this->assertTrue($guidelineTable->hasColumn('mptt_parent_id')); $this->assertTrue($guidelineTable->hasColumn('original_id')); $this->assertTrue($guidelineTable->hasColumn('language_id')); $this->assertTrue($guidelineTable->hasColumn('forward_url')); $this->assertTrue($guidelineTable->hasColumn('flatpage_type')); $this->assertTrue($guidelineTable->hasColumn('route')); $this->assertTrue($guidelineTable->hasColumn('class')); $this->assertTrue($guidelineTable->hasColumn('cover_id')); }
public function prePopulate($signal, $sender, $values) { if (isset($values[Translation_Traits_Model_DbTable::ORIGINAL_FIELD]) || $this->hasInstance() && null !== $this->getInstance()->{Translation_Traits_Model_DbTable::ORIGINAL_FIELD}) { try { $value = $this->getModel()->get(array('id' => $values[Translation_Traits_Model_DbTable::ORIGINAL_FIELD])); } catch (Centurion_Db_Table_Row_Exception $e) { return; } $spec = $this->_form->getModel()->getTranslationSpec(); if (!$this->hasInstance()) { foreach ($spec[Translation_Traits_Model_DbTable::TRANSLATED_FIELDS] as $field) { $element = $this->getElement($field); if (null !== $element) { $element->setValue($value->{$field}); } } } $f = $this->_getInfoField(Translation_Traits_Model_DbTable::ORIGINAL_FIELD); $f->setValue((string) $value); $value = Centurion_Db::getSingleton('translation/language')->get(array('id' => $values[Translation_Traits_Model_DbTable::LANGUAGE_FIELD])); $f = $this->_getInfoField(Translation_Traits_Model_DbTable::LANGUAGE_FIELD); $f->setValue((string) $value->name); $fields = array_merge($spec[Translation_Traits_Model_DbTable::DUPLICATED_FIELDS], $spec[Translation_Traits_Model_DbTable::SET_NULL_FIELDS]); foreach ($fields as $field) { $this->removeElement($field); $this->addExclude($field); } } }
public function indexAction() { $form = new Centurion_Form(); $form->addElement('text', 'module_name', array('required' => true, 'label' => $this->view->translate('Module:'))); $form->addElement('text', 'controller_name', array('required' => true, 'label' => $this->view->translate('Controller:'))); $form->addElement('text', 'ressource_name', array('required' => true, 'label' => $this->view->translate('Ressource:'))); $form->addElement('submit', 'submit', array('label' => $this->view->translate('Submit'))); $post = $this->_request->getParams(); if ($form->isValid($post)) { $this->view->message = 'Les permission ont bien été ajoutées. <br />'; $permissionTable = Centurion_Db::getSingleton('auth/permission'); $tab = array('index' => 'View %s %s index', 'list' => 'View %s %s list', 'get' => 'View an %s %s', 'post' => 'Create an %s %s', 'new' => 'Access to creation of an %s %s', 'delete' => 'Delete an %s %s', 'put' => 'Update an %s %s', 'batch' => 'Batch an %s %s', 'switch' => 'Switch an %s %s'); foreach ($tab as $key => $description) { list($row, $created) = $permissionTable->getOrCreate(array('name' => $post['module_name'] . '_' . $post['controller_name'] . '_' . $key)); if ($created) { $row->description = sprintf($description, $post['module_name'], $post['ressource_name']); $row->save(); } } /* INSERT INTO \`auth_permission\` (\`name\`,\`description\`) VALUES ('${1:module}_${2:controller}_index', 'View ${1:module} ${3:resource} index'), ('${1:module}_${2:controller}_list', 'View ${1:module} ${3:resource} list'), ('${1:module}_${2:controller}_get', 'View an ${1:module} ${3:resource}'), ('${1:module}_${2:controller}_post', 'Create an ${1:module} ${3:resource}'), ('${1:module}_${2:controller}_new', 'Access to creation of an ${1:module} ${3:resource}'), ('${1:module}_${2:controller}_delete', 'Delete an ${1:module} ${3:resource}'), ('${1:module}_${2:controller}_put', 'Update an ${1:module} ${3:resource}'); */ } $this->view->form = $form; }
public function notice($param) { if (!is_array($param)) { return; } $inserted = false; if (!isset($this->_testedLanguage[$param[1]])) { $languageTable = Centurion_Db::getSingleton('translation/language'); $languageRow = $languageTable->findOneByLocale($param[1]); if (null === $languageRow) { $inserted = true; $languageRow = $languageTable->insert(array('locale' => $param[1])); } $this->_testedLanguage[$param[1]] = true; } if (!isset($this->_testedUid[$param[0]]) && trim($param[0]) !== '') { $uidTable = Centurion_Db::getSingleton('translation/uid'); list($uidRow, $inserted) = $uidTable->getOrCreate(array('uid' => $param[0])); /*if (null === $uidRow) { $inserted = true; $uidRow = $uidTable->insert(array('uid' => $param[0])); }*/ if ($inserted) { //TODO: send a signal to bootstrap for clearing cache Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('cachemanager')->getCache('core')->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('translation')); } $this->_testedUid[$param[0]] = true; } }
public function __construct($options = array()) { $this->_model = Centurion_Db::getSingleton('user/profile'); $this->_exclude = array('user_id', 'created_at', 'updated_at', 'id', 'avatar_id'); $this->_elementLabels = array('nickname' => 'Nickname', 'about' => 'About', 'website' => 'Website', 'facebook_pageid' => 'Facebook Page ID'); parent::__construct($options); }
public function __construct($options = array(), Centurion_Db_Table_Row_Abstract $instance = null) { $this->_model = Centurion_Db::getSingleton('cms/flatpage_template'); $this->_exclude = array(); $this->_elementLabels = array('name' => $this->_translate('Name'), 'view_script' => $this->_translate('View script')); $this->setLegend($this->_translate('Edit flatpage template')); parent::__construct($options, $instance); }
public function __construct($options = array()) { $this->_model = Centurion_Db::getSingleton('user/profile'); $this->_elementLabels = array('nickname' => 'Nickname', 'function' => 'Function', 'about' => 'About', 'website' => 'Website', 'user_id' => 'User Parent'); $this->_exclude = array('created_at', 'updated_at', 'id', 'avatar_id'); $this->setLegend($this->_translate('Edit User')); parent::__construct($options); }
public function checkNavigationAction() { $roots = Centurion_Db::getSingleton('core/navigation')->getRootNodes()->fetchAll(); foreach ($roots as $node) { $this->_recursiveCheckLeftRight($node); } die; }
public function testImageWithoutEffect() { list($file, $created) = Centurion_Db::getSingleton('media/file')->getOrCreate(array('delete_original' => 0, 'local_filename' => APPLICATION_PATH . '/../tests/support/imgs/php.jpg')); $url = $file->getStaticUrl(); $this->assert200($url); $file->delete(); $this->assertNot200($url); }
public function logInAsAnnonymous() { $user = Centurion_Db::getSingleton('auth/user')->findOneById(2); if ($user == null) { throw new PHPUnit_Framework_Exception('Can not log as annonymous. User does not exists'); } Centurion_Auth::getInstance()->clearIdentity(); Centurion_Auth::getInstance()->getStorage()->write($user); }
public function getContainer() { if (null === $this->_container) { if (!Zend_Registry::isRegistered('Zend_Navigation')) { $this->_container = new Zend_Navigation(Centurion_Db::getSingleton('core/navigation')->getCache()->toNavigation()); } } return parent::getContainer(); }
public function init() { $this->_model = Centurion_Db::getSingleton('core/navigation'); $this->_formClass = 'Admin_Form_Model_Navigation'; $this->setOptions(array('titleColumn' => 'title', 'publishColumn' => 'is_published', 'publishDateColumn' => 'published_at')); $this->view->placeholder('headling_1_content')->set($this->view->translate('Manage navigation')); $this->view->placeholder('headling_1_add_button')->set($this->view->translate('navigation')); parent::init(); }
public function testApostropheInOriginalWording() { $translate = new Translation_Model_Translate_Adapter_Array(array()); $original = '3 raisons de s\'inscrir ? ! ? %s e'; $translatedWording = $translate->translate($original); $this->assertEquals($original, $translatedWording); $uid = Centurion_Db::getSingleton('translation/uid')->fetchRow(null, 'id desc'); $this->assertEquals($original, $uid->uid); }
public function testMultiJointure() { $permissionTable = Centurion_Db::getSingleton('auth/permission'); $permissionRow = $permissionTable->insert(array('name' => 'test', Centurion_Db_Table_Abstract::RETRIEVE_ROW_ON_INSERT => true)); $userOriginalRow = Centurion_Db::getSingleton('auth/user')->insert(array('username' => 'testOriginal', Centurion_Db_Table_Abstract::RETRIEVE_ROW_ON_INSERT => true)); $userRow = Centurion_Db::getSingleton('auth/user')->insert(array('username' => 'test', 'user_parent_id' => $userOriginalRow->id, Centurion_Db_Table_Abstract::RETRIEVE_ROW_ON_INSERT => true)); Centurion_Db::getSingleton('auth/user_permission')->insert(array('permission_id' => $permissionRow->id, 'user_id' => $userRow->id)); $select = $permissionTable->select(true)->filter(array('users__parent_user__id' => $userOriginalRow->id)); $this->assertEquals($select->count(), 1, sprintf("Except 1, found %d\n", $select->count())); }
public function testSleep() { $table = Centurion_Db::getSingleton('auth/group'); $table->insert(array('name' => 'test1')); $rowSet = $table->fetchAll(array('name=?' => 'test1')); $str = serialize($rowSet); $rowSet = unserialize($str); foreach ($rowSet as $row) { $row->delete(); } }
public static function getPx() { if (null == self::$_px) { $data = array(); $data['id'] = '88888888'; $data['local_filename'] = '../../public/layouts/backoffice/images/px.png'; $data['delete_original'] = 0; list(self::$_px, ) = Centurion_Db::getSingleton('media/file')->getOrCreate($data); } return self::$_px; }
public function __construct($options) { $this->_uidTable = Centurion_Db::getSingleton('translation/uid'); $this->_tagTable = Centurion_Db::getSingleton('translation/tag'); $this->_languageTable = Centurion_Db::getSingleton('translation/language'); $this->_tagUidTable = Centurion_Db::getSingleton('translation/tagUid'); parent::__construct($options); if ($cached = self::getCache()->load('Translation_Model_Translate_Adapter_Array_Cache')) { list($this->_checkedWord, $this->_checkedTag, $this->_checkedWordTag) = $cached; } }
public function save($adapter = null) { $translationTable = Centurion_Db::getSingleton('translation/translation'); $id = $this->_instance->id; foreach ($this->language as $key => $val) { if (!$val->getValue()) { continue; } $translationTable->save(array('uid_id' => $id, 'language_id' => $key, 'translation' => $val->getValue())); } return $this->_instance; }
public function preDispatch() { $languageTable = Centurion_Db::getSingleton('translation/language'); $languageName = array_flip(Zend_Locale_Data_Translation::$languageTranslation); $languagesArray = array(); foreach ($languageTable->fetchAll() as $lang) { $languagesArray[$lang->pk] = $languageName[$lang->locale]; } try { $this->_filters = array_merge(array('language_id' => array('type' => Centurion_Controller_CRUD::FILTER_TYPE_CHECKBOX, 'behavior' => Centurion_Controller_CRUD::FILTER_BEHAVIOR_IN, 'label' => $this->_controller->view->translate('Language'), 'data' => $languagesArray)), $this->_filters); } catch (Exception $e) { } }
public function render(Zend_View_Interface $view = null) { $realName = $this->getName(); foreach ($this->_parentForm->getElements() as $key => $element) { if ($element === $this) { $realName = $key; } } $this->setDecorators(array(new Media_Form_Decorator_MultiFile())); $ticket = Centurion_Db::getSingleton('media/multiupload_ticket')->createTicket($this->_parentForm, $realName); $this->setAttrib('ticket', $ticket->ticket); return parent::render($view); }
public function getAction() { Centurion_Db_Table_Abstract::setFiltersStatus(true); $flatpageRow = $this->_helper->getObjectOr404('cms/flatpage', array('id' => $this->_getParam('id'), 'is_published' => 1, 'published_at__lt' => new Zend_Db_Expr('NOW()'))); Centurion_Db_Table_Abstract::restoreFiltersStatus(); Centurion_Cache_TagManager::addTag($flatpageRow); $navRow = Centurion_Db::getSingleton('core/navigation')->findOneByProxy($flatpageRow); if (null !== $navRow) { $navigation = $this->view->navigation()->getContainer(); $this->view->currentNavigation = $navigation->findOneById($navRow->id); } return $this->renderToResponse($flatpageRow->flatpage_template->view_script, array('flatpageRow' => $flatpageRow)); }
/** * authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to * attempt an authentication. Previous to this call, this adapter would have already * been configured with all necessary information to successfully connect to a database * table and attempt to find a record matching the provided identity. * * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible * @return Zend_Auth_Result */ public function authenticate() { if ($user = Centurion_Db::getSingleton('auth/user')->findOneByUsername($this->_identity)) { $algorithm = $user['algorithm']; if (false !== ($pos = strpos($algorithm, '::'))) { $algorithm = array(substr($algorithm, 0, $pos), substr($algorithm, $pos + 2)); } if (!is_callable($algorithm)) { throw new Zend_Auth_Adapter_Exception(sprintf('The algorithm callable "%s" is not callable.', $algorithm)); } $this->setCredential(call_user_func_array($algorithm, array($user['salt'] . $this->_credential))); } return parent::authenticate(); }
public function init() { $this->_helper->authCheck(); $this->_helper->aclCheck(); $this->_model = Centurion_Db::getSingleton('cms/flatpage'); $this->_formClassName = 'Cms_Form_Model_Flatpage'; /*$this->setOptions(array( 'titleColumn' => 'title', 'publishColumn' => 'is_published', 'publishDateColumn' => 'published_at' ));*/ $this->view->placeholder('headling_1_content')->set($this->view->translate('Manage flatpage@backoffice,cms')); $this->view->placeholder('headling_1_add_button')->set($this->view->translate('flatpage@backoffice,cms')); parent::init(); }