Example #1
0
 function shAppendCat($cat_id, $option, $shLangName)
 {
     $sefConfig =& Sh404sefFactory::getConfig();
     $sef = array();
     $pathWay = new mtPathWay($cat_id);
     $pathway_ids = $pathWay->getPathWay($cat_id);
     switch ($sefConfig->shMTreeInsertCategories) {
         case '1':
             // only last cat
             if ($cat_id > 0) {
                 //this is not root we must use this cat
                 $sef[] = ($sefConfig->shMTreeInsertCategoryId ? $cat_id . $sefConfig->replacement : '') . $pathWay->getCatName($cat_id);
             }
             //else // this is root, don't add cat name
             shRemoveFromGETVarsList('cat_id');
             break;
         case '0':
             // if no cat, we still put them all. This param only applies to listing links
         // if no cat, we still put them all. This param only applies to listing links
         case '2':
             // we want all cats
             foreach ($pathway_ids as $id) {
                 $sef[] = ($sefConfig->shMTreeInsertCategoryId ? $id . $sefConfig->replacement : '') . $pathWay->getCatName($id);
             }
             // If curreny category is not root, append to sefstring
             if ($cat_id > 0) {
                 $sef[] = ($sefConfig->shMTreeInsertCategoryId ? $cat_id . $sefConfig->replacement : '') . $pathWay->getCatName($cat_id);
             }
             shRemoveFromGETVarsList('cat_id');
             break;
     }
     return $sef;
 }
 function plugin($cat_id, $attr = null)
 {
     require_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_mtree' . DS . 'admin.mtree.class.php';
     $mtPathWay = new mtPathWay($cat_id);
     $cat_ids = $mtPathWay->getPathWay();
     $cat_ids[] = $cat_id;
     $cat_names = array();
     if (empty($cat_ids[0])) {
         $cat_names[] = JText::_('Root');
     }
     foreach ($cat_ids as $cid) {
         // Do not add 'Root' name since its done above already
         if ($cid > 0) {
             $cat_names[] = $mtPathWay->getCatName($cid);
         }
     }
     $html = '<a href="';
     $html .= JRoute::_('index.php?option=com_mtree&task=listcats&cat_id=' . $cat_id);
     $html .= '"';
     # Insert attributes
     if (is_array($attr)) {
         // from array
         foreach ($attr as $key => $val) {
             $key = htmlspecialchars($key);
             $val = htmlspecialchars($val);
             $html .= " {$key}=\"{$val}\"";
         }
     } elseif (!is_null($attr)) {
         // from scalar
         $html .= " {$attr}";
     }
     # set the listing text, close the tag
     $html .= '>' . htmlspecialchars(implode(JText::_('Arrow'), $cat_names)) . '</a> ';
     return $html;
 }
Example #3
0
function smartCountUpdate_catMove($old_cat_parent, $new_cat_parent, $cat_links, $cat_cats)
{
    $database =& JFactory::getDBO();
    // Add $old_cat_parent to $old_ancestors array first
    $old_ancestors = mtPathWay::getPathWay($old_cat_parent);
    $old_ancestors[] = $old_cat_parent;
    $new_ancestors = mtPathWay::getPathWay($new_cat_parent);
    $new_ancestors[] = $new_cat_parent;
    if (count($old_ancestors) > 0) {
        foreach ($old_ancestors as $old_ancestor) {
            if ($old_ancestor > 0) {
                $database->setQuery("UPDATE #__mt_cats SET cat_cats = cat_cats - " . intval($cat_cats) . ", cat_links = cat_links - " . intval($cat_links) . " WHERE cat_id = {$old_ancestor}");
                $database->query();
            }
        }
    }
    if (count($new_ancestors) > 0) {
        foreach ($new_ancestors as $new_ancestor) {
            if ($new_ancestor > 0) {
                $database->setQuery("UPDATE #__mt_cats SET cat_cats = cat_cats + " . intval($cat_cats) . ", cat_links = cat_links + " . intval($cat_links) . " WHERE cat_id = {$new_ancestor}");
                $database->query();
            }
        }
    }
    return true;
}
defined('_JEXEC') or die('Restricted access');
$parent_cat_id = JRequest::getInt('parent_cat_id', 0);
$task2 = JRequest::getCmd('task2', '');
switch ($task2) {
    case 'spiderurl':
        spiderurl($option);
        break;
    case 'checklinkcomplete':
        checklinkcomplete();
        break;
    case 'checklink':
        checklink();
        break;
    case 'getcats':
        # Get pathway
        $mtPathWay = new mtPathWay($parent_cat_id);
        $return = $mtPathWay->printPathWayFromCat_withCurrentCat($parent_cat_id, 0);
        $return .= "\n";
        $database->setQuery('SELECT cat_id, cat_name FROM #__mt_cats WHERE cat_parent = ' . $database->quote($parent_cat_id) . ' ORDER BY cat_name ASC');
        $cats = $database->loadObjectList();
        if ($parent_cat_id > 0) {
            $database->setQuery('SELECT cat_parent FROM #__mt_cats WHERE cat_id = ' . $database->quote($parent_cat_id) . ' LIMIT 1');
            $browse_cat_parent = $database->loadResult();
            $return .= $browse_cat_parent . "|" . JText::_('Arrow back');
            if (count($cats) > 0) {
                $return .= "\n";
            }
        } else {
            //
        }
        if (count($cats) > 0) {
 function updateLinkCount($inc = 1, $cat_id = null)
 {
     if (!isset($this->cat_id) && is_null($cat_id)) {
         return false;
     } elseif (is_null($cat_id) && $this->cat_id >= 0) {
         $cat_id = $this->cat_id;
     }
     $mtPathWay = new mtPathWay($cat_id);
     $cat_parent_ids = implode(',', $mtPathWay->getPathWayWithCurrentCat());
     if ($inc < 0) {
         $this->_db->setQuery('UPDATE #__mt_cats SET cat_links = (cat_links - ABS(' . intval($inc) . ")) WHERE cat_id IN ({$cat_parent_ids})");
     } else {
         $this->_db->setQuery('UPDATE #__mt_cats SET cat_links = (cat_links + ABS(' . intval($inc) . ")) WHERE cat_id IN ({$cat_parent_ids})");
     }
     if (!$this->_db->query()) {
         echo "<script> alert('" . $this->_db->getErrorMsg() . "'); window.history.go(-1); </script>\n";
         return false;
     }
     return true;
 }
Example #6
0
function editlisting($link_id, $option)
{
    global $savantConf, $Itemid, $mtconf;
    $database =& JFactory::getDBO();
    $my =& JFactory::getUser();
    $document =& JFactory::getDocument();
    require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'mfields.class.php';
    # Get cat_id if user is adding new listing.
    $cat_id = JRequest::getInt('cat_id', 0);
    // This var retrieve the link_id for adding listing
    $link_id_passfromurl = JRequest::getInt('link_id', 0);
    if ($link_id_passfromurl > 0 && $cat_id == 0) {
        $database->setQuery("SELECT cat_id FROM (#__mt_links AS l, #__mt_cl AS cl) WHERE l.link_id ='" . $link_id_passfromurl . "' AND cl.link_id = l.link_id");
        $cat_id = $database->loadResult();
    }
    $link = new mtLinks($database);
    # Do not allow Guest to edit listing
    if ($link_id > 0 && $my->id <= 0) {
        $link->load(0);
    } else {
        $link->load($link_id);
    }
    # Load all published CORE & custom fields
    $sql = "SELECT cf.*, " . ($link_id ? $link_id : 0) . " AS link_id, cfv.value AS 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 = " . $link_id . "\nLEFT JOIN #__mt_fieldtypes AS ft ON ft.field_type=cf.field_type" . "\nWHERE cf.hidden ='0' AND cf.published='1' ORDER BY ordering ASC";
    $database->setQuery($sql);
    $fields = new mFields();
    $fields->setCoresValue($link->link_name, $link->link_desc, $link->address, $link->city, $link->state, $link->country, $link->postcode, $link->telephone, $link->fax, $link->email, $link->website, $link->price, $link->link_hits, $link->link_votes, $link->link_rating, $link->link_featured, $link->link_created, $link->link_modified, $link->link_visited, $link->publish_up, $link->publish_down, $link->metakey, $link->metadesc, $link->user_id, '');
    $fields->loadFields($database->loadObjectList());
    # Load images
    $database->setQuery("SELECT img_id, filename FROM #__mt_images WHERE link_id = '" . $link_id . "' ORDER BY ordering ASC");
    $images = $database->loadObjectList();
    # Get current category's template
    $database->setQuery("SELECT cat_name, cat_parent, cat_template, metakey, metadesc FROM #__mt_cats WHERE cat_id='" . $cat_id . "' AND cat_published='1' LIMIT 1");
    $cat = $database->loadObject();
    if ($link->link_id == 0) {
        if ($cat) {
            $document->setTitle(sprintf(JText::_('Add listing2'), $cat->cat_name));
        } else {
            $document->setTitle(JText::_('Add listing'));
        }
    } else {
        $document->setTitle(sprintf(JText::_('Edit listing2'), $link->link_name));
    }
    if (isset($cat->cat_template) && $cat->cat_template != '') {
        loadCustomTemplate(null, $savantConf, $cat->cat_template);
    }
    # Get other categories
    $database->setQuery("SELECT cl.cat_id FROM #__mt_cl AS cl WHERE cl.link_id = '{$link_id}' AND cl.main = '0'");
    $other_cats = $database->loadResultArray();
    # Pathway
    $pathWay = new mtPathWay($cat_id);
    $pw_cats = $pathWay->getPathWayWithCurrentCat($cat_id);
    $pathWayToCurrentCat = '';
    $mtCats = new mtCats($database);
    $pathWayToCurrentCat = ' <a href="' . JRoute::_("index.php?option=com_mtree&task=listcats&Itemid=" . $Itemid) . '">' . JText::_('Root') . "</a>";
    foreach ($pw_cats as $pw_cat) {
        $pathWayToCurrentCat .= JText::_('Arrow') . ' <a href="' . JRoute::_("index.php?option=com_mtree&task=listcats&cat_id=" . $pw_cat . "&Itemid=" . $Itemid) . '">' . $mtCats->getName($pw_cat) . "</a>";
    }
    # Savant Template
    $savant = new Savant2($savantConf);
    assignCommonVar($savant);
    $savant->assign('pathway', $pathWay);
    $savant->assign('pathWayToCurrentCat', $pathWayToCurrentCat);
    $savant->assign('cat_id', $link_id == 0 ? $cat_id : $link->cat_id);
    $savant->assign('other_cats', $other_cats);
    $savant->assignRef('link', $link);
    $savant->assignRef('fields', $fields);
    $savant->assignRef('images', $images);
    if ($mtconf->get('image_maxsize') > 1048576) {
        $savant->assign('image_size_limit', round($mtconf->get('image_maxsize') / 1048576, 1) . 'MB');
    } else {
        $savant->assign('image_size_limit', round($mtconf->get('image_maxsize') / 1024) . 'KB');
    }
    # Check permission
    if ($mtconf->get('user_addlisting') == 1 && $my->id < 1 || $link_id > 0 && $my->id == 0) {
        $savant->assign('error_msg', JText::_('Please login before addlisting'));
        $savant->display('page_error.tpl.php');
    } elseif ($link_id > 0 && $my->id != $link->user_id || $mtconf->get('user_allowmodify') == 0 && $link_id > 0 || $mtconf->get('user_addlisting') == -1 && $link_id == 0 || $mtconf->get('user_addlisting') == 1 && $my->id == 0) {
        echo _NOT_EXIST;
    } else {
        // OK, you can edit
        $database->setQuery("SELECT CONCAT('cust_',cf_id) as varname, caption As value, field_type, prefix_text_mod, suffix_text_mod FROM #__mt_customfields WHERE hidden <> '1' AND published = '1'");
        $custom_fields = $database->loadObjectList('varname');
        $savant->assign('custom_fields', $custom_fields);
        # Load custom fields' value from #__mt_cfvalues to $link
        $database->setQuery("SELECT CONCAT('cust_',cf_id) as varname, value FROM #__mt_cfvalues WHERE link_id = '" . $link_id . "'");
        $cfvalues = $database->loadObjectList('varname');
        foreach ($custom_fields as $cfkey => $value) {
            if (isset($cfvalues[$cfkey])) {
                $savant->custom_data[$cfkey] = $cfvalues[$cfkey]->value;
            } else {
                $savant->custom_data[$cfkey] = '';
            }
        }
        // Get category's tree
        if ($mtconf->get('allow_changing_cats_in_addlisting')) {
            getCatsSelectlist($cat_id, $cat_tree, 1);
            if ($cat_id > 0) {
                $cat_options[] = JHTML::_('select.option', $cat->cat_parent, JText::_('Arrow back'));
            }
            if ($mtconf->get('allow_listings_submission_in_root')) {
                $cat_options[] = JHTML::_('select.option', '0', JText::_('Root'));
            }
            if (count($cat_tree) > 0) {
                foreach ($cat_tree as $ct) {
                    if ($ct["cat_allow_submission"] == 1) {
                        $cat_options[] = JHTML::_('select.option', $ct["cat_id"], str_repeat("&nbsp;", $ct["level"] * 3) . ($ct["level"] > 0 ? " -" : '') . $ct["cat_name"]);
                    } else {
                        $cat_options[] = JHTML::_('select.option', $ct["cat_id"] * -1, str_repeat("&nbsp;", $ct["level"] * 3) . ($ct["level"] > 0 ? " -" : '') . "(" . $ct["cat_name"] . ")");
                    }
                }
            }
            $catlist = JHTML::_('select.genericlist', $cat_options, 'new_cat_id', 'size=8 class="inputbox"', 'value', 'text', '', 'browsecat');
            $savant->assignRef('catlist', $catlist);
        }
        // Give warning is there is already a pending approval for modification.
        if ($link_id > 0) {
            $database->setQuery("SELECT link_id FROM #__mt_links WHERE link_approved = '" . -1 * $link_id . "'");
            if ($database->loadResult() > 0) {
                $savant->assign('warn_duplicate', 1);
            } else {
                $savant->assign('warn_duplicate', 0);
            }
        }
        $savant->assign('pathWay', $pathWay);
        $savant->display('page_addListing.tpl.php');
    }
}
Example #7
0
function findCatID($cat_names)
{
    global $mtconf;
    $db =& JFactory::getDBO();
    if (count($cat_names) == 0) {
        return 0;
    }
    for ($i = 0; $i < count($cat_names); $i++) {
        $cat_names[$i] = preg_replace('/:/', '-', $cat_names[$i], 1);
    }
    // (1)
    // First Attempt will try to search by category's alias.
    // If it returns one result, then this is most probably the correct category
    $db->setQuery("SELECT cat_id, cat_parent, alias FROM #__mt_cats WHERE cat_published='1' AND cat_approved='1' && alias = " . $db->quote($cat_names[count($cat_names) - 1]));
    $cat_ids = $db->loadObjectList();
    if (count($cat_ids) == 1 && $cat_ids[0]->cat_id > 0) {
        return $cat_ids[0]->cat_id;
    } else {
        // (2)
        // Second attempt will load each matches above for their pathway cat_ids
        if (!class_exists('mtPathWay')) {
            require_once $mtconf->getjconf('absolute_path') . '/administrator/components/com_mtree/admin.mtree.class.php';
        }
        $pathway_matches = array();
        $i = 0;
        foreach ($cat_ids as $cat_id) {
            $pathWay = new mtPathWay($cat_id->cat_id);
            $pathway_ids = $pathWay->getPathWay($cat_id->cat_id);
            // Only matches the category that has the same number of level
            if (count($cat_names) - 1 == count($pathway_ids)) {
                $pathway_matches[$i]->pathway_ids = $pathway_ids;
                $pathway_matches[$i]->cat = $cat_id;
                $i++;
            }
        }
        // There is only one match, return the result
        if (count($pathway_matches) == 1) {
            return $pathway_matches[0]->cat->cat_id;
        } else {
            // There is more than one result, we have to do another round of check based on their aliases
            // There are at least 2 matches and all of them have the same number of levels
            // First, get all the alias of all matching pathways.
            $select_cat_ids = array();
            foreach ($pathway_matches as $pathway_match) {
                $select_cat_ids = array_merge($select_cat_ids, $pathway_match->pathway_ids);
            }
            if (!empty($select_cat_ids)) {
                $db->setQuery('SELECT cat_id, alias FROM #__mt_cats WHERE cat_id IN (' . implode(', ', $select_cat_ids) . ') LIMIT ' . count($select_cat_ids));
                $cat_aliases = $db->loadObjectList('cat_id');
                // Now for each pathway matches, look through their aliases and look for matches against the SEF URLs
                foreach ($pathway_matches as $pathway_match) {
                    $matched = true;
                    for ($i = count($pathway_match->pathway_ids) - 1; $i >= 0; $i--) {
                        $cat_id = $pathway_match->pathway_ids[$i];
                        if ($cat_aliases[$cat_id]->alias == $cat_names[$i]) {
                            $matched = true;
                        } else {
                            $matched = false;
                            continue 2;
                        }
                    }
                    if ($matched) {
                        return $pathway_match->cat->cat_id;
                    }
                }
            }
        }
    }
}
Example #8
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}");
    }
}