Esempio n. 1
0
function listlisting_cache($cat_id, $option, $listListing)
{
    global $savantConf, $Itemid;
    $database =& JFactory::getDBO();
    # Retrieve Links
    $listListing->setSubcats(getSubCats_Recursive($cat_id));
    $listListing->prepareQuery();
    $links = $listListing->getListings();
    # Load custom template
    loadCustomTemplate($cat_id, $savantConf);
    # Savant Template
    $savant = new Savant2($savantConf);
    assignCommonListlinksVar($savant, $links, new mtPathWay(), $listListing->getPageNav());
    $savant->assign('title', $listListing->getHeader());
    $savant->display('page_listListings.tpl.php');
}
Esempio n. 2
0
function rss($option, $type, $cat_id = 0)
{
    global $mtconf;
    $database =& JFactory::getDBO();
    $info = null;
    $rss = null;
    $jdate = JFactory::getDate();
    $now = $jdate->toMySQL();
    $nullDate = $database->getNullDate();
    $rss = new MTRSSCreator20();
    if ($type == 'new') {
        $filename = $mtconf->getjconf('cachepath') . '/mtreeNew' . ($cat_id ? '-' . $cat_id : '') . '.xml';
    } else {
        $filename = $mtconf->getjconf('cachepath') . '/mtreeUpdated' . ($cat_id ? '-' . $cat_id : '') . '.xml';
    }
    $rss->useCached($filename);
    switch ($type) {
        case 'updated':
            $rss->title = $mtconf->getjconf('sitename') . $mtconf->get('rss_title_separator') . JText::_('Recently updated listing');
            break;
        case 'new':
        default:
            $rss->title = $mtconf->getjconf('sitename') . $mtconf->get('rss_title_separator') . JText::_('New listing');
            break;
    }
    if ($cat_id > 0) {
        $mtCats = new mtCats($database);
        $cat_name = $mtCats->getName($cat_id);
        $rss->title .= $mtconf->get('rss_title_separator') . $cat_name;
    }
    $rss->link = JURI::root();
    $rss->cssStyleSheet = NULL;
    $rss->feedURL = $mtconf->getjconf('live_site') . $_SERVER['PHP_SELF'];
    $database->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_mtree' AND published='1' LIMIT 1");
    $Itemid = $database->loadResult();
    $sql = "SELECT l.*, u.username, u.name AS owner, c.cat_id, c.cat_name FROM (#__mt_links AS l, #__mt_cl AS cl, #__users AS u, #__mt_cats AS c) " . "WHERE link_published='1' && link_approved='1' " . "\n AND ( publish_up = " . $database->Quote($nullDate) . " OR publish_up <= '{$now}'  ) " . "\n AND ( publish_down = " . $database->Quote($nullDate) . " OR publish_down >= '{$now}' ) " . "\n AND l.link_id = cl.link_id " . "\n AND cl.main = 1 " . "\n AND cl.cat_id = c.cat_id " . "\n AND l.user_id = u.id ";
    if ($cat_id > 0) {
        $subcats = getSubCats_Recursive($cat_id);
        if (count($subcats) > 1) {
            $sql .= ' AND cl.cat_id IN (' . implode(',', $subcats) . ')';
        }
    }
    switch ($type) {
        case 'updated':
            $sql .= "ORDER BY l.link_modified DESC ";
            break;
        case 'new':
        default:
            $sql .= "ORDER BY l.link_created DESC ";
            break;
    }
    if ($mtconf->get('rss_' . $type . '_limit') > 0) {
        $sql .= "LIMIT " . intval($mtconf->get('rss_' . $type . '_limit'));
    }
    $database->setQuery($sql);
    $links = $database->loadObjectList();
    # Get first image of each listings
    if ($mtconf->get('show_image_rss') && !empty($links)) {
        foreach ($links as $link) {
            $link_ids[] = $link->link_id;
        }
        $database->setQuery('SELECT link_id, filename FROM #__mt_images WHERE link_id IN (' . implode(', ', $link_ids) . ') AND ordering = 1 LIMIT ' . count($link_ids));
        $link_images = $database->loadObjectList('link_id');
    }
    # Get arrays if link_ids
    foreach ($links as $link) {
        $link_ids[] = $link->link_id;
    }
    # Additional elements from core fields
    $core_fields = array('cat_name', 'cat_url', 'link_votes', 'link_rating', 'address', 'city', 'postcode', 'state', 'country', 'email', 'website', 'telephone', 'fax', 'metakey', 'metadesc');
    $additional_elements = array();
    foreach ($core_fields as $core_field) {
        if ($mtconf->get('rss_' . $core_field)) {
            $additional_elements[] = $core_field;
        }
    }
    # Additional elements from custom fields
    $custom_fields = trim($mtconf->get('rss_custom_fields'));
    $custom_fields_values = array();
    if (!empty($custom_fields) && count($link_ids) > 0) {
        $array_custom_fields = explode(',', $custom_fields);
        foreach ($array_custom_fields as $key => $value) {
            if (intval($value) > 0) {
                $array_custom_fields[$key] = intval($value);
                $additional_elements[] = 'cust_' . $array_custom_fields[$key];
            } else {
                unset($array_custom_fields[$key]);
            }
        }
        if (count($array_custom_fields) > 0) {
            $database->setQuery('SELECT cf_id, link_id, value FROM #__mt_cfvalues WHERE cf_id IN (' . implode(',', $array_custom_fields) . ') AND link_id IN (' . implode(',', $link_ids) . ') LIMIT ' . count($array_custom_fields) * count($link_ids));
            $array_custom_fields_values = $database->loadObjectList();
            foreach ($array_custom_fields_values as $array_custom_fields_value) {
                $custom_fields_values[$array_custom_fields_value->link_id][$array_custom_fields_value->cf_id] = $array_custom_fields_value->value;
            }
        }
    }
    $uri =& JURI::getInstance(JURI::base());
    $host = $uri->toString(array('scheme', 'host', 'port'));
    $thumbnail_path = $mtconf->get('relative_path_to_listing_small_image');
    foreach ($links as $link) {
        $item = new FeedItem();
        $item->title = $link->link_name;
        $item->link = $host . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id=" . $link->link_id . "&Itemid=" . $Itemid);
        $item->guid = $host . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id=" . $link->link_id . "&Itemid=" . $Itemid);
        $item->description = '';
        if ($mtconf->get('show_image_rss') && isset($link_images[$link->link_id]) && !empty($link_images[$link->link_id]->filename)) {
            $item->description .= '<img align="right" src="' . $mtconf->getjconf('live_site') . $thumbnail_path . $link_images[$link->link_id]->filename . '" alt="' . $link->link_name . '" />';
        }
        $item->description .= $link->link_desc;
        //optional
        $item->descriptionHtmlSyndicated = true;
        switch ($type) {
            case 'updated':
                $item->date = strtotime($link->link_modified);
                break;
            case 'new':
            default:
                $item->date = strtotime($link->link_created);
                break;
        }
        $item->source = $mtconf->getjconf('live_site');
        // $item->author = $link->owner;
        $item->author = $link->username;
        if (count($additional_elements) > 0) {
            $ae = array();
            foreach ($additional_elements as $additional_element) {
                if (in_array($additional_element, $core_fields)) {
                    if ($additional_element == 'cat_url') {
                        $ae['mtree:' . $additional_element] = htmlspecialchars(JRoute::_('index.php?option=com_mtree&task=listcats&cat_id=' . $link->cat_id . '&Itemid=' . $Itemid));
                    } else {
                        $ae['mtree:' . $additional_element] = '<![CDATA[' . $link->{$additional_element} . ']]>';
                    }
                } else {
                    $cf_id = substr($additional_element, 5);
                    if (array_key_exists($link->link_id, $custom_fields_values) && array_key_exists($cf_id, $custom_fields_values[$link->link_id])) {
                        $ae['mtree:' . $additional_element] = '<![CDATA[' . str_replace('|', ',', $custom_fields_values[$link->link_id][$cf_id]) . ']]>';
                    }
                }
            }
            $item->additionalElements = $ae;
        }
        $rss->addItem($item);
    }
    echo $rss->saveFeed($filename);
}