From 0448cc4d69f7edd33cac3ab57b69720b4b5c8db0 Mon Sep 17 00:00:00 2001 From: Fawaz Date: Fri, 6 Aug 2010 11:42:41 +0000 Subject: [PATCH] Added : Sub-categories Fixed : Featured Channels on Channels page Fixed : autoPlay typo in player.html Fixed : Made CBv2 Template compatible with Sub-Categories Fixed : Related Videos Fixed : HQ Videos with other players --- sql/2.0.7~2.0.8.txt | 16 +- upload/admin_area/category.php | 7 + upload/admin_area/main.php | 1 + .../styles/cbv2/layout/category.html | 18 ++ .../admin_area/styles/cbv2/layout/main.html | 15 + upload/channels.php | 2 +- upload/includes/classes/category.class.php | 272 +++++++++++++++++- upload/includes/functions.php | 8 +- upload/player/pak_player/player.html | 2 +- .../cbv2new/layout/blocks/category_list.html | 18 +- upload/styles/cbv2new/layout/watch_video.html | 9 +- upload/styles/cbv2new/theme/main.css | 4 +- 12 files changed, 344 insertions(+), 28 deletions(-) diff --git a/sql/2.0.7~2.0.8.txt b/sql/2.0.7~2.0.8.txt index 335cc817..5dc985b5 100644 --- a/sql/2.0.7~2.0.8.txt +++ b/sql/2.0.7~2.0.8.txt @@ -6,4 +6,18 @@ INSERT INTO cb_config (name,value) VALUES ('smtp_user','user@myserver.com'), ('smtp_pass','password'), ('smtp_auth','yes'), -('smtp_port','26'); \ No newline at end of file +('smtp_port','26'); + + +ALTER TABLE `cb_video_categories` ADD `parent_id` INT( 5 ) NOT NULL DEFAULT '0' AFTER `category_id` + + + +INSERT INTO `clipbucket_svn`.`cb_config` ( +`configid` , +`name` , +`value` +) +VALUES ( +NULL , 'use_subs', '0' +); \ No newline at end of file diff --git a/upload/admin_area/category.php b/upload/admin_area/category.php index 49fc6758..2082ac7e 100644 --- a/upload/admin_area/category.php +++ b/upload/admin_area/category.php @@ -42,6 +42,12 @@ if(isset($_GET['delete_category'])){ $cats = $cbvid->get_categories(); +$pid = $cbvid->get_category_field($_GET['category'],'parent_id'); + +if($pid) + $selected = $pid; + +$parent_cats = $cbvid->admin_area_cats($selected); //Updating Category Order @@ -62,6 +68,7 @@ if(isset($_POST['update_order'])) //Assing Category Values assign('category',$cats); +assign('parent_cats',$parent_cats); assign('total',$cbvid->total_categories()); subtitle("Video Category Manager"); diff --git a/upload/admin_area/main.php b/upload/admin_area/main.php index f8ca816f..0444329d 100644 --- a/upload/admin_area/main.php +++ b/upload/admin_area/main.php @@ -55,6 +55,7 @@ if(isset($_POST['update'])){ 'default_country_iso2', 'default_time_zone', 'disallowed_usernames', + 'use_subs', 'embedUpload', 'email_verification', diff --git a/upload/admin_area/styles/cbv2/layout/category.html b/upload/admin_area/styles/cbv2/layout/category.html index 3198a315..f7c7d0bf 100644 --- a/upload/admin_area/styles/cbv2/layout/category.html +++ b/upload/admin_area/styles/cbv2/layout/category.html @@ -28,6 +28,15 @@ Category Description* + + Parent Category + + + + Make Default Category

@@ -72,6 +81,15 @@ Category Description* + + Parent Category + + + + Make Default Category

diff --git a/upload/admin_area/styles/cbv2/layout/main.html b/upload/admin_area/styles/cbv2/layout/main.html index 9304039f..a99575bb 100644 --- a/upload/admin_area/styles/cbv2/layout/main.html +++ b/upload/admin_area/styles/cbv2/layout/main.html @@ -138,6 +138,21 @@ $(document).ready(function(){ + + Use Sub-Categories + + >     diff --git a/upload/channels.php b/upload/channels.php index bd396160..1c71212d 100644 --- a/upload/channels.php +++ b/upload/channels.php @@ -32,7 +32,7 @@ switch($sort) break; case "featured": { - $u_cond['order'] = "yes"; + $u_cond['featured'] = "yes"; } break; case "top_rated": diff --git a/upload/includes/classes/category.class.php b/upload/includes/classes/category.class.php index 1c5f486d..3d68ce02 100644 --- a/upload/includes/classes/category.class.php +++ b/upload/includes/classes/category.class.php @@ -74,6 +74,7 @@ abstract class CBCategory $name = ($array['name']); $desc = ($array['desc']); $default = mysql_clean($array['default']); + $parent_id = mysql_clean($array['parent_cat']); if($this->get_cat_by_name($name)) { @@ -84,9 +85,9 @@ abstract class CBCategory e(lang("add_cat_no_name_err")); }else{ $cid = $db->insert(tbl($this->cat_tbl), - array("category_name","category_desc","date_added"), - array($name,$desc,now()) - ); + array("parent_id","category_name","category_desc","date_added"), + array($parent_id,$name,$desc,now()) + ); $cid = $db->insert_id(); if($default=='yes' || !$this->get_default_category()) $this->make_default_category($cid); @@ -127,6 +128,75 @@ abstract class CBCategory return $select; } + /** + * Function used to list of categories + */ + function cb_list_categories($type,$with_all=false) + { + global $db; + if($type == 'video' || $type == 'vid' || $type == 'v') + $cond = " parent_id = 0"; + else + $cond = NULL; + + //Getting List of categories + $cats = $db->select(tbl($this->cat_tbl),"*",$cond,NULL," category_order ASC"); + + if($with_all) + array_unshift($cats,array("category_id"=>"all","category_name"=>"All")); + + $html = ''; + for($i=0;$i"; + $html .= "".$cats[$i]['category_name'].""; + if($this->is_parent($cats[$i]['category_id'])) + { + $html .= $this->cb_list_subs($cats[$i]['category_id'],$type); + } + $html .= ""; + } + return $html; + + } + + function cb_list_subs($cid,$type) + { + global $db; + $html = ""; + $query = mysql_query("SELECT * FROM ".tbl($this->cat_tbl)." WHERE parent_id = $cid"); + + if(!empty($query)) + { + + $html .= "

"; + } + + return $html; + } + /** * Function used to count total number of categoies @@ -147,12 +217,35 @@ abstract class CBCategory $cat_details = $this->category_exists($cid); if(!$cat_details) e(lang("cat_exist_error")); + //CHecking if category is default or not elseif($cat_details['isdefault'] == 'yes') e(lang("cat_default_err")); else{ - //Moving all contents to default category - $this->change_category($cid); + + $pcat = $this->has_parent($cid,true); + + //Checking if category is both parent and child + if($pcat && $this->is_parent($cid)) + { + $to = $pcat[0]['category_id']; + $has_child = TRUE; + } + elseif($pcat && !$this->is_parent($cid)) //Checking if category is only child + { + $to = $pcat[0]['category_id']; + $has_child = TRUE; + } + elseif(!$pcat && $this->is_parent($cid)) //Checking if category is only parent + { + $to = NULL; + $has_child = NULL; + $db->update(tbl($this->cat_tbl),array('parent_id'),array('0')," parent_id = $cid"); + } + + //Moving all contents to parent OR default category + $this->change_category($cid,$to,$has_child); + //Removing Category $db->execute("DELETE FROM ".tbl($this->cat_tbl)." WHERE category_id='$cid'"); e(lang("class_cat_del_msg"),'m'); @@ -187,12 +280,19 @@ abstract class CBCategory /** * Function used to move contents from one section to other */ - function change_category($from,$to=NULL,$check_multiple=false) + function change_category($from,$to=NULL,$has_child=NULL,$check_multiple=false) { global $db; + if(!$this->category_exists($to)) $to = $this->get_default_cid(); + + if($has_child) { + $db->update(tbl($this->cat_tbl),array('parent_id'),array($to)," parent_id = $from"); + } + $db->execute("UPDATE ".tbl($this->section_tbl)." SET category = replace(category,'#".$from."#','#".$to."#') WHERE category LIKE '%#".$from."#%'"); + $db->execute("UPDATE ".tbl($this->section_tbl)." SET category = replace(category,'#".$to."# #".$to."#','#".$to."#') WHERE category LIKE '%#".$to."#%'"); } @@ -207,22 +307,25 @@ abstract class CBCategory $name = ($array['name']); $desc = ($array['desc']); $default = mysql_clean($array['default']); + $pcat = mysql_clean($array['parent_cat']); $cur_name = mysql_clean($array['cur_name']); $cid = mysql_clean($array['cid']); + $cur_parent = mysql_clean($array['cur_parent']); if($this->get_cat_by_name($name) && $cur_name !=$name ) { e(lang("add_cat_erro")); - }elseif(empty($name)) - { + }elseif(empty($name)){ e(lang("add_cat_no_name_err")); + } elseif($pcat == $cid){ + e(lang("You can not make category parent of itself")); }else{ $db->update(tbl($this->cat_tbl), - array("category_name","category_desc"), - array($name,$desc), + array("parent_id","category_name","category_desc"), + array($pcat,$name,$desc), " category_id='$cid' " ); if($default=='yes' || !$this->get_default_category()) @@ -349,6 +452,155 @@ abstract class CBCategory } } + /** + * Function used get parent cateogry + */ + function get_parent_category($pid) + { + global $db; + $result = $db->select(tbl($this->cat_tbl),"*"," category_id = $pid"); + if($db->num_rows>0) + return $result; + else + return false; + } + + /** + * Function used to check category is parent or not + */ + function is_parent($cid) + { + global $db; + $result = $db->count(tbl($this->cat_tbl),"category_id"," parent_id = $cid"); + + if($result > 0) + return true; + else + return false; + } + + /** + * Function used to check wheather category has parent or not + */ + function has_parent($cid,$return_parent=false) + { + global $db; + $result = $db->select(tbl($this->cat_tbl),"*"," category_id = $cid AND parent_id != 0"); + + if($result > 0) { + if($return_parent) + { + $pid = $this->get_parent_category($result[0]['parent_id']); + return $pid; + } else { + return true; + } + } else { + return false; + } + } + + /** + * Function used to get parent categories + */ + function get_parents($count=false) { + global $db; + + if($count) { + $result = $db->count(tbl($this->cat_tbl),"*"," parent_id = 0"); + } else { + $result = $db->select(tbl($this->cat_tbl),"*"," parent_id = 0"); + } + + return $result; + } + + /** + * Function used to list categories in admin area + * with indention + */ + function admin_area_cats($selected) + { + global $db; + $html = ''; + $pcats = $this->get_parents(); + + if(!empty($pcats)) + { + foreach($pcats as $key=>$pcat) + { + if($selected == $pcat['category_id']) + $select = "selected='selected'"; + else + $select = NULL; + + $html .= ""; + if($this->is_parent($pcat['category_id'])) + $html .= $this->get_sub_subs($pcat['category_id'],$selected); + } + + return $html; + } + } + + /** + * Function used to get child categories + */ + function get_sub_categories($cid) + { + global $db; + $result = $db->select(tbl($this->cat_tbl),"*"," parent_id = $cid"); + //echo $db->db_query; + if($result > 0){ + return $result; + }else{ + return false; + } + } + + /** + * Function used to get child child categories + */ + function get_sub_subs($cid,$selected,$space="  - ") + { + global $db; + $html = ''; + $subs = $this->get_sub_categories($cid); + if(!empty($subs)) + { + foreach($subs as $sub_key=>$sub) + { + if($selected == $sub['category_id']) + $select = "selected='selected'"; + else + $select = NULL; + + $html .= ""; + if($this->is_parent($sub['category_id'])) + $html .= $this->get_sub_subs($sub['category_id'],$selected,$space." - "); + } + return $html; + } + } + + function get_category_field($cid,$field) + { + global $db; + $result = $db->select(tbl($this->cat_tbl),"$field"," category_id = $cid"); + //echo $db->db_query; + if($result) + return $result[0][$field]; + else + return false; + } + + + + } ?> \ No newline at end of file diff --git a/upload/includes/functions.php b/upload/includes/functions.php index f07bf7c3..133c6a21 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -922,6 +922,8 @@ */ function getCategoryList($type='video',$with_all=false,$return_html=false) { + $use_subs = config('use_subs'); + switch ($type) { case "video": @@ -929,7 +931,7 @@ { global $cbvid; - if($return_html) { + if($return_html && $use_subs == "1") { $cats = $cbvid->cb_list_categories($type,$with_all); } else { if($with_all) @@ -948,7 +950,7 @@ global $userquery; - if($return_html) { + if($return_html && $use_subs == "1") { $cats = $userquery->cb_list_categories($type,$with_all); } else { if($with_all) @@ -969,7 +971,7 @@ global $cbgroup; - if($return_html) { + if($return_html && $use_subs == "1") { $cats = $cbgroup->cb_list_categories($type,$with_all); } else { if($with_all) diff --git a/upload/player/pak_player/player.html b/upload/player/pak_player/player.html index a8924898..8025fbf1 100644 --- a/upload/player/pak_player/player.html +++ b/upload/player/pak_player/player.html @@ -80,7 +80,7 @@ flowplayer("the_Video_Player", "{$pak_player_url}/pak_player.swf", {literal}{ , clip:{ {/literal} - autoPlay:{$player_data.autoplay}, + autoplay:'{$player_data.autoplay}', {if $youtube} url : 'api:{$ytcode}', diff --git a/upload/styles/cbv2new/layout/blocks/category_list.html b/upload/styles/cbv2new/layout/blocks/category_list.html index f697fd0a..ff4323ab 100644 --- a/upload/styles/cbv2new/layout/blocks/category_list.html +++ b/upload/styles/cbv2new/layout/blocks/category_list.html @@ -1,15 +1,17 @@
{lang code='categories'} -{assign var='category_list' value=func->getCategoryList($type,true)} +{assign var='category_list' value=func->getCategoryList($type,true,true)} +{assign var='use_subs' value=func->config(use_subs)} +
-{if $category_list} -
    - {foreach from=$category_list item=cat} +
      + {if $use_subs == "1"} + {$category_list} + {else} + {foreach from=$category_list item=cat}
    • {$cat.category_name}
    • {/foreach} -
    -{else} -No Category -{/if} + {/if} +
\ No newline at end of file diff --git a/upload/styles/cbv2new/layout/watch_video.html b/upload/styles/cbv2new/layout/watch_video.html index ce6c917e..ea3d7f34 100644 --- a/upload/styles/cbv2new/layout/watch_video.html +++ b/upload/styles/cbv2new/layout/watch_video.html @@ -22,6 +22,11 @@ {FlashPlayer vdetails = $vdo} +{if has_hq($vdo)} + +{/if}
@@ -163,9 +168,9 @@ {assign var=videos_items_columns value=func->config(videos_items_columns)} -{get_videos nonuser=$vdo.userid exclude=$vdo.videoid limit=$videos_items_columns order="date_added ASC" assign=related_vids} +{get_videos nonuser=$vdo.userid exclude=$vdo.videoid limit=$videos_items_columns order="date_added ASC" assign=related_vids show_related=yes title=$vdo.title} -{* get_videos category=$vid_cat nonuser=$vdo.userid exclude=$vdo.videoid limit=$videos_items_columns order="date_added ASC" assign=related_vids *} +{* get_videos category=$vid_cat nonuser=$vdo.userid exclude=$vdo.videoid limit=$videos_items_columns order="date_added ASC" assign=related_vids show_related=yes title=$vdo.title*} {if $related_vids} diff --git a/upload/styles/cbv2new/theme/main.css b/upload/styles/cbv2new/theme/main.css index 16e20157..4a5fdbe5 100644 --- a/upload/styles/cbv2new/theme/main.css +++ b/upload/styles/cbv2new/theme/main.css @@ -385,8 +385,8 @@ span.remember { font-size:10px; } .categories ul li:last-child{border-bottom:none} .categories .selected { background-color:#efefef; display:block;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px} .categories ul a{font:bold 14px arial;color:#0066cc; text-decoration:none; display:block; padding:2px 2px 2px 6px; } -.categories ul.sub_categories { padding:0px; margin:0px 0 0 5px; } -.categories ul.sub_categories li { padding:2px; margin:0px; } +.categories ul.sub_categories { padding:0px; margin:0px 0px 0px 5px; } +.categories ul.sub_categories li { padding:1px; margin:0px; } .categories ul.sub_categories li a { font:bold 11px Tahoma; } .time_cont{border-bottom:1px solid #CCC; margin-bottom:5px; padding:5px; font-size:10px} .time_cont a{ font-size:10px; color:#666; text-decoration:none}