settings ); // No need to initialize options since defaults are applied as needed return ( NULL!==$options[$option_string] ? $options[$option_string] : $this->set_default_option( $options, $option_string ) ); } /** * Simple function to array of all option settings * * @ Since 1.2.0 */ function get_all_options(){ $options = get_option( $this->settings ); $defaults = $this->option_defaults(); foreach( $defaults as $option_string => $details ){ if( NULL === $options[$option_string] && !empty($default_options[$option_string]['default']) ){ $options[$option_string] = $default_options[$option_string]['default']; } } //update_option( $this->settings, $options ); Unnecessary since options will soon be updated if this fuction was called return $options; } /** * Correctly set and save the option's default setting * * @ Since 1.2.0 */ function set_default_option( $options, $option_string ){ $default_options = $this->option_defaults(); if( NULL !== $default_options[$option_string] ){ $options[$option_string] = $default_options[$option_string]['default']; update_option( $this->settings, $options ); return $options[$option_string]; }else{ return NULL; } } /** * Create array of option names for a given tab * * @ Since 1.2.0 */ function get_options_by_tab( $tab = 'generator' ){ $default_options = $this->option_defaults(); $return = array(); foreach($default_options as $key => $val){ if( $val['tab'] == $tab ){ $return[$key] = $key; } } return $return; } /** * Create array of option names and current values for a given tab * * @ Since 1.2.0 */ function get_settings_by_tab( $tab = 'generator' ){ $current = $this->get_all_options(); $default_options = $this->option_defaults(); $return = array(); foreach($default_options as $key => $val){ if( $val['tab'] == $tab ){ $return[$key] = $current[$key]; } } return $return; } /** * Create array of positions for a given tab along with a list of settings for each position * * @ Since 1.2.0 * @ Updated 1.2.3 */ function get_option_positions_by_tab( $tab = 'generator' ){ $positions = $this->option_positions(); $return = array(); if( NULL !== $positions[$tab] ){ $options = $this->get_options_by_tab( $tab ); $defaults = $this->option_defaults(); foreach($positions[$tab] as $pos => $info ){ $return[$pos]['title'] = $info['title']; $return[$pos]['description'] = $info['description']; $return[$pos]['options'] = array(); } foreach($options as $name){ $pos = $defaults[$name]['position']; $return[ $pos ]['options'][] = $name; } } return $return; } /** * Create array of positions for each widget along with a list of settings for each position * * @ Since 1.2.0 */ function get_widget_options_by_position(){ $default_options = $this->option_defaults(); $positions = $this->widget_positions(); $return = array(); foreach($positions as $key => $val ){ $return[$key]['title'] = $val; $return[$key]['options'] = array(); } foreach($default_options as $key => $val){ if($val['widget']){ $return[ $val['position'] ]['options'][] = $key; } } return $return; } /** * Register styles and scripts * * @ Since 1.2.3 * */ function register_style_and_script(){ wp_register_script($this->wjs,$this->url.'/js/'.$this->wjs.'.js','',$this->ver); wp_register_style($this->wcss,$this->url.'/css/'.$this->wcss.'.css','',$this->ver); $lightbox = $this->get_option('general_lightbox'); $prevent = $this->get_option('general_lightbox_no_load'); if( 'fancybox' == $lightbox && !$prevent ){ wp_register_script( 'fancybox', $this->url.'/js/fancybox/jquery.fancybox-1.3.4.pack.js', '', '1.3.4', true ); wp_register_style( 'fancybox-stylesheet', $this->url . '/js/fancybox/jquery.fancybox-1.3.4.css', false, '1.3.4', 'screen' ); }elseif( 'prettyphoto' == $lightbox && !$prevent ){ wp_register_script( 'prettyphoto', $this->url.'/js/prettyphoto/js/jquery.prettyPhoto.js', '', '3.1.4', true ); wp_register_style( 'prettyphoto-stylesheet', $this->url . '/js/prettyphoto/css/prettyPhoto.css', false, '3.1.4', 'screen' ); }elseif( 'colorbox' == $lightbox && !$prevent ){ wp_register_script( 'colorbox', $this->url.'/js/colorbox/jquery.colorbox-min.js', '', '1.3.21', true ); wp_register_style( 'colorbox-stylesheet', $this->url . '/js/colorbox/colorbox.css', false, '3.1.4', 'screen' ); }elseif( 'alpine-fancybox' == $lightbox ){ wp_register_script( 'fancybox-alpine', $this->url.'/js/fancybox-alpine-safemode/jquery.fancyboxForAlpine-1.3.4.pack.js', '', '1.3.4', true ); wp_register_style( 'fancybox-alpine-stylesheet', $this->url . '/js/fancybox-alpine-safemode/jquery.fancyboxForAlpine-1.3.4.css', false, '1.3.4', 'screen' ); } // Enable loading the styles and scripts in the header $headerload = $this->get_option('general_load_header'); if( $headerload ){ if( 'fancybox' == $lightbox && !$prevent ){ wp_enqueue_script( 'fancybox' ); wp_enqueue_style( 'fancybox-stylesheet'); }elseif( 'prettyphoto' == $lightbox && !$prevent ){ wp_enqueue_script( 'prettyphoto' ); wp_enqueue_style( 'prettyphoto-stylesheet'); }elseif( 'colorbox' == $lightbox && !$prevent ){ wp_enqueue_script( 'colorbox' ); wp_enqueue_style( 'colorbox-stylesheet' ); }elseif( 'alpine-fancybox' == $lightbox ){ wp_enqueue_script( 'fancybox-alpine' ); wp_enqueue_style( 'fancybox-alpine-stylesheet' ); } wp_enqueue_style($this->wcss); wp_enqueue_script($this->wjs); } } /** * Enqueue styles and scripts * * @ Since 1.2.3 * */ function enqueue_style_and_script(){ $headerload = $this->get_option('general_load_header'); if( !$headerload ){ // Change web source if( $this->options['flickr_image_link_option'] == "fancybox" ){ $lightbox = $this->get_option('general_lightbox'); $prevent = $this->get_option('general_lightbox_no_load'); if( 'fancybox' == $lightbox && !$prevent ){ wp_enqueue_script( 'fancybox' ); wp_enqueue_style( 'fancybox-stylesheet'); }elseif( 'prettyphoto' == $lightbox && !$prevent ){ wp_enqueue_script( 'prettyphoto' ); wp_enqueue_style( 'prettyphoto-stylesheet'); }elseif( 'colorbox' == $lightbox && !$prevent ){ wp_enqueue_script( 'colorbox' ); wp_enqueue_style( 'colorbox-stylesheet' ); }elseif( 'alpine-fancybox' == $lightbox ){ wp_enqueue_script( 'fancybox-alpine' ); wp_enqueue_style( 'fancybox-alpine-stylesheet' ); } } wp_enqueue_style($this->wcss); wp_enqueue_script($this->wjs); } } /** * Options Simple Update for Admin Page * * @since 1.2.0 * */ function SimpleUpdate( $currenttab, $newoptions, $oldoptions ){ $options = $this->option_defaults(); $bytab = $this->get_options_by_tab( $currenttab ); foreach( $bytab as $id){ $oldoptions[$id] = $this->MenuOptionsValidate( $newoptions[$id],$oldoptions[$id],$options[$id] ); } update_option( $this->settings, $oldoptions); return $oldoptions; } /** * Function for displaying forms in the widget page * * @since 1.0.0 * */ function MenuDisplayCallback($options,$option,$fieldname,$fieldid){ $default = $option['default']; $optionname = $option['name']; $optiontitle = $option['title']; $optiondescription = $option['description']; $fieldtype = $option['type']; $value = ( Null !== $options[$optionname] ? $options[$optionname] : $default ); // Output checkbox form field markup if ( 'checkbox' == $fieldtype ) { ?> /> value="" />

/> value="" />

=$optiondetails['min'] && $newinput<=$optiondetails['max']) ? $newinput : $valid_input ); } // Validate text input and textarea fields else if ( ( 'text' == $optiondetails['type'] || 'textarea' == $optiondetails['type'] || 'image-upload' == $optiondetails['type']) ) { $valid_input = strip_tags( $newinput ); // Validate no-HTML content // nospaces option offers additional filters if ( 'nospaces' == $optiondetails['sanitize'] ) { // Pass input data through the wp_filter_nohtml_kses filter $valid_input = wp_filter_nohtml_kses( $newinput ); // Remove specified character(s) if(Null !== $optiondetails['remove']){ if( is_array($optiondetails['remove']) ){ foreach( $optiondetails['remove'] as $remove ){ $valid_input = str_replace($remove,'',$valid_input); } }else{ $valid_input = str_replace($optiondetails['remove'],'',$valid_input); } } // Switch or encode characters if( is_array( $optiondetails['encode'] ) ){ foreach( $optiondetails['encode'] as $find=>$replace ){ $valid_input = str_replace($find,$replace,$valid_input); } } // Replace spaces with provided character or just remove spaces if(Null !== $optiondetails['replace']){ $valid_input = str_replace(array(' ',' '),$optiondetails['replace'],$valid_input); }else{ $valid_input = str_replace(' ','',$valid_input); } } // Check if numeric if ( 'numeric' == $optiondetails['sanitize'] && is_numeric( wp_filter_nohtml_kses( $newinput ) ) ) { // Pass input data through the wp_filter_nohtml_kses filter $valid_input = wp_filter_nohtml_kses( $newinput ); if( NULL !== $optiondetails['min'] && $valid_input<$optiondetails['min']){ $valid_input = $optiondetails['min']; } if( NULL !== $optiondetails['max'] && $valid_input>$optiondetails['max']){ $valid_input = $optiondetails['max']; } } if ( 'int' == $optiondetails['sanitize'] && is_numeric( wp_filter_nohtml_kses( $newinput ) ) ) { // Pass input data through the wp_filter_nohtml_kses filter $valid_input = round( wp_filter_nohtml_kses( $newinput ) ); if( NULL !== $optiondetails['min'] && $valid_input<$optiondetails['min']){ $valid_input = $optiondetails['min']; } if( NULL !== $optiondetails['max'] && $valid_input>$optiondetails['max']){ $valid_input = $optiondetails['max']; } } if ( 'tag' == $optiondetails['sanitize'] ) { // Pass input data through the wp_filter_nohtml_kses filter $valid_input = wp_filter_nohtml_kses( $newinput ); $valid_input = str_replace(' ','-',$valid_input); } // Validate no-HTML content if ( 'nohtml' == $optiondetails['sanitize'] ) { // Pass input data through the wp_filter_nohtml_kses filter $valid_input = wp_filter_nohtml_kses( $newinput ); $valid_input = str_replace(' ','',$valid_input); } // Validate HTML content if ( 'html' == $optiondetails['sanitize'] ) { // Pass input data through the wp_filter_kses filter using allowed post tags $valid_input = wp_kses_post($newinput ); } // Validate URL address if( 'url' == $optiondetails['sanitize'] ){ $valid_input = esc_url( $newinput ); } // Validate URL address if( 'css' == $optiondetails['sanitize'] ){ $valid_input = wp_htmledit_pre( stripslashes( $newinput ) ); } }else if( 'wp-textarea' == $optiondetails['type'] ){ // Text area filter $valid_input = wp_kses_post( force_balance_tags($newinput) ); } elseif( 'color' == $optiondetails['type'] ){ $value = wp_filter_nohtml_kses( $newinput ); if( '#' == $value ){ $valid_input = ''; }else{ $valid_input = $value; } } return $valid_input; } /** * Get current settings page tab * * @since 1.2.0 * */ function get_current_tab( $current = 'general' ) { if ( isset ( $_GET['tab'] ) ) : $current = $_GET['tab']; else: $current = 'general'; endif; return $current; } /** * Create shortcode based on given options * * @since 1.1.0 * */ function generate_shortcode( $options, $optiondetails ){ $short = '['.$this->short; $trigger = ''; foreach( $options as $key=>$value ){ if($value && $optiondetails[$key]['short']){ if( $optiondetails[$key]['child'] && $optiondetails[$key]['hidden'] ){ $hidden = @explode(' ',$optiondetails[$key]['hidden']); if( !in_array( $options[ $optiondetails[$key]['child'] ] ,$hidden) ){ $short .= ' '.$optiondetails[$key]['short'].'="'.$value.'"'; } }else{ $short .= ' '.$optiondetails[$key]['short'].'="'.$value.'"'; } } } $short .= ']'; return $short; } /** * Define Settings Page Tab Markup * * @since 1.1.0 * @link`http://www.onedesigns.com/tutorials/separate-multiple-theme-options-pages-using-tabs Daniel Tara * */ function admin_options_page_tabs( $current = 'general' ) { $tabs = $this->settings_page_tabs(); $links = array(); foreach( $tabs as $tab ) : $tabname = $tab['name']; $tabtitle = $tab['title']; if ( $tabname == $current ) : $links[] = "$tabtitle"; else : $links[] = "$tabtitle"; endif; endforeach; echo '

'.$this->name.'

'; echo '
'; } /** * Function for printing general settings page * * @since 1.2.0 * */ function display_general(){ ?>

name; _e(", a WordPress plugin by the Alpine Press.");?>

the Alpine PressWordPress.org.


plugins) ){ foreach($this->plugins as $each){ ?>



option_defaults(); $positions = $this->get_option_positions_by_tab( $currenttab ); if( 'generator' == $currenttab ) { echo '
'; if($short){ echo '
Now, copy (Crtl+C) and paste (Crtl+V) the following shortcode into a page or post.
'; echo '
'; } } if( count($positions) ){ foreach( $positions as $position=>$positionsinfo){ echo '
'; if( $positionsinfo['title'] ){ echo '

'. $positionsinfo['title'].'

'; } if( $positionsinfo['description'] ){ echo '
'. $positionsinfo['description'].'
'; } echo ''; echo ''; if( count($positionsinfo['options']) ){ foreach( $positionsinfo['options'] as $optionname ){ $option = $defaults[$optionname]; $fieldname = ( $option['name'] ); $fieldid = ( $option['name'] ); if( $option['hidden-option'] && $option['check'] ){ $show = $this->get_option( $option['check'] ); if( !$show ){ continue; } } if($option['parent']){ $class = $option['parent']; }elseif($option['child']){ $class =($option['child']); }else{ $class = ('unlinked'); } $trigger = ($option['trigger']?('data-trigger="'.(($option['trigger'])).'"'):''); $hidden = ($option['hidden']?' '.$option['hidden']:''); if( 'generator' == $currenttab ){ echo ''; }else{ echo ''; } } } echo ''; echo '
'; $this->MenuDisplayCallback($options,$option,$fieldname,$fieldid); echo '
'; $this->AdminDisplayCallback($options,$option,$fieldname,$fieldid); echo '
'; echo '
'; } } echo ''; if( 'generator' == $currenttab ) { echo ''; }elseif( 'plugin-settings' == $currenttab ){ echo ''; echo ''; } } /** * Functions for caching results and clearing cache * * @since 1.1.0 * */ public function setCacheDir($val) { $this->cacheDir = $val; } public function setExpiryInterval($val) { $this->expiryInterval = $val; } public function getExpiryInterval($val) { return (int)$this->expiryInterval; } public function cacheExists($key) { $filename_cache = $this->cacheDir . '/' . $key . '.cache'; //Cache filename $filename_info = $this->cacheDir . '/' . $key . '.info'; //Cache info if (file_exists($filename_cache) && file_exists($filename_info)) { $cache_time = file_get_contents ($filename_info) + (int)$this->expiryInterval; //Last update time of the cache file $time = time(); //Current Time $expiry_time = (int)$time; //Expiry time for the cache if ((int)$cache_time >= (int)$expiry_time) {//Compare last updated and current time return true; } } return false; } public function getCache($key) { $filename_cache = $this->cacheDir . '/' . $key . '.cache'; //Cache filename $filename_info = $this->cacheDir . '/' . $key . '.info'; //Cache info if (file_exists($filename_cache) && file_exists($filename_info)) { $cache_time = file_get_contents ($filename_info) + (int)$this->expiryInterval; //Last update time of the cache file $time = time(); //Current Time $expiry_time = (int)$time; //Expiry time for the cache if ((int)$cache_time >= (int)$expiry_time){ //Compare last updated and current time return file_get_contents ($filename_cache); //Get contents from file } } return null; } public function putCache($key, $content) { $time = time(); //Current Time if ( ! file_exists($this->cacheDir) ){ @mkdir($this->cacheDir); $cleaning_info = $this->cacheDir . '/cleaning.info'; //Cache info @file_put_contents ($cleaning_info , $time); // save the time of last cache update } if ( file_exists($this->cacheDir) && is_dir($this->cacheDir) ){ $dir = $this->cacheDir . '/'; $filename_cache = $dir . $key . '.cache'; //Cache filename $filename_info = $dir . $key . '.info'; //Cache info @file_put_contents($filename_cache , $content); // save the content @file_put_contents($filename_info , $time); // save the time of last cache update } } public function clearAllCache() { $dir = $this->cacheDir . '/'; if(is_dir($dir)){ $opendir = @opendir($dir); while(false !== ($file = readdir($opendir))) { if($file != "." && $file != "..") { if(file_exists($dir.$file)) { $file_array = @explode('.',$file); $file_type = @array_pop( $file_array ); // only remove cache or info files if( 'cache' == $file_type || 'info' == $file_type){ @chmod($dir.$file, 0777); @unlink($dir.$file); } } /*elseif(is_dir($dir.$file)) { @chmod($dir.$file, 0777); @chdir('.'); @destroy($dir.$file.'/'); @rmdir($dir.$file); }*/ } } @closedir($opendir); } } public function cleanCache() { $cleaning_info = $this->cacheDir . '/cleaning.info'; //Cache info if (file_exists($cleaning_info)) { $cache_time = file_get_contents ($cleaning_info) + (int)$this->cleaningInterval; //Last update time of the cache cleaning $time = time(); //Current Time $expiry_time = (int)$time; //Expiry time for the cache if ((int)$cache_time < (int)$expiry_time){ //Compare last updated and current time // Clean old files $dir = $this->cacheDir . '/'; if(is_dir($dir)){ $opendir = @opendir($dir); while(false !== ($file = readdir($opendir))) { if($file != "." && $file != "..") { if(is_dir($dir.$file)) { //@chmod($dir.$file, 0777); //@chdir('.'); //@destroy($dir.$file.'/'); //@rmdir($dir.$file); } elseif(file_exists($dir.$file)) { $file_array = @explode('.',$file); $file_type = @array_pop( $file_array ); $file_key = @implode( $file_array ); if( $file_type && $file_key && 'info' == $file_type){ $filename_cache = $dir . $file_key . '.cache'; //Cache filename $filename_info = $dir . $file_key . '.info'; //Cache info if (file_exists($filename_cache) && file_exists($filename_info)) { $cache_time = file_get_contents ($filename_info) + (int)$this->cleaningInterval; //Last update time of the cache file $expiry_time = (int)$time; //Expiry time for the cache if ((int)$cache_time < (int)$expiry_time) {//Compare last updated and current time @chmod($filename_cache, 0777); @unlink($filename_cache); @chmod($filename_info, 0777); @unlink($filename_info); } } } } } } @closedir($opendir); } @file_put_contents ($cleaning_info , $time); // save the time of last cache cleaning } } } ///////////////////////////////////////////////////////////// ///////// Source-specific functions below this line ///////// ///////////////////////////////////////////////////////////// /** * Alpine PhotoTile: Options Page * * @since 1.1.1 * */ function build_settings_page(){ $optiondetails = $this->option_defaults(); $currenttab = $this->get_current_tab(); echo '
'; $this->admin_options_page_tabs( $currenttab ); echo '
'; if( 'general' == $currenttab ){ $this->display_general(); }elseif( 'preview' == $currenttab ){ $this->display_preview(); }else{ $options = $this->get_all_options(); $settings_section = $this->id . '_' . $currenttab . '_tab'; $submitted = ( ( isset($_POST[ "hidden" ]) && ($_POST[ "hidden" ]=="Y") ) ? true : false ); if( $submitted ){ $options = $this->SimpleUpdate( $currenttab, $_POST, $options ); if( 'generator' == $currenttab ) { $short = $this->generate_shortcode( $options, $optiondetails ); } } echo '
'; if( $_POST[$this->settings.'_'.$currenttab]['submit-'.$currenttab] == 'Delete Current Cache' ){ $this->clearAllCache(); echo '
'.__("Cache Cleared").'
'; } elseif( $_POST[$this->settings.'_'.$currenttab]['submit-'.$currenttab] == 'Save Settings' ){ $this->clearAllCache(); echo '
'.__("Settings Saved").'
'; } echo '
'; echo ''; $this->display_options_form($options,$currenttab,$short); echo '
'; echo '
'; } echo '
'; // Close Container echo '
'; // Close wrap } } ?>