option_defaults();
$bytab = $this->admin_get_options_by_tab( $currenttab );
foreach( $bytab as $id){
$new = (isset($newoptions[$id])?$newoptions[$id]:'');
$old = (isset($oldoptions[$id])?$oldoptions[$id]:'');
$opt = (isset($options[$id])?$options[$id]:'');
$oldoptions[$id] = $this->MenuOptionsValidate( $new, $old, $opt ); // Make changes to existing options array
}
update_option( $this->get_private('settings'), $oldoptions);
return $oldoptions;
}
//////////////////////////////////////////////////////////////////////////////////////
////////////////////// Admin Option Functions //////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
/**
* Create array of option names for a given tab
*
* @ Since 1.2.0
*/
function admin_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 admin_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->admin_option_positions();
$return = array();
if( isset($positions[$tab]) ){
$options = $this->admin_get_options_by_tab( $tab );
$defaults = $this->option_defaults();
foreach($positions[$tab] as $pos => $info ){
$return[$pos]['title'] = (isset($info['title'])?$info['title']:'');
$return[$pos]['description'] = (isset($info['description'])?$info['description']:'');
$return[$pos]['options'] = array();
}
foreach($options as $name){
$pos = (isset($defaults[$name]['position'])?$defaults[$name]['position']:'none');
$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 admin_get_widget_options_by_position(){
$default_options = $this->option_defaults();
$positions = $this->admin_widget_positions();
$return = array();
foreach($positions as $key => $val ){
$return[$key]['title'] = $val;
$return[$key]['options'] = array();
}
foreach($default_options as $key => $val){
if(!empty($val['widget'])){
$return[ $val['position'] ]['options'][] = $key;
}
}
return $return;
}
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////// Admin Page Functions //////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
/**
* Create shortcode based on given options
*
* @ Since 1.1.0
* @ Update 1.2.5
*/
function admin_generate_shortcode( $options, $optiondetails ){
$short = '['.$this->get_private('short');
$trigger = '';
foreach( $options as $key=>$value ){
if($value && isset($optiondetails[$key]['short'])){
if( isset($optiondetails[$key]['child']) && isset($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->admin_settings_page_tabs();
$links = array();
foreach( $tabs as $tab ){
$tabname = $tab['name'];
$tabtitle = $tab['title'];
if( $tabname == $current ){
$links[] = ''.$tabtitle.' ';
}else{
$links[] = ''.$tabtitle.' ';
}
}
echo '
'.$this->get_private('name').' ';
echo '';
}
/**
* Function for printing general settings page
*
* @ Since 1.2.0
* @ Updated 1.2.4
*/
function admin_display_general(){
?>
get_private('name'); _e(", a WordPress plugin by the Alpine Press.");?>
check_private('termsofservice') ) {
echo ''.$this->get_private('termsofservice').'
';
}?>
the Alpine Press .
check_private('plugins') && is_array( $this->get_private('plugins') ) ){
foreach($this->get_private('plugins') as $each){
?>
Please support further development of this plugin with a small donation .
get_all_options();
$settings_section = $this->get_private('id'). '_' . $currenttab . '_tab';
$submitted = ( ( isset($_POST[ "hidden" ]) && ($_POST[ "hidden" ]=="Y") ) ? true : false );
if( $submitted ){
$options = $this->admin_simple_update( $currenttab, $_POST, $options );
}
$buttom = (isset($_POST[$this->get_private('settings').'_'.$currenttab]['submit-'.$currenttab])?$_POST[$this->get_private('settings').'_'.$currenttab]['submit-'.$currenttab]:'');
if( $buttom == 'Delete Current Cache' ){
$bot = new PhotoTileForFlickrBot();
$bot->clearAllCache();
echo ''.__("Cache Cleared").'
';
}
elseif( $buttom == 'Save Settings' ){
$bot = new PhotoTileForFlickrBot();
$bot->clearAllCache();
echo ''.__("Settings Saved").'
';
}
echo '';
}
/**
* Second function for printing options page
*
* @ Since 1.1.0
* @ Updated 1.2.5
*
*/
function admin_display_opt_form($options,$currenttab){
$defaults = $this->option_defaults();
$positions = $this->get_option_positions_by_tab( $currenttab );
$submitted = ( ( isset($_POST[ "hidden" ]) && ($_POST[ "hidden" ]=="Y") ) ? true : false );
if( 'generator' == $currenttab ) {
$preview = (isset($_POST[ $this->get_private('settings').'_preview']['submit-preview']) && $_POST[ $this->get_private('settings').'_preview']['submit-preview'] == 'Preview')?true:false;
if( $submitted && isset($_POST['shortcode']) && $preview ){
$short = str_replace('\"','"',$_POST['shortcode']);
}elseif( $submitted ){
$short = $this->admin_generate_shortcode( $_POST, $defaults );
}
?>
This tool allows you to create shortcodes for the Alpine PhotoTile plugin.
A shortcode is a line of text that tells WordPress how to load a plugin inside the content of a page or post. Rather than explaining how to put together a shortcode, this tool will create the shortcode for you.
';
echo do_shortcode($short);
echo '';
}
}
echo ' ';
}
if( !empty($positions) && count($positions) ){
foreach( $positions as $position=>$positionsinfo){
echo '';
if( !empty($positionsinfo['title']) ){ echo '
'. $positionsinfo['title'].' '; }
if( !empty($positionsinfo['description']) ){ echo '
'. $positionsinfo['description'].'
'; }
echo '
';
echo '
';
}
}
if( 'generator' == $currenttab ) {
echo ' ';
}elseif( 'plugin-settings' == $currenttab ){
echo ' ';
echo ' ';
}
}
//////////////////////////////////////////////////////////////////////////////////////
////////////////////// Menu Display Functions /////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
/**
* Function for displaying forms in the widget page
*
* @ Since 1.0.0
* @ Updated 1.2.5
*/
function MenuDisplayCallback($options,$option,$fieldname,$fieldid){
$default = (isset($option['default'])?$option['default']:'');
$optionname = (isset($option['name'])?$option['name']:'');
$optiontitle = (isset($option['title'])?$option['title']:'');
$optiondescription = (isset($option['description'])?$option['description']:'');
$fieldtype = (isset($option['type'])?$option['type']:'');
$value = ( isset($options[$optionname]) ? $options[$optionname] : $default );
// Output checkbox form field markup
if ( 'checkbox' == $fieldtype ) {
?>
/>
value="" />
value="" >
value="" >
/>
value="" />
value="" >
value="" >
=$min && $newinput<=$max) ? $newinput : $valid_input );
}
// Validate text input and textarea fields
else if ( ( 'text' == $type || 'textarea' == $type || 'image-upload' == $type) ) {
$valid_input = strip_tags( $newinput );
$sanatize = (isset($optiondetails['sanitize'])?$optiondetails['sanitize']:'');
// Validate no-HTML content
// nospaces option offers additional filters
if ( 'nospaces' == $sanatize ) {
// Pass input data through the wp_filter_nohtml_kses filter
$valid_input = wp_filter_nohtml_kses( $newinput );
// Remove specified character(s)
if( isset($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( isset($optiondetails['encode']) && 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( isset($optiondetails['replace']) ){
$valid_input = str_replace(array(' ',' '),$optiondetails['replace'],$valid_input);
}else{
$valid_input = str_replace(' ','',$valid_input);
}
}
// Check if numeric
if ( 'numeric' == $sanatize && 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( isset($optiondetails['min']) && $valid_input<$optiondetails['min']){
$valid_input = $optiondetails['min'];
}
if( isset($optiondetails['max']) && $valid_input>$optiondetails['max']){
$valid_input = $optiondetails['max'];
}
}
if ( 'int' == $sanatize && 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( isset($optiondetails['min']) && $valid_input<$optiondetails['min']){
$valid_input = $optiondetails['min'];
}
if( isset($optiondetails['max']) && $valid_input>$optiondetails['max']){
$valid_input = $optiondetails['max'];
}
}
if ( 'tag' == $sanatize ) {
// 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' == $sanatize ) {
// 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' == $sanatize ) {
// Pass input data through the wp_filter_kses filter using allowed post tags
$valid_input = wp_kses_post($newinput );
}
// Validate URL address
if( 'url' == $sanatize ){
$valid_input = esc_url( $newinput );
}
// Validate URL address
if( 'css' == $sanatize ){
$valid_input = wp_htmledit_pre( stripslashes( $newinput ) );
}
}else if( 'wp-textarea' == $type ){
// Text area filter
$valid_input = wp_kses_post( force_balance_tags($newinput) );
}
elseif( 'color' == $type ){
$value = wp_filter_nohtml_kses( $newinput );
if( '#' == $value ){
$valid_input = '';
}else{
$valid_input = $value;
}
}
return $valid_input;
}
}
/** ##############################################################################################################################################
* ##############################################################################################################################################
* ##############################################################################################################################################
* ##############################################################################################################################################
* ##############################################################################################################################################
* ##############################################################################################################################################
* ##############################################################################################################################################
* ##############################################################################################################################################
*
* AlpineBot
*
* ADMIN Functions
* Contains ONLY UNIQUE ADMIN functions
*
* ##########################################################################################
*/
class PhotoTileForFlickrAdmin extends PhotoTileForFlickrAdminSecondary{
//////////////////////////////////////////////////////////////////////////////////////
//////////////////// Unique Admin Functions ////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
/**
* Alpine PhotoTile: Options Page
*
* @ Since 1.1.1
* @ Updated 1.2.4
*/
function admin_build_settings_page(){
$currenttab = isset( $_GET['tab'] )?$_GET['tab']:'general';
echo '';
$this->admin_options_page_tabs( $currenttab );
echo '
';
echo '
';
if( 'general' == $currenttab ){
$this->admin_display_general();
}elseif( 'add' == $currenttab ){
$this->admin_display_add();
}else{
$this->admin_setup_options_form($currenttab);
}
echo '
';
echo '
';
$this->admin_donate_button();
echo '
'.__('Need Help? Visit ').'the Alpine Press '.__(' for more about this plugin.').'
';
echo '
';
echo '
'; // Close Container
echo '
'; // Close wrap
}
function admin_add_key($key){
$options = get_option( $this->get_private('settings') );
$options['api_key'] = $key;
update_option( $this->get_private('settings'), $options );
}
function admin_delete_key(){
$options = get_option( $this->get_private('settings') );
$options['api_key'] = 0;
update_option( $this->get_private('settings'), $options );
}
/**
* Display add page
*
* @ Since 1.2.3
*
*/
function admin_display_add(){
$currenttab = 'add';
$options = $this->get_all_options();
$settings_section = $this->get_private('id') . '_'.$currenttab.'_tab';
$submitted = ( ( isset($_POST[ "hidden" ]) && ($_POST[ "hidden" ]=="Y") ) ? true : false );
$success = false;
$errormessage = null;
$errortype = null;
// Check that key works
if($submitted && !empty( $_POST['api_key']) ) {
$key = $_POST['api_key'];
$request = 'http://api.flickr.com/services/rest/?method=flickr.test.echo&format=php_serial&api_key='.$key;
$response = wp_remote_get( $request );
if(!is_wp_error($response) && isset($response['response']['code']) && $response['response']['code'] < 400 && $response['response']['code'] >= 200) {
$echo = @unserialize($response['body']);
if( $key == $echo['api_key']['_content'] ){
$this->admin_add_key($key);
$success = true;
}elseif( $echo['stat'] == 'fail' ){
$errormessage = ' '.$echo['message'].' ';
$success = false;
}else{
$errormessage = 'API Key saved but not verified';
$this->admin_add_key($key);
$success = true;
}
}elseif( !is_wp_error($response) && isset($response['response']['code']) && $response['response']['code'] >= 400 ) {
$error = unserialize($response['body']);
$errormessage = $error->error;
}elseif( is_wp_error($response) ){
$errormessage = $response->get_error_message();
}
}elseif($submitted && isset($_POST[ $this->get_private('settings').'_add']['submit-add']) && $_POST[ $this->get_private('settings').'_add']['submit-add'] == 'Delete Your API Key'){
$this->admin_delete_key();
$delete = true;
}
if( !empty($success) ){
echo ' API key verified and saved.
';
}elseif( !empty($delete) ){
echo ' API key deleted.
';
}elseif( !empty($errormessage) ){
echo ' An error occured ('.$errormessage.').
';
}
$key = $this->get_option('api_key');
if( !empty($key) ){
echo 'Thank you for adding an API Key ';
echo '';
echo '';
echo '
';
}else{
$defaults = $this->option_defaults();
$positions = $this->get_option_positions_by_tab( $currenttab );
if( count($positions) ){
foreach( $positions as $position=>$positionsinfo){
echo '';
echo ' ';
echo '';
echo ' ';
echo '';
}
}
}
?>
:
(!!!)
get_private('info').'" target="_blank">let me know if these directions become outdated.');?>
http://www.flickr.com/services/apps/create/ .
get_private('name');?> WordPress plugin
A simple plugin to display images from Flickr on my WordPress website.