Esempio n. 1
0
 /**
  * Get items from ZOO module params.
  *
  * @param AppData $params Module Parameter
  * @return array Items
  */
 public function getItems($params)
 {
     $items = array();
     if ($application = $this->app->table->application->get($params->get('application', 0))) {
         // set one or multiple categories
         $category = (int) $params->get('category', 0);
         if ($params->get('subcategories')) {
             $categories = $application->getCategoryTree(true);
             if (isset($categories[$category])) {
                 $category = array_merge(array($category), array_keys($categories[$category]->getChildren(true)));
             }
         }
         // get items
         if ($params->get('mode') == 'item') {
             if (($item = $this->app->table->item->get($params->get('item_id'))) && $item->isPublished() && $item->canAccess()) {
                 $items[] = $item;
             }
         } else {
             if ($params->get('mode') == 'types') {
                 $items = $this->app->table->item->getByType($params->get('type'), $application->id, true, null, $params->get('order', array('_itemname')), 0, $params->get('count', 4));
             } else {
                 $items = $this->app->table->item->getByCategory($application->id, $category, true, null, $params->get('order', array('_itemname')), 0, $params->get('count', 4));
             }
         }
     }
     return $items;
 }
Esempio n. 2
0
 /**
  * Magic method to get access to protected property @_options
  * @param string $property
  * @return mixed
  */
 public function __get($property)
 {
     return $this->options->get($property, null);
 }
Esempio n. 3
0
 /**
  * Validates the submitted element
  *
  * @param AppData $value  value
  * @param AppData $params submission parameters
  *
  * @return array
  * @throws AppValidatorException
  */
 public function _validateSubmission($value, $params)
 {
     // init vars
     $trusted_mode = $params->get('trusted_mode');
     // get old file value
     $old_file = $this->get('file');
     $file = '';
     // get file from select list
     if ($trusted_mode && ($file = $value->get('image'))) {
         if (!$this->_inUploadPath($file) && $file != $old_file) {
             throw new AppValidatorException(sprintf('This file is not located in the upload directory.'));
         }
         if (!JFile::exists($file)) {
             throw new AppValidatorException(sprintf('This file does not exist.'));
         }
     } else {
         try {
             // get the uploaded file information
             $userfile = $this->_getUploadedFile();
             // validator hack for element error message after submission controller redirect
             if ((empty($userfile) || empty($userfile['tmp_name'])) && ($value->get('filename') || $value->get('image'))) {
                 if ($message = $this->app->jbsession->get($this->identifier . '||' . $this->key(), 'jbimage_validate')) {
                     throw new AppValidatorException($message);
                 }
             }
             // hack hide undefined error after redirect
             if (!empty($userfile)) {
                 $max_upload_size = $this->config->get('max_upload_size', '512') * 1024;
                 $max_upload_size = empty($max_upload_size) ? null : $max_upload_size;
                 $file = $this->app->validator->create('file', array('mime_type_group' => 'image', 'max_size' => $max_upload_size))->addMessage('mime_type_group', 'Uploaded file is not an image.')->clean($userfile);
             }
         } catch (AppValidatorException $e) {
             $this->app->jbsession->set($this->identifier . '||' . $this->key(), $e->getMessage(), 'jbimage_validate');
             if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
                 throw $e;
             }
             if (!$trusted_mode && $old_file && $value->get('image')) {
                 $file = $old_file;
             }
         }
     }
     if ($params->get('required') && empty($file)) {
         throw new AppValidatorException('Please select an image to upload.');
     }
     $result = array('file' => $this->_moveUploadedFiles($file));
     if ($trusted_mode) {
         $result['title'] = $this->app->validator->create('string', array('required' => false))->clean($value->get('title'));
         $result['link'] = $this->app->validator->create('url', array('required' => false), array('required' => 'Please enter an URL.'))->clean($value->get('link'));
         $result['target'] = $this->app->validator->create('', array('required' => false))->clean($value->get('target'));
         $result['rel'] = $this->app->validator->create('string', array('required' => false))->clean($value->get('rel'));
     }
     $this->next();
     return $result;
 }
Esempio n. 4
0
 /**
  * Validates the submitted element
  * @param AppData $value  value
  * @param AppData $params submission parameters
  * @return array
  * @throws AppValidatorException
  */
 public function validateSubmission($value, $params)
 {
     $images_arr = $value->get('images');
     if (empty($images_arr)) {
         $images_arr = $value;
     }
     if ($params->get('required') && empty($images_arr)) {
         throw new AppValidatorException('Please select an image to upload.');
     }
     $key = 0;
     foreach ($images_arr as $image) {
         $result[$key]['name'] = $this->app->validator->create('string', array('required' => true))->clean($image['name']);
         $key++;
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * Builds the assign element info from JSON.
  *
  * @param AppData $data the export data
  *
  * @return array Assign element info
  */
 public function getImportInfo(AppData $data)
 {
     $info = array();
     $application = $this->app->zoo->getApplication();
     // get frontpage count
     $info['frontpage_count'] = (bool) $data->find('categories._root');
     // get category count
     $info['category_count'] = max(array(count($data->get('categories', array())) - (int) $info['frontpage_count'], 0));
     // get types
     $type_elements = array();
     foreach ($application->getTypes() as $type) {
         foreach ($type->getElements() as $element) {
             $type_elements[$type->id][$element->getElementType()][] = $element;
         }
     }
     // get item types
     $info['items'] = array();
     foreach ($data->get('items', array()) as $alias => $item) {
         $group = $item['group'];
         if (!isset($info['items'][$group])) {
             $info['items'][$group]['item_count'] = 0;
             $info['items'][$group]['elements'] = array();
             if (isset($item['elements'])) {
                 foreach ($item['elements'] as $alias => $element) {
                     if (!isset($info['items'][$group]['elements'][$alias])) {
                         // add element type
                         $info['items'][$group]['elements'][$alias]['type'] = ucfirst($element['type']);
                         // add element name
                         $info['items'][$group]['elements'][$alias]['name'] = $element['name'];
                         // add elements to assign too
                         $info['items'][$group]['elements'][$alias]['assign'] = array();
                         foreach ($type_elements as $type => $assign_elements) {
                             if (isset($assign_elements[$element['type']])) {
                                 $info['items'][$group]['elements'][$alias]['assign'][$type] = $assign_elements[$element['type']];
                             }
                         }
                     }
                 }
             }
         }
         $info['items'][$group]['item_count'] += 1;
     }
     return $info;
 }
Esempio n. 6
0
 /**
  * Get interface params for all core elements that used in widgets.
  * @return array
  */
 public function elementsInterfaceParams()
 {
     $options = array();
     $parameters = $this->loadParams();
     $variant = $this->_list->current();
     foreach ($parameters as $params) {
         if (($element = $variant->get($params['identifier'])) && $element->isCore()) {
             $params = new AppData($params);
             $element = $this->_storage->configure($element, array('index' => $params->get('_index'), 'position' => $params->get('_position'), 'template' => $params->get('_template')));
             $options[$element->getElementType()] = $element->interfaceParams($params);
         }
     }
     return $options;
 }
Esempio n. 7
0
 /**
  * @param null $default
  * @return mixed
  */
 public function getDescription($default = null)
 {
     return JText::_($this->config->get('description', $default));
 }
Esempio n. 8
0
 /**
  * @param array $options
  * @return $this
  */
 public function bindData(array $options = array())
 {
     $elements = new AppData();
     if (isset($options['data'])) {
         $elements->exchangeArray($options['data']);
     }
     foreach ($this->elements as $key => $element) {
         $this->set($key, $this->setElement($element, $elements->get($key)));
     }
     return $this;
 }