L
L
lexstile2017-06-15 23:31:21
CMS
lexstile, 2017-06-15 23:31:21

How to set up a 404 error?

There is a site on cms - ArwShop.
Most of the errors are processed by cms itself, including 404, but there is a drawback.
The system does not check for the existence of .php, .htm, .txt extension pages.
I went the usual way, created 404.php, entered it in htaccess.
I copied the contents of index.php to 404.php - now the main page is displayed with a 404 error, which is logical.
So, I would like the 404 template to be displayed, it is already embedded in the system.
There is a function that header404() is responsible for.
But I can't stick it to the 404 page - I don't understand how.
Here is index.php and 404.php :
https://pastebin.com/7uDP5w4a
And also output 404 error if category not found:

<?php 
// ArwShop Market v3.3.1 Copyright (c) Igor Anikeev ( http://www.arwshop.ru/ ) 2006 - 2017.
// YOU CAN NOT SPREAD THIS SOFTWARE AND ITS SEPARATE PARTS NOT IN WHAT ITS KIND!
// ВЫ НЕ ИМЕЕТЕ ПРАВА ТИРАЖИРОВАТЬ, ИМИТИРОВАТЬ, РАСПРОСТРАНЯТЬ ДАННЫЙ ПРОГРАММНЫЙ ПРОДУКТ НИ В КАКОМ ЕГО ВИДЕ.
?><?php
if(! defined('SYS_LOADER')){die();}

echo get_products($cat);

function get_products($cat){
global $sett, $pg, $page_tags, $db, $custom, $lang, $shop, $fcat;
 if(! $page_tags['chain_title_link']){
 return header404();
 }

$custom->get_lang('category');

$_GET['sort'] = isset($_GET['sort']) ? preg_replace("([^a-z\_])", '', $_GET['sort']) : '';
$_GET['desc'] = isset($_GET['desc']) ? intval($_GET['desc']) : 0;
$_GET['only_mnf'] = isset($_GET['only_mnf']) ? intval($_GET['only_mnf']) : 0;

$tbl_items=DB_PREFIX.'items';
$tbl_item_categories=DB_PREFIX.'item_categories';
$tbl_manufacturers=DB_PREFIX.'manufacturers';

$check_def_cat=preg_replace('/\D/', '', $cat);
if($check_def_cat != $cat){return '';}
$cat=intval($cat);

$cat_where1="$tbl_item_categories.catid = $cat";
$item_goup1='';
 if($sett['sbcpr']){
 $sql_cats=c_child_categories($cat);
 $cat_where1="$tbl_item_categories.catid IN($sql_cats)";
 $item_goup1="GROUP BY $tbl_items.itemid";
 unset($sql_cats);
 }

 if($sett['sort_onlycatmnf'] || ! empty($sett['mnu_onlycatmnf'])){
 $res = $db->query("SELECT $tbl_items.mnf_id FROM $tbl_item_categories, $tbl_items WHERE $cat_where1 AND $tbl_items.itemid = $tbl_item_categories.itemid AND $tbl_items.visible = 1 $item_goup1") or die($db->error());
  while($row=$db->fetch_array($res)){
   if($row['mnf_id'] && ! in_array($row['mnf_id'], $shop->onlycatmnfs)){
    if(isset($shop->manufacturers["$row[mnf_id]"])){
    array_push($shop->onlycatmnfs, $row['mnf_id']);
    }
   }
  }
 }

$template = new template('category.tpl');

$subcats_count = get_subcategories($cat, $template);

 if($subcats_count < 1){
 $template->not_condition('subcategories_exists');
 }
 else{
 $template->condition('subcategories_exists');
 }

$template->assign('category_chain_link', "$page_tags[chain_title_link]");
$template->assign('special_text', $page_tags['special']);
$template->assign('category_id', $cat);
$template->assign('sort_options', $shop->get_sort_options());
$template->assign('desc_options', $shop->get_desc_options());
$template->assign('manufacturer_options', get_manufacturer_options());

$template->assign('category_description', $page_tags['description']);

$template->assign('sel_currencies_options', $shop->get_sel_currencies_options());
$template->assign('request_uri_encoded', urlencode($_SERVER['REQUEST_URI']));

 if($page_tags['image']){
 $template->condition('category_image');
 $template->assign('category_image', "<img src=\"$sett[relative_url]img/small/$page_tags[image]\" alt=\"$page_tags[chain_title]\">");
 }
 else{
 $template->not_condition('category_image');
 $template->assign('category_image', '');
 }

 if(! empty($shop->categories["$cat"]['menu_img'])){
 $template->assign('category_menu_image', "<img src=\"$sett[relative_url]img/small/".$shop->categories[$cat]['menu_img'].'">');
 }
 else{
 $template->assign('category_menu_image', '');
 }

 if(! empty($shop->categories["$cat"]['main_img'])){
 $template->assign('category_main_image', "<img src=\"$sett[relative_url]img/small/{$shop->categories[$cat][main_img]}\">");
 }
 else{
 $template->assign('category_main_image', '');
 }

 if($_GET['only_mnf']){
 $mnf_where=" AND $tbl_items.mnf_id = $_GET[only_mnf] ";
 }
 else{
 $mnf_where='';
 }

$res = $db->query("SELECT $tbl_items.itemid FROM $tbl_item_categories, $tbl_items WHERE $cat_where1 AND $tbl_items.itemid = $tbl_item_categories.itemid AND $tbl_items.visible = 1 $mnf_where $item_goup1") or die($db->error());
$quantity_products = $db->num_rows($res);

$pg=intval($pg);
if(! $pg){$pg=1;}

 if($quantity_products<1){
 $template->not_condition('products');
 return $template->out_content();
 }
 else{
 $template->condition('products');
 }


$sett['products_onpage']=intval($sett['products_onpage']);
 if($sett['products_onpage'] < 1){
 $sett['products_onpage'] = 10;
 }

$tstfirst_line=$pg * $sett['products_onpage'] - $sett['products_onpage'];
$first_line=intval($tstfirst_line);
if($first_line != $tstfirst_line){return header404();}

if($first_line < 0 ){return '';}

 if($_GET['sort']){
   switch($_GET['sort']){
   case 'id': $orderby = "$tbl_items.itemid"; break;
   case 'udate': $orderby = "$tbl_items.upd_date"; break;
   case 'price': $orderby = "$tbl_items.price"; break;
   case 'title': $orderby = "$tbl_items.title"; break;
   case 'sku': $orderby = "$tbl_items.sku"; break;
   case 'mnf': $orderby = "$tbl_manufacturers.title"; break;

   default: $orderby = "$tbl_items.itemid";
   }
  if($_GET['desc']){$orderby.=' DESC';}
 }
 elseif(! empty($sett['sort_products'])){
   switch($sett['sort_products']){
   case 'id': $orderby = "$tbl_item_categories.sortid, $tbl_items.itemid"; break;
   case 'udate': $orderby = "$tbl_item_categories.sortid, $tbl_items.upd_date"; break;
   case 'price': $orderby = "$tbl_item_categories.sortid, $tbl_items.price"; break;
   case 'title': $orderby = "$tbl_item_categories.sortid, $tbl_items.title"; break;
   case 'sku': $orderby = "$tbl_item_categories.sortid, $tbl_items.sku"; break;
   case 'mnf': $orderby = "$tbl_item_categories.sortid, $tbl_manufacturers.title"; break;
   default: $orderby = "$tbl_item_categories.sortid, $tbl_items.itemid";
   }
  if($sett['sortpr_desc']){$orderby.=' DESC';}
 }
 else{
 $orderby = "$tbl_item_categories.sortid, $tbl_items.itemid DESC";
 }


$template->get_cycle('products');
$template->get_cycle('product_options', 'products');

$limit='';
 if(empty($_GET['show_all'])){
 $limit=" LIMIT $first_line, $sett[products_onpage]";
 }

 if(! empty($sett['sort_nostock_last'])){
 $order_nostock_last = "`$tbl_items`.`quantity` > 0 DESC, ";
 }
 else{
 $order_nostock_last = '';
 }

$res = $db->query("SELECT $tbl_items.itemid, $tbl_items.itemname, $tbl_items.catid, $tbl_items.mnf_id, $tbl_items.sku, $tbl_items.title, $tbl_items.price, $tbl_items.old_price, $tbl_items.quantity, $tbl_items.quantity_txt, $tbl_items.short_descript, $tbl_items.small_img, $tbl_items.big_img, $tbl_manufacturers.mnfname, $tbl_manufacturers.title as manufacturer_title FROM $tbl_item_categories, $tbl_items, $tbl_manufacturers WHERE $cat_where1 AND $tbl_items.itemid = $tbl_item_categories.itemid AND $tbl_items.visible = 1 AND $tbl_manufacturers.mnf_id = $tbl_items.mnf_id $mnf_where $item_goup1 ORDER BY $order_nostock_last$orderby$limit") or die($db->error());

$shop->list_products($res, $template, 'prLstNoCat');

$template->out_cycle();



$kolvopagesconst=ceil($quantity_products / $sett['products_onpage']);

 if($pg>1 && $pg>$kolvopagesconst){
 return header404();
 }



$full_pagebar='';

 if($kolvopagesconst > 1 && empty($_GET['show_all'])){

 $kolvopages = $kolvopagesconst;
 $pagenumber = 1;
 $pagebar = '';

  while($kolvopages>0){
   if($pagenumber == $pg){
   $pagebar .= "<span class=\"PgOpen\">$pagenumber</span> &nbsp;";
   }
   else{
    if($pagenumber==1){
    $pagebar.='<a href="' . $shop->rparams("cat=$cat", $custom->statlink($fcat, '', "cat$cat/", 'c')) . "\" class=\"PglA\">$pagenumber</a> &nbsp;";
    }
    else{
    $pagebar.='<a href="' . $shop->rparams("cat=$cat&amp;pg=$pagenumber", $custom->statlink($fcat, "pg$pagenumber.html", "cat$cat/pg$pagenumber.html", 'c')) . "\" class=\"PglA\">$pagenumber</a> &nbsp;";
    }
   }
  $kolvopages--;
  $pagenumber++;
  }

  if($pg >= $kolvopagesconst){
  $nextpage = '';
  }
  else{
  $nextpage=$lang['next'];
  }

  if($pg<=1){
  $prevpage='';
  }
  else{
  $prevpage=$lang['previous'];
  }

 $nextpagenumber=$pg+1;
 $prevpagenumber=$pg-1;

  if($prevpagenumber==1 && $prevpage){
  $full_pagebar.='<a href="' . $shop->rparams("cat=$cat", $custom->statlink($fcat, '', "cat$cat/", 'c')) . "\" rel=\"prev\" class=\"PglPrev\">$prevpage</a> &nbsp;";
  }
  elseif($prevpage){
  $full_pagebar.='<a href="' . $shop->rparams("cat=$cat&amp;pg=$prevpagenumber", $custom->statlink($fcat, "pg$prevpagenumber.html", "cat$cat/pg$prevpagenumber.html", 'c'))  . "\" rel=\"prev\" class=\"PglPrev\">$prevpage</a> &nbsp;";
  }

 $full_pagebar .= $pagebar;

  if($nextpage){
  $full_pagebar.='<a href="' . $shop->rparams("cat=$cat&amp;pg=$nextpagenumber", $custom->statlink($fcat, "pg$nextpagenumber.html", "cat$cat/pg$nextpagenumber.html", 'c')) . "\" rel=\"next\" class=\"PglNext\">$nextpage</a>";
  }

  if(! empty($sett['show_all_lnk'])){
   if(empty($_GET['sort'])){
   $_GET['sort'] = $shop->get_sort();
   }
  $full_pagebar .= ' <a href="'.$shop->rparams("cat=$cat", 'show_all').'" class="show_all">'.$lang['show_all'].'</a>';
  }

 }

$template->assign('pages_links', $full_pagebar);
$template->assign('category_id', $cat);

return $template->out_content();
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question