<?php
global $gdeoptions;
$import = false;
if ( isset( $_POST['_general_default'] ) ) {
check_admin_referer('update-default-opts', '_general_default');
$tabid = "gentab";
if ( gde_form_to_profile( 1, $_POST ) ) {
gde_show_msg( __('Default profile <strong>updated</strong>.', 'google-document-embedder') );
} else {
gde_show_msg( __('Unable to update profile.', 'google-document-embedder'), true );
}
} elseif ( isset( $_POST['_profiles_new'] ) ) {
check_admin_referer('update-profile-opts', '_profile_edit');
global $wpdb;
$tabid = "protab";
if ( ! empty( $_POST['profile-name'] ) ) {
$name = preg_replace( "/[^A-Za-z0-9 -]/", '', trim( $_POST['profile-name'] ) );
$name = strtolower( str_replace( " ", "-", $name ) );
if ( ! preg_match( '/[\pL]/u', $name ) ) {
gde_show_msg( __('Profile name must contain at least one letter.', 'google-document-embedder'), true );
} elseif ( gde_profile_name_exists( $name ) !== -1 ) {
gde_show_msg( __('Profile name already exists. Please choose another name.', 'google-document-embedder'), true );
} elseif ( gde_profile_to_profile( $_POST['parent'], $name, stripslashes( $_POST['description'] ) ) ) {
$lastid = gde_profile_name_exists( $name );
$_POST['action'] = "edit";
$_POST['profile'] = $lastid;
$noload = "gentab";
gde_show_msg( __('New profile <strong>created</strong>.', 'google-document-embedder') );
} else {
gde_show_msg( __('Unable to create profile.', 'google-document-embedder'), true );
}
} else {
gde_show_msg( __('Unable to create profile.', 'google-document-embedder'), true );
}
} elseif ( isset( $_POST['_profile_edit'] ) ) {
$tabid = "protab";
if ( gde_form_to_profile( $_POST['profile_id'], $_POST ) ) {
gde_show_msg( __('Profile <strong>updated</strong>.', 'google-document-embedder') );
} else {
gde_show_msg( __('Unable to update profile.', 'google-document-embedder'), true );
}
} elseif ( isset( $_POST['action'] ) && isset( $_POST['profile'] ) ) {
if ( $_POST['action'] == "delete" ) {
$tabid = "protab";
if ( gde_delete_profile( $_POST['profile'] ) ) {
gde_show_msg( __('Profile <strong>deleted</strong>.', 'google-document-embedder') );
} else {
gde_show_msg( __('Unable to delete profile.', 'google-document-embedder'), true );
}
} elseif ( $_POST['action'] == "default" ) {
$tabid = "gentab";
if ( gde_overwrite_profile( $_POST['profile'] ) ) {
gde_show_msg( __('Default profile <strong>updated</strong>.', 'google-document-embedder') );
}
} elseif ( $_POST['action'] == "edit" ) {
$tabid = "protab";
$noload = "gentab";
}
} elseif ( isset( $_POST['_advanced'] ) ) {
check_admin_referer('update-adv-opts', '_advanced');
$tabid = "advtab";
$oldoptions = $gdeoptions;
$gdeoptions['ed_disable'] = "no";
$gdeoptions['ed_embed_sc'] = "no";
$gdeoptions['ed_extend_upload'] = "no";
$gdeoptions['error_display'] = "no";
$gdeoptions['error_check'] = "no";
$gdeoptions['error_log'] = "no";
foreach ( $_POST as $k => $v ) {
if ( $k == "ed_disable" ) {
$gdeoptions[$k] = "yes";
} elseif ( $k == "ed_embed_sc" ) {
$gdeoptions[$k] = "yes";
} elseif ( $k == "ed_extend_upload" ) {
$gdeoptions[$k] = "yes";
} elseif ( $k == "error_display" ) {
$gdeoptions[$k] = "yes";
} elseif ( $k == "error_check" ) {
$gdeoptions[$k] = "yes";
} elseif ( $k == "error_log" ) {
$gdeoptions[$k] = "yes";
if ( ! isset( $oldoptions['error_log'] ) || $oldoptions['error_log'] == "no" ) {
if ( ! gde_dx_log("Diagnostic logging enabled") ) {
gde_show_msg( __('Unable to enable diagnostic logging.', 'google-document-embedder'), true );
$gdeoptions[$k] = "no";
}
}
} elseif ( array_key_exists( $k, $gdeoptions ) ) {
$gdeoptions[$k] = stripslashes( $v );
}
}
if ( update_option( 'gde_options', $gdeoptions ) ) {
gde_show_msg( __('Settings <strong>updated</strong>.', 'google-document-embedder') );
} else {
gde_show_msg( __('Settings <strong>updated</strong>.', 'google-document-embedder') );
gde_dx_log('Settings update failed - maybe no changes');
}
}
if ( isset( $tabid ) && ! isset( $noload ) ) {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#<?php echo $tabid; ?>').click();
});
</script>
<?php
}
if ( ! $import ) {
?>
<div class="wrap">
<div class="icon32" id="icon-options-general"></div>
<h2>Google Doc Embedder <?php _e('Settings', 'google-document-embedder'); ?></h2>
<div id="gdeadmintabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
<ul class="nav-tab-wrapper ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<?php
if ( ! isset( $noload ) ) {
?>
<li id="gentab" class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active">
<a href="#general" class="nav-tab">
<span><?php _e('General', 'google-document-embedder'); ?></span>
</a>
</li>
<li id="protab" class="ui-state-default ui-corner-top">
<a href="#profiles" class="nav-tab">
<span><?php _e('Profiles', 'google-document-embedder'); ?></span>
</a>
</li>
<?php
} else {
?>
<li id="gentab-reload" class="ui-state-default ui-corner-top">
<a href="#general" class="nav-tab">
<span><?php _e('General', 'google-document-embedder'); ?></span>
</a>
</li>
<li id="protab" class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active">
<a href="#profiles" class="nav-tab">
<span><?php _e('Profiles', 'google-document-embedder'); ?></span>
</a>
</li>
<?php
}
?>
<li id="advtab" class="ui-state-default ui-corner-top">
<a href="#advanced" class="nav-tab">
<span><?php _e('Advanced', 'google-document-embedder'); ?></span>
</a>
</li>
<!--li id="suptab" class="ui-state-default ui-corner-top">
<a href="#support" class="nav-tab">
<span><?php _e('Support', 'google-document-embedder'); ?></span>
</a>
</li-->
</ul>
</div>
<div id="gde-tabcontent">
<?php
if ( ! isset( $noload ) ) {
?>
<div id="gencontent" class="gde-tab gde-tab-active">
<?php gde_show_tab('general'); ?>
</div>
<div id="procontent" class="gde-tab">
<?php gde_show_tab('profiles'); ?>
</div>
<?php
} else {
?>
<div id="gencontent" class="gde-tab"></div>
<div id="procontent" class="gde-tab gde-tab-active">
<?php gde_show_tab('profiles'); ?>
</div>
<?php
}
?>
<div id="advcontent" class="gde-tab">
<?php gde_show_tab('advanced'); ?>
</div>
<div id="supcontent" class="gde-tab">
<?php
</div>
</div>
</div>
<?php
}
function gde_opts_checkbox( $field, $label, $wrap = '', $br = '', $disabled = false ) {
global $gdeoptions;
if ( ! empty( $wrap ) ) {
echo '<span id="'.esc_attr($wrap).'">';
}
echo '<input type="checkbox" id="'.esc_attr($field).'" name="'.esc_attr($field).'"';
if ( ( isset( $gdeoptions[$field] ) && $gdeoptions[$field] == "yes" ) || ( $disabled ) ) {
echo ' checked="checked"';
}
if ( $disabled ) {
echo ' disabled="disabled"';
}
echo ' value="'.esc_attr($field).'"> <label for="'.esc_attr($field).'">'.htmlentities($label).'</label>';
if ( ! empty( $br ) ) {
echo '<br/>';
}
if ( ! empty( $wrap ) ) {
echo '</span>';
}
}
function gde_profile_option( $option, $value, $label, $helptext = '' ) {
echo "<option value=\"".esc_attr($value)."\"";
if ( ! empty( $helptext ) ) {
echo " title=\"".esc_attr($helptext)."\"";
}
if ( $option == $value ) {
echo ' selected="selected"';
}
echo ">$label </option>\n";
}
function gde_profile_checkbox( $option, $field, $label, $wrap = '', $br = '' ) {
if ( ! empty( $wrap ) ) {
echo '<span id="'.esc_attr($wrap).'">';
}
echo '<input type="checkbox" id="'.esc_attr($field).'" name="'.esc_attr($field).'"';
if ( substr( $field, 0, 5 ) == "gdet_" ) {
if ( $field == "gdet_h" && strstr( $option, str_replace( "gdet_", "", $field ) ) ) {
echo ' checked="checked"';
} elseif ( $field !== "gdet_h" && ! strstr( $option, str_replace( "gdet_", "", $field ) ) ) {
echo ' checked="checked"';
}
} elseif ( $field == "fs_win" && $option !== "same" ) {
echo ' checked="checked"';
} elseif ( $field == "fs_user" && $option == "yes" ) {
echo ' checked="checked"';
} elseif ( $field == "fs_print" && $option !== "no" ) {
echo ' checked="checked"';
} elseif ( substr( $field, 0, 5 ) == "gdev_" ) {
if ( strstr( $option, str_replace( "gdev_", "", $field ) ) ) {
echo ' checked="checked"';
}
} elseif ( $field == "force" && $option !== "no" ) {
echo ' checked="checked"';
} elseif ( $field == "mask" && $option !== "no" ) {
echo ' checked="checked"';
} elseif ( $field == "block" && $option !== "no" ) {
echo ' checked="checked"';
}
echo ' value="'.esc_attr($field).'"> <label for="'.esc_attr($field).'">'.htmlentities($label).'</label>';
if ( ! empty( $br ) ) {
echo '<br/>';
}
if ( ! empty( $wrap ) ) {
echo '</span>';
}
}
function gde_profile_text( $option, $field, $class = '', $size = '', $enabled = true ) {
echo '<input type="text" id="'.esc_attr($field).'" name="'.esc_attr($field).'" value="'.esc_attr($option).'"';
if ( ! empty( $class ) ) {
echo ' class="'.esc_attr($class).'"';
}
if ( ! empty( $size ) ) {
echo ' size="'.esc_attr($size).'"';
}
if ( $enabled === false ) {
echo ' disabled="disabled"';
echo ' style="color:#aaa;background-color:#eee;"';
}
echo ">";
}
function gde_help_link( $url, $float = '' ) {
$title = __('Help', 'google-document-embedder');
$img = GDE_PLUGIN_URL . "img/help.png";
if ( ! empty( $float ) ) {
echo '<div style="float:'.esc_attr($float).';">';
}
echo '<a href="'.esc_attr($url).'" target="_blank" title="'.esc_attr($title).'"><img src="'.esc_attr($img).'" alt="?"></a>';
if ( ! empty( $float ) ) {
echo "</div>\n";
}
}
function gde_row_cb( $pid ) {
if ( $pid == 1 ) {
return " ";
} else {
return '<input type="checkbox" value="'.esc_attr($pid).'" name="delete_tags[]">';
}
}
function gde_row_actions( $pid ) {
$actions = array(
"edit" => array( __('Edit', 'google-document-embedder'), 'edit' ),
"delete" => array( __('Delete', 'google-document-embedder'), 'delete' ),
"default" => array( __('Make Default', 'google-document-embedder'), 'default' )
);
if ( $pid == 1 ) {
unset( $actions['delete'], $actions['default'] );
}
foreach ($actions as $k => $v) {
$act[] = '<span class="'.esc_attr($v[1]).'" id="'.esc_attr($k).'-'.esc_attr($pid).'"><a href="options-general.php?page=gde-settings">'.htmlentities($v[0]).'</a></span>';
}
$acts = implode( " | ", $act );
return $acts;
}
?>