web/wp-content/themes/selecta/functions.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 /**
       
     3  * @package WordPress
       
     4  * @subpackage Selecta
       
     5  */
       
     6 
       
     7 function fetch_post_image($use_id, $width, $height)
       
     8 	{
       
     9 		$attach_args = array("post_type" => "attachment", "post_parent" => $use_id);
       
    10 		$attachments = get_posts($attach_args);
       
    11 		$attach_id = $attachments[0]->ID;
       
    12 		return  wp_get_attachment_image($attach_id, array($width, $height));
       
    13 	}
       
    14 function ocmx_pagination()
       
    15 	{
       
    16 		global $wp_query;
       
    17 		$request = $wp_query->request;
       
    18 		$numposts = $wp_query->found_posts;
       
    19 		if((get_option("ocmx_home_page_posts") && $numposts !== 0) && $numposts > get_option("ocmx_home_page_posts")) :
       
    20 ?>
       
    21      <div class="pagination-container">
       
    22         <ul class="page_button_content clearfix">
       
    23         	<?php if(get_query_var("paged") !== 0) : ?>
       
    24 	            <li class="previous-page"><?php previous_posts_link("Previous"); ?></li>            
       
    25             <?php endif;
       
    26 			for($i = 1; $i <= (ceil($numposts/get_option("ocmx_home_page_posts"))); $i++) : ?>
       
    27 				<li><a href="<?php echo clean_url(get_pagenum_link($i)); ?>" class="<?php if($i == get_query_var('paged') || ($i == 1 && get_query_var('paged') == "")) :?>selected-page<?php else : ?>other-page<?php endif; ?>"><?php echo $i; ?></a></li>  
       
    28 			<?php endfor;
       
    29 			if(get_query_var("paged") !== ceil($numposts/get_option("ocmx_home_page_posts"))) : ?>
       
    30 				<li class="next-page"><?php next_posts_link("Next"); ?></li>
       
    31 			<?php endif;?>
       
    32         </ul>
       
    33     </div>
       
    34 <?php
       
    35 		endif;
       
    36 	}
       
    37 function ocmx_set_colour()
       
    38 	{setcookie("ocmx_theme_style", $_GET["use_colour"], 0, COOKIEPATH, COOKIE_DOMAIN);}
       
    39 function fetch_post_tags($post_id)
       
    40 	{
       
    41 		global $wpdb;
       
    42 		$tags = $wpdb->get_results("SELECT $wpdb->term_relationships.*, $wpdb->terms.* FROM $wpdb->terms INNER JOIN $wpdb->term_relationships ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->terms.term_id WHERE $wpdb->term_relationships.object_id = ".$post_id);
       
    43 		foreach($tags as $posttag) :
       
    44 			if(!isset($tag_list)) :
       
    45 				$tag_list = $posttag->name;
       
    46 			else :
       
    47 				$tag_list .= ", ".$posttag->name;
       
    48 			endif;
       
    49 		endforeach;
       
    50 		return $tag_list;
       
    51 	}
       
    52  // VARIABLES
       
    53 global $themename, $input_prefix;
       
    54 $themename = "Selecta";
       
    55 $input_prefix = "ocmx_";
       
    56 
       
    57 $template_path = get_bloginfo('template_directory');
       
    58 $functions_path = TEMPLATEPATH . '/functions/';
       
    59 
       
    60 //CREATE THEME OPTIONS
       
    61 
       
    62 include_once (TEMPLATEPATH."/ocmx/custom.php");
       
    63 include_once (TEMPLATEPATH."/ocmx/ocmx-setup.php");
       
    64 include_once (TEMPLATEPATH."/ocmx/ocmx-create-options.php");
       
    65 include_once (TEMPLATEPATH."/ocmx/ocmx-functions.php");
       
    66 include_once (TEMPLATEPATH."/ocmx/ocmx-install-options.php");
       
    67 include_once (TEMPLATEPATH."/ocmx/ocmx-general-options.php");
       
    68 include_once (TEMPLATEPATH."/ocmx/ocmx-advert-options.php");
       
    69 include_once (TEMPLATEPATH."/ocmx/ocmx-comment-options.php");
       
    70 include_once (TEMPLATEPATH."/ocmx/ocmx-widgets.php");
       
    71 
       
    72 function ocmx_add_admin() {
       
    73 	global $wpdb;
       
    74 	
       
    75 	add_menu_page("OCMX Options", "OCMX Options", 'edit_themes', basename(__FILE__), '');
       
    76 	$comment_table = $wpdb->prefix ."ocmx_comment_meta";
       
    77 	$gallery_hdr_table = $wpdb->prefix . "ocmx_gallery";
       
    78 	if(check_table_existance($comment_table)) :
       
    79 		add_submenu_page(basename(__FILE__), "General Options", "General & Layout", 8, basename(__FILE__), 'ocmx_general_options');
       
    80 		add_submenu_page(basename(__FILE__), "Adverts", "Adverts", 8,  "ocmx-adverts", 'ocmx_advert_options');
       
    81 		add_submenu_page(basename(__FILE__), "Comments", "Comments", 8, "ocmx-comments", 'ocmx_comment_options');
       
    82 	else :
       
    83 		add_option("white-red");
       
    84 		add_submenu_page(basename(__FILE__), "Install Options", "Install", 8, basename(__FILE__), 'ocmx_install_options');
       
    85 	endif;
       
    86 };
       
    87 // Add the Custom Functions to Wordpress
       
    88 if($_GET["install_ocmx"]) : 
       
    89 	add_action('init', 'install_ocmx');
       
    90 endif;
       
    91 if(isset($_GET["use_colour"])) :
       
    92 	add_action('init', 'ocmx_set_colour');
       
    93 endif;
       
    94 
       
    95 add_action('admin_menu', 'ocmx_add_admin');
       
    96 add_action('comment_post', create_function('$a', 'ocmx_commentmeta_update($a);'));
       
    97 
       
    98 if(!get_option("ocmx_theme_style")) :
       
    99 	add_option("ocmx_theme_style", "blue");
       
   100 endif;
       
   101 
       
   102 // Create Dynamic Sidebars
       
   103 if (function_exists('register_sidebar')) :
       
   104     register_sidebar(array("name" => "Header Panel"));
       
   105     register_sidebar(array("name" => "Index Header Panel"));	
       
   106     register_sidebar(array("name" => "Advert Sidebar"));
       
   107 	
       
   108     register_sidebar(
       
   109 		array(
       
   110 			  	"name" => "Sidebar",
       
   111 				"before_widget" => "
       
   112 					<li class=\"widget widget_links\">
       
   113 					<div class=\"container-header-dark-normal\"><span></span></div>
       
   114 						<div class=\"container-dark\">",
       
   115 				"before_title" => "
       
   116 							<h2 class=\"recent-comments-title\">",
       
   117 				"after_title" => "
       
   118 							</h2>
       
   119 							<ul class=\"xoxo blogroll\">",
       
   120 				"after_widget" => "
       
   121 							</ul>
       
   122 						</div>
       
   123 						<div class=\"container-footer-dark-normal\"><span></span></div>
       
   124 				</li>"
       
   125 			)
       
   126 	);
       
   127     register_sidebar(array("name" => "Footer Left", "before_title" => "<h3>", "after_title" => "</h3>", "before_widget" => "<ul><li>", "after_widget" => "</li></ul>"));
       
   128     register_sidebar(array("name" => "Footer Middle", "before_title" => "<h3>", "after_title" => "</h3>", "before_widget" => "<ul><li>", "after_widget" => "</li></ul>"));
       
   129     register_sidebar(array("name" => "Footer Right", "before_title" => "<h3>", "after_title" => "</h3>", "before_widget" => "<ul><li>", "after_widget" => "</li></ul>"));
       
   130 endif;
       
   131 // Widgets
       
   132 function ocmx_page_menu()
       
   133 	{
       
   134 		if(get_option("ocmx_page_order") !== "post_title") :
       
   135 			$page_args = array("sort_column" => get_option("ocmx_page_order"), "sort_order" => get_option("ocmx_page_updown"), "depth" => "1");
       
   136 		else :
       
   137 			$page_args = array("sort_order" => get_option("ocmx_page_updown"), "depth" => "1");
       
   138 		endif;
       
   139 		$fetch_pages = get_pages($page_args);
       
   140 		foreach ($fetch_pages as $this_page) :
       
   141 			$this_option = "ocmx_menu_page_".$this_page->ID;
       
   142 			if(get_option($this_option)) :
       
   143 				$sub_page_count = 0;
       
   144 				if(get_option("ocmx_page_order") !== "post_title") :
       
   145 					$sub_page_defaults = array("child_of" => $this_page->ID, "sort_column" => get_option("ocmx_page_order"), "sort_order" => get_option("ocmx_page_updown"));
       
   146 				else :
       
   147 					$sub_page_defaults = array("child_of" => $this_page->ID, "sort_order" => get_option("ocmx_page_updown"));
       
   148 				endif;
       
   149 				$sub_pages = get_pages($sub_page_defaults);
       
   150 				foreach ($sub_pages as $sub_page) :
       
   151 					$this_sub_page_option = "ocmx_subpage_".$sub_page->ID;
       
   152 					if(get_option($this_sub_page_option)) :
       
   153 						$sub_page_count++;
       
   154 					endif;
       
   155 				endforeach; 
       
   156 ?>
       
   157 				<li class="parent-item">
       
   158                 	<a href="<?php echo get_page_link($this_page->ID); ?>" id="main-menu-page-item-<?php echo $this_page->ID; ?>" class="parent-link"><span><?php echo $this_page->post_title; ?></span></a>
       
   159 					<?php if($sub_page_count !== 0) : ?>
       
   160                         <div class="sub-menu-container" id="sub-page-menu-<?php echo $this_page->ID; ?>" style="display: none;">
       
   161                             <ul class="sub-menu">
       
   162                                 <?php
       
   163                                     foreach ($sub_pages as $sub_page) :
       
   164                                         $this_sub_page_option = "ocmx_subpage_".$sub_page->ID;
       
   165                                         if(get_option($this_sub_page_option)) :
       
   166                                 ?>
       
   167                                     <li><a href="<?php echo get_page_link($sub_page->ID); ?>"><?php echo $sub_page->post_title; ?></a></li>
       
   168                                 <?php
       
   169                                         endif;
       
   170                                     endforeach;
       
   171                                 ?>
       
   172                             </ul>      
       
   173 							<div class="sub-menu-footer"></div>   
       
   174                         </div>         
       
   175                     <?php endif; ?>
       
   176 				</li>
       
   177 <?php
       
   178 			endif;
       
   179 		endforeach;
       
   180 		$parent_count = 0;
       
   181 	}
       
   182 function ocmx_category_menu()
       
   183 	{
       
   184         $defaults = array("type" => "post", "child_of" => 0, "orderby" => get_option("ocmx_category_order"), "order" => get_option("ocmx_category_updown"), "hide_empty" => false);
       
   185 		$parent_categories = get_categories($defaults);
       
   186 		// Count the Parent Categories (That is Categories without Parents themselves (To be used in the loop, explained below)
       
   187 		foreach ($parent_categories as $this_category) :
       
   188 			$this_option = "ocmx_maincategory_".$this_category->cat_ID;				
       
   189 			if(get_option($this_option)) :
       
   190 				$sub_category_count = 0;
       
   191 				$sub_category_defaults = array('type' => 'post', 'child_of' => $this_category->cat_ID, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false);
       
   192 				$sub_categories = get_categories($sub_category_defaults);
       
   193 				// Below will loop through the sub categories and populate the sub_category_count if there is an option selected for the category
       
   194 				foreach ($sub_categories as $sub_category) :
       
   195 					$this_sub_option = "ocmx_subcategory_".$sub_category->cat_ID;
       
   196 					if(get_option($this_sub_option)) :
       
   197 						$sub_category_count++;
       
   198 					endif;
       
   199 				endforeach; ?>
       
   200 				<li class="parent-item">
       
   201 					<a href="<?php echo get_category_link($this_category->term_id); ?>" class="parent-link" id="main-menu-item-<?php echo $this_category->cat_ID; ?>">
       
   202 						<span>
       
   203 							<?php echo $this_category->cat_name; ?>
       
   204                         </span>
       
   205 					</a>
       
   206 <?php
       
   207 				if($sub_category_count !== 0) :
       
   208 ?>
       
   209 					<div class="sub-menu-container" id="sub-menu-<?php echo $this_category->cat_ID; ?>" style="display: none;">
       
   210 						<ul class="sub-menu">
       
   211 <?php
       
   212 							foreach ($sub_categories as $sub_category) :
       
   213 								$this_sub_option = "ocmx_subcategory_".$sub_category->cat_ID;
       
   214 								if(get_option($this_sub_option)) :
       
   215 ?>
       
   216 									<li><a href="<?php echo get_category_link($sub_category->term_id); ?>"><?php echo $sub_category->cat_name; ?></a></li>
       
   217 <?php
       
   218 								endif;
       
   219 							endforeach;
       
   220 ?>
       
   221 						</ul>
       
   222                         <div class="sub-menu-footer"></div>
       
   223 					</div>       
       
   224 <?php 
       
   225 				endif;
       
   226 ?>
       
   227 				</li>         
       
   228 <?php
       
   229 			endif;
       
   230 		endforeach;
       
   231 	}
       
   232 function ocmx_menu()
       
   233 	{
       
   234 		if(get_option("ocmx_page_category_order") == "page_first") :
       
   235 			ocmx_page_menu();
       
   236 			ocmx_category_menu();
       
   237 		else :
       
   238 			ocmx_category_menu();
       
   239 			ocmx_page_menu();
       
   240 		endif;
       
   241 	}
       
   242 ?>