示例#1
0
文件: Fields.php 项目: robeendey/ce
 public function getForm()
 {
     if (is_null($this->_form)) {
         $formArgs = array();
         // Preload profile type field stuff
         $profileTypeField = $this->getProfileTypeField();
         if ($profileTypeField) {
             $accountSession = new Zend_Session_Namespace('User_Plugin_Signup_Account');
             $profileTypeValue = @$accountSession->data['profile_type'];
             if ($profileTypeValue) {
                 $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $profileTypeValue);
             }
         }
         // Create form
         Engine_Loader::loadClass($this->_formClass);
         $class = $this->_formClass;
         $this->_form = new $class($formArgs);
         $data = $this->getSession()->data;
         if (empty($data)) {
             $fb_session = new Zend_Session_Namespace('User_AuthController');
             $data = $fb_session->data;
         }
         if (!empty($data)) {
             foreach ($data as $key => $val) {
                 $el = $this->_form->getElement($key);
                 if ($el) {
                     $el->setValue($val);
                 }
             }
         }
     }
     return $this->_form;
 }
示例#2
0
文件: Core.php 项目: hoalangoc/ftf
 public function getPlugin($gateway_id)
 {
     if (null === $this->_plugin) {
         if (null == ($gateway = Engine_Api::_()->getItem('payment_gateway', $gateway_id))) {
             return null;
         }
         Engine_Loader::loadClass($gateway->plugin);
         if (!class_exists($gateway->plugin)) {
             return null;
         }
         if (in_array($gateway->title, array('Authorize.Net', 'iTransact'))) {
             $class = str_replace('Ynpayment', 'Ynsocialads', $gateway->plugin);
         } else {
             $class = str_replace('Payment', 'Ynsocialads', $gateway->plugin);
         }
         Engine_Loader::loadClass($class);
         if (!class_exists($class)) {
             return null;
         }
         $plugin = new $class($gateway);
         if (!$plugin instanceof Engine_Payment_Plugin_Abstract) {
             throw new Engine_Exception(sprintf('Payment plugin "%1$s" must ' . 'implement Engine_Payment_Plugin_Abstract', $class));
         }
         $this->_plugin = $plugin;
     }
     return $this->_plugin;
 }
 public function getJobPlugin($job, $jobType = null)
 {
     // Must be a row of jobs
     if (!is_object($job)) {
         throw new Core_Model_Exception(sprintf('Must be given a row of ' . 'Core_Model_DbTable_Jobs, given ' . '%s', gettype($job)));
     } else {
         if (!$job->getTable() instanceof Core_Model_DbTable_Jobs) {
             throw new Core_Model_Exception(sprintf('Must be given a row of ' . 'Core_Model_DbTable_Jobs, given ' . '%s', get_class($job)));
         }
     }
     // Get job type if missing
     if (null === $jobType) {
         $jobType = $this->find($job->jobtype_id)->current();
     }
     // Get plugin class
     $class = $jobType->plugin;
     // Load class
     Engine_Loader::loadClass($class);
     // Make sure is a subclass of Core_Plugin_Task_Abstract
     if (!is_subclass_of($class, 'Core_Plugin_Job_Abstract')) {
         throw new Core_Model_Exception(sprintf('Job plugin %1$s should extend Core_Plugin_Job_Abstract', $class));
     }
     // Check for execute method?
     if (!method_exists($class, 'execute')) {
         throw new Core_Model_Exception(sprintf('Job plugin %1$s does not have an execute method', $class));
     }
     // Get plugin object
     $plugin = new $class($job, $jobType);
     // Set the log
     $plugin->setLog($this->getLog());
     return $plugin;
 }
 public function getStorage()
 {
     if (is_null($this->_storage)) {
         Engine_Loader::loadClass('File_Model_Storage');
         $this->_storage = File_Model_Storage::getInstance();
     }
     return $this->_storage;
 }
示例#5
0
文件: Action.php 项目: robeendey/ce
 /**
  * Gets a session namespace unique to this controller
  * 
  * @return Zend_Session_Namespace
  */
 public function getSession()
 {
     if (is_null($this->_session)) {
         Engine_Loader::loadClass('Zend_Session_Namespace');
         $namespace = get_class($this);
         $this->_session = new Zend_Session_Namespace($namespace);
     }
     return $this->_session;
 }
 public static function factory($itemType, $tableType, $config = array())
 {
     if (!is_string($itemType) || !is_string($tableType)) {
         throw new Fields_Model_Exception('Item type and table type must be strings');
     }
     $class = 'Fields_Model_DbTable_' . ucfirst($tableType);
     Engine_Loader::loadClass($class);
     return new $class($itemType, $tableType, $config);
 }
 public static function factory(Zend_Db_Adapter_Abstract $adapter, $options = array())
 {
     list($prefix, $type) = explode('_Db_Adapter_', get_class($adapter));
     $class = 'Engine' . '_Db_Export_' . $type;
     Engine_Loader::loadClass($class);
     $instance = new $class($adapter, $options);
     if (!$instance instanceof Engine_Db_Export) {
         throw new Engine_Exception('Must be an instance of Engine_Db_Export');
     }
     return $instance;
 }
示例#8
0
 public function getGateway()
 {
     if (null === $this->_gateway) {
         $class = 'Engine_Payment_Gateway_2Checkout';
         Engine_Loader::loadClass($class);
         $gateway = new $class(array('config' => (array) $this->_gatewayInfo->config, 'testMode' => $this->_gatewayInfo->test_mode, 'currency' => Engine_Api::_()->getApi('settings', 'core')->getSetting('payment.currency', 'USD')));
         if (!$gateway instanceof Engine_Payment_Gateway) {
             throw new Engine_Exception('Plugin class not instance of Engine_Payment_Gateway');
         }
         $this->_gateway = $gateway;
     }
     return $this->_gateway;
 }
 /**
  * Get the payment plugin
  *
  * @return Engine_Payment_Plugin_Abstract
  */
 public function getPlugin()
 {
     if (null === $this->_plugin) {
         $class = $this->plugin;
         Engine_Loader::loadClass($class);
         $plugin = new $class($this);
         if (!$plugin instanceof Engine_Payment_Plugin_Abstract) {
             throw new Engine_Exception(sprintf('Payment plugin "%1$s" must ' . 'implement Engine_Payment_Plugin_Abstract', $class));
         }
         $this->_plugin = $plugin;
     }
     return $this->_plugin;
 }
示例#10
0
文件: Vfs.php 项目: robeendey/ce
 /**
  * Factory method for VFS
  * 
  * @param string $adapter
  * @param array $config
  * @return Engine_Vfs_Adapter_Interface
  */
 public static function factory($adapter, array $config = array())
 {
     $classPrefix = 'Engine_Vfs_Adapter_';
     if (isset($config['adapterPrefix'])) {
         $classPrefix = rtrim($config['adapterPrefix'], '_') . ')';
     }
     $class = $classPrefix . ucfirst($adapter);
     Engine_Loader::loadClass($class);
     if (!is_subclass_of($class, 'Engine_Vfs_Adapter_Interface')) {
         throw new Engine_Vfs_Exception('Adapter class must extend Engine_Vfs_Adapter_Interface');
     }
     $instance = new $class($config);
     return $instance;
 }
示例#11
0
文件: Abstract.php 项目: robeendey/ce
 public function getAdminForm()
 {
     if (is_null($this->_adminForm)) {
         Engine_Loader::loadClass($this->_adminFormClass);
         $class = $this->_adminFormClass;
         $this->_adminForm = new $class();
         $data = $this->getSession()->data;
         if (!empty($data)) {
             foreach ($data as $key => $val) {
                 $el = $this->_adminForm->getElement($key);
                 if ($el) {
                     $el->setValue($val);
                 }
             }
         }
     }
     return $this->_adminForm;
 }
示例#12
0
文件: Fields.php 项目: hoalangoc/ftf
 public function getForm()
 {
     $formArgs = array();
     // Preload profile type field stuff
     $profileTypeField = $this->getProfileTypeField();
     if ($profileTypeField) {
         $accountSession = new Zend_Session_Namespace('User_Plugin_Signup_Account');
         $profileTypeValue = @$accountSession->data['profile_type'];
         if ($profileTypeValue) {
             $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $profileTypeValue);
         } else {
             $topStructure = Engine_Api::_()->fields()->getFieldStructureTop('user');
             if (count($topStructure) == 1 && $topStructure[0]->getChild()->type == 'profile_type') {
                 $profileTypeField = $topStructure[0]->getChild();
                 $options = $profileTypeField->getOptions();
                 if (count($options) == 1) {
                     $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $options[0]->option_id);
                 }
             }
         }
     }
     // Create form
     Engine_Loader::loadClass($this->_formClass);
     $class = $this->_formClass;
     $this->_form = new $class($formArgs);
     $fieldsSession = new Zend_Session_Namespace('User_Plugin_Signup_Fields');
     $this->setSession($fieldsSession);
     $data = $this->getSession()->data;
     if (!empty($data)) {
         foreach ($data as $key => $val) {
             $el = $this->_form->getElement($key);
             if ($el instanceof Zend_Form_Element) {
                 $el->setValue($val);
             }
         }
     }
     return $this->_form;
 }
 public function getService($serviceIdentity = null)
 {
     if (null === $serviceIdentity) {
         $serviceIdentity = $this->getDefaultServiceIdentity();
     } else {
         if (!is_numeric($serviceIdentity)) {
             throw new Storage_Model_Exception('Invalid storage service identity specifier');
         }
     }
     if (!isset($this->_services[$serviceIdentity])) {
         // Get service info
         $serviceInfo = $this->select()->where('service_id = ?', $serviceIdentity)->where('enabled = ?', 1)->limit(1)->query()->fetch();
         if (!$serviceInfo) {
             throw new Storage_Model_Exception(sprintf('Missing storage service "%s"', $serviceIdentity));
         }
         // Get service type info
         $serviceTypeIdentity = $serviceInfo['servicetype_id'];
         $serviceTypeInfo = Engine_Api::_()->getDbtable('serviceTypes', 'storage')->select()->where('servicetype_id = ?', $serviceTypeIdentity)->limit(1)->query()->fetch();
         if (!$serviceTypeInfo) {
             throw new Storage_Model_Exception(sprintf('Missing storage service type "%s"', $serviceTypeIdentity));
         }
         $class = $serviceTypeInfo['plugin'];
         Engine_Loader::loadClass($class);
         if (!class_exists($class, false) || !in_array('Storage_Service_Interface', class_implements($class))) {
             throw new Storage_Model_Exception(sprintf('Missing storage service ' . 'class or does not implement Storage_Service_Interface for ' . 'service "%s"', $serviceIdentity));
         }
         $config = array();
         if (!empty($serviceInfo['config'])) {
             $config = Zend_Json::decode($serviceInfo['config']);
             if (!is_array($config)) {
                 $config = array();
             }
         }
         $config['service_id'] = $serviceInfo['service_id'];
         $this->_services[$serviceIdentity] = new $class($config);
     }
     return $this->_services[$serviceIdentity];
 }
示例#14
0
 /**
  * Factory method. Automatically picks available adapter
  * 
  * @param string $adapter Force this adapter
  * @param array $options
  * @return Engine_Image
  */
 public static function factory($options = array(), $adapter = 'gd')
 {
     $hasGd = function_exists('gd_info');
     $hasImagick = class_exists('Imagick', false);
     if (!$hasGd && !$hasImagick) {
         throw new Engine_Image_Exception('No available adapter for image operations');
     }
     if (!($adapter == 'gd' && $hasGd) && !($adapter == 'imagick' && $hasImagick)) {
         if ($hasGd) {
             $adapter = 'gd';
         } else {
             if ($hasImagick) {
                 $adapter = 'imagick';
             }
         }
     }
     $class = 'Engine_Image_Adapter_' . ucfirst($adapter);
     Engine_Loader::loadClass($class);
     if (!class_exists($class, false)) {
         throw new Engine_Image_Exception(sprintf('Missing class for adapter "%s"', $adapter));
     }
     return new $class($options);
 }
示例#15
0
文件: Comet.php 项目: robeendey/ce
 protected function _loadFrontend(array $options)
 {
     if (!isset($options['adapter']) || !is_string($options['adapter'])) {
         throw new Engine_Comet_Exception('Adapter not set or not string.');
     }
     $adapter = $options['adapter'];
     unset($options['adapter']);
     $class = 'Engine_Comet_Frontend_' . ucfirst($adapter);
     Engine_Loader::loadClass($class);
     if (!is_subclass_of($class, 'Engine_Comet_Frontend_Abstract')) {
         throw new Engine_Comet_Exception(sprintf('Adapter %s does not extend Engine_Comet_Frontend_Abstract', $class));
     }
     return new $class($options);
 }
示例#16
0
文件: Core.php 项目: hoalangoc/ftf
 public function getPlugin($gateway_id)
 {
     if (null === $this->_plugin) {
         if (null == ($gateway = Engine_Api::_()->getItem('payment_gateway', $gateway_id))) {
             return null;
         }
         Engine_Loader::loadClass($gateway->plugin);
         if (!class_exists($gateway->plugin)) {
             return null;
         }
         $class = str_replace('Payment', 'Ynmember', $gateway->plugin);
         Engine_Loader::loadClass($class);
         if (!class_exists($class)) {
             return null;
         }
         $plugin = new $class($gateway);
         if (!$plugin instanceof Engine_Payment_Plugin_Abstract) {
             throw new Engine_Exception(sprintf('Payment plugin "%1$s" must ' . 'implement Engine_Payment_Plugin_Abstract', $class));
         }
         $this->_plugin = $plugin;
     }
     return $this->_plugin;
 }
示例#17
0
文件: Sanity.php 项目: robeendey/ce
 public function addTest($spec, $options = array())
 {
     if ($spec instanceof Engine_Sanity_Test_Interface) {
         $test = $spec;
     } else {
         if (is_string($spec)) {
             $class = 'Engine_Sanity_Test_' . ucfirst($spec);
             Engine_Loader::loadClass($class);
             $test = new $class($options);
         } else {
             if (is_array($spec)) {
                 if (!empty($spec['type'])) {
                     $class = 'Engine_Sanity_Test_' . ucfirst($spec['type']);
                     unset($spec['type']);
                 } else {
                     if (!empty($spec['class'])) {
                         $class = $spec['class'];
                         unset($spec['class']);
                     } else {
                         throw new Engine_Sanity_Exception('No type or class specified for test');
                     }
                 }
                 Engine_Loader::loadClass($class);
                 $options = array_merge($spec, $options);
                 $test = new $class($options);
             }
         }
     }
     if (!$test instanceof Engine_Sanity_Test_Interface) {
         throw new Engine_Sanity_Exception('Test must be an instance of Engine_Sanity_Test_Abstract');
     }
     $this->_tests[] = $test;
     return $this;
 }
示例#18
0
 public function indexAction()
 {
     // Make filter form
     $this->view->formFilter = $formFilter = new Core_Form_Admin_Tasks_Filter();
     // Process form
     $values = $this->_getAllParams();
     if (null === $this->_getParam('category')) {
         $values['category'] = 'system';
     }
     if (!$formFilter->isValid($values)) {
         $values = array();
     } else {
         $values = $formFilter->getValues();
     }
     $values = array_filter($values);
     $this->view->formFilterValues = $values;
     // Make select
     $tasksTable = Engine_Api::_()->getDbtable('tasks', 'core');
     $select = $tasksTable->select()->where('module IN(?)', (array) Engine_Api::_()->getDbtable('modules', 'core')->getEnabledModuleNames());
     // Make select - order
     if (empty($values['order'])) {
         $values['order'] = 'task_id';
     }
     if (empty($values['direction'])) {
         $values['direction'] = 'ASC';
     }
     $select->order($values['order'] . ' ' . $values['direction']);
     unset($values['order']);
     unset($values['direction']);
     // Make select - where
     if (isset($values['moduleName'])) {
         $values['module'] = $values['moduleName'];
         unset($values['moduleName']);
     }
     foreach ($values as $key => $value) {
         $select->where($tasksTable->getAdapter()->quoteIdentifier($key) . ' = ?', $value);
     }
     // Make paginator
     $this->view->tasks = $tasks = Zend_Paginator::factory($select);
     $tasks->setItemCountPerPage(25);
     $tasks->setCurrentPageNumber($this->_getParam('page'));
     // Get task progresses
     $taskProgress = array();
     foreach ($tasks as $task) {
         try {
             Engine_Loader::loadClass($task->plugin);
             $pluginClass = $task->plugin;
             $plugin = new $pluginClass($task);
             if ($plugin instanceof Core_Plugin_Task_Abstract) {
                 $total = $plugin->getTotal();
                 $progress = $plugin->getProgress();
                 if ($total || $progress) {
                     $taskProgress[$task->plugin]['progress'] = $plugin->getProgress();
                     $taskProgress[$task->plugin]['total'] = $plugin->getTotal();
                 }
             }
         } catch (Exception $e) {
         }
     }
     $this->view->taskProgress = $taskProgress;
     // Get task settings
     $this->view->taskSettings = Engine_Api::_()->getApi('settings', 'core')->core_tasks;
     // Get currently executing task info
     $this->view->currentlyExecutingCount = $tasksTable->select()->from($tasksTable->info('name'), new Zend_Db_Expr('COUNT(*)'))->where('executing = ?', 1)->query()->fetchColumn(0);
     $this->view->navigation = $this->getNavigation();
 }
示例#19
0
 public function addToArchive(Archive_Tar $archive)
 {
     // Add package file
     $rval = $archive->addString('application' . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . $this->getKey() . '.json', $this->toString('json'));
     if ($archive->isError($rval)) {
         throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage());
     }
     // Add internal structure
     if ($this->getAddDirectoryToArchive()) {
         $rval = $archive->addModify($this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath(), null, $this->getBasePath());
         if ($archive->isError($rval)) {
             throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage());
         }
     } else {
         foreach ($this->getStructure() as $key => $value) {
             if ($this->_jitInstantiation && is_array($value) && !empty($value['type'])) {
                 $class = 'Engine_Package_Manifest_Entity_' . ucfirst($value['type']);
                 Engine_Loader::loadClass($class);
                 $value = new $class($value);
                 $value->setBasePath($this->getBasePath());
             } else {
                 if (!$value instanceof Engine_Package_Manifest_Entity_Abstract) {
                     throw new Engine_Package_Manifest_Exception('Not a package entity');
                 }
             }
             if (method_exists($value, 'setAddDirectoryToArchive')) {
                 $value->setAddDirectoryToArchive($this->getAddDirectoryToArchive());
             }
             $value->addToArchive($archive);
         }
     }
 }
示例#20
0
文件: Abstract.php 项目: robeendey/ce
 public function object($path, $mode = 'r')
 {
     // Create
     $class = $this->getAdapterPrefix() . '_Vfs_Object_' . $this->getAdapterType();
     Engine_Loader::loadClass($class);
     $instance = new $class($this, $path, $mode);
     return $instance;
 }
示例#21
0
 public function getTaskPlugin($task)
 {
     // Must be a row of tasks or jobs
     if (!is_object($task)) {
         throw new Core_Model_Exception(sprintf('Must be given a row of ' . 'Core_Model_DbTable_Tasks, given ' . '%s', gettype($task)));
     } else {
         if (!$task->getTable() instanceof Core_Model_DbTable_Tasks) {
             throw new Core_Model_Exception(sprintf('Must be given a row of ' . 'Core_Model_DbTable_Tasks, given ' . '%s', get_class($task)));
         }
     }
     // Get plugin class
     $class = $task->plugin;
     // Load class
     Engine_Loader::loadClass($class);
     // Make sure is a subclass of Core_Plugin_Task_Abstract
     if (!is_subclass_of($class, 'Core_Plugin_Task_Abstract')) {
         throw new Core_Model_Exception(sprintf('Task plugin %1$s should extend Core_Plugin_Task_Abstract', $class));
     }
     // Check for execute method?
     if (!method_exists($class, 'execute')) {
         throw new Core_Model_Exception(sprintf('Task plugin %1$s does not have an execute method', $class));
     }
     // Get plugin object
     $plugin = new $class($task);
     // Set the log
     $plugin->setLog($this->getLog());
     return $plugin;
 }
 /**
  * Set the class name to use for the default registry instance.
  * Does not affect the currently initialized instance, it only applies
  * for the next time you instantiate.
  *
  * @param string $registryClassName
  * @return void
  * @throws Zend_Exception if the registry is initialized or if the
  *   class name is not valid.
  */
 public static function setClassName($registryClassName = 'Engine_Registry')
 {
     if (self::$_registry !== null) {
         // require_once 'Zend/Exception.php';
         throw new Zend_Exception('Registry is already initialized');
     }
     if (!is_string($registryClassName)) {
         // require_once 'Zend/Exception.php';
         throw new Zend_Exception("Argument is not a class name");
     }
     /**
      * @see Zend_Loader
      */
     if (!class_exists($registryClassName)) {
         Engine_Loader::loadClass($registryClassName);
     }
     parent::setClassName($registryClassName);
     self::$_registryClassName = $registryClassName;
 }
 public function widgetAction()
 {
     // Render by widget name
     $mod = $this->_getParam('mod');
     $name = $this->_getParam('name');
     if (null === $name) {
         throw new Exception('no widget found with name: ' . $name);
     }
     if (null !== $mod) {
         $name = $mod . '.' . $name;
     }
     $contentInfoRaw = $this->getContentAreas();
     $contentInfo = array();
     foreach ($contentInfoRaw as $info) {
         $contentInfo[$info['name']] = $info;
     }
     // It has a form specified in content manifest
     if (!empty($contentInfo[$name]['adminForm'])) {
         if (is_string($contentInfo[$name]['adminForm'])) {
             // Core_Form_Admin_Widget_*
             $formClass = $contentInfo[$name]['adminForm'];
             Engine_Loader::loadClass($formClass);
             $this->view->form = $form = new $formClass();
         } else {
             if (is_array($contentInfo[$name]['adminForm'])) {
                 $this->view->form = $form = new Engine_Form($contentInfo[$name]['adminForm']);
             } else {
                 throw new Core_Model_Exception('Unable to load admin form class');
             }
         }
         // Try to set title if missing
         if (!$form->getTitle()) {
             $form->setTitle('Editing: ' . $contentInfo[$name]['title']);
         }
         // Try to set description if missing
         if (!$form->getDescription()) {
             $form->setDescription('placeholder');
         }
         $form->setAttrib('class', 'global_form_popup ' . $form->getAttrib('class'));
         // Add title element
         if (!$form->getElement('title')) {
             $form->addElement('Text', 'title', array('label' => 'Title', 'order' => -100));
         }
         // Add mobile element?
         if (!$form->getElement('nomobile')) {
             $form->addElement('Select', 'nomobile', array('label' => 'Hide on mobile site?', 'order' => 100000 - 5, 'multiOptions' => array('1' => 'Yes, do not display on mobile site.', '0' => 'No, display on mobile site.'), 'value' => '0'));
         }
         if (!empty($contentInfo[$name]['isPaginated']) && !$form->getElement('itemCountPerPage')) {
             $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0))), 'order' => 1000000 - 1));
         }
         // Add submit button
         if (!$form->getElement('submit') && !$form->getElement('execute')) {
             $form->addElement('Button', 'execute', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000000));
         }
         // Add name
         $form->addElement('Hidden', 'name', array('value' => $name, 'order' => 1000010));
         if (!$form->getElement('cancel')) {
             $form->addElement('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000001));
         }
         if (!$form->getDisplayGroup('buttons')) {
             $submitName = $form->getElement('execute') ? 'execute' : 'submit';
             $form->addDisplayGroup(array($submitName, 'cancel'), 'buttons', array('order' => 1000002));
         }
         // Force method and action
         $form->setMethod('post')->setAction($_SERVER['REQUEST_URI']);
         if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
             $this->view->values = $form->getValues();
             $this->view->form = null;
         }
         return;
     }
     // Try to render admin page
     if (!empty($contentInfo[$name])) {
         try {
             $structure = array('type' => 'widget', 'name' => $name, 'request' => $this->getRequest(), 'action' => 'admin', 'throwExceptions' => true);
             // Create element (with structure)
             $element = new Engine_Content_Element_Container(array('elements' => array($structure), 'decorators' => array('Children')));
             $content = $element->render();
             $this->getResponse()->setBody($content);
             $this->_helper->viewRenderer->setNoRender(true);
             return;
         } catch (Exception $e) {
         }
     }
     // Just render default editing form
     $this->view->form = $form = new Engine_Form(array('title' => $contentInfo[$name]['title'], 'description' => 'placeholder', 'method' => 'post', 'action' => $_SERVER['REQUEST_URI'], 'class' => 'global_form_popup', 'elements' => array(array('Text', 'title', array('label' => 'Title')), array('Button', 'submit', array('label' => 'Save', 'type' => 'submit', 'decorators' => array('ViewHelper'), 'ignore' => true, 'order' => 1501)), array('Hidden', 'name', array('value' => $name)), array('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1502))), 'displaygroups' => array('buttons' => array('name' => 'buttons', 'elements' => array('submit', 'cancel'), 'options' => array('order' => 1500)))));
     if (!empty($contentInfo[$name]['isPaginated'])) {
         $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0)))));
     }
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         $this->view->values = $form->getValues();
         $this->view->form = null;
     } else {
         $form->populate($this->_getAllParams());
     }
 }
示例#24
0
 public function getForm()
 {
     if (is_null($this->_form)) {
         $formArgs = array();
         // Preload profile type field stuff
         $profileTypeField = $this->getProfileTypeField();
         if ($profileTypeField) {
             $accountSession = new Zend_Session_Namespace('User_Plugin_Signup_Account');
             $profileTypeValue = @$accountSession->data['profile_type'];
             if ($profileTypeValue) {
                 $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $profileTypeValue);
             } else {
                 $topStructure = Engine_Api::_()->fields()->getFieldStructureTop('user');
                 if (count($topStructure) == 1 && $topStructure[0]->getChild()->type == 'profile_type') {
                     $profileTypeField = $topStructure[0]->getChild();
                     $options = $profileTypeField->getOptions();
                     if (count($options) == 1) {
                         $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $options[0]->option_id);
                     }
                 }
             }
         }
         // Create form
         Engine_Loader::loadClass($this->_formClass);
         $class = $this->_formClass;
         $this->_form = new $class($formArgs);
         $data = $this->getSession()->data;
         if (!empty($_SESSION['facebook_signup'])) {
             try {
                 $facebookTable = Engine_Api::_()->getDbtable('facebook', 'user');
                 $facebook = $facebookTable->getApi();
                 $settings = Engine_Api::_()->getDbtable('settings', 'core');
                 if ($facebook && $settings->core_facebook_enable) {
                     // Load Faceboolk data
                     $apiInfo = $facebook->api('/me');
                     $fb_data = array();
                     $fb_keys = array('first_name', 'last_name', 'birthday', 'birthdate');
                     foreach ($fb_keys as $key) {
                         if (isset($apiInfo[$key])) {
                             $fb_data[$key] = $apiInfo[$key];
                         }
                     }
                     if (isset($apiInfo['birthday']) && !empty($apiInfo['birthday'])) {
                         $fb_data['birthdate'] = date("Y-m-d", strtotime($fb_data['birthday']));
                     }
                     // populate fields, using Facebook data
                     $struct = $this->_form->getFieldStructure();
                     foreach ($struct as $fskey => $map) {
                         $field = $map->getChild();
                         if ($field->isHeading()) {
                             continue;
                         }
                         if (isset($field->type) && in_array($field->type, $fb_keys)) {
                             $el_key = $map->getKey();
                             $el_val = $fb_data[$field->type];
                             $el_obj = $this->_form->getElement($el_key);
                             if ($el_obj instanceof Zend_Form_Element && !$el_obj->getValue()) {
                                 $el_obj->setValue($el_val);
                             }
                         }
                     }
                 }
             } catch (Exception $e) {
                 // Silence?
             }
         }
         // Attempt to preload information
         if (!empty($_SESSION['janrain_signup']) && !empty($_SESSION['janrain_signup_info'])) {
             try {
                 $settings = Engine_Api::_()->getDbtable('settings', 'core');
                 if ($settings->core_janrain_enable) {
                     $jr_info = $_SESSION['janrain_signup_info'];
                     $jr_poco = @$_SESSION['janrain_signup_info']['merged_poco'];
                     $jr_data = array();
                     if (!empty($jr_info['displayName'])) {
                         if (false !== strpos($jr_info['displayName'], ' ')) {
                             list($jr_data['first_name'], $jr_data['last_name']) = explode(' ', $jr_info['displayName']);
                         } else {
                             $jr_data['first_name'] = $jr_info['displayName'];
                         }
                     }
                     if (!empty($jr_info['name']['givenName'])) {
                         $jr_data['first_name'] = $jr_info['name']['givenName'];
                     }
                     if (!empty($jr_info['name']['familyName'])) {
                         $jr_data['last_name'] = $jr_info['name']['familyName'];
                     }
                     if (!empty($jr_info['email'])) {
                         $jr_data['email'] = $jr_info['email'];
                     }
                     if (!empty($jr_info['url'])) {
                         $jr_data['website'] = $jr_info['url'];
                     }
                     if (!empty($jr_info['birthday'])) {
                         $jr_data['birthdate'] = date("Y-m-d", strtotime($jr_info['birthday']));
                     }
                     if (!empty($jr_poco['url']) && false !== stripos($jr_poco['url'], 'www.facebook.com/profile.php?id=')) {
                         list($null, $jr_data['facebook']) = explode('www.facebook.com/profile.php?id=', $jr_poco['url']);
                     } else {
                         if (!empty($jr_data['url']) && false !== stripos($jr_poco['url'], 'http://www.facebook.com/')) {
                             list($null, $jr_data['facebook']) = explode('http://www.facebook.com/', $jr_data['url']);
                         }
                     }
                     if (!empty($jr_poco['currentLocation']['formatted'])) {
                         $jr_data['location'] = $jr_poco['currentLocation']['formatted'];
                     }
                     if (!empty($jr_poco['religion'])) {
                         // Might not match any values
                         $jr_data['religion'] = str_replace(' ', '_', strtolower($jr_poco['religion']));
                     }
                     if (!empty($jr_poco['relationshipStatus'])) {
                         // Might not match all values
                         $jr_data['relationship_status'] = str_replace(' ', '_', strtolower($jr_poco['relationshipStatus']));
                     }
                     if (!empty($jr_poco['politicalViews'])) {
                         // Only works if text
                         $jr_data['political_views'] = $jr_poco['politicalViews'];
                     }
                     // populate fields, using janrain data
                     $struct = $this->_form->getFieldStructure();
                     foreach ($struct as $fskey => $map) {
                         $field = $map->getChild();
                         if ($field->isHeading()) {
                             continue;
                         }
                         if (!empty($field->type) && !empty($jr_data[$field->type])) {
                             $val = $jr_data[$field->type];
                         } else {
                             if (!empty($field->alias) && !empty($jr_data[$field->alias])) {
                                 $val = $jr_data[$field->alias];
                             } else {
                                 continue;
                             }
                         }
                         $el_key = $map->getKey();
                         $el_val = $val;
                         $el_obj = $this->_form->getElement($el_key);
                         if ($el_obj instanceof Zend_Form_Element && !$el_obj->getValue()) {
                             $el_obj->setValue($el_val);
                         }
                     }
                 }
             } catch (Exception $e) {
                 echo $e;
                 // Silence?
             }
         }
         if (!empty($data)) {
             foreach ($data as $key => $val) {
                 $el = $this->_form->getElement($key);
                 if ($el instanceof Zend_Form_Element) {
                     $el->setValue($val);
                 }
             }
         }
     }
     return $this->_form;
 }
示例#25
0
 public function editAction()
 {
     // Check params
     $justCreated = $this->_getParam('justCreated');
     $serviceIdentity = $this->_getParam('service_id');
     if (!$serviceIdentity) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'index', 'service_id' => null, 'justCreated' => null));
     }
     $serviceTable = Engine_Api::_()->getDbtable('services', 'storage');
     $service = $serviceTable->find($serviceIdentity)->current();
     if (!$service) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'index', 'service_id' => null, 'justCreated' => null));
     }
     $serviceTypesTable = Engine_Api::_()->getDbtable('serviceTypes', 'storage');
     $serviceType = $serviceTypesTable->find($service->servicetype_id)->current();
     if (!$serviceType) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'index', 'service_id' => null, 'justCreated' => null));
     }
     // Get form class
     if (!empty($serviceType['form'])) {
         $formClass = $serviceType['form'];
     } else {
         $formClass = 'Storage_Form_Admin_Service_Generic';
     }
     Engine_Loader::loadClass($formClass);
     // Make form
     $this->view->form = $form = new $formClass();
     $form->setTitle($this->view->translate('Edit Storage Service: %s (ID: %d)', $serviceType->title, $service->service_id));
     // Populate form
     $config = null;
     if (!empty($service->config)) {
         $config = Zend_Json::decode($service->config);
         if (!is_array($config)) {
             $config = null;
         } else {
             $config = $this->_flattenParams($config);
         }
     }
     $form->populate($service->toArray());
     if (!empty($config)) {
         $form->populate($config);
     }
     // Check method
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $values = $form->getValues();
     $values = $this->_expandParams($values);
     $db = $serviceTable->getAdapter();
     $db->beginTransaction();
     try {
         $service->enabled = (bool) $values['enabled'];
         unset($values['enabled']);
         if (empty($values)) {
             $service->config = null;
         } else {
             $service->config = Zend_Json::encode($values);
         }
         $service->save();
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     $form->addNotice('Your changes have been saved.');
 }
示例#26
0
 protected function _initView()
 {
     // Create view
     $view = new Zend_View();
     // Set encoding (@todo maybe use configuration?)
     $view->setEncoding('utf-8');
     $view->addScriptPath(APPLICATION_PATH);
     // Setup and register viewRenderer
     // @todo we may not need to override zend's
     $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
     //$viewRenderer = new Engine_Controller_Action_Helper_ViewRenderer($view);
     $viewRenderer->setViewSuffix('tpl');
     Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, $viewRenderer);
     // Initialize contextSwitch helper
     Zend_Controller_Action_HelperBroker::addHelper(new Core_Controller_Action_Helper_ContextSwitch());
     // Add default helper paths
     $view->addHelperPath('Engine/View/Helper/', 'Engine_View_Helper_');
     $this->initViewHelperPath();
     // Set doctype
     Engine_Loader::loadClass('Zend_View_Helper_Doctype');
     $doctypeHelper = new Zend_View_Helper_Doctype();
     $doctypeHelper->doctype(Engine_Api::_()->getApi('settings', 'core')->getSetting('core.doctype', 'HTML4_LOOSE'));
     // Add to local container and registry
     Zend_Registry::set('Zend_View', $view);
     return $view;
 }
示例#27
0
文件: Tasks.php 项目: robeendey/ce
 protected function _executeTask(Engine_Db_Table_Row $task)
 {
     // Return if we reached our limit
     if ($this->_runCount >= $this->getMaxJobs()) {
         return $this;
     }
     // Log
     if (APPLICATION_ENV == 'development') {
         $this->getLog()->log('Task Execution Check: ' . $task->title, Zend_Log::NOTICE);
     }
     // Update task using where (this will prevent double executions)
     $affected = $task->getTable()->update(array('state' => 'active', 'executing' => 1, 'executing_id' => $this->getPid(), 'started_last' => time(), 'started_count' => new Zend_Db_Expr('started_count + 1')), array('task_id = ?' => $task->task_id, 'state = ?' => $task->state, 'executing = ?' => 0, 'executing_id = ?' => 0));
     // Refresh
     $task->refresh();
     // If not affected cancel
     if ($affected !== 1) {
         // $task->executing_id != $this->getPid()
         return $this;
     }
     // Log
     if (APPLICATION_ENV == 'development') {
         $this->getLog()->log('Task Execution Pass: '******'Core_Plugin_Task_Abstract')) {
             $this->getLog()->log(sprintf('Task plugin %1$s should extend Core_Plugin_Task_Abstract', $task->plugin), Zend_Log::WARN);
             // Execute plugin
             $plugin = Engine_Api::_()->loadClass($task->plugin);
             if (method_exists($plugin, 'execute')) {
                 $plugin->execute();
             } else {
                 if (method_exists($plugin, 'executeTask')) {
                     $plugin->executeTask();
                 } else {
                     throw new Engine_Exception('Task ' . $task->plugin . ' does not have an execute or executeTask method');
                 }
             }
         } else {
             // Create plugin object
             $pluginClass = $task->plugin;
             $plugin = new $pluginClass($task);
             $plugin->setLog($this->getLog());
             // Execute
             $plugin->execute();
             // Ask semi auto ones if they are done yet
             if ($task->type == 'semi-automatic' && ($plugin instanceof Core_Plugin_Task_PersistentAbstract || method_exists($plugin, 'isComplete'))) {
                 $isComplete = (bool) $plugin->isComplete();
             }
             // Check was idle
             $wasIdle = $plugin->wasIdle();
         }
         $status = true;
     } catch (Exception $e) {
         // Log exception
         $this->getLog()->log($e->__toString(), Zend_Log::ERR);
         $status = false;
     }
     // Update task
     if (!$isComplete) {
         $task->state = 'sleeping';
     } else {
         $task->state = 'dormant';
     }
     $task->executing = false;
     $task->executing_id = 0;
     $task->completed_count++;
     $task->completed_last = time();
     if ($status) {
         $task->success_count++;
         $task->success_last = time();
     } else {
         $task->failure_count++;
         $task->failure_last = time();
     }
     $task->save();
     // Update count
     if (!$wasIdle) {
         $this->_runCount++;
     }
     // Remove executing task
     $this->_executingTask = null;
     // Log
     if (APPLICATION_ENV == 'development') {
         if ($status) {
             $this->getLog()->log('Task Execution Complete: ' . $task->title, Zend_Log::NOTICE);
         } else {
             $this->getLog()->log('Task Execution Complete (with errors): ' . $task->title, Zend_Log::NOTICE);
         }
     }
     return $this;
 }
 public function jobAddAction()
 {
     // Get available types
     $jobTypeTable = Engine_Api::_()->getDbtable('jobTypes', 'core');
     $enabledModules = Engine_Api::_()->getDbtable('modules', 'core')->getEnabledModuleNames();
     $enabledJobTypesSelect = $jobTypeTable->select()->where('enabled = ?', 1)->where('module IN(?)', $enabledModules);
     $this->view->enabledJobTypes = $enabledJobTypes = $jobTypeTable->fetchAll($enabledJobTypesSelect);
     // Check given type against available types
     $type = $this->_getParam('type');
     if (!$type) {
         return;
     }
     $jobType = $enabledJobTypes->getRowMatching('type', $type);
     if (!$jobType) {
         return;
     }
     $this->view->type = $type;
     // Show form
     $formClass = $jobType->form;
     if (!$formClass) {
         $formClass = 'Core_Form_Admin_Job_Generic';
     }
     Engine_Loader::loadClass($formClass);
     $this->view->form = $form = new $formClass();
     // Special case for generic
     if ($formClass == 'Core_Form_Admin_Job_Generic') {
         $form->setTitle($this->view->translate('Job: %1$s', $this->view->translate($jobType->title)));
     }
     // Check method/data
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $values = $form->getValues();
     $jobTable = Engine_Api::_()->getDbtable('jobs', 'core');
     $db = $jobTable->getAdapter();
     try {
         $jobTable->addJob($jobType->type, $values);
     } catch (Exception $e) {
         throw $e;
     }
     return $this->_helper->redirector->gotoRoute(array('action' => 'jobs', 'type' => null));
 }