/** * Options Page and Input Validation for WPG3-Modules * * Depends on WP-Settings Api * * {@source} * **/ public function wpg3_admin_init() { global $wp_rewrite; // MODULES register their options here $modules = array($this->get_module() ); if($this->is_enabled){ $xhttp = $this->get_module_instance('WPG3_Xhttp'); array_push($modules, $xhttp->admin_init() ); $template = $this->get_module_instance('WPG3_Template'); array_push($modules, $template->admin_init() ); /* $imagechoser = $this->get_module_instance('WPG3_Imagechoser'); array_push($modules, $imagechoser->admin_init() ); */ if ( $wp_rewrite->using_permalinks() ){ $gallerypage = $this->get_module_instance('WPG3_Rewrite'); array_push($modules, $gallerypage->admin_init() ); } } register_setting( 'wpg3_options_grp', // settings group 'wpg3_options', // settings array(&$this,'admin_validate_options') // fn to validate input ); $page = 'wpg3_options_page'; // load Settings API if (!function_exists('add_settings_section')){ require_once(ABSPATH.'wp-admin/includes/template.php'); } /* stores validation functions */ $this->validate_fields = array(); // setting Option sections and fields foreach( $modules as $module){ if ( $module ){ add_settings_section( $module['unique_name'], $module['title'], $module['function'], $page); if( isset($module['settings_fields']) ){ foreach($module['settings_fields'] as $field){ add_settings_field($field['field_id'], $field['field_title'], $field['field_display'], $page, $module['unique_name']); if( isset($field['field_validate']) )$this->validate_fields[ $field['field_id'] ] = $field['field_validate']; } } } } } /** * get a module instance, load if required * * {@source} * * @param string Classname * @return object instance **/ public function get_module_instance($module, $override_options = false){ $return = false; if (isset($this->modules[$module]) and !$override_options){ $return = $this->modules[$module]; }else{ if (! isset($this->modules[$module])) $this->__autoload( $module ); if ( $override_options){ $this->wpg3_options = $override_options; } $instance = new $module( $this->wpg3_options ); $this->modules[$module] = $instance; $return = $instance; } return $return; } /** * Create Options Page for WPG3 * @internal **/ public function admin_add_page() { add_options_page(__('WPG3 Settings'), __('WPG3'), 'manage_options', __('WPG3'), array(&$this,'admin_optins_page_fn') ); } /** * Echo Option Page * @internal **/ public function admin_optins_page_fn() { //echo "This is the admin_optins_page() "; echo "\n
\n"; echo '

'.__('WPG3 Settings')."

\n"; echo '
'."\n"; settings_fields('wpg3_options_grp'); // Group Name echo "\n"; do_settings_sections('wpg3_options_page'); echo "\n"; echo '

'."\n"; echo "
\n
\n"; } /** * Validate Option Fields * * @param array WP-secured Input from $_POST * @return array Input validated **/ public function admin_validate_options($input) { $wpg3_options = $this->wpg3_options; $validatable = array_intersect_key( $this->validate_fields, $input); foreach ($validatable as $field => $function){ $val = call_user_func ($function, $input[$field]); if( $val) $wpg3_options[$field] = $val; } return $wpg3_options; } /** * Every Module can provide its own Options or return "false" * **/ private function get_module(){ $main_mudule = array( // unique section ID 'unique_name' =>'main_options', // visible Section Title 'title' => __('Basic WPG3 Options'), // callback_fn displaying the Settings 'function' => array( $this , 'admin_options_section_display' ), // FIELDS 'settings_fields' => array( array( // unique ID 'field_id' => 'g3Url', // field TITLE text 'field_title' => __('Gallery3 Url'), // function CALLBACK, to display the input box 'field_display' => array( $this , 'admin_options_section_display_g3Url'), // function CALLBACK validate field 'field_validate' => array( $this , 'admin_options_section_validate_g3Url') ), array( // unique ID 'field_id' => 'g3Resize', // field TITLE text 'field_title' => __('Resize Options'), // function CALLBACK, to display the input box 'field_display' => array( $this , 'admin_options_section_display_g3Resize'), // function CALLBACK validate field 'field_validate' => array( $this , 'admin_options_section_validate_g3Resize') ) ) ); return $main_mudule; } /** * Section Header for Options Page * **/ public function admin_options_section_display() {?>

You must enable REST-Module in Gallery3 in Order to use WPG3.

wpg3_options; $field_id = 'g3Resize'; $val = isset($options[$field_id])? $options[$field_id] : array('max_thumb' => 100, 'max_resize' => 300) ; ?>

Gallery 2 offered custom Resizes. Gallery3 not yet.
You can chose which reize to use in WPG3 for the width parameter in WPGX-Tags
Note: The Numbered width paramater is available in the Template to adjust width by CSS.

px'."\n"; echo ''; echo ''."\n"; ?>
Max pixel width
to use Thumb
Max pixel width
to use Medium
pxFor higher width values
we use the Fullsize Image

According to this settings WPG3 will chose the 'thumb', 'resize' or 'full' G3-Image to be inserted for a width parameter

wpg3_options['g3Resize']) ? $this->wpg3_options['g3Resize'] : array('max_thumb' => 60, 'max_resize' => 500 ); if ( is_array($field_val)){ if ( intval( $field_val['max_thumb']) > 0 and intval( $field_val['max_resize'] ) > $field_val['max_thumb']){ $return['max_thumb'] = $field_val['max_thumb']; }else{ add_settings_error('g3Resize', 'settings_updated', __('The Thumb width must be lower than the Medium width @ g3Resize
You entered:
max_thumb = '.$field_val['max_thumb'].'px
max_resize = '.$field_val['max_resize'].'px')); } if ( intval( $field_val['max_resize']) > 0 and $field_val['max_resize'] > $return['max_thumb'] ){ $return['max_resize'] = $field_val['max_resize']; } } return $return; } /** * Options Page Output for "g3Url" * **/ public function admin_options_section_display_g3Url() { $field_id = 'g3Url'; $options = $this->wpg3_options; // we should use data of $this !! ?>

The Url of you Gallery3 installation e.g. http://wpg3.local/gallery3/index.php

is_enabled ? $enabled = ' style="color: red;" ': $enabled =''; echo ''."\n"; } /** * Validate field "restReqestKey" * * @todo validate g3Url against REST **/ public function admin_options_section_validate_g3Url($field_val) { $return = false; // validate input if ( preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $field_val)){ if( substr( $field_val, -1 ) === "/" ) $field_val = substr ( $field_val, 0 , -1 ); // unset REST API Key unset($this->wpg3_options['restReqestKey']); $return = $field_val; }else{ // create a nice Error including you field_id add_settings_error('g3Url', 'settings_updated', __('A valid Gallery3 Url is required @ g3Url
You entered: "'.$field_val.'"')); } return $return; } private function __autoload($class_name) { include 'wpg3_class_'.$class_name . '.php'; } /** * Get WPG3 Options * @return array wpg3_options **/ public function get_options() { return $this->wpg3_options; } /** * WPG3 enabled? * @return bool true/false **/ public function is_enabled($type){ $return = false; if (isset($this->wpg3_options[$type]) and $this->wpg3_options[$type] == "enabled") $return = true; return $return; } }// END class WPG3_Main add_action('init', array(&$wpg3, 'wpg3_init') ); add_action('admin_init', array(&$wpg3, 'wpg3_admin_init') ); /* Add options Page */ add_action('admin_menu', array(&$wpg3, 'admin_add_page') ); if($wpg3->is_enabled){ add_filter('the_content', array(&$wpg3, 'wpg3_content_callback') );