Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    H-J
    H-J is offline
    New to the CF scene
    Join Date
    May 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP help with sitemap.php

    Hello everyone,

    I'm walking away from windows based applications and moving into the php based coding. Being a novice with php codes, I need help to modify the "sitemap.php" codes I'll be posting below. The issue I have with this code is that due to the large "Location" counts in the database, the sitemap takes over 30 seconds to load, which is unacceptable and don't want to reduce the locations.

    I'd like to know if anyone can help me to omit the locations from the results, basically removing it from below. Thanks in advance for any and all help I can get:



    <?php
    define('JTS_SECTION', 'public');

    include ('./defaults.php');

    $JTSR->loadLanguage(array('public_sitemap'));

    $menu = $JTSR->get('CustomLinks');

    $JTSR->setAdd('page_title',$JTSR->getLanguage('public_sitemap'));
    $JTSR->set('meta_title',coalesce($JTSR->getConfig('sitemap_meta_title'),$JTSR->getLanguage('public_sitemap')));
    $JTSR->set('meta_description',coalesce($JTSR->getConfig('sitemap_meta_description'),$JTSR->getLanguage('public_sitemap')));

    $JTSR->setAddArray('breadcrumb',array('link'=>BASE_URL.'/sitemap.php','text'=>$JTSR->getLanguage('public_sitemap')));

    $JTSR->loadCSS('<link rel="stylesheet" type="text/css" href="'.BASE_URL.'/includes/jquery/dynatree/skin/ui.dynatree.css" />',20);
    $JTSR->loadJavascript('<script type="text/javascript" src="'.BASE_URL.'/includes/jquery/dynatree/jquery.dynatree.min.js"></script>',20);

    if(!isset($_GET['id']) OR !isset($_GET['letter']) OR !isset($_GET['type'])) {
    if(!$content = $JTSR->get('Cache')->get('categories_sitemap', 1800)) {
    $categories = $JTSR->get('Categories')->getSitemap();
    $categories_count = count($categories);
    // Loop through categories to get rid of hidden and count = 0
    for($x=0; $x < $categories_count; $x++) {
    $categories[$x]['url'] = $JTSR->get('Categories')->getURL($categories[$x]['id'],$categories[$x]['friendly_url_path']);
    $categories[$x]['children'] = !$JTSR->get('Categories')->isLeaf($categories[$x]);
    if($categories[$x]['hidden'] OR ($JTSR->getConfig('cat_empty_hidden') AND $categories[$x]['count_total'] == 0)) {
    for($y=$x+1; $y < $categories_count; $y++) {
    if($categories[$y]['level'] <= $categories[$x]['level']) {
    break;
    } else {
    unset($categories[$y]);
    }
    }
    unset($categories[$x]);
    $x = $y-1;
    }
    }
    $content = $JTSR->get('HTML')->toList($categories,'children','folder','url','sitemap_category_');
    $JTSR->get('Cache')->write('categories_sitemap',$content);
    }

    if(!$content2 = $JTSR->get('Cache')->get('locations_sitemap', 1800)) {
    $locations = $db->GetAll("SELECT id, title, level, hidden, count_total, left_, right_, friendly_url_path FROM ".T_LOCATIONS." WHERE id!=1 ORDER BY left_");
    $locations_count = count($locations);
    // Loop through locations to get rid of hidden and count = 0
    for($x=0; $x < $locations_count; $x++) {
    $locations[$x]['url'] = $JTSR->get('Locations')->getURL($locations[$x]['id'],$locations[$x]['friendly_url_path']);
    $locations[$x]['children'] = !$JTSR->get('Locations')->isLeaf($locations[$x]);
    if($locations[$x]['hidden'] OR ($JTSR->getConfig('loc_empty_hidden') AND $locations[$x]['count_total'] == 0)) {
    for($y=$x+1; $y < $locations_count; $y++) {
    if($locations[$y]['level'] <= $locations[$x]['level']) {
    break;
    } else {
    unset($locations[$y]);
    }
    }
    unset($locations[$x]);
    $x = $y-1;
    }
    }
    $content2 = $JTSR->get('HTML')->toList($locations,'children','folder','url','sitemap_location_');
    $JTSR->get('Cache')->write('locations_sitemap',$content2);
    }
    } else {
    if($_GET['type'] == 'locations') {
    $datasource = $JTSR->get('Locations');
    $variable_name = 'content2';
    } else {
    $datasource = $JTSR->get('Categories');
    $variable_name = 'content';
    }
    if(empty($_GET['id'])) {
    $_GET['id'] = 1;
    }
    if($_GET['letter'] == "0-9") {
    $sitemap_cats = $datasource->getChildren(intval($_GET['id']),1,null,"AND title REGEXP '^[[:digit:]].*$'",array('id','level','friendly_url_path','title'));
    } else {
    $sitemap_cats = $datasource->getChildren(intval($_GET['id']),1,null,"AND title LIKE ".$JTSR->get('Cleaner')->clean_db($_GET['letter']."%"),array('id','level','friendly_url_path','title'));
    }
    foreach($sitemap_cats as &$category) {
    $category['url'] = $datasource->getURL($category['id'],$category['friendly_url_path']);
    $category['children'] = !$datasource->isLeaf($category);
    }
    $$variable_name = $JTSR->get('HTML')->toList($sitemap_cats,'children','folder','url');
    }

    $template_content = $JTSR->getNew('Template',JTSROOT.TEMPLATE_PATH.'sitemap.tpl');
    $template_content->set('sitemap_categories',$content);
    $template_content->set('sitemap_locations',$content2);
    $template_content->set('links',$JTSR->get('HTML')->toList($menu->getLinksFlat(1),'children','','link'));

    include(JTSROOT.'/includes/template_setup.php');
    ?>

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    408
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Put a limit in the query to imit the results, then use page numbering to select how far you should go into the results.

    Ex:
    Page 1: rows 0-9
    Page 2: rows 10-19
    Page 3: rows 20-29
    etc.

    Basically to get the starting number, subtract 1 and multiply it by 10, then make the limit 10 as well. If you want to use a different number, such as 25, then use 25 instead of ti in the math and limit.

    Original code to help others not get a headache:
    PHP Code:
    <?php
    define
    ('JTS_SECTION''public');

    include (
    './defaults.php');

    $JTSR->loadLanguage(array('public_sitemap'));

    $menu $JTSR->get('CustomLinks');

    $JTSR->setAdd('page_title',$JTSR->getLanguage('public_sitemap'));
    $JTSR->set('meta_title',coalesce($JTSR->getConfig('sitemap_meta_title'),$JTSR->getLanguage('public_sitemap')));
    $JTSR->set('meta_description',coalesce($JTSR->getConfig('sitemap_meta_description'),$JTSR->getLanguage('public_sitemap')));

    $JTSR->setAddArray('breadcrumb',array('link'=>BASE_URL.'/sitemap.php','text'=>$JTSR->getLanguage('public_sitemap')));

    $JTSR->loadCSS('<link rel="stylesheet" type="text/css" href="'.BASE_URL.'/includes/jquery/dynatree/skin/ui.dynatree.css" />',20);
    $JTSR->loadJavascript('<script type="text/javascript" src="'.BASE_URL.'/includes/jquery/dynatree/jquery.dynatree.min.js"></script>',20);

    if(!isset(
    $_GET['id']) OR !isset($_GET['letter']) OR !isset($_GET['type'])) {
    if(!
    $content $JTSR->get('Cache')->get('categories_sitemap'1800)) {
    $categories $JTSR->get('Categories')->getSitemap();
    $categories_count count($categories);
    // Loop through categories to get rid of hidden and count = 0
    for($x=0$x $categories_count$x++) {
    $categories[$x]['url'] = $JTSR->get('Categories')->getURL($categories[$x]['id'],$categories[$x]['friendly_url_path']);
    $categories[$x]['children'] = !$JTSR->get('Categories')->isLeaf($categories[$x]);
    if(
    $categories[$x]['hidden'] OR ($JTSR->getConfig('cat_empty_hidden') AND $categories[$x]['count_total'] == 0)) {
    for(
    $y=$x+1$y $categories_count$y++) {
    if(
    $categories[$y]['level'] <= $categories[$x]['level']) {
    break;
    } else {
    unset(
    $categories[$y]);
    }
    }
    unset(
    $categories[$x]);
    $x $y-1;
    }
    }
    $content $JTSR->get('HTML')->toList($categories,'children','folder','url','sitemap_category_');
    $JTSR->get('Cache')->write('categories_sitemap',$content);
    }

    if(!
    $content2 $JTSR->get('Cache')->get('locations_sitemap'1800)) {
    $locations $db->GetAll("SELECT id, title, level, hidden, count_total, left_, right_, friendly_url_path FROM ".T_LOCATIONS." WHERE id!=1 ORDER BY left_");
    $locations_count count($locations);
    // Loop through locations to get rid of hidden and count = 0
    for($x=0$x $locations_count$x++) {
    $locations[$x]['url'] = $JTSR->get('Locations')->getURL($locations[$x]['id'],$locations[$x]['friendly_url_path']);
    $locations[$x]['children'] = !$JTSR->get('Locations')->isLeaf($locations[$x]);
    if(
    $locations[$x]['hidden'] OR ($JTSR->getConfig('loc_empty_hidden') AND $locations[$x]['count_total'] == 0)) {
    for(
    $y=$x+1$y $locations_count$y++) {
    if(
    $locations[$y]['level'] <= $locations[$x]['level']) {
    break;
    } else {
    unset(
    $locations[$y]);
    }
    }
    unset(
    $locations[$x]);
    $x $y-1;
    }
    }
    $content2 $JTSR->get('HTML')->toList($locations,'children','folder','url','sitemap_location_');
    $JTSR->get('Cache')->write('locations_sitemap',$content2);
    }
    } else {
    if(
    $_GET['type'] == 'locations') {
    $datasource $JTSR->get('Locations');
    $variable_name 'content2';
    } else {
    $datasource $JTSR->get('Categories');
    $variable_name 'content';
    }
    if(empty(
    $_GET['id'])) {
    $_GET['id'] = 1;
    }
    if(
    $_GET['letter'] == "0-9") {
    $sitemap_cats $datasource->getChildren(intval($_GET['id']),1,null,"AND title REGEXP '^[[:digit:]].*$'",array('id','level','friendly_url_path','title'));
    } else {
    $sitemap_cats $datasource->getChildren(intval($_GET['id']),1,null,"AND title LIKE ".$JTSR->get('Cleaner')->clean_db($_GET['letter']."%"),array('id','level','friendly_url_path','title'));
    }
    foreach(
    $sitemap_cats as &$category) {
    $category['url'] = $datasource->getURL($category['id'],$category['friendly_url_path']);
    $category['children'] = !$datasource->isLeaf($category);
    }
    $
    $variable_name $JTSR->get('HTML')->toList($sitemap_cats,'children','folder','url');
    }

    $template_content $JTSR->getNew('Template',JTSROOT.TEMPLATE_PATH.'sitemap.tpl');
    $template_content->set('sitemap_categories',$content);
    $template_content->set('sitemap_locations',$content2);
    $template_content->set('links',$JTSR->get('HTML')->toList($menu->getLinksFlat(1),'children','','link'));

    include(
    JTSROOT.'/includes/template_setup.php');
    ?>
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube

  • Users who have thanked Dubz for this post:

    H-J (05-26-2014)

  • #3
    H-J
    H-J is offline
    New to the CF scene
    Join Date
    May 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the help Dubz, unfortunately that didn't work for me :-( there's java script that truncate it into a collapsible short tree view in one short page, so that didn't work for me. Please keep in mind that I'm a real novice with php, so I'm wondering if there's a way to have the "Locations" excluded from the sitemap.

    Thanks again for the tip and trying to help out. :-)

    HJ


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •