Exemplo n.º 1
0
function editlink($link_id, $cat_id, $for_approval = false, $option)
{
    global $mainframe, $mtconf;
    $database =& JFactory::getDBO();
    $my =& JFactory::getUser();
    $row = new mtLinks($database);
    $row->load($link_id);
    if ($row->link_id == 0) {
        $createdate =& JFactory::getDate();
        $row->cat_id = $cat_id;
        $row->alias = '';
        $row->link_hits = 0;
        $row->link_visited = 0;
        $row->link_votes = 0;
        $row->link_rating = 0.0;
        $row->link_featured = 0;
        $row->link_created = $createdate->toUnix();
        $row->publish_up = $createdate->toUnix();
        $row->publish_down = JText::_('Never');
        $row->link_published = 1;
        $row->link_approved = 1;
        $row->user_id = $my->id;
        $row->owner = $my->username;
    } else {
        if ($row->user_id > 0) {
            $database->setQuery('SELECT username FROM #__users WHERE id =' . $database->quote($row->user_id));
            $row->owner = $database->loadResult();
        } else {
            $row->owner = $my->username;
        }
    }
    if ($cat_id == 0 && $row->cat_id > 0) {
        $cat_id = $row->cat_id;
    }
    # Load images
    $database->setQuery('SELECT img_id, filename FROM #__mt_images WHERE link_id = ' . $database->quote($row->link_id) . ' ORDER BY ordering ASC');
    $images = $database->loadObjectList();
    $lists = array();
    # Load all published CORE & custom fields
    $sql = "SELECT cf.*, " . ($row->link_id ? $row->link_id : 0) . " AS link_id, cfv.value, cfv.attachment, cfv.counter, ft.ft_class FROM #__mt_customfields AS cf " . "\nLEFT JOIN #__mt_cfvalues AS cfv ON cf.cf_id=cfv.cf_id AND cfv.link_id = " . $database->quote($link_id) . "\nLEFT JOIN #__mt_fieldtypes AS ft ON ft.field_type=cf.field_type" . "\nWHERE cf.published='1' ORDER BY ordering ASC";
    $database->setQuery($sql);
    $fields = new mFields();
    $fields->setCoresValue($row->link_name, $row->link_desc, $row->address, $row->city, $row->state, $row->country, $row->postcode, $row->telephone, $row->fax, $row->email, $row->website, $row->price, $row->link_hits, $row->link_votes, $row->link_rating, $row->link_featured, $row->link_created, $row->link_modified, $row->link_visited, $row->publish_up, $row->publish_down, $row->metakey, $row->metadesc, $row->user_id, $row->owner);
    $fields->loadFields($database->loadObjectList());
    # Get other categories
    $database->setQuery('SELECT cl.cat_id FROM #__mt_cl AS cl WHERE cl.link_id = ' . $database->quote($link_id) . ' AND cl.main = 0');
    $other_cats = $database->loadResultArray();
    # Get Pathway
    $pathWay = new mtPathWay($cat_id);
    # Is this approval for modification?
    if ($row->link_approved < 0) {
        $row->original_link_id = -1 * $row->link_approved;
    } else {
        $row->original_link_id = '';
    }
    # Compile list of categories
    if ($cat_id > 0) {
        $database->setQuery('SELECT cat_parent FROM #__mt_cats WHERE cat_id = ' . $database->quote($cat_id));
        $browse_cat_parent = $database->loadResult();
    }
    $categories = array();
    if ($cat_id > 0) {
        $categories[] = JHTML::_('select.option', $browse_cat_parent, JText::_('Arrow back'));
    }
    $database->setQuery('SELECT cat_id AS value, cat_name AS text FROM #__mt_cats' . "\nWHERE cat_parent = " . $database->quote($cat_id) . " AND cat_approved = '1' AND cat_published = '1' ORDER BY cat_name ASC");
    $categories = array_merge($categories, $database->loadObjectList());
    $lists['cat_id'] = JHTML::_('select.genericlist', $categories, 'new_cat_id', 'size="8" class="text_area" style="display:block;width:50%;margin-top:6px;"', 'value', 'text', $row->getCatID(), 'browsecat');
    # Get Return task - Used by listpending_links
    $returntask = JRequest::getCmd('returntask', '', 'post');
    # Get params definitions
    $form = new JParameter($row->attribs, JPATH_COMPONENT . DS . 'models' . DS . 'listing.xml');
    $form->set('owner', $row->owner);
    $form->set('alias', $row->alias);
    $form->set('link_approved', $row->link_approved);
    $form->set('link_published', $row->link_published);
    $form->set('link_featured', $row->link_featured);
    $form->set('link_created', JHTML::_('date', $row->link_created, '%Y-%m-%d %H:%M:%S'));
    $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
    if (JHTML::_('date', $row->publish_down, '%Y') <= 1969 || $row->publish_down == $database->getNullDate()) {
        $form->set('publish_down', JText::_('Never'));
    } else {
        $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
    }
    $form->set('link_template', $row->link_template);
    $form->set('metakey', $row->metakey);
    $form->set('metadesc', $row->metadesc);
    $form->set('link_rating', $row->link_rating);
    $form->set('link_votes', $row->link_votes);
    $form->set('link_hits', $row->link_hits);
    $form->set('link_visited', $row->link_visited);
    $form->set('internal_notes', $row->internal_notes);
    $form->loadINI($row->attribs);
    if ($row->link_approved <= 0) {
        $database->setQuery('SELECT link_id FROM #__mt_links WHERE link_approved <= 0 ORDER BY link_created ASC, link_modified DESC');
        $links = $database->loadResultArray();
        $number_of_prev = array_search($row->link_id, $links);
        $number_of_next = count($links) - 1 - $number_of_prev;
    } else {
        $number_of_prev = 0;
        $number_of_next = 0;
    }
    HTML_mtree::editlink($row, $fields, $images, $cat_id, $other_cats, $lists, $number_of_prev, $number_of_next, $pathWay, $returntask, $form, $option);
}
Exemplo n.º 2
0
function mtAppendPathWay($option, $task, $cat_id = 0, $link_id = 0, $img_id = 0)
{
    global $mainframe, $Itemid;
    $database =& JFactory::getDBO();
    $mtPathWay = new mtPathWay();
    $pathway =& $mainframe->getPathway();
    switch ($task) {
        case "listcats":
        case "addcategory":
            // Show "Add Category Path?"
            $cids = $mtPathWay->getPathWay($cat_id);
            break;
        case "viewlink":
        case "writereview":
        case "rate":
        case "recommend":
        case "viewgallery":
            $mtLink = new mtLinks($database);
            $mtLink->load($link_id);
            $cat_id = $mtLink->getCatID();
            $cids = $mtPathWay->getPathWay($cat_id);
            break;
        case "viewimage":
            if ($img_id > 0) {
                $database->setQuery('SELECT link_id FROM #__mt_images WHERE img_id = \'' . $img_id . '\' LIMIT 1');
                $link_id = $database->loadResult();
                if (!is_null($link_id)) {
                    $mtLink = new mtLinks($database);
                    $mtLink->load($link_id);
                    $cat_id = $mtLink->getCatID();
                    $cids = $mtPathWay->getPathWay($cat_id);
                }
            }
            break;
            // Adding listing from a category
        // Adding listing from a category
        case "addlisting":
            if ($cat_id > 0) {
                $cids = $mtPathWay->getPathWay($cat_id);
            } elseif ($link_id > 0) {
                $mtLink = new mtLinks($database);
                $mtLink->load($link_id);
                $cat_id = $mtLink->getCatID();
                $cids = $mtPathWay->getPathWay($cat_id);
            }
            // Show "Add Listing" Path?
            break;
        case "listnew":
            $pathway->addItem(JText::_('New listing'));
            break;
        case "listfeatured":
            $pathway->addItem(JText::_('Featured listing'));
            break;
        case "listpopular":
            $pathway->addItem(JText::_('Popular listing'));
            break;
        case "listmostrated":
            $pathway->addItem(JText::_('Most rated listing'));
            break;
        case "listtoprated":
            $pathway->addItem(JText::_('Top rated listing'));
            break;
        case "listmostreview":
            $pathway->addItem(JText::_('Most reviewed listing'));
            break;
        case "advsearch":
            $pathway->addItem(JText::_('Advanced search'));
            break;
        case "advsearch2":
            $pathway->addItem(JText::_('Advanced search results'));
            break;
        case "search":
            $pathway->addItem(JText::_('Search results'));
            break;
    }
    if (isset($cids) && is_array($cids) && count($cids) > 0) {
        foreach ($cids as $cid) {
            $pathway->addItem($mtPathWay->getCatName($cid), "index.php?option={$option}&task=listcats&cat_id={$cid}");
        }
        // Append the curreny category name
        $pathway->addItem($mtPathWay->getCatName($cat_id), "index.php?option={$option}&task=listcats&cat_id={$cat_id}");
    } elseif ($cat_id > 0) {
        $pathway->addItem($mtPathWay->getCatName($cat_id), "index.php?option={$option}&task=listcats&cat_id={$cat_id}");
    }
    if (in_array($task, array("viewlink", "writereview", "rate", "recommend", "viewgallery"))) {
        $pathway->addItem($mtLink->link_name, "index.php?option={$option}&task=viewlink&link_id={$link_id}");
    }
}