web/wp-content/themes/IRI-Theme/functions.php
changeset 170 8e3a5a6fc63e
parent 146 8d4c66d892cf
child 180 d8780eeb2607
equal deleted inserted replaced
169:2d410dc8c1f3 170:8e3a5a6fc63e
     1 <?php
     1 <?php
     2 
     2 
       
     3 function theme_init(){
       
     4 	if (class_exists('xili_language')) {
       
     5 		define('THEME_TEXTDOMAIN','IriTheme');
       
     6 		define('THEME_LANGS_FOLDER','/language');
       
     7 	} else {
       
     8 	   load_theme_textdomain('IriTheme', get_template_directory() . '/languages');	
       
     9 	}	
       
    10 }
       
    11 add_action ('init', 'theme_init');
       
    12 
       
    13 
       
    14 //
       
    15 define('THEME_TEXTDOMAIN','IriTheme');
       
    16 define('THEME_LANGS_FOLDER','/language');
     3 require( "lib/zip.lib.php" ) ; //indiquez le chemin d'accès à la lib
    17 require( "lib/zip.lib.php" ) ; //indiquez le chemin d'accès à la lib
     4 
    18 
     5 //error_reporting(E_ALL);
    19 //error_reporting(E_ALL);
     6 
    20 
     7 function getPost($post = NULL) {
    21 function getPost($post = NULL) {
    10 
    24 
    11 function getSearch($q = NULL) {
    25 function getSearch($q = NULL) {
    12 	include('searchform.php');
    26 	include('searchform.php');
    13 }
    27 }
    14 
    28 
    15 if ( function_exists('register_sidebar') )
    29 if ( function_exists('register_sidebar') ){
    16 {
       
    17     register_sidebar
    30     register_sidebar
    18     (   array
    31     (   array
    19         (
    32         (
    20           'name' => 'Sidebar-Single',
    33           'name' => 'Sidebar-Single',
    21           'before_widget' => '<div class="bottombar">',
    34           'before_widget' => '<div class="bottombar">',
    64           'after_title' => '</h2>',
    77           'after_title' => '</h2>',
    65         )
    78         )
    66     );   
    79     );   
    67 }
    80 }
    68 
    81 
       
    82 // Need the tag Cloud Plug In 
       
    83 // piece together the flash code
       
    84 function xilimlSam_wp_cumulus_createflashcode( $widget=false, $atts=NULL ){
       
    85 
       
    86 
       
    87 	// get the options
       
    88 	if( $widget == true ){
       
    89 		$options = get_option('wpcumulus_widget');
       
    90 		$soname = "widget_so";
       
    91 		$divname = "wpcumuluswidgetcontent";
       
    92 		// get compatibility mode variable from the main options
       
    93 		$mainoptions = get_option('wpcumulus_options');
       
    94 		$options['compmode'] = $mainoptions['compmode'];
       
    95 		$options['showwptags'] = $mainoptions['showwptags'];
       
    96 	} else if( $atts != NULL ){
       
    97 		$options = shortcode_atts( get_option('wpcumulus_options'), $atts );
       
    98 		$soname = "shortcode_so";
       
    99 		$divname = "wpcumuluscontent";
       
   100 	} else {
       
   101 		$options = get_option('wpcumulus_options');
       
   102 		$soname = "so";
       
   103 		$divname = "wpcumuluscontent";
       
   104 	}
       
   105 	// get the tag cloud...
       
   106 	if( $options['mode'] != "cats" ){
       
   107 		ob_start();	
       
   108 		//wp_tag_cloud( $options['args'] );
       
   109 		xili_tidy_tag_cloud('tagsgroup='.the_curlang());
       
   110 		$tagcloud = urlencode( str_replace( "&nbsp;", " ", ob_get_clean() ) );	
       
   111 	}
       
   112 	// get categories
       
   113 	if( $options['mode'] != "tags" ){
       
   114 		ob_start();
       
   115 		xili_tidy_tag_cloud('tagsgroup='.the_curlang());//
       
   116 		$cats = urlencode( ob_get_clean() );
       
   117 	}
       
   118 	// get some paths
       
   119 	if( function_exists('plugins_url') ){ 
       
   120 		// 2.6 or better
       
   121 		$movie = plugins_url('wp-cumulus/tagcloud.swf');
       
   122 		$path = plugins_url('wp-cumulus/');
       
   123 	} else {
       
   124 		// pre 2.6
       
   125 		$movie = get_bloginfo('wpurl') . "/wp-content/plugins/wp-cumulus/tagcloud.swf";
       
   126 		$path = get_bloginfo('wpurl')."/wp-content/plugins/wp-cumulus/";
       
   127 	}
       
   128 	// add random seeds to so name and movie url to avoid collisions and force reloading (needed for IE)
       
   129 	$soname .= rand(0,9999999);
       
   130 	$movie .= '?r=' . rand(0,9999999);
       
   131 	$divname .= rand(0,9999999);
       
   132 	// write flash tag
       
   133 	if( $options['compmode']!='true' ){
       
   134 		$flashtag = '<!-- SWFObject embed by Geoff Stearns geoff@deconcept.com http://blog.deconcept.com/swfobject/ -->';	
       
   135 		$flashtag .= '<script type="text/javascript" src="'.$path.'swfobject.js"></script>';
       
   136 		// ------------------------------------------------------------------------------------
       
   137 		$flashtag .= '<div id="'.$divname.'" style="position:absolute;z-index:0;">';
       
   138 		if( $options['showwptags'] == 'true' ){ $flashtag .= '<p>'; } else { $flashtag .= '<p style="display:none;">'; };
       
   139 		// alternate content
       
   140 		if( $options['mode'] != "cats" ){ $flashtag .= urldecode($tagcloud); }
       
   141 		if( $options['mode'] != "tags" ){ $flashtag .= urldecode($cats); }
       
   142 		$flashtag .= '</p><!-- WP Cumulus Flash tag cloud by <a href="http://www.roytanck.com">Roy Tanck</a> and <a href="http://lukemorton.co.uk/">Luke Morton</a> requires <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> 9 or better.   --></div>';
       
   143 		$flashtag .= '<script type="text/javascript">';
       
   144 		$flashtag .= 'var '.$soname.' = new SWFObject("'.$movie.'", "tagcloudflash", "'.$options['width'].'", "'.$options['height'].'", "9", "#'.$options['bgcolor'].'");';
       
   145 		if( $options['trans'] == 'true' ){
       
   146 			$flashtag .= $soname.'.addParam("wmode", "transparent");';
       
   147 		}
       
   148 		$flashtag .= $soname.'.addParam("allowScriptAccess", "always");';
       
   149 		$flashtag .= $soname.'.addVariable("tcolor", "0x'.$options['tcolor'].'");';
       
   150 		$flashtag .= $soname.'.addVariable("tcolor2", "0x' . ($options['tcolor2'] == "" ? $options['tcolor'] : $options['tcolor2']) . '");';
       
   151 		$flashtag .= $soname.'.addVariable("hicolor", "0x' . ($options['hicolor'] == "" ? $options['tcolor'] : $options['hicolor']) . '");';
       
   152 		$flashtag .= $soname.'.addVariable("tspeed", "'.$options['speed'].'");';
       
   153 		$flashtag .= $soname.'.addVariable("distr", "'.$options['distr'].'");';
       
   154 		$flashtag .= $soname.'.addVariable("mode", "'.$options['mode'].'");';
       
   155 		// put tags in flashvar
       
   156 		if( $options['mode'] != "cats" ){
       
   157 			$flashtag .= $soname.'.addVariable("tagcloud", "'.urlencode('<tags>') . $tagcloud . urlencode('</tags>').'");';
       
   158 		}
       
   159 		// put categories in flashvar
       
   160 		if( $options['mode'] != "tags" ){
       
   161 			$flashtag .= $soname.'.addVariable("categories", "' . $cats . '");';
       
   162 		}
       
   163 		$flashtag .= $soname.'.write("'.$divname.'");';
       
   164 		$flashtag .= '</script>';
       
   165 	} else {
       
   166 		$flashtag = '<object type="application/x-shockwave-flash" data="'.$movie.'" width="'.$options['width'].'" height="'.$options['height'].'" wmode="opaque">';
       
   167 		$flashtag .= '<param name="movie" value="'.$movie.'" />';
       
   168 		$flashtag .= '<param name="bgcolor" value="#'.$options['bgcolor'].'" />';
       
   169 		$flashtag .= '<param name="AllowScriptAccess" value="always" />';
       
   170 		$flashtag .= '<param name="wmode" value="opaque" />';
       
   171 		if( $options['trans'] == 'true' ){
       
   172 			$flashtag .= '<param name="wmode" value="transparent" />';
       
   173 		}
       
   174 		$flashtag .= '<param name="flashvars" value="';
       
   175 		$flashtag .= 'tcolor=0x'.$options['tcolor'];
       
   176 		$flashtag .= '&amp;tcolor2=0x'.$options['tcolor2'];
       
   177 		$flashtag .= '&amp;hicolor=0x'.$options['hicolor'];
       
   178 		$flashtag .= '&amp;tspeed='.$options['speed'];
       
   179 		$flashtag .= '&amp;distr='.$options['distr'];
       
   180 		$flashtag .= '&amp;mode='.$options['mode'];
       
   181 		// put tags in flashvar
       
   182 		if( $options['mode'] != "cats" ){
       
   183 			$flashtag .= '&amp;tagcloud='.urlencode('<tags>') . $tagcloud . urlencode('</tags>');
       
   184 		}
       
   185 		// put categories in flashvar
       
   186 		if( $options['mode'] != "tags" ){
       
   187 			$flashtag .= '&amp;categories=' . $cats;
       
   188 		}
       
   189 		$flashtag .= '" />';
       
   190 		// alternate content
       
   191 		if( $options['mode'] != "cats" ){ $flashtag .= '<p>'.urldecode($tagcloud).'</p>'; }
       
   192 		if( $options['mode'] != "tags" ){ $flashtag .= '<p>'.urldecode($cats).'</p>'; }
       
   193 		$flashtag .= '<!-- WP-Cumulus by <a href="http://www.roytanck.com/">Roy Tanck</a> and <a href="http://lukemorton.co.uk/">Luke Morton</a> requires <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> 9 or better. -->';
       
   194 		$flashtag .= '</object>';
       
   195 	}
       
   196 	return $flashtag;
       
   197 }
       
   198 
       
   199 // Copy of the current category widget plugin adapted to xiliml
       
   200 function xilimlSam_post_of_current_category (){
       
   201  global $wpdb;
       
   202 	
       
   203 	$defaults = array(
       
   204 		'limit' => 30,
       
   205 		'AscDesc' => "DSC", 
       
   206 		'OrderBy' =>'ID',
       
   207 	);
       
   208 	
       
   209 	$args =  $defaults;
       
   210 	$lang = the_curlang();//echo ($lang);
       
   211 	extract($args);
       
   212 	
       
   213 	$limit = (int) abs($limit);
       
   214 		
       
   215 	if(is_category()){
       
   216 		$curCategoryID = get_query_var('cat');
       
   217 	}
       
   218 	
       
   219 	if (is_single()) {
       
   220 		$curCategoryID = '';
       
   221 		
       
   222 		foreach (get_the_category() as $catt) {
       
   223 			$curCategoryID .= $catt->cat_ID.' '; 
       
   224 		}
       
   225 		
       
   226 		$curCategoryID = str_replace(" ", ",", trim($curCategoryID));
       
   227 	}
       
   228 	
       
   229 	if (!intval($curCategoryID)) $curCategoryID='';
       
   230 	$query = "&category=$curCategoryID&showposts=$limit&orderby=$OrderBy&order=$AscDesc";
       
   231 	$posts = get_posts($query); //get posts
       
   232 	$postlist = '';	
       
   233 	
       
   234     foreach ($posts as $post) {
       
   235 	
       
   236 		$CurLang = get_cur_post_lang_dir ($post->ID);//echo ($post->ID."-> ".$CurLang["lang"]."   <br/>");
       
   237 		if($CurLang["lang"]==$lang){
       
   238 			$post_title_s = htmlspecialchars(stripslashes(cache_cutter($post->post_title)));
       
   239 			$post_title_l = htmlspecialchars(stripslashes(text_cutter($post->post_title,200)));
       
   240 			$postlist .= '<li> <a href="' . get_permalink($post->ID) . '" title="'.  $post_title_s .'" >' . $post_title_l . ' </a> </li>';
       
   241 		}
       
   242     }
       
   243 	
       
   244 	echo '<ul class="advanced-recent-posts">';		
       
   245 		echo $postlist;
       
   246 	echo '</ul>';
       
   247 
       
   248 }
       
   249 
       
   250 # 
       
   251 function xilimlSam_page2cat_output_Hook($cat){
       
   252 	
       
   253 	if( function_exists(page2cat_output) and function_exists(xiliml_the_other_posts) ){
       
   254 	
       
   255 		global $wpdb;
       
   256 		$mypage = $wpdb->get_row("SELECT * FROM {$wpdb->page2cat} WHERE cat_ID = '".$cat."';",OBJECT);
       
   257 		$pageid = $mypage->page_ID;
       
   258 		$pageInOtherLang = xiliml_the_other_posts ($pageid,'','','array');
       
   259 		
       
   260 		if($pageInOtherLang[the_curlang()]!=null){
       
   261 			$pageid=$pageInOtherLang[the_curlang()];
       
   262 		}
       
   263 		
       
   264 		if($pageid != ""):
       
   265 		
       
   266 		switch($style):
       
   267 		
       
   268 		case 'inline':
       
   269 		default:	
       
   270 		?>
       
   271 		<div id="category-page-header">
       
   272 		<?php
       
   273 		$pagina = "SELECT * FROM {$wpdb->posts} WHERE ID='".$pageid."' AND post_type = 'page';";
       
   274 		$mine = $wpdb->get_results($pagina);
       
   275 		if($mine[0]->post_title!=""){
       
   276 					?>
       
   277 					<div id="p2c-header">
       
   278 						<h2><?php echo $mine[0]->post_title; ?></h2>
       
   279 						<p><?php echo wptexturize($mine[0]->post_content,1); ?></p>
       
   280 					</div> 
       
   281 			<div class="category-page-cleaner"></div>
       
   282 		</div>
       
   283 		<?php
       
   284 		}
       
   285 		break;
       
   286 		
       
   287 		
       
   288 		endswitch;
       
   289 		endif;
       
   290 	}
       
   291 	
       
   292 	/*
       
   293 		$current_lang = the_cur_lang_dir();
       
   294 		page2cat_output($cat);
       
   295 		
       
   296 		$MyPost = xiliml_the_other_posts($post_ID,"","","array");
       
   297 		//var_dump($MyPost);
       
   298 		//echo($current_lang['lang']." -> ".$MyPost[$current_lang['lang']]);
       
   299 		
       
   300 		if (in_array($current_lang['lang'],$MyPost)){
       
   301 			return ($post_ID);
       
   302 		} else {
       
   303 			return ($MyPost[$current_lang['lang']]);
       
   304 			
       
   305 		}
       
   306 	*/
       
   307 }
       
   308 
       
   309 # 
       
   310 function xilimlSam_other_posts($post_ID){
       
   311 
       
   312 		if (class_exists('xili_language')) {
       
   313 		
       
   314 			$current_lang = the_cur_lang_dir();
       
   315 			
       
   316 			$MyPost = xiliml_the_other_posts($post_ID,"","","array");
       
   317 			//var_dump($MyPost);
       
   318 			//echo($current_lang['lang']." -> ".$MyPost[$current_lang['lang']]);
       
   319 			
       
   320 			if (in_array($current_lang['lang'],$MyPost)){
       
   321 				return ($post_ID);
       
   322 			} else {
       
   323 				return ($MyPost[$current_lang['lang']]);
       
   324 				
       
   325 			}
       
   326 			
       
   327 		} else {
       
   328 			return ($post_ID);
       
   329 		}
       
   330 		
       
   331 }
       
   332 
       
   333 # 
       
   334 function xilimlSam_other_pages($post_ID){
       
   335 
       
   336 		if (class_exists('xili_language')) {
       
   337 		
       
   338 			$current_lang = the_cur_lang_dir();
       
   339 			
       
   340 			$MyPost = xiliml_the_other_posts($post_ID,"","","array");
       
   341 			//var_dump($MyPost);
       
   342 			//echo($current_lang['lang']." -> ".$MyPost[$current_lang['lang']]);
       
   343 			
       
   344 			if (in_array($current_lang['lang'],$MyPost)){
       
   345 				return ($post_ID);
       
   346 			} else {
       
   347 				return ($MyPost[$current_lang['lang']]);
       
   348 				
       
   349 			}
       
   350 			
       
   351 		} else {
       
   352 			return ($post_ID);
       
   353 		}
       
   354 }
       
   355 
    69 # Displays a list of categories
   356 # Displays a list of categories
    70 function dp_list_categories($Eparam='') {
   357 function dp_list_categories($Eparam='') {
    71 
   358 
       
   359 	if (class_exists('xili_language')) {
       
   360 		$current_lang = the_cur_lang_dir();
       
   361 	}
       
   362 	
    72 	$categories = get_categories('hide_empty=1'.$Eparam);
   363 	$categories = get_categories('hide_empty=1'.$Eparam);
    73 	$first = true;
   364 	$first = true;
    74 	$count = 0;
   365 	$count = 0;
    75 	
   366 	
    76 	foreach ($categories as $category) {
   367 	foreach ($categories as $category) {
    77 
   368 
    78 		if ($category->parent<1) {
   369 		if ($category->parent<1) {
    79 						
   370 						
    80 			echo ('<li class="menu-h-li">');
   371 			echo ('<li class="menu-h-li">');
    81 			echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' </a>');
   372 
       
   373 			if (class_exists('xili_language')) {
       
   374 				echo ('<a href="'.xiliml_get_category_link($category->cat_ID).'?lang='.$current_lang['lang'].'">'.__($category->name,'IriTheme').' </a>');
       
   375 			} else {
       
   376 				echo ('<a href="'.get_category_link($category->cat_ID).'">'.__($category->name,'IriTheme').' </a>');
       
   377 			}
    82 			echo '<ul>';
   378 			echo '<ul>';
    83 			
   379 			
    84 		
   380 			$category_posts = get_posts('numberposts=15&order=ASC&orderby=parent&category='.$category->cat_ID);
    85 			$category_posts = get_posts('numberposts=15&category='.$category->cat_ID);
       
    86 			$count2 = 0;
   381 			$count2 = 0;
    87 				 //echo("<!-- ".sizeof($category_posts)." -->");
   382 			/*$categoryN2 = get_category_link($category->cat_ID);
       
   383 			
       
   384 					foreach($categoryN2 as $catN2) {
       
   385 						
       
   386 						//$category_posts = get_posts('numberposts=15&order=ASC&orderby=parent&category='.$category->cat_ID);
       
   387 						echo ('<li class="menu-h-li2"><a href="'.get_category_link($catN2->cat_ID).'"> XX '.$catN2->name.' </a></li>');
       
   388 					}*/
       
   389 					
       
   390 					//echo("<!-- ".sizeof($category_posts)." -->");
    88 					foreach($category_posts as $post) {
   391 					foreach($category_posts as $post) {
    89 						
   392 						
    90 						echo '<li class="menu-h-li2" title="'.cache_cutter($post->post_title).'"><a href="'.$post->guid.'">'.text_cutter($post->post_title,200).'</a></li>';
   393 						
    91 						//echo '<li class="menu-h-li2" title="'.$count2.'"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
   394 						if (class_exists('xili_language')) {
    92 						$count2++; //if ($count2>6) break;
   395 								// Affiche les posts de la langue courante + les indéfinis 
       
   396 								//if (get_cur_language($post->ID)==$current_lang['lang'] or get_cur_language($post->ID)==""){
       
   397 								// Affiche seulement les posts  de la langue courante + les indéfinis 
       
   398 							if (get_cur_language($post->ID)==$current_lang['lang']){
       
   399 								
       
   400 								// gestion des niv 2 ajout de class si nécessaire
       
   401 								$MyCategoryPost = get_the_category($post->ID);
       
   402 								//var_dump($MyCategoryPost);
       
   403 
       
   404 								$MoreStyle="";
       
   405 								$title ="";
       
   406 								if (count($MyCategoryPost)>1){
       
   407 										foreach($MyCategoryPost as $MyCategory) { 
       
   408 											$MoreStyle.= " ".$MyCategory->category_nicename;
       
   409 											$title.= " ".$MyCategory->category_nicename;
       
   410 											//category_parent!=0
       
   411 										} 							
       
   412 								} else {
       
   413 								$MoreStyle ="menu-h-li2";
       
   414 								}
       
   415 								
       
   416 								echo '<li class="'.$MoreStyle.'" title="'.cache_cutter($post->post_title)." : ".$MoreStyle.'"><a href="'.get_permalink($post->ID).'">'.text_cutter($post->post_title,200).'</a></li>';
       
   417 								$count2++; //if ($count2>6) break;
       
   418 							}
       
   419 							
       
   420 						} else {
       
   421 						
       
   422 							echo '<li class="menu-h-li2" title="'.cache_cutter($post->post_title).'"><a href="'.get_permalink($post->ID).'">'.text_cutter($post->post_title,200).'</a></li>';
       
   423 							$count2++; //if ($count2>6) break;
       
   424 						}
       
   425 						
    93 					};
   426 					};
    94 					
   427 					
    95 
   428 
    96 				echo "</ul></li>";
   429 				echo "</ul></li>";
    97 			
   430 			
   285 # Cache cutter
   618 # Cache cutter
   286 function cache_cutter($text){
   619 function cache_cutter($text){
   287 	return (str_replace( "<!-- cut -->", "", $text));
   620 	return (str_replace( "<!-- cut -->", "", $text));
   288 }
   621 }
   289 
   622 
   290 
   623 # Créer le menu du footer 
   291 function dp_list_posts($Eparam='') {
   624 function dp_list_posts($Eparam='') {
   292 
   625 
   293 		$category_posts = get_posts($Eparam);
   626 	$category_posts = get_posts($Eparam);
   294 		
   627 	
       
   628 	if (class_exists('xili_language')) {
       
   629 		$current_lang = the_cur_lang_dir();
   295 		foreach($category_posts as $post) {
   630 		foreach($category_posts as $post) {
   296 			echo '<li><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
   631 			if (get_cur_language($post->ID)==$current_lang['lang']){
       
   632 				echo '<li><a href="'.get_permalink($post->ID).'">'.__($post->post_title,'IriTheme').'</a></li>';
       
   633 			}
   297 		};
   634 		};
       
   635 	} else {
       
   636 		foreach($category_posts as $post) {
       
   637 			echo '<li><a href="'.get_permalink($post->ID).'">'.__($post->post_title,'IriTheme').'</a></li>';
       
   638 		};
       
   639 	}
   298 }
   640 }
   299 
   641 
   300 
   642 
   301 /*
   643 /*
   302 Plugin Name: Get The Image
   644 Plugin Name: Get The Image
   446 	else :
   788 	else :
   447 		$img_arr = false;
   789 		$img_arr = false;
   448 	endif;
   790 	endif;
   449 	return $img_arr;
   791 	return $img_arr;
   450 }
   792 }
       
   793 
   451 ?>
   794 ?>