Esempio n. 1
0
/**
* Outputs the pathway breadcrumbs
* @param database A database connector object
* @param int The db id field value of the current menu item
*/
function showPathway($Itemid)
{
    global $database, $option, $task, $mainframe, $mosConfig_absolute_path, $mosConfig_live_site, $my;
    // the the whole menu array and index the array by the id
    $query = "SELECT id, name, link, parent, type, menutype, access" . "\n FROM #__menu" . "\n WHERE published = 1" . "\n AND access <= " . (int) $my->gid . "\n ORDER BY menutype, parent, ordering";
    $database->setQuery($query);
    $mitems = $database->loadObjectList('id');
    // get the home page
    $home_menu = new mosMenu($database);
    foreach ($mitems as $mitem) {
        if ($mitem->menutype == 'mainmenu') {
            $home_menu = $mitem;
            break;
        }
    }
    $optionstring = '';
    if (isset($_SERVER['REQUEST_URI'])) {
        $optionstring = $_SERVER['REQUEST_URI'];
    } else {
        if (isset($_SERVER['QUERY_STRING'])) {
            $optionstring = $_SERVER['QUERY_STRING'];
        }
    }
    // are we at the home page or not
    $homekeys = array_keys($mitems);
    $home = @$mitems[$home_menu->id]->name;
    $path = '';
    // this is a patch job for the frontpage items! aje
    if ($Itemid == $home_menu->id) {
        switch ($option) {
            case 'content':
                $id = intval(mosGetParam($_REQUEST, 'id', 0));
                if ($task == 'blogsection') {
                    $query = "SELECT title, id" . "\n FROM #__sections" . "\n WHERE id = " . (int) $id;
                } else {
                    if ($task == 'blogcategory') {
                        $query = "SELECT title, id" . "\n FROM #__categories" . "\n WHERE id = " . (int) $id;
                    } else {
                        $query = "SELECT title, catid, id" . "\n FROM #__content" . "\n WHERE id = " . (int) $id;
                    }
                }
                $database->setQuery($query);
                $row = null;
                $database->loadObject($row);
                $id = max(array_keys($mitems)) + 1;
                // add the content item
                $mitem2 = pathwayMakeLink($Itemid, $row->title, '', 1);
                $mitems[$id] = $mitem2;
                $Itemid = $id;
                $home = '<a href="' . sefRelToAbs('index.php') . '" class="pathway">' . $home . '</a>';
                break;
        }
    }
    // breadcrumbs for content items
    switch (@$mitems[$Itemid]->type) {
        // menu item = List - Content Section
        case 'content_section':
            $id = intval(mosGetParam($_REQUEST, 'id', 0));
            switch ($task) {
                case 'category':
                    if ($id) {
                        $query = "SELECT title, id" . "\n FROM #__categories" . "\n WHERE id = " . (int) $id . "\n AND access <= " . (int) $my->id;
                        $database->setQuery($query);
                        $title = $database->loadResult();
                        $id = max(array_keys($mitems)) + 1;
                        $mitem = pathwayMakeLink($id, $title, 'index.php?option=' . $option . '&task=' . $task . '&id=' . $id . '&Itemid=' . $Itemid, $Itemid);
                        $mitems[$id] = $mitem;
                        $Itemid = $id;
                    }
                    break;
                case 'view':
                    if ($id) {
                        // load the content item name and category
                        $query = "SELECT title, catid, id, access" . "\n FROM #__content" . "\n WHERE id = " . (int) $id;
                        $database->setQuery($query);
                        $row = null;
                        $database->loadObject($row);
                        // load and add the category
                        $query = "SELECT c.title AS title, s.id AS sectionid, c.id AS id, c.access AS cat_access" . "\n FROM #__categories AS c" . "\n LEFT JOIN #__sections AS s" . "\n ON c.section = s.id" . "\n WHERE c.id = " . (int) $row->catid . "\n AND c.access <= " . (int) $my->id;
                        $database->setQuery($query);
                        $result = $database->loadObjectList();
                        $title = $result[0]->title;
                        $sectionid = $result[0]->sectionid;
                        $id = max(array_keys($mitems)) + 1;
                        $mitem1 = pathwayMakeLink($Itemid, $title, 'index.php?option=' . $option . '&task=category&sectionid=' . $sectionid . '&id=' . $row->catid, $Itemid);
                        $mitems[$id] = $mitem1;
                        if ($row->access <= $my->gid) {
                            // add the final content item
                            $id++;
                            $mitem2 = pathwayMakeLink($Itemid, $row->title, '', $id - 1);
                            $mitems[$id] = $mitem2;
                        }
                        $Itemid = $id;
                    }
                    break;
            }
            break;
            // menu item = Table - Content Category
        // menu item = Table - Content Category
        case 'content_category':
            $id = intval(mosGetParam($_REQUEST, 'id', 0));
            switch ($task) {
                case 'view':
                    if ($id) {
                        // load the content item name and category
                        $query = "SELECT title, catid, id" . "\n FROM #__content" . "\n WHERE id = " . (int) $id . "\n AND access <= " . (int) $my->id;
                        $database->setQuery($query);
                        $row = null;
                        $database->loadObject($row);
                        $id = max(array_keys($mitems)) + 1;
                        // add the final content item
                        $mitem2 = pathwayMakeLink($Itemid, $row->title, '', $Itemid);
                        $mitems[$id] = $mitem2;
                        $Itemid = $id;
                    }
                    break;
            }
            break;
            // menu item = Blog - Content Category
            // menu item = Blog - Content Section
        // menu item = Blog - Content Category
        // menu item = Blog - Content Section
        case 'content_blog_category':
        case 'content_blog_section':
            switch ($task) {
                case 'view':
                    $id = intval(mosGetParam($_REQUEST, 'id', 0));
                    if ($id) {
                        // load the content item name and category
                        $query = "SELECT title, catid, id" . "\n FROM #__content" . "\n WHERE id = " . (int) $id . "\n AND access <= " . (int) $my->id;
                        $database->setQuery($query);
                        $row = null;
                        $database->loadObject($row);
                        $id = max(array_keys($mitems)) + 1;
                        $mitem2 = pathwayMakeLink($Itemid, $row->title, '', $Itemid);
                        $mitems[$id] = $mitem2;
                        $Itemid = $id;
                    }
                    break;
            }
            break;
    }
    $i = count($mitems);
    $mid = $Itemid;
    $imgPath = 'templates/' . $mainframe->getTemplate() . '/images/arrow.png';
    if (file_exists("{$mosConfig_absolute_path}/{$imgPath}")) {
        $img = '<img src="' . $mosConfig_live_site . '/' . $imgPath . '" border="0" alt="arrow" />';
    } else {
        $imgPath = '/images/M_images/arrow.png';
        if (file_exists($mosConfig_absolute_path . $imgPath)) {
            $img = '<img src="' . $mosConfig_live_site . '/images/M_images/arrow.png" alt="arrow" />';
        } else {
            $img = '&gt;';
        }
    }
    while ($i--) {
        if (!$mid || empty($mitems[$mid]) || $Itemid == $home_menu->id || !preg_match("option", $optionstring)) {
            break;
        }
        $item =& $mitems[$mid];
        $itemname = stripslashes($item->name);
        // if it is the current page, then display a non hyperlink
        if ($item->id == $Itemid && !$mainframe->getCustomPathWay() || empty($mid) || empty($item->link)) {
            $newlink = "  {$itemname}";
        } else {
            if (isset($item->type) && $item->type == 'url') {
                $correctLink = preg_match('/http:\\/\\//i', $item->link);
                if ($correctLink == 1) {
                    $newlink = '<a href="' . $item->link . '" target="_window" class="pathway">' . $itemname . '</a>';
                } else {
                    $newlink = $itemname;
                }
            } else {
                $newlink = '<a href="' . sefRelToAbs($item->link . '&Itemid=' . $item->id) . '" class="pathway">' . $itemname . '</a>';
            }
        }
        // converts & to &amp; for xtml compliance
        $newlink = ampReplace($newlink);
        if (trim($newlink) != "") {
            $path = $img . ' ' . $newlink . ' ' . $path;
        } else {
            $path = '';
        }
        $mid = $item->parent;
    }
    if (preg_match('/option/i', $optionstring) && trim($path)) {
        $home = '<a href="' . sefRelToAbs('index.php') . '" class="pathway">' . $home . '</a>';
    }
    if ($mainframe->getCustomPathWay()) {
        $path .= $img . ' ';
        $path .= implode("{$img} ", $mainframe->getCustomPathWay());
    }
    if ($Itemid && $Itemid != 99999999) {
        echo '<span class="pathway">' . $home . ' ' . $path . '</span>';
    }
}
Esempio n. 2
0
File: pathway.php Progetto: cwcw/cms
/**
* Outputs the pathway breadcrumbs
* @param database A database connector object
* @param int The db id field value of the current menu item
*/
function showPathway($Itemid)
{
    global $database, $option, $task, $mainframe, $mosConfig_absolute_path, $mosConfig_live_site;
    global $SERVER_SOFTWARE, $QUERY_STRING, $REQUEST_URI;
    // get the home page
    $database->setQuery("SELECT id, link" . "\nFROM #__menu" . "\nWHERE menutype='mainmenu' AND published='1'" . "\nORDER BY parent, ordering LIMIT 1");
    $home_menu = new mosMenu($database);
    $database->loadObject($home_menu);
    // the the whole menu array and index the array by the id
    $database->setQuery("SELECT id, name, link, parent, type" . "\nFROM #__menu" . "\nWHERE published='1'" . "\nORDER BY parent, ordering");
    $mitems = $database->loadObjectList('id');
    $isWin = substr(PHP_OS, 0, 3) == 'WIN';
    $optionstring = $isWin ? $QUERY_STRING : $REQUEST_URI;
    // are we at the home page or not
    $homekeys = array_keys($mitems);
    $home = @$mitems[$home_menu->id]->name;
    $path = "";
    // this is a patch job for the frontpage items! aje
    if ($Itemid == $home_menu->id) {
        switch ($option) {
            case 'content':
                $id = intval(mosGetParam($_REQUEST, 'id', 0));
                if ($task == 'blogsection') {
                    $database->setQuery("SELECT title FROM #__sections WHERE id={$id}");
                } else {
                    if ($task == 'blogcategory') {
                        $database->setQuery("SELECT title FROM #__categories WHERE id={$id}");
                    } else {
                        $database->setQuery("SELECT title, catid FROM #__content WHERE id={$id}");
                    }
                }
                $row = null;
                $database->loadObject($row);
                $id = max(array_keys($mitems)) + 1;
                // add the content item
                $mitem2 = pathwayMakeLink($Itemid, $row->title, "", 1);
                $mitems[$id] = $mitem2;
                $Itemid = $id;
                $home = '<a href="' . sefRelToAbs('index.php') . '" class="pathway">' . $home . '</a>';
                break;
        }
    }
    switch (@$mitems[$Itemid]->type) {
        case 'content_section':
            $id = intval(mosGetParam($_REQUEST, 'id', 0));
            switch ($task) {
                case 'category':
                    if ($id) {
                        $database->setQuery("SELECT title FROM #__categories WHERE id={$id}");
                        $title = $database->loadResult();
                        $id = max(array_keys($mitems)) + 1;
                        $mitem = pathwayMakeLink($id, $title, 'index.php?option=' . $option . '&task=' . $task . '&id=' . $id . '&Itemid=' . $Itemid, $Itemid);
                        $mitems[$id] = $mitem;
                        $Itemid = $id;
                    }
                    break;
                case 'view':
                    if ($id) {
                        // load the content item name and category
                        $database->setQuery("SELECT title, catid FROM #__content WHERE id={$id}");
                        $row = null;
                        $database->loadObject($row);
                        // load and add the category
                        $database->setQuery("SELECT c.title AS title, s.id AS sectionid " . "FROM #__categories AS c " . "LEFT JOIN #__sections AS s " . "ON c.section=s.id " . "WHERE c.id={$row->catid}");
                        $result = $database->loadObjectList();
                        $title = $result[0]->title;
                        $sectionid = $result[0]->sectionid;
                        $id = max(array_keys($mitems)) + 1;
                        $mitem1 = pathwayMakeLink($Itemid, $title, 'index.php?option=' . $option . '&task=category&sectionid=' . $sectionid . '&id=' . $row->catid, $Itemid);
                        $mitems[$id] = $mitem1;
                        // add the final content item
                        $id++;
                        $mitem2 = pathwayMakeLink($Itemid, $row->title, "", $id - 1);
                        $mitems[$id] = $mitem2;
                        $Itemid = $id;
                    }
                    break;
            }
            break;
        case 'content_category':
            $id = intval(mosGetParam($_REQUEST, 'id', 0));
            switch ($task) {
                case 'view':
                    if ($id) {
                        // load the content item name and category
                        $database->setQuery("SELECT title, catid FROM #__content WHERE id={$id}");
                        $row = null;
                        $database->loadObject($row);
                        $id = max(array_keys($mitems)) + 1;
                        // add the final content item
                        $mitem2 = pathwayMakeLink($Itemid, $row->title, "", $Itemid);
                        $mitems[$id] = $mitem2;
                        $Itemid = $id;
                    }
                    break;
            }
            break;
        case 'content_blog_category':
        case 'content_blog_section':
            switch ($task) {
                case 'view':
                    $id = intval(mosGetParam($_REQUEST, 'id', 0));
                    if ($id) {
                        // load the content item name and category
                        $database->setQuery("SELECT title, catid FROM #__content WHERE id={$id}");
                        $row = null;
                        $database->loadObject($row);
                        $id = max(array_keys($mitems)) + 1;
                        $mitem2 = pathwayMakeLink($Itemid, $row->title, "", $Itemid);
                        $mitems[$id] = $mitem2;
                        $Itemid = $id;
                    }
                    break;
            }
            break;
    }
    $i = count($mitems);
    $mid = $Itemid;
    $imgPath = 'templates/' . $mainframe->getTemplate() . '/images/arrow.png';
    if (file_exists("{$mosConfig_absolute_path}/{$imgPath}")) {
        $img = '<img src="' . $mosConfig_live_site . '/' . $imgPath . '" border="0" alt="arrow" />';
    } else {
        $imgPath = '/images/M_images/arrow.png';
        if (file_exists($mosConfig_absolute_path . $imgPath)) {
            $img = '<img src="' . $mosConfig_live_site . '/images/M_images/arrow.png" alt="arrow" />';
        } else {
            $img = '&gt;';
        }
    }
    while ($i--) {
        if (!$mid || empty($mitems[$mid]) || $mid == 1 || !eregi("option", $optionstring)) {
            break;
        }
        $item =& $mitems[$mid];
        // if it is the current page, then display a non hyperlink
        if ($item->id == $Itemid || empty($mid) || empty($item->link)) {
            $newlink = "  {$item->name}";
        } else {
            if (isset($item->type) && $item->type == 'url') {
                $correctLink = eregi('http://', $item->link);
                if ($correctLink == 1) {
                    $newlink = '<a href="' . $item->link . '" target="_window" class="pathway">' . $item->name . '</a>';
                } else {
                    $newlink = $item->name;
                }
            } else {
                $newlink = '<a href="' . sefRelToAbs($item->link . '&Itemid=' . $item->id) . '" class="pathway">' . $item->name . '</a>';
            }
        }
        if (trim($newlink) != "") {
            $path = $img . ' ' . $newlink . ' ' . $path;
        } else {
            $path = '';
        }
        $mid = $item->parent;
    }
    if (eregi('option', $optionstring) && trim($path)) {
        $home = '<a href="' . sefRelToAbs('index.php') . '" class="pathway">' . $home . '</a>';
    }
    // converts & to &amp; for xtml compliance
    $path = str_replace('&', '&amp;', $path);
    if ($mainframe->getCustomPathWay()) {
        $path .= $img . ' ';
        $path .= implode("{$img} ", $mainframe->getCustomPathWay());
    }
    echo "<span class=\"pathway\">" . $home . " " . $path . "</span>\n";
}