Ejemplo n.º 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;
 }
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 function updateCatCount($inc = 1)
 {
     if ($this->cat_id <= 0) {
         return false;
     } else {
         $cat_parent_ids = mtPathWay::getPathWay($this->cat_id);
         if (!empty($cat_parent_ids)) {
             $cat_parent_ids2 = implode(',', $cat_parent_ids);
             //echo $cat_parent_ids2;
             if ($inc < 0) {
                 $this->_db->setQuery('UPDATE #__mt_cats SET cat_cats = (cat_cats - ABS(' . intval($inc) . ')) WHERE cat_id IN (' . $cat_parent_ids2 . ')');
             } else {
                 $this->_db->setQuery('UPDATE #__mt_cats SET cat_cats = (cat_cats + ABS(' . intval($inc) . ')) WHERE cat_id IN (' . $cat_parent_ids2 . ')');
             }
             if (!$this->_db->query()) {
                 echo "<script> alert('" . $this->_db->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                 return false;
             }
         }
         return true;
     }
 }
Ejemplo n.º 5
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;
                    }
                }
            }
        }
    }
}
Ejemplo n.º 6
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}");
    }
}