Beispiel #1
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get document
     $document = JFactory::getDocument();
     // Legacy
     $moduleId = $application->input->get('moduleID', 0, 'int');
     if ($moduleId) {
         $application->input->set('task', 'module');
         $application->input->set('id', $moduleId);
     }
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     // Trigger the corresponding subview
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Load the comments counters in a single query for all items
     $params = JComponentHelper::getParams('com_k2');
     if ($params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Add items to feed
     foreach ($this->items as $item) {
         // Add item
         $document->addItem($this->getFeedItem($item));
     }
 }
Beispiel #2
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $id = $application->input->get('id', 0, 'int');
     // Get item
     $this->item = K2Items::getInstance($id);
     // Check access
     $this->item->checkSiteAccess();
     // Merge menu params with category params
     $effectiveParams = $this->item->category->getEffectiveParams();
     $this->params->merge($effectiveParams);
     // Merge params with item params
     $this->params->merge($this->item->params);
     // Get the image depending on params
     $this->item->image = $this->item->getImage($this->params->get('itemImgSize'));
     // Trigger plugins. We need to do this there in order to provide the correct context
     $this->item->events = $this->item->getEvents('com_k2.item', $this->params, 0);
     // Get related items. We need to do this here since the parameter is related with the view
     if ($this->params->get('itemRelated')) {
         $this->item->related = $this->item->getRelated($this->params->get('itemRelatedLimit', 5));
     }
     // Get latest from same author. We need to do this here since the parameter is related with the view
     if ($this->params->get('itemAuthorLatest')) {
         $this->item->author->latest = $this->item->getLatestByAuthor($this->params->get('itemAuthorLatestLimit', 5));
     }
     // Set the layout
     $this->setLayout('item');
     // Add the template path
     $this->addTemplatePath(JPATH_SITE . '/components/com_k2/templates/' . $this->item->category->template);
     $this->addTemplatePath(JPATH_SITE . '/templates/' . JFactory::getApplication()->getTemplate() . '/html/com_k2/' . $this->item->category->template);
     // Display
     parent::display($tpl);
 }
Beispiel #3
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     $this->offset = $application->input->get('limitstart', 0, 'int');
     $this->limit = $application->input->get('limit', 10, 'int');
     // Trigger the corresponding method
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Generate the view params depedning on the task prefix. This let's us have one common layout file for listing items
     $this->generateItemlistParams($task);
     // Load the comments counters in a single query for all items
     if ($this->params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Plugins
     foreach ($this->items as $item) {
         $item->events = $item->getEvents('com_k2.itemlist.' . $task, $this->params, $this->offset);
     }
     // Pagination
     jimport('joomla.html.pagination');
     $this->pagination = new JPagination($this->total, $this->offset, $this->limit);
     // Display
     parent::display($tpl);
 }
Beispiel #4
0
    public function getInput()
    {
        JHtml::_('jquery.framework');
        // Load required scripts
        $document = JFactory::getDocument();
        $document->addStyleSheet(JURI::root(true) . '/media/k2app/vendor/magnific/magnific-popup.css?v=3.0.0');
        $document->addScript(JURI::root(true) . '/media/k2app/vendor/magnific/jquery.magnific-popup.min.js?v=3.0.0');
        $document->addScript(JURI::root(true) . '/media/k2app/vendor/sortable/jquery-sortable-min.js?v=3.0.0');
        $document->addScript(JURI::root(true) . '/media/k2app/assets/js/fields.js?v=3.0.0');
        $this->multiple = (bool) $this->element['k2multiple'];
        $link = JURI::root(true) . '/administrator/index.php?option=com_k2&tmpl=component#modal/items';
        if ($this->multiple) {
            $title = JText::_('K2_ADD_ITEMS');
            $items = array();
            if ($this->value) {
                foreach ($this->value as $itemId) {
                    $items[] = K2Items::getInstance($itemId);
                }
            }
            $js = "\n\t\t\tfunction K2SelectRow(row) {\n\t\t\t\tvar itemAlreadyInList = false;\n\t\t\t\tjQuery('#" . $this->id . " input').each(function(){\n\t\t\t\t\tif(jQuery(this).val() == row.get('id')){\n\t\t\t\t\t\talert('" . JText::_('K2_THE_SELECTED_ITEM_IS_ALREADY_IN_THE_LIST') . "');\n\t\t\t\t\t\titemAlreadyInList = true;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tif(!itemAlreadyInList){\n\t\t\t\t\tvar li = '<li><a class=\"k2FieldResourceRemove\">" . JText::_('K2_REMOVE_ENTRY_FROM_LIST') . "</a><span class=\"k2FieldResourceMultipleHandle\">' + row.get('title') + '</span><input type=\"hidden\" value=\"' + row.get('id') + '\" name=\"" . $this->name . "[]\"/></li>';\n\t\t\t\t\tjQuery('#" . $this->id . " .k2FieldItemsMultiple').append(li);\n\t\t\t\t\tjQuery('#" . $this->id . " ul').sortable('refresh');\n\t\t\t\t\talert('" . JText::_('K2_ITEM_ADDED_IN_THE_LIST', true) . "');\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $document->addScriptDeclaration($js);
            $html = '<div id="' . $this->id . '"><a class="k2Modal btn" title="' . JText::_('K2_ADD_ITEMS') . '"  href="' . $link . '"><i class="icon-list"></i>' . JText::_('K2_ADD_ITEMS') . '</a>';
            $html .= '<ul class="k2FieldResourceMultiple k2FieldItemsMultiple">';
            foreach ($items as $item) {
                $html .= '
				<li>
					<a class="k2FieldResourceRemove">' . JText::_('K2_REMOVE_ENTRY_FROM_LIST') . '</a>
					<span class="k2FieldResourceMultipleHandle">' . $item->title . '</span>
					<input type="hidden" value="' . $item->id . '" name="' . $this->name . '[]"/>
				</li>
				';
            }
            $html .= '</ul></div>';
        } else {
            $title = JText::_('K2_SELECT_AN_ITEM');
            if ($this->value) {
                $item = K2Items::getInstance($this->value);
                $title = $item->title;
            }
            $js = "\n\t\t\tfunction K2SelectRow(row) {\n\t\t\t\tdocument.getElementById('" . $this->name . "' + '_id').value = row.get('id');\n\t\t\t\tdocument.getElementById('" . $this->name . "' + '_name').value = row.get('title');\n\t\t\t\tjQuery.magnificPopup.close();\n\t\t\t}\n\t\t\t";
            $document->addScriptDeclaration($js);
            $html = '<span class="input-append">
            <input type="text" id="' . $this->name . '_name" value="' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '" disabled="disabled" />
            <a class="k2Modal btn" title="' . JText::_('K2_SELECT_AN_ITEM') . '"  href="' . $link . '"><i class="icon-list"></i>' . JText::_('K2_SELECT') . '</a>
            <input type="hidden" class="required modal-value" id="' . $this->name . '_id" name="' . $this->name . '" value="' . (int) $this->value . '" />
            </span>';
        }
        return $html;
    }
Beispiel #5
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     $this->offset = $application->input->get('limitstart', 0, 'int');
     $this->limit = $application->input->get('limit', 10, 'int');
     // Trigger the corresponding method
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Generate the view params depedning on the task prefix. This let's us have one common layout file for listing items
     $this->generateItemlistParams($task);
     // Load the comments counters in a single query for all items
     if ($this->params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Plugins
     foreach ($this->items as $item) {
         $item->events = $item->getEvents('com_k2.itemlist.' . $task, $this->params, $this->offset);
     }
     // Add feed link
     $this->feedLink = JRoute::_('&format=feed&limitstart=');
     // Add feed links to head
     if ($this->feedLinkToHead) {
         $attributes = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $this->document->addHeadLink(JRoute::_('&format=feed&limitstart=&type=rss'), 'alternate', 'rel', $attributes);
         $attributes = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $this->document->addHeadLink(JRoute::_('&format=feed&limitstart=&type=atom'), 'alternate', 'rel', $attributes);
     }
     // Pagination
     jimport('joomla.html.pagination');
     $this->pagination = new JPagination($this->total, $this->offset, $this->limit);
     // Display
     try {
         parent::display($tpl);
     } catch (Exception $e) {
         if ($this->_template === false) {
             $this->setLayout('itemlist');
         }
         parent::display($tpl);
     }
 }
 public function resetHits()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // User
     $user = JFactory::getUser();
     // Item
     $application = JFactory::getApplication();
     $id = $application->input->get('id');
     $item = K2Items::getInstance($id);
     if (!$item->canEdit) {
         K2Response::throwError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION'), 403);
     }
     $statistics = K2Model::getInstance('Statistics');
     $statistics->resetItemHitsCounter($item->id);
     echo json_encode(K2Response::render());
     return $this;
 }
Beispiel #7
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     $this->offset = $application->input->get('limitstart', 0, 'int');
     $this->limit = $application->input->get('limit', 10, 'int');
     $callback = $application->input->get('callback', '', 'cmd');
     // Trigger the corresponding subview
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Response
     $response = new stdClass();
     $response->site = new stdClass();
     $response->site->url = JURI::root();
     $response->site->name = $application->getCfg('sitename');
     $response->items = array();
     // Load the comments counters in a single query for all items
     $params = JComponentHelper::getParams('com_k2');
     if ($params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Add items to JSON
     foreach ($this->items as $item) {
         // Add item
         $response->items[] = $this->getJsonItem($item);
     }
     // Encode response
     $response = json_encode($response);
     // Output
     if ($callback) {
         $this->document->setMimeEncoding('application/javascript');
         echo $callback . '(' . $response . ')';
     } else {
         echo $response;
     }
 }
 public function upload()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // Get user
     $user = JFactory::getUser();
     // Get input
     $type = $this->input->get('type', '', 'cmd');
     $itemId = $this->input->get('itemId', 0, 'int');
     $replace = $this->input->get('temp', '', 'cmd');
     $file = $this->input->files->get('file');
     $path = $this->input->get('path', '', 'string');
     $path = str_replace(JURI::root(true) . '/', '', $path);
     $categoryId = null;
     // Permissions check
     if ($itemId) {
         if ($type == 'item') {
             $item = K2Items::getInstance($itemId);
             $authorised = $item->canEdit;
             $categoryId = $item->catid;
         } else {
             if ($type == 'category') {
                 $authorised = K2Categories::getInstance($itemId)->canEdit;
             } else {
                 if ($type == 'user') {
                     $authorised = $user->authorise('core.edit', 'com_users') || $user->id == $itemId;
                 }
             }
         }
     } else {
         $authorised = $user->authorise('k2.' . $type . '.create', 'com_k2');
     }
     if (!$authorised) {
         K2Response::throwError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION'), 403);
     }
     // Generate image using helper depending on type
     $image = K2HelperImages::add($type, $file, $path, $replace, $categoryId);
     // Response
     echo json_encode($image);
     return $this;
 }
 public function render()
 {
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/helpers/extrafields.php';
     $input = JFactory::getApplication()->input;
     $scope = $input->get('scope', '', 'cmd');
     $resourceId = $input->get('resourceId', 0, 'int');
     $filterId = $input->get('filterId', 0, 'raw');
     if ($scope == 'item') {
         require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/items.php';
         $item = K2Items::getInstance($resourceId);
         $values = $item->extra_fields;
         $fields = K2HelperExtraFields::getItemExtraFieldsGroups((int) $filterId, $values);
     } else {
         if ($scope == 'category') {
             require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/categories.php';
             $category = K2Categories::getInstance($resourceId);
             $values = $category->extra_fields;
             $fields = K2HelperExtraFields::getCategoryExtraFieldsGroups($values);
         } else {
             if ($scope == 'user') {
                 require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/users.php';
                 $user = K2Users::getInstance($resourceId);
                 $values = $user->extra_fields;
                 $fields = K2HelperExtraFields::getUserExtraFieldsGroups($values);
             } else {
                 if ($scope == 'tag') {
                     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/tags.php';
                     $tag = K2Tags::getInstance($resourceId);
                     $values = $tag->extra_fields;
                     $fields = K2HelperExtraFields::getTagExtraFieldsGroups($values);
                 }
             }
         }
     }
     echo json_encode($fields);
     return $this;
 }
Beispiel #10
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $id = $application->input->get('id', 0, 'int');
     $callback = $application->input->get('callback', '', 'cmd');
     // Get item
     $this->item = K2Items::getInstance($id);
     // Check access
     $this->item->checkSiteAccess();
     // Merge menu params with category params
     $effectiveParams = $this->item->category->getEffectiveParams();
     $this->params->merge($effectiveParams);
     // Merge params with item params
     $this->params->merge($this->item->params);
     // Get the image depending on params
     $this->item->image = $this->item->getImage($this->params->get('itemImgSize'));
     // Trigger plugins. We need to do this there in order to provide the correct context
     $this->item->events = $this->item->getEvents('com_k2.item', $this->params, 0);
     // Response
     $response = new stdClass();
     $response->site = new stdClass();
     $response->site->url = JURI::root();
     $response->site->name = $application->getCfg('sitename');
     $response->item = $this->getJsonItem($this->item);
     // Encode response
     $response = json_encode($response);
     // Output
     if ($callback) {
         $this->document->setMimeEncoding('application/javascript');
         echo $callback . '(' . $response . ')';
     } else {
         echo $response;
     }
 }
Beispiel #11
0
 public static function getBreadcrumbs($params)
 {
     $application = JFactory::getApplication();
     $option = $application->input->get('option', '', 'cmd');
     $view = $application->input->get('view', '', 'cmd');
     $task = $application->input->get('task', '', 'cmd');
     $id = $application->input->get('id', 0, 'int');
     $menu = $application->getMenu();
     $active = $menu->getActive();
     $breadcrumbs = new stdClass();
     $breadcrumbs->title = '';
     $breadcrumbs->path = array();
     $breadcrumbs->home = $params->get('home', JText::_('K2_HOME'));
     $breadcrumbs->separator = $params->get('seperator', '&raquo;');
     $pathway = $application->getPathway();
     $pathwayItems = $pathway->getPathWay();
     foreach ($pathwayItems as $pathwayItem) {
         $pathwayItem->title = $pathwayItem->name;
     }
     if ($option == 'com_k2' && $view == 'item' || $view == 'itemlist' && $task == 'category') {
         switch ($view) {
             case 'item':
                 // Get item
                 $item = K2Items::getInstance($id);
                 // Check for menu link
                 $matchItem = $active && isset($active->query['view']) && $active->query['view'] == 'item' && isset($active->query['id']) && $active->query['id'] == $id;
                 $matchCategory = $active && isset($active->query['view']) && $active->query['view'] == 'itemlist' && isset($active->query['task']) && $active->query['task'] == 'category' && isset($active->query['id']) && $active->query['id'] == $item->catid;
                 // Handle depending on matches
                 if ($matchItem) {
                     $breadcrumbs->title = end($pathwayItems)->title;
                     foreach ($pathwayItems as $pathwayItem) {
                         $breadcrumbs->path[] = $pathwayItem;
                     }
                     array_pop($breadcrumbs->path);
                 } else {
                     if ($matchCategory) {
                         $breadcrumbs->title = $item->title;
                         foreach ($pathwayItems as $pathwayItem) {
                             $breadcrumbs->path[] = $pathwayItem;
                         }
                         array_pop($breadcrumbs->path);
                     } else {
                         $breadcrumbs->title = $item->title;
                         $categories = explode('/', $item->category->path);
                         foreach ($categories as $alias) {
                             $breadcrumbs->path[] = K2Categories::getInstance($alias);
                         }
                     }
                 }
                 break;
             case 'itemlist':
                 // Check for menu link
                 $matchCategory = $active && isset($active->query['view']) && $active->query['view'] == 'itemlist' && isset($active->query['task']) && $active->query['task'] == 'category' && isset($active->query['id']) && $active->query['id'] == $id;
                 // Handle depending on matches
                 if ($matchCategory) {
                     $breadcrumbs->title = end($pathwayItems)->title;
                     foreach ($pathwayItems as $pathwayItem) {
                         $breadcrumbs->path[] = $pathwayItem;
                     }
                 } else {
                     $category = K2Categories::getInstance($id);
                     $breadcrumbs->title = $category->title;
                     $categories = explode('/', $category->path);
                     foreach ($categories as $alias) {
                         $breadcrumbs->path[] = K2Categories::getInstance($alias);
                     }
                 }
                 array_pop($breadcrumbs->path);
                 break;
         }
     } else {
         $breadcrumbs->title = count($pathwayItems) ? end($pathwayItems)->title : '';
         foreach ($pathwayItems as $pathwayItem) {
             $breadcrumbs->path[] = $pathwayItem;
         }
         array_pop($breadcrumbs->path);
     }
     return $breadcrumbs;
 }
Beispiel #12
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $id = $application->input->get('id', 0, 'int');
     // Get item
     $this->item = K2Items::getInstance($id);
     // Check access
     $this->item->checkSiteAccess();
     // Merge menu params with category params
     $effectiveParams = $this->item->category->getEffectiveParams();
     $this->params->merge($effectiveParams);
     // Merge params with item params
     $this->params->merge($this->item->params);
     // Get the image depending on params
     $this->item->image = $this->item->getImage($this->params->get('itemImgSize'));
     // Trigger plugins. We need to do this there in order to provide the correct context
     $this->item->events = $this->item->getEvents('com_k2.item', $this->params, 0);
     // Image modal
     JHtml::_('behavior.modal', 'a.k2Modal');
     // Load head data for comments and inline editing if required
     if ($this->item->canEdit || $this->params->get('itemComments') && $this->params->get('comments') && empty($this->item->events->K2CommentsCounter) && empty($this->item->events->K2CommentsBlock)) {
         // Common
         JHtml::_('behavior.keepalive');
         $this->document->addScriptDeclaration('var K2SitePath = "' . JUri::root(true) . '";');
         $this->document->addScriptDeclaration('var K2SessionToken = "' . JSession::getFormToken() . '";');
         // Comments
         if ($this->params->get('itemComments') && $this->params->get('comments') && empty($this->item->events->K2CommentsCounter) && empty($this->item->events->K2CommentsBlock)) {
             // Check if user can comment
             $this->user->canComment = $this->user->authorise('k2.comment.create', 'com_k2');
             // Load comments requirements
             $this->document->addScript(JURI::root(true) . '/media/k2app/vendor/underscore/underscore-min.js');
             $this->document->addScript(JURI::root(true) . '/media/k2app/vendor/backbone/backbone-min.js');
             $this->document->addScript(JURI::root(true) . '/media/k2app/vendor/marionette/backbone.marionette.min.js');
             $this->document->addScript(JURI::root(true) . '/media/k2app/app/sync.js');
             require_once JPATH_SITE . '/components/com_k2/helpers/captcha.php';
             K2HelperCaptcha::initialize();
         }
         // Inline editing
         if ($this->item->canEdit) {
             $this->document->addScript('//cdn.ckeditor.com/4.4.6/standard/ckeditor.js');
         }
     }
     // Get related items. We need to do this here since the parameter is related with the view
     if ($this->params->get('itemRelated')) {
         $this->item->related = $this->item->getRelated($this->params->get('itemRelatedLimit', 5));
         foreach ($this->item->related as $related) {
             $related->image = $related->getImage($this->params->get('itemRelatedImageSize'));
         }
     }
     // Get latest from same author. We need to do this here since the parameter is related with the view
     if ($this->params->get('itemAuthorLatest')) {
         $this->item->author->latest = $this->item->getLatestByAuthor($this->params->get('itemAuthorLatestLimit', 5));
     }
     // Increase hits counter
     $this->item->hit();
     // Set metadata
     $this->setMetadata($this->item);
     // Set Facebook meta data
     if ($this->params->get('facebookMetadata')) {
         $this->document->setMetaData('og:url', $this->item->url);
         $this->document->setMetaData('og:title', $this->document->getTitle());
         $this->document->setMetaData('og:type', 'article');
         $this->document->setMetaData('og:description', $this->document->getDescription());
         $facebookImage = $this->item->getImage($this->params->get('facebookMetadataImageSize'));
         if ($facebookImage) {
             $this->document->setMetaData('og:image', $facebookImage->url);
         }
     }
     // Set the layout
     $this->setLayout('item');
     // Add the template path
     $this->addTemplatePath(JPATH_SITE . '/components/com_k2/templates/' . $this->item->category->template);
     $this->addTemplatePath(JPATH_SITE . '/templates/' . JFactory::getApplication()->getTemplate() . '/html/com_k2/' . $this->item->category->template);
     // Display
     parent::display($tpl);
 }
Beispiel #13
0
 public function getCopyData($id)
 {
     // Get params
     $params = JComponentHelper::getParams('com_k2');
     // Get source item
     $source = K2Items::getInstance($id);
     // Get source item properties as data array. This array will be the inout to the model.
     $data = get_object_vars($source);
     // It's a new item so reset some properties
     $data['id'] = '';
     $data['tmpId'] = uniqid();
     $data['title'] = JText::_('K2_COPY_OF') . ' ' . $data['title'];
     $data['alias'] = '';
     $data['tags'] = json_decode($data['_tags']);
     $data['media'] = json_decode($data['_media']);
     $data['galleries'] = json_decode($data['_galleries']);
     $data['extra_fields'] = json_decode($data['extra_fields']);
     $data['metadata'] = $data['metadata']->toString();
     $data['plugins'] = $data['plugins']->toString();
     $data['params'] = $data['params']->toString();
     unset($data['ordering']);
     unset($data['featured_ordering']);
     // Handle tags
     $tagNames = array();
     if (is_array($data['tags'])) {
         foreach ($data['tags'] as $tag) {
             $tagNames[] = $tag->name;
         }
     }
     $data['tags'] = implode(',', $tagNames);
     // Handle image
     if (isset($data['images']) && is_array($data['images']) && isset($data['images']['src'])) {
         // If filesystem is not local then path is the URL
         $filesystem = $params->get('filesystem');
         $path = $filesystem == 'Local' || !$filesystem ? 'media/k2/items/src/' . $data['images']['src']->id . '.jpg' : $data['images']['src']->url;
         $image = K2HelperImages::add('item', null, $path);
         $data['image'] = array('id' => '', 'temp' => $image->temp, 'path' => '', 'remove' => 0, 'caption' => $data['image']->caption, 'credits' => $data['image']->credits);
     } else {
         unset($data['image']);
     }
     // Handle media
     $media = array();
     if (is_array($data['media'])) {
         foreach ($data['media'] as $key => $entry) {
             if ($entry->upload) {
                 $filesystem = K2FileSystem::getInstance();
                 if ($filesystem->has('media/k2/media/' . $id . '/' . $entry->upload)) {
                     $buffer = $filesystem->read('media/k2/media/' . $id . '/' . $entry->upload);
                     JFile::write(JPATH_SITE . '/tmp/' . $entry->upload, $buffer);
                 }
             }
             $newEntry = array();
             $newEntry['url'] = $entry->url;
             $newEntry['provider'] = $entry->provider;
             $newEntry['id'] = $entry->id;
             $newEntry['embed'] = $entry->embed;
             $newEntry['caption'] = $entry->caption;
             $newEntry['credits'] = $entry->credits;
             $newEntry['upload'] = $entry->upload;
             $newEntry['remove'] = 0;
             $media[$key] = $newEntry;
         }
     }
     $data['media'] = $media;
     // Handle galleries
     $galleries = array();
     if (is_array($data['galleries'])) {
         foreach ($data['galleries'] as $key => $entry) {
             if ($entry->upload) {
                 $filesystem = K2FileSystem::getInstance();
                 if ($filesystem->has('media/k2/galleries/' . $id . '/' . $entry->upload)) {
                     JFolder::create(JPATH_SITE . '/tmp/' . $entry->upload);
                     $files = $filesystem->listKeys('media/k2/galleries/' . $id . '/' . $entry->upload);
                     foreach ($files['keys'] as $key) {
                         if ($filesystem->has($key)) {
                             $buffer = $filesystem->read($key);
                             JFile::write(JPATH_SITE . '/tmp/' . $entry->upload . '/' . basename($key), $buffer);
                         }
                     }
                 }
             }
             $newEntry = array();
             $newEntry['url'] = $entry->url;
             $newEntry['upload'] = $entry->upload;
             $newEntry['remove'] = 0;
             $galleries[$key] = $newEntry;
         }
     }
     $data['galleries'] = $galleries;
     // Handle attachments
     $filesystem = K2FileSystem::getInstance();
     $attachmentsModel = K2Model::getInstance('Attachments');
     $attachments = array();
     $data['attachments'] = $source->getAttachments();
     foreach ($data['attachments'] as $key => $attachment) {
         // Prepare the data array
         $newEntry = array();
         $newEntry['id'] = '';
         $newEntry['name'] = $attachment->name;
         $newEntry['title'] = $attachment->title;
         if ($attachment->file) {
             $tmpId = uniqid();
             if ($filesystem->has('media/k2/attachments/' . $id . '/' . $attachment->file)) {
                 $buffer = $filesystem->read('media/k2/attachments/' . $id . '/' . $attachment->file);
                 JFile::write(JPATH_SITE . '/tmp/' . $tmpId . '_' . $attachment->file, $buffer);
             }
             $newEntry['file'] = $tmpId . '_' . $attachment->file;
         }
         $newEntry['path'] = $attachment->path;
         $newEntry['remove'] = 0;
         $attachments[$key] = $newEntry;
     }
     $data['attachments'] = $attachments;
     // Return the input data
     return $data;
 }
 /**
  * onBeforeDelete method. 		Hook for chidlren model.
  *
  * @param   JTable  $table     	The table object.
  *
  * @return boolean
  */
 protected function onBeforeDelete($table)
 {
     // Permissions check
     if ($table->itemId > 0) {
         require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/items.php';
         $item = K2Items::getInstance($table->itemId);
         if ($item && !$item->canEdit) {
             $this->setError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION'));
             return false;
         }
     }
     // Delete any associated files
     $this->deleteFile($table);
     return true;
 }
Beispiel #15
0
 public static function getItems($params)
 {
     // Component params
     $componentParams = JComponentHelper::getParams('com_k2');
     // Get model
     $model = K2Model::getInstance('Items');
     // Set site state
     $model->setState('site', true);
     // Set states depending on source
     if ($params->get('source') == 'specific') {
         $items = array();
         if ($params->get('items')) {
             $itemIds = array_filter((array) $params->get('items'));
             if (count($itemIds)) {
                 // Apply sorting
                 foreach ($itemIds as $itemId) {
                     // Fetch item
                     $model->setState('id', $itemId);
                     $items[] = $model->getRow();
                 }
             }
         }
     } else {
         // Category filter
         $model->setState('category.filter', $params->get('filter'));
         // Featured
         if ($params->get('featured') == 2) {
             $model->setState('featured', 1);
         } else {
             if ($params->get('featured') == 0) {
                 $model->setState('featured', 0);
             }
         }
         // Set time range if sorting is comments or hits
         if ($params->get('timeRange') && ($params->get('sorting') == 'comments' || $params->get('sorting') == 'hits')) {
             $now = JFactory::getDate();
             switch ($params->get('timeRange')) {
                 case '1':
                     $interval = 'P1D';
                     break;
                 case '3':
                     $interval = 'P3D';
                     break;
                 case '7':
                     $interval = 'P1W';
                     break;
                 case '15':
                     $interval = 'P2W';
                     break;
                 case '30':
                     $interval = 'P1M';
                     break;
                 case '90':
                     $interval = 'P3M';
                     break;
                 case '180':
                     $interval = 'P6M';
                     break;
             }
             $date = $now->sub(new DateInterval($interval));
             $model->setState('created.value', $date->toSql());
             $model->setState('created.operator', '>');
         }
         // Fetch only items with media
         if ($params->get('media')) {
             $model->setState('media', true);
         }
         // Set limit
         $model->setState('limit', $params->get('limit'));
         // Set sorting
         $model->setState('sorting', $params->get('sorting'));
         // Get items
         $items = $model->getRows();
     }
     // Prepare data
     foreach ($items as $item) {
         // Plugins
         $item->events = $item->getEvents('mod_k2_content', $params, 0, $params->get('k2Plugins'), $params->get('jPlugins'));
         // Introtext word limit
         if ($params->get('itemIntroTextWordLimit')) {
             $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
         }
         // Set the selected image as default
         $item->image = $item->getImage($params->get('itemImgSize'));
     }
     // Load the comments counters in a single query for all items
     if ($params->get('itemCommentsCounter') && $componentParams->get('comments')) {
         K2Items::countComments($items);
     }
     // Set the avatar width if it's inherited from component settings
     if ($params->get('itemAuthorAvatarWidthSelect') == 'custom') {
         $params->set('itemAuthorAvatarWidth', $componentParams->get('userImageWidth'));
     }
     // Set the custom link url if user has selected a menu link item
     if ($params->get('itemCustomLinkMenuItem') && $params->get('itemCustomLink')) {
         $application = JFactory::getApplication();
         $menu = $application->getMenu();
         $menuLink = $menu->getItem($params->get('itemCustomLinkMenuItem'));
         if ($menuLink) {
             if (!$params->get('itemCustomLinkTitle')) {
                 $params->set('itemCustomLinkTitle', $menuLink->title);
             }
             $params->set('itemCustomLinkURL', JRoute::_('index.php?&Itemid=' . $menuLink->id));
         }
     }
     // Return
     return $items;
 }
Beispiel #16
0
 /**
  * Parse the route for the K2 component using the advanced SEF options in legacy mode
  *
  * @param  array  An array of URL arguments
  *
  * @return  void
  */
 private function advancedParseLegacy($segments)
 {
     // Initialize
     $vars = array();
     $reservedViews = array('item', 'itemlist', 'media', 'users', 'comments', 'latest');
     if (!in_array($segments[0], $reservedViews)) {
         // Category view
         if ($segments[0] == $this->params->get('k2SefLabelCat', 'content')) {
             $segments[0] = 'itemlist';
             array_splice($segments, 1, 0, 'category');
             if (!$this->params->get('k2SefInsertCatId')) {
                 $category = K2categories::getInstance($segments[2]);
                 $segments[2] = $category->id . ':' . $category->alias;
             }
         } elseif ($segments[0] == $this->params->get('k2SefLabelTag', 'tag')) {
             $segments[0] = 'itemlist';
             array_splice($segments, 1, 0, 'tag');
         } elseif ($segments[0] == $this->params->get('k2SefLabelUser', 'author')) {
             $segments[0] = 'itemlist';
             array_splice($segments, 1, 0, 'user');
         } elseif ($segments[0] == $this->params->get('k2SefLabelDate', 'date')) {
             $segments[0] = 'itemlist';
             array_splice($segments, 1, 0, 'date');
         } elseif ($segments[0] == $this->params->get('k2SefLabelSearch', 'search')) {
             $segments[0] = 'itemlist';
             array_splice($segments, 1, 0, 'search');
         } else {
             // Replace the category prefix with item
             if ($this->params->get('k2SefLabelItem')) {
                 $segments[0] = 'item';
             } else {
                 array_splice($segments, 0, 0, 'item');
             }
             // Reinsert item id to the item alias
             if (!$this->params->get('k2SefInsertItemId') && @$segments[1] != 'download' && @$segments[1] != 'edit') {
                 $segments[1] = str_replace(':', '-', $segments[1]);
                 $item = K2Items::getInstance($segments[1]);
                 $ItemId = $item->id;
                 $segments[1] = $ItemId . ':' . $segments[1];
             }
         }
     }
     $vars['view'] = $segments[0];
     if (!isset($segments[1])) {
         $segments[1] = '';
     }
     $vars['task'] = $segments[1];
     if ($segments[0] == 'itemlist') {
         switch ($segments[1]) {
             case 'category':
                 if (isset($segments[2])) {
                     $vars['id'] = $segments[2];
                 }
                 break;
             case 'tag':
                 if (isset($segments[2])) {
                     $tag = K2Tags::getInstance($segments[2]);
                     $vars['id'] = $tag->id;
                 }
                 break;
             case 'user':
                 if (isset($segments[2])) {
                     $vars['id'] = $segments[2];
                 }
                 break;
             case 'date':
                 if (isset($segments[2])) {
                     $vars['year'] = $segments[2];
                 }
                 if (isset($segments[3])) {
                     $vars['month'] = $segments[3];
                 }
                 if (isset($segments[4])) {
                     $vars['day'] = $segments[4];
                 }
                 break;
         }
     } elseif ($segments[0] == 'item') {
         switch ($segments[1]) {
             case 'add':
             case 'edit':
                 if (isset($segments[2])) {
                     $vars['cid'] = $segments[2];
                 }
                 break;
             case 'download':
                 if (isset($segments[2])) {
                     $vars['id'] = $segments[2];
                 }
                 break;
             default:
                 $vars['id'] = $segments[1];
                 if (isset($segments[2])) {
                     $vars['id'] .= ':' . str_replace(':', '-', $segments[2]);
                 }
                 unset($vars['task']);
                 break;
         }
     }
     if ($segments[0] == 'comments' && isset($segments[1]) && $segments[1] == 'reportSpammer') {
         $vars['id'] = $segments[2];
     }
     return $vars;
 }
<?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;
}
 public function report()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // Get application
     $application = JFactory::getApplication();
     // Get configuration
     $configuration = JFactory::getConfig();
     // Get input
     $id = $application->input->get('id', 0, 'int');
     $reportName = $application->input->get('reportName', '', 'string');
     $reportReason = $application->input->get('reportReason', '', 'string');
     // Get params
     $params = JComponentHelper::getParams('com_k2');
     // Get user
     $user = JFactory::getUser();
     // Check if user can report
     if (!$params->get('comments') || !$params->get('commentsReporting') || $params->get('commentsReporting') == '2' && $user->guest) {
         K2Response::throwError(JText::_('K2_ALERTNOTAUTH'), 403);
     }
     // Get comment
     $comment = K2Comments::getInstance($id);
     // Check comment is published
     if (!$comment->state) {
         K2Response::throwError(JText::_('K2_COMMENT_NOT_FOUND'));
     }
     // Get item
     $item = K2Items::getInstance($comment->itemId);
     // Check access to the item
     $item->checkSiteAccess();
     // Check input
     if (trim($reportName) == '') {
         K2Response::throwError(JText::_('K2_PLEASE_TYPE_YOUR_NAME'));
     }
     if (trim($reportReason) == '') {
         K2Response::throwError(JText::_('K2_PLEASE_TYPE_THE_REPORT_REASON'));
     }
     // Check captcha depending on settings
     require_once JPATH_SITE . '/components/com_k2/helpers/captcha.php';
     $data = $this->getInputData();
     if (!($result = K2HelperCaptcha::check($data, $this))) {
         K2Response::throwError($this->getError());
     }
     $mailer = JFactory::getMailer();
     $senderEmail = $configuration->get('mailfrom');
     $senderName = $configuration->get('fromname');
     $mailer->setSender(array($senderEmail, $senderName));
     $mailer->setSubject(JText::_('K2_COMMENT_REPORT'));
     $mailer->IsHTML(true);
     $body = "\n        <strong>" . JText::_('K2_NAME') . "</strong>: " . $reportName . " <br/>\n        <strong>" . JText::_('K2_REPORT_REASON') . "</strong>: " . $reportReason . " <br/>\n        <strong>" . JText::_('K2_COMMENT') . "</strong>: " . nl2br($comment->text) . " <br/>\n        ";
     $mailer->setBody($body);
     $mailer->ClearAddresses();
     $mailer->AddAddress($params->get('commentsReportRecipient', $configuration->get('mailfrom')));
     $mailer->Send();
     $application->enqueueMessage(JText::_('K2_REPORT_SUBMITTED'));
     echo json_encode(K2Response::render());
     return $this;
 }