PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/wp_aegean5/panel/ci_panel.php

https://bitbucket.org/matyhaty/senses-45retallack
PHP | 377 lines | 264 code | 69 blank | 44 comment | 34 complexity | b9577c8600db9b27b52e2ef1639a5c1a MD5 | raw file
  1. <?php
  2. if(!defined('CI_PANEL_TABS_DIR')) define('CI_PANEL_TABS_DIR', 'functions/tabs');
  3. // Load our default options.
  4. load_ci_defaults();
  5. add_action('init', 'ci_register_theme_default_scripts', 10);
  6. function ci_register_theme_default_scripts()
  7. {
  8. global $wp_scripts, $wp_version;
  9. // Returns jquery version, or boolean false if undefined.
  10. // Can't use it as of WP 3.6-beta2 as it's undefined.
  11. //$jquery_ver = isset($wp_scripts->registered['jquery']->ver) ? $wp_scripts->registered['jquery']->ver : false;
  12. // jQuery version-depended scripts (WP 3.6 will have jQuery >= 1.9)
  13. // Check for WP 3.5.9 in order to capture the 3.6 betas and RCs.
  14. if( version_compare($wp_version, '3.5.9', '<') )
  15. {
  16. // jQuery < 1.9
  17. wp_register_script('jquery-cycle-all', get_child_or_parent_file_uri('/panel/scripts/jquery.cycle.all.latest.min.js'), array('jquery'), '2.88', true);
  18. }
  19. else
  20. {
  21. // jQuery >= 1.9
  22. wp_register_script('jquery-cycle-all', get_child_or_parent_file_uri('/panel/scripts/jquery.cycle.all-3.0.2.js'), array('jquery'), '3.0.2', true);
  23. }
  24. // jQuery version-independed scripts
  25. wp_register_script('jquery-flexslider', get_child_or_parent_file_uri('/panel/scripts/jquery.flexslider-2.1-min.js'), array('jquery'), false, true);
  26. wp_register_script('jquery-hoverIntent', get_child_or_parent_file_uri('/panel/scripts/jquery.hoverIntent.r7.min.js'), array('jquery'), 'r7', true);
  27. wp_register_script('jquery-superfish', get_child_or_parent_file_uri('/panel/scripts/superfish-1.7.2.js'), array('jquery', 'jquery-hoverIntent'), '1.7.2', true);
  28. }
  29. add_action('admin_init','ci_register_admin_scripts');
  30. function ci_register_admin_scripts()
  31. {
  32. //
  33. // Register all scripts and style here, unconditionally. Conditionals are used further down this file for enqueueing.
  34. //
  35. wp_register_script('ci-colorpicker', get_child_or_parent_file_uri('/panel/scripts/colorpicker/js/colorpicker.js'), array('jquery'));
  36. wp_register_style('ci-colorpicker', get_child_or_parent_file_uri('/panel/scripts/colorpicker/css/colorpicker.css'));
  37. wp_register_script('ci-panel', get_child_or_parent_file_uri('/panel/scripts/panelscripts.js'), array('jquery'));
  38. wp_register_style('ci-panel-css', get_child_or_parent_file_uri('/panel/panel.css'));
  39. wp_register_script('ci-post-formats', get_child_or_parent_file_uri('/panel/scripts/ci-post-formats.js'), array('jquery'));
  40. wp_register_style('ci-post-formats', get_child_or_parent_file_uri('/panel/styles/ci-post-formats.css'));
  41. // Can be enqueued properly by ci_enqueue_media_manager_scripts() defined in panel/generic.php
  42. wp_register_script('ci-media-manager-3-3', get_child_or_parent_file_uri('/panel/scripts/media-manager-3.3.js'), array('thickbox'));
  43. wp_register_script('ci-media-manager-3-5', get_child_or_parent_file_uri('/panel/scripts/media-manager-3.5.js'), array('media-editor'));
  44. }
  45. add_action('admin_enqueue_scripts','ci_enqueue_admin_scripts');
  46. function ci_enqueue_admin_scripts()
  47. {
  48. global $pagenow;
  49. //
  50. // Enqueue here scripts and styles that are to be loaded on all admin pages.
  51. //
  52. if($pagenow=='post-new.php' or $pagenow=='post.php')
  53. {
  54. //
  55. // Enqueue here scripts and styles that are to be loaded only on post edit screens.
  56. //
  57. if( current_theme_supports('post-formats') )
  58. {
  59. wp_enqueue_script('ci-post-formats');
  60. wp_enqueue_style('ci-post-formats');
  61. }
  62. }
  63. if($pagenow=='themes.php' and isset($_GET['page']) and $_GET['page']=='ci_panel.php')
  64. {
  65. //
  66. // Enqueue here scripts and styles that are to be loaded only on CSSIgniter Settings panel.
  67. //
  68. global $wp_version;
  69. wp_enqueue_script('ci-panel');
  70. wp_enqueue_style('ci-panel-css');
  71. //
  72. // Version depended scripts.
  73. //
  74. if(version_compare($wp_version, '3.5', '<'))
  75. {
  76. wp_enqueue_script('ci-colorpicker');
  77. wp_enqueue_style('ci-colorpicker');
  78. wp_enqueue_script('media-upload');
  79. wp_enqueue_script('thickbox');
  80. wp_enqueue_style('thickbox');
  81. wp_enqueue_script('ci-media-manager-3-3');
  82. }
  83. if(version_compare($wp_version, '3.5', '>='))
  84. {
  85. wp_enqueue_style( 'wp-color-picker' );
  86. wp_enqueue_script( 'wp-color-picker' );
  87. wp_enqueue_media();
  88. wp_enqueue_script('ci-media-manager-3-5');
  89. }
  90. }
  91. }
  92. add_action('admin_menu', 'ci_create_menu');
  93. function ci_create_menu() {
  94. add_action( 'admin_init', 'ci_register_settings' );
  95. // Handle reset before anything is outputed in the browser.
  96. // This is here because it needs the settings to be registered, but because it
  97. // redirects, it should be called before the ci_settings_page.
  98. global $pagenow;
  99. if (is_admin() and isset($_POST['reset']) and ($pagenow == "themes.php") )
  100. {
  101. delete_option(THEME_OPTIONS);
  102. global $ci;
  103. $ci=array();
  104. ci_default_options(true);
  105. wp_redirect( 'themes.php?page=ci_panel.php' );
  106. }
  107. if(!CI_WHITELABEL)
  108. $menu_title = __('CSSIgniter Settings', 'ci_theme');
  109. else
  110. $menu_title = __('Theme Settings', 'ci_theme');
  111. add_theme_page($menu_title, $menu_title, 'edit_theme_options', basename(__FILE__), 'ci_settings_page');
  112. }
  113. function ci_register_settings() {
  114. //register_setting( 'ci-settings-group', THEME_OPTIONS, 'ci_options_validate');
  115. register_setting( 'ci-settings-group', THEME_OPTIONS);
  116. }
  117. function ci_settings_page()
  118. {
  119. ?>
  120. <div class="wrap">
  121. <h2><?php echo sprintf(_x('%s Settings', 'theme name settings', 'ci_theme'), CI_THEME_NICENAME); ?></h2>
  122. <?php $latest_version = ci_theme_update_check(); ?>
  123. <?php if(($latest_version !== false) and version_compare($latest_version, CI_THEME_VERSION, '>')): ?>
  124. <div id="theme-update">
  125. <?php echo sprintf( __('A theme update is available. The latest version is <b>%1$s</b> and you are running <b>%2$s</b>', 'ci_theme'), $latest_version, CI_THEME_VERSION); ?>
  126. </div>
  127. <?php endif; ?>
  128. <div id="ci_panel">
  129. <form method="post" action="options.php" id="theform" enctype="multipart/form-data">
  130. <?php
  131. settings_fields('ci-settings-group');
  132. $theme_options = get_option(THEME_OPTIONS);
  133. ?>
  134. <div id="ci_header">
  135. <?php if(!CI_WHITELABEL): ?>
  136. <img src="<?php echo apply_filters('ci_panel_logo_url', get_child_or_parent_file_uri('/panel/img/logo.png'), '/panel/img/logo.png'); ?>" />
  137. <?php endif; ?>
  138. </div>
  139. <?php if (isset($_POST['reset'])) { ?> <div class="resetbox"><?php _e('Settings reset!', 'ci_theme'); ?></div> <?php } ?>
  140. <div class="success"></div>
  141. <div class="ci_save ci_save_top group">
  142. <p>
  143. <?php if(CI_DOCS != ''): ?><a href="<?php echo CI_DOCS; ?>"><?php _e('Documentation', 'ci_theme'); ?></a><?php endif; ?>
  144. <?php if(CI_DOCS != '' and CI_FORUM != ''): ?> | <?php endif; ?>
  145. <?php if(CI_FORUM != ''): ?><a href="<?php echo CI_FORUM; ?>"><?php _e('Support forum', 'ci_theme'); ?></a><?php endif; ?>
  146. </p>
  147. <input type="submit" class="button-primary save" value="<?php _e('Save Changes', 'ci_theme') ?>" />
  148. </div>
  149. <div id="ci_main" class="group">
  150. <?php
  151. // Each tab is responsible for adding itself to the list of the panel tabs.
  152. // The priority on add_filter() affects the order of the tabs.
  153. // Tab files are automatically loaded for initialization by the function load_ci_defaults().
  154. // Child themes have a chance to load their tabs (or unload the parent theme's tabs) only after
  155. // the parent theme has initialized its tabs.
  156. $paneltabs = apply_filters( 'ci_panel_tabs', array() );
  157. ?>
  158. <div id="ci_sidebar">
  159. <ul>
  160. <?php $tabNum = 1; ?>
  161. <?php foreach($paneltabs as $name => $title): ?>
  162. <?php if ($tabNum==1) $firstclass = 'class="active"'; else $firstclass = ''; ?>
  163. <li id="<?php echo $name; ?>"><a href="#tab<?php echo $tabNum; ?>" rel="tab<?php echo $tabNum; ?>" <?php echo $firstclass; ?>><span><?php echo $title ?></span></a></li>
  164. <?php $tabNum++; ?>
  165. <?php endforeach; ?>
  166. </ul>
  167. </div><!-- /sidebar -->
  168. <div id="ci_options">
  169. <?php $tabNum = 1; ?>
  170. <?php foreach($paneltabs as $name => $title): ?>
  171. <?php if ($tabNum==1) $firstclass='one'; else $firstclass=''; ?>
  172. <div id="tab<?php echo $tabNum; ?>" class="tab <?php echo $firstclass?>"><?php get_template_part(CI_PANEL_TABS_DIR.'/'.$name); ?></div>
  173. <?php $tabNum++; ?>
  174. <?php endforeach; ?>
  175. </div><!-- #ci_options -->
  176. </div><!-- #ci_main -->
  177. <div class="ci_save group"><input type="submit" class="button-primary save" value="<?php _e('Save Changes', 'ci_theme'); ?>" /></div>
  178. </form>
  179. </div><!-- #ci_panel -->
  180. <div id="ci-reset-box">
  181. <form method="post" action="">
  182. <input type="hidden" name="reset" value="reset" />
  183. <input type="submit" class="button" value="<?php _e('Reset Settings', 'ci_theme') ?>" onclick="return confirm('<?php _e('Are you sure? All settings will be lost!', 'ci_theme'); ?>'); " />
  184. </form>
  185. </div>
  186. </div><!-- wrap -->
  187. <?php
  188. }
  189. function ci_options_validate($set)
  190. {
  191. $set = (array)$set;
  192. foreach ($set as &$item)
  193. {
  194. if (is_string($item)){
  195. $item = htmlentities($item,ENT_COMPAT,'UTF-8',false);
  196. }
  197. }
  198. return $set;
  199. }
  200. function load_ci_defaults()
  201. {
  202. global $load_defaults, $ci, $ci_defaults;
  203. $load_defaults = TRUE;
  204. // All php files in CI_PANEL_TABS_DIR are loaded by default.
  205. // Those files (tabs) are responsible for adding themselves on the actual tabs that will be show,
  206. // by hooking on the 'ci_panel_tabs' filter.
  207. $paths = array();
  208. $paths[] = get_template_directory();
  209. if( is_child_theme() ) {
  210. $paths[] = get_stylesheet_directory();
  211. }
  212. foreach($paths as $path)
  213. {
  214. $path .= '/' . CI_PANEL_TABS_DIR;
  215. if (file_exists($path) and $handle = opendir($path)) {
  216. while (false !== ($file = readdir($handle))) {
  217. if ($file != "." && $file != "..") {
  218. $file_info = pathinfo($path.'/'.$file);
  219. if(isset($file_info['extension']) and $file_info['extension']=='php') {
  220. get_template_part( CI_PANEL_TABS_DIR . '/' . basename( $file, '.php' ) );
  221. }
  222. }
  223. }
  224. closedir($handle);
  225. }
  226. }
  227. $load_defaults = FALSE;
  228. $ci_defaults = apply_filters('ci_defaults', $ci_defaults);
  229. }
  230. function load_panel_snippet( $slug, $name = null )
  231. {
  232. $slug = 'panel/snippets/' . $slug;
  233. do_action( "get_template_part_{$slug}", $slug, $name );
  234. $templates = array();
  235. if ( isset($name) )
  236. $templates[] = "{$slug}-{$name}.php";
  237. $templates[] = "{$slug}.php";
  238. locate_template($templates, true, false);
  239. }
  240. //
  241. //
  242. // CSSIgniter panel control generators
  243. //
  244. //
  245. function ci_panel_textarea($fieldname, $label)
  246. {
  247. global $ci;
  248. ?>
  249. <label for="<?php echo $fieldname; ?>"><?php echo $label; ?></label>
  250. <textarea id="<?php echo $fieldname; ?>" name="<?php echo THEME_OPTIONS.'['.$fieldname.']'; ?>" rows="5"><?php echo esc_textarea($ci[$fieldname]); ?></textarea>
  251. <?php
  252. }
  253. function ci_panel_input($fieldname, $label, $params=array())
  254. {
  255. global $ci;
  256. $defaults = array(
  257. 'label_class' => '',
  258. 'input_class' => '',
  259. 'input_type' => 'text'
  260. );
  261. $params = wp_parse_args( $params, $defaults );
  262. ?>
  263. <label for="<?php echo $fieldname; ?>" class="<?php echo $params['label_class']; ?>"><?php echo $label; ?></label>
  264. <input id="<?php echo $fieldname; ?>" type="<?php echo $params['input_type']; ?>" size="60" name="<?php echo THEME_OPTIONS.'['.$fieldname.']'; ?>" value="<?php echo esc_attr($ci[$fieldname]); ?>" class="<?php echo $params['input_class']; ?>" />
  265. <?php
  266. }
  267. // $fieldname is the actual name="" attribute common to all radios in the group.
  268. // $optionname is the id of the radio, so that the label can be associated with it.
  269. function ci_panel_radio($fieldname, $optionname, $optionval, $label)
  270. {
  271. global $ci;
  272. ?>
  273. <input type="radio" class="radio" id="<?php echo $optionname; ?>" name="<?php echo THEME_OPTIONS.'['.$fieldname.']'; ?>" value="<?php echo $optionval; ?>" <?php checked($ci[$fieldname], $optionval); ?> />
  274. <label for="<?php echo $optionname; ?>" class="radio"><?php echo $label; ?></label>
  275. <?php
  276. }
  277. function ci_panel_checkbox($fieldname, $value, $label)
  278. {
  279. global $ci;
  280. ?>
  281. <input type="checkbox" id="<?php echo $fieldname; ?>" class="check" name="<?php echo THEME_OPTIONS.'['.$fieldname.']'; ?>" value="<?php echo $value; ?>" <?php checked($ci[$fieldname], $value); ?> />
  282. <label for="<?php echo $fieldname; ?>"><?php echo $label; ?></label>
  283. <?php
  284. }
  285. function ci_panel_upload_image($fieldname, $label)
  286. {
  287. global $ci;
  288. ?>
  289. <label for="<?php echo $fieldname; ?>"><?php echo $label; ?></label>
  290. <input id="<?php echo $fieldname; ?>" type="text" size="60" name="<?php echo THEME_OPTIONS.'['.$fieldname.']'; ?>" value="<?php echo esc_attr($ci[$fieldname]); ?>" class="uploaded" />
  291. <input type="submit" class="ci-upload button" value="<?php _e('Upload image', 'ci_theme'); ?>" />
  292. <div class="up-preview"><?php echo (isset($ci[$fieldname]) ? '<img src="'.esc_attr($ci[$fieldname]).'" />' : '' ); ?></div>
  293. <?php
  294. }
  295. function ci_panel_dropdown($fieldname, $options, $label)
  296. {
  297. global $ci;
  298. $options = (array)$options;
  299. ?>
  300. <label for="<?php echo $fieldname; ?>"><?php echo $label; ?></label>
  301. <select id="<?php echo $fieldname; ?>" name="<?php echo THEME_OPTIONS.'['.$fieldname.']'; ?>">
  302. <?php foreach($options as $opt_val => $opt_label): ?>
  303. <option value="<?php echo $opt_val; ?>" <?php selected($ci[$fieldname], $opt_val); ?>><?php echo $opt_label; ?></option>
  304. <?php endforeach; ?>
  305. </select>
  306. <?php
  307. }
  308. ?>