theme = $theme;
if(is_admin()) {
if(isset($_GET['activated'] ) && $pagenow == "themes.php") {
wp_redirect( admin_url('themes.php?page=themater') );
exit();
}
add_action('admin_menu', array(&$this, 'loadMenu'));
add_action('admin_head', array(&$this, 'loadHead') );
add_action('wp_ajax_themater_ajax', array(&$this, 'Ajax') );
}
if($this->theme->is_admin_user()) {
$this->setupThemater();
}
}
function setupThemater($reset = false)
{
if(!$this->theme->options['theme_options'] || $reset) {
if(is_array($this->theme->admin_options)) {
$save_options = array();
foreach($this->theme->admin_options as $themater_options) {
if(is_array($themater_options['content'])) {
foreach($themater_options['content'] as $themater_elements) {
if(is_array($themater_elements['content'])) {
$elements = $themater_elements['content'];
if($elements['type'] !='content' && $elements['type'] !='raw') {
$save_options[$elements['name']] = $elements['value'];
}
}
}
}
}
update_option($this->theme->options['theme_options_field'], $save_options);
$this->theme->options['theme_options'] = $save_options;
}
}
}
function loadMenu()
{
add_theme_page($this->theme->theme_name . " Theme Options", $this->theme->theme_name . " Theme Options", 'administrator', 'themater', array(&$this, 'ThematerThemeOptions'));
}
function loadHead()
{
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo '' . "\n";
}
function Ajax()
{
check_ajax_referer( "themater-nonce");
$act = 'ajax_' . $this->theme->request('act');
if (is_callable(array(get_class($this), $act))) {
$this->$act();
} else {
echo 'Call to not defined ajax function: ' . $act;
}
exit();
}
function ajax_savechanges()
{
if($_POST) {
$options = $this->theme->options['theme_options'];
foreach($options as $option_key =>$option_val) {
$saveval = isset($_POST[$option_key]) ? $_POST[$option_key] : '';
$options[$option_key] = $saveval;
}
update_option($this->theme->options['theme_options_field'], $options);
}
echo 'Changes saved successfully!';
}
function ajax_imageupload()
{
$allowed_imagetypes = array('.jpg', '.jpeg', '.gif', '.png', '.bmp', '.ico');
$imgname = $_POST['imgname'];
$filename = $_FILES[$imgname];
$filename['name'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', $filename['name']);
$filename_ext = substr($filename['name'], strpos($filename['name'],'.'), strlen($filename['name'])-1);
if(!in_array(strtolower($filename_ext),$allowed_imagetypes)) {
echo 'Upload Error: The file extension ' . $filename_ext . ' is not allowed!';
} else {
$override['test_form'] = false;
$override['action'] = 'wp_handle_upload';
$uploaded_image = wp_handle_upload($filename,$override);
if(!empty($uploaded_image['error'])) {
echo 'Upload Error: ' . $uploaded_image['error'];
} else {
echo $uploaded_image['url'];
}
}
}
function ajax_admin_options()
{
$do = $this->theme->request('do');
if($do == 'reset') {
$this->setupThemater(true);
echo '
The options was reset successfully.
Click here to reload the Options Page.
';
}
}
function get_priority($array = array(), $current_priority)
{
if(isset($array[$current_priority])) {
$return_priority = $this->get_priority($array, $current_priority+1);
} else {
$return_priority = $current_priority;
}
return $return_priority;
}
function do_priority($array = array())
{
$i = time();
$return = array();
foreach($array as $key=>$val) {
$i++;
$priority = $val['priority'] ? $val['priority'] : $i;
$val['name'] = $key;
$return[$this->get_priority($return, $priority)] = $val;
}
ksort($return);
return $return;
}
function apply_attributes($attributes = array())
{
$skip = array('type', 'name', 'value', 'help', 'priority', 'display', 'options', 'prefix', 'suffix', 'callback');
$returnval = '';
foreach ($attributes as $key => $val) {
if(!in_array($key, $skip)) {
$returnval .= ' ' . $key . '="' . $val . '" ';
}
}
return $returnval;
}
function form_text ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
return $prefix . 'apply_attributes($attributes) . ' />' . $suffix;
}
function form_textarea ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
return $prefix . '' . $suffix;
}
function form_checkbox ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
$checked = (strlen($this->theme->get_option($name)) > 0) ? ' checked="checked" ' : '';
$thevalue = (strlen($attributes['value']) > 0) ? $attributes['value'] : $name;
return $prefix . 'apply_attributes($attributes) . ' />' . $suffix;
}
function form_checkboxes ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '
';
$current_val = is_array($this->theme->get_option($name)) ? $this->theme->get_option($name) : array();
$options = $attributes['options'];
$returnval = '';
foreach ($options as $option_name => $option_value) {
$checked = in_array($option_name,$current_val) ? ' checked="checked" ' : '';
$returnval .= $prefix . 'apply_attributes($attributes) . ' /> ' . $option_value . $suffix . "\n";
}
return $returnval;
}
function form_radio ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '
';
$current_val = $this->theme->get_option($name);
$options = $attributes['options'];
$returnval = '';
foreach ($options as $option_name => $option_value) {
$checked = $current_val == $option_name ? ' checked="checked" ' : '';
$returnval .= $prefix . 'apply_attributes($attributes) . ' /> ' . $option_value . $suffix . "\n";
}
return $returnval;
}
function form_select ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
$current_val = $this->theme->get_option($name);
$options = $attributes['options'];
$returnval = $prefix . '' . $suffix . "\n";
return $returnval;
}
function form_hidden ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
return $prefix . 'apply_attributes($attributes) . ' />' . $suffix;
}
function form_content ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
return $prefix . 'apply_attributes($attributes) . '>' . $attributes['value'] . '
' . $suffix;
}
function form_callback ($name, $attributes = array())
{
if(isset($attributes['callback']) && is_array(($attributes['callback']))) {
$callback = $attributes['callback'];
$callback[0]->$callback[1]();
} else {
if(function_exists($name)) {
return $name($attributes);
}
}
}
function form_colorpicker ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
$return = $prefix . "theme->get_option($name) . "\" class=\"color {required:false}\" style=\"border:2px solid #dcdfe4; width: 72px; \" " . $this->apply_attributes($attributes) . ">" . $suffix;
return $return;
}
function form_imageupload ($name, $attributes = array())
{
$prefix = isset($attributes['prefix']) ? $attributes['prefix'] : '';
$suffix = isset($attributes['suffix']) ? $attributes['suffix'] : '';
$current_image = $this->theme->get_option($name);
echo $prefix;
?>
The image might be resized, click for full preview!
apply_attributes($attributes); ?> />
do_priority($this->theme->admin_options);
if( is_array($themater_options) && count($themater_options) > 0) {
foreach($themater_options as $menu) {
$menuids++;
if(isset($menu['content']) && is_array($menu['content'])) {
$menu_items_content = $this->do_priority($menu['content']);
$default_first_menu = ($menuids == '1') ? ' tt-menu-content-first' : '';
?>
$form_item($itemval['name'], $itemval);
} else {
?>