PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/themes/nonus/framework/options/options.php

https://github.com/alniko009/magic
PHP | 934 lines | 507 code | 249 blank | 178 comment | 100 complexity | d830cb6da41896a65f1e86901dc3948d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if (!class_exists('NHP_Options')) {
  3. // windows-proof constants: replace backward by forward slashes - thanks to: https://github.com/peterbouwmeester
  4. $fslashed_dir = trailingslashit(str_replace('\\', '/', dirname(__FILE__)));
  5. $fslashed_abs = trailingslashit(str_replace('\\', '/', ABSPATH));
  6. if (!defined('NHP_OPTIONS_DIR')) {
  7. define('NHP_OPTIONS_DIR', $fslashed_dir);
  8. }
  9. if (!defined('NHP_OPTIONS_URL')) {
  10. define('NHP_OPTIONS_URL', site_url(str_replace($fslashed_abs, '', $fslashed_dir)));
  11. }
  12. class NHP_Options {
  13. protected $framework_url = 'http://leemason.github.com/NHP-Theme-Options-Framework/';
  14. protected $framework_version = '1.0.6';
  15. public $dir = NHP_OPTIONS_DIR;
  16. public $url = NHP_OPTIONS_URL;
  17. public $page = '';
  18. public $args = array();
  19. public $sections = array();
  20. public $extra_tabs = array();
  21. public $errors = array();
  22. public $warnings = array();
  23. public $options = array();
  24. /**
  25. * Class Constructor. Defines the args for the theme options class
  26. *
  27. * @since NHP_Options 1.0
  28. *
  29. * @param $array $args Arguments. Class constructor arguments.
  30. */
  31. function __construct($sections = array(), $args = array(), $extra_tabs = array()) {
  32. $defaults = array();
  33. $defaults['opt_name'] = ''; //must be defined by theme/plugin
  34. $defaults['google_api_key'] = ''; //must be defined for use with google webfonts field type
  35. $defaults['menu_icon'] = NHP_OPTIONS_URL . '/img/menu_icon.png';
  36. $defaults['menu_title'] = __('Options', 'nhp-opts');
  37. $defaults['page_icon'] = 'icon-themes';
  38. $defaults['page_title'] = __('Options', 'nhp-opts');
  39. $defaults['page_slug'] = '_options';
  40. $defaults['page_cap'] = 'manage_options';
  41. $defaults['page_type'] = 'menu';
  42. $defaults['page_parent'] = '';
  43. $defaults['page_position'] = 100;
  44. $defaults['allow_sub_menu'] = true;
  45. $defaults['show_import_export'] = true;
  46. $defaults['dev_mode'] = true;
  47. $defaults['stylesheet_override'] = false;
  48. $defaults['help_tabs'] = array();
  49. $defaults['help_sidebar'] = __('', 'nhp-opts');
  50. //get args
  51. $this->args = wp_parse_args($args, $defaults);
  52. $this->args = apply_filters('nhp-opts-args-' . $this->args['opt_name'], $this->args);
  53. //get sections
  54. $this->sections = apply_filters('nhp-opts-sections-' . $this->args['opt_name'], $sections);
  55. //get extra tabs
  56. $this->extra_tabs = apply_filters('nhp-opts-extra-tabs-' . $this->args['opt_name'], $extra_tabs);
  57. //set option with defaults
  58. add_action('init', array(&$this, '_set_default_options'));
  59. //options page
  60. add_action('admin_menu', array(&$this, '_options_page'));
  61. //register setting
  62. add_action('admin_init', array(&$this, '_register_setting'));
  63. //add the js for the error handling before the form
  64. add_action('nhp-opts-page-before-form-' . $this->args['opt_name'], array(&$this, '_errors_js'), 1);
  65. //add the js for the warning handling before the form
  66. add_action('nhp-opts-page-before-form-' . $this->args['opt_name'], array(&$this, '_warnings_js'), 2);
  67. //hook into the wp feeds for downloading the exported settings
  68. add_action('do_feed_nhpopts-' . $this->args['opt_name'], array(&$this, '_download_options'), 1, 1);
  69. //get the options for use later on
  70. $this->options = get_option($this->args['opt_name']);
  71. }
  72. //function
  73. /**
  74. * ->get(); This is used to return and option value from the options array
  75. *
  76. * @since NHP_Options 1.0.1
  77. *
  78. * @param $array $args Arguments. Class constructor arguments.
  79. */
  80. function get($opt_name, $default = null) {
  81. return (!empty($this->options[$opt_name])) ? $this->options[$opt_name] : $default;
  82. }
  83. //function
  84. /**
  85. * ->set(); This is used to set an arbitrary option in the options array
  86. *
  87. * @since NHP_Options 1.0.1
  88. *
  89. * @param string $opt_name the name of the option being added
  90. * @param mixed $value the value of the option being added
  91. */
  92. function set($opt_name = '', $value = '') {
  93. if ($opt_name != '') {
  94. $this->options[$opt_name] = $value;
  95. update_option($this->args['opt_name'], $this->options);
  96. }
  97. //if
  98. }
  99. /**
  100. * ->show(); This is used to echo and option value from the options array
  101. *
  102. * @since NHP_Options 1.0.1
  103. *
  104. * @param $array $args Arguments. Class constructor arguments.
  105. */
  106. function show($opt_name, $default = '') {
  107. $option = $this->get($opt_name);
  108. if (!is_array($option) && $option != '') {
  109. echo $option;
  110. } elseif ($default != '') {
  111. echo $default;
  112. }
  113. }
  114. //function
  115. /**
  116. * Get default options into an array suitable for the settings API
  117. *
  118. * @since NHP_Options 1.0
  119. *
  120. */
  121. function _default_values() {
  122. $defaults = array();
  123. foreach ($this->sections as $k => $section) {
  124. if (isset($section['fields'])) {
  125. foreach ($section['fields'] as $fieldk => $field) {
  126. if (!isset($field['std'])) {
  127. $field['std'] = '';
  128. }
  129. $defaults[$field['id']] = $field['std'];
  130. }
  131. //foreach
  132. }
  133. //if
  134. }
  135. //foreach
  136. //fix for notice on first page load
  137. $defaults['last_tab'] = 0;
  138. return $defaults;
  139. }
  140. /**
  141. * Set default options on admin_init if option doesnt exist (theme activation hook caused problems, so admin_init it is)
  142. *
  143. * @since NHP_Options 1.0
  144. *
  145. */
  146. function _set_default_options() {
  147. if (!get_option($this->args['opt_name'])) {
  148. add_option($this->args['opt_name'], $this->_default_values());
  149. }
  150. $this->options = get_option($this->args['opt_name']);
  151. }
  152. //function
  153. /**
  154. * Class Theme Options Page Function, creates main options page.
  155. *
  156. * @since NHP_Options 1.0
  157. */
  158. function _options_page() {
  159. if ($this->args['page_type'] == 'submenu') {
  160. if (!isset($this->args['page_parent']) || empty($this->args['page_parent'])) {
  161. $this->args['page_parent'] = 'themes.php';
  162. }
  163. $this->page = add_theme_page(
  164. $this->args['page_title'],
  165. $this->args['menu_title'],
  166. $this->args['page_cap'],
  167. $this->args['page_slug'],
  168. array(&$this, '_options_page_html')
  169. );
  170. }
  171. add_action('admin_print_styles-' . $this->page, array(&$this, '_enqueue'));
  172. add_action('load-' . $this->page, array(&$this, '_load_page'));
  173. }
  174. //function
  175. /**
  176. * enqueue styles/js for theme page
  177. *
  178. * @since NHP_Options 1.0
  179. */
  180. function _enqueue() {
  181. wp_register_style(
  182. 'nhp-opts-css',
  183. $this->url . 'css/options.css',
  184. array('farbtastic'),
  185. time(),
  186. 'all'
  187. );
  188. wp_register_style(
  189. 'nhp-opts-jquery-ui-css',
  190. apply_filters('nhp-opts-ui-theme', $this->url . 'css/jquery-ui-aristo/aristo.css'),
  191. '',
  192. time(),
  193. 'all'
  194. );
  195. if (false === $this->args['stylesheet_override']) {
  196. wp_enqueue_style('nhp-opts-css');
  197. }
  198. wp_enqueue_script(
  199. 'nhp-opts-js',
  200. $this->url . 'js/options.js',
  201. array('jquery'),
  202. time(),
  203. true
  204. );
  205. wp_localize_script('nhp-opts-js', 'nhp_opts', array('reset_confirm' => __('Are you sure? Resetting will loose all custom values.', 'nhp-opts'), 'opt_name' => $this->args['opt_name']));
  206. do_action('nhp-opts-enqueue-' . $this->args['opt_name']);
  207. foreach ($this->sections as $k => $section) {
  208. if (isset($section['fields'])) {
  209. foreach ($section['fields'] as $fieldk => $field) {
  210. if (isset($field['type'])) {
  211. $field_class = 'NHP_Options_' . $field['type'];
  212. if (!class_exists($field_class)) {
  213. require_once($this->dir . 'fields/' . $field['type'] . '/field_' . $field['type'] . '.php');
  214. }
  215. //if
  216. if (class_exists($field_class) && method_exists($field_class, 'enqueue')) {
  217. $enqueue = new $field_class('', '', $this);
  218. $enqueue->enqueue();
  219. }
  220. //if
  221. }
  222. //if type
  223. }
  224. //foreach
  225. }
  226. //if fields
  227. }
  228. //foreach
  229. }
  230. //function
  231. /**
  232. * Download the options file, or display it
  233. *
  234. * @since NHP_Options 1.0.1
  235. */
  236. function _download_options() {
  237. //-'.$this->args['opt_name']
  238. if (!isset($_GET['secret']) || $_GET['secret'] != md5(AUTH_KEY . SECURE_AUTH_KEY)) {
  239. wp_die('Invalid Secret for options use');
  240. exit;
  241. }
  242. if (!isset($_GET['feed'])) {
  243. wp_die('No Feed Defined');
  244. exit;
  245. }
  246. $backup_options = get_option(str_replace('nhpopts-', '', $_GET['feed']));
  247. $backup_options['nhp-opts-backup'] = '1';
  248. $content = '###' . serialize($backup_options) . '###';
  249. if (isset($_GET['action']) && $_GET['action'] == 'download_options') {
  250. header('Content-Description: File Transfer');
  251. header('Content-type: application/txt');
  252. header('Content-Disposition: attachment; filename="' . str_replace('nhpopts-', '', $_GET['feed']) . '_options_' . date('d-m-Y') . '.txt"');
  253. header('Content-Transfer-Encoding: binary');
  254. header('Expires: 0');
  255. header('Cache-Control: must-revalidate');
  256. header('Pragma: public');
  257. echo $content;
  258. exit;
  259. } else {
  260. echo $content;
  261. exit;
  262. }
  263. }
  264. /**
  265. * show page help
  266. *
  267. * @since NHP_Options 1.0
  268. */
  269. function _load_page() {
  270. //do admin head action for this page
  271. add_action('admin_head', array(&$this, 'admin_head'));
  272. //do admin footer text hook
  273. add_filter('admin_footer_text', array(&$this, 'admin_footer_text'));
  274. $screen = get_current_screen();
  275. if (is_array($this->args['help_tabs'])) {
  276. foreach ($this->args['help_tabs'] as $tab) {
  277. $screen->add_help_tab($tab);
  278. }
  279. //foreach
  280. }
  281. //if
  282. if ($this->args['help_sidebar'] != '') {
  283. $screen->set_help_sidebar($this->args['help_sidebar']);
  284. }
  285. //if
  286. do_action('nhp-opts-load-page-' . $this->args['opt_name'], $screen);
  287. }
  288. //function
  289. /**
  290. * do action nhp-opts-admin-head for theme options page
  291. *
  292. * @since NHP_Options 1.0
  293. */
  294. function admin_head() {
  295. do_action('nhp-opts-admin-head-' . $this->args['opt_name'], $this);
  296. }
  297. //function
  298. function admin_footer_text($footer_text) {
  299. return $this->args['footer_credit'];
  300. }
  301. //function
  302. /**
  303. * Register Option for use
  304. *
  305. * @since NHP_Options 1.0
  306. */
  307. function _register_setting() {
  308. register_setting($this->args['opt_name'] . '_group', $this->args['opt_name'], array(&$this, '_validate_options'));
  309. foreach ($this->sections as $k => $section) {
  310. add_settings_section($k . '_section', $section['title'], array(&$this, '_section_desc'), $k . '_section_group');
  311. if (isset($section['fields'])) {
  312. foreach ($section['fields'] as $fieldk => $field) {
  313. if (isset($field['title'])) {
  314. $th = (isset($field['sub_desc'])) ? $field['title'] . '<span class="description">' . $field['sub_desc'] . '</span>' : $field['title'];
  315. } else {
  316. $th = '';
  317. }
  318. add_settings_field($fieldk . '_field', $th, array(&$this, '_field_input'), $k . '_section_group', $k . '_section', $field); // checkbox
  319. }
  320. //foreach
  321. }
  322. //if(isset($section['fields'])){
  323. }
  324. //foreach
  325. do_action('nhp-opts-register-settings-' . $this->args['opt_name']);
  326. }
  327. //function
  328. /**
  329. * Validate the Options options before insertion
  330. *
  331. * @since NHP_Options 1.0
  332. */
  333. function _validate_options($plugin_options) {
  334. set_transient('nhp-opts-saved', '1', 1000);
  335. if (!empty($plugin_options['import'])) {
  336. if ($plugin_options['import_code'] != '') {
  337. $import = $plugin_options['import_code'];
  338. } elseif ($plugin_options['import_link'] != '') {
  339. $import = wp_remote_retrieve_body(wp_remote_get($plugin_options['import_link']));
  340. }
  341. $imported_options = unserialize(trim($import, '###'));
  342. if (is_array($imported_options) && isset($imported_options['nhp-opts-backup']) && $imported_options['nhp-opts-backup'] == '1') {
  343. $imported_options['imported'] = 1;
  344. return $imported_options;
  345. }
  346. }
  347. if (!empty($plugin_options['defaults'])) {
  348. $plugin_options = $this->_default_values();
  349. return $plugin_options;
  350. }
  351. //if set defaults
  352. //validate fields (if needed)
  353. $plugin_options = $this->_validate_values($plugin_options, $this->options);
  354. if ($this->errors) {
  355. set_transient('nhp-opts-errors-' . $this->args['opt_name'], $this->errors, 1000);
  356. }
  357. //if errors
  358. if ($this->warnings) {
  359. set_transient('nhp-opts-warnings-' . $this->args['opt_name'], $this->warnings, 1000);
  360. }
  361. //if errors
  362. do_action('nhp-opts-options-validate-' . $this->args['opt_name'], $plugin_options, $this->options);
  363. unset($plugin_options['defaults']);
  364. unset($plugin_options['import']);
  365. unset($plugin_options['import_code']);
  366. unset($plugin_options['import_link']);
  367. return $plugin_options;
  368. }
  369. //function
  370. /**
  371. * Validate values from options form (used in settings api validate function)
  372. * calls the custom validation class for the field so authors can override with custom classes
  373. *
  374. * @since NHP_Options 1.0
  375. */
  376. function _validate_values($plugin_options, $options) {
  377. foreach ($this->sections as $k => $section) {
  378. if (isset($section['fields'])) {
  379. foreach ($section['fields'] as $fieldk => $field) {
  380. $field['section_id'] = $k;
  381. if (isset($field['type']) && $field['type'] == 'multi_text') {
  382. continue;
  383. } //we cant validate this yet
  384. if (!isset($plugin_options[$field['id']]) || $plugin_options[$field['id']] == '') {
  385. continue;
  386. }
  387. //force validate of custom filed types
  388. if (isset($field['type']) && !isset($field['validate'])) {
  389. if ($field['type'] == 'color' || $field['type'] == 'color_gradient') {
  390. $field['validate'] = 'color';
  391. } elseif ($field['type'] == 'date') {
  392. $field['validate'] = 'date';
  393. }
  394. }
  395. //if
  396. if (isset($field['validate'])) {
  397. $validate = 'NHP_Validation_' . $field['validate'];
  398. if (!class_exists($validate)) {
  399. require_once($this->dir . 'validation/' . $field['validate'] . '/validation_' . $field['validate'] . '.php');
  400. }
  401. //if
  402. if (class_exists($validate)) {
  403. $validation = new $validate($field, $plugin_options[$field['id']], $options[$field['id']]);
  404. $plugin_options[$field['id']] = $validation->value;
  405. if (isset($validation->error)) {
  406. $this->errors[] = $validation->error;
  407. }
  408. if (isset($validation->warning)) {
  409. $this->warnings[] = $validation->warning;
  410. }
  411. continue;
  412. }
  413. //if
  414. }
  415. //if
  416. if (isset($field['validate_callback']) && function_exists($field['validate_callback'])) {
  417. $callbackvalues = call_user_func($field['validate_callback'], $field, $plugin_options[$field['id']], $options[$field['id']]);
  418. $plugin_options[$field['id']] = $callbackvalues['value'];
  419. if (isset($callbackvalues['error'])) {
  420. $this->errors[] = $callbackvalues['error'];
  421. }
  422. //if
  423. if (isset($callbackvalues['warning'])) {
  424. $this->warnings[] = $callbackvalues['warning'];
  425. }
  426. //if
  427. }
  428. //if
  429. }
  430. //foreach
  431. }
  432. //if(isset($section['fields'])){
  433. }
  434. //foreach
  435. return $plugin_options;
  436. }
  437. //function
  438. /**
  439. * HTML OUTPUT.
  440. *
  441. * @since NHP_Options 1.0
  442. */
  443. function _options_page_html() {
  444. echo '<div class="wrap">';
  445. echo '<div id="' . $this->args['page_icon'] . '" class="icon32"><br/></div>';
  446. echo '<h2 id="nhp-opts-heading">' . get_admin_page_title() . '</h2>';
  447. echo (isset($this->args['intro_text'])) ? $this->args['intro_text'] : '';
  448. do_action('nhp-opts-page-before-form-' . $this->args['opt_name']);
  449. echo '<form method="post" action="options.php" enctype="multipart/form-data" id="nhp-opts-form-wrapper">';
  450. settings_fields($this->args['opt_name'] . '_group');
  451. $this->options['last_tab'] = (isset($_GET['tab']) && !get_transient('nhp-opts-saved')) ? $_GET['tab'] : $this->options['last_tab'];
  452. echo '<input type="hidden" id="last_tab" name="' . $this->args['opt_name'] . '[last_tab]" value="' . $this->options['last_tab'] . '" />';
  453. echo '<div id="nhp-opts-header">';
  454. submit_button('', 'primary', '', false);
  455. submit_button(__('Reset to Defaults', 'nhp-opts'), 'secondary', $this->args['opt_name'] . '[defaults]', false);
  456. echo '<div class="clear"></div><!--clearfix-->';
  457. echo '</div>';
  458. if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-saved') == '1') {
  459. if (isset($this->options['imported']) && $this->options['imported'] == 1) {
  460. echo '<div id="nhp-opts-imported">' . apply_filters('nhp-opts-imported-text-' . $this->args['opt_name'], __('<strong>Settings Imported!</strong>', 'nhp-opts')) . '</div>';
  461. } else {
  462. echo '<div id="nhp-opts-save">' . apply_filters('nhp-opts-saved-text-' . $this->args['opt_name'], __('<strong>Settings Saved!</strong>', 'nhp-opts')) . '</div>';
  463. }
  464. delete_transient('nhp-opts-saved');
  465. }
  466. echo '<div id="nhp-opts-save-warn">' . apply_filters('nhp-opts-changed-text-' . $this->args['opt_name'], __('<strong>Settings have changed!, you should save them!</strong>', 'nhp-opts')) . '</div>';
  467. echo '<div id="nhp-opts-field-errors">' . __('<strong><span></span> error(s) were found!</strong>', 'nhp-opts') . '</div>';
  468. echo '<div id="nhp-opts-field-warnings">' . __('<strong><span></span> warning(s) were found!</strong>', 'nhp-opts') . '</div>';
  469. echo '<div class="clear"></div><!--clearfix-->';
  470. echo '<div id="nhp-opts-sidebar">';
  471. echo '<ul id="nhp-opts-group-menu">';
  472. foreach ($this->sections as $k => $section) {
  473. $icon = (!isset($section['icon'])) ? '<img src="' . $this->url . 'img/glyphicons/glyphicons_019_cogwheel.png" /> ' : '<img src="' . $section['icon'] . '" /> ';
  474. echo '<li id="' . $k . '_section_group_li" class="nhp-opts-group-tab-link-li">';
  475. echo '<a href="javascript:void(0);" id="' . $k . '_section_group_li_a" class="nhp-opts-group-tab-link-a" data-rel="' . $k . '">' . $icon . '<span>' . $section['title'] . '</span></a>';
  476. echo '</li>';
  477. }
  478. echo '<li class="divide">&nbsp;</li>';
  479. do_action('nhp-opts-after-section-menu-items-' . $this->args['opt_name'], $this);
  480. if (true === $this->args['show_import_export']) {
  481. echo '<li id="import_export_default_section_group_li" class="nhp-opts-group-tab-link-li">';
  482. echo '<a href="javascript:void(0);" id="import_export_default_section_group_li_a" class="nhp-opts-group-tab-link-a" data-rel="import_export_default"><img src="' . $this->url . 'img/glyphicons/glyphicons_082_roundabout.png" /> <span>' . __('Import / Export', 'nhp-opts') . '</span></a>';
  483. echo '</li>';
  484. echo '<li class="divide">&nbsp;</li>';
  485. }
  486. //if
  487. foreach ($this->extra_tabs as $k => $tab) {
  488. $icon = (!isset($tab['icon'])) ? '<img src="' . $this->url . 'img/glyphicons/glyphicons_019_cogwheel.png" /> ' : '<img src="' . $tab['icon'] . '" /> ';
  489. echo '<li id="' . $k . '_section_group_li" class="nhp-opts-group-tab-link-li">';
  490. echo '<a href="javascript:void(0);" id="' . $k . '_section_group_li_a" class="nhp-opts-group-tab-link-a custom-tab" data-rel="' . $k . '">' . $icon . '<span>' . $tab['title'] . '</span></a>';
  491. echo '</li>';
  492. }
  493. if (true === $this->args['dev_mode']) {
  494. echo '<li id="dev_mode_default_section_group_li" class="nhp-opts-group-tab-link-li">';
  495. echo '<a href="javascript:void(0);" id="dev_mode_default_section_group_li_a" class="nhp-opts-group-tab-link-a custom-tab" data-rel="dev_mode_default"><img src="' . $this->url . 'img/glyphicons/glyphicons_195_circle_info.png" /> <span>' . __('Dev Mode Info', 'nhp-opts') . '</span></a>';
  496. echo '</li>';
  497. }
  498. //if
  499. echo '</ul>';
  500. echo '</div>';
  501. echo '<div id="nhp-opts-main">';
  502. foreach ($this->sections as $k => $section) {
  503. echo '<div id="' . $k . '_section_group' . '" class="nhp-opts-group-tab">';
  504. do_settings_sections($k . '_section_group');
  505. echo '</div>';
  506. }
  507. if (true === $this->args['show_import_export']) {
  508. echo '<div id="import_export_default_section_group' . '" class="nhp-opts-group-tab">';
  509. echo '<h3>' . __('Import / Export Options', 'nhp-opts') . '</h3>';
  510. echo '<h4>' . __('Import Options', 'nhp-opts') . '</h4>';
  511. echo '<p><a href="javascript:void(0);" id="nhp-opts-import-code-button" class="button-secondary">Import from file</a> <a href="javascript:void(0);" id="nhp-opts-import-link-button" class="button-secondary">Import from URL</a></p>';
  512. echo '<div id="nhp-opts-import-code-wrapper">';
  513. echo '<div class="nhp-opts-section-desc">';
  514. echo '<p class="description" id="import-code-description">' . apply_filters('nhp-opts-import-file-description', __('Input your backup file below and hit Import to restore your sites options from a backup.', 'nhp-opts')) . '</p>';
  515. echo '</div>';
  516. echo '<textarea id="import-code-value" name="' . $this->args['opt_name'] . '[import_code]" class="large-text" rows="8"></textarea>';
  517. echo '</div>';
  518. echo '<div id="nhp-opts-import-link-wrapper">';
  519. echo '<div class="nhp-opts-section-desc">';
  520. echo '<p class="description" id="import-link-description">' . apply_filters('nhp-opts-import-link-description', __('Input the URL to another sites options set and hit Import to load the options from that site.', 'nhp-opts')) . '</p>';
  521. echo '</div>';
  522. echo '<input type="text" id="import-link-value" name="' . $this->args['opt_name'] . '[import_link]" class="large-text" value="" />';
  523. echo '</div>';
  524. echo '<p id="nhp-opts-import-action"><input type="submit" id="nhp-opts-import" name="' . $this->args['opt_name'] . '[import]" class="button-primary" value="' . __('Import', 'nhp-opts') . '"> <span>' . apply_filters('nhp-opts-import-warning', __('WARNING! This will overwrite any existing options, please proceed with caution!', 'nhp-opts')) . '</span></p>';
  525. echo '<div id="import_divide"></div>';
  526. echo '<h4>' . __('Export Options', 'nhp-opts') . '</h4>';
  527. echo '<div class="nhp-opts-section-desc">';
  528. echo '<p class="description">' . apply_filters('nhp-opts-backup-description', __('Here you can copy/download your themes current option settings. Keep this safe as you can use it as a backup should anything go wrong. Or you can use it to restore your settings on this site (or any other site). You also have the handy option to copy the link to yours sites settings. Which you can then use to duplicate on another site', 'nhp-opts')) . '</p>';
  529. echo '</div>';
  530. echo '<p><a href="javascript:void(0);" id="nhp-opts-export-code-copy" class="button-secondary">Copy</a> <a href="' . add_query_arg(array('feed' => 'nhpopts-' . $this->args['opt_name'], 'action' => 'download_options', 'secret' => md5(AUTH_KEY . SECURE_AUTH_KEY)), site_url()) . '" id="nhp-opts-export-code-dl" class="button-primary">Download</a> <a href="javascript:void(0);" id="nhp-opts-export-link" class="button-secondary">Copy Link</a></p>';
  531. $backup_options = $this->options;
  532. $backup_options['nhp-opts-backup'] = '1';
  533. $encoded_options = '###' . serialize($backup_options) . '###';
  534. echo '<textarea class="large-text" id="nhp-opts-export-code" rows="8">';
  535. print_r($encoded_options);
  536. echo '</textarea>';
  537. echo '<input type="text" class="large-text" id="nhp-opts-export-link-value" value="' . add_query_arg(array('feed' => 'nhpopts-' . $this->args['opt_name'], 'secret' => md5(AUTH_KEY . SECURE_AUTH_KEY)), site_url()) . '" />';
  538. echo '</div>';
  539. }
  540. foreach ($this->extra_tabs as $k => $tab) {
  541. echo '<div id="' . $k . '_section_group' . '" class="nhp-opts-group-tab">';
  542. echo '<h3>' . $tab['title'] . '</h3>';
  543. echo $tab['content'];
  544. echo '</div>';
  545. }
  546. if (true === $this->args['dev_mode']) {
  547. echo '<div id="dev_mode_default_section_group' . '" class="nhp-opts-group-tab">';
  548. echo '<h3>' . __('Dev Mode Info', 'nhp-opts') . '</h3>';
  549. echo '<div class="nhp-opts-section-desc">';
  550. echo '<textarea class="large-text" rows="24">' . print_r($this, true) . '</textarea>';
  551. echo '</div>';
  552. echo '</div>';
  553. }
  554. do_action('nhp-opts-after-section-items-' . $this->args['opt_name'], $this);
  555. echo '<div class="clear"></div><!--clearfix-->';
  556. echo '</div>';
  557. echo '<div class="clear"></div><!--clearfix-->';
  558. echo '<div id="nhp-opts-footer">';
  559. if (isset($this->args['share_icons'])) {
  560. echo '<div id="nhp-opts-share">';
  561. foreach ($this->args['share_icons'] as $link) {
  562. echo '<a href="' . $link['link'] . '" title="' . $link['title'] . '" target="_blank"><img src="' . $link['img'] . '"/></a>';
  563. }
  564. echo '</div>';
  565. }
  566. submit_button('', 'primary', '', false);
  567. submit_button(__('Reset to Defaults', 'nhp-opts'), 'secondary', $this->args['opt_name'] . '[defaults]', false);
  568. echo '<div class="clear"></div><!--clearfix-->';
  569. echo '</div>';
  570. echo '</form>';
  571. do_action('nhp-opts-page-after-form-' . $this->args['opt_name']);
  572. echo '<div class="clear"></div><!--clearfix-->';
  573. echo '</div><!--wrap-->';
  574. }
  575. //function
  576. /**
  577. * JS to display the errors on the page
  578. *
  579. * @since NHP_Options 1.0
  580. */
  581. function _errors_js() {
  582. if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-errors-' . $this->args['opt_name'])) {
  583. $errors = get_transient('nhp-opts-errors-' . $this->args['opt_name']);
  584. $section_errors = array();
  585. foreach ($errors as $error) {
  586. $section_errors[$error['section_id']] = (isset($section_errors[$error['section_id']])) ? $section_errors[$error['section_id']] : 0;
  587. $section_errors[$error['section_id']]++;
  588. }
  589. echo '<script type="text/javascript">';
  590. echo 'jQuery(document).ready(function(){';
  591. echo 'jQuery("#nhp-opts-field-errors span").html("' . count($errors) . '");';
  592. echo 'jQuery("#nhp-opts-field-errors").show();';
  593. foreach ($section_errors as $sectionkey => $section_error) {
  594. echo 'jQuery("#' . $sectionkey . '_section_group_li_a").append("<span class=\"nhp-opts-menu-error\">' . $section_error . '</span>");';
  595. }
  596. foreach ($errors as $error) {
  597. echo 'jQuery("#' . $error['id'] . '").addClass("nhp-opts-field-error");';
  598. echo 'jQuery("#' . $error['id'] . '").closest("td").append("<span class=\"nhp-opts-th-error\">' . $error['msg'] . '</span>");';
  599. }
  600. echo '});';
  601. echo '</script>';
  602. delete_transient('nhp-opts-errors-' . $this->args['opt_name']);
  603. }
  604. }
  605. //function
  606. /**
  607. * JS to display the warnings on the page
  608. *
  609. * @since NHP_Options 1.0.3
  610. */
  611. function _warnings_js() {
  612. if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-warnings-' . $this->args['opt_name'])) {
  613. $warnings = get_transient('nhp-opts-warnings-' . $this->args['opt_name']);
  614. $section_warnings = array();
  615. foreach ($warnings as $warning) {
  616. $section_warnings[$warning['section_id']] = (isset($section_warnings[$warning['section_id']])) ? $section_warnings[$warning['section_id']] : 0;
  617. $section_warnings[$warning['section_id']]++;
  618. }
  619. echo '<script type="text/javascript">';
  620. echo 'jQuery(document).ready(function(){';
  621. echo 'jQuery("#nhp-opts-field-warnings span").html("' . count($warnings) . '");';
  622. echo 'jQuery("#nhp-opts-field-warnings").show();';
  623. foreach ($section_warnings as $sectionkey => $section_warning) {
  624. echo 'jQuery("#' . $sectionkey . '_section_group_li_a").append("<span class=\"nhp-opts-menu-warning\">' . $section_warning . '</span>");';
  625. }
  626. foreach ($warnings as $warning) {
  627. echo 'jQuery("#' . $warning['id'] . '").addClass("nhp-opts-field-warning");';
  628. echo 'jQuery("#' . $warning['id'] . '").closest("td").append("<span class=\"nhp-opts-th-warning\">' . $warning['msg'] . '</span>");';
  629. }
  630. echo '});';
  631. echo '</script>';
  632. delete_transient('nhp-opts-warnings-' . $this->args['opt_name']);
  633. }
  634. }
  635. //function
  636. /**
  637. * Section HTML OUTPUT.
  638. *
  639. * @since NHP_Options 1.0
  640. */
  641. function _section_desc($section) {
  642. $id = rtrim($section['id'], '_section');
  643. if (isset($this->sections[$id]['desc']) && !empty($this->sections[$id]['desc'])) {
  644. echo '<div class="nhp-opts-section-desc">' . $this->sections[$id]['desc'] . '</div>';
  645. }
  646. }
  647. //function
  648. /**
  649. * Field HTML OUTPUT.
  650. *
  651. * Gets option from options array, then calls the speicfic field type class - allows extending by other devs
  652. *
  653. * @since NHP_Options 1.0
  654. */
  655. function _field_input($field) {
  656. if (isset($field['callback']) && function_exists($field['callback'])) {
  657. $value = (isset($this->options[$field['id']])) ? $this->options[$field['id']] : '';
  658. do_action('nhp-opts-before-field-' . $this->args['opt_name'], $field, $value);
  659. call_user_func($field['callback'], $field, $value);
  660. do_action('nhp-opts-after-field-' . $this->args['opt_name'], $field, $value);
  661. return;
  662. }
  663. if (isset($field['type'])) {
  664. $field_class = 'NHP_Options_' . $field['type'];
  665. if (class_exists($field_class)) {
  666. require_once($this->dir . 'fields/' . $field['type'] . '/field_' . $field['type'] . '.php');
  667. }
  668. //if
  669. if (class_exists($field_class)) {
  670. $value = (isset($this->options[$field['id']])) ? $this->options[$field['id']] : '';
  671. do_action('nhp-opts-before-field-' . $this->args['opt_name'], $field, $value);
  672. $render = '';
  673. $render = new $field_class($field, $value, $this);
  674. $render->render();
  675. do_action('nhp-opts-after-field-' . $this->args['opt_name'], $field, $value);
  676. }
  677. //if
  678. }
  679. //if $field['type']
  680. }
  681. //function
  682. }
  683. //class
  684. }//if
  685. ?>