All pastes #535558 Raw Edit

Stuff

public text v1 · immutable
·published 2007-06-04 03:18 UTC
rendered paste body
<?php

/* *********************************************************************
*
*   This script is owned and copyrighted by phpMyDirectory.com. Your
*  license confers  no  title  or ownership in the Software and is
*  not a sale of any rights to the Software.
*
***********************************************************************/

define('PMD_SECTION', 'public');

include ('./defaults.php');
include ('./includes/functions_paginate.php');

if($config['run_bot_check'] == 1) {
    runBotCheck(); // Check for bot statistics
}

if ($_GET['OUT'] == 'logout') {
    ($event = PMDPlugin::run_event('user_logout')) ? eval($event) : false;
    $PMDSession->destroy();
}

//$template_content = & new PMDTemplate(PMDROOT .'/template/' . $config['template'] . '/index.tpl','index.tpl'.$_SERVER['REQUEST_URI']);
$template_content = & new PMDTemplate(PMDROOT .'/template/' . $config['template'] . '/index.tpl');
$template_content->set('yes',$homepage);
$template_content->set('lang',$lang);
$template_content->set('mod_rewrite',$config['mod_rewrite']);
$template_content->set('search_display_all',$config['search_display_all']);
                
/****** CHECK FOR A SPECIFIC CATEGORY BEING SET ************/
if (!isset($_GET['id']) AND $_GET['id'] == '') {
    $path = array();
    $show_banner=$config['show_banner_index'];
    $_GET['id'] = 1;
} else {
    if($config['mod_rewrite'] == 'YES') {
        $categories = explode('/',$_GET['id']);
        $category_part = array();
        foreach($categories as $key=>$value) {
            if(sizeof($category_part) > 0) {
                $lft_rgt_sql = "AND left_>".$category_part['left_']." AND right_<".$category_part['right_'];    
            }
            $category_part = $db->GetRow("SELECT id, left_, right_ FROM ".T_CATEGORY." WHERE friendly_url=? $lft_rgt_sql AND level=?",array($value,$key+1));   
        }
        //$path = $category_tree->getPathByFriendlyURL($categories[(count($categories)-1)]);
        $_GET['id'] = $category_part['id'];
    }
    $path = $category_tree->getPath($_GET['id']); 
    $path_count = count($path);
    if($path_count < 1) {
        header('HTTP/1.1 410 Gone');
        header('Location: '.BASE_URL);
        exit();
    }
    $category_tree->addHit($_GET['id'],$_SERVER['REMOTE_ADDR']);
    
    if(!($template_content->is_cached())) {
        $show_banner = $config['show_banner_cats'];
        //$path = $category_tree->getPath($_GET['id']);
        //$category_url_string = getPlainTextString($path,'/',true);
        $page_title = getCategoryPathDisplay($path,$lang['category'],'|',true,'status_line');
        $incomingline = '<a class="status_line" href="'.BASE_URL.'/">'.$lang['home'].'</a> | '.$page_title;

        $cat_info = $path[($path_count-1)];
        if($cat_info['description'] != '' AND $config['show_category_description'] == 'YES') {
            $cat_info['description'] = unHTML($cat_info['description'].'<br><br><br>');
        } else {
            $cat_info['description'] = '';
        }
        
        if($config['show_category_title'] != 'YES') {
            $cat_info['title'] == '';
        }
        
        $template_content->set('cat_info',$cat_info);
    }
}

if(!($template_content->is_cached())) {
    if($config['show_indexes'] == 'NO' AND $config['cat_empty_hidden'] == 'NO') {
        $get_category_count = false;
    } else {
        $get_category_count = true;
    }
    
    if ($config['show_subs_number'] > 0) {
        $categories=$category_tree->getCategoryPlusImmediateChildren($_GET['id'], 2, $get_category_count);
    } else {
        $categories=$category_tree->getCategoryPlusImmediateChildren($_GET['id'], 1, $get_category_count);
    }
    $first_level_count = 0;
    $first_level_count_reference = $categories[0]['level']; 
    for ($i=0;$i<sizeof($categories);$i++) {
        if($first_level_count_reference == $categories[$i]['level'] AND ($categories[$i]['count'] > 0 OR $config['cat_empty_hidden'] != 'YES')) {
            $first_level_count++;
        }
        // If we never get the listing counts for categories, make it 1 for all categories so they all display normally.  Then if clicked we give a no listings message. (speed improvement)
        if(!$get_category_count) {
            $categories[$i]['count'] = 1;
        }        
    }
                   
    $j = 0;
    $category_table = '<table border="0" cellpadding="0" cellspacing="0" align="center" width="90%">';
    if($config['category_vertical_sort'] == "YES") {
        $category_table .= '<tr>';
    }

    $td_width = floor(100 / $config['category_num_columns']);            

    for ($i=0;$i<sizeof($categories);$i++) {
        if(($config['cat_empty_hidden'] == 'YES' AND $categories[$i]['count'] == 0) OR ($categories[$i]['level'] != $first_level_count_reference)) {
            continue;
        }
        
        $maincat_string = '';
        if ($j % $config['category_num_columns'] == 0 AND $config['category_vertical_sort'] != 'YES') {
            $maincat_string .= '<tr>';
        } elseif(($j == 0 OR $j % ceil($first_level_count/$config['category_num_columns']) == 0) AND $config['category_vertical_sort'] == 'YES') {
            $maincat_string .= '<td valign="top" width="'.$td_width.'%">';  
        }
        
        if($config['category_vertical_sort'] != 'YES') {
            $maincat_string .= '<td valign="top" width="'.$td_width.'%">';
        }
        
        $subcat_string = '';
        
        $maincat_string .= '<ul class="category_ul"><li class="category_li">';

        if($categories[$i]['count'] > 0) {
            $maincat_string .= '<a href="'.getCategoryURL($categories[$i]['id'],$categories[$i]['friendly_url'],$lang['category'],$path).'">';;
            $maincat_string .= '<span class="text_large_bold">';
        } else {
            $categories[$i]['count'] = 0;
            $maincat_string .= '<span class="text_large_bold_grey">';
        } 
        $maincat_string .= $categories[$i]['title'].'</span>';

        if ($categories[$i]['count'] > 0) {
            $maincat_string .= '</a>';
        }

        if ($config['show_indexes'] == 'YES') {
 		    $maincat_string .= '<span class="text_large_bold_grey">&nbsp;('.$categories[$i]['count'].')</span>';
        }
        $sub_counter = 0;
        if ($config['show_subs_number'] > 0) {  // if we want to have subcats
            for($y=$i; $y<sizeof($categories); $y++) { // loop through remaining categories
                if($config['cat_empty_hidden'] == 'YES' AND $categories[$y+1]['count'] == 0) {
                    continue;
                }
                if($categories[($y+1)]['level'] > $categories[$i]['level']) { // if they are a higher level, it means they are a subcat
                    $sub_counter++;  // count how many subcats we add
                    if(($sub_counter-1) < $config['show_subs_number']) {  // subtract one because we count before this comparison
                        if($sub_counter != 1) {
                            $subcat_string .=  '<span class="text_small_grey">, </span>';    
                        }
                        if($categories[$y+1]['count'] > 0) {
                            array_push($path,$categories[$i]); // add parent array to end of path array for subcats
                            $subcat_string .= '<a href="'.getCategoryURL($categories[$y+1]['id'],$categories[$y+1]['friendly_url'],$lang['category'],$path).'">';
                            array_pop($path); // get rid of parent of subcat to prevent bad paging links
                            $subcat_string .= '<span class="text_small">';
                        } else {
                            $categories[$y+1]['count'] = 0; 
                            $subcat_string .= '<span class="text_small_grey">';
                        } 
                        $subcat_string .= $categories[$y+1]['title'].'</span>';

                        if ($categories[$y+1]['count'] > 0) {
                           $subcat_string .= '</a>';
                        }
                        if ($config['show_indexes'] == 'YES') {
                             $subcat_string .= '<span class="text_small_grey">&nbsp;('.$categories[$y+1]['count'].')</span>';
                        }
                        //if ($categories[($y+2)]['level'] == $categories[($y+1)]['level']) { // if we have more subcats
                        //     $subcat_string .=  '<span class="text_small_grey">, </span>';
                        //}
                    } else {
                        $subcat_string .= '<span class="text_small_grey">, </span><a href="'.getCategoryURL($categories[$i]['id'],$categories[$i]['friendly_url'],$lang['category'],$path).'/">'.$lang['more'].'..</a>';
                        break;
                    }
                } else {  // break if we run out of categories, or next one is a main category
                    break;
                }
            }
        }
        $i += $sub_counter;   
        if($subcat_string != '') $maincat_string .= '<br class=spacer><br class=spacer>'.$subcat_string;
        
        $maincat_string .= '</li></ul>';
        $j++;
        if ($j % $config['category_num_columns'] == 0 AND $config['category_vertical_sort'] != 'YES') {
            $maincat_string .= '</tr>';
        } elseif($j % ceil($first_level_count/$config['category_num_columns']) == 0 AND $config['category_vertical_sort'] == 'YES') {
            $maincat_string .= '</td>';
        }
        $category_table .= $maincat_string;
    }

    if ($j % $config['category_num_columns'] != 0 AND $config['category_vertical_sort'] != 'YES') {
        while ($j % $config['category_num_columns'] != 0) {
            $category_table .= '<td>&nbsp;</td>';
            $j++;
        }
        $category_table .= '</tr>';
    } else {
        //echo '</tr>';
    }

    $category_table .= '</table>';
     
      
    /******************************************
    * Show Listings if any exist in category
    ******************************************/

    $listing_page = declare_page($_GET['page']);
    $page_start = get_page_start($listing_page,$config['count_directory']);

    $fetchcounter = $config['count_directory'];

    $r = $category_tree->getListings($_GET['id'],false, $page_start, $config['count_directory'],'membership DESC, firmname');
    $results_amount = $category_tree->getListings($_GET['id'],true);
    $results_amount = $results_amount->FetchRow();

    ob_start();
    if($results_amount['count'] > 0) {  
        echo '<br><div align="left"><span class="text">&nbsp;&nbsp;&nbsp;'.$lang['results'].': <b>'.$results_amount['count'].'</b></span></div><br>'; 
        if ($results_amount['count'] > 0) {
	        include (PMDROOT . "/includes/template_listing_results.php");
            
	        if ( $config['count_directory'] > 0 ) {
	            if ($config['mod_rewrite'] == 'YES') {
	 		        echo paginate($results_amount['count'], $config['count_directory'], 30, $listing_page, $lang['previous'], $lang['next'], $lang['first'], $lang['last'], getCategoryURL($cat_info['id'],$cat_info['friendly_url'],$lang['category'],$path).'#page.html', true);
                } else{
	 		        echo paginate($results_amount['count'], $config['count_directory'], 30, $listing_page, $lang['previous'], $lang['next'], $lang['first'], $lang['last'], getCategoryURL($cat_info['id'],$cat_info['friendly_url'],$lang['category'],$path).'&page=#page', true);
                }
            }
            echo '<br/><br/>';
        }
        echo '<br><br>';
    } elseif(sizeof($categories) < 1 AND $_GET['id'] != 1) {
        echo '<span class="text">'.$lang['no_listings'].'</span>';
    }
    $listing_results = ob_get_contents();
    ob_end_clean();

    if($config['search_display_all'] != 'YES') {
        include (PMDROOT.'/includes/template_searchform.php');
        $template_content->set('searchform',$searchform);
    }
    $template_content->set('category_table',$category_table);
    $template_content->set('listing_results',$listing_results);
    $template_search_alpha_links = & new PMDTemplate(PMDROOT .'/template/' . $config['template'] . '/blocks/search_alpha_links.tpl');
    $template_search_alpha_links->set('alpha_letters',explode('#',$config['alpha_index_search']));
    $template_content->set('search_alpha_links',$template_search_alpha_links);

    $meta_desc = $cat_info['title'].' '.$cat_info['description'];
}
include(PMDROOT.'/includes/template_setup.php');
?>