PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/universite/themes/meezio/functions.php

http://jvstutoriales.googlecode.com/
PHP | 459 lines | 393 code | 30 blank | 36 comment | 25 complexity | 79ff57a90c5e0a580e56cf98470bd4b3 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, GPL-3.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. $themename = "Meezio Theme";
  3. $shortname = "mzo";
  4. $options = array (
  5. array( "type" => "open"),
  6. array( "name" => "Theme color",
  7. "desc" => "Choose a color scheme for your theme",
  8. "id" => $shortname."_color_scheme",
  9. "std" => "",
  10. "type" => "select",
  11. "options" => array("blue", "brown", "green", "orange", "pink", "purple", "red", "salmon", "yellow"),
  12. ),
  13. array( "name" => "Background image",
  14. "desc" => "Choose a a background image for your theme",
  15. "id" => $shortname."_background_image",
  16. "std" => "",
  17. "type" => "select",
  18. "options" => array("pattern1", "pattern2", "pattern3", "pattern4", "pattern5"),
  19. ),
  20. array( "name" => "Logo image",
  21. "desc" => "Enter the path to your logo image (base path is wp-content/themes/meezio/).",
  22. "id" => $shortname."_logo_image",
  23. "std" => "wp-content/themes/meezio/images/logo.png",
  24. "type" => "text"),
  25. array( "name" => "Logo image width",
  26. "desc" => "Enter the logo image width in pixels.",
  27. "id" => $shortname."_logo_image_width",
  28. "std" => "222",
  29. "type" => "text"),
  30. array( "name" => "Logo image height",
  31. "desc" => "Enter the logo image height in pixels.",
  32. "id" => $shortname."_logo_image_height",
  33. "std" => "95",
  34. "type" => "text"),
  35. array( "name" => "Page transition style",
  36. "desc" => "Choose the page transition style for your theme",
  37. "id" => $shortname."_transition",
  38. "std" => "",
  39. "type" => "select",
  40. "options" => array("horizontal", "vertical", "horizontal_vertical"),
  41. ),
  42. array( "name" => "Page alignement",
  43. "desc" => "Choose the page alignement for your theme",
  44. "id" => $shortname."_page_alignement",
  45. "std" => "",
  46. "type" => "select",
  47. "options" => array("centered", "left"),
  48. ),
  49. array( "name" => "Custom font for H1 and H2 headers",
  50. "desc" => "Specify whether you'd like to use a special font for the H1 and H2 headings",
  51. "id" => $shortname."_cufon",
  52. "std" => "",
  53. "type" => "select",
  54. "options" => array("yes", "no"),
  55. ),
  56. array( "name" => "Footer text",
  57. "desc" => "Footer text",
  58. "id" => $shortname."_footer_text",
  59. "std" => "This is the &copy; copyright info. Your company name.",
  60. "type" => "text"),
  61. array( "name" => "Blog category",
  62. "desc" => "Blog category to open after the last page has been reached. Leave empty if not used.",
  63. "id" => $shortname."_blog_category",
  64. "std" => "",
  65. "type" => "text"),
  66. array( "type" => "close")
  67. );
  68. function mytheme_add_admin() {
  69. global $themename, $shortname, $options;
  70. if ( $_GET['page'] == basename(__FILE__) ) {
  71. if ( 'save' == $_REQUEST['action'] ) {
  72. foreach ($options as $value) {
  73. update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  74. foreach ($options as $value) {
  75. if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
  76. header("Location: themes.php?page=functions.php&saved=true");
  77. die;
  78. } else if( 'reset' == $_REQUEST['action'] ) {
  79. foreach ($options as $value) {
  80. delete_option( $value['id'] ); }
  81. header("Location: themes.php?page=functions.php&reset=true");
  82. die;
  83. }
  84. }
  85. add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
  86. }
  87. function mytheme_admin() {
  88. global $themename, $shortname, $options;
  89. if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  90. if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
  91. ?>
  92. <div class="wrap">
  93. <h2><?php echo $themename; ?> settings</h2>
  94. <form method="post">
  95. <?php foreach ($options as $value) {
  96. switch ( $value['type'] ) {
  97. case "open":
  98. ?>
  99. <table width="100%" border="0" style="background-color:#f9f9f9; padding:5px;">
  100. <?php break;
  101. case "close":
  102. ?>
  103. </table><br />
  104. <?php break;
  105. case "title":
  106. ?>
  107. <table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
  108. <td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
  109. </tr>
  110. <?php break;
  111. case 'text':
  112. ?>
  113. <tr>
  114. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  115. <td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
  116. </tr>
  117. <tr>
  118. <td><small><?php echo $value['desc']; ?></small></td>
  119. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px solid #ececec;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  120. <?php
  121. break;
  122. case 'textarea':
  123. ?>
  124. <tr>
  125. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  126. <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>
  127. </tr>
  128. <tr>
  129. <td><small><?php echo $value['desc']; ?></small></td>
  130. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px solid #ececec;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  131. <?php
  132. break;
  133. case 'select':
  134. ?>
  135. <tr>
  136. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  137. <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
  138. </tr>
  139. <tr>
  140. <td><small><?php echo $value['desc']; ?></small></td>
  141. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px solid #ececec;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  142. <?php
  143. break;
  144. case "checkbox":
  145. ?>
  146. <tr>
  147. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  148. <td width="80%"><? if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
  149. <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  150. </td>
  151. </tr>
  152. <tr>
  153. <td><small><?php echo $value['desc']; ?></small></td>
  154. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px solid #ececec;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  155. <?php break;
  156. }
  157. }
  158. ?>
  159. <!--</table>-->
  160. <p class="submit">
  161. <input name="save" type="submit" value="Save changes" />
  162. <input type="hidden" name="action" value="save" />
  163. </p>
  164. </form>
  165. <form method="post">
  166. <p class="submit">
  167. <input name="reset" type="submit" value="Reset" />
  168. <input type="hidden" name="action" value="reset" />
  169. </p>
  170. </form>
  171. <?php
  172. }
  173. add_action('admin_menu', 'mytheme_add_admin'); ?>
  174. <?php
  175. if ( function_exists('register_sidebar') )
  176. register_sidebar(array(
  177. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  178. 'after_widget' => '</li>',
  179. 'before_title' => '',
  180. 'after_title' => '',
  181. ));
  182. ?>
  183. <?php
  184. function list_all_pages() {
  185. global $wpdb;
  186. $query = "
  187. SELECT post_content, ID, menu_order
  188. FROM wp_posts
  189. WHERE post_status = 'publish'
  190. AND post_type = 'page'
  191. ORDER BY menu_order ASC
  192. ";
  193. $p = $wpdb->get_results($query);
  194. return $p;
  195. }
  196. ?>
  197. <?php
  198. function get_menu_item_ID($menu_item) {
  199. global $wpdb;
  200. $query = "
  201. SELECT id, parent
  202. FROM wp_menuitems
  203. WHERE value = '#$menu_item'
  204. LIMIT 1
  205. ";
  206. $result = $wpdb->get_results($query);
  207. if($result[0]->parent != 0) {
  208. return $result[0]->parent;
  209. } else {
  210. return $result[0]->id;
  211. }
  212. }
  213. ?>
  214. <?php
  215. function pageURL() {
  216. $pageURL = 'http';
  217. if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
  218. $pageURL .= "://";
  219. if ($_SERVER["SERVER_PORT"] != "80") {
  220. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  221. } else {
  222. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  223. }
  224. return $pageURL;
  225. }
  226. ?>
  227. <?php
  228. add_filter('mce_buttons_2', 'mcekit_editor_buttons');
  229. function mcekit_editor_buttons($buttons) {
  230. array_unshift($buttons, 'styleselect');
  231. return $buttons;
  232. }
  233. ?>
  234. <?php
  235. add_filter('tiny_mce_before_init', 'mcekit_editor_settings');
  236. function mcekit_editor_settings($settings) {
  237. if ( !empty($settings['theme_advanced_styles']) )
  238. $settings['theme_advanced_styles'] .= ';';
  239. else
  240. $settings['theme_advanced_styles'] = '';
  241. /**
  242. * The format for this setting is "Name to display=class-name;".
  243. * More info: http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/theme_advanced_styles
  244. *
  245. * To be able to translate the class names they can be set in a PHP array (to keep them readable)
  246. * and then converted to TinyMCE's format. You will need to replace 'tinymce-kit' with your theme's textdomain.
  247. */
  248. $classes = array(
  249. __('260px grid', 'tinymce-kit') => 'grid_260',
  250. __('540px grid', 'tinymce-kit') => 'grid_540',
  251. __('Fancybox image', 'tinymce-kit') => 'fancybox',
  252. __('Thumbnail', 'tinymce-kit') => 'thumb',
  253. __('Clear float', 'tinymce-kit') => 'clear',
  254. );
  255. $class_settings = '';
  256. foreach ( $classes as $name => $value ) {
  257. $class_settings .= "{$name}={$value};";
  258. }
  259. $settings['theme_advanced_styles'] .= trim($class_settings, '; ');
  260. return $settings;
  261. }
  262. /**
  263. * Custom functions
  264. */
  265. /* Disable the Admin Bar. */
  266. add_filter( 'show_admin_bar', '__return_false' );
  267. /* Remove the Admin Bar preference in user profile */
  268. remove_action( 'personal_options', '_admin_bar_preferences' );
  269. /**
  270. * Add menu
  271. */
  272. function register_menu() {
  273. register_nav_menus( array(
  274. 'home-menu' => __( 'Home Menu' ),
  275. 'inner-menu' => __( 'Inner Menu' )
  276. ) );
  277. }
  278. add_action( 'after_setup_theme', 'register_menu' );
  279. /**
  280. * Check child pages
  281. */
  282. function is_child($pageID) {
  283. global $post;
  284. if( is_page() && ($post->post_parent==$pageID) ) {
  285. return true;
  286. } else {
  287. return false;
  288. }
  289. }
  290. /**
  291. * Get first image of post/page
  292. */
  293. function get_first_image($post) {
  294. $first_img = '';
  295. ob_start();
  296. ob_end_clean();
  297. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  298. $first_img = $matches [1] [0];
  299. if(empty($first_img)){
  300. return false;
  301. }
  302. return $first_img;
  303. }
  304. /**
  305. * Get Subpages
  306. */
  307. function get_child_pages(){
  308. global $post;
  309. $output = '';
  310. $query = new WP_Query(array('post_parent' => $post->ID, 'post_type' => 'page', 'order' => 'ASC', 'orderby' => 'menu_order', 'posts_per_page' => -1));
  311. if ( $query->have_posts () ) {
  312. $cnt = 0;
  313. while ( $query->have_posts() ) : $query->the_post();
  314. if ($cnt == 6) {
  315. $style = 'style="margin-left:0"';
  316. } elseif ($cnt == 2) {
  317. $style = 'style="margin-left:0; clear: both"';
  318. } else {
  319. $style = '';
  320. }
  321. $output .= '<div class="child-page-link" ' . $style . ' id="child-page-' . get_the_ID() . '"><a class="fancybox" href="' . get_the_guid() . '&ajax=true">' . get_the_title() . '</a></div>';
  322. $cnt++; $style = '';
  323. endwhile;
  324. return '<div id="child-pages">' . $output . '</div>';
  325. } else {
  326. return false;
  327. }
  328. }
  329. /**
  330. * Subpages shortcode
  331. */
  332. add_shortcode('subpages-links', 'get_child_pages');
  333. /**
  334. * Add image map
  335. */
  336. function add_image_map($atts, $content = null){
  337. extract(shortcode_atts(array(
  338. "href1" => '#',
  339. "href2" => '#',
  340. "href3" => '#',
  341. "href4" => '#',
  342. "href5" => '#'
  343. ), $atts));
  344. $links .= '<div id="parcours-map">';
  345. $links .= '<a class="first" href="' . $href1 . '"></a>';
  346. $links .= '<a class="second" href="' . $href2 . '"></a>';
  347. $links .= '<a class="third" href="' . $href3 . '"></a>';
  348. $links .= '<a class="fourth" href="' . $href4 . '"></a>';
  349. $links .= '<a class="fifth" href="' . $href5 . '"></a>';
  350. $links .= '</div>';
  351. return $links;
  352. }
  353. /**
  354. * Subpages shortcode
  355. */
  356. add_shortcode('parcours-unique', 'add_image_map');
  357. /**
  358. * Add sidebar
  359. */
  360. register_sidebar(array(
  361. 'name' => 'Sidebar 2',
  362. 'description' => '',
  363. 'before_title' => '<h4>',
  364. 'after_title' => '</h4>',
  365. 'before_widget' => '<div class="widget">',
  366. 'after_widget' => '</div>',
  367. ));
  368. ?>