示例#1
0
 /**
  * Store content
  * Can be passed a boolean to turn off check() method
  *
  * @param   boolean $check Call check() method?
  * @return  boolean True on success, false if errors
  */
 public function store($check = true)
 {
     if ($this->get('_file')) {
         $path = $this->filespace() . DS . $this->get('item_id');
         if (!is_dir($path)) {
             if (!Filesystem::makeDirectory($path)) {
                 $this->setError(Lang::txt('Error uploading. Unable to create path.'));
                 return false;
             }
         }
         $file = $this->get('_file');
         // Make the filename safe
         $file['name'] = urldecode($files['name']);
         $file['name'] = Filesystem::clean($file['name']);
         $file['name'] = str_replace(' ', '_', $file['name']);
         // Upload new files
         if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
             $this->setError(Lang::txt('ERROR_UPLOADING') . ': ' . $file['name']);
             return false;
         }
         $this->set('filename', $file['name']);
         // Generate a thumbnail
         $this->thumbnail();
     }
     return parent::store($check);
 }
示例#2
0
 /**
  * Store content
  * Can be passed a boolean to turn off check() method
  *
  * @param   boolean $check Call check() method?
  * @return  boolean True on success, false if errors
  */
 public function store($check = true)
 {
     if (!parent::store($check)) {
         return false;
     }
     if (!$this->get('id')) {
         if (!$this->_tbl->id) {
             $this->_tbl->id = $this->_tbl->_db->insertid();
         }
         $this->set('id', $this->_tbl->id);
     }
     if ($this->get('_assets')) {
         $k = 0;
         foreach ($this->get('_assets') as $i => $asset) {
             $k++;
             $a = new Asset($asset['id']);
             $a->set('type', $asset['type']);
             $a->set('item_id', $this->get('id'));
             $a->set('ordering', $k);
             $a->set('filename', $asset['filename']);
             if (strtolower($a->get('filename')) == 'http://') {
                 if ($a->get('id') && !$a->remove()) {
                     $this->setError($a->getError());
                 }
             } else {
                 if (!$a->store()) {
                     $this->setError($a->getError());
                 }
             }
         }
         $a->reorder();
     }
     if ($files = $this->get('_files')) {
         $config = Component::params('com_collections');
         // Build the upload path if it doesn't exist
         $path = $this->filespace() . DS . $this->get('id');
         if (!is_dir($path)) {
             if (!Filesystem::makeDirectory($path)) {
                 $this->setError(Lang::txt('Error uploading. Unable to create path.'));
                 return false;
             }
         }
         $descriptions = $this->get('_descriptions', array());
         if (isset($files['name'])) {
             foreach ($files['name'] as $i => $file) {
                 // Make the filename safe
                 $files['name'][$i] = urldecode($files['name'][$i]);
                 $files['name'][$i] = Filesystem::clean($files['name'][$i]);
                 $files['name'][$i] = str_replace(' ', '_', $files['name'][$i]);
                 // Upload new files
                 if (!Filesystem::upload($files['tmp_name'][$i], $path . DS . $files['name'][$i])) {
                     $this->setError(Lang::txt('ERROR_UPLOADING') . ': ' . $files['name'][$i]);
                 } else {
                     $asset = new Asset();
                     //$asset->set('_file', $file);
                     $asset->set('item_id', $this->get('id'));
                     $asset->set('filename', $files['name'][$i]);
                     $asset->set('description', isset($descriptions[$i]) ? $descriptions[$i] : '');
                     if (!$asset->store()) {
                         $this->setError($asset->getError());
                     }
                 }
             }
         }
         if ($this->getError()) {
             return false;
         }
     }
     $trashed = $this->assets(array('state' => self::APP_STATE_DELETED));
     if ($trashed->total() > 0) {
         foreach ($trashed as $trash) {
             if ($trash->get('filename') == 'http://') {
                 $trash->remove();
             }
         }
     }
     // Process tags
     if ($this->get('_tags', null) !== null) {
         $this->tag($this->get('_tags', ''), $this->get('created_by'));
     }
     return true;
 }
示例#3
0
 /**
  * Store changes
  *
  * @param   boolean  $check  Validate data?
  * @return  boolean  True on success, False on error
  */
 public function store($check = true)
 {
     if (!parent::store($check)) {
         return false;
     }
     // Create an Item entry
     // This is because even collections can be reposted.
     // Thus, there needs to be an item entry to "repost"
     $item = new Tables\Item($this->_db);
     $item->loadType($this->get('id'), 'collection');
     if (!$item->get('id')) {
         $item->type = 'collection';
         $item->object_id = $this->get('id');
         $item->title = $this->get('title');
         $item->description = $this->get('description');
         $item->access = $this->get('access', 0);
         if (!$item->check()) {
             $this->setError($item->getError());
         }
         // Store new content
         if (!$item->store()) {
             $this->setError($item->getError());
         }
     }
     /*if (!$this->getError() && $this->get('state') == self::APP_STATE_DELETED)
     		{
     			foreach ($this->posts(array('access' => array(0, 1, 2, 4))) as $post)
     			{
     				$post->delete();
     			}
     		}*/
     return true;
 }