1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

content: categories and subcategories can now be sorted (each has it's own new added preference), used on the category pages

This commit is contained in:
lia 2007-04-17 21:06:06 +00:00
parent 9b5cbebbda
commit e47f8ee167
3 changed files with 114 additions and 34 deletions

View File

@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/content/content.php,v $
| $Revision: 1.14 $
| $Date: 2007-04-16 22:11:08 $
| $Revision: 1.15 $
| $Date: 2007-04-17 21:06:06 $
| $Author: lisa_ $
+---------------------------------------------------------------+
*/
@ -493,9 +493,19 @@ function show_content_recent(){
$cachecheck = CachePost($cachestr);
}
//function to (multi)sort by key
function multi_sort($array, $key)
{
$cmp_val="((\$a['$key']>\$b['$key'])?1:((\$a['$key']==\$b['$key'])?0:-1))";
$cmp=create_function('$a, $b', "return $cmp_val;");
uasort($array, $cmp);
return $array;
}
// ##### CATEGORY LIST ------------------------------------
function show_content_cat_all(){
global $qs, $plugindir, $content_shortcodes, $ns, $plugintable, $aa, $e107cache, $tp, $pref, $content_pref, $totalitems, $row, $datestamp, $comment_total, $gen, $authordetails, $rater, $crumb, $sql, $datequery, $amount, $from, $n, $mainparent, $CM_AUTHOR, $CONTENT_CAT_TABLE_INFO_PRE, $CONTENT_CAT_TABLE_INFO_POST, $CONTENT_CAT_LIST_TABLE_INFO_PRE, $CONTENT_CAT_LIST_TABLE_INFO_POST;
global $qs, $plugindir, $content_shortcodes, $ns, $plugintable, $aa, $e107cache, $tp, $pref, $content_pref, $totalitems, $row, $datestamp, $comment_total, $gen, $authordetails, $rater, $crumb, $sql, $sql2, $datequery, $amount, $from, $n, $mainparent, $CM_AUTHOR, $CONTENT_CAT_TABLE_INFO_PRE, $CONTENT_CAT_TABLE_INFO_POST, $CONTENT_CAT_LIST_TABLE_INFO_PRE, $CONTENT_CAT_LIST_TABLE_INFO_POST;
unset($text);
@ -514,12 +524,7 @@ function show_content_cat_all(){
echo $cachecheck;
return;
}
$array = $aa -> getCategoryTree("", $mainparent, TRUE);
$validparent = implode(",", array_keys($array));
$order = $aa -> getOrder();
$number = varsettrue($content_pref["content_nextprev_number"], '5');
$nextprevquery = (varsettrue($content_pref["content_nextprev"]) ? "LIMIT ".intval($from).",".intval($number) : "");
$qry = " content_parent REGEXP '".$aa -> CONTENTREGEXP($validparent)."' ";
$array = $aa -> getCategoryTree("", $mainparent, TRUE);
$newarray = array_merge_recursive($array);
for($a=0;$a<count($newarray);$a++){
@ -528,12 +533,41 @@ function show_content_cat_all(){
$b++;
}
}
$string = "";
foreach($newparent as $key => $value){
$totalitems = $aa -> countCatItems($key);
$sql -> db_Select($plugintable, "content_id, content_heading, content_subheading, content_text, content_icon, content_author, content_datestamp, content_parent, content_comment, content_rate", "content_id = '".$key."' ");
$row = $sql -> db_Fetch();
$cids = implode(",", array_keys($newparent) );
//we need to get the order for the current mainparent
//the order value for all categories of this top level category will be increased with the top level categories order
//that way, the top level category will always be the first result,
//while all other categories are sorted correctly beneath it
$sql2 -> db_Select($plugintable, "content_id, content_order", " content_id = '".$mainparent."' ");
$row = $sql2 -> db_Fetch();
$mainparent_order = $row['content_order'];
//we parse the order string, dependent of the content_pref
$order = $aa -> getOrder('catall');
//get all records, and tmp store them in the $data array
$data=array();
$sql2 -> db_Select($plugintable, "content_id, content_heading, content_subheading, content_text, content_icon, content_author, content_datestamp, content_parent, content_comment, content_rate, content_order", " content_id IN (".$cids.") ".$order." ");
while($row = $sql2 -> db_Fetch()){
if($row['content_id']!=$mainparent){
$row['content_order'] += $mainparent_order;
}
$data[] = $row;
}
//we need to reorder the records, but only if we need to sort by the content_order value
//in all other sort/order cases, the above query is already correct
$orderstring = ($content_pref['content_catall_defaultorder'] ? $content_pref['content_catall_defaultorder'] : "orderaheading" );
if(substr($orderstring,6) == "order"){
//sort the array on the order field
$data = multi_sort($data, "content_order");
}
//finally we can loop through all records
$string = "";
foreach($data as $row){
$totalitems = $aa -> countCatItems($row['content_id']);
$date = $tp -> parseTemplate('{CM_DATE|cat}', FALSE, $content_shortcodes);
$auth = $tp -> parseTemplate('{CM_AUTHOR|cat}', FALSE, $content_shortcodes);
$ep = $tp -> parseTemplate('{CM_EPICONS|cat}', FALSE, $content_shortcodes);
@ -546,8 +580,8 @@ function show_content_cat_all(){
}
$CM_AUTHOR = $aa -> prepareAuthor("catall", $row['content_author'], $row['content_id']);
$string .= $tp -> parseTemplate($CONTENT_CAT_TABLE, FALSE, $content_shortcodes);
}
$text = $aa->getCrumbPage("catall", $array, $mainparent);
$text .= $tp -> parseTemplate($CONTENT_CAT_TABLE_START, FALSE, $content_shortcodes);
$text .= $string;
@ -558,7 +592,7 @@ function show_content_cat_all(){
}
function show_content_cat($mode=""){
global $qs, $plugindir, $content_shortcodes, $ns, $plugintable, $sql, $aa, $e107cache, $tp, $pref, $content_pref, $cobj, $datequery, $from, $CONTENT_RECENT_TABLE, $CM_AUTHOR, $CONTENT_CAT_LIST_TABLE_INFO_PRE, $CONTENT_CAT_LIST_TABLE_INFO_POST, $mainparent, $totalparent, $totalsubcat, $row, $datestamp, $comment_total, $gen, $authordetails, $rater, $crumb, $amount, $array;
global $qs, $plugindir, $content_shortcodes, $ns, $plugintable, $sql, $sql2, $aa, $e107cache, $tp, $pref, $content_pref, $cobj, $datequery, $from, $CONTENT_RECENT_TABLE, $CM_AUTHOR, $CONTENT_CAT_LIST_TABLE_INFO_PRE, $CONTENT_CAT_LIST_TABLE_INFO_POST, $mainparent, $totalparent, $totalsubcat, $row, $datestamp, $comment_total, $gen, $authordetails, $rater, $crumb, $amount, $array;
$mainparent = $aa -> getMainParent(intval($qs[1]));
$content_pref = $aa -> getContentPref($mainparent, true);
@ -635,6 +669,7 @@ function show_content_cat($mode=""){
$b++;
}
}
$subparent = array_keys($subparent);
$validsub = "0.".implode(",0.", $subparent);
$subqry = " content_refer !='sa' AND content_parent REGEXP '".$aa -> CONTENTREGEXP($validsub)."' ".$datequery." AND content_class REGEXP '".e_CLASS_REGEXP."' ";
@ -642,16 +677,20 @@ function show_content_cat($mode=""){
//list subcategories
if( varsettrue($content_pref["content_cat_showparentsub"]) ){
$cids = implode(",", $subparent );
//we parse the order string, dependent of the content_pref
$order = $aa -> getOrder('cat');
//finally we can loop through all records
$content_cat_listsub_table_string = "";
for($i=0;$i<count($subparent);$i++){
if($resultsubparent = $sql -> db_Select($plugintable, "content_id, content_heading, content_subheading, content_icon, content_parent", " content_id = '".$subparent[$i]."' AND ".$subqry." " )){
while($row = $sql -> db_Fetch()){
$totalsubcat = $aa -> countCatItems($row['content_id']);
$content_cat_listsub_table_string .= $tp -> parseTemplate($CONTENT_CAT_LISTSUB_TABLE, FALSE, $content_shortcodes);
}
$textsubparent = $CONTENT_CAT_LISTSUB_TABLE_START.$content_cat_listsub_table_string.$CONTENT_CAT_LISTSUB_TABLE_END;
$captionsubparent = $content_pref['content_cat_sub_caption'];
if($sql2 -> db_Select($plugintable, "content_id, content_heading, content_subheading, content_icon, content_parent, content_order", " content_id IN (".$cids.") AND ".$subqry." ".$order." ")){
while($row = $sql2 -> db_Fetch()){
$totalsubcat = $aa -> countCatItems($row['content_id']);
$content_cat_listsub_table_string .= $tp -> parseTemplate($CONTENT_CAT_LISTSUB_TABLE, FALSE, $content_shortcodes);
}
$textsubparent = $CONTENT_CAT_LISTSUB_TABLE_START.$content_cat_listsub_table_string.$CONTENT_CAT_LISTSUB_TABLE_END;
$captionsubparent = $content_pref['content_cat_sub_caption'];
}
}

View File

@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/content/handlers/content_class.php,v $
| $Revision: 1.18 $
| $Date: 2007-04-16 22:11:09 $
| $Revision: 1.19 $
| $Date: 2007-04-17 21:06:06 $
| $Author: lisa_ $
+---------------------------------------------------------------+
*/
@ -176,6 +176,7 @@ class content{
$cp['content_catall_text_post'] = CONTENT_LAN_16; //define postfix is text is too long
$cp['content_catall_text_link'] = '1'; //define if link to category should be added on postfix
$cp['content_catall_caption'] = CONTENT_LAN_25; //caption for all categories page
$cp['content_catall_defaultorder'] = 'orderaheading'; //default order for categories on the all categories page
//sections of content category in 'view category' page
$cp['content_cat_icon'] = '1'; //show icon
$cp['content_cat_subheading'] = '1'; //show subheading
@ -193,6 +194,7 @@ class content{
$cp['content_cat_caption_append_name'] = '1'; //append category heading to caption
$cp['content_cat_sub_caption'] = CONTENT_LAN_28; //caption for subcategories
$cp['content_cat_item_caption'] = CONTENT_LAN_31; //caption for items in category
$cp['content_cat_defaultorder'] = 'orderaheading'; //default order for the subcategories on the single category page
//sections of subcategories in 'view category page'
$cp['content_catsub_icon'] = '1'; //show icon
@ -1074,7 +1076,7 @@ class content{
return $text;
}
function getOrder(){
function getOrder($mode=''){
global $qs, $content_pref;
if(isset($qs[0]) && substr($qs[0],0,5) == "order"){
@ -1086,7 +1088,13 @@ class content{
}elseif(isset($qs[3]) && substr($qs[3],0,5) == "order"){
$orderstring = $qs[3];
}else{
$orderstring = ($content_pref["content_defaultorder"] ? $content_pref["content_defaultorder"] : "orderddate" );
if(isset($mode) && $mode=='catall'){
$orderstring = ($content_pref["content_catall_defaultorder"] ? $content_pref["content_catall_defaultorder"] : "orderaheading" );
}elseif(isset($mode) && $mode=='cat'){
$orderstring = ($content_pref['content_cat_defaultorder'] ? $content_pref['content_cat_defaultorder'] : "orderaheading" );
}else{
$orderstring = ($content_pref["content_defaultorder"] ? $content_pref["content_defaultorder"] : "orderddate" );
}
}
if(substr($orderstring,6) == "heading"){
@ -1104,10 +1112,16 @@ class content{
}elseif(substr($orderstring,6) == "author"){
}elseif(substr($orderstring,6) == "order"){
if($qs[0] == "cat"){
$orderby = "SUBSTRING_INDEX(content_order, '.', 1)+0";
}elseif($qs[0] != "cat"){
$orderby = "SUBSTRING_INDEX(content_order, '.', -1)+0";
if(isset($mode) && $mode=='catall'){
$orderby = "content_order+0";
}elseif(isset($mode) && $mode=='cat'){
$orderby = "content_order+0";
}else{
if($qs[0] == "cat"){
$orderby = "SUBSTRING_INDEX(content_order, '.', 1)+0";
}elseif($qs[0] != "cat"){
$orderby = "SUBSTRING_INDEX(content_order, '.', -1)+0";
}
}
$orderby2 = ", content_heading ASC";
}else{

View File

@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/content/handlers/content_form_class.php,v $
| $Revision: 1.12 $
| $Date: 2007-04-16 22:11:09 $
| $Revision: 1.13 $
| $Date: 2007-04-17 21:06:06 $
| $Author: lisa_ $
+---------------------------------------------------------------+
*/
@ -2378,6 +2378,20 @@ class contentform{
$TOPIC_FIELD = $rs -> form_text("content_catall_caption", 25, $tp->toHTML($content_pref['content_catall_caption'],"","defs"), 50);
$text .= preg_replace("/\{(.*?)\}/e", '$\1', $TOPIC_ROW_NOEXPAND);
//content_catall_defaultorder
$TOPIC_TOPIC = CONTENT_ADMIN_OPT_LAN_51;
$TOPIC_FIELD = "
".$rs -> form_select_open("content_catall_defaultorder")."
".$rs -> form_option(CONTENT_ORDER_LAN_1, ($content_pref['content_catall_defaultorder'] == "orderaheading" ? "1" : "0"), "orderaheading")."
".$rs -> form_option(CONTENT_ORDER_LAN_2, ($content_pref['content_catall_defaultorder'] == "orderdheading" ? "1" : "0"), "orderdheading")."
".$rs -> form_option(CONTENT_ORDER_LAN_3, ($content_pref['content_catall_defaultorder'] == "orderadate" ? "1" : "0"), "orderadate")."
".$rs -> form_option(CONTENT_ORDER_LAN_4, ($content_pref['content_catall_defaultorder'] == "orderddate" ? "1" : "0"), "orderddate")."
".$rs -> form_option(CONTENT_ORDER_LAN_9, ($content_pref['content_catall_defaultorder'] == "orderaorder" ? "1" : "0"), "orderaorder")."
".$rs -> form_option(CONTENT_ORDER_LAN_10, ($content_pref['content_catall_defaultorder'] == "orderdorder" ? "1" : "0"), "orderdorder")."
".$rs -> form_select_close();
$text .= preg_replace("/\{(.*?)\}/e", '$\1', $TOPIC_ROW_NOEXPAND);
$text .= $TOPIC_ROW_SPACER;
$TOPIC_CAPTION = CONTENT_ADMIN_OPT_LAN_MENU_17;
@ -2514,6 +2528,19 @@ class contentform{
$TOPIC_FIELD = CONTENT_ADMIN_OPT_LAN_172."<br />".$rs -> form_text("content_cat_levels", 10, $content_pref['content_cat_levels'], 3);
$text .= preg_replace("/\{(.*?)\}/e", '$\1', $TOPIC_ROW_NOEXPAND);
//content_cat_defaultorder
$TOPIC_TOPIC = CONTENT_ADMIN_OPT_LAN_51;
$TOPIC_FIELD = "
".$rs -> form_select_open("content_cat_defaultorder")."
".$rs -> form_option(CONTENT_ORDER_LAN_1, ($content_pref['content_cat_defaultorder'] == "orderaheading" ? "1" : "0"), "orderaheading")."
".$rs -> form_option(CONTENT_ORDER_LAN_2, ($content_pref['content_cat_defaultorder'] == "orderdheading" ? "1" : "0"), "orderdheading")."
".$rs -> form_option(CONTENT_ORDER_LAN_3, ($content_pref['content_cat_defaultorder'] == "orderadate" ? "1" : "0"), "orderadate")."
".$rs -> form_option(CONTENT_ORDER_LAN_4, ($content_pref['content_cat_defaultorder'] == "orderddate" ? "1" : "0"), "orderddate")."
".$rs -> form_option(CONTENT_ORDER_LAN_9, ($content_pref['content_cat_defaultorder'] == "orderaorder" ? "1" : "0"), "orderaorder")."
".$rs -> form_option(CONTENT_ORDER_LAN_10, ($content_pref['content_cat_defaultorder'] == "orderdorder" ? "1" : "0"), "orderdorder")."
".$rs -> form_select_close();
$text .= preg_replace("/\{(.*?)\}/e", '$\1', $TOPIC_ROW_NOEXPAND);
$text .= $TOPIC_TABLE_END;
$text .= "