Esempio n. 1
0
 function extraFields()
 {
     $mainframe =& JFactory::getApplication();
     $itemID = JRequest::getInt('cid', NULL);
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $catid = JRequest::getVar('id');
     $category =& JTable::getInstance('K2Category', 'Table');
     $category->load($catid);
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php';
     $extraFieldModel = new K2ModelExtraField();
     $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
     $output = '<table class="admintable" id="extraFields">';
     $counter = 0;
     if (count($extraFields)) {
         foreach ($extraFields as $extraField) {
             $output .= '<tr><td align="right" class="key">' . $extraField->name . '</td>';
             $output .= '<td>' . $extraFieldModel->renderExtraField($extraField, $itemID) . '</td></tr>';
             $counter++;
         }
     }
     $output .= '</table>';
     if ($counter == 0) {
         $output = JText::_("This category doesn't have assigned extra fields");
     }
     echo $output;
     $mainframe->close();
 }
Esempio n. 2
0
 function extraFields()
 {
     $k2Path = JPATH_ADMINISTRATOR . '/components/com_k2/';
     JTable::addIncludePath($k2Path . 'tables');
     require_once $k2Path . 'models/model.php';
     require_once $k2Path . 'models/category.php';
     require_once $k2Path . 'models/extrafield.php';
     $mainframe = JFactory::getApplication();
     $itemID = JRequest::getInt('id', NULL);
     //$categoryModel = $this->getModel('category');
     $categoryModel = new K2ModelCategory();
     $category = $categoryModel->getData();
     //$extraFieldModel = $this->getModel('extraField');
     $extraFieldModel = new K2ModelExtraField();
     $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
     $output = '<table class="admintable" id="extraFields">';
     $counter = 0;
     if (count($extraFields)) {
         foreach ($extraFields as $extraField) {
             if ($extraField->type == 'header') {
                 $output .= '<tr><td colspan="2" ><h4 class="k2ExtraFieldHeader">' . $extraField->name . '</h4></td></tr>';
             } else {
                 $output .= '<tr><td align="right" class="key"><label for="K2ExtraField_' . $extraField->id . '">' . $extraField->name . '</label></td>';
                 $html = $extraFieldModel->renderExtraField($extraField, $itemID);
                 if ($extraField->type == 'textfield') {
                     $html2 = $this->renderField($itemID, $extraField);
                     if ($html2) {
                         $html = $html2;
                     }
                 }
                 $output .= '<td>' . $html . '</td></tr>';
             }
             $counter++;
         }
     }
     $output .= '</table>';
     if ($counter == 0) {
         $output = JText::_('K2_THIS_CATEGORY_DOESNT_HAVE_ASSIGNED_EXTRA_FIELDS');
     }
     echo $output;
     $mainframe->close();
 }
Esempio n. 3
0
 function extraFields()
 {
     $mainframe = JFactory::getApplication();
     $language = JFactory::getLanguage();
     $language->load('com_k2', JPATH_ADMINISTRATOR);
     $itemID = JRequest::getInt('id', NULL);
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $catid = JRequest::getInt('cid');
     $category = JTable::getInstance('K2Category', 'Table');
     $category->load($catid);
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php';
     $extraFieldModel = new K2ModelExtraField();
     $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
     $output = '<table class="admintable" id="extraFields">';
     $counter = 0;
     if (count($extraFields)) {
         foreach ($extraFields as $extraField) {
             if ($extraField->type == 'header') {
                 $output .= '<tr><td colspan="2" ><h4 class="k2ExtraFieldHeader">' . $extraField->name . '</h4></td></tr>';
             } else {
                 $output .= '<tr><td align="right" class="key"><label for="K2ExtraField_' . $extraField->id . '">' . $extraField->name . '</label></td>';
                 $output .= '<td>' . $extraFieldModel->renderExtraField($extraField, $itemID) . '</td></tr>';
             }
             $counter++;
         }
     }
     $output .= '</table>';
     if ($counter == 0) {
         $output = JText::_('K2_THIS_CATEGORY_DOESNT_HAVE_ASSIGNED_EXTRA_FIELDS');
     }
     echo $output;
     $mainframe->close();
 }
Esempio n. 4
0
 function save($front = false)
 {
     $mainframe =& JFactory::getApplication();
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.archive');
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php';
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $row =& JTable::getInstance('K2Item', 'Table');
     $params =& JComponentHelper::getParams('com_k2');
     $nullDate = $db->getNullDate();
     if (!$row->bind(JRequest::get('post'))) {
         $mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error');
     }
     if ($front && $row->id == NULL) {
         if (!$user->authorize('com_k2', 'add', 'category', $row->catid) && !$user->authorize('com_k2', 'add', 'category', 'all')) {
             $mainframe->redirect('index.php?option=com_k2&view=item&task=add&tmpl=component', JText::_('You are not allowed to post to this category. Save failed.'), 'error');
         }
     }
     $row->id ? $isNew = false : ($isNew = true);
     if ($params->get('mergeEditors')) {
         $text = JRequest::getVar('text', '', 'post', 'string', 2);
         if ($params->get('xssFiltering')) {
             $filter = new JFilterInput(array(), array(), 1, 1, 0);
             $text = $filter->clean($text);
         }
         $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
         $tagPos = preg_match($pattern, $text);
         if ($tagPos == 0) {
             $row->introtext = $text;
             $row->fulltext = '';
         } else {
             list($row->introtext, $row->fulltext) = preg_split($pattern, $text, 2);
         }
     } else {
         $row->introtext = JRequest::getVar('introtext', '', 'post', 'string', 2);
         $row->fulltext = JRequest::getVar('fulltext', '', 'post', 'string', 2);
         if ($params->get('xssFiltering')) {
             $filter = new JFilterInput(array(), array(), 1, 1, 0);
             $row->introtext = $filter->clean($row->introtext);
             $row->fulltext = $filter->clean($row->fulltext);
         }
     }
     if ($row->id) {
         $datenow =& JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     } else {
         $row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0");
         if (JRequest::getInt('featured')) {
             $row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering');
         }
     }
     if ($front) {
         if (!$row->id) {
             $row->created_by = $user->get('id');
         }
     } else {
         $row->created_by = $row->created_by ? $row->created_by : $user->get('id');
     }
     if ($row->created && strlen(trim($row->created)) <= 10) {
         $row->created .= ' 00:00:00';
     }
     $config =& JFactory::getConfig();
     $tzoffset = $config->getValue('config.offset');
     $date =& JFactory::getDate($row->created, $tzoffset);
     $row->created = $date->toMySQL();
     if (strlen(trim($row->publish_up)) <= 10) {
         $row->publish_up .= ' 00:00:00';
     }
     $date =& JFactory::getDate($row->publish_up, $tzoffset);
     $row->publish_up = $date->toMySQL();
     if (trim($row->publish_down) == JText::_('Never') || trim($row->publish_down) == '') {
         $row->publish_down = $nullDate;
     } else {
         if (strlen(trim($row->publish_down)) <= 10) {
             $row->publish_down .= ' 00:00:00';
         }
         $date =& JFactory::getDate($row->publish_down, $tzoffset);
         $row->publish_down = $date->toMySQL();
     }
     $metadata = JRequest::getVar('meta', null, 'post', 'array');
     if (is_array($metadata)) {
         $txt = array();
         foreach ($metadata as $k => $v) {
             if ($k == 'description') {
                 $row->metadesc = $v;
             } elseif ($k == 'keywords') {
                 $row->metakey = $v;
             } else {
                 $txt[] = "{$k}={$v}";
             }
         }
         $row->metadata = implode("\n", $txt);
     }
     $row->featured = JRequest::getInt('featured');
     if (!$row->check()) {
         $mainframe->redirect('index.php?option=com_k2&view=item&cid=' . $row->id, $row->getError(), 'error');
     }
     $dispatcher =& JDispatcher::getInstance();
     JPluginHelper::importPlugin('k2');
     $result = $dispatcher->trigger('onBeforeK2Save', array(&$row, $isNew));
     if (in_array(false, $result, true)) {
         JError::raiseError(500, $row->getError());
         return false;
     }
     if (version_compare(phpversion(), '5.0') < 0) {
         $tmpRow = $row;
     } else {
         $tmpRow = clone $row;
     }
     if (!$row->store()) {
         $mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error');
     }
     $itemID = $row->id;
     $row = $tmpRow;
     $row->id = $itemID;
     if (!$params->get('disableCompactOrdering')) {
         $row->reorder("catid = {$row->catid} AND trash = 0");
     }
     if (JRequest::getInt('featured') && !$params->get('disableCompactOrdering')) {
         $row->reorder("featured = 1 AND trash = 0", 'featured_ordering');
     }
     $files = JRequest::get('files');
     //Image
     $existingImage = JRequest::getVar('existingImage');
     if (($files['image']['error'] === 0 || $existingImage) && !JRequest::getBool('del_image')) {
         if ($files['image']['error'] === 0) {
             $image = $files['image'];
         } else {
             $image = JPATH_SITE . DS . JPath::clean($existingImage);
         }
         $handle = new Upload($image);
         $handle->allowed = array('image/*');
         if ($handle->uploaded) {
             //Image params
             $category =& JTable::getInstance('K2Category', 'Table');
             $category->load($row->catid);
             $cparams = new JParameter($category->params);
             if ($cparams->get('inheritFrom')) {
                 $masterCategoryID = $cparams->get('inheritFrom');
                 $query = "SELECT * FROM #__k2_categories WHERE id=" . (int) $masterCategoryID;
                 $db->setQuery($query, 0, 1);
                 $masterCategory = $db->loadObject();
                 $cparams = new JParameter($masterCategory->params);
             }
             $params->merge($cparams);
             //Original image
             $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src';
             $handle->image_convert = 'jpg';
             $handle->jpeg_quality = 100;
             $handle->file_auto_rename = false;
             $handle->file_overwrite = true;
             $handle->file_new_name_body = md5("Image" . $row->id);
             $handle->Process($savepath);
             $filename = $handle->file_dst_name_body;
             $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache';
             //XLarge image
             $handle->image_resize = true;
             $handle->image_ratio_y = true;
             $handle->image_convert = 'jpg';
             $handle->jpeg_quality = $params->get('imagesQuality');
             $handle->file_auto_rename = false;
             $handle->file_overwrite = true;
             $handle->file_new_name_body = $filename . '_XL';
             if (JRequest::getInt('itemImageXL')) {
                 $imageWidth = JRequest::getInt('itemImageXL');
             } else {
                 $imageWidth = $params->get('itemImageXL', '800');
             }
             $handle->image_x = $imageWidth;
             $handle->Process($savepath);
             //Large image
             $handle->image_resize = true;
             $handle->image_ratio_y = true;
             $handle->image_convert = 'jpg';
             $handle->jpeg_quality = $params->get('imagesQuality');
             $handle->file_auto_rename = false;
             $handle->file_overwrite = true;
             $handle->file_new_name_body = $filename . '_L';
             if (JRequest::getInt('itemImageL')) {
                 $imageWidth = JRequest::getInt('itemImageL');
             } else {
                 $imageWidth = $params->get('itemImageL', '600');
             }
             $handle->image_x = $imageWidth;
             $handle->Process($savepath);
             //Medium image
             $handle->image_resize = true;
             $handle->image_ratio_y = true;
             $handle->image_convert = 'jpg';
             $handle->jpeg_quality = $params->get('imagesQuality');
             $handle->file_auto_rename = false;
             $handle->file_overwrite = true;
             $handle->file_new_name_body = $filename . '_M';
             if (JRequest::getInt('itemImageM')) {
                 $imageWidth = JRequest::getInt('itemImageM');
             } else {
                 $imageWidth = $params->get('itemImageM', '400');
             }
             $handle->image_x = $imageWidth;
             $handle->Process($savepath);
             //Small image
             $handle->image_resize = true;
             $handle->image_ratio_y = true;
             $handle->image_convert = 'jpg';
             $handle->jpeg_quality = $params->get('imagesQuality');
             $handle->file_auto_rename = false;
             $handle->file_overwrite = true;
             $handle->file_new_name_body = $filename . '_S';
             if (JRequest::getInt('itemImageS')) {
                 $imageWidth = JRequest::getInt('itemImageS');
             } else {
                 $imageWidth = $params->get('itemImageS', '200');
             }
             $handle->image_x = $imageWidth;
             $handle->Process($savepath);
             //XSmall image
             $handle->image_resize = true;
             $handle->image_ratio_y = true;
             $handle->image_convert = 'jpg';
             $handle->jpeg_quality = $params->get('imagesQuality');
             $handle->file_auto_rename = false;
             $handle->file_overwrite = true;
             $handle->file_new_name_body = $filename . '_XS';
             if (JRequest::getInt('itemImageXS')) {
                 $imageWidth = JRequest::getInt('itemImageXS');
             } else {
                 $imageWidth = $params->get('itemImageXS', '100');
             }
             $handle->image_x = $imageWidth;
             $handle->Process($savepath);
             //Generic image
             $handle->image_resize = true;
             $handle->image_ratio_y = true;
             $handle->image_convert = 'jpg';
             $handle->jpeg_quality = $params->get('imagesQuality');
             $handle->file_auto_rename = false;
             $handle->file_overwrite = true;
             $handle->file_new_name_body = $filename . '_Generic';
             $imageWidth = $params->get('itemImageGeneric', '300');
             $handle->image_x = $imageWidth;
             $handle->Process($savepath);
             if ($files['image']['error'] === 0) {
                 $handle->Clean();
             }
         } else {
             $mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error');
         }
     }
     if (JRequest::getBool('del_image')) {
         $current =& JTable::getInstance('K2Item', 'Table');
         $current->load($row->id);
         $filename = md5("Image" . $current->id);
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg');
         }
         $row->image_caption = '';
         $row->image_credits = '';
     }
     //Attachments
     $attachments = JRequest::getVar('attachment_file', NULL, 'FILES', 'array');
     $attachments_names = JRequest::getVar('attachment_name', '', 'POST', 'array');
     $attachments_titles = JRequest::getVar('attachment_title', '', 'POST', 'array');
     $attachments_title_attributes = JRequest::getVar('attachment_title_attribute', '', 'POST', 'array');
     $attachmentFiles = array();
     if (count($attachments)) {
         foreach ($attachments as $k => $l) {
             foreach ($l as $i => $v) {
                 if (!array_key_exists($i, $attachmentFiles)) {
                     $attachmentFiles[$i] = array();
                 }
                 $attachmentFiles[$i][$k] = $v;
             }
         }
         $path = $params->get('attachmentsFolder', NULL);
         if (is_null($path)) {
             $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
         } else {
             $savepath = $path;
         }
         $counter = 0;
         foreach ($attachmentFiles as $file) {
             if ($file["tmp_name"]) {
                 $handle = new Upload($file);
                 if ($handle->uploaded) {
                     $handle->file_auto_rename = true;
                     $handle->allowed[] = 'application/x-zip';
                     $handle->Process($savepath);
                     $filename = $handle->file_dst_name;
                     $handle->Clean();
                     $attachment =& JTable::getInstance('K2Attachment', 'Table');
                     $attachment->itemID = $row->id;
                     $attachment->filename = $filename;
                     $attachment->title = empty($attachments_titles[$counter]) ? $filename : $attachments_titles[$counter];
                     $attachment->titleAttribute = empty($attachments_title_attributes[$counter]) ? $filename : $attachments_title_attributes[$counter];
                     $attachment->store();
                 } else {
                     $mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error');
                 }
             }
             $counter++;
         }
     }
     //Gallery
     if (isset($files['gallery']) && $files['gallery']['error'] == 0 && !JRequest::getBool('del_gallery')) {
         $handle = new Upload($files['gallery']);
         $handle->file_auto_rename = true;
         $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries';
         $handle->allowed = array("application/download", "application/rar", "application/x-rar-compressed", "application/arj", "application/gnutar", "application/x-bzip", "application/x-bzip2", "application/x-compressed", "application/x-gzip", "application/x-zip-compressed", "application/zip", "multipart/x-zip", "multipart/x-gzip", "application/x-unknown", "application/x-zip");
         if ($handle->uploaded) {
             $handle->Process($savepath);
             $handle->Clean();
             if (JFolder::exists($savepath . DS . $row->id)) {
                 JFolder::delete($savepath . DS . $row->id);
             }
             if (!JArchive::extract($savepath . DS . $handle->file_dst_name, $savepath . DS . $row->id)) {
                 $mainframe->redirect('index.php?option=com_k2&view=items', JText::_('Gallery upload error: Cannot extract archive!'), 'error');
             } else {
                 $row->gallery = '{gallery}' . $row->id . '{/gallery}';
             }
             JFile::delete($savepath . DS . $handle->file_dst_name);
             $handle->Clean();
         } else {
             $mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error');
         }
     }
     if (JRequest::getBool('del_gallery')) {
         $current =& JTable::getInstance('K2Item', 'Table');
         $current->load($row->id);
         if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id)) {
             JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id);
         }
         $row->gallery = '';
     }
     //Video
     if (!JRequest::getBool('del_video')) {
         if (isset($files['video']) && $files['video']['error'] == 0) {
             $validExtensions = array('flv', 'swf', 'wmv', 'mov', 'mp4', '3gp', 'avi', 'divx');
             $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos';
             $filetype = JFile::getExt($files['video']['name']);
             if (!in_array($filetype, $validExtensions)) {
                 $mainframe->redirect('index.php?option=com_k2&view=items', JText::_('Invalid video file'), 'error');
             }
             $filename = JFile::stripExt($files['video']['name']);
             JFile::upload($files['video']['tmp_name'], $savepath . DS . $row->id . '.' . $filetype);
             $filetype = JFile::getExt($files['video']['name']);
             $row->video = '{' . $filetype . '}' . $row->id . '{/' . $filetype . '}';
         } else {
             if (JRequest::getVar('remoteVideo')) {
                 $fileurl = JRequest::getVar('remoteVideo');
                 $filetype = JFile::getExt($fileurl);
                 $row->video = '{' . $filetype . 'remote}' . $fileurl . '{/' . $filetype . 'remote}';
             }
             if (JRequest::getVar('videoID')) {
                 $provider = JRequest::getWord('videoProvider');
                 $videoID = JRequest::getVar('videoID');
                 $row->video = '{' . $provider . '}' . $videoID . '{/' . $provider . '}';
             }
             if (JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW)) {
                 $row->video = JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW);
             }
         }
     } else {
         $current =& JTable::getInstance('K2Item', 'Table');
         $current->load($row->id);
         preg_match_all("#^{(.*?)}(.*?){#", $current->video, $matches, PREG_PATTERN_ORDER);
         $videotype = $matches[1][0];
         $videofile = $matches[2][0];
         if ($videotype == 'flv' || $videotype == 'swf' || $videotype == 'wmv' || $videotype == 'mov' || $videotype == 'mp4' || $videotype == '3gp' || $videotype == 'divx') {
             if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype)) {
                 JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype);
             }
         }
         $row->video = '';
         $row->video_caption = '';
         $row->video_credits = '';
     }
     //Extra fields
     $objects = array();
     $variables = JRequest::get('post', 4);
     foreach ($variables as $key => $value) {
         if ((bool) JString::stristr($key, 'K2ExtraField_')) {
             $object = new JObject();
             $object->set('id', JString::substr($key, 13));
             $object->set('value', $value);
             unset($object->_errors);
             $objects[] = $object;
         }
     }
     $csvFiles = JRequest::get('files');
     foreach ($csvFiles as $key => $file) {
         if ((bool) JString::stristr($key, 'K2ExtraField_')) {
             $object = new JObject();
             $object->set('id', JString::substr($key, 13));
             $csvFile = $file['tmp_name'][0];
             if (!empty($csvFile) && JFile::getExt($file['name'][0]) == 'csv') {
                 $handle = @fopen($csvFile, 'r');
                 $csvData = array();
                 while (($data = fgetcsv($handle, 1000)) !== FALSE) {
                     $csvData[] = $data;
                 }
                 fclose($handle);
                 $object->set('value', $csvData);
             } else {
                 require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php';
                 $json = new Services_JSON();
                 $object->set('value', $json->decode(JRequest::getVar('K2CSV_' . $object->id)));
                 if (JRequest::getBool('K2ResetCSV_' . $object->id)) {
                     $object->set('value', null);
                 }
             }
             unset($object->_errors);
             $objects[] = $object;
         }
     }
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php';
     $json = new Services_JSON();
     $row->extra_fields = $json->encode($objects);
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php';
     $extraFieldModel = new K2ModelExtraField();
     $row->extra_fields_search = '';
     foreach ($objects as $object) {
         $row->extra_fields_search .= $extraFieldModel->getSearchValue($object->id, $object->value);
         $row->extra_fields_search .= ' ';
     }
     //Tags
     if ($user->gid < 24 && $params->get('lockTags')) {
         $params->set('taggingSystem', 0);
     }
     $db =& JFactory::getDBO();
     $query = "DELETE FROM #__k2_tags_xref WHERE itemID={intval({$row->id})}";
     $db->setQuery($query);
     $db->query();
     if ($params->get('taggingSystem')) {
         if ($user->gid < 24 && $params->get('lockTags')) {
             JError::raiseError(403, JText::_("ALERTNOTAUTH"));
         }
         $tags = JRequest::getVar('tags', NULL, 'POST', 'array');
         if (count($tags)) {
             $tags = array_unique($tags);
             foreach ($tags as $tag) {
                 $tag = str_replace('-', '', $tag);
                 $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($tag);
                 $db->setQuery($query);
                 $tagID = $db->loadResult();
                 if ($tagID) {
                     $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})";
                     $db->setQuery($query);
                     $db->query();
                 } else {
                     $K2Tag =& JTable::getInstance('K2Tag', 'Table');
                     $K2Tag->name = $tag;
                     $K2Tag->published = 1;
                     $K2Tag->check();
                     $K2Tag->store();
                     $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$K2Tag->id})}, {intval({$row->id})})";
                     $db->setQuery($query);
                     $db->query();
                 }
             }
         }
     } else {
         $tags = JRequest::getVar('selectedTags', NULL, 'POST', 'array');
         if (count($tags)) {
             foreach ($tags as $tagID) {
                 $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})";
                 $db->setQuery($query);
                 $db->query();
             }
         }
     }
     if ($front) {
         if (!K2HelperPermissions::canPublishItem($row->catid) && $row->published == 1) {
             $row->published = 0;
             $mainframe->enqueueMessage(JText::_("You don't have the permission to publish items."), 'notice');
         }
     }
     if (!$row->store()) {
         $mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error');
     }
     $row->checkin();
     $cache =& JFactory::getCache('com_k2');
     $cache->clean();
     $dispatcher->trigger('onAfterK2Save', array(&$row, $isNew));
     switch (JRequest::getCmd('task')) {
         case 'apply':
             $msg = JText::_('Changes to Item saved');
             $link = 'index.php?option=com_k2&view=item&cid=' . $row->id;
             break;
         case 'saveAndNew':
             $msg = JText::_('Item saved');
             $link = 'index.php?option=com_k2&view=item';
             break;
         case 'save':
         default:
             $msg = JText::_('Item Saved');
             if ($front) {
                 $link = 'index.php?option=com_k2&view=item&task=edit&cid=' . $row->id . '&tmpl=component';
             } else {
                 $link = 'index.php?option=com_k2&view=items';
             }
             break;
     }
     $mainframe->redirect($link, $msg);
 }
Esempio n. 5
0
    function edit()
    {
        $mainframe =& JFactory::getApplication();
        jimport('joomla.filesystem.file');
        jimport('joomla.html.pane');
        $db =& JFactory::getDBO();
        JHTML::_('behavior.mootools');
        $document =& JFactory::getDocument();
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/Autocompleter.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/observer.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/simpletabs_1.3.js');
        //$document->addScript(JURI::root().'administrator/components/com_k2/js/k2.js'); // Core JS
        $document->addScript(JURI::root() . 'administrator/components/com_k2/js/k2.mootools.js');
        // Mootools based JS
        $document->addCustomTag('
        
<!-- K2 by JoomlaWorks (start) -->
		
	<!-- Load Khepri styling -->
	<link rel="stylesheet" href="' . JURI::root() . 'administrator/templates/system/css/system.css" type="text/css" />
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/template.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="' . JURI::root() . 'administrator/templates/khepri/css/rounded.css" />
	
	<!-- Load K2 styling -->
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
		
<!-- K2 by JoomlaWorks (end) -->

		');
        JRequest::setVar('tmpl', 'component');
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.php';
        $model = new K2ModelItem();
        $task = JRequest::getCmd('task');
        $user =& JFactory::getUser();
        if ($task == 'edit') {
            $item = $model->getData();
            JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'video');
            if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            if (JTable::isCheckedOut($user->get('id'), $item->checked_out)) {
                $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $item->title);
                $mainframe->redirect('index.php?option=com_k2&view=item&id=' . $item->id . '&tmpl=component', $msg);
            }
        } elseif ($task == 'add') {
            if (!K2HelperPermissions::canAddItem()) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
            $item =& JTable::getInstance('K2Item', 'Table');
            $createdate =& JFactory::getDate();
            $item->published = 1;
            $item->publish_up = $createdate->toUnix();
            $item->publish_down = JText::_('Never');
            $item->created = $createdate->toUnix();
            $item->modified = $db->getNullDate();
        }
        if ($item->id) {
            $item->checkout($user->get('id'));
        }
        $item->created = JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S');
        $item->publish_up = JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S');
        if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate()) {
            $item->publish_down = JText::_('Never');
        } else {
            $item->publish_down = JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S');
        }
        $params =& JComponentHelper::getParams('com_k2');
        $wysiwyg =& JFactory::getEditor();
        if ($params->get("mergeEditors")) {
            if (JString::strlen($item->fulltext) > 1) {
                $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
            } else {
                $textValue = $item->introtext;
            }
            $text = $wysiwyg->display('text', $textValue, '100%', '400', '40', '5', array('pagebreak'));
            $this->assignRef('text', $text);
        } else {
            $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('introtext', $introtext);
            $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('fulltext', $fulltext);
        }
        $lists = array();
        $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
        $lists['access'] = JHTML::_('list.accesslevel', $item);
        $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
        $lists['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories = $categoriesModel->categoriesTree();
        $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
        $lists['checkSIG'] = $model->checkSIG();
        $lists['checkAllVideos'] = $model->checkAllVideos();
        $remoteVideo = false;
        $providerVideo = false;
        $embedVideo = false;
        $options['startOffset'] = 0;
        if (stristr($item->video, 'remote}') !== false) {
            $remoteVideo = true;
            $options['startOffset'] = 1;
        }
        $providers = $model->getVideoProviders();
        if (count($providers)) {
            foreach ($providers as $provider) {
                $providersOptions[] = JHTML::_('select.option', $provider, $provider);
                if (stristr($item->video, "{{$provider}}") !== false) {
                    $providerVideo = true;
                    $options['startOffset'] = 2;
                }
            }
        }
        if (JString::substr($item->video, 0, 1) !== '{') {
            $embedVideo = true;
            $options['startOffset'] = 3;
        }
        $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
        if ($lists['uploadedVideo']) {
            $options['startOffset'] = 0;
        }
        $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['embedVideo'] = $embedVideo ? $item->video : '';
        if (count($providers)) {
            $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
        }
        JPluginHelper::importPlugin('content', 'jw_sigpro');
        JPluginHelper::importPlugin('content', 'jw_sig');
        JPluginHelper::importPlugin('content', 'jw_allvideos');
        $dispatcher =& JDispatcher::getInstance();
        $params->set('galleries_rootfolder', 'media/k2/galleries');
        $params->set('thb_width', '150');
        $params->set('thb_height', '120');
        $params->set('popup_engine', 'mootools_slimbox');
        $params->set('enabledownload', '0');
        $item->text = $item->gallery;
        $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
        $item->gallery = $item->text;
        if (!$embedVideo) {
            $params->set('vfolder', 'media/k2/videos');
            $item->text = $item->video;
            $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
            $item->video = $item->text;
        } else {
            $item->video = '<div>' . $item->video . '</div>';
        }
        if (isset($item->created_by)) {
            $author =& JUser::getInstance($item->created_by);
            $item->author = $author->name;
        }
        if (isset($item->modified_by)) {
            $moderator =& JUser::getInstance($item->modified_by);
            $item->moderator = $moderator->name;
        }
        if ($task == 'edit') {
            $item->editor = $item->author;
        } else {
            $item->editor = $user->name;
        }
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories_option[] = JHTML::_('select.option', 0, JText::_('- Select category -'));
        $categories = $categoriesModel->categoriesTree();
        if (($task == 'add' || $task == 'edit') && !$user->authorize('com_k2', 'add', 'category', 'all')) {
            for ($i = 0; $i < sizeof($categories); $i++) {
                if (!$user->authorize('com_k2', 'add', 'category', $categories[$i]->value)) {
                    $categories[$i]->disable = true;
                }
            }
        }
        $categories_options = @array_merge($categories_option, $categories);
        $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
        JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
        $category =& JTable::getInstance('K2Category', 'Table');
        $category->load($item->catid);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php';
        $extraFieldModel = new K2ModelExtraField();
        if ($category->extraFieldsGroup) {
            $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
        } else {
            $extraFields = NULL;
        }
        for ($i = 0; $i < sizeof($extraFields); $i++) {
            $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
        }
        if ($item->id) {
            $item->attachments = $model->getAttachments($item->id);
        } else {
            $item->attachments = NULL;
        }
        $tags = $model->getAvailableTags($item->id);
        $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
        if (isset($item->id)) {
            $item->tags = $model->getCurrentTags($item->id);
            $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
        } else {
            $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
        }
        if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
            $item->image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
        }
        if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
            $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
        }
        $lists['metadata'] = new JParameter($item->metadata);
        JPluginHelper::importPlugin('k2');
        $dispatcher =& JDispatcher::getInstance();
        $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
        $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
        $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
        $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
        $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
        $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
        $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
        $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
        $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
        $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
        $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
        $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
        $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
        $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
        $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
        $form->loadINI($item->params);
        $this->assignRef('form', $form);
        $this->assignRef('extraFields', $extraFields);
        $this->assignRef('options', $options);
        $this->assignRef('row', $item);
        $this->assignRef('lists', $lists);
        $this->assignRef('params', $params);
        parent::display();
    }
Esempio n. 6
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     $db =& JFactory::getDBO();
     jimport('joomla.filesystem.file');
     jimport('joomla.html.pane');
     JHTML::_('behavior.keepalive');
     JRequest::setVar('hidemainmenu', 1);
     $document =& JFactory::getDocument();
     $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/Autocompleter.js');
     $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/observer.js');
     $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/nicEdit.js');
     $js = "function initExtraFieldsEditor(){\n\t\t\t\$\$('.k2ExtraFieldEditor').each(function(element) {\n\t\t\t\tvar id = element.id;\n\t\t\t\tif (typeof JContentEditor != 'undefined') {\n\t\t\t\t\tif (tinyMCE.get(id)) {\n\t\t\t\t\t\ttinymce.EditorManager.remove(tinyMCE.get(id));\n\t\t\t\t\t}\n\t\t\t\t\ttinyMCE.execCommand('mceAddControl', false, id);\n\t\t\t\t} else {\n\t\t\t\t\tnew nicEditor({fullPanel: true, maxHeight: 180, iconsPath: '" . JURI::root() . "administrator/components/com_k2/images/system/nicEditorIcons.gif'}).panelInstance(element.getProperty('id'));\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tfunction syncExtraFieldsEditor(){\n\t\t\t\$\$('.k2ExtraFieldEditor').each(function(element){\n\t\t\t\teditor = nicEditors.findEditor(element.getProperty('id'));\n\t\t\t\tif(typeof editor != 'undefined'){\n\t\t\t\t\teditor.saveContent();\n\t\t\t\t}\n    \t\t});\n\t\t}\n\t\t";
     $document->addScriptDeclaration($js);
     $model =& $this->getModel();
     $item = $model->getData();
     JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'video');
     $user =& JFactory::getUser();
     if (JTable::isCheckedOut($user->get('id'), $item->checked_out)) {
         $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $item->title);
         $mainframe->redirect('index.php?option=com_k2', $msg);
     }
     if ($item->id) {
         $item->checkout($user->get('id'));
     } else {
         $createdate =& JFactory::getDate();
         $item->published = 1;
         $item->publish_up = $createdate->toUnix();
         $item->publish_down = JText::_('Never');
         $item->created = $createdate->toUnix();
         $item->modified = $db->getNullDate();
     }
     $item->created = JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S');
     $item->publish_up = JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S');
     if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate()) {
         $item->publish_down = JText::_('Never');
     } else {
         $item->publish_down = JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S');
     }
     $params =& JComponentHelper::getParams('com_k2');
     $wysiwyg =& JFactory::getEditor();
     if ($params->get("mergeEditors")) {
         if (JString::strlen($item->fulltext) > 1) {
             $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
         } else {
             $textValue = $item->introtext;
         }
         $text = $wysiwyg->display('text', $textValue, '100%', '400', '40', '5');
         $this->assignRef('text', $text);
     } else {
         $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400', '40', '5', array('readmore'));
         $this->assignRef('introtext', $introtext);
         $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400', '40', '5', array('readmore'));
         $this->assignRef('fulltext', $fulltext);
     }
     $lists = array();
     $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
     $lists['access'] = JHTML::_('list.accesslevel', $item);
     $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
     $lists['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query);
     if (!$item->id) {
         $item->catid = $mainframe->getUserStateFromRequest('com_k2itemsfilter_category', 'catid', 0, 'int');
     }
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'categories.php';
     $categoriesModel = new K2ModelCategories();
     $categories = $categoriesModel->categoriesTree();
     $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
     $lists['checkSIG'] = $model->checkSIG();
     $lists['checkAllVideos'] = $model->checkAllVideos();
     $remoteVideo = false;
     $providerVideo = false;
     $embedVideo = false;
     if (stristr($item->video, 'remote}') !== false) {
         $remoteVideo = true;
         $options['startOffset'] = 1;
     }
     $providers = $model->getVideoProviders();
     if (count($providers)) {
         foreach ($providers as $provider) {
             $providersOptions[] = JHTML::_('select.option', $provider, $provider);
             if (stristr($item->video, "{{$provider}}") !== false) {
                 $providerVideo = true;
                 $options['startOffset'] = 2;
             }
         }
     }
     if (JString::substr($item->video, 0, 1) !== '{') {
         $embedVideo = true;
         $options['startOffset'] = 3;
     }
     $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
     if ($lists['uploadedVideo'] || $item->video == '') {
         $options['startOffset'] = 0;
     }
     $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['embedVideo'] = $embedVideo ? $item->video : '';
     if (isset($providersOptions)) {
         $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
     }
     JPluginHelper::importPlugin('content', 'jw_sigpro');
     JPluginHelper::importPlugin('content', 'jw_allvideos');
     $dispatcher =& JDispatcher::getInstance();
     $params->set('galleries_rootfolder', 'media/k2/galleries');
     $params->set('thb_width', '150');
     $params->set('thb_height', '120');
     $params->set('popup_engine', 'mootools_slimbox');
     $params->set('enabledownload', '0');
     $item->text = $item->gallery;
     $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
     $item->gallery = $item->text;
     if (!$embedVideo) {
         $params->set('vfolder', 'media/k2/videos');
         if (JString::strpos($item->video, 'remote}')) {
             preg_match("#}(.*?){/#s", $item->video, $matches);
             if (JString::substr($matches[1], 0, 7) != 'http://') {
                 $item->video = JString::str_ireplace($matches[1], JURI::root() . $matches[1], $item->video);
             }
         }
         $item->text = $item->video;
         $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
         $item->video = $item->text;
     } else {
         // no nothing
     }
     if (isset($item->created_by)) {
         $author =& JUser::getInstance($item->created_by);
         $item->author = $author->name;
     }
     if (isset($item->modified_by)) {
         $moderator =& JUser::getInstance($item->modified_by);
         $item->moderator = $moderator->name;
     }
     if ($item->id) {
         $active = $item->created_by;
     } else {
         $active = $user->id;
     }
     $lists['authors'] = JHTML::_('list.users', 'created_by', $active, false);
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'categories.php';
     $categoriesModel = new K2ModelCategories();
     $categories_option[] = JHTML::_('select.option', 0, JText::_('- Select category -'));
     $categories = $categoriesModel->categoriesTree(NUll, true, false);
     $categories_options = @array_merge($categories_option, $categories);
     $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
     JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
     $category =& JTable::getInstance('K2Category', 'Table');
     $category->load($item->catid);
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'extrafield.php';
     $extraFieldModel = new K2ModelExtraField();
     if ($item->id) {
         $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
     } else {
         $extraFields = NULL;
     }
     for ($i = 0; $i < sizeof($extraFields); $i++) {
         $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
     }
     if ($item->id) {
         $item->attachments = $model->getAttachments($item->id);
         $rating = $model->getRating();
         if (is_null($rating)) {
             $item->ratingSum = 0;
             $item->ratingCount = 0;
         } else {
             $item->ratingSum = (int) $rating->rating_sum;
             $item->ratingCount = (int) $rating->rating_count;
         }
     } else {
         $item->attachments = NULL;
         $item->ratingSum = 0;
         $item->ratingCount = 0;
     }
     if ($user->gid < 24 && $params->get('lockTags')) {
         $params->set('taggingSystem', 0);
     }
     $tags = $model->getAvailableTags($item->id);
     $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
     if (isset($item->id)) {
         $item->tags = $model->getCurrentTags($item->id);
         $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
     } else {
         $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
     }
     $lists['metadata'] = new JParameter($item->metadata);
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
         $item->image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
         $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
     }
     JPluginHelper::importPlugin('k2');
     $dispatcher =& JDispatcher::getInstance();
     $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
     $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
     $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
     $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
     $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
     $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
     $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
     $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
     $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
     $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
     $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
     $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
     $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
     $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item.xml');
     $form->loadINI($item->params);
     $this->assignRef('form', $form);
     $this->assignRef('extraFields', $extraFields);
     $this->assignRef('options', $options);
     $this->assignRef('row', $item);
     $this->assignRef('lists', $lists);
     $this->assignRef('params', $params);
     $this->assignRef('user', $user);
     JRequest::getInt('cid') ? $title = JText::_('Edit Item') : ($title = JText::_('Add Item'));
     JToolBarHelper::title($title, 'k2.png');
     JToolBarHelper::save();
     JToolBarHelper::custom('saveAndNew', 'save.png', 'save_f2.png', 'Save &amp; New', false);
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     parent::display($tpl);
 }