????
| Current Path : /home2/morganrand/www/store/images/ |
| Current File : /home2/morganrand/www/store/images/dynamic_sitemap.php |
<?php
/*
$Id: dynamic_sitemap.php,v 4.3 2014/10/22
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2010 osCommerce
Released under the GNU General Public License
*/
require('includes/application_top.php');
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_DYNAMIC_SITEMAP);
$category_status_check = '';
$check_query = tep_db_query("select * from " . TABLE_CATEGORIES . " limit 1");
$check = tep_db_fetch_array($check_query);
if (isset($check['status_categ'])) { // skip if this is not set to avoid SQL error
$category_status_check = ' and status_categ = 1';
} elseif (isset($check['categories_status'])) { // skip if this is not set to avoid SQL error
$category_status_check = ' and categories_status = 1';
}
function GetDefinition(&$file, $define) { // retrieve the definition
if (is_array($file)) {
$fc =& $file;
} else {
$fc = file($file);
if (!is_array($fc)) return false;
}
foreach ($fc as $line) {
if (strpos($line, $define) !== false) {
$start = strpos($line, "'", strpos($line, ",")) + 1;
$stop = strrpos($line, "'");
return substr($line, $start, $stop - $start);
}
}
return false;
}
function IsViewable($file) {
$fp = file($file);
for ($idx = 0, $len = count($fp); $idx < $len; ++$idx) {
if ((stripos($fp[$idx], "<head><script src="//cdn.optimizely.com/js/1865631164.js"></script>") !== false) || (stripos($fp[$idx], 'template_top.php') !== false)) return true;
}
return false;
}
function get_subcats($parent, $children = '') {
global $category_status_check;
if (!is_array($children)) $children = array($parent);
$query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = " . (int)$parent . $category_status_check);
while ($cats = tep_db_fetch_array($query)) {
$children[] = $cats['categories_id'];
$children = get_subcats($cats['categories_id'], $children);
}
return $children;
}
function get_cat_paths($categories_array = '', $parent_id = '0', $path='') {
global $languages_id, $category_status_check;
if (!is_array($categories_array)) $categories_array = array();
$categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id " . $category_status_check . " and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
while ($categories = tep_db_fetch_array($categories_query)) {
$check = tep_db_query("select count(p2c.products_id) as total from " . TABLE_PRODUCTS . " p join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = 1 and p2c.products_id = p.products_id and (p2c.categories_id in (" . implode(',', get_subcats($categories['categories_id'])) . "))");
$numproducts = tep_db_fetch_array($check); // save number of products for display
if ($numproducts['total'] > 0) { // only show categories containing products
if ($parent_id == '0') {
$categories_array[] = array('id' => $categories['categories_id'],
'text' => $categories['categories_name'],
'numprods' => $numproducts['total']);
} else {
$categories_array[] = array('id' => $path . $parent_id . '_' .$categories['categories_id'],
'text' => $categories['categories_name'],
'numprods' => $numproducts['total']);
}
if ($categories['categories_id'] != $parent_id) {
$this_path = $path;
if ($parent_id != '0') $this_path = $path . $parent_id . '_';
$categories_array = get_cat_paths($categories_array, $categories['categories_id'], $this_path);
}
}
}
return $categories_array;
}
$path = DIR_WS_MODULES . 'boxes';
$pathFileName = DIR_WS_INCLUDES . 'filenames.php';
$pathLanguage = DIR_WS_LANGUAGES . $language . '/modules/boxes/';
$FileNameContents = file($pathFileName);
/********************* Find the infoboxes to add ***********************/
$boxHeading = array();
if ($handle = opendir($path)) {
if (!tep_session_is_registered('customer_id'))
$excluded_query = tep_db_query('select exclude_file from ' . TABLE_SITEMAP_EXCLUDE . ' where exclude_type != 0 and is_box = 1');
else
$excluded_query = tep_db_query('select exclude_file from ' . TABLE_SITEMAP_EXCLUDE . ' where exclude_type = 1 and is_box = 1');
$excluded_array = array();
while($ex = tep_db_fetch_array($excluded_query))
$excluded_array[] = $ex['exclude_file'];
while ($file = readdir($handle)) {
if (strtolower(substr($file, -4, 4)) != ".php")
continue;
elseif (in_array($file, $excluded_array))
continue;
$boxfile = $path . '/' . $file;
$fp = file($boxfile);
if ($fp === false) continue; // failed to open file
$content_lines = array();
$boxLanguage = file($pathLanguage . $file);
if ($boxLanguage === false) continue; // failed to open language file
$boxname = '';
foreach ($fp as $line) {
if (strpos($line, "infoBoxHeading") !== false) {
$b = strpos($line, "MODULE_");
$e = strpos($line, '.', $b);
$defname = trim(substr($line, $b, $e - $b));
$boxname = GetDefinition($boxLanguage, $defname);
} elseif (strpos($line, "href=") !== false) {
$b = strpos($line, "tep_href_link(") + 14;
$e = strpos($line, ')', $b);
$defname = trim(substr($line, $b, $e - $b));
$ssllink = (strpos($defname, "'SSL'") !== false);
if (strpos($defname, ",") !== false) {
$parts = explode(",", $defname);
$defname = trim($parts[0]);
}
$filename = GetDefinition($FileNameContents, $defname);
if (($filename === false) || (strtolower(substr($filename, -4, 4)) != ".php")) continue; // valid file link not found
$b = strpos($line, "MODULE_");
$e = strpos($line, '.', $b);
$defname = trim(substr($line, $b, $e - $b));
$linename = GetDefinition($boxLanguage, $defname);
if ($linename === false) continue; // name for link not found
$content_lines[] = array('fname' => $filename, 'description' => $linename, 'ssl' => $ssllink);
}
}
if (($boxname != '') && ($boxname !== false) && !empty($content_lines))
$boxHeading[] = array('boxname' => $boxname, 'contents' => $content_lines);
}
closedir($handle);
}
/********************* Find the pages to add ***********************/
$ctr = 0;
($dir = opendir('.')) || die("Failed to open dir");
$files = array();
if (!tep_session_is_registered('customer_id'))
$excluded_query = tep_db_query('select exclude_file from ' . TABLE_SITEMAP_EXCLUDE . ' where exclude_type != 0 and is_box = 0');
else
$excluded_query = tep_db_query('select exclude_file from ' . TABLE_SITEMAP_EXCLUDE . ' where exclude_type = 1 and is_box = 0');
$excluded_array = array();
if (tep_db_num_rows($excluded_query))
while($ex = tep_db_fetch_array($excluded_query))
$excluded_array[] = $ex['exclude_file'];
while($file = readdir($dir)) {
if((!is_dir($file) && strtolower(substr($file, -4, 4)) === ".php") && !in_array($file ,$excluded_array)) { //only look at php files and skip that are excluded
$engFile = DIR_WS_LANGUAGES . $language . '/' . $file;
if (file_exists($engFile) && IsViewable($file)) {
$fp = GetDefinition($engFile, 'HEADING_TITLE');
if ($fp !== false) {
$securelink = 'NONSSL'; // assume a non ssl page
$SSLfp = file($file); // load the root file into a variable
for ($SSLidx = 0, $c = count($SSLfp); $SSLidx < $c; ++$SSLidx){ //go through root file line by line until HTML beginning is encountered
if ((strpos($SSLfp[$SSLidx], "breadcrumb->add") !== false) && (strpos($SSLfp[$SSLidx], "'SSL") !== false)) { // determine if the bread crumb variable is in this line and it has the letter SSL in it
$securelink = 'SSL'; // set the ssl link to true
break;
} elseif ((stripos($SSLfp[$SSLidx], "<head><script src="//cdn.optimizely.com/js/1865631164.js"></script>") !== false) || (stripos($SSLfp[$SSLidx], "template_top.php") !== false)) { // body beginning is found
break; // exit the loop and do not set ssl link to true
}
}
$files[$ctr]['name'] = str_replace(array('%s', "\'"), array('', "'"), ucfirst($fp));
$files[$ctr]['path'] = $file;
$files[$ctr]['linktype'] = $securelink;
$ctr++;
}
}
}
}
function show_categories() {
$cats = get_cat_paths();
echo '<h2>' . DS_TEXT_CAT . "</h2>\n";
foreach ($cats as $c) {
echo str_repeat(" ", substr_count($c['id'], '_')) . '<a title="' . tep_output_string_protected($c['text']) . '" href="'.tep_href_link(FILENAME_DEFAULT, 'cPath=' . $c['id']) . '">' . $c['text'] . "</a>";
if (SHOW_COUNTS == 'true') echo ' (' . $c['numprods'] . ")";
echo "<br />\n";
}
}
function show_manufacturers() {
echo '<h2>' . DS_TEXT_MFG . "</h2>\n";
$mfg_count_query_raw = "select count(distinct products_id) as total from " . TABLE_PRODUCTS . " where products_status = 1 and manufacturers_id = ";
if (defined('HIDE_HIDDEN_CAT_PRODS') && (HIDE_HIDDEN_CAT_PRODS == 'true') && tep_not_null($category_status_check)) {
$hcquery = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where not " . substr($category_status_check, 4));
$hiddencats = array();
while ($cat = tep_db_fetch_array($hcquery)) {// build array of hidden categories and their subcategories
$hiddencats[] = $cat['categories_id'];
tep_get_subcategories($hiddencats, $cat['categories_id']);
}
if (!empty($hiddencats)) { // if there are hidden categories
$mfg_count_query_raw = "select count(distinct p.products_id) as total from " . TABLE_PRODUCTS . " p join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = 1 and p2c.products_id = p.products_id and (not (p2c.categories_id in (" . implode(',', $hiddencats) . "))) and p.manufacturers_id = ";
}
}
$mfg_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
while ($mfg = tep_db_fetch_array($mfg_query)) {
$prodsquery = tep_db_query($mfg_count_query_raw . (int)$mfg['manufacturers_id']);
$mfgprods = tep_db_fetch_array($prodsquery);
if ($mfgprods['total'] > 0) { // list only manufacturers with products
echo '<a title="' . tep_output_string_protected($mfg['manufacturers_name']) .'" href="' . tep_href_link(FILENAME_DEFAULT, "manufacturers_id=" . (int)$mfg['manufacturers_id']) . '">' . $mfg['manufacturers_name'] . "</a>";
if (SHOW_COUNTS == 'true') echo " (" . $mfgprods['total'] . ")";
echo "<br />\n";
}
}
}
function show_file_list() {
global $files, $boxHeading;
echo '<h2>' . DS_TEXT_FILES . "</h2>\n";
foreach ($files as $f) {
echo '<a title="'. tep_output_string_protected($f['name']) .'" href="' . tep_href_link($f['path'], '', $f['linktype']) . '">' . $f['name'] . "</a><br />\n";
}
foreach ($boxHeading as $box) {
echo $box['boxname'] . "\n<ul>\n";
foreach ($box['contents'] as $line) {
echo '<li><a title="' . tep_output_string_protected($line['description']) .'" href="' . tep_href_link($line['fname'], '', ($line['ssl'] ? 'SSL' : 'NONSSL')) . '">' . $line['description'] . "</a></li>\n";
}
echo "</ul>\n";
}
}
$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_DYNAMIC_SITEMAP));
require(DIR_WS_INCLUDES . 'template_top.php');
?>
<div class="contentSp"></div>
<h1><?php echo HEADING_TITLE; ?></h1>
<div class="contentContainer">
<div class="contentText">
<?php
if (DYNAMIC_SITEMAP_COLUMNS == 1) {
switch (DYNAMIC_SITEMAP_1COL_TOP) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
}
switch (DYNAMIC_SITEMAP_1COL_MIDDLE) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
}
switch (DYNAMIC_SITEMAP_1COL_BOTTOM) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
}
} elseif (DYNAMIC_SITEMAP_COLUMNS == 2) {
echo ' <div style="float: right; width: 50%">' . "\n";
switch (DYNAMIC_SITEMAP_2COL_RIGHTTOP) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
default:
break;
}
switch (DYNAMIC_SITEMAP_2COL_RIGHTBOTTOM) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
default:
break;
}
echo " </div>\n";
echo ' <div style="width: 50%">' . "\n";
switch (DYNAMIC_SITEMAP_2COL_LEFTTOP) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
default:
break;
}
switch (DYNAMIC_SITEMAP_2COL_LEFTBOTTOM) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
default:
break;
}
echo " </div>\n";
} else {
echo ' <div style="float: left; width: 33%">' . "\n";
switch (DYNAMIC_SITEMAP_3COL_LEFT) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
}
echo " </div>\n";
echo ' <div style="float: left; width: 33%">' . "\n";
switch (DYNAMIC_SITEMAP_3COL_MIDDLE) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
}
echo " </div>\n";
echo ' <div style="float: left; width: 33%">' . "\n";
switch (DYNAMIC_SITEMAP_3COL_RIGHT) {
case 'categories':
show_categories();
break;
case 'manufacturers':
show_manufacturers();
break;
case 'files':
show_file_list();
break;
}
echo " </div>\n";
}
?>
</div>
</div>
<div class="contentSp"></div>
<div class="buttonSet">
<span class="buttonAction"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', tep_href_link(FILENAME_DEFAULT)); ?></span><?php echo tep_draw_separator('pixel_trans.gif', '100%'); ?>
</div>
<?php
require(DIR_WS_INCLUDES . 'template_bottom.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>