version, false ); } } } /** * Add a page to settings menu * */ function addMenu() { add_menu_page( __('AdFever', 'adfever'), __('AdFever', 'adfever'), 'manage_options', 'adfever-general', array (&$this, 'pageGeneral' ) , '' ); add_submenu_page( 'adfever-general', __('General', 'adfever'), __('General', 'adfever'), 'manage_options', 'adfever-general', array (&$this, 'pageGeneral' ) ); } /** * Pugin configuration * */ function pageGeneral() { $options = parent::getOptions( 'general' ); // Check update options if ( isset($_POST['submit-general-adfever']) ) { $this->saveOptions( $options ); $this->message = __('General settings updated with success !', 'adfever'); } $this->displayMessage(); $tpl = '

'.__('AdFever Settings', 'adfever').'

'.$this->displayOptionsTable( $options ).'

'; echo $tpl; } /*function pageComparator() { $options = parent::getOptions( 'comparator' ); // Check update options if ( isset($_POST['submit-comparator-adfever']) ) { $this->saveMultipleCategories(); $this->saveOptions( $options, false ); $this->saveHomeConfiguration(); $this->message = __('Comparator settings updated with success !', 'adfever'); } $this->displayMessage(); // Check AID $result = parent::isValidAid( true ); ?>

'.__('You must enter an valid AID before can customize the settings of Adfever.', 'adfever').'

'; } else { ?>

Url de votre comparateur :

displayOptionsTable( $options ); ?>

option_name ); $this->prefix = $current_options['prefix']; $wp_rewrite->flush_rules(); } */ /** * Return nice title for each tabs * * @param string $id * @param boolean $return_all * @return string|array */ function getTabTitle( $id = '', $return_all = false ) { $titles = array( 'account' => __('Account', 'adfever'), 'design' => __('Design', 'adfever'), 'uninstall' => __('Uninstall', 'adfever'), 'visitors' => __('Visitors', 'adfever'), 'categories' => __('Categories', 'adfever'), ); if ( $return_all == true ) { return $titles; } if ( isset($titles[$id]) ) { return $titles[$id]; } return $id; } /** * Build table HTML form options * * @param array $options */ function displayOptionsTable( $options = array() ) { ob_start(); $current_options = get_option( $this->option_name ); if( count($options) > 1 ) { echo '' . "\n"; } $i = 0; foreach ( (array) $options as $key => $sub_options ) { $i++; echo '
' . "\n"; if ( $i == 1 ) { $this->displaySidebar(); } echo '

'.$this->getTabTitle($key).'

' . "\n"; echo '' . "\n"; foreach ( (array) $sub_options as $key_option => $option ) { // Get values if ( isset($_POST[$key_option]) ) { // Take POST datas $value = stripslashes($_POST[$key_option]); } elseif ( isset($current_options[$key_option]) ) { // Take DB $value = stripslashes($current_options[$key_option]); } else { // Take default $value = stripslashes($option['default']); } echo '' . "\n"; if ( $option['type'] == 'text' ) { // Texts in form, one colunm echo '' . "\n"; continue; } elseif ( substr($option['type'], 0, 5) == 'title' ) { // Titles in form, one colunm $level_title = substr($option['type'], 6); echo '' . "\n"; continue; //} elseif ( $option['type'] == 'checkbox' ) { // No label here for checkbox // echo '' . "\n"; } else { echo '' . "\n"; } echo '' . "\n"; echo '' . "\n"; } echo '
'.$option['name'].'<'.$level_title.' class="sub-title">'.$option['name'].''.$option['name'].'' . "\n"; switch ( $option['type'] ) { case 'checkbox': echo '' . "\n"; break; case 'selectbox': echo '' . "\n"; break; case 'colorbox': echo ' ' . "\n"; break; case 'multiples_cat': $this->displayMultiCat( $key_option, $value ); break; case 'textbox': default : echo '' . "\n"; break; } if ( isset($option['description']) && !empty($option['description']) ) echo '
'.wp_specialchars($option['description']).''; echo '
' . "\n"; echo '
' . "\n"; } $content = ob_get_contents(); ob_end_clean(); return $content; } /** * Check POST data for update options in DB * * @param array $options */ function saveOptions( $options = array(), $delete_post = true ) { // Get current options $current_options = get_option( $this->option_name ); if ( $current_options == false ) $current_options = array(); // Save original options $original_options = $current_options; // Make loop on options array, skip text and another non option value foreach ( (array) $options as $sub_options ) { foreach ( (array) $sub_options as $key_option => $option ) { if ( !empty($option['check']) ) { $checks = explode(',', $option['check']); foreach( (array) $checks as $check ) { if ( $check == 'slug' ) { $_POST[$key_option] = sanitize_title( $_POST[$key_option] ); } } } if ( $option['type'] == 'text' || substr($option['type'], 0, 5) == 'title' ) { continue; } else { if ( isset($_POST[$key_option]) ) $current_options[ $key_option ] = trim ( stripslashes( $_POST[$key_option] ) ); elseif ( $option['type'] == 'checkbox' ) $current_options[ $key_option ] = '0'; } } } // If enable colors is uncheck, fix default value for all colors options, for shortcode if ( @$current_options[ 'enable_colors' ] == '0' ) { $options_to_reset = array( 'text', 'border-table', 'bg-header-table', 'text-header-table', 'bg-table', 'text-table' ); $default_options = parent::getOptions('banners'); foreach ( (array) $default_options as $sub_options ) { foreach ( (array) $sub_options as $key_option => $option ) { if ( in_array( $key_option, $options_to_reset ) ) { $current_options[ $key_option ] = $option['default']; } } } } // If enable colors is uncheck, fix default value for all colors options, for comparator if ( $current_options[ 'c-enable-colors' ] == '0' ) { $options_to_reset = array( 'c-enable-colors', 'c-title', 'c-text', 'c-price', 'c-links-navigation', 'c-border-best-price', 'c-border-table', 'c-bg-table', 'c-text-table', 'c-bg-header-table', 'c-text-header-table' ); $default_options = parent::getOptions('comparator'); foreach ( (array) $default_options as $sub_options ) { foreach ( (array) $sub_options as $key_option => $option ) { if ( in_array( $key_option, $options_to_reset ) ) { $current_options[ $key_option ] = $option['default']; } } } } // Save options in DB. update_option( $this->option_name, $current_options ); // Delete POST values if ($delete_post == true ) unset($_POST); // Test site AID $result = parent::isValidAid( false, true, true, $original_options['aid'] ); if ( $result !== true ) { $this->message = $result; $this->status = 'error'; $this->displayMessage(); } return true; } /** * Build HTML for siderbar block * */ function displaySidebar() { ?>

version, true ); wp_enqueue_style( 'jquery-colorpicker', ADFEVER_URL . '/lib/colorpicker/css/colorpicker.css', array(), '1.0.0', 'screen'); wp_enqueue_style( 'jquery-checkboxtree', ADFEVER_URL . '/lib/checkboxtree/css/checkboxtree.css', array(), '1.0.0', 'screen' ); wp_enqueue_style( 'jquery-ui-tabs-redmond', ADFEVER_URL . '/lib/jquery-ui-theme/redmond/jquery-ui-1.7.2.custom.css', array(), '1.0.0', 'screen'); wp_enqueue_style( 'adfever', ADFEVER_URL . '/inc/css/adfever.css', array(), $this->version, 'screen'); return true; } return false; } /** * Display WP alert * */ function displayMessage() { if ( $this->message != '') { $message = $this->message; $status = $this->status; $this->message = $this->status = ''; // Reset } if ( isset($message) && $message ) { $tpl = '

'.$message.'

'; echo $tpl; } } function initBox() { add_meta_box('nouveautes-div', __('AdFever', 'adfever'), array(&$this, 'blockAdfeverWrite'), 'post', 'normal', 'core'); } function blockAdfeverWrite( $post ) { echo '

ID, 'desactive_adfever', true)=='1')?'checked="checked"':'').' />

'; } function save( $id, $post = '' ) { if (isset($_POST['desactive_adfever'])) { update_post_meta( $id, 'desactive_adfever', 1 ); } else { update_post_meta( $id, 'desactive_adfever', 0 ); } } /** * Display categories for multiples choices. * * @param $key_option * @param $value * @return unknown_type */ function displayMultiCat( $key_option = '', $value ) { if ( empty($value) ) { $value = 'all'; } // Init Shopping class $current_options = get_option( $this->option_name ); $current_options['multiples_cat'] = ( isset($current_options['multiples_cat']) ? (array) $current_options['multiples_cat']: array()); $shop = new Shopping ( $current_options['aid'], ADFEVER_UUID ); // Get categories tree $categories = $shop->getCategories(); ?>
type="radio" name="" value="all" id="-all" /> type="radio" name="" value="sel" id="-sel" />
'.__('No category currently. Strange ! Perhaps your server can\'t call the AdFever server', 'adfever').'

'; } else { echo '' . "\n"; } ?>