Example #1
0
 /**
  * Save an item after it has been translated
  * This will be called by Josetta when a user clicks
  * the Save button. The context is passed so
  * that each plugin knows if it must process the data or not
  *
  * if $item->reference_id is empty, this is
  * a new item, otherwise we are updating the item
  *
  * $item->data contains the fields entered by the user
  * that needs to be saved
  *
  *@param context type
  *@param data in form of array
  *
  *return table id if data is inserted
  *
  *return false if error occurs
  *
  */
 public function onJosettaSaveItem($context, $item, &$errors)
 {
     if ($context != $this->_context) {
         return;
     }
     // load languages for form and error messages
     $this->loadLanguages();
     require_once JPATH_PLUGINS . '/josetta_ext/k2item/models/item.php';
     $k2ItemModel = new JosettaK2ModelItem();
     $savedItemId = $k2ItemModel->save($item);
     if (empty($savedItemId)) {
         // make sure errors are displayed
         JosettaHelper::enqueueMessages($k2ItemModel->getErrors());
         return false;
     }
     return $savedItemId;
 }
Example #2
0
 /**
  * Save an item after it has been translated
  * This will be called by Josetta when a user clicks
  * the Save button. The context is passed so
  * that each plugin knows if it must process the data or not
  *
  * if $item->reference_id is empty, this is
  * a new item, otherwise we are updating the item
  *
  * $item->data contains the fields entered by the user
  * that needs to be saved
  *
  *@param context type
  *@param data in form of array
  *
  *return table id if data is inserted
  *
  *return false if error occurs
  *
  */
 public function onJosettaSaveItem($context, $item, &$errors)
 {
     if ($context != $this->_context) {
         return;
     }
     // load languages for form and error messages
     $this->loadLanguages();
     // Save
     jimport('joomla.filesystem.file');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables');
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/lib/class.upload.php';
     $row = JTable::getInstance('K2Category', 'Table');
     $params = JComponentHelper::getParams('com_k2');
     if (!$row->bind($item)) {
         JosettaHelper::enqueueMessages($row->getError());
         return false;
     }
     $row->parent = (int) $row->parent;
     //$input = JRequest::get('post');
     $filter = JFilterInput::getInstance();
     $categoryParams = new JRegistry($row->params);
     $categoryParams->set('catMetaDesc', $filter->clean($item['metadesc']));
     $categoryParams->set('catMetaKey', $filter->clean($item['metakey']));
     $row->params = $categoryParams->toString();
     $isNew = $row->id ? false : true;
     //Trigger the finder before save event
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('finder');
     $results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.category', $row, $isNew));
     if ($params->get('xssFiltering')) {
         $filter = new JFilterInput(array(), array(), 1, 1, 0);
         $row->description = $filter->clean($row->description);
     }
     if (!$row->id) {
         $row->ordering = $row->getNextOrder('parent = ' . $row->parent . ' AND trash=0');
     }
     $savepath = JPATH_ROOT . '/media/k2/categories/';
     if ($row->image && JFile::exists($savepath . $image)) {
         $uniqueName = uniqid() . '.jpg';
         JFile::copy($savepath . $row->image, $savepath . $uniqueName);
         $row->image = $uniqueName;
     }
     if (!$row->check()) {
         JosettaHelper::enqueueMessages($row->getError());
         return false;
     }
     if (!$row->store()) {
         JosettaHelper::enqueueMessages($row->getError());
         return false;
     }
     if (!$params->get('disableCompactOrdering')) {
         $row->reorder('parent = ' . $row->parent . ' AND trash=0');
     }
     if ((int) $params->get('imageMemoryLimit')) {
         ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M');
     }
     //$files = JRequest::get('files');
     $savepath = JPATH_ROOT . '/media/k2/categories/';
     // TODO: this will be renamed when used through Josetta
     //$existingImage = JRequest::getVar('existingImage');
     if (!empty($item['files']) && !empty($item['files']['image'])) {
         if (($item['files']['image']['error'] === 0 || !empty($item['existingImage'])) && empty($item['del_image'])) {
             if ($item['files']['image']['error'] === 0) {
                 $image = $item['files']['image'];
             } else {
                 $image = JPATH_SITE . '/' . JPath::clean($item['existingImage']);
             }
             $handle = new Upload($image);
             if ($handle->uploaded) {
                 $handle->file_auto_rename = false;
                 $handle->jpeg_quality = $params->get('imagesQuality', '85');
                 $handle->file_overwrite = true;
                 $handle->file_new_name_body = $row->id;
                 $handle->image_resize = true;
                 $handle->image_ratio_y = true;
                 $handle->image_x = $params->get('catImageWidth', '100');
                 $handle->Process($savepath);
                 if ($files['image']['error'] === 0) {
                     $handle->Clean();
                 }
             } else {
                 JosettaHelper::enqueueMessages($handle->error);
                 return false;
             }
             $row->image = $handle->file_dst_name;
         }
     }
     // TODO: this will be renamed when used through Josetta
     if (!empty($item['del_image'])) {
         $currentRow = JTable::getInstance('K2Category', 'Table');
         $currentRow->load($row->id);
         if (JFile::exists(JPATH_ROOT . '/media/k2/categories/' . $currentRow->image)) {
             JFile::delete(JPATH_ROOT . '/media/k2/categories/' . $currentRow->image);
         }
         $row->image = '';
     }
     if (!$row->store()) {
         JosettaHelper::enqueueMessages($row->getError());
         return false;
     }
     //Trigger the finder after save event
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('finder');
     $results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.category', $row, $isNew));
     $cache = JFactory::getCache('com_k2');
     $cache->clean();
     return $row->id;
 }