/options.php

  1. <?php 
  2.  
  3. global $gdeoptions; 
  4. $import = false; 
  5.  
  6. // which form are we submitting (uses nonce for security and identification) 
  7. if ( isset( $_POST['_general_default'] ) ) { 
  8. check_admin_referer('update-default-opts', '_general_default'); 
  9.  
  10. // updating default profile 
  11. $tabid = "gentab"; 
  12.  
  13. if ( gde_form_to_profile( 1, $_POST ) ) { 
  14. // update successful 
  15. gde_show_msg( __('Default profile <strong>updated</strong>.', 'google-document-embedder') ); 
  16. } else { 
  17. gde_show_msg( __('Unable to update profile.', 'google-document-embedder'), true ); 
  18. } elseif ( isset( $_POST['_profiles_new'] ) ) { 
  19.  
  20. check_admin_referer('update-profile-opts', '_profile_edit'); 
  21.  
  22. // new profile creation 
  23. global $wpdb; 
  24. $tabid = "protab"; 
  25.  
  26. if ( ! empty( $_POST['profile-name'] ) ) { 
  27. $name = preg_replace( "/[^A-Za-z0-9 -]/", '', trim( $_POST['profile-name'] ) ); 
  28. $name = strtolower( str_replace( " ", "-", $name ) ); 
  29.  
  30. if ( ! preg_match( '/[\pL]/u', $name ) ) { 
  31. // profile name doesn't contain any letter - possible ID conflict 
  32. gde_show_msg( __('Profile name must contain at least one letter.', 'google-document-embedder'), true ); 
  33. } elseif ( gde_profile_name_exists( $name ) !== -1 ) { 
  34. // profile name is duplicate 
  35. gde_show_msg( __('Profile name already exists. Please choose another name.', 'google-document-embedder'), true ); 
  36. } elseif ( gde_profile_to_profile( $_POST['parent'], $name, stripslashes( $_POST['description'] ) ) ) { 
  37. // intercept and redirect to edit profile page 
  38. $lastid = gde_profile_name_exists( $name ); 
  39. $_POST['action'] = "edit"; 
  40. $_POST['profile'] = $lastid; 
  41. $noload = "gentab"; 
  42. gde_show_msg( __('New profile <strong>created</strong>.', 'google-document-embedder') ); 
  43. } else { 
  44. gde_show_msg( __('Unable to create profile.', 'google-document-embedder'), true ); 
  45. } else { 
  46. gde_show_msg( __('Unable to create profile.', 'google-document-embedder'), true ); 
  47. } elseif ( isset( $_POST['_profile_edit'] ) ) { 
  48. // profile edit 
  49. $tabid = "protab"; 
  50.  
  51. if ( gde_form_to_profile( $_POST['profile_id'], $_POST ) ) { 
  52. // update successful 
  53. gde_show_msg( __('Profile <strong>updated</strong>.', 'google-document-embedder') ); 
  54. } else { 
  55. gde_show_msg( __('Unable to update profile.', 'google-document-embedder'), true ); 
  56. } elseif ( isset( $_POST['action'] ) && isset( $_POST['profile'] ) ) { 
  57. // profile row action 
  58.  
  59. if ( $_POST['action'] == "delete" ) { 
  60. $tabid = "protab"; 
  61. if ( gde_delete_profile( $_POST['profile'] ) ) { 
  62. gde_show_msg( __('Profile <strong>deleted</strong>.', 'google-document-embedder') ); 
  63. } else { 
  64. gde_show_msg( __('Unable to delete profile.', 'google-document-embedder'), true ); 
  65. } elseif ( $_POST['action'] == "default" ) { 
  66. $tabid = "gentab"; 
  67. if ( gde_overwrite_profile( $_POST['profile'] ) ) { 
  68. gde_show_msg( __('Default profile <strong>updated</strong>.', 'google-document-embedder') ); 
  69. } elseif ( $_POST['action'] == "edit" ) { 
  70. $tabid = "protab"; 
  71. $noload = "gentab"; 
  72. } elseif ( isset( $_POST['_advanced'] ) ) { 
  73.  
  74. check_admin_referer('update-adv-opts', '_advanced'); 
  75.  
  76. // updated advanced options (global) 
  77. $tabid = "advtab"; 
  78.  
  79. // keep old options for a moment 
  80. $oldoptions = $gdeoptions; 
  81.  
  82. // initialize checkbox values (values if options unchecked) 
  83. $gdeoptions['ed_disable'] = "no"; 
  84. $gdeoptions['ed_embed_sc'] = "no"; 
  85. $gdeoptions['ed_extend_upload'] = "no"; 
  86. $gdeoptions['error_display'] = "no"; 
  87. $gdeoptions['error_check'] = "no"; 
  88. $gdeoptions['error_log'] = "no"; 
  89.  
  90. foreach ( $_POST as $k => $v ) { 
  91. if ( $k == "ed_disable" ) { 
  92. $gdeoptions[$k] = "yes"; 
  93. } elseif ( $k == "ed_embed_sc" ) { 
  94. $gdeoptions[$k] = "yes"; 
  95. } elseif ( $k == "ed_extend_upload" ) { 
  96. $gdeoptions[$k] = "yes"; 
  97. } elseif ( $k == "error_display" ) { 
  98. $gdeoptions[$k] = "yes"; 
  99. } elseif ( $k == "error_check" ) { 
  100. $gdeoptions[$k] = "yes"; 
  101. } elseif ( $k == "error_log" ) { 
  102. $gdeoptions[$k] = "yes"; 
  103. if ( ! isset( $oldoptions['error_log'] ) || $oldoptions['error_log'] == "no" ) { 
  104. if ( ! gde_dx_log("Diagnostic logging enabled") ) { 
  105. // can't write to db - don't enable logging 
  106. gde_show_msg( __('Unable to enable diagnostic logging.', 'google-document-embedder'), true ); 
  107. $gdeoptions[$k] = "no"; 
  108. } elseif ( array_key_exists( $k, $gdeoptions ) ) { 
  109. // all fields where name == settings key 
  110. $gdeoptions[$k] = stripslashes( $v ); 
  111.  
  112. if ( update_option( 'gde_options', $gdeoptions ) ) { 
  113. // update successful 
  114. gde_show_msg( __('Settings <strong>updated</strong>.', 'google-document-embedder') ); 
  115. } else { 
  116. gde_show_msg( __('Settings <strong>updated</strong>.', 'google-document-embedder') ); // not true, but avoids confusion in case where no changes were made 
  117. gde_dx_log('Settings update failed - maybe no changes'); 
  118.  
  119. // maintain tab on form submission 
  120. if ( isset( $tabid ) && ! isset( $noload ) ) { 
  121. ?> 
  122.  
  123. <script type="text/javascript"> 
  124. jQuery(document).ready(function() { 
  125. jQuery('#<?php echo $tabid; ?>').click(); 
  126. }); 
  127. </script> 
  128.  
  129. <?php 
  130.  
  131. if ( ! $import ) { 
  132. ?> 
  133.  
  134. <div class="wrap"> 
  135. <div class="icon32" id="icon-options-general"></div> 
  136. <h2>Google Doc Embedder <?php _e('Settings', 'google-document-embedder'); ?></h2> 
  137.  
  138. <div id="gdeadmintabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all"> 
  139. <ul class="nav-tab-wrapper ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"> 
  140. <?php 
  141. if ( ! isset( $noload ) ) { 
  142. ?> 
  143. <li id="gentab" class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"> 
  144. <a href="#general" class="nav-tab"> 
  145. <span><?php _e('General', 'google-document-embedder'); ?></span> 
  146. </a> 
  147. </li> 
  148. <li id="protab" class="ui-state-default ui-corner-top"> 
  149. <a href="#profiles" class="nav-tab"> 
  150. <span><?php _e('Profiles', 'google-document-embedder'); ?></span> 
  151. </a> 
  152. </li> 
  153. <?php 
  154. } else { 
  155. ?> 
  156. <li id="gentab-reload" class="ui-state-default ui-corner-top"> 
  157. <a href="#general" class="nav-tab"> 
  158. <span><?php _e('General', 'google-document-embedder'); ?></span> 
  159. </a> 
  160. </li> 
  161. <li id="protab" class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"> 
  162. <a href="#profiles" class="nav-tab"> 
  163. <span><?php _e('Profiles', 'google-document-embedder'); ?></span> 
  164. </a> 
  165. </li> 
  166. <?php 
  167. ?> 
  168. <li id="advtab" class="ui-state-default ui-corner-top"> 
  169. <a href="#advanced" class="nav-tab"> 
  170. <span><?php _e('Advanced', 'google-document-embedder'); ?></span> 
  171. </a> 
  172. </li> 
  173. <!--li id="suptab" class="ui-state-default ui-corner-top"> 
  174. <a href="#support" class="nav-tab"> 
  175. <span><?php _e('Support', 'google-document-embedder'); ?></span> 
  176. </a> 
  177. </li--> 
  178. </ul> 
  179. </div> 
  180.  
  181. <div id="gde-tabcontent"> 
  182. <?php 
  183. if ( ! isset( $noload ) ) { 
  184. ?> 
  185. <div id="gencontent" class="gde-tab gde-tab-active"> 
  186. <?php gde_show_tab('general'); ?> 
  187. </div> 
  188.  
  189. <div id="procontent" class="gde-tab"> 
  190. <?php gde_show_tab('profiles'); ?> 
  191. </div> 
  192.  
  193. <?php 
  194. } else { 
  195. // don't load gentab content if this is a profile edit (avoid js conflicts) 
  196. ?> 
  197. <div id="gencontent" class="gde-tab"></div> 
  198.  
  199. <div id="procontent" class="gde-tab gde-tab-active"> 
  200. <?php gde_show_tab('profiles'); ?> 
  201. </div> 
  202. <?php 
  203. ?> 
  204.  
  205. <div id="advcontent" class="gde-tab"> 
  206. <?php gde_show_tab('advanced'); ?> 
  207. </div> 
  208.  
  209. <div id="supcontent" class="gde-tab"> 
  210. <?php //gde_show_tab('support'); ?> 
  211. </div> 
  212. </div> 
  213.  
  214. </div> 
  215.  
  216. <?php 
  217.  
  218. function gde_opts_checkbox( $field, $label, $wrap = '', $br = '', $disabled = false ) { 
  219. global $gdeoptions; 
  220.  
  221. if ( ! empty( $wrap ) ) { 
  222. echo '<span id="'.esc_attr($wrap).'">'; 
  223. echo '<input type="checkbox" id="'.esc_attr($field).'" name="'.esc_attr($field).'"'; 
  224. if ( ( isset( $gdeoptions[$field] ) && $gdeoptions[$field] == "yes" ) || ( $disabled ) ) { 
  225. echo ' checked="checked"'; 
  226. if ( $disabled ) { 
  227. // used only for dx logging option due to global override in functions.php 
  228. echo ' disabled="disabled"'; 
  229.  
  230. echo ' value="'.esc_attr($field).'"> <label for="'.esc_attr($field).'">'.htmlentities($label).'</label>'; 
  231. if ( ! empty( $br ) ) { 
  232. echo '<br/>'; 
  233. if ( ! empty( $wrap ) ) { 
  234. echo '</span>'; 
  235.  
  236. function gde_profile_option( $option, $value, $label, $helptext = '' ) { 
  237. echo "<option value=\"".esc_attr($value)."\""; 
  238. if ( ! empty( $helptext ) ) { 
  239. echo " title=\"".esc_attr($helptext)."\""; 
  240. if ( $option == $value ) { 
  241. echo ' selected="selected"'; 
  242. echo ">$label  </option>\n"; 
  243.  
  244. function gde_profile_checkbox( $option, $field, $label, $wrap = '', $br = '' ) { 
  245. if ( ! empty( $wrap ) ) { 
  246. echo '<span id="'.esc_attr($wrap).'">'; 
  247. echo '<input type="checkbox" id="'.esc_attr($field).'" name="'.esc_attr($field).'"'; 
  248.  
  249. // toolbar items 
  250. if ( substr( $field, 0, 5 ) == "gdet_" ) { 
  251. if ( $field == "gdet_h" && strstr( $option, str_replace( "gdet_", "", $field ) ) ) { 
  252. echo ' checked="checked"'; 
  253. } elseif ( $field !== "gdet_h" && ! strstr( $option, str_replace( "gdet_", "", $field ) ) ) { 
  254. echo ' checked="checked"'; 
  255. // open in new window 
  256. } elseif ( $field == "fs_win" && $option !== "same" ) { 
  257. echo ' checked="checked"'; 
  258. // logged-in users only 
  259. } elseif ( $field == "fs_user" && $option == "yes" ) { 
  260. echo ' checked="checked"'; 
  261. // allow print 
  262. } elseif ( $field == "fs_print" && $option !== "no" ) { 
  263. echo ' checked="checked"'; 
  264. // content area options 
  265. } elseif ( substr( $field, 0, 5 ) == "gdev_" ) { 
  266. if ( strstr( $option, str_replace( "gdev_", "", $field ) ) ) { 
  267. echo ' checked="checked"'; 
  268. // doc security options 
  269. } elseif ( $field == "force" && $option !== "no" ) { 
  270. echo ' checked="checked"'; 
  271. } elseif ( $field == "mask" && $option !== "no" ) { 
  272. echo ' checked="checked"'; 
  273. } elseif ( $field == "block" && $option !== "no" ) { 
  274. echo ' checked="checked"'; 
  275.  
  276. echo ' value="'.esc_attr($field).'"> <label for="'.esc_attr($field).'">'.htmlentities($label).'</label>'; 
  277. if ( ! empty( $br ) ) { 
  278. echo '<br/>'; 
  279. if ( ! empty( $wrap ) ) { 
  280. echo '</span>'; 
  281.  
  282. function gde_profile_text( $option, $field, $class = '', $size = '', $enabled = true ) { 
  283. echo '<input type="text" id="'.esc_attr($field).'" name="'.esc_attr($field).'" value="'.esc_attr($option).'"'; 
  284. if ( ! empty( $class ) ) { 
  285. echo ' class="'.esc_attr($class).'"'; 
  286. if ( ! empty( $size ) ) { 
  287. echo ' size="'.esc_attr($size).'"'; 
  288. if ( $enabled === false ) { 
  289. echo ' disabled="disabled"'; 
  290. echo ' style="color:#aaa;background-color:#eee;"'; 
  291. echo ">"; 
  292.  
  293. function gde_help_link( $url, $float = '' ) { 
  294. $title = __('Help', 'google-document-embedder'); 
  295. $img = GDE_PLUGIN_URL . "img/help.png"; 
  296.  
  297. if ( ! empty( $float ) ) { 
  298. echo '<div style="float:'.esc_attr($float).';">'; 
  299.  
  300. echo '<a href="'.esc_attr($url).'" target="_blank" title="'.esc_attr($title).'"><img src="'.esc_attr($img).'" alt="?"></a>'; 
  301.  
  302. if ( ! empty( $float ) ) { 
  303. echo "</div>\n"; 
  304.  
  305. function gde_row_cb( $pid ) { 
  306. // default profile 
  307. if ( $pid == 1 ) { 
  308. return " "; 
  309. } else { 
  310. return '<input type="checkbox" value="'.esc_attr($pid).'" name="delete_tags[]">'; 
  311.  
  312. function gde_row_actions( $pid ) { 
  313. $actions = array( 
  314. // action name => arr ( label, class ) 
  315. "edit" => array( __('Edit', 'google-document-embedder'), 'edit' ),  
  316. "delete" => array( __('Delete', 'google-document-embedder'), 'delete' ),  
  317. "default" => array( __('Make Default', 'google-document-embedder'), 'default' ) 
  318. ); 
  319.  
  320. // protect default profile 
  321. if ( $pid == 1 ) { 
  322. unset( $actions['delete'], $actions['default'] ); 
  323.  
  324. foreach ($actions as $k => $v) { 
  325. $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>'; 
  326. $acts = implode( " | ", $act ); 
  327.  
  328. return $acts; 
  329.  
  330. ?> 
.