PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/grand-media/config/setup.php

https://gitlab.com/che234/smproducciones
PHP | 321 lines | 230 code | 55 blank | 36 comment | 23 complexity | 930a7673175ca80cce2b5d2d6aec8ec6 MD5 | raw file
  1. <?php // don't load directly
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * Setup Gmedia plugin
  7. */
  8. /**
  9. * Setup the default option array for the plugin
  10. *
  11. * @access internal
  12. * @return array
  13. */
  14. function gmedia_default_options() {
  15. $gm['site_email'] = '';
  16. $gm['site_ID'] = '';
  17. $gm['site_title'] = '';
  18. $gm['site_description'] = '';
  19. $gm['mobile_app'] = 0;
  20. $gm['gmedia_post_slug'] = 'gmedia';
  21. $gm['gmedia_exclude_from_search'] = '0';
  22. $gm['gmedia_has_archive'] = '1';
  23. $gm['default_gmedia_comment_status'] = 'open'; // can be 'closed', 'open'
  24. $gm['gmedia_album_post_slug'] = 'gmedia-album';
  25. $gm['gmedia_album_has_archive'] = '1';
  26. $gm['gmedia_album_exclude_from_search'] = '0';
  27. $gm['gmedia_gallery_post_slug'] = 'gmedia-gallery';
  28. $gm['gmedia_gallery_has_archive'] = '0';
  29. $gm['gmedia_gallery_exclude_from_search'] = '0';
  30. $gm['default_gmedia_term_comment_status'] = 'closed'; // can be 'closed', 'open'
  31. $gm['uninstall_dropdata'] = 'none'; // can be 'all', 'none', 'db'
  32. $gm['in_tag_orderby'] = 'ID';
  33. $gm['in_tag_order'] = 'DESC';
  34. $gm['in_category_orderby'] = 'ID';
  35. $gm['in_category_order'] = 'DESC';
  36. $gm['in_album_orderby'] = 'ID';
  37. $gm['in_album_order'] = 'DESC';
  38. $gm['in_album_status'] = 'publish';
  39. $gm['default_gmedia_module'] = 'phantom';
  40. $gm['isolation_mode'] = '0';
  41. $gm['shortcode_raw'] = '0';
  42. $gm['debug_mode'] = WP_DEBUG ? '1' : '';
  43. $gm['endpoint'] = 'gmedia';
  44. $gm['gmediacloud_socialbuttons'] = '1';
  45. $gm['gmediacloud_footer_js'] = '';
  46. $gm['gmediacloud_footer_css'] = '';
  47. $gm['gmedia_post_types_support'] = '';
  48. $gm['folder']['image'] = 'image';
  49. $gm['folder']['image_thumb'] = 'image/thumb';
  50. $gm['folder']['image_original'] = 'image/original';
  51. $gm['folder']['audio'] = 'audio';
  52. $gm['folder']['video'] = 'video';
  53. $gm['folder']['text'] = 'text';
  54. $gm['folder']['application'] = 'application';
  55. $gm['folder']['module'] = 'module';
  56. $gm['thumb'] = array( 'width' => 300, 'height' => 300, 'quality' => 80, 'crop' => 0 );
  57. $gm['image'] = array( 'width' => 2200, 'height' => 2200, 'quality' => 85, 'crop' => 0 );
  58. $gm['modules_xml'] = 'https://dl.dropboxusercontent.com/u/6295502/gmedia_modules/modules_v1.xml';
  59. $gm['license_name'] = '';
  60. $gm['license_key'] = '';
  61. $gm['license_key2'] = '';
  62. $gm['taxonomies']['gmedia_category'] = array();
  63. $gm['taxonomies']['gmedia_tag'] = array();
  64. $gm['taxonomies']['gmedia_album'] = array();
  65. $gm['taxonomies']['gmedia_gallery'] = array(); // not linked with gmedia_term_relationships table
  66. $gm['taxonomies']['gmedia_module'] = array(); // not linked with gmedia_term_relationships table
  67. $gm['gm_screen_options']['per_page_sort_gmedia'] = 60;
  68. $gm['gm_screen_options']['per_page_gmedia'] = 30;
  69. $gm['gm_screen_options']['orderby_gmedia'] = 'ID';
  70. $gm['gm_screen_options']['sortorder_gmedia'] = 'DESC';
  71. $gm['gm_screen_options']['display_mode_gmedia'] = 'list';
  72. $gm['gm_screen_options']['grid_cell_fit_gmedia'] = false;
  73. $gm['gm_screen_options']['per_page_gmedia_album'] = 30;
  74. $gm['gm_screen_options']['orderby_gmedia_album'] = 'name';
  75. $gm['gm_screen_options']['sortorder_gmedia_album'] = 'ASC';
  76. $gm['gm_screen_options']['per_page_gmedia_category'] = 30;
  77. $gm['gm_screen_options']['orderby_gmedia_category'] = 'name';
  78. $gm['gm_screen_options']['sortorder_gmedia_category'] = 'ASC';
  79. $gm['gm_screen_options']['per_page_gmedia_tag'] = 30;
  80. $gm['gm_screen_options']['orderby_gmedia_tag'] = 'name';
  81. $gm['gm_screen_options']['sortorder_gmedia_tag'] = 'ASC';
  82. $gm['gm_screen_options']['per_page_gmedia_gallery'] = 30;
  83. $gm['gm_screen_options']['orderby_gmedia_gallery'] = 'name';
  84. $gm['gm_screen_options']['sortorder_gmedia_gallery'] = 'ASC';
  85. $gm['gm_screen_options']['per_page_wpmedia'] = 30;
  86. $gm['gm_screen_options']['orderby_wpmedia'] = 'ID';
  87. $gm['gm_screen_options']['sortorder_wpmedia'] = 'DESC';
  88. $gm['gm_screen_options']['uploader_runtime'] = 'auto';
  89. $gm['gm_screen_options']['uploader_chunking'] = 'true';
  90. $gm['gm_screen_options']['uploader_chunk_size'] = 8; // in Mb
  91. $gm['gm_screen_options']['uploader_urlstream_upload'] = 'false';
  92. $gm['gm_screen_options']['library_edit_quicktags'] = 'false';
  93. return $gm;
  94. }
  95. /**
  96. * sets gmedia capabilities to administrator role
  97. **/
  98. function gmedia_capabilities() {
  99. global $gmCore;
  100. // Set the capabilities for the administrator
  101. $role = get_role( 'administrator' );
  102. // We need this role, no other chance
  103. if ( empty( $role ) ) {
  104. update_option( "gmediaInitCheck", __( 'Sorry, Gmedia Gallery works only with a role called administrator', 'grand-media' ) );
  105. return;
  106. }
  107. $capabilities = $gmCore->plugin_capabilities();
  108. $capabilities = apply_filters( 'gmedia_capabilities', $capabilities );
  109. foreach ( $capabilities as $cap ) {
  110. $role->add_cap( $cap );
  111. }
  112. }
  113. /**
  114. * creates all tables for the plugin
  115. * called during register_activation hook
  116. *
  117. * @access internal
  118. * @return void
  119. **/
  120. function gmedia_install() {
  121. /** @var $wpdb wpdb */
  122. global $wpdb, $gmGallery, $gmCore;
  123. // Check for capability
  124. if ( ! current_user_can( 'activate_plugins' ) ) {
  125. return;
  126. }
  127. gmedia_capabilities();
  128. // upgrade function changed in WordPress 2.3
  129. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  130. // add charset & collate like wp core
  131. $charset_collate = '';
  132. if ( $wpdb->has_cap( 'collation' ) ) {
  133. if ( ! empty( $wpdb->charset ) ) {
  134. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  135. }
  136. if ( ! empty( $wpdb->collate ) ) {
  137. $charset_collate .= " COLLATE $wpdb->collate";
  138. }
  139. }
  140. $gmedia = $wpdb->prefix . 'gmedia';
  141. $gmedia_meta = $wpdb->prefix . 'gmedia_meta';
  142. $gmedia_term = $wpdb->prefix . 'gmedia_term';
  143. $gmedia_term_meta = $wpdb->prefix . 'gmedia_term_meta';
  144. $gmedia_term_relationships = $wpdb->prefix . 'gmedia_term_relationships';
  145. if ( $wpdb->get_var( "show tables like '$gmedia'" ) != $gmedia ) {
  146. $sql = "CREATE TABLE {$gmedia} (
  147. ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  148. author BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
  149. date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  150. description LONGTEXT NOT NULL,
  151. title TEXT NOT NULL,
  152. gmuid VARCHAR(255) NOT NULL DEFAULT '',
  153. link VARCHAR(255) NOT NULL DEFAULT '',
  154. modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  155. mime_type VARCHAR(100) NOT NULL DEFAULT '',
  156. status VARCHAR(20) NOT NULL DEFAULT 'publish',
  157. post_id BIGINT(20) UNSIGNED DEFAULT NULL,
  158. PRIMARY KEY (ID),
  159. KEY gmuid (gmuid),
  160. KEY type_status_date (mime_type,status,date,ID),
  161. KEY author (author),
  162. KEY post_id (post_id)
  163. ) {$charset_collate}";
  164. dbDelta( $sql );
  165. }
  166. if ( $wpdb->get_var( "show tables like '$gmedia_meta'" ) != $gmedia_meta ) {
  167. $sql = "CREATE TABLE {$gmedia_meta} (
  168. meta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  169. gmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
  170. meta_key VARCHAR(255) DEFAULT NULL,
  171. meta_value LONGTEXT,
  172. PRIMARY KEY (meta_id),
  173. KEY gmedia_id (gmedia_id),
  174. KEY meta_key (meta_key),
  175. INDEX `_hash` (meta_value(32))
  176. ) {$charset_collate}";
  177. dbDelta( $sql );
  178. }
  179. if ( $wpdb->get_var( "show tables like '$gmedia_term'" ) != $gmedia_term ) {
  180. $sql = "CREATE TABLE {$gmedia_term} (
  181. term_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  182. name VARCHAR(200) NOT NULL DEFAULT '',
  183. taxonomy VARCHAR(32) NOT NULL DEFAULT '',
  184. description LONGTEXT NOT NULL,
  185. global BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
  186. count BIGINT(20) NOT NULL DEFAULT '0',
  187. status VARCHAR(20) NOT NULL DEFAULT 'publish',
  188. PRIMARY KEY (term_id),
  189. KEY taxonomy (taxonomy),
  190. KEY name (name)
  191. ) {$charset_collate}";
  192. dbDelta( $sql );
  193. }
  194. if ( $wpdb->get_var( "show tables like '$gmedia_term_meta'" ) != $gmedia_term_meta ) {
  195. $sql = "CREATE TABLE {$gmedia_term_meta} (
  196. meta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  197. gmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
  198. meta_key VARCHAR(255) DEFAULT NULL,
  199. meta_value LONGTEXT,
  200. PRIMARY KEY (meta_id),
  201. KEY gmedia_term_id (gmedia_term_id),
  202. KEY meta_key (meta_key)
  203. ) {$charset_collate}";
  204. dbDelta( $sql );
  205. }
  206. if ( $wpdb->get_var( "show tables like '$gmedia_term_relationships'" ) != $gmedia_term_relationships ) {
  207. $sql = "CREATE TABLE {$gmedia_term_relationships} (
  208. gmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
  209. gmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
  210. term_order INT(11) NOT NULL DEFAULT '0',
  211. gmedia_order INT(11) NOT NULL DEFAULT '0',
  212. PRIMARY KEY (gmedia_id,gmedia_term_id),
  213. KEY gmedia_term_id (gmedia_term_id)
  214. ) {$charset_collate}";
  215. dbDelta( $sql );
  216. }
  217. // check one table again, to be sure
  218. if ( $wpdb->get_var( "show tables like '$gmedia'" ) != $gmedia ) {
  219. update_option( "gmediaInitCheck", __( 'GmediaGallery: Tables could not created, please check your database settings', 'grand-media' ) );
  220. return;
  221. }
  222. if ( ! get_option( 'GmediaHashID_salt' ) ) {
  223. $ustr = wp_generate_password( 12, false );
  224. add_option( 'GmediaHashID_salt', $ustr );
  225. }
  226. // set the default settings, if we didn't upgrade
  227. if ( empty( $gmGallery->options ) ) {
  228. $gmGallery->options = gmedia_default_options();
  229. // Set installation date
  230. if ( ! get_option( 'gmediaInstallDate' ) ) {
  231. $installDate = time();
  232. add_option( 'gmediaInstallDate', $installDate );
  233. }
  234. update_option( 'gmediaOptions', $gmGallery->options );
  235. } else {
  236. $default_options = gmedia_default_options();
  237. unset( $gmGallery->options['folder'], $gmGallery->options['taxonomies'] );
  238. $new_options = $gmCore->array_diff_key_recursive( $default_options, $gmGallery->options );
  239. $gmGallery->options = $gmCore->array_replace_recursive( $gmGallery->options, $new_options );
  240. update_option( 'gmediaOptions', $gmGallery->options );
  241. }
  242. // try to make gallery dirs if not exists
  243. foreach ( $gmGallery->options['folder'] as $folder ) {
  244. wp_mkdir_p( $gmCore->upload['path'] . '/' . $folder );
  245. }
  246. wp_clear_scheduled_hook( 'gmedia_app_cronjob' );
  247. wp_schedule_event( time(), 'gmedia_app', 'gmedia_app_cronjob' );
  248. add_option( 'gmediaActivated', time() );
  249. }
  250. /**
  251. * Called via Setup and register_deactivate hook
  252. *
  253. * @access internal
  254. * @return void
  255. */
  256. function gmedia_deactivate() {
  257. global $gmCore;
  258. flush_rewrite_rules( false );
  259. wp_clear_scheduled_hook( 'gmedia_app_cronjob' );
  260. $options = get_option( 'gmediaOptions' );
  261. if ( (int) $options['mobile_app'] ) {
  262. $gmCore->app_service( 'app_deactivateplugin' );
  263. }
  264. // remove & reset the init check option
  265. delete_option( 'gmediaInitCheck' );
  266. }