/functions-admin.php

  1. <?php 
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) { exit; } 
  4.  
  5. /** PROFILES ****/ 
  6.  
  7. /** 
  8. * Write profile from form data 
  9. * 
  10. * @since 2.5.0.1 
  11. * @return bool Whether or not action successful 
  12. */ 
  13. function gde_form_to_profile( $pid, $data ) { 
  14.  
  15. // get current profile data 
  16. $profile = gde_get_profiles( $pid, false ); 
  17.  
  18. // initialize checkbox values (values if options unchecked) 
  19. $profile['tb_flags'] = "przn"; 
  20. $profile['tb_fullwin'] = "same"; 
  21. $profile['tb_fulluser'] = "no"; 
  22. $profile['tb_print'] = "no"; 
  23. $profile['vw_flags'] = ""; 
  24. $profile['link_force'] = "no"; 
  25. $profile['link_mask'] = "no"; 
  26. $profile['link_block'] = "no"; 
  27.  
  28. // enforce trailing slash on base_url 
  29. $data['base_url'] = trailingslashit( $data['base_url'] ); 
  30.  
  31. // sanitize width/height 
  32. $data['default_width'] = gde_sanitize_dims( $data['default_width'] ); 
  33. $data['default_height'] = gde_sanitize_dims( $data['default_height'] ); 
  34. if ( ! $data['default_width'] ) { 
  35. $data['default_width'] = $profile['default_width']; 
  36. if ( ! $data['default_height'] ) { 
  37. $data['default_height'] = $profile['default_height']; 
  38.  
  39. foreach ( $data as $k => $v ) { 
  40. if ( array_key_exists( $k, $profile ) ) { 
  41. // all fields where name == profile key 
  42. $profile[$k] = stripslashes( $v ); 
  43. } elseif ( strstr( $k, 'gdet_' ) && ( strstr( $v, 'gdet_' ) ) ) { 
  44. // toolbar checkboxes 
  45. if ( $k == 'gdet_h' ) { 
  46. $profile['tb_flags'] .= "h"; 
  47. } else { 
  48. $profile['tb_flags'] = str_replace( str_replace( "gdet_", "", $v ), "", $profile['tb_flags'] ); 
  49. } elseif ( $k == "fs_win" ) { 
  50. $profile['tb_fullwin'] = "new"; 
  51. } elseif ( $k == "fs_user" ) { 
  52. $profile['tb_fulluser'] = "yes"; 
  53. } elseif ( $k == "fs_print" ) { 
  54. $profile['tb_print'] = "yes"; 
  55. } elseif ( strstr( $k, 'gdev_' ) && ( strstr( $v, 'gdev_' ) ) ) { 
  56. $profile['vw_flags'] .= str_replace( "gdev_", "", $v ); 
  57. } elseif ( $k == "force" ) { 
  58. $profile['link_force'] = "yes"; 
  59. } elseif ( $k == "mask" ) { 
  60. $profile['link_mask'] = "yes"; 
  61. } elseif ( $k == "block" && gde_is_blockable( $profile ) ) { 
  62. $profile['link_block'] = "yes"; 
  63.  
  64. $newprofile = array( '', '', serialize( $profile ) ); 
  65. if ( gde_write_profile( $newprofile, $pid, true ) > 0 ) { 
  66. // update successful 
  67. return true; 
  68. } else { 
  69. return false; 
  70.  
  71. /** 
  72. * Make new profile (from existing) 
  73. * 
  74. * @since 2.5.0.1 
  75. * @return bool Whether or not action successful 
  76. */ 
  77. function gde_profile_to_profile( $sourceid, $name, $desc = '' ) { 
  78. global $wpdb; 
  79. $table = $wpdb->prefix . 'gde_profiles'; 
  80.  
  81. if ( $sourcedata = $wpdb->get_row( $wpdb->prepare( "SELECT profile_data FROM $table WHERE profile_id = %d", $sourceid ), ARRAY_A ) ) { 
  82. $newprofile = array( $name, $desc, $sourcedata['profile_data'] ); 
  83. if ( gde_write_profile( $newprofile ) > 0 ) { 
  84. return true; 
  85. } else { 
  86. return false; 
  87. } else { 
  88. return false; 
  89.  
  90. /** 
  91. * Create/update profile 
  92. * 
  93. * @since 2.5.0.1 
  94. * @return int 0 = fail, 1 = created, 2 = updated, 3 = nothing to do 
  95. * @note data array expected: [0] name, [1] desc, [2] serialized data 
  96. */ 
  97. function gde_write_profile( $data, $id = null, $overwrite = false ) { 
  98. global $wpdb; 
  99. $table = $wpdb->prefix . 'gde_profiles'; 
  100.  
  101. if ( empty( $id ) ) { 
  102. // get profile name 
  103. $pname = strtolower( $data[0] ); 
  104.  
  105. // new (non-default) profile 
  106. if ( ! $wpdb->insert( 
  107. $table,  
  108. array( 
  109. 'profile_name' => $pname,  
  110. 'profile_desc' => $data[1],  
  111. 'profile_data' => $data[2] 
  112. ) ) { 
  113. gde_dx_log("Failed to create profile '$pname'"); 
  114. return 0; 
  115. } else { 
  116. gde_dx_log("New profile '$pname' created"); 
  117. return 1; 
  118. } else { 
  119. // new (default) or updated profile 
  120. if ( is_null( $wpdb->get_row( "SELECT * FROM $table WHERE profile_id = $id" ) ) ) { 
  121. // new default profile 
  122. //gde_dx_log("Profile ID $id doesn't exist - creating"); 
  123.  
  124. if ( ! $wpdb->insert( 
  125. $table,  
  126. array( 
  127. 'profile_id' => $id,  
  128. 'profile_name' => strtolower( $data[0] ),  
  129. 'profile_desc' => $data[1],  
  130. 'profile_data' => $data[2] 
  131. ),  
  132. array( 
  133. '%d', '%s', '%s', '%s' 
  134. ) ) { 
  135. gde_dx_log("Profile $id creation failed"); 
  136. return 0; 
  137. } else { 
  138. gde_dx_log("Profile $id created"); 
  139. return 1; 
  140. } elseif ( $overwrite ) { 
  141. // get old data 
  142. $olddata = gde_get_profiles( $id, false, true ); 
  143. $olddesc = $olddata['profile_desc']; 
  144. unset( $olddata['profile_desc'] ); 
  145.  
  146. // update profile 
  147. gde_dx_log("Profile ID $id exists - updating"); 
  148.  
  149. if ( ! empty( $data[0] ) ) { 
  150. // overwrite name 
  151. $newdata['profile_name'] = strtolower( $data[0] ); 
  152. if ( ! empty( $data[1] ) && ( $data[1] !== $olddesc ) ) { 
  153. // overwrite description 
  154. $newdata['profile_desc'] = $data[1]; 
  155.  
  156. if ( ! empty( $data[2] ) && ( $data[2] !== serialize( $olddata ) ) ) { 
  157. // overwrite data 
  158. $newdata['profile_data'] = $data[2]; 
  159.  
  160. if ( isset( $newdata ) ) { 
  161. if ( ! $wpdb->update( 
  162. $table,  
  163. $newdata,  
  164. array( 'profile_id' => $id ),  
  165. array( 
  166. '%s', '%s', '%s' 
  167. ) ) { 
  168. $info = print_r($newdata, true); 
  169. gde_dx_log("Profile $id update failed writing: \n\n $info"); 
  170. return 0; 
  171. } else { 
  172. gde_dx_log("Profile $id updated"); 
  173. return 2; 
  174. } else { 
  175. gde_dx_log("Overwrite requested but no changes found"); 
  176. return 3; 
  177. } else { 
  178. gde_dx_log("Profile $id exists, overwrite not specified - nothing changed"); 
  179. return 3; 
  180.  
  181. /** 
  182. * Delete profile 
  183. * 
  184. * @since 2.5.0.1 
  185. * @return bool Whether or not action successful 
  186. */ 
  187. function gde_delete_profile( $id ) { 
  188. global $wpdb; 
  189. $table = $wpdb->prefix . 'gde_profiles'; 
  190.  
  191. if ( $wpdb->query( $wpdb->prepare( "DELETE FROM $table WHERE profile_id = %d", $id ) ) > 0 ) { 
  192. return true; 
  193. } else { 
  194. return false; 
  195.  
  196. /** 
  197. * Check for duplicate profile name 
  198. * 
  199. * @since 2.5.0.2 
  200. * @return int Profile id of name or -1 if no match 
  201. */ 
  202. function gde_profile_name_exists( $name ) { 
  203. global $wpdb; 
  204. $table = $wpdb->prefix . 'gde_profiles'; 
  205.  
  206. if ( $id = $wpdb->get_row( $wpdb->prepare( "SELECT profile_id FROM $table WHERE profile_name = %s", $name ), ARRAY_A ) ) { 
  207. return (int) $id['profile_id']; 
  208. } else { 
  209. return -1; 
  210.  
  211. /** 
  212. * Make existing profile data default (overwrite current default) 
  213. * 
  214. * @since 2.5.0.1 
  215. * @return bool Whether or not action successful 
  216. */ 
  217. function gde_overwrite_profile( $sourceid ) { 
  218. global $wpdb; 
  219. $table = $wpdb->prefix . 'gde_profiles'; 
  220.  
  221. if ( $data = $wpdb->get_row( $wpdb->prepare( "SELECT profile_data FROM $table WHERE profile_id = %d", $sourceid ), ARRAY_A ) ) { 
  222. if ( $wpdb->update ( $table, $data, array( 'profile_id' => 1 ), array( '%s' ) ) ) { 
  223. return true; 
  224. } else { 
  225. return false; 
  226. } else { 
  227. return false; 
  228.  
  229. /** 
  230. * Process profile/settings import file 
  231. * 
  232. * @since 2.5.0.3 
  233. * @return void 
  234. */ 
  235. function gde_import( $data ) { 
  236. $label = __('Import', 'google-document-embedder'); 
  237. $status = array(); 
  238.  
  239. echo ' 
  240. <div class="wrap"> 
  241. <div class="icon32" id="icon-plugins"></div> 
  242. <h2>Google Doc Embedder ' . $label . '</h2> 
  243. '; 
  244.  
  245. if ( isset( $data['profiles'] ) || isset( $data['profiles'] ) ) { 
  246. // full import 
  247. echo "<p>" . __('Performing full import...', 'google-document-embedder') . "</p>\n"; 
  248.  
  249. // profiles import 
  250. if ( isset( $data['profiles'] ) ) { 
  251. echo "<p>" . __('Importing profiles', 'google-document-embedder'); 
  252.  
  253. $success = gde_import_profiles( $data['profiles'] ); 
  254. $total = count( $data['profiles'] ); 
  255. echo " ($success/$total)... "; 
  256. if ( $success == $total ) { 
  257. echo __('done', 'google-document-embedder') . ".</p>\n"; 
  258. } else { 
  259. $status[] = "fail"; 
  260. echo "<strong>" . __('failed', 'google-document-embedder') . ".</strong></p>\n"; 
  261.  
  262. // settings import 
  263. if ( isset( $data['settings'] ) ) { 
  264. echo "<p>" . __('Importing settings', 'google-document-embedder') . "... "; 
  265. if ( ! gde_import_settings( $data['settings'] ) ) { 
  266. $status[] = "fail"; 
  267. echo "<strong>" . __('failed', 'google-document-embedder') . ".</strong></p>\n"; 
  268. } else { 
  269. echo __('done', 'google-document-embedder') . ".</p>\n"; 
  270. } elseif ( isset( $data[0]['profile_id'] ) ) { 
  271. // profile import 
  272. echo "<p>" . __('Importing profiles', 'google-document-embedder'); 
  273.  
  274. $success = gde_import_profiles( $data ); 
  275. $total = count( $data ); 
  276. echo " ($success/$total)... "; 
  277. if ( $success == $total ) { 
  278. echo __('done', 'google-document-embedder') . ".</p>\n"; 
  279. } else { 
  280. $status[] = "fail"; 
  281. echo "<strong>" . __('failed', 'google-document-embedder') . ".</strong></p>\n"; 
  282. } elseif ( isset( $data['ed_disable'] ) ) { 
  283. // settings import 
  284. echo "<p>" . __('Importing settings... ', 'google-document-embedder'); 
  285.  
  286. if ( ! gde_import_settings( $data ) ) { 
  287. $status[] = "fail"; 
  288. echo "<strong>" . __('failed', 'google-document-embedder') . ".</strong></p>\n"; 
  289. } else { 
  290. echo __('done', 'google-document-embedder') . ".</p>\n"; 
  291. } else { 
  292. echo "<p>" . __('Please select a valid export file to import.', 'google-document-embedder') . "</p>\n"; 
  293.  
  294. if ( in_array( 'fail', $status ) ) { 
  295. echo "<p>" . __('All or part of the import failed. See above for information.', 'google-document-embedder') . "</p>\n"; 
  296. } else { 
  297. echo "<p>" . __('Import completed successfully.', 'google-document-embedder') . "</p>\n"; 
  298.  
  299. echo "<p><a href=''>" . __('Return to GDE Settings', 'google-document-embedder') . "</a></p>\n"; 
  300. echo "</div>\n"; 
  301.  
  302. /** 
  303. * Process settings import data 
  304. * 
  305. * @since 2.5.0.3 
  306. * @return bool Whether or not settings import succeeded 
  307. */ 
  308. function gde_import_settings( $data ) { 
  309. global $gdeoptions; 
  310.  
  311. $current = $gdeoptions; 
  312.  
  313. if ( $current == $data ) { 
  314. // nothing to do 
  315. return true; 
  316. } else { 
  317. foreach ( $data as $k => $v ) { 
  318. $gdeoptions[$k] = $v; 
  319.  
  320. if ( update_option( 'gde_options', $gdeoptions ) ) { 
  321. return true; 
  322. } else { 
  323. return false; 
  324.  
  325. function gde_import_profiles( $data ) { 
  326. $success = 0; 
  327.  
  328. foreach ( $data as $v ) { 
  329. $pid = gde_profile_name_exists( $v['profile_name'] ); 
  330. if ( $pid !== -1 ) { 
  331. // overwrite existing profile 
  332. $prodata = array( '', $v['profile_desc'], $v['profile_data'] ); 
  333. if ( gde_write_profile( $prodata, $pid, true ) > 0 ) { 
  334. $success++; 
  335. } else { 
  336. gde_dx_log("failure importing to overwrite profile $pid"); 
  337. } else { 
  338. // write as new profile 
  339. $prodata = array( $v['profile_name'], $v['profile_desc'], $v['profile_data'] ); 
  340. if ( gde_write_profile( $prodata ) > 0 ) { 
  341. $success++; 
  342. } else { 
  343. gde_dx_log("failure importing to new profile"); 
  344.  
  345. return $success; 
  346.  
  347. /** SETTINGS ****/ 
  348.  
  349. /** 
  350. * Get locale 
  351. * 
  352. * @since 2.4.1.1 
  353. * @return string Google viewer lang code based on WP_LANG setting, or en_US if not defined 
  354. */ 
  355. function gde_get_locale() { 
  356. $locale = get_locale(); 
  357.  
  358. require_once( GDE_PLUGIN_DIR . 'libs/lib-langs.php' ); 
  359. return gde_mapped_langs( $locale ); 
  360.  
  361. function gde_option_page() { 
  362. global $gde_settings_page, $gdeoptions; 
  363.  
  364. $gde_settings_page = add_options_page( 'GDE '.__('Settings', 'google-document-embedder'), 'GDE '.__('Settings', 'google-document-embedder'), 'manage_options', 'gde-settings', 'gde_options' ); 
  365.  
  366. // enable custom styles and settings jQuery 
  367. add_action( 'admin_print_styles', 'gde_admin_custom_css' ); 
  368. add_action( 'admin_enqueue_scripts', 'gde_admin_custom_js' ); 
  369.  
  370. function gde_options() { 
  371. if (! current_user_can('manage_options') ) wp_die('You don\'t have access to this page.'); 
  372. if (! user_can_access_admin_page()) wp_die( __('You do not have sufficient permissions to access this page', 'google-document-embedder') ); 
  373.  
  374. require( GDE_PLUGIN_DIR . 'options.php' ); 
  375. add_action('in_admin_footer', 'gde_admin_footer'); 
  376.  
  377. /** 
  378. function gde_site_option_page() { 
  379. global $gde_global_page; 
  380.  
  381. $gde_global_page = add_submenu_page( 'settings.php', 'GDE '.__('Settings', 'google-document-embedder'), 'GDE '.__('Settings', 'google-document-embedder'), 'manage_network_options', basename(__FILE__), 'gde_site_options' ); 
  382.  
  383. // enable custom styles and settings jQuery 
  384. //add_action( 'admin_print_styles', 'gde_admin_custom_css' ); 
  385. //add_action( 'admin_enqueue_scripts', 'gde_admin_custom_js' ); 
  386.  
  387. function gde_site_options() { 
  388. //if ( function_exists('current_user_can') && !current_user_can('manage_options') ) wp_die('You don\'t have access to this page.'); 
  389. //if (! user_can_access_admin_page()) wp_die( __('You do not have sufficient permissions to access this page', 'google-document-embedder') ); 
  390.  
  391. require( GDE_PLUGIN_DIR . 'site-options.php' ); 
  392. add_action( 'in_admin_footer', 'gde_admin_footer' ); 
  393. */ 
  394.  
  395. /** 
  396. * Get Default Base URL 
  397. * 
  398. * @since 2.5.0.1 
  399. * @return string Default base URL based on WP settings 
  400. */ 
  401. function gde_base_url() { 
  402. if ( ! $baseurl = get_option( 'upload_url_path' ) ) { 
  403. $uploads = wp_upload_dir(); 
  404. $baseurl = $uploads['baseurl']; 
  405.  
  406. return trailingslashit( $baseurl ); 
  407.  
  408. /** 
  409. * Display tabs 
  410. * 
  411. * @since 2.5.0.1 
  412. * @return void 
  413. */ 
  414. function gde_show_tab( $name ) { 
  415. $tabfile = GDE_PLUGIN_DIR . "libs/tab-$name.php"; 
  416.  
  417. if ( file_exists( $tabfile ) ) { 
  418. include_once( $tabfile ); 
  419.  
  420. /** 
  421. * Reset global (multisite) options 
  422. * 
  423. * @since 2.5.0.1 
  424. * @return void 
  425. */ 
  426. /** 
  427. function gde_global_reset() { 
  428. global $gdeglobals; 
  429.  
  430. // by default, global settings are empty 
  431. if ($gdeglobals) { 
  432. delete_site_option('gde_globals'); 
  433. } 
  434. } 
  435. */ 
  436.  
  437. /** 
  438. * Delete autoexpire secure docs 
  439. * 
  440. * @since 2.5.0.1 
  441. * @note Runs via wp-cron according to schedule defined in lib-setup 
  442. * @return void 
  443. */ 
  444. /** 
  445. function gde_sec_cleanup() { 
  446. global $wpdb; 
  447.  
  448. $table = $wpdb->prefix . 'gde_secure'; 
  449. $wpdb->query( "DELETE FROM $table WHERE autoexpire = 'Y'" ); 
  450. gde_dx_log("Cleanup ran"); 
  451. } 
  452. */ 
  453.  
  454. /** 
  455. * Include custom css for settings pages 
  456. * 
  457. * @since 2.5.0.1 
  458. * @return void 
  459. */ 
  460. function gde_admin_custom_css( $hook ) { 
  461. global $wp_version; 
  462.  
  463. if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'gde-settings' ) ) { 
  464. if ( version_compare( $wp_version, '3.8-RC1', '>=' ) ) { 
  465. $css = GDE_PLUGIN_URL . 'css/admin-styles38.css'; 
  466. } else { 
  467. $css = GDE_PLUGIN_URL . 'css/admin-styles.css'; 
  468. wp_enqueue_style( 'gde_css', $css ); 
  469.  
  470. // native color picker 
  471. wp_enqueue_style( 'wp-color-picker' ); 
  472.  
  473. function gde_admin_footer() { 
  474. global $pdata; 
  475.  
  476. $plugin_str = __('plugin', 'google-document-embedder'); 
  477. $version_str = __('Version', 'google-document-embedder'); 
  478. printf( '%1$s %2$s | %3$s %4$s<br />', $pdata['Title'], $plugin_str, $version_str, $pdata['Version'] ); 
  479.  
  480. function gde_show_msg( $message, $error = false ) { 
  481. if ( $error ) { $class = "error"; } else { $class = "updated"; } 
  482. echo '<div id="message" class="'.$class.'"><p>' . $message . '</p></div>'; 
  483.  
  484. // add additional links, for convenience 
  485. function gde_actlinks( $links ) {  
  486. $settings_link = '<a href="options-general.php?page=gde-settings">' . __('Settings', 'google-document-embedder') . '</a>';  
  487. array_unshift( $links, $settings_link );  
  488. return $links;  
  489.  
  490. function gde_admin_print_scripts( $arg ) { 
  491. global $pagenow; 
  492. if (is_admin() && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { 
  493. $js = GDE_PLUGIN_URL . 'js/gde-quicktags.js'; 
  494. wp_enqueue_script( 'gde_qts', $js, array('quicktags') ); 
  495.  
  496. function gde_admin_custom_js( $hook ) { 
  497. global $gde_settings_page, $gde_global_page, $pagenow; 
  498.  
  499. if ( $gde_settings_page == $hook || $gde_global_page == $hook ) { 
  500. wp_enqueue_script( 'gde_jqs', GDE_PLUGIN_URL . 'js/gde-jquery.js', array( 'wp-color-picker' ), false, true ); 
  501.  
  502. // localize 
  503. wp_localize_script( 'gde_jqs', 'jqs_vars', array ( 
  504. // internal use 
  505. 'gde_url' => GDE_PLUGIN_URL,  
  506. // profiles tab 
  507. 'delete' => __('This profile will be permanently deleted.', 'google-document-embedder') . "\n\n" . __('Are you sure?', 'google-document-embedder'),  
  508. 'default' => __('Settings for this profile will overwrite the default profile.', 'google-document-embedder') . "\n\n" . __('Are you sure?', 'google-document-embedder'),  
  509. 'reset' => __('Your profile list will be reset to its original state. All changes will be lost.', 'google-document-embedder') . "\n\n" . __('Are you sure?', 'google-document-embedder'),  
  510. // advanced tab 
  511. 'badimport' => __('Please select a valid export file to import.', 'google-document-embedder'),  
  512. 'warnimport' => __('Any settings or duplicate profile names in this import will overwrite the current values.', 'google-document-embedder') . "\n\n" . __('Are you sure?', 'google-document-embedder'),  
  513. // support tab 
  514. 'baddebug' => __('Please include a shortcode or message to request support.', 'google-document-embedder') 
  515. ); 
  516.  
  517. /** MEDIA LIBRARY & EDITOR INTEGRATION ****/ 
  518.  
  519. /** 
  520. * Modify the file insertion from Media Library if requested 
  521. * 
  522. * @since 2.4.0.1 
  523. * @note Requires WP 3.5+ 
  524. * @return string HTML to insert into editor 
  525. */ 
  526. function gde_media_insert( $html, $id, $attachment ) { 
  527. global $gdeoptions; 
  528.  
  529. $gdoc_url = ''; 
  530. if (isset($attachment['url'])) { 
  531. $gdoc_url = $attachment['url']; 
  532. elseif ($id > 0) { 
  533. $post = get_post($id); 
  534. if ($post) { 
  535. $gdoc_url = wp_get_attachment_url($id); 
  536.  
  537. if ($gdoc_url != '' && gde_valid_type( $gdoc_url ) && $gdeoptions['ed_embed_sc'] == "yes" ) { 
  538. return '[gview file="' . $gdoc_url . '"]'; 
  539. } else { 
  540. return $html; 
  541.  
  542. /** 
  543. * Add upload support for natively unsupported mimetypes used by this plugin 
  544. * 
  545. * @since 2.4.0.1 
  546. * @return array Updated array of allowed upload types 
  547. */ 
  548. function gde_upload_mimes( $existing_mimes = array() ) { 
  549. $supported_exts = gde_supported_types(); 
  550.  
  551. foreach ( $supported_exts as $ext => $mimetype ) { 
  552. if ( ! array_key_exists( $ext, gde_mimes_expanded( $existing_mimes ) ) ) { 
  553. $existing_mimes[$ext] = $mimetype; 
  554. return gde_mimes_collapsed( $existing_mimes ); 
  555.  
  556. function gde_mimes_expanded( array $types ) { 
  557. // expand the supported mime types so that every ext is its own key 
  558. foreach ( $types as $k => $v ) { 
  559. if ( strpos( "|", $k ) ) { 
  560. $subtypes = explode( "|", $k ); 
  561. foreach ( $subtypes as $type ) { 
  562. $newtypes[$type] = $v; 
  563. unset( $types[$k] ); 
  564. $types = array_merge( $types, $newtypes ); 
  565. return $types; 
  566.  
  567. function gde_mimes_collapsed( $types ) { 
  568. // collapes the supported mime types so that each mime is listed once with combined key (default) 
  569. $newtypes = array(); 
  570.  
  571. foreach ( $types as $k => $v ) { 
  572. if ( isset( $newtypes[$v] ) ) { 
  573. $newtypes[$v] .= '|' . $k; 
  574. } else { 
  575. $newtypes[$v] = $k; 
  576. return array_flip( $newtypes ); 
  577.  
  578. /** 
  579. * Add TinyMCE button 
  580. * 
  581. * @since 2.0.0.1 
  582. * @return void 
  583. */ 
  584. function gde_mce_addbuttons() { 
  585. // don't bother doing this stuff if the current user lacks permissions 
  586. if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) 
  587. return; 
  588.  
  589. // add only in Rich Editor mode 
  590. if ( get_user_option('rich_editing') == 'true') { 
  591. add_filter("mce_external_plugins", "gde_add_tinymce_plugin"); 
  592. add_filter('mce_buttons', 'gde_register_mce_button'); 
  593.  
  594. function gde_add_tinymce_plugin( $plugin_array ) { 
  595. // load the TinyMCE plugin 
  596. $plugin_array['gde'] = GDE_PLUGIN_URL . 'js/editor_plugin.js'; 
  597. return $plugin_array; 
  598.  
  599. function gde_register_mce_button( $buttons ) { 
  600. array_push( $buttons, "separator", "gde" ); 
  601. return $buttons; 
  602.  
  603. /** 
  604. * Check current beta status 
  605. * 
  606. * @since 2.5.0.1 
  607. * @return bool Whether or not the currently running version is a beta 
  608. */ 
  609. function gde_is_beta() { 
  610. global $pdata; 
  611.  
  612. // check for currently running beta version (contains any letter or hyphen) 
  613. if ( preg_match( '/[a-z-]/i', $pdata['Version'] ) ) { 
  614. // running a beta 
  615. return true; 
  616. } else { 
  617. return false; 
  618.  
  619. /** 
  620. * Display beta status 
  621. * 
  622. * @since 2.5.0.1 
  623. * @return void 
  624. */ 
  625. function gde_warn_on_plugin_page( $plugin_file ) { 
  626. global $pdata; 
  627.  
  628. if ( strstr( $plugin_file, $pdata['mainfile'] ) ) { 
  629.  
  630. // see if there's a release waiting first (prevent double messages) 
  631. $updates = (array) get_site_option( '_site_transient_update_plugins' ); 
  632. if ( isset( $updates['response'] ) && array_key_exists( $pdata['basename'], $updates['response'] ) ) { 
  633. return; 
  634.  
  635. if ( gde_is_beta() ) { 
  636. $message[] = __('You are running a pre-release version of Google Doc Embedder. Please watch this space for important updates.', 'google-document-embedder'); 
  637. } else { 
  638. $message = array(); 
  639.  
  640. // print message if any 
  641. $message = rtrim( implode( " ", $message ) ); 
  642. if ( ! empty( $message ) ) { 
  643. // style improvements?? 
  644. //add_action( 'admin_enqueue_scripts', 'gde_admin_beta_js' ); 
  645.  
  646. print(' 
  647. <tr class="plugin-update-tr"> 
  648. <td colspan="3" class="plugin-update colspanchange"> 
  649. <div class="update-message" style="background:#e3e3e3;"> 
  650. '.$message.' 
  651. </div> 
  652. </td> 
  653. </tr> 
  654. '); 
  655.  
  656. /** 
  657. * Check for existence and valid content of dx log 
  658. * 
  659. * @since 2.5.2.1 
  660. * @return bool 
  661. */ 
  662. function gde_log_available() { 
  663. global $wpdb; 
  664.  
  665. $table = $wpdb->base_prefix . 'gde_dx_log'; 
  666. $blogid = get_current_blog_id(); 
  667. $log = false; 
  668.  
  669. if ( $wpdb->get_var( "SHOW TABLES LIKE '$table'" ) == $table ) { 
  670. $c = $wpdb->get_var( "SELECT COUNT(*) FROM $table WHERE blogid = $blogid" ); 
  671. if ( $c > 0 ) { 
  672. $log = true; 
  673.  
  674. return $log; 
  675.  
  676. ?> 
.