示例#1
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/tags';
        if ($this->multiple) {
            $title = JText::_('K2_ADD_TAGS');
            $tags = array();
            if ($this->value) {
                foreach ($this->value as $tagId) {
                    $tags[] = K2Tags::getInstance($tagId);
                }
            }
            $js = "\n\t\t\tfunction K2SelectRow(row) {\n\t\t\t\tvar tagAlreadyInList = 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_TAG_IS_ALREADY_IN_THE_LIST') . "');\n\t\t\t\t\t\ttagAlreadyInList = true;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tif(!tagAlreadyInList){\n\t\t\t\t\tvar li = '<li><a class=\"k2FieldResourceRemove\"><i class=\"icon icon-cancel\"></i></a><span class=\"k2FieldResourceMultipleHandle\">' + row.get('name') + '</span><input type=\"hidden\" value=\"' + row.get('id') + '\" name=\"" . $this->name . "[]\"/></li>';\n\t\t\t\t\tjQuery('#" . $this->id . " .k2FieldTagsMultiple').append(li);\n\t\t\t\t\tjQuery('#" . $this->id . " ul').sortable('refresh');\n\t\t\t\t\talert('" . JText::_('K2_TAG_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_TAGS') . '"  href="' . $link . '"><i class="icon-list"></i>' . JText::_('K2_ADD_TAGS') . '</a>';
            $html .= '<ul class="k2FieldResourceMultiple k2FieldTagsMultiple">';
            foreach ($tags as $tag) {
                $html .= '
				<li>
					<a class="k2FieldResourceRemove"><i class="icon icon-cancel"></i></a>
					<span class="k2FieldResourceMultipleHandle">' . $tag->name . '</span>
					<input type="hidden" value="' . $tag->id . '" name="' . $this->name . '[]"/>
				</li>
				';
            }
            $html .= '</ul></div>';
        } else {
            $title = JText::_('K2_SELECT_A_TAG');
            if ($this->value) {
                $tag = K2Tags::getInstance($this->value);
                $title = $tag->name;
            }
            $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('name');\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_A_TAG') . '"  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;
    }
 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;
 }
示例#3
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;
 }
示例#4
0
 public function getTags()
 {
     $result = array();
     $instances = array();
     $tags = json_decode($this->_tags);
     if ($this->id && is_array($tags) && count($tags)) {
         $tagIds = array();
         foreach ($tags as $tag) {
             if (K2Tags::loaded($tag->id)) {
                 $instance = K2Tags::getInstance($tag->id);
                 if ($instance->state) {
                     $instances[] = $instance;
                 }
             } else {
                 $tagIds[] = (int) $tag->id;
             }
         }
         if (count($tagIds)) {
             $application = JFactory::getApplication();
             $model = K2Model::getInstance('Tags');
             if ($application->isSite()) {
                 $model->setState('state', 1);
             }
             $model->setState('id', $tagIds);
             $rows = $model->getRows();
             $result = array_merge($instances, $rows);
         } else {
             $result = $instances;
         }
     }
     return $result;
 }
示例#5
0
 protected function setUserStates()
 {
     $this->setUserState('persist', 1, 'int');
     $this->setUserState('limit', 10, 'int', $this->getUserState('persist'));
     $this->setUserState('page', 1, 'int');
     $this->setUserState('search', '', 'string');
     $this->setUserState('access', 0, 'int');
     $this->setUserState('state', '', 'cmd');
     $this->setUserState('featured', '', 'cmd');
     $this->setUserState('category', 0, 'cmd', $this->getUserState('persist'));
     $this->setUserState('author', 0, 'int');
     $this->setUserState('tag', 0, 'int');
     $this->setUserState('language', '', 'string');
     $this->setUserState('sorting', '', 'string');
     $this->setUserState('recursive', JComponentHelper::getParams('com_k2')->get('showChildCatItems'), 'int');
     if ($this->getUserState('author') > 0) {
         $this->setUserState('authorName', JFactory::getUser($this->getUserState('author'))->name, 'string', false);
     }
     if ($this->getUserState('tag') > 0) {
         $this->setUserState('tagName', K2Tags::getInstance($this->getUserState('tag'))->name, 'string', false);
     }
 }
示例#6
0
 protected function getTagItems($count = false)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $id = $application->input->get('id', 0, 'int');
     // Determine offset and limit based on document type
     if ($this->type == 'html' || $this->type == 'raw') {
         $this->limit = $application->input->get('limit', 10, 'int');
     } else {
         $this->limit = $this->params->get('feedLimit', 10, 'int');
     }
     // Get tag
     $this->tag = K2Tags::getInstance($id);
     // Check access and publishing state
     $this->tag->checkSiteAccess();
     // Get items
     $model = K2Model::getInstance('Items');
     $model->setState('site', true);
     $model->setState('tag', $id);
     $model->setState('limit', $this->limit);
     $model->setState('limitstart', $this->offset);
     // @TODO Apply menu settings. Since they will be common all tasks we need to wait
     //$model->setState('sorting', 'created.reverse');
     $this->items = $model->getRows();
     // Count items
     if ($count) {
         $this->total = $model->countRows();
     }
 }