function report() { $model = K2Model::getInstance('User', 'K2Model'); $model->setState('id', JRequest::getInt('id')); $model->reportSpammer(); $this->setRedirect('index.php?option=com_k2&view=users'); }
protected function getInput() { $document = JFactory::getDocument(); $document->addScriptDeclaration('var K2BasePath = "' . JURI::root(true) . '";'); $document->addScript(JURI::root(true) . '/plugins/josetta_ext/k2item/fields/k2extrafields.js'); K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models'); JLoader::register('K2HelperUtilities', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'utilities.php'); $model = K2Model::getInstance('Item', 'K2Model'); $extraFields = $model->getItemExtraFields($this->value); $html = '<div id="extraFieldsContainer">'; if (count($extraFields)) { $html .= '<table class="admintable" id="extraFields">'; foreach ($extraFields as $extraField) { $html .= '<tr> <td align="right" class="key">' . $extraField->name . '</td> <td>' . $extraField->element . '</td> </tr>'; } $html .= '</table>'; } else { $html .= '<span class="k2Note"> ' . JText::_('K2_PLEASE_SELECT_A_CATEGORY_FIRST_TO_RETRIEVE_ITS_RELATED_EXTRA_FIELDS') . ' </span>'; } $html .= '</div>'; return $html; }
public function onJosettaLoadItem($context, $id = '') { if (!empty($context) && $context != $this->_context || empty($id)) { return null; } $item = parent::onJosettaLoadItem($context, $id); // Merge introtext and fulltext $item->articletext = trim($item->fulltext) != '' ? $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext : $item->introtext; // Get tags K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models'); JLoader::register('K2HelperUtilities', JPATH_SITE . '/components/com_k2/helpers/utilities.php'); $model = K2Model::getInstance('Item', 'K2Model'); $tags = $model->getItemTags($item->id); $tmp = array(); foreach ($tags as $tag) { $tmp[] = $tag->name; } $item->tags = implode(', ', $tmp); // Get extra fields $extraFields = $model->getItemExtraFields($item->extra_fields); $html = ''; if (count($extraFields)) { $html .= '<ul>'; foreach ($extraFields as $key => $extraField) { $html .= '<li class="type' . ucfirst($extraField->type) . ' group' . $extraField->group . '"> <span class="itemExtraFieldsLabel">' . $extraField->name . ':</span> <span class="itemExtraFieldsValue">' . $extraField->value . '</span> </li>'; } $html .= '</ul>'; } $item->extra_fields = $html; // Return the item return $item; }
public static function getAvatar($userID, $email = NULL, $width = 50) { jimport('joomla.filesystem.folder'); jimport('joomla.application.component.model'); $mainframe = JFactory::getApplication(); $params = K2HelperUtilities::getParams('com_k2'); if (K2_CB && $userID != 'alias') { $cbUser = CBuser::getInstance((int) $userID); if (is_object($cbUser)) { $avatar = $cbUser->getField('avatar', null, 'csv', 'none', 'profile'); return $avatar; } } /* // JomSocial Avatar integration if(JFolder::exists(JPATH_SITE.DS.'components'.DS.'com_community') && $userID>0){ $userInfo = &CFactory::getUser($userID); return $userInfo->getThumbAvatar(); } */ // Check for placeholder overrides if (JFile::exists(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'images' . DS . 'placeholder' . DS . 'user.png')) { $avatarPath = 'templates/' . $mainframe->getTemplate() . '/images/placeholder/user.png'; } else { $avatarPath = 'components/com_k2/images/placeholder/user.png'; } // Continue with default K2 avatar determination if ($userID == 'alias') { $avatar = JURI::root(true) . '/' . $avatarPath; } else { if ($userID == 0) { if ($params->get('gravatar') && !is_null($email)) { $avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&default=' . urlencode(JURI::root() . $avatarPath); } else { $avatar = JURI::root(true) . '/' . $avatarPath; } } else { if (is_numeric($userID) && $userID > 0) { K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models'); $model = K2Model::getInstance('Item', 'K2Model'); $profile = $model->getUserProfile($userID); $avatar = is_null($profile) ? '' : $profile->image; if (empty($avatar)) { if ($params->get('gravatar') && !is_null($email)) { $avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&default=' . urlencode(JURI::root() . $avatarPath); } else { $avatar = JURI::root(true) . '/' . $avatarPath; } } else { $avatar = JURI::root(true) . '/media/k2/users/' . $avatar; } } } } if (!$params->get('userImageDefault') && $avatar == JURI::root(true) . '/' . $avatarPath) { $avatar = ''; } return $avatar; }
function display($tpl = null) { JRequest::setVar('hidemainmenu', 1); $model = $this->getModel(); $extraField = $model->getData(); if (!$extraField->id) { $extraField->published = 1; } $this->assignRef('row', $extraField); $lists = array(); $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $extraField->published); $groups[] = JHTML::_('select.option', 0, JText::_('K2_CREATE_NEW_GROUP')); $extraFieldModel = K2Model::getInstance('ExtraFields', 'K2Model'); $uniqueGroups = $extraFieldModel->getGroups(true); foreach ($uniqueGroups as $group) { $groups[] = JHTML::_('select.option', $group->id, $group->name); } $lists['group'] = JHTML::_('select.genericlist', $groups, 'groups', '', 'value', 'text', $extraField->group); $typeOptions[] = JHTML::_('select.option', 0, JText::_('K2_SELECT_TYPE')); $typeOptions[] = JHTML::_('select.option', 'textfield', JText::_('K2_TEXT_FIELD')); $typeOptions[] = JHTML::_('select.option', 'textarea', JText::_('K2_TEXTAREA')); $typeOptions[] = JHTML::_('select.option', 'select', JText::_('K2_DROPDOWN_SELECTION')); $typeOptions[] = JHTML::_('select.option', 'multipleSelect', JText::_('K2_MULTISELECT_LIST')); $typeOptions[] = JHTML::_('select.option', 'radio', JText::_('K2_RADIO_BUTTONS')); $typeOptions[] = JHTML::_('select.option', 'link', JText::_('K2_LINK')); $typeOptions[] = JHTML::_('select.option', 'csv', JText::_('K2_CSV_DATA')); $typeOptions[] = JHTML::_('select.option', 'labels', JText::_('K2_SEARCHABLE_LABELS')); $typeOptions[] = JHTML::_('select.option', 'date', JText::_('K2_DATE')); $lists['type'] = JHTML::_('select.genericlist', $typeOptions, 'type', '', 'value', 'text', $extraField->type); $this->assignRef('lists', $lists); JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_EXTRA_FIELD') : ($title = JText::_('K2_ADD_EXTRA_FIELD')); JToolBarHelper::title($title, 'k2.png'); JToolBarHelper::save(); JToolBarHelper::apply(); JToolBarHelper::cancel(); JHTML::_('behavior.calendar'); $document = JFactory::getDocument(); $document->addScriptDeclaration(' var K2Language = [ "' . JText::_('K2_REMOVE', true) . '", "' . JText::_('K2_OPTIONAL', true) . '", "' . JText::_('K2_COMMA_SEPARATED_VALUES', true) . '", "' . JText::_('K2_USE_EDITOR', true) . '", "' . JText::_('K2_ALL_SETTINGS_ABOVE_ARE_OPTIONAL', true) . '", "' . JText::_('K2_ADD_AN_OPTION', true) . '", "' . JText::_('K2_LINK_TEXT', true) . '", "' . JText::_('K2_URL', true) . '", "' . JText::_('K2_OPEN_IN', true) . '", "' . JText::_('K2_SAME_WINDOW', true) . '", "' . JText::_('K2_NEW_WINDOW', true) . '", "' . JText::_('K2_CLASSIC_JAVASCRIPT_POPUP', true) . '", "' . JText::_('K2_LIGHTBOX_POPUP', true) . '", "' . JText::_('K2_RESET_VALUE', true) . '", "' . JText::_('K2_CALENDAR', true) . '", "' . JText::_('K2_PLEASE_SELECT_A_FIELD_TYPE_FROM_THE_LIST_ABOVE', true) . '", ];'); parent::display($tpl); }
/** * Gets an item instance. * * @param integer $id The id of the item to get. * * @return K2Tag The tag object. */ public static function getInstance($id) { if (empty(self::$instances[$id])) { K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models'); $model = K2Model::getInstance('Comments', 'K2Model'); $model->setState('id', $id); $item = $model->getRow(); self::$instances[$id] = $item; } return self::$instances[$id]; }
protected function getOptions() { require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/categories.php'; $categoriesModel = K2Model::getInstance('Categories', 'K2Model'); $categories = $categoriesModel->categoriesTree(NULL, true, false); $options = array(); $options[] = JHtml::_('select.option', 0, 'All'); foreach ($categories as $ca) { $options[] = JHtml::_('select.option', $ca->value, $ca->text); } return $options; }
public function getFields() { $fields = array(); if ($this->id) { K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models'); $model = K2Model::getInstance('ExtraFields', 'K2Model'); $model->setState('group', $this->id); $model->setState('sorting', 'ordering'); $fields = $model->getRows(); } return $fields; }
public static function getList(&$params) { $mainframe = JFactory::getApplication(); if ($params->get('catfilter')) { $cid = $params->get('category_id', NULL); } else { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $cid = $itemListModel->getCategoryTree($category = 0); } $items = self::getItems($cid, $params); return $items; }
public static function _findItem($catid) { $component = JComponentHelper::getComponent('com_jak2filter'); $application = JFactory::getApplication(); $menus = $application->getMenu('site', array()); if (K2_JVERSION != '15') { $items = $menus->getItems('component_id', $component->id); } else { $items = $menus->getItems('componentid', $component->id); } $match = null; if (count($items)) { foreach ($items as $item) { if ($catid) { if (@$item->query['view'] == 'itemlist' && @$item->query['category_id'] == $catid) { $match = $item; break; } } else { if (@$item->query['view'] == 'itemlist' && !isset($item->query['category_id'])) { $match = $item; break; } } } } if (is_null($match)) { // Try to detect any parent category menu item.... if (is_null(self::$tree)) { include_once JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php'; K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models'); $model = K2Model::getInstance('Itemlist', 'K2Model'); self::$model = $model; self::$tree = $model->getCategoriesTree(); } $parents = self::$model->getTreePath(self::$tree, $catid); if (is_array($parents)) { foreach ($parents as $categoryID) { if ($categoryID != $catid) { $match = JAK2FilterHelperRoute::_findItem($categoryID); if (!is_null($match)) { break; } } } } if (is_null($match) && !is_null(self::$anyK2Link)) { $match = self::$anyK2Link; } } return $match; }
public function display($cachable = false, $urlparams = array()) { $model = $this->getModel('itemlist'); $document = JFactory::getDocument(); $viewType = $document->getType(); $view = $this->getView('item', $viewType); $view->setModel($model); JRequest::setVar('view', 'item'); $user = JFactory::getUser(); if ($user->guest) { $cache = true; } else { $cache = true; JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'); $row = JTable::getInstance('K2Item', 'Table'); $row->load(JRequest::getInt('id')); if (K2HelperPermissions::canEditItem($row->created_by, $row->catid)) { $cache = false; } $params = K2HelperUtilities::getParams('com_k2'); if ($row->created_by == $user->id && $params->get('inlineCommentsModeration')) { $cache = false; } if ($row->access > 0) { $cache = false; } $category = JTable::getInstance('K2Category', 'Table'); $category->load($row->catid); if ($category->access > 0) { $cache = false; } if ($params->get('comments') && $document->getType() == 'html') { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $profile = $itemListModel->getUserProfile($user->id); $script = "\n\$K2(document).ready(function() {\n\$K2('#userName').val('" . $view->escape($user->name) . "').attr('disabled', 'disabled');\n\$K2('#commentEmail').val('" . $user->email . "').attr('disabled', 'disabled');"; if (is_object($profile) && $profile->url) { $script .= " \$K2('#commentURL').val('" . htmlspecialchars($profile->url, ENT_QUOTES, 'UTF-8') . "').attr('disabled', 'disabled');"; } $script .= " });"; $document->addScriptDeclaration($script); } } if (K2_JVERSION != '15') { $urlparams['id'] = 'INT'; $urlparams['print'] = 'INT'; $urlparams['lang'] = 'CMD'; $urlparams['Itemid'] = 'INT'; } parent::display($cache, $urlparams); }
public static function getGroups($scope = 'item') { if (!isset(self::$groups[$scope])) { K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models'); $model = K2Model::getInstance('ExtraFieldsGroups', 'K2Model'); $model->setState('scope', $scope); $model->setState('sorting', 'name'); $rows = $model->getRows(); self::$groups[$scope] = array(); foreach ($rows as $row) { self::$groups[$scope][$row->id] = $row; } } return self::$groups[$scope]; }
public function deleteOrphans() { // Check for token JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN')); // Check permissions $user = JFactory::getUser(); if (!$user->authorise('k2.tags.manage', 'com_k2')) { K2Response::throwError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION')); } // Get model $model = K2Model::getInstance('Tags'); $model->deleteOrphans(); $application = JFactory::getApplication(); $application->enqueueMessage(JText::_('K2_DELETE_COMPLETED')); echo json_encode(K2Response::render()); return $this; }
function display($tpl = null) { JHTML::_('behavior.tooltip'); JRequest::setVar('hidemainmenu', 1); $model = $this->getModel(); $userGroup = $model->getData(); if (K2_JVERSION == '15') { JFilterOutput::objectHTMLSafe($userGroup); } else { JFilterOutput::objectHTMLSafe($userGroup, ENT_QUOTES, 'permissions'); } $this->assignRef('row', $userGroup); if (K2_JVERSION == '15') { $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'usergroup.xml'); $form->loadINI($userGroup->permissions); $appliedCategories = $form->get('categories'); $inheritance = $form->get('inheritance'); } else { jimport('joomla.form.form'); $form = JForm::getInstance('permissions', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'usergroup.xml'); $values = array('params' => json_decode($userGroup->permissions)); $form->bind($values); $inheritance = isset($values['params']->inheritance) ? $values['params']->inheritance : 0; $appliedCategories = isset($values['params']->categories) ? $values['params']->categories : ''; } $this->assignRef('form', $form); $this->assignRef('categories', $appliedCategories); $lists = array(); require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/categories.php'; $categoriesModel = K2Model::getInstance('Categories', 'K2Model'); $categories = $categoriesModel->categoriesTree(NULL, true); $categories_options = @array_merge($categories_option, $categories); $lists['categories'] = JHTML::_('select.genericlist', $categories, 'params[categories][]', 'multiple="multiple" size="15"', 'value', 'text', $appliedCategories); $lists['inheritance'] = JHTML::_('select.booleanlist', 'params[inheritance]', NULL, $inheritance); $this->assignRef('lists', $lists); JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_USER_GROUP') : ($title = JText::_('K2_ADD_USER_GROUP')); JToolBarHelper::title($title, 'k2.png'); JToolBarHelper::save(); JToolBarHelper::apply(); JToolBarHelper::cancel(); parent::display($tpl); }
public function report() { // Check for token JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN')); // Get application $application = JFactory::getApplication(); // Get input $id = $application->input->get('id', 0, 'int'); // Get model $model = K2Model::getInstance('Users'); $model->setState('id', $id); $model->report(); if (!$model->report()) { K2Response::throwError($model->getError()); } // Response echo json_encode(K2Response::render()); // Return return $this; }
public static function getTopCommenters($params) { $model = K2Model::getInstance('Users'); $rows = $model->getTopCommenters(); $commenters = array(); foreach ($rows as $row) { if ($row->comments > 0) { $commenter = K2Users::getInstance($row->userId); $commenter->comments = $row->comments; $commenter->displayName = $params->get('commenterNameOrUsername', 1) == 2 ? $commenter->username : $commenter->name; if ($params->get('commenterLatestComment')) { $model = K2Model::getInstance('Comments'); $model->setState('userId', $commenter->id); $model->setState('state', 1); $model->setState('limit', 1); $model->setState('sorting', 'id.reverse'); $comments = $model->getRows(); $commenter->comment = $comments[0]; } $commenters[] = $commenter; } } return $commenters; }
private function items($id) { $this->response->status = 'Processing Items'; $step = 10; $session = JFactory::getSession(); $db = JFactory::getDbo(); if ($id == 0) { $query = $db->getQuery(true); $query->select('COUNT(*)')->from($db->quoteName('#__k2_v2_items')); $db->setQuery($query); $total = $db->loadResult(); $session->set('k2.upgrade.items.total', $total); $session->set('k2.upgrade.items.processed', 0); } $query = $db->getQuery(true); $query->select('*')->from($db->quoteName('#__k2_v2_items'))->where($db->quoteName('id') . ' > ' . $id)->order($db->quoteName('id')); $db->setQuery($query, 0, $step); $items = $db->loadObjectList(); foreach ($items as $item) { $query = $db->getQuery(true); $query->select($db->quoteName('id'))->from($db->quoteName('#__k2_items'))->where($db->quoteName('alias') . ' = ' . $db->quote($item->alias)); $db->setQuery($query); if ($db->loadResult()) { $item->alias .= '-' . uniqid(); } $data = array(); $data['id'] = ''; $data['title'] = $item->title; $data['alias'] = $item->alias; $data['state'] = $item->trash ? -1 : $item->published; $data['featured'] = $item->featured; $data['access'] = $item->access; $data['catid'] = $item->catid; if ($data['catid'] == 1) { $data['catid'] = 99999; } $data['introtext'] = $item->introtext; $data['fulltext'] = $item->fulltext; $data['ordering'] = $item->ordering; $data['featured_ordering'] = $item->featured_ordering; $data['created'] = $item->created; $data['created_by'] = $item->created_by; $data['created_by_alias'] = $item->created_by_alias; $data['modified'] = $item->modified; $data['modified_by'] = $item->modified_by ? $item->modified_by : $item->created_by; $data['publish_up'] = $item->publish_up; $data['publish_down'] = $item->publish_down; $data['metadata'] = array(); $data['metadata']['description'] = $item->metadesc; $data['metadata']['keywords'] = $item->metakey; $data['metadata']['robots'] = ''; $data['metadata']['author'] = ''; $metadata = new JRegistry($item->metadata); $metadata = $metadata->toArray(); foreach ($metadata as $key => $value) { if ($key == 'robots' || $key == 'author') { $data['metadata'][$key] = $value; } } $data['language'] = $item->language; $model = K2Model::getInstance('Items'); $model->setState('data', $data); if (!$model->save()) { $this->response->errors[] = $model->getError(); $this->response->failed = 1; return; } $lastInsertedId = $model->getState('id'); $image = new stdClass(); $image->caption = $item->image_caption; $image->credits = $item->image_credits; $image->flag = JFile::exists(JPATH_SITE . '/media/k2/items/cache/' . md5('Image' . $item->id) . '_Generic.jpg') ? 1 : 0; $image = json_encode($image); $media = array(); $mediaEntry = new stdClass(); $mediaEntry->url = ''; $mediaEntry->provider = ''; $mediaEntry->id = ''; $mediaEntry->embed = ''; $mediaEntry->caption = $item->video_caption; $mediaEntry->credits = $item->video_credits; $mediaEntry->upload = ''; if (!empty($item->video)) { if (substr($item->video, 0, 1) !== '{') { $mediaEntry->embed = $item->video; } else { if (strpos($item->video, 'remote}')) { preg_match("#}(.*?){/#s", $item->video, $matches); if (substr($matches[1], 0, 4) != 'http') { $mediaEntry->upload = basename($matches[1]); if (JFile::exists(JPATH_SITE . '/media/k2/videos/' . $mediaEntry->upload)) { if (!JFolder::exists(JPATH_SITE . '/media/k2/media')) { JFolder::create(JPATH_SITE . '/media/k2/media'); } if (!JFolder::exists(JPATH_SITE . '/media/k2/media/' . $item->id)) { JFolder::create(JPATH_SITE . '/media/k2/media/' . $item->id); } JFile::move(JPATH_SITE . '/media/k2/videos/' . $mediaEntry->upload, JPATH_SITE . '/media/k2/media/' . $item->id . '/' . $mediaEntry->upload); } } else { $mediaEntry->url = $matches[1]; } } else { preg_match("#}(.*?){/#s", $item->video, $matches); $mediaEntry->id = $matches[1]; $video = substr($item->video, 1); $mediaEntry->provider = substr($video, 0, strpos($video, '}')); } } $media[] = $mediaEntry; } $media = json_encode($media); $tags = array(); $query = $db->getQuery(true); $query->select($db->quoteName('tagId'))->from($db->quoteName('#__k2_tags_xref'))->where($db->quoteName('itemId') . ' = ' . $item->id); $db->setQuery($query); $tagIds = $db->loadColumn(); if (count($tagIds)) { $query = $db->getQuery(true); $query->select($db->quoteName('name') . ',' . $db->quoteName('id'))->from($db->quoteName('#__k2_tags'))->where($db->quoteName('id') . ' IN(' . implode(',', $tagIds) . ')')->where($db->quoteName('state') . ' = 1'); $db->setQuery($query); $tags = $db->loadObjectList(); } $tags = json_encode($tags); $query = $db->getQuery(true); $query->select($db->quoteName('id'))->from($db->quoteName('#__k2_attachments'))->where($db->quoteName('itemId') . ' = ' . $item->id); $db->setQuery($query); $attachments = $db->loadColumn(); $attachments = json_encode($attachments); $galleries = array(); if (strpos($item->gallery, '{gallery') !== false) { $gallery = new stdClass(); preg_match("#}(.*?){/#s", $item->gallery, $matches); $value = $matches[1]; if (strpos($value, 'flickr.com') !== false) { $gallery->url = $value; $gallery->upload = ''; } else { $gallery->url = ''; $tmp = uniqid(); if (JFolder::exists(JPATH_SITE . '/media/k2/galleries/' . $item->id)) { JFolder::move(JPATH_SITE . '/media/k2/galleries/' . $item->id, JPATH_SITE . '/media/k2/galleries/' . $tmp); JFolder::create(JPATH_SITE . '/media/k2/galleries/' . $item->id); JFolder::move(JPATH_SITE . '/media/k2/galleries/' . $tmp, JPATH_SITE . '/media/k2/galleries/' . $item->id . '/' . $tmp); } $gallery->upload = $tmp; } $galleries[] = $gallery; } $galleries = json_encode($galleries); $extraFields = new stdClass(); $itemFields = json_decode($item->extra_fields); if (is_array($itemFields)) { foreach ($itemFields as $itemField) { $query = $db->getQuery(true); $query->select('*')->from($db->quoteName('#__k2_extra_fields'))->where($db->quoteName('id') . ' = ' . $itemField->id); $db->setQuery($query); $field = $db->loadObject(); // No field found, go for the next one if (!$field) { continue; } $entry = new stdClass(); if ($field->type == 'text') { $entry->value = isset($itemField->value) ? $itemField->value : ''; } else { if ($field->type == 'textarea') { $entry->value = isset($itemField->value) ? $itemField->value : ''; } else { if ($field->type == 'date') { $entry->date = isset($itemField->value) ? $itemField->value : ''; } else { if ($field->type == 'image') { $entry->src = isset($itemField->value) ? $itemField->value : ''; $entry->alt = isset($itemField->value) ? $itemField->value : ''; } else { if ($field->type == 'labels') { $entry->value = isset($itemField->value) ? $itemField->value : ''; } else { if ($field->type == 'link') { $entry->text = isset($itemField->value) && is_array($itemField->value) && isset($itemField->value[0]) ? $itemField->value[0] : ''; $entry->url = isset($itemField->value) && is_array($itemField->value) && isset($itemField->value[1]) ? $itemField->value[1] : ''; $entry->target = isset($itemField->value) && is_array($itemField->value) && isset($itemField->value[2]) ? $itemField->value[2] : ''; } else { if ($field->type == 'radio') { $entry->value = ''; $json = json_decode($field->value); if (isset($json->options) && is_array($json->options) && isset($itemField->value) && $itemField->value && isset($json->options[$itemField->value - 1])) { $entry->value = $json->options[$itemField->value - 1]; } } else { if ($field->type == 'select') { $entry->value = ''; $json = json_decode($field->value); if (isset($json->multiple) && $json->multiple) { $entry->value = array(); if (isset($itemField->value) && is_array($itemField->value) && isset($json->options) && is_array($json->options)) { foreach ($itemField->value as $value) { if (isset($json->options[$value - 1])) { $entry->value[] = $json->options[$value - 1]; } } } } else { $entry->value = ''; if (isset($json->options) && is_array($json->options) && isset($itemField->value) && $itemField->value && isset($json->options[$itemField->value - 1])) { $entry->value = $json->options[$itemField->value - 1]; } } } else { if ($field->type == 'csv') { $entry->value = isset($itemField->value) ? json_encode($itemField->value) : ''; } else { if ($field->type == 'header') { $entry->value = isset($itemField->value) ? $itemField->value : ''; } } } } } } } } } } $property = $field->id; $extraFields->{$property} = $entry; } } $extraFields = json_encode($extraFields); $updatedParams = new JRegistry($item->params); $this->updateImageSizeParam($updatedParams, 'itemImgSize', ''); $this->updateImageSizeParam($updatedParams, 'itemRelatedImageSize', ''); $query = $db->getQuery(true); $query->update($db->quoteName('#__k2_items')); $query->set(array($db->quoteName('id') . ' = ' . $item->id, $db->quoteName('ordering') . ' = ' . (int) $item->ordering, $db->quoteName('image') . ' = ' . $db->quote($image), $db->quoteName('media') . ' = ' . $db->quote($media), $db->quoteName('tags') . ' = ' . $db->quote($tags), $db->quoteName('attachments') . ' = ' . $db->quote($attachments), $db->quoteName('galleries') . ' = ' . $db->quote($galleries), $db->quoteName('extra_fields') . ' = ' . $db->quote($extraFields), $db->quoteName('created') . ' = ' . $db->quote($item->created), $db->quoteName('created_by') . ' = ' . $db->quote($item->created_by), $db->quoteName('modified') . ' = ' . $db->quote($item->modified), $db->quoteName('modified_by') . ' = ' . $db->quote($item->modified_by), $db->quoteName('plugins') . ' = ' . $db->quote($item->plugins), $db->quoteName('params') . ' = ' . $db->quote($updatedParams->toString())))->where($db->quoteName('id') . ' = ' . $lastInsertedId); $db->setQuery($query); $db->execute(); // Update auto increment to avoid SQL errors $db->setQuery('ALTER TABLE ' . $db->quoteName('#__k2_items') . ' AUTO_INCREMENT=' . ((int) $item->id + 1)); $db->execute(); $query = $db->getQuery(true); $query->select('COUNT(*)')->from('#__k2_v2_comments')->where($db->quoteName('itemID') . ' = ' . (int) $item->id)->where('published = 1'); $db->setQuery($query); $comments = $db->loadResult(); $query = $db->getQuery(true); $query->update($db->quoteName('#__k2_items_stats')); $query->set($db->quoteName('hits') . ' = ' . (int) $item->hits); $query->set($db->quoteName('comments') . ' = ' . (int) $comments); $query->where($db->quoteName('itemId') . ' = ' . (int) $item->id); $db->setQuery($query); $db->execute(); $this->response->id = $item->id; } $this->response->total = $session->get('k2.upgrade.items.total'); $session->set('k2.upgrade.items.processed', (int) $session->get('k2.upgrade.items.processed') + count($items)); $this->response->processed = $session->get('k2.upgrade.items.processed'); if (count($items) == 0) { $this->response->id = 0; $this->response->type = 'users'; } }
function remove() { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $mainframe = JFactory::getApplication(); $params = JComponentHelper::getParams('com_k2'); $itemModel = K2Model::getInstance('Item', 'K2Model'); $db = JFactory::getDBO(); $cid = JRequest::getVar('cid'); JPluginHelper::importPlugin('finder'); $dispatcher = JDispatcher::getInstance(); foreach ($cid as $id) { $row = JTable::getInstance('K2Item', 'Table'); $row->load($id); $row->id = (int) $row->id; //Delete images if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . md5("Image" . $row->id) . '.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . md5("Image" . $row->id) . '.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg'); } //Delete gallery if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $row->id)) { JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $row->id); } //Delete video preg_match_all("#^{(.*?)}(.*?){#", $row->video, $matches, PREG_PATTERN_ORDER); $videotype = $matches[1][0]; $videofile = $matches[2][0]; $videoExtensions = array('flv', 'mp4', 'ogv', 'webm', 'f4v', 'm4v', '3gp', '3g2', 'mov', 'mpeg', 'mpg', 'avi', 'wmv', 'divx', 'swf'); $audioExtensions = array('mp3', 'aac', 'mp4', 'ogg', 'wma'); if (in_array($videotype, $videoExtensions) || in_array($videotype, $audioExtensions)) { 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); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype); } } //Delete attachments $path = $params->get('attachmentsFolder', NULL); if (is_null($path)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments'; } else { $savepath = $path; } $attachments = $itemModel->getAttachments($row->id); foreach ($attachments as $attachment) { if (JFile::exists($savepath . DS . $attachment->filename)) { JFile::delete($savepath . DS . $attachment->filename); } } $query = "DELETE FROM #__k2_attachments WHERE itemID={$row->id}"; $db->setQuery($query); $db->query(); //Delete tags $query = "DELETE FROM #__k2_tags_xref WHERE itemID={$row->id}"; $db->setQuery($query); $db->query(); //Delete comments $query = "DELETE FROM #__k2_comments WHERE itemID={$row->id}"; $db->setQuery($query); $db->query(); $row->delete($id); $dispatcher->trigger('onFinderAfterDelete', array('com_k2.item', $row)); } $cache = JFactory::getCache('com_k2'); $cache->clean(); $mainframe->enqueueMessage(JText::_('K2_DELETE_COMPLETED')); $mainframe->redirect('index.php?option=com_k2&view=items'); }
function reportSpammer() { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $format = JRequest::getVar('format'); $errors = array(); if (K2_JVERSION != '15') { if (!$user->authorise('core.admin', 'com_k2')) { $format == 'raw' ? die(JText::_('K2_ALERTNOTAUTH')) : JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } } else { if ($user->gid < 25) { $format == 'raw' ? die(JText::_('K2_ALERTNOTAUTH')) : JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } } K2Model::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'models'); $model = K2Model::getInstance('User', 'K2Model'); $model->setState('id', JRequest::getInt('id')); $model->reportSpammer(); if ($format == 'raw') { $response = ''; $messages = $mainframe->getMessageQueue(); foreach ($messages as $message) { $response .= $message['message']."\n"; } die($response); } $this->setRedirect('index.php?option=com_k2&view=comments&tmpl=component'); }
function move() { $mainframe = JFactory::getApplication(); JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables'); $cid = JRequest::getVar('cid'); foreach ($cid as $id) { $row = JTable::getInstance('K2Item', 'Table'); $row->load($id); $rows[] = $row; } $categoriesModel = K2Model::getInstance('Categories', 'K2Model'); $categories = $categoriesModel->categoriesTree(null, true, false); $lists['categories'] = JHTML::_('select.genericlist', $categories, 'category', 'class="inputbox" size="8"', 'value', 'text'); $this->assignRef('rows', $rows); $this->assignRef('lists', $lists); JToolBarHelper::title(JText::_('K2_MOVE_ITEMS'), 'k2.png'); JToolBarHelper::custom('saveMove', 'save.png', 'save_f2.png', 'K2_SAVE', false); JToolBarHelper::cancel(); parent::display(); }
function save($front = false) { $mainframe = JFactory::getApplication(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); 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->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } if ($front && $row->id == NULL) { JLoader::register('K2HelperPermissions', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'permissions.php'); if (!K2HelperPermissions::canAddItem($row->catid)) { $mainframe->enqueueMessage(JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY_SAVE_FAILED'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=item&task=add&tmpl=component'); } } $isNew = $row->id ? false : true; // If we are in front-end and the item is not new we need to get it's current published state. if (!$isNew && $front) { $id = JRequest::getInt('id'); $currentRow = JTable::getInstance('K2Item', 'Table'); $currentRow->load($id); $isAlreadyPublished = $currentRow->published; $currentFeaturedState = $currentRow->featured; } 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 = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $row->modified_by = $user->get('id'); } else { $row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0"); if ($row->featured) { $row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering'); } } $row->created_by = $row->created_by ? $row->created_by : $user->get('id'); if ($front) { $K2Permissions = K2Permissions::getInstance(); if (!$K2Permissions->permissions->get('editAll')) { $row->created_by = $user->get('id'); } } if ($row->created && strlen(trim($row->created)) <= 10) { $row->created .= ' 00:00:00'; } $config = JFactory::getConfig(); $tzoffset = K2_JVERSION == '30' ? $config->get('offset') : $config->getValue('config.offset'); $date = JFactory::getDate($row->created, $tzoffset); $row->created = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); if (strlen(trim($row->publish_up)) <= 10) { $row->publish_up .= ' 00:00:00'; } $date = JFactory::getDate($row->publish_up, $tzoffset); $row->publish_up = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); if (trim($row->publish_down) == JText::_('K2_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 = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); } $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); } if (!$row->check()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=item&cid=' . $row->id); } $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; } //Trigger the finder before save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.item', $row, $isNew)); // Try to save the video if there is no need to wait for item ID if (!JRequest::getBool('del_video')) { if (!isset($files['video'])) { 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); } } } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) { if (version_compare(phpversion(), '5.0') < 0) { $tmpRow = $row; } else { $tmpRow = clone $row; } } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) { $itemID = $row->id; $row = $tmpRow; $row->id = $itemID; } if (!$params->get('disableCompactOrdering')) { $row->reorder("catid = {$row->catid} AND trash = 0"); } if ($row->featured && !$params->get('disableCompactOrdering')) { $row->reorder("featured = 1 AND trash = 0", 'featured_ordering'); } $files = JRequest::get('files'); //Image if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $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 = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($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 = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($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->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } 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'); $attachments_existing_files = JRequest::getVar('attachment_existing_file', '', '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 $key => $file) { if ($file["tmp_name"] || $attachments_existing_files[$key]) { if ($attachments_existing_files[$key]) { $src = JPATH_SITE . DS . JPath::clean($attachments_existing_files[$key]); $copyName = basename($src); $dest = $savepath . DS . $copyName; if (JFile::exists($dest)) { $existingFileName = JFile::getName($dest); $ext = JFile::getExt($existingFileName); $basename = JFile::stripExt($existingFileName); $newFilename = $basename . '_' . time() . '.' . $ext; $copyName = $newFilename; $dest = $savepath . DS . $newFilename; } JFile::copy($src, $dest); $attachment = JTable::getInstance('K2Attachment', 'Table'); $attachment->itemID = $row->id; $attachment->filename = $copyName; $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 { $handle = new Upload($file); if ($handle->uploaded) { $handle->file_auto_rename = true; $handle->allowed[] = 'application/x-zip'; $handle->allowed[] = 'application/download'; $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->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } } $counter++; } } //Gallery $flickrGallery = JRequest::getVar('flickrGallery'); if ($flickrGallery) { $row->gallery = '{gallery}' . $flickrGallery . '{/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->enqueueMessage(JText::_('K2_GALLERY_UPLOAD_ERROR_CANNOT_EXTRACT_ARCHIVE'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } else { $row->gallery = '{gallery}' . $row->id . '{/gallery}'; } JFile::delete($savepath . DS . $handle->file_dst_name); $handle->Clean(); } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } 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) { $videoExtensions = array("flv", "mp4", "ogv", "webm", "f4v", "m4v", "3gp", "3g2", "mov", "mpeg", "mpg", "avi", "wmv", "divx"); $audioExtensions = array("mp3", "aac", "m4a", "ogg", "wma"); $validExtensions = array_merge($videoExtensions, $audioExtensions); $filetype = JFile::getExt($files['video']['name']); if (!in_array($filetype, $validExtensions)) { $mainframe->enqueueMessage(JText::_('K2_INVALID_VIDEO_FILE'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } if (in_array($filetype, $videoExtensions)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos'; } else { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio'; } $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 { $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 (in_array($videotype, $videoExtensions)) { 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); } } if (in_array($videotype, $audioExtensions)) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype); } } $row->video = ''; $row->video_caption = ''; $row->video_credits = ''; } //Extra fields $objects = array(); $variables = JRequest::get('post', 2); foreach ($variables as $key => $value) { if ((bool) JString::stristr($key, 'K2ExtraField_')) { $object = new JObject(); $object->set('id', JString::substr($key, 13)); if (is_string($value)) { $value = trim($value); } $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 = K2Model::getInstance('ExtraField', 'K2Model'); $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::_('K2_ALERTNOTAUTH')); } $tags = JRequest::getVar('tags', NULL, 'POST', 'array'); if (count($tags)) { $tags = array_unique($tags); foreach ($tags as $tag) { $tag = JString::trim($tag); if ($tag) { $tagID = false; $K2Tag = JTable::getInstance('K2Tag', 'Table'); $K2Tag->name = $tag; // Tag has been filtred and does not exist if ($K2Tag->check()) { $K2Tag->published = 1; if ($K2Tag->store()) { $tagID = $K2Tag->id; } } else { if ($K2Tag->name) { $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($K2Tag->name); $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 { $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 we are in front-end check publishing permissions properly. if ($front) { // New items require the "Publish items" permission. if ($isNew && $row->published && !K2HelperPermissions::canPublishItem($row->catid)) { $row->published = 0; $mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice'); } // Existing items require either the "Publish items" or the "Allow editing of already published items" permission. if (!$isNew && $row->published) { $canEditPublished = $isAlreadyPublished && K2HelperPermissions::canEditPublished($row->catid); if (!K2HelperPermissions::canPublishItem($row->catid) && !$canEditPublished) { $row->published = 0; $mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice'); } } // If user has cannot publish the item then also cannot make it featured if (!K2HelperPermissions::canPublishItem($row->catid)) { if ($isNew) { $row->featured = 0; } else { $row->featured = $currentFeaturedState; } } } $query = "UPDATE #__k2_items SET \n video_caption = " . $db->Quote($row->video_caption) . ", \n video_credits = " . $db->Quote($row->video_credits) . ", "; if (!is_null($row->video)) { $query .= " video = " . $db->Quote($row->video) . ", "; } if (!is_null($row->gallery)) { $query .= " gallery = " . $db->Quote($row->gallery) . ", "; } $query .= " extra_fields = " . $db->Quote($row->extra_fields) . ", \n extra_fields_search = " . $db->Quote($row->extra_fields_search) . " ,\n published = " . $db->Quote($row->published) . " \n WHERE id = " . $row->id; $db->setQuery($query); if (!$db->query()) { $mainframe->enqueueMessage($db->getErrorMsg(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } $row->checkin(); $cache = JFactory::getCache('com_k2'); $cache->clean(); $dispatcher->trigger('onAfterK2Save', array(&$row, $isNew)); JPluginHelper::importPlugin('content'); if (K2_JVERSION != '15') { $dispatcher->trigger('onContentAfterSave', array('com_k2.item', &$row, $isNew)); } else { $dispatcher->trigger('onAfterContentSave', array(&$row, $isNew)); } //Trigger the finder after save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.item', $row, $isNew)); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('K2_CHANGES_TO_ITEM_SAVED'); $link = 'index.php?option=com_k2&view=item&cid=' . $row->id; break; case 'saveAndNew': $msg = JText::_('K2_ITEM_SAVED'); $link = 'index.php?option=com_k2&view=item'; break; case 'save': default: $msg = JText::_('K2_ITEM_SAVED'); if ($front) { $link = 'index.php?option=com_k2&view=item&task=edit&cid=' . $row->id . '&tmpl=component&Itemid=' . JRequest::getInt('Itemid'); } else { $link = 'index.php?option=com_k2&view=items'; } break; } $mainframe->enqueueMessage($msg); $mainframe->redirect($link); }
function display($tpl = null) { $mainframe = JFactory::getApplication(); $document = JFactory::getDocument(); $db = JFactory::getDBO(); $params = JComponentHelper::getParams('com_k2'); $option = JRequest::getCmd('option'); $view = JRequest::getCmd('view'); $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); $limitstart = $mainframe->getUserStateFromRequest($option . $view . '.limitstart', 'limitstart', 0, 'int'); $filter_order = $mainframe->getUserStateFromRequest($option . $view . 'filter_order', 'filter_order', 'juser.name', 'cmd'); $filter_order_Dir = $mainframe->getUserStateFromRequest($option . $view . 'filter_order_Dir', 'filter_order_Dir', '', 'word'); $filter_status = $mainframe->getUserStateFromRequest($option . $view . 'filter_status', 'filter_status', -1, 'int'); $filter_group = $mainframe->getUserStateFromRequest($option . $view . 'filter_group', 'filter_group', '', 'string'); $filter_group_k2 = $mainframe->getUserStateFromRequest($option . $view . 'filter_group_k2', 'filter_group_k2', '', 'string'); $search = $mainframe->getUserStateFromRequest($option . $view . 'search', 'search', '', 'string'); $search = JString::strtolower($search); K2Model::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models'); $model = K2Model::getInstance('Users', 'K2Model'); $total = $model->getTotal(); if ($limitstart > $total - $limit) { $limitstart = max(0, (int) (ceil($total / $limit) - 1) * $limit); JRequest::setVar('limitstart', $limitstart); } $users = $model->getData(); $task = JRequest::getCmd('task'); for ($i = 0; $i < sizeof($users); $i++) { $users[$i]->loggedin = $model->checkLogin($users[$i]->id); $users[$i]->profileID = $model->hasProfile($users[$i]->id); if ($users[$i]->profileID) { $db->setQuery("SELECT ip FROM #__k2_users WHERE id = " . $users[$i]->profileID); $users[$i]->ip = $db->loadResult(); } else { $users[$i]->ip = ''; } if ($users[$i]->lastvisitDate == "0000-00-00 00:00:00") { $users[$i]->lvisit = false; } else { $users[$i]->lvisit = $users[$i]->lastvisitDate; } $users[$i]->link = JRoute::_('index.php?option=com_k2&view=user&cid=' . $users[$i]->id); if (K2_JVERSION == '15') { $users[$i]->published = $users[$i]->loggedin; $users[$i]->loggedInStatus = strip_tags(JHTML::_('grid.published', $users[$i], $i), '<img>'); $users[$i]->blockStatus = ''; if ($users[$i]->block) { $users[$i]->blockStatus .= '<a title="' . JText::_('K2_ENABLE') . '" onclick="return listItemTask(\'cb' . $i . ',\'enable\')" href="#"><img alt="' . JText::_('K2_ENABLED') . '" src="images/publish_x.png"></a>'; } else { $users[$i]->blockStatus .= '<a title="' . JText::_('K2_DISABLE') . '" onclick="return listItemTask(\'cb' . $i . ',\'disable\')" href="#"><img alt="' . JText::_('K2_DISABLED') . '" src="images/tick.png"></a>'; } if ($task == 'element') { $users[$i]->blockStatus = strip_tags($users[$i]->blockStatus, '<img>'); } } else { $states = array(1 => array('', 'K2_LOGGED_IN', 'K2_LOGGED_IN', 'K2_LOGGED_IN', false, 'publish', 'publish'), 0 => array('', 'K2_NOT_LOGGED_IN', 'K2_NOT_LOGGED_IN', 'K2_NOT_LOGGED_IN', false, 'unpublish', 'unpublish')); $users[$i]->loggedInStatus = JHtml::_('jgrid.state', $states, $users[$i]->loggedin, $i, '', false); $states = array(0 => array('disable', 'K2_ENABLED', 'K2_DISABLE', 'K2_ENABLED', false, 'publish', 'publish'), 1 => array('enable', 'K2_DISABLED', 'K2_ENABLE', 'K2_DISABLED', false, 'unpublish', 'unpublish')); $users[$i]->blockStatus = JHtml::_('jgrid.state', $states, $users[$i]->block, $i, '', $task != 'element'); } } $this->assignRef('rows', $users); jimport('joomla.html.pagination'); $pageNav = new JPagination($total, $limitstart, $limit); $this->assignRef('page', $pageNav); $lists = array(); $lists['search'] = $search; $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; $filter_status_options[] = JHTML::_('select.option', -1, JText::_('K2_SELECT_STATE')); $filter_status_options[] = JHTML::_('select.option', 0, JText::_('K2_ENABLED')); $filter_status_options[] = JHTML::_('select.option', 1, JText::_('K2_BLOCKED')); $lists['status'] = JHTML::_('select.genericlist', $filter_status_options, 'filter_status', '', 'value', 'text', $filter_status); $userGroups = $model->getUserGroups(); $groups[] = JHTML::_('select.option', '0', JText::_('K2_SELECT_JOOMLA_GROUP')); foreach ($userGroups as $userGroup) { $groups[] = JHTML::_('select.option', $userGroup->value, $userGroup->text); } $lists['filter_group'] = JHTML::_('select.genericlist', $groups, 'filter_group', '', 'value', 'text', $filter_group); $K2userGroups = $model->getUserGroups('k2'); $K2groups[] = JHTML::_('select.option', '0', JText::_('K2_SELECT_K2_GROUP')); foreach ($K2userGroups as $K2userGroup) { $K2groups[] = JHTML::_('select.option', $K2userGroup->id, $K2userGroup->name); } $lists['filter_group_k2'] = JHTML::_('select.genericlist', $K2groups, 'filter_group_k2', '', 'value', 'text', $filter_group_k2); $this->assignRef('lists', $lists); if (K2_JVERSION != '15') { $dateFormat = JText::_('K2_J16_DATE_FORMAT'); } else { $dateFormat = JText::_('K2_DATE_FORMAT'); } $this->assignRef('dateFormat', $dateFormat); $template = $mainframe->getTemplate(); $this->assignRef('template', $template); if ($mainframe->isAdmin()) { JToolBarHelper::title(JText::_('K2_USERS'), 'k2.png'); JToolBarHelper::custom('move', 'move.png', 'move_f2.png', 'K2_MOVE', true); JToolBarHelper::deleteList('K2_WARNING_YOU_ARE_ABOUT_TO_DELETE_THE_SELECTED_USERS_PERMANENTLY_FROM_THE_SYSTEM', 'delete', 'K2_DELETE'); JToolBarHelper::publishList('enable', 'K2_ENABLE'); JToolBarHelper::unpublishList('disable', 'K2_DISABLE'); JToolBarHelper::editList(); JToolBarHelper::deleteList('K2_ARE_YOU_SURE_YOU_WANT_TO_RESET_SELECTED_USERS', 'remove', 'K2_RESET_USER_DETAILS'); $toolbar = JToolBar::getInstance('toolbar'); if (K2_JVERSION != '15') { JToolBarHelper::preferences('com_k2', 550, 875, 'K2_PARAMETERS'); } else { $toolbar->appendButton('Popup', 'config', 'K2_PARAMETERS', 'index.php?option=com_k2&view=settings'); } $this->loadHelper('html'); K2HelperHTML::subMenu(); $user = JFactory::getUser(); $canImport = false; if (K2_JVERSION == '15') { $canImport = $user->gid > 23; } else { $canImport = $user->authorise('core.admin', 'com_k2'); } if ($canImport) { if (!$params->get('hideImportButton')) { $buttonUrl = JURI::base() . 'index.php?option=com_k2&view=users&task=import'; $buttonText = JText::_('K2_IMPORT_JOOMLA_USERS'); if (K2_JVERSION == '30') { $button = '<a id="K2ImportUsersButton" class="btn btn-small" href="' . $buttonUrl . '"><i class="icon-archive "></i>' . $buttonText . '</a>'; } else { $button = '<a id="K2ImportUsersButton" href="' . $buttonUrl . '"><span class="icon-32-archive" title="' . $buttonText . '"></span>' . $buttonText . '</a>'; } $toolbar->appendButton('Custom', $button); } } $document = JFactory::getDocument(); $document->addScriptDeclaration('var K2Language = ["' . JText::_('K2_REPORT_USER_WARNING', true) . '"];'); } $isAdmin = $mainframe->isAdmin(); $this->assignRef('isAdmin', $isAdmin); if ($mainframe->isSite()) { // CSS $document->addStyleSheet(JURI::root(true) . '/media/k2/assets/css/k2.frontend.css?v=2.7.0'); $document->addStyleSheet(JURI::root(true) . '/templates/system/css/general.css'); $document->addStyleSheet(JURI::root(true) . '/templates/system/css/system.css'); if (K2_JVERSION != '15') { $document->addStyleSheet(JURI::root(true) . '/administrator/templates/bluestork/css/template.css'); $document->addStyleSheet(JURI::root(true) . '/media/system/css/system.css'); } else { $document->addStyleSheet(JURI::root(true) . '/administrator/templates/khepri/css/general.css'); } } parent::display($tpl); }
public static function getList(&$params) { jimport('joomla.filesystem.file'); $mainframe = JFactory::getApplication(); $limit = $params->get('itemCount', 5); $cid = $params->get('category_id', NULL); $ordering = $params->get('itemsOrdering', ''); $componentParams = JComponentHelper::getParams('com_k2'); $limitstart = JRequest::getInt('limitstart'); $user = JFactory::getUser(); $aid = $user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); if ($params->get('source') == 'specific') { $value = $params->get('items'); $current = array(); if (is_string($value) && !empty($value)) { $current[] = $value; } if (is_array($value)) { $current = $value; } $items = array(); foreach ($current as $id) { $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams \n\t\t\t\tFROM #__k2_items as i \n\t\t\t\tLEFT JOIN #__k2_categories c ON c.id = i.catid \n\t\t\t\tWHERE i.published = 1 "; if (K2_JVERSION != '15') { $query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; } else { $query .= " AND i.access<={$aid} "; } $query .= " AND i.trash = 0 AND c.published = 1 "; if (K2_JVERSION != '15') { $query .= " AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; } else { $query .= " AND c.access<={$aid} "; } $query .= " AND c.trash = 0 \n\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " ) \n\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " ) \n\t\t\t\tAND i.id={$id}"; if (K2_JVERSION != '15') { if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")"; } } $db->setQuery($query); $item = $db->loadObject(); if ($item) { $items[] = $item; } } } else { $query = "SELECT i.*, CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams"; if ($ordering == 'best') { $query .= ", (r.rating_sum/r.rating_count) AS rating"; } if ($ordering == 'comments') { $query .= ", COUNT(comments.id) AS numOfComments"; } $query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid"; if ($ordering == 'best') { $query .= " LEFT JOIN #__k2_rating r ON r.itemID = i.id"; } if ($ordering == 'comments') { $query .= " LEFT JOIN #__k2_comments comments ON comments.itemID = i.id"; } if (K2_JVERSION != '15') { $query .= " WHERE i.published = 1 AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND i.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND c.trash = 0"; } else { $query .= " WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0"; } $query .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )"; $query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )"; if ($params->get('catfilter')) { if (!is_null($cid)) { if (is_array($cid)) { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { JArrayHelper::toInteger($cid); $query .= " AND i.catid IN(" . implode(',', $cid) . ")"; } } else { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { $query .= " AND i.catid=" . (int) $cid; } } } } if ($params->get('FeaturedItems') == '0') { $query .= " AND i.featured != 1"; } if ($params->get('FeaturedItems') == '2') { $query .= " AND i.featured = 1"; } if ($params->get('videosOnly')) { $query .= " AND (i.video IS NOT NULL AND i.video!='')"; } if ($ordering == 'comments') { $query .= " AND comments.published = 1"; } if (K2_JVERSION != '15') { if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")"; } } switch ($ordering) { case 'date': $orderby = 'i.created ASC'; break; case 'rdate': $orderby = 'i.created DESC'; break; case 'alpha': $orderby = 'i.title'; break; case 'ralpha': $orderby = 'i.title DESC'; break; case 'order': if ($params->get('FeaturedItems') == '2') { $orderby = 'i.featured_ordering'; } else { $orderby = 'i.ordering'; } break; case 'rorder': if ($params->get('FeaturedItems') == '2') { $orderby = 'i.featured_ordering DESC'; } else { $orderby = 'i.ordering DESC'; } break; case 'hits': if ($params->get('popularityRange')) { $datenow = JFactory::getDate(); $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) "; } $orderby = 'i.hits DESC'; break; case 'rand': $orderby = 'RAND()'; break; case 'best': $orderby = 'rating DESC'; break; case 'comments': if ($params->get('popularityRange')) { $datenow = JFactory::getDate(); $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) "; } $query .= " GROUP BY i.id "; $orderby = 'numOfComments DESC'; break; case 'modified': $orderby = 'lastChanged DESC'; break; case 'publishUp': $orderby = 'i.publish_up DESC'; break; default: $orderby = 'i.id DESC'; break; } $query .= " ORDER BY " . $orderby; // $sql = str_replace('#__','jos_',$query); // echo $sql;die; //var_dump($limit); $db->setQuery($query, 0, $limit); $items = $db->loadObjectList(); } $model = K2Model::getInstance('Item', 'K2Model'); $show_introtext = $params->get('item_desc_display', 0); $introtext_limit = $params->get('item_desc_max_characs', 100); $show_title = $params->get('item_title_display', 1); $title_limit = $params->get('item_title_max_characs', 20); $item_title_ending_char = $params->get('item_title_ending_char', ''); $item_desc_ending_char = $params->get('item_desc_ending_char', ''); if (count($items)) { foreach ($items as $item) { //Clean title $item->title = JFilterOutput::ampReplace($item->title); $item->displaytitle = $show_title ? self::truncate($item->title, $title_limit, $item_title_ending_char) : ''; //Read more link $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias)))); //Tags $item->tags = ''; if ($params->get('item_tags_display')) { $tags = $model->getItemTags($item->id); for ($i = 0; $i < sizeof($tags); $i++) { $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name)); } $item->tags = $tags; } else { $item->tags = ''; } // Restore the intotext variable after plugins execution self::getK2Images($item, $params); //Clean the plugin tags $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext); if ($item->fulltext != '') { $item->fulltext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->fulltext); $item->introtext = self::_cleanText($item->introtext . $item->fulltext); } else { $item->introtext = self::_cleanText($item->introtext); } $item->displayIntrotext = $show_introtext ? self::truncate($item->introtext, $introtext_limit, $item_desc_ending_char) : ''; $rows[] = $item; } return $rows; } }
<?php // // // K2 Data layer (introduced in version 3) // // // Fetch a single K2 item by ID $item = K2Items::getInstance(12); // Fetch an item by its alias $item = K2Items::getInstance('docs'); // Fetching multiple items based on filters // Get items from categories which have the IDs 33 and 40 $model = K2Model::getInstance('items'); // Apply publishing and ACL $model->setState('site', true); $model->setState('category', array(33, 40)); $model->setState('sorting', 'title'); $items = $model->getRows(); foreach ($items as $item) { // Do something } // Lazy loading. // Access the item's tags from ANYWHERE $item = K2Items::getInstance(12); foreach ($items->tags as $tag) { echo $tag->name; echo $tag->link; }
function display($tpl = null) { JRequest::setVar('hidemainmenu', 1); $model = $this->getModel(); $category = $model->getData(); if (K2_JVERSION == '15') { JFilterOutput::objectHTMLSafe($category); } else { JFilterOutput::objectHTMLSafe($category, ENT_QUOTES, array('params', 'plugins')); } if (!$category->id) { $category->published = 1; } $this->assignRef('row', $category); $wysiwyg = JFactory::getEditor(); $editor = $wysiwyg->display('description', $category->description, '100%', '250px', '', '', array('pagebreak', 'readmore')); $this->assignRef('editor', $editor); $document = JFactory::getDocument(); $js = "\n\t\tvar K2SitePath = '" . JURI::root(true) . "/';\n\t\tvar K2BasePath = '" . JURI::base(true) . "/';\n\t\t"; $document->addScriptDeclaration($js); $lists = array(); $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $category->published); $lists['access'] = version_compare(JVERSION, '3.0', 'ge') ? JHTML::_('access.level', 'access', $category->access) : JHTML::_('list.accesslevel', $category); $query = 'SELECT ordering AS value, name AS text FROM #__k2_categories ORDER BY ordering'; $lists['ordering'] = version_compare(JVERSION, '3.0', 'ge') ? NUll : JHTML::_('list.specificordering', $category, $category->id, $query); $categories[] = JHTML::_('select.option', '0', JText::_('K2_NONE_ONSELECTLISTS')); $categoriesModel = K2Model::getInstance('Categories', 'K2Model'); $tree = $categoriesModel->categoriesTree($category, true, false); $categories = array_merge($categories, $tree); $lists['parent'] = JHTML::_('select.genericlist', $categories, 'parent', 'class="inputbox"', 'value', 'text', $category->parent); $extraFieldsModel = K2Model::getInstance('ExtraFields', 'K2Model'); $groups = $extraFieldsModel->getGroups(); $group[] = JHTML::_('select.option', '0', JText::_('K2_NONE_ONSELECTLISTS'), 'id', 'name'); $group = array_merge($group, $groups); $lists['extraFieldsGroup'] = JHTML::_('select.genericlist', $group, 'extraFieldsGroup', 'class="inputbox" size="1" ', 'id', 'name', $category->extraFieldsGroup); if (version_compare(JVERSION, '1.6.0', 'ge')) { $languages = JHTML::_('contentlanguage.existing', true, true); $lists['language'] = JHTML::_('select.genericlist', $languages, 'language', '', 'value', 'text', $category->language); } JPluginHelper::importPlugin('k2'); $dispatcher = JDispatcher::getInstance(); $K2Plugins = $dispatcher->trigger('onRenderAdminForm', array(&$category, 'category')); $this->assignRef('K2Plugins', $K2Plugins); $params = JComponentHelper::getParams('com_k2'); $this->assignRef('params', $params); if (version_compare(JVERSION, '1.6.0', 'ge')) { jimport('joomla.form.form'); $form = JForm::getInstance('categoryForm', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'category.xml'); $values = array('params' => json_decode($category->params)); $form->bind($values); $inheritFrom = isset($values['params']->inheritFrom) ? $values['params']->inheritFrom : 0; } else { $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'category.xml'); $form->loadINI($category->params); $inheritFrom = $form->get('inheritFrom'); } $this->assignRef('form', $form); $categories[0] = JHTML::_('select.option', '0', JText::_('K2_NONE_ONSELECTLISTS')); $lists['inheritFrom'] = JHTML::_('select.genericlist', $categories, 'params[inheritFrom]', 'class="inputbox"', 'value', 'text', $inheritFrom); $this->assignRef('lists', $lists); JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_CATEGORY') : ($title = JText::_('K2_ADD_CATEGORY')); JToolBarHelper::title($title, 'k2.png'); JToolBarHelper::save(); JToolBarHelper::custom('saveAndNew', 'save.png', 'save_f2.png', 'K2_SAVE_AND_NEW', false); JToolBarHelper::apply(); JToolBarHelper::cancel(); // ACE ACL integration $definedConstants = get_defined_constants(); if (!empty($definedConstants['ACEACL']) && AceaclApi::authorize('permissions', 'com_aceacl')) { $aceAclFlag = true; } else { $aceAclFlag = false; } $this->assignRef('aceAclFlag', $aceAclFlag); parent::display($tpl); }
function display($tpl = null) { JRequest::setVar('hidemainmenu', 1); $model = $this->getModel(); $extraField = $model->getData(); if (!$extraField->id) { $extraField->published = 1; $extraField->alias = ''; $extraField->required = 1; $extraField->showNull = 0; $extraField->displayInFrontEnd = 1; } else { require_once JPATH_COMPONENT . DS . 'lib' . DS . 'JSON.php'; $json = new Services_JSON(); $values = $json->decode($extraField->value); if (isset($values[0]->alias) && !empty($values[0]->alias)) { $extraField->alias = $values[0]->alias; } else { $filter = JFilterInput::getInstance(); $extraField->alias = $filter->clean($extraField->name, 'WORD'); } if (isset($values[0]->required)) { $extraField->required = $values[0]->required; } else { $extraField->required = 0; } if (isset($values[0]->showNull)) { $extraField->showNull = $values[0]->showNull; } else { $extraField->showNull = 0; } if (isset($values[0]->displayInFrontEnd)) { $extraField->displayInFrontEnd = $values[0]->displayInFrontEnd; } else { $extraField->displayInFrontEnd = 0; } } $extraField->name = htmlspecialchars($extraField->name, ENT_QUOTES, 'UTF-8'); $this->assignRef('row', $extraField); $lists = array(); $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $extraField->published); $groups[] = JHTML::_('select.option', 0, JText::_('K2_CREATE_NEW_GROUP')); $extraFieldModel = K2Model::getInstance('ExtraFields', 'K2Model'); $uniqueGroups = $extraFieldModel->getGroups(true); foreach ($uniqueGroups as $group) { $groups[] = JHTML::_('select.option', $group->id, $group->name); } $lists['group'] = JHTML::_('select.genericlist', $groups, 'groups', '', 'value', 'text', $extraField->group); $typeOptions[] = JHTML::_('select.option', 0, JText::_('K2_SELECT_TYPE')); $typeOptions[] = JHTML::_('select.option', 'textfield', JText::_('K2_TEXT_FIELD')); $typeOptions[] = JHTML::_('select.option', 'textarea', JText::_('K2_TEXTAREA')); $typeOptions[] = JHTML::_('select.option', 'select', JText::_('K2_DROPDOWN_SELECTION')); $typeOptions[] = JHTML::_('select.option', 'multipleSelect', JText::_('K2_MULTISELECT_LIST')); $typeOptions[] = JHTML::_('select.option', 'radio', JText::_('K2_RADIO_BUTTONS')); $typeOptions[] = JHTML::_('select.option', 'link', JText::_('K2_LINK')); $typeOptions[] = JHTML::_('select.option', 'csv', JText::_('K2_CSV_DATA')); $typeOptions[] = JHTML::_('select.option', 'labels', JText::_('K2_SEARCHABLE_LABELS')); $typeOptions[] = JHTML::_('select.option', 'date', JText::_('K2_DATE')); $typeOptions[] = JHTML::_('select.option', 'image', JText::_('K2_IMAGE')); $typeOptions[] = JHTML::_('select.option', 'header', JText::_('K2_HEADER')); $lists['type'] = JHTML::_('select.genericlist', $typeOptions, 'type', '', 'value', 'text', $extraField->type); $this->assignRef('lists', $lists); JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_EXTRA_FIELD') : ($title = JText::_('K2_ADD_EXTRA_FIELD')); JToolBarHelper::title($title, 'k2.png'); JToolBarHelper::save(); JToolBarHelper::apply(); JToolBarHelper::cancel(); JHTML::_('behavior.calendar'); $document = JFactory::getDocument(); $document->addScriptDeclaration(' var K2BasePath = "' . JURI::base(true) . '/"; var K2Language = [ "' . JText::_('K2_REMOVE', true) . '", "' . JText::_('K2_OPTIONAL', true) . '", "' . JText::_('K2_COMMA_SEPARATED_VALUES', true) . '", "' . JText::_('K2_USE_EDITOR', true) . '", "' . JText::_('K2_ALL_SETTINGS_ABOVE_ARE_OPTIONAL', true) . '", "' . JText::_('K2_ADD_AN_OPTION', true) . '", "' . JText::_('K2_LINK_TEXT', true) . '", "' . JText::_('K2_URL', true) . '", "' . JText::_('K2_OPEN_IN', true) . '", "' . JText::_('K2_SAME_WINDOW', true) . '", "' . JText::_('K2_NEW_WINDOW', true) . '", "' . JText::_('K2_CLASSIC_JAVASCRIPT_POPUP', true) . '", "' . JText::_('K2_LIGHTBOX_POPUP', true) . '", "' . JText::_('K2_RESET_VALUE', true) . '", "' . JText::_('K2_CALENDAR', true) . '", "' . JText::_('K2_PLEASE_SELECT_A_FIELD_TYPE_FROM_THE_LIST_ABOVE', true) . '", ];'); JHTML::_('behavior.modal'); parent::display($tpl); }
function onAfterInitialise() { // Determine Joomla! version if (version_compare(JVERSION, '3.0', 'ge')) { define('K2_JVERSION', '30'); } else { if (version_compare(JVERSION, '2.5', 'ge')) { define('K2_JVERSION', '25'); } else { define('K2_JVERSION', '15'); } } // Define the DS constant under Joomla! 3.0 if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } // Import Joomla! classes jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.application.component.controller'); jimport('joomla.application.component.model'); jimport('joomla.application.component.view'); // Get application $mainframe = JFactory::getApplication(); // Load the K2 classes JLoader::register('K2Table', JPATH_ADMINISTRATOR . '/components/com_k2/tables/table.php'); JLoader::register('K2Controller', JPATH_BASE . '/components/com_k2/controllers/controller.php'); JLoader::register('K2Model', JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php'); if ($mainframe->isSite()) { K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models'); } else { // Fix warning under Joomla! 1.5 caused by conflict in model names if (K2_JVERSION != '15' || K2_JVERSION == '15' && JRequest::getCmd('option') != 'com_users') { K2Model::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'models'); } } JLoader::register('K2View', JPATH_ADMINISTRATOR . '/components/com_k2/views/view.php'); JLoader::register('K2HelperHTML', JPATH_ADMINISTRATOR . '/components/com_k2/helpers/html.php'); // Community Builder integration $componentParams = JComponentHelper::getParams('com_k2'); if ($componentParams->get('cbIntegration') && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_comprofiler' . DS . 'plugin.foundation.php')) { define('K2_CB', true); global $_CB_framework; require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_comprofiler' . DS . 'plugin.foundation.php'; cbimport('cb.html'); cbimport('language.front'); } else { define('K2_CB', false); } // Define the default Itemid for users and tags. Defined here instead of the K2HelperRoute for performance reasons. // UPDATE : Removed. All K2 links without Itemid now use the anyK2Link defined in the router helper. // define('K2_USERS_ITEMID', $componentParams->get('defaultUsersItemid')); // define('K2_TAGS_ITEMID', $componentParams->get('defaultTagsItemid')); // Define JoomFish compatibility version. if (JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) { if (K2_JVERSION == '15') { $db = JFactory::getDBO(); $config = JFactory::getConfig(); $prefix = $config->getValue('config.dbprefix'); if (array_key_exists($prefix . '_jf_languages_ext', $db->getTableList())) { define('K2_JF_ID', 'lang_id'); } else { define('K2_JF_ID', 'id'); } } else { define('K2_JF_ID', 'lang_id'); } } /* if(JRequest::getCmd('option')=='com_k2' && JRequest::getCmd('task')=='save' && !$mainframe->isAdmin()){ $dispatcher = JDispatcher::getInstance(); foreach($dispatcher->_observers as $observer){ if($observer->_name=='jfdatabase' || $observer->_name=='jfrouter' || $observer->_name=='missing_translation'){ $dispatcher->detach($observer); } } } */ // Use K2 to make Joomla! Varnish-friendly // For more checkout: https://snipt.net/fevangelou/the-perfect-varnish-configuration-for-joomla-websites/ $user = JFactory::getUser(); if (!$user->guest) { JResponse::setHeader('X-Logged-In', 'True', true); } else { JResponse::setHeader('X-Logged-In', 'False', true); } if (!$mainframe->isAdmin()) { return; } $option = JRequest::getCmd('option'); $task = JRequest::getCmd('task'); $type = JRequest::getCmd('catid'); if ($option != 'com_joomfish') { return; } if (!JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php')) { return; } JPlugin::loadLanguage('com_k2', JPATH_ADMINISTRATOR); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php'; // Joom!Fish if ($option == 'com_joomfish' && ($task == 'translate.apply' || $task == 'translate.save') && $type == 'k2_items') { $language_id = JRequest::getInt('select_language_id'); $reference_id = JRequest::getInt('reference_id'); $objects = array(); $variables = JRequest::get('post'); 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; } } $json = new Services_JSON(); $extra_fields = $json->encode($objects); $extra_fields_search = ''; foreach ($objects as $object) { $extra_fields_search .= $this->getSearchValue($object->id, $object->value); $extra_fields_search .= ' '; } $user = JFactory::getUser(); $db = JFactory::getDBO(); $query = "SELECT COUNT(*) FROM #__jf_content WHERE reference_field = 'extra_fields' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'"; $db->setQuery($query); $result = $db->loadResult(); if ($result > 0) { $query = "UPDATE #__jf_content SET value=" . $db->Quote($extra_fields) . " WHERE reference_field = 'extra_fields' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'"; $db->setQuery($query); $db->query(); } else { $modified = date("Y-m-d H:i:s"); $modified_by = $user->id; $published = JRequest::getVar('published', 0); $query = "INSERT INTO #__jf_content (`id`, `language_id`, `reference_id`, `reference_table`, `reference_field` ,`value`, `original_value`, `original_text`, `modified`, `modified_by`, `published`) VALUES (NULL, {$language_id}, {$reference_id}, 'k2_items', 'extra_fields', " . $db->Quote($extra_fields) . ", '','', " . $db->Quote($modified) . ", {$modified_by}, {$published} )"; $db->setQuery($query); $db->query(); } $query = "SELECT COUNT(*) FROM #__jf_content WHERE reference_field = 'extra_fields_search' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'"; $db->setQuery($query); $result = $db->loadResult(); if ($result > 0) { $query = "UPDATE #__jf_content SET value=" . $db->Quote($extra_fields_search) . " WHERE reference_field = 'extra_fields_search' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'"; $db->setQuery($query); $db->query(); } else { $modified = date("Y-m-d H:i:s"); $modified_by = $user->id; $published = JRequest::getVar('published', 0); $query = "INSERT INTO #__jf_content (`id`, `language_id`, `reference_id`, `reference_table`, `reference_field` ,`value`, `original_value`, `original_text`, `modified`, `modified_by`, `published`) VALUES (NULL, {$language_id}, {$reference_id}, 'k2_items', 'extra_fields_search', " . $db->Quote($extra_fields_search) . ", '','', " . $db->Quote($modified) . ", {$modified_by}, {$published} )"; $db->setQuery($query); $db->query(); } } if ($option == 'com_joomfish' && ($task == 'translate.edit' || $task == 'translate.apply') && $type == 'k2_items') { if ($task == 'translate.edit') { $cid = JRequest::getVar('cid'); $array = explode('|', $cid[0]); $reference_id = $array[1]; } if ($task == 'translate.apply') { $reference_id = JRequest::getInt('reference_id'); } $item = JTable::getInstance('K2Item', 'Table'); $item->load($reference_id); $category_id = $item->catid; $language_id = JRequest::getInt('select_language_id'); $category = JTable::getInstance('K2Category', 'Table'); $category->load($category_id); $group = $category->extraFieldsGroup; $db = JFactory::getDBO(); $query = "SELECT * FROM #__k2_extra_fields WHERE `group`=" . $db->Quote($group) . " AND published=1 ORDER BY ordering"; $db->setQuery($query); $extraFields = $db->loadObjectList(); $json = new Services_JSON(); $output = ''; if (count($extraFields)) { $output .= '<h1>' . JText::_('K2_EXTRA_FIELDS') . '</h1>'; $output .= '<h2>' . JText::_('K2_ORIGINAL') . '</h2>'; foreach ($extraFields as $extrafield) { $extraField = $json->decode($extrafield->value); $output .= trim($this->renderOriginal($extrafield, $reference_id)); } } if (count($extraFields)) { $output .= '<h2>' . JText::_('K2_TRANSLATION') . '</h2>'; foreach ($extraFields as $extrafield) { $extraField = $json->decode($extrafield->value); $output .= trim($this->renderTranslated($extrafield, $reference_id)); } } $pattern = '/\\r\\n|\\r|\\n/'; // *** Mootools Snippet *** $js = "\n\t\t\twindow.addEvent('domready', function(){\n\t\t\t\tvar target = \$\$('table.adminform');\n\t\t\t\ttarget.setProperty('id', 'adminform');\n\t\t\t\tvar div = new Element('div', {'id': 'K2ExtraFields'}).setHTML('" . preg_replace($pattern, '', $output) . "').injectInside(\$('adminform'));\n\t\t\t});\n\t\t\t"; if (K2_JVERSION == '15') { JHTML::_('behavior.mootools'); } else { JHTML::_('behavior.framework'); } $document = JFactory::getDocument(); $document->addScriptDeclaration($js); // *** Embedded CSS Snippet *** $document->addCustomTag(' <style type="text/css" media="all"> #K2ExtraFields { color:#000; font-size:11px; padding:6px 2px 4px 4px; text-align:left; } #K2ExtraFields h1 { font-size:16px; height:25px; } #K2ExtraFields h2 { font-size:14px; } #K2ExtraFields strong { font-style:italic; } </style> '); } if ($option == 'com_joomfish' && ($task == 'translate.apply' || $task == 'translate.save') && $type == 'k2_extra_fields') { $language_id = JRequest::getInt('select_language_id'); $reference_id = JRequest::getInt('reference_id'); $extraFieldType = JRequest::getVar('extraFieldType'); $objects = array(); $values = JRequest::getVar('option_value'); $names = JRequest::getVar('option_name'); $target = JRequest::getVar('option_target'); for ($i = 0; $i < sizeof($values); $i++) { $object = new JObject(); $object->set('name', $names[$i]); if ($extraFieldType == 'select' || $extraFieldType == 'multipleSelect' || $extraFieldType == 'radio') { $object->set('value', $i + 1); } elseif ($extraFieldType == 'link') { if (substr($values[$i], 0, 7) == 'http://') { $values[$i] = $values[$i]; } else { $values[$i] = 'http://' . $values[$i]; } $object->set('value', $values[$i]); } else { $object->set('value', $values[$i]); } $object->set('target', $target[$i]); unset($object->_errors); $objects[] = $object; } $json = new Services_JSON(); $value = $json->encode($objects); $user = JFactory::getUser(); $db = JFactory::getDBO(); $query = "SELECT COUNT(*) FROM #__jf_content WHERE reference_field = 'value' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_extra_fields'"; $db->setQuery($query); $result = $db->loadResult(); if ($result > 0) { $query = "UPDATE #__jf_content SET value=" . $db->Quote($value) . " WHERE reference_field = 'value' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_extra_fields'"; $db->setQuery($query); $db->query(); } else { $modified = date("Y-m-d H:i:s"); $modified_by = $user->id; $published = JRequest::getVar('published', 0); $query = "INSERT INTO #__jf_content (`id`, `language_id`, `reference_id`, `reference_table`, `reference_field` ,`value`, `original_value`, `original_text`, `modified`, `modified_by`, `published`) VALUES (NULL, {$language_id}, {$reference_id}, 'k2_extra_fields', 'value', " . $db->Quote($value) . ", '','', " . $db->Quote($modified) . ", {$modified_by}, {$published} )"; $db->setQuery($query); $db->query(); } } if ($option == 'com_joomfish' && ($task == 'translate.edit' || $task == 'translate.apply') && $type == 'k2_extra_fields') { if ($task == 'translate.edit') { $cid = JRequest::getVar('cid'); $array = explode('|', $cid[0]); $reference_id = $array[1]; } if ($task == 'translate.apply') { $reference_id = JRequest::getInt('reference_id'); } $extraField = JTable::getInstance('K2ExtraField', 'Table'); $extraField->load($reference_id); $language_id = JRequest::getInt('select_language_id'); if ($extraField->type == 'multipleSelect' || $extraField->type == 'select' || $extraField->type == 'radio') { $subheader = '<strong>' . JText::_('K2_OPTIONS') . '</strong>'; } else { $subheader = '<strong>' . JText::_('K2_DEFAULT_VALUE') . '</strong>'; } $json = new Services_JSON(); $objects = $json->decode($extraField->value); $output = '<input type="hidden" value="' . $extraField->type . '" name="extraFieldType" />'; if (count($objects)) { $output .= '<h1>' . JText::_('K2_EXTRA_FIELDS') . '</h1>'; $output .= '<h2>' . JText::_('K2_ORIGINAL') . '</h2>'; $output .= $subheader . '<br />'; foreach ($objects as $object) { $output .= '<p>' . $object->name . '</p>'; if ($extraField->type == 'textfield' || $extraField->type == 'textarea') { $output .= '<p>' . $object->value . '</p>'; } } } $db = JFactory::getDBO(); $query = "SELECT `value` FROM #__jf_content WHERE reference_field = 'value' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_extra_fields'"; $db->setQuery($query); $result = $db->loadResult(); $translatedObjects = $json->decode($result); if (count($objects)) { $output .= '<h2>' . JText::_('K2_TRANSLATION') . '</h2>'; $output .= $subheader . '<br />'; foreach ($objects as $key => $value) { if (isset($translatedObjects[$key])) { $value = $translatedObjects[$key]; } if ($extraField->type == 'textarea') { $output .= '<p><textarea name="option_name[]" cols="30" rows="15"> ' . $value->name . '</textarea></p>'; } else { $output .= '<p><input type="text" name="option_name[]" value="' . $value->name . '" /></p>'; } $output .= '<p><input type="hidden" name="option_value[]" value="' . $value->value . '" /></p>'; $output .= '<p><input type="hidden" name="option_target[]" value="' . $value->target . '" /></p>'; } } $pattern = '/\\r\\n|\\r|\\n/'; // *** Mootools Snippet *** $js = "\n\t\t\twindow.addEvent('domready', function(){\n\t\t\t\tvar target = \$\$('table.adminform');\n\t\t\t\ttarget.setProperty('id', 'adminform');\n\t\t\t\tvar div = new Element('div', {'id': 'K2ExtraFields'}).setHTML('" . preg_replace($pattern, '', $output) . "').injectInside(\$('adminform'));\n\t\t\t});\n\t\t\t"; JHTML::_('behavior.mootools'); $document = JFactory::getDocument(); $document->addScriptDeclaration($js); } return; }
public static function getItems(&$params, $format = 'html') { jimport('joomla.filesystem.file'); $mainframe = JFactory::getApplication(); $limit = $params->get('itemCount', 5); $cid = $params->get('category_id', NULL); $ordering = $params->get('itemsOrdering', ''); $componentParams = JComponentHelper::getParams('com_k2'); $limitstart = JRequest::getInt('limitstart'); $user = JFactory::getUser(); $aid = $user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); if ($params->get('source') == 'specific') { $value = $params->get('items'); $current = array(); if (is_string($value) && !empty($value)) { $current[] = $value; } if (is_array($value)) { $current = $value; } $items = array(); foreach ($current as $id) { $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams \n\t\t\t\tFROM #__k2_items as i \n\t\t\t\tLEFT JOIN #__k2_categories c ON c.id = i.catid \n\t\t\t\tWHERE i.published = 1 "; if (K2_JVERSION != '15') { $query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; } else { $query .= " AND i.access<={$aid} "; } $query .= " AND i.trash = 0 AND c.published = 1 "; if (K2_JVERSION != '15') { $query .= " AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; } else { $query .= " AND c.access<={$aid} "; } $query .= " AND c.trash = 0 \n\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " ) \n\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " ) \n\t\t\t\tAND i.id={$id}"; if (K2_JVERSION != '15') { if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")"; } } $db->setQuery($query); $item = $db->loadObject(); if ($item) { $items[] = $item; } } } else { $query = "SELECT i.*, CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams"; if ($ordering == 'best') { $query .= ", (r.rating_sum/r.rating_count) AS rating"; } if ($ordering == 'comments') { $query .= ", COUNT(comments.id) AS numOfComments"; } $query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid"; if ($ordering == 'best') { $query .= " LEFT JOIN #__k2_rating r ON r.itemID = i.id"; } if ($ordering == 'comments') { $query .= " LEFT JOIN #__k2_comments comments ON comments.itemID = i.id"; } if (K2_JVERSION != '15') { $query .= " WHERE i.published = 1 AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND i.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND c.trash = 0"; } else { $query .= " WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0"; } $query .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )"; $query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )"; if ($params->get('catfilter')) { if (!is_null($cid)) { if (is_array($cid)) { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { JArrayHelper::toInteger($cid); $query .= " AND i.catid IN(" . implode(',', $cid) . ")"; } } else { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { $query .= " AND i.catid=" . (int) $cid; } } } } if ($params->get('FeaturedItems') == '0') { $query .= " AND i.featured != 1"; } if ($params->get('FeaturedItems') == '2') { $query .= " AND i.featured = 1"; } if ($ordering == 'comments') { $query .= " AND comments.published = 1"; } if (K2_JVERSION != '15') { if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")"; } } switch ($ordering) { case 'date': $orderby = 'i.created ASC'; break; case 'rdate': $orderby = 'i.created DESC'; break; case 'alpha': $orderby = 'i.title'; break; case 'ralpha': $orderby = 'i.title DESC'; break; case 'order': if ($params->get('FeaturedItems') == '2') { $orderby = 'i.featured_ordering'; } else { $orderby = 'i.ordering'; } break; case 'rorder': if ($params->get('FeaturedItems') == '2') { $orderby = 'i.featured_ordering DESC'; } else { $orderby = 'i.ordering DESC'; } break; case 'hits': if ($params->get('popularityRange')) { $datenow = JFactory::getDate(); $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) "; } $orderby = 'i.hits DESC'; break; case 'rand': $orderby = 'RAND()'; break; case 'best': $orderby = 'rating DESC'; break; case 'comments': if ($params->get('popularityRange')) { $datenow = JFactory::getDate(); $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) "; } $query .= " GROUP BY i.id "; $orderby = 'numOfComments DESC'; break; case 'modified': $orderby = 'lastChanged DESC'; break; case 'publishUp': $orderby = 'i.publish_up DESC'; break; default: $orderby = 'i.id DESC'; break; } $query .= " ORDER BY " . $orderby; $db->setQuery($query, 0, $limit); $items = $db->loadObjectList(); } $model = K2Model::getInstance('Item', 'K2Model'); if (count($items)) { foreach ($items as $item) { //Clean title $item->title = JFilterOutput::ampReplace($item->title); //Images if ($params->get('itemImage')) { $date = JFactory::getDate($item->modified); $timestamp = '?t=' . $date->toUnix(); if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XS.jpg')) { $item->imageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageXSmall .= $timestamp; } } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) { $item->imageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageSmall .= $timestamp; } } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_M.jpg')) { $item->imageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageMedium .= $timestamp; } } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) { $item->imageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageLarge .= $timestamp; } } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XL.jpg')) { $item->imageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageXLarge .= $timestamp; } } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_Generic.jpg')) { $item->imageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageGeneric .= $timestamp; } } $image = 'image' . $params->get('itemImgSize', 'Small'); if (isset($item->{$image})) { $item->image = $item->{$image}; } } //Read more link $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias)))); //Category link $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias)))); // Introtext $item->text = ''; if ($params->get('itemIntroText')) { // Word limit if ($params->get('itemIntroTextWordLimit')) { $item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit')); } else { $item->text .= $item->introtext; } } // Restore the intotext variable after plugins execution $item->introtext = $item->text; //Clean the plugin tags $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext); $rows[] = $item; } return $rows; } }
function trash() { $mainframe = JFactory::getApplication(); $db = JFactory::getDBO(); $cid = JRequest::getVar('cid'); $row = JTable::getInstance('K2Category', 'Table'); JArrayHelper::toInteger($cid); K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models'); $model = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $model->getCategoryTree($cid); $sql = @implode(',', $categories); $db = JFactory::getDBO(); $query = "UPDATE #__k2_categories SET trash=1 WHERE id IN ({$sql})"; $db->setQuery($query); $db->query(); $query = "UPDATE #__k2_items SET trash=1 WHERE catid IN ({$sql})"; $db->setQuery($query); $db->query(); $cache = JFactory::getCache('com_k2'); $cache->clean(); $mainframe->redirect('index.php?option=com_k2&view=categories', JText::_('K2_CATEGORIES_MOVED_TO_TRASH')); }
public static function getUsers($params) { $model = K2Model::getInstance('Users'); if ($params->get('source') == 'specific' && $params->get('userIDs')) { if (is_array($params->get('userIDs'))) { $ids = $params->get('userIDs'); } else { $ids = array(); $ids[] = $params->get('userIDs'); } $users = array(); $model->setState('block', 0); foreach ($ids as $id) { $model->setState('id', $id); $users = array_merge($users, $model->getRows()); } } else { $users = array(); switch ($params->get('filter', 'mostItems')) { case 'mostItems': $model->setState('limit', $params->get('limit', 4)); $rows = $model->getTopAuthors(); foreach ($rows as $row) { $users[] = K2Users::getInstance($row->userId); } break; case 'mostPopularItems': // Get database $db = JFactory::getDbo(); // Get query $query = $db->getQuery(true); // Select statement $query->select('DISTINCT(' . $db->quoteName('item.created_by') . ')'); $query->from($db->quoteName('#__k2_items', 'item')); $query->where($db->quoteName('item.created_by_alias') . ' = ' . $db->quote('')); $query->rightJoin($db->quoteName('#__k2_items_stats', 'stats') . ' ON ' . $db->quoteName('stats.itemId') . ' = ' . $db->quoteName('item.id')); // Sorting $query->order($db->quoteName('stats.hits') . ' DESC'); // Set the query $db->setQuery($query, 0, (int) $params->get('limit', 4)); // Get the result $rows = $db->loadObjectList(); foreach ($rows as $row) { $users[] = K2Users::getInstance($row->created_by); } break; case 'mostCommentedItems': // Get database $db = JFactory::getDbo(); // Get query $query = $db->getQuery(true); // Select statement $query->select('DISTINCT(' . $db->quoteName('item.created_by') . ')'); $query->from($db->quoteName('#__k2_items', 'item')); $query->where($db->quoteName('item.created_by_alias') . ' = ' . $db->quote('')); $query->rightJoin($db->quoteName('#__k2_items_stats', 'stats') . ' ON ' . $db->quoteName('stats.itemId') . ' = ' . $db->quoteName('item.id')); // Sorting $query->order($db->quoteName('stats.comments') . ' DESC'); // Set the query $db->setQuery($query, 0, (int) $params->get('limit', 4)); // Get the result $rows = $db->loadObjectList(); foreach ($rows as $row) { $users[] = K2Users::getInstance($row->created_by); } break; } } foreach ($users as $user) { if ($params->get('userItemCount')) { $model = K2Model::getInstance('Items'); $model->setState('site', true); $model->setState('author', $user->id); $model->setState('limit', $params->get('userItemCount')); $user->items = $model->getRows(); } else { $user->items = array(); } } return $users; }