PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/file-gallery/file-gallery.php

https://bitbucket.org/Wallynm/iptb
PHP | 1333 lines | 1136 code | 96 blank | 101 comment | 46 complexity | 37574915dd0c3b8df87f3a5c60e6447a MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, GPL-3.0
  1. <?php
  2. /*
  3. Plugin Name: File Gallery
  4. Plugin URI: http://skyphe.org/code/wordpress/file-gallery/
  5. Version: 1.7.4
  6. Description: "File Gallery" extends WordPress' media (attachments) capabilities by adding a new gallery shortcode handler with templating support, a new interface for attachment handling when editing posts, and much more.
  7. Author: Bruno "Aesqe" Babic
  8. Author URI: http://skyphe.org
  9. ////////////////////////////////////////////////////////////////////////////
  10. This program is free software: you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation, either version 3 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. ////////////////////////////////////////////////////////////////////////////
  21. */
  22. /**
  23. * Setup default File Gallery options
  24. */
  25. define('FILE_GALLERY_VERSION', '1.7.4');
  26. define('FILE_GALLERY_DEFAULT_TEMPLATES', serialize( array('default', 'file-gallery', 'list', 'simple') ) );
  27. /**
  28. * Just a variables placeholder for now
  29. *
  30. * @since 1.6.5.1
  31. */
  32. class File_Gallery
  33. {
  34. /**
  35. * settings,
  36. * their default values,
  37. * and false default values
  38. *
  39. * @since 1.7
  40. */
  41. var $settings = array();
  42. var $defaults = array();
  43. var $false_defaults = array();
  44. var $debug = array();
  45. /**
  46. * Holds the ID number of current post's gallery
  47. */
  48. var $gallery_id;
  49. /**
  50. * Holds gallery options overriden
  51. * via 'file_gallery_overrides' template function
  52. */
  53. var $overrides;
  54. /**
  55. * Whether Attachment custom fields plugin is
  56. * installed or not
  57. */
  58. var $acf = false;
  59. /**
  60. * Whether SSL is on for wp-admin
  61. */
  62. var $ssl_admin = false;
  63. /**
  64. * Current version of this plugin
  65. */
  66. var $version = FILE_GALLERY_VERSION;
  67. /***/
  68. function __construct()
  69. {
  70. $this->File_Gallery();
  71. }
  72. /***/
  73. function File_Gallery()
  74. {
  75. // Checks if Attachment custom fields plugin is installed (not released yet)
  76. if( false !== strpos(serialize(get_option('active_plugins')), 'attachment-custom-fields.php') )
  77. $this->acf = true;
  78. if( defined('FORCE_SSL_ADMIN') && true === FORCE_SSL_ADMIN )
  79. $this->ssl_admin = true;
  80. }
  81. function debug_add( $section, $vars )
  82. {
  83. if( ! FILE_GALLERY_DEBUG )
  84. return;
  85. foreach( $vars as $k => $v )
  86. {
  87. $type = gettype($v);
  88. if( 'boolean' === $type )
  89. $v = false === $v ? 'false' : 'true';
  90. $this->debug[$section][$k] = $type . ': ' . $v;
  91. }
  92. }
  93. function debug_print()
  94. {
  95. if( ! FILE_GALLERY_DEBUG )
  96. return;
  97. if( isset($_GET['file_gallery_debug']) )
  98. {
  99. $vars = get_object_vars($this);
  100. unset($vars['defaults']);
  101. unset($vars['false_defaults']);
  102. unset($vars['settings']);
  103. function block($a)
  104. {
  105. $out = '<ul>';
  106. foreach($a as $k => $v)
  107. {
  108. $out .= '<li>[' . $k . '] => ';
  109. if( is_array($v) )
  110. $out .= block($v);
  111. else
  112. $out .= empty($v) ? '""' : $v;
  113. $out .= '</li>' . "\n";
  114. }
  115. $out .= '</ul>' . "\n";
  116. return $out;
  117. }
  118. return block($vars);
  119. }
  120. }
  121. };
  122. function file_gallery_debug_print( $content )
  123. {
  124. global $file_gallery;
  125. return $content . $file_gallery->debug_print();
  126. }
  127. if( isset($_GET['file_gallery_debug']) )
  128. add_action('the_content', 'file_gallery_debug_print', 100);
  129. // Begin
  130. $file_gallery = new File_Gallery();
  131. /**
  132. *
  133. * @since 1.7
  134. */
  135. function file_gallery_do_settings()
  136. {
  137. global $file_gallery;
  138. $file_gallery->settings = array(
  139. 'disable_shortcode_handler' => array(
  140. 'default' => 0,
  141. 'display' => true,
  142. 'title' => __("Disable 'File Gallery' handling of [gallery] shortcode?", 'file-gallery'),
  143. 'type' => 'checkbox',
  144. 'section' => 0,
  145. 'position' => 0
  146. ),
  147. 'show_on_post_type' => array(
  148. 'default' => 1,
  149. 'display' => true,
  150. 'title' => __('Display File Gallery on which post types?', 'file-gallery'),
  151. 'type' => 'checkbox',
  152. 'values' => file_gallery_post_type_checkboxes(),
  153. 'section' => 0,
  154. 'position' => 0
  155. ),
  156. 'alt_color_scheme' => array(
  157. 'default' => 1,
  158. 'display' => true,
  159. 'title' => __('Use alternative color scheme (a bit more contrast)?', 'file-gallery'),
  160. 'type' => 'checkbox',
  161. 'section' => 0,
  162. 'position' => 0
  163. ),
  164. 'pagination_count' => array(
  165. 'default' => 9,
  166. 'display' => true,
  167. 'title' => __('How many page links should be shown in pagination?', 'file-gallery'),
  168. 'type' => 'text',
  169. 'section' => 0,
  170. 'position' => 0
  171. ),
  172. 'auto_enqueued_scripts' => array(
  173. 'default' => 'thickbox',
  174. 'display' => true,
  175. 'title' => __('Auto enqueue lightbox scripts for which link classes (separate with commas)?', 'file-gallery'),
  176. 'type' => 'text',
  177. 'section' => 0,
  178. 'position' => 0
  179. ),
  180. 'default_metabox_image_size' => array(
  181. 'default' => 'thumbnail',
  182. 'display' => true,
  183. 'title' => __('Default WordPress image size for thumbnails in File Gallery metabox on post editing screens?', 'file-gallery'),
  184. 'type' => 'select',
  185. 'values' => file_gallery_dropdown( 'default_metabox_image_size', 'image_size' ),
  186. 'section' => 0,
  187. 'position' => 0
  188. ),
  189. 'default_metabox_image_width' => array(
  190. 'default' => 75,
  191. 'display' => true,
  192. 'title' => __('Default width (in pixels) for thumbnails in File Gallery metabox on post editing screens?', 'file-gallery'),
  193. 'type' => 'text',
  194. 'section' => 0,
  195. 'position' => 0
  196. ),
  197. 'default_image_size' => array(
  198. 'default' => 'thumbnail',
  199. 'display' => true,
  200. 'title' => '</th></tr><tr><td colspan="2"><strong style="display: block; margin-top: -15px; font-size: 115%; color: #21759B;">' . __('Some default values for when inserting a gallery into a post', 'file-gallery') . '...</strong></td></tr><tr><td colspan="2"><p id="file-gallery-media-settings-notice" style="margin: 0; background-color: #FFFFE8; border-color: #EEEED0; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; border-style: solid; border-width: 1px; padding: 0.6em;">' . sprintf(__('The following two blocks of options <strong>do not</strong> affect the output/display of your galleries - they are here only so you could set default values for File Gallery metabox on post editing screen. <a href="%s/help/index.html#settings_page" target="_blank">More information is available in the help file</a>.', "file-gallery"), FILE_GALLERY_URL) . '</p></td></tr><tr valign="top"><th scope="row">' . __('size', 'file-gallery'),
  201. 'type' => 'select',
  202. 'values' => file_gallery_dropdown( 'default_image_size', 'image_size' ),
  203. 'section' => 0,
  204. 'position' => 0
  205. ),
  206. 'default_linkto' => array(
  207. 'default' => 'attachment',
  208. 'display' => true,
  209. 'title' => __('link', 'file-gallery'),
  210. 'type' => 'select',
  211. 'values' => file_gallery_dropdown( 'default_linkto', 'linkto' ),
  212. 'section' => 0,
  213. 'position' => 0
  214. ),
  215. 'default_linked_image_size' => array(
  216. 'default' => 'full',
  217. 'display' => true,
  218. 'title' => __('linked image size', 'file-gallery'),
  219. 'type' => 'select',
  220. 'values' => file_gallery_dropdown( 'default_linked_image_size', 'image_size' ),
  221. 'section' => 0,
  222. 'position' => 0
  223. ),
  224. 'default_external_url' => array(
  225. 'default' => '',
  226. 'display' => true,
  227. 'title' => __('external url', 'file-gallery'),
  228. 'type' => 'text',
  229. 'section' => 0,
  230. 'position' => 0
  231. ),
  232. 'default_orderby' => array(
  233. 'default' => '',
  234. 'display' => true,
  235. 'title' => __('order by', 'file-gallery'),
  236. 'type' => 'select',
  237. 'values' => file_gallery_dropdown( 'default_orderby', 'orderby' ),
  238. 'section' => 0,
  239. 'position' => 0
  240. ),
  241. 'default_order' => array(
  242. 'default' => 'ASC',
  243. 'display' => true,
  244. 'title' => __('order', 'file-gallery'),
  245. 'type' => 'select',
  246. 'values' => file_gallery_dropdown( 'default_order', 'order' ),
  247. 'section' => 0,
  248. 'position' => 0
  249. ),
  250. 'default_template' => array(
  251. 'default' => 'default',
  252. 'display' => true,
  253. 'title' => __('template', 'file-gallery'),
  254. 'type' => 'select',
  255. 'values' => file_gallery_dropdown( 'default_template', 'template' ),
  256. 'section' => 0,
  257. 'position' => 0
  258. ),
  259. 'default_linkclass' => array(
  260. 'default' => '',
  261. 'display' => true,
  262. 'title' => __('link class', 'file-gallery'),
  263. 'type' => 'text',
  264. 'section' => 0,
  265. 'position' => 0
  266. ),
  267. 'default_imageclass' => array(
  268. 'default' => '',
  269. 'display' => true,
  270. 'title' => __('image class', 'file-gallery'),
  271. 'type' => 'text',
  272. 'section' => 0,
  273. 'position' => 0
  274. ),
  275. 'default_columns' => array(
  276. 'default' => 3,
  277. 'display' => true,
  278. 'title' => __('columns', 'file-gallery'),
  279. 'type' => 'select',
  280. 'values' => file_gallery_dropdown( 'default_columns', 'columns' ),
  281. 'section' => 0,
  282. 'position' => 0
  283. ),
  284. 'default_mimetype' => array(
  285. 'default' => '',
  286. 'display' => true,
  287. 'title' => __('mime type', 'file-gallery'),
  288. 'type' => 'text',
  289. 'section' => 0,
  290. 'position' => 0
  291. ),
  292. 'default_galleryclass' => array(
  293. 'default' => '',
  294. 'display' => true,
  295. 'title' => __('gallery class', 'file-gallery'),
  296. 'type' => 'text',
  297. 'section' => 0,
  298. 'position' => 0
  299. ),
  300. 'single_default_image_size' => array(
  301. 'default' => 'thumbnail',
  302. 'display' => true,
  303. 'title' => '</th></tr><tr><td colspan="2"><strong style="display: block; margin-top: -15px; font-size: 115%; color: #21759B;">' . __('...and for when inserting (a) single image(s) into a post', 'file-gallery') . '</strong></td></tr><tr valign="top"><th scope="row">' . __('size', 'file-gallery'),
  304. 'type' => 'select',
  305. 'values' => file_gallery_dropdown( 'single_default_image_size', 'image_size' ),
  306. 'section' => 0,
  307. 'position' => 0
  308. ),
  309. 'single_default_linkto' => array(
  310. 'default' => 'attachment',
  311. 'display' => true,
  312. 'title' => __('link', 'file-gallery'),
  313. 'type' => 'select',
  314. 'values' => file_gallery_dropdown( 'single_default_linkto', 'linkto' ),
  315. 'section' => 0,
  316. 'position' => 0
  317. ),
  318. 'single_default_external_url' => array(
  319. 'default' => '',
  320. 'display' => true,
  321. 'title' => __('external url', 'file-gallery'),
  322. 'type' => 'text',
  323. 'section' => 0,
  324. 'position' => 0
  325. ),
  326. 'single_default_linkclass' => array(
  327. 'default' => '',
  328. 'display' => true,
  329. 'title' => __('link class', 'file-gallery'),
  330. 'type' => 'text',
  331. 'section' => 0,
  332. 'position' => 0
  333. ),
  334. 'single_default_imageclass' => array(
  335. 'default' => '',
  336. 'display' => true,
  337. 'title' => __('image class', 'file-gallery'),
  338. 'type' => 'text',
  339. 'section' => 0,
  340. 'position' => 0
  341. ),
  342. 'single_default_align' => array(
  343. 'default' => 'none',
  344. 'display' => true,
  345. 'title' => __('alignment', 'file-gallery'),
  346. 'type' => 'select',
  347. 'values' => file_gallery_dropdown( 'single_default_align', 'align' ),
  348. 'section' => 0,
  349. 'position' => 0
  350. ),
  351. 'cache' => array(
  352. 'default' => 0,
  353. 'display' => true,
  354. 'title' => '</th></tr><tr><td colspan="2"><strong style="display: block; margin-top: -15px; font-size: 115%; color: #21759B;">' . __('Cache', 'file-gallery') . '</strong></td></tr><tr valign="top"><th scope="row">' . __('Enable caching?', 'file-gallery'),
  355. 'type' => 'checkbox',
  356. 'section' => 0,
  357. 'position' => 0
  358. ),
  359. 'cache_time' => array(
  360. 'default' => 3600, // == 1 hour
  361. 'display' => true,
  362. 'title' => __("Cache expires after how many seconds? (leave as is if you don't know what it means)", 'file-gallery'),
  363. 'type' => 'text',
  364. 'section' => 0,
  365. 'position' => 0
  366. ),
  367. 'cache_non_html_output' => array(
  368. 'default' => 0,
  369. 'display' => true,
  370. 'title' => __('Cache non-HTML gallery output (<em>array, object, json</em>)', 'file-gallery'),
  371. 'type' => 'checkbox',
  372. 'section' => 0,
  373. 'position' => 0
  374. ),
  375. 'e_display_attachment_count' => array(
  376. 'default' => 1,
  377. 'display' => true,
  378. 'title' => '</th></tr><tr><td colspan="2"><strong style="display: block; margin-top: -15px; font-size: 115%; color: #21759B;">' . __('Edit screens options', 'file-gallery') . '</strong></td></tr><tr valign="top"><th scope="row">' . __('Display attachment count?', 'file-gallery'),
  379. 'type' => 'checkbox',
  380. 'section' => 0,
  381. 'position' => 0
  382. ),
  383. 'library_filter_duplicates' => array(
  384. 'default' => 1,
  385. 'display' => true,
  386. 'title' => __('Filter out duplicate attachments (copies) when browsing media library?', 'file-gallery'),
  387. 'type' => 'checkbox',
  388. 'section' => 0,
  389. 'position' => 0
  390. ),
  391. 'e_display_media_tags' => array(
  392. 'default' => 1,
  393. 'display' => true,
  394. 'title' => __('Display media tags for attachments in media library?', 'file-gallery'),
  395. 'type' => 'checkbox',
  396. 'section' => 0,
  397. 'position' => 0
  398. ),
  399. 'e_display_post_thumb' => array(
  400. 'default' => 1,
  401. 'display' => true,
  402. 'title' => __('Display post thumb (if set)?', 'file-gallery'),
  403. 'type' => 'checkbox',
  404. 'section' => 0,
  405. 'position' => 0
  406. ),
  407. 'in_excerpt' => array(
  408. 'default' => 1,
  409. 'display' => true,
  410. 'title' => '</th></tr><tr><td colspan="2"><strong style="display: block; margin-top: -15px; font-size: 115%; color: #21759B;">' . __('Other options', 'file-gallery') . '</strong></td></tr><tr valign="top"><th scope="row">' . __('Display galleries within post excerpts?', 'file-gallery'),
  411. 'type' => 'checkbox',
  412. 'section' => 0,
  413. 'position' => 0
  414. ),
  415. 'in_excerpt_replace_content' => array(
  416. 'default' => '<p><strong>(' . __('galleries are shown on full posts only', 'file-gallery') . ')</strong></p>',
  417. 'display' => true,
  418. 'title' => __("Replacement text for galleries within post excerpts (if you haven't checked the above option)", 'file-gallery'),
  419. 'type' => 'textarea',
  420. 'section' => 0,
  421. 'position' => 0
  422. ),
  423. 'display_gallery_fieldset' => array(
  424. 'default' => 1,
  425. 'display' => true,
  426. 'title' => __('Display options for inserting galleries into a post?', 'file-gallery'),
  427. 'type' => 'checkbox',
  428. 'section' => 0,
  429. 'position' => 0
  430. ),
  431. 'display_single_fieldset' => array(
  432. 'default' => 1,
  433. 'display' => true,
  434. 'title' => __('Display options for inserting single images into a post?', 'file-gallery'),
  435. 'type' => 'checkbox',
  436. 'section' => 0,
  437. 'position' => 0
  438. ),
  439. 'display_acf' => array(
  440. 'default' => 1,
  441. 'display' => true,
  442. 'title' => __('Display attachment custom fields?', 'file-gallery'),
  443. 'type' => 'checkbox',
  444. 'section' => 0,
  445. 'position' => 0
  446. ),
  447. 'insert_gallery_button' => array(
  448. 'default' => 1,
  449. 'display' => true,
  450. 'title' => __("Display 'insert gallery' button even if gallery options are hidden?", 'file-gallery'),
  451. 'type' => 'checkbox',
  452. 'section' => 0,
  453. 'position' => 0
  454. ),
  455. 'insert_single_button' => array(
  456. 'default' => 1,
  457. 'display' => true,
  458. 'title' => __("Display 'insert single image(s)' button even if single image options are hidden?", 'file-gallery'),
  459. 'type' => 'checkbox',
  460. 'section' => 0,
  461. 'position' => 0
  462. ),
  463. 'del_options_on_deactivate' => array(
  464. 'default' => 0,
  465. 'display' => true,
  466. 'title' => __('Delete all options on deactivation?', 'file-gallery'),
  467. 'type' => 'checkbox',
  468. 'section' => 0,
  469. 'position' => 0
  470. ),
  471. /**
  472. * Disabled options
  473. */
  474. 'version' => array(
  475. 'default' => FILE_GALLERY_VERSION,
  476. 'display' => 'disabled',
  477. 'title' => __('File Gallery version', 'file-gallery'),
  478. 'type' => 'text',
  479. 'section' => 0,
  480. 'position' => 0
  481. ),
  482. 'folder' => array(
  483. 'default' => file_gallery_https( FILE_GALLERY_URL ),
  484. 'display' => 'disabled',
  485. 'title' => __('File Gallery folder', 'file-gallery'),
  486. 'type' => 'text',
  487. 'section' => 0,
  488. 'position' => 0
  489. ),
  490. 'abspath' => array(
  491. 'default' => FILE_GALLERY_ABSPATH,
  492. 'display' => 'disabled',
  493. 'title' => __('File Gallery path', 'file-gallery'),
  494. 'type' => 'text',
  495. 'section' => 0,
  496. 'position' => 100
  497. ),
  498. 'media_tag_taxonomy_name' => array(
  499. 'default' => 'media_tag',
  500. 'display' => 'disabled',
  501. 'title' => __('Media tags Taxonomy name', 'file-gallery'),
  502. 'type' => 'text',
  503. 'section' => 0,
  504. 'position' => 0
  505. ),
  506. 'media_tag_taxonomy_slug' => array(
  507. 'default' => 'media-tag',
  508. 'display' => 'disabled',
  509. 'title' => __('Media tags URL slug', 'file-gallery'),
  510. 'type' => 'text',
  511. 'section' => 0,
  512. 'position' => 0
  513. ),
  514. /**
  515. * Hidden options
  516. */
  517. 'insert_options_state' => array(
  518. 'default' => 1,
  519. 'display' => true,
  520. 'title' => __('Gallery insert options state', 'file-gallery'),
  521. 'type' => 'checkbox',
  522. 'section' => 0,
  523. 'position' => 0
  524. ),
  525. 'insert_single_options_state' => array(
  526. 'default' => 1,
  527. 'display' => true,
  528. 'title' => __('Single images insert options state', 'file-gallery'),
  529. 'type' => 'checkbox',
  530. 'section' => 0,
  531. 'position' => 0
  532. ),
  533. 'acf_state' => array(
  534. 'default' => 1,
  535. 'display' => true,
  536. 'title' => __('Attachment custom fields state', 'file-gallery'),
  537. 'type' => 'checkbox',
  538. 'section' => 0,
  539. 'position' => 0
  540. )
  541. );
  542. foreach( $file_gallery->settings as $key => $val )
  543. {
  544. $file_gallery->defaults[$key] = $val['default'];
  545. if( is_bool($val['default']) || 1 === $val['default'] || 0 === $val['default'] )
  546. $file_gallery->false_defaults[$key] = 0;
  547. }
  548. }
  549. /**
  550. * Registers default File Gallery options when plugin is activated
  551. */
  552. function file_gallery_activate()
  553. {
  554. global $file_gallery;
  555. file_gallery_plugins_loaded();
  556. file_gallery_after_setup_theme();
  557. file_gallery_do_settings();
  558. $defaults = $file_gallery->defaults;
  559. // if options already exist, upgrade
  560. if( $options = get_option('file_gallery') )
  561. {
  562. // preserve display options when upgrading from below 1.6.5.3
  563. if( ! isset($options['display_acf']) )
  564. {
  565. if( isset($options['insert_options_states']) )
  566. $states = explode(',', $options['insert_options_states']);
  567. else
  568. $states = array('1', '1');
  569. if( isset($options['display_insert_fieldsets']) )
  570. $display = $options['display_insert_fieldsets'];
  571. else
  572. $display = 1;
  573. $defaults['insert_options_state'] = (int) $states[0];
  574. $defaults['insert_single_options_state'] = (int) $states[1];
  575. $defaults['acf_state'] = 1;
  576. $defaults['display_gallery_fieldset'] = $display;
  577. $defaults['display_single_fieldset'] = $display;
  578. $defaults['display_acf'] = 1;
  579. }
  580. $defaults = file_gallery_parse_args( $options, $defaults);
  581. $defaults['folder'] = file_gallery_https( FILE_GALLERY_URL );
  582. $defaults['abspath'] = FILE_GALLERY_ABSPATH;
  583. $defaults['version'] = FILE_GALLERY_VERSION;
  584. }
  585. else // Fresh installation, show on posts and pages
  586. {
  587. $defaults['show_on_post_type_post'] = 1;
  588. $defaults['show_on_post_type_page'] = 1;
  589. }
  590. update_option('file_gallery', $defaults);
  591. // clear any existing cache
  592. file_gallery_clear_cache();
  593. }
  594. register_activation_hook( __FILE__, 'file_gallery_activate' );
  595. /**
  596. * Do activation procedure on plugin upgrade
  597. */
  598. function file_gallery_upgrade()
  599. {
  600. $options = get_option('file_gallery');
  601. if( $options && version_compare( $options['version'], FILE_GALLERY_VERSION, '<') )
  602. file_gallery_activate();
  603. }
  604. add_action( 'admin_init', 'file_gallery_upgrade' );
  605. /**
  606. * Some cleanup on deactivation
  607. */
  608. function file_gallery_deactivate()
  609. {
  610. file_gallery_clear_cache();
  611. $options = get_option('file_gallery');
  612. if( isset($options['del_options_on_deactivate']) && true == $options['del_options_on_deactivate'] )
  613. delete_option('file_gallery');
  614. }
  615. register_deactivation_hook( __FILE__, 'file_gallery_deactivate' );
  616. /**
  617. * Support for other plugins
  618. *
  619. * Supported so far:
  620. * - WordPress Mobile Edition
  621. * - Media Tags
  622. */
  623. function file_gallery_plugins_loaded()
  624. {
  625. $file_gallery_abspath = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
  626. $file_gallery_abspath = str_replace('\\', '/', $file_gallery_abspath);
  627. $file_gallery_abspath = preg_replace('#/+#', '/', $file_gallery_abspath);
  628. // file gallery directories and template names
  629. define('FILE_GALLERY_URL', WP_PLUGIN_URL . '/' . basename( dirname(__FILE__) ));
  630. define('FILE_GALLERY_ABSPATH', $file_gallery_abspath);
  631. $mobile = false;
  632. $options = get_option('file_gallery');
  633. // WordPress Mobile Edition
  634. if( function_exists('cfmobi_check_mobile') && cfmobi_check_mobile() )
  635. {
  636. $mobile = true;
  637. if( ! isset($options['disable_shortcode_handler']) || true != $options['disable_shortcode_handler'] )
  638. add_filter('stylesheet_uri', 'file_gallery_mobile_css');
  639. }
  640. define('FILE_GALLERY_MOBILE', $mobile);
  641. file_gallery_media_tags_get_taxonomy_slug();
  642. }
  643. add_action('plugins_loaded', 'file_gallery_plugins_loaded', 100);
  644. /*
  645. * Some constants you can filter even with your theme's functions.php file
  646. *
  647. * @since 1.6.3
  648. */
  649. function file_gallery_after_setup_theme()
  650. {
  651. $stylesheet_directory = get_stylesheet_directory();
  652. $file_gallery_theme_abspath = str_replace('\\', '/', $stylesheet_directory);
  653. $file_gallery_theme_abspath = preg_replace('#/+#', '/', $file_gallery_theme_abspath);
  654. define( 'FILE_GALLERY_THEME_ABSPATH', $file_gallery_theme_abspath );
  655. define( 'FILE_GALLERY_THEME_TEMPLATES_ABSPATH', apply_filters('file_gallery_templates_folder_abspath', FILE_GALLERY_THEME_ABSPATH . '/file-gallery-templates') ) ;
  656. define( 'FILE_GALLERY_THEME_TEMPLATES_URL', apply_filters('file_gallery_templates_folder_url', get_bloginfo('stylesheet_directory') . '/file-gallery-templates') );
  657. define( 'FILE_GALLERY_CONTENT_TEMPLATES_ABSPATH', apply_filters('file_gallery_content_templates_folder_abspath', WP_CONTENT_DIR . '/file-gallery-templates') );
  658. define( 'FILE_GALLERY_CONTENT_TEMPLATES_URL', apply_filters('file_gallery_content_templates_folder_url', WP_CONTENT_URL . '/file-gallery-templates') );
  659. define( 'FILE_GALLERY_DEFAULT_TEMPLATE_URL', apply_filters('file_gallery_default_template_url', FILE_GALLERY_URL . '/templates/default') );
  660. define( 'FILE_GALLERY_DEFAULT_TEMPLATE_ABSPATH', apply_filters('file_gallery_default_template_abspath', FILE_GALLERY_ABSPATH . '/templates/default') );
  661. define( 'FILE_GALLERY_DEFAULT_TEMPLATE_NAME', apply_filters('file_gallery_default_template_name', 'default') );
  662. // file icons directory
  663. $file_gallery_crystal_url = get_bloginfo('wpurl') . '/' . WPINC . '/images/crystal';
  664. if( ! defined( 'FILE_GALLERY_CRYSTAL_URL' ) )
  665. define( 'FILE_GALLERY_CRYSTAL_URL', apply_filters('file_gallery_crystal_url', $file_gallery_crystal_url) );
  666. // display debug information
  667. if( ! defined( 'FILE_GALLERY_DEBUG' ) )
  668. define( 'FILE_GALLERY_DEBUG', false );
  669. }
  670. add_action('after_setup_theme', 'file_gallery_after_setup_theme');
  671. /**
  672. * Adds a link to plugin's settings and help pages (shows up next to the
  673. * deactivation link on the plugins management page)
  674. */
  675. function file_gallery_plugin_action_links( $links )
  676. {
  677. array_unshift( $links, '<a href="options-media.php">' . __('Settings', 'file-gallery') . '</a>' );
  678. array_unshift( $links, '<a href="' . FILE_GALLERY_URL . '/help/index.html" target="_blank">' . __('Help', 'file-gallery') . '</a>' );
  679. return $links;
  680. }
  681. add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'file_gallery_plugin_action_links' );
  682. /**
  683. * Adds media_tags taxonomy so we can tag attachments
  684. */
  685. function file_gallery_add_textdomain_and_taxonomies()
  686. {
  687. global $mediatags;
  688. load_plugin_textdomain('file-gallery', false, dirname(plugin_basename(__FILE__)) . '/languages');
  689. if( ! (isset($mediatags) && is_a($mediatags, 'MediaTags') && defined('MEDIA_TAGS_TAXONOMY')) )
  690. {
  691. $args = array(
  692. 'public' => true,
  693. 'update_count_callback' => 'file_gallery_update_media_tag_term_count',
  694. 'rewrite' => array(
  695. 'slug' => FILE_GALLERY_MEDIA_TAG_SLUG
  696. ),
  697. 'labels' => array(
  698. 'name' => __('Media tags', 'file-gallery'),
  699. 'singular_label' => __('Media tag', 'file-gallery')
  700. )
  701. );
  702. register_taxonomy( FILE_GALLERY_MEDIA_TAG_NAME, 'attachment', $args );
  703. }
  704. if( true == get_option('file_gallery_flush_rewrite_rules') )
  705. {
  706. global $wp_rewrite;
  707. $wp_rewrite->flush_rules( false );
  708. delete_option('file_gallery_flush_rewrite_rules');
  709. }
  710. }
  711. add_action('init', 'file_gallery_add_textdomain_and_taxonomies', 100);
  712. /**
  713. * A slightly modified copy of WordPress' _update_post_term_count function
  714. *
  715. * Updates number of posts that use a certain media_tag
  716. */
  717. function file_gallery_update_media_tag_term_count( $terms )
  718. {
  719. global $wpdb;
  720. foreach ( (array) $terms as $term )
  721. {
  722. $count = $wpdb->get_var(
  723. $wpdb->prepare(
  724. "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts
  725. WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id
  726. AND post_type = 'attachment'
  727. AND term_taxonomy_id = %d",
  728. $term )
  729. );
  730. do_action( 'edit_term_taxonomy', $term );
  731. $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
  732. do_action( 'edited_term_taxonomy', $term );
  733. }
  734. // clear cache
  735. file_gallery_clear_cache('mediatags_all');
  736. }
  737. /**
  738. * Adds media tags submenu
  739. */
  740. function file_gallery_media_submenu()
  741. {
  742. global $mediatags;
  743. if( ! (isset($mediatags) && is_a($mediatags, 'MediaTags') && defined('MEDIA_TAGS_TAXONOMY')) )
  744. add_submenu_page('upload.php', __('Media tags', 'file-gallery'), __('Media tags', 'file-gallery'), 'upload_files', 'edit-tags.php?taxonomy=' . FILE_GALLERY_MEDIA_TAG_NAME);
  745. }
  746. add_action('admin_menu', 'file_gallery_media_submenu');
  747. /**
  748. * Gets intermediate image sizes
  749. */
  750. function file_gallery_get_intermediate_image_sizes()
  751. {
  752. $sizes = array();
  753. if( function_exists('get_intermediate_image_sizes') )
  754. $sizes = get_intermediate_image_sizes();
  755. $additional_intermediate_sizes = apply_filters('intermediate_image_sizes', $sizes);
  756. array_unshift($additional_intermediate_sizes, 'thumbnail', 'medium', 'large', 'full');
  757. return array_unique($additional_intermediate_sizes);
  758. }
  759. /**
  760. * Media library extensions
  761. */
  762. function file_gallery_add_library_query_vars( $input )
  763. {
  764. global $wpdb, $pagenow;
  765. if( is_admin() )
  766. {
  767. $options = get_option('file_gallery');
  768. // affect the query only if we're on a certain page
  769. if( "media-upload.php" == $pagenow && "library" == $_GET["tab"] && is_numeric($_GET['post_id']) )
  770. {
  771. if( isset($_GET['exclude']) && "current" == $_GET['exclude'] )
  772. $input .= " AND `post_parent` != " . (int) $_GET["post_id"] . " ";
  773. if( isset($options["library_filter_duplicates"]) && true == $options["library_filter_duplicates"] )
  774. $input .= " AND $wpdb->posts.ID NOT IN ( SELECT ID FROM $wpdb->posts AS ps INNER JOIN $wpdb->postmeta AS pm ON pm.post_id = ps.ID WHERE pm.meta_key = '_is_copy_of' ) ";
  775. }
  776. elseif( "upload.php" == $pagenow && isset($options["library_filter_duplicates"]) && true == $options["library_filter_duplicates"] )
  777. {
  778. $input .= " AND $wpdb->posts.ID NOT IN ( SELECT ID FROM $wpdb->posts AS ps INNER JOIN $wpdb->postmeta AS pm ON pm.post_id = ps.ID WHERE pm.meta_key = '_is_copy_of' ) ";
  779. }
  780. }
  781. return $input;
  782. }
  783. add_filter('posts_where', 'file_gallery_add_library_query_vars');
  784. /**
  785. * Adds js to admin area
  786. */
  787. function file_gallery_js_admin()
  788. {
  789. global $pagenow, $current_screen, $wp_version, $post_ID, $file_gallery;
  790. $s = array('{"', '",', '"}', '\/', '"[', ']"');
  791. $r = array("\n{\n\"", "\",\n", "\"\n}", '/', '[', ']');
  792. if(
  793. "post.php" == $pagenow
  794. || "post-new.php" == $pagenow
  795. || "page.php" == $pagenow
  796. || "page-new.php" == $pagenow
  797. || "edit.php" == $pagenow
  798. || ("post" == $current_screen->base && isset($current_screen->post_type))
  799. )
  800. {
  801. // file_gallery.L10n
  802. $file_gallery_localize = array(
  803. "switch_to_tags" => __("Switch to tags", "file-gallery"),
  804. "switch_to_files" => __("Switch to list of attachments", "file-gallery"),
  805. "fg_info" => __("Insert checked attachments into post as", "file-gallery"),
  806. "no_attachments_upload" => __("No files are currently attached to this post.", "file-gallery"),
  807. "sure_to_delete" => __("Are you sure that you want to delete these attachments? Press [OK] to delete or [Cancel] to abort.", "file-gallery"),
  808. "saving_attachment_data" => __("saving attachment data...", "file-gallery"),
  809. "loading_attachment_data" => __("loading attachment data...", "file-gallery"),
  810. "deleting_attachment" => __("deleting attachment...", "file-gallery"),
  811. "deleting_attachments" => __("deleting attachments...", "file-gallery"),
  812. "loading" => __("loading...", "file-gallery"),
  813. "detaching_attachment" => __("detaching attachment", "file-gallery"),
  814. "detaching_attachments" => __("detaching attachments", "file-gallery"),
  815. "sure_to_detach" => __("Are you sure that you want to detach these attachments? Press [OK] to detach or [Cancel] to abort.", "file-gallery"),
  816. "close" => __("close", "file-gallery"),
  817. "loading_attachments" => __("loading attachments", "file-gallery"),
  818. "post_thumb_set" => __("Featured image set successfully", "file-gallery"),
  819. "post_thumb_unset" => __("Featured image removed", "file-gallery"),
  820. 'copy_all_from_original' => __('Copy all attachments from the original post', 'file-gallery'),
  821. 'copy_all_from_original_' => __('Copy all attachments from the original post?', 'file-gallery'),
  822. 'copy_all_from_translation' => __('Copy all attachments from this translation', 'file-gallery'),
  823. 'copy_all_from_translation_' => __('Copy all attachments from this translation?', 'file-gallery'),
  824. "set_as_featured" => __("Set as featured image", "file-gallery"),
  825. "unset_as_featured" => __("Unset as featured image", "file-gallery"),
  826. 'copy_from_is_nan_or_zero' => __('Supplied ID (%d) is zero or not a number, please correct.', 'file-gallery'),
  827. 'regenerating' => __('regenerating...', 'file-gallery')
  828. );
  829. // file_gallery.options
  830. $file_gallery_options = array(
  831. "file_gallery_url" => file_gallery_https( FILE_GALLERY_URL ),
  832. "file_gallery_nonce" => wp_create_nonce('file-gallery'),
  833. "file_gallery_mode" => "list",
  834. "num_attachments" => 1,
  835. "tags_from" => true,
  836. "clear_cache_nonce" => wp_create_nonce('file-gallery-clear_cache'),
  837. "post_thumb_nonce" => wp_create_nonce( "set_post_thumbnail-" . $post_ID )
  838. );
  839. // acf.L10n
  840. $acf_localize = array(
  841. 'new_custom_field' => __("Add New Custom Field", "file-gallery"),
  842. 'add_new_custom_field' => __("Add Custom Field", "file-gallery"),
  843. 'error_deleting_attachment_custom_field' => __("Error deleting attachment custom field!", "file-gallery"),
  844. 'error_adding_attachment_custom_field' => __("Error adding attachment custom field!", "file-gallery"),
  845. 'name' => __("Name:", "file-gallery"),
  846. 'value' => __("Value:", "file-gallery")
  847. );
  848. // acf.options
  849. $acf_options = array(
  850. 'add_new_attachment_custom_field_nonce' => wp_create_nonce( 'add_new_attachment_custom_field_nonce' ),
  851. 'delete_attachment_custom_field_nonce' => wp_create_nonce( 'delete_attachment_custom_field_nonce' ),
  852. 'custom_fields' => '[]'
  853. );
  854. $dependencies = array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-sortable', 'jquery-ui-dialog');
  855. wp_enqueue_script('file-gallery-main', file_gallery_https( FILE_GALLERY_URL ) . '/js/file-gallery.js', $dependencies, FILE_GALLERY_VERSION);
  856. wp_enqueue_script('file-gallery-clear_cache', file_gallery_https( FILE_GALLERY_URL ) . '/js/file-gallery-clear_cache.js', false, FILE_GALLERY_VERSION);
  857. wp_enqueue_script('acf-attachment-custom-fields', file_gallery_https( FILE_GALLERY_URL ) . '/js/file-gallery-attachment_custom_fields.js', false, FILE_GALLERY_VERSION);
  858. echo '
  859. <script type="text/javascript">
  860. var file_gallery_L10n = ' . str_replace($s, $r, json_encode($file_gallery_localize)) . ',
  861. file_gallery_options = ' . str_replace($s, $r, json_encode($file_gallery_options)) . ',
  862. acf_L10n = ' . str_replace($s, $r, json_encode($acf_localize)) . ',
  863. acf_options = ' . str_replace($s, $r, json_encode($acf_options)) . ';
  864. </script>
  865. ';
  866. }
  867. elseif( "media.php" == $pagenow && is_numeric($_GET['attachment_id']) && "edit" == $_GET["action"] )
  868. {
  869. $custom_fields = array();
  870. $custom = get_post_custom($_GET['attachment_id']);
  871. foreach( (array) $custom as $key => $val )
  872. {
  873. if( 1 < count($val) || "_" == substr($key, 0, 1) || is_array($val[0]) )
  874. continue;
  875. $custom_fields[] = $key;
  876. }
  877. $custom_fields = (! empty($custom_fields)) ? "'" . implode("','", $custom_fields) . "'" : "";
  878. $acf_localize = array(
  879. 'new_custom_field' => __("Add New Custom Field", "file-gallery"),
  880. 'add_new_custom_field' => __("Add Custom Field", "file-gallery"),
  881. 'error_deleting_attachment_custom_field' => __("Error deleting attachment custom field!", "file-gallery"),
  882. 'error_adding_attachment_custom_field' => __("Error adding attachment custom field!", "file-gallery"),
  883. 'name' => __("Name:", "file-gallery"),
  884. 'value' => __("Value:", "file-gallery")
  885. );
  886. $acf_options = array(
  887. 'add_new_attachment_custom_field_nonce' => wp_create_nonce( 'add_new_attachment_custom_field_nonce' ),
  888. 'delete_attachment_custom_field_nonce' => wp_create_nonce( 'delete_attachment_custom_field_nonce' ),
  889. 'custom_fields' => '[' . $custom_fields . ']'
  890. );
  891. wp_enqueue_script('acf-attachment-custom-fields', file_gallery_https( FILE_GALLERY_URL ) . '/js/file-gallery-attachment_custom_fields.js', false, FILE_GALLERY_VERSION);
  892. echo '
  893. <script type="text/javascript">
  894. var acf_L10n = ' . str_replace($s, $r, json_encode($acf_localize)) . ',
  895. acf_options = ' . str_replace($s, $r, json_encode($acf_options)) . ';
  896. </script>
  897. ';
  898. }
  899. elseif( "media-upload.php" == $pagenow && isset($_GET["tab"]) && "library" == $_GET["tab"] )
  900. {
  901. $file_gallery_localize = array(
  902. 'attach_all_checked_copy' => __("Attach all checked items to current post", "file-gallery"),
  903. 'exclude_current' => __("Exclude current post's attachments", "file-gallery"),
  904. 'include_current' => __("Include current post's attachments", "file-gallery")
  905. );
  906. wp_enqueue_script('file-gallery-attach', file_gallery_https( FILE_GALLERY_URL ) . '/js/file-gallery-attach.js', false, FILE_GALLERY_VERSION);
  907. echo '
  908. <style type="text/css">
  909. #library-form .media-item.child-of-' . $_GET["post_id"] . '
  910. {
  911. background-color: #FFE;
  912. }
  913. </style>
  914. <script type="text/javascript">
  915. var file_gallery_attach_nonce = "' . wp_create_nonce( 'file-gallery-attach' ) . '",
  916. file_gallery_L10n = ' . str_replace($s, $r, json_encode($file_gallery_localize)) . ';
  917. </script>
  918. ';
  919. }
  920. elseif( "options-media.php" == $pagenow )
  921. {
  922. echo '
  923. <script type="text/javascript">
  924. var file_gallery_options =
  925. {
  926. clear_cache_nonce : "' . wp_create_nonce('file-gallery-clear_cache') . '"
  927. };
  928. </script>
  929. ';
  930. wp_enqueue_script('file-gallery-clear_cache', file_gallery_https( FILE_GALLERY_URL ) . '/js/file-gallery-clear_cache.js', false, FILE_GALLERY_VERSION);
  931. }
  932. elseif( 'edit-tags.php' == $pagenow && FILE_GALLERY_MEDIA_TAG_NAME == $_GET['taxonomy'] && 3 > floatval($wp_version) )
  933. {
  934. echo '
  935. <script type="text/javascript">
  936. jQuery(document).ready(function()
  937. {
  938. jQuery("h2").html("' . __("Media tags", "file-gallery") . '");
  939. });
  940. </script>
  941. ';
  942. }
  943. }
  944. add_action('admin_print_scripts', 'file_gallery_js_admin');
  945. /**
  946. * Adds css to admin area
  947. */
  948. function file_gallery_css_admin()
  949. {
  950. global $pagenow, $current_screen, $file_gallery;
  951. if(
  952. 'post.php' == $pagenow
  953. || 'post-new.php' == $pagenow
  954. || 'page.php' == $pagenow
  955. || 'page-new.php' == $pagenow
  956. || 'media.php' == $pagenow
  957. || 'options-media.php' == $pagenow
  958. || 'media-upload.php' == $pagenow
  959. || 'upload.php' == $pagenow
  960. || 'edit.php' == $pagenow
  961. || 'options-permalink.php' == $pagenow
  962. || (isset($current_screen->post_type) && 'post' == $current_screen->base)
  963. )
  964. {
  965. wp_enqueue_style('file_gallery_admin', apply_filters('file_gallery_admin_css_location', file_gallery_https( FILE_GALLERY_URL ) . '/css/file-gallery.css'), false, FILE_GALLERY_VERSION );
  966. if( 'rtl' == get_bloginfo('text_direction') )
  967. wp_enqueue_style('file_gallery_admin_rtl', apply_filters('file_gallery_admin_rtl_css_location', file_gallery_https( FILE_GALLERY_URL ) . '/css/file-gallery-rtl.css'), false, FILE_GALLERY_VERSION );
  968. }
  969. }
  970. add_action('admin_print_styles', 'file_gallery_css_admin');
  971. /**
  972. * Edit post/page meta box content
  973. */
  974. function file_gallery_content()
  975. {
  976. global $post;
  977. echo
  978. '<div id="fg_container">
  979. <noscript>
  980. <div class="error" style="margin: 0;">
  981. <p>' . __('File Gallery requires Javascript to function. Please enable it in your browser.', 'file-gallery') . '</p>
  982. </div>
  983. </noscript>
  984. </div>
  985. <div id="file_gallery_image_dialog">
  986. </div>
  987. <div id="file_gallery_delete_dialog" title="' . __('Delete attachment dialog', 'file-gallery') . '">
  988. <p><strong>' . __("Warning: one of the attachments you've chosen to delete has copies.", 'file-gallery') . '</strong></p>
  989. <p>' . __('How do you wish to proceed?', 'file-gallery') . '</p>
  990. <p><a href="' . FILE_GALLERY_URL . '/help/index.html#deleting_originals" target="_blank">' . __('Click here if you have no idea what this dialog means', 'file-gallery') . '</a> ' . __('(opens File Gallery help in new browser window)', 'file-gallery') . '</p>
  991. </div>
  992. <div id="file_gallery_copy_all_dialog" title="' . __('Copy all attachments from another post', 'file-gallery') . '">
  993. <div id="file_gallery_copy_all_wrap">
  994. <label for="file_gallery_copy_all_from">' . __('Post ID:', 'file-gallery') . '</label>
  995. <input type="text" id="file_gallery_copy_all_from" value="" />
  996. </div>
  997. </div>';
  998. }
  999. /**
  1000. * Creates meta boxes on post editing screen
  1001. */
  1002. function file_gallery()
  1003. {
  1004. $options = get_option('file_gallery');
  1005. if( function_exists('get_post_types') )
  1006. {
  1007. $types = get_post_types();
  1008. foreach( $types as $type )
  1009. {
  1010. if( ! in_array( $type, array('nav_menu_item', 'revision', 'attachment') ) &&
  1011. isset($options['show_on_post_type_' . $type]) && true == $options['show_on_post_type_' . $type]
  1012. )
  1013. add_meta_box('file_gallery', __( 'File Gallery', 'file-gallery' ), 'file_gallery_content', $type, 'normal');
  1014. }
  1015. }
  1016. else // pre 2.9
  1017. {
  1018. add_meta_box('file_gallery', __( 'File Gallery', 'file-gallery' ), 'file_gallery_content', 'post', 'normal');
  1019. add_meta_box('file_gallery', __( 'File Gallery', 'file-gallery' ), 'file_gallery_content', 'page', 'normal');
  1020. }
  1021. }
  1022. add_action('admin_menu', 'file_gallery');
  1023. /**
  1024. * Outputs attachment count in the proper column
  1025. */
  1026. function file_gallery_posts_custom_column($column_name, $post_id)
  1027. {
  1028. global $wpdb;
  1029. $options = get_option('file_gallery');
  1030. if( 'attachment_count' == $column_name && isset($options['e_display_attachment_count']) && true == $options['e_display_attachment_count'] )
  1031. {
  1032. $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type='attachment' AND post_parent=%d", $post_id) );
  1033. echo apply_filters('file_gallery_post_attachment_count', $count, $post_id);
  1034. }
  1035. elseif( 'post_thumb' == $column_name && isset($options['e_display_post_thumb']) && true == $options['e_display_post_thumb'] )
  1036. {
  1037. if( $thumb_id = get_post_meta( $post_id, '_thumbnail_id', true ) )
  1038. {
  1039. $thumb_src = wp_get_attachment_image_src( $thumb_id, 'thumbnail', false );
  1040. $content = '<img src="' . $thumb_src[0] .'" alt="Post thumb" />';
  1041. echo apply_filters('file_gallery_post_thumb_content', $content, $post_id, $thumb_id);
  1042. }
  1043. else
  1044. {
  1045. echo apply_filters('file_gallery_no_post_thumb_content', '<span class="no-post-thumbnail">-</span>', $post_id);
  1046. }
  1047. }
  1048. }
  1049. add_action('manage_posts_custom_column', 'file_gallery_posts_custom_column', 100, 2);
  1050. add_action('manage_pages_custom_column', 'file_gallery_posts_custom_column', 100, 2);
  1051. /**
  1052. * Adds attachment count column to the post and page edit screens
  1053. */
  1054. function file_gallery_posts_columns( $columns )
  1055. {
  1056. $options = get_option('file_gallery');
  1057. if( isset($options['e_display_attachment_count']) && true == $options['e_display_attachment_count'] )
  1058. $columns['attachment_count'] = __('No. of attachments', 'file-gallery');
  1059. if( isset($options['e_display_post_thumb']) && true == $options['e_display_post_thumb'] )
  1060. $columns = array('post_thumb' => __('Post thumb', 'file-gallery')) + $columns; // $columns['post_thumb'] = 'Post thumb';
  1061. return $columns;
  1062. }
  1063. add_filter('manage_posts_columns', 'file_gallery_posts_columns');
  1064. add_filter('manage_pages_columns', 'file_gallery_posts_columns');
  1065. /**
  1066. * Outputs attachment media tags in the proper column
  1067. */
  1068. function file_gallery_media_custom_column($column_name, $post_id)
  1069. {
  1070. global $wpdb;
  1071. $options = get_option('file_gallery');
  1072. if( 'media_tags' == $column_name && isset($options['e_display_media_tags']) && true == $options['e_display_media_tags'])
  1073. {
  1074. if( isset($options['cache']) && true == $options['cache'] )
  1075. {
  1076. $transient = 'fileglry_mt_' . md5($post_id);
  1077. $cache = get_transient($transient);
  1078. if( $cache )
  1079. {
  1080. echo $cache;
  1081. return;
  1082. }
  1083. }
  1084. $l = '?taxonomy=' . FILE_GALLERY_MEDIA_TAG_NAME . '&amp;term=';
  1085. $out = __('No Media Tags', 'file-gallery');
  1086. $q = "SELECT `name`, `slug`
  1087. FROM $wpdb->terms
  1088. LEFT JOIN $wpdb->term_taxonomy ON ( $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id )
  1089. LEFT JOIN $wpdb->term_relationships ON ( $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id )
  1090. WHERE `taxonomy` = '" . FILE_GALLERY_MEDIA_TAG_NAME . "'
  1091. AND `object_id` = %d
  1092. ORDER BY `name` ASC";
  1093. if( $r = $wpdb->get_results($wpdb->prepare($q, $post_id)) )
  1094. {
  1095. $out = array();
  1096. foreach( $r as $tag )
  1097. {
  1098. $out[] = '<a href="' . $l . $tag->slug . '">' . $tag->name . '</a>';
  1099. }
  1100. $out = implode(', ', $out);
  1101. }
  1102. if( isset($options['cache']) && true == $options['cache'] )
  1103. set_transient($transient, $out, $options['cache_time']);
  1104. echo $out;
  1105. }
  1106. }
  1107. add_action('manage_media_custom_column', 'file_gallery_media_custom_column', 100, 2);
  1108. /**
  1109. * Adds media tags column to attachments
  1110. */
  1111. function file_gallery_media_columns( $columns )
  1112. {
  1113. global $mediatags;
  1114. if( ! (is_a($mediatags, 'MediaTags') && defined('MEDIA_TAGS_TAXONOMY')) )
  1115. $columns['media_tags'] = __('Media tags', 'file-gallery');
  1116. return $columns;
  1117. }
  1118. add_filter('manage_media_columns', 'file_gallery_media_columns');
  1119. /**
  1120. * Includes
  1121. */
  1122. require_once('includes/media-tags.php');
  1123. require_once('includes/media-settings.php');
  1124. // require_once('includes/media-upload.php');
  1125. require_once('includes/attachments.php');
  1126. require_once('includes/miscellaneous.php');
  1127. require_once('includes/mime-types.php');
  1128. require_once('includes/lightboxes-support.php');
  1129. require_once('includes/templating.php');
  1130. require_once('includes/main.php');
  1131. require_once('includes/functions.php');
  1132. require_once('includes/cache.php');
  1133. require_once('includes/regenerate-images.php');
  1134. require_once('includes/attachments-custom-fields.php');
  1135. if( 3.1 <= floatval(get_bloginfo('version')) )
  1136. require_once('includes/media-tags-list-table.class.php');
  1137. ?>