简体   繁体   中英

How say to this joomla module to take me to my SEF url article?

This module takes the articles from categories in joomla and displays them like a blog (short of). the problem is when i click on the title it gives a &view=item&layout=edit&sliderid=1&id=2 . non friendly, and the link opens the article in my home page. how to make it produce the correct SEF link like suppose to do? I use joomla 3 and mod_rewrite is enabled

Here is the code:

defined('_JEXEC') or die('Restricted access');
    require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');

class PBHSourceJcontent {

public $arg;

public function loadFromDB($itemId = -1) {

    $myQuery = 'SELECT 
                i.* 
                FROM #__content as i 
                WHERE 1=1 
                AND i.state = 1';
    if ($itemId < 0 && !empty($this->arg['categories'])) {
        $myQuery .= ' AND i.catid IN (' .implode(',',$this->arg['categories']). ')';
    }
    if ($this->arg['ordering'] == 'random' && !empty($this->arg['loaded_items'])) {
        $myQuery .= ' AND i.id NOT IN ('.implode(',',$this->arg['loaded_items']).')';
    }
    if ($itemId < 0 && !empty($this->arg['ordering'])) {
        switch ($this->arg['ordering']) {
            case 'title_asc': 
                $myQuery .= ' ORDER BY i.title ASC';
                break;
            case 'title_desc': 
                $myQuery .= ' ORDER BY i.title DESC';
                break;
            case 'date_asc': 
                $myQuery .= ' ORDER BY i.publish_up ASC';
                break;
            case 'hits_desc': 
                $myQuery .= ' ORDER BY i.hits DESC';
                break;
            case 'hits_asc': 
                $myQuery .= ' ORDER BY i.hits ASC';
                break;
            case 'article_order': 
                $myQuery .= ' ORDER BY i.ordering ASC';
                break;
            case 'random':
                $myQuery .= ' ORDER BY RAND()';
                break;
            default: 
                $myQuery .= ' ORDER BY i.publish_up DESC';
                break;
        }
    }
    if ($itemId < 0 && !empty($this->arg['items_number'])) {
        $myQuery .= ' LIMIT ' . $this->arg['items_number'];
    }
    if ($itemId < 0 && !empty($this->arg['items_offset']) && $this->arg['items_offset'] > 0 && $this->arg['ordering'] != 'random') {
        $myQuery .= ' OFFSET ' . $this->arg['items_offset'];
    }
    if ($itemId < 0) {
        return DMHData::loadObjectList($myQuery);
    } else {
        $myQuery .= ' AND i.id = ' . $itemId;
        return DMHData::loadObject($myQuery);
    }
}

public function getItemId($item) {

    return $item->id;
}

public function getItemUrl($item) {

    if ($this->arg['previewpopup'] == 'enabled') {
        $myLink = 'href="#" onclick="DMPinboard.getPreview('.$item->id.');return false;"';
    } else {
        $link = 'index.php?option=com_content&view=article&id='.$item->id;
        $link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
        $myLink = 'href="'.urldecode($link).'"';
    }

    return $myLink;
}

public function getItemTitle($item) {

    if ($this->arg['show_title'] == 'yes') {
        return $item->title;
    } else {
        return '';
    }
}

public function getItemImage($item) {

    if ($this->arg['show_image'] == 'fromtext') {
        $myImage = '';
        $output = preg_match( '/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $item->introtext, $matches);
        if ($output > 0) {
            $myImage = $matches[1];
        }
        return $myImage;
    } else if($this->arg['show_image'] == 'introimg') {
        $images = json_decode($item->images);
        return $images->image_intro;
    } else if ($this->arg['show_image'] == 'fullimg') {
        $images = json_decode($item->images);
        return $images->image_fulltext;
    } else {
        return '';
    }
}

public function getItemIntro($item) {

    if ($this->arg['show_intro'] == 'yes') {
        $outText = str_replace(array("\t","\n","\r","\r\n"),'',strip_tags($item->introtext));
        if (!empty($this->arg['introlength']) && $this->arg['introlength'] > 0) {
            $outText = PBHHtml::shorter($outText, $this->arg['introlength']);
        }
        return $outText;
    } else {
        return '';
    }
}

public function getPreviewImage($item) {

    if ($this->arg['show_popup_images'] == 'fromtext') {
        $myImage = '';
        $output = preg_match('/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $item->introtext, $matches);
        if ($output > 0) {
            $myImage = $matches[1];
        }
        return $myImage;
    } else if ($this->arg['show_popup_images'] == 'fullimg') {
        $images = json_decode($item->images);
        return $images->image_fulltext;
    } else {
        return '';
    }
}

public function getPreviewTitle($item) {

    if ($this->arg['show_popup_title'] == 'linked') {
        $link = 'index.php?option=com_content&view=article&id='.$item->id;
        $link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
        return '<a href="'.urldecode($link).'">'.$item->title.'</a>';
    } else if ($this->arg['show_popup_title'] == 'yes') {
        return $item->title;
    } else {
        return '';
    }
}

public function getPreviewContent($item) {

    if ($this->arg['show_popup_intro'] == 'withoutimg') {
        $outText = preg_replace('/<img[^>]+\>/i', '', $item->introtext);
    } else if($this->arg['show_popup_intro'] == 'yes') {
        $outText = preg_replace_callback('/(src=["\'])([^"\']+)(["\'])/','PBHHtml::checkImgSrc',$item->introtext);
    } else {
        $outText = '';
    }
    if (!empty($this->arg['previewlength']) && $this->arg['previewlength'] > 0) {
        $outText = PBHHtml::truncate_teaser($outText,$this->arg['previewlength']);
    }
    return $outText;
}

public function getPreviewReadmore($item) {

    if ($this->arg['show_popup_articlelink'] == 'yes') {
        $link = 'index.php?option=com_content&view=article&id='.$item->id;
        $link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
        return '<a href="'.urldecode($link).'">'.JText::_('COM_DMPINBOARD_FRONTEND_READMORE').'</a>';
    } else {
        return '';
    }
}

public function getShareInfo($item) {

    $share = array();
    //---
    $link = 'index.php?option=com_content&view=article&id='.$item->id;
    $link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
    $share['url'] = urldecode(JUri::base().$link);
    //---
    $share['title'] = $item->title;
    return $share;
}

}

?>

I am assuming you mean to output a SEF url in the second part of the getItemUrl($item) function.

Simply

$link = JRoute::_('index.php?option=com_content&view=article&id='.$item->id);

will do. However in your question, above your code, you show &view=item&layout=edit&sliderid=1&id=2 which is not the url in the code below, and will not take you to the article view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM