* DOWNLOADS ARE DOWN ATM *
Probably one of the most requested modifications, is pretty much complete. Big Thank yous to Keyrocks, Rui, Joost and bakercad for thier help with making this a reality!
This is a core package, 1 level only. The ability to build further is there if the desire is to do that. If you plan your site accordingly, 1 level is sometimes all one needs.
Please note a few things:
1. No Home Category.
- Home has been replaced by an 'Uncategorized' category since there is a great debate about home being a category.
2. Option to show each article on the front page (thanks to Bakercad)
- With Home being gone as a category, we needed a way to show articles on the front page, just a click away
3. Same name functionality (thanks to Bakercad)
- for instance a store would have Mens Coats and Women's Coats, well you can have Mens -> Coats as category and subcategory, then Womens -> Coats as the same.
4. Booster modifications
- Thanks to Joost and Invarbrass, I have added booster mods to speed up the engine.
NOTE :
1. In index.php - find and remove
<? timing('end'); ?>
Validation fix:
Replace function subcategories
// DISPLAY SUBCATEGORIES
// Subcategories new function
function subcategories($parent) {
$categorySEF = get_id('category');
if (s('num_categories') != 'on') { $sql = ''; }
else { $sql = ", (select count(id) from articles where category = cat.id AND position = 1 AND published = 1) as cat_articles "; }
$subresult = mysql_query("select cat.id, cat.name, cat.seftitle, cat.description$sql from categories as cat WHERE subcat = ".$parent." AND published = 'YES' ORDER BY catorder,id ASC");
// validation fix
if (mysql_num_rows($subresult) > 0) { echo '<ul>'; }
while ($s = mysql_fetch_array($subresult)) {
$subcat_title = $s['seftitle']; $subcatSEF = cat_rel($s['id'], 'seftitle');
$class = $subcat_title == $categorySEF ? ' class="current"' : '';
if (s('num_categories') != 'on') { $num = ''; } else { $num = ' ('.$s['cat_articles'].')'; }
echo '<li class="subcat"><a'.$class.' href="'.db('website').$subcatSEF.'/" title="'.$s['description'].'">'.$s['name'].$num.'</a>';
/* Brave souls could do multiple levels just by looping this function
$parent = $s['id'];
if ($category_title == $categorySEF) { subcategories($parent); }
$subcat = retrieve('subcat','categories','seftitle',$categorySEF);
if ($subcat == $parent) { subcategories($subcat); }
*/
echo '</li>';
}
// validation fix
if (mysql_num_rows($subresult) > 0) { echo '</ul>'; }
}
Bugs -
This removes home as a category and makes sure the user doesn't delete the default category (which should be 1)
. Find:
echo html_input('hidden', 'id', 'id', $categoryid, '', '', '', '', '', '', '', '', '', '', '');
echo html_input('submit', 'delete_category', 'delete_category', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
Replace with:
echo html_input('hidden', 'id', 'id', $categoryid, '', '', '', '', '', '', '', '', '', '', '');
// subcategories
if ($categoryid != 1) {
echo html_input('submit', 'delete_category', 'delete_category', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', ''); } else { echo ''; }
}
Another BUG: From admin panel if you try to "view" a PAGE, you won't get it - engine doesn't add "home" into the link - so the link remains "localhost/subs
//page/" instead of "localhost/subs
/home/gerberrerebe/"
// subcategories
// echo '<p>'.date(s('date_format'), strtotime($r['date'])).' <strong>'.$r['title'].'</strong>'.$cat_subcat.' '.l('divider').' <a href="'.db('website').cat_rel($r['category'],'seftitle').'/'.$articleSEF.'">'.l('view').'</a> ';
$catSEF = $r['category'] == 0 ? l('home_sef') : cat_rel($r['category'], 'name');
echo '<p>'.date(s('date_format'), strtotime($r['date'])).' <strong>'.$r['title'].'</strong>'.$cat_subcat.' '.l('divider').' <a href="'.db('website').$catSEF.'/'.$articleSEF.'">'.l('view').'</a> ';
One can still unpublish it and when adding an article, he/she'd get an empty category-selection-dropdown-list... It's pretty dirty, don't you think?
Now that is a bug right there. Thanks i will get to fixing that too.
FIX:
Find:
if ($subcat=='cat') echo html_input('checkbox', 'publish', 'pub', 'YES', l('publish_category'), '', '', '', '', $frm_publish, '', '', '', '', ''); else echo html_input('checkbox', 'publish', 'pub', 'YES', l('publish_subcategory'), '', '', '', '', $frm_publish, '', '', '', '', '');
Replace with:
if ($subcat=='cat' && $categoryid != 1) {
echo html_input('checkbox', 'publish', 'pub', 'YES', l('publish_category'), '', '', '', '', $frm_publish, '', '', '', '', ''); }
elseif ($subcat!='cat' && $categoryid != 1) {
echo html_input('checkbox', 'publish', 'pub', 'YES', l('publish_subcategory'), '', '', '', '', $frm_publish, '', '', '', '', '');
}
else { echo ''; }
New fix:
Find:
$name = empty($categoryid) || $subcat!='cat' ? retrieve('name','categories','id',$sub_cat):'';
Replace with:
if ($sub_cat!='cat') { $jresult = mysql_query("select name from ".db('prefix')."categories where id = $sub_cat"); while($j = mysql_fetch_array($jresult)) { $name = $j['name']; }}
Codetwist Booster thanks to Armen!
Replace get_id with these 2 functions:
function get_id($parameter) {
$url = array();
$url = explode('/', $_GET['category']);
$get_id = array();
if ($url['1']) {
$sub_cat = cleanGetSef($url['1']);
$result = mysql_query("SELECT seftitle FROM ".db('prefix')."categories WHERE seftitle = '$sub_cat'");
if (!$result || !mysql_num_rows($result)) { $subcat=''; } else {
$r = mysql_fetch_array($result); {$subcat = $r['seftitle'];}
$get_id['subcategory'] = $subcat;}
}
$get_id['category'] = cleanGetSef($url['0']);
if ($url['1'] && !$subcat) {
$get_id['article'] = cleanGetSef($url['1']);
} elseif ($url['2'] && $subcat) {
$get_id['article'] = cleanGetSef($url['2']);
}
if ($url['2'] && !$subcat) {
$get_id['commentspage'] = cleanGetSef($url['2']);
} elseif ($url['3'] && $subcat) {
$get_id['commentspage'] = cleanGetSef($url['3']);}
if (isset($get_id[$parameter])) {return cleanGetSef($get_id[$parameter]);}
}
function cleanGetSef($inSef) {
if ($inSef == '') { $sef = ''; }
elseif (is_int($inSef)) { $sef = (int) $inSef; } else {
if (! preg_match('/^[a-z0-9\-_#\.]+$/', $inSef)) { $sef = false; }
else { $sef = $inSef; }} return $sef;}
In function articles()
replace teh line after:
$home = l('home_sef'); $categorySEF = get_id('category');
with:
$categorySEF = empty($categorySEF) ? $home : $categorySEF;
Then find:
paginator($categorySEF, $currentPage, $totalPages, '', l('paginator'));
Before that line add:
if (!empty($subcatSEF)) { $categorySEF = $categorySEF.'/'.$subcatSEF; } else { $categorySEF = $categorySEF; }