options = $options;
$this->pageinfo = $pageinfo;
$this->grouped = false;
$this->make_data_available();
// call method to create the sidebar menu items, if its not a child call it with higher priority
$priority = 10;
if(!$this->pageinfo['child']) $priority = 1;
add_action('admin_menu', array(&$this, 'add_admin_menu'), $priority);
if(isset($_GET['page']) && $_GET['page'] == $this->pageinfo['filename'])
{
add_action('admin_head', array(&$this, 'admin_head_addition'));
}
}
// add stylesheet and javascript to the options page
function admin_head_addition()
{
global $papyrus_option;
echo ' ';
echo '';
echo '';
wp_enqueue_script( 'common');
wp_enqueue_script( 'jquery-color' );
wp_print_scripts('editor');
if (function_exists('add_thickbox')) add_thickbox();
wp_print_scripts('media-upload');
wp_admin_css();
wp_enqueue_script('utils');
do_action('admin_print_styles-post-php');
do_action('admin_print_styles');
}
// function that creates the sidebar menus
function add_admin_menu()
{
global $papyrus_themename;
$top_level = $papyrus_themename." ".__("Options",'papyrus_wdl');
add_theme_page($top_level, $this->pageinfo['full_name'], 'edit_theme_options', $this->pageinfo['filename'], array(&$this, 'initialize'));
}
function make_data_available()
{
global $papyrus_option;
global $shortname;
// save basic values into $papyrus_options array, then overwrite it with retrieved options from database table if avaliable
// add widgets if necessary
foreach ($this->options as $option)
{
if(isset($option['type']) && $option['type'] == 'boxes')
{
$this->add_widget($option);
}
if(isset($option['std']) && $option['std'])
{
$papyrus_option_std[$this->pageinfo['optionname']][$option['id']] = $option['std'];
}
}
$this->saved_optionname = $shortname."_".$this->pageinfo['optionname'];
$papyrus_option[$this->pageinfo['optionname']] = get_option($this->saved_optionname);
$papyrus_option[$this->pageinfo['optionname']] = array_merge((array)$papyrus_option_std[$this->pageinfo['optionname']], (array)$papyrus_option[$this->pageinfo['optionname']]);
//htmlspecialchars decode the array for frontend use
$papyrus_option[$this->pageinfo['optionname']] = $this->htmlspecialchars_deep($papyrus_option[$this->pageinfo['optionname']]);
}
//decode the whole options array with a recursive function
function htmlspecialchars_deep($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8')
{
if (is_array($mixed) || is_object($mixed))
{
foreach($mixed as $key => $value)
{
$mixed[$key] = $this->htmlspecialchars_deep($value, $quote_style, $charset);
}
}
elseif (is_string($mixed))
{
$mixed = htmlspecialchars_decode($mixed, $quote_style);
}
return $mixed;
}
function initialize()
{
$this->get_save_options();
$this->display();
}
// display options page
function display()
{
echo '
';
echo '
';
echo '
'.$this->pageinfo['full_name'].' ';
echo '
';
}
function stripe()
{
if($this->grouped === false)
$this->table_bg_class = $this->table_bg_class == "" ? 'class="alternate"' : '';
}
function get_save_options()
{
$options = $newoptions = get_option($this->saved_optionname);
//reset update_option($saved_optionname, "");
if ( isset($_POST['Reset']) && $_POST['Reset']== 'Reset Changes' )
{
$newoptions = '';
}
if ( isset($_POST['Submit']) && $_POST['Submit']== 'Save Changes' )
{
echo '';
//update_option($saved_optionname, "");
foreach ($_POST as $key => $value)
{
$value = stripslashes($value);
$newoptions[$key] = htmlspecialchars($value, ENT_QUOTES,"UTF-8");
//multiple cat "final" builder
if (preg_match("/(\w+)(hidden)$/", $key, $result))
{
$loops = $newoptions[$key];
$newoptions[$key] = 0;
$final = $result[1].'final';
$newoptions[$final] = "";
for($i = 0; $i < $loops; $i++)
{
$name = $result[1].$i;
$newoptions[$name] = stripslashes($_POST[$name]);
if($newoptions[$name] != "")
{
$newoptions[$key]++;
$newoptions[$final] .= $newoptions[$name];
if($i+2 < $loops)
{
$newoptions[$final] .=", ";
}
}
}
$newoptions[$key]++;
}
if (preg_match("/^(matrix_)(page_)(\w+)(\d+)/", $key, $result))
{
$final_field_matrix = $result[1].$result[3].'final';
}
}
//matrix divider
if(isset($final_field_matrix))
unset($newoptions[$final_field_matrix]);
$save_matrix_count = 0;
foreach ($newoptions as $key => $value) //check all fields
{
if(isset($_POST['super_matrix_count']) && $save_matrix_count < $_POST['super_matrix_count']) // dont save fields that are to high
{
if (preg_match("/^(matrix_)(page_)(\w+)(\d+)/", $key, $result))
{
foreach ($newoptions as $key2 => $value2)
{
if (preg_match("/^(matrix_)(".$result[3].")(".$result[4].")_final/", $key2, $result2))
{
$newoptions[$final_field_matrix][$value] = $value2;
$save_matrix_count++;
}
}
}
}
}
}
if ( $options != $newoptions )
{
$options = $newoptions;
update_option($this->saved_optionname, $options);
}
if($options)
{
foreach ($options as $key => $value)
{
$options[$key] = empty($options[$key]) ? false : $options[$key];
}
}
$this->database_options = $options;
}
function add_widget($values)
{
for ($i = 1; $i <= $values['count']; $i++)
{
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => $values['widget'].' '.$i,
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
));
}
}
############################################################################################################################
# Displaying NEW helper functions:
############################################################################################################################
function sliderouteropen($values)
{
global $papyrus_option;
echo '
';
}
function sliderouterclose($values)
{
echo '
';
}
function sliderpanelopen($values)
{
echo '
'.$values['name'].'
';
}
function sliderpanelclose($values)
{
echo '
';
}
function newtext($values)
{
if(isset($this->database_options[$values['id']])) $values['std'] = $this->database_options[$values['id']];
echo ' ';
}
function newtexttwo($values)
{
if(isset($this->database_options[$values['id']])) $values['std'] = $this->database_options[$values['id']];
echo ' ';
}
function newtextarea($values)
{
if(isset($this->database_options[$values['id']])) $values['std'] = $this->database_options[$values['id']];
echo '
'.$values['name'].'
';
echo ' ';
echo '
'.$values['desc'].'
';
}
function newradio($values)
{
echo ' ';
}
function ads125($values)
{
global $papyrus_option;
$count = $papyrus_option['main']['number_125_ads'];
if($count>0)
{
for($i=1; $i<=$count; $i++)
{
echo ' ';
}
}
else
{
?>Go to General Page and setup count of banners.
';
echo ''.$values['desc'].' ';
}
##############################################################
# CLOSE
##############################################################
function close($values)
{
echo ' ';
}
##############################################################
# GROUP
##############################################################
function group($values)
{
if($this->grouped === false)
{
$this->grouped = $this->table_bg_class;
if($this->grouped === "" )
{
$this->table_bg_class = 'class="grouped"';
}
else
{
$this->table_bg_class = 'class="alternate grouped"';
}
}
else
{
$this->table_bg_class = $this->table_bg_class == "" ? 'class="alternate"' : '';
echo 'grouped.'>';
echo ' ';
$this->grouped = false;
}
}
##############################################################
# TITLE
##############################################################
function title($values)
{
echo ''.$values['name'].' ';
if (isset($values['desc'])) echo ''.$values['desc'].'
';
}
##############################################################
# TITLE_INSIDE
##############################################################
function title_inside($values)
{
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
if (isset($values['desc'])) echo ''.$values['desc'].'
';
if (isset($values['id']) && $values['id']) echo ' ';
echo ' ';
}
##############################################################
# TEXTAREA
##############################################################
function textarea($values)
{
if(isset($this->database_options[$values['id']])) $values['std'] = $this->database_options[$values['id']];
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
echo ''.$values['desc'].' ';
echo ' ';
echo ' ';
echo ' ';
}
##############################################################
# WYSIWYG
##############################################################
function wysiwyg($values)
{
if(isset($this->database_options[$values['id']])) $values['std'] = $this->database_options[$values['id']];
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
echo ''.$values['desc'].' ';
?> ';
do_action( 'media_buttons' );
echo '';
echo '";
echo ' ';
echo ' ';
}
##############################################################
# TEXT
##############################################################
function text($values)
{
if(isset($this->database_options[$values['id']])) $values['std'] = $this->database_options[$values['id']];
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
echo ''.$values['desc'].' ';
if(!isset($values['size']))
$values['size'] = 20;
echo ' ';
echo ' ';
echo ' ';
}
##############################################################
# CHECKBOX
##############################################################
function checkbox($values)
{
if(isset($this->database_options[$values['id']]) && $this->database_options[$values['id']] == true) $checked = 'checked = "checked"';
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
echo ' ';
echo ''.$values['desc'].' ';
echo ' ';
echo ' ';
}
##############################################################
# RADIO
##############################################################
function radio($values)
{
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
echo ''.$values['desc'].' ';
$counter = 1;
foreach($values['buttons'] as $radiobutton)
{
$checked ="";
if(isset($this->database_options[$values['id']]))
{
if($this->database_options[$values['id']] == $counter)
{
$checked = 'checked = "checked"';
}
}
else if(isset($values['std']) && $values['std'] == $counter)
{
$checked = 'checked = "checked"';
}
echo ' ';
echo ''.$radiobutton.'
';
$counter++;
}
echo ' ';
echo ' ';
}
##############################################################
# DROPDOWN
##############################################################
function dropdown($values)
{
if(!isset($this->database_options[$values['id']]) && isset($values['std'])) $this->database_options[$values['id']] = $values['std'];
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
echo ''.$values['desc'].' ';
if($values['subtype'] == 'page')
{
$select = 'Select page';
$entries = get_pages('title_li=&orderby=name');
}
else if($values['subtype'] == 'cat')
{
$select = 'Select category';
$entries = get_categories('title_li=&orderby=name&hide_empty=0');
}
else
{
$select = 'Select...';
$entries = $values['subtype'];
}
echo ' ';
echo ''.$select .' ';
foreach ($entries as $key => $entry)
{
if($values['subtype'] == 'page')
{
$id = $entry->ID;
if($entry->post_parent==0)
$title = $entry->post_title;
else
$title = get_the_title($entry->post_parent).': '.$entry->post_title;
}
else if($values['subtype'] == 'cat')
{
$id = $entry->term_id;
if($entry->parent==0)
$title = $entry->name;
else
$title = get_cat_name($entry->parent).': '.$entry->name;
}
else
{
$id = $entry;
$title = $key;
}
if ($this->database_options[$values['id']] == $id )
{
$selected = "selected='selected'";
}
else
{
$selected = "";
}
echo"". $title." ";
}
echo ' ';
echo ' ';
echo ' ';
}
##############################################################
# MULTI
##############################################################
function multi($values)
{
echo 'table_bg_class.'>';
echo ''.$values['name'].' ';
echo ''.$values['desc'].' ';
///////////////////
echo '';
$hidden_name = $values['id'].'_hidden';
if($this->database_options[$hidden_name] == "" || $this->database_options[$hidden_name] == false)
{
$this->database_options[$hidden_name] = 1;
}
for($i = 0; $i < $this->database_options[$hidden_name]; $i++)
{
if($values['subtype'] == 'page')
{
$select = 'Select additional page?';
$entries = get_pages('title_li=&orderby=name');
}
else
{
$select = 'Select additional category?';
$entries = get_categories('title_li=&orderby=name&hide_empty=0');
}
echo ' ';
echo ''.$select .' ';
foreach ($entries as $entry)
{
if($values['subtype'] == 'page')
{
$id = $entry->ID;
if($entry->post_parent==0)
$title = $entry->post_title;
else
$title = get_the_title($entry->post_parent).': '.$entry->post_title;
}
else
{
$id = $entry->term_id;
if($entry->parent==0)
$title = $entry->name;
else
$title = get_cat_name($entry->parent).': '.$entry->name;
}
if ($this->database_options[$values['id'] .'_'.$i] == $id )
{
$selected = "selected='selected'";
}
else
{
$selected = "";
}
echo"". $title." ";
}
echo ' ';
}
if(isset($this->database_options[$hidden_name])) $values['std'] = $this->database_options[$hidden_name];
echo ' ';
echo '
';
echo ' ';
echo ' ';
//////////////////
echo ' ';
echo '';
}
##############################################################
# BOXES
##############################################################
function boxes($values)
{
for ($i = 1; $i <= $values['count']; $i++)
{
if ($i != 1) $this->stripe();
echo 'table_bg_class.'>';
echo ''.$values['name'].' '.$i.' ';
echo $values['desc'].' '.$i;
echo '';
//select box
echo '
';
echo 'HTML (simple placeholder text gets applied) ';
$s1 = $s2 = $s3 = '';
if ($this->database_options[$values['id'].$i.'_content'] == 'post') $s1 = 'selected="selected"';
if ($this->database_options[$values['id'].$i.'_content'] == 'page') $s2 = 'selected="selected"';
if ($this->database_options[$values['id'].$i.'_content'] == 'widget') $s3 = 'selected="selected"';
echo 'Post ';
echo 'Page ';
echo 'Widget ';
echo ' ';
// 3 different dropdowns:
//categories
$s1 = $s2 = $s3 = '';
if ($this->database_options[$values['id'].$i.'_content'] != "post") $s1 = "hidden";
echo '
';
echo '';
echo 'Select post category ';
$categories = get_categories('title_li=&orderby=name&hide_empty=0');
foreach ($categories as $category)
{
if ($this->database_options[$values['id'].$i.'_content_post'] == $category->term_id)
{
$selected = "selected='selected'";
}
else
{
$selected = "";
}
echo "". $category->name." ";
}
echo ' ';
//pages
if ($this->database_options[$values['id'].$i.'_content'] != "page") $s2 = "hidden";
echo '
';
echo '';
echo 'Select page ';
$pages = get_pages('title_li=&orderby=name');
foreach ($pages as $page)
{
if ($this->database_options[$values['id'].$i.'_content_page'] == $page->ID)
{
$selected = "selected='selected'";
}
else
{
$selected = "";
}
echo "". $page->post_title." ";
}
echo ' ';
//widgets
if ($this->database_options[$values['id'].$i.'_content'] != "widget") $s3 = "hidden";
echo '
';
echo 'Please save this page, then head over to the widget page and add widgets to the "'.$values['widget'].' '.$i.' Widget Area" ';
echo ' ';
echo ' ';
echo ' ';
}
}
##################################################################
} # end class
##################################################################
?>