Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 8

Author Topic: [PACKAGE] Subcategories  (Read 37122 times)

centered

  • Guest
[PACKAGE] Subcategories
« on: February 22, 2008, 05:20:01 AM »

* 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
Code: [Select]
<? timing('end'); ?>
Validation fix:
Replace function subcategories
Code: [Select]
// 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:
Code: [Select]
echo html_input('hidden', 'id', 'id', $categoryid, '', '', '', '', '', '', '', '', '', '', '');
echo html_input('submit', 'delete_category', 'delete_category', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');

Replace with:
Code: [Select]
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/"
Code: [Select]
// 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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
$name = empty($categoryid) || $subcat!='cat' ? retrieve('name','categories','id',$sub_cat):'';

Replace with:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
$home = l('home_sef'); $categorySEF = get_id('category');

with:
Code: [Select]
$categorySEF = empty($categorySEF) ? $home : $categorySEF;
Then find:
Code: [Select]
paginator($categorySEF, $currentPage, $totalPages, '', l('paginator'));Before that line add:
Code: [Select]
if (!empty($subcatSEF)) { $categorySEF = $categorySEF.'/'.$subcatSEF; } else { $categorySEF = $categorySEF; }
« Last Edit: September 27, 2008, 08:46:27 AM by equilni »
Logged

jlhaslip

  • Sr. Member
  • ****
  • Karma: 16
  • Posts: 374
    • My snews with AEF Forum site
Re: [PACKAGE] Subcategories
« Reply #1 on: February 22, 2008, 07:12:28 AM »

Do you have a Demo site?
Logged
Yes! I have no siggy.

centered

  • Guest
Re: [PACKAGE] Subcategories
« Reply #2 on: February 22, 2008, 12:34:30 PM »

No sorry, no demo site as of yet
Logged

Nicu Alecu

  • Full Member
  • ***
  • Karma: 12
  • Posts: 224
    • BLUEBYTE.ro // IT consultant
Re: [PACKAGE] Subcategories
« Reply #3 on: February 22, 2008, 12:38:04 PM »

Now this is something I would really like ... I'll test it over the weekend (I'm too lazy today, it's one of those Fridays ;)).
If everythings works ok (and I'm over my laziness tomorrow) I'll post a test url.
Logged

centered

  • Guest
Re: [PACKAGE] Subcategories
« Reply #4 on: February 22, 2008, 12:52:23 PM »

Thanks Nick!
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [PACKAGE] Subcategories
« Reply #5 on: February 22, 2008, 02:38:02 PM »

I know exactly where I can use this mod! New site in the works... stay tuned (as someone reported having heard Steve-o say ...whether it was FSJ or RSJ or some other Steve-o I have no idea...)
;D
Logged

centered

  • Guest
Re: [PACKAGE] Subcategories
« Reply #6 on: February 22, 2008, 03:46:11 PM »

Thanks for that Baker!
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [PACKAGE] Subcategories
« Reply #7 on: February 22, 2008, 04:12:48 PM »

nice package!  holy crap, I sound like Patric.

Hehe... I'll vouch for that!  ;D
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: [PACKAGE] Subcategories
« Reply #8 on: February 22, 2008, 05:25:06 PM »

 8) awesome work equilni
thank you +karma 2u

update:
that was the most needed mod.
that made a very big step to sNewsCMS development.

and a huge thank you to all dev/mod/duds group for all improvments.

 :o

awesome day 2 all
« Last Edit: February 22, 2008, 10:10:57 PM by mosh »
Logged

Phil

  • Full Member
  • ***
  • Karma: 1
  • Posts: 135
    • http://www.ckt.com
Re: [PACKAGE] Subcategories
« Reply #9 on: February 22, 2008, 05:35:41 PM »

Thanks equilni and the others who contributed to this mod.  Does this mod work for both vertical and horizontal layouts?
Logged

centered

  • Guest
Re: [PACKAGE] Subcategories
« Reply #10 on: February 22, 2008, 05:58:10 PM »

If you can style it correct, i don't see why not. Currently my test site gives me an output of:
Code: [Select]
<h3>Categories:</h3>
<ul>
<li><a class="current" href="http://localhost:8888/subCat/uncategorized/" title="">Uncategorized (0)</a>
<ul>
<li class="subcat"><a href="http://localhost:8888/subCat/uncategorized/unsorted/" title="">Unsorted (0)</a></li>
</ul>
</li>
</ul>

Just give your ul a class or id and you should be good to go
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [PACKAGE] Subcategories
« Reply #11 on: February 22, 2008, 06:27:31 PM »

Thanks equilni and the others who contributed to this mod.  Does this mod work for both vertical and horizontal layouts?

Yes it does... provided you style the functions to work with your menus as EQ noted. Horizontal dropdowns with 2 child levels are tricky though.  ;)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [PACKAGE] Subcategories
« Reply #12 on: February 22, 2008, 09:04:24 PM »

Jason, Jason, Jason ... we need to get you a different stash for downloads than Mediafire... I forgot to control-click the download link (Leopard has unfortunately altered my downloading behavior, these days I just normal-click dl-links...) and of course now I can't change your text encoding from Western (Mac OS Roman) to UTF-8 which I need. Don't know why though. It just doesn't work. And if fu*ks things up... And Mediafire is under maintenance so I can't re-download...
What? Patience? ME!?!?! lol
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [PACKAGE] Subcategories
« Reply #13 on: February 22, 2008, 09:52:12 PM »

Jason, Jason, Jason ... we need to get you a different stash for downloads than Mediafire... I forgot to control-click the download link (Leopard has unfortunately altered my downloading behavior, these days I just normal-click dl-links...) and of course now I can't change your text encoding from Western (Mac OS Roman) to UTF-8 which I need. Don't know why though. It just doesn't work. And if fu*ks things up... And Mediafire is under maintenance so I can't re-download...
What? Patience? ME!?!?! lol

We're starting the "Get Jason some WebSpace Campaign. All donations for Jason will be favorably received by Fred.  ;)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Ken Dahlin

  • Full Member
  • ***
  • Karma: 30
  • Posts: 139
    • http://www.kendahlin.com/
Re: [PACKAGE] Subcategories
« Reply #14 on: February 23, 2008, 05:22:19 AM »

Oh me oh my, I can't wait to take this for a spin.  :D
Logged
Pages: [1] 2 3 ... 8