Version Description
Download this release
Release Info
Developer | pasyuk |
Plugin | Gmedia Photo Gallery |
Version | 1.8.80 |
Comparing to | |
See all releases |
Code changes from version 1.8.23 to 1.8.80
- admin/admin.php +258 -116
- admin/ajax.php +540 -589
- admin/app.php +1 -0
- admin/assets/css/gmedia.admin.css +208 -38
- admin/assets/img/audio.png +0 -0
- admin/assets/js/gmedia.admin.js +501 -231
- admin/class.processor.php +45 -37
- admin/functions.php +118 -60
- admin/pages/addmedia/tpl/assign-terms.php +5 -0
- admin/pages/addmedia/tpl/import.php +12 -2
- admin/pages/addmedia/tpl/panel-heading.php +7 -1
- admin/pages/addmedia/tpl/upload.php +32 -31
- admin/pages/galleries/edit-gallery.php +40 -30
- admin/pages/galleries/functions.php +1 -65
- admin/pages/galleries/tpl/choose-module.php +6 -0
- admin/pages/galleries/tpl/galleries-panel-heading.php +19 -6
- admin/pages/galleries/tpl/gallery-edit-item.php +74 -727
- admin/pages/galleries/tpl/gallery-list-item.php +5 -0
- admin/pages/galleries/tpl/gallery-panel-heading.php +9 -3
- admin/pages/galleries/tpl/modal-build-query.php +500 -0
- admin/pages/galleries/tpl/module-settings.php +232 -0
- admin/pages/library/functions.php +108 -40
- admin/pages/library/library.php +12 -6
- admin/pages/library/tpl/edit-item.php +16 -6
- admin/pages/library/tpl/grid-item.php +32 -25
- admin/pages/library/tpl/list-item.php +12 -2
- admin/pages/library/tpl/no-items.php +19 -8
- admin/pages/library/tpl/panel-footer.php +6 -0
- admin/pages/library/tpl/panel-heading.php +37 -15
- admin/pages/modules/edit-preset.php +87 -0
- admin/pages/modules/functions.php +55 -8
- admin/pages/modules/modules.php +4 -2
- admin/pages/modules/tpl/modal-modulezip.php +5 -0
- admin/pages/modules/tpl/module-item.php +86 -16
- admin/pages/modules/tpl/module-preset-edit-item.php +104 -0
- admin/pages/modules/tpl/module-preset-panel-heading.php +35 -0
- admin/pages/settings/settings.php +2 -1
- admin/pages/settings/tpl/common.php +32 -7
- admin/pages/settings/tpl/license.php +12 -5
- admin/pages/settings/tpl/permalinks.php +23 -0
- admin/pages/settings/tpl/roles.php +5 -0
- admin/pages/settings/tpl/system.php +5 -0
- admin/pages/terms/functions.php +58 -56
- admin/pages/terms/tpl/album-create-item.php +39 -0
- admin/pages/terms/tpl/album-edit-item.php +54 -10
- admin/pages/terms/tpl/album-list-item.php +5 -0
- admin/pages/terms/tpl/album-sort-gmedia.php +10 -8
- admin/pages/terms/tpl/category-create-item.php +55 -11
- admin/pages/terms/tpl/category-edit-item.php +51 -7
- admin/pages/terms/tpl/category-list-item.php +5 -1
- admin/pages/terms/tpl/category-preview-gmedia.php +8 -3
- admin/pages/terms/tpl/no-items.php +5 -1
- admin/pages/terms/tpl/tag-create-item.php +5 -1
- admin/pages/terms/tpl/tag-list-item.php +5 -1
- admin/pages/terms/tpl/term-panel-heading.php +8 -2
- admin/pages/terms/tpl/terms-create-alert.php +5 -1
- admin/pages/terms/tpl/terms-panel-heading.php +19 -7
- admin/processor/class.processor.addmedia.php +1 -1
- admin/processor/class.processor.galleries.php +107 -98
- admin/processor/class.processor.library.php +71 -30
- admin/processor/class.processor.modules.php +123 -24
- admin/processor/class.processor.settings.php +67 -66
- admin/processor/class.processor.terms.php +4 -4
- admin/tpl/comments.php +3 -0
- admin/tpl/modal-customfield.php +27 -19
- admin/tpl/modal-share.php +5 -0
- admin/tpl/module-preview.php +28 -0
- admin/tpl/search-form.php +7 -3
- admin/wpmedia.php +1 -0
- app/access.php +731 -564
- assets/wavesurfer/wavesurfer.js +2089 -0
- assets/wavesurfer/wavesurfer.min.js +60 -0
- changelog.txt +494 -0
- config/setup.php +65 -39
- config/update.php +236 -206
- config/wp-load.php +4 -0
- grand-media.php +171 -148
- inc/color.php +480 -0
- inc/compatibility.php +4 -0
- inc/core.php +1589 -1189
admin/admin.php
CHANGED
@@ -2,17 +2,19 @@
|
|
2 |
|
3 |
/**
|
4 |
* GmediaAdmin - Admin Section for GRAND Media
|
5 |
-
*
|
6 |
*/
|
7 |
-
class GmediaAdmin
|
8 |
var $pages = array();
|
|
|
9 |
|
10 |
/**
|
11 |
* constructor
|
12 |
*/
|
13 |
-
function __construct()
|
14 |
global $pagenow;
|
15 |
|
|
|
|
|
16 |
// Add the admin menu
|
17 |
add_action('admin_menu', array(&$this, 'add_menu'));
|
18 |
|
@@ -22,33 +24,73 @@ class GmediaAdmin {
|
|
22 |
add_filter('screen_settings', array(&$this, 'screen_settings'), 10, 2);
|
23 |
add_filter('set-screen-option', array(&$this, 'screen_settings_save'), 11, 3);
|
24 |
|
25 |
-
if(isset($_GET['page']) && (false !== strpos($_GET['page'], 'GrandMedia')))
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
add_action('admin_init', array(&$this, 'gmedia_blank_page'));
|
28 |
}
|
|
|
|
|
29 |
}
|
30 |
|
31 |
}
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
/**
|
34 |
* Load gmedia pages in wpless interface
|
35 |
*/
|
36 |
-
function gmedia_blank_page()
|
37 |
set_current_screen('GrandMedia_Settings');
|
38 |
|
39 |
-
global $gmCore;
|
40 |
$gmediablank = $gmCore->_get('gmediablank', '');
|
41 |
-
/*
|
42 |
-
add_filter('admin_body_class', function(){
|
43 |
-
$gmediablank = isset($_GET['gmediablank'])? $_GET['gmediablank'] : '';
|
44 |
-
return "gmedia-blank $gmediablank"; });
|
45 |
-
*/
|
46 |
-
add_filter('admin_body_class', create_function('', '$gmediablank = isset($_GET["gmediablank"])? $_GET["gmediablank"] : ""; return "gmedia-blank gmedia_{$gmediablank}";'));
|
47 |
define('IFRAME_REQUEST', true);
|
48 |
|
49 |
iframe_header('GmediaGallery');
|
50 |
|
51 |
-
|
|
|
52 |
case 'update_plugin':
|
53 |
require_once(dirname(dirname(__FILE__)) . '/config/update.php');
|
54 |
gmedia_do_update();
|
@@ -61,29 +103,32 @@ class GmediaAdmin {
|
|
61 |
require_once(dirname(dirname(__FILE__)) . '/inc/map-editor.php');
|
62 |
gmedia_map_editor();
|
63 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
case 'comments':
|
65 |
require_once(dirname(__FILE__) . '/tpl/comments.php');
|
66 |
break;
|
|
|
|
|
|
|
67 |
}
|
|
|
68 |
|
69 |
iframe_footer();
|
70 |
exit;
|
71 |
}
|
72 |
|
73 |
-
/**
|
74 |
-
* @return string
|
75 |
-
*/
|
76 |
-
function gmedia_blank_page_body_class() {
|
77 |
-
return 'gmedia-blank';
|
78 |
-
}
|
79 |
-
|
80 |
// integrate the menu
|
81 |
-
function add_menu()
|
82 |
$gmediaURL = plugins_url(GMEDIA_FOLDER);
|
83 |
$this->pages = array();
|
84 |
$this->pages[] = add_menu_page(__('Gmedia Library', 'grand-media'), 'Gmedia Gallery', 'gmedia_library', 'GrandMedia', array(&$this, 'shell'), $gmediaURL . '/admin/assets/img/gm-icon.png', 11);
|
85 |
$this->pages[] = add_submenu_page('GrandMedia', __('Gmedia Library', 'grand-media'), __('Gmedia Library', 'grand-media'), 'gmedia_library', 'GrandMedia', array(&$this, 'shell'));
|
86 |
-
if(current_user_can('gmedia_library'))
|
87 |
$this->pages[] = add_submenu_page('GrandMedia', __('Add Media Files', 'grand-media'), __('Add/Import Files', 'grand-media'), 'gmedia_upload', 'GrandMedia_AddMedia', array(&$this, 'shell'));
|
88 |
$this->pages[] = add_submenu_page('GrandMedia', __('Tags', 'grand-media'), __('Tags', 'grand-media'), 'gmedia_library', 'GrandMedia_Tags', array(&$this, 'shell'));
|
89 |
$this->pages[] = add_submenu_page('GrandMedia', __('Categories', 'grand-media'), __('Categories', 'grand-media'), 'gmedia_library', 'GrandMedia_Categories', array(&$this, 'shell'));
|
@@ -95,7 +140,7 @@ class GmediaAdmin {
|
|
95 |
$this->pages[] = add_submenu_page('GrandMedia', __('Wordpress Media Library', 'grand-media'), __('WP Media Library', 'grand-media'), 'gmedia_import', 'GrandMedia_WordpressLibrary', array(&$this, 'shell'));
|
96 |
}
|
97 |
|
98 |
-
foreach($this->pages as $page)
|
99 |
add_action("load-$page", array(&$this, 'screen_help'));
|
100 |
}
|
101 |
}
|
@@ -104,21 +149,22 @@ class GmediaAdmin {
|
|
104 |
* Load the script for the defined page and load only this code
|
105 |
* Display shell of plugin
|
106 |
*/
|
107 |
-
function shell()
|
108 |
global $gmCore, $gmProcessor, $gmGallery;
|
109 |
|
110 |
$sideLinks = $this->sideLinks();
|
111 |
|
112 |
// check for upgrade
|
113 |
-
if(get_option('gmediaDbVersion') != GMEDIA_DBVERSION)
|
114 |
-
if(get_transient('gmediaUpgrade') || (isset($_GET['do_update']) && ('gmedia' == $_GET['do_update'])))
|
115 |
$sideLinks['grandTitle'] = __('Updating GmediaGallery Plugin', 'grand-media');
|
116 |
-
$sideLinks['sideLinks']
|
117 |
-
$gmProcessor->page
|
118 |
-
} else
|
119 |
return;
|
120 |
}
|
121 |
}
|
|
|
122 |
?>
|
123 |
<div id="gmedia-container" class="gmedia-admin">
|
124 |
<div id="gmedia-header" class="clearfix">
|
@@ -133,12 +179,12 @@ class GmediaAdmin {
|
|
133 |
<?php echo $sideLinks['sideLinks']; ?>
|
134 |
|
135 |
<?php $installDate = get_option('gmediaInstallDate');
|
136 |
-
if($installDate && (strtotime($installDate) < strtotime('2 weeks ago')))
|
137 |
<div class="row panel panel-default visible-lg-block">
|
138 |
<div class="panel-heading" data-toggle="collapse" data-target="#support_div_collapse" aria-expanded="true" aria-controls="support_div_collapse" style="cursor:pointer;">
|
139 |
<b><?php _e('Any feedback?', 'grand-media'); ?></b>
|
140 |
</div>
|
141 |
-
<div class="collapse<?php if(empty($gmGallery->options['license_key']))
|
142 |
echo ' in';
|
143 |
} ?>" id="support_div_collapse">
|
144 |
<div class="panel-body">
|
@@ -181,48 +227,84 @@ class GmediaAdmin {
|
|
181 |
<?php
|
182 |
}
|
183 |
|
184 |
-
function sideLinks()
|
185 |
-
global $submenu, $gmProcessor;
|
186 |
$content['sideLinks'] = '
|
187 |
<div id="gmedia-navbar">
|
188 |
<div class="row">
|
189 |
-
<ul class="list-group">';
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
192 |
$iscur = ' active';
|
193 |
-
$content['grandTitle'] = $submenu['GrandMedia'][$menuKey][3];
|
194 |
-
} else
|
195 |
$iscur = '';
|
196 |
}
|
197 |
|
198 |
-
$content['sideLinks'] .= "\n" . '<a class="list-group-item' . $iscur . '" href="' . admin_url('admin.php?page=' . $submenu['GrandMedia'][$menuKey][2]) . '">' . $submenu['GrandMedia'][$menuKey][0] . '</a>';
|
199 |
}
|
200 |
$content['sideLinks'] .= '
|
201 |
-
</ul>
|
202 |
</div>
|
203 |
</div>';
|
204 |
|
205 |
return $content;
|
206 |
}
|
207 |
|
208 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
global $gmProcessor;
|
211 |
-
switch($gmProcessor->page)
|
212 |
case 'GrandMedia_AddMedia':
|
213 |
include_once(dirname(__FILE__) . '/pages/addmedia/addmedia.php');
|
214 |
break;
|
215 |
case 'GrandMedia_Albums':
|
216 |
-
if(isset($_GET['edit_item']))
|
217 |
include_once(dirname(__FILE__) . '/pages/terms/edit-term.php');
|
218 |
-
} else
|
219 |
include_once(dirname(__FILE__) . '/pages/terms/terms.php');
|
220 |
}
|
221 |
break;
|
222 |
case 'GrandMedia_Categories':
|
223 |
-
if(isset($_GET['edit_item']))
|
224 |
include_once(dirname(__FILE__) . '/pages/terms/edit-term.php');
|
225 |
-
} else
|
226 |
include_once(dirname(__FILE__) . '/pages/terms/terms.php');
|
227 |
}
|
228 |
break;
|
@@ -230,14 +312,18 @@ class GmediaAdmin {
|
|
230 |
include_once(dirname(__FILE__) . '/pages/terms/terms.php');
|
231 |
break;
|
232 |
case 'GrandMedia_Galleries':
|
233 |
-
if(isset($_GET['gallery_module']) || isset($_GET['edit_item']))
|
234 |
include_once(dirname(__FILE__) . '/pages/galleries/edit-gallery.php');
|
235 |
-
} else
|
236 |
include_once(dirname(__FILE__) . '/pages/galleries/galleries.php');
|
237 |
}
|
238 |
break;
|
239 |
case 'GrandMedia_Modules':
|
240 |
-
|
|
|
|
|
|
|
|
|
241 |
break;
|
242 |
case 'GrandMedia_Settings':
|
243 |
include_once(dirname(__FILE__) . '/pages/settings/settings.php');
|
@@ -264,27 +350,27 @@ class GmediaAdmin {
|
|
264 |
/**
|
265 |
* @param $hook
|
266 |
*/
|
267 |
-
function load_scripts($hook)
|
268 |
global $gmCore, $gmProcessor, $gmGallery;
|
269 |
|
270 |
// no need to go on if it's not a plugin page
|
271 |
-
if('admin.php' != $hook && strpos($gmCore->_get('page'), 'GrandMedia') === false)
|
272 |
return;
|
273 |
}
|
274 |
|
275 |
-
if($gmGallery->options['isolation_mode'])
|
276 |
global $wp_scripts, $wp_styles;
|
277 |
-
foreach($wp_scripts->registered as $handle => $wp_script)
|
278 |
-
if(((false !== strpos($wp_script->src, '/plugins/')) || (false !== strpos($wp_script->src, '/themes/'))) && (false === strpos($wp_script->src, GMEDIA_FOLDER)))
|
279 |
-
if(in_array($handle, $wp_scripts->queue))
|
280 |
wp_dequeue_script($handle);
|
281 |
}
|
282 |
wp_deregister_script($handle);
|
283 |
}
|
284 |
}
|
285 |
-
foreach($wp_styles->registered as $handle => $wp_style)
|
286 |
-
if(((false !== strpos($wp_style->src, '/plugins/')) || (false !== strpos($wp_style->src, '/themes/'))) && (false === strpos($wp_style->src, GMEDIA_FOLDER)))
|
287 |
-
if(in_array($handle, $wp_styles->queue))
|
288 |
wp_dequeue_style($handle);
|
289 |
}
|
290 |
wp_deregister_style($handle);
|
@@ -298,11 +384,11 @@ class GmediaAdmin {
|
|
298 |
wp_register_script('selectize', $gmCore->gmedia_url . '/assets/selectize/selectize.min.js', array('jquery'), '0.12.1');
|
299 |
wp_register_style('selectize', $gmCore->gmedia_url . '/assets/selectize/selectize.bootstrap3.css', array('gmedia-bootstrap'), '0.12.1', 'screen');
|
300 |
|
301 |
-
if(isset($_GET['page']))
|
302 |
-
switch($_GET['page'])
|
303 |
case "GrandMedia" :
|
304 |
-
if($gmCore->caps['gmedia_edit_media'])
|
305 |
-
if($gmCore->_get('gmediablank') == 'image_editor')
|
306 |
wp_enqueue_script('camanjs', $gmCore->gmedia_url . '/assets/image-editor/camanjs/caman.full.min.js', array(), '4.1.2');
|
307 |
|
308 |
wp_enqueue_style('nouislider', $gmCore->gmedia_url . '/assets/image-editor/js/jquery.nouislider.css', array('gmedia-bootstrap'), '6.1.0');
|
@@ -312,29 +398,29 @@ class GmediaAdmin {
|
|
312 |
wp_enqueue_script('gmedia-image-editor', $gmCore->gmedia_url . '/assets/image-editor/image-editor.js', array('jquery', 'camanjs'), '0.9.16');
|
313 |
break;
|
314 |
}
|
315 |
-
if($gmProcessor->
|
316 |
wp_enqueue_script('alphanum', $gmCore->gmedia_url . '/assets/jq-plugins/jquery.alphanum.js', array('jquery'), '1.0.16');
|
317 |
|
318 |
wp_enqueue_script('moment', $gmCore->gmedia_url . '/assets/bootstrap-datetimepicker/moment.min.js', array('jquery'), '2.5.1');
|
319 |
wp_enqueue_style('datetimepicker', $gmCore->gmedia_url . '/assets/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css', array('gmedia-bootstrap'), '2.1.32');
|
320 |
-
wp_enqueue_script('datetimepicker', $gmCore->gmedia_url . '/assets/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js', array(
|
321 |
-
|
322 |
-
|
323 |
-
'gmedia-bootstrap'
|
324 |
), '2.1.32');
|
325 |
}
|
326 |
}
|
327 |
wp_enqueue_style('selectize');
|
328 |
wp_enqueue_script('selectize');
|
|
|
329 |
break;
|
330 |
case "GrandMedia_WordpressLibrary" :
|
331 |
-
if($gmCore->caps['gmedia_import'])
|
332 |
wp_enqueue_style('selectize');
|
333 |
wp_enqueue_script('selectize');
|
334 |
}
|
335 |
break;
|
336 |
case "GrandMedia_Albums" :
|
337 |
-
if(isset($_GET['edit_item']) && $gmCore->caps['gmedia_album_manage'])
|
338 |
wp_enqueue_style('jquery-ui-smoothness', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css', array(), '1.10.2', 'screen');
|
339 |
wp_enqueue_script('jquery-ui-full', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js', array(), '1.10.2');
|
340 |
|
@@ -342,22 +428,21 @@ class GmediaAdmin {
|
|
342 |
}
|
343 |
break;
|
344 |
case "GrandMedia_AddMedia" :
|
345 |
-
if($gmCore->caps['gmedia_terms'])
|
346 |
wp_enqueue_style('selectize');
|
347 |
wp_enqueue_script('selectize');
|
348 |
}
|
349 |
-
if($gmCore->caps['gmedia_upload'])
|
350 |
$tab = $gmCore->_get('tab', 'upload');
|
351 |
-
if($tab == 'upload')
|
352 |
wp_enqueue_style('jquery-ui-smoothness', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css', array(), '1.10.2', 'screen');
|
353 |
wp_enqueue_script('jquery-ui-full', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js', array(), '1.10.2');
|
354 |
|
355 |
wp_enqueue_script('gmedia-plupload', $gmCore->gmedia_url . '/assets/plupload/plupload.full.min.js', array('jquery', 'jquery-ui-full'), '2.1.2');
|
356 |
|
357 |
wp_enqueue_style('jquery.ui.plupload', $gmCore->gmedia_url . '/assets/plupload/jquery.ui.plupload/css/jquery.ui.plupload.css', array('jquery-ui-smoothness'), '2.1.2', 'screen');
|
358 |
-
wp_enqueue_script('jquery.ui.plupload', $gmCore->gmedia_url . '/assets/plupload/jquery.ui.plupload/jquery.ui.plupload.min.js', array(
|
359 |
-
|
360 |
-
'jquery-ui-full'
|
361 |
), '2.1.2');
|
362 |
|
363 |
}
|
@@ -368,7 +453,21 @@ class GmediaAdmin {
|
|
368 |
// under construction
|
369 |
break;
|
370 |
case "GrandMedia_Galleries" :
|
371 |
-
if($gmCore->caps['gmedia_gallery_manage'] && (isset($_GET['gallery_module']) || isset($_GET['edit_item'])))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
|
373 |
wp_enqueue_style('jquery-ui-smoothness', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css', array(), '1.10.2', 'screen');
|
374 |
wp_enqueue_script('jquery-ui-resizable');
|
@@ -389,15 +488,14 @@ class GmediaAdmin {
|
|
389 |
|
390 |
}
|
391 |
|
392 |
-
function screen_help()
|
393 |
$screen = get_current_screen();
|
394 |
$screen_id = explode('page_', $screen->id, 2);
|
395 |
$screen_id = $screen_id[1];
|
396 |
|
397 |
-
$screen->add_help_tab(array(
|
398 |
-
|
399 |
-
|
400 |
-
'content' => '<h4>First steps</h4>
|
401 |
<p>If you have any problems with displaying Gmedia Gallery in admin or on website. Before posting to the Forum try next:</p>
|
402 |
<ul>
|
403 |
<li>Exclude plugin conflicts: Disable other plugins one by one and check if it resolve problem</li>
|
@@ -411,15 +509,14 @@ class GmediaAdmin {
|
|
411 |
</p>',
|
412 |
));
|
413 |
|
414 |
-
switch($screen_id)
|
415 |
case 'GrandMedia' :
|
416 |
break;
|
417 |
case 'GrandMedia_Settings' :
|
418 |
-
if(current_user_can('manage_options'))
|
419 |
-
$screen->add_help_tab(array(
|
420 |
-
|
421 |
-
|
422 |
-
'content' => '<h4>Should I buy it, to use plugin?</h4>
|
423 |
<p>No, plugin is absolutely free and all modules for it are free to install.</p>
|
424 |
<p>Even premium modules are fully functional and free to test, but have backlink labels. To remove baclink labels from premium modules you need license key.</p>
|
425 |
<p>Note: License Key will remove backlinks from all current and future premium modules, so you can use all available modules on one website.</p>
|
@@ -439,9 +536,9 @@ class GmediaAdmin {
|
|
439 |
*
|
440 |
* @return string
|
441 |
*/
|
442 |
-
function screen_settings($current, $screen)
|
443 |
global $gmProcessor, $gmCore;
|
444 |
-
if(in_array($screen->id, $this->pages))
|
445 |
|
446 |
$gm_screen_options = $gmProcessor->user_options;
|
447 |
|
@@ -453,7 +550,7 @@ class GmediaAdmin {
|
|
453 |
|
454 |
$screen_id = explode('page_', $screen->id, 2);
|
455 |
|
456 |
-
switch($screen_id[1])
|
457 |
case 'GrandMedia' :
|
458 |
$settings = '
|
459 |
<div class="form-inline pull-left">
|
@@ -478,7 +575,7 @@ class GmediaAdmin {
|
|
478 |
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
479 |
</div>
|
480 |
';
|
481 |
-
if($gmCore->_get('
|
482 |
$settings .= '
|
483 |
<div class="form-group">
|
484 |
<select name="gm_screen_options[library_edit_quicktags]" class="form-control input-sm">
|
@@ -494,7 +591,7 @@ class GmediaAdmin {
|
|
494 |
break;
|
495 |
case 'GrandMedia_AddMedia' :
|
496 |
$tab = $gmCore->_get('tab', 'upload');
|
497 |
-
if('upload' == $tab)
|
498 |
$html4_hide = ('html4' == $gm_screen_options['uploader_runtime'])? ' hide' : '';
|
499 |
$settings = '
|
500 |
<div class="form-inline pull-left">
|
@@ -523,7 +620,7 @@ class GmediaAdmin {
|
|
523 |
}
|
524 |
break;
|
525 |
case 'GrandMedia_Albums' :
|
526 |
-
if(isset($_GET['edit_item']))
|
527 |
$settings = '
|
528 |
<div class="form-inline pull-left">
|
529 |
<div class="form-group">
|
@@ -531,49 +628,94 @@ class GmediaAdmin {
|
|
531 |
</div>
|
532 |
</div>
|
533 |
';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
534 |
}
|
535 |
break;
|
536 |
case 'GrandMedia_Categories' :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
$settings = '
|
538 |
<div class="form-inline pull-left">
|
539 |
<div class="form-group">
|
540 |
-
<input type="number" max="999" min="0" step="5" size="3" name="gm_screen_options[
|
541 |
</div>
|
542 |
<div class="form-group">
|
543 |
-
<select name="gm_screen_options[
|
544 |
-
<option' . selected($gm_screen_options['
|
545 |
-
<option' . selected($gm_screen_options['
|
546 |
-
<option' . selected($gm_screen_options['
|
547 |
-
<option' . selected($gm_screen_options['orderby_gmedia_terms'], 'global', false) . ' value="global">' . __('Author ID (for albums only)', 'grand-media') . '</option>
|
548 |
</select> <span>' . __('order items', 'grand-media') . '</span>
|
549 |
</div>
|
550 |
<div class="form-group">
|
551 |
-
<select name="gm_screen_options[
|
552 |
-
<option' . selected($gm_screen_options['
|
553 |
-
<option' . selected($gm_screen_options['
|
554 |
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
555 |
</div>
|
556 |
</div>
|
557 |
';
|
558 |
break;
|
559 |
case 'GrandMedia_Galleries' :
|
560 |
-
if(!$gmCore->_get('
|
561 |
$settings = '
|
562 |
<div class="form-inline pull-left">
|
563 |
<div class="form-group">
|
564 |
-
<input type="number" max="999" min="0" step="5" size="3" name="gm_screen_options[
|
565 |
</div>
|
566 |
<div class="form-group">
|
567 |
-
<select name="gm_screen_options[
|
568 |
-
<option' . selected($gm_screen_options['
|
569 |
-
<option' . selected($gm_screen_options['
|
570 |
-
<option' . selected($gm_screen_options['
|
571 |
</select> <span>' . __('order items', 'grand-media') . '</span>
|
572 |
</div>
|
573 |
<div class="form-group">
|
574 |
-
<select name="gm_screen_options[
|
575 |
-
<option' . selected($gm_screen_options['
|
576 |
-
<option' . selected($gm_screen_options['
|
577 |
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
578 |
</div>
|
579 |
</div>
|
@@ -608,7 +750,7 @@ class GmediaAdmin {
|
|
608 |
break;
|
609 |
}
|
610 |
|
611 |
-
if($settings)
|
612 |
$current = $title . $settings . $wp_screen_options . $button;
|
613 |
}
|
614 |
|
@@ -624,9 +766,9 @@ class GmediaAdmin {
|
|
624 |
*
|
625 |
* @return array
|
626 |
*/
|
627 |
-
function screen_settings_save($status, $option, $value)
|
628 |
global $user_ID;
|
629 |
-
if('gm_screen_options' == $option)
|
630 |
/*
|
631 |
global $gmGallery;
|
632 |
foreach ( $_POST['gm_screen_options'] as $key => $val ) {
|
@@ -635,7 +777,7 @@ class GmediaAdmin {
|
|
635 |
update_option( 'gmediaOptions', $gmGallery->options );
|
636 |
*/
|
637 |
$gm_screen_options = get_user_meta($user_ID, 'gm_screen_options', true);
|
638 |
-
if(!is_array($gm_screen_options))
|
639 |
$gm_screen_options = array();
|
640 |
}
|
641 |
$value = array_merge($gm_screen_options, $_POST['gm_screen_options']);
|
2 |
|
3 |
/**
|
4 |
* GmediaAdmin - Admin Section for GRAND Media
|
|
|
5 |
*/
|
6 |
+
class GmediaAdmin{
|
7 |
var $pages = array();
|
8 |
+
var $body_classes = array();
|
9 |
|
10 |
/**
|
11 |
* constructor
|
12 |
*/
|
13 |
+
function __construct(){
|
14 |
global $pagenow;
|
15 |
|
16 |
+
add_action('admin_head', array(&$this, 'admin_head'));
|
17 |
+
|
18 |
// Add the admin menu
|
19 |
add_action('admin_menu', array(&$this, 'add_menu'));
|
20 |
|
24 |
add_filter('screen_settings', array(&$this, 'screen_settings'), 10, 2);
|
25 |
add_filter('set-screen-option', array(&$this, 'screen_settings_save'), 11, 3);
|
26 |
|
27 |
+
if(isset($_GET['page']) && (false !== strpos($_GET['page'], 'GrandMedia'))){
|
28 |
+
|
29 |
+
if(!isset($_GET['gmediablank']) || 'library' === $_GET['gmediablank']){
|
30 |
+
$this->body_classes[] = $_GET['page'];
|
31 |
+
if(!empty($_GET['mode'])){
|
32 |
+
$this->body_classes[] = $_GET['page'] . '_' . $_GET['mode'];
|
33 |
+
}
|
34 |
+
if(isset($_GET['edit_item']) || isset($_GET['gallery_module']) || isset($_GET['preset'])){
|
35 |
+
$this->body_classes[] = $_GET['page'] . '_edit';
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
if(('admin.php' == $pagenow) && isset($_GET['gmediablank'])){
|
40 |
add_action('admin_init', array(&$this, 'gmedia_blank_page'));
|
41 |
}
|
42 |
+
|
43 |
+
add_action('admin_footer', array(&$this, 'admin_footer'));
|
44 |
}
|
45 |
|
46 |
}
|
47 |
|
48 |
+
/**
|
49 |
+
* admin_head
|
50 |
+
*/
|
51 |
+
function admin_head(){
|
52 |
+
add_filter('admin_body_class', array(&$this, 'admin_body_class'));
|
53 |
+
|
54 |
+
if(isset($_GET['page']) && (false !== strpos($_GET['page'], 'GrandMedia'))){
|
55 |
+
?>
|
56 |
+
<style type="text/css" id="gmedia_admin_css">html, body { background: <?php echo isset( $_GET['gmediablank'] )? 'transparent' : '#708090'; ?>; }</style>
|
57 |
+
<?php
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* admin_body_class
|
63 |
+
*
|
64 |
+
* @param $classes_string
|
65 |
+
*
|
66 |
+
* @return string
|
67 |
+
*/
|
68 |
+
function admin_body_class($classes_string){
|
69 |
+
$classes = $this->body_classes;
|
70 |
+
|
71 |
+
$classes[] = $classes_string;
|
72 |
+
if(isset($_GET["gmediablank"])){
|
73 |
+
$classes[] = "gmedia-blank gmedia_{$_GET['gmediablank']}";
|
74 |
+
}
|
75 |
+
$classes = array_filter($classes);
|
76 |
+
|
77 |
+
return implode(' ', $classes);
|
78 |
+
}
|
79 |
+
|
80 |
/**
|
81 |
* Load gmedia pages in wpless interface
|
82 |
*/
|
83 |
+
function gmedia_blank_page(){
|
84 |
set_current_screen('GrandMedia_Settings');
|
85 |
|
86 |
+
global $gmCore, $gmProcessor;
|
87 |
$gmediablank = $gmCore->_get('gmediablank', '');
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
define('IFRAME_REQUEST', true);
|
89 |
|
90 |
iframe_header('GmediaGallery');
|
91 |
|
92 |
+
echo '<div id="gmedia-container">';
|
93 |
+
switch($gmediablank){
|
94 |
case 'update_plugin':
|
95 |
require_once(dirname(dirname(__FILE__)) . '/config/update.php');
|
96 |
gmedia_do_update();
|
103 |
require_once(dirname(dirname(__FILE__)) . '/inc/map-editor.php');
|
104 |
gmedia_map_editor();
|
105 |
break;
|
106 |
+
case 'library':
|
107 |
+
echo '<div id="gmedia_iframe_content">';
|
108 |
+
echo '<div id="gm-message">' . $gmCore->alert('success', $gmProcessor->msg) . $gmCore->alert('danger', $gmProcessor->error) . '</div>';
|
109 |
+
include(GMEDIA_ABSPATH . 'admin/pages/library/library.php');
|
110 |
+
echo '</div>';
|
111 |
+
break;
|
112 |
case 'comments':
|
113 |
require_once(dirname(__FILE__) . '/tpl/comments.php');
|
114 |
break;
|
115 |
+
case 'module_preview':
|
116 |
+
require_once(dirname(__FILE__) . '/tpl/module-preview.php');
|
117 |
+
break;
|
118 |
}
|
119 |
+
echo '</div>';
|
120 |
|
121 |
iframe_footer();
|
122 |
exit;
|
123 |
}
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
// integrate the menu
|
126 |
+
function add_menu(){
|
127 |
$gmediaURL = plugins_url(GMEDIA_FOLDER);
|
128 |
$this->pages = array();
|
129 |
$this->pages[] = add_menu_page(__('Gmedia Library', 'grand-media'), 'Gmedia Gallery', 'gmedia_library', 'GrandMedia', array(&$this, 'shell'), $gmediaURL . '/admin/assets/img/gm-icon.png', 11);
|
130 |
$this->pages[] = add_submenu_page('GrandMedia', __('Gmedia Library', 'grand-media'), __('Gmedia Library', 'grand-media'), 'gmedia_library', 'GrandMedia', array(&$this, 'shell'));
|
131 |
+
if(current_user_can('gmedia_library')){
|
132 |
$this->pages[] = add_submenu_page('GrandMedia', __('Add Media Files', 'grand-media'), __('Add/Import Files', 'grand-media'), 'gmedia_upload', 'GrandMedia_AddMedia', array(&$this, 'shell'));
|
133 |
$this->pages[] = add_submenu_page('GrandMedia', __('Tags', 'grand-media'), __('Tags', 'grand-media'), 'gmedia_library', 'GrandMedia_Tags', array(&$this, 'shell'));
|
134 |
$this->pages[] = add_submenu_page('GrandMedia', __('Categories', 'grand-media'), __('Categories', 'grand-media'), 'gmedia_library', 'GrandMedia_Categories', array(&$this, 'shell'));
|
140 |
$this->pages[] = add_submenu_page('GrandMedia', __('Wordpress Media Library', 'grand-media'), __('WP Media Library', 'grand-media'), 'gmedia_import', 'GrandMedia_WordpressLibrary', array(&$this, 'shell'));
|
141 |
}
|
142 |
|
143 |
+
foreach($this->pages as $page){
|
144 |
add_action("load-$page", array(&$this, 'screen_help'));
|
145 |
}
|
146 |
}
|
149 |
* Load the script for the defined page and load only this code
|
150 |
* Display shell of plugin
|
151 |
*/
|
152 |
+
function shell(){
|
153 |
global $gmCore, $gmProcessor, $gmGallery;
|
154 |
|
155 |
$sideLinks = $this->sideLinks();
|
156 |
|
157 |
// check for upgrade
|
158 |
+
if(get_option('gmediaDbVersion') != GMEDIA_DBVERSION){
|
159 |
+
if(get_transient('gmediaUpgrade') || (isset($_GET['do_update']) && ('gmedia' == $_GET['do_update']))){
|
160 |
$sideLinks['grandTitle'] = __('Updating GmediaGallery Plugin', 'grand-media');
|
161 |
+
$sideLinks['sideLinks'] = '';
|
162 |
+
$gmProcessor->page = 'GrandMedia_Update';
|
163 |
+
} else{
|
164 |
return;
|
165 |
}
|
166 |
}
|
167 |
+
|
168 |
?>
|
169 |
<div id="gmedia-container" class="gmedia-admin">
|
170 |
<div id="gmedia-header" class="clearfix">
|
179 |
<?php echo $sideLinks['sideLinks']; ?>
|
180 |
|
181 |
<?php $installDate = get_option('gmediaInstallDate');
|
182 |
+
if($installDate && (strtotime($installDate) < strtotime('2 weeks ago'))){ ?>
|
183 |
<div class="row panel panel-default visible-lg-block">
|
184 |
<div class="panel-heading" data-toggle="collapse" data-target="#support_div_collapse" aria-expanded="true" aria-controls="support_div_collapse" style="cursor:pointer;">
|
185 |
<b><?php _e('Any feedback?', 'grand-media'); ?></b>
|
186 |
</div>
|
187 |
+
<div class="collapse<?php if(empty($gmGallery->options['license_key'])){
|
188 |
echo ' in';
|
189 |
} ?>" id="support_div_collapse">
|
190 |
<div class="panel-body">
|
227 |
<?php
|
228 |
}
|
229 |
|
230 |
+
function sideLinks(){
|
231 |
+
global $submenu, $gmProcessor, $gmGallery;
|
232 |
$content['sideLinks'] = '
|
233 |
<div id="gmedia-navbar">
|
234 |
<div class="row">
|
235 |
+
<ul class="list-group"><li>';
|
236 |
+
if(empty($gmGallery->options['license_key'])){
|
237 |
+
$content['sideLinks'] .= "\n" . '<a class="list-group-item list-group-item-premium" target="_blank" href="http://codeasily.com/product/one-site-license/">' . __('Get Gmedia Premium', 'grand-media') . '</a></li><li>';
|
238 |
+
}
|
239 |
+
foreach($submenu['GrandMedia'] as $menuKey => $menuItem){
|
240 |
+
if($submenu['GrandMedia'][ $menuKey ][2] == $gmProcessor->page){
|
241 |
$iscur = ' active';
|
242 |
+
$content['grandTitle'] = $submenu['GrandMedia'][ $menuKey ][3];
|
243 |
+
} else{
|
244 |
$iscur = '';
|
245 |
}
|
246 |
|
247 |
+
$content['sideLinks'] .= "\n" . '<a class="list-group-item' . $iscur . '" href="' . admin_url('admin.php?page=' . $submenu['GrandMedia'][ $menuKey ][2]) . '">' . $submenu['GrandMedia'][ $menuKey ][0] . '</a>';
|
248 |
}
|
249 |
$content['sideLinks'] .= '
|
250 |
+
</li></ul>
|
251 |
</div>
|
252 |
</div>';
|
253 |
|
254 |
return $content;
|
255 |
}
|
256 |
|
257 |
+
function admin_footer(){
|
258 |
+
$ajax_operations = get_option('gmedia_ajax_long_operations');
|
259 |
+
if(!$ajax_operations){
|
260 |
+
return;
|
261 |
+
}
|
262 |
+
reset($ajax_operations);
|
263 |
+
$ajax = key($ajax_operations);
|
264 |
+
$nonce = wp_create_nonce('ajaxLongOperation');
|
265 |
+
?>
|
266 |
+
<script type="text/javascript">
|
267 |
+
jQuery(document).ready(function($) {
|
268 |
+
var header = $('#gmedia-header');
|
269 |
+
header.append('<div id="ajax-long-operation"><div class="progress"><div class="progress-bar progress-bar-info" style="width: 0%;"></div><div class="progress-bar-indicator">0%</div></div></div>');
|
270 |
+
gmAjaxLongOperation = function() {
|
271 |
+
jQuery.post(ajaxurl, {action: '<?php echo $ajax; ?>', _ajax_nonce: '<?php echo $nonce; ?>'}, function(r) {
|
272 |
+
if(r.data) {
|
273 |
+
jQuery('.progress-bar-info', header).width(r.data.progress);
|
274 |
+
var indicator = r.data.info? r.data.info + ' ' + r.data.progress : r.data.progress;
|
275 |
+
jQuery('.progress-bar-indicator', header).html(indicator);
|
276 |
+
|
277 |
+
if(r.data.done) {
|
278 |
+
return;
|
279 |
+
}
|
280 |
+
}
|
281 |
+
gmAjaxLongOperation();
|
282 |
+
});
|
283 |
+
}
|
284 |
+
gmAjaxLongOperation();
|
285 |
+
});
|
286 |
+
</script>
|
287 |
+
<?php
|
288 |
+
}
|
289 |
+
|
290 |
+
function controller(){
|
291 |
|
292 |
global $gmProcessor;
|
293 |
+
switch($gmProcessor->page){
|
294 |
case 'GrandMedia_AddMedia':
|
295 |
include_once(dirname(__FILE__) . '/pages/addmedia/addmedia.php');
|
296 |
break;
|
297 |
case 'GrandMedia_Albums':
|
298 |
+
if(isset($_GET['edit_item'])){
|
299 |
include_once(dirname(__FILE__) . '/pages/terms/edit-term.php');
|
300 |
+
} else{
|
301 |
include_once(dirname(__FILE__) . '/pages/terms/terms.php');
|
302 |
}
|
303 |
break;
|
304 |
case 'GrandMedia_Categories':
|
305 |
+
if(isset($_GET['edit_item'])){
|
306 |
include_once(dirname(__FILE__) . '/pages/terms/edit-term.php');
|
307 |
+
} else{
|
308 |
include_once(dirname(__FILE__) . '/pages/terms/terms.php');
|
309 |
}
|
310 |
break;
|
312 |
include_once(dirname(__FILE__) . '/pages/terms/terms.php');
|
313 |
break;
|
314 |
case 'GrandMedia_Galleries':
|
315 |
+
if(isset($_GET['gallery_module']) || isset($_GET['edit_item'])){
|
316 |
include_once(dirname(__FILE__) . '/pages/galleries/edit-gallery.php');
|
317 |
+
} else{
|
318 |
include_once(dirname(__FILE__) . '/pages/galleries/galleries.php');
|
319 |
}
|
320 |
break;
|
321 |
case 'GrandMedia_Modules':
|
322 |
+
if(isset($_GET['preset_module']) || isset($_GET['preset'])){
|
323 |
+
include_once(dirname(__FILE__) . '/pages/modules/edit-preset.php');
|
324 |
+
} else{
|
325 |
+
include_once(dirname(__FILE__) . '/pages/modules/modules.php');
|
326 |
+
}
|
327 |
break;
|
328 |
case 'GrandMedia_Settings':
|
329 |
include_once(dirname(__FILE__) . '/pages/settings/settings.php');
|
350 |
/**
|
351 |
* @param $hook
|
352 |
*/
|
353 |
+
function load_scripts($hook){
|
354 |
global $gmCore, $gmProcessor, $gmGallery;
|
355 |
|
356 |
// no need to go on if it's not a plugin page
|
357 |
+
if('admin.php' != $hook && strpos($gmCore->_get('page'), 'GrandMedia') === false){
|
358 |
return;
|
359 |
}
|
360 |
|
361 |
+
if($gmGallery->options['isolation_mode']){
|
362 |
global $wp_scripts, $wp_styles;
|
363 |
+
foreach($wp_scripts->registered as $handle => $wp_script){
|
364 |
+
if(((false !== strpos($wp_script->src, '/plugins/')) || (false !== strpos($wp_script->src, '/themes/'))) && (false === strpos($wp_script->src, GMEDIA_FOLDER))){
|
365 |
+
if(in_array($handle, $wp_scripts->queue)){
|
366 |
wp_dequeue_script($handle);
|
367 |
}
|
368 |
wp_deregister_script($handle);
|
369 |
}
|
370 |
}
|
371 |
+
foreach($wp_styles->registered as $handle => $wp_style){
|
372 |
+
if(((false !== strpos($wp_style->src, '/plugins/')) || (false !== strpos($wp_style->src, '/themes/'))) && (false === strpos($wp_style->src, GMEDIA_FOLDER))){
|
373 |
+
if(in_array($handle, $wp_styles->queue)){
|
374 |
wp_dequeue_style($handle);
|
375 |
}
|
376 |
wp_deregister_style($handle);
|
384 |
wp_register_script('selectize', $gmCore->gmedia_url . '/assets/selectize/selectize.min.js', array('jquery'), '0.12.1');
|
385 |
wp_register_style('selectize', $gmCore->gmedia_url . '/assets/selectize/selectize.bootstrap3.css', array('gmedia-bootstrap'), '0.12.1', 'screen');
|
386 |
|
387 |
+
if(isset($_GET['page'])){
|
388 |
+
switch($_GET['page']){
|
389 |
case "GrandMedia" :
|
390 |
+
if($gmCore->caps['gmedia_edit_media']){
|
391 |
+
if($gmCore->_get('gmediablank') == 'image_editor'){
|
392 |
wp_enqueue_script('camanjs', $gmCore->gmedia_url . '/assets/image-editor/camanjs/caman.full.min.js', array(), '4.1.2');
|
393 |
|
394 |
wp_enqueue_style('nouislider', $gmCore->gmedia_url . '/assets/image-editor/js/jquery.nouislider.css', array('gmedia-bootstrap'), '6.1.0');
|
398 |
wp_enqueue_script('gmedia-image-editor', $gmCore->gmedia_url . '/assets/image-editor/image-editor.js', array('jquery', 'camanjs'), '0.9.16');
|
399 |
break;
|
400 |
}
|
401 |
+
if($gmProcessor->mode == 'edit'){
|
402 |
wp_enqueue_script('alphanum', $gmCore->gmedia_url . '/assets/jq-plugins/jquery.alphanum.js', array('jquery'), '1.0.16');
|
403 |
|
404 |
wp_enqueue_script('moment', $gmCore->gmedia_url . '/assets/bootstrap-datetimepicker/moment.min.js', array('jquery'), '2.5.1');
|
405 |
wp_enqueue_style('datetimepicker', $gmCore->gmedia_url . '/assets/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css', array('gmedia-bootstrap'), '2.1.32');
|
406 |
+
wp_enqueue_script('datetimepicker', $gmCore->gmedia_url . '/assets/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js', array('jquery',
|
407 |
+
'moment',
|
408 |
+
'gmedia-bootstrap'
|
|
|
409 |
), '2.1.32');
|
410 |
}
|
411 |
}
|
412 |
wp_enqueue_style('selectize');
|
413 |
wp_enqueue_script('selectize');
|
414 |
+
wp_enqueue_script('wavesurfer', $gmCore->gmedia_url . '/assets/wavesurfer/wavesurfer.min.js', array('jquery'), '1.1.5');
|
415 |
break;
|
416 |
case "GrandMedia_WordpressLibrary" :
|
417 |
+
if($gmCore->caps['gmedia_import']){
|
418 |
wp_enqueue_style('selectize');
|
419 |
wp_enqueue_script('selectize');
|
420 |
}
|
421 |
break;
|
422 |
case "GrandMedia_Albums" :
|
423 |
+
if(isset($_GET['edit_item']) && $gmCore->caps['gmedia_album_manage']){
|
424 |
wp_enqueue_style('jquery-ui-smoothness', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css', array(), '1.10.2', 'screen');
|
425 |
wp_enqueue_script('jquery-ui-full', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js', array(), '1.10.2');
|
426 |
|
428 |
}
|
429 |
break;
|
430 |
case "GrandMedia_AddMedia" :
|
431 |
+
if($gmCore->caps['gmedia_terms']){
|
432 |
wp_enqueue_style('selectize');
|
433 |
wp_enqueue_script('selectize');
|
434 |
}
|
435 |
+
if($gmCore->caps['gmedia_upload']){
|
436 |
$tab = $gmCore->_get('tab', 'upload');
|
437 |
+
if($tab == 'upload'){
|
438 |
wp_enqueue_style('jquery-ui-smoothness', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css', array(), '1.10.2', 'screen');
|
439 |
wp_enqueue_script('jquery-ui-full', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js', array(), '1.10.2');
|
440 |
|
441 |
wp_enqueue_script('gmedia-plupload', $gmCore->gmedia_url . '/assets/plupload/plupload.full.min.js', array('jquery', 'jquery-ui-full'), '2.1.2');
|
442 |
|
443 |
wp_enqueue_style('jquery.ui.plupload', $gmCore->gmedia_url . '/assets/plupload/jquery.ui.plupload/css/jquery.ui.plupload.css', array('jquery-ui-smoothness'), '2.1.2', 'screen');
|
444 |
+
wp_enqueue_script('jquery.ui.plupload', $gmCore->gmedia_url . '/assets/plupload/jquery.ui.plupload/jquery.ui.plupload.min.js', array('gmedia-plupload',
|
445 |
+
'jquery-ui-full'
|
|
|
446 |
), '2.1.2');
|
447 |
|
448 |
}
|
453 |
// under construction
|
454 |
break;
|
455 |
case "GrandMedia_Galleries" :
|
456 |
+
if($gmCore->caps['gmedia_gallery_manage'] && (isset($_GET['gallery_module']) || isset($_GET['edit_item']))){
|
457 |
+
|
458 |
+
wp_enqueue_style('jquery-ui-smoothness', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css', array(), '1.10.2', 'screen');
|
459 |
+
wp_enqueue_script('jquery-ui-resizable');
|
460 |
+
|
461 |
+
wp_enqueue_script('jquery-ui-sortable');
|
462 |
+
wp_enqueue_style('selectize');
|
463 |
+
wp_enqueue_script('selectize');
|
464 |
+
|
465 |
+
wp_enqueue_style('jquery.minicolors', $gmCore->gmedia_url . '/assets/minicolors/jquery.minicolors.css', array('gmedia-bootstrap'), '0.9.13');
|
466 |
+
wp_enqueue_script('jquery.minicolors', $gmCore->gmedia_url . '/assets/minicolors/jquery.minicolors.js', array('jquery'), '0.9.13');
|
467 |
+
}
|
468 |
+
break;
|
469 |
+
case "GrandMedia_Modules" :
|
470 |
+
if(isset($_GET['preset_module']) || isset($_GET['preset'])){
|
471 |
|
472 |
wp_enqueue_style('jquery-ui-smoothness', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.min.css', array(), '1.10.2', 'screen');
|
473 |
wp_enqueue_script('jquery-ui-resizable');
|
488 |
|
489 |
}
|
490 |
|
491 |
+
function screen_help(){
|
492 |
$screen = get_current_screen();
|
493 |
$screen_id = explode('page_', $screen->id, 2);
|
494 |
$screen_id = $screen_id[1];
|
495 |
|
496 |
+
$screen->add_help_tab(array('id' => 'help_' . $screen_id . '_support',
|
497 |
+
'title' => __('Support'),
|
498 |
+
'content' => '<h4>First steps</h4>
|
|
|
499 |
<p>If you have any problems with displaying Gmedia Gallery in admin or on website. Before posting to the Forum try next:</p>
|
500 |
<ul>
|
501 |
<li>Exclude plugin conflicts: Disable other plugins one by one and check if it resolve problem</li>
|
509 |
</p>',
|
510 |
));
|
511 |
|
512 |
+
switch($screen_id){
|
513 |
case 'GrandMedia' :
|
514 |
break;
|
515 |
case 'GrandMedia_Settings' :
|
516 |
+
if(current_user_can('manage_options')){
|
517 |
+
$screen->add_help_tab(array('id' => 'help_' . $screen_id . '_license',
|
518 |
+
'title' => __('License Key'),
|
519 |
+
'content' => '<h4>Should I buy it, to use plugin?</h4>
|
|
|
520 |
<p>No, plugin is absolutely free and all modules for it are free to install.</p>
|
521 |
<p>Even premium modules are fully functional and free to test, but have backlink labels. To remove baclink labels from premium modules you need license key.</p>
|
522 |
<p>Note: License Key will remove backlinks from all current and future premium modules, so you can use all available modules on one website.</p>
|
536 |
*
|
537 |
* @return string
|
538 |
*/
|
539 |
+
function screen_settings($current, $screen){
|
540 |
global $gmProcessor, $gmCore;
|
541 |
+
if(in_array($screen->id, $this->pages)){
|
542 |
|
543 |
$gm_screen_options = $gmProcessor->user_options;
|
544 |
|
550 |
|
551 |
$screen_id = explode('page_', $screen->id, 2);
|
552 |
|
553 |
+
switch($screen_id[1]){
|
554 |
case 'GrandMedia' :
|
555 |
$settings = '
|
556 |
<div class="form-inline pull-left">
|
575 |
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
576 |
</div>
|
577 |
';
|
578 |
+
if('edit' == $gmCore->_get('mode')){
|
579 |
$settings .= '
|
580 |
<div class="form-group">
|
581 |
<select name="gm_screen_options[library_edit_quicktags]" class="form-control input-sm">
|
591 |
break;
|
592 |
case 'GrandMedia_AddMedia' :
|
593 |
$tab = $gmCore->_get('tab', 'upload');
|
594 |
+
if('upload' == $tab){
|
595 |
$html4_hide = ('html4' == $gm_screen_options['uploader_runtime'])? ' hide' : '';
|
596 |
$settings = '
|
597 |
<div class="form-inline pull-left">
|
620 |
}
|
621 |
break;
|
622 |
case 'GrandMedia_Albums' :
|
623 |
+
if(isset($_GET['edit_item'])){
|
624 |
$settings = '
|
625 |
<div class="form-inline pull-left">
|
626 |
<div class="form-group">
|
628 |
</div>
|
629 |
</div>
|
630 |
';
|
631 |
+
} else{
|
632 |
+
$settings = '
|
633 |
+
<div class="form-inline pull-left">
|
634 |
+
<div class="form-group">
|
635 |
+
<input type="number" max="999" min="0" step="5" size="3" name="gm_screen_options[per_page_gmedia_album]" class="form-control input-sm" style="width: 5em;" value="' . $gm_screen_options['per_page_gmedia_album'] . '" /> <span>' . __('items per page', 'grand-media') . '</span>
|
636 |
+
</div>
|
637 |
+
<div class="form-group">
|
638 |
+
<select name="gm_screen_options[orderby_gmedia_album]" class="form-control input-sm">
|
639 |
+
<option' . selected($gm_screen_options['orderby_gmedia_album'], 'id', false) . ' value="id">' . __('ID', 'grand-media') . '</option>
|
640 |
+
<option' . selected($gm_screen_options['orderby_gmedia_album'], 'name', false) . ' value="name">' . __('Name', 'grand-media') . '</option>
|
641 |
+
<option' . selected($gm_screen_options['orderby_gmedia_album'], 'count', false) . ' value="count">' . __('Gmedia Count', 'grand-media') . '</option>
|
642 |
+
<option' . selected($gm_screen_options['orderby_gmedia_album'], 'global', false) . ' value="global">' . __('Author ID', 'grand-media') . '</option>
|
643 |
+
</select> <span>' . __('order items', 'grand-media') . '</span>
|
644 |
+
</div>
|
645 |
+
<div class="form-group">
|
646 |
+
<select name="gm_screen_options[sortorder_gmedia_album]" class="form-control input-sm">
|
647 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_album'], 'DESC', false) . ' value="DESC">' . __('DESC', 'grand-media') . '</option>
|
648 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_album'], 'ASC', false) . ' value="ASC">' . __('ASC', 'grand-media') . '</option>
|
649 |
+
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
650 |
+
</div>
|
651 |
+
</div>
|
652 |
+
';
|
653 |
}
|
654 |
break;
|
655 |
case 'GrandMedia_Categories' :
|
656 |
+
if(!isset($_GET['edit_item'])){
|
657 |
+
$settings = '
|
658 |
+
<div class="form-inline pull-left">
|
659 |
+
<div class="form-group">
|
660 |
+
<input type="number" max="999" min="0" step="5" size="3" name="gm_screen_options[per_page_gmedia_category]" class="form-control input-sm" style="width: 5em;" value="' . $gm_screen_options['per_page_gmedia_category'] . '" /> <span>' . __('items per page', 'grand-media') . '</span>
|
661 |
+
</div>
|
662 |
+
<div class="form-group">
|
663 |
+
<select name="gm_screen_options[orderby_gmedia_category]" class="form-control input-sm">
|
664 |
+
<option' . selected($gm_screen_options['orderby_gmedia_category'], 'id', false) . ' value="id">' . __('ID', 'grand-media') . '</option>
|
665 |
+
<option' . selected($gm_screen_options['orderby_gmedia_category'], 'name', false) . ' value="name">' . __('Name', 'grand-media') . '</option>
|
666 |
+
<option' . selected($gm_screen_options['orderby_gmedia_category'], 'count', false) . ' value="count">' . __('Gmedia Count', 'grand-media') . '</option>
|
667 |
+
</select> <span>' . __('order items', 'grand-media') . '</span>
|
668 |
+
</div>
|
669 |
+
<div class="form-group">
|
670 |
+
<select name="gm_screen_options[sortorder_gmedia_category]" class="form-control input-sm">
|
671 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_category'], 'DESC', false) . ' value="DESC">' . __('DESC', 'grand-media') . '</option>
|
672 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_category'], 'ASC', false) . ' value="ASC">' . __('ASC', 'grand-media') . '</option>
|
673 |
+
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
674 |
+
</div>
|
675 |
+
</div>
|
676 |
+
';
|
677 |
+
}
|
678 |
+
break;
|
679 |
+
case 'GrandMedia_Tags' :
|
680 |
$settings = '
|
681 |
<div class="form-inline pull-left">
|
682 |
<div class="form-group">
|
683 |
+
<input type="number" max="999" min="0" step="5" size="3" name="gm_screen_options[per_page_gmedia_tag]" class="form-control input-sm" style="width: 5em;" value="' . $gm_screen_options['per_page_gmedia_tag'] . '" /> <span>' . __('items per page', 'grand-media') . '</span>
|
684 |
</div>
|
685 |
<div class="form-group">
|
686 |
+
<select name="gm_screen_options[orderby_gmedia_tag]" class="form-control input-sm">
|
687 |
+
<option' . selected($gm_screen_options['orderby_gmedia_tag'], 'id', false) . ' value="id">' . __('ID', 'grand-media') . '</option>
|
688 |
+
<option' . selected($gm_screen_options['orderby_gmedia_tag'], 'name', false) . ' value="name">' . __('Name', 'grand-media') . '</option>
|
689 |
+
<option' . selected($gm_screen_options['orderby_gmedia_tag'], 'count', false) . ' value="count">' . __('Gmedia Count', 'grand-media') . '</option>
|
|
|
690 |
</select> <span>' . __('order items', 'grand-media') . '</span>
|
691 |
</div>
|
692 |
<div class="form-group">
|
693 |
+
<select name="gm_screen_options[sortorder_gmedia_tag]" class="form-control input-sm">
|
694 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_tag'], 'DESC', false) . ' value="DESC">' . __('DESC', 'grand-media') . '</option>
|
695 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_tag'], 'ASC', false) . ' value="ASC">' . __('ASC', 'grand-media') . '</option>
|
696 |
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
697 |
</div>
|
698 |
</div>
|
699 |
';
|
700 |
break;
|
701 |
case 'GrandMedia_Galleries' :
|
702 |
+
if(!$gmCore->_get('edit_item') && !$gmCore->_get('gallery_module')){
|
703 |
$settings = '
|
704 |
<div class="form-inline pull-left">
|
705 |
<div class="form-group">
|
706 |
+
<input type="number" max="999" min="0" step="5" size="3" name="gm_screen_options[per_page_gmedia_gallery]" class="form-control input-sm" style="width: 5em;" value="' . $gm_screen_options['per_page_gmedia_gallery'] . '" /> <span>' . __('items per page', 'grand-media') . '</span>
|
707 |
</div>
|
708 |
<div class="form-group">
|
709 |
+
<select name="gm_screen_options[orderby_gmedia_gallery]" class="form-control input-sm">
|
710 |
+
<option' . selected($gm_screen_options['orderby_gmedia_gallery'], 'id', false) . ' value="id">' . __('ID', 'grand-media') . '</option>
|
711 |
+
<option' . selected($gm_screen_options['orderby_gmedia_gallery'], 'name', false) . ' value="name">' . __('Name', 'grand-media') . '</option>
|
712 |
+
<option' . selected($gm_screen_options['orderby_gmedia_gallery'], 'global', false) . ' value="global">' . __('Author ID', 'grand-media') . '</option>
|
713 |
</select> <span>' . __('order items', 'grand-media') . '</span>
|
714 |
</div>
|
715 |
<div class="form-group">
|
716 |
+
<select name="gm_screen_options[sortorder_gmedia_gallery]" class="form-control input-sm">
|
717 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_gallery'], 'DESC', false) . ' value="DESC">' . __('DESC', 'grand-media') . '</option>
|
718 |
+
<option' . selected($gm_screen_options['sortorder_gmedia_gallery'], 'ASC', false) . ' value="ASC">' . __('ASC', 'grand-media') . '</option>
|
719 |
</select> <span>' . __('sort order', 'grand-media') . '</span>
|
720 |
</div>
|
721 |
</div>
|
750 |
break;
|
751 |
}
|
752 |
|
753 |
+
if($settings){
|
754 |
$current = $title . $settings . $wp_screen_options . $button;
|
755 |
}
|
756 |
|
766 |
*
|
767 |
* @return array
|
768 |
*/
|
769 |
+
function screen_settings_save($status, $option, $value){
|
770 |
global $user_ID;
|
771 |
+
if('gm_screen_options' == $option){
|
772 |
/*
|
773 |
global $gmGallery;
|
774 |
foreach ( $_POST['gm_screen_options'] as $key => $val ) {
|
777 |
update_option( 'gmediaOptions', $gmGallery->options );
|
778 |
*/
|
779 |
$gm_screen_options = get_user_meta($user_ID, 'gm_screen_options', true);
|
780 |
+
if(!is_array($gm_screen_options)){
|
781 |
$gm_screen_options = array();
|
782 |
}
|
783 |
$value = array_merge($gm_screen_options, $_POST['gm_screen_options']);
|
admin/ajax.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
add_action('wp_ajax_gmedia_update_data', 'gmedia_update_data');
|
3 |
-
function gmedia_update_data()
|
4 |
global $gmDB, $gmCore;
|
5 |
check_ajax_referer("GmediaGallery");
|
6 |
-
if(!current_user_can('gmedia_edit_media'))
|
7 |
die('-1');
|
8 |
}
|
9 |
|
@@ -11,10 +11,10 @@ function gmedia_update_data() {
|
|
11 |
|
12 |
wp_parse_str($data, $gmedia);
|
13 |
|
14 |
-
if(!empty($gmedia['ID']))
|
15 |
$item = $gmDB->get_gmedia($gmedia['ID']);
|
16 |
-
if((int)$item->author != get_current_user_id())
|
17 |
-
if(!current_user_can('gmedia_edit_others_media'))
|
18 |
die('-2');
|
19 |
}
|
20 |
}
|
@@ -22,74 +22,71 @@ function gmedia_update_data() {
|
|
22 |
$gmedia['modified'] = current_time('mysql');
|
23 |
$gmedia['mime_type'] = $item->mime_type;
|
24 |
$gmedia['gmuid'] = $item->gmuid;
|
25 |
-
if(!current_user_can('gmedia_delete_others_media'))
|
26 |
$gmedia['author'] = $item->author;
|
27 |
}
|
28 |
|
29 |
$gmuid = pathinfo($item->gmuid);
|
30 |
|
31 |
$gmedia['filename'] = preg_replace('/[^a-z0-9_\.-]+/i', '_', $gmedia['filename']);
|
32 |
-
if(($gmedia['filename'] != $gmuid['filename']) && (current_user_can('gmedia_delete_others_media') || ((int)$item->author == get_current_user_id())))
|
33 |
$fileinfo = $gmCore->fileinfo($gmedia['filename'] . '.' . $gmuid['extension']);
|
34 |
-
if(false !== $fileinfo)
|
35 |
-
if('image' == $fileinfo['dirname'] && file_is_displayable_image($fileinfo['dirpath'] . '/' . $item->gmuid))
|
36 |
@rename($fileinfo['dirpath_original'] . '/' . $item->gmuid, $fileinfo['filepath_original']);
|
37 |
@rename($fileinfo['dirpath_thumb'] . '/' . $item->gmuid, $fileinfo['filepath_thumb']);
|
38 |
}
|
39 |
-
if(@rename($fileinfo['dirpath'] . '/' . $item->gmuid, $fileinfo['filepath']))
|
40 |
$gmedia['gmuid'] = $fileinfo['basename'];
|
41 |
}
|
42 |
}
|
43 |
}
|
44 |
-
if(!current_user_can('gmedia_terms'))
|
45 |
unset($gmedia['terms']);
|
46 |
}
|
47 |
|
48 |
$id = $gmDB->insert_gmedia($gmedia);
|
49 |
-
if(!is_wp_error($id))
|
50 |
// Meta Stuff
|
51 |
-
if(isset($gmedia['meta']) && is_array($gmedia['meta']))
|
52 |
$meta_error = array();
|
53 |
-
foreach($gmedia['meta'] as $key => $value)
|
54 |
-
if($gmCore->is_digit($key))
|
55 |
$mid = (int)$key;
|
56 |
//$value = wp_unslash( $value );
|
57 |
-
if(!($meta = $gmDB->get_metadata_by_mid('gmedia', $mid)))
|
58 |
-
$meta_error[] = array(
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
'meta_key' => $meta->meta_key
|
63 |
);
|
64 |
continue;
|
65 |
}
|
66 |
-
if('' == trim($value))
|
67 |
-
$meta_error[] = array(
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
'meta_value' => $meta->meta_value
|
73 |
);
|
74 |
continue;
|
75 |
}
|
76 |
|
77 |
-
if($meta->meta_value != $value)
|
78 |
-
if(!($u = $gmDB->update_metadata_by_mid('gmedia', $mid, $value)))
|
79 |
-
$meta_error[] = array(
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
'meta_value' => $meta->meta_value
|
85 |
);
|
86 |
}
|
87 |
}
|
88 |
-
} elseif(
|
89 |
-
if('_cover' == $key)
|
90 |
$value = ltrim($value, '#');
|
91 |
-
} elseif('_gps' == $key)
|
92 |
-
if($value)
|
93 |
$latlng = explode(',', $value);
|
94 |
$value = array('lat' => trim($latlng[0]), 'lng' => trim($latlng[1]));
|
95 |
}
|
@@ -100,27 +97,27 @@ function gmedia_update_data() {
|
|
100 |
}
|
101 |
}
|
102 |
$result = $gmDB->get_gmedia($id);
|
103 |
-
} else
|
104 |
$result = $gmDB->get_gmedia($id);
|
105 |
}
|
106 |
-
if(current_user_can('gmedia_terms'))
|
107 |
$tags = $gmDB->get_the_gmedia_terms($id, 'gmedia_tag');
|
108 |
-
if($tags)
|
109 |
$tags_list = array();
|
110 |
-
foreach($tags as $tag)
|
111 |
$tags_list[] = $tag->name;
|
112 |
}
|
113 |
$result->tags = implode(', ', $tags_list);
|
114 |
}
|
115 |
-
if(!empty($gmedia['terms']['gmedia_album']))
|
116 |
-
$alb_id =
|
117 |
-
$alb = $gmDB->get_term($alb_id);
|
118 |
-
$result->album_status = $alb->status;
|
119 |
-
} else
|
120 |
$result->album_status = 'none';
|
121 |
}
|
122 |
}
|
123 |
-
if(!empty($meta_error))
|
124 |
$result->meta_error = $meta_error;
|
125 |
}
|
126 |
|
@@ -132,10 +129,10 @@ function gmedia_update_data() {
|
|
132 |
}
|
133 |
|
134 |
add_action('wp_ajax_gmedit_save', 'gmedit_save');
|
135 |
-
function gmedit_save()
|
136 |
global $gmDB, $gmCore, $gmGallery;
|
137 |
check_ajax_referer("gmedit-save");
|
138 |
-
if(!current_user_can('gmedia_edit_media'))
|
139 |
die('-1');
|
140 |
}
|
141 |
|
@@ -147,9 +144,9 @@ function gmedit_save() {
|
|
147 |
$applyto = $gmCore->_post('applyto', 'web_thumb');
|
148 |
|
149 |
$item = $gmDB->get_gmedia($gmid);
|
150 |
-
if(!empty($item))
|
151 |
-
if((int)$item->author != get_current_user_id())
|
152 |
-
if(!current_user_can('gmedia_edit_others_media'))
|
153 |
die('-2');
|
154 |
}
|
155 |
}
|
@@ -168,10 +165,10 @@ function gmedit_save() {
|
|
168 |
|
169 |
$size = @getimagesize($fileinfo['filepath']);
|
170 |
|
171 |
-
do
|
172 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
173 |
-
if(function_exists('memory_get_usage'))
|
174 |
-
switch($extensions[$size[2]])
|
175 |
case 'GIF':
|
176 |
$CHANNEL = 1;
|
177 |
break;
|
@@ -193,25 +190,28 @@ function gmedit_save() {
|
|
193 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
194 |
$current_limit = @ini_get('memory_limit');
|
195 |
$current_limit_int = intval($current_limit);
|
196 |
-
if(false !== strpos($current_limit, 'M'))
|
197 |
$current_limit_int *= $MB;
|
198 |
}
|
199 |
-
if(false !== strpos($current_limit, 'G'))
|
200 |
$current_limit_int *= 1024;
|
201 |
}
|
202 |
|
203 |
-
if(-1 != $current_limit && $memoryNeeded > $current_limit_int)
|
204 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
|
|
|
|
|
|
205 |
@ini_set('memory_limit', $newLimit . 'M');
|
206 |
}
|
207 |
}
|
208 |
|
209 |
-
if('thumb' == $applyto)
|
210 |
$editfile = $fileinfo['filepath_thumb'];
|
211 |
-
} else
|
212 |
$editfile = $fileinfo['filepath'];
|
213 |
}
|
214 |
-
if(!@file_put_contents($editfile, $image['data']))
|
215 |
$fail = $fileinfo['basename'] . ": " . __('Can\'t write to file. Permission denied', 'grand-media');
|
216 |
break;
|
217 |
}
|
@@ -220,18 +220,18 @@ function gmedit_save() {
|
|
220 |
$gmDB->update_metadata($meta_type = 'gmedia', $item->ID, $meta_key = '_modified', $modified);
|
221 |
|
222 |
// Web-image
|
223 |
-
if('thumb' !== $applyto)
|
224 |
-
if(('JPG' == $extensions[$size[2]]) && !(extension_loaded('imagick') || class_exists("Imagick")))
|
225 |
$gmCore->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
226 |
}
|
227 |
}
|
228 |
// Thumbnail
|
229 |
-
if('web_thumb' == $applyto)
|
230 |
$size_ratio = $size[0] / $size[1];
|
231 |
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
232 |
-
if($thumbimg['resize'])
|
233 |
$editor = wp_get_image_editor($editfile);
|
234 |
-
if(is_wp_error($editor))
|
235 |
$fail = $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message();
|
236 |
break;
|
237 |
}
|
@@ -239,31 +239,31 @@ function gmedit_save() {
|
|
239 |
$editor->set_quality($thumbimg['quality']);
|
240 |
$ed_size = $editor->get_size();
|
241 |
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
242 |
-
if(1 > $ed_ratio)
|
243 |
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
244 |
-
} else
|
245 |
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
246 |
}
|
247 |
-
if(is_wp_error($resized))
|
248 |
$fail = $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})) applyto-{$applyto}: " . $resized->get_error_message();
|
249 |
break;
|
250 |
}
|
251 |
|
252 |
$thumbis = false;
|
253 |
-
if(file_exists($fileinfo['filepath_thumb']))
|
254 |
$thumbis = true;
|
255 |
rename($fileinfo['filepath_thumb'], $fileinfo['filepath_thumb'] . '.tmp');
|
256 |
}
|
257 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
258 |
-
if(is_wp_error($saved))
|
259 |
-
if($thumbis)
|
260 |
rename($fileinfo['filepath_thumb'] . '.tmp', $fileinfo['filepath_thumb']);
|
261 |
}
|
262 |
$fail = $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message();
|
263 |
break;
|
264 |
}
|
265 |
|
266 |
-
} else
|
267 |
@copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
268 |
}
|
269 |
}
|
@@ -281,9 +281,9 @@ function gmedit_save() {
|
|
281 |
$success = sprintf(__('Image "%d" updated', 'grand-media'), $id);
|
282 |
} while(0);
|
283 |
|
284 |
-
if(empty($fail))
|
285 |
$out = array('msg' => $gmCore->alert('info', $success), 'modified' => $gmedia['modified']);
|
286 |
-
} else
|
287 |
$out = array('error' => $gmCore->alert('danger', $fail));
|
288 |
}
|
289 |
|
@@ -295,211 +295,44 @@ function gmedit_save() {
|
|
295 |
}
|
296 |
|
297 |
add_action('wp_ajax_gmedit_restore', 'gmedit_restore');
|
298 |
-
function gmedit_restore()
|
299 |
-
global $
|
300 |
check_ajax_referer("gmedit-save");
|
301 |
-
if(!current_user_can('gmedia_edit_media'))
|
302 |
die('-1');
|
303 |
}
|
304 |
|
305 |
-
$
|
306 |
-
$
|
307 |
-
$success = '';
|
308 |
-
$gmid = $gmCore->_post('id');
|
309 |
-
|
310 |
-
$item = $gmDB->get_gmedia($gmid);
|
311 |
-
if(!empty($item)) {
|
312 |
-
if((int)$item->author != get_current_user_id()) {
|
313 |
-
if(!current_user_can('gmedia_edit_others_media')) {
|
314 |
-
die('-2');
|
315 |
-
}
|
316 |
-
}
|
317 |
-
$meta = $gmDB->get_metadata('gmedia', $item->ID);
|
318 |
-
$metadata = $meta['_metadata'][0];
|
319 |
-
$gmedia['ID'] = $gmid;
|
320 |
-
$gmedia['date'] = $item->date;
|
321 |
-
$gmedia['modified'] = current_time('mysql');
|
322 |
-
$gmedia['author'] = $item->author;
|
323 |
-
|
324 |
-
$webimg = $gmGallery->options['image'];
|
325 |
-
$thumbimg = $gmGallery->options['thumb'];
|
326 |
-
|
327 |
-
$fileinfo = $gmCore->fileinfo($item->gmuid, false);
|
328 |
-
|
329 |
-
$size = @getimagesize($fileinfo['filepath_original']);
|
330 |
-
|
331 |
-
do {
|
332 |
-
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
333 |
-
if(function_exists('memory_get_usage')) {
|
334 |
-
switch($extensions[$size[2]]) {
|
335 |
-
case 'GIF':
|
336 |
-
$CHANNEL = 1;
|
337 |
-
break;
|
338 |
-
case 'JPG':
|
339 |
-
$CHANNEL = $size['channels'];
|
340 |
-
break;
|
341 |
-
case 'PNG':
|
342 |
-
$CHANNEL = 3;
|
343 |
-
break;
|
344 |
-
case 'BMP':
|
345 |
-
default:
|
346 |
-
$CHANNEL = 6;
|
347 |
-
break;
|
348 |
-
}
|
349 |
-
$MB = 1048576; // number of bytes in 1M
|
350 |
-
$K64 = 65536; // number of bytes in 64K
|
351 |
-
$TWEAKFACTOR = 1.8; // Or whatever works for you
|
352 |
-
$memoryNeeded = round(($size[0] * $size[1] * $size['bits'] * $CHANNEL / 8 + $K64) * $TWEAKFACTOR);
|
353 |
-
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
354 |
-
$current_limit = @ini_get('memory_limit');
|
355 |
-
$current_limit_int = intval($current_limit);
|
356 |
-
if(false !== strpos($current_limit, 'M')) {
|
357 |
-
$current_limit_int *= $MB;
|
358 |
-
}
|
359 |
-
if(false !== strpos($current_limit, 'G')) {
|
360 |
-
$current_limit_int *= 1024;
|
361 |
-
}
|
362 |
-
|
363 |
-
if(-1 != $current_limit && $memoryNeeded > $current_limit_int) {
|
364 |
-
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
365 |
-
@ini_set('memory_limit', $newLimit . 'M');
|
366 |
-
}
|
367 |
-
}
|
368 |
-
|
369 |
-
$size_ratio = $size[0] / $size[1];
|
370 |
-
|
371 |
-
$angle = 0;
|
372 |
-
$image_meta = @$gmCore->wp_read_image_metadata($fileinfo['filepath_original']);
|
373 |
-
if(!empty($image_meta['orientation'])) {
|
374 |
-
switch($image_meta['orientation']) {
|
375 |
-
case 3:
|
376 |
-
$angle = 180;
|
377 |
-
break;
|
378 |
-
case 6:
|
379 |
-
$angle = 270;
|
380 |
-
$size_ratio = $size[1] / $size[0];
|
381 |
-
break;
|
382 |
-
case 8:
|
383 |
-
$angle = 90;
|
384 |
-
$size_ratio = $size[1] / $size[0];
|
385 |
-
break;
|
386 |
-
}
|
387 |
-
}
|
388 |
-
|
389 |
-
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
390 |
-
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
391 |
-
|
392 |
-
if($webimg['resize'] || $thumbimg['resize'] || $angle) {
|
393 |
-
|
394 |
-
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
395 |
-
if(is_wp_error($editor)) {
|
396 |
-
$fail = $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message();
|
397 |
-
break;
|
398 |
-
}
|
399 |
-
|
400 |
-
if($angle) {
|
401 |
-
$editor->rotate($angle);
|
402 |
-
}
|
403 |
-
|
404 |
-
if($webimg['resize'] || $angle) {
|
405 |
-
// Web-image
|
406 |
-
$editor->set_quality($webimg['quality']);
|
407 |
-
|
408 |
-
if($webimg['resize']) {
|
409 |
-
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
410 |
-
if(is_wp_error($resized)) {
|
411 |
-
$fail = $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})): " . $resized->get_error_message();
|
412 |
-
break;
|
413 |
-
}
|
414 |
-
}
|
415 |
-
|
416 |
-
$saved = $editor->save($fileinfo['filepath']);
|
417 |
-
if(is_wp_error($saved)) {
|
418 |
-
$fail = $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->webimage): " . $saved->get_error_message();
|
419 |
-
break;
|
420 |
-
}
|
421 |
-
if(('JPG' == $extensions[$size[2]]) && !(extension_loaded('imagick') || class_exists("Imagick"))) {
|
422 |
-
$gmCore->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
423 |
-
}
|
424 |
-
} else {
|
425 |
-
@copy($fileinfo['filepath_original'], $fileinfo['filepath']);
|
426 |
-
}
|
427 |
-
|
428 |
-
// Thumbnail
|
429 |
-
$editor->set_quality($thumbimg['quality']);
|
430 |
-
if($thumbimg['resize']) {
|
431 |
-
$ed_size = $editor->get_size();
|
432 |
-
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
433 |
-
if(1 > $ed_ratio) {
|
434 |
-
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
435 |
-
} else {
|
436 |
-
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
437 |
-
}
|
438 |
-
if(is_wp_error($resized)) {
|
439 |
-
$fail = $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})): " . $resized->get_error_message();
|
440 |
-
break;
|
441 |
-
}
|
442 |
-
}
|
443 |
-
|
444 |
-
$saved = $editor->save($fileinfo['filepath_thumb']);
|
445 |
-
if(is_wp_error($saved)) {
|
446 |
-
$fail = $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message();
|
447 |
-
break;
|
448 |
-
}
|
449 |
-
|
450 |
-
} else {
|
451 |
-
@copy($fileinfo['filepath_original'], $fileinfo['filepath']);
|
452 |
-
@copy($fileinfo['filepath_original'], $fileinfo['filepath_thumb']);
|
453 |
-
}
|
454 |
-
|
455 |
-
$id = $gmDB->insert_gmedia($gmedia);
|
456 |
-
|
457 |
-
$new_metadata = $gmDB->generate_gmedia_metadata($id, $fileinfo);
|
458 |
-
$metadata['web'] = $new_metadata['web'];
|
459 |
-
$metadata['original'] = $new_metadata['original'];
|
460 |
-
$metadata['thumb'] = $new_metadata['thumb'];
|
461 |
-
|
462 |
-
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $metadata);
|
463 |
-
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_modified', 0);
|
464 |
-
|
465 |
-
$success = sprintf(__('Image "%d" restored from backup and saved', 'grand-media'), $id);
|
466 |
-
} while(0);
|
467 |
-
|
468 |
-
if(empty($fail)) {
|
469 |
-
$out = array('msg' => $gmCore->alert('info', $success), 'modified' => $gmedia['modified']);
|
470 |
-
} else {
|
471 |
-
$out = array('error' => $gmCore->alert('danger', $fail));
|
472 |
-
}
|
473 |
|
474 |
-
|
475 |
-
|
476 |
-
}
|
477 |
|
478 |
die();
|
479 |
}
|
480 |
|
481 |
add_action('wp_ajax_gmedia_get_modal', 'gmedia_get_modal');
|
482 |
-
function gmedia_get_modal()
|
483 |
global $gmDB, $gmCore, $gmGallery;
|
484 |
check_ajax_referer("GmediaGallery");
|
485 |
$user_ID = get_current_user_id();
|
486 |
$button_class = 'btn-primary';
|
487 |
$gm_terms = array();
|
488 |
$modal = $gmCore->_post('modal');
|
489 |
-
switch($modal)
|
490 |
case 'quick_gallery':
|
491 |
-
if(!current_user_can('gmedia_gallery_manage'))
|
492 |
die('-1');
|
493 |
}
|
494 |
-
$ckey
|
495 |
$modal_title = __('Quick Gallery from selected items', 'grand-media');
|
496 |
$modal_button = __('Create Quick Gallery', 'grand-media');
|
497 |
break;
|
498 |
case 'quick_gallery_stack':
|
499 |
-
if(!current_user_can('gmedia_gallery_manage'))
|
500 |
die('-1');
|
501 |
}
|
502 |
-
$ckey
|
503 |
$modal_title = __('Quick Gallery from Stack', 'grand-media');
|
504 |
$modal_button = __('Create Quick Gallery', 'grand-media');
|
505 |
break;
|
@@ -509,14 +342,14 @@ function gmedia_get_modal() {
|
|
509 |
$modal_button = __('Show Selected', 'grand-media');
|
510 |
break;
|
511 |
case 'assign_category':
|
512 |
-
if(!current_user_can('gmedia_terms'))
|
513 |
die('-1');
|
514 |
}
|
515 |
$modal_title = __('Assign Category for Selected Images', 'grand-media');
|
516 |
$modal_button = __('Assign Category', 'grand-media');
|
517 |
break;
|
518 |
case 'unassign_category':
|
519 |
-
if(!current_user_can('gmedia_terms'))
|
520 |
die('-1');
|
521 |
}
|
522 |
$button_class = 'btn-danger';
|
@@ -529,7 +362,7 @@ function gmedia_get_modal() {
|
|
529 |
$modal_button = __('Show Selected', 'grand-media');
|
530 |
break;
|
531 |
case 'assign_album':
|
532 |
-
if(!current_user_can('gmedia_terms'))
|
533 |
die('-1');
|
534 |
}
|
535 |
$modal_title = __('Assign Album for Selected Items', 'grand-media');
|
@@ -541,14 +374,14 @@ function gmedia_get_modal() {
|
|
541 |
$modal_button = __('Show Selected', 'grand-media');
|
542 |
break;
|
543 |
case 'add_tags':
|
544 |
-
if(!current_user_can('gmedia_terms'))
|
545 |
die('-1');
|
546 |
}
|
547 |
$modal_title = __('Add Tags to Selected Items', 'grand-media');
|
548 |
$modal_button = __('Add Tags', 'grand-media');
|
549 |
break;
|
550 |
case 'delete_tags':
|
551 |
-
if(!current_user_can('gmedia_terms'))
|
552 |
die('-1');
|
553 |
}
|
554 |
$button_class = 'btn-danger';
|
@@ -561,22 +394,22 @@ function gmedia_get_modal() {
|
|
561 |
break;
|
562 |
case 'filter_author':
|
563 |
$modal_title = __('Filter by Author', 'grand-media');
|
564 |
-
if($gmCore->caps['gmedia_show_others_media'])
|
565 |
$modal_button = __('Show Selected', 'grand-media');
|
566 |
-
} else
|
567 |
$modal_button = false;
|
568 |
}
|
569 |
break;
|
570 |
case 'select_author':
|
571 |
$modal_title = __('Select Author', 'grand-media');
|
572 |
-
if($gmCore->caps['gmedia_show_others_media'])
|
573 |
$modal_button = __('Select', 'grand-media');
|
574 |
-
} else
|
575 |
$modal_button = false;
|
576 |
}
|
577 |
break;
|
578 |
case 'batch_edit':
|
579 |
-
if(!current_user_can('gmedia_edit_media'))
|
580 |
die('-1');
|
581 |
}
|
582 |
$modal_title = __('Batch Edit', 'grand-media');
|
@@ -597,13 +430,13 @@ function gmedia_get_modal() {
|
|
597 |
</div>
|
598 |
<div class="modal-body">
|
599 |
<?php
|
600 |
-
switch($modal)
|
601 |
-
|
602 |
case 'quick_gallery_stack':
|
603 |
-
if(!empty($ckey))
|
604 |
-
$selected_in_library = isset($_COOKIE[$ckey])? $_COOKIE[$ckey] : '';
|
605 |
}
|
606 |
-
if(empty($selected_in_library))
|
607 |
_e('No selected Gmedia. Select at least one item in library.', 'grand-media');
|
608 |
break;
|
609 |
}
|
@@ -616,19 +449,26 @@ function gmedia_get_modal() {
|
|
616 |
<div class="form-group">
|
617 |
<label><?php _e('Modue', 'grand-media'); ?></label>
|
618 |
<select class="form-control input-sm" name="gallery[module]">
|
619 |
-
<?php foreach($gmedia_modules['in'] as $mfold => $module)
|
620 |
echo '<optgroup label="' . esc_attr($module['title']) . '">';
|
621 |
-
$presets
|
622 |
-
$selected
|
623 |
-
$option
|
624 |
-
$option[
|
625 |
-
foreach($presets as $preset)
|
626 |
-
$
|
627 |
-
|
628 |
-
|
629 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
630 |
$preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
|
631 |
-
$option[]
|
632 |
}
|
633 |
}
|
634 |
echo implode('', $option);
|
@@ -644,32 +484,31 @@ function gmedia_get_modal() {
|
|
644 |
break;
|
645 |
case 'exclude_albums':
|
646 |
case 'filter_albums':
|
647 |
-
if($gmCore->caps['gmedia_show_others_media'])
|
648 |
$args = array();
|
649 |
-
} else
|
650 |
-
$args = array(
|
651 |
-
|
652 |
-
'orderby' => 'global_desc_name'
|
653 |
);
|
654 |
}
|
655 |
$gm_terms = $gmDB->get_terms('gmedia_album', $args);
|
656 |
?>
|
657 |
<div class="checkbox"><label><input type="checkbox" name="alb[]" value="0"> <?php _e('No Album', 'grand-media'); ?></label></div>
|
658 |
<hr/>
|
659 |
-
<?php if(count($gm_terms))
|
660 |
-
foreach($gm_terms as $term)
|
661 |
$author_name = '';
|
662 |
-
if($term->global)
|
663 |
-
if($gmCore->caps['gmedia_show_others_media'])
|
664 |
$author_name .= sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $term->global));
|
665 |
}
|
666 |
-
} else
|
667 |
$author_name .= '(' . __('shared', 'grand-media') . ')';
|
668 |
}
|
669 |
-
if('publish' != $term->status)
|
670 |
$author_name .= ' [' . $term->status . ']';
|
671 |
}
|
672 |
-
if($author_name)
|
673 |
$author_name = " <small>{$author_name}</small>";
|
674 |
}
|
675 |
?>
|
@@ -679,33 +518,32 @@ function gmedia_get_modal() {
|
|
679 |
</div>
|
680 |
<?php
|
681 |
}
|
682 |
-
} else
|
683 |
$modal_button = false;
|
684 |
}
|
685 |
break;
|
686 |
case 'assign_album':
|
687 |
-
if($gmCore->caps['gmedia_edit_others_media'])
|
688 |
$args = array();
|
689 |
-
} else
|
690 |
-
$args = array(
|
691 |
-
|
692 |
-
'orderby' => 'global_desc_name'
|
693 |
);
|
694 |
}
|
695 |
$gm_terms = $gmDB->get_terms('gmedia_album', $args);
|
696 |
|
697 |
$terms_album = '';
|
698 |
-
if(count($gm_terms))
|
699 |
-
foreach($gm_terms as $term)
|
700 |
$author_name = '';
|
701 |
-
if($term->global)
|
702 |
-
if($gmCore->caps['gmedia_edit_others_media'])
|
703 |
$author_name .= ' ' . sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $term->global));
|
704 |
}
|
705 |
-
} else
|
706 |
$author_name .= ' (' . __('shared', 'grand-media') . ')';
|
707 |
}
|
708 |
-
if('publish' != $term->status)
|
709 |
$author_name .= ' [' . $term->status . ']';
|
710 |
}
|
711 |
$terms_album .= '<option value="' . $term->term_id . '" data-count="' . $term->count . '" data-name="' . esc_html($term->name) . '" data-meta="' . $author_name . '">' . esc_html($term->name) . $author_name . '</option>' . "\n";
|
@@ -772,22 +610,22 @@ function gmedia_get_modal() {
|
|
772 |
break;
|
773 |
case 'exclude_categories':
|
774 |
case 'filter_categories':
|
775 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
776 |
?>
|
777 |
-
|
778 |
-
<?php
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
<span class="badge pull-right"><?php echo $term->count; ?></span>
|
786 |
-
</div>
|
787 |
-
<?php
|
788 |
-
}
|
789 |
-
}
|
790 |
-
}
|
791 |
break;
|
792 |
case 'assign_category':
|
793 |
$gm_terms = $gmDB->get_terms('gmedia_category', array('fields' => 'names_count'));
|
@@ -841,8 +679,8 @@ function gmedia_get_modal() {
|
|
841 |
case 'unassign_category':
|
842 |
// get selected items in Gmedia Library
|
843 |
$ckey = "gmuser_{$user_ID}_library";
|
844 |
-
$selected_items = array_filter(explode(',', $_COOKIE[$ckey]), 'is_numeric');
|
845 |
-
if(!empty($selected_items))
|
846 |
$gm_terms = $gmDB->get_gmedia_terms($selected_items, 'gmedia_category');
|
847 |
}
|
848 |
if(count($gm_terms)){
|
@@ -854,7 +692,7 @@ function gmedia_get_modal() {
|
|
854 |
</div>
|
855 |
<?php
|
856 |
}
|
857 |
-
} else
|
858 |
$modal_button = false; ?>
|
859 |
<p class="noterms"><?php _e('No categories', 'grand-media'); ?></p>
|
860 |
<?php
|
@@ -959,8 +797,8 @@ function gmedia_get_modal() {
|
|
959 |
case 'delete_tags':
|
960 |
// get selected items in Gmedia Library
|
961 |
$ckey = "gmuser_{$user_ID}_library";
|
962 |
-
$selected_items = array_filter(explode(',', $_COOKIE[$ckey]), 'is_numeric');
|
963 |
-
if(!empty($selected_items))
|
964 |
$gm_terms = $gmDB->get_gmedia_terms($selected_items, 'gmedia_tag');
|
965 |
}
|
966 |
if(count($gm_terms)){
|
@@ -972,7 +810,7 @@ function gmedia_get_modal() {
|
|
972 |
</div>
|
973 |
<?php
|
974 |
}
|
975 |
-
} else
|
976 |
$modal_button = false; ?>
|
977 |
<p class="noterms"><?php _e('No tags', 'grand-media'); ?></p>
|
978 |
<?php
|
@@ -986,25 +824,24 @@ function gmedia_get_modal() {
|
|
986 |
<label><?php _e('Choose Author', 'grand-media'); ?></label>
|
987 |
<?php
|
988 |
$user_ids = $gmCore->get_editable_user_ids();
|
989 |
-
if($user_ids)
|
990 |
-
if(!in_array($user_ID, $user_ids))
|
991 |
array_push($user_ids, $user_ID);
|
992 |
}
|
993 |
-
wp_dropdown_users(array(
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
'class' => 'form-control'
|
1000 |
));
|
1001 |
-
} else
|
1002 |
echo '<div>' . get_the_author_meta('display_name', $user_ID) . '</div>';
|
1003 |
}
|
1004 |
?>
|
1005 |
</div>
|
1006 |
<?php
|
1007 |
-
} else
|
1008 |
echo '<p>' . __('You are not allowed to see others media') . '</p>';
|
1009 |
echo '<p><strong>' . get_the_author_meta('display_name', $user_ID) . '</strong></p>';
|
1010 |
}
|
@@ -1082,19 +919,18 @@ function gmedia_get_modal() {
|
|
1082 |
</div>
|
1083 |
<?php $user_ids = current_user_can('gmedia_delete_others_media')? $gmCore->get_editable_user_ids() : false;
|
1084 |
if($user_ids){
|
1085 |
-
if(!in_array($user_ID, $user_ids))
|
1086 |
array_push($user_ids, $user_ID);
|
1087 |
}
|
1088 |
?>
|
1089 |
<div class="form-group">
|
1090 |
<label><?php _e('Author', 'grand-media'); ?></label>
|
1091 |
-
<?php wp_dropdown_users(array(
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
'class' => 'input-sm form-control'
|
1098 |
));
|
1099 |
?>
|
1100 |
</div>
|
@@ -1120,7 +956,7 @@ function gmedia_get_modal() {
|
|
1120 |
</div>
|
1121 |
<div class="modal-footer">
|
1122 |
<button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Cancel', 'grand-media'); ?></button>
|
1123 |
-
<?php if($modal_button)
|
1124 |
<input type="hidden" name="<?php echo $modal; ?>"/>
|
1125 |
<button type="button" onclick="jQuery('#ajax-modal-form').submit()" name="<?php echo $modal; ?>" class="btn <?php echo $button_class; ?>"><?php echo $modal_button; ?></button>
|
1126 |
<?php
|
@@ -1134,11 +970,11 @@ function gmedia_get_modal() {
|
|
1134 |
}
|
1135 |
|
1136 |
add_action('wp_ajax_gmedia_tag_edit', 'gmedia_tag_edit');
|
1137 |
-
function gmedia_tag_edit()
|
1138 |
global $gmCore, $gmDB;
|
1139 |
|
1140 |
check_ajax_referer('GmediaTerms');
|
1141 |
-
if(!current_user_can('gmedia_tag_manage') && !current_user_can('gmedia_edit_others_media'))
|
1142 |
$out['error'] = $gmCore->alert('danger', __("You are not allowed to edit others media", 'grand-media'));
|
1143 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
1144 |
echo json_encode($out);
|
@@ -1148,22 +984,22 @@ function gmedia_tag_edit() {
|
|
1148 |
$term = array('taxonomy' => 'gmedia_tag');
|
1149 |
$term['name'] = trim($gmCore->_post('tag_name', ''));
|
1150 |
$term['term_id'] = intval($gmCore->_post('tag_id', 0));
|
1151 |
-
if($term['name'] && !$gmCore->is_digit($term['name']))
|
1152 |
-
if(($term_id = $gmDB->term_exists($term['term_id'])))
|
1153 |
-
if(!$gmDB->term_exists($term['name'], $term['taxonomy']))
|
1154 |
$term_id = $gmDB->update_term($term['term_id'], $term);
|
1155 |
-
if(is_wp_error($term_id))
|
1156 |
$out['error'] = $gmCore->alert('danger', $term_id->get_error_message());
|
1157 |
-
} else
|
1158 |
$out['msg'] = $gmCore->alert('info', sprintf(__("Tag #%d successfuly updated", 'grand-media'), $term_id));
|
1159 |
}
|
1160 |
-
} else
|
1161 |
$out['error'] = $gmCore->alert('danger', __("A term with the name provided already exists", 'grand-media'));
|
1162 |
}
|
1163 |
-
} else
|
1164 |
$out['error'] = $gmCore->alert('danger', __("A term with the id provided do not exists", 'grand-media'));
|
1165 |
}
|
1166 |
-
} else
|
1167 |
$out['error'] = $gmCore->alert('danger', __("Term name can't be only digits or empty", 'grand-media'));
|
1168 |
}
|
1169 |
|
@@ -1175,18 +1011,30 @@ function gmedia_tag_edit() {
|
|
1175 |
}
|
1176 |
|
1177 |
add_action('wp_ajax_gmedia_module_preset_delete', 'gmedia_module_preset_delete');
|
1178 |
-
function gmedia_module_preset_delete()
|
1179 |
-
global $gmCore, $gmDB;
|
1180 |
$out = array('error' => '');
|
1181 |
|
1182 |
check_ajax_referer('GmediaGallery');
|
1183 |
-
if(!current_user_can('gmedia_gallery_manage'))
|
1184 |
$out['error'] = $gmCore->alert('danger', __("You are not allowed to manage galleries", 'grand-media'));
|
1185 |
-
} else
|
1186 |
-
$term_id
|
1187 |
-
$
|
1188 |
-
if(is_wp_error($
|
1189 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1190 |
}
|
1191 |
}
|
1192 |
|
@@ -1198,32 +1046,32 @@ function gmedia_module_preset_delete() {
|
|
1198 |
}
|
1199 |
|
1200 |
add_action('wp_ajax_gmedia_module_install', 'gmedia_module_install');
|
1201 |
-
function gmedia_module_install()
|
1202 |
global $gmCore, $gmGallery;
|
1203 |
|
1204 |
-
check_ajax_referer('
|
1205 |
-
if(!current_user_can('gmedia_module_manage'))
|
1206 |
echo $gmCore->alert('danger', __('You are not allowed to install modules'));
|
1207 |
die();
|
1208 |
}
|
1209 |
|
1210 |
-
if(($download = $gmCore->_post('download')))
|
1211 |
$module = $gmCore->_post('module');
|
1212 |
$mzip = download_url($download);
|
1213 |
-
if(is_wp_error($mzip))
|
1214 |
echo $gmCore->alert('danger', $mzip->get_error_message());
|
1215 |
die();
|
1216 |
}
|
1217 |
|
1218 |
$mzip = str_replace("\\", "/", $mzip);
|
1219 |
$to_folder = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/';
|
1220 |
-
if(!wp_mkdir_p($to_folder))
|
1221 |
echo $gmCore->alert('danger', sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $to_folder));
|
1222 |
die();
|
1223 |
}
|
1224 |
-
if(!is_writable($to_folder))
|
1225 |
@chmod($to_folder, 0755);
|
1226 |
-
if(!is_writable($to_folder))
|
1227 |
echo $gmCore->alert('danger', sprintf(__('Directory %s is not writable by the server.', 'grand-media'), $to_folder));
|
1228 |
die();
|
1229 |
}
|
@@ -1231,15 +1079,15 @@ function gmedia_module_install() {
|
|
1231 |
|
1232 |
global $wp_filesystem;
|
1233 |
// Is a filesystem accessor setup?
|
1234 |
-
if(!$wp_filesystem || !is_object($wp_filesystem))
|
1235 |
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
1236 |
WP_Filesystem();
|
1237 |
}
|
1238 |
-
if(!is_object($wp_filesystem))
|
1239 |
$result = new WP_Error('fs_unavailable', __('Could not access filesystem.', 'flag'));
|
1240 |
-
} elseif($wp_filesystem->errors->get_error_code())
|
1241 |
$result = new WP_Error('fs_error', __('Filesystem error', 'flag'), $wp_filesystem->errors);
|
1242 |
-
} else
|
1243 |
if($module && is_dir($to_folder . $module)){
|
1244 |
$gmCore->delete_folder($to_folder . $module);
|
1245 |
}
|
@@ -1249,13 +1097,13 @@ function gmedia_module_install() {
|
|
1249 |
// Once extracted, delete the package
|
1250 |
unlink($mzip);
|
1251 |
|
1252 |
-
if(is_wp_error($result))
|
1253 |
echo $gmCore->alert('danger', $result->get_error_message());
|
1254 |
die();
|
1255 |
-
} else
|
1256 |
echo $gmCore->alert('success', sprintf(__("The `%s` module successfuly installed", 'flag'), $module));
|
1257 |
}
|
1258 |
-
} else
|
1259 |
echo $gmCore->alert('danger', __('No file specified', 'grand-media'));
|
1260 |
}
|
1261 |
|
@@ -1265,11 +1113,11 @@ function gmedia_module_install() {
|
|
1265 |
|
1266 |
|
1267 |
add_action('wp_ajax_gmedia_import_wpmedia_modal', 'gmedia_import_wpmedia_modal');
|
1268 |
-
function gmedia_import_wpmedia_modal()
|
1269 |
global $user_ID, $gmDB, $gmCore;
|
1270 |
|
1271 |
check_ajax_referer('GmediaGallery');
|
1272 |
-
if(!current_user_can('gmedia_import'))
|
1273 |
die('-1');
|
1274 |
}
|
1275 |
?>
|
@@ -1284,18 +1132,18 @@ function gmedia_import_wpmedia_modal() {
|
|
1284 |
<input type="hidden" name="action" value="gmedia_import_handler"/>
|
1285 |
<input type="hidden" id="import-action" name="import" value="import-wpmedia"/>
|
1286 |
<input type="hidden" name="selected" value="<?php $ckey = "gmuser_{$user_ID}_wpmedia";
|
1287 |
-
if(isset($_COOKIE[$ckey]))
|
1288 |
-
echo $_COOKIE[$ckey];
|
1289 |
} ?>"/>
|
1290 |
-
<?php if($gmCore->caps['gmedia_terms'])
|
1291 |
<div class="form-group">
|
1292 |
<?php
|
1293 |
$term_type = 'gmedia_album';
|
1294 |
$gm_terms = $gmDB->get_terms($term_type, array('global' => array(0, $user_ID), 'orderby' => 'global_desc_name'));
|
1295 |
|
1296 |
$terms_album = '';
|
1297 |
-
if(count($gm_terms))
|
1298 |
-
foreach($gm_terms as $term)
|
1299 |
$terms_album .= '<option value="' . esc_attr($term->term_id) . '">' . esc_html($term->name) . ($term->global? '' : __(' (shared)', 'grand-media')) . ('publish' == $term->status? '' : " [{$term->status}]") . '</option>' . "\n";
|
1300 |
}
|
1301 |
}
|
@@ -1309,8 +1157,8 @@ function gmedia_import_wpmedia_modal() {
|
|
1309 |
|
1310 |
<div class="form-group">
|
1311 |
<?php
|
1312 |
-
$term_type
|
1313 |
-
$gm_cat_terms
|
1314 |
?>
|
1315 |
<label><?php _e('Assign Categories', 'grand-media'); ?></label>
|
1316 |
<input id="combobox_gmedia_category" name="terms[gmedia_category]" class="form-control input-sm" value="" placeholder="<?php _e('Uncategorized', 'grand-media'); ?>"/>
|
@@ -1318,8 +1166,8 @@ function gmedia_import_wpmedia_modal() {
|
|
1318 |
|
1319 |
<div class="form-group">
|
1320 |
<?php
|
1321 |
-
$term_type
|
1322 |
-
$gm_tag_terms
|
1323 |
?>
|
1324 |
<label><?php _e('Add Tags', 'grand-media'); ?> </label>
|
1325 |
<input id="combobox_gmedia_tag" name="terms[gmedia_tag]" class="form-control input-sm" value="" placeholder="<?php _e('Add Tags...', 'grand-media'); ?>"/>
|
@@ -1399,6 +1247,7 @@ function gmedia_import_wpmedia_modal() {
|
|
1399 |
<?php } ?>
|
1400 |
<div class="checkbox">
|
1401 |
<label><input type="checkbox" name="skip_exists" value="skip"> <?php _e('Skip if file with the same name already exists in Gmedia Library', 'grand-media'); ?></label>
|
|
|
1402 |
</div>
|
1403 |
<script type="text/javascript">
|
1404 |
jQuery(function($) {
|
@@ -1429,17 +1278,16 @@ add_action('wp_ajax_gmedia_relimage', 'gmedia_relimage');
|
|
1429 |
* Do Actions via Ajax
|
1430 |
* TODO add related images to post
|
1431 |
* TODO check author for related images
|
1432 |
-
*
|
1433 |
* @return void
|
1434 |
*/
|
1435 |
-
function gmedia_relimage()
|
1436 |
/** @var $wpdb wpdb */
|
1437 |
global $wpdb, $gmCore, $gmDB;
|
1438 |
|
1439 |
check_ajax_referer("grandMedia");
|
1440 |
|
1441 |
// check for correct capability
|
1442 |
-
if(!current_user_can('gmedia_library'))
|
1443 |
die('-1');
|
1444 |
}
|
1445 |
|
@@ -1447,9 +1295,9 @@ function gmedia_relimage() {
|
|
1447 |
$paged = (int)$gmCore->_get('paged', 1);
|
1448 |
$per_page = 20;
|
1449 |
$s = trim(stripslashes(urldecode($gmCore->_get('search'))));
|
1450 |
-
if($s && strlen($s) > 2)
|
1451 |
$post_tags = array();
|
1452 |
-
} else
|
1453 |
$s = '';
|
1454 |
}
|
1455 |
|
@@ -1458,23 +1306,22 @@ function gmedia_relimage() {
|
|
1458 |
$continue = true;
|
1459 |
$content = '';
|
1460 |
|
1461 |
-
if($relative == 1)
|
1462 |
-
$arg = array(
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
'null_tags' => true
|
1471 |
);
|
1472 |
$gmediaLib = $gmDB->get_gmedias($arg);
|
1473 |
}
|
1474 |
|
1475 |
-
if(empty($gmediaLib) && count($post_tags))
|
1476 |
|
1477 |
-
if($relative == 1)
|
1478 |
$relative = 0;
|
1479 |
$paged = 1;
|
1480 |
$content .= '<li class="emptydb">' . __('No items related by tags.', 'grand-media') . '</li>' . "\n";
|
@@ -1488,31 +1335,30 @@ function gmedia_relimage() {
|
|
1488 |
AND name IN ({$tag__not_in})
|
1489 |
");
|
1490 |
|
1491 |
-
$arg = array(
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
'tag__not_in' => $tag__not_in
|
1498 |
);
|
1499 |
$gmediaLib = $gmDB->get_gmedias($arg);
|
1500 |
}
|
1501 |
|
1502 |
-
if(($count = count($gmediaLib)))
|
1503 |
-
foreach($gmediaLib as $item)
|
1504 |
$content .= "<li class='gmedia-image-li' id='gm-img-{$item->ID}'>\n";
|
1505 |
$content .= " <a target='_blank' class='gm-img' data-gmid='{$item->ID}' href='" . $gmCore->gm_get_media_image($item) . "'><img src='" . $gmCore->gm_get_media_image($item, 'thumb') . "' height='50' style='width:auto;' alt='' title='" . esc_attr($item->title) . "' /></a>\n";
|
1506 |
$content .= " <div style='display: none;' class='gm-img-description'>" . esc_html($item->description) . "</div>\n";
|
1507 |
$content .= "</li>\n";
|
1508 |
}
|
1509 |
-
if(($count < $per_page) && ($relative == 0 || !empty($s)))
|
1510 |
$continue = false;
|
1511 |
}
|
1512 |
-
} else
|
1513 |
-
if($s)
|
1514 |
$content .= '<li class="emptydb">' . __('No items matching the search query.', 'grand-media') . '</li>' . "\n";
|
1515 |
-
} else
|
1516 |
$content .= '<li class="emptydb">' . __('No items to show', 'grand-media') . '</li>' . "\n";
|
1517 |
}
|
1518 |
$continue = false;
|
@@ -1530,11 +1376,10 @@ add_action('wp_ajax_gmedia_ftp_browser', 'gmedia_ftp_browser');
|
|
1530 |
* jQuery File Tree PHP Connector
|
1531 |
* @author Cory S.N. LaViska - A Beautiful Site (http://abeautifulsite.net/)
|
1532 |
* @version 1.0.1
|
1533 |
-
*
|
1534 |
* @return string folder content
|
1535 |
*/
|
1536 |
-
function gmedia_ftp_browser()
|
1537 |
-
if(!current_user_can('gmedia_import'))
|
1538 |
die('No access');
|
1539 |
}
|
1540 |
|
@@ -1546,20 +1391,20 @@ function gmedia_ftp_browser() {
|
|
1546 |
// get the current directory
|
1547 |
$dir = trailingslashit(urldecode($_POST['dir']));
|
1548 |
|
1549 |
-
if((false === strpos($dir, '..')) && file_exists($root . $dir))
|
1550 |
$files = scandir($root . $dir);
|
1551 |
natcasesort($files);
|
1552 |
|
1553 |
// The 2 counts for . and ..
|
1554 |
-
if(count($files) > 2)
|
1555 |
echo "<ul class=\"jqueryDirTree\" style=\"display: none;\">";
|
1556 |
// return only directories
|
1557 |
-
foreach($files as $file)
|
1558 |
-
if(in_array($file, array('wp-admin', 'wp-includes', 'plugins', 'themes', 'thumb', 'thumbs')))
|
1559 |
continue;
|
1560 |
}
|
1561 |
|
1562 |
-
if(file_exists($root . $dir . $file) && $file != '.' && $file != '..' && is_dir($root . $dir . $file))
|
1563 |
echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . esc_attr($dir . $file) . "/\">" . esc_html($file) . "</a></li>";
|
1564 |
}
|
1565 |
}
|
@@ -1571,12 +1416,12 @@ function gmedia_ftp_browser() {
|
|
1571 |
}
|
1572 |
|
1573 |
add_action('wp_ajax_gmedia_set_post_thumbnail', 'gmedia_set_post_thumbnail');
|
1574 |
-
function gmedia_set_post_thumbnail()
|
1575 |
global $gmCore, $gmDB, $gmGallery;
|
1576 |
|
1577 |
$post_ID = intval($gmCore->_post('post_id', 0));
|
1578 |
|
1579 |
-
if(!$post_ID || !current_user_can('edit_post', $post_ID))
|
1580 |
die('-1');
|
1581 |
}
|
1582 |
|
@@ -1593,48 +1438,46 @@ function gmedia_set_post_thumbnail() {
|
|
1593 |
}
|
1594 |
*/
|
1595 |
|
1596 |
-
if($img_id)
|
1597 |
|
1598 |
$image = $gmDB->get_gmedia($img_id);
|
1599 |
-
if($image)
|
1600 |
|
1601 |
-
$args = array(
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
'meta_value' => $img_id
|
1606 |
);
|
1607 |
$posts = get_posts($args);
|
1608 |
$attachment_id = null;
|
1609 |
|
1610 |
-
if($posts != null)
|
1611 |
$attachment_id = $posts[0]->ID;
|
1612 |
//$target_path = get_attached_file( $attachment_id );
|
1613 |
-
} else
|
1614 |
$upload_dir = wp_upload_dir();
|
1615 |
$basedir = $upload_dir['basedir'];
|
1616 |
$thumbs_dir = implode(DIRECTORY_SEPARATOR, array($basedir, 'gmedia_featured'));
|
1617 |
|
1618 |
$type = explode('/', $image->mime_type);
|
1619 |
|
1620 |
-
$url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $image->gmuid;
|
1621 |
-
$image_abspath = $gmCore->upload['path'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $image->gmuid;
|
1622 |
|
1623 |
$img_name = current_time('ymd_Hi') . '_' . basename($image->gmuid);
|
1624 |
$target_path = path_join($thumbs_dir, $img_name);
|
1625 |
wp_mkdir_p($thumbs_dir);
|
1626 |
|
1627 |
-
if(@copy($image_abspath, $target_path))
|
1628 |
$title = sanitize_title($image->title);
|
1629 |
$caption = $gmCore->sanitize($image->description);
|
1630 |
|
1631 |
-
$attachment = array(
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
'guid' => $url
|
1638 |
);
|
1639 |
|
1640 |
//require for wp_generate_attachment_metadata which generates image related meta-data also creates thumbs
|
@@ -1646,7 +1489,7 @@ function gmedia_set_post_thumbnail() {
|
|
1646 |
}
|
1647 |
}
|
1648 |
|
1649 |
-
if($attachment_id)
|
1650 |
delete_post_meta($post_ID, '_thumbnail_id');
|
1651 |
add_post_meta($post_ID, '_thumbnail_id', $attachment_id, true);
|
1652 |
|
@@ -1660,17 +1503,19 @@ function gmedia_set_post_thumbnail() {
|
|
1660 |
}
|
1661 |
|
1662 |
add_action('wp_ajax_gmedia_upload_handler', 'gmedia_upload_handler');
|
1663 |
-
function gmedia_upload_handler()
|
1664 |
global $gmCore;
|
1665 |
|
1666 |
ini_set('max_execution_time', 300);
|
1667 |
|
1668 |
// HTTP headers for no cache etc
|
|
|
|
|
1669 |
nocache_headers();
|
1670 |
|
1671 |
// if nonce is not correct it returns -1
|
1672 |
check_ajax_referer('GmediaUpload');
|
1673 |
-
if(!current_user_can('gmedia_upload'))
|
1674 |
wp_die(__('You do not have permission to upload files in Gmedia Library.'));
|
1675 |
}
|
1676 |
|
@@ -1683,44 +1528,44 @@ function gmedia_upload_handler() {
|
|
1683 |
$filename = $gmCore->_req('name');
|
1684 |
|
1685 |
// Get parameters
|
1686 |
-
if(!$filename)
|
1687 |
$return = json_encode(array("error" => array("code" => 100, "message" => __("No file name.", 'grand-media'))));
|
1688 |
die($return);
|
1689 |
}
|
1690 |
|
1691 |
$fileinfo = $gmCore->fileinfo($filename);
|
1692 |
-
if(false === $fileinfo)
|
1693 |
$return = json_encode(array("error" => array("code" => 100, "message" => __("File type not allowed.", 'grand-media')), "id" => $filename));
|
1694 |
die($return);
|
1695 |
}
|
1696 |
|
1697 |
// Look for the content type header
|
1698 |
$contentType = '';
|
1699 |
-
if(isset($_SERVER["HTTP_CONTENT_TYPE"]))
|
1700 |
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
|
1701 |
}
|
1702 |
|
1703 |
-
if(isset($_SERVER["CONTENT_TYPE"]))
|
1704 |
$contentType = $_SERVER["CONTENT_TYPE"];
|
1705 |
}
|
1706 |
|
1707 |
// Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
|
1708 |
$file_tmp = '';
|
1709 |
-
if(strpos($contentType, "multipart") !== false)
|
1710 |
-
if(isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name']))
|
1711 |
$file_tmp = $_FILES['file']['tmp_name'];
|
1712 |
}
|
1713 |
-
} else
|
1714 |
$file_tmp = "php://input";
|
1715 |
}
|
1716 |
|
1717 |
-
if(empty($file_tmp))
|
1718 |
$return = json_encode(array("error" => array("code" => 103, "message" => __("Failed to move uploaded file.", 'grand-media')), "id" => $filename));
|
1719 |
die($return);
|
1720 |
}
|
1721 |
|
1722 |
$post_data = array();
|
1723 |
-
if(($params = $gmCore->_req('params', '')))
|
1724 |
parse_str($params, $post_data);
|
1725 |
}
|
1726 |
|
@@ -1731,16 +1576,18 @@ function gmedia_upload_handler() {
|
|
1731 |
}
|
1732 |
|
1733 |
add_action('wp_ajax_gmedia_import_handler', 'gmedia_import_handler');
|
1734 |
-
function gmedia_import_handler()
|
1735 |
global $wpdb, $gmCore, $gmDB;
|
1736 |
|
1737 |
ini_set('max_execution_time', 600);
|
1738 |
|
1739 |
// HTTP headers for no cache etc
|
|
|
|
|
1740 |
nocache_headers();
|
1741 |
|
1742 |
check_admin_referer('GmediaImport');
|
1743 |
-
if(!current_user_can('gmedia_import'))
|
1744 |
wp_die(__('You do not have permission to upload files.'));
|
1745 |
}
|
1746 |
|
@@ -1753,7 +1600,7 @@ function gmedia_import_handler() {
|
|
1753 |
$import = $gmCore->_post('import');
|
1754 |
$terms = $gmCore->_post('terms', array());
|
1755 |
|
1756 |
-
if(ob_get_level() == 0)
|
1757 |
ob_start();
|
1758 |
}
|
1759 |
echo str_pad(' ', 4096) . PHP_EOL;
|
@@ -1770,72 +1617,72 @@ function gmedia_import_handler() {
|
|
1770 |
</style>
|
1771 |
<body>
|
1772 |
<?php
|
1773 |
-
if(('import-folder' == $import) || isset($_POST['import-folder']))
|
1774 |
|
1775 |
$path = $gmCore->_post('path');
|
1776 |
echo '<h4 style="margin: 0 0 10px">' . __('Import Server Folder') . " `$path`:</h4>" . PHP_EOL;
|
1777 |
|
1778 |
-
if($path)
|
1779 |
$path = trim(urldecode($path), '/');
|
1780 |
-
if(!empty($path))
|
1781 |
$fullpath = ABSPATH . trailingslashit($path);
|
1782 |
$files = glob($fullpath . '?*.?*', GLOB_NOSORT);
|
1783 |
-
if(!empty($files))
|
1784 |
$allowed_ext = get_allowed_mime_types();
|
1785 |
$allowed_ext = array_keys($allowed_ext);
|
1786 |
$allowed_ext = implode('|', $allowed_ext);
|
1787 |
$allowed_ext = explode('|', $allowed_ext);
|
1788 |
-
if((GMEDIA_UPLOAD_FOLDER == basename(dirname(dirname($path)))) || (GMEDIA_UPLOAD_FOLDER == basename(dirname($path))))
|
1789 |
global $wpdb;
|
1790 |
$gmedias = $wpdb->get_col("SELECT gmuid FROM {$wpdb->prefix}gmedia");
|
1791 |
-
foreach($files as $i => $filepath)
|
1792 |
$gmuid = basename($filepath);
|
1793 |
-
if(in_array($gmuid, $gmedias))
|
1794 |
$fileinfo = $gmCore->fileinfo($gmuid, false);
|
1795 |
-
if(!(('image' == $fileinfo['dirname']) && !file_exists($fileinfo['filepath'])))
|
1796 |
-
unset($files[$i]);
|
1797 |
}
|
1798 |
}
|
1799 |
}
|
1800 |
$move = false;
|
1801 |
$exists = false;
|
1802 |
-
} else
|
1803 |
$move = $gmCore->_post('delete_source');
|
1804 |
-
$exists = 0;
|
1805 |
}
|
1806 |
-
foreach($files as $i => $filepath)
|
1807 |
$ext = pathinfo($filepath, PATHINFO_EXTENSION);
|
1808 |
-
if(!in_array(strtolower($ext), $allowed_ext))
|
1809 |
-
unset($files[$i]);
|
1810 |
}
|
1811 |
}
|
1812 |
$gmCore->gmedia_import_files($files, $terms, $move, $exists);
|
1813 |
-
} else
|
1814 |
echo sprintf(__('Folder `%s` is empty', 'grand-media'), $path) . PHP_EOL;
|
1815 |
}
|
1816 |
-
} else
|
1817 |
echo __('No folder chosen', 'grand-media') . PHP_EOL;
|
1818 |
}
|
1819 |
}
|
1820 |
-
} elseif(('import-flagallery' == $import) || isset($_POST['import-flagallery']))
|
1821 |
|
1822 |
echo '<h4 style="margin: 0 0 10px">' . __('Import from Flagallery plugin') . ":</h4>" . PHP_EOL;
|
1823 |
|
1824 |
$gallery = $gmCore->_post('gallery');
|
1825 |
-
if(!empty($gallery))
|
1826 |
$album = (!isset($terms['gmedia_album']) || empty($terms['gmedia_album']))? false : true;
|
1827 |
-
foreach($gallery as $gid)
|
1828 |
$flag_gallery = $wpdb->get_row($wpdb->prepare("SELECT gid, path, title, galdesc FROM {$wpdb->prefix}flag_gallery WHERE gid = %d", $gid), ARRAY_A);
|
1829 |
-
if(empty($flag_gallery))
|
1830 |
continue;
|
1831 |
}
|
1832 |
|
1833 |
-
if(!$album)
|
1834 |
$terms['gmedia_album'] = $flag_gallery['title'];
|
1835 |
-
if($gmCore->is_digit($terms['gmedia_album']))
|
1836 |
$terms['gmedia_album'] = 'a' . $terms['gmedia_album'];
|
1837 |
}
|
1838 |
-
if(!$gmDB->term_exists($terms['gmedia_album'], 'gmedia_album'))
|
1839 |
$term_id = $gmDB->insert_term($terms['gmedia_album'], 'gmedia_album', array('description' => htmlspecialchars_decode(stripslashes($flag_gallery['galdesc']))));
|
1840 |
}
|
1841 |
}
|
@@ -1845,35 +1692,37 @@ function gmedia_import_handler() {
|
|
1845 |
echo '<h5 style="margin: 10px 0 5px">' . sprintf(__('Import `%s` gallery', 'grand-media'), $flag_gallery['title']) . ":</h5>" . PHP_EOL;
|
1846 |
|
1847 |
$flag_pictures = $wpdb->get_results($wpdb->prepare("SELECT CONCAT('%s', filename) AS file, description, alttext AS title, link FROM {$wpdb->prefix}flag_pictures WHERE galleryid = %d", $path, $flag_gallery['gid']), ARRAY_A);
|
1848 |
-
if(empty($flag_pictures))
|
1849 |
echo '<pre>' . __('gallery contains 0 images', 'grand-media') . '</pre>';
|
1850 |
continue;
|
1851 |
}
|
|
|
|
|
1852 |
//echo '<pre>'.print_r($flag_pictures, true).'</pre>';
|
1853 |
-
$gmCore->gmedia_import_files($flag_pictures, $terms, false);
|
1854 |
}
|
1855 |
-
} else
|
1856 |
echo __('No gallery chosen', 'grand-media') . PHP_EOL;
|
1857 |
}
|
1858 |
-
} elseif(('import-nextgen' == $import) || isset($_POST['import-nextgen']))
|
1859 |
|
1860 |
echo '<h4 style="margin: 0 0 10px">' . __('Import from NextGen plugin') . ":</h4>" . PHP_EOL;
|
1861 |
|
1862 |
$gallery = $gmCore->_post('gallery');
|
1863 |
-
if(!empty($gallery))
|
1864 |
$album = (!isset($terms['gmedia_album']) || empty($terms['gmedia_album']))? false : true;
|
1865 |
-
foreach($gallery as $gid)
|
1866 |
$ngg_gallery = $wpdb->get_row($wpdb->prepare("SELECT gid, path, title, galdesc FROM {$wpdb->prefix}ngg_gallery WHERE gid = %d", $gid), ARRAY_A);
|
1867 |
-
if(empty($ngg_gallery))
|
1868 |
continue;
|
1869 |
}
|
1870 |
|
1871 |
-
if(!$album)
|
1872 |
$terms['gmedia_album'] = $ngg_gallery['title'];
|
1873 |
-
if($gmCore->is_digit($terms['gmedia_album']))
|
1874 |
$terms['gmedia_album'] = 'a' . $ngg_gallery['title'];
|
1875 |
}
|
1876 |
-
if(!$gmDB->term_exists($terms['gmedia_album'], 'gmedia_album'))
|
1877 |
$term_id = $gmDB->insert_term($terms['gmedia_album'], 'gmedia_album', array('description' => htmlspecialchars_decode(stripslashes($ngg_gallery['galdesc']))));
|
1878 |
}
|
1879 |
}
|
@@ -1883,36 +1732,37 @@ function gmedia_import_handler() {
|
|
1883 |
echo '<h5 style="margin: 10px 0 5px">' . sprintf(__('Import `%s` gallery', 'grand-media'), $ngg_gallery['title']) . ":</h5>" . PHP_EOL;
|
1884 |
|
1885 |
$ngg_pictures = $wpdb->get_results($wpdb->prepare("SELECT CONCAT('%s', filename) AS file, description, alttext AS title FROM {$wpdb->prefix}ngg_pictures WHERE galleryid = %d", $path, $ngg_gallery['gid']), ARRAY_A);
|
1886 |
-
if(empty($ngg_pictures))
|
1887 |
echo '<pre>' . __('gallery contains 0 images', 'grand-media') . '</pre>';
|
1888 |
continue;
|
1889 |
}
|
1890 |
-
$gmCore->
|
|
|
|
|
1891 |
}
|
1892 |
-
} else
|
1893 |
echo __('No gallery chosen', 'grand-media') . PHP_EOL;
|
1894 |
}
|
1895 |
-
} elseif(('import-wpmedia' == $import) || isset($_POST['import-wpmedia']))
|
1896 |
|
1897 |
echo '<h4 style="margin: 0 0 10px">' . __('Import from WP Media Library') . ":</h4>" . PHP_EOL;
|
1898 |
|
1899 |
$wpMediaLib = $gmDB->get_wp_media_lib(array('filter' => 'selected', 'selected' => $gmCore->_post('selected')));
|
1900 |
|
1901 |
-
if(!empty($wpMediaLib))
|
1902 |
|
1903 |
$wp_media = array();
|
1904 |
-
foreach($wpMediaLib as $item)
|
1905 |
-
$wp_media[] = array(
|
1906 |
-
|
1907 |
-
|
1908 |
-
'description' => $item->post_content
|
1909 |
);
|
1910 |
}
|
1911 |
$exists = $gmCore->_post('skip_exists', 0);
|
1912 |
//echo '<pre>' . print_r($wp_media, true) . '</pre>';
|
1913 |
$gmCore->gmedia_import_files($wp_media, $terms, false, $exists);
|
1914 |
|
1915 |
-
} else
|
1916 |
echo __('No items chosen', 'grand-media') . PHP_EOL;
|
1917 |
}
|
1918 |
}
|
@@ -1926,17 +1776,17 @@ function gmedia_import_handler() {
|
|
1926 |
}
|
1927 |
|
1928 |
add_action('wp_ajax_gmedia_application', 'gmedia_application');
|
1929 |
-
function gmedia_application()
|
1930 |
global $gmCore, $gmGallery;
|
1931 |
|
1932 |
// if nonce is not correct it returns -1
|
1933 |
check_ajax_referer('GmediaService');
|
1934 |
-
if(!current_user_can('manage_options'))
|
1935 |
die('-1');
|
1936 |
}
|
1937 |
|
1938 |
$service = $gmCore->_post('service');
|
1939 |
-
if(!$service)
|
1940 |
die('0');
|
1941 |
}
|
1942 |
$_data = $gmCore->_post('data');
|
@@ -1946,7 +1796,7 @@ function gmedia_application() {
|
|
1946 |
$options['site_email'] = $data['site_email'];
|
1947 |
$options['site_title'] = $data['site_title'];
|
1948 |
$options['site_description'] = $data['site_description'];
|
1949 |
-
if($options != $gmGallery->options)
|
1950 |
$gmGallery->options = $options;
|
1951 |
update_option('gmediaOptions', $options);
|
1952 |
}
|
@@ -1960,7 +1810,7 @@ function gmedia_application() {
|
|
1960 |
}
|
1961 |
|
1962 |
add_action('wp_ajax_gmedia_share_page', 'gmedia_share_page');
|
1963 |
-
function gmedia_share_page()
|
1964 |
global $gmCore, $user_ID;
|
1965 |
// if nonce is not correct it returns -1
|
1966 |
check_ajax_referer('share_modal', '_sharenonce');
|
@@ -1968,7 +1818,7 @@ function gmedia_share_page() {
|
|
1968 |
$sharelink = $gmCore->_post('sharelink', '');
|
1969 |
$email = $gmCore->_post('email', '');
|
1970 |
$sharemessage = $gmCore->_post('message', '');
|
1971 |
-
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
|
1972 |
echo $gmCore->alert('danger', __('Invalid email', 'grand-media') . ': ' . esc_html($email));
|
1973 |
die();
|
1974 |
}
|
@@ -1977,7 +1827,7 @@ function gmedia_share_page() {
|
|
1977 |
$subject = sprintf(__('%s shared GmediaCloud Page with you', 'grand-media'), $display_name);
|
1978 |
$sharetitle = sprintf(__('%s used Gmedia to share something interesting with you!', 'grand-media'), $display_name);
|
1979 |
$sharelinktext = __('Click here to view page', 'grand-media');
|
1980 |
-
if($sharemessage)
|
1981 |
$sharemessage = '<blockquote>"' . nl2br(esc_html($sharemessage)) . '"</blockquote>';
|
1982 |
}
|
1983 |
$footer = '© ' . date('Y') . ' GmediaGallery';
|
@@ -2021,7 +1871,7 @@ function gmedia_share_page() {
|
|
2021 |
EOT;
|
2022 |
|
2023 |
$headers = array('Content-Type: text/html; charset=UTF-8');
|
2024 |
-
if(wp_mail($email, $subject, $message, $headers))
|
2025 |
echo $gmCore->alert('success', sprintf(__('Message sent to %s', 'grand-media'), $email));
|
2026 |
}
|
2027 |
|
@@ -2029,7 +1879,7 @@ EOT;
|
|
2029 |
}
|
2030 |
|
2031 |
add_action('wp_ajax_gmedia_add_custom_field', 'gmedia_add_custom_field');
|
2032 |
-
function gmedia_add_custom_field()
|
2033 |
global $gmDB, $user_ID, $gmCore;
|
2034 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
2035 |
|
@@ -2040,16 +1890,16 @@ function gmedia_add_custom_field() {
|
|
2040 |
|
2041 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
2042 |
|
2043 |
-
if(!current_user_can('gmedia_edit_media') || ($user_ID != $post->author && !current_user_can('gmedia_edit_others_media')))
|
2044 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
2045 |
die();
|
2046 |
}
|
2047 |
-
if(isset($_POST['metakeyselect']) && empty($_POST['metakeyselect']) && empty($_POST['metakeyinput']))
|
2048 |
echo json_encode(array('error' => array('code' => 101, 'message' => __('Choose or provide a custom field name', 'grand-media')), 'id' => $pid));
|
2049 |
die();
|
2050 |
}
|
2051 |
|
2052 |
-
if(!$mid = $gmCore->add_meta($pid, $meta_type))
|
2053 |
echo json_encode(array('error' => array('code' => 102, 'message' => __('Please provide a custom field value', 'grand-media')), 'id' => $pid));
|
2054 |
die();
|
2055 |
}
|
@@ -2058,15 +1908,13 @@ function gmedia_add_custom_field() {
|
|
2058 |
$meta = $gmDB->get_metadata_by_mid($meta_type, $mid);
|
2059 |
$pid = (int)$meta->{$column};
|
2060 |
$meta = get_object_vars($meta);
|
2061 |
-
$result = array(
|
2062 |
-
|
2063 |
-
|
2064 |
-
'
|
2065 |
-
),
|
2066 |
-
'id' => $pid
|
2067 |
);
|
2068 |
|
2069 |
-
if(!empty($_POST['metakeyinput']))
|
2070 |
$result['newmeta_form'] = $gmCore->meta_form($meta_type);
|
2071 |
}
|
2072 |
|
@@ -2076,8 +1924,8 @@ function gmedia_add_custom_field() {
|
|
2076 |
}
|
2077 |
|
2078 |
add_action('wp_ajax_gmedia_delete_custom_field', 'gmedia_delete_custom_field');
|
2079 |
-
function gmedia_delete_custom_field()
|
2080 |
-
global $gmDB, $user_ID;
|
2081 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
2082 |
|
2083 |
$meta_type = 'gmedia';
|
@@ -2085,7 +1933,7 @@ function gmedia_delete_custom_field() {
|
|
2085 |
$pid = (int)$_POST['ID'];
|
2086 |
$post = $gmDB->get_gmedia($pid);
|
2087 |
|
2088 |
-
if(!current_user_can('gmedia_edit_media') || ($user_ID != $post->author && !current_user_can('gmedia_edit_others_media')))
|
2089 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
2090 |
die();
|
2091 |
}
|
@@ -2094,18 +1942,18 @@ function gmedia_delete_custom_field() {
|
|
2094 |
|
2095 |
$deletemeta = $_POST['meta'];
|
2096 |
$column = sanitize_key($meta_type . '_id');
|
2097 |
-
if(isset($deletemeta) && is_array($deletemeta))
|
2098 |
-
foreach($deletemeta as $key => $value)
|
2099 |
-
if(!$meta = $gmDB->get_metadata_by_mid($meta_type, $key))
|
2100 |
continue;
|
2101 |
}
|
2102 |
-
if($meta->{$column} != $pid)
|
2103 |
continue;
|
2104 |
}
|
2105 |
-
if(is_protected_meta($meta->meta_key, $meta_type))
|
2106 |
continue;
|
2107 |
}
|
2108 |
-
if(($del_meta = $gmDB->delete_metadata_by_mid($meta_type, $key)))
|
2109 |
$result['deleted'][] = $key;
|
2110 |
}
|
2111 |
}
|
@@ -2118,29 +1966,29 @@ function gmedia_delete_custom_field() {
|
|
2118 |
}
|
2119 |
|
2120 |
add_action('wp_ajax_gmedia_term_add_custom_field', 'gmedia_term_add_custom_field');
|
2121 |
-
function gmedia_term_add_custom_field()
|
2122 |
global $gmDB, $user_ID, $gmCore;
|
2123 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
2124 |
|
2125 |
$meta_type = 'gmedia_term';
|
2126 |
|
2127 |
-
$pid
|
2128 |
-
$post
|
2129 |
|
2130 |
$taxonomy = $post->taxonomy;
|
2131 |
|
2132 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
2133 |
|
2134 |
-
if(!current_user_can($taxonomy.'_manage') || ($user_ID != $post->global && !current_user_can('gmedia_edit_others_media')))
|
2135 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
2136 |
die();
|
2137 |
}
|
2138 |
-
if(isset($_POST['metakeyselect']) && empty($_POST['metakeyselect']) && empty($_POST['metakeyinput']))
|
2139 |
echo json_encode(array('error' => array('code' => 101, 'message' => __('Choose or provide a custom field name', 'grand-media')), 'id' => $pid));
|
2140 |
die();
|
2141 |
}
|
2142 |
|
2143 |
-
if(!$mid = $gmCore->add_meta($pid, $meta_type))
|
2144 |
echo json_encode(array('error' => array('code' => 102, 'message' => __('Please provide a custom field value', 'grand-media')), 'id' => $pid));
|
2145 |
die();
|
2146 |
}
|
@@ -2149,15 +1997,13 @@ function gmedia_term_add_custom_field() {
|
|
2149 |
$meta = $gmDB->get_metadata_by_mid($meta_type, $mid);
|
2150 |
$pid = (int)$meta->{$column};
|
2151 |
$meta = get_object_vars($meta);
|
2152 |
-
$result = array(
|
2153 |
-
|
2154 |
-
|
2155 |
-
'
|
2156 |
-
),
|
2157 |
-
'id' => $pid
|
2158 |
);
|
2159 |
|
2160 |
-
if(!empty($_POST['metakeyinput']))
|
2161 |
$result['newmeta_form'] = $gmCore->meta_form($meta_type);
|
2162 |
}
|
2163 |
|
@@ -2167,20 +2013,20 @@ function gmedia_term_add_custom_field() {
|
|
2167 |
}
|
2168 |
|
2169 |
add_action('wp_ajax_gmedia_term_delete_custom_field', 'gmedia_term_delete_custom_field');
|
2170 |
-
function gmedia_term_delete_custom_field()
|
2171 |
-
global $gmDB, $user_ID;
|
2172 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
2173 |
|
2174 |
$meta_type = 'gmedia_term';
|
2175 |
|
2176 |
-
$pid
|
2177 |
-
$post
|
2178 |
|
2179 |
$taxonomy = $post->taxonomy;
|
2180 |
|
2181 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
2182 |
|
2183 |
-
if(!current_user_can($taxonomy.'_manage') || ($user_ID != $post->global && !current_user_can('gmedia_edit_others_media')))
|
2184 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
2185 |
die();
|
2186 |
}
|
@@ -2189,18 +2035,18 @@ function gmedia_term_delete_custom_field() {
|
|
2189 |
|
2190 |
$deletemeta = $_POST['meta'];
|
2191 |
$column = sanitize_key($meta_type . '_id');
|
2192 |
-
if(isset($deletemeta) && is_array($deletemeta))
|
2193 |
-
foreach($deletemeta as $key => $value)
|
2194 |
-
if(!$meta = $gmDB->get_metadata_by_mid($meta_type, $key))
|
2195 |
continue;
|
2196 |
}
|
2197 |
-
if($meta->{$column} != $pid)
|
2198 |
continue;
|
2199 |
}
|
2200 |
-
if(is_protected_meta($meta->meta_key, $meta_type))
|
2201 |
continue;
|
2202 |
}
|
2203 |
-
if(($del_meta = $gmDB->delete_metadata_by_mid($meta_type, $key)))
|
2204 |
$result['deleted'][] = $key;
|
2205 |
}
|
2206 |
}
|
@@ -2212,27 +2058,27 @@ function gmedia_term_delete_custom_field() {
|
|
2212 |
}
|
2213 |
|
2214 |
add_action('wp_ajax_gmedia_upgrade_process', 'gmedia_upgrade_process');
|
2215 |
-
function gmedia_upgrade_process()
|
2216 |
|
2217 |
$db_version = get_option('gmediaDbVersion');
|
2218 |
-
$info
|
2219 |
-
$result
|
2220 |
|
2221 |
$upgrading = get_transient('gmediaUpgrade');
|
2222 |
if($upgrading){
|
2223 |
$timeout = time() - $upgrading;
|
2224 |
-
} else
|
2225 |
$timeout = 0;
|
2226 |
}
|
2227 |
if($timeout > 20){
|
2228 |
-
require_once(GMEDIA_ABSPATH.'config/update.php');
|
2229 |
gmedia_db_update();
|
2230 |
}
|
2231 |
$result['timeout'] = $timeout;
|
2232 |
|
2233 |
-
if(!empty($info))
|
2234 |
$result['content'] = '<div>' . implode("</div>\n<div>", $info) . '</div>';
|
2235 |
-
} elseif($db_version == GMEDIA_DBVERSION)
|
2236 |
$result['status'] = 'done';
|
2237 |
}
|
2238 |
|
@@ -2242,30 +2088,135 @@ function gmedia_upgrade_process() {
|
|
2242 |
|
2243 |
}
|
2244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2245 |
add_action('wp_ajax_gmedia_module_interaction', 'gmedia_module_interaction');
|
2246 |
add_action('wp_ajax_nopriv_gmedia_module_interaction', 'gmedia_module_interaction');
|
2247 |
-
function gmedia_module_interaction()
|
2248 |
global $gmDB, $gmCore;
|
2249 |
|
2250 |
-
if(empty($_SERVER['HTTP_REFERER']))
|
2251 |
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
2252 |
die();
|
2253 |
}
|
2254 |
|
2255 |
$ref = $_SERVER['HTTP_REFERER'];
|
2256 |
//$uip = str_replace('.', '', $_SERVER['REMOTE_ADDR'])
|
2257 |
-
if((false === strpos($ref, get_home_url())) && (false === strpos($ref, get_site_url())))
|
2258 |
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
2259 |
die();
|
2260 |
}
|
2261 |
-
if(('POST' !== $_SERVER['REQUEST_METHOD']) || !isset($_SERVER['HTTP_HOST']) || !strpos(get_home_url(), $_SERVER['HTTP_HOST']))
|
2262 |
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
2263 |
die();
|
2264 |
}
|
2265 |
|
2266 |
|
2267 |
-
if(isset($_POST['hit']) && ($gmID = intval($_POST['hit'])))
|
2268 |
-
if(null === $gmDB->get_gmedia($gmID))
|
2269 |
die('0');
|
2270 |
}
|
2271 |
$meta['views'] = $gmDB->get_metadata('gmedia', $gmID, 'views', true);
|
@@ -2279,34 +2230,34 @@ function gmedia_module_interaction() {
|
|
2279 |
die();
|
2280 |
}
|
2281 |
|
2282 |
-
if(isset($_POST['rate']))
|
2283 |
/**
|
2284 |
* @var $uip
|
2285 |
* @var $gmid
|
2286 |
* @var $rate
|
2287 |
*/
|
2288 |
extract($_POST['rate'], EXTR_OVERWRITE);
|
2289 |
-
if(!intval($gmid) || (null === $gmDB->get_gmedia($gmid)))
|
2290 |
die('0');
|
2291 |
}
|
2292 |
$rating = $gmDB->get_metadata('gmedia', $gmid, '_rating', true);
|
|
|
2293 |
$old_rate = 0;
|
2294 |
|
2295 |
$transient_key = 'gm_rate_day' . date('w');
|
2296 |
$transient_value = get_transient($transient_key);
|
2297 |
-
if(false !== $transient_value)
|
2298 |
-
if(isset($transient_value[$uip][$gmid]))
|
2299 |
-
$old_rate = $transient_value[$uip][$gmid];
|
2300 |
}
|
2301 |
-
$transient_value[$uip][$gmid] = $rate;
|
2302 |
-
} else
|
2303 |
$transient_value = array($uip => array($gmid => $rate));
|
2304 |
}
|
2305 |
set_transient($transient_key, $transient_value, 18 * HOUR_IN_SECONDS);
|
2306 |
|
2307 |
-
$
|
2308 |
-
$
|
2309 |
-
$rating = array('value' => $rating_value, 'votes' => $rating_votes);
|
2310 |
|
2311 |
$gmDB->update_metadata('gmedia', $gmid, '_rating', $rating);
|
2312 |
|
@@ -2320,7 +2271,7 @@ function gmedia_module_interaction() {
|
|
2320 |
|
2321 |
add_action('wp_ajax_load_comments', 'gmedia_module_load_comments');
|
2322 |
add_action('wp_ajax_nopriv_load_comments', 'gmedia_module_load_comments');
|
2323 |
-
function gmedia_module_load_comments()
|
2324 |
global $gmCore;
|
2325 |
|
2326 |
/* if(empty($_SERVER['HTTP_REFERER'])) {
|
@@ -2344,11 +2295,11 @@ function gmedia_module_load_comments() {
|
|
2344 |
$data = $gmCore->_post('data', false);
|
2345 |
|
2346 |
$post_id = (int)$data['post_id'];
|
2347 |
-
if($post_id)
|
2348 |
$comments_link = apply_filters('gmedia_comments_link', add_query_arg('comments', 'show', get_permalink($post_id)), $post_id);
|
2349 |
$comments_count = wp_count_comments($post_id);
|
2350 |
$comments_count = $comments_count->approved;
|
2351 |
-
} else
|
2352 |
$comments_link = '//about:blank';
|
2353 |
$comments_count = 0;
|
2354 |
}
|
1 |
<?php
|
2 |
add_action('wp_ajax_gmedia_update_data', 'gmedia_update_data');
|
3 |
+
function gmedia_update_data(){
|
4 |
global $gmDB, $gmCore;
|
5 |
check_ajax_referer("GmediaGallery");
|
6 |
+
if(!current_user_can('gmedia_edit_media')){
|
7 |
die('-1');
|
8 |
}
|
9 |
|
11 |
|
12 |
wp_parse_str($data, $gmedia);
|
13 |
|
14 |
+
if(!empty($gmedia['ID'])){
|
15 |
$item = $gmDB->get_gmedia($gmedia['ID']);
|
16 |
+
if((int)$item->author != get_current_user_id()){
|
17 |
+
if(!current_user_can('gmedia_edit_others_media')){
|
18 |
die('-2');
|
19 |
}
|
20 |
}
|
22 |
$gmedia['modified'] = current_time('mysql');
|
23 |
$gmedia['mime_type'] = $item->mime_type;
|
24 |
$gmedia['gmuid'] = $item->gmuid;
|
25 |
+
if(!current_user_can('gmedia_delete_others_media')){
|
26 |
$gmedia['author'] = $item->author;
|
27 |
}
|
28 |
|
29 |
$gmuid = pathinfo($item->gmuid);
|
30 |
|
31 |
$gmedia['filename'] = preg_replace('/[^a-z0-9_\.-]+/i', '_', $gmedia['filename']);
|
32 |
+
if(($gmedia['filename'] != $gmuid['filename']) && (current_user_can('gmedia_delete_others_media') || ((int)$item->author == get_current_user_id()))){
|
33 |
$fileinfo = $gmCore->fileinfo($gmedia['filename'] . '.' . $gmuid['extension']);
|
34 |
+
if(false !== $fileinfo){
|
35 |
+
if('image' == $fileinfo['dirname'] && file_is_displayable_image($fileinfo['dirpath'] . '/' . $item->gmuid)){
|
36 |
@rename($fileinfo['dirpath_original'] . '/' . $item->gmuid, $fileinfo['filepath_original']);
|
37 |
@rename($fileinfo['dirpath_thumb'] . '/' . $item->gmuid, $fileinfo['filepath_thumb']);
|
38 |
}
|
39 |
+
if(@rename($fileinfo['dirpath'] . '/' . $item->gmuid, $fileinfo['filepath'])){
|
40 |
$gmedia['gmuid'] = $fileinfo['basename'];
|
41 |
}
|
42 |
}
|
43 |
}
|
44 |
+
if(!current_user_can('gmedia_terms')){
|
45 |
unset($gmedia['terms']);
|
46 |
}
|
47 |
|
48 |
$id = $gmDB->insert_gmedia($gmedia);
|
49 |
+
if(!is_wp_error($id)){
|
50 |
// Meta Stuff
|
51 |
+
if(isset($gmedia['meta']) && is_array($gmedia['meta'])){
|
52 |
$meta_error = array();
|
53 |
+
foreach($gmedia['meta'] as $key => $value){
|
54 |
+
if($gmCore->is_digit($key)){
|
55 |
$mid = (int)$key;
|
56 |
//$value = wp_unslash( $value );
|
57 |
+
if(!($meta = $gmDB->get_metadata_by_mid('gmedia', $mid))){
|
58 |
+
$meta_error[] = array('error' => 'no_meta',
|
59 |
+
'message' => __('No record in DataBase.', 'grand-media'),
|
60 |
+
'meta_id' => $mid,
|
61 |
+
'meta_key' => $meta->meta_key
|
|
|
62 |
);
|
63 |
continue;
|
64 |
}
|
65 |
+
if('' == trim($value)){
|
66 |
+
$meta_error[] = array('error' => 'empty_value',
|
67 |
+
'message' => __('Please provide a custom field value.', 'grand-media'),
|
68 |
+
'meta_id' => $mid,
|
69 |
+
'meta_key' => $meta->meta_key,
|
70 |
+
'meta_value' => $meta->meta_value
|
|
|
71 |
);
|
72 |
continue;
|
73 |
}
|
74 |
|
75 |
+
if($meta->meta_value != $value){
|
76 |
+
if(!($u = $gmDB->update_metadata_by_mid('gmedia', $mid, $value))){
|
77 |
+
$meta_error[] = array('error' => 'meta_update',
|
78 |
+
'message' => __('Something goes wrong.', 'grand-media'),
|
79 |
+
'meta_id' => $mid,
|
80 |
+
'meta_key' => $meta->meta_key,
|
81 |
+
'meta_value' => $meta->meta_value
|
|
|
82 |
);
|
83 |
}
|
84 |
}
|
85 |
+
} elseif('_' == $key[0]){
|
86 |
+
if('_cover' == $key){
|
87 |
$value = ltrim($value, '#');
|
88 |
+
} elseif('_gps' == $key){
|
89 |
+
if($value){
|
90 |
$latlng = explode(',', $value);
|
91 |
$value = array('lat' => trim($latlng[0]), 'lng' => trim($latlng[1]));
|
92 |
}
|
97 |
}
|
98 |
}
|
99 |
$result = $gmDB->get_gmedia($id);
|
100 |
+
} else{
|
101 |
$result = $gmDB->get_gmedia($id);
|
102 |
}
|
103 |
+
if(current_user_can('gmedia_terms')){
|
104 |
$tags = $gmDB->get_the_gmedia_terms($id, 'gmedia_tag');
|
105 |
+
if($tags){
|
106 |
$tags_list = array();
|
107 |
+
foreach($tags as $tag){
|
108 |
$tags_list[] = $tag->name;
|
109 |
}
|
110 |
$result->tags = implode(', ', $tags_list);
|
111 |
}
|
112 |
+
if(!empty($gmedia['terms']['gmedia_album'])){
|
113 |
+
$alb_id = $gmedia['terms']['gmedia_album'];
|
114 |
+
$alb = $gmDB->get_term($alb_id, 'gmedia_album');
|
115 |
+
$result->album_status = $alb? $alb->status : 'none';
|
116 |
+
} else{
|
117 |
$result->album_status = 'none';
|
118 |
}
|
119 |
}
|
120 |
+
if(!empty($meta_error)){
|
121 |
$result->meta_error = $meta_error;
|
122 |
}
|
123 |
|
129 |
}
|
130 |
|
131 |
add_action('wp_ajax_gmedit_save', 'gmedit_save');
|
132 |
+
function gmedit_save(){
|
133 |
global $gmDB, $gmCore, $gmGallery;
|
134 |
check_ajax_referer("gmedit-save");
|
135 |
+
if(!current_user_can('gmedia_edit_media')){
|
136 |
die('-1');
|
137 |
}
|
138 |
|
144 |
$applyto = $gmCore->_post('applyto', 'web_thumb');
|
145 |
|
146 |
$item = $gmDB->get_gmedia($gmid);
|
147 |
+
if(!empty($item)){
|
148 |
+
if((int)$item->author != get_current_user_id()){
|
149 |
+
if(!current_user_can('gmedia_edit_others_media')){
|
150 |
die('-2');
|
151 |
}
|
152 |
}
|
165 |
|
166 |
$size = @getimagesize($fileinfo['filepath']);
|
167 |
|
168 |
+
do{
|
169 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
170 |
+
if(function_exists('memory_get_usage')){
|
171 |
+
switch($extensions[ $size[2] ]){
|
172 |
case 'GIF':
|
173 |
$CHANNEL = 1;
|
174 |
break;
|
190 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
191 |
$current_limit = @ini_get('memory_limit');
|
192 |
$current_limit_int = intval($current_limit);
|
193 |
+
if(false !== strpos($current_limit, 'M')){
|
194 |
$current_limit_int *= $MB;
|
195 |
}
|
196 |
+
if(false !== strpos($current_limit, 'G')){
|
197 |
$current_limit_int *= 1024;
|
198 |
}
|
199 |
|
200 |
+
if(- 1 != $current_limit && $memoryNeeded > $current_limit_int){
|
201 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
202 |
+
if($newLimit < 256){
|
203 |
+
$newLimit = 256;
|
204 |
+
}
|
205 |
@ini_set('memory_limit', $newLimit . 'M');
|
206 |
}
|
207 |
}
|
208 |
|
209 |
+
if('thumb' == $applyto){
|
210 |
$editfile = $fileinfo['filepath_thumb'];
|
211 |
+
} else{
|
212 |
$editfile = $fileinfo['filepath'];
|
213 |
}
|
214 |
+
if(!@file_put_contents($editfile, $image['data'])){
|
215 |
$fail = $fileinfo['basename'] . ": " . __('Can\'t write to file. Permission denied', 'grand-media');
|
216 |
break;
|
217 |
}
|
220 |
$gmDB->update_metadata($meta_type = 'gmedia', $item->ID, $meta_key = '_modified', $modified);
|
221 |
|
222 |
// Web-image
|
223 |
+
if('thumb' !== $applyto){
|
224 |
+
if(('JPG' == $extensions[ $size[2] ]) && !(extension_loaded('imagick') || class_exists("Imagick"))){
|
225 |
$gmCore->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
226 |
}
|
227 |
}
|
228 |
// Thumbnail
|
229 |
+
if('web_thumb' == $applyto){
|
230 |
$size_ratio = $size[0] / $size[1];
|
231 |
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
232 |
+
if($thumbimg['resize']){
|
233 |
$editor = wp_get_image_editor($editfile);
|
234 |
+
if(is_wp_error($editor)){
|
235 |
$fail = $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message();
|
236 |
break;
|
237 |
}
|
239 |
$editor->set_quality($thumbimg['quality']);
|
240 |
$ed_size = $editor->get_size();
|
241 |
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
242 |
+
if(1 > $ed_ratio){
|
243 |
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
244 |
+
} else{
|
245 |
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
246 |
}
|
247 |
+
if(is_wp_error($resized)){
|
248 |
$fail = $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})) applyto-{$applyto}: " . $resized->get_error_message();
|
249 |
break;
|
250 |
}
|
251 |
|
252 |
$thumbis = false;
|
253 |
+
if(file_exists($fileinfo['filepath_thumb'])){
|
254 |
$thumbis = true;
|
255 |
rename($fileinfo['filepath_thumb'], $fileinfo['filepath_thumb'] . '.tmp');
|
256 |
}
|
257 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
258 |
+
if(is_wp_error($saved)){
|
259 |
+
if($thumbis){
|
260 |
rename($fileinfo['filepath_thumb'] . '.tmp', $fileinfo['filepath_thumb']);
|
261 |
}
|
262 |
$fail = $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message();
|
263 |
break;
|
264 |
}
|
265 |
|
266 |
+
} else{
|
267 |
@copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
268 |
}
|
269 |
}
|
281 |
$success = sprintf(__('Image "%d" updated', 'grand-media'), $id);
|
282 |
} while(0);
|
283 |
|
284 |
+
if(empty($fail)){
|
285 |
$out = array('msg' => $gmCore->alert('info', $success), 'modified' => $gmedia['modified']);
|
286 |
+
} else{
|
287 |
$out = array('error' => $gmCore->alert('danger', $fail));
|
288 |
}
|
289 |
|
295 |
}
|
296 |
|
297 |
add_action('wp_ajax_gmedit_restore', 'gmedit_restore');
|
298 |
+
function gmedit_restore(){
|
299 |
+
global $gmCore;
|
300 |
check_ajax_referer("gmedit-save");
|
301 |
+
if(!current_user_can('gmedia_edit_media')){
|
302 |
die('-1');
|
303 |
}
|
304 |
|
305 |
+
$gmid = $gmCore->_post('id');
|
306 |
+
$out = $gmCore->recreate_images_from_original($gmid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
309 |
+
echo json_encode($out);
|
|
|
310 |
|
311 |
die();
|
312 |
}
|
313 |
|
314 |
add_action('wp_ajax_gmedia_get_modal', 'gmedia_get_modal');
|
315 |
+
function gmedia_get_modal(){
|
316 |
global $gmDB, $gmCore, $gmGallery;
|
317 |
check_ajax_referer("GmediaGallery");
|
318 |
$user_ID = get_current_user_id();
|
319 |
$button_class = 'btn-primary';
|
320 |
$gm_terms = array();
|
321 |
$modal = $gmCore->_post('modal');
|
322 |
+
switch($modal){
|
323 |
case 'quick_gallery':
|
324 |
+
if(!current_user_can('gmedia_gallery_manage')){
|
325 |
die('-1');
|
326 |
}
|
327 |
+
$ckey = "gmuser_{$user_ID}_library";
|
328 |
$modal_title = __('Quick Gallery from selected items', 'grand-media');
|
329 |
$modal_button = __('Create Quick Gallery', 'grand-media');
|
330 |
break;
|
331 |
case 'quick_gallery_stack':
|
332 |
+
if(!current_user_can('gmedia_gallery_manage')){
|
333 |
die('-1');
|
334 |
}
|
335 |
+
$ckey = "gmuser_{$user_ID}_library_stack";
|
336 |
$modal_title = __('Quick Gallery from Stack', 'grand-media');
|
337 |
$modal_button = __('Create Quick Gallery', 'grand-media');
|
338 |
break;
|
342 |
$modal_button = __('Show Selected', 'grand-media');
|
343 |
break;
|
344 |
case 'assign_category':
|
345 |
+
if(!current_user_can('gmedia_terms')){
|
346 |
die('-1');
|
347 |
}
|
348 |
$modal_title = __('Assign Category for Selected Images', 'grand-media');
|
349 |
$modal_button = __('Assign Category', 'grand-media');
|
350 |
break;
|
351 |
case 'unassign_category':
|
352 |
+
if(!current_user_can('gmedia_terms')){
|
353 |
die('-1');
|
354 |
}
|
355 |
$button_class = 'btn-danger';
|
362 |
$modal_button = __('Show Selected', 'grand-media');
|
363 |
break;
|
364 |
case 'assign_album':
|
365 |
+
if(!current_user_can('gmedia_terms')){
|
366 |
die('-1');
|
367 |
}
|
368 |
$modal_title = __('Assign Album for Selected Items', 'grand-media');
|
374 |
$modal_button = __('Show Selected', 'grand-media');
|
375 |
break;
|
376 |
case 'add_tags':
|
377 |
+
if(!current_user_can('gmedia_terms')){
|
378 |
die('-1');
|
379 |
}
|
380 |
$modal_title = __('Add Tags to Selected Items', 'grand-media');
|
381 |
$modal_button = __('Add Tags', 'grand-media');
|
382 |
break;
|
383 |
case 'delete_tags':
|
384 |
+
if(!current_user_can('gmedia_terms')){
|
385 |
die('-1');
|
386 |
}
|
387 |
$button_class = 'btn-danger';
|
394 |
break;
|
395 |
case 'filter_author':
|
396 |
$modal_title = __('Filter by Author', 'grand-media');
|
397 |
+
if($gmCore->caps['gmedia_show_others_media']){
|
398 |
$modal_button = __('Show Selected', 'grand-media');
|
399 |
+
} else{
|
400 |
$modal_button = false;
|
401 |
}
|
402 |
break;
|
403 |
case 'select_author':
|
404 |
$modal_title = __('Select Author', 'grand-media');
|
405 |
+
if($gmCore->caps['gmedia_show_others_media']){
|
406 |
$modal_button = __('Select', 'grand-media');
|
407 |
+
} else{
|
408 |
$modal_button = false;
|
409 |
}
|
410 |
break;
|
411 |
case 'batch_edit':
|
412 |
+
if(!current_user_can('gmedia_edit_media')){
|
413 |
die('-1');
|
414 |
}
|
415 |
$modal_title = __('Batch Edit', 'grand-media');
|
430 |
</div>
|
431 |
<div class="modal-body">
|
432 |
<?php
|
433 |
+
switch($modal){
|
434 |
+
case 'quick_gallery':
|
435 |
case 'quick_gallery_stack':
|
436 |
+
if(!empty($ckey)){
|
437 |
+
$selected_in_library = isset($_COOKIE[ $ckey ])? $_COOKIE[ $ckey ] : '';
|
438 |
}
|
439 |
+
if(empty($selected_in_library)){
|
440 |
_e('No selected Gmedia. Select at least one item in library.', 'grand-media');
|
441 |
break;
|
442 |
}
|
449 |
<div class="form-group">
|
450 |
<label><?php _e('Modue', 'grand-media'); ?></label>
|
451 |
<select class="form-control input-sm" name="gallery[module]">
|
452 |
+
<?php foreach($gmedia_modules['in'] as $mfold => $module){
|
453 |
echo '<optgroup label="' . esc_attr($module['title']) . '">';
|
454 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
|
455 |
+
$selected = selected($gmGallery->options['default_gmedia_module'], esc_attr($mfold), false);
|
456 |
+
$option = array();
|
457 |
+
$option[] = '<option ' . $selected . ' value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
|
458 |
+
foreach($presets as $preset){
|
459 |
+
if(!(int)$preset->global && '[' . $mfold . ']' === $preset->name){
|
460 |
+
continue;
|
461 |
+
}
|
462 |
+
$selected = selected($gmGallery->options['default_gmedia_module'], $preset->term_id, false);
|
463 |
+
$by_author = '';
|
464 |
+
if((int)$preset->global){
|
465 |
+
$by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
|
466 |
+
}
|
467 |
+
if('[' . $mfold . ']' === $preset->name){
|
468 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
|
469 |
+
} else{
|
470 |
$preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
|
471 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
|
472 |
}
|
473 |
}
|
474 |
echo implode('', $option);
|
484 |
break;
|
485 |
case 'exclude_albums':
|
486 |
case 'filter_albums':
|
487 |
+
if($gmCore->caps['gmedia_show_others_media']){
|
488 |
$args = array();
|
489 |
+
} else{
|
490 |
+
$args = array('global' => array(0, $user_ID),
|
491 |
+
'orderby' => 'global_desc_name'
|
|
|
492 |
);
|
493 |
}
|
494 |
$gm_terms = $gmDB->get_terms('gmedia_album', $args);
|
495 |
?>
|
496 |
<div class="checkbox"><label><input type="checkbox" name="alb[]" value="0"> <?php _e('No Album', 'grand-media'); ?></label></div>
|
497 |
<hr/>
|
498 |
+
<?php if(count($gm_terms)){
|
499 |
+
foreach($gm_terms as $term){
|
500 |
$author_name = '';
|
501 |
+
if($term->global){
|
502 |
+
if($gmCore->caps['gmedia_show_others_media']){
|
503 |
$author_name .= sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $term->global));
|
504 |
}
|
505 |
+
} else{
|
506 |
$author_name .= '(' . __('shared', 'grand-media') . ')';
|
507 |
}
|
508 |
+
if('publish' != $term->status){
|
509 |
$author_name .= ' [' . $term->status . ']';
|
510 |
}
|
511 |
+
if($author_name){
|
512 |
$author_name = " <small>{$author_name}</small>";
|
513 |
}
|
514 |
?>
|
518 |
</div>
|
519 |
<?php
|
520 |
}
|
521 |
+
} else{
|
522 |
$modal_button = false;
|
523 |
}
|
524 |
break;
|
525 |
case 'assign_album':
|
526 |
+
if($gmCore->caps['gmedia_edit_others_media']){
|
527 |
$args = array();
|
528 |
+
} else{
|
529 |
+
$args = array('global' => array(0, $user_ID),
|
530 |
+
'orderby' => 'global_desc_name'
|
|
|
531 |
);
|
532 |
}
|
533 |
$gm_terms = $gmDB->get_terms('gmedia_album', $args);
|
534 |
|
535 |
$terms_album = '';
|
536 |
+
if(count($gm_terms)){
|
537 |
+
foreach($gm_terms as $term){
|
538 |
$author_name = '';
|
539 |
+
if($term->global){
|
540 |
+
if($gmCore->caps['gmedia_edit_others_media']){
|
541 |
$author_name .= ' ' . sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $term->global));
|
542 |
}
|
543 |
+
} else{
|
544 |
$author_name .= ' (' . __('shared', 'grand-media') . ')';
|
545 |
}
|
546 |
+
if('publish' != $term->status){
|
547 |
$author_name .= ' [' . $term->status . ']';
|
548 |
}
|
549 |
$terms_album .= '<option value="' . $term->term_id . '" data-count="' . $term->count . '" data-name="' . esc_html($term->name) . '" data-meta="' . $author_name . '">' . esc_html($term->name) . $author_name . '</option>' . "\n";
|
610 |
break;
|
611 |
case 'exclude_categories':
|
612 |
case 'filter_categories':
|
613 |
+
$gm_terms = $gmDB->get_terms('gmedia_category');
|
614 |
+
?>
|
615 |
+
<div class="checkbox"><label><input type="checkbox" name="cat[]" value="0"> <?php _e('Uncategorized', 'grand-media'); ?></label></div>
|
616 |
+
<?php
|
617 |
+
if(count($gm_terms)){
|
618 |
+
foreach($gm_terms as $term){
|
619 |
+
if($term->count){
|
620 |
?>
|
621 |
+
<div class="checkbox">
|
622 |
+
<label><input type="checkbox" name="cat[]" value="<?php echo $term->term_id; ?>"> <?php echo esc_html($term->name); ?></label>
|
623 |
+
<span class="badge pull-right"><?php echo $term->count; ?></span>
|
624 |
+
</div>
|
625 |
+
<?php
|
626 |
+
}
|
627 |
+
}
|
628 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
629 |
break;
|
630 |
case 'assign_category':
|
631 |
$gm_terms = $gmDB->get_terms('gmedia_category', array('fields' => 'names_count'));
|
679 |
case 'unassign_category':
|
680 |
// get selected items in Gmedia Library
|
681 |
$ckey = "gmuser_{$user_ID}_library";
|
682 |
+
$selected_items = array_filter(explode(',', $_COOKIE[ $ckey ]), 'is_numeric');
|
683 |
+
if(!empty($selected_items)){
|
684 |
$gm_terms = $gmDB->get_gmedia_terms($selected_items, 'gmedia_category');
|
685 |
}
|
686 |
if(count($gm_terms)){
|
692 |
</div>
|
693 |
<?php
|
694 |
}
|
695 |
+
} else{
|
696 |
$modal_button = false; ?>
|
697 |
<p class="noterms"><?php _e('No categories', 'grand-media'); ?></p>
|
698 |
<?php
|
797 |
case 'delete_tags':
|
798 |
// get selected items in Gmedia Library
|
799 |
$ckey = "gmuser_{$user_ID}_library";
|
800 |
+
$selected_items = array_filter(explode(',', $_COOKIE[ $ckey ]), 'is_numeric');
|
801 |
+
if(!empty($selected_items)){
|
802 |
$gm_terms = $gmDB->get_gmedia_terms($selected_items, 'gmedia_tag');
|
803 |
}
|
804 |
if(count($gm_terms)){
|
810 |
</div>
|
811 |
<?php
|
812 |
}
|
813 |
+
} else{
|
814 |
$modal_button = false; ?>
|
815 |
<p class="noterms"><?php _e('No tags', 'grand-media'); ?></p>
|
816 |
<?php
|
824 |
<label><?php _e('Choose Author', 'grand-media'); ?></label>
|
825 |
<?php
|
826 |
$user_ids = $gmCore->get_editable_user_ids();
|
827 |
+
if($user_ids){
|
828 |
+
if(!in_array($user_ID, $user_ids)){
|
829 |
array_push($user_ids, $user_ID);
|
830 |
}
|
831 |
+
wp_dropdown_users(array('show_option_all' => ' — ',
|
832 |
+
'include' => $user_ids,
|
833 |
+
'include_selected' => true,
|
834 |
+
'name' => 'author_ids',
|
835 |
+
'selected' => $user_ID,
|
836 |
+
'class' => 'form-control'
|
|
|
837 |
));
|
838 |
+
} else{
|
839 |
echo '<div>' . get_the_author_meta('display_name', $user_ID) . '</div>';
|
840 |
}
|
841 |
?>
|
842 |
</div>
|
843 |
<?php
|
844 |
+
} else{
|
845 |
echo '<p>' . __('You are not allowed to see others media') . '</p>';
|
846 |
echo '<p><strong>' . get_the_author_meta('display_name', $user_ID) . '</strong></p>';
|
847 |
}
|
919 |
</div>
|
920 |
<?php $user_ids = current_user_can('gmedia_delete_others_media')? $gmCore->get_editable_user_ids() : false;
|
921 |
if($user_ids){
|
922 |
+
if(!in_array($user_ID, $user_ids)){
|
923 |
array_push($user_ids, $user_ID);
|
924 |
}
|
925 |
?>
|
926 |
<div class="form-group">
|
927 |
<label><?php _e('Author', 'grand-media'); ?></label>
|
928 |
+
<?php wp_dropdown_users(array('show_option_none' => __('Skip. Do not change', 'grand-media'),
|
929 |
+
'include' => $user_ids,
|
930 |
+
'include_selected' => true,
|
931 |
+
'name' => 'batch_author',
|
932 |
+
'selected' => - 1,
|
933 |
+
'class' => 'input-sm form-control'
|
|
|
934 |
));
|
935 |
?>
|
936 |
</div>
|
956 |
</div>
|
957 |
<div class="modal-footer">
|
958 |
<button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Cancel', 'grand-media'); ?></button>
|
959 |
+
<?php if($modal_button){ ?>
|
960 |
<input type="hidden" name="<?php echo $modal; ?>"/>
|
961 |
<button type="button" onclick="jQuery('#ajax-modal-form').submit()" name="<?php echo $modal; ?>" class="btn <?php echo $button_class; ?>"><?php echo $modal_button; ?></button>
|
962 |
<?php
|
970 |
}
|
971 |
|
972 |
add_action('wp_ajax_gmedia_tag_edit', 'gmedia_tag_edit');
|
973 |
+
function gmedia_tag_edit(){
|
974 |
global $gmCore, $gmDB;
|
975 |
|
976 |
check_ajax_referer('GmediaTerms');
|
977 |
+
if(!current_user_can('gmedia_tag_manage') && !current_user_can('gmedia_edit_others_media')){
|
978 |
$out['error'] = $gmCore->alert('danger', __("You are not allowed to edit others media", 'grand-media'));
|
979 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
980 |
echo json_encode($out);
|
984 |
$term = array('taxonomy' => 'gmedia_tag');
|
985 |
$term['name'] = trim($gmCore->_post('tag_name', ''));
|
986 |
$term['term_id'] = intval($gmCore->_post('tag_id', 0));
|
987 |
+
if($term['name'] && !$gmCore->is_digit($term['name'])){
|
988 |
+
if(($term_id = $gmDB->term_exists($term['term_id']))){
|
989 |
+
if(!$gmDB->term_exists($term['name'], $term['taxonomy'])){
|
990 |
$term_id = $gmDB->update_term($term['term_id'], $term);
|
991 |
+
if(is_wp_error($term_id)){
|
992 |
$out['error'] = $gmCore->alert('danger', $term_id->get_error_message());
|
993 |
+
} else{
|
994 |
$out['msg'] = $gmCore->alert('info', sprintf(__("Tag #%d successfuly updated", 'grand-media'), $term_id));
|
995 |
}
|
996 |
+
} else{
|
997 |
$out['error'] = $gmCore->alert('danger', __("A term with the name provided already exists", 'grand-media'));
|
998 |
}
|
999 |
+
} else{
|
1000 |
$out['error'] = $gmCore->alert('danger', __("A term with the id provided do not exists", 'grand-media'));
|
1001 |
}
|
1002 |
+
} else{
|
1003 |
$out['error'] = $gmCore->alert('danger', __("Term name can't be only digits or empty", 'grand-media'));
|
1004 |
}
|
1005 |
|
1011 |
}
|
1012 |
|
1013 |
add_action('wp_ajax_gmedia_module_preset_delete', 'gmedia_module_preset_delete');
|
1014 |
+
function gmedia_module_preset_delete(){
|
1015 |
+
global $gmCore, $gmDB, $user_ID;
|
1016 |
$out = array('error' => '');
|
1017 |
|
1018 |
check_ajax_referer('GmediaGallery');
|
1019 |
+
if(!current_user_can('gmedia_gallery_manage')){
|
1020 |
$out['error'] = $gmCore->alert('danger', __("You are not allowed to manage galleries", 'grand-media'));
|
1021 |
+
} else{
|
1022 |
+
$term_id = intval($gmCore->_post('preset_id', 0));
|
1023 |
+
$term = $gmDB->get_term($term_id);
|
1024 |
+
if($term && !is_wp_error($term)){
|
1025 |
+
if(($term->global != $user_ID && !gm_user_can('delete_others_media')) || ((int)$term->global === 0 && !current_user_can('manage_options'))){
|
1026 |
+
$out['error'] = $gmCore->alert('danger', __("You are not allowed to manage galleries", 'grand-media'));
|
1027 |
+
|
1028 |
+
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
1029 |
+
echo json_encode($out);
|
1030 |
+
|
1031 |
+
die();
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
$delete = $gmDB->delete_term($term_id);
|
1035 |
+
if(is_wp_error($delete)){
|
1036 |
+
$out['error'] = $delete->get_error_message();
|
1037 |
+
}
|
1038 |
}
|
1039 |
}
|
1040 |
|
1046 |
}
|
1047 |
|
1048 |
add_action('wp_ajax_gmedia_module_install', 'gmedia_module_install');
|
1049 |
+
function gmedia_module_install(){
|
1050 |
global $gmCore, $gmGallery;
|
1051 |
|
1052 |
+
check_ajax_referer('GmediaGallery');
|
1053 |
+
if(!current_user_can('gmedia_module_manage')){
|
1054 |
echo $gmCore->alert('danger', __('You are not allowed to install modules'));
|
1055 |
die();
|
1056 |
}
|
1057 |
|
1058 |
+
if(($download = $gmCore->_post('download'))){
|
1059 |
$module = $gmCore->_post('module');
|
1060 |
$mzip = download_url($download);
|
1061 |
+
if(is_wp_error($mzip)){
|
1062 |
echo $gmCore->alert('danger', $mzip->get_error_message());
|
1063 |
die();
|
1064 |
}
|
1065 |
|
1066 |
$mzip = str_replace("\\", "/", $mzip);
|
1067 |
$to_folder = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/';
|
1068 |
+
if(!wp_mkdir_p($to_folder)){
|
1069 |
echo $gmCore->alert('danger', sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $to_folder));
|
1070 |
die();
|
1071 |
}
|
1072 |
+
if(!is_writable($to_folder)){
|
1073 |
@chmod($to_folder, 0755);
|
1074 |
+
if(!is_writable($to_folder)){
|
1075 |
echo $gmCore->alert('danger', sprintf(__('Directory %s is not writable by the server.', 'grand-media'), $to_folder));
|
1076 |
die();
|
1077 |
}
|
1079 |
|
1080 |
global $wp_filesystem;
|
1081 |
// Is a filesystem accessor setup?
|
1082 |
+
if(!$wp_filesystem || !is_object($wp_filesystem)){
|
1083 |
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
1084 |
WP_Filesystem();
|
1085 |
}
|
1086 |
+
if(!is_object($wp_filesystem)){
|
1087 |
$result = new WP_Error('fs_unavailable', __('Could not access filesystem.', 'flag'));
|
1088 |
+
} elseif($wp_filesystem->errors->get_error_code()){
|
1089 |
$result = new WP_Error('fs_error', __('Filesystem error', 'flag'), $wp_filesystem->errors);
|
1090 |
+
} else{
|
1091 |
if($module && is_dir($to_folder . $module)){
|
1092 |
$gmCore->delete_folder($to_folder . $module);
|
1093 |
}
|
1097 |
// Once extracted, delete the package
|
1098 |
unlink($mzip);
|
1099 |
|
1100 |
+
if(is_wp_error($result)){
|
1101 |
echo $gmCore->alert('danger', $result->get_error_message());
|
1102 |
die();
|
1103 |
+
} else{
|
1104 |
echo $gmCore->alert('success', sprintf(__("The `%s` module successfuly installed", 'flag'), $module));
|
1105 |
}
|
1106 |
+
} else{
|
1107 |
echo $gmCore->alert('danger', __('No file specified', 'grand-media'));
|
1108 |
}
|
1109 |
|
1113 |
|
1114 |
|
1115 |
add_action('wp_ajax_gmedia_import_wpmedia_modal', 'gmedia_import_wpmedia_modal');
|
1116 |
+
function gmedia_import_wpmedia_modal(){
|
1117 |
global $user_ID, $gmDB, $gmCore;
|
1118 |
|
1119 |
check_ajax_referer('GmediaGallery');
|
1120 |
+
if(!current_user_can('gmedia_import')){
|
1121 |
die('-1');
|
1122 |
}
|
1123 |
?>
|
1132 |
<input type="hidden" name="action" value="gmedia_import_handler"/>
|
1133 |
<input type="hidden" id="import-action" name="import" value="import-wpmedia"/>
|
1134 |
<input type="hidden" name="selected" value="<?php $ckey = "gmuser_{$user_ID}_wpmedia";
|
1135 |
+
if(isset($_COOKIE[ $ckey ])){
|
1136 |
+
echo $_COOKIE[ $ckey ];
|
1137 |
} ?>"/>
|
1138 |
+
<?php if($gmCore->caps['gmedia_terms']){ ?>
|
1139 |
<div class="form-group">
|
1140 |
<?php
|
1141 |
$term_type = 'gmedia_album';
|
1142 |
$gm_terms = $gmDB->get_terms($term_type, array('global' => array(0, $user_ID), 'orderby' => 'global_desc_name'));
|
1143 |
|
1144 |
$terms_album = '';
|
1145 |
+
if(count($gm_terms)){
|
1146 |
+
foreach($gm_terms as $term){
|
1147 |
$terms_album .= '<option value="' . esc_attr($term->term_id) . '">' . esc_html($term->name) . ($term->global? '' : __(' (shared)', 'grand-media')) . ('publish' == $term->status? '' : " [{$term->status}]") . '</option>' . "\n";
|
1148 |
}
|
1149 |
}
|
1157 |
|
1158 |
<div class="form-group">
|
1159 |
<?php
|
1160 |
+
$term_type = 'gmedia_category';
|
1161 |
+
$gm_cat_terms = $gmDB->get_terms($term_type, array('fields' => 'names'));
|
1162 |
?>
|
1163 |
<label><?php _e('Assign Categories', 'grand-media'); ?></label>
|
1164 |
<input id="combobox_gmedia_category" name="terms[gmedia_category]" class="form-control input-sm" value="" placeholder="<?php _e('Uncategorized', 'grand-media'); ?>"/>
|
1166 |
|
1167 |
<div class="form-group">
|
1168 |
<?php
|
1169 |
+
$term_type = 'gmedia_tag';
|
1170 |
+
$gm_tag_terms = $gmDB->get_terms($term_type, array('fields' => 'names'));
|
1171 |
?>
|
1172 |
<label><?php _e('Add Tags', 'grand-media'); ?> </label>
|
1173 |
<input id="combobox_gmedia_tag" name="terms[gmedia_tag]" class="form-control input-sm" value="" placeholder="<?php _e('Add Tags...', 'grand-media'); ?>"/>
|
1247 |
<?php } ?>
|
1248 |
<div class="checkbox">
|
1249 |
<label><input type="checkbox" name="skip_exists" value="skip"> <?php _e('Skip if file with the same name already exists in Gmedia Library', 'grand-media'); ?></label>
|
1250 |
+
<div class="help-block"><?php _e('Note: duplicates will be skipped in any way (checked by file hash)') ?></div>
|
1251 |
</div>
|
1252 |
<script type="text/javascript">
|
1253 |
jQuery(function($) {
|
1278 |
* Do Actions via Ajax
|
1279 |
* TODO add related images to post
|
1280 |
* TODO check author for related images
|
|
|
1281 |
* @return void
|
1282 |
*/
|
1283 |
+
function gmedia_relimage(){
|
1284 |
/** @var $wpdb wpdb */
|
1285 |
global $wpdb, $gmCore, $gmDB;
|
1286 |
|
1287 |
check_ajax_referer("grandMedia");
|
1288 |
|
1289 |
// check for correct capability
|
1290 |
+
if(!current_user_can('gmedia_library')){
|
1291 |
die('-1');
|
1292 |
}
|
1293 |
|
1295 |
$paged = (int)$gmCore->_get('paged', 1);
|
1296 |
$per_page = 20;
|
1297 |
$s = trim(stripslashes(urldecode($gmCore->_get('search'))));
|
1298 |
+
if($s && strlen($s) > 2){
|
1299 |
$post_tags = array();
|
1300 |
+
} else{
|
1301 |
$s = '';
|
1302 |
}
|
1303 |
|
1306 |
$continue = true;
|
1307 |
$content = '';
|
1308 |
|
1309 |
+
if($relative == 1){
|
1310 |
+
$arg = array('mime_type' => 'image/*',
|
1311 |
+
'orderby' => 'ID',
|
1312 |
+
'order' => 'DESC',
|
1313 |
+
'per_page' => $per_page,
|
1314 |
+
'page' => $paged,
|
1315 |
+
's' => $s,
|
1316 |
+
'tag_name__in' => $post_tags,
|
1317 |
+
'null_tags' => true
|
|
|
1318 |
);
|
1319 |
$gmediaLib = $gmDB->get_gmedias($arg);
|
1320 |
}
|
1321 |
|
1322 |
+
if(empty($gmediaLib) && count($post_tags)){
|
1323 |
|
1324 |
+
if($relative == 1){
|
1325 |
$relative = 0;
|
1326 |
$paged = 1;
|
1327 |
$content .= '<li class="emptydb">' . __('No items related by tags.', 'grand-media') . '</li>' . "\n";
|
1335 |
AND name IN ({$tag__not_in})
|
1336 |
");
|
1337 |
|
1338 |
+
$arg = array('mime_type' => 'image/*',
|
1339 |
+
'orderby' => 'ID',
|
1340 |
+
'order' => 'DESC',
|
1341 |
+
'per_page' => $per_page,
|
1342 |
+
'page' => $paged,
|
1343 |
+
'tag__not_in' => $tag__not_in
|
|
|
1344 |
);
|
1345 |
$gmediaLib = $gmDB->get_gmedias($arg);
|
1346 |
}
|
1347 |
|
1348 |
+
if(($count = count($gmediaLib))){
|
1349 |
+
foreach($gmediaLib as $item){
|
1350 |
$content .= "<li class='gmedia-image-li' id='gm-img-{$item->ID}'>\n";
|
1351 |
$content .= " <a target='_blank' class='gm-img' data-gmid='{$item->ID}' href='" . $gmCore->gm_get_media_image($item) . "'><img src='" . $gmCore->gm_get_media_image($item, 'thumb') . "' height='50' style='width:auto;' alt='' title='" . esc_attr($item->title) . "' /></a>\n";
|
1352 |
$content .= " <div style='display: none;' class='gm-img-description'>" . esc_html($item->description) . "</div>\n";
|
1353 |
$content .= "</li>\n";
|
1354 |
}
|
1355 |
+
if(($count < $per_page) && ($relative == 0 || !empty($s))){
|
1356 |
$continue = false;
|
1357 |
}
|
1358 |
+
} else{
|
1359 |
+
if($s){
|
1360 |
$content .= '<li class="emptydb">' . __('No items matching the search query.', 'grand-media') . '</li>' . "\n";
|
1361 |
+
} else{
|
1362 |
$content .= '<li class="emptydb">' . __('No items to show', 'grand-media') . '</li>' . "\n";
|
1363 |
}
|
1364 |
$continue = false;
|
1376 |
* jQuery File Tree PHP Connector
|
1377 |
* @author Cory S.N. LaViska - A Beautiful Site (http://abeautifulsite.net/)
|
1378 |
* @version 1.0.1
|
|
|
1379 |
* @return string folder content
|
1380 |
*/
|
1381 |
+
function gmedia_ftp_browser(){
|
1382 |
+
if(!current_user_can('gmedia_import')){
|
1383 |
die('No access');
|
1384 |
}
|
1385 |
|
1391 |
// get the current directory
|
1392 |
$dir = trailingslashit(urldecode($_POST['dir']));
|
1393 |
|
1394 |
+
if((false === strpos($dir, '..')) && file_exists($root . $dir)){
|
1395 |
$files = scandir($root . $dir);
|
1396 |
natcasesort($files);
|
1397 |
|
1398 |
// The 2 counts for . and ..
|
1399 |
+
if(count($files) > 2){
|
1400 |
echo "<ul class=\"jqueryDirTree\" style=\"display: none;\">";
|
1401 |
// return only directories
|
1402 |
+
foreach($files as $file){
|
1403 |
+
if(in_array($file, array('wp-admin', 'wp-includes', 'plugins', 'themes', 'thumb', 'thumbs'))){
|
1404 |
continue;
|
1405 |
}
|
1406 |
|
1407 |
+
if(file_exists($root . $dir . $file) && $file != '.' && $file != '..' && is_dir($root . $dir . $file)){
|
1408 |
echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . esc_attr($dir . $file) . "/\">" . esc_html($file) . "</a></li>";
|
1409 |
}
|
1410 |
}
|
1416 |
}
|
1417 |
|
1418 |
add_action('wp_ajax_gmedia_set_post_thumbnail', 'gmedia_set_post_thumbnail');
|
1419 |
+
function gmedia_set_post_thumbnail(){
|
1420 |
global $gmCore, $gmDB, $gmGallery;
|
1421 |
|
1422 |
$post_ID = intval($gmCore->_post('post_id', 0));
|
1423 |
|
1424 |
+
if(!$post_ID || !current_user_can('edit_post', $post_ID)){
|
1425 |
die('-1');
|
1426 |
}
|
1427 |
|
1438 |
}
|
1439 |
*/
|
1440 |
|
1441 |
+
if($img_id){
|
1442 |
|
1443 |
$image = $gmDB->get_gmedia($img_id);
|
1444 |
+
if($image){
|
1445 |
|
1446 |
+
$args = array('post_type' => 'attachment',
|
1447 |
+
'meta_key' => '_gmedia_image_id',
|
1448 |
+
'meta_compare' => '==',
|
1449 |
+
'meta_value' => $img_id
|
|
|
1450 |
);
|
1451 |
$posts = get_posts($args);
|
1452 |
$attachment_id = null;
|
1453 |
|
1454 |
+
if($posts != null){
|
1455 |
$attachment_id = $posts[0]->ID;
|
1456 |
//$target_path = get_attached_file( $attachment_id );
|
1457 |
+
} else{
|
1458 |
$upload_dir = wp_upload_dir();
|
1459 |
$basedir = $upload_dir['basedir'];
|
1460 |
$thumbs_dir = implode(DIRECTORY_SEPARATOR, array($basedir, 'gmedia_featured'));
|
1461 |
|
1462 |
$type = explode('/', $image->mime_type);
|
1463 |
|
1464 |
+
$url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][ $type[0] ] . '/' . $image->gmuid;
|
1465 |
+
$image_abspath = $gmCore->upload['path'] . '/' . $gmGallery->options['folder'][ $type[0] ] . '/' . $image->gmuid;
|
1466 |
|
1467 |
$img_name = current_time('ymd_Hi') . '_' . basename($image->gmuid);
|
1468 |
$target_path = path_join($thumbs_dir, $img_name);
|
1469 |
wp_mkdir_p($thumbs_dir);
|
1470 |
|
1471 |
+
if(@copy($image_abspath, $target_path)){
|
1472 |
$title = sanitize_title($image->title);
|
1473 |
$caption = $gmCore->sanitize($image->description);
|
1474 |
|
1475 |
+
$attachment = array('post_title' => $title,
|
1476 |
+
'post_content' => $caption,
|
1477 |
+
'post_status' => 'attachment',
|
1478 |
+
'post_parent' => 0,
|
1479 |
+
'post_mime_type' => $image->mime_type,
|
1480 |
+
'guid' => $url
|
|
|
1481 |
);
|
1482 |
|
1483 |
//require for wp_generate_attachment_metadata which generates image related meta-data also creates thumbs
|
1489 |
}
|
1490 |
}
|
1491 |
|
1492 |
+
if($attachment_id){
|
1493 |
delete_post_meta($post_ID, '_thumbnail_id');
|
1494 |
add_post_meta($post_ID, '_thumbnail_id', $attachment_id, true);
|
1495 |
|
1503 |
}
|
1504 |
|
1505 |
add_action('wp_ajax_gmedia_upload_handler', 'gmedia_upload_handler');
|
1506 |
+
function gmedia_upload_handler(){
|
1507 |
global $gmCore;
|
1508 |
|
1509 |
ini_set('max_execution_time', 300);
|
1510 |
|
1511 |
// HTTP headers for no cache etc
|
1512 |
+
send_nosniff_header();
|
1513 |
+
//send_origin_headers();
|
1514 |
nocache_headers();
|
1515 |
|
1516 |
// if nonce is not correct it returns -1
|
1517 |
check_ajax_referer('GmediaUpload');
|
1518 |
+
if(!current_user_can('gmedia_upload')){
|
1519 |
wp_die(__('You do not have permission to upload files in Gmedia Library.'));
|
1520 |
}
|
1521 |
|
1528 |
$filename = $gmCore->_req('name');
|
1529 |
|
1530 |
// Get parameters
|
1531 |
+
if(!$filename){
|
1532 |
$return = json_encode(array("error" => array("code" => 100, "message" => __("No file name.", 'grand-media'))));
|
1533 |
die($return);
|
1534 |
}
|
1535 |
|
1536 |
$fileinfo = $gmCore->fileinfo($filename);
|
1537 |
+
if(false === $fileinfo){
|
1538 |
$return = json_encode(array("error" => array("code" => 100, "message" => __("File type not allowed.", 'grand-media')), "id" => $filename));
|
1539 |
die($return);
|
1540 |
}
|
1541 |
|
1542 |
// Look for the content type header
|
1543 |
$contentType = '';
|
1544 |
+
if(isset($_SERVER["HTTP_CONTENT_TYPE"])){
|
1545 |
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
|
1546 |
}
|
1547 |
|
1548 |
+
if(isset($_SERVER["CONTENT_TYPE"])){
|
1549 |
$contentType = $_SERVER["CONTENT_TYPE"];
|
1550 |
}
|
1551 |
|
1552 |
// Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
|
1553 |
$file_tmp = '';
|
1554 |
+
if(strpos($contentType, "multipart") !== false){
|
1555 |
+
if(isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])){
|
1556 |
$file_tmp = $_FILES['file']['tmp_name'];
|
1557 |
}
|
1558 |
+
} else{
|
1559 |
$file_tmp = "php://input";
|
1560 |
}
|
1561 |
|
1562 |
+
if(empty($file_tmp)){
|
1563 |
$return = json_encode(array("error" => array("code" => 103, "message" => __("Failed to move uploaded file.", 'grand-media')), "id" => $filename));
|
1564 |
die($return);
|
1565 |
}
|
1566 |
|
1567 |
$post_data = array();
|
1568 |
+
if(($params = $gmCore->_req('params', ''))){
|
1569 |
parse_str($params, $post_data);
|
1570 |
}
|
1571 |
|
1576 |
}
|
1577 |
|
1578 |
add_action('wp_ajax_gmedia_import_handler', 'gmedia_import_handler');
|
1579 |
+
function gmedia_import_handler(){
|
1580 |
global $wpdb, $gmCore, $gmDB;
|
1581 |
|
1582 |
ini_set('max_execution_time', 600);
|
1583 |
|
1584 |
// HTTP headers for no cache etc
|
1585 |
+
send_nosniff_header();
|
1586 |
+
//send_origin_headers();
|
1587 |
nocache_headers();
|
1588 |
|
1589 |
check_admin_referer('GmediaImport');
|
1590 |
+
if(!current_user_can('gmedia_import')){
|
1591 |
wp_die(__('You do not have permission to upload files.'));
|
1592 |
}
|
1593 |
|
1600 |
$import = $gmCore->_post('import');
|
1601 |
$terms = $gmCore->_post('terms', array());
|
1602 |
|
1603 |
+
if(ob_get_level() == 0){
|
1604 |
ob_start();
|
1605 |
}
|
1606 |
echo str_pad(' ', 4096) . PHP_EOL;
|
1617 |
</style>
|
1618 |
<body>
|
1619 |
<?php
|
1620 |
+
if(('import-folder' == $import) || isset($_POST['import-folder'])){
|
1621 |
|
1622 |
$path = $gmCore->_post('path');
|
1623 |
echo '<h4 style="margin: 0 0 10px">' . __('Import Server Folder') . " `$path`:</h4>" . PHP_EOL;
|
1624 |
|
1625 |
+
if($path){
|
1626 |
$path = trim(urldecode($path), '/');
|
1627 |
+
if(!empty($path)){
|
1628 |
$fullpath = ABSPATH . trailingslashit($path);
|
1629 |
$files = glob($fullpath . '?*.?*', GLOB_NOSORT);
|
1630 |
+
if(!empty($files)){
|
1631 |
$allowed_ext = get_allowed_mime_types();
|
1632 |
$allowed_ext = array_keys($allowed_ext);
|
1633 |
$allowed_ext = implode('|', $allowed_ext);
|
1634 |
$allowed_ext = explode('|', $allowed_ext);
|
1635 |
+
if((GMEDIA_UPLOAD_FOLDER == basename(dirname(dirname($path)))) || (GMEDIA_UPLOAD_FOLDER == basename(dirname($path)))){
|
1636 |
global $wpdb;
|
1637 |
$gmedias = $wpdb->get_col("SELECT gmuid FROM {$wpdb->prefix}gmedia");
|
1638 |
+
foreach($files as $i => $filepath){
|
1639 |
$gmuid = basename($filepath);
|
1640 |
+
if(in_array($gmuid, $gmedias)){
|
1641 |
$fileinfo = $gmCore->fileinfo($gmuid, false);
|
1642 |
+
if(!(('image' == $fileinfo['dirname']) && !file_exists($fileinfo['filepath']))){
|
1643 |
+
unset($files[ $i ]);
|
1644 |
}
|
1645 |
}
|
1646 |
}
|
1647 |
$move = false;
|
1648 |
$exists = false;
|
1649 |
+
} else{
|
1650 |
$move = $gmCore->_post('delete_source');
|
1651 |
+
$exists = $gmCore->_post('skip_exists', 0);
|
1652 |
}
|
1653 |
+
foreach($files as $i => $filepath){
|
1654 |
$ext = pathinfo($filepath, PATHINFO_EXTENSION);
|
1655 |
+
if(!in_array(strtolower($ext), $allowed_ext)){
|
1656 |
+
unset($files[ $i ]);
|
1657 |
}
|
1658 |
}
|
1659 |
$gmCore->gmedia_import_files($files, $terms, $move, $exists);
|
1660 |
+
} else{
|
1661 |
echo sprintf(__('Folder `%s` is empty', 'grand-media'), $path) . PHP_EOL;
|
1662 |
}
|
1663 |
+
} else{
|
1664 |
echo __('No folder chosen', 'grand-media') . PHP_EOL;
|
1665 |
}
|
1666 |
}
|
1667 |
+
} elseif(('import-flagallery' == $import) || isset($_POST['import-flagallery'])){
|
1668 |
|
1669 |
echo '<h4 style="margin: 0 0 10px">' . __('Import from Flagallery plugin') . ":</h4>" . PHP_EOL;
|
1670 |
|
1671 |
$gallery = $gmCore->_post('gallery');
|
1672 |
+
if(!empty($gallery)){
|
1673 |
$album = (!isset($terms['gmedia_album']) || empty($terms['gmedia_album']))? false : true;
|
1674 |
+
foreach($gallery as $gid){
|
1675 |
$flag_gallery = $wpdb->get_row($wpdb->prepare("SELECT gid, path, title, galdesc FROM {$wpdb->prefix}flag_gallery WHERE gid = %d", $gid), ARRAY_A);
|
1676 |
+
if(empty($flag_gallery)){
|
1677 |
continue;
|
1678 |
}
|
1679 |
|
1680 |
+
if(!$album){
|
1681 |
$terms['gmedia_album'] = $flag_gallery['title'];
|
1682 |
+
if($gmCore->is_digit($terms['gmedia_album'])){
|
1683 |
$terms['gmedia_album'] = 'a' . $terms['gmedia_album'];
|
1684 |
}
|
1685 |
+
if(!$gmDB->term_exists($terms['gmedia_album'], 'gmedia_album')){
|
1686 |
$term_id = $gmDB->insert_term($terms['gmedia_album'], 'gmedia_album', array('description' => htmlspecialchars_decode(stripslashes($flag_gallery['galdesc']))));
|
1687 |
}
|
1688 |
}
|
1692 |
echo '<h5 style="margin: 10px 0 5px">' . sprintf(__('Import `%s` gallery', 'grand-media'), $flag_gallery['title']) . ":</h5>" . PHP_EOL;
|
1693 |
|
1694 |
$flag_pictures = $wpdb->get_results($wpdb->prepare("SELECT CONCAT('%s', filename) AS file, description, alttext AS title, link FROM {$wpdb->prefix}flag_pictures WHERE galleryid = %d", $path, $flag_gallery['gid']), ARRAY_A);
|
1695 |
+
if(empty($flag_pictures)){
|
1696 |
echo '<pre>' . __('gallery contains 0 images', 'grand-media') . '</pre>';
|
1697 |
continue;
|
1698 |
}
|
1699 |
+
$exists = $gmCore->_post('skip_exists', 0);
|
1700 |
+
|
1701 |
//echo '<pre>'.print_r($flag_pictures, true).'</pre>';
|
1702 |
+
$gmCore->gmedia_import_files($flag_pictures, $terms, false, $exists);
|
1703 |
}
|
1704 |
+
} else{
|
1705 |
echo __('No gallery chosen', 'grand-media') . PHP_EOL;
|
1706 |
}
|
1707 |
+
} elseif(('import-nextgen' == $import) || isset($_POST['import-nextgen'])){
|
1708 |
|
1709 |
echo '<h4 style="margin: 0 0 10px">' . __('Import from NextGen plugin') . ":</h4>" . PHP_EOL;
|
1710 |
|
1711 |
$gallery = $gmCore->_post('gallery');
|
1712 |
+
if(!empty($gallery)){
|
1713 |
$album = (!isset($terms['gmedia_album']) || empty($terms['gmedia_album']))? false : true;
|
1714 |
+
foreach($gallery as $gid){
|
1715 |
$ngg_gallery = $wpdb->get_row($wpdb->prepare("SELECT gid, path, title, galdesc FROM {$wpdb->prefix}ngg_gallery WHERE gid = %d", $gid), ARRAY_A);
|
1716 |
+
if(empty($ngg_gallery)){
|
1717 |
continue;
|
1718 |
}
|
1719 |
|
1720 |
+
if(!$album){
|
1721 |
$terms['gmedia_album'] = $ngg_gallery['title'];
|
1722 |
+
if($gmCore->is_digit($terms['gmedia_album'])){
|
1723 |
$terms['gmedia_album'] = 'a' . $ngg_gallery['title'];
|
1724 |
}
|
1725 |
+
if(!$gmDB->term_exists($terms['gmedia_album'], 'gmedia_album')){
|
1726 |
$term_id = $gmDB->insert_term($terms['gmedia_album'], 'gmedia_album', array('description' => htmlspecialchars_decode(stripslashes($ngg_gallery['galdesc']))));
|
1727 |
}
|
1728 |
}
|
1732 |
echo '<h5 style="margin: 10px 0 5px">' . sprintf(__('Import `%s` gallery', 'grand-media'), $ngg_gallery['title']) . ":</h5>" . PHP_EOL;
|
1733 |
|
1734 |
$ngg_pictures = $wpdb->get_results($wpdb->prepare("SELECT CONCAT('%s', filename) AS file, description, alttext AS title FROM {$wpdb->prefix}ngg_pictures WHERE galleryid = %d", $path, $ngg_gallery['gid']), ARRAY_A);
|
1735 |
+
if(empty($ngg_pictures)){
|
1736 |
echo '<pre>' . __('gallery contains 0 images', 'grand-media') . '</pre>';
|
1737 |
continue;
|
1738 |
}
|
1739 |
+
$exists = $gmCore->_post('skip_exists', 0);
|
1740 |
+
|
1741 |
+
$gmCore->gmedia_import_files($ngg_pictures, $terms, false, $exists);
|
1742 |
}
|
1743 |
+
} else{
|
1744 |
echo __('No gallery chosen', 'grand-media') . PHP_EOL;
|
1745 |
}
|
1746 |
+
} elseif(('import-wpmedia' == $import) || isset($_POST['import-wpmedia'])){
|
1747 |
|
1748 |
echo '<h4 style="margin: 0 0 10px">' . __('Import from WP Media Library') . ":</h4>" . PHP_EOL;
|
1749 |
|
1750 |
$wpMediaLib = $gmDB->get_wp_media_lib(array('filter' => 'selected', 'selected' => $gmCore->_post('selected')));
|
1751 |
|
1752 |
+
if(!empty($wpMediaLib)){
|
1753 |
|
1754 |
$wp_media = array();
|
1755 |
+
foreach($wpMediaLib as $item){
|
1756 |
+
$wp_media[] = array('file' => get_attached_file($item->ID),
|
1757 |
+
'title' => $item->post_title,
|
1758 |
+
'description' => $item->post_content
|
|
|
1759 |
);
|
1760 |
}
|
1761 |
$exists = $gmCore->_post('skip_exists', 0);
|
1762 |
//echo '<pre>' . print_r($wp_media, true) . '</pre>';
|
1763 |
$gmCore->gmedia_import_files($wp_media, $terms, false, $exists);
|
1764 |
|
1765 |
+
} else{
|
1766 |
echo __('No items chosen', 'grand-media') . PHP_EOL;
|
1767 |
}
|
1768 |
}
|
1776 |
}
|
1777 |
|
1778 |
add_action('wp_ajax_gmedia_application', 'gmedia_application');
|
1779 |
+
function gmedia_application(){
|
1780 |
global $gmCore, $gmGallery;
|
1781 |
|
1782 |
// if nonce is not correct it returns -1
|
1783 |
check_ajax_referer('GmediaService');
|
1784 |
+
if(!current_user_can('manage_options')){
|
1785 |
die('-1');
|
1786 |
}
|
1787 |
|
1788 |
$service = $gmCore->_post('service');
|
1789 |
+
if(!$service){
|
1790 |
die('0');
|
1791 |
}
|
1792 |
$_data = $gmCore->_post('data');
|
1796 |
$options['site_email'] = $data['site_email'];
|
1797 |
$options['site_title'] = $data['site_title'];
|
1798 |
$options['site_description'] = $data['site_description'];
|
1799 |
+
if($options != $gmGallery->options){
|
1800 |
$gmGallery->options = $options;
|
1801 |
update_option('gmediaOptions', $options);
|
1802 |
}
|
1810 |
}
|
1811 |
|
1812 |
add_action('wp_ajax_gmedia_share_page', 'gmedia_share_page');
|
1813 |
+
function gmedia_share_page(){
|
1814 |
global $gmCore, $user_ID;
|
1815 |
// if nonce is not correct it returns -1
|
1816 |
check_ajax_referer('share_modal', '_sharenonce');
|
1818 |
$sharelink = $gmCore->_post('sharelink', '');
|
1819 |
$email = $gmCore->_post('email', '');
|
1820 |
$sharemessage = $gmCore->_post('message', '');
|
1821 |
+
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
|
1822 |
echo $gmCore->alert('danger', __('Invalid email', 'grand-media') . ': ' . esc_html($email));
|
1823 |
die();
|
1824 |
}
|
1827 |
$subject = sprintf(__('%s shared GmediaCloud Page with you', 'grand-media'), $display_name);
|
1828 |
$sharetitle = sprintf(__('%s used Gmedia to share something interesting with you!', 'grand-media'), $display_name);
|
1829 |
$sharelinktext = __('Click here to view page', 'grand-media');
|
1830 |
+
if($sharemessage){
|
1831 |
$sharemessage = '<blockquote>"' . nl2br(esc_html($sharemessage)) . '"</blockquote>';
|
1832 |
}
|
1833 |
$footer = '© ' . date('Y') . ' GmediaGallery';
|
1871 |
EOT;
|
1872 |
|
1873 |
$headers = array('Content-Type: text/html; charset=UTF-8');
|
1874 |
+
if(wp_mail($email, $subject, $message, $headers)){
|
1875 |
echo $gmCore->alert('success', sprintf(__('Message sent to %s', 'grand-media'), $email));
|
1876 |
}
|
1877 |
|
1879 |
}
|
1880 |
|
1881 |
add_action('wp_ajax_gmedia_add_custom_field', 'gmedia_add_custom_field');
|
1882 |
+
function gmedia_add_custom_field(){
|
1883 |
global $gmDB, $user_ID, $gmCore;
|
1884 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
1885 |
|
1890 |
|
1891 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
1892 |
|
1893 |
+
if(!current_user_can('gmedia_edit_media') || ($user_ID != $post->author && !current_user_can('gmedia_edit_others_media'))){
|
1894 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
1895 |
die();
|
1896 |
}
|
1897 |
+
if(isset($_POST['metakeyselect']) && empty($_POST['metakeyselect']) && empty($_POST['metakeyinput'])){
|
1898 |
echo json_encode(array('error' => array('code' => 101, 'message' => __('Choose or provide a custom field name', 'grand-media')), 'id' => $pid));
|
1899 |
die();
|
1900 |
}
|
1901 |
|
1902 |
+
if(!$mid = $gmCore->add_meta($pid, $meta_type)){
|
1903 |
echo json_encode(array('error' => array('code' => 102, 'message' => __('Please provide a custom field value', 'grand-media')), 'id' => $pid));
|
1904 |
die();
|
1905 |
}
|
1908 |
$meta = $gmDB->get_metadata_by_mid($meta_type, $mid);
|
1909 |
$pid = (int)$meta->{$column};
|
1910 |
$meta = get_object_vars($meta);
|
1911 |
+
$result = array('success' => array('meta_id' => $mid,
|
1912 |
+
'data' => $gmCore->_list_meta_item($meta)
|
1913 |
+
),
|
1914 |
+
'id' => $pid
|
|
|
|
|
1915 |
);
|
1916 |
|
1917 |
+
if(!empty($_POST['metakeyinput'])){
|
1918 |
$result['newmeta_form'] = $gmCore->meta_form($meta_type);
|
1919 |
}
|
1920 |
|
1924 |
}
|
1925 |
|
1926 |
add_action('wp_ajax_gmedia_delete_custom_field', 'gmedia_delete_custom_field');
|
1927 |
+
function gmedia_delete_custom_field(){
|
1928 |
+
global $gmDB, $user_ID, $gmCore;
|
1929 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
1930 |
|
1931 |
$meta_type = 'gmedia';
|
1933 |
$pid = (int)$_POST['ID'];
|
1934 |
$post = $gmDB->get_gmedia($pid);
|
1935 |
|
1936 |
+
if(!current_user_can('gmedia_edit_media') || ($user_ID != $post->author && !current_user_can('gmedia_edit_others_media'))){
|
1937 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
1938 |
die();
|
1939 |
}
|
1942 |
|
1943 |
$deletemeta = $_POST['meta'];
|
1944 |
$column = sanitize_key($meta_type . '_id');
|
1945 |
+
if(isset($deletemeta) && is_array($deletemeta)){
|
1946 |
+
foreach($deletemeta as $key => $value){
|
1947 |
+
if(!$meta = $gmDB->get_metadata_by_mid($meta_type, $key)){
|
1948 |
continue;
|
1949 |
}
|
1950 |
+
if($meta->{$column} != $pid){
|
1951 |
continue;
|
1952 |
}
|
1953 |
+
if($gmCore->is_protected_meta($meta->meta_key, $meta_type)){
|
1954 |
continue;
|
1955 |
}
|
1956 |
+
if(($del_meta = $gmDB->delete_metadata_by_mid($meta_type, $key))){
|
1957 |
$result['deleted'][] = $key;
|
1958 |
}
|
1959 |
}
|
1966 |
}
|
1967 |
|
1968 |
add_action('wp_ajax_gmedia_term_add_custom_field', 'gmedia_term_add_custom_field');
|
1969 |
+
function gmedia_term_add_custom_field(){
|
1970 |
global $gmDB, $user_ID, $gmCore;
|
1971 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
1972 |
|
1973 |
$meta_type = 'gmedia_term';
|
1974 |
|
1975 |
+
$pid = (int)$_POST['ID'];
|
1976 |
+
$post = $gmDB->get_term($pid);
|
1977 |
|
1978 |
$taxonomy = $post->taxonomy;
|
1979 |
|
1980 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
1981 |
|
1982 |
+
if(!current_user_can($taxonomy . '_manage') || ($user_ID != $post->global && !current_user_can('gmedia_edit_others_media'))){
|
1983 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
1984 |
die();
|
1985 |
}
|
1986 |
+
if(isset($_POST['metakeyselect']) && empty($_POST['metakeyselect']) && empty($_POST['metakeyinput'])){
|
1987 |
echo json_encode(array('error' => array('code' => 101, 'message' => __('Choose or provide a custom field name', 'grand-media')), 'id' => $pid));
|
1988 |
die();
|
1989 |
}
|
1990 |
|
1991 |
+
if(!$mid = $gmCore->add_meta($pid, $meta_type)){
|
1992 |
echo json_encode(array('error' => array('code' => 102, 'message' => __('Please provide a custom field value', 'grand-media')), 'id' => $pid));
|
1993 |
die();
|
1994 |
}
|
1997 |
$meta = $gmDB->get_metadata_by_mid($meta_type, $mid);
|
1998 |
$pid = (int)$meta->{$column};
|
1999 |
$meta = get_object_vars($meta);
|
2000 |
+
$result = array('success' => array('meta_id' => $mid,
|
2001 |
+
'data' => $gmCore->_list_meta_item($meta)
|
2002 |
+
),
|
2003 |
+
'id' => $pid
|
|
|
|
|
2004 |
);
|
2005 |
|
2006 |
+
if(!empty($_POST['metakeyinput'])){
|
2007 |
$result['newmeta_form'] = $gmCore->meta_form($meta_type);
|
2008 |
}
|
2009 |
|
2013 |
}
|
2014 |
|
2015 |
add_action('wp_ajax_gmedia_term_delete_custom_field', 'gmedia_term_delete_custom_field');
|
2016 |
+
function gmedia_term_delete_custom_field(){
|
2017 |
+
global $gmDB, $user_ID, $gmCore;
|
2018 |
check_ajax_referer('gmedia_custom_field', '_customfield_nonce');
|
2019 |
|
2020 |
$meta_type = 'gmedia_term';
|
2021 |
|
2022 |
+
$pid = (int)$_POST['ID'];
|
2023 |
+
$post = $gmDB->get_term($pid);
|
2024 |
|
2025 |
$taxonomy = $post->taxonomy;
|
2026 |
|
2027 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
2028 |
|
2029 |
+
if(!current_user_can($taxonomy . '_manage') || ($user_ID != $post->global && !current_user_can('gmedia_edit_others_media'))){
|
2030 |
echo json_encode(array('error' => array('code' => 100, 'message' => __('You are not allowed to edit others media', 'grand-media')), 'id' => $pid));
|
2031 |
die();
|
2032 |
}
|
2035 |
|
2036 |
$deletemeta = $_POST['meta'];
|
2037 |
$column = sanitize_key($meta_type . '_id');
|
2038 |
+
if(isset($deletemeta) && is_array($deletemeta)){
|
2039 |
+
foreach($deletemeta as $key => $value){
|
2040 |
+
if(!$meta = $gmDB->get_metadata_by_mid($meta_type, $key)){
|
2041 |
continue;
|
2042 |
}
|
2043 |
+
if($meta->{$column} != $pid){
|
2044 |
continue;
|
2045 |
}
|
2046 |
+
if($gmCore->is_protected_meta($meta->meta_key, $meta_type)){
|
2047 |
continue;
|
2048 |
}
|
2049 |
+
if(($del_meta = $gmDB->delete_metadata_by_mid($meta_type, $key))){
|
2050 |
$result['deleted'][] = $key;
|
2051 |
}
|
2052 |
}
|
2058 |
}
|
2059 |
|
2060 |
add_action('wp_ajax_gmedia_upgrade_process', 'gmedia_upgrade_process');
|
2061 |
+
function gmedia_upgrade_process(){
|
2062 |
|
2063 |
$db_version = get_option('gmediaDbVersion');
|
2064 |
+
$info = get_transient('gmediaHeavyJob');
|
2065 |
+
$result = array('content' => '');
|
2066 |
|
2067 |
$upgrading = get_transient('gmediaUpgrade');
|
2068 |
if($upgrading){
|
2069 |
$timeout = time() - $upgrading;
|
2070 |
+
} else{
|
2071 |
$timeout = 0;
|
2072 |
}
|
2073 |
if($timeout > 20){
|
2074 |
+
require_once(GMEDIA_ABSPATH . 'config/update.php');
|
2075 |
gmedia_db_update();
|
2076 |
}
|
2077 |
$result['timeout'] = $timeout;
|
2078 |
|
2079 |
+
if(!empty($info)){
|
2080 |
$result['content'] = '<div>' . implode("</div>\n<div>", $info) . '</div>';
|
2081 |
+
} elseif($db_version == GMEDIA_DBVERSION){
|
2082 |
$result['status'] = 'done';
|
2083 |
}
|
2084 |
|
2088 |
|
2089 |
}
|
2090 |
|
2091 |
+
add_action('wp_ajax_gmedia_hash_files', 'gmedia_hash_files');
|
2092 |
+
function gmedia_hash_files(){
|
2093 |
+
global $wpdb, $gmCore, $gmDB;
|
2094 |
+
|
2095 |
+
check_ajax_referer('ajaxLongOperation');
|
2096 |
+
|
2097 |
+
$all_count = wp_cache_get('gmedia_count_all');
|
2098 |
+
if(false === $all_count){
|
2099 |
+
$all_count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}gmedia");
|
2100 |
+
wp_cache_set('gmedia_count_all', $all_count);
|
2101 |
+
}
|
2102 |
+
$sql = "SELECT SQL_CALC_FOUND_ROWS ID, gmuid FROM {$wpdb->prefix}gmedia AS g WHERE 1 = 1
|
2103 |
+
AND ( NOT EXISTS ( SELECT * FROM {$wpdb->prefix}gmedia_meta AS gm WHERE gm.meta_key = '_hash' AND gm.gmedia_id = g.ID )
|
2104 |
+
OR NOT EXISTS ( SELECT * FROM {$wpdb->prefix}gmedia_meta AS gm2 WHERE gm2.meta_key = '_size' AND gm2.gmedia_id = g.ID)
|
2105 |
+
)
|
2106 |
+
LIMIT 20";
|
2107 |
+
$unhashed = $wpdb->get_results($sql);
|
2108 |
+
if(!$unhashed){
|
2109 |
+
$ajax_operations = get_option('gmedia_ajax_long_operations', array());
|
2110 |
+
unset($ajax_operations['gmedia_hash_files']);
|
2111 |
+
if(empty($ajax_operations)){
|
2112 |
+
delete_option('gmedia_ajax_long_operations');
|
2113 |
+
} else{
|
2114 |
+
update_option('gmedia_ajax_long_operations', $ajax_operations);
|
2115 |
+
}
|
2116 |
+
wp_cache_delete('gmedia_count_all');
|
2117 |
+
|
2118 |
+
wp_send_json_success(array('progress' => '100%', 'info' => __('Indexing:', 'grand-media'), 'done' => true));
|
2119 |
+
}
|
2120 |
+
|
2121 |
+
$unhashed_count = $wpdb->get_var('SELECT FOUND_ROWS()');
|
2122 |
+
|
2123 |
+
foreach($unhashed as $item){
|
2124 |
+
$fileinfo = $gmCore->fileinfo($item->gmuid, false);
|
2125 |
+
$hash_file = hash_file('md5', $fileinfo['filepath_original']);
|
2126 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $item->ID, $meta_key = '_hash', $hash_file);
|
2127 |
+
$file_size = filesize($fileinfo['filepath_original']);
|
2128 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $item->ID, $meta_key = '_size', $file_size);
|
2129 |
+
}
|
2130 |
+
|
2131 |
+
$progress = round(($all_count - $unhashed_count) * 100 / $all_count);
|
2132 |
+
|
2133 |
+
wp_send_json_success(array('progress' => "{$progress}%", 'info' => __('Indexing:', 'grand-media')));
|
2134 |
+
}
|
2135 |
+
|
2136 |
+
add_action('wp_ajax_gmedia_recreate_images', 'gmedia_recreate_images');
|
2137 |
+
function gmedia_recreate_images(){
|
2138 |
+
global $gmCore;
|
2139 |
+
|
2140 |
+
check_ajax_referer('ajaxLongOperation');
|
2141 |
+
|
2142 |
+
$gmid = 0;
|
2143 |
+
$ajax_operations = get_option('gmedia_ajax_long_operations', array());
|
2144 |
+
if(!empty($ajax_operations['gmedia_recreate_images'])){
|
2145 |
+
$all_count = count($ajax_operations['gmedia_recreate_images']);
|
2146 |
+
$recreate_ids = array_filter($ajax_operations['gmedia_recreate_images']);
|
2147 |
+
$do_count = count($recreate_ids);
|
2148 |
+
|
2149 |
+
if(!empty($recreate_ids)){
|
2150 |
+
$gmid = reset($recreate_ids);
|
2151 |
+
$gmCore->recreate_images_from_original($gmid);
|
2152 |
+
|
2153 |
+
$ajax_operations['gmedia_recreate_images'][$gmid] = false;
|
2154 |
+
update_option('gmedia_ajax_long_operations', $ajax_operations);
|
2155 |
+
} else {
|
2156 |
+
unset($ajax_operations['gmedia_recreate_images']);
|
2157 |
+
}
|
2158 |
+
|
2159 |
+
if(empty($ajax_operations)){
|
2160 |
+
delete_option('gmedia_ajax_long_operations');
|
2161 |
+
|
2162 |
+
wp_send_json_success(array('progress' => '100%', 'info' => __('Done:', 'grand-media'), 'done' => true, 'id' => $gmid));
|
2163 |
+
} else {
|
2164 |
+
$progress = round(($all_count - $do_count) * 100 / $all_count);
|
2165 |
+
|
2166 |
+
wp_send_json_success(array('progress' => "{$progress}%", 'info' => __('Working:', 'grand-media'), 'id' => $gmid));
|
2167 |
+
}
|
2168 |
+
}
|
2169 |
+
|
2170 |
+
wp_send_json_success(array('progress' => '100%', 'info' => __('Done:', 'grand-media'), 'done' => true, 'id' => $gmid));
|
2171 |
+
}
|
2172 |
+
|
2173 |
+
add_action('wp_ajax_gmedia_save_waveform', 'gmedia_save_waveform');
|
2174 |
+
add_action('wp_ajax_nopriv_gmedia_save_waveform', 'gmedia_save_waveform');
|
2175 |
+
function gmedia_save_waveform(){
|
2176 |
+
global $gmCore, $gmDB;
|
2177 |
+
|
2178 |
+
check_ajax_referer('GmediaGallery');
|
2179 |
+
|
2180 |
+
$id = $gmCore->_post('id');
|
2181 |
+
$peaks = $gmCore->_post('peaks');
|
2182 |
+
if($id && $peaks){
|
2183 |
+
$peaks_arr = json_decode($peaks);
|
2184 |
+
$peaks_arr = array_filter($peaks_arr, 'is_numeric');
|
2185 |
+
if(3600 !== count($peaks_arr)){
|
2186 |
+
wp_send_json_error(array('peaks_cnt' => count($peaks_arr)));
|
2187 |
+
}
|
2188 |
+
|
2189 |
+
$gmDB->update_metadata('gmedia', $id, '_peaks', $peaks);
|
2190 |
+
wp_send_json_success(array('peaks' => $peaks));
|
2191 |
+
} else{
|
2192 |
+
wp_send_json_error();
|
2193 |
+
}
|
2194 |
+
}
|
2195 |
+
|
2196 |
add_action('wp_ajax_gmedia_module_interaction', 'gmedia_module_interaction');
|
2197 |
add_action('wp_ajax_nopriv_gmedia_module_interaction', 'gmedia_module_interaction');
|
2198 |
+
function gmedia_module_interaction(){
|
2199 |
global $gmDB, $gmCore;
|
2200 |
|
2201 |
+
if(empty($_SERVER['HTTP_REFERER'])){
|
2202 |
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
2203 |
die();
|
2204 |
}
|
2205 |
|
2206 |
$ref = $_SERVER['HTTP_REFERER'];
|
2207 |
//$uip = str_replace('.', '', $_SERVER['REMOTE_ADDR'])
|
2208 |
+
if((false === strpos($ref, get_home_url())) && (false === strpos($ref, get_site_url()))){
|
2209 |
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
2210 |
die();
|
2211 |
}
|
2212 |
+
if(('POST' !== $_SERVER['REQUEST_METHOD']) || !isset($_SERVER['HTTP_HOST']) || !strpos(get_home_url(), $_SERVER['HTTP_HOST'])){
|
2213 |
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
2214 |
die();
|
2215 |
}
|
2216 |
|
2217 |
|
2218 |
+
if(isset($_POST['hit']) && ($gmID = intval($_POST['hit']))){
|
2219 |
+
if(null === $gmDB->get_gmedia($gmID)){
|
2220 |
die('0');
|
2221 |
}
|
2222 |
$meta['views'] = $gmDB->get_metadata('gmedia', $gmID, 'views', true);
|
2230 |
die();
|
2231 |
}
|
2232 |
|
2233 |
+
if(isset($_POST['rate'])){
|
2234 |
/**
|
2235 |
* @var $uip
|
2236 |
* @var $gmid
|
2237 |
* @var $rate
|
2238 |
*/
|
2239 |
extract($_POST['rate'], EXTR_OVERWRITE);
|
2240 |
+
if(!intval($gmid) || (null === $gmDB->get_gmedia($gmid))){
|
2241 |
die('0');
|
2242 |
}
|
2243 |
$rating = $gmDB->get_metadata('gmedia', $gmid, '_rating', true);
|
2244 |
+
$rating = wp_parse_args((array)$rating, array('votes' => 0, 'value' => 0));
|
2245 |
$old_rate = 0;
|
2246 |
|
2247 |
$transient_key = 'gm_rate_day' . date('w');
|
2248 |
$transient_value = get_transient($transient_key);
|
2249 |
+
if(false !== $transient_value){
|
2250 |
+
if(isset($transient_value[ $uip ][ $gmid ])){
|
2251 |
+
$old_rate = $transient_value[ $uip ][ $gmid ];
|
2252 |
}
|
2253 |
+
$transient_value[ $uip ][ $gmid ] = $rate;
|
2254 |
+
} else{
|
2255 |
$transient_value = array($uip => array($gmid => $rate));
|
2256 |
}
|
2257 |
set_transient($transient_key, $transient_value, 18 * HOUR_IN_SECONDS);
|
2258 |
|
2259 |
+
$rating['votes'] = $old_rate? $rating['votes'] : $rating['votes'] + 1;
|
2260 |
+
$rating['value'] = ($rating['value'] * $rating['votes'] + $rate - $old_rate) / $rating['votes'];
|
|
|
2261 |
|
2262 |
$gmDB->update_metadata('gmedia', $gmid, '_rating', $rating);
|
2263 |
|
2271 |
|
2272 |
add_action('wp_ajax_load_comments', 'gmedia_module_load_comments');
|
2273 |
add_action('wp_ajax_nopriv_load_comments', 'gmedia_module_load_comments');
|
2274 |
+
function gmedia_module_load_comments(){
|
2275 |
global $gmCore;
|
2276 |
|
2277 |
/* if(empty($_SERVER['HTTP_REFERER'])) {
|
2295 |
$data = $gmCore->_post('data', false);
|
2296 |
|
2297 |
$post_id = (int)$data['post_id'];
|
2298 |
+
if($post_id){
|
2299 |
$comments_link = apply_filters('gmedia_comments_link', add_query_arg('comments', 'show', get_permalink($post_id)), $post_id);
|
2300 |
$comments_count = wp_count_comments($post_id);
|
2301 |
$comments_count = $comments_count->approved;
|
2302 |
+
} else{
|
2303 |
$comments_link = '//about:blank';
|
2304 |
$comments_count = 0;
|
2305 |
}
|
admin/app.php
CHANGED
@@ -39,6 +39,7 @@ function gmediaApp() {
|
|
39 |
</div>
|
40 |
<button type="button" name="gmedia_application_activate" data-action="app_activate" class="gmapp_activate btn btn-primary<?php echo $btn_state . ($mobile_app? ' hidden' : ''); ?>"><?php _e('Enable GmediaService', 'grand-media'); ?></button>
|
41 |
</div>
|
|
|
42 |
<?php
|
43 |
wp_nonce_field('GmediaService');
|
44 |
?>
|
39 |
</div>
|
40 |
<button type="button" name="gmedia_application_activate" data-action="app_activate" class="gmapp_activate btn btn-primary<?php echo $btn_state . ($mobile_app? ' hidden' : ''); ?>"><?php _e('Enable GmediaService', 'grand-media'); ?></button>
|
41 |
</div>
|
42 |
+
<div class="spinner"></div>
|
43 |
<?php
|
44 |
wp_nonce_field('GmediaService');
|
45 |
?>
|
admin/assets/css/gmedia.admin.css
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
html {
|
2 |
-
background:#708090;
|
3 |
-
}
|
4 |
#adminmenu #toplevel_page_GrandMedia ul.wp-submenu {
|
5 |
display:none;
|
6 |
}
|
@@ -36,17 +33,36 @@ input::-moz-focus-inner {
|
|
36 |
}
|
37 |
form,
|
38 |
.gmedia-admin form { margin:0; }
|
39 |
-
legend.label { text-align:left; }
|
40 |
textarea.vert { resize:vertical; }
|
41 |
textarea.noResize { resize:none; }
|
42 |
body.gmedia-busy {
|
43 |
cursor:wait !important;
|
44 |
}
|
45 |
-
iframe
|
46 |
background-color:#ffffff;
|
47 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
body.gmedia-blank {
|
49 |
-
background-color:#ffffff;
|
50 |
height:auto;
|
51 |
min-height:100%;
|
52 |
padding:0 0 1px;
|
@@ -74,6 +90,17 @@ div#gmedia-container {
|
|
74 |
z-index:1;
|
75 |
direction:ltr;
|
76 |
min-width:560px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
div#gmedia-header {
|
79 |
position:relative;
|
@@ -110,9 +137,35 @@ div#gmedia-header h2 {
|
|
110 |
font:italic 24px/35px Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
|
111 |
color:#ffffff;
|
112 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
div#gmedia-navbar {
|
114 |
font-size:14px;
|
115 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
div.custom-message {
|
117 |
padding:5px 10px;
|
118 |
margin:0 0 10px;
|
@@ -184,6 +237,8 @@ a.text-danger {
|
|
184 |
.panel-fixed-header .panel-heading { position:relative; top:0; max-width:100%;
|
185 |
/*transition:top 0.2s ease-out; -webkit-transition:top 0.2s ease-out;*/
|
186 |
}
|
|
|
|
|
187 |
.panel-floatingHeader .panel-heading {
|
188 |
position:fixed;
|
189 |
top:32px;
|
@@ -193,6 +248,10 @@ a.text-danger {
|
|
193 |
-moz-box-shadow:0 5px 10px #888888;
|
194 |
box-shadow:0 5px 10px #888888;
|
195 |
}
|
|
|
|
|
|
|
|
|
196 |
.panel-absoluteHeader .panel-heading {
|
197 |
position:absolute;
|
198 |
z-index:10;
|
@@ -202,6 +261,10 @@ a.text-danger {
|
|
202 |
border-bottom-right-radius:3px;
|
203 |
border-bottom-left-radius:3px;
|
204 |
}
|
|
|
|
|
|
|
|
|
205 |
div#gm-list-table {
|
206 |
font-size:13px;
|
207 |
}
|
@@ -242,10 +305,12 @@ div#gm-list-table {
|
|
242 |
div#gmedia-container .list-group-item-info,
|
243 |
div#gmedia-container .list-group-item-info:hover {
|
244 |
background-color:#d9edf7 !important;
|
|
|
245 |
}
|
246 |
div#gmedia-container .list-group-item-warning,
|
247 |
div#gmedia-container .list-group-item-warning:hover {
|
248 |
background-color:#fcf8e3 !important;
|
|
|
249 |
}
|
250 |
div#gmedia-container .item-after-limit {
|
251 |
filter:blur(1px);
|
@@ -291,8 +356,61 @@ label.cb_media-object-gallery {
|
|
291 |
max-width:100%;
|
292 |
}
|
293 |
.display-as-grid .gm-item-cell {
|
294 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
.display-as-grid div.thumbnail {
|
297 |
cursor:pointer;
|
298 |
position:relative;
|
@@ -300,6 +418,8 @@ label.cb_media-object-gallery {
|
|
300 |
border-radius:0;
|
301 |
margin:0;
|
302 |
padding:0;
|
|
|
|
|
303 |
}
|
304 |
.display-as-grid div.thumbnail:before {
|
305 |
content:"";
|
@@ -310,6 +430,7 @@ label.cb_media-object-gallery {
|
|
310 |
-webkit-box-shadow:0 0 0 7px #1e8cbe;
|
311 |
-moz-box-shadow:0 0 0 7px #1e8cbe;
|
312 |
box-shadow:0 0 0 7px #1e8cbe;
|
|
|
313 |
}
|
314 |
.display-as-grid div.thumbnail .cb_media-object {
|
315 |
bottom:0px;
|
@@ -328,31 +449,19 @@ label.cb_media-object-gallery {
|
|
328 |
color:#000000;
|
329 |
cursor:auto;
|
330 |
}
|
331 |
-
.display-as-grid div.thumbnail .gm-cell-title {
|
332 |
-
overflow:hidden;
|
333 |
-
font-size:12px;
|
334 |
-
font-weight:bold;
|
335 |
-
padding:5px 25px 4px 7px;
|
336 |
-
cursor:pointer;
|
337 |
-
}
|
338 |
-
.display-as-grid div.thumbnail .gm-cell-title span {
|
339 |
-
display:block;
|
340 |
-
width:100%;
|
341 |
-
white-space:nowrap;
|
342 |
-
text-overflow:ellipsis;
|
343 |
-
overflow:hidden;
|
344 |
-
}
|
345 |
.display-as-grid div.thumbnail .gm-cell-more-btn {
|
346 |
position:absolute;
|
347 |
-
top:
|
348 |
-
padding:
|
349 |
cursor:pointer;
|
|
|
|
|
350 |
}
|
351 |
.display-as-grid div.thumbnail .gm-cell-more-content {
|
352 |
-
padding:
|
353 |
-
|
354 |
overflow:hidden;
|
355 |
-
transition:all 0.2s easy-out
|
356 |
font-size:11px;
|
357 |
}
|
358 |
.display-as-grid div.thumbnail .gm-cell-more-content .gmedia-actions {
|
@@ -379,7 +488,7 @@ label.cb_media-object-gallery {
|
|
379 |
}
|
380 |
.display-as-grid div.thumbnail .gm-cell-more:hover .gm-cell-more-content,
|
381 |
.display-as-grid div.thumbnail .gm-cell-more.gm-cell-more-active .gm-cell-more-content {
|
382 |
-
|
383 |
}
|
384 |
.display-as-grid div.thumbnail .gm-cell-more-content p {
|
385 |
font-size:11px;
|
@@ -417,14 +526,24 @@ label.cb_media-object-gallery {
|
|
417 |
height:101%;
|
418 |
width:auto;
|
419 |
}
|
420 |
-
.thumbnail .gmedia-typethumb
|
|
|
421 |
position:absolute;
|
422 |
-
right:
|
423 |
bottom:7px;
|
424 |
height:75px;
|
425 |
max-height:60%;
|
426 |
width:auto;
|
427 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
.thumbwrap { position:relative; margin-bottom:5px; }
|
429 |
.gm-stack { position:absolute; right:-8px; bottom:-8px; padding:5px; margin:0; border:1px solid #1e8cbe; background-color:#ffffff; border-width:1px 0 0 1px; }
|
430 |
.gm-stack input{ margin:0; padding:0; }
|
@@ -472,7 +591,7 @@ label.cb_media-object-gallery {
|
|
472 |
}
|
473 |
.no-touch .gmedia_id,
|
474 |
.no-touch .term_id {
|
475 |
-
display:none
|
476 |
}
|
477 |
.term_id {
|
478 |
position:absolute;
|
@@ -482,10 +601,17 @@ label.cb_media-object-gallery {
|
|
482 |
background-color:#ffffff;
|
483 |
display:none;
|
484 |
height:100%;
|
485 |
-
-
|
486 |
-
|
487 |
-
|
488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
}
|
490 |
.term-list-item.gm-selected .term_id {
|
491 |
display:block;
|
@@ -654,6 +780,16 @@ a.trash-icon:hover { color:#843534; }
|
|
654 |
white-space:nowrap;
|
655 |
color:#444444;
|
656 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
657 |
.no-touch .term-list-item .term-images img:hover {
|
658 |
z-index:100 !important;
|
659 |
}
|
@@ -773,9 +909,35 @@ a.edit_tag_save.btn {
|
|
773 |
padding:4px;
|
774 |
margin-right:10px
|
775 |
}
|
776 |
-
.
|
777 |
-
|
778 |
-
padding-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
779 |
}
|
780 |
.delpreset {
|
781 |
position:absolute;
|
@@ -978,6 +1140,9 @@ body.gmedia-blank .media-edit-sidebar .panel-footer {
|
|
978 |
bottom:0;
|
979 |
right:0;
|
980 |
}
|
|
|
|
|
|
|
981 |
#map-floating-panel {
|
982 |
position:absolute;
|
983 |
top:15px;
|
@@ -1007,7 +1172,6 @@ body.gmedia-blank .media-edit-sidebar .panel-footer {
|
|
1007 |
border:solid #cccccc 2px;
|
1008 |
}
|
1009 |
.gallery_preview {
|
1010 |
-
overflow:auto;
|
1011 |
padding:0 5px 5px 0;
|
1012 |
border-right:1px dotted;
|
1013 |
border-bottom:1px dotted;
|
@@ -1031,6 +1195,9 @@ body.gmedia-blank .media-edit-sidebar .panel-footer {
|
|
1031 |
z-index:9999;
|
1032 |
overflow-x:auto;
|
1033 |
}
|
|
|
|
|
|
|
1034 |
input.sharelink[readonly] { cursor:text; }
|
1035 |
fieldset.gmediacustomstuff { margin:0 0 10px; padding:.35em .625em .4em; position:relative; border:1px solid silver }
|
1036 |
.delete-custom-field { margin:4px 2px 0; cursor:pointer; }
|
@@ -1039,6 +1206,9 @@ fieldset.gmediacustomstuff { margin:0 0 10px; padding:.35em .625em .4em; positio
|
|
1039 |
div.modal {
|
1040 |
top:32px;
|
1041 |
}
|
|
|
|
|
|
|
1042 |
div#termsModal .modal-dialog {
|
1043 |
width:350px;
|
1044 |
}
|
|
|
|
|
|
|
1 |
#adminmenu #toplevel_page_GrandMedia ul.wp-submenu {
|
2 |
display:none;
|
3 |
}
|
33 |
}
|
34 |
form,
|
35 |
.gmedia-admin form { margin:0; }
|
36 |
+
legend.label { text-align:left; display:block; }
|
37 |
textarea.vert { resize:vertical; }
|
38 |
textarea.noResize { resize:none; }
|
39 |
body.gmedia-busy {
|
40 |
cursor:wait !important;
|
41 |
}
|
42 |
+
iframe {
|
43 |
background-color:#ffffff;
|
44 |
}
|
45 |
+
#gmedia-data-helper{
|
46 |
+
background: #333;
|
47 |
+
background: rgba(0,0,0,.8);
|
48 |
+
border-radius: 5px;
|
49 |
+
color: #fff;
|
50 |
+
padding: 4px 10px;
|
51 |
+
position: fixed;
|
52 |
+
z-index: 999999;
|
53 |
+
max-width: 220px;
|
54 |
+
}
|
55 |
+
#gmedia-data-helper:before{
|
56 |
+
border: solid;
|
57 |
+
border-color: #333 transparent;
|
58 |
+
border-width: 0 6px 6px 6px;
|
59 |
+
bottom: 100%;
|
60 |
+
content: "";
|
61 |
+
left: 17px;
|
62 |
+
position: absolute;
|
63 |
+
z-index: 99;
|
64 |
+
}
|
65 |
body.gmedia-blank {
|
|
|
66 |
height:auto;
|
67 |
min-height:100%;
|
68 |
padding:0 0 1px;
|
90 |
z-index:1;
|
91 |
direction:ltr;
|
92 |
min-width:560px;
|
93 |
+
-webkit-backface-visibility: hidden;
|
94 |
+
backface-visibility: hidden;
|
95 |
+
}
|
96 |
+
body.gmedia-blank div#gmedia-container {
|
97 |
+
margin:0;
|
98 |
+
position:static;
|
99 |
+
z-index:auto;
|
100 |
+
direction:ltr;
|
101 |
+
min-width:auto;
|
102 |
+
width:100%;
|
103 |
+
height:100%;
|
104 |
}
|
105 |
div#gmedia-header {
|
106 |
position:relative;
|
137 |
font:italic 24px/35px Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
|
138 |
color:#ffffff;
|
139 |
}
|
140 |
+
#ajax-long-operation {
|
141 |
+
position:absolute;
|
142 |
+
right:20px;
|
143 |
+
bottom:0;
|
144 |
+
width: 25%;
|
145 |
+
min-width:220px;
|
146 |
+
}
|
147 |
+
.progress-bar-indicator {
|
148 |
+
position:absolute;
|
149 |
+
width:100%;
|
150 |
+
text-align:center;
|
151 |
+
color:#204D74;
|
152 |
+
}
|
153 |
div#gmedia-navbar {
|
154 |
font-size:14px;
|
155 |
}
|
156 |
+
a.list-group-item-premium {
|
157 |
+
color: #ffffff !important;
|
158 |
+
background-color: #D82700;
|
159 |
+
border-color:#A52A2A;
|
160 |
+
font-weight:bold;
|
161 |
+
}
|
162 |
+
a.list-group-item-premium:hover {
|
163 |
+
color: #ffffff !important;
|
164 |
+
background-color:#c52400;
|
165 |
+
border-color:#A52A2A;
|
166 |
+
font-weight:bold;
|
167 |
+
}
|
168 |
+
|
169 |
div.custom-message {
|
170 |
padding:5px 10px;
|
171 |
margin:0 0 10px;
|
237 |
.panel-fixed-header .panel-heading { position:relative; top:0; max-width:100%;
|
238 |
/*transition:top 0.2s ease-out; -webkit-transition:top 0.2s ease-out;*/
|
239 |
}
|
240 |
+
.panel-heading .spinner { margin-top:0; }
|
241 |
+
body.gmedia-blank .panel-floatingHeader .panel-heading,
|
242 |
.panel-floatingHeader .panel-heading {
|
243 |
position:fixed;
|
244 |
top:32px;
|
248 |
-moz-box-shadow:0 5px 10px #888888;
|
249 |
box-shadow:0 5px 10px #888888;
|
250 |
}
|
251 |
+
body.gmedia-blank .panel-floatingHeader .panel-heading {
|
252 |
+
top: 0;
|
253 |
+
}
|
254 |
+
body.gmedia-blank .panel-absoluteHeader .panel-heading,
|
255 |
.panel-absoluteHeader .panel-heading {
|
256 |
position:absolute;
|
257 |
z-index:10;
|
261 |
border-bottom-right-radius:3px;
|
262 |
border-bottom-left-radius:3px;
|
263 |
}
|
264 |
+
.dropdown-menu {
|
265 |
+
max-height: calc(100vh - 50px);
|
266 |
+
overflow-y: auto;
|
267 |
+
}
|
268 |
div#gm-list-table {
|
269 |
font-size:13px;
|
270 |
}
|
305 |
div#gmedia-container .list-group-item-info,
|
306 |
div#gmedia-container .list-group-item-info:hover {
|
307 |
background-color:#d9edf7 !important;
|
308 |
+
color:inherit !important;
|
309 |
}
|
310 |
div#gmedia-container .list-group-item-warning,
|
311 |
div#gmedia-container .list-group-item-warning:hover {
|
312 |
background-color:#fcf8e3 !important;
|
313 |
+
color:inherit !important;
|
314 |
}
|
315 |
div#gmedia-container .item-after-limit {
|
316 |
filter:blur(1px);
|
356 |
max-width:100%;
|
357 |
}
|
358 |
.display-as-grid .gm-item-cell {
|
359 |
+
padding:12px 12px 10px;
|
360 |
+
border:4px solid #ffffff;
|
361 |
+
background-color:#f7f7f7;
|
362 |
+
min-width:200px;
|
363 |
+
max-width:340px;
|
364 |
+
border-radius:14px;
|
365 |
+
}
|
366 |
+
.edit-gmedia .gmedia-actions { margin:10px; }
|
367 |
+
.gm-item-cell .gmedia-actions {
|
368 |
+
overflow:hidden;
|
369 |
+
position:absolute;
|
370 |
+
left:0; top:0;
|
371 |
+
transform:translateY(100%) translateZ(0);
|
372 |
+
opacity:0;
|
373 |
+
transition: transform 0.1s, opacity 0.2s;
|
374 |
+
}
|
375 |
+
.gmedia-actions > * {margin-left:5px; margin-right:5px;}
|
376 |
+
.gm-item-cell .gmedia-actions > * {float:left;}
|
377 |
+
.gm-item-cell .gmedia-actions * {
|
378 |
+
-webkit-backface-visibility: hidden;
|
379 |
+
backface-visibility: hidden;
|
380 |
+
-webkit-transform-style: preserve-3d;
|
381 |
+
}
|
382 |
+
.gmedia-actions > *:first-child {margin-left: 0;}
|
383 |
+
.gmedia-actions > *:last-child {margin-right: 0;}
|
384 |
+
|
385 |
+
.gm-item-cell .gm-cell-bottom {
|
386 |
+
position:relative;
|
387 |
+
min-height:20px;
|
388 |
+
margin:15px 0 0 2px;
|
389 |
+
overflow:hidden;
|
390 |
}
|
391 |
+
.gm-item-cell .gm-cell-title {
|
392 |
+
overflow:hidden;
|
393 |
+
font-size:12px;
|
394 |
+
font-weight:bold;
|
395 |
+
cursor:pointer;
|
396 |
+
opacity:1;
|
397 |
+
position:absolute;
|
398 |
+
left:0;
|
399 |
+
top:0;
|
400 |
+
width:100%;
|
401 |
+
transition:opacity 0.15s;
|
402 |
+
}
|
403 |
+
.gm-item-cell .gm-cell-title span {
|
404 |
+
display:block;
|
405 |
+
width:100%;
|
406 |
+
white-space:nowrap;
|
407 |
+
text-overflow:ellipsis;
|
408 |
+
overflow:hidden;
|
409 |
+
}
|
410 |
+
|
411 |
+
.gm-item-cell:hover .gm-cell-title { opacity:0; pointer-events:none;}
|
412 |
+
.gm-item-cell:hover .gmedia-actions { transform:translateY(0); opacity:1;}
|
413 |
+
|
414 |
.display-as-grid div.thumbnail {
|
415 |
cursor:pointer;
|
416 |
position:relative;
|
418 |
border-radius:0;
|
419 |
margin:0;
|
420 |
padding:0;
|
421 |
+
-webkit-backface-visibility: hidden;
|
422 |
+
backface-visibility: hidden;
|
423 |
}
|
424 |
.display-as-grid div.thumbnail:before {
|
425 |
content:"";
|
430 |
-webkit-box-shadow:0 0 0 7px #1e8cbe;
|
431 |
-moz-box-shadow:0 0 0 7px #1e8cbe;
|
432 |
box-shadow:0 0 0 7px #1e8cbe;
|
433 |
+
border-radius:1px;
|
434 |
}
|
435 |
.display-as-grid div.thumbnail .cb_media-object {
|
436 |
bottom:0px;
|
449 |
color:#000000;
|
450 |
cursor:auto;
|
451 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
.display-as-grid div.thumbnail .gm-cell-more-btn {
|
453 |
position:absolute;
|
454 |
+
top:0; right:0;
|
455 |
+
padding:5px;
|
456 |
cursor:pointer;
|
457 |
+
color: #1e8cbe;
|
458 |
+
/*text-shadow: 1px 1px 1px #83acbf;*/
|
459 |
}
|
460 |
.display-as-grid div.thumbnail .gm-cell-more-content {
|
461 |
+
padding:5px 5px 0;
|
462 |
+
display:none;
|
463 |
overflow:hidden;
|
464 |
+
/*transition:all 0.2s easy-out;*/
|
465 |
font-size:11px;
|
466 |
}
|
467 |
.display-as-grid div.thumbnail .gm-cell-more-content .gmedia-actions {
|
488 |
}
|
489 |
.display-as-grid div.thumbnail .gm-cell-more:hover .gm-cell-more-content,
|
490 |
.display-as-grid div.thumbnail .gm-cell-more.gm-cell-more-active .gm-cell-more-content {
|
491 |
+
display:block;
|
492 |
}
|
493 |
.display-as-grid div.thumbnail .gm-cell-more-content p {
|
494 |
font-size:11px;
|
526 |
height:101%;
|
527 |
width:auto;
|
528 |
}
|
529 |
+
.thumbnail img.gmedia-typethumb,
|
530 |
+
.display-as-grid div.thumbnail .cb_media-object img.gmedia-typethumb {
|
531 |
position:absolute;
|
532 |
+
right:7px;
|
533 |
bottom:7px;
|
534 |
height:75px;
|
535 |
max-height:60%;
|
536 |
width:auto;
|
537 |
}
|
538 |
+
.display-as-grid div.thumbnail .cb_media-object img.gmedia-typethumb {
|
539 |
+
left:auto;
|
540 |
+
top:auto;
|
541 |
+
right:50%;
|
542 |
+
bottom:50%;
|
543 |
+
margin:0 5px 5px 0;
|
544 |
+
transform:none;
|
545 |
+
opacity:0.9;
|
546 |
+
}
|
547 |
.thumbwrap { position:relative; margin-bottom:5px; }
|
548 |
.gm-stack { position:absolute; right:-8px; bottom:-8px; padding:5px; margin:0; border:1px solid #1e8cbe; background-color:#ffffff; border-width:1px 0 0 1px; }
|
549 |
.gm-stack input{ margin:0; padding:0; }
|
591 |
}
|
592 |
.no-touch .gmedia_id,
|
593 |
.no-touch .term_id {
|
594 |
+
/*display:none;*/
|
595 |
}
|
596 |
.term_id {
|
597 |
position:absolute;
|
601 |
background-color:#ffffff;
|
602 |
display:none;
|
603 |
height:100%;
|
604 |
+
z-index:10;
|
605 |
+
}
|
606 |
+
.term_id:before {
|
607 |
+
content: '';
|
608 |
+
position:absolute;
|
609 |
+
right:100%;
|
610 |
+
top:0;
|
611 |
+
bottom:0;
|
612 |
+
width:17px;
|
613 |
+
background: linear-gradient(to right, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 50%,rgba(255,255,255,1) 100%);
|
614 |
+
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 );
|
615 |
}
|
616 |
.term-list-item.gm-selected .term_id {
|
617 |
display:block;
|
780 |
white-space:nowrap;
|
781 |
color:#444444;
|
782 |
}
|
783 |
+
.object-actions .term-shortcode {float:left;margin:0;}
|
784 |
+
.object-actions .term-shortcode input,
|
785 |
+
.object-actions .term-shortcode .input-buffer{ font-family: Courier, sans-serif; font-size: 14px; line-height:100%; letter-spacing: 0.05em; border:none; box-shadow:none; background-color:#fff; margin:0; padding:0;}
|
786 |
+
|
787 |
+
.panel-heading .term-shortcode {float:left;margin-left:20px;}
|
788 |
+
.panel-heading .term-shortcode input,
|
789 |
+
.panel-heading .term-shortcode .input-buffer{ font-family: Courier, sans-serif; font-size: 14px; letter-spacing: 0.05em; }
|
790 |
+
|
791 |
+
.term-shortcode .input-buffer{position: absolute; top: -1000px; left: -1000px; visibility: hidden; white-space: nowrap;}
|
792 |
+
|
793 |
.no-touch .term-list-item .term-images img:hover {
|
794 |
z-index:100 !important;
|
795 |
}
|
909 |
padding:4px;
|
910 |
margin-right:10px
|
911 |
}
|
912 |
+
.media.module-gallery {
|
913 |
+
border-bottom: 1px solid #444444;
|
914 |
+
padding-bottom:15px;
|
915 |
+
margin-bottom:30px;
|
916 |
+
}
|
917 |
+
.media.module-gallery:last-child {
|
918 |
+
border-bottom: none;
|
919 |
+
padding-bottom:0;
|
920 |
+
margin-bottom:0;
|
921 |
+
}
|
922 |
+
.presetlist a { }
|
923 |
+
.gm-preset-id {
|
924 |
+
font-size:smaller;
|
925 |
+
float:right;
|
926 |
+
padding:0 15px 0 5px;
|
927 |
+
}
|
928 |
+
.addpreset:hover,
|
929 |
+
.addpreset:active,
|
930 |
+
.addpreset {
|
931 |
+
margin:0 8px 0;
|
932 |
+
line-height:100%;
|
933 |
+
text-decoration:none;
|
934 |
+
outline:none;
|
935 |
+
}
|
936 |
+
.addpreset span {
|
937 |
+
line-height:100%;
|
938 |
+
font-size:74%;
|
939 |
+
padding:0 5px 2px;
|
940 |
+
cursor:pointer;
|
941 |
}
|
942 |
.delpreset {
|
943 |
position:absolute;
|
1140 |
bottom:0;
|
1141 |
right:0;
|
1142 |
}
|
1143 |
+
body.gmedia_library .panel {
|
1144 |
+
margin-bottom:0;
|
1145 |
+
}
|
1146 |
#map-floating-panel {
|
1147 |
position:absolute;
|
1148 |
top:15px;
|
1172 |
border:solid #cccccc 2px;
|
1173 |
}
|
1174 |
.gallery_preview {
|
|
|
1175 |
padding:0 5px 5px 0;
|
1176 |
border-right:1px dotted;
|
1177 |
border-bottom:1px dotted;
|
1195 |
z-index:9999;
|
1196 |
overflow-x:auto;
|
1197 |
}
|
1198 |
+
.edit_gmedia_item .modal-header {display:none;}
|
1199 |
+
.edit_gmedia_item .modal-body {padding:0;}
|
1200 |
+
.edit_gmedia_item iframe {transition:height 0.2s linear; -webkit-transition:height 0.2s linear; max-height:calc(100vh - 110px)}
|
1201 |
input.sharelink[readonly] { cursor:text; }
|
1202 |
fieldset.gmediacustomstuff { margin:0 0 10px; padding:.35em .625em .4em; position:relative; border:1px solid silver }
|
1203 |
.delete-custom-field { margin:4px 2px 0; cursor:pointer; }
|
1206 |
div.modal {
|
1207 |
top:32px;
|
1208 |
}
|
1209 |
+
body.gmedia-blank div.modal {
|
1210 |
+
top:0;
|
1211 |
+
}
|
1212 |
div#termsModal .modal-dialog {
|
1213 |
width:350px;
|
1214 |
}
|
admin/assets/img/audio.png
CHANGED
Binary file
|
admin/assets/js/gmedia.admin.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
* Gmedia Library
|
3 |
*/
|
4 |
var GmediaLibrary = {
|
5 |
-
init: function
|
6 |
jQuery('#gm-selected').on('change', function() {
|
7 |
var val = jQuery(this).val();
|
8 |
jQuery('.edit-mode-link').each(function() {
|
@@ -14,20 +14,166 @@ var GmediaLibrary = {
|
|
14 |
});
|
15 |
}).trigger('change');
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
GmediaLibrary.editmode();
|
19 |
}
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
},
|
22 |
/**
|
23 |
* Edit Mode
|
24 |
*/
|
25 |
editmode: function() {
|
|
|
26 |
// SelectBox for albums
|
27 |
var combobox_albums = jQuery('.combobox_gmedia_album');
|
28 |
-
combobox_albums.selectize({
|
29 |
create: (combobox_albums.data('create')? true : false),
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
});
|
32 |
|
33 |
if(window.gmedia_categories) {
|
@@ -37,7 +183,7 @@ var GmediaLibrary = {
|
|
37 |
return {item: x};
|
38 |
});
|
39 |
|
40 |
-
categories.selectize({
|
41 |
create: function(input) {
|
42 |
if(categories.data('create')) {
|
43 |
return {
|
@@ -47,11 +193,26 @@ var GmediaLibrary = {
|
|
47 |
return false;
|
48 |
}
|
49 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
createOnBlur: true,
|
51 |
delimiter: ',',
|
52 |
maxItems: null,
|
53 |
-
openOnFocus:
|
54 |
-
persist:
|
55 |
options: categories_data,
|
56 |
labelField: 'item',
|
57 |
valueField: 'item',
|
@@ -60,6 +221,52 @@ var GmediaLibrary = {
|
|
60 |
});
|
61 |
}
|
62 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
// Date/Time picker
|
65 |
var gmedia_date_temp;
|
@@ -97,17 +304,19 @@ var GmediaLibrary = {
|
|
97 |
* Gmedia AddMedia
|
98 |
*/
|
99 |
var GmediaAddMedia = {
|
100 |
-
init: function
|
101 |
|
102 |
-
jQuery('
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
111 |
|
112 |
var albums = jQuery('select#combobox_gmedia_album');
|
113 |
if(albums.length) {
|
@@ -168,7 +377,7 @@ var GmediaAddMedia = {
|
|
168 |
createOnBlur: true,
|
169 |
delimiter: ',',
|
170 |
maxItems: null,
|
171 |
-
openOnFocus:
|
172 |
persist: false,
|
173 |
options: tags_data,
|
174 |
labelField: 'item',
|
@@ -198,7 +407,7 @@ var GmediaAddMedia = {
|
|
198 |
createOnBlur: true,
|
199 |
delimiter: ',',
|
200 |
maxItems: null,
|
201 |
-
openOnFocus:
|
202 |
persist: false,
|
203 |
options: categories_data,
|
204 |
labelField: 'item',
|
@@ -222,62 +431,82 @@ var GmediaAddMedia = {
|
|
222 |
* Gmedia Terms
|
223 |
*/
|
224 |
var GmediaTerms = {
|
225 |
-
init: function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
|
228 |
-
jQuery('input.edit_tag_input').keypress(function(e) {
|
229 |
-
var tagdiv = jQuery('#tag_' + jQuery(this).data('tag_id'));
|
230 |
-
var charCode = e.charCode || e.keyCode || e.which;
|
231 |
-
if(charCode == 13) {
|
232 |
e.preventDefault();
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
-
}
|
236 |
-
var tagdiv = jQuery('#tag_' + jQuery(this).data('tag_id'));
|
237 |
-
edit_tag(tagdiv);
|
238 |
-
});
|
239 |
|
240 |
-
jQuery('.
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
jQuery(id).find('.edit_tag_form').show().find('input').focus();
|
245 |
-
jQuery('#gm-list-table').data('edit', true);
|
246 |
});
|
247 |
-
|
248 |
-
|
249 |
});
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
var
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
tagdiv.find('.edit_tag_link').show();
|
259 |
-
return;
|
260 |
-
}
|
261 |
-
var post_data = {
|
262 |
-
action: 'gmedia_tag_edit',
|
263 |
-
tag_id: inp.data('tag_id'),
|
264 |
-
tag_name: new_tag_name,
|
265 |
-
_wpnonce: jQuery('#_wpnonce').val()
|
266 |
-
};
|
267 |
-
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
268 |
-
console.log(data);
|
269 |
-
if(data.error) {
|
270 |
-
//inp.val(inp.attr('placeholder'));
|
271 |
-
jQuery('#gmedia-panel').before(data.error);
|
272 |
-
} else {
|
273 |
-
//new_tag_name = new_tag_name.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
274 |
-
inp.attr('placeholder', new_tag_name);
|
275 |
-
tagdiv.find('.edit_tag_link').text(new_tag_name).show();
|
276 |
-
//noinspection JSUnresolvedVariable
|
277 |
-
jQuery('#gmedia-panel').before(data.msg);
|
278 |
-
tagdiv.find('.edit_tag_form').hide();
|
279 |
-
}
|
280 |
-
});
|
281 |
}
|
282 |
|
283 |
}
|
@@ -405,23 +634,23 @@ var GmediaSelect = {
|
|
405 |
});
|
406 |
}
|
407 |
},
|
408 |
-
init: function
|
409 |
var cb_global = jQuery('#cb_global'),
|
410 |
cb_obj = cb_global.data('group');
|
411 |
|
412 |
-
if
|
413 |
GmediaSelect.msg_selected(cb_obj);
|
414 |
-
jQuery('#gm-selected-clear').click(function
|
415 |
jQuery('#gm-selected').val('');
|
416 |
GmediaSelect.chk_none(false, cb_obj);
|
417 |
GmediaSelect.msg_selected(cb_obj);
|
418 |
e.preventDefault();
|
419 |
});
|
420 |
-
jQuery('#gm-selected-show').click(function
|
421 |
jQuery('#gm-selected-btn').submit();
|
422 |
e.preventDefault();
|
423 |
});
|
424 |
-
jQuery('#gm-stack-in').click(function
|
425 |
e.preventDefault();
|
426 |
var stack_obj = jQuery('#gm-stack'),
|
427 |
sel_obj = jQuery('#gm-selected'),
|
@@ -438,7 +667,7 @@ var GmediaSelect = {
|
|
438 |
//GmediaSelect.chk_none(false, cb_obj);
|
439 |
//GmediaSelect.msg_selected(cb_obj);
|
440 |
});
|
441 |
-
jQuery('#gm-stack-out').click(function
|
442 |
e.preventDefault();
|
443 |
var stack_obj = jQuery('#gm-stack'),
|
444 |
sel_obj = jQuery('#gm-selected'),
|
@@ -456,17 +685,17 @@ var GmediaSelect = {
|
|
456 |
//GmediaSelect.msg_selected(cb_obj);
|
457 |
});
|
458 |
}
|
459 |
-
cb_global.click(function
|
460 |
-
if
|
461 |
GmediaSelect.chk_all(false, cb_obj);
|
462 |
} else {
|
463 |
GmediaSelect.chk_none(false, cb_obj);
|
464 |
}
|
465 |
GmediaSelect.msg_selected(cb_obj, true);
|
466 |
});
|
467 |
-
jQuery('#cb_global-btn li a').click(function
|
468 |
var sel = jQuery(this).data('select');
|
469 |
-
switch
|
470 |
case 'total':
|
471 |
GmediaSelect.chk_all(false, cb_obj);
|
472 |
break;
|
@@ -485,18 +714,18 @@ var GmediaSelect = {
|
|
485 |
GmediaSelect.msg_selected(cb_obj, true);
|
486 |
e.preventDefault();
|
487 |
});
|
488 |
-
jQuery('.cb_media-object input:checkbox, .cb_term-object input:checkbox').change(function
|
489 |
var selected = jQuery('#gm-selected'),
|
490 |
arr = selected.val();
|
491 |
var cur = jQuery(this).val();
|
492 |
-
if
|
493 |
-
if
|
494 |
arr = arr + ',' + cur;
|
495 |
} else {
|
496 |
arr = cur;
|
497 |
}
|
498 |
} else {
|
499 |
-
arr = jQuery.grep(arr.split(','), function
|
500 |
return a != cur;
|
501 |
}).join(',');
|
502 |
}
|
@@ -505,32 +734,32 @@ var GmediaSelect = {
|
|
505 |
GmediaSelect.msg_selected(cb_obj);
|
506 |
});
|
507 |
|
508 |
-
if
|
509 |
GmediaSelect.msg_stack();
|
510 |
-
jQuery('#gm-stack-clear').click(function
|
511 |
jQuery('#gm-stack').val('');
|
512 |
jQuery('.gm-stack input').prop('checked', false);
|
513 |
GmediaSelect.msg_stack();
|
514 |
e.preventDefault();
|
515 |
});
|
516 |
-
jQuery('#gm-stack-show').click(function
|
517 |
jQuery('#gm-stack-btn').submit();
|
518 |
e.preventDefault();
|
519 |
});
|
520 |
|
521 |
}
|
522 |
-
jQuery('.gm-stack input:checkbox').change(function
|
523 |
var selected = jQuery('#gm-stack'),
|
524 |
arr = selected.val();
|
525 |
var cur = jQuery(this).val();
|
526 |
-
if
|
527 |
-
if
|
528 |
arr = arr + ',' + cur;
|
529 |
} else {
|
530 |
arr = cur;
|
531 |
}
|
532 |
} else {
|
533 |
-
arr = jQuery.grep(arr.split(','), function
|
534 |
return a != cur;
|
535 |
}).join(',');
|
536 |
}
|
@@ -538,9 +767,9 @@ var GmediaSelect = {
|
|
538 |
GmediaSelect.msg_stack();
|
539 |
});
|
540 |
|
541 |
-
jQuery('.term-label').click(function
|
542 |
-
if
|
543 |
-
if
|
544 |
var cb = jQuery('input:checkbox', this);
|
545 |
cb.prop("checked", !cb.prop("checked")).change();
|
546 |
jQuery(this).closest('.term-list-item').toggleClass('gm-selected');
|
@@ -553,63 +782,63 @@ var GmediaSelect = {
|
|
553 |
}
|
554 |
|
555 |
var GmediaFunction = {
|
556 |
-
confirm: function
|
557 |
-
if
|
558 |
return true;
|
559 |
}
|
560 |
var r = false;
|
561 |
//noinspection UnusedCatchParameterJS
|
562 |
-
try
|
563 |
r = confirm(txt);
|
564 |
}
|
565 |
-
catch
|
566 |
alert('Disable Popup Blocker');
|
567 |
}
|
568 |
return r;
|
569 |
},
|
570 |
-
init: function
|
571 |
jQuery('#toplevel_page_GrandMedia').addClass('current').removeClass('wp-not-current-submenu');
|
572 |
-
if
|
573 |
jQuery('html').addClass('no-touch');
|
574 |
}
|
575 |
|
576 |
-
|
577 |
-
jQuery(
|
578 |
-
jQuery('
|
579 |
-
}).ajaxStop(function(){
|
580 |
-
jQuery('body').removeClass('gmedia-busy');
|
581 |
-
|
582 |
-
|
583 |
|
584 |
-
jQuery('[data-confirm]').click(function
|
585 |
return GmediaFunction.confirm(jQuery(this).data('confirm'));
|
586 |
});
|
587 |
|
588 |
-
jQuery('.show-settings-link').click(function
|
589 |
e.preventDefault();
|
590 |
jQuery('#show-settings-link').trigger('click');
|
591 |
});
|
592 |
|
593 |
-
jQuery('.fit-thumbs').click(function
|
594 |
e.preventDefault();
|
595 |
jQuery(this).toggleClass('btn-success btn-default');
|
596 |
jQuery('.display-as-grid').toggleClass('invert-ratio');
|
597 |
jQuery.get(jQuery(this).attr('href'), {ajaxload: 1});
|
598 |
});
|
599 |
|
600 |
-
jQuery('.gm-cell-more-btn, .gm-cell-title').click(function
|
601 |
jQuery(this).parent().toggleClass('gm-cell-more-active');
|
602 |
});
|
603 |
|
604 |
jQuery('div.gmedia-modal').appendTo('body');
|
605 |
-
jQuery('a.gmedia-modal').click(function
|
606 |
jQuery('body').addClass('gmedia-busy');
|
607 |
var modal_div = jQuery(jQuery(this).attr('href'));
|
608 |
var post_data = {
|
609 |
action: jQuery(this).data('action'), modal: jQuery(this).data('modal'), _wpnonce: jQuery('#_wpnonce').val()
|
610 |
};
|
611 |
-
jQuery.post(ajaxurl, post_data, function
|
612 |
-
if
|
613 |
jQuery('body').removeClass('gmedia-busy');
|
614 |
alert(data);
|
615 |
return false;
|
@@ -619,7 +848,7 @@ var GmediaFunction = {
|
|
619 |
backdrop: 'static',
|
620 |
show: true,
|
621 |
keyboard: false
|
622 |
-
}).one('hidden.bs.modal', function
|
623 |
jQuery('.modal-dialog', this).empty();
|
624 |
});
|
625 |
jQuery('body').removeClass('gmedia-busy');
|
@@ -627,7 +856,7 @@ var GmediaFunction = {
|
|
627 |
e.preventDefault();
|
628 |
});
|
629 |
|
630 |
-
jQuery('a.gmedit-modal').click(function
|
631 |
e.preventDefault();
|
632 |
var modal_div = jQuery(jQuery(this).data('target'));
|
633 |
jQuery('.modal-content', modal_div).html(
|
@@ -643,36 +872,41 @@ var GmediaFunction = {
|
|
643 |
backdrop: true,
|
644 |
show: true,
|
645 |
keyboard: false
|
646 |
-
}).one('hidden.bs.modal', function
|
647 |
jQuery('.modal-content', this).empty();
|
648 |
});
|
649 |
});
|
650 |
|
651 |
-
jQuery('a.preview-modal').click(function
|
652 |
e.preventDefault();
|
653 |
var data = jQuery(this).data(),
|
654 |
-
modal_div = jQuery(data['target'])
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
|
|
|
|
|
|
660 |
} else {
|
661 |
var r = data['width'] / data['height'],
|
662 |
w = Math.min(jQuery(window).width() * 0.98 - 32, data['width']),
|
663 |
h = w / r;
|
664 |
-
|
665 |
-
|
|
|
|
|
|
|
666 |
jQuery('<iframe />', {
|
667 |
name: 'previewFrame',
|
668 |
id: 'previewFrame',
|
669 |
width: '100%',
|
670 |
height: h,
|
671 |
-
src: jQuery(this).attr('href')
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
}
|
676 |
}).css({display: 'block', margin: '4px 0'})
|
677 |
);
|
678 |
}
|
@@ -680,36 +914,45 @@ var GmediaFunction = {
|
|
680 |
modal_div.modal({
|
681 |
backdrop: true,
|
682 |
show: true
|
683 |
-
}).one('hidden.bs.modal', function
|
684 |
-
|
685 |
-
|
686 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
687 |
});
|
688 |
});
|
689 |
|
690 |
-
jQuery('input.sharelink').on('click focus', function
|
691 |
this.setSelectionRange(0, this.value.length);
|
692 |
});
|
693 |
-
jQuery('input.sharetoemail').on('keyup', function
|
694 |
jQuery('.sharebutton').prop('disabled', !validateEmail(this.value));
|
695 |
});
|
696 |
-
jQuery('.sharebutton').on('click', function
|
697 |
var sharetoemail = jQuery('input.sharetoemail');
|
698 |
-
if
|
699 |
sharetoemail.focus();
|
700 |
sharetoemail.parent().addClass('has-error');
|
701 |
return false;
|
702 |
}
|
703 |
var post_data = jQuery('#shareForm').serialize();
|
704 |
-
jQuery.post(ajaxurl, post_data, function
|
705 |
jQuery('body').removeClass('gmedia-busy');
|
706 |
-
if
|
707 |
jQuery('#gm-message').append(data);
|
708 |
}
|
709 |
});
|
710 |
jQuery('#shareModal').modal('hide');
|
711 |
});
|
712 |
-
jQuery('a.share-modal').click(function
|
713 |
e.preventDefault();
|
714 |
var data = jQuery(this).data(),
|
715 |
modal_div = jQuery(data['target']),
|
@@ -731,7 +974,7 @@ var GmediaFunction = {
|
|
731 |
jQuery('.sharelink_page', modal_div).show();
|
732 |
jQuery('.sharelink_page input', modal_div).val(cloudlink);
|
733 |
jQuery('.sharelink_page a', modal_div).attr('href', cloudlink);
|
734 |
-
if(cloudlink_checked){
|
735 |
jQuery('.sharelink_page input[type="radio"]', modal_div).prop('checked', true);
|
736 |
}
|
737 |
} else {
|
@@ -743,34 +986,34 @@ var GmediaFunction = {
|
|
743 |
backdrop: true,
|
744 |
show: true,
|
745 |
keyboard: false
|
746 |
-
}).one('shown.bs.modal', function
|
747 |
jQuery('input.sharelink', this).focus();
|
748 |
-
}).one('hidden.bs.modal', function
|
749 |
jQuery('input.sharelink', this).val('');
|
750 |
});
|
751 |
});
|
752 |
|
753 |
-
jQuery('.buildquery-modal').click(function
|
754 |
e.preventDefault();
|
755 |
var data = jQuery(this).data(),
|
756 |
modal_div = jQuery(jQuery(this).attr('href')),
|
757 |
query_field = jQuery(jQuery(this).attr('id') + '_field');
|
758 |
-
|
759 |
|
760 |
modal_div.modal({
|
761 |
backdrop: false,
|
762 |
show: true,
|
763 |
keyboard: false
|
764 |
-
}).one('shown.bs.modal', function
|
765 |
-
if(query){
|
766 |
query = gm_parse_query(query);
|
767 |
console.log(query);
|
768 |
}
|
769 |
-
}).one('hidden.bs.modal', function
|
770 |
});
|
771 |
|
772 |
-
jQuery('.buildquerysubmit').on('click', function
|
773 |
-
var qform = jQuery('#buildQuery :input').filter(function
|
774 |
return !!jQuery(this).val();
|
775 |
});
|
776 |
|
@@ -779,7 +1022,7 @@ var GmediaFunction = {
|
|
779 |
jQuery('#build_query_field').val(qform);
|
780 |
jQuery('#buildQuery').modal('hide');
|
781 |
});
|
782 |
-
jQuery('a.newcustomfield-modal').click(function
|
783 |
e.preventDefault();
|
784 |
var data = jQuery(this).data(),
|
785 |
modal_div = jQuery(jQuery(this).attr('href'));
|
@@ -788,37 +1031,37 @@ var GmediaFunction = {
|
|
788 |
backdrop: false,
|
789 |
show: true,
|
790 |
keyboard: false
|
791 |
-
}).one('shown.bs.modal', function
|
792 |
jQuery('input.newcustomfield-for-id', this).val(data['gmid']);
|
793 |
-
}).one('hidden.bs.modal', function
|
794 |
jQuery(':input.form-control, input.newcustomfield-for-id', this).val('');
|
795 |
-
if
|
796 |
jQuery('a.gmediacustomstuff').click();
|
797 |
}
|
798 |
});
|
799 |
});
|
800 |
-
jQuery('.customfieldsubmit').on('click', function
|
801 |
var cform = jQuery('#newCustomFieldForm');
|
802 |
-
if
|
803 |
jQuery('#newCustomFieldModal').modal('hide');
|
804 |
alert('No ID');
|
805 |
return false;
|
806 |
}
|
807 |
var post_data = cform.serialize();
|
808 |
-
jQuery.post(ajaxurl, post_data, function
|
809 |
jQuery('body').removeClass('gmedia-busy');
|
810 |
-
if
|
811 |
-
jQuery('#newCustomFieldModal').modal('hide').one('hidden.bs.modal', function
|
812 |
//noinspection JSUnresolvedVariable
|
813 |
-
if
|
814 |
//noinspection JSUnresolvedVariable
|
815 |
jQuery('#newmeta').replaceWith(data.newmeta_form);
|
816 |
}
|
817 |
});
|
818 |
jQuery('.row:last', '#gmediacustomstuff_' + data.id).append(data.success.data);
|
819 |
} else {
|
820 |
-
if
|
821 |
-
if
|
822 |
jQuery('#newCustomFieldModal').modal('hide');
|
823 |
}
|
824 |
alert(data.error.message);
|
@@ -828,26 +1071,26 @@ var GmediaFunction = {
|
|
828 |
}
|
829 |
});
|
830 |
});
|
831 |
-
jQuery('.gmediacustomstuff').on('click', '.delete-custom-field', function
|
832 |
var t = jQuery(this).closest('.form-group'),
|
833 |
post_data = convertInputsToJSON(jQuery(':input', t));
|
834 |
-
if
|
835 |
return false;
|
836 |
}
|
837 |
var meta_type = jQuery(this).closest('fieldset').attr('data-metatype');
|
838 |
post_data.action = meta_type + '_delete_custom_field';
|
839 |
post_data.ID = jQuery(this).closest('form').attr('data-id');
|
840 |
post_data._customfield_nonce = jQuery('#_customfield_nonce').val();
|
841 |
-
jQuery.post(ajaxurl, post_data, function
|
842 |
jQuery('body').removeClass('gmedia-busy');
|
843 |
//noinspection JSUnresolvedVariable
|
844 |
-
if
|
845 |
//noinspection JSUnresolvedVariable
|
846 |
-
jQuery.each(data.deleted, function
|
847 |
jQuery('.gm-custom-meta-' + val).remove();
|
848 |
});
|
849 |
} else {
|
850 |
-
if
|
851 |
alert(data.error.message);
|
852 |
} else {
|
853 |
console.log(data);
|
@@ -857,65 +1100,67 @@ var GmediaFunction = {
|
|
857 |
});
|
858 |
|
859 |
|
860 |
-
jQuery('form.edit-gmedia').on('change', ':input', function
|
861 |
-
if(jQuery(this).hasClass('edit-gmedia-ignore')){
|
862 |
return;
|
863 |
}
|
864 |
jQuery('body').addClass('gmedia-busy');
|
|
|
865 |
var post_data = {
|
866 |
action: 'gmedia_update_data', data: jQuery(this).closest('form').serialize(), _wpnonce: jQuery('#_wpnonce').val()
|
867 |
};
|
868 |
-
jQuery.post(ajaxurl, post_data, function
|
869 |
console.log(data);
|
870 |
var item = jQuery('#list-item-' + data.ID);
|
871 |
item.find('.modified').text(data.modified);
|
872 |
//noinspection JSUnresolvedVariable
|
873 |
item.find('.status-album').attr('class', 'form-group status-album bg-status-' + data.album_status);
|
874 |
item.find('.status-item').attr('class', 'form-group status-item bg-status-' + data.status);
|
875 |
-
if
|
876 |
item.find('.gmedia_tags_input').val(data.tags);
|
877 |
}
|
878 |
//noinspection JSUnresolvedVariable
|
879 |
-
if
|
880 |
-
jQuery.each(data.meta_error, function
|
881 |
console.log(err);
|
882 |
alert(err.meta_key + ': ' + err.message);
|
883 |
-
if
|
884 |
jQuery('.gm-custom-field-' + err.meta_id).val(err.meta_value);
|
885 |
}
|
886 |
});
|
887 |
}
|
888 |
jQuery('body').removeClass('gmedia-busy');
|
|
|
889 |
});
|
890 |
});
|
891 |
|
892 |
-
gmedia_DOM.on('click', '.gm-toggle-cb', function
|
893 |
var checkBoxes = jQuery(this).attr('href');
|
894 |
-
jQuery(checkBoxes + ' :checkbox').each(function
|
895 |
jQuery(this).prop("checked", !jQuery(this).prop("checked"));
|
896 |
});
|
897 |
e.preventDefault();
|
898 |
});
|
899 |
-
jQuery('.linkblock').on('click', '[data-href]', function
|
900 |
window.location.href = jQuery(this).data('href');
|
901 |
});
|
902 |
|
903 |
-
jQuery('.gmedia-import').click(function
|
904 |
jQuery('#import-action').val(jQuery(this).attr('name'));
|
905 |
jQuery('#importModal').modal({
|
906 |
backdrop: 'static',
|
907 |
show: true,
|
908 |
keyboard: false
|
909 |
-
}).one('shown.bs.modal', function
|
910 |
jQuery('#import_form').submit();
|
911 |
-
}).one('hidden.bs.modal', function
|
912 |
var btn = jQuery('#import-done');
|
913 |
btn.text(btn.data('reset-text')).prop('disabled', true);
|
914 |
jQuery('#import_window').attr('src', 'about:blank');
|
915 |
});
|
916 |
});
|
917 |
|
918 |
-
jQuery('#gmedia_modules').on('click', '.module_install', function
|
919 |
e.preventDefault();
|
920 |
jQuery('body').addClass('gmedia-busy');
|
921 |
var module = jQuery(this).data('module');
|
@@ -925,21 +1170,22 @@ var GmediaFunction = {
|
|
925 |
action: 'gmedia_module_install', download: jQuery(this).attr('href'), module: module, _wpnonce: jQuery('#_wpnonce').val()
|
926 |
};
|
927 |
var pathname = window.location.href;
|
928 |
-
jQuery.post(ajaxurl, post_data, function
|
929 |
jQuery('#gmedia_modules').load(pathname + ' #gmedia_modules > *').before(data);
|
930 |
jQuery('body').removeClass('gmedia-busy');
|
931 |
});
|
932 |
});
|
933 |
|
934 |
-
jQuery('form').on('keydown', ':input:visible:not(:submit,:button,:reset,textarea)', function
|
935 |
var charCode = e.charCode || e.keyCode || e.which;
|
936 |
-
if
|
937 |
var inputs = jQuery(this).parents("form").eq(0).find(":input:visible");
|
938 |
var inp = inputs[inputs.index(this) + 1];
|
939 |
-
if
|
940 |
jQuery(inp).focus();
|
941 |
-
var inp_type = jQuery(
|
942 |
-
if
|
|
|
943 |
inp.setSelectionRange(0, inp.value.length);
|
944 |
}
|
945 |
}
|
@@ -948,29 +1194,29 @@ var GmediaFunction = {
|
|
948 |
}
|
949 |
});
|
950 |
|
951 |
-
var preset_popover = function
|
952 |
-
jQuery('#
|
953 |
container: '#module_preset',
|
954 |
-
content: function
|
955 |
-
return jQuery('#
|
956 |
},
|
957 |
html: true,
|
958 |
placement: 'bottom'
|
959 |
-
}).on('show.bs.popover', function
|
960 |
jQuery(this).addClass('active');
|
961 |
-
}).on('hide.bs.popover', function
|
962 |
jQuery(this).removeClass('active');
|
963 |
});
|
964 |
};
|
965 |
preset_popover();
|
966 |
-
jQuery('#module_preset').on('click', '.ajax-submit', function
|
967 |
e.preventDefault();
|
968 |
jQuery('body').addClass('gmedia-busy');
|
969 |
-
var form = jQuery('#gmedia-edit-
|
970 |
var post_data = form.serializeArray();
|
971 |
post_data.push({name: jQuery(this).attr('name'), value: 1});
|
972 |
var pathname = window.location.href;
|
973 |
-
jQuery.post(pathname, jQuery.param(post_data), function
|
974 |
jQuery('body').removeClass('gmedia-busy');
|
975 |
data = jQuery(data).find('#gmedia-container');
|
976 |
jQuery('#gm-message').append(jQuery('#gm-message', data).html());
|
@@ -980,14 +1226,14 @@ var GmediaFunction = {
|
|
980 |
preset_popover();
|
981 |
});
|
982 |
});
|
983 |
-
jQuery('body').on('click', function
|
984 |
-
if
|
985 |
&& jQuery(e.target).parents('.popover.in').length === 0) {
|
986 |
jQuery('[data-toggle="popover"]').popover('hide');
|
987 |
}
|
988 |
});
|
989 |
|
990 |
-
jQuery('#module_preset').on('click', '.delpreset span', function
|
991 |
jQuery('body').addClass('gmedia-busy');
|
992 |
var module_preset = this;
|
993 |
var preset_item_li = jQuery(this).closest('li');
|
@@ -995,33 +1241,35 @@ var GmediaFunction = {
|
|
995 |
var post_data = {
|
996 |
action: 'gmedia_module_preset_delete', preset_id: preset_id, _wpnonce: jQuery('#_wpnonce').val()
|
997 |
};
|
998 |
-
jQuery.post(ajaxurl, post_data, function
|
999 |
-
if
|
1000 |
jQuery('#gm-message').append(data.error);
|
1001 |
} else {
|
1002 |
preset_item_li.remove();
|
1003 |
-
|
1004 |
-
|
|
|
|
|
1005 |
}
|
1006 |
jQuery('body').removeClass('gmedia-busy');
|
1007 |
});
|
1008 |
});
|
1009 |
|
1010 |
-
if
|
1011 |
setPanelHeadersWidth();
|
1012 |
-
setTimeout(function
|
1013 |
setPanelHeadersWidth();
|
1014 |
}, 800);
|
1015 |
-
jQuery(window).resize(function
|
1016 |
setPanelHeadersWidth();
|
1017 |
});
|
1018 |
-
jQuery('#collapse-menu').click(function
|
1019 |
-
setTimeout(function
|
1020 |
setPanelHeadersWidth();
|
1021 |
}, 10);
|
1022 |
});
|
1023 |
|
1024 |
-
jQuery(window).scroll(function
|
1025 |
UpdatePanelHeaders();
|
1026 |
/*clearTimeout(jQuery.data(this, 'scrollTimer'));
|
1027 |
jQuery.data(this, 'scrollTimer', setTimeout(function() {
|
@@ -1035,34 +1283,56 @@ var GmediaFunction = {
|
|
1035 |
};
|
1036 |
|
1037 |
|
1038 |
-
|
1039 |
window.closeModal = function(id) {
|
1040 |
jQuery('#' + id).modal('hide');
|
1041 |
};
|
1042 |
|
1043 |
|
1044 |
-
|
1045 |
-
|
1046 |
/*
|
1047 |
* jQuery functions for GRAND Flash Media
|
1048 |
*/
|
1049 |
var gmedia_DOM;
|
1050 |
-
|
1051 |
-
gmedia_DOM =
|
1052 |
|
1053 |
GmediaSelect.init();
|
1054 |
GmediaFunction.init();
|
1055 |
-
GmediaLibrary.init();
|
1056 |
-
GmediaAddMedia.init();
|
1057 |
-
GmediaTerms.init();
|
1058 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1059 |
});
|
1060 |
|
1061 |
function convertInputsToJSON(form) {
|
1062 |
var array = jQuery(form).serializeArray();
|
1063 |
var json = {};
|
1064 |
|
1065 |
-
jQuery.each(array, function
|
1066 |
json[this.name] = this.value || '';
|
1067 |
});
|
1068 |
|
@@ -1074,33 +1344,33 @@ function gm_parse_query(s) {
|
|
1074 |
res = s.split(/&/gm).map(function(e) {
|
1075 |
var o = e.split(/=/),
|
1076 |
pt = j;
|
1077 |
-
if(typeof o[1] == 'undefined'){
|
1078 |
o[1] = '';
|
1079 |
}
|
1080 |
o[0].replace(/^(\w+)\[([^&]*)\]/, '$1][$2').split(/\]\[/).map(function(e, i, a) {
|
1081 |
-
if(e === ''){
|
1082 |
e = Object.keys(pt).length;
|
1083 |
}
|
1084 |
-
pt = (pt[e] = pt[e] || (i == a.length - 1
|
1085 |
});
|
1086 |
});
|
1087 |
return j;
|
1088 |
}
|
1089 |
|
1090 |
function validateEmail(email) {
|
1091 |
-
|
1092 |
return re.test(email);
|
1093 |
}
|
1094 |
|
1095 |
function getStorage(keyPprefix) {
|
1096 |
// use document.cookie:
|
1097 |
return {
|
1098 |
-
set: function
|
1099 |
document.cookie = keyPprefix + id + '=' + encodeURIComponent(data);
|
1100 |
},
|
1101 |
-
get: function
|
1102 |
var cookies = document.cookie, parsed = {};
|
1103 |
-
cookies.replace(/([^=]+)=([^;]*);?\s*/g, function
|
1104 |
parsed[key] = decodeURIComponent(value);
|
1105 |
});
|
1106 |
return parsed[keyPprefix + id];
|
@@ -1137,7 +1407,7 @@ function getStorage(keyPprefix) {
|
|
1137 |
*/
|
1138 |
|
1139 |
function UpdatePanelHeaders() {
|
1140 |
-
jQuery(".panel-fixed-header").each(function
|
1141 |
var el = jQuery(this),
|
1142 |
headerRow = jQuery(".panel-heading", this),
|
1143 |
offset = el.offset(),
|
@@ -1146,9 +1416,9 @@ function UpdatePanelHeaders() {
|
|
1146 |
absoluteHeader = "panel-absoluteHeader",
|
1147 |
pad_top = jQuery('#wpadminbar').height();
|
1148 |
|
1149 |
-
if
|
1150 |
el.addClass(floatingHeader).removeClass(absoluteHeader);
|
1151 |
-
} else if
|
1152 |
el.addClass(absoluteHeader).removeClass(floatingHeader);
|
1153 |
} else {
|
1154 |
el.removeClass(absoluteHeader + ' ' + floatingHeader)
|
@@ -1157,7 +1427,7 @@ function UpdatePanelHeaders() {
|
|
1157 |
}
|
1158 |
|
1159 |
function setPanelHeadersWidth() {
|
1160 |
-
jQuery(".panel-fixed-header").each(function
|
1161 |
var headerRow = jQuery(".panel-heading", this);
|
1162 |
headerRow.css("width", jQuery(this).innerWidth());
|
1163 |
jQuery(".panel-heading-fake", this).height(headerRow.outerHeight());
|
2 |
* Gmedia Library
|
3 |
*/
|
4 |
var GmediaLibrary = {
|
5 |
+
init: function() {
|
6 |
jQuery('#gm-selected').on('change', function() {
|
7 |
var val = jQuery(this).val();
|
8 |
jQuery('.edit-mode-link').each(function() {
|
14 |
});
|
15 |
}).trigger('change');
|
16 |
|
17 |
+
window.gm_wavesurfer = {};
|
18 |
+
if(jQuery('.gmedia-audio-item').length) {
|
19 |
+
|
20 |
+
jQuery('.gm-waveform-player').each(function() {
|
21 |
+
var data = jQuery(this).data();
|
22 |
+
data.gmid = data.id;
|
23 |
+
data.id = 'ws' + data.gmid;
|
24 |
+
|
25 |
+
if(data.peaks){
|
26 |
+
jQuery('.gm-play', this).show();
|
27 |
+
jQuery('.gm-pause', this).hide();
|
28 |
+
|
29 |
+
GmediaLibrary.waveplayer(data);
|
30 |
+
}
|
31 |
+
});
|
32 |
+
jQuery('.gm-waveform').on('click', function() {
|
33 |
+
var parent = jQuery(this).parent(),
|
34 |
+
data = parent.data();
|
35 |
+
|
36 |
+
jQuery(this).remove();
|
37 |
+
|
38 |
+
GmediaLibrary.waveplayer(data);
|
39 |
+
|
40 |
+
if(data.peaks) {
|
41 |
+
//window.gm_wavesurfer[data.id].play();
|
42 |
+
} else {
|
43 |
+
window.gm_wavesurfer[data.id].on('ready', function() {
|
44 |
+
jQuery('.gm-play', parent).show();
|
45 |
+
jQuery('.gm-pause', parent).hide();
|
46 |
+
jQuery('.spinner', parent).removeClass('is-active');
|
47 |
+
var peaks = window.gm_wavesurfer[data.id].exportPCM(1800, 10000, true);
|
48 |
+
var post_data = {
|
49 |
+
action: 'gmedia_save_waveform',
|
50 |
+
id: data.gmid,
|
51 |
+
peaks: peaks,
|
52 |
+
_wpnonce: jQuery('#_wpnonce').val()
|
53 |
+
};
|
54 |
+
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
55 |
+
var data_peaks = window.gm_wavesurfer[data.id].exportPCM(450, 10000, true);
|
56 |
+
parent.attr('data-peaks', data_peaks);
|
57 |
+
});
|
58 |
+
});
|
59 |
+
}
|
60 |
+
});
|
61 |
+
jQuery('.gm-play, .gm-pause').on('click', function() {
|
62 |
+
var parent = jQuery(this).parent(),
|
63 |
+
data = parent.data();
|
64 |
+
window.gm_wavesurfer[data.id].playPause();
|
65 |
+
});
|
66 |
+
|
67 |
+
var resize;
|
68 |
+
jQuery(window).on('resize', function(){
|
69 |
+
clearTimeout(resize);
|
70 |
+
resize = setTimeout(function(){
|
71 |
+
jQuery('.gm-waveform-player').each(function() {
|
72 |
+
var data = jQuery(this).data();
|
73 |
+
if(data.peaks && window.gm_wavesurfer[data.id]){
|
74 |
+
window.gm_wavesurfer[data.id].load(data.file, data.peaks);
|
75 |
+
}
|
76 |
+
});
|
77 |
+
}, 500);
|
78 |
+
});
|
79 |
+
|
80 |
+
}
|
81 |
+
|
82 |
+
if(jQuery('body').hasClass('GrandMedia_edit')) {
|
83 |
GmediaLibrary.editmode();
|
84 |
}
|
85 |
|
86 |
+
if(jQuery('body').hasClass('gmedia_library')) {
|
87 |
+
jQuery(window).on('load resize', function(){
|
88 |
+
jQuery('#previewFrame', window.parent.document).height(window.document.getElementById('gmedia_iframe_content').offsetHeight + 2);
|
89 |
+
});
|
90 |
+
|
91 |
+
var observer = new MutationObserver(function(mutations) {
|
92 |
+
jQuery('#previewFrame', window.parent.document).height(window.document.getElementById('gmedia_iframe_content').offsetHeight + 2);
|
93 |
+
jQuery('#previewModal', window.parent.document).attr('data-refresh', 'true');
|
94 |
+
});
|
95 |
+
var gmedia_iframe_content = window.document.getElementById('gmedia_iframe_content');
|
96 |
+
observer.observe(gmedia_iframe_content, {
|
97 |
+
childList: true,
|
98 |
+
subtree: true,
|
99 |
+
attributes: true,
|
100 |
+
attributeFilter: ['value']
|
101 |
+
});
|
102 |
+
}
|
103 |
+
|
104 |
+
},
|
105 |
+
waveplayer: function(data) {
|
106 |
+
window.gm_wavesurfer[data.id] = Object.create(WaveSurfer);
|
107 |
+
window.gm_wavesurfer[data.id].init({
|
108 |
+
container: '#' + data.id,
|
109 |
+
waveColor: '#428bca',
|
110 |
+
progressColor: '#31708f',
|
111 |
+
height: 60,
|
112 |
+
barWidth: 1
|
113 |
+
});
|
114 |
+
// Play on audio load
|
115 |
+
var parent = jQuery(window.gm_wavesurfer[data.id].container).parent();
|
116 |
+
|
117 |
+
if(!parent.hasClass('ws-loaded')) {
|
118 |
+
parent.addClass('ws-loaded');
|
119 |
+
|
120 |
+
window.gm_wavesurfer[data.id].load(data.file, data.peaks);
|
121 |
+
} else {
|
122 |
+
window.gm_wavesurfer[data.id].play();
|
123 |
+
}
|
124 |
+
|
125 |
+
jQuery(window.gm_wavesurfer[data.id].container).on('click', function() {
|
126 |
+
window.gm_wavesurfer[data.id].play();
|
127 |
+
});
|
128 |
+
|
129 |
+
window.gm_wavesurfer[data.id].on('play', function() {
|
130 |
+
parent.find('.gm-play').hide();
|
131 |
+
parent.find('.gm-pause').show();
|
132 |
+
parent.find('.spinner').removeClass('is-active');
|
133 |
+
|
134 |
+
jQuery.each(window.gm_wavesurfer, function(id) {
|
135 |
+
if(id !== data.id && window.gm_wavesurfer[id].isPlaying()) {
|
136 |
+
window.gm_wavesurfer[id].pause();
|
137 |
+
}
|
138 |
+
});
|
139 |
+
})
|
140 |
+
window.gm_wavesurfer[data.id].on('pause', function() {
|
141 |
+
parent.find('.gm-play').show();
|
142 |
+
parent.find('.gm-pause').hide();
|
143 |
+
});
|
144 |
+
window.gm_wavesurfer[data.id].on('loading', function(p) {
|
145 |
+
if(p == 100) {
|
146 |
+
//parent.find('.spinner').removeClass('is-active');
|
147 |
+
} else {
|
148 |
+
parent.find('.spinner').addClass('is-active');
|
149 |
+
}
|
150 |
+
});
|
151 |
},
|
152 |
/**
|
153 |
* Edit Mode
|
154 |
*/
|
155 |
editmode: function() {
|
156 |
+
var focus_input_val;
|
157 |
// SelectBox for albums
|
158 |
var combobox_albums = jQuery('.combobox_gmedia_album');
|
159 |
+
var selectize_albums = combobox_albums.selectize({
|
160 |
create: (combobox_albums.data('create')? true : false),
|
161 |
+
onOptionAdd: function(value, data){
|
162 |
+
jQuery.each(selectize_albums, function(i, e){
|
163 |
+
e.selectize.options[value] = data;
|
164 |
+
});
|
165 |
+
},
|
166 |
+
onFocus: function(){
|
167 |
+
this.$input.addClass('edit-gmedia-ignore');
|
168 |
+
focus_input_val = this.$input.val();
|
169 |
+
},
|
170 |
+
onBlur: function(){
|
171 |
+
this.$input.removeClass('edit-gmedia-ignore');
|
172 |
+
if(focus_input_val != this.$input.val()) {
|
173 |
+
this.$input.trigger('change');
|
174 |
+
}
|
175 |
+
},
|
176 |
+
persist: true
|
177 |
});
|
178 |
|
179 |
if(window.gmedia_categories) {
|
183 |
return {item: x};
|
184 |
});
|
185 |
|
186 |
+
var selectize_categories = categories.selectize({
|
187 |
create: function(input) {
|
188 |
if(categories.data('create')) {
|
189 |
return {
|
193 |
return false;
|
194 |
}
|
195 |
},
|
196 |
+
onOptionAdd: function(value, data){
|
197 |
+
jQuery.each(selectize_categories, function(i, e){
|
198 |
+
e.selectize.options[value] = data;
|
199 |
+
});
|
200 |
+
},
|
201 |
+
onFocus: function(){
|
202 |
+
this.$input.addClass('edit-gmedia-ignore');
|
203 |
+
focus_input_val = this.$input.val();
|
204 |
+
},
|
205 |
+
onBlur: function(){
|
206 |
+
this.$input.removeClass('edit-gmedia-ignore');
|
207 |
+
if(focus_input_val != this.$input.val()) {
|
208 |
+
this.$input.trigger('change');
|
209 |
+
}
|
210 |
+
},
|
211 |
createOnBlur: true,
|
212 |
delimiter: ',',
|
213 |
maxItems: null,
|
214 |
+
openOnFocus: true,
|
215 |
+
persist: true,
|
216 |
options: categories_data,
|
217 |
labelField: 'item',
|
218 |
valueField: 'item',
|
221 |
});
|
222 |
}
|
223 |
}
|
224 |
+
if(window.gmedia_tags) {
|
225 |
+
var tags = jQuery('.combobox_gmedia_tag');
|
226 |
+
if(tags.length) {
|
227 |
+
var tags_data = window.gmedia_tags.map(function(x) {
|
228 |
+
return {item: x};
|
229 |
+
});
|
230 |
+
|
231 |
+
var selectize_tags = tags.selectize({
|
232 |
+
create: function(input) {
|
233 |
+
if(this.$input.data('create')) {
|
234 |
+
var option = { item: input }
|
235 |
+
tags_data.push(option);
|
236 |
+
return option;
|
237 |
+
} else {
|
238 |
+
return false;
|
239 |
+
}
|
240 |
+
},
|
241 |
+
onOptionAdd: function(value, data){
|
242 |
+
jQuery.each(selectize_tags, function(i, e){
|
243 |
+
e.selectize.options[value] = data;
|
244 |
+
});
|
245 |
+
},
|
246 |
+
onFocus: function(){
|
247 |
+
this.$input.addClass('edit-gmedia-ignore');
|
248 |
+
focus_input_val = this.$input.val();
|
249 |
+
},
|
250 |
+
onBlur: function(){
|
251 |
+
this.$input.removeClass('edit-gmedia-ignore');
|
252 |
+
if(focus_input_val != this.$input.val()) {
|
253 |
+
this.$input.trigger('change');
|
254 |
+
}
|
255 |
+
},
|
256 |
+
createOnBlur: true,
|
257 |
+
delimiter: ',',
|
258 |
+
maxItems: null,
|
259 |
+
openOnFocus: true,
|
260 |
+
persist: true,
|
261 |
+
options: tags_data,
|
262 |
+
labelField: 'item',
|
263 |
+
valueField: 'item',
|
264 |
+
searchField: ['item'],
|
265 |
+
hideSelected: true
|
266 |
+
});
|
267 |
+
|
268 |
+
}
|
269 |
+
}
|
270 |
|
271 |
// Date/Time picker
|
272 |
var gmedia_date_temp;
|
304 |
* Gmedia AddMedia
|
305 |
*/
|
306 |
var GmediaAddMedia = {
|
307 |
+
init: function() {
|
308 |
|
309 |
+
if(jQuery('body').hasClass('GrandMedia_AddMedia')) {
|
310 |
+
jQuery('#uploader_runtime select').change(function() {
|
311 |
+
if('html4' == jQuery(this).val()) {
|
312 |
+
jQuery('#uploader_chunking').addClass('hide');
|
313 |
+
jQuery('#uploader_urlstream_upload').addClass('hide');
|
314 |
+
} else {
|
315 |
+
jQuery('#uploader_chunking').removeClass('hide');
|
316 |
+
jQuery('#uploader_urlstream_upload').removeClass('hide');
|
317 |
+
}
|
318 |
+
});
|
319 |
+
}
|
320 |
|
321 |
var albums = jQuery('select#combobox_gmedia_album');
|
322 |
if(albums.length) {
|
377 |
createOnBlur: true,
|
378 |
delimiter: ',',
|
379 |
maxItems: null,
|
380 |
+
openOnFocus: true,
|
381 |
persist: false,
|
382 |
options: tags_data,
|
383 |
labelField: 'item',
|
407 |
createOnBlur: true,
|
408 |
delimiter: ',',
|
409 |
maxItems: null,
|
410 |
+
openOnFocus: true,
|
411 |
persist: false,
|
412 |
options: categories_data,
|
413 |
labelField: 'item',
|
431 |
* Gmedia Terms
|
432 |
*/
|
433 |
var GmediaTerms = {
|
434 |
+
init: function() {
|
435 |
+
|
436 |
+
if(jQuery('body').hasClass('GrandMedia_Tags')) {
|
437 |
+
jQuery('#gm-list-table').data('edit', false);
|
438 |
+
jQuery('input.edit_tag_input').keypress(function(e) {
|
439 |
+
var tagdiv = jQuery('#tag_' + jQuery(this).data('tag_id'));
|
440 |
+
var charCode = e.charCode || e.keyCode || e.which;
|
441 |
+
if(charCode == 13) {
|
442 |
+
e.preventDefault();
|
443 |
+
edit_tag(tagdiv);
|
444 |
+
}
|
445 |
+
}).blur(function() {
|
446 |
+
var tagdiv = jQuery('#tag_' + jQuery(this).data('tag_id'));
|
447 |
+
edit_tag(tagdiv);
|
448 |
+
});
|
449 |
|
450 |
+
jQuery('.edit_tag_link').click(function(e) {
|
|
|
|
|
|
|
|
|
451 |
e.preventDefault();
|
452 |
+
var id = jQuery(this).attr('href');
|
453 |
+
jQuery(this).hide();
|
454 |
+
jQuery(id).find('.edit_tag_form').show().find('input').focus();
|
455 |
+
jQuery('#gm-list-table').data('edit', true);
|
456 |
+
});
|
457 |
+
jQuery('.edit_tag_save').click(function(e) {
|
458 |
+
e.preventDefault();
|
459 |
+
});
|
460 |
+
|
461 |
+
function edit_tag(tagdiv) {
|
462 |
+
var inp = tagdiv.find('.edit_tag_form input');
|
463 |
+
var new_tag_name = jQuery.trim(inp.val());
|
464 |
+
var old_tag_name = inp.attr('placeholder');
|
465 |
+
if((old_tag_name == new_tag_name) || ('' === new_tag_name) || jQuery.isNumeric()) {
|
466 |
+
inp.val(old_tag_name);
|
467 |
+
tagdiv.find('.edit_tag_form').hide();
|
468 |
+
tagdiv.find('.edit_tag_link').show();
|
469 |
+
return;
|
470 |
+
}
|
471 |
+
var post_data = {
|
472 |
+
action: 'gmedia_tag_edit',
|
473 |
+
tag_id: inp.data('tag_id'),
|
474 |
+
tag_name: new_tag_name,
|
475 |
+
_wpnonce: jQuery('#_wpnonce').val()
|
476 |
+
};
|
477 |
+
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
478 |
+
console.log(data);
|
479 |
+
if(data.error) {
|
480 |
+
//inp.val(inp.attr('placeholder'));
|
481 |
+
jQuery('#gmedia-panel').before(data.error);
|
482 |
+
} else {
|
483 |
+
//new_tag_name = new_tag_name.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
484 |
+
inp.attr('placeholder', new_tag_name);
|
485 |
+
tagdiv.find('.edit_tag_link').text(new_tag_name).show();
|
486 |
+
//noinspection JSUnresolvedVariable
|
487 |
+
jQuery('#gmedia-panel').before(data.msg);
|
488 |
+
tagdiv.find('.edit_tag_form').hide();
|
489 |
+
}
|
490 |
+
});
|
491 |
}
|
492 |
+
}
|
|
|
|
|
|
|
493 |
|
494 |
+
var input = jQuery('.term-shortcode input');
|
495 |
+
input.on('click', function() {
|
496 |
+
this.setSelectionRange(0, 0);
|
497 |
+
this.setSelectionRange(0, this.value.length);
|
|
|
|
|
498 |
});
|
499 |
+
input.on('change', function() {
|
500 |
+
shortcode_inp_autowidth(this);
|
501 |
});
|
502 |
+
jQuery.each(input, function(i, e) {
|
503 |
+
shortcode_inp_autowidth(this)
|
504 |
+
});
|
505 |
+
function shortcode_inp_autowidth(e) {
|
506 |
+
var inp = jQuery(e),
|
507 |
+
buffer = inp.next('.input-buffer');
|
508 |
+
buffer.text(inp.val());
|
509 |
+
inp.width(buffer.width());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
}
|
511 |
|
512 |
}
|
634 |
});
|
635 |
}
|
636 |
},
|
637 |
+
init: function() {
|
638 |
var cb_global = jQuery('#cb_global'),
|
639 |
cb_obj = cb_global.data('group');
|
640 |
|
641 |
+
if(jQuery('#gm-selected').length) {
|
642 |
GmediaSelect.msg_selected(cb_obj);
|
643 |
+
jQuery('#gm-selected-clear').click(function(e) {
|
644 |
jQuery('#gm-selected').val('');
|
645 |
GmediaSelect.chk_none(false, cb_obj);
|
646 |
GmediaSelect.msg_selected(cb_obj);
|
647 |
e.preventDefault();
|
648 |
});
|
649 |
+
jQuery('#gm-selected-show').click(function(e) {
|
650 |
jQuery('#gm-selected-btn').submit();
|
651 |
e.preventDefault();
|
652 |
});
|
653 |
+
jQuery('#gm-stack-in').click(function(e) {
|
654 |
e.preventDefault();
|
655 |
var stack_obj = jQuery('#gm-stack'),
|
656 |
sel_obj = jQuery('#gm-selected'),
|
667 |
//GmediaSelect.chk_none(false, cb_obj);
|
668 |
//GmediaSelect.msg_selected(cb_obj);
|
669 |
});
|
670 |
+
jQuery('#gm-stack-out').click(function(e) {
|
671 |
e.preventDefault();
|
672 |
var stack_obj = jQuery('#gm-stack'),
|
673 |
sel_obj = jQuery('#gm-selected'),
|
685 |
//GmediaSelect.msg_selected(cb_obj);
|
686 |
});
|
687 |
}
|
688 |
+
cb_global.click(function() {
|
689 |
+
if(jQuery(this).is(':checked')) {
|
690 |
GmediaSelect.chk_all(false, cb_obj);
|
691 |
} else {
|
692 |
GmediaSelect.chk_none(false, cb_obj);
|
693 |
}
|
694 |
GmediaSelect.msg_selected(cb_obj, true);
|
695 |
});
|
696 |
+
jQuery('#cb_global-btn li a').click(function(e) {
|
697 |
var sel = jQuery(this).data('select');
|
698 |
+
switch(sel) {
|
699 |
case 'total':
|
700 |
GmediaSelect.chk_all(false, cb_obj);
|
701 |
break;
|
714 |
GmediaSelect.msg_selected(cb_obj, true);
|
715 |
e.preventDefault();
|
716 |
});
|
717 |
+
jQuery('.cb_media-object input:checkbox, .cb_term-object input:checkbox').change(function() {
|
718 |
var selected = jQuery('#gm-selected'),
|
719 |
arr = selected.val();
|
720 |
var cur = jQuery(this).val();
|
721 |
+
if(jQuery(this).is(':checked')) {
|
722 |
+
if(arr) {
|
723 |
arr = arr + ',' + cur;
|
724 |
} else {
|
725 |
arr = cur;
|
726 |
}
|
727 |
} else {
|
728 |
+
arr = jQuery.grep(arr.split(','), function(a) {
|
729 |
return a != cur;
|
730 |
}).join(',');
|
731 |
}
|
734 |
GmediaSelect.msg_selected(cb_obj);
|
735 |
});
|
736 |
|
737 |
+
if(jQuery('#gm-stack').length) {
|
738 |
GmediaSelect.msg_stack();
|
739 |
+
jQuery('#gm-stack-clear').click(function(e) {
|
740 |
jQuery('#gm-stack').val('');
|
741 |
jQuery('.gm-stack input').prop('checked', false);
|
742 |
GmediaSelect.msg_stack();
|
743 |
e.preventDefault();
|
744 |
});
|
745 |
+
jQuery('#gm-stack-show').click(function(e) {
|
746 |
jQuery('#gm-stack-btn').submit();
|
747 |
e.preventDefault();
|
748 |
});
|
749 |
|
750 |
}
|
751 |
+
jQuery('.gm-stack input:checkbox').change(function() {
|
752 |
var selected = jQuery('#gm-stack'),
|
753 |
arr = selected.val();
|
754 |
var cur = jQuery(this).val();
|
755 |
+
if(jQuery(this).is(':checked')) {
|
756 |
+
if(arr) {
|
757 |
arr = arr + ',' + cur;
|
758 |
} else {
|
759 |
arr = cur;
|
760 |
}
|
761 |
} else {
|
762 |
+
arr = jQuery.grep(arr.split(','), function(a) {
|
763 |
return a != cur;
|
764 |
}).join(',');
|
765 |
}
|
767 |
GmediaSelect.msg_stack();
|
768 |
});
|
769 |
|
770 |
+
jQuery('.term-label').click(function(e) {
|
771 |
+
if('DIV' == e.target.nodeName) {
|
772 |
+
if(!jQuery('#gm-list-table').data('edit')) {
|
773 |
var cb = jQuery('input:checkbox', this);
|
774 |
cb.prop("checked", !cb.prop("checked")).change();
|
775 |
jQuery(this).closest('.term-list-item').toggleClass('gm-selected');
|
782 |
}
|
783 |
|
784 |
var GmediaFunction = {
|
785 |
+
confirm: function(txt) {
|
786 |
+
if(!txt) {
|
787 |
return true;
|
788 |
}
|
789 |
var r = false;
|
790 |
//noinspection UnusedCatchParameterJS
|
791 |
+
try{
|
792 |
r = confirm(txt);
|
793 |
}
|
794 |
+
catch(err){
|
795 |
alert('Disable Popup Blocker');
|
796 |
}
|
797 |
return r;
|
798 |
},
|
799 |
+
init: function() {
|
800 |
jQuery('#toplevel_page_GrandMedia').addClass('current').removeClass('wp-not-current-submenu');
|
801 |
+
if(!("ontouchstart" in document.documentElement)) {
|
802 |
jQuery('html').addClass('no-touch');
|
803 |
}
|
804 |
|
805 |
+
//jQuery(document).ajaxStart(function(a,b,c){
|
806 |
+
// //jQuery('body').addClass('gmedia-busy');
|
807 |
+
// jQuery('.panel-heading .spinner').addClass('is-active');
|
808 |
+
//}).ajaxStop(function(){
|
809 |
+
// //jQuery('body').removeClass('gmedia-busy');
|
810 |
+
// jQuery('.panel-heading .spinner').removeClass('is-active');
|
811 |
+
//});
|
812 |
|
813 |
+
jQuery('[data-confirm]').click(function() {
|
814 |
return GmediaFunction.confirm(jQuery(this).data('confirm'));
|
815 |
});
|
816 |
|
817 |
+
jQuery('.show-settings-link').click(function(e) {
|
818 |
e.preventDefault();
|
819 |
jQuery('#show-settings-link').trigger('click');
|
820 |
});
|
821 |
|
822 |
+
jQuery('.fit-thumbs').click(function(e) {
|
823 |
e.preventDefault();
|
824 |
jQuery(this).toggleClass('btn-success btn-default');
|
825 |
jQuery('.display-as-grid').toggleClass('invert-ratio');
|
826 |
jQuery.get(jQuery(this).attr('href'), {ajaxload: 1});
|
827 |
});
|
828 |
|
829 |
+
jQuery('.gm-cell-more-btn, .gm-cell-title').click(function() {
|
830 |
jQuery(this).parent().toggleClass('gm-cell-more-active');
|
831 |
});
|
832 |
|
833 |
jQuery('div.gmedia-modal').appendTo('body');
|
834 |
+
jQuery('a.gmedia-modal').click(function(e) {
|
835 |
jQuery('body').addClass('gmedia-busy');
|
836 |
var modal_div = jQuery(jQuery(this).attr('href'));
|
837 |
var post_data = {
|
838 |
action: jQuery(this).data('action'), modal: jQuery(this).data('modal'), _wpnonce: jQuery('#_wpnonce').val()
|
839 |
};
|
840 |
+
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
841 |
+
if(!data || ('-1' == data)) {
|
842 |
jQuery('body').removeClass('gmedia-busy');
|
843 |
alert(data);
|
844 |
return false;
|
848 |
backdrop: 'static',
|
849 |
show: true,
|
850 |
keyboard: false
|
851 |
+
}).one('hidden.bs.modal', function() {
|
852 |
jQuery('.modal-dialog', this).empty();
|
853 |
});
|
854 |
jQuery('body').removeClass('gmedia-busy');
|
856 |
e.preventDefault();
|
857 |
});
|
858 |
|
859 |
+
jQuery('a.gmedit-modal').click(function(e) {
|
860 |
e.preventDefault();
|
861 |
var modal_div = jQuery(jQuery(this).data('target'));
|
862 |
jQuery('.modal-content', modal_div).html(
|
872 |
backdrop: true,
|
873 |
show: true,
|
874 |
keyboard: false
|
875 |
+
}).one('hidden.bs.modal', function() {
|
876 |
jQuery('.modal-content', this).empty();
|
877 |
});
|
878 |
});
|
879 |
|
880 |
+
jQuery('a.preview-modal').click(function(e) {
|
881 |
e.preventDefault();
|
882 |
var data = jQuery(this).data(),
|
883 |
+
modal_div = jQuery(data['target']),
|
884 |
+
modal_dialog = jQuery('.modal-dialog', modal_div),
|
885 |
+
modal_body = jQuery('.modal-body', modal_div),
|
886 |
+
modal_title = jQuery('.modal-title', modal_div);
|
887 |
+
modal_title.text(jQuery(this).attr('data-title')? jQuery(this).attr('data-title') : jQuery(this).attr('title'));
|
888 |
+
|
889 |
+
if(data['metainfo']) {
|
890 |
+
modal_dialog.addClass('modal-md');
|
891 |
+
modal_body.html(jQuery('#metainfo_' + data['metainfo']).html());
|
892 |
} else {
|
893 |
var r = data['width'] / data['height'],
|
894 |
w = Math.min(jQuery(window).width() * 0.98 - 32, data['width']),
|
895 |
h = w / r;
|
896 |
+
modal_dialog.css({'width': (data['width'] + 32), 'max-width': '98%'});
|
897 |
+
if(data['cls']){
|
898 |
+
modal_dialog.addClass(data['cls']);
|
899 |
+
}
|
900 |
+
modal_body.html(
|
901 |
jQuery('<iframe />', {
|
902 |
name: 'previewFrame',
|
903 |
id: 'previewFrame',
|
904 |
width: '100%',
|
905 |
height: h,
|
906 |
+
src: jQuery(this).attr('href')
|
907 |
+
}).on('load', function(){
|
908 |
+
jQuery(this.contentWindow.document.body).css('margin', 0);
|
909 |
+
jQuery('.modal-backdrop', modal_div).css({'width': (data['width'] + 32), 'min-width': '100%'});
|
|
|
910 |
}).css({display: 'block', margin: '4px 0'})
|
911 |
);
|
912 |
}
|
914 |
modal_div.modal({
|
915 |
backdrop: true,
|
916 |
show: true
|
917 |
+
}).one('hidden.bs.modal', function() {
|
918 |
+
modal_title.empty();
|
919 |
+
modal_body.empty();
|
920 |
+
modal_dialog.removeAttr('style').attr('class', 'modal-dialog');
|
921 |
+
if(modal_div.attr('data-refresh')){
|
922 |
+
modal_div.removeAttr('data-refresh');
|
923 |
+
jQuery('.panel-heading .spinner').addClass('is-active');
|
924 |
+
var url = window.location.href;
|
925 |
+
jQuery.get(url, function(data) {
|
926 |
+
jQuery('#gmedia-panel').html(jQuery('#gmedia-panel', data).html());
|
927 |
+
GmediaInit();
|
928 |
+
});
|
929 |
+
}
|
930 |
});
|
931 |
});
|
932 |
|
933 |
+
jQuery('input.sharelink').on('click focus', function() {
|
934 |
this.setSelectionRange(0, this.value.length);
|
935 |
});
|
936 |
+
jQuery('input.sharetoemail').on('keyup', function() {
|
937 |
jQuery('.sharebutton').prop('disabled', !validateEmail(this.value));
|
938 |
});
|
939 |
+
jQuery('.sharebutton').on('click', function() {
|
940 |
var sharetoemail = jQuery('input.sharetoemail');
|
941 |
+
if(!validateEmail(sharetoemail.val())) {
|
942 |
sharetoemail.focus();
|
943 |
sharetoemail.parent().addClass('has-error');
|
944 |
return false;
|
945 |
}
|
946 |
var post_data = jQuery('#shareForm').serialize();
|
947 |
+
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
948 |
jQuery('body').removeClass('gmedia-busy');
|
949 |
+
if(data) {
|
950 |
jQuery('#gm-message').append(data);
|
951 |
}
|
952 |
});
|
953 |
jQuery('#shareModal').modal('hide');
|
954 |
});
|
955 |
+
jQuery('a.share-modal').click(function(e) {
|
956 |
e.preventDefault();
|
957 |
var data = jQuery(this).data(),
|
958 |
modal_div = jQuery(data['target']),
|
974 |
jQuery('.sharelink_page', modal_div).show();
|
975 |
jQuery('.sharelink_page input', modal_div).val(cloudlink);
|
976 |
jQuery('.sharelink_page a', modal_div).attr('href', cloudlink);
|
977 |
+
if(cloudlink_checked) {
|
978 |
jQuery('.sharelink_page input[type="radio"]', modal_div).prop('checked', true);
|
979 |
}
|
980 |
} else {
|
986 |
backdrop: true,
|
987 |
show: true,
|
988 |
keyboard: false
|
989 |
+
}).one('shown.bs.modal', function() {
|
990 |
jQuery('input.sharelink', this).focus();
|
991 |
+
}).one('hidden.bs.modal', function() {
|
992 |
jQuery('input.sharelink', this).val('');
|
993 |
});
|
994 |
});
|
995 |
|
996 |
+
jQuery('.buildquery-modal').click(function(e) {
|
997 |
e.preventDefault();
|
998 |
var data = jQuery(this).data(),
|
999 |
modal_div = jQuery(jQuery(this).attr('href')),
|
1000 |
query_field = jQuery(jQuery(this).attr('id') + '_field');
|
1001 |
+
query = query_field.val();
|
1002 |
|
1003 |
modal_div.modal({
|
1004 |
backdrop: false,
|
1005 |
show: true,
|
1006 |
keyboard: false
|
1007 |
+
}).one('shown.bs.modal', function() {
|
1008 |
+
if(query) {
|
1009 |
query = gm_parse_query(query);
|
1010 |
console.log(query);
|
1011 |
}
|
1012 |
+
}).one('hidden.bs.modal', function() {});
|
1013 |
});
|
1014 |
|
1015 |
+
jQuery('.buildquerysubmit').on('click', function() {
|
1016 |
+
var qform = jQuery('#buildQuery :input').filter(function() {
|
1017 |
return !!jQuery(this).val();
|
1018 |
});
|
1019 |
|
1022 |
jQuery('#build_query_field').val(qform);
|
1023 |
jQuery('#buildQuery').modal('hide');
|
1024 |
});
|
1025 |
+
jQuery('a.newcustomfield-modal').click(function(e) {
|
1026 |
e.preventDefault();
|
1027 |
var data = jQuery(this).data(),
|
1028 |
modal_div = jQuery(jQuery(this).attr('href'));
|
1031 |
backdrop: false,
|
1032 |
show: true,
|
1033 |
keyboard: false
|
1034 |
+
}).one('shown.bs.modal', function() {
|
1035 |
jQuery('input.newcustomfield-for-id', this).val(data['gmid']);
|
1036 |
+
}).one('hidden.bs.modal', function() {
|
1037 |
jQuery(':input.form-control, input.newcustomfield-for-id', this).val('');
|
1038 |
+
if(jQuery('.newcfield', this).length) {
|
1039 |
jQuery('a.gmediacustomstuff').click();
|
1040 |
}
|
1041 |
});
|
1042 |
});
|
1043 |
+
jQuery('.customfieldsubmit').on('click', function() {
|
1044 |
var cform = jQuery('#newCustomFieldForm');
|
1045 |
+
if(!jQuery('.newcustomfield-for-id', cform).val()) {
|
1046 |
jQuery('#newCustomFieldModal').modal('hide');
|
1047 |
alert('No ID');
|
1048 |
return false;
|
1049 |
}
|
1050 |
var post_data = cform.serialize();
|
1051 |
+
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
1052 |
jQuery('body').removeClass('gmedia-busy');
|
1053 |
+
if(data.success) {
|
1054 |
+
jQuery('#newCustomFieldModal').modal('hide').one('hidden.bs.modal', function() {
|
1055 |
//noinspection JSUnresolvedVariable
|
1056 |
+
if(data.newmeta_form) {
|
1057 |
//noinspection JSUnresolvedVariable
|
1058 |
jQuery('#newmeta').replaceWith(data.newmeta_form);
|
1059 |
}
|
1060 |
});
|
1061 |
jQuery('.row:last', '#gmediacustomstuff_' + data.id).append(data.success.data);
|
1062 |
} else {
|
1063 |
+
if(data.error) {
|
1064 |
+
if('100' == data.error.code) {
|
1065 |
jQuery('#newCustomFieldModal').modal('hide');
|
1066 |
}
|
1067 |
alert(data.error.message);
|
1071 |
}
|
1072 |
});
|
1073 |
});
|
1074 |
+
jQuery('.gmediacustomstuff').on('click', '.delete-custom-field', function() {
|
1075 |
var t = jQuery(this).closest('.form-group'),
|
1076 |
post_data = convertInputsToJSON(jQuery(':input', t));
|
1077 |
+
if(!post_data) {
|
1078 |
return false;
|
1079 |
}
|
1080 |
var meta_type = jQuery(this).closest('fieldset').attr('data-metatype');
|
1081 |
post_data.action = meta_type + '_delete_custom_field';
|
1082 |
post_data.ID = jQuery(this).closest('form').attr('data-id');
|
1083 |
post_data._customfield_nonce = jQuery('#_customfield_nonce').val();
|
1084 |
+
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
1085 |
jQuery('body').removeClass('gmedia-busy');
|
1086 |
//noinspection JSUnresolvedVariable
|
1087 |
+
if(data.deleted) {
|
1088 |
//noinspection JSUnresolvedVariable
|
1089 |
+
jQuery.each(data.deleted, function(i, val) {
|
1090 |
jQuery('.gm-custom-meta-' + val).remove();
|
1091 |
});
|
1092 |
} else {
|
1093 |
+
if(data.error) {
|
1094 |
alert(data.error.message);
|
1095 |
} else {
|
1096 |
console.log(data);
|
1100 |
});
|
1101 |
|
1102 |
|
1103 |
+
jQuery('form.edit-gmedia').on('change', ':input', function() {
|
1104 |
+
if(jQuery(this).hasClass('edit-gmedia-ignore')) {
|
1105 |
return;
|
1106 |
}
|
1107 |
jQuery('body').addClass('gmedia-busy');
|
1108 |
+
jQuery('.panel-heading .spinner').addClass('is-active');
|
1109 |
var post_data = {
|
1110 |
action: 'gmedia_update_data', data: jQuery(this).closest('form').serialize(), _wpnonce: jQuery('#_wpnonce').val()
|
1111 |
};
|
1112 |
+
jQuery.post(ajaxurl, post_data, function(data, textStatus, jqXHR) {
|
1113 |
console.log(data);
|
1114 |
var item = jQuery('#list-item-' + data.ID);
|
1115 |
item.find('.modified').text(data.modified);
|
1116 |
//noinspection JSUnresolvedVariable
|
1117 |
item.find('.status-album').attr('class', 'form-group status-album bg-status-' + data.album_status);
|
1118 |
item.find('.status-item').attr('class', 'form-group status-item bg-status-' + data.status);
|
1119 |
+
if(data.tags) {
|
1120 |
item.find('.gmedia_tags_input').val(data.tags);
|
1121 |
}
|
1122 |
//noinspection JSUnresolvedVariable
|
1123 |
+
if(data.meta_error) {
|
1124 |
+
jQuery.each(data.meta_error, function(i, err) {
|
1125 |
console.log(err);
|
1126 |
alert(err.meta_key + ': ' + err.message);
|
1127 |
+
if(err.meta_value) {
|
1128 |
jQuery('.gm-custom-field-' + err.meta_id).val(err.meta_value);
|
1129 |
}
|
1130 |
});
|
1131 |
}
|
1132 |
jQuery('body').removeClass('gmedia-busy');
|
1133 |
+
jQuery('.panel-heading .spinner').removeClass('is-active');
|
1134 |
});
|
1135 |
});
|
1136 |
|
1137 |
+
gmedia_DOM.on('click', '.gm-toggle-cb', function(e) {
|
1138 |
var checkBoxes = jQuery(this).attr('href');
|
1139 |
+
jQuery(checkBoxes + ' :checkbox').each(function() {
|
1140 |
jQuery(this).prop("checked", !jQuery(this).prop("checked"));
|
1141 |
});
|
1142 |
e.preventDefault();
|
1143 |
});
|
1144 |
+
jQuery('.linkblock').on('click', '[data-href]', function() {
|
1145 |
window.location.href = jQuery(this).data('href');
|
1146 |
});
|
1147 |
|
1148 |
+
jQuery('.gmedia-import').click(function() {
|
1149 |
jQuery('#import-action').val(jQuery(this).attr('name'));
|
1150 |
jQuery('#importModal').modal({
|
1151 |
backdrop: 'static',
|
1152 |
show: true,
|
1153 |
keyboard: false
|
1154 |
+
}).one('shown.bs.modal', function() {
|
1155 |
jQuery('#import_form').submit();
|
1156 |
+
}).one('hidden.bs.modal', function() {
|
1157 |
var btn = jQuery('#import-done');
|
1158 |
btn.text(btn.data('reset-text')).prop('disabled', true);
|
1159 |
jQuery('#import_window').attr('src', 'about:blank');
|
1160 |
});
|
1161 |
});
|
1162 |
|
1163 |
+
jQuery('#gmedia_modules').on('click', '.module_install', function(e) {
|
1164 |
e.preventDefault();
|
1165 |
jQuery('body').addClass('gmedia-busy');
|
1166 |
var module = jQuery(this).data('module');
|
1170 |
action: 'gmedia_module_install', download: jQuery(this).attr('href'), module: module, _wpnonce: jQuery('#_wpnonce').val()
|
1171 |
};
|
1172 |
var pathname = window.location.href;
|
1173 |
+
jQuery.post(ajaxurl, post_data, function(data, status, xhr) {
|
1174 |
jQuery('#gmedia_modules').load(pathname + ' #gmedia_modules > *').before(data);
|
1175 |
jQuery('body').removeClass('gmedia-busy');
|
1176 |
});
|
1177 |
});
|
1178 |
|
1179 |
+
jQuery('form').on('keydown', ':input:visible:not(:submit,:button,:reset,textarea)', function(e) {
|
1180 |
var charCode = e.charCode || e.keyCode || e.which;
|
1181 |
+
if(13 == charCode && !jQuery(this).parent().hasClass('selectize-input')) {
|
1182 |
var inputs = jQuery(this).parents("form").eq(0).find(":input:visible");
|
1183 |
var inp = inputs[inputs.index(this) + 1];
|
1184 |
+
if(inp !== null) {
|
1185 |
jQuery(inp).focus();
|
1186 |
+
var inp_type = jQuery(inp).attr('type');
|
1187 |
+
if(!!inp_type && (inp_type == 'text' || inp_type == 'number')) {
|
1188 |
+
console.log(inp);
|
1189 |
inp.setSelectionRange(0, inp.value.length);
|
1190 |
}
|
1191 |
}
|
1194 |
}
|
1195 |
});
|
1196 |
|
1197 |
+
var preset_popover = function() {
|
1198 |
+
jQuery('#module_presets').popover({
|
1199 |
container: '#module_preset',
|
1200 |
+
content: function() {
|
1201 |
+
return jQuery('#_module_presets').html();
|
1202 |
},
|
1203 |
html: true,
|
1204 |
placement: 'bottom'
|
1205 |
+
}).on('show.bs.popover', function() {
|
1206 |
jQuery(this).addClass('active');
|
1207 |
+
}).on('hide.bs.popover', function() {
|
1208 |
jQuery(this).removeClass('active');
|
1209 |
});
|
1210 |
};
|
1211 |
preset_popover();
|
1212 |
+
jQuery('#module_preset').on('click', '.ajax-submit', function(e) {
|
1213 |
e.preventDefault();
|
1214 |
jQuery('body').addClass('gmedia-busy');
|
1215 |
+
var form = jQuery('#gmedia-edit-term');
|
1216 |
var post_data = form.serializeArray();
|
1217 |
post_data.push({name: jQuery(this).attr('name'), value: 1});
|
1218 |
var pathname = window.location.href;
|
1219 |
+
jQuery.post(pathname, jQuery.param(post_data), function(data, status, xhr) {
|
1220 |
jQuery('body').removeClass('gmedia-busy');
|
1221 |
data = jQuery(data).find('#gmedia-container');
|
1222 |
jQuery('#gm-message').append(jQuery('#gm-message', data).html());
|
1226 |
preset_popover();
|
1227 |
});
|
1228 |
});
|
1229 |
+
jQuery('body').on('click', function(e) {
|
1230 |
+
if(jQuery(e.target).data('toggle') !== 'popover'
|
1231 |
&& jQuery(e.target).parents('.popover.in').length === 0) {
|
1232 |
jQuery('[data-toggle="popover"]').popover('hide');
|
1233 |
}
|
1234 |
});
|
1235 |
|
1236 |
+
jQuery('#module_preset, .module_presets').on('click', '.delpreset span', function() {
|
1237 |
jQuery('body').addClass('gmedia-busy');
|
1238 |
var module_preset = this;
|
1239 |
var preset_item_li = jQuery(this).closest('li');
|
1241 |
var post_data = {
|
1242 |
action: 'gmedia_module_preset_delete', preset_id: preset_id, _wpnonce: jQuery('#_wpnonce').val()
|
1243 |
};
|
1244 |
+
jQuery.post(ajaxurl, post_data, function(data, status, xhr) {
|
1245 |
+
if(data.error) {
|
1246 |
jQuery('#gm-message').append(data.error);
|
1247 |
} else {
|
1248 |
preset_item_li.remove();
|
1249 |
+
if('module_presets_list' !== jQuery(this).attr('id')) {
|
1250 |
+
var _module_presets = jQuery('#module_preset').find('.popover-content').html();
|
1251 |
+
jQuery('#_module_presets').replaceWith('<script type="text/html" id="_module_presets">' + _module_presets + '</script>');
|
1252 |
+
}
|
1253 |
}
|
1254 |
jQuery('body').removeClass('gmedia-busy');
|
1255 |
});
|
1256 |
});
|
1257 |
|
1258 |
+
if(jQuery(".panel-fixed-header").length) {
|
1259 |
setPanelHeadersWidth();
|
1260 |
+
setTimeout(function() {
|
1261 |
setPanelHeadersWidth();
|
1262 |
}, 800);
|
1263 |
+
jQuery(window).resize(function() {
|
1264 |
setPanelHeadersWidth();
|
1265 |
});
|
1266 |
+
jQuery('#collapse-menu').click(function() {
|
1267 |
+
setTimeout(function() {
|
1268 |
setPanelHeadersWidth();
|
1269 |
}, 10);
|
1270 |
});
|
1271 |
|
1272 |
+
jQuery(window).scroll(function() {
|
1273 |
UpdatePanelHeaders();
|
1274 |
/*clearTimeout(jQuery.data(this, 'scrollTimer'));
|
1275 |
jQuery.data(this, 'scrollTimer', setTimeout(function() {
|
1283 |
};
|
1284 |
|
1285 |
|
|
|
1286 |
window.closeModal = function(id) {
|
1287 |
jQuery('#' + id).modal('hide');
|
1288 |
};
|
1289 |
|
1290 |
|
|
|
|
|
1291 |
/*
|
1292 |
* jQuery functions for GRAND Flash Media
|
1293 |
*/
|
1294 |
var gmedia_DOM;
|
1295 |
+
function GmediaInit(){
|
1296 |
+
gmedia_DOM = jQuery('#gmedia-container');
|
1297 |
|
1298 |
GmediaSelect.init();
|
1299 |
GmediaFunction.init();
|
|
|
|
|
|
|
1300 |
|
1301 |
+
if(jQuery('body').hasClass('GrandMedia')) {
|
1302 |
+
GmediaLibrary.init();
|
1303 |
+
}
|
1304 |
+
if(jQuery('body').hasClass('GrandMedia_AddMedia')) {
|
1305 |
+
GmediaAddMedia.init();
|
1306 |
+
}
|
1307 |
+
if(jQuery('body').is('.GrandMedia_Tags,.GrandMedia_Categories,.GrandMedia_Albums,.GrandMedia_Galleries')) {
|
1308 |
+
GmediaTerms.init();
|
1309 |
+
}
|
1310 |
+
|
1311 |
+
var helper, title;
|
1312 |
+
jQuery('[title]', gmedia_DOM).each(function(){
|
1313 |
+
title = jQuery(this).attr('title');
|
1314 |
+
jQuery(this).removeAttr('title').attr('data-title', title);
|
1315 |
+
});
|
1316 |
+
title = null;
|
1317 |
+
jQuery(gmedia_DOM).on('mouseenter', '[data-title]', function(e) {
|
1318 |
+
helper = jQuery('<div id="gmedia-data-helper">' + jQuery(this).attr('data-title') + '</div>').appendTo('body');
|
1319 |
+
helper.css({left: e.clientX - 25, top: e.clientY + 25});
|
1320 |
+
}).on('mousemove', '[data-title]', function(e) {
|
1321 |
+
helper.css({left: e.clientX - 25, top: e.clientY + 25});
|
1322 |
+
}).on('mouseleave', '[data-title]', function(e) {
|
1323 |
+
jQuery('#gmedia-data-helper').remove();
|
1324 |
+
helper = null;
|
1325 |
+
});
|
1326 |
+
}
|
1327 |
+
jQuery(document).on('ready', function() {
|
1328 |
+
GmediaInit();
|
1329 |
});
|
1330 |
|
1331 |
function convertInputsToJSON(form) {
|
1332 |
var array = jQuery(form).serializeArray();
|
1333 |
var json = {};
|
1334 |
|
1335 |
+
jQuery.each(array, function() {
|
1336 |
json[this.name] = this.value || '';
|
1337 |
});
|
1338 |
|
1344 |
res = s.split(/&/gm).map(function(e) {
|
1345 |
var o = e.split(/=/),
|
1346 |
pt = j;
|
1347 |
+
if(typeof o[1] == 'undefined') {
|
1348 |
o[1] = '';
|
1349 |
}
|
1350 |
o[0].replace(/^(\w+)\[([^&]*)\]/, '$1][$2').split(/\]\[/).map(function(e, i, a) {
|
1351 |
+
if(e === '') {
|
1352 |
e = Object.keys(pt).length;
|
1353 |
}
|
1354 |
+
pt = (pt[e] = pt[e] || (i == a.length - 1? decodeURIComponent(o[1].replace(/\+/, ' ')) : {}));
|
1355 |
});
|
1356 |
});
|
1357 |
return j;
|
1358 |
}
|
1359 |
|
1360 |
function validateEmail(email) {
|
1361 |
+
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
1362 |
return re.test(email);
|
1363 |
}
|
1364 |
|
1365 |
function getStorage(keyPprefix) {
|
1366 |
// use document.cookie:
|
1367 |
return {
|
1368 |
+
set: function(id, data) {
|
1369 |
document.cookie = keyPprefix + id + '=' + encodeURIComponent(data);
|
1370 |
},
|
1371 |
+
get: function(id) {
|
1372 |
var cookies = document.cookie, parsed = {};
|
1373 |
+
cookies.replace(/([^=]+)=([^;]*);?\s*/g, function(whole, key, value) {
|
1374 |
parsed[key] = decodeURIComponent(value);
|
1375 |
});
|
1376 |
return parsed[keyPprefix + id];
|
1407 |
*/
|
1408 |
|
1409 |
function UpdatePanelHeaders() {
|
1410 |
+
jQuery(".panel-fixed-header").each(function() {
|
1411 |
var el = jQuery(this),
|
1412 |
headerRow = jQuery(".panel-heading", this),
|
1413 |
offset = el.offset(),
|
1416 |
absoluteHeader = "panel-absoluteHeader",
|
1417 |
pad_top = jQuery('#wpadminbar').height();
|
1418 |
|
1419 |
+
if((scrollTop > offset.top - pad_top) && (scrollTop < offset.top - pad_top + (el.height() - headerRow.outerHeight(false)) + 4)) {
|
1420 |
el.addClass(floatingHeader).removeClass(absoluteHeader);
|
1421 |
+
} else if(scrollTop > (offset.top - pad_top + (el.height() - headerRow.outerHeight(false)))) {
|
1422 |
el.addClass(absoluteHeader).removeClass(floatingHeader);
|
1423 |
} else {
|
1424 |
el.removeClass(absoluteHeader + ' ' + floatingHeader)
|
1427 |
}
|
1428 |
|
1429 |
function setPanelHeadersWidth() {
|
1430 |
+
jQuery(".panel-fixed-header").each(function() {
|
1431 |
var headerRow = jQuery(".panel-heading", this);
|
1432 |
headerRow.css("width", jQuery(this).innerWidth());
|
1433 |
jQuery(".panel-heading-fake", this).height(headerRow.outerHeight());
|
admin/class.processor.php
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Class GmediaProcessor
|
4 |
*/
|
5 |
-
class GmediaProcessor
|
6 |
|
7 |
public $page;
|
|
|
8 |
public $url;
|
9 |
public $msg;
|
10 |
public $error;
|
@@ -13,15 +15,16 @@ class GmediaProcessor {
|
|
13 |
/**
|
14 |
* initiate the manage page
|
15 |
*/
|
16 |
-
public function __construct()
|
17 |
global $pagenow, $gmCore;
|
18 |
// GET variables
|
19 |
$this->page = $gmCore->_get('page');
|
20 |
-
$this->
|
21 |
-
|
|
|
22 |
add_filter('wp_redirect', array($this, 'redirect'), 10, 2);
|
23 |
}
|
24 |
-
if('edit-comments.php' === $pagenow)
|
25 |
add_filter('get_comment_text', array($this, 'gmedia_comment_text'), 10, 3);
|
26 |
}
|
27 |
|
@@ -32,11 +35,11 @@ class GmediaProcessor {
|
|
32 |
/**
|
33 |
* load only on Gmedia admin pages
|
34 |
*/
|
35 |
-
public function controller()
|
36 |
|
37 |
$this->user_options = self::user_options();
|
38 |
|
39 |
-
if(!$this->page || strpos($this->page, 'GrandMedia') === false)
|
40 |
return;
|
41 |
}
|
42 |
|
@@ -49,36 +52,36 @@ class GmediaProcessor {
|
|
49 |
/**
|
50 |
* Do diff process before lib shell
|
51 |
*/
|
52 |
-
protected function processor()
|
53 |
|
54 |
/**
|
55 |
* @return array|mixed
|
56 |
*/
|
57 |
-
public static function user_options()
|
58 |
global $user_ID, $gmGallery;
|
59 |
|
60 |
$screen_options = get_user_meta($user_ID, 'gm_screen_options', true);
|
61 |
-
if(!is_array($screen_options))
|
62 |
$screen_options = array();
|
63 |
}
|
|
|
64 |
return array_merge($gmGallery->options['gm_screen_options'], $screen_options);
|
65 |
}
|
66 |
|
67 |
/**
|
68 |
* @param string $cookie_key
|
69 |
-
*
|
70 |
* @param string $post_key
|
71 |
*
|
72 |
* @return array
|
73 |
*/
|
74 |
-
public static function selected_items($cookie_key, $post_key = 'selected_items')
|
75 |
|
76 |
$selected_items = array();
|
77 |
-
if($cookie_key)
|
78 |
-
if(isset($_POST[$post_key]))
|
79 |
-
$selected_items = array_filter(explode(',', $_POST[$post_key]), 'is_numeric');
|
80 |
-
} elseif(isset($_COOKIE[$cookie_key]))
|
81 |
-
$selected_items = array_filter(explode(',', $_COOKIE[$cookie_key]), 'is_numeric');
|
82 |
}
|
83 |
}
|
84 |
|
@@ -90,13 +93,14 @@ class GmediaProcessor {
|
|
90 |
*
|
91 |
* @return array
|
92 |
*/
|
93 |
-
public function clear_selected_items($cookie_key)
|
94 |
global $user_ID;
|
95 |
|
96 |
-
if($cookie_key)
|
97 |
setcookie("gmuser_{$user_ID}_{$cookie_key}", '', time() - 3600);
|
98 |
unset($_COOKIE["gmuser_{$user_ID}_{$cookie_key}"]);
|
99 |
}
|
|
|
100 |
return array();
|
101 |
}
|
102 |
|
@@ -105,17 +109,19 @@ class GmediaProcessor {
|
|
105 |
*
|
106 |
* @return array|mixed
|
107 |
*/
|
108 |
-
public static function filter_by_author($author_id_list = false)
|
109 |
global $user_ID, $gmCore;
|
110 |
|
111 |
-
$
|
112 |
-
|
113 |
-
if(
|
114 |
-
$author =
|
|
|
|
|
|
|
|
|
115 |
$author = array_intersect(array($user_ID, 0), $author);
|
116 |
}
|
117 |
-
} else {
|
118 |
-
$author = array($user_ID, 0);
|
119 |
}
|
120 |
|
121 |
return $author;
|
@@ -129,12 +135,12 @@ class GmediaProcessor {
|
|
129 |
*
|
130 |
* @return mixed
|
131 |
*/
|
132 |
-
public function redirect($location, $status)
|
133 |
global $pagenow;
|
134 |
-
if('media.php' === $pagenow && isset($_POST['_wp_original_http_referer']))
|
135 |
-
if(strpos($_POST['_wp_original_http_referer'], 'GrandMedia') !== false)
|
136 |
return $_POST['_wp_original_http_referer'];
|
137 |
-
} else
|
138 |
return $location;
|
139 |
}
|
140 |
}
|
@@ -151,28 +157,29 @@ class GmediaProcessor {
|
|
151 |
*
|
152 |
* @return string $comment_content
|
153 |
*/
|
154 |
-
function gmedia_comment_text($comment_content, $comment, $args)
|
155 |
global $post;
|
156 |
if(!$post){
|
157 |
return $comment_content;
|
158 |
}
|
159 |
//if('gmedia' == substr($post->post_type, 0, 6)) {
|
160 |
-
if('gmedia' == $post->post_type)
|
161 |
global $gmDB, $gmCore;
|
162 |
-
$gmedia
|
163 |
-
$thumb
|
164 |
$comment_content = $thumb . $comment_content;
|
165 |
}
|
|
|
166 |
return $comment_content;
|
167 |
}
|
168 |
|
169 |
/**
|
170 |
* Autoloader
|
171 |
*/
|
172 |
-
public static function autoload()
|
173 |
$path_ = GMEDIA_ABSPATH . '/admin/processor/class.processor.';
|
174 |
-
$page
|
175 |
-
switch($page)
|
176 |
case 'GrandMedia':
|
177 |
include_once($path_ . 'library.php');
|
178 |
break;
|
@@ -205,4 +212,5 @@ class GmediaProcessor {
|
|
205 |
|
206 |
|
207 |
}
|
|
|
208 |
GmediaProcessor::autoload();
|
1 |
<?php
|
2 |
+
|
3 |
/**
|
4 |
* Class GmediaProcessor
|
5 |
*/
|
6 |
+
class GmediaProcessor{
|
7 |
|
8 |
public $page;
|
9 |
+
public $gmediablank;
|
10 |
public $url;
|
11 |
public $msg;
|
12 |
public $error;
|
15 |
/**
|
16 |
* initiate the manage page
|
17 |
*/
|
18 |
+
public function __construct(){
|
19 |
global $pagenow, $gmCore;
|
20 |
// GET variables
|
21 |
$this->page = $gmCore->_get('page');
|
22 |
+
$this->gmediablank = $gmCore->_get('gmediablank');
|
23 |
+
$this->url = add_query_arg(array('page' => $this->page, 'gmediablank' => $this->gmediablank), admin_url('admin.php'));
|
24 |
+
if('media.php' === $pagenow){
|
25 |
add_filter('wp_redirect', array($this, 'redirect'), 10, 2);
|
26 |
}
|
27 |
+
if('edit-comments.php' === $pagenow){
|
28 |
add_filter('get_comment_text', array($this, 'gmedia_comment_text'), 10, 3);
|
29 |
}
|
30 |
|
35 |
/**
|
36 |
* load only on Gmedia admin pages
|
37 |
*/
|
38 |
+
public function controller(){
|
39 |
|
40 |
$this->user_options = self::user_options();
|
41 |
|
42 |
+
if(!$this->page || strpos($this->page, 'GrandMedia') === false){
|
43 |
return;
|
44 |
}
|
45 |
|
52 |
/**
|
53 |
* Do diff process before lib shell
|
54 |
*/
|
55 |
+
protected function processor(){ }
|
56 |
|
57 |
/**
|
58 |
* @return array|mixed
|
59 |
*/
|
60 |
+
public static function user_options(){
|
61 |
global $user_ID, $gmGallery;
|
62 |
|
63 |
$screen_options = get_user_meta($user_ID, 'gm_screen_options', true);
|
64 |
+
if(!is_array($screen_options)){
|
65 |
$screen_options = array();
|
66 |
}
|
67 |
+
|
68 |
return array_merge($gmGallery->options['gm_screen_options'], $screen_options);
|
69 |
}
|
70 |
|
71 |
/**
|
72 |
* @param string $cookie_key
|
|
|
73 |
* @param string $post_key
|
74 |
*
|
75 |
* @return array
|
76 |
*/
|
77 |
+
public static function selected_items($cookie_key, $post_key = 'selected_items'){
|
78 |
|
79 |
$selected_items = array();
|
80 |
+
if($cookie_key){
|
81 |
+
if(isset($_POST[ $post_key ])){
|
82 |
+
$selected_items = array_filter(explode(',', $_POST[ $post_key ]), 'is_numeric');
|
83 |
+
} elseif(isset($_COOKIE[ $cookie_key ])){
|
84 |
+
$selected_items = array_filter(explode(',', $_COOKIE[ $cookie_key ]), 'is_numeric');
|
85 |
}
|
86 |
}
|
87 |
|
93 |
*
|
94 |
* @return array
|
95 |
*/
|
96 |
+
public function clear_selected_items($cookie_key){
|
97 |
global $user_ID;
|
98 |
|
99 |
+
if($cookie_key){
|
100 |
setcookie("gmuser_{$user_ID}_{$cookie_key}", '', time() - 3600);
|
101 |
unset($_COOKIE["gmuser_{$user_ID}_{$cookie_key}"]);
|
102 |
}
|
103 |
+
|
104 |
return array();
|
105 |
}
|
106 |
|
109 |
*
|
110 |
* @return array|mixed
|
111 |
*/
|
112 |
+
public static function filter_by_author($author_id_list = false){
|
113 |
global $user_ID, $gmCore;
|
114 |
|
115 |
+
if($author_id_list === false){
|
116 |
+
$author = false;
|
117 |
+
if(!$gmCore->caps['gmedia_show_others_media']){
|
118 |
+
$author = array($user_ID, 0);
|
119 |
+
}
|
120 |
+
} else{
|
121 |
+
$author = wp_parse_id_list($author_id_list);
|
122 |
+
if(!$gmCore->caps['gmedia_show_others_media']){
|
123 |
$author = array_intersect(array($user_ID, 0), $author);
|
124 |
}
|
|
|
|
|
125 |
}
|
126 |
|
127 |
return $author;
|
135 |
*
|
136 |
* @return mixed
|
137 |
*/
|
138 |
+
public function redirect($location, $status){
|
139 |
global $pagenow;
|
140 |
+
if('media.php' === $pagenow && isset($_POST['_wp_original_http_referer'])){
|
141 |
+
if(strpos($_POST['_wp_original_http_referer'], 'GrandMedia') !== false){
|
142 |
return $_POST['_wp_original_http_referer'];
|
143 |
+
} else{
|
144 |
return $location;
|
145 |
}
|
146 |
}
|
157 |
*
|
158 |
* @return string $comment_content
|
159 |
*/
|
160 |
+
function gmedia_comment_text($comment_content, $comment, $args){
|
161 |
global $post;
|
162 |
if(!$post){
|
163 |
return $comment_content;
|
164 |
}
|
165 |
//if('gmedia' == substr($post->post_type, 0, 6)) {
|
166 |
+
if('gmedia' == $post->post_type){
|
167 |
global $gmDB, $gmCore;
|
168 |
+
$gmedia = $gmDB->get_post_gmedia($post->ID);
|
169 |
+
$thumb = '<div class="alignright" style="clear:right;"><img class="gmedia-thumb" style="max-height:72px;" src="' . $gmCore->gm_get_media_image($gmedia, 'thumb', false) . '" alt=""/></div>';
|
170 |
$comment_content = $thumb . $comment_content;
|
171 |
}
|
172 |
+
|
173 |
return $comment_content;
|
174 |
}
|
175 |
|
176 |
/**
|
177 |
* Autoloader
|
178 |
*/
|
179 |
+
public static function autoload(){
|
180 |
$path_ = GMEDIA_ABSPATH . '/admin/processor/class.processor.';
|
181 |
+
$page = isset($_GET['page'])? $_GET['page'] : '';
|
182 |
+
switch($page){
|
183 |
case 'GrandMedia':
|
184 |
include_once($path_ . 'library.php');
|
185 |
break;
|
212 |
|
213 |
|
214 |
}
|
215 |
+
|
216 |
GmediaProcessor::autoload();
|
admin/functions.php
CHANGED
@@ -1,125 +1,125 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
function gm_get_admin_url($add_args = array(), $remove_args = array(), $uri = false)
|
4 |
global $gmCore;
|
5 |
|
6 |
-
return $gmCore->get_admin_url($add_args, $remove_args, $uri);
|
7 |
}
|
8 |
|
9 |
-
function gm_panel_classes($classes)
|
10 |
echo implode(' ', (array)$classes);
|
11 |
}
|
12 |
|
13 |
-
function gm_user_can($capability)
|
14 |
global $gmCore;
|
15 |
|
16 |
-
return isset($gmCore->caps['gmedia_' . $capability])? $gmCore->caps['gmedia_' . $capability] : false;
|
17 |
}
|
18 |
|
19 |
-
function gmedia_term_choose_author_field($selected = false)
|
20 |
global $gmCore;
|
21 |
|
22 |
$user_ID = get_current_user_id();
|
23 |
-
if(false === $selected)
|
24 |
$selected = $user_ID;
|
25 |
}
|
26 |
|
27 |
$user_ids = gm_user_can('delete_others_media')? $gmCore->get_editable_user_ids() : array($user_ID);
|
28 |
-
if($user_ids && gm_user_can('edit_others_media'))
|
29 |
-
if(!in_array($user_ID, $user_ids))
|
30 |
array_push($user_ids, $user_ID);
|
31 |
}
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
42 |
echo '<input type="hidden" name="term[global]" value="' . $user_ID . '"/>';
|
43 |
echo '<div>' . get_the_author_meta('display_name', $user_ID) . '</div>';
|
44 |
}
|
45 |
}
|
46 |
|
47 |
/** Get available modules
|
|
|
48 |
* @param bool|true $including_remote
|
49 |
*
|
50 |
* @return array
|
51 |
*/
|
52 |
-
function get_gmedia_modules($including_remote = true)
|
53 |
global $gmCore, $gmGallery;
|
54 |
|
55 |
$modules = array();
|
56 |
$modules['in'] = $gmCore->modules_order();
|
57 |
-
if(($plugin_modules = glob(GMEDIA_ABSPATH . 'module/*', GLOB_ONLYDIR | GLOB_NOSORT)))
|
58 |
-
foreach($plugin_modules as $path)
|
59 |
-
$mfold
|
60 |
-
$modules['in'][$mfold] = array(
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
'module_path' => $path
|
65 |
);
|
66 |
}
|
67 |
}
|
68 |
-
if(($upload_modules = glob($gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/*', GLOB_ONLYDIR | GLOB_NOSORT)))
|
69 |
-
foreach($upload_modules as $path)
|
70 |
-
$mfold
|
71 |
-
$modules['in'][$mfold] = array(
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
'module_path' => $path
|
76 |
);
|
77 |
}
|
78 |
}
|
79 |
|
80 |
$modules['in'] = array_filter($modules['in']);
|
81 |
|
82 |
-
if(isset($modules['in']) && !empty($modules['in']))
|
83 |
-
foreach($modules['in'] as $mfold => $module)
|
84 |
// todo: get broken modules folders and delete them
|
85 |
-
if(!file_exists($module['module_path'] . '/index.php'))
|
86 |
-
unset($modules['in'][$mfold]);
|
87 |
continue;
|
88 |
}
|
89 |
$module_info = array();
|
90 |
include($module['module_path'] . '/index.php');
|
91 |
-
if(empty($module_info))
|
92 |
-
unset($modules['in'][$mfold]);
|
93 |
continue;
|
94 |
}
|
95 |
-
$modules['in'][$mfold] = array_merge($module, (array)$module_info);
|
96 |
-
$modules['in'][$mfold]['update'] = false;
|
97 |
}
|
98 |
}
|
99 |
|
100 |
-
if($including_remote)
|
101 |
$get_xml = wp_remote_get($gmGallery->options['modules_xml'], array('sslverify' => true));
|
102 |
-
if(!is_wp_error($get_xml) && (200 == $get_xml['response']['code']))
|
103 |
$xml = @simplexml_load_string($get_xml['body']);
|
104 |
-
if(!empty($xml))
|
105 |
-
foreach($xml as $m)
|
106 |
-
$name
|
107 |
-
$modules['xml'][$name] = get_object_vars($m);
|
108 |
-
$modules['xml'][$name]['place'] = 'remote';
|
109 |
-
if(isset($modules['in'][$name]) && !empty($modules['in'][$name]))
|
110 |
-
$modules['in'][$name] = array_merge(get_object_vars($m), $modules['in'][$name]);
|
111 |
-
if(version_compare((float)$modules['xml'][$name]['version'], (float)$modules['in'][$name]['version'], '>'))
|
112 |
-
$modules['in'][$name]['update'] = $modules['xml'][$name]['version'];
|
113 |
-
$modules['out'][$name] = $modules['xml'][$name];
|
114 |
}
|
115 |
-
} else
|
116 |
-
$modules['out'][$name] = $modules['xml'][$name];
|
117 |
}
|
118 |
}
|
119 |
}
|
120 |
-
} else
|
121 |
$modules['error'] = array(__('Error loading remote xml...', 'grand-media'));
|
122 |
-
if(is_wp_error($get_xml))
|
123 |
$modules['error'][] = $get_xml->get_error_message();
|
124 |
}
|
125 |
}
|
@@ -127,3 +127,61 @@ function get_gmedia_modules($including_remote = true) {
|
|
127 |
|
128 |
return $modules;
|
129 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
|
3 |
+
function gm_get_admin_url($add_args = array(), $remove_args = array(), $uri = false, $preserve_args = array()){
|
4 |
global $gmCore;
|
5 |
|
6 |
+
return $gmCore->get_admin_url($add_args, $remove_args, $uri, $preserve_args);
|
7 |
}
|
8 |
|
9 |
+
function gm_panel_classes($classes){
|
10 |
echo implode(' ', (array)$classes);
|
11 |
}
|
12 |
|
13 |
+
function gm_user_can($capability){
|
14 |
global $gmCore;
|
15 |
|
16 |
+
return isset($gmCore->caps[ 'gmedia_' . $capability ])? $gmCore->caps[ 'gmedia_' . $capability ] : false;
|
17 |
}
|
18 |
|
19 |
+
function gmedia_term_choose_author_field($selected = false, $_args = array()){
|
20 |
global $gmCore;
|
21 |
|
22 |
$user_ID = get_current_user_id();
|
23 |
+
if(false === $selected){
|
24 |
$selected = $user_ID;
|
25 |
}
|
26 |
|
27 |
$user_ids = gm_user_can('delete_others_media')? $gmCore->get_editable_user_ids() : array($user_ID);
|
28 |
+
if($user_ids && gm_user_can('edit_others_media')){
|
29 |
+
if(!in_array($user_ID, $user_ids)){
|
30 |
array_push($user_ids, $user_ID);
|
31 |
}
|
32 |
+
$args = array('include' => $user_ids,
|
33 |
+
'include_selected' => true,
|
34 |
+
'name' => 'term[global]',
|
35 |
+
'selected' => $selected,
|
36 |
+
'class' => 'form-control input-sm',
|
37 |
+
'multi' => true,
|
38 |
+
'show_option_all' => __('Shared', 'grand-media')
|
39 |
+
);
|
40 |
+
$args = array_merge($args, $_args);
|
41 |
+
wp_dropdown_users($args);
|
42 |
+
} else{
|
43 |
echo '<input type="hidden" name="term[global]" value="' . $user_ID . '"/>';
|
44 |
echo '<div>' . get_the_author_meta('display_name', $user_ID) . '</div>';
|
45 |
}
|
46 |
}
|
47 |
|
48 |
/** Get available modules
|
49 |
+
*
|
50 |
* @param bool|true $including_remote
|
51 |
*
|
52 |
* @return array
|
53 |
*/
|
54 |
+
function get_gmedia_modules($including_remote = true){
|
55 |
global $gmCore, $gmGallery;
|
56 |
|
57 |
$modules = array();
|
58 |
$modules['in'] = $gmCore->modules_order();
|
59 |
+
if(($plugin_modules = glob(GMEDIA_ABSPATH . 'module/*', GLOB_ONLYDIR | GLOB_NOSORT))){
|
60 |
+
foreach($plugin_modules as $path){
|
61 |
+
$mfold = basename($path);
|
62 |
+
$modules['in'][ $mfold ] = array('place' => 'plugin',
|
63 |
+
'module_name' => $mfold,
|
64 |
+
'module_url' => $gmCore->gmedia_url . "/module/{$mfold}",
|
65 |
+
'module_path' => $path
|
|
|
66 |
);
|
67 |
}
|
68 |
}
|
69 |
+
if(($upload_modules = glob($gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/*', GLOB_ONLYDIR | GLOB_NOSORT))){
|
70 |
+
foreach($upload_modules as $path){
|
71 |
+
$mfold = basename($path);
|
72 |
+
$modules['in'][ $mfold ] = array('place' => 'upload',
|
73 |
+
'module_name' => $mfold,
|
74 |
+
'module_url' => $gmCore->upload['url'] . "/{$gmGallery->options['folder']['module']}/{$mfold}",
|
75 |
+
'module_path' => $path
|
|
|
76 |
);
|
77 |
}
|
78 |
}
|
79 |
|
80 |
$modules['in'] = array_filter($modules['in']);
|
81 |
|
82 |
+
if(isset($modules['in']) && !empty($modules['in'])){
|
83 |
+
foreach($modules['in'] as $mfold => $module){
|
84 |
// todo: get broken modules folders and delete them
|
85 |
+
if(!file_exists($module['module_path'] . '/index.php')){
|
86 |
+
unset($modules['in'][ $mfold ]);
|
87 |
continue;
|
88 |
}
|
89 |
$module_info = array();
|
90 |
include($module['module_path'] . '/index.php');
|
91 |
+
if(empty($module_info)){
|
92 |
+
unset($modules['in'][ $mfold ]);
|
93 |
continue;
|
94 |
}
|
95 |
+
$modules['in'][ $mfold ] = array_merge($module, (array)$module_info);
|
96 |
+
$modules['in'][ $mfold ]['update'] = false;
|
97 |
}
|
98 |
}
|
99 |
|
100 |
+
if($including_remote){
|
101 |
$get_xml = wp_remote_get($gmGallery->options['modules_xml'], array('sslverify' => true));
|
102 |
+
if(!is_wp_error($get_xml) && (200 == $get_xml['response']['code'])){
|
103 |
$xml = @simplexml_load_string($get_xml['body']);
|
104 |
+
if(!empty($xml)){
|
105 |
+
foreach($xml as $m){
|
106 |
+
$name = (string)$m->name;
|
107 |
+
$modules['xml'][ $name ] = get_object_vars($m);
|
108 |
+
$modules['xml'][ $name ]['place'] = 'remote';
|
109 |
+
if(isset($modules['in'][ $name ]) && !empty($modules['in'][ $name ])){
|
110 |
+
$modules['in'][ $name ] = array_merge(get_object_vars($m), $modules['in'][ $name ]);
|
111 |
+
if(version_compare((float)$modules['xml'][ $name ]['version'], (float)$modules['in'][ $name ]['version'], '>')){
|
112 |
+
$modules['in'][ $name ]['update'] = $modules['xml'][ $name ]['version'];
|
113 |
+
$modules['out'][ $name ] = $modules['xml'][ $name ];
|
114 |
}
|
115 |
+
} else{
|
116 |
+
$modules['out'][ $name ] = $modules['xml'][ $name ];
|
117 |
}
|
118 |
}
|
119 |
}
|
120 |
+
} else{
|
121 |
$modules['error'] = array(__('Error loading remote xml...', 'grand-media'));
|
122 |
+
if(is_wp_error($get_xml)){
|
123 |
$modules['error'][] = $get_xml->get_error_message();
|
124 |
}
|
125 |
}
|
127 |
|
128 |
return $modules;
|
129 |
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* @param array $query
|
133 |
+
*
|
134 |
+
* @return array
|
135 |
+
*/
|
136 |
+
function gmedia_gallery_query_data($query = array()){
|
137 |
+
$filter_data = array('author__in' => array(),
|
138 |
+
'author__not_in' => array(),
|
139 |
+
'category__and' => array(), /* use category id. Display posts that are tagged with all listed categories in array */
|
140 |
+
'category__in' => array(), /* use category id. Same as 'cat', but does not accept negative values */
|
141 |
+
'category__not_in' => array(), /* use category id. Exclude multiple categories */
|
142 |
+
'album__in' => array(), /* use album id. Same as 'alb' */
|
143 |
+
'album__not_in' => array(), /* use album id. Exclude multiple albums */
|
144 |
+
'tag__and' => array(), /* use tag ids. Display posts that are tagged with all listed tags in array */
|
145 |
+
'tag__in' => array(), /* use tag ids. To display posts from either tags listed in array. Same as 'tag' */
|
146 |
+
'tag__not_in' => array(), /* use tag ids. Display posts that do not have any of the listed tag ids */
|
147 |
+
'terms_relation' => '', /* allows you to describe the boolean relationship between the taxonomy queries. Possible values are 'OR', 'AND'. Default 'AND' */
|
148 |
+
'gmedia__in' => array(), /* use gmedia ids. Specify posts to retrieve */
|
149 |
+
'gmedia__not_in' => array(), /* use gmedia ids. Specify post NOT to retrieve */
|
150 |
+
'mime_type' => array(), /* mime types */
|
151 |
+
'limit' => '', /* (int) - set limit */
|
152 |
+
'page' => '', /* (int) - set limit */
|
153 |
+
'per_page' => '', /* (int) - set limit */
|
154 |
+
'order' => '', /* Designates the ascending or descending order of the 'orderby' parameter. Defaults to 'DESC' */
|
155 |
+
'orderby' => '', /* Sort retrieved posts by parameter. Defaults to 'ID' */
|
156 |
+
'year' => '', /* (int) - 4 digit year */
|
157 |
+
'monthnum' => '', /* (int) - Month number (from 1 to 12) */
|
158 |
+
'day' => '', /* (int) - Day of the month (from 1 to 31) */
|
159 |
+
'meta_query' => array(array('key' => '',
|
160 |
+
'value' => '',
|
161 |
+
'compare' => '',
|
162 |
+
'type' => ''
|
163 |
+
)
|
164 |
+
),
|
165 |
+
's' => '', /* (string) - search string or terms separated by comma */
|
166 |
+
'exact' => false /* Search exactly string if 'exact' parameter set to true */
|
167 |
+
|
168 |
+
);
|
169 |
+
|
170 |
+
$filter_data = wp_parse_args($query, $filter_data);
|
171 |
+
|
172 |
+
$query_args = (array)gmedia_array_filter_recursive($filter_data);
|
173 |
+
|
174 |
+
return array('query_data' => $filter_data,
|
175 |
+
'query_args' => $query_args
|
176 |
+
);
|
177 |
+
}
|
178 |
+
|
179 |
+
function gmedia_array_filter_recursive($input){
|
180 |
+
foreach($input as &$value){
|
181 |
+
if(is_array($value)){
|
182 |
+
$value = gmedia_array_filter_recursive($value);
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
return array_filter($input);
|
187 |
+
}
|
admin/pages/addmedia/tpl/assign-terms.php
CHANGED
@@ -5,6 +5,11 @@
|
|
5 |
* @var $gmDB
|
6 |
*/
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
if(gm_user_can('terms')) { ?>
|
9 |
<div class="form-group">
|
10 |
<?php
|
5 |
* @var $gmDB
|
6 |
*/
|
7 |
|
8 |
+
// don't load directly
|
9 |
+
if(!defined('ABSPATH')) {
|
10 |
+
die('-1');
|
11 |
+
}
|
12 |
+
|
13 |
if(gm_user_can('terms')) { ?>
|
14 |
<div class="form-group">
|
15 |
<?php
|
admin/pages/addmedia/tpl/import.php
CHANGED
@@ -58,8 +58,10 @@ $import_tab = array();
|
|
58 |
</div>
|
59 |
<div class="tab-footer">
|
60 |
<div class="checkbox pull-left">
|
61 |
-
<label><input type="checkbox" name="delete_source" value="1"/> <?php _e('delete source files after importing', 'grand-media')
|
62 |
-
|
|
|
|
|
63 |
<button class="pull-right btn btn-info gmedia-import" type="button" name="import-folder" value="true"><?php _e('Import folder', 'grand-media'); ?></button>
|
64 |
</div>
|
65 |
<script type="text/javascript">
|
@@ -99,6 +101,10 @@ $import_tab = array();
|
|
99 |
</div>
|
100 |
</div>
|
101 |
<div class="tab-footer">
|
|
|
|
|
|
|
|
|
102 |
<button class="pull-right btn btn-info gmedia-import" type="button" name="import-flagallery" value="true"><?php _e('Import', 'grand-media'); ?></button>
|
103 |
</div>
|
104 |
<?php } else { ?>
|
@@ -128,6 +134,10 @@ $import_tab = array();
|
|
128 |
</div>
|
129 |
</div>
|
130 |
<div class="tab-footer">
|
|
|
|
|
|
|
|
|
131 |
<button class="pull-right btn btn-info gmedia-import" type="button" name="import-nextgen" value="true"><?php _e('Import', 'grand-media'); ?></button>
|
132 |
</div>
|
133 |
<?php } else { ?>
|
58 |
</div>
|
59 |
<div class="tab-footer">
|
60 |
<div class="checkbox pull-left">
|
61 |
+
<div><label><input type="checkbox" name="delete_source" value="1"/> <?php _e('delete source files after importing', 'grand-media') ?></label></div>
|
62 |
+
<div><label><input type="checkbox" name="skip_exists" value="skip"> <?php _e('Skip if file with the same name already exists in Gmedia Library', 'grand-media'); ?></label></div>
|
63 |
+
<div class="help-block"><?php _e('Note: duplicates will be skipped in any way (checked by file hash)') ?></div>
|
64 |
+
</div>
|
65 |
<button class="pull-right btn btn-info gmedia-import" type="button" name="import-folder" value="true"><?php _e('Import folder', 'grand-media'); ?></button>
|
66 |
</div>
|
67 |
<script type="text/javascript">
|
101 |
</div>
|
102 |
</div>
|
103 |
<div class="tab-footer">
|
104 |
+
<div class="checkbox pull-left">
|
105 |
+
<label><input type="checkbox" name="skip_exists" value="skip"> <?php _e('Skip if file with the same name already exists in Gmedia Library', 'grand-media'); ?></label>
|
106 |
+
<div class="help-block"><?php _e('Note: duplicates will be skipped in any way (checked by file hash)') ?></div>
|
107 |
+
</div>
|
108 |
<button class="pull-right btn btn-info gmedia-import" type="button" name="import-flagallery" value="true"><?php _e('Import', 'grand-media'); ?></button>
|
109 |
</div>
|
110 |
<?php } else { ?>
|
134 |
</div>
|
135 |
</div>
|
136 |
<div class="tab-footer">
|
137 |
+
<div class="checkbox pull-left">
|
138 |
+
<label><input type="checkbox" name="skip_exists" value="skip"> <?php _e('Skip if file with the same name already exists in Gmedia Library', 'grand-media'); ?></label>
|
139 |
+
<div class="help-block"><?php _e('Note: duplicates will be skipped in any way (checked by file hash)') ?></div>
|
140 |
+
</div>
|
141 |
<button class="pull-right btn btn-info gmedia-import" type="button" name="import-nextgen" value="true"><?php _e('Import', 'grand-media'); ?></button>
|
142 |
</div>
|
143 |
<?php } else { ?>
|
admin/pages/addmedia/tpl/panel-heading.php
CHANGED
@@ -1,9 +1,14 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* @var $url
|
4 |
* @var $import
|
5 |
*/
|
6 |
-
$extra_tools = (defined('GMEDIA_IFRAME') && GMEDIA_IFRAME)? false : true;
|
7 |
?>
|
8 |
<div class="panel-heading clearfix">
|
9 |
<?php if($extra_tools) { ?>
|
@@ -32,4 +37,5 @@ $extra_tools = (defined('GMEDIA_IFRAME') && GMEDIA_IFRAME)? false : true;
|
|
32 |
</div>
|
33 |
<div style="padding: 2px 10px;"><?php echo $msg; ?></div>
|
34 |
</div>
|
|
|
35 |
</div>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* @var $url
|
9 |
* @var $import
|
10 |
*/
|
11 |
+
$extra_tools = ($gmProcessor->gmediablank || (defined('GMEDIA_IFRAME') && GMEDIA_IFRAME))? false : true;
|
12 |
?>
|
13 |
<div class="panel-heading clearfix">
|
14 |
<?php if($extra_tools) { ?>
|
37 |
</div>
|
38 |
<div style="padding: 2px 10px;"><?php echo $msg; ?></div>
|
39 |
</div>
|
40 |
+
<div class="spinner"></div>
|
41 |
</div>
|
admin/pages/addmedia/tpl/upload.php
CHANGED
@@ -8,19 +8,20 @@
|
|
8 |
*/
|
9 |
|
10 |
// don't load directly
|
11 |
-
if(!defined('ABSPATH')) {
|
12 |
-
die('-1');
|
13 |
}
|
14 |
|
15 |
-
if(!gm_user_can('upload')) {
|
16 |
-
_e('You do not have permissions to upload media', 'grand-media');
|
17 |
|
18 |
return;
|
19 |
}
|
20 |
|
21 |
$maxupsize = wp_max_upload_size();
|
22 |
-
$
|
23 |
-
$
|
|
|
24 |
|
25 |
$screen_options = $gmProcessor->user_options;
|
26 |
|
@@ -30,52 +31,52 @@ $gm_terms = array();
|
|
30 |
<form class="row" id="gmUpload" name="upload_form" method="POST" accept-charset="utf-8" onsubmit="return false;">
|
31 |
<div class="col-md-4" id="uploader_multipart_params">
|
32 |
<br/>
|
33 |
-
<?php if('false' == $screen_options['uploader_chunking'] || ('html4' == $screen_options['uploader_runtime'])) { ?>
|
34 |
-
<p class="clearfix text-right"><span class="label label-default"><?php echo __('Maximum file size', 'grand-media') . ": {$maxupsize_mb}Mb"; ?></span></p>
|
35 |
<?php } else { ?>
|
36 |
<p class="clearfix text-right hidden">
|
37 |
-
<span class="label label-default"><?php echo __('Maximum $_POST size', 'grand-media') . ": {$maxupsize_mb}Mb"; ?></span>
|
38 |
-
<span class="label label-default"><?php echo __('Chunk size', 'grand-media') . ': ' . min($
|
39 |
</p>
|
40 |
<?php } ?>
|
41 |
|
42 |
<div class="form-group">
|
43 |
-
<label><?php _e('Title', 'grand-media'); ?></label>
|
44 |
<select name="set_title" class="form-control input-sm">
|
45 |
-
<option value="exif"><?php _e('EXIF or File Name', 'grand-media'); ?></option>
|
46 |
-
<option value="filename"><?php _e('File Name', 'grand-media'); ?></option>
|
47 |
-
<option value="empty"><?php _e('Empty', 'grand-media'); ?></option>
|
48 |
</select>
|
49 |
</div>
|
50 |
<div class="form-group">
|
51 |
-
<label><?php _e('Status', 'grand-media'); ?></label>
|
52 |
<select name="set_status" class="form-control input-sm">
|
53 |
-
<option value="inherit"><?php _e('Same as Album or Public', 'grand-media'); ?></option>
|
54 |
-
<option value="publish"><?php _e('Public', 'grand-media'); ?></option>
|
55 |
-
<option value="private"><?php _e('Private', 'grand-media'); ?></option>
|
56 |
-
<option value="draft"><?php _e('Draft', 'grand-media'); ?></option>
|
57 |
</select>
|
58 |
</div>
|
59 |
|
60 |
<hr/>
|
61 |
|
62 |
-
<?php include(dirname(__FILE__) . '/assign-terms.php'); ?>
|
63 |
|
64 |
</div>
|
65 |
<div class="col-md-8" id="pluploadUploader">
|
66 |
-
<p><?php _e("You browser doesn't have Flash or HTML5 support. Check also if page have no JavaScript errors.", 'grand-media'); ?></p>
|
67 |
<?php
|
68 |
-
$mime_types = get_allowed_mime_types($user_ID);
|
69 |
$type_ext = array();
|
70 |
$filters = array();
|
71 |
-
foreach($mime_types as $ext => $mime) {
|
72 |
-
$type
|
73 |
-
$type_ext[$type][] = $ext;
|
74 |
}
|
75 |
-
foreach($type_ext as $filter => $ext) {
|
76 |
$filters[] = array(
|
77 |
'title' => $filter,
|
78 |
-
'extensions' => str_replace('|', ',', implode(',', $ext))
|
79 |
);
|
80 |
}
|
81 |
?>
|
@@ -87,7 +88,7 @@ $gm_terms = array();
|
|
87 |
<?php if('auto' != $screen_options['uploader_runtime']){ ?>
|
88 |
runtimes: '<?php echo $screen_options['uploader_runtime']; ?>',
|
89 |
<?php } ?>
|
90 |
-
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
|
91 |
<?php if(('true' == $screen_options['uploader_urlstream_upload']) && ('html4' != $screen_options['uploader_runtime'])){ ?>
|
92 |
urlstream_upload: true,
|
93 |
multipart: false,
|
@@ -97,7 +98,7 @@ $gm_terms = array();
|
|
97 |
multipart_params: {action: 'gmedia_upload_handler', _ajax_nonce: '<?php echo wp_create_nonce('GmediaUpload'); ?>', params: ''},
|
98 |
<?php if('true' == $screen_options['uploader_chunking'] && ('html4' != $screen_options['uploader_runtime'])){ ?>
|
99 |
max_file_size: '2000Mb',
|
100 |
-
chunk_size:
|
101 |
<?php } else{ ?>
|
102 |
max_file_size: <?php echo $maxupsize; ?>,
|
103 |
<?php } ?>
|
@@ -112,8 +113,8 @@ $gm_terms = array();
|
|
112 |
active: 'thumbs'
|
113 |
},
|
114 |
filters: <?php echo json_encode($filters); ?>,
|
115 |
-
flash_swf_url: '<?php echo $gmCore->gmedia_url; ?>/assets/plupload/Moxie.swf',
|
116 |
-
silverlight_xap_url: '<?php echo $gmCore->gmedia_url; ?>/assets/plupload/Moxie.xap'
|
117 |
|
118 |
});
|
119 |
var closebtn = '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
|
8 |
*/
|
9 |
|
10 |
// don't load directly
|
11 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
+
die( '-1' );
|
13 |
}
|
14 |
|
15 |
+
if ( ! gm_user_can( 'upload' ) ) {
|
16 |
+
_e( 'You do not have permissions to upload media', 'grand-media' );
|
17 |
|
18 |
return;
|
19 |
}
|
20 |
|
21 |
$maxupsize = wp_max_upload_size();
|
22 |
+
$maxupsize_mb = floor( $maxupsize / 1024 / 1024 );
|
23 |
+
$maxchunksize = floor( $maxupsize * 0.9 );
|
24 |
+
$maxchunksize_mb = floor( $maxupsize_mb * 0.9 );
|
25 |
|
26 |
$screen_options = $gmProcessor->user_options;
|
27 |
|
31 |
<form class="row" id="gmUpload" name="upload_form" method="POST" accept-charset="utf-8" onsubmit="return false;">
|
32 |
<div class="col-md-4" id="uploader_multipart_params">
|
33 |
<br/>
|
34 |
+
<?php if ( 'false' == $screen_options['uploader_chunking'] || ( 'html4' == $screen_options['uploader_runtime'] ) ) { ?>
|
35 |
+
<p class="clearfix text-right"><span class="label label-default"><?php echo __( 'Maximum file size', 'grand-media' ) . ": {$maxupsize_mb}Mb"; ?></span></p>
|
36 |
<?php } else { ?>
|
37 |
<p class="clearfix text-right hidden">
|
38 |
+
<span class="label label-default"><?php echo __( 'Maximum $_POST size', 'grand-media' ) . ": {$maxupsize_mb}Mb"; ?></span>
|
39 |
+
<span class="label label-default"><?php echo __( 'Chunk size', 'grand-media' ) . ': ' . min( $maxchunksize_mb, $screen_options['uploader_chunk_size'] ) . 'Mb'; ?></span>
|
40 |
</p>
|
41 |
<?php } ?>
|
42 |
|
43 |
<div class="form-group">
|
44 |
+
<label><?php _e( 'Title', 'grand-media' ); ?></label>
|
45 |
<select name="set_title" class="form-control input-sm">
|
46 |
+
<option value="exif"><?php _e( 'EXIF or File Name', 'grand-media' ); ?></option>
|
47 |
+
<option value="filename"><?php _e( 'File Name', 'grand-media' ); ?></option>
|
48 |
+
<option value="empty"><?php _e( 'Empty', 'grand-media' ); ?></option>
|
49 |
</select>
|
50 |
</div>
|
51 |
<div class="form-group">
|
52 |
+
<label><?php _e( 'Status', 'grand-media' ); ?></label>
|
53 |
<select name="set_status" class="form-control input-sm">
|
54 |
+
<option value="inherit"><?php _e( 'Same as Album or Public', 'grand-media' ); ?></option>
|
55 |
+
<option value="publish"><?php _e( 'Public', 'grand-media' ); ?></option>
|
56 |
+
<option value="private"><?php _e( 'Private', 'grand-media' ); ?></option>
|
57 |
+
<option value="draft"><?php _e( 'Draft', 'grand-media' ); ?></option>
|
58 |
</select>
|
59 |
</div>
|
60 |
|
61 |
<hr/>
|
62 |
|
63 |
+
<?php include( dirname( __FILE__ ) . '/assign-terms.php' ); ?>
|
64 |
|
65 |
</div>
|
66 |
<div class="col-md-8" id="pluploadUploader">
|
67 |
+
<p><?php _e( "You browser doesn't have Flash or HTML5 support. Check also if page have no JavaScript errors.", 'grand-media' ); ?></p>
|
68 |
<?php
|
69 |
+
$mime_types = get_allowed_mime_types( $user_ID );
|
70 |
$type_ext = array();
|
71 |
$filters = array();
|
72 |
+
foreach ( $mime_types as $ext => $mime ) {
|
73 |
+
$type = strtok( $mime, '/' );
|
74 |
+
$type_ext[ $type ][] = $ext;
|
75 |
}
|
76 |
+
foreach ( $type_ext as $filter => $ext ) {
|
77 |
$filters[] = array(
|
78 |
'title' => $filter,
|
79 |
+
'extensions' => str_replace( '|', ',', implode( ',', $ext ) )
|
80 |
);
|
81 |
}
|
82 |
?>
|
88 |
<?php if('auto' != $screen_options['uploader_runtime']){ ?>
|
89 |
runtimes: '<?php echo $screen_options['uploader_runtime']; ?>',
|
90 |
<?php } ?>
|
91 |
+
url: '<?php echo $gmCore->punyencode(admin_url( 'admin-ajax.php' )); ?>',
|
92 |
<?php if(('true' == $screen_options['uploader_urlstream_upload']) && ('html4' != $screen_options['uploader_runtime'])){ ?>
|
93 |
urlstream_upload: true,
|
94 |
multipart: false,
|
98 |
multipart_params: {action: 'gmedia_upload_handler', _ajax_nonce: '<?php echo wp_create_nonce('GmediaUpload'); ?>', params: ''},
|
99 |
<?php if('true' == $screen_options['uploader_chunking'] && ('html4' != $screen_options['uploader_runtime'])){ ?>
|
100 |
max_file_size: '2000Mb',
|
101 |
+
chunk_size: <?php echo min($maxchunksize, $screen_options['uploader_chunk_size']*1024*1024); ?>,
|
102 |
<?php } else{ ?>
|
103 |
max_file_size: <?php echo $maxupsize; ?>,
|
104 |
<?php } ?>
|
113 |
active: 'thumbs'
|
114 |
},
|
115 |
filters: <?php echo json_encode($filters); ?>,
|
116 |
+
flash_swf_url: '<?php echo $gmCore->punyencode($gmCore->gmedia_url); ?>/assets/plupload/Moxie.swf',
|
117 |
+
silverlight_xap_url: '<?php echo $gmCore->punyencode($gmCore->gmedia_url); ?>/assets/plupload/Moxie.xap'
|
118 |
|
119 |
});
|
120 |
var closebtn = '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
|
admin/pages/galleries/edit-gallery.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
*/
|
5 |
|
6 |
// don't load directly
|
7 |
-
if(!defined('ABSPATH'))
|
8 |
die('-1');
|
9 |
}
|
10 |
|
@@ -16,14 +16,14 @@ $gmedia_user_options = $gmProcessor->user_options;
|
|
16 |
$gmedia_term_taxonomy = $gmProcessor->taxonomy;
|
17 |
$taxterm = str_replace('gmedia_', '', $gmedia_term_taxonomy);
|
18 |
|
19 |
-
if(!gm_user_can("{$taxterm}_manage"))
|
20 |
die('-1');
|
21 |
}
|
22 |
|
23 |
-
$term_id = (int)
|
24 |
$term = $gmDB->get_term($term_id);
|
25 |
|
26 |
-
if(empty($term) || is_wp_error($term))
|
27 |
$term_id = 0;
|
28 |
$term = new stdClass();
|
29 |
}
|
@@ -35,6 +35,7 @@ $default_options = array();
|
|
35 |
$presets = false;
|
36 |
$default_preset = array();
|
37 |
$load_preset = array();
|
|
|
38 |
|
39 |
$gmedia_filter = gmedia_gallery_query_data($term->meta['_query']);
|
40 |
|
@@ -44,61 +45,70 @@ $gmedia_filter = gmedia_gallery_query_data($term->meta['_query']);
|
|
44 |
* @var $module_url
|
45 |
* @var $module_path
|
46 |
*/
|
47 |
-
if($term->module['name'])
|
48 |
-
$presets = $gmDB->get_terms('gmedia_module', array('
|
49 |
-
foreach($presets as $i => $preset)
|
50 |
-
if('[' . $term->module['name'] . ']' == $preset->name)
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
-
if((int)$preset->term_id == (int)$gmCore->_get('preset', 0))
|
57 |
$load_preset = maybe_unserialize($preset->description);
|
58 |
$load_preset['term_id'] = $preset->term_id;
|
59 |
$load_preset['name'] = $preset->name;
|
60 |
}
|
61 |
}
|
62 |
|
63 |
-
if(isset($gmedia_modules['in'][$term->module['name']]))
|
64 |
-
extract($gmedia_modules['in'][$term->module['name']]);
|
65 |
|
66 |
/**
|
67 |
* @var $module_info
|
68 |
-
*
|
69 |
* @var $default_options
|
70 |
* @var $options_tree
|
71 |
*/
|
72 |
-
if(file_exists($module_path . '/index.php') && file_exists($module_path . '/settings.php'))
|
73 |
/** @noinspection PhpIncludeInspection */
|
74 |
include($module_path . '/index.php');
|
75 |
/** @noinspection PhpIncludeInspection */
|
76 |
include($module_path . '/settings.php');
|
77 |
|
78 |
-
if(!empty($
|
|
|
|
|
|
|
79 |
$default_options = $gmCore->array_replace_recursive($default_options, $default_preset);
|
80 |
}
|
81 |
-
} else
|
82 |
-
$alert[] = sprintf(__('Module `%s` is broken. Choose another module from the list
|
83 |
}
|
84 |
-
} else
|
85 |
-
$alert[] = sprintf(__('Can\'t get module with name `%s`. Choose module from the list
|
86 |
}
|
87 |
-
} else
|
88 |
-
$alert[] = sprintf(__('Module is not selected for this gallery. Choose module from the list
|
89 |
}
|
90 |
|
91 |
-
if
|
92 |
echo $gmCore->alert('danger', $alert);
|
93 |
}
|
94 |
|
95 |
-
if
|
96 |
-
$term->meta['_settings'][$term->module['name']] = $gmCore->array_replace_recursive($term->meta['_settings'][$term->module['name']], $load_preset);
|
97 |
echo $gmCore->alert('info', sprintf(__('Preset `%s` loaded. To apply it for current gallery click Save button'), $load_preset['name']));
|
98 |
}
|
99 |
-
if
|
100 |
-
$gallery_settings = $gmCore->array_replace_recursive($default_options, $term->meta['_settings'][$term->module['name']]);
|
101 |
-
} else
|
102 |
$gallery_settings = $default_options;
|
103 |
}
|
104 |
|
4 |
*/
|
5 |
|
6 |
// don't load directly
|
7 |
+
if(!defined('ABSPATH')){
|
8 |
die('-1');
|
9 |
}
|
10 |
|
16 |
$gmedia_term_taxonomy = $gmProcessor->taxonomy;
|
17 |
$taxterm = str_replace('gmedia_', '', $gmedia_term_taxonomy);
|
18 |
|
19 |
+
if(!gm_user_can("{$taxterm}_manage")){
|
20 |
die('-1');
|
21 |
}
|
22 |
|
23 |
+
$term_id = (int)$term_id;
|
24 |
$term = $gmDB->get_term($term_id);
|
25 |
|
26 |
+
if(empty($term) || is_wp_error($term)){
|
27 |
$term_id = 0;
|
28 |
$term = new stdClass();
|
29 |
}
|
35 |
$presets = false;
|
36 |
$default_preset = array();
|
37 |
$load_preset = array();
|
38 |
+
$global_preset = array();
|
39 |
|
40 |
$gmedia_filter = gmedia_gallery_query_data($term->meta['_query']);
|
41 |
|
45 |
* @var $module_url
|
46 |
* @var $module_path
|
47 |
*/
|
48 |
+
if($term->module['name']){
|
49 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $term->module['name']));
|
50 |
+
foreach($presets as $i => $preset){
|
51 |
+
if('[' . $term->module['name'] . ']' == $preset->name){
|
52 |
+
if(0 === (int)$preset->global){
|
53 |
+
$global_preset = maybe_unserialize($preset->description);
|
54 |
+
$global_preset['term_id'] = $preset->term_id;
|
55 |
+
$global_preset['name'] = $preset->name;
|
56 |
+
unset($presets[ $i ]);
|
57 |
+
} elseif($user_ID == $preset->global){
|
58 |
+
$default_preset = maybe_unserialize($preset->description);
|
59 |
+
$default_preset['term_id'] = $preset->term_id;
|
60 |
+
$default_preset['name'] = $preset->name;
|
61 |
+
unset($presets[ $i ]);
|
62 |
+
}
|
63 |
}
|
64 |
+
if((int)$preset->term_id == (int)$gmCore->_get('preset', 0)){
|
65 |
$load_preset = maybe_unserialize($preset->description);
|
66 |
$load_preset['term_id'] = $preset->term_id;
|
67 |
$load_preset['name'] = $preset->name;
|
68 |
}
|
69 |
}
|
70 |
|
71 |
+
if(isset($gmedia_modules['in'][ $term->module['name'] ])){
|
72 |
+
extract($gmedia_modules['in'][ $term->module['name'] ]);
|
73 |
|
74 |
/**
|
75 |
* @var $module_info
|
|
|
76 |
* @var $default_options
|
77 |
* @var $options_tree
|
78 |
*/
|
79 |
+
if(file_exists($module_path . '/index.php') && file_exists($module_path . '/settings.php')){
|
80 |
/** @noinspection PhpIncludeInspection */
|
81 |
include($module_path . '/index.php');
|
82 |
/** @noinspection PhpIncludeInspection */
|
83 |
include($module_path . '/settings.php');
|
84 |
|
85 |
+
if(!empty($global_preset)){
|
86 |
+
$default_options = $gmCore->array_replace_recursive($default_options, $global_preset);
|
87 |
+
}
|
88 |
+
if(!empty($default_preset)){
|
89 |
$default_options = $gmCore->array_replace_recursive($default_options, $default_preset);
|
90 |
}
|
91 |
+
} else{
|
92 |
+
$alert[] = sprintf(__('Module `%s` is broken. Choose another module from the list.'), $module_name);
|
93 |
}
|
94 |
+
} else{
|
95 |
+
$alert[] = sprintf(__('Can\'t get module with name `%s`. Choose module from the list.'), $module_name);
|
96 |
}
|
97 |
+
} else{
|
98 |
+
$alert[] = sprintf(__('Module is not selected for this gallery. Choose module from the list.'), $module_name);
|
99 |
}
|
100 |
|
101 |
+
if(!empty($alert)){
|
102 |
echo $gmCore->alert('danger', $alert);
|
103 |
}
|
104 |
|
105 |
+
if(!empty($load_preset)){
|
106 |
+
$term->meta['_settings'][ $term->module['name'] ] = $gmCore->array_replace_recursive($term->meta['_settings'][ $term->module['name'] ], $load_preset);
|
107 |
echo $gmCore->alert('info', sprintf(__('Preset `%s` loaded. To apply it for current gallery click Save button'), $load_preset['name']));
|
108 |
}
|
109 |
+
if(!empty($term->meta['_settings'][ $term->module['name'] ])){
|
110 |
+
$gallery_settings = $gmCore->array_replace_recursive($default_options, $term->meta['_settings'][ $term->module['name'] ]);
|
111 |
+
} else{
|
112 |
$gallery_settings = $default_options;
|
113 |
}
|
114 |
|
admin/pages/galleries/functions.php
CHANGED
@@ -66,7 +66,7 @@ function gmedia_gallery_more_data(&$item) {
|
|
66 |
} else {
|
67 |
$meta = $gmDB->get_metadata('gmedia_term', $item->term_id);
|
68 |
foreach($meta as $key => $value) {
|
69 |
-
if(is_protected_meta($key, '
|
70 |
$item->meta[$key] = $value[0];
|
71 |
} else {
|
72 |
$item->custom[$key] = $value;
|
@@ -107,67 +107,3 @@ function gmedia_gallery_more_data(&$item) {
|
|
107 |
|
108 |
$item = apply_filters('gmedia_gallery_more_data', $item);
|
109 |
}
|
110 |
-
|
111 |
-
/**
|
112 |
-
* @param array $query
|
113 |
-
*
|
114 |
-
* @return array
|
115 |
-
*/
|
116 |
-
function gmedia_gallery_query_data($query = array()) {
|
117 |
-
$filter_data = array(
|
118 |
-
'author__in' => array()
|
119 |
-
, 'author__not_in' => array()
|
120 |
-
, 'category__and' => array() // use category id. Display posts that are tagged with all listed categories in array
|
121 |
-
, 'category__in' => array() // use category id. Same as 'cat', but does not accept negative values
|
122 |
-
, 'category__not_in' => array() // use category id. Exclude multiple categories
|
123 |
-
, 'album__in' => array() // use album id. Same as 'alb'
|
124 |
-
, 'album__not_in' => array() // use album id. Exclude multiple albums
|
125 |
-
, 'tag__and' => array() // use tag ids. Display posts that are tagged with all listed tags in array
|
126 |
-
, 'tag__in' => array() // use tag ids. To display posts from either tags listed in array. Same as 'tag'
|
127 |
-
, 'tag__not_in' => array() // use tag ids. Display posts that do not have any of the listed tag ids
|
128 |
-
, 'terms_relation' => '' // allows you to describe the boolean relationship between the taxonomy queries. Possible values are 'OR', 'AND'. Default 'AND'
|
129 |
-
, 'gmedia__in' => array() // use gmedia ids. Specify posts to retrieve
|
130 |
-
, 'gmedia__not_in' => array() // use gmedia ids. Specify post NOT to retrieve
|
131 |
-
, 'mime_type' => array() // mime types
|
132 |
-
|
133 |
-
, 'limit' => '' // (int) - set limit
|
134 |
-
, 'page' => '' // (int) - set limit
|
135 |
-
, 'per_page' => '' // (int) - set limit
|
136 |
-
, 'order' => '' // Designates the ascending or descending order of the 'orderby' parameter. Defaults to 'DESC'
|
137 |
-
, 'orderby' => '' // Sort retrieved posts by parameter. Defaults to 'ID'
|
138 |
-
, 'year' => '' // (int) - 4 digit year
|
139 |
-
, 'monthnum' => '' // (int) - Month number (from 1 to 12)
|
140 |
-
, 'day' => '' // (int) - Day of the month (from 1 to 31)
|
141 |
-
|
142 |
-
, 'meta_query' => array(
|
143 |
-
array(
|
144 |
-
'key' => '',
|
145 |
-
'value' => '',
|
146 |
-
'compare' => '',
|
147 |
-
'type' => ''
|
148 |
-
)
|
149 |
-
)
|
150 |
-
, 's' => '' // (string) - search string or terms separated by comma
|
151 |
-
, 'exact' => false // Search exactly string if 'exact' parameter set to true
|
152 |
-
|
153 |
-
);
|
154 |
-
|
155 |
-
$filter_data = wp_parse_args($query, $filter_data);
|
156 |
-
|
157 |
-
$query_args = (array) gmedia_array_filter_recursive($filter_data);
|
158 |
-
|
159 |
-
return array(
|
160 |
-
'query_data' => $filter_data,
|
161 |
-
'query_args' => $query_args
|
162 |
-
);
|
163 |
-
}
|
164 |
-
|
165 |
-
function gmedia_array_filter_recursive($input) {
|
166 |
-
foreach($input as &$value) {
|
167 |
-
if(is_array($value)) {
|
168 |
-
$value = gmedia_array_filter_recursive($value);
|
169 |
-
}
|
170 |
-
}
|
171 |
-
|
172 |
-
return array_filter($input);
|
173 |
-
}
|
66 |
} else {
|
67 |
$meta = $gmDB->get_metadata('gmedia_term', $item->term_id);
|
68 |
foreach($meta as $key => $value) {
|
69 |
+
if($gmCore->is_protected_meta($key, 'gmedia_term')) {
|
70 |
$item->meta[$key] = $value[0];
|
71 |
} else {
|
72 |
$item->custom[$key] = $value;
|
107 |
|
108 |
$item = apply_filters('gmedia_gallery_more_data', $item);
|
109 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin/pages/galleries/tpl/choose-module.php
CHANGED
@@ -1,7 +1,13 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* @var $gmedia_modules
|
4 |
*/
|
|
|
5 |
?>
|
6 |
<div class="modal fade gmedia-modal" id="chooseModuleModal" tabindex="-1" role="dialog" aria-hidden="true">
|
7 |
<div class="modal-dialog">
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* @var $gmedia_modules
|
9 |
*/
|
10 |
+
|
11 |
?>
|
12 |
<div class="modal fade gmedia-modal" id="chooseModuleModal" tabindex="-1" role="dialog" aria-hidden="true">
|
13 |
<div class="modal-dialog">
|
admin/pages/galleries/tpl/galleries-panel-heading.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Panel heading for terms
|
4 |
*
|
@@ -8,14 +13,22 @@
|
|
8 |
*/
|
9 |
?>
|
10 |
<div class="panel-heading-fake"></div>
|
11 |
-
<div class="panel-heading clearfix">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
echo $gmedia_terms_pager;
|
16 |
-
?>
|
17 |
|
18 |
-
<div class="btn-toolbar pull-left">
|
19 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
20 |
<span class="btn btn-default active"><input class="doaction" id="cb_global"
|
21 |
data-group="cb_term-object" type="checkbox"/></span>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Panel heading for terms
|
9 |
*
|
13 |
*/
|
14 |
?>
|
15 |
<div class="panel-heading-fake"></div>
|
16 |
+
<div class="panel-heading clearfix" style="padding-bottom:2px;">
|
17 |
+
<div class="pull-right" style="margin-bottom:3px;">
|
18 |
+
<div class="clearfix">
|
19 |
+
<?php include(GMEDIA_ABSPATH . 'admin/tpl/search-form.php'); ?>
|
20 |
+
|
21 |
+
<div class="btn-toolbar pull-right" style="margin-bottom:4px; margin-left:4px;">
|
22 |
+
<a title="<?php _e('More Screen Settings', 'grand-media'); ?>" class="show-settings-link pull-right btn btn-default btn-xs"><span class="glyphicon glyphicon-cog"></span></a>
|
23 |
+
</div>
|
24 |
+
</div>
|
25 |
+
|
26 |
+
<?php echo $gmedia_terms_pager; ?>
|
27 |
|
28 |
+
<div class="spinner"></div>
|
29 |
+
</div>
|
|
|
|
|
30 |
|
31 |
+
<div class="btn-toolbar pull-left" style="margin-bottom:7px;">
|
32 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
33 |
<span class="btn btn-default active"><input class="doaction" id="cb_global"
|
34 |
data-group="cb_term-object" type="checkbox"/></span>
|
admin/pages/galleries/tpl/gallery-edit-item.php
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Edit Gallery Form
|
4 |
*/
|
5 |
?>
|
6 |
-
|
7 |
-
<form method="post" id="gmedia-edit-gallery" name="gmEditTerm" data-id="<?php echo $term_id; ?>" action="<?php echo $gmedia_url; ?>">
|
8 |
<div class="panel-body">
|
9 |
<!--<h4 style="margin-top:0;">
|
10 |
<?php /*if($term_id) { */ ?>
|
@@ -48,7 +52,9 @@
|
|
48 |
<div class="form-group">
|
49 |
<div class="pull-right"><a id="build_query" class="label label-primary buildquery-modal" href="#buildQuery" style="font-size:90%;"><?php _e('Build Query', 'grand-media'); ?></a></div>
|
50 |
<label><?php _e('Query Args.', 'grand-media'); ?></label>
|
51 |
-
<textarea class="form-control input-sm" id="build_query_field" style="height:64px;"
|
|
|
|
|
52 |
</div>
|
53 |
</div>
|
54 |
</div>
|
@@ -70,12 +76,12 @@
|
|
70 |
</label>
|
71 |
<div>
|
72 |
<div class="btn-group btn-group-sm" id="save_buttons">
|
73 |
-
<?php if($term->module['name'] != $term->meta['_module'])
|
74 |
<a href="<?php echo $gmedia_url; ?>" class="btn btn-default"><?php _e('Cancel preview module', 'grand-media'); ?></a>
|
75 |
<button type="submit" name="gmedia_gallery_save" class="btn btn-primary"><?php _e('Save with new module', 'grand-media'); ?></button>
|
76 |
-
<?php } else
|
77 |
<?php $reset_settings = $gmCore->array_diff_keyval_recursive($default_options, $gallery_settings, true);
|
78 |
-
if(!empty($reset_settings))
|
79 |
?>
|
80 |
<button type="submit" name="gmedia_gallery_reset" class="btn btn-default" data-confirm="<?php _e('Confirm reset module settings to default preset') ?>"><?php _e('Reset to default', 'grand-media'); ?></button>
|
81 |
<?php } ?>
|
@@ -88,28 +94,30 @@
|
|
88 |
<p><b><?php _e('Gallery ID:'); ?></b> #<?php echo $term_id; ?></p>
|
89 |
<p><b><?php _e('Last edited:'); ?></b> <?php echo $term->meta['_edited']; ?></p>
|
90 |
<p><?php echo '<b>' . __('Gallery module:') . '</b> <a href="#chooseModuleModal" data-toggle="modal">' . $term->meta['_module'] . '</a>';
|
91 |
-
if($term->module['name'] != $term->meta['_module'])
|
92 |
echo '<br /><b>' . __('Preview module:') . '</b> ' . $term->module['name'];
|
93 |
echo '<br /><span class="text-danger">' . sprintf(__('Note: Module changed to %s, but not saved yet'), $term->module['name']) . '</span>';
|
94 |
} ?></p>
|
95 |
<input type="hidden" name="term[module]" value="<?php echo esc_attr($term->module['name']); ?>">
|
96 |
-
<?php if($term_id)
|
97 |
-
$params
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
?>
|
101 |
<p><b><?php _e('GmediaCloud page URL for current gallery:'); ?></b> <?php
|
102 |
$endpoint = $gmGallery->options['endpoint'];
|
103 |
$gmedia_hashid = gmedia_hash_id_encode($term_id, 'gallery');
|
104 |
$gallery_link_default = add_query_arg(array("$endpoint" => $gmedia_hashid, 't' => 'g'), home_url('index.php'));
|
105 |
-
if(get_option('permalink_structure'))
|
106 |
$gallery_link = home_url(urlencode($endpoint) . '/g/' . $gmedia_hashid);
|
107 |
-
} else
|
108 |
$gallery_link = $gallery_link_default;
|
109 |
} ?>
|
110 |
<br/><a target="_blank" href="<?php echo $gallery_link; ?>"><?php echo $gallery_link; ?></a>
|
111 |
</p>
|
112 |
-
<?php if($term->post_id)
|
113 |
<p><b><?php _e('Gmedia Post URL for current gallery:'); ?></b>
|
114 |
<?php $post_link = get_permalink($term->post_id); ?>
|
115 |
<br/><a target="_blank" href="<?php echo $post_link; ?>"><?php echo $post_link; ?></a>
|
@@ -117,7 +125,7 @@
|
|
117 |
<?php } ?>
|
118 |
<div class="help-block">
|
119 |
<?php _e('update <a href="options-permalink.php">Permalink Settings</a> if above link not working', 'grand-media'); ?>
|
120 |
-
<?php if(current_user_can('manage_options'))
|
121 |
echo '<br>' . __('More info about GmediaCloud Pages and GmediaCloud Settings can be found <a href="admin.php?page=GrandMedia_Settings#gmedia_settings_cloud">here</a>', 'grand-media');
|
122 |
} ?>
|
123 |
</div>
|
@@ -129,14 +137,17 @@
|
|
129 |
<div class="well well-sm clearfix">
|
130 |
<div class="btn-toolbar pull-right" id="module_preset">
|
131 |
<div class="btn-group">
|
132 |
-
<button type="button" class="btn btn-default<?php echo ($term->module['name'] != $term->meta['_module'])? ' disabled' : ''; ?>" id="
|
133 |
</div>
|
134 |
-
<script type="text/html" id="
|
135 |
<div style="padding-top: 5px;">
|
|
|
|
|
|
|
136 |
<p style="white-space: nowrap">
|
137 |
<button type="button" name="module_preset_save_default" class="ajax-submit btn btn-default btn-sm"><?php _e('Save as Default', 'grand-media'); ?></button>
|
138 |
<em><?php _e('or', 'grand-media'); ?></em>
|
139 |
-
<?php if(!empty($default_preset))
|
140 |
<button type="button" name="module_preset_restore_original" class="ajax-submit btn btn-default btn-sm"><?php _e('Restore Original', 'grand-media'); ?></button>
|
141 |
<input type="hidden" name="preset_default" value="<?php echo $default_preset['term_id']; ?>"/>
|
142 |
<?php } ?>
|
@@ -146,738 +157,74 @@
|
|
146 |
|
147 |
<div class="input-group input-group-sm">
|
148 |
<input type="text" class="form-control input-sm" name="module_preset_name" placeholder="<?php _e('Preset Name', 'grand-media'); ?>" value=""/>
|
149 |
-
<span class="input-group-btn"><button type="button" name="
|
150 |
</div>
|
151 |
</div>
|
152 |
|
153 |
-
<?php if(!empty($presets))
|
154 |
<ul class="list-group presetlist">
|
155 |
-
<?php foreach($presets as $preset)
|
156 |
-
$
|
157 |
-
$count = 1;
|
158 |
-
?>
|
159 |
-
<li class="list-group-item" id="gm-preset-<?php echo $preset->term_id; ?>">
|
160 |
-
<span class="delpreset"><span class="label label-danger" data-id="<?php echo $preset->term_id; ?>">×</span></span>
|
161 |
-
<a href="<?php echo $gmCore->get_admin_url(array('preset' => $preset->term_id), array(), $gmedia_url); ?>"><?php echo str_replace($trim, '', $preset->name, $count); ?></a>
|
162 |
-
</li>
|
163 |
-
<?php } ?>
|
164 |
-
</ul>
|
165 |
-
<?php } ?>
|
166 |
-
</div>
|
167 |
-
</script>
|
168 |
-
</div>
|
169 |
-
|
170 |
-
<h5><?php _e('Module Settings', 'grand-media'); ?></h5>
|
171 |
-
</div>
|
172 |
-
<div class="row">
|
173 |
-
<div class="col-lg-5 tabable tabs-left">
|
174 |
-
<ul class="nav nav-tabs" id="galleryTabs">
|
175 |
-
<?php if(isset($module_info)) { ?>
|
176 |
-
<li class="text-center">
|
177 |
-
<strong><?php echo $module_info['title']; ?></strong><a href="#chooseModuleModal" data-toggle="modal" style="padding:5px 0;"><img src="<?php echo $term->module['url'] . '/screenshot.png'; ?>" alt="<?php echo esc_attr($module_info['title']); ?>" width="100" style="height:auto;"/></a>
|
178 |
-
</li>
|
179 |
-
<?php } else { ?>
|
180 |
-
<li class="text-center"><strong><?php echo $term->module['name']; ?></strong>
|
181 |
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
gmedia_gallery_options_nav($options_tree);
|
189 |
-
}
|
190 |
-
?>
|
191 |
-
</ul>
|
192 |
-
|
193 |
-
<div id="gallery_options_block" class="tab-content">
|
194 |
-
<?php
|
195 |
-
if(isset($options_tree)) {
|
196 |
-
gmedia_gallery_options_fieldset($options_tree, $default_options, $gallery_settings);
|
197 |
-
}
|
198 |
-
?>
|
199 |
-
</div>
|
200 |
-
|
201 |
-
</div>
|
202 |
-
<div class="col-lg-7">
|
203 |
-
<?php if($term_id) { ?>
|
204 |
-
<div><b><?php _e('Gallery Preview:'); ?></b></div>
|
205 |
-
<div class="gallery_preview">
|
206 |
-
<iframe id="gallery_preview" name="gallery_preview" src="<?php echo add_query_arg($params, set_url_scheme($gallery_link_default, 'admin')); ?>"></iframe>
|
207 |
-
</div>
|
208 |
-
<?php } ?>
|
209 |
-
</div>
|
210 |
-
</div>
|
211 |
-
<script type="text/javascript">
|
212 |
-
jQuery(function($) {
|
213 |
-
<?php if(!empty($alert)){ ?>
|
214 |
-
$('#chooseModuleModal').modal('show');
|
215 |
-
<?php } ?>
|
216 |
-
|
217 |
-
var hash = window.location.hash;
|
218 |
-
if(hash) {
|
219 |
-
$('#galleryTabs a').eq(hash.replace('#tab-', '')).tab('show');
|
220 |
-
}
|
221 |
-
$('.gallery_preview').resizable();
|
222 |
-
$('#gmedia-edit-gallery').on('submit', function() {
|
223 |
-
$(this).attr('action', $(this).attr('action') + '#tab-' + $('#galleryTabs li.active').index());
|
224 |
-
});
|
225 |
-
|
226 |
-
var main = $('#gallery_options_block');
|
227 |
-
|
228 |
-
$('input', main).filter('[data-type="color"]').minicolors({
|
229 |
-
animationSpeed: 50,
|
230 |
-
animationEasing: 'swing',
|
231 |
-
change: null,
|
232 |
-
changeDelay: 0,
|
233 |
-
control: 'hue',
|
234 |
-
//defaultValue: '',
|
235 |
-
hide: null,
|
236 |
-
hideSpeed: 100,
|
237 |
-
inline: false,
|
238 |
-
letterCase: 'lowercase',
|
239 |
-
opacity: false,
|
240 |
-
position: 'bottom left',
|
241 |
-
show: null,
|
242 |
-
showSpeed: 100,
|
243 |
-
theme: 'bootstrap'
|
244 |
-
});
|
245 |
-
|
246 |
-
$('[data-watch]', main).each(function() {
|
247 |
-
var el = $(this);
|
248 |
-
gmedia_options_conditional_logic(el, 0);
|
249 |
-
var event = el.attr('data-watch');
|
250 |
-
if(event) {
|
251 |
-
el.on(event, function() {
|
252 |
-
if('change' == el.attr('data-watch')) {
|
253 |
-
$(this).blur().focus();
|
254 |
-
}
|
255 |
-
gmedia_options_conditional_logic($(this), 400);
|
256 |
-
});
|
257 |
-
}
|
258 |
-
});
|
259 |
-
|
260 |
-
function gmedia_options_conditional_logic(el, slide) {
|
261 |
-
if(el.is(':input')) {
|
262 |
-
var val = el.val();
|
263 |
-
var id = el.attr('id').toLowerCase();
|
264 |
-
if(el.is(':checkbox') && !el[0].checked) {
|
265 |
-
val = '0';
|
266 |
-
}
|
267 |
-
$('[data-' + id + ']', main).each(function() {
|
268 |
-
var key = $(this).attr('data-' + id);
|
269 |
-
key = key.split(':');
|
270 |
-
//var hidden = $(this).data('hidden')? parseInt($(this).data('hidden')) : 0;
|
271 |
-
var hidden = $(this).data('hidden')? $(this).data('hidden') : {};
|
272 |
-
var ch = true;
|
273 |
-
switch(key[0]) {
|
274 |
-
case '=':
|
275 |
-
case 'is':
|
276 |
-
if(val == key[1]) {
|
277 |
-
delete hidden[id];
|
278 |
-
if(slide && $.isEmptyObject(hidden)) {
|
279 |
-
$(this).prop('disabled', false).closest('.form-group').stop().slideDown(slide, function() {
|
280 |
-
$(this).css({display: 'block'});
|
281 |
-
});
|
282 |
-
if(key[2]) {
|
283 |
-
key[2] = $(this).data('value');
|
284 |
-
} else {
|
285 |
-
ch = false;
|
286 |
-
}
|
287 |
-
} else {
|
288 |
-
ch = false;
|
289 |
-
}
|
290 |
-
$(this).data('hidden', hidden);
|
291 |
-
} else {
|
292 |
-
if($.isEmptyObject(hidden)) {
|
293 |
-
if(key[2]) {
|
294 |
-
$(this).closest('.form-group').stop().slideUp(slide, function() {
|
295 |
-
$(this).css({display: 'none'});
|
296 |
-
});
|
297 |
-
} else {
|
298 |
-
$(this).prop('disabled', true).closest('.form-group').stop().slideUp(slide, function() {
|
299 |
-
$(this).css({display: 'none'});
|
300 |
-
});
|
301 |
-
}
|
302 |
-
} else {
|
303 |
-
ch = false;
|
304 |
-
}
|
305 |
-
hidden[id] = 1;
|
306 |
-
$(this).data('hidden', hidden);
|
307 |
-
}
|
308 |
-
break;
|
309 |
-
case '!=':
|
310 |
-
case 'not':
|
311 |
-
if(val == key[1]) {
|
312 |
-
if($.isEmptyObject(hidden)) {
|
313 |
-
if(key[2]) {
|
314 |
-
$(this).closest('.form-group').stop().slideUp(slide, function() {
|
315 |
-
$(this).css({display: 'none'});
|
316 |
-
});
|
317 |
-
} else {
|
318 |
-
$(this).prop('disabled', true).closest('.form-group').stop().slideUp(slide, function() {
|
319 |
-
$(this).css({display: 'none'});
|
320 |
-
});
|
321 |
-
}
|
322 |
-
} else {
|
323 |
-
ch = false;
|
324 |
-
}
|
325 |
-
hidden[id] = 1;
|
326 |
-
$(this).data('hidden', hidden);
|
327 |
-
} else {
|
328 |
-
delete hidden[id];
|
329 |
-
if(slide && $.isEmptyObject(hidden)) {
|
330 |
-
$(this).prop('disabled', false).closest('.form-group').stop().slideDown(slide, function() {
|
331 |
-
$(this).css({display: 'block'});
|
332 |
-
});
|
333 |
-
if(key[2] && slide) {
|
334 |
-
key[2] = $(this).data('value');
|
335 |
-
} else {
|
336 |
-
ch = false;
|
337 |
-
}
|
338 |
-
} else {
|
339 |
-
ch = false;
|
340 |
}
|
341 |
-
$(
|
342 |
}
|
343 |
-
|
344 |
-
|
345 |
-
if(key[2] && ch) {
|
346 |
-
if($(this).is(':checkbox')) {
|
347 |
-
if(+($(this).prop('checked')) != parseInt(key[2])) {
|
348 |
-
$(this).data('value', ($(this).prop('checked')? '1' : '0'));
|
349 |
-
$(this).prop('checked', ('0' != key[2])).trigger('change');
|
350 |
}
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
$
|
355 |
}
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
}
|
360 |
-
}
|
361 |
-
});
|
362 |
-
|
363 |
-
</script>
|
364 |
-
</div>
|
365 |
-
|
366 |
-
</form>
|
367 |
-
|
368 |
-
<div class="modal fade gmedia-modal" id="buildQuery" tabindex="-1" role="dialog" aria-hidden="true">
|
369 |
-
<div class="modal-dialog" style="width:700px;">
|
370 |
-
<div class="modal-content">
|
371 |
-
<div class="modal-header">
|
372 |
-
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
373 |
-
<h4 class="modal-title"><?php _e('Query Parameters'); ?></h4>
|
374 |
-
</div>
|
375 |
-
<div class="modal-body">
|
376 |
-
|
377 |
-
<?php
|
378 |
-
$query_data = $gmedia_filter['query_data'];
|
379 |
-
if(gm_user_can('terms')) { ?>
|
380 |
-
<div class="form-group">
|
381 |
-
<?php
|
382 |
-
$term_type = 'gmedia_album';
|
383 |
-
$args = array();
|
384 |
-
if(gm_user_can('edit_others_media')) {
|
385 |
-
$args['global'] = '';
|
386 |
-
} else {
|
387 |
-
$args['global'] = array(0, $user_ID);
|
388 |
-
}
|
389 |
-
$gm_album_terms = $gmDB->get_terms($term_type, $args);
|
390 |
-
|
391 |
-
$no_term = array(
|
392 |
-
'term_id' => 0,
|
393 |
-
'name' => __('No Album', 'grand-media'),
|
394 |
-
);
|
395 |
-
if(count($gm_album_terms)) {
|
396 |
-
foreach($gm_album_terms as &$_term) {
|
397 |
-
unset($_term->description);
|
398 |
-
unset($_term->taxonomy);
|
399 |
-
$_term->by_author = $_term->global? sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $_term->global)) : '';
|
400 |
-
/* ('publish' == $_term->status? '' : " [{$_term->status}]") . ' (' . $_term->count . ')';*/
|
401 |
-
}
|
402 |
-
}
|
403 |
-
$gm_album_terms = array_merge(array($no_term), $gm_album_terms);
|
404 |
-
$query_gmedia_albums = array();
|
405 |
-
if(!empty($query_data['album__in'])) {
|
406 |
-
$query_gmedia_albums = wp_parse_id_list($query_data['album__in']);
|
407 |
-
} elseif(!empty($query_data['album__not_in'])) {
|
408 |
-
$query_gmedia_albums = wp_parse_id_list($query_data['album__not_in']);
|
409 |
-
}
|
410 |
-
?>
|
411 |
-
<label><?php _e('Albums', 'grand-media'); ?> </label>
|
412 |
-
|
413 |
-
<div class="row">
|
414 |
-
<div class="col-xs-8">
|
415 |
-
<input id="query_album__" name="album__in" data-include="album__in" data-exclude="album__not_in" class="form-control input-sm" value="<?php echo implode(',', $query_gmedia_albums) ?>" placeholder="<?php echo esc_attr(__('Any Album...', 'grand-media')); ?>"/>
|
416 |
-
</div>
|
417 |
-
<div class="col-xs-4">
|
418 |
-
<div class="checkbox"><label><input class="query_switch" data-target="query_album__" type="checkbox"<?php echo (empty($query_data['album__in']) && !empty($query_data['album__not_in']))? ' checked="checked"' : ''; ?> /> <?php _e('Exclude selected Albums', 'grand-media'); ?></label></div>
|
419 |
-
</div>
|
420 |
-
</div>
|
421 |
-
</div>
|
422 |
-
|
423 |
-
<div class="form-group">
|
424 |
-
<?php
|
425 |
-
$term_type = 'gmedia_category';
|
426 |
-
$gm_category_terms = $gmDB->get_terms($term_type, array('fields' => 'names_count'));
|
427 |
|
428 |
-
|
429 |
-
'term_id' => 0,
|
430 |
-
'name' => __('Uncategorized', 'grand-media'),
|
431 |
-
);
|
432 |
-
$gm_category_terms = array_merge(array($no_term), $gm_category_terms);
|
433 |
-
?>
|
434 |
-
<div class="row">
|
435 |
-
<div class="col-xs-4">
|
436 |
-
<label><?php _e('[IN] Categories', 'grand-media'); ?></label>
|
437 |
-
<input name="category__in" class="form-control input-sm combobox_gmedia_category" value="<?php echo implode(',', wp_parse_id_list($query_data['category__in'])); ?>" placeholder="<?php echo esc_attr(__('Either of chosen Categories...', 'grand-media')); ?>"/>
|
438 |
-
</div>
|
439 |
-
<div class="col-xs-4">
|
440 |
-
<label><?php _e('[AND] Categories', 'grand-media'); ?></label>
|
441 |
-
<input name="category__and" class="form-control input-sm combobox_gmedia_category" value="<?php echo implode(',', wp_parse_id_list($query_data['category__and'])); ?>" placeholder="<?php echo esc_attr(__('Have all chosen Categories...', 'grand-media')); ?>"/>
|
442 |
-
</div>
|
443 |
-
<div class="col-xs-4">
|
444 |
-
<label><?php _e('[NOT IN] Categories', 'grand-media'); ?></label>
|
445 |
-
<input name="category__not_in" class="form-control input-sm combobox_gmedia_category" value="<?php echo implode(',', wp_parse_id_list($query_data['category__not_in'])); ?>" placeholder="<?php echo esc_attr(__('Exclude Categories...', 'grand-media')); ?>"/>
|
446 |
-
</div>
|
447 |
-
</div>
|
448 |
-
</div>
|
449 |
-
|
450 |
-
<div class="form-group">
|
451 |
-
<?php
|
452 |
-
$term_type = 'gmedia_tag';
|
453 |
-
$gm_tag_terms = $gmDB->get_terms($term_type, array('fields' => 'names_count'));
|
454 |
-
?>
|
455 |
-
<div class="row">
|
456 |
-
<div class="col-xs-4">
|
457 |
-
<label><?php _e('[IN] Tags', 'grand-media'); ?> </label>
|
458 |
-
<input name="tag__in" class="form-control input-sm combobox_gmedia_tag" value="<?php echo implode(',', wp_parse_id_list($query_data['tag__in'])); ?>" placeholder="<?php echo esc_attr(__('Either of chosen Tags...', 'grand-media')); ?>"/>
|
459 |
-
</div>
|
460 |
-
<div class="col-xs-4">
|
461 |
-
<label><?php _e('[AND] Tags', 'grand-media'); ?> </label>
|
462 |
-
<input name="tag__and" class="form-control input-sm combobox_gmedia_tag" value="<?php echo implode(',', wp_parse_id_list($query_data['tag__and'])); ?>" placeholder="<?php echo esc_attr(__('Have all chosen Tags...', 'grand-media')); ?>"/>
|
463 |
-
</div>
|
464 |
-
<div class="col-xs-4">
|
465 |
-
<label><?php _e('[NOT IN] Tags', 'grand-media'); ?> </label>
|
466 |
-
<input name="tag__not_in" class="form-control input-sm combobox_gmedia_tag" value="<?php echo implode(',', wp_parse_id_list($query_data['tag__not_in'])); ?>" placeholder="<?php echo esc_attr(__('Exclude Tags...', 'grand-media')); ?>"/>
|
467 |
-
</div>
|
468 |
-
</div>
|
469 |
-
</div>
|
470 |
-
|
471 |
-
<?php } ?>
|
472 |
-
<div class="form-group">
|
473 |
-
<label><?php _e('Terms Relation', 'grand-media'); ?> </label>
|
474 |
-
|
475 |
-
<div class="row">
|
476 |
-
<div class="col-xs-4">
|
477 |
-
<select name="terms_relation" class="form-control input-sm">
|
478 |
-
<option <?php selected($query_data['terms_relation'], ''); ?> value=""><?php _e('Default (AND)'); ?></option>
|
479 |
-
<option <?php selected($query_data['terms_relation'], 'AND'); ?> value=""><?php _e('AND'); ?></option>
|
480 |
-
<option <?php selected($query_data['terms_relation'], 'OR'); ?> value="OR"><?php _e('OR'); ?></option>
|
481 |
-
</select>
|
482 |
-
</div>
|
483 |
-
<div class="col-xs-8">
|
484 |
-
<p class="help-block"><?php _e('allows you to describe the relationship between the taxonomy queries', 'grand-media'); ?></p>
|
485 |
-
</div>
|
486 |
-
</div>
|
487 |
-
</div>
|
488 |
-
<div class="form-group">
|
489 |
-
<label><?php _e('Search', 'grand-media'); ?></label>
|
490 |
-
|
491 |
-
<div class="row">
|
492 |
-
<div class="col-xs-8">
|
493 |
-
<input type="text" class="form-control input-sm" placeholder="<?php _e('Search string or terms separated by comma', 'grand-media'); ?>" value="<?php echo $query_data['s']; ?>" name="s">
|
494 |
-
</div>
|
495 |
-
<div class="col-xs-4">
|
496 |
-
<div class="checkbox"><label><input type="checkbox" name="exact" value="yes"<?php echo $query_data['exact']? ' checked="checked"' : ''; ?> /> <?php _e('Search exactly string', 'grand-media'); ?></label></div>
|
497 |
-
</div>
|
498 |
-
</div>
|
499 |
-
</div>
|
500 |
-
<div class="form-group">
|
501 |
-
<div class="row">
|
502 |
-
<div class="col-xs-8">
|
503 |
-
<div class="pull-right"><a id="use_lib_selected" class="label label-primary" href="#libselected"><?php _e('Use selected in Library', 'grand-media'); ?></a></div>
|
504 |
-
<label><?php _e('Gmedia IDs <small class="text-muted">separated by comma</small>', 'grand-media'); ?> </label>
|
505 |
-
</div>
|
506 |
-
</div>
|
507 |
-
<div class="row">
|
508 |
-
<div class="col-xs-8">
|
509 |
-
<?php $query_gmedia_items = array();
|
510 |
-
if(!empty($query_data['gmedia__in'])) {
|
511 |
-
$query_gmedia_items = $query_data['gmedia__in'];
|
512 |
-
} elseif(!empty($query_data['gmedia__not_in'])) {
|
513 |
-
$query_gmedia_items = $query_data['gmedia__not_in'];
|
514 |
-
}
|
515 |
-
?>
|
516 |
-
<textarea id="query_gmedia__" name="gmedia__in" data-include="gmedia__in" data-exclude="gmedia__not_in" rows="1" class="form-control input-sm" style="resize:vertical;" placeholder="<?php echo esc_attr(__('Gmedia IDs...', 'grand-media')); ?>"><?php echo implode(',', wp_parse_id_list($query_gmedia_items)); ?></textarea>
|
517 |
-
</div>
|
518 |
-
<div class="col-xs-4">
|
519 |
-
<div class="checkbox"><label><input class="query_switch" data-target="query_gmedia__" type="checkbox"<?php echo (empty($query_data['gmedia__in']) && !empty($query_data['gmedia__not_in']))? ' checked="checked"' : ''; ?> /> <?php _e('Exclude selected Items', 'grand-media'); ?></label></div>
|
520 |
-
</div>
|
521 |
-
</div>
|
522 |
-
<p class="help-block"><?php _e('You can select items you want to add here right in Gmedia Library and then return here and click button "Use selected in Library"', 'grand-media'); ?></p>
|
523 |
-
</div>
|
524 |
-
<div class="form-group">
|
525 |
-
<div class="row">
|
526 |
-
<div class="col-xs-4">
|
527 |
-
<label><?php _e('Mime Type', 'grand-media'); ?> </label>
|
528 |
-
<?php
|
529 |
-
$mime_types = array(
|
530 |
-
array('value' => 'image', 'text' => 'Image'),
|
531 |
-
array('value' => 'audio', 'text' => 'Audio'),
|
532 |
-
array('value' => 'video', 'text' => 'Video'),
|
533 |
-
array('value' => 'text', 'text' => 'Text'),
|
534 |
-
array('value' => 'application', 'text' => 'Application'),
|
535 |
-
);
|
536 |
-
?>
|
537 |
-
<input name="mime_type" class="form-control input-sm gmedia-combobox" data-options='<?php echo json_encode($mime_types); ?>' value="<?php echo implode(',', $query_data['mime_type']); ?>" placeholder="<?php esc_attr_e(__('All authors...', 'grand-media')); ?>"/>
|
538 |
-
</div>
|
539 |
-
<div class="col-xs-4">
|
540 |
-
<label><?php _e('Authors', 'grand-media'); ?></label>
|
541 |
-
<?php if(gm_user_can('show_others_media')) {
|
542 |
-
$user_ids = $gmCore->get_editable_user_ids();
|
543 |
-
if(!in_array($user_ID, $user_ids)) {
|
544 |
-
array_push($user_ids, $user_ID);
|
545 |
-
}
|
546 |
-
$filter_users = get_users(array('include' => $user_ids));
|
547 |
-
$users = '';
|
548 |
-
$_users = array();
|
549 |
-
if(count($filter_users)) {
|
550 |
-
foreach((array)$filter_users as $user) {
|
551 |
-
$user->ID = (int)$user->ID;
|
552 |
-
$_selected = in_array($user->ID, $query_data['author__in'])? ' selected="selected"' : '';
|
553 |
-
$users .= "<option value='{$user->ID}'{$_selected}>" . esc_html($user->display_name) . "</option>";
|
554 |
-
$_users[] = array('value' => $user->ID, 'text' => esc_html($user->display_name));
|
555 |
-
}
|
556 |
-
}
|
557 |
-
$query_authors = array();
|
558 |
-
if(!empty($query_data['author__in'])) {
|
559 |
-
$query_authors = $query_data['author__in'];
|
560 |
-
} elseif(!empty($query_data['author__not_in'])) {
|
561 |
-
$query_authors = $query_data['author__not_in'];
|
562 |
}
|
|
|
563 |
?>
|
564 |
-
|
565 |
-
<?php } else { ?>
|
566 |
-
<input type="text" readonly="readonly" name="author__in" class="form-control input-sm" value="<?php the_author_meta('display_name', $user_ID); ?>"/>
|
567 |
-
<?php } ?>
|
568 |
-
</div>
|
569 |
-
<?php if(gm_user_can('show_others_media')) { ?>
|
570 |
-
<div class="col-xs-4">
|
571 |
-
<label> </label>
|
572 |
-
<div class="checkbox"><label><input class="query_switch" data-target="query_author__" type="checkbox"<?php echo (empty($query_data['author__in']) && !empty($query_data['author__not_in']))? ' checked="checked"' : ''; ?> /> <?php _e('Exclude Authors', 'grand-media'); ?></label></div>
|
573 |
-
</div>
|
574 |
<?php } ?>
|
575 |
</div>
|
576 |
-
</
|
577 |
-
<div class="form-group">
|
578 |
-
<div class="row">
|
579 |
-
<div class="col-xs-4">
|
580 |
-
<label><?php _e('Year', 'grand-media'); ?></label>
|
581 |
-
<input type="text" class="form-control input-sm" placeholder="<?php _e('4 digit year e.g. 2011', 'grand-media'); ?>" value="<?php echo $query_data['year']; ?>" name="year">
|
582 |
-
</div>
|
583 |
-
<div class="col-xs-4">
|
584 |
-
<label><?php _e('Month', 'grand-media'); ?></label>
|
585 |
-
<input type="text" class="form-control input-sm" placeholder="<?php _e('from 1 to 12', 'grand-media'); ?>" value="<?php echo $query_data['monthnum']; ?>" name="monthnum">
|
586 |
-
</div>
|
587 |
-
<div class="col-xs-4">
|
588 |
-
<label><?php _e('Day', 'grand-media'); ?></label>
|
589 |
-
<input type="text" class="form-control input-sm" placeholder="<?php _e('from 1 to 31', 'grand-media'); ?>" value="<?php echo $query_data['day']; ?>" name="day">
|
590 |
-
</div>
|
591 |
-
</div>
|
592 |
-
</div>
|
593 |
-
<div class="form-group">
|
594 |
-
<?php foreach($query_data['meta_query'] as $i => $q) {
|
595 |
-
if($i) {
|
596 |
-
continue;
|
597 |
-
}
|
598 |
-
?>
|
599 |
-
<div class="row">
|
600 |
-
<div class="col-xs-6 col-sm-3">
|
601 |
-
<label><?php _e('Custom Field Key', 'grand-media'); ?></label>
|
602 |
-
<input type="text" class="form-control input-sm" value="<?php echo $q['key']; ?>" name="meta_query[<?php echo $i; ?>][key]">
|
603 |
-
<span class="help-block"><?php _e('Display items with this field key', 'grand-media'); ?></span>
|
604 |
-
</div>
|
605 |
-
<div class="col-xs-6 col-sm-3">
|
606 |
-
<label><?php _e('Custom Field Value', 'grand-media'); ?></label>
|
607 |
-
<input type="text" class="form-control input-sm" value="<?php echo $q['value']; ?>" name="meta_query[<?php echo $i; ?>][value]">
|
608 |
-
<span class="help-block"><?php _e('Display items with this field value', 'grand-media'); ?></span>
|
609 |
-
</div>
|
610 |
-
<div class="col-xs-6 col-sm-3">
|
611 |
-
<label><?php _e('Compare Operator', 'grand-media'); ?></label>
|
612 |
-
<select class="form-control input-sm" name="meta_query[<?php echo $i; ?>][compare]">
|
613 |
-
<option <?php selected($q['compare'], ''); ?> value=""><?php _e('Default', 'grand-media'); ?> (=)</option>
|
614 |
-
<option <?php selected($q['compare'], '='); ?> value="">=</option>
|
615 |
-
<option <?php selected($q['compare'], '!='); ?> value="!=">!=</option>
|
616 |
-
<option <?php selected($q['compare'], '>'); ?> value=">">></option>
|
617 |
-
<option <?php selected($q['compare'], '>='); ?> value=">=">>=</option>
|
618 |
-
<option <?php selected($q['compare'], '<'); ?> value="<"><</option>
|
619 |
-
<option <?php selected($q['compare'], '<='); ?> value="<="><=</option>
|
620 |
-
<option <?php selected($q['compare'], 'LIKE'); ?> value="LIKE">LIKE</option>
|
621 |
-
<option <?php selected($q['compare'], 'NOT LIKE'); ?> value="NOT LIKE">NOT LIKE</option>
|
622 |
-
<?php /* ?>
|
623 |
-
<option <?php selected($q['compare'], 'IN'); ?> value="IN">IN</option>
|
624 |
-
<option <?php selected($q['compare'], 'NOT IN'); ?> value="NOT IN">NOT IN</option>
|
625 |
-
<option <?php selected($q['compare'], 'BETWEEN'); ?> value="BETWEEN">BETWEEN</option>
|
626 |
-
<option <?php selected($q['compare'], 'NOT BETWEEN'); ?> value="NOT BETWEEN">NOT BETWEEN</option>
|
627 |
-
<?php */ ?>
|
628 |
-
<option <?php selected($q['compare'], 'EXISTS'); ?> value="EXISTS">EXISTS</option>
|
629 |
-
</select>
|
630 |
-
<span class="help-block"><?php _e('Operator to test the field value', 'grand-media'); ?></span>
|
631 |
-
</div>
|
632 |
-
<div class="col-xs-6 col-sm-3">
|
633 |
-
<label><?php _e('Meta Type', 'grand-media'); ?></label>
|
634 |
-
<select class="form-control input-sm" name="meta_query[<?php echo $i; ?>][type]">
|
635 |
-
<option <?php selected($q['type'], ''); ?> value=""><?php _e('Default', 'grand-media'); ?> (CHAR)</option>
|
636 |
-
<option <?php selected($q['type'], 'CHAR'); ?> value="">CHAR</option>
|
637 |
-
<option <?php selected($q['type'], 'NUMERIC'); ?> value="NUMERIC">NUMERIC</option>
|
638 |
-
<option <?php selected($q['type'], 'DECIMAL'); ?> value="DECIMAL">DECIMAL</option>
|
639 |
-
<option <?php selected($q['type'], 'DATE'); ?> value="DATE">DATE</option>
|
640 |
-
<option <?php selected($q['type'], 'DATETIME'); ?> value="DATETIME">DATETIME</option>
|
641 |
-
<option <?php selected($q['type'], 'TIME'); ?> value="TIME">TIME</option>
|
642 |
-
<option <?php selected($q['type'], 'BINARY'); ?> value="BINARY">BINARY</option>
|
643 |
-
<option <?php selected($q['type'], 'SIGNED'); ?> value="SIGNED">SIGNED</option>
|
644 |
-
<option <?php selected($q['type'], 'UNSIGNED'); ?> value="UNSIGNED">UNSIGNED</option>
|
645 |
-
</select>
|
646 |
-
<span class="help-block"><?php _e('Custom field type', 'grand-media'); ?></span>
|
647 |
-
</div>
|
648 |
-
</div>
|
649 |
-
<?php } ?>
|
650 |
-
</div>
|
651 |
-
<div class="form-group">
|
652 |
-
<div class="row">
|
653 |
-
<div class="col-xs-6 col-sm-3">
|
654 |
-
<label><?php _e('Order', 'grand-media'); ?></label>
|
655 |
-
<select class="form-control input-sm" name="order">
|
656 |
-
<option <?php selected($query_data['order'], ''); ?> value=""><?php _e('Default (DESC)', 'grand-media'); ?></option>
|
657 |
-
<option <?php selected($query_data['order'], 'DESC'); ?> value=""><?php _e('DESC', 'grand-media'); ?></option>
|
658 |
-
<option <?php selected($query_data['order'], 'ASC'); ?> value="ASC"><?php _e('ASC', 'grand-media'); ?></option>
|
659 |
-
</select>
|
660 |
-
<span class="help-block"><?php _e('Ascending or Descending order', 'grand-media'); ?></span>
|
661 |
-
</div>
|
662 |
-
<div class="col-xs-6 col-sm-3">
|
663 |
-
<label><?php _e('Order by', 'grand-media'); ?></label>
|
664 |
-
<select class="form-control input-sm" name="orderby">
|
665 |
-
<option <?php selected($query_data['orderby'], ''); ?> value=""><?php _e('Default (ID)', 'grand-media'); ?></option>
|
666 |
-
<option <?php selected($query_data['orderby'], 'id'); ?> value=""><?php _e('ID', 'grand-media'); ?></option>
|
667 |
-
<option <?php selected($query_data['orderby'], 'title'); ?> value="title"><?php _e('Title', 'grand-media'); ?></option>
|
668 |
-
<option <?php selected($query_data['orderby'], 'gmuid'); ?> value="gmuid"><?php _e('Filename', 'grand-media'); ?></option>
|
669 |
-
<option <?php selected($query_data['orderby'], 'date'); ?> value="date"><?php _e('Date', 'grand-media'); ?></option>
|
670 |
-
<option <?php selected($query_data['orderby'], 'modified'); ?> value="modified"><?php _e('Modified Date', 'grand-media'); ?></option>
|
671 |
-
<option <?php selected($query_data['orderby'], 'author'); ?> value="author"><?php _e('Author', 'grand-media'); ?></option>
|
672 |
-
<option <?php selected($query_data['orderby'], 'gmedia__in'); ?> value="gmedia__in"><?php _e('Selected Order', 'grand-media'); ?></option>
|
673 |
-
<option <?php selected($query_data['orderby'], 'meta_value'); ?> value="meta_value"><?php _e('Custom Field Value', 'grand-media'); ?></option>
|
674 |
-
<option <?php selected($query_data['orderby'], 'meta_value_num'); ?> value="meta_value_num"><?php _e('Custom Field Value (Numeric)', 'grand-media'); ?></option>
|
675 |
-
<option <?php selected($query_data['orderby'], 'rand'); ?> value="rand"><?php _e('Random', 'grand-media'); ?></option>
|
676 |
-
<option <?php selected($query_data['orderby'], 'none'); ?> value="none"><?php _e('None', 'grand-media'); ?></option>
|
677 |
-
</select>
|
678 |
-
<span class="help-block"><?php _e('Sort retrieved posts by', 'grand-media'); ?></span>
|
679 |
-
</div>
|
680 |
-
<div class="col-xs-6 col-sm-3">
|
681 |
-
<label><?php _e('Limit', 'grand-media'); ?></label>
|
682 |
-
<input type="text" class="form-control input-sm" value="<?php echo $query_data['limit']; ?>" name="limit" placeholder="<?php _e('leave empty for no limit', 'grand-media'); ?>">
|
683 |
-
<span class="help-block"><?php _e('Limit number of gmedia items', 'grand-media'); ?></span>
|
684 |
-
</div>
|
685 |
-
</div>
|
686 |
-
</div>
|
687 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
688 |
<script type="text/javascript">
|
689 |
jQuery(function($) {
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
$('#query_album__').selectize({
|
696 |
-
plugins: ['drag_drop'],
|
697 |
-
create: false,
|
698 |
-
options: gmedia_albums,
|
699 |
-
hideSelected: true,
|
700 |
-
allowEmptyOption: true,
|
701 |
-
valueField: 'term_id',
|
702 |
-
searchField: ['name'],
|
703 |
-
//labelField: 'name',
|
704 |
-
render: {
|
705 |
-
item: function(item, escape) {
|
706 |
-
var count = '';
|
707 |
-
var status = '';
|
708 |
-
var author = '';
|
709 |
-
if(item.term_id) {
|
710 |
-
count = '(' + escape(item.count) + ')';
|
711 |
-
status = (typeof item.status != 'undefined' && ('publish' != item.status))? ' [' + item.status + '] ' : '';
|
712 |
-
author = ' ' + item.by_author;
|
713 |
-
}
|
714 |
-
return '<div>' + escape(item.name) + ' <small>' + count + status + author + '</small></div>';
|
715 |
-
},
|
716 |
-
option: function(item, escape) {
|
717 |
-
var count = '';
|
718 |
-
var status = '';
|
719 |
-
var author = '';
|
720 |
-
if(item.term_id) {
|
721 |
-
count = '(' + escape(item.count) + ')';
|
722 |
-
status = (typeof item.status != 'undefined' && ('publish' != item.status))? ' [' + item.status + '] ' : '';
|
723 |
-
author = ' ' + item.by_author;
|
724 |
-
}
|
725 |
-
return '<div>' + escape(item.name) + ' <small>' + count + status + author + '</small></div>';
|
726 |
-
}
|
727 |
-
}
|
728 |
-
|
729 |
-
});
|
730 |
-
var cats = $('.combobox_gmedia_category').selectize({
|
731 |
-
create: false,
|
732 |
-
options: gmedia_categories,
|
733 |
-
preload: true,
|
734 |
-
hideSelected: true,
|
735 |
-
allowEmptyOption: true,
|
736 |
-
valueField: 'term_id',
|
737 |
-
searchField: ['name'],
|
738 |
-
//labelField: 'name',
|
739 |
-
render: {
|
740 |
-
item: function(item, escape) {
|
741 |
-
var count = '';
|
742 |
-
if(item.term_id) {
|
743 |
-
count = ' <small>(' + escape(item.count) + ')</small>';
|
744 |
-
}
|
745 |
-
return '<div>' + escape(item.name) + count + '</div>';
|
746 |
-
},
|
747 |
-
option: function(item, escape) {
|
748 |
-
if(('category__and' == this.$input[0].name) && !item.term_id) {
|
749 |
-
return '';
|
750 |
-
}
|
751 |
-
var count = '';
|
752 |
-
if(item.term_id) {
|
753 |
-
count = ' <small>(' + escape(item.count) + ')</small>';
|
754 |
-
}
|
755 |
-
return '<div>' + escape(item.name) + count + '</div>';
|
756 |
-
}
|
757 |
-
}
|
758 |
-
|
759 |
-
}).on('change', function() {
|
760 |
-
var allSelected = [];
|
761 |
-
jQuery.each(cats, function(i, e) {
|
762 |
-
allSelected = jQuery.merge(allSelected, e.selectize.items);
|
763 |
-
});
|
764 |
-
|
765 |
-
jQuery.each(cats, function(i, e) {
|
766 |
-
var orig_items = e.selectize.items;
|
767 |
-
e.selectize.items = allSelected;
|
768 |
-
e.selectize.currentResults = e.selectize.search();
|
769 |
-
e.selectize.refreshOptions(false);
|
770 |
-
e.selectize.items = orig_items;
|
771 |
-
|
772 |
-
});
|
773 |
-
});
|
774 |
-
|
775 |
-
var tags = $('.combobox_gmedia_tag').selectize({
|
776 |
-
create: false,
|
777 |
-
options: gmedia_tags,
|
778 |
-
hideSelected: true,
|
779 |
-
allowEmptyOption: true,
|
780 |
-
valueField: 'term_id',
|
781 |
-
searchField: ['name'],
|
782 |
-
render: {
|
783 |
-
item: function(item, escape) {
|
784 |
-
return '<div>' + escape(item.name) + ' <small>(' + escape(item.count) + ')</small></div>';
|
785 |
-
},
|
786 |
-
option: function(item, escape) {
|
787 |
-
return '<div>' + escape(item.name) + ' <small>(' + escape(item.count) + ')</small></div>';
|
788 |
-
}
|
789 |
-
}
|
790 |
-
|
791 |
-
}).on('change', function() {
|
792 |
-
var allSelected = [];
|
793 |
-
jQuery.each(tags, function(i, e) {
|
794 |
-
allSelected = jQuery.merge(allSelected, e.selectize.items);
|
795 |
-
});
|
796 |
|
797 |
-
|
798 |
-
var orig_items = e.selectize.items;
|
799 |
-
e.selectize.items = allSelected;
|
800 |
-
e.selectize.currentResults = e.selectize.search();
|
801 |
-
e.selectize.refreshOptions(false);
|
802 |
-
e.selectize.items = orig_items;
|
803 |
|
804 |
-
|
805 |
-
});
|
806 |
-
;
|
807 |
-
<?php } ?>
|
808 |
|
809 |
-
|
810 |
-
var select = $(this).selectize({
|
811 |
-
create: false,
|
812 |
-
hideSelected: true,
|
813 |
-
options: $(this).data('options')
|
814 |
-
});
|
815 |
-
});
|
816 |
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
} else {
|
822 |
-
el.attr('name', el.attr('data-include'));
|
823 |
-
}
|
824 |
-
});
|
825 |
-
$('#use_lib_selected').on('click', function() {
|
826 |
-
var field = $('#query_gmedia__');
|
827 |
-
var valData = field.val().split(',');
|
828 |
-
var storedData = getStorage('gmuser_<?php echo $user_ID; ?>_');
|
829 |
-
storedData = storedData.get('library').split(',');
|
830 |
-
valData = $.grep(valData, function(e) {
|
831 |
-
return e;
|
832 |
-
});
|
833 |
-
$.each(storedData, function(i, id) {
|
834 |
-
if(!id) {
|
835 |
-
return true;
|
836 |
-
}
|
837 |
-
if($.inArray(id, valData) === -1) {
|
838 |
-
valData.push(id);
|
839 |
-
}
|
840 |
-
});
|
841 |
-
field.val(valData.join(','));
|
842 |
-
});
|
843 |
-
});
|
844 |
|
845 |
-
|
846 |
-
<div class="modal-footer">
|
847 |
-
<button type="button" class="btn btn-primary buildquerysubmit"><?php _e('Build Query', 'grand-media'); ?></button>
|
848 |
-
<button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Close', 'grand-media'); ?></button>
|
849 |
-
</div>
|
850 |
-
</div>
|
851 |
-
</div>
|
852 |
-
</div>
|
853 |
-
|
854 |
-
<?php if($term_id) { ?>
|
855 |
-
<div class="modal fade gmedia-modal" id="newCustomFieldModal" tabindex="-1" role="dialog" aria-hidden="true">
|
856 |
-
<div class="modal-dialog">
|
857 |
-
<div class="modal-content">
|
858 |
-
<div class="modal-header">
|
859 |
-
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
860 |
-
<h4 class="modal-title"><?php _e('Add New Custom Field'); ?></h4>
|
861 |
-
</div>
|
862 |
-
<form class="modal-body" method="post" id="newCustomFieldForm">
|
863 |
-
<?php
|
864 |
-
echo $gmCore->meta_form($meta_type = 'gmedia_term');
|
865 |
-
wp_nonce_field('gmedia_custom_field', '_customfield_nonce');
|
866 |
-
wp_referer_field();
|
867 |
-
?>
|
868 |
-
<input type="hidden" name="action" value="gmedia_term_add_custom_field"/>
|
869 |
-
<input type="hidden" class="newcustomfield-for-id" name="ID" value=""/>
|
870 |
-
</form>
|
871 |
-
<div class="modal-footer">
|
872 |
-
<button type="button" class="btn btn-primary customfieldsubmit"><?php _e('Add', 'grand-media'); ?></button>
|
873 |
-
<button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Close', 'grand-media'); ?></button>
|
874 |
-
</div>
|
875 |
-
</div>
|
876 |
-
</div>
|
877 |
-
</div>
|
878 |
-
<?php } ?>
|
879 |
|
880 |
-
<?php if(gm_user_can('edit_others_media'))
|
881 |
<div class="modal fade gmedia-modal" id="gallModal" tabindex="-1" role="dialog" aria-hidden="true">
|
882 |
<div class="modal-dialog"></div>
|
883 |
</div>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Edit Gallery Form
|
9 |
*/
|
10 |
?>
|
11 |
+
<form method="post" id="gmedia-edit-term" name="gmEditTerm" data-id="<?php echo $term_id; ?>" action="<?php echo $gmedia_url; ?>">
|
|
|
12 |
<div class="panel-body">
|
13 |
<!--<h4 style="margin-top:0;">
|
14 |
<?php /*if($term_id) { */ ?>
|
52 |
<div class="form-group">
|
53 |
<div class="pull-right"><a id="build_query" class="label label-primary buildquery-modal" href="#buildQuery" style="font-size:90%;"><?php _e('Build Query', 'grand-media'); ?></a></div>
|
54 |
<label><?php _e('Query Args.', 'grand-media'); ?></label>
|
55 |
+
<textarea class="form-control input-sm" id="build_query_field" style="height:64px;"
|
56 |
+
placeholder="<?php _e("Click 'Build Query' button for help with Query Args.\nIf you leave this field empty then whole Library will be loaded. That's could exceed your server's PHP Memory Limit.", 'grand-media') ?>"
|
57 |
+
rows="2" name="term[query]"><?php echo(empty($gmedia_filter['query_args'])? '' : urldecode(build_query($gmedia_filter['query_args']))); ?></textarea>
|
58 |
</div>
|
59 |
</div>
|
60 |
</div>
|
76 |
</label>
|
77 |
<div>
|
78 |
<div class="btn-group btn-group-sm" id="save_buttons">
|
79 |
+
<?php if($term->module['name'] != $term->meta['_module']){ ?>
|
80 |
<a href="<?php echo $gmedia_url; ?>" class="btn btn-default"><?php _e('Cancel preview module', 'grand-media'); ?></a>
|
81 |
<button type="submit" name="gmedia_gallery_save" class="btn btn-primary"><?php _e('Save with new module', 'grand-media'); ?></button>
|
82 |
+
<?php } else{ ?>
|
83 |
<?php $reset_settings = $gmCore->array_diff_keyval_recursive($default_options, $gallery_settings, true);
|
84 |
+
if(!empty($reset_settings)){
|
85 |
?>
|
86 |
<button type="submit" name="gmedia_gallery_reset" class="btn btn-default" data-confirm="<?php _e('Confirm reset module settings to default preset') ?>"><?php _e('Reset to default', 'grand-media'); ?></button>
|
87 |
<?php } ?>
|
94 |
<p><b><?php _e('Gallery ID:'); ?></b> #<?php echo $term_id; ?></p>
|
95 |
<p><b><?php _e('Last edited:'); ?></b> <?php echo $term->meta['_edited']; ?></p>
|
96 |
<p><?php echo '<b>' . __('Gallery module:') . '</b> <a href="#chooseModuleModal" data-toggle="modal">' . $term->meta['_module'] . '</a>';
|
97 |
+
if($term->module['name'] != $term->meta['_module']){
|
98 |
echo '<br /><b>' . __('Preview module:') . '</b> ' . $term->module['name'];
|
99 |
echo '<br /><span class="text-danger">' . sprintf(__('Note: Module changed to %s, but not saved yet'), $term->module['name']) . '</span>';
|
100 |
} ?></p>
|
101 |
<input type="hidden" name="term[module]" value="<?php echo esc_attr($term->module['name']); ?>">
|
102 |
+
<?php if($term_id){
|
103 |
+
$params = array();
|
104 |
+
if($term->module['name'] != $term->meta['_module']){
|
105 |
+
$params['gmedia_module'] = $term->module['name'];
|
106 |
+
}
|
107 |
+
$params['iframe'] = 1;
|
108 |
?>
|
109 |
<p><b><?php _e('GmediaCloud page URL for current gallery:'); ?></b> <?php
|
110 |
$endpoint = $gmGallery->options['endpoint'];
|
111 |
$gmedia_hashid = gmedia_hash_id_encode($term_id, 'gallery');
|
112 |
$gallery_link_default = add_query_arg(array("$endpoint" => $gmedia_hashid, 't' => 'g'), home_url('index.php'));
|
113 |
+
if(get_option('permalink_structure')){
|
114 |
$gallery_link = home_url(urlencode($endpoint) . '/g/' . $gmedia_hashid);
|
115 |
+
} else{
|
116 |
$gallery_link = $gallery_link_default;
|
117 |
} ?>
|
118 |
<br/><a target="_blank" href="<?php echo $gallery_link; ?>"><?php echo $gallery_link; ?></a>
|
119 |
</p>
|
120 |
+
<?php if($term->post_id){ ?>
|
121 |
<p><b><?php _e('Gmedia Post URL for current gallery:'); ?></b>
|
122 |
<?php $post_link = get_permalink($term->post_id); ?>
|
123 |
<br/><a target="_blank" href="<?php echo $post_link; ?>"><?php echo $post_link; ?></a>
|
125 |
<?php } ?>
|
126 |
<div class="help-block">
|
127 |
<?php _e('update <a href="options-permalink.php">Permalink Settings</a> if above link not working', 'grand-media'); ?>
|
128 |
+
<?php if(current_user_can('manage_options')){
|
129 |
echo '<br>' . __('More info about GmediaCloud Pages and GmediaCloud Settings can be found <a href="admin.php?page=GrandMedia_Settings#gmedia_settings_cloud">here</a>', 'grand-media');
|
130 |
} ?>
|
131 |
</div>
|
137 |
<div class="well well-sm clearfix">
|
138 |
<div class="btn-toolbar pull-right" id="module_preset">
|
139 |
<div class="btn-group">
|
140 |
+
<button type="button" class="btn btn-default<?php echo ($term->module['name'] != $term->meta['_module'])? ' disabled' : ''; ?>" id="module_presets" data-toggle="popover"><?php _e('Module Presets', 'grand-media'); ?></button>
|
141 |
</div>
|
142 |
+
<script type="text/html" id="_module_presets">
|
143 |
<div style="padding-top: 5px;">
|
144 |
+
<?php if(current_user_can('manage_options')){ ?>
|
145 |
+
<p><button type="button" name="module_preset_save_global" class="ajax-submit btn btn-default btn-sm" style="width:100%"><?php _e('Save as Global Preset', 'grand-media'); ?></button></p>
|
146 |
+
<?php } ?>
|
147 |
<p style="white-space: nowrap">
|
148 |
<button type="button" name="module_preset_save_default" class="ajax-submit btn btn-default btn-sm"><?php _e('Save as Default', 'grand-media'); ?></button>
|
149 |
<em><?php _e('or', 'grand-media'); ?></em>
|
150 |
+
<?php if(!empty($default_preset)){ ?>
|
151 |
<button type="button" name="module_preset_restore_original" class="ajax-submit btn btn-default btn-sm"><?php _e('Restore Original', 'grand-media'); ?></button>
|
152 |
<input type="hidden" name="preset_default" value="<?php echo $default_preset['term_id']; ?>"/>
|
153 |
<?php } ?>
|
157 |
|
158 |
<div class="input-group input-group-sm">
|
159 |
<input type="text" class="form-control input-sm" name="module_preset_name" placeholder="<?php _e('Preset Name', 'grand-media'); ?>" value=""/>
|
160 |
+
<span class="input-group-btn"><button type="button" name="module_preset_save" class="ajax-submit btn btn-primary"><?php _e('Save', 'grand-media'); ?></button></span>
|
161 |
</div>
|
162 |
</div>
|
163 |
|
164 |
+
<?php if(!empty($presets)){ ?>
|
165 |
<ul class="list-group presetlist">
|
166 |
+
<?php foreach($presets as $preset){
|
167 |
+
$href = $gmCore->get_admin_url(array('preset' => $preset->term_id), array());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
+
$count = 1;
|
170 |
+
$name = trim(str_replace('[' . $term->module['name'] . ']', '', $preset->name, $count));
|
171 |
+
$by = '';
|
172 |
+
if(!$name){
|
173 |
+
if(!(int)$preset->global){
|
174 |
+
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
}
|
176 |
+
$name = __('Default Settings', 'grand-media');
|
177 |
}
|
178 |
+
if((int)$preset->global){
|
179 |
+
$by = ' <small style="white-space:nowrap">[' . get_the_author_meta('display_name', $preset->global) . ']</small>';
|
|
|
|
|
|
|
|
|
|
|
180 |
}
|
181 |
+
$li_item = '
|
182 |
+
<li class="list-group-item" id="gm-preset-' . $preset->term_id . '">';
|
183 |
+
if($user_ID == $preset->global || ((int)$preset->global && $gmCore->caps['gmedia_edit_others_media']) || current_user_can('manage_options')){
|
184 |
+
$li_item .= '<span class="delpreset"><span class="label label-danger" data-id="' . $preset->term_id . '">×</span></span>';
|
185 |
}
|
186 |
+
$li_item .= '
|
187 |
+
<a href="' . $href . '">' . $name . $by . '</a>
|
188 |
+
</li>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
+
$li[] = $li_item;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
}
|
192 |
+
echo implode('', $li);
|
193 |
?>
|
194 |
+
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
<?php } ?>
|
196 |
</div>
|
197 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
</div>
|
199 |
+
|
200 |
+
<h5><?php _e('Module Settings', 'grand-media'); ?></h5>
|
201 |
+
</div>
|
202 |
+
<?php
|
203 |
+
include(GMEDIA_ABSPATH . 'admin/pages/galleries/tpl/module-settings.php');
|
204 |
+
?>
|
205 |
+
<?php if(!empty($alert)){ ?>
|
206 |
<script type="text/javascript">
|
207 |
jQuery(function($) {
|
208 |
+
$('#chooseModuleModal').modal('show');
|
209 |
+
});
|
210 |
+
</script>
|
211 |
+
<?php } ?>
|
212 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
+
</form>
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
+
<?php
|
|
|
|
|
|
|
217 |
|
218 |
+
include(GMEDIA_ABSPATH . 'admin/pages/galleries/tpl/modal-build-query.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
+
if($term_id){
|
221 |
+
$customfield_meta_type = 'gmedia_term';
|
222 |
+
include(GMEDIA_ABSPATH . 'admin/tpl/modal-customfield.php');
|
223 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
+
<?php if(gm_user_can('edit_others_media')){ ?>
|
228 |
<div class="modal fade gmedia-modal" id="gallModal" tabindex="-1" role="dialog" aria-hidden="true">
|
229 |
<div class="modal-dialog"></div>
|
230 |
</div>
|
admin/pages/galleries/tpl/gallery-list-item.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Gallery list item
|
4 |
*
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Gallery list item
|
9 |
*
|
admin/pages/galleries/tpl/gallery-panel-heading.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Panel heading for term
|
4 |
*
|
@@ -10,7 +15,7 @@
|
|
10 |
<div class="panel-heading-fake"></div>
|
11 |
<div class="panel-heading clearfix">
|
12 |
<div class="btn-toolbar pull-left">
|
13 |
-
<a class="btn btn-default pull-left" style="margin-right:20px;" href="<?php echo remove_query_arg(array('edit_item'), wp_get_referer()); ?>"><?php _e('Go Back', 'grand-media'); ?></a>
|
14 |
|
15 |
<?php if($term_id) { ?>
|
16 |
<div class="btn-group">
|
@@ -20,12 +25,12 @@
|
|
20 |
<span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?></span>
|
21 |
</button>
|
22 |
<ul class="dropdown-menu" role="menu">
|
23 |
-
<li><a href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'gallery' => $term->term_id),
|
24 |
</ul>
|
25 |
</div>
|
26 |
<?php } ?>
|
27 |
<?php if($term_id) { ?>
|
28 |
-
<input type="text" title="<?php _e('Shortcode'); ?>" class="form-control pull-left"
|
29 |
<?php } ?>
|
30 |
</div>
|
31 |
|
@@ -41,4 +46,5 @@
|
|
41 |
<?php } ?>
|
42 |
</div>
|
43 |
|
|
|
44 |
</div>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Panel heading for term
|
9 |
*
|
15 |
<div class="panel-heading-fake"></div>
|
16 |
<div class="panel-heading clearfix">
|
17 |
<div class="btn-toolbar pull-left">
|
18 |
+
<a class="btn btn-default pull-left" style="margin-right:20px;" href="<?php echo remove_query_arg(array('edit_item', 'gmedia_module'), wp_get_referer()); ?>"><?php _e('Go Back', 'grand-media'); ?></a>
|
19 |
|
20 |
<?php if($term_id) { ?>
|
21 |
<div class="btn-group">
|
25 |
<span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?></span>
|
26 |
</button>
|
27 |
<ul class="dropdown-menu" role="menu">
|
28 |
+
<li><a href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'gallery' => $term->term_id), $gmProcessor->url); ?>"><?php _e('Show in Gmedia Library', 'grand-media'); ?></a></li>
|
29 |
</ul>
|
30 |
</div>
|
31 |
<?php } ?>
|
32 |
<?php if($term_id) { ?>
|
33 |
+
<div class="term-shortcode pull-left"><input type="text" title="<?php _e('Shortcode'); ?>" class="form-control pull-left" value="<?php echo "[gmedia id={$term_id}]"; ?>" readonly /><div class="input-buffer"></div></div>
|
34 |
<?php } ?>
|
35 |
</div>
|
36 |
|
46 |
<?php } ?>
|
47 |
</div>
|
48 |
|
49 |
+
<div class="spinner"></div>
|
50 |
</div>
|
admin/pages/galleries/tpl/modal-build-query.php
ADDED
@@ -0,0 +1,500 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Modal for Build Query
|
9 |
+
* @var $gm_album_terms
|
10 |
+
* @var $gm_category_terms
|
11 |
+
* @var $gm_tag_terms
|
12 |
+
*/
|
13 |
+
global $user_ID, $gmDB, $gmCore
|
14 |
+
?>
|
15 |
+
<div class="modal fade gmedia-modal" id="buildQuery" tabindex="-1" role="dialog" aria-hidden="true">
|
16 |
+
<div class="modal-dialog" style="width:700px;">
|
17 |
+
<div class="modal-content">
|
18 |
+
<div class="modal-header">
|
19 |
+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
20 |
+
<h4 class="modal-title"><?php _e('Query Parameters'); ?></h4>
|
21 |
+
</div>
|
22 |
+
<div class="modal-body">
|
23 |
+
|
24 |
+
<?php
|
25 |
+
$query_data = $gmedia_filter['query_data'];
|
26 |
+
if(gm_user_can('terms')) { ?>
|
27 |
+
<div class="form-group">
|
28 |
+
<?php
|
29 |
+
$term_type = 'gmedia_album';
|
30 |
+
$args = array();
|
31 |
+
if(gm_user_can('edit_others_media')) {
|
32 |
+
$args['global'] = '';
|
33 |
+
} else {
|
34 |
+
$args['global'] = array(0, $user_ID);
|
35 |
+
}
|
36 |
+
$gm_album_terms = $gmDB->get_terms($term_type, $args);
|
37 |
+
|
38 |
+
$no_term = array(
|
39 |
+
'term_id' => 0,
|
40 |
+
'name' => __('No Album', 'grand-media'),
|
41 |
+
);
|
42 |
+
if(count($gm_album_terms)) {
|
43 |
+
foreach($gm_album_terms as &$_term) {
|
44 |
+
unset($_term->description);
|
45 |
+
unset($_term->taxonomy);
|
46 |
+
$_term->by_author = $_term->global? sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $_term->global)) : '';
|
47 |
+
/* ('publish' == $_term->status? '' : " [{$_term->status}]") . ' (' . $_term->count . ')';*/
|
48 |
+
}
|
49 |
+
}
|
50 |
+
$gm_album_terms = array_merge(array($no_term), $gm_album_terms);
|
51 |
+
$query_gmedia_albums = array();
|
52 |
+
if(!empty($query_data['album__in'])) {
|
53 |
+
$query_gmedia_albums = wp_parse_id_list($query_data['album__in']);
|
54 |
+
} elseif(!empty($query_data['album__not_in'])) {
|
55 |
+
$query_gmedia_albums = wp_parse_id_list($query_data['album__not_in']);
|
56 |
+
}
|
57 |
+
?>
|
58 |
+
<label><?php _e('Albums', 'grand-media'); ?> </label>
|
59 |
+
|
60 |
+
<div class="row">
|
61 |
+
<div class="col-xs-8">
|
62 |
+
<input id="query_album__" name="album__in" data-include="album__in" data-exclude="album__not_in" class="form-control input-sm" value="<?php echo implode(',', $query_gmedia_albums) ?>" placeholder="<?php echo esc_attr(__('Any Album...', 'grand-media')); ?>"/>
|
63 |
+
</div>
|
64 |
+
<div class="col-xs-4">
|
65 |
+
<div class="checkbox"><label><input class="query_switch" data-target="query_album__" type="checkbox"<?php echo (empty($query_data['album__in']) && !empty($query_data['album__not_in']))? ' checked="checked"' : ''; ?> /> <?php _e('Exclude selected Albums', 'grand-media'); ?></label></div>
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
</div>
|
69 |
+
|
70 |
+
<div class="form-group">
|
71 |
+
<?php
|
72 |
+
$term_type = 'gmedia_category';
|
73 |
+
$gm_category_terms = $gmDB->get_terms($term_type, array('fields' => 'names_count'));
|
74 |
+
|
75 |
+
$no_term = array(
|
76 |
+
'term_id' => 0,
|
77 |
+
'name' => __('Uncategorized', 'grand-media'),
|
78 |
+
);
|
79 |
+
$gm_category_terms = array_merge(array($no_term), $gm_category_terms);
|
80 |
+
?>
|
81 |
+
<div class="row">
|
82 |
+
<div class="col-xs-4">
|
83 |
+
<label><?php _e('[IN] Categories', 'grand-media'); ?></label>
|
84 |
+
<input name="category__in" class="form-control input-sm combobox_gmedia_category" value="<?php echo implode(',', wp_parse_id_list($query_data['category__in'])); ?>" placeholder="<?php echo esc_attr(__('Either of chosen Categories...', 'grand-media')); ?>"/>
|
85 |
+
</div>
|
86 |
+
<div class="col-xs-4">
|
87 |
+
<label><?php _e('[AND] Categories', 'grand-media'); ?></label>
|
88 |
+
<input name="category__and" class="form-control input-sm combobox_gmedia_category" value="<?php echo implode(',', wp_parse_id_list($query_data['category__and'])); ?>" placeholder="<?php echo esc_attr(__('Have all chosen Categories...', 'grand-media')); ?>"/>
|
89 |
+
</div>
|
90 |
+
<div class="col-xs-4">
|
91 |
+
<label><?php _e('[NOT IN] Categories', 'grand-media'); ?></label>
|
92 |
+
<input name="category__not_in" class="form-control input-sm combobox_gmedia_category" value="<?php echo implode(',', wp_parse_id_list($query_data['category__not_in'])); ?>" placeholder="<?php echo esc_attr(__('Exclude Categories...', 'grand-media')); ?>"/>
|
93 |
+
</div>
|
94 |
+
</div>
|
95 |
+
</div>
|
96 |
+
|
97 |
+
<div class="form-group">
|
98 |
+
<?php
|
99 |
+
$term_type = 'gmedia_tag';
|
100 |
+
$gm_tag_terms = $gmDB->get_terms($term_type, array('fields' => 'names_count'));
|
101 |
+
?>
|
102 |
+
<div class="row">
|
103 |
+
<div class="col-xs-4">
|
104 |
+
<label><?php _e('[IN] Tags', 'grand-media'); ?> </label>
|
105 |
+
<input name="tag__in" class="form-control input-sm combobox_gmedia_tag" value="<?php echo implode(',', wp_parse_id_list($query_data['tag__in'])); ?>" placeholder="<?php echo esc_attr(__('Either of chosen Tags...', 'grand-media')); ?>"/>
|
106 |
+
</div>
|
107 |
+
<div class="col-xs-4">
|
108 |
+
<label><?php _e('[AND] Tags', 'grand-media'); ?> </label>
|
109 |
+
<input name="tag__and" class="form-control input-sm combobox_gmedia_tag" value="<?php echo implode(',', wp_parse_id_list($query_data['tag__and'])); ?>" placeholder="<?php echo esc_attr(__('Have all chosen Tags...', 'grand-media')); ?>"/>
|
110 |
+
</div>
|
111 |
+
<div class="col-xs-4">
|
112 |
+
<label><?php _e('[NOT IN] Tags', 'grand-media'); ?> </label>
|
113 |
+
<input name="tag__not_in" class="form-control input-sm combobox_gmedia_tag" value="<?php echo implode(',', wp_parse_id_list($query_data['tag__not_in'])); ?>" placeholder="<?php echo esc_attr(__('Exclude Tags...', 'grand-media')); ?>"/>
|
114 |
+
</div>
|
115 |
+
</div>
|
116 |
+
</div>
|
117 |
+
|
118 |
+
<?php } ?>
|
119 |
+
<div class="form-group">
|
120 |
+
<label><?php _e('Terms Relation', 'grand-media'); ?> </label>
|
121 |
+
|
122 |
+
<div class="row">
|
123 |
+
<div class="col-xs-4">
|
124 |
+
<select name="terms_relation" class="form-control input-sm">
|
125 |
+
<option <?php selected($query_data['terms_relation'], ''); ?> value=""><?php _e('Default (AND)'); ?></option>
|
126 |
+
<option <?php selected($query_data['terms_relation'], 'AND'); ?> value=""><?php _e('AND'); ?></option>
|
127 |
+
<option <?php selected($query_data['terms_relation'], 'OR'); ?> value="OR"><?php _e('OR'); ?></option>
|
128 |
+
</select>
|
129 |
+
</div>
|
130 |
+
<div class="col-xs-8">
|
131 |
+
<p class="help-block"><?php _e('allows you to describe the relationship between the taxonomy queries', 'grand-media'); ?></p>
|
132 |
+
</div>
|
133 |
+
</div>
|
134 |
+
</div>
|
135 |
+
<div class="form-group">
|
136 |
+
<label><?php _e('Search', 'grand-media'); ?></label>
|
137 |
+
|
138 |
+
<div class="row">
|
139 |
+
<div class="col-xs-8">
|
140 |
+
<input type="text" class="form-control input-sm" placeholder="<?php _e('Search string or terms separated by comma', 'grand-media'); ?>" value="<?php echo $query_data['s']; ?>" name="s">
|
141 |
+
</div>
|
142 |
+
<div class="col-xs-4">
|
143 |
+
<div class="checkbox"><label><input type="checkbox" name="exact" value="yes"<?php echo $query_data['exact']? ' checked="checked"' : ''; ?> /> <?php _e('Search exactly string', 'grand-media'); ?></label></div>
|
144 |
+
</div>
|
145 |
+
</div>
|
146 |
+
</div>
|
147 |
+
<div class="form-group">
|
148 |
+
<div class="row">
|
149 |
+
<div class="col-xs-8">
|
150 |
+
<div class="pull-right"><a id="use_lib_selected" class="label label-primary" href="#libselected"><?php _e('Use selected in Library', 'grand-media'); ?></a></div>
|
151 |
+
<label><?php _e('Gmedia IDs <small class="text-muted">separated by comma</small>', 'grand-media'); ?> </label>
|
152 |
+
</div>
|
153 |
+
</div>
|
154 |
+
<div class="row">
|
155 |
+
<div class="col-xs-8">
|
156 |
+
<?php $query_gmedia_items = array();
|
157 |
+
if(!empty($query_data['gmedia__in'])) {
|
158 |
+
$query_gmedia_items = $query_data['gmedia__in'];
|
159 |
+
} elseif(!empty($query_data['gmedia__not_in'])) {
|
160 |
+
$query_gmedia_items = $query_data['gmedia__not_in'];
|
161 |
+
}
|
162 |
+
?>
|
163 |
+
<textarea id="query_gmedia__" name="gmedia__in" data-include="gmedia__in" data-exclude="gmedia__not_in" rows="1" class="form-control input-sm" style="resize:vertical;" placeholder="<?php echo esc_attr(__('Gmedia IDs...', 'grand-media')); ?>"><?php echo implode(',', wp_parse_id_list($query_gmedia_items)); ?></textarea>
|
164 |
+
</div>
|
165 |
+
<div class="col-xs-4">
|
166 |
+
<div class="checkbox"><label><input class="query_switch" data-target="query_gmedia__" type="checkbox"<?php echo (empty($query_data['gmedia__in']) && !empty($query_data['gmedia__not_in']))? ' checked="checked"' : ''; ?> /> <?php _e('Exclude selected Items', 'grand-media'); ?></label></div>
|
167 |
+
</div>
|
168 |
+
</div>
|
169 |
+
<p class="help-block"><?php _e('You can select items you want to add here right in Gmedia Library and then return here and click button "Use selected in Library"', 'grand-media'); ?></p>
|
170 |
+
</div>
|
171 |
+
<div class="form-group">
|
172 |
+
<div class="row">
|
173 |
+
<div class="col-xs-4">
|
174 |
+
<label><?php _e('Mime Type', 'grand-media'); ?> </label>
|
175 |
+
<?php
|
176 |
+
$mime_types = array(
|
177 |
+
array('value' => 'image', 'text' => 'Image'),
|
178 |
+
array('value' => 'audio', 'text' => 'Audio'),
|
179 |
+
array('value' => 'video', 'text' => 'Video'),
|
180 |
+
array('value' => 'text', 'text' => 'Text'),
|
181 |
+
array('value' => 'application', 'text' => 'Application'),
|
182 |
+
);
|
183 |
+
$mime_type_val = is_array($query_data['mime_type'])? implode(',', $query_data['mime_type']) : str_replace(', ', ',', $query_data['mime_type']);
|
184 |
+
?>
|
185 |
+
<input name="mime_type" class="form-control input-sm gmedia-combobox" data-options='<?php echo json_encode($mime_types); ?>' value="<?php esc_attr_e($mime_type_val); ?>" placeholder="<?php esc_attr_e(__('All types...', 'grand-media')); ?>"/>
|
186 |
+
</div>
|
187 |
+
<div class="col-xs-4">
|
188 |
+
<label><?php _e('Authors', 'grand-media'); ?></label>
|
189 |
+
<?php if(gm_user_can('show_others_media')) {
|
190 |
+
$user_ids = $gmCore->get_editable_user_ids();
|
191 |
+
if(!in_array($user_ID, $user_ids)) {
|
192 |
+
array_push($user_ids, $user_ID);
|
193 |
+
}
|
194 |
+
$filter_users = get_users(array('include' => $user_ids));
|
195 |
+
$users = '';
|
196 |
+
$_users = array();
|
197 |
+
if(count($filter_users)) {
|
198 |
+
foreach((array)$filter_users as $user) {
|
199 |
+
$user->ID = (int)$user->ID;
|
200 |
+
$_selected = in_array($user->ID, $query_data['author__in'])? ' selected="selected"' : '';
|
201 |
+
$users .= "<option value='{$user->ID}'{$_selected}>" . esc_html($user->display_name) . "</option>";
|
202 |
+
$_users[] = array('value' => $user->ID, 'text' => esc_html($user->display_name));
|
203 |
+
}
|
204 |
+
}
|
205 |
+
$query_authors = array();
|
206 |
+
if(!empty($query_data['author__in'])) {
|
207 |
+
$query_authors = $query_data['author__in'];
|
208 |
+
} elseif(!empty($query_data['author__not_in'])) {
|
209 |
+
$query_authors = $query_data['author__not_in'];
|
210 |
+
}
|
211 |
+
?>
|
212 |
+
<input id="query_author__" name="author__in" data-include="author__in" data-exclude="author__not_in" class="form-control input-sm gmedia-combobox" data-options='<?php echo str_replace("'", "\'", json_encode($_users)); ?>' value="<?php echo implode(',', wp_parse_id_list($query_authors)); ?>" placeholder="<?php esc_attr_e(__('All authors...', 'grand-media')); ?>"/>
|
213 |
+
<?php } else { ?>
|
214 |
+
<input type="text" readonly="readonly" name="author__in" class="form-control input-sm" value="<?php the_author_meta('display_name', $user_ID); ?>"/>
|
215 |
+
<?php } ?>
|
216 |
+
</div>
|
217 |
+
<?php if(gm_user_can('show_others_media')) { ?>
|
218 |
+
<div class="col-xs-4">
|
219 |
+
<label> </label>
|
220 |
+
<div class="checkbox"><label><input class="query_switch" data-target="query_author__" type="checkbox"<?php echo (empty($query_data['author__in']) && !empty($query_data['author__not_in']))? ' checked="checked"' : ''; ?> /> <?php _e('Exclude Authors', 'grand-media'); ?></label></div>
|
221 |
+
</div>
|
222 |
+
<?php } ?>
|
223 |
+
</div>
|
224 |
+
</div>
|
225 |
+
<div class="form-group">
|
226 |
+
<div class="row">
|
227 |
+
<div class="col-xs-4">
|
228 |
+
<label><?php _e('Year', 'grand-media'); ?></label>
|
229 |
+
<input type="text" class="form-control input-sm" placeholder="<?php _e('4 digit year e.g. 2011', 'grand-media'); ?>" value="<?php echo $query_data['year']; ?>" name="year">
|
230 |
+
</div>
|
231 |
+
<div class="col-xs-4">
|
232 |
+
<label><?php _e('Month', 'grand-media'); ?></label>
|
233 |
+
<input type="text" class="form-control input-sm" placeholder="<?php _e('from 1 to 12', 'grand-media'); ?>" value="<?php echo $query_data['monthnum']; ?>" name="monthnum">
|
234 |
+
</div>
|
235 |
+
<div class="col-xs-4">
|
236 |
+
<label><?php _e('Day', 'grand-media'); ?></label>
|
237 |
+
<input type="text" class="form-control input-sm" placeholder="<?php _e('from 1 to 31', 'grand-media'); ?>" value="<?php echo $query_data['day']; ?>" name="day">
|
238 |
+
</div>
|
239 |
+
</div>
|
240 |
+
</div>
|
241 |
+
<div class="form-group">
|
242 |
+
<?php foreach($query_data['meta_query'] as $i => $q) {
|
243 |
+
if($i) {
|
244 |
+
continue;
|
245 |
+
}
|
246 |
+
?>
|
247 |
+
<div class="row">
|
248 |
+
<div class="col-xs-6 col-sm-3">
|
249 |
+
<label><?php _e('Custom Field Key', 'grand-media'); ?></label>
|
250 |
+
<input type="text" class="form-control input-sm" value="<?php echo $q['key']; ?>" name="meta_query[<?php echo $i; ?>][key]">
|
251 |
+
<span class="help-block"><?php _e('Display items with this field key', 'grand-media'); ?></span>
|
252 |
+
</div>
|
253 |
+
<div class="col-xs-6 col-sm-3">
|
254 |
+
<label><?php _e('Custom Field Value', 'grand-media'); ?></label>
|
255 |
+
<input type="text" class="form-control input-sm" value="<?php echo $q['value']; ?>" name="meta_query[<?php echo $i; ?>][value]">
|
256 |
+
<span class="help-block"><?php _e('Display items with this field value', 'grand-media'); ?></span>
|
257 |
+
</div>
|
258 |
+
<div class="col-xs-6 col-sm-3">
|
259 |
+
<label><?php _e('Compare Operator', 'grand-media'); ?></label>
|
260 |
+
<select class="form-control input-sm" name="meta_query[<?php echo $i; ?>][compare]">
|
261 |
+
<option <?php selected($q['compare'], ''); ?> value=""><?php _e('Default', 'grand-media'); ?> (=)</option>
|
262 |
+
<option <?php selected($q['compare'], '='); ?> value="">=</option>
|
263 |
+
<option <?php selected($q['compare'], '!='); ?> value="!=">!=</option>
|
264 |
+
<option <?php selected($q['compare'], '>'); ?> value=">">></option>
|
265 |
+
<option <?php selected($q['compare'], '>='); ?> value=">=">>=</option>
|
266 |
+
<option <?php selected($q['compare'], '<'); ?> value="<"><</option>
|
267 |
+
<option <?php selected($q['compare'], '<='); ?> value="<="><=</option>
|
268 |
+
<option <?php selected($q['compare'], 'LIKE'); ?> value="LIKE">LIKE</option>
|
269 |
+
<option <?php selected($q['compare'], 'NOT LIKE'); ?> value="NOT LIKE">NOT LIKE</option>
|
270 |
+
<?php /* ?>
|
271 |
+
<option <?php selected($q['compare'], 'IN'); ?> value="IN">IN</option>
|
272 |
+
<option <?php selected($q['compare'], 'NOT IN'); ?> value="NOT IN">NOT IN</option>
|
273 |
+
<option <?php selected($q['compare'], 'BETWEEN'); ?> value="BETWEEN">BETWEEN</option>
|
274 |
+
<option <?php selected($q['compare'], 'NOT BETWEEN'); ?> value="NOT BETWEEN">NOT BETWEEN</option>
|
275 |
+
<?php */ ?>
|
276 |
+
<option <?php selected($q['compare'], 'EXISTS'); ?> value="EXISTS">EXISTS</option>
|
277 |
+
</select>
|
278 |
+
<span class="help-block"><?php _e('Operator to test the field value', 'grand-media'); ?></span>
|
279 |
+
</div>
|
280 |
+
<div class="col-xs-6 col-sm-3">
|
281 |
+
<label><?php _e('Meta Type', 'grand-media'); ?></label>
|
282 |
+
<select class="form-control input-sm" name="meta_query[<?php echo $i; ?>][type]">
|
283 |
+
<option <?php selected($q['type'], ''); ?> value=""><?php _e('Default', 'grand-media'); ?> (CHAR)</option>
|
284 |
+
<option <?php selected($q['type'], 'CHAR'); ?> value="">CHAR</option>
|
285 |
+
<option <?php selected($q['type'], 'NUMERIC'); ?> value="NUMERIC">NUMERIC</option>
|
286 |
+
<option <?php selected($q['type'], 'DECIMAL'); ?> value="DECIMAL">DECIMAL</option>
|
287 |
+
<option <?php selected($q['type'], 'DATE'); ?> value="DATE">DATE</option>
|
288 |
+
<option <?php selected($q['type'], 'DATETIME'); ?> value="DATETIME">DATETIME</option>
|
289 |
+
<option <?php selected($q['type'], 'TIME'); ?> value="TIME">TIME</option>
|
290 |
+
<option <?php selected($q['type'], 'BINARY'); ?> value="BINARY">BINARY</option>
|
291 |
+
<option <?php selected($q['type'], 'SIGNED'); ?> value="SIGNED">SIGNED</option>
|
292 |
+
<option <?php selected($q['type'], 'UNSIGNED'); ?> value="UNSIGNED">UNSIGNED</option>
|
293 |
+
</select>
|
294 |
+
<span class="help-block"><?php _e('Custom field type', 'grand-media'); ?></span>
|
295 |
+
</div>
|
296 |
+
</div>
|
297 |
+
<?php } ?>
|
298 |
+
</div>
|
299 |
+
<div class="form-group">
|
300 |
+
<div class="row">
|
301 |
+
<div class="col-xs-6 col-sm-3">
|
302 |
+
<label><?php _e('Order', 'grand-media'); ?></label>
|
303 |
+
<select class="form-control input-sm" name="order">
|
304 |
+
<option <?php selected($query_data['order'], ''); ?> value=""><?php _e('Default (DESC)', 'grand-media'); ?></option>
|
305 |
+
<option <?php selected($query_data['order'], 'DESC'); ?> value=""><?php _e('DESC', 'grand-media'); ?></option>
|
306 |
+
<option <?php selected($query_data['order'], 'ASC'); ?> value="ASC"><?php _e('ASC', 'grand-media'); ?></option>
|
307 |
+
</select>
|
308 |
+
<span class="help-block"><?php _e('Ascending or Descending order', 'grand-media'); ?></span>
|
309 |
+
</div>
|
310 |
+
<div class="col-xs-6 col-sm-3">
|
311 |
+
<label><?php _e('Order by', 'grand-media'); ?></label>
|
312 |
+
<select class="form-control input-sm" name="orderby">
|
313 |
+
<option <?php selected($query_data['orderby'], ''); ?> value=""><?php _e('Default (ID)', 'grand-media'); ?></option>
|
314 |
+
<option <?php selected($query_data['orderby'], 'id'); ?> value=""><?php _e('ID', 'grand-media'); ?></option>
|
315 |
+
<option <?php selected($query_data['orderby'], 'title'); ?> value="title"><?php _e('Title', 'grand-media'); ?></option>
|
316 |
+
<option <?php selected($query_data['orderby'], 'gmuid'); ?> value="gmuid"><?php _e('Filename', 'grand-media'); ?></option>
|
317 |
+
<option <?php selected($query_data['orderby'], 'date'); ?> value="date"><?php _e('Date', 'grand-media'); ?></option>
|
318 |
+
<option <?php selected($query_data['orderby'], 'modified'); ?> value="modified"><?php _e('Modified Date', 'grand-media'); ?></option>
|
319 |
+
<option <?php selected($query_data['orderby'], 'author'); ?> value="author"><?php _e('Author', 'grand-media'); ?></option>
|
320 |
+
<option <?php selected($query_data['orderby'], 'gmedia__in'); ?> value="gmedia__in"><?php _e('Selected Order', 'grand-media'); ?></option>
|
321 |
+
<option <?php selected($query_data['orderby'], 'meta_value'); ?> value="meta_value"><?php _e('Custom Field Value', 'grand-media'); ?></option>
|
322 |
+
<option <?php selected($query_data['orderby'], 'meta_value_num'); ?> value="meta_value_num"><?php _e('Custom Field Value (Numeric)', 'grand-media'); ?></option>
|
323 |
+
<option <?php selected($query_data['orderby'], 'rand'); ?> value="rand"><?php _e('Random', 'grand-media'); ?></option>
|
324 |
+
<option <?php selected($query_data['orderby'], 'none'); ?> value="none"><?php _e('None', 'grand-media'); ?></option>
|
325 |
+
</select>
|
326 |
+
<span class="help-block"><?php _e('Sort retrieved posts by', 'grand-media'); ?></span>
|
327 |
+
</div>
|
328 |
+
<div class="col-xs-6 col-sm-3">
|
329 |
+
<label><?php _e('Limit', 'grand-media'); ?></label>
|
330 |
+
<input type="text" class="form-control input-sm" value="<?php echo $query_data['limit']; ?>" name="limit" placeholder="<?php _e('leave empty for no limit', 'grand-media'); ?>">
|
331 |
+
<span class="help-block"><?php _e('Limit number of gmedia items', 'grand-media'); ?></span>
|
332 |
+
</div>
|
333 |
+
</div>
|
334 |
+
</div>
|
335 |
+
</div>
|
336 |
+
<script type="text/javascript">
|
337 |
+
jQuery(function($) {
|
338 |
+
<?php if(gm_user_can('terms')){ ?>
|
339 |
+
|
340 |
+
var gmedia_albums = <?php echo json_encode(array_values($gm_album_terms)); ?>;
|
341 |
+
var gmedia_categories = <?php echo json_encode(array_values($gm_category_terms)); ?>;
|
342 |
+
var gmedia_tags = <?php echo json_encode(array_values($gm_tag_terms)); ?>;
|
343 |
+
$('#query_album__').selectize({
|
344 |
+
plugins: ['drag_drop'],
|
345 |
+
create: false,
|
346 |
+
options: gmedia_albums,
|
347 |
+
hideSelected: true,
|
348 |
+
allowEmptyOption: true,
|
349 |
+
valueField: 'term_id',
|
350 |
+
searchField: ['name'],
|
351 |
+
//labelField: 'name',
|
352 |
+
render: {
|
353 |
+
item: function(item, escape) {
|
354 |
+
var count = '';
|
355 |
+
var status = '';
|
356 |
+
var author = '';
|
357 |
+
if(item.term_id) {
|
358 |
+
count = '(' + escape(item.count) + ')';
|
359 |
+
status = (typeof item.status != 'undefined' && ('publish' != item.status))? ' [' + item.status + '] ' : '';
|
360 |
+
author = ' ' + item.by_author;
|
361 |
+
}
|
362 |
+
return '<div>' + escape(item.name) + ' <small>' + count + status + author + '</small></div>';
|
363 |
+
},
|
364 |
+
option: function(item, escape) {
|
365 |
+
var count = '';
|
366 |
+
var status = '';
|
367 |
+
var author = '';
|
368 |
+
if(item.term_id) {
|
369 |
+
count = '(' + escape(item.count) + ')';
|
370 |
+
status = (typeof item.status != 'undefined' && ('publish' != item.status))? ' [' + item.status + '] ' : '';
|
371 |
+
author = ' ' + item.by_author;
|
372 |
+
}
|
373 |
+
return '<div>' + escape(item.name) + ' <small>' + count + status + author + '</small></div>';
|
374 |
+
}
|
375 |
+
}
|
376 |
+
|
377 |
+
});
|
378 |
+
var cats = $('.combobox_gmedia_category').selectize({
|
379 |
+
create: false,
|
380 |
+
options: gmedia_categories,
|
381 |
+
preload: true,
|
382 |
+
hideSelected: true,
|
383 |
+
allowEmptyOption: true,
|
384 |
+
valueField: 'term_id',
|
385 |
+
searchField: ['name'],
|
386 |
+
//labelField: 'name',
|
387 |
+
render: {
|
388 |
+
item: function(item, escape) {
|
389 |
+
var count = '';
|
390 |
+
if(item.term_id) {
|
391 |
+
count = ' <small>(' + escape(item.count) + ')</small>';
|
392 |
+
}
|
393 |
+
return '<div>' + escape(item.name) + count + '</div>';
|
394 |
+
},
|
395 |
+
option: function(item, escape) {
|
396 |
+
if(('category__and' == this.$input[0].name) && !item.term_id) {
|
397 |
+
return '';
|
398 |
+
}
|
399 |
+
var count = '';
|
400 |
+
if(item.term_id) {
|
401 |
+
count = ' <small>(' + escape(item.count) + ')</small>';
|
402 |
+
}
|
403 |
+
return '<div>' + escape(item.name) + count + '</div>';
|
404 |
+
}
|
405 |
+
}
|
406 |
+
|
407 |
+
}).on('change', function() {
|
408 |
+
var allSelected = [];
|
409 |
+
jQuery.each(cats, function(i, e) {
|
410 |
+
allSelected = jQuery.merge(allSelected, e.selectize.items);
|
411 |
+
});
|
412 |
+
|
413 |
+
jQuery.each(cats, function(i, e) {
|
414 |
+
var orig_items = e.selectize.items;
|
415 |
+
e.selectize.items = allSelected;
|
416 |
+
e.selectize.currentResults = e.selectize.search();
|
417 |
+
e.selectize.refreshOptions(false);
|
418 |
+
e.selectize.items = orig_items;
|
419 |
+
|
420 |
+
});
|
421 |
+
});
|
422 |
+
|
423 |
+
var tags = $('.combobox_gmedia_tag').selectize({
|
424 |
+
create: false,
|
425 |
+
options: gmedia_tags,
|
426 |
+
hideSelected: true,
|
427 |
+
allowEmptyOption: true,
|
428 |
+
valueField: 'term_id',
|
429 |
+
searchField: ['name'],
|
430 |
+
render: {
|
431 |
+
item: function(item, escape) {
|
432 |
+
return '<div>' + escape(item.name) + ' <small>(' + escape(item.count) + ')</small></div>';
|
433 |
+
},
|
434 |
+
option: function(item, escape) {
|
435 |
+
return '<div>' + escape(item.name) + ' <small>(' + escape(item.count) + ')</small></div>';
|
436 |
+
}
|
437 |
+
}
|
438 |
+
|
439 |
+
}).on('change', function() {
|
440 |
+
var allSelected = [];
|
441 |
+
jQuery.each(tags, function(i, e) {
|
442 |
+
allSelected = jQuery.merge(allSelected, e.selectize.items);
|
443 |
+
});
|
444 |
+
|
445 |
+
jQuery.each(tags, function(i, e) {
|
446 |
+
var orig_items = e.selectize.items;
|
447 |
+
e.selectize.items = allSelected;
|
448 |
+
e.selectize.currentResults = e.selectize.search();
|
449 |
+
e.selectize.refreshOptions(false);
|
450 |
+
e.selectize.items = orig_items;
|
451 |
+
|
452 |
+
});
|
453 |
+
});
|
454 |
+
;
|
455 |
+
<?php } ?>
|
456 |
+
|
457 |
+
$('.gmedia-combobox').each(function() {
|
458 |
+
var select = $(this).selectize({
|
459 |
+
create: false,
|
460 |
+
hideSelected: true,
|
461 |
+
options: $(this).data('options')
|
462 |
+
});
|
463 |
+
});
|
464 |
+
|
465 |
+
$('.query_switch').on('click', function() {
|
466 |
+
var el = $('#'+$(this).attr('data-target'));
|
467 |
+
if($(this).is(':checked')) {
|
468 |
+
el.attr('name', el.attr('data-exclude'));
|
469 |
+
} else {
|
470 |
+
el.attr('name', el.attr('data-include'));
|
471 |
+
}
|
472 |
+
});
|
473 |
+
$('#use_lib_selected').on('click', function() {
|
474 |
+
var field = $('#query_gmedia__');
|
475 |
+
var valData = field.val().split(',');
|
476 |
+
var storedData = getStorage('gmuser_<?php echo $user_ID; ?>_');
|
477 |
+
storedData = storedData.get('library').split(',');
|
478 |
+
valData = $.grep(valData, function(e) {
|
479 |
+
return e;
|
480 |
+
});
|
481 |
+
$.each(storedData, function(i, id) {
|
482 |
+
if(!id) {
|
483 |
+
return true;
|
484 |
+
}
|
485 |
+
if($.inArray(id, valData) === -1) {
|
486 |
+
valData.push(id);
|
487 |
+
}
|
488 |
+
});
|
489 |
+
field.val(valData.join(','));
|
490 |
+
});
|
491 |
+
});
|
492 |
+
|
493 |
+
</script>
|
494 |
+
<div class="modal-footer">
|
495 |
+
<button type="button" class="btn btn-primary buildquerysubmit"><?php _e('Build Query', 'grand-media'); ?></button>
|
496 |
+
<button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Close', 'grand-media'); ?></button>
|
497 |
+
</div>
|
498 |
+
</div>
|
499 |
+
</div>
|
500 |
+
</div>
|
admin/pages/galleries/tpl/module-settings.php
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Module Settings
|
9 |
+
*/
|
10 |
+
global $gmGallery;
|
11 |
+
?>
|
12 |
+
<div class="row">
|
13 |
+
<div class="col-lg-5 tabable tabs-left">
|
14 |
+
<ul class="nav nav-tabs" id="galleryTabs">
|
15 |
+
<?php if(isset($module_info)){ ?>
|
16 |
+
<li class="text-center">
|
17 |
+
<strong><?php echo $module_info['title']; ?></strong><a href="#chooseModuleModal" data-toggle="modal" style="padding:5px 0;"><img src="<?php echo $term->module['url'] . '/screenshot.png'; ?>" alt="<?php echo esc_attr($module_info['title']); ?>" width="100" style="height:auto;"/></a>
|
18 |
+
</li>
|
19 |
+
<?php } else{ ?>
|
20 |
+
<li class="text-center"><strong><?php echo $term->module['name']; ?></strong>
|
21 |
+
|
22 |
+
<p><?php _e('This module is broken or outdated. Please, go to Modules page and update/install module or choose another one for this gallery', 'grand-media'); ?></p>
|
23 |
+
<a href="#chooseModuleModal" data-toggle="modal" style="padding:5px 0;"><img src="<?php echo $term->module['url'] . '/screenshot.png'; ?>" alt="<?php echo esc_attr($term->module['name']); ?>" width="100" style="height:auto;"/></a>
|
24 |
+
</li>
|
25 |
+
<?php } ?>
|
26 |
+
<?php
|
27 |
+
if(isset($options_tree)){
|
28 |
+
gmedia_gallery_options_nav($options_tree);
|
29 |
+
}
|
30 |
+
?>
|
31 |
+
</ul>
|
32 |
+
|
33 |
+
<div id="gallery_options_block" class="tab-content">
|
34 |
+
<?php
|
35 |
+
if(isset($options_tree)){
|
36 |
+
gmedia_gallery_options_fieldset($options_tree, $default_options, $gallery_settings);
|
37 |
+
}
|
38 |
+
?>
|
39 |
+
</div>
|
40 |
+
|
41 |
+
</div>
|
42 |
+
<div class="col-lg-7">
|
43 |
+
<?php if($term_id || isset($preset_module)){
|
44 |
+
$bgcolor = empty($gmGallery->options['preview_bgcolor'])? 'ffffff' : $gmGallery->options['preview_bgcolor'];
|
45 |
+
?>
|
46 |
+
<div class="clearfix">
|
47 |
+
<div class="form-group pull-right" style="margin:-10px 0 5px 0;"><input type="text" data-type="color" class="form-control input-sm" id="preview_color" name="preview_bgcolor" value="<?php echo $bgcolor; ?>" placeholder="ffffff" size="7"/></div>
|
48 |
+
<b><?php _e('Gallery Preview:'); ?></b>
|
49 |
+
</div>
|
50 |
+
<div class="gallery_preview">
|
51 |
+
<iframe id="gallery_preview" style="background-color:<?php echo "#$bgcolor"; ?>;padding:5px;" name="gallery_preview" src="<?php echo add_query_arg($params, set_url_scheme($gallery_link_default, 'admin')); ?>"></iframe>
|
52 |
+
</div>
|
53 |
+
<?php } ?>
|
54 |
+
</div>
|
55 |
+
</div>
|
56 |
+
<script type="text/javascript">
|
57 |
+
jQuery(function($) {
|
58 |
+
var hash = window.location.hash;
|
59 |
+
if(hash) {
|
60 |
+
$('#galleryTabs a').eq(hash.replace('#tab-', '')).tab('show');
|
61 |
+
}
|
62 |
+
$('.gallery_preview').resizable();
|
63 |
+
$('#gmedia-edit-term').on('submit', function(e) {
|
64 |
+
if($('#build_query_field').val() == '') {
|
65 |
+
var conf_txt = "<?php _e("Warning: Query Args. field is empty! Show in gallery all files from Gmedia Library?") ?>";
|
66 |
+
if(!GmediaFunction.confirm(conf_txt)) {
|
67 |
+
e.preventDefault();
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
$(this).attr('action', $(this).attr('action') + '#tab-' + $('#galleryTabs li.active').index());
|
72 |
+
});
|
73 |
+
|
74 |
+
var main = $('#gallery_options_block');
|
75 |
+
|
76 |
+
$('input', main).filter('[data-type="color"]').minicolors({
|
77 |
+
animationSpeed: 50,
|
78 |
+
animationEasing: 'swing',
|
79 |
+
change: null,
|
80 |
+
changeDelay: 0,
|
81 |
+
control: 'hue',
|
82 |
+
//defaultValue: '',
|
83 |
+
hide: null,
|
84 |
+
hideSpeed: 100,
|
85 |
+
inline: false,
|
86 |
+
letterCase: 'lowercase',
|
87 |
+
opacity: false,
|
88 |
+
position: 'bottom left',
|
89 |
+
show: null,
|
90 |
+
showSpeed: 100,
|
91 |
+
theme: 'bootstrap'
|
92 |
+
});
|
93 |
+
$('#preview_color').on('change', function() {
|
94 |
+
var color = $(this).val();
|
95 |
+
$('#gallery_preview').css({backgroundColor: '#' + color});
|
96 |
+
}).minicolors({
|
97 |
+
animationSpeed: 50,
|
98 |
+
animationEasing: 'swing',
|
99 |
+
change: null,
|
100 |
+
changeDelay: 0,
|
101 |
+
control: 'hue',
|
102 |
+
//defaultValue: '',
|
103 |
+
hide: null,
|
104 |
+
hideSpeed: 100,
|
105 |
+
inline: false,
|
106 |
+
letterCase: 'lowercase',
|
107 |
+
opacity: false,
|
108 |
+
position: 'bottom right',
|
109 |
+
show: null,
|
110 |
+
showSpeed: 100,
|
111 |
+
theme: 'bootstrap'
|
112 |
+
});
|
113 |
+
|
114 |
+
$('[data-watch]', main).each(function() {
|
115 |
+
var el = $(this);
|
116 |
+
gmedia_options_conditional_logic(el, 0);
|
117 |
+
var event = el.attr('data-watch');
|
118 |
+
if(event) {
|
119 |
+
el.on(event, function() {
|
120 |
+
if('change' == el.attr('data-watch')) {
|
121 |
+
$(this).blur().focus();
|
122 |
+
}
|
123 |
+
gmedia_options_conditional_logic($(this), 400);
|
124 |
+
});
|
125 |
+
}
|
126 |
+
});
|
127 |
+
|
128 |
+
function gmedia_options_conditional_logic(el, slide) {
|
129 |
+
if(el.is(':input')) {
|
130 |
+
var val = el.val();
|
131 |
+
var id = el.attr('id').toLowerCase();
|
132 |
+
if(el.is(':checkbox') && !el[0].checked) {
|
133 |
+
val = '0';
|
134 |
+
}
|
135 |
+
$('[data-' + id + ']', main).each(function() {
|
136 |
+
var key = $(this).attr('data-' + id);
|
137 |
+
key = key.split(':');
|
138 |
+
//var hidden = $(this).data('hidden')? parseInt($(this).data('hidden')) : 0;
|
139 |
+
var hidden = $(this).data('hidden')? $(this).data('hidden') : {};
|
140 |
+
var ch = true;
|
141 |
+
switch(key[0]) {
|
142 |
+
case '=':
|
143 |
+
case 'is':
|
144 |
+
if(val == key[1]) {
|
145 |
+
delete hidden[id];
|
146 |
+
if(slide && $.isEmptyObject(hidden)) {
|
147 |
+
$(this).prop('disabled', false).closest('.form-group').stop().slideDown(slide, function() {
|
148 |
+
$(this).css({display: 'block'});
|
149 |
+
});
|
150 |
+
if(key[2]) {
|
151 |
+
key[2] = $(this).data('value');
|
152 |
+
} else {
|
153 |
+
ch = false;
|
154 |
+
}
|
155 |
+
} else {
|
156 |
+
ch = false;
|
157 |
+
}
|
158 |
+
$(this).data('hidden', hidden);
|
159 |
+
} else {
|
160 |
+
if($.isEmptyObject(hidden)) {
|
161 |
+
if(key[2]) {
|
162 |
+
$(this).closest('.form-group').stop().slideUp(slide, function() {
|
163 |
+
$(this).css({display: 'none'});
|
164 |
+
});
|
165 |
+
} else {
|
166 |
+
$(this).prop('disabled', true).closest('.form-group').stop().slideUp(slide, function() {
|
167 |
+
$(this).css({display: 'none'});
|
168 |
+
});
|
169 |
+
}
|
170 |
+
} else {
|
171 |
+
ch = false;
|
172 |
+
}
|
173 |
+
hidden[id] = 1;
|
174 |
+
$(this).data('hidden', hidden);
|
175 |
+
}
|
176 |
+
break;
|
177 |
+
case '!=':
|
178 |
+
case 'not':
|
179 |
+
if(val == key[1]) {
|
180 |
+
if($.isEmptyObject(hidden)) {
|
181 |
+
if(key[2]) {
|
182 |
+
$(this).closest('.form-group').stop().slideUp(slide, function() {
|
183 |
+
$(this).css({display: 'none'});
|
184 |
+
});
|
185 |
+
} else {
|
186 |
+
$(this).prop('disabled', true).closest('.form-group').stop().slideUp(slide, function() {
|
187 |
+
$(this).css({display: 'none'});
|
188 |
+
});
|
189 |
+
}
|
190 |
+
} else {
|
191 |
+
ch = false;
|
192 |
+
}
|
193 |
+
hidden[id] = 1;
|
194 |
+
$(this).data('hidden', hidden);
|
195 |
+
} else {
|
196 |
+
delete hidden[id];
|
197 |
+
if(slide && $.isEmptyObject(hidden)) {
|
198 |
+
$(this).prop('disabled', false).closest('.form-group').stop().slideDown(slide, function() {
|
199 |
+
$(this).css({display: 'block'});
|
200 |
+
});
|
201 |
+
if(key[2] && slide) {
|
202 |
+
key[2] = $(this).data('value');
|
203 |
+
} else {
|
204 |
+
ch = false;
|
205 |
+
}
|
206 |
+
} else {
|
207 |
+
ch = false;
|
208 |
+
}
|
209 |
+
$(this).data('hidden', hidden);
|
210 |
+
}
|
211 |
+
break;
|
212 |
+
}
|
213 |
+
if(key[2] && ch) {
|
214 |
+
if($(this).is(':checkbox')) {
|
215 |
+
if(+($(this).prop('checked')) != parseInt(key[2])) {
|
216 |
+
$(this).data('value', ($(this).prop('checked')? '1' : '0'));
|
217 |
+
$(this).prop('checked', ('0' != key[2])).trigger('change');
|
218 |
+
}
|
219 |
+
} else {
|
220 |
+
if($(this).val() != key[2]) {
|
221 |
+
$(this).data('value', $(this).val());
|
222 |
+
$(this).val(key[2]).trigger('change');
|
223 |
+
}
|
224 |
+
}
|
225 |
+
}
|
226 |
+
});
|
227 |
+
}
|
228 |
+
}
|
229 |
+
});
|
230 |
+
|
231 |
+
</script>
|
232 |
+
|
admin/pages/library/functions.php
CHANGED
@@ -1,56 +1,92 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
function gmedia_item_thumbnail($item)
|
4 |
global $gmCore;
|
5 |
|
6 |
echo '<img class="gmedia-thumb" src="' . $gmCore->gm_get_media_image($item, 'thumb') . '" alt=""/>';
|
7 |
|
8 |
-
if(isset($item->meta['_cover'][0]) && !empty($item->meta['_cover'][0]))
|
9 |
echo '<img class="gmedia-typethumb" src="' . $gmCore->gm_get_media_image($item, 'thumb', false) . '" alt=""/>';
|
10 |
}
|
11 |
}
|
12 |
|
13 |
-
function gmedia_item_actions($item)
|
14 |
-
global $gmCore;
|
15 |
|
16 |
$actions = array();
|
17 |
-
|
|
|
|
|
18 |
if(!empty($item->post_id)){
|
19 |
$cloud_link = get_permalink($item->post_id);
|
20 |
-
} else
|
21 |
$cloud_link = $gmCore->gmcloudlink($item->ID, 'single');
|
22 |
}
|
23 |
-
$actions['share']
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
|
|
|
|
27 |
}
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
}
|
32 |
-
$actions['show'] = '<a href="' . $gmCore->gm_get_media_image($item, 'web') . '" data-target="#previewModal" data-width="' . $item->msize['width'] . '" data-height="' . $item->msize['height'] . '" class="preview-modal" title="' . esc_attr($item->title) . '">' . __('Show', 'grand-media') . '</a>';
|
33 |
|
34 |
-
|
35 |
-
$actions['show'] = '<a href="' . $item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
|
|
|
|
37 |
$metainfo = $gmCore->metadata_text($item->ID);
|
38 |
-
if($metainfo)
|
39 |
-
$actions['info'] = '<a href="#metaInfo" data-target="#previewModal" data-metainfo="' . $item->ID . '" class="preview-modal" title="' . __('Exif Info', 'grand-media') . '">' .
|
40 |
$actions['info'] .= '<div class="metainfo hidden" id="metainfo_' . $item->ID . '">' . nl2br($metainfo) . '</div>';
|
|
|
|
|
41 |
}
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
}
|
|
|
|
|
47 |
}
|
48 |
|
49 |
return apply_filters('gmedia_item_actions', $actions);
|
50 |
}
|
51 |
|
52 |
|
53 |
-
function gmedia_item_more_data(&$item)
|
54 |
global $gmDB, $gmCore, $gmGallery;
|
55 |
|
56 |
$meta = $gmDB->get_metadata('gmedia', $item->ID);
|
@@ -62,25 +98,25 @@ function gmedia_item_more_data(&$item) {
|
|
62 |
$item->type = $type[0];
|
63 |
$item->ext = pathinfo($item->gmuid, PATHINFO_EXTENSION);
|
64 |
|
65 |
-
$item->url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $item->gmuid;
|
66 |
-
$item->path = $gmCore->upload['path'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $item->gmuid;
|
67 |
|
68 |
-
if(function_exists('exif_imagetype')) {
|
69 |
-
$item->editor = (('image' == $type[0]) && in_array(exif_imagetype($item->path), array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))? true : false;
|
70 |
-
} else {
|
71 |
-
|
72 |
-
}
|
73 |
$item->gps = '';
|
74 |
-
if($item->editor)
|
75 |
$item->url_original = $gmCore->upload['url'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $item->gmuid;
|
76 |
$item->url_thumb = $gmCore->upload['url'] . '/' . $gmGallery->options['folder']['image_thumb'] . '/' . $item->gmuid;
|
77 |
$item->path_original = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $item->gmuid;
|
78 |
$item->path_thumb = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_thumb'] . '/' . $item->gmuid;
|
79 |
-
if(!empty($metadata['image_meta']['GPS']))
|
80 |
$item->gps = implode(', ', $metadata['image_meta']['GPS']);
|
81 |
}
|
82 |
}
|
83 |
-
if(!empty($meta['_gps'][0]))
|
84 |
$item->gps = implode(', ', $meta['_gps'][0]);
|
85 |
}
|
86 |
|
@@ -88,22 +124,22 @@ function gmedia_item_more_data(&$item) {
|
|
88 |
$item->msize['height'] = isset($metadata['web']['height'])? $metadata['web']['height'] : (isset($metadata['height'])? $metadata['height'] : '200');
|
89 |
|
90 |
$item->thumb_ratio = 1;
|
91 |
-
if(isset($metadata['thumb']['width']) && isset($metadata['thumb']['height']))
|
92 |
$item->thumb_ratio = $metadata['thumb']['width'] / $metadata['thumb']['height'];
|
93 |
}
|
94 |
|
95 |
-
$item->tags
|
96 |
-
$item->album
|
97 |
$item->categories = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_category');
|
98 |
|
99 |
$item = apply_filters('gmedia_item_more_data', $item);
|
100 |
}
|
101 |
|
102 |
-
function gmedia_filter_message()
|
103 |
global $gmProcessor;
|
104 |
-
if(!empty($gmProcessor->filters))
|
105 |
echo '<div class="custom-message alert alert-info">';
|
106 |
-
foreach($gmProcessor->filters as $key => $value)
|
107 |
echo '<div class="custom-message-row">';
|
108 |
echo '<strong><a href="#libModal" data-modal="' . $key . '" data-action="gmedia_get_modal" class="gmedia-modal">' . $value['title'] . '</a>: </strong>';
|
109 |
echo implode(', ', $value['filter']);
|
@@ -113,9 +149,9 @@ function gmedia_filter_message() {
|
|
113 |
}
|
114 |
}
|
115 |
|
116 |
-
function gmedia_alert_message()
|
117 |
global $gmProcessor;
|
118 |
-
if($gmProcessor->
|
119 |
?>
|
120 |
<div class="alert alert-warning alert-dismissible" role="alert" style="margin-bottom:0">
|
121 |
<button type="button" class="close" data-dismiss="alert">
|
@@ -126,3 +162,35 @@ function gmedia_alert_message() {
|
|
126 |
}
|
127 |
}
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
|
3 |
+
function gmedia_item_thumbnail($item){
|
4 |
global $gmCore;
|
5 |
|
6 |
echo '<img class="gmedia-thumb" src="' . $gmCore->gm_get_media_image($item, 'thumb') . '" alt=""/>';
|
7 |
|
8 |
+
if(isset($item->meta['_cover'][0]) && !empty($item->meta['_cover'][0])){
|
9 |
echo '<img class="gmedia-typethumb" src="' . $gmCore->gm_get_media_image($item, 'thumb', false) . '" alt=""/>';
|
10 |
}
|
11 |
}
|
12 |
|
13 |
+
function gmedia_item_actions($item){
|
14 |
+
global $gmCore, $gmProcessor;
|
15 |
|
16 |
$actions = array();
|
17 |
+
|
18 |
+
$share_icon = '<span class="glyphicon glyphicon-share"></span>';
|
19 |
+
if('draft' !== $item->status){
|
20 |
if(!empty($item->post_id)){
|
21 |
$cloud_link = get_permalink($item->post_id);
|
22 |
+
} else{
|
23 |
$cloud_link = $gmCore->gmcloudlink($item->ID, 'single');
|
24 |
}
|
25 |
+
$actions['share'] = '<a target="_blank" data-target="#shareModal" data-share="' . $item->ID . '" class="share-modal" title="' . __('Share Gmedia Post', 'grand-media') . '" href="' . $cloud_link . '">' . $share_icon . '</a>';
|
26 |
+
} else{
|
27 |
+
$actions['share'] = "<span class='action-inactive'>$share_icon</span>";
|
28 |
+
}
|
29 |
+
|
30 |
+
$edit_icon = '<span class="glyphicon glyphicon-edit"></span>';
|
31 |
+
if(gm_user_can('edit_media')){
|
32 |
+
if(((int)$item->author == get_current_user_id()) || gm_user_can('edit_others_media')){
|
33 |
+
$edit_data_data = $gmProcessor->gmediablank? '' : ' data-target="#previewModal" data-width="1200" data-height="500" data-cls="edit_gmedia_item" class="preview-modal"';
|
34 |
+
$actions['edit_data'] = '<a href="' . add_query_arg(array('page' => 'GrandMedia', 'mode' => 'edit', 'gmediablank' => 'library', 'gmedia__in' => $item->ID), $gmProcessor->url) . '"' . $edit_data_data . ' title="' . __('Edit Data', 'grand-media') . '">' . $edit_icon . '</a>';
|
35 |
}
|
36 |
+
} else {
|
37 |
+
$actions['edit'] = "<span class='action-inactive'>$edit_icon</span>";
|
38 |
}
|
39 |
+
|
40 |
+
if('image' == $item->type){
|
41 |
+
$edit_image_icon = '<span class="glyphicon glyphicon-adjust"></span>';
|
42 |
+
if((gm_user_can('edit_media') && ((int)$item->author == get_current_user_id())) || gm_user_can('edit_others_media')){
|
43 |
+
$actions['edit_image'] = '<a href="' . add_query_arg(array('page' => 'GrandMedia', 'gmediablank' => 'image_editor', 'id' => $item->ID), $gmProcessor->url) . '" data-target="#gmeditModal" class="gmedit-modal" title="' . __('Edit Image', 'grand-media') . '">' . $edit_image_icon . '</a>';
|
44 |
+
} else {
|
45 |
+
$actions['edit'] = "<span class='action-inactive'>$edit_image_icon</span>";
|
46 |
}
|
|
|
47 |
|
48 |
+
$show_icon = '<span class="glyphicon glyphicon-fullscreen"></span>';
|
49 |
+
$actions['show'] = '<a href="' . $gmCore->gm_get_media_image($item, 'web') . '" data-target="#previewModal" data-width="' . $item->msize['width'] . '" data-height="' . $item->msize['height'] . '" class="preview-modal" title="' . esc_attr( __('Show', 'grand-media') . ' ' . $item->title) . '">' . $show_icon . '</a>';
|
50 |
+
|
51 |
+
} elseif(in_array($item->ext, array('mp3', 'ogg', 'wav', 'ogg', 'mp4', 'mpeg', 'webm'))){
|
52 |
+
$show_icon = '<span class="glyphicon glyphicon-play"></span>';
|
53 |
+
$actions['show'] = '<a href="' . $item->url . '" data-target="#previewModal" data-width="' . $item->msize['width'] . '" data-height="' . $item->msize['height'] . '" class="preview-modal" title="' . esc_attr(__('Play', 'grand-media') . ' ' . $item->title) . '">' . $show_icon . '</a>';
|
54 |
+
} else{
|
55 |
+
$show_icon = '<span class="glyphicon glyphicon-cloud-download"></span>';
|
56 |
+
$actions['show'] = '<a href="' . $item->url . '" title="' . __('Download', 'grand-media') . '" download="' . $item->gmuid . '">' . $show_icon . '</a>';
|
57 |
}
|
58 |
+
|
59 |
+
$info_icon = '<span class="glyphicon glyphicon-info-sign"></span>';
|
60 |
$metainfo = $gmCore->metadata_text($item->ID);
|
61 |
+
if($metainfo){
|
62 |
+
$actions['info'] = '<a href="#metaInfo" data-target="#previewModal" data-metainfo="' . $item->ID . '" class="preview-modal" title="' . __('Exif/Meta Info', 'grand-media') . '">' . $info_icon . '</a>';
|
63 |
$actions['info'] .= '<div class="metainfo hidden" id="metainfo_' . $item->ID . '">' . nl2br($metainfo) . '</div>';
|
64 |
+
} else {
|
65 |
+
$actions['info'] = "<span class='action-inactive'>$info_icon</span>";
|
66 |
}
|
67 |
+
|
68 |
+
$duplicate_icon = '<span class="glyphicon glyphicon-duplicate"></span>';
|
69 |
+
$actions['duplicate'] = '<a href="' . wp_nonce_url(gm_get_admin_url(array('duplicate' => $item->ID)), 'gmedia_duplicate') . '" title="' . __('Duplicate', 'grand-media') . '">' . $duplicate_icon . '</a>';
|
70 |
+
|
71 |
+
$delete_icon = '<span class="glyphicon glyphicon-trash"></span>';
|
72 |
+
if((gm_user_can('delete_media') && ((int)$item->author == get_current_user_id())) || gm_user_can('delete_others_media')){
|
73 |
+
$actions['delete'] = '<a class="text-danger" href="' . wp_nonce_url(gm_get_admin_url(array('delete' => $item->ID)), 'gmedia_delete') . '" data-confirm="' . sprintf(__("You are about to permanently delete %s file.\n\r'Cancel' to stop, 'OK' to delete.", "grand-media"), $item->gmuid) . '" title="' . __('Delete', 'grand-media') . '">' . $delete_icon . '</a>';
|
74 |
+
|
75 |
+
if($gmCore->_get('showmore')){
|
76 |
+
$erase_icon = '<span class="glyphicon glyphicon-erase"></span>';
|
77 |
+
$actions['db_delete'] = '<a class="text-danger" href="' . wp_nonce_url(gm_get_admin_url(array('delete' => $item->ID,
|
78 |
+
'save_original_file' => 1
|
79 |
+
)), 'gmedia_delete') . '" data-confirm="' . sprintf(__("You are about to delete record from DB for %s file.\n\r'Cancel' to stop, 'OK' to delete.", "grand-media"), $item->gmuid) . '" title="' . __('Delete DB record (leave file on the server)', 'grand-media') . '">' . $erase_icon . '</a>';
|
80 |
}
|
81 |
+
} else {
|
82 |
+
$actions['delete'] = "<span class='action-inactive'>$delete_icon</span>";
|
83 |
}
|
84 |
|
85 |
return apply_filters('gmedia_item_actions', $actions);
|
86 |
}
|
87 |
|
88 |
|
89 |
+
function gmedia_item_more_data(&$item){
|
90 |
global $gmDB, $gmCore, $gmGallery;
|
91 |
|
92 |
$meta = $gmDB->get_metadata('gmedia', $item->ID);
|
98 |
$item->type = $type[0];
|
99 |
$item->ext = pathinfo($item->gmuid, PATHINFO_EXTENSION);
|
100 |
|
101 |
+
$item->url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][ $type[0] ] . '/' . $item->gmuid;
|
102 |
+
$item->path = $gmCore->upload['path'] . '/' . $gmGallery->options['folder'][ $type[0] ] . '/' . $item->gmuid;
|
103 |
|
104 |
+
// if(function_exists('exif_imagetype')) {
|
105 |
+
// $item->editor = (('image' == $type[0]) && in_array(exif_imagetype($item->path), array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))? true : false;
|
106 |
+
// } else {
|
107 |
+
$item->editor = (('image' == $type[0]) && in_array($type[1], array('jpeg', 'png', 'gif')))? true : false;
|
108 |
+
// }
|
109 |
$item->gps = '';
|
110 |
+
if($item->editor){
|
111 |
$item->url_original = $gmCore->upload['url'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $item->gmuid;
|
112 |
$item->url_thumb = $gmCore->upload['url'] . '/' . $gmGallery->options['folder']['image_thumb'] . '/' . $item->gmuid;
|
113 |
$item->path_original = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $item->gmuid;
|
114 |
$item->path_thumb = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_thumb'] . '/' . $item->gmuid;
|
115 |
+
if(!empty($metadata['image_meta']['GPS'])){
|
116 |
$item->gps = implode(', ', $metadata['image_meta']['GPS']);
|
117 |
}
|
118 |
}
|
119 |
+
if(!empty($meta['_gps'][0])){
|
120 |
$item->gps = implode(', ', $meta['_gps'][0]);
|
121 |
}
|
122 |
|
124 |
$item->msize['height'] = isset($metadata['web']['height'])? $metadata['web']['height'] : (isset($metadata['height'])? $metadata['height'] : '200');
|
125 |
|
126 |
$item->thumb_ratio = 1;
|
127 |
+
if(isset($metadata['thumb']['width']) && isset($metadata['thumb']['height'])){
|
128 |
$item->thumb_ratio = $metadata['thumb']['width'] / $metadata['thumb']['height'];
|
129 |
}
|
130 |
|
131 |
+
$item->tags = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_tag');
|
132 |
+
$item->album = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_album');
|
133 |
$item->categories = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_category');
|
134 |
|
135 |
$item = apply_filters('gmedia_item_more_data', $item);
|
136 |
}
|
137 |
|
138 |
+
function gmedia_filter_message(){
|
139 |
global $gmProcessor;
|
140 |
+
if(!empty($gmProcessor->filters)){
|
141 |
echo '<div class="custom-message alert alert-info">';
|
142 |
+
foreach($gmProcessor->filters as $key => $value){
|
143 |
echo '<div class="custom-message-row">';
|
144 |
echo '<strong><a href="#libModal" data-modal="' . $key . '" data-action="gmedia_get_modal" class="gmedia-modal">' . $value['title'] . '</a>: </strong>';
|
145 |
echo implode(', ', $value['filter']);
|
149 |
}
|
150 |
}
|
151 |
|
152 |
+
function gmedia_alert_message(){
|
153 |
global $gmProcessor;
|
154 |
+
if(($gmProcessor->mode == 'edit') && gm_user_can('show_others_media') && !gm_user_can('edit_others_media')){
|
155 |
?>
|
156 |
<div class="alert alert-warning alert-dismissible" role="alert" style="margin-bottom:0">
|
157 |
<button type="button" class="close" data-dismiss="alert">
|
162 |
}
|
163 |
}
|
164 |
|
165 |
+
/**
|
166 |
+
* @param $item
|
167 |
+
*
|
168 |
+
* @return string
|
169 |
+
*/
|
170 |
+
function gmedia_waveform_player($item){
|
171 |
+
global $gmDB;
|
172 |
+
$peaks = $gmDB->get_metadata('gmedia', $item->ID, '_peaks', true);
|
173 |
+
if($peaks){
|
174 |
+
if('[]' === $peaks){
|
175 |
+
$gmDB->delete_metadata('gmedia', $item->ID, '_peaks');
|
176 |
+
$peaks = '';
|
177 |
+
} else{
|
178 |
+
$peaks = json_decode($peaks);
|
179 |
+
while(900 < count($peaks)){
|
180 |
+
$peaks = array_map('reset', array_chunk($peaks, 2));
|
181 |
+
}
|
182 |
+
$peaks = json_encode($peaks);
|
183 |
+
}
|
184 |
+
} else{
|
185 |
+
$peaks = '';
|
186 |
+
}
|
187 |
+
$content = '
|
188 |
+
<div class="gm-waveform-player" data-id="' . $item->ID . '" data-file="' . $item->url . '" data-peaks="' . $peaks . '">
|
189 |
+
<div id="ws' . $item->ID . '"></div>' . ($peaks? '' : ('<button type="button" class="btn btn-sm btn-info gm-waveform">' . __('Create & Save WaveForm', 'grand-media') . '</button>')) . '<button type="button" class="btn btn-sm btn-info gm-play" style="display:none;">' . __('Play', 'grand-media') . '</button>
|
190 |
+
<button type="button" class="btn btn-sm btn-info gm-pause" style="display:none;">' . __('Pause', 'grand-media') . '</button>
|
191 |
+
<span style="float:none;" class="spinner"></span>
|
192 |
+
</div>';
|
193 |
+
|
194 |
+
return $content;
|
195 |
+
}
|
196 |
+
|
admin/pages/library/library.php
CHANGED
@@ -17,9 +17,12 @@ $gmedia_query = $gmDB->get_gmedias($gmProcessor->query_args);
|
|
17 |
$gmedia_count = $gmDB->count_gmedia();
|
18 |
$gmedia_pager = $gmDB->query_pager();
|
19 |
|
|
|
|
|
|
|
20 |
$panel_class = array();
|
21 |
$panel_class[] = 'panel-fixed-header';
|
22 |
-
$panel_class[] = "display-as-{$
|
23 |
if($gmProcessor->user_options['grid_cell_fit_gmedia']) {
|
24 |
$panel_class[] = 'invert-ratio';
|
25 |
}
|
@@ -39,11 +42,11 @@ if($gmProcessor->user_options['grid_cell_fit_gmedia']) {
|
|
39 |
|
40 |
gmedia_alert_message();
|
41 |
|
42 |
-
if(
|
43 |
foreach($gmedia_query as &$item) {
|
44 |
gmedia_item_more_data($item);
|
45 |
|
46 |
-
$item->classes = array();
|
47 |
if('publish' != $item->status) {
|
48 |
if('private' == $item->status) {
|
49 |
$item->classes[] = 'list-group-item-info';
|
@@ -57,19 +60,21 @@ if($gmProcessor->user_options['grid_cell_fit_gmedia']) {
|
|
57 |
}
|
58 |
$item->in_stack = in_array($item->ID, (array)$gmProcessor->stack_items);
|
59 |
|
60 |
-
include(dirname(__FILE__) .
|
61 |
}
|
62 |
} elseif(gm_user_can('edit_media')) {
|
63 |
$gm_category_terms = $gmDB->get_terms('gmedia_category', array('fields' => 'names'));
|
|
|
64 |
?>
|
65 |
<script type="text/javascript">
|
66 |
var gmedia_categories = <?php echo json_encode($gm_category_terms); ?>;
|
|
|
67 |
</script>
|
68 |
<?php
|
69 |
foreach($gmedia_query as &$item) {
|
70 |
gmedia_item_more_data($item);
|
71 |
|
72 |
-
$item->classes = array();
|
73 |
if('publish' != $item->status) {
|
74 |
if('private' == $item->status) {
|
75 |
$item->classes[] = 'list-group-item-info';
|
@@ -128,7 +133,8 @@ if($gmProcessor->user_options['grid_cell_fit_gmedia']) {
|
|
128 |
<?php
|
129 |
include(GMEDIA_ABSPATH . 'admin/tpl/modal-share.php');
|
130 |
|
131 |
-
if($gmProcessor->
|
|
|
132 |
include(GMEDIA_ABSPATH . 'admin/tpl/modal-customfield.php');
|
133 |
} ?>
|
134 |
|
17 |
$gmedia_count = $gmDB->count_gmedia();
|
18 |
$gmedia_pager = $gmDB->query_pager();
|
19 |
|
20 |
+
$view = $gmProcessor->gmediablank? '_frame' : '';
|
21 |
+
$display_mode_gmedia = $gmedia_user_options["display_mode_gmedia{$view}"];
|
22 |
+
|
23 |
$panel_class = array();
|
24 |
$panel_class[] = 'panel-fixed-header';
|
25 |
+
$panel_class[] = "display-as-{$display_mode_gmedia}";
|
26 |
if($gmProcessor->user_options['grid_cell_fit_gmedia']) {
|
27 |
$panel_class[] = 'invert-ratio';
|
28 |
}
|
42 |
|
43 |
gmedia_alert_message();
|
44 |
|
45 |
+
if(!($gmProcessor->mode == 'edit')) {
|
46 |
foreach($gmedia_query as &$item) {
|
47 |
gmedia_item_more_data($item);
|
48 |
|
49 |
+
$item->classes = array('gmedia-' . $item->type . '-item');
|
50 |
if('publish' != $item->status) {
|
51 |
if('private' == $item->status) {
|
52 |
$item->classes[] = 'list-group-item-info';
|
60 |
}
|
61 |
$item->in_stack = in_array($item->ID, (array)$gmProcessor->stack_items);
|
62 |
|
63 |
+
include(dirname(__FILE__) . "/tpl/{$display_mode_gmedia}-item.php");
|
64 |
}
|
65 |
} elseif(gm_user_can('edit_media')) {
|
66 |
$gm_category_terms = $gmDB->get_terms('gmedia_category', array('fields' => 'names'));
|
67 |
+
$gm_tag_terms = $gmDB->get_terms('gmedia_tag', array('fields' => 'names'));
|
68 |
?>
|
69 |
<script type="text/javascript">
|
70 |
var gmedia_categories = <?php echo json_encode($gm_category_terms); ?>;
|
71 |
+
var gmedia_tags = <?php echo json_encode($gm_tag_terms); ?>;
|
72 |
</script>
|
73 |
<?php
|
74 |
foreach($gmedia_query as &$item) {
|
75 |
gmedia_item_more_data($item);
|
76 |
|
77 |
+
$item->classes = array('gmedia-' . $item->type . '-item');
|
78 |
if('publish' != $item->status) {
|
79 |
if('private' == $item->status) {
|
80 |
$item->classes[] = 'list-group-item-info';
|
133 |
<?php
|
134 |
include(GMEDIA_ABSPATH . 'admin/tpl/modal-share.php');
|
135 |
|
136 |
+
if($gmProcessor->mode == 'edit') {
|
137 |
+
$customfield_meta_type = 'gmedia';
|
138 |
include(GMEDIA_ABSPATH . 'admin/tpl/modal-customfield.php');
|
139 |
} ?>
|
140 |
|
admin/pages/library/tpl/edit-item.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Edit Gmedia Item
|
4 |
*/
|
@@ -21,6 +26,11 @@
|
|
21 |
echo implode(' | ', $media_action_links);
|
22 |
?>
|
23 |
</div>
|
|
|
|
|
|
|
|
|
|
|
24 |
</div>
|
25 |
<div class="col-sm-8">
|
26 |
<div class="row">
|
@@ -117,14 +127,14 @@
|
|
117 |
foreach($item->tags as $c) {
|
118 |
$terms_tag[] = esc_html($c->name);
|
119 |
}
|
120 |
-
$terms_tag = join(',
|
121 |
} else {
|
122 |
$terms_tag = '';
|
123 |
}
|
124 |
?>
|
125 |
<div class="form-group">
|
126 |
<label><?php _e('Tags ', 'grand-media'); ?></label>
|
127 |
-
<
|
128 |
</div>
|
129 |
<?php } ?>
|
130 |
</div>
|
@@ -132,7 +142,7 @@
|
|
132 |
<div class="row">
|
133 |
<div class="col-lg-6">
|
134 |
<div class="form-group">
|
135 |
-
<label><?php _e('Filename', 'grand-media'); ?> <small>(ext: .<?php echo $item->ext; ?>)</small></label>
|
136 |
<input name="filename" type="text" class="form-control input-sm gmedia-filename" <?php echo (!gm_user_can('delete_others_media') && ((int)$item->author !== $user_ID))? 'readonly' : ''; ?> value="<?php echo pathinfo($item->gmuid, PATHINFO_FILENAME); ?>"/>
|
137 |
</div>
|
138 |
<div class="form-group">
|
@@ -154,7 +164,7 @@
|
|
154 |
</div>
|
155 |
<?php if(!empty($item->post_id)){ ?>
|
156 |
<div class="form-group">
|
157 |
-
<a href="<?php echo
|
158 |
<b class="comment-count"><?php echo $item->comment_count; ?></b>
|
159 |
<span class="glyphicon glyphicon-comment"></span>
|
160 |
</a>
|
@@ -191,7 +201,7 @@
|
|
191 |
<?php if(('image' != $item->type)) { ?>
|
192 |
<div class="form-group">
|
193 |
<label><?php _e('Custom Cover', 'grand-media'); echo ' <small>('.__('media image ID', 'grand-media').')</small>'; ?></label>
|
194 |
-
<input name="meta[_cover]" type="text" class="form-control input-sm gmedia-cover" value="<?php echo isset($item->meta['_cover'][0])? $item->meta['_cover'][0] : ''; ?>" placeholder="<?php _e('Gmedia ID
|
195 |
</div>
|
196 |
<?php } ?>
|
197 |
<?php if(('image' == $item->type) || ('video' == $item->type)) { ?>
|
@@ -200,7 +210,7 @@
|
|
200 |
|
201 |
<div class="input-group input-group-sm">
|
202 |
<input name="meta[_gps]" type="text" class="form-control input-sm gps_map_coordinates" value="<?php echo $item->gps; ?>" placeholder="<?php _e('Latitude, Longtitude', 'grand-media'); ?>" autocomplete="off"/>
|
203 |
-
<span class="input-group-btn"><a href="<?php echo
|
204 |
<span class="glyphicon glyphicon-map-marker"></span></a></span>
|
205 |
</div>
|
206 |
</div>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Edit Gmedia Item
|
9 |
*/
|
26 |
echo implode(' | ', $media_action_links);
|
27 |
?>
|
28 |
</div>
|
29 |
+
<?php
|
30 |
+
if('audio' == $item->type) {
|
31 |
+
echo gmedia_waveform_player($item);
|
32 |
+
}
|
33 |
+
?>
|
34 |
</div>
|
35 |
<div class="col-sm-8">
|
36 |
<div class="row">
|
127 |
foreach($item->tags as $c) {
|
128 |
$terms_tag[] = esc_html($c->name);
|
129 |
}
|
130 |
+
$terms_tag = join(',', $terms_tag);
|
131 |
} else {
|
132 |
$terms_tag = '';
|
133 |
}
|
134 |
?>
|
135 |
<div class="form-group">
|
136 |
<label><?php _e('Tags ', 'grand-media'); ?></label>
|
137 |
+
<input name="terms[gmedia_tag]" data-create="<?php echo gm_user_can('tag_manage')? 'true' : 'false'; ?>" class="combobox_gmedia_tag form-control input-sm" value="<?php echo $terms_tag; ?>"/>
|
138 |
</div>
|
139 |
<?php } ?>
|
140 |
</div>
|
142 |
<div class="row">
|
143 |
<div class="col-lg-6">
|
144 |
<div class="form-group">
|
145 |
+
<label><?php _e('Filename', 'grand-media'); ?> <small style="white-space:nowrap;">(ext: .<?php echo $item->ext; ?>)</small></label>
|
146 |
<input name="filename" type="text" class="form-control input-sm gmedia-filename" <?php echo (!gm_user_can('delete_others_media') && ((int)$item->author !== $user_ID))? 'readonly' : ''; ?> value="<?php echo pathinfo($item->gmuid, PATHINFO_FILENAME); ?>"/>
|
147 |
</div>
|
148 |
<div class="form-group">
|
164 |
</div>
|
165 |
<?php if(!empty($item->post_id)){ ?>
|
166 |
<div class="form-group">
|
167 |
+
<a href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'gmediablank' => 'comments', 'gmedia_id' => $item->ID), $gmProcessor->url); ?>" data-target="#previewModal" data-width="900" data-height="500" class="preview-modal gmpost-com-count pull-right" title="<?php esc_attr_e('Comments', 'grand-media'); ?>">
|
168 |
<b class="comment-count"><?php echo $item->comment_count; ?></b>
|
169 |
<span class="glyphicon glyphicon-comment"></span>
|
170 |
</a>
|
201 |
<?php if(('image' != $item->type)) { ?>
|
202 |
<div class="form-group">
|
203 |
<label><?php _e('Custom Cover', 'grand-media'); echo ' <small>('.__('media image ID', 'grand-media').')</small>'; ?></label>
|
204 |
+
<input name="meta[_cover]" type="text" class="form-control input-sm gmedia-cover" value="<?php echo isset($item->meta['_cover'][0])? $item->meta['_cover'][0] : ''; ?>" placeholder="<?php _e('Gmedia ID', 'grand-media'); ?>"/>
|
205 |
</div>
|
206 |
<?php } ?>
|
207 |
<?php if(('image' == $item->type) || ('video' == $item->type)) { ?>
|
210 |
|
211 |
<div class="input-group input-group-sm">
|
212 |
<input name="meta[_gps]" type="text" class="form-control input-sm gps_map_coordinates" value="<?php echo $item->gps; ?>" placeholder="<?php _e('Latitude, Longtitude', 'grand-media'); ?>" autocomplete="off"/>
|
213 |
+
<span class="input-group-btn"><a href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'gmediablank' => 'map_editor', 'id' => $item->ID), $gmProcessor->url); ?>" class="btn btn-primary gmedit-modal" data-target="#gmeditModal">
|
214 |
<span class="glyphicon glyphicon-map-marker"></span></a></span>
|
215 |
</div>
|
216 |
</div>
|
admin/pages/library/tpl/grid-item.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Gmedia Item for Grid View in Library
|
4 |
*/
|
@@ -13,66 +18,60 @@
|
|
13 |
</label>
|
14 |
<label class="gm-stack"><input title="<?php _e('Add to Stack', 'grand-media'); ?>" name="stack[]" type="checkbox"<?php echo $item->in_stack? ' checked="checked"' : ''; ?> data-type="<?php echo $item->type; ?>" value="<?php echo $item->ID; ?>"/></label>
|
15 |
<div class="gm-cell-more">
|
16 |
-
<span class="gm-cell-more-btn glyphicon glyphicon-
|
17 |
-
<div class="gm-cell-title"><span><?php echo esc_html($item->title); ?> </span></div>
|
18 |
<div class="gm-cell-more-content">
|
19 |
-
<
|
20 |
-
<span
|
21 |
-
<?php $media_action_links = gmedia_item_actions($item);
|
22 |
-
echo implode(' | ', $media_action_links);
|
23 |
-
?>
|
24 |
-
</div>
|
25 |
-
<p class="media-meta"><span class="label label-default"><?php _e('Album', 'grand-media'); ?>:</span>
|
26 |
<?php
|
27 |
-
if($item->album)
|
28 |
$terms_album = array();
|
29 |
-
foreach($item->album as $c)
|
30 |
$terms_album[] = sprintf('<a class="album" href="%s">%s</a>', esc_url(add_query_arg(array('alb' => $c->term_id), $gmedia_url)), esc_html($c->name));
|
31 |
}
|
32 |
$terms_album = join(', ', $terms_album);
|
33 |
-
} else
|
34 |
$terms_album = sprintf('<a class="album" href="%s">%s</a>', esc_url(add_query_arg(array('alb' => 0), $gmedia_url)), '—');
|
35 |
}
|
36 |
echo $terms_album;
|
37 |
?>
|
38 |
<br/><span class="label label-default"><?php _e('Category', 'grand-media'); ?>:</span>
|
39 |
<?php
|
40 |
-
if($item->categories)
|
41 |
$terms_category = array();
|
42 |
-
foreach($item->categories as $c)
|
43 |
$terms_category[] = sprintf('<a class="category" href="%s">%s</a>', esc_url(add_query_arg(array('cat' => $c->term_id), $gmedia_url)), esc_html($c->name));
|
44 |
}
|
45 |
$terms_category = join(', ', $terms_category);
|
46 |
-
} else
|
47 |
$terms_category = sprintf('<a class="category" href="%s">%s</a>', esc_url(add_query_arg(array('cat' => 0), $gmedia_url)), __('Uncategorized', 'grand-media'));
|
48 |
}
|
49 |
echo $terms_category;
|
50 |
?>
|
51 |
<br/><span class="label label-default"><?php _e('Tags', 'grand-media'); ?>:</span>
|
52 |
<?php
|
53 |
-
if($item->tags)
|
54 |
$terms_tag = array();
|
55 |
-
foreach($item->tags as $c)
|
56 |
$terms_tag[] = sprintf('<a class="tag" href="%s">%s</a>', esc_url(add_query_arg(array('tag_id' => $c->term_id), $gmedia_url)), esc_html($c->name));
|
57 |
}
|
58 |
$terms_tag = join(', ', $terms_tag);
|
59 |
-
} else
|
60 |
$terms_tag = '—';
|
61 |
}
|
62 |
echo $terms_tag;
|
63 |
?>
|
64 |
|
65 |
-
<?php if(isset($item->post_id))
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
<?php } ?>
|
72 |
<br/><span class="label label-default"><?php _e('Views / Likes', 'grand-media'); ?>:</span>
|
73 |
<?php echo (isset($item->meta['views'][0])? $item->meta['views'][0] : '0') . ' / ' . (isset($item->meta['likes'][0])? $item->meta['likes'][0] : '0'); ?>
|
74 |
|
75 |
-
<?php if(isset($item->meta['_rating'][0]))
|
76 |
$ratings = maybe_unserialize($item->meta['_rating'][0]); ?>
|
77 |
<br/><span class="label label-default"><?php _e('Rating', 'grand-media'); ?>:</span> <?php echo $ratings['value'] . ' / ' . $ratings['votes']; ?>
|
78 |
<?php } ?>
|
@@ -80,6 +79,14 @@
|
|
80 |
</div>
|
81 |
</div>
|
82 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
</div>
|
84 |
|
85 |
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Gmedia Item for Grid View in Library
|
9 |
*/
|
18 |
</label>
|
19 |
<label class="gm-stack"><input title="<?php _e('Add to Stack', 'grand-media'); ?>" name="stack[]" type="checkbox"<?php echo $item->in_stack? ' checked="checked"' : ''; ?> data-type="<?php echo $item->type; ?>" value="<?php echo $item->ID; ?>"/></label>
|
20 |
<div class="gm-cell-more">
|
21 |
+
<span class="gm-cell-more-btn glyphicon glyphicon-menu-hamburger"></span>
|
|
|
22 |
<div class="gm-cell-more-content">
|
23 |
+
<p class="media-meta"><span class="label label-default"><?php _e('ID', 'grand-media'); ?>:</span> #<?php echo $item->ID; ?>
|
24 |
+
<br/><span class="label label-default"><?php _e('Album', 'grand-media'); ?>:</span>
|
|
|
|
|
|
|
|
|
|
|
25 |
<?php
|
26 |
+
if($item->album){
|
27 |
$terms_album = array();
|
28 |
+
foreach($item->album as $c){
|
29 |
$terms_album[] = sprintf('<a class="album" href="%s">%s</a>', esc_url(add_query_arg(array('alb' => $c->term_id), $gmedia_url)), esc_html($c->name));
|
30 |
}
|
31 |
$terms_album = join(', ', $terms_album);
|
32 |
+
} else{
|
33 |
$terms_album = sprintf('<a class="album" href="%s">%s</a>', esc_url(add_query_arg(array('alb' => 0), $gmedia_url)), '—');
|
34 |
}
|
35 |
echo $terms_album;
|
36 |
?>
|
37 |
<br/><span class="label label-default"><?php _e('Category', 'grand-media'); ?>:</span>
|
38 |
<?php
|
39 |
+
if($item->categories){
|
40 |
$terms_category = array();
|
41 |
+
foreach($item->categories as $c){
|
42 |
$terms_category[] = sprintf('<a class="category" href="%s">%s</a>', esc_url(add_query_arg(array('cat' => $c->term_id), $gmedia_url)), esc_html($c->name));
|
43 |
}
|
44 |
$terms_category = join(', ', $terms_category);
|
45 |
+
} else{
|
46 |
$terms_category = sprintf('<a class="category" href="%s">%s</a>', esc_url(add_query_arg(array('cat' => 0), $gmedia_url)), __('Uncategorized', 'grand-media'));
|
47 |
}
|
48 |
echo $terms_category;
|
49 |
?>
|
50 |
<br/><span class="label label-default"><?php _e('Tags', 'grand-media'); ?>:</span>
|
51 |
<?php
|
52 |
+
if($item->tags){
|
53 |
$terms_tag = array();
|
54 |
+
foreach($item->tags as $c){
|
55 |
$terms_tag[] = sprintf('<a class="tag" href="%s">%s</a>', esc_url(add_query_arg(array('tag_id' => $c->term_id), $gmedia_url)), esc_html($c->name));
|
56 |
}
|
57 |
$terms_tag = join(', ', $terms_tag);
|
58 |
+
} else{
|
59 |
$terms_tag = '—';
|
60 |
}
|
61 |
echo $terms_tag;
|
62 |
?>
|
63 |
|
64 |
+
<?php if(isset($item->post_id)){ ?>
|
65 |
+
<br/><span class="label label-default"><?php _e('Comments', 'grand-media'); ?>:</span>
|
66 |
+
<a href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'gmediablank' => 'comments', 'gmedia_id' => $item->ID), $gmProcessor->url); ?>" data-target="#previewModal" data-width="900" data-height="500" class="preview-modal gmpost-com-count" title="<?php esc_attr_e('Comments', 'grand-media'); ?>">
|
67 |
+
<b class="comment-count"><?php echo $item->comment_count; ?></b>
|
68 |
+
<span class="glyphicon glyphicon-comment"></span>
|
69 |
+
</a>
|
70 |
<?php } ?>
|
71 |
<br/><span class="label label-default"><?php _e('Views / Likes', 'grand-media'); ?>:</span>
|
72 |
<?php echo (isset($item->meta['views'][0])? $item->meta['views'][0] : '0') . ' / ' . (isset($item->meta['likes'][0])? $item->meta['likes'][0] : '0'); ?>
|
73 |
|
74 |
+
<?php if(isset($item->meta['_rating'][0])){
|
75 |
$ratings = maybe_unserialize($item->meta['_rating'][0]); ?>
|
76 |
<br/><span class="label label-default"><?php _e('Rating', 'grand-media'); ?>:</span> <?php echo $ratings['value'] . ' / ' . $ratings['votes']; ?>
|
77 |
<?php } ?>
|
79 |
</div>
|
80 |
</div>
|
81 |
</div>
|
82 |
+
<div class="gm-cell-bottom">
|
83 |
+
<div class="gm-cell-title"><span><?php echo esc_html($item->title); ?> </span></div>
|
84 |
+
<div class="gmedia-actions">
|
85 |
+
<?php $media_action_links = gmedia_item_actions($item);
|
86 |
+
echo implode(' ', $media_action_links);
|
87 |
+
?>
|
88 |
+
</div>
|
89 |
+
</div>
|
90 |
</div>
|
91 |
|
92 |
|
admin/pages/library/tpl/list-item.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Gmedia Item for List View in Library
|
4 |
*
|
@@ -18,6 +23,11 @@
|
|
18 |
</label>
|
19 |
<label class="gm-stack"><input title="<?php _e('Add to Stack', 'grand-media'); ?>" name="stack[]" type="checkbox"<?php echo $item->in_stack? ' checked="checked"' : ''; ?> data-type="<?php echo $item->type; ?>" value="<?php echo $item->ID; ?>"/></label>
|
20 |
</div>
|
|
|
|
|
|
|
|
|
|
|
21 |
</div>
|
22 |
<div class="col-sm-8">
|
23 |
<div class="row" style="margin:0;">
|
@@ -70,7 +80,7 @@
|
|
70 |
</p>
|
71 |
</div>
|
72 |
<div class="col-lg-6">
|
73 |
-
<div class="media-meta" style="margin:0 0 10px 0;">
|
74 |
<?php $media_action_links = gmedia_item_actions($item);
|
75 |
echo implode(' | ', $media_action_links);
|
76 |
?>
|
@@ -78,7 +88,7 @@
|
|
78 |
<?php if(isset($item->post_id)) { ?>
|
79 |
<p class="media-meta">
|
80 |
<span class="label label-default"><?php _e('Comments', 'grand-media'); ?>:</span>
|
81 |
-
<a href="<?php echo
|
82 |
<b class="comment-count"><?php echo $item->comment_count; ?></b>
|
83 |
<span class="glyphicon glyphicon-comment"></span>
|
84 |
</a>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Gmedia Item for List View in Library
|
9 |
*
|
23 |
</label>
|
24 |
<label class="gm-stack"><input title="<?php _e('Add to Stack', 'grand-media'); ?>" name="stack[]" type="checkbox"<?php echo $item->in_stack? ' checked="checked"' : ''; ?> data-type="<?php echo $item->type; ?>" value="<?php echo $item->ID; ?>"/></label>
|
25 |
</div>
|
26 |
+
<?php
|
27 |
+
if('audio' == $item->type) {
|
28 |
+
echo gmedia_waveform_player($item);
|
29 |
+
}
|
30 |
+
?>
|
31 |
</div>
|
32 |
<div class="col-sm-8">
|
33 |
<div class="row" style="margin:0;">
|
80 |
</p>
|
81 |
</div>
|
82 |
<div class="col-lg-6">
|
83 |
+
<div class="media-meta gmedia-actions" style="margin:0 0 10px 0;">
|
84 |
<?php $media_action_links = gmedia_item_actions($item);
|
85 |
echo implode(' | ', $media_action_links);
|
86 |
?>
|
88 |
<?php if(isset($item->post_id)) { ?>
|
89 |
<p class="media-meta">
|
90 |
<span class="label label-default"><?php _e('Comments', 'grand-media'); ?>:</span>
|
91 |
+
<a href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'gmediablank' => 'comments', 'gmedia_id' => $item->ID), $gmProcessor->url); ?>" data-target="#previewModal" data-width="900" data-height="500" class="preview-modal gmpost-com-count" title="<?php esc_attr_e('Comments', 'grand-media'); ?>">
|
92 |
<b class="comment-count"><?php echo $item->comment_count; ?></b>
|
93 |
<span class="glyphicon glyphicon-comment"></span>
|
94 |
</a>
|
admin/pages/library/tpl/no-items.php
CHANGED
@@ -1,12 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<div class="list-group-item">
|
2 |
<div class="well well-lg text-center">
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
</div>
|
12 |
</div>
|
1 |
+
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
global $gmCore, $gmProcessor;
|
7 |
+
?>
|
8 |
<div class="list-group-item">
|
9 |
<div class="well well-lg text-center">
|
10 |
+
<?php if('duplicates' === $gmCore->_get('gmedia__in')){
|
11 |
+
echo '<h4>' . __('No duplicates in Gmedia Library.', 'grand-media') . '</h4>';
|
12 |
+
} else{
|
13 |
+
echo '<h4>' . __('No items to show.', 'grand-media') . '</h4>';
|
14 |
+
if(gm_user_can('upload') && !$gmProcessor->gmediablank) { ?>
|
15 |
+
<p>
|
16 |
+
<a href="<?php echo add_query_arg(array('page' => 'GrandMedia_AddMedia'), $gmProcessor->url); ?>" class="btn btn-success">
|
17 |
+
<span class="glyphicon glyphicon-plus"></span> <?php _e('Add Media', 'grand-media'); ?>
|
18 |
+
</a>
|
19 |
+
</p>
|
20 |
+
<?php }
|
21 |
+
} ?>
|
22 |
</div>
|
23 |
</div>
|
admin/pages/library/tpl/panel-footer.php
CHANGED
@@ -1,3 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<div class="panel-footer clearfix">
|
2 |
<?php echo $gmedia_pager; ?>
|
3 |
|
1 |
+
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
?>
|
7 |
<div class="panel-footer clearfix">
|
8 |
<?php echo $gmedia_pager; ?>
|
9 |
|
admin/pages/library/tpl/panel-heading.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* @var $gmCore
|
4 |
* @var $gmProcessor
|
@@ -11,15 +16,20 @@
|
|
11 |
<?php include(GMEDIA_ABSPATH . 'admin/tpl/search-form.php'); ?>
|
12 |
|
13 |
<div class="btn-toolbar pull-right" style="margin-bottom:4px; margin-left:4px;">
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
<?php if(
|
|
|
|
|
|
|
17 |
<div class="btn-group pull-right">
|
18 |
-
<a title="<?php _e('Show as Grid', 'grand-media'); ?>" href="<?php echo gm_get_admin_url(array('display_mode' => 'grid')); ?>" class="btn btn<?php echo ($
|
19 |
-
<a title="<?php _e('Show as List', 'grand-media'); ?>" href="<?php echo gm_get_admin_url(array('display_mode' => 'list')); ?>" class="btn btn<?php echo ($
|
20 |
</div>
|
21 |
-
<?php if($
|
22 |
-
<a title="<?php _e('Thumbnails Fit/Fill Cell', 'grand-media'); ?>" href="<?php echo gm_get_admin_url(array('grid_cell_fit' => 'toggle')); ?>" class="fit-thumbs pull-right btn btn<?php echo ($gmedia_user_options[
|
23 |
<?php } ?>
|
24 |
<?php } ?>
|
25 |
</div>
|
@@ -27,6 +37,8 @@
|
|
27 |
|
28 |
<?php echo $gmedia_pager; ?>
|
29 |
|
|
|
|
|
30 |
</div>
|
31 |
<div class="btn-toolbar pull-left" style="margin-bottom:7px;">
|
32 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
@@ -49,7 +61,7 @@
|
|
49 |
<?php // todo: !!!!!
|
50 |
$curr_mime = explode(',', $gmCore->_get('mime_type', 'total')); ?>
|
51 |
<?php if($gmDB->filter) { ?>
|
52 |
-
<a class="btn btn-warning" title="<?php _e('Reset Filter', 'grand-media'); ?>" rel="total" href="<?php echo $gmedia_url; ?>"><?php _e('Reset Filter', 'grand-media'); ?></a>
|
53 |
<?php } else { ?>
|
54 |
<button type="button" class="btn btn-default" data-toggle="dropdown"><?php _e('Filter', 'grand-media'); ?></button>
|
55 |
<?php } ?>
|
@@ -96,13 +108,13 @@
|
|
96 |
</div>
|
97 |
|
98 |
<div class="btn-group">
|
99 |
-
<?php if(
|
100 |
-
$action_args = array('
|
101 |
$edit_mode_href = gm_get_admin_url($action_args);
|
102 |
-
$action_args2 = array('
|
103 |
$edit_mode_data = 'data-href="' . $edit_mode_href . '" data-href_sel="' . gm_get_admin_url($action_args2) . '"';
|
104 |
} else {
|
105 |
-
$edit_mode_href = gm_get_admin_url(array(), array('
|
106 |
$edit_mode_data = '';
|
107 |
} ?>
|
108 |
<?php if(gm_user_can('edit_media')) { ?>
|
@@ -117,7 +129,7 @@
|
|
117 |
$rel_selected_hide = 'rel-selected-hide';
|
118 |
?>
|
119 |
<ul class="dropdown-menu" role="menu">
|
120 |
-
<?php if(
|
121 |
<li class="<?php echo gm_user_can('edit_media')? '' : 'disabled'; ?>">
|
122 |
<a class="edit-mode-link" href="<?php echo $edit_mode_href; ?>" <?php echo $edit_mode_data; ?>><?php _e('Enter Edit Mode', 'grand-media'); ?></a>
|
123 |
</li>
|
@@ -127,7 +139,7 @@
|
|
127 |
<li class="<?php echo $rel_selected_show . (gm_user_can('edit_media')? '' : ' disabled'); ?>">
|
128 |
<a href="#libModal" data-modal="batch_edit" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Batch Edit', 'grand-media'); ?></a></li>
|
129 |
|
130 |
-
<li class="divider"></li>
|
131 |
<li class="<?php echo $rel_selected_show . (gm_user_can('terms')? '' : ' disabled'); ?>">
|
132 |
<a href="#libModal" data-modal="assign_album" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Move to Album...', 'grand-media'); ?></a>
|
133 |
</li>
|
@@ -147,12 +159,22 @@
|
|
147 |
</li>
|
148 |
|
149 |
<li class="divider <?php echo $rel_selected_show; ?>"></li>
|
|
|
|
|
|
|
150 |
<li class="<?php echo $rel_selected_show . (gm_user_can('edit_media')? '' : ' disabled'); ?>">
|
151 |
<a href="<?php echo wp_nonce_url(gm_get_admin_url(array('update_meta' => 'selected'), array()), 'gmedia_update_meta') ?>" class="gmedia-update"><?php _e('Update Metadata in Database', 'grand-media'); ?></a>
|
152 |
</li>
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
<li class="dropdown-header <?php echo $rel_selected_hide; ?>"><span><?php _e("Select items to see more actions", "grand-media"); ?></span></li>
|
155 |
<?php do_action('gmedia_action_list'); ?>
|
|
|
156 |
</ul>
|
157 |
</div>
|
158 |
|
@@ -163,7 +185,7 @@
|
|
163 |
$filter_selected = $gmCore->_req('filter');
|
164 |
$filter_selected_arg = $filter_selected? false : 'selected';
|
165 |
?>
|
166 |
-
<form class="btn-group" id="gm-stack-btn" name="gm-stack-form" action="<?php echo
|
167 |
<button type="submit" class="btn btn<?php echo ('show' == $filter_stack)? '-success' : '-info' ?>"><?php printf(__('%s in Stack', 'grand-media'), '<span id="gm-stack-qty">' . count($gmProcessor->stack_items) . '</span>'); ?></button>
|
168 |
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><span class="caret"></span>
|
169 |
<span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?></span></button>
|
@@ -183,7 +205,7 @@
|
|
183 |
</ul>
|
184 |
</form>
|
185 |
|
186 |
-
<form class="btn-group" id="gm-selected-btn" name="gm-selected-form" action="<?php echo
|
187 |
<button type="submit" class="btn btn<?php echo ('selected' == $filter_selected)? '-success' : '-info' ?>"><?php printf(__('%s selected', 'grand-media'), '<span id="gm-selected-qty">' . count($gmProcessor->selected_items) . '</span>'); ?></button>
|
188 |
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><span class="caret"></span>
|
189 |
<span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?></span></button>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* @var $gmCore
|
9 |
* @var $gmProcessor
|
16 |
<?php include(GMEDIA_ABSPATH . 'admin/tpl/search-form.php'); ?>
|
17 |
|
18 |
<div class="btn-toolbar pull-right" style="margin-bottom:4px; margin-left:4px;">
|
19 |
+
<?php if(!$gmProcessor->gmediablank){ ?>
|
20 |
+
<a title="<?php _e('More Screen Settings', 'grand-media'); ?>" class="show-settings-link pull-right btn btn-default btn-xs"><span class="glyphicon glyphicon-cog"></span></a>
|
21 |
+
<?php } ?>
|
22 |
|
23 |
+
<?php if(!($gmProcessor->mode == 'edit')) {
|
24 |
+
$view = $gmProcessor->gmediablank? '_frame' : '';
|
25 |
+
$display_mode_gmedia = $gmedia_user_options["display_mode_gmedia{$view}"];
|
26 |
+
?>
|
27 |
<div class="btn-group pull-right">
|
28 |
+
<a title="<?php _e('Show as Grid', 'grand-media'); ?>" href="<?php echo gm_get_admin_url(array('display_mode' => 'grid')); ?>" class="btn btn<?php echo ($display_mode_gmedia == 'grid')? '-primary active' : '-default'; ?> btn-xs"><span class="glyphicon glyphicon-th"></span></a>
|
29 |
+
<a title="<?php _e('Show as List', 'grand-media'); ?>" href="<?php echo gm_get_admin_url(array('display_mode' => 'list')); ?>" class="btn btn<?php echo ($display_mode_gmedia == 'list')? '-primary active' : '-default'; ?> btn-xs"><span class="glyphicon glyphicon-th-list"></span></a>
|
30 |
</div>
|
31 |
+
<?php if($display_mode_gmedia == 'grid') { ?>
|
32 |
+
<a title="<?php _e('Thumbnails Fit/Fill Cell', 'grand-media'); ?>" href="<?php echo gm_get_admin_url(array('grid_cell_fit' => 'toggle')); ?>" class="fit-thumbs pull-right btn btn<?php echo ($gmedia_user_options["grid_cell_fit_gmedia{$view}"] == 'true')? '-success active' : '-default'; ?> btn-xs"><span class="glyphicon glyphicon-eye-open"></span></a>
|
33 |
<?php } ?>
|
34 |
<?php } ?>
|
35 |
</div>
|
37 |
|
38 |
<?php echo $gmedia_pager; ?>
|
39 |
|
40 |
+
<div class="spinner"></div>
|
41 |
+
|
42 |
</div>
|
43 |
<div class="btn-toolbar pull-left" style="margin-bottom:7px;">
|
44 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
61 |
<?php // todo: !!!!!
|
62 |
$curr_mime = explode(',', $gmCore->_get('mime_type', 'total')); ?>
|
63 |
<?php if($gmDB->filter) { ?>
|
64 |
+
<a class="btn btn-warning" title="<?php _e('Reset Filter', 'grand-media'); ?>" rel="total" href="<?php echo gm_get_admin_url(array(), array(), $gmedia_url); ?>"><?php _e('Reset Filter', 'grand-media'); ?></a>
|
65 |
<?php } else { ?>
|
66 |
<button type="button" class="btn btn-default" data-toggle="dropdown"><?php _e('Filter', 'grand-media'); ?></button>
|
67 |
<?php } ?>
|
108 |
</div>
|
109 |
|
110 |
<div class="btn-group">
|
111 |
+
<?php if(!($gmProcessor->mode == 'edit')) {
|
112 |
+
$action_args = array('mode' => 'edit');
|
113 |
$edit_mode_href = gm_get_admin_url($action_args);
|
114 |
+
$action_args2 = array('mode' => 'edit', 'filter' => 'selected', 'pager' => false, 's' => false);
|
115 |
$edit_mode_data = 'data-href="' . $edit_mode_href . '" data-href_sel="' . gm_get_admin_url($action_args2) . '"';
|
116 |
} else {
|
117 |
+
$edit_mode_href = gm_get_admin_url(array(), array('mode'));
|
118 |
$edit_mode_data = '';
|
119 |
} ?>
|
120 |
<?php if(gm_user_can('edit_media')) { ?>
|
129 |
$rel_selected_hide = 'rel-selected-hide';
|
130 |
?>
|
131 |
<ul class="dropdown-menu" role="menu">
|
132 |
+
<?php if(!($gmProcessor->mode == 'edit')) { ?>
|
133 |
<li class="<?php echo gm_user_can('edit_media')? '' : 'disabled'; ?>">
|
134 |
<a class="edit-mode-link" href="<?php echo $edit_mode_href; ?>" <?php echo $edit_mode_data; ?>><?php _e('Enter Edit Mode', 'grand-media'); ?></a>
|
135 |
</li>
|
139 |
<li class="<?php echo $rel_selected_show . (gm_user_can('edit_media')? '' : ' disabled'); ?>">
|
140 |
<a href="#libModal" data-modal="batch_edit" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Batch Edit', 'grand-media'); ?></a></li>
|
141 |
|
142 |
+
<li class="divider <?php echo $rel_selected_show; ?>"></li>
|
143 |
<li class="<?php echo $rel_selected_show . (gm_user_can('terms')? '' : ' disabled'); ?>">
|
144 |
<a href="#libModal" data-modal="assign_album" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Move to Album...', 'grand-media'); ?></a>
|
145 |
</li>
|
159 |
</li>
|
160 |
|
161 |
<li class="divider <?php echo $rel_selected_show; ?>"></li>
|
162 |
+
<li class="<?php echo $rel_selected_show . (gm_user_can('edit_media')? '' : ' disabled'); ?>">
|
163 |
+
<a href="<?php echo wp_nonce_url(gm_get_admin_url(array('recreate' => 'selected'), array()), 'gmedia_recreate') ?>" class="gmedia-update"><?php _e('Re-create Images (heavy process)', 'grand-media'); ?></a>
|
164 |
+
</li>
|
165 |
<li class="<?php echo $rel_selected_show . (gm_user_can('edit_media')? '' : ' disabled'); ?>">
|
166 |
<a href="<?php echo wp_nonce_url(gm_get_admin_url(array('update_meta' => 'selected'), array()), 'gmedia_update_meta') ?>" class="gmedia-update"><?php _e('Update Metadata in Database', 'grand-media'); ?></a>
|
167 |
</li>
|
168 |
|
169 |
+
<li class="divider"></li>
|
170 |
+
<li class="">
|
171 |
+
<a href="<?php echo gm_get_admin_url(array('gmedia__in' => 'duplicates'), array()); ?>"><?php _e('Show Duplicates in Library', 'grand-media'); ?></a>
|
172 |
+
</li>
|
173 |
+
|
174 |
+
<li class="divider <?php echo $rel_selected_hide; ?>"></li>
|
175 |
<li class="dropdown-header <?php echo $rel_selected_hide; ?>"><span><?php _e("Select items to see more actions", "grand-media"); ?></span></li>
|
176 |
<?php do_action('gmedia_action_list'); ?>
|
177 |
+
|
178 |
</ul>
|
179 |
</div>
|
180 |
|
185 |
$filter_selected = $gmCore->_req('filter');
|
186 |
$filter_selected_arg = $filter_selected? false : 'selected';
|
187 |
?>
|
188 |
+
<form class="btn-group" id="gm-stack-btn" name="gm-stack-form" action="<?php echo gm_get_admin_url(array('stack' => $filter_stack_arg, 'filter' => $filter_selected), array(), $gmedia_url); ?>" method="post">
|
189 |
<button type="submit" class="btn btn<?php echo ('show' == $filter_stack)? '-success' : '-info' ?>"><?php printf(__('%s in Stack', 'grand-media'), '<span id="gm-stack-qty">' . count($gmProcessor->stack_items) . '</span>'); ?></button>
|
190 |
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><span class="caret"></span>
|
191 |
<span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?></span></button>
|
205 |
</ul>
|
206 |
</form>
|
207 |
|
208 |
+
<form class="btn-group" id="gm-selected-btn" name="gm-selected-form" action="<?php echo gm_get_admin_url(array('stack' => $filter_stack, 'filter' => $filter_selected_arg), array(), $gmedia_url); ?>" method="post">
|
209 |
<button type="submit" class="btn btn<?php echo ('selected' == $filter_selected)? '-success' : '-info' ?>"><?php printf(__('%s selected', 'grand-media'), '<span id="gm-selected-qty">' . count($gmProcessor->selected_items) . '</span>'); ?></button>
|
210 |
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><span class="caret"></span>
|
211 |
<span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?></span></button>
|
admin/pages/modules/edit-preset.php
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Gmedia Gallery Edit
|
4 |
+
*/
|
5 |
+
|
6 |
+
// don't load directly
|
7 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
8 |
+
die( '-1' );
|
9 |
+
}
|
10 |
+
|
11 |
+
global $user_ID, $gmDB, $gmCore, $gmGallery, $gmProcessor;
|
12 |
+
|
13 |
+
$term_id = (int) $gmCore->_get( 'preset', 0 );
|
14 |
+
$preset_module = $gmCore->_get( 'preset_module' );
|
15 |
+
$gmedia_url = add_query_arg( array( 'preset_module' => $preset_module, 'preset' => $term_id ), $gmProcessor->url );
|
16 |
+
$gmedia_term_taxonomy = 'gmedia_module';
|
17 |
+
$taxterm = str_replace( 'gmedia_', '', $gmedia_term_taxonomy );
|
18 |
+
|
19 |
+
if ( ! gm_user_can( "{$taxterm}_manage" ) ) {
|
20 |
+
die( '-1' );
|
21 |
+
}
|
22 |
+
|
23 |
+
$term = $gmDB->get_term( $term_id );
|
24 |
+
gmedia_module_preset_more_data( $term );
|
25 |
+
|
26 |
+
$term_id = $term->term_id;
|
27 |
+
|
28 |
+
$gmedia_modules = get_gmedia_modules( false );
|
29 |
+
|
30 |
+
$default_module_demo_query_args = get_user_option('gmedia_preset_demo_query_args');
|
31 |
+
$gmedia_filter = gmedia_gallery_query_data($default_module_demo_query_args);
|
32 |
+
$default_options = array();
|
33 |
+
|
34 |
+
if ( isset( $gmedia_modules['in'][ $term->module['name'] ] ) ) {
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @var $module_name
|
38 |
+
* @var $module_path
|
39 |
+
* @var $options_tree
|
40 |
+
* @var $default_options
|
41 |
+
*/
|
42 |
+
extract( $gmedia_modules['in'][ $term->module['name'] ] );
|
43 |
+
if ( file_exists( $module_path . '/index.php' ) && file_exists( $module_path . '/settings.php' ) ) {
|
44 |
+
/** @noinspection PhpIncludeInspection */
|
45 |
+
include( $module_path . '/index.php' );
|
46 |
+
/** @noinspection PhpIncludeInspection */
|
47 |
+
include( $module_path . '/settings.php' );
|
48 |
+
|
49 |
+
} else {
|
50 |
+
$alert[] = sprintf( __( 'Module `%s` is broken. Choose another module from the list.' ), $module_name );
|
51 |
+
}
|
52 |
+
} else {
|
53 |
+
$alert[] = sprintf( __( 'Can\'t get module with name `%s`. Choose module from the list.' ), $term->module['name'] );
|
54 |
+
}
|
55 |
+
|
56 |
+
if ( ! empty( $alert ) ) {
|
57 |
+
echo $gmCore->alert( 'danger', $alert );
|
58 |
+
}
|
59 |
+
|
60 |
+
if ( ! empty( $term->module['settings'] ) ) {
|
61 |
+
$gallery_settings = $gmCore->array_replace_recursive( $default_options, $term->module['settings'] );
|
62 |
+
} else {
|
63 |
+
$gallery_settings = $default_options;
|
64 |
+
}
|
65 |
+
|
66 |
+
$params = array();
|
67 |
+
$gallery_link_default = add_query_arg( array( 'page' => 'GrandMedia', 'gmediablank' => 'module_preview', 'module' => $term->module['name'], 'preset' => $term->term_id, 'query' => $gmedia_filter['query_args'] ), admin_url( 'admin.php' ) );
|
68 |
+
|
69 |
+
/** @noinspection PhpIncludeInspection */
|
70 |
+
include_once( GMEDIA_ABSPATH . '/inc/module.options.php' );
|
71 |
+
|
72 |
+
do_action( 'gmedia_module_preset_before_panel' );
|
73 |
+
?>
|
74 |
+
|
75 |
+
<div class="panel panel-default panel-fixed-header">
|
76 |
+
|
77 |
+
<?php
|
78 |
+
include( dirname( __FILE__ ) . '/tpl/module-preset-panel-heading.php' );
|
79 |
+
|
80 |
+
include( dirname( __FILE__ ) . "/tpl/module-preset-edit-item.php" );
|
81 |
+
?>
|
82 |
+
|
83 |
+
</div>
|
84 |
+
|
85 |
+
<?php
|
86 |
+
do_action( 'gmedia_module_preset_after_panel' );
|
87 |
+
?>
|
admin/pages/modules/functions.php
CHANGED
@@ -3,27 +3,74 @@
|
|
3 |
* Modules functions
|
4 |
*/
|
5 |
|
6 |
-
function gmedia_module_action_buttons($module)
|
7 |
global $gmCore, $gmProcessor;
|
8 |
|
9 |
$buttons = array();
|
10 |
-
if('remote' == $module['place'])
|
11 |
$buttons['install'] = '<a class="btn btn-primary ' . (gm_user_can('module_manage')? 'module_install' : 'disabled') . '" data-module="' . $module['name'] . '" data-loading-text="' . __('Loading...', 'grand-media') . '" href="' . esc_url($module['download']) . '">' . __('Install Module', 'grand-media') . '</a>';
|
12 |
-
} else
|
13 |
$buttons['create'] = '<a class="btn btn-success" href="' . $gmCore->get_admin_url(array('page' => 'GrandMedia_Galleries', 'gallery_module' => $module['module_name']), array(), true) . '">' . __('Create Gallery', 'grand-media') . '</a>';
|
14 |
}
|
15 |
-
if(!empty($module['demo']) && $module['demo'] != '#')
|
16 |
$buttons['demo'] = '<a class="btn btn-default" target="_blank" href="' . $module['demo'] . '">' . __('View Demo', 'grand-media') . '</a>';
|
17 |
}
|
18 |
-
if(!empty($module['update']) && 'remote' != $module['place'])
|
19 |
$buttons['update'] = '<a class="btn btn-warning module_install" data-module="' . $module['module_name'] . '" data-loading-text="' . __('Loading...', 'grand-media') . '" href="' . esc_url($module['download']) . '">' . __('Update Module', 'grand-media') . " (v{$module['update']})</a>";
|
20 |
}
|
21 |
-
if(('upload' == $module['place']) && gm_user_can('module_manage'))
|
22 |
$buttons['delete'] = '<a class="btn btn-danger" href="' . wp_nonce_url($gmCore->get_admin_url(array('delete_module' => $module['module_name']), array(), $gmProcessor->url), 'gmedia_module_delete') . '">' . __('Delete Module', 'grand-media') . '</a>';
|
23 |
}
|
24 |
-
if(!empty($module['download']))
|
25 |
$buttons['download'] = '<a class="btn btn-link" href="' . $module['download'] . '" download="true">' . __('Download module ZIP', 'grand-media') . '</a>';
|
26 |
}
|
27 |
|
28 |
return $buttons;
|
29 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
* Modules functions
|
4 |
*/
|
5 |
|
6 |
+
function gmedia_module_action_buttons($module){
|
7 |
global $gmCore, $gmProcessor;
|
8 |
|
9 |
$buttons = array();
|
10 |
+
if('remote' == $module['place']){
|
11 |
$buttons['install'] = '<a class="btn btn-primary ' . (gm_user_can('module_manage')? 'module_install' : 'disabled') . '" data-module="' . $module['name'] . '" data-loading-text="' . __('Loading...', 'grand-media') . '" href="' . esc_url($module['download']) . '">' . __('Install Module', 'grand-media') . '</a>';
|
12 |
+
} else{
|
13 |
$buttons['create'] = '<a class="btn btn-success" href="' . $gmCore->get_admin_url(array('page' => 'GrandMedia_Galleries', 'gallery_module' => $module['module_name']), array(), true) . '">' . __('Create Gallery', 'grand-media') . '</a>';
|
14 |
}
|
15 |
+
if(!empty($module['demo']) && $module['demo'] != '#'){
|
16 |
$buttons['demo'] = '<a class="btn btn-default" target="_blank" href="' . $module['demo'] . '">' . __('View Demo', 'grand-media') . '</a>';
|
17 |
}
|
18 |
+
if(!empty($module['update']) && 'remote' != $module['place']){
|
19 |
$buttons['update'] = '<a class="btn btn-warning module_install" data-module="' . $module['module_name'] . '" data-loading-text="' . __('Loading...', 'grand-media') . '" href="' . esc_url($module['download']) . '">' . __('Update Module', 'grand-media') . " (v{$module['update']})</a>";
|
20 |
}
|
21 |
+
if(('upload' == $module['place']) && gm_user_can('module_manage')){
|
22 |
$buttons['delete'] = '<a class="btn btn-danger" href="' . wp_nonce_url($gmCore->get_admin_url(array('delete_module' => $module['module_name']), array(), $gmProcessor->url), 'gmedia_module_delete') . '">' . __('Delete Module', 'grand-media') . '</a>';
|
23 |
}
|
24 |
+
if(!empty($module['download'])){
|
25 |
$buttons['download'] = '<a class="btn btn-link" href="' . $module['download'] . '" download="true">' . __('Download module ZIP', 'grand-media') . '</a>';
|
26 |
}
|
27 |
|
28 |
return $buttons;
|
29 |
+
}
|
30 |
+
|
31 |
+
function gmedia_module_preset_more_data(&$item){
|
32 |
+
global $gmCore, $user_ID;
|
33 |
+
|
34 |
+
|
35 |
+
if(!$item || is_wp_error($item)){
|
36 |
+
$item = new stdClass();
|
37 |
+
gmedia_module_preset_more_data($item);
|
38 |
+
|
39 |
+
return;
|
40 |
+
}
|
41 |
+
|
42 |
+
if(empty($item->term_id)){
|
43 |
+
$item->term_id = 0;
|
44 |
+
$item->name = '';
|
45 |
+
$item->taxonomy = 'gmedia_module';
|
46 |
+
$item->description = array();
|
47 |
+
$item->global = $user_ID;
|
48 |
+
$item->status = $gmCore->_get('preset_module', 'phantom');
|
49 |
+
} else{
|
50 |
+
if(($preset_module = $gmCore->_get('preset_module')) && $item->status != $preset_module){
|
51 |
+
$item = new stdClass();
|
52 |
+
gmedia_module_preset_more_data($item);
|
53 |
+
|
54 |
+
return;
|
55 |
+
}
|
56 |
+
|
57 |
+
$item->name = trim(str_replace('[' . $item->status . ']', '', $item->name));
|
58 |
+
}
|
59 |
+
|
60 |
+
$item->module = $gmCore->get_module_path($item->status);
|
61 |
+
|
62 |
+
$module_info = array('type' => '—');
|
63 |
+
if(file_exists($item->module['path'] . '/index.php')){
|
64 |
+
include($item->module['path'] . '/index.php');
|
65 |
+
|
66 |
+
$item->module['info'] = $module_info;
|
67 |
+
} else{
|
68 |
+
$item->module['broken'] = true;
|
69 |
+
}
|
70 |
+
|
71 |
+
$getModulePreset = $gmCore->getModulePreset($item->status);
|
72 |
+
$item->module['name'] = $getModulePreset['module'];
|
73 |
+
$item->module['settings'] = $gmCore->array_replace_recursive($getModulePreset['settings'][ $getModulePreset['module'] ], maybe_unserialize($item->description));
|
74 |
+
|
75 |
+
$item = apply_filters('gmedia_module_preset_more_data', $item);
|
76 |
+
}
|
admin/pages/modules/modules.php
CHANGED
@@ -8,7 +8,7 @@ if(!defined('ABSPATH')) {
|
|
8 |
die('-1');
|
9 |
}
|
10 |
|
11 |
-
global $gmCore, $gmProcessor, $gmGallery;
|
12 |
|
13 |
$gmedia_url = $gmProcessor->url;
|
14 |
$modules = get_gmedia_modules();
|
@@ -63,7 +63,9 @@ if(isset($modules['error'])) {
|
|
63 |
} ?>
|
64 |
</div>
|
65 |
</div>
|
66 |
-
<?php }
|
|
|
|
|
67 |
</div>
|
68 |
|
69 |
<?php if($gmCore->caps['gmedia_module_manage']) {
|
8 |
die('-1');
|
9 |
}
|
10 |
|
11 |
+
global $gmCore, $gmProcessor, $gmGallery, $gmDB;
|
12 |
|
13 |
$gmedia_url = $gmProcessor->url;
|
14 |
$modules = get_gmedia_modules();
|
63 |
} ?>
|
64 |
</div>
|
65 |
</div>
|
66 |
+
<?php }
|
67 |
+
wp_nonce_field('GmediaGallery');
|
68 |
+
?>
|
69 |
</div>
|
70 |
|
71 |
<?php if($gmCore->caps['gmedia_module_manage']) {
|
admin/pages/modules/tpl/modal-modulezip.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Modal to install Module ZIP
|
4 |
*/
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Modal to install Module ZIP
|
9 |
*/
|
admin/pages/modules/tpl/module-item.php
CHANGED
@@ -1,26 +1,96 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Module List Item
|
4 |
*/
|
|
|
|
|
5 |
?>
|
6 |
<div class="media<?php echo $module['mclass']; ?>">
|
7 |
-
<div class="
|
8 |
-
<
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
?>
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
</div>
|
26 |
</div>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Module List Item
|
9 |
*/
|
10 |
+
|
11 |
+
global $gmDB, $gmCore, $user_ID;
|
12 |
?>
|
13 |
<div class="media<?php echo $module['mclass']; ?>">
|
14 |
+
<div class="row">
|
15 |
+
<div class="col-sm-3">
|
16 |
+
<div class="thumbnail">
|
17 |
+
<img class="media-object" src="<?php echo $module['screenshot_url']; ?>" alt="<?php echo esc_attr($module['title']); ?>" width="320" height="240"/>
|
18 |
+
</div>
|
19 |
+
</div>
|
20 |
+
<div class="<?php echo(($module['place'] === 'remote')? 'col-sm-9' : 'col-sm-5'); ?>">
|
21 |
+
<h4 class="media-heading"><?php echo $module['title']; ?></h4>
|
22 |
|
23 |
+
<p class="version"><?php echo __('Version', 'grand-media') . ': ' . $module['version']; ?></p>
|
24 |
+
<?php if(isset($module['info'])){ ?>
|
25 |
+
<div class="module_info"><?php echo str_replace("\n", '<br />', (string)$module['info']); ?></div>
|
26 |
+
<?php } ?>
|
27 |
+
<div class="description"><?php echo str_replace("\n", '<br />', (string)$module['description']); ?></div>
|
28 |
+
<hr/>
|
29 |
+
<p class="buttons">
|
30 |
+
<?php
|
31 |
+
$buttons = gmedia_module_action_buttons($module);
|
32 |
+
echo implode(' ', $buttons);
|
33 |
+
?>
|
34 |
+
</p>
|
35 |
+
</div>
|
36 |
+
<?php
|
37 |
+
if($module['place'] !== 'remote'){
|
38 |
?>
|
39 |
+
<div class="col-sm-4">
|
40 |
+
<div id="module_presets_list" class="module_presets module_presets_<?php echo $module['name'] ?>">
|
41 |
+
<h4 class="media-heading" style="margin-bottom:10px;">
|
42 |
+
<a href="<?php echo $gmCore->get_admin_url(array('page' => 'GrandMedia_Modules', 'preset_module' => $module['name']), array(), admin_url('admin.php')); ?>" class="addpreset pull-right"><span class="label label-success">+</span></a>
|
43 |
+
<?php _e('Presets', 'grand-media'); ?></h4>
|
44 |
+
<?php
|
45 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $module['name']));
|
46 |
+
if(!empty($presets)){
|
47 |
+
?>
|
48 |
+
<ul class="list-group presetlist">
|
49 |
+
<?php
|
50 |
+
$li = array();
|
51 |
+
foreach($presets as $preset){
|
52 |
+
$href = $gmCore->get_admin_url(array('page' => 'GrandMedia_Modules', 'preset' => $preset->term_id), array(), admin_url('admin.php'));
|
53 |
+
|
54 |
+
$count = 1;
|
55 |
+
$name = trim(str_replace('[' . $module['name'] . ']', '', $preset->name, $count));
|
56 |
+
$by = '';
|
57 |
+
$global_preset = false;
|
58 |
+
if(!$name){
|
59 |
+
if((int)$preset->global){
|
60 |
+
$name = __('Default Settings', 'grand-media');
|
61 |
+
} else{
|
62 |
+
$name = __('Global Settings', 'grand-media');
|
63 |
+
$global_preset = true;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
if((int)$preset->global){
|
67 |
+
$by = ' <small style="white-space:nowrap">[' . get_the_author_meta('display_name', $preset->global) . ']</small>';
|
68 |
+
}
|
69 |
+
$li_item = '
|
70 |
+
<li class="list-group-item" id="gm-preset-' . $preset->term_id . '">
|
71 |
+
<span class="gm-preset-id">ID: ' . $preset->term_id . '</span>';
|
72 |
+
if($user_ID == $preset->global || $gmCore->caps['gmedia_edit_others_media']){
|
73 |
+
$li_item .= '<span class="delpreset"><span class="label label-danger" data-id="' . $preset->term_id . '">×</span></span>';
|
74 |
+
}
|
75 |
+
$li_item .= '
|
76 |
+
<a href="' . $href . '">' . $name . $by . '</a>
|
77 |
+
</li>';
|
78 |
+
if($global_preset){
|
79 |
+
if(current_user_can('manage_options')){
|
80 |
+
array_unshift($li, $li_item);
|
81 |
+
}
|
82 |
+
} else{
|
83 |
+
$li[] = $li_item;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
echo implode('', $li);
|
87 |
+
?>
|
88 |
+
</ul>
|
89 |
+
<?php } ?>
|
90 |
+
</div>
|
91 |
+
</div>
|
92 |
+
<?php
|
93 |
+
}
|
94 |
+
?>
|
95 |
</div>
|
96 |
</div>
|
admin/pages/modules/tpl/module-preset-edit-item.php
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Edit Gallery Form
|
9 |
+
*/
|
10 |
+
global $user_ID;
|
11 |
+
?>
|
12 |
+
|
13 |
+
<form method="post" id="gmedia-edit-term" name="gmEditTerm" data-id="<?php echo $term_id; ?>" action="<?php echo $gmedia_url; ?>">
|
14 |
+
<div class="panel-body">
|
15 |
+
<h4 style="margin-top:0;">
|
16 |
+
<?php if($term_id){
|
17 |
+
$is_preset = 'edit';
|
18 |
+
?>
|
19 |
+
<span class="pull-right"><?php echo __('ID', 'grand-media') . ": {$term->term_id}"; ?></span>
|
20 |
+
<?php printf(__('Edit %s Preset', 'grand-media'), $term->module['info']['title']); ?>: <em><?php echo esc_html($term->name); ?></em>
|
21 |
+
<?php } else{
|
22 |
+
$is_preset = 'new';
|
23 |
+
printf(__('New %s Preset', 'grand-media'), $term->module['info']['title']);
|
24 |
+
} ?>
|
25 |
+
</h4>
|
26 |
+
<div class="row">
|
27 |
+
<div class="col-sm-5">
|
28 |
+
<div class="form-group">
|
29 |
+
<label><?php _e('Name', 'grand-media'); ?></label>
|
30 |
+
<?php if($term_id && !$term->name){
|
31 |
+
if((int)$term->global){
|
32 |
+
$is_preset = 'default';
|
33 |
+
} else{
|
34 |
+
$is_preset = 'global';
|
35 |
+
}
|
36 |
+
?>
|
37 |
+
<input type="text" class="form-control input-sm" name="term[name]" value="<?php $is_preset === 'global'? _e('Global Settings', 'grand-media') : _e('Default Settings', 'grand-media'); ?>" readonly/>
|
38 |
+
<input type="hidden" name="module_preset_save_default" value="1"/>
|
39 |
+
<?php } else{ ?>
|
40 |
+
<input type="text" class="form-control input-sm" name="term[name]" value="<?php echo esc_attr($term->name); ?>" placeholder="<?php echo $term->name? esc_attr($term->name) : __('Preset Name', 'grand-media'); ?>"/>
|
41 |
+
<?php } ?>
|
42 |
+
</div>
|
43 |
+
<div class="form-group">
|
44 |
+
<label><?php _e('Author', 'grand-media'); ?></label>
|
45 |
+
<?php
|
46 |
+
if($is_preset === 'global'){
|
47 |
+
echo '<input type="hidden" name="term[global]" value="0"/>';
|
48 |
+
echo '<div>' . __('Global Preset', 'grand-media') . '</div>';
|
49 |
+
} else{
|
50 |
+
$_args = array('show_option_all' => '');
|
51 |
+
if(!(int)$term->global){
|
52 |
+
$_args['selected'] = $user_ID;
|
53 |
+
}
|
54 |
+
gmedia_term_choose_author_field($term->global, $_args);
|
55 |
+
} ?>
|
56 |
+
</div>
|
57 |
+
<input type="hidden" name="term[term_id]" value="<?php echo $term_id; ?>"/>
|
58 |
+
<input type="hidden" name="term[module]" value="<?php echo esc_attr($term->module['name']); ?>"/>
|
59 |
+
<input type="hidden" name="term[taxonomy]" value="<?php echo $gmedia_term_taxonomy; ?>"/>
|
60 |
+
<?php
|
61 |
+
wp_nonce_field('GmediaGallery');
|
62 |
+
wp_referer_field();
|
63 |
+
?>
|
64 |
+
<div class="pull-right" id="save_buttons">
|
65 |
+
<?php if($is_preset !== 'global'){ ?>
|
66 |
+
<button type="submit" name="module_preset_save_global" class="btn btn-default btn-sm"><?php _e('Save as Global Preset', 'grand-media'); ?></button>
|
67 |
+
<?php if($is_preset !== 'default'){ ?>
|
68 |
+
<button type="submit" name="module_preset_save_default" class="btn btn-default btn-sm"><?php _e('Save as Default User Preset', 'grand-media'); ?></button>
|
69 |
+
<?php
|
70 |
+
}
|
71 |
+
}
|
72 |
+
$submit_name = 'module_preset_save';
|
73 |
+
if($is_preset === 'default'){
|
74 |
+
$submit_name = 'module_preset_save_default';
|
75 |
+
}
|
76 |
+
if($is_preset === 'global'){
|
77 |
+
$submit_name = 'module_preset_save_global';
|
78 |
+
}
|
79 |
+
?>
|
80 |
+
<button type="submit" name="<?php echo $submit_name; ?>" class="btn btn-primary btn-sm"><?php _e('Save', 'grand-media'); ?></button>
|
81 |
+
</div>
|
82 |
+
</div>
|
83 |
+
|
84 |
+
<div class="col-sm-5 col-sm-offset-2">
|
85 |
+
<div class="form-group">
|
86 |
+
<div class="pull-right"><a id="build_query" class="label label-primary buildquery-modal" href="#buildQuery" style="font-size:90%;"><?php _e('Build Query', 'grand-media'); ?></a></div>
|
87 |
+
<label><?php _e('Query Args. for Preset Demo', 'grand-media'); ?></label>
|
88 |
+
<textarea class="form-control input-sm" id="build_query_field" style="height:64px;" rows="2" name="term[query]"><?php echo(empty($gmedia_filter['query_args'])? 'limit=20' : urldecode(build_query($gmedia_filter['query_args']))); ?></textarea>
|
89 |
+
</div>
|
90 |
+
</div>
|
91 |
+
</div>
|
92 |
+
|
93 |
+
<hr/>
|
94 |
+
<?php
|
95 |
+
include(GMEDIA_ABSPATH . 'admin/pages/galleries/tpl/module-settings.php');
|
96 |
+
?>
|
97 |
+
|
98 |
+
</div>
|
99 |
+
|
100 |
+
</form>
|
101 |
+
|
102 |
+
<?php
|
103 |
+
include(GMEDIA_ABSPATH . 'admin/pages/galleries/tpl/modal-build-query.php');
|
104 |
+
?>
|
admin/pages/modules/tpl/module-preset-panel-heading.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Panel heading for term
|
9 |
+
* @var $gmCore
|
10 |
+
* @var $term_id
|
11 |
+
* @var $term
|
12 |
+
*/
|
13 |
+
?>
|
14 |
+
<div class="panel-heading-fake"></div>
|
15 |
+
<div class="panel-heading clearfix">
|
16 |
+
<div class="btn-toolbar pull-left">
|
17 |
+
<a class="btn btn-default pull-left" style="margin-right:20px;" href="<?php echo remove_query_arg(array('preset_module', 'preset'), wp_get_referer()); ?>"><?php _e('Go Back', 'grand-media'); ?></a>
|
18 |
+
|
19 |
+
<?php if($term_id){ ?>
|
20 |
+
<div class="btn-group">
|
21 |
+
<a class="btn btn-default" href="#"><?php _e('Action', 'grand-media'); ?></a>
|
22 |
+
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
|
23 |
+
<span class="caret"></span>
|
24 |
+
<span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?></span>
|
25 |
+
</button>
|
26 |
+
<ul class="dropdown-menu" role="menu">
|
27 |
+
<li><a href="<?php echo add_query_arg(array('page' => 'GrandMedia_Galleries', 'gallery_module' => $term->module['name'], 'preset' => $term->term_id), admin_url('admin.php')); ?>"><?php _e('Create Gallery with this preset', 'grand-media'); ?></a></li>
|
28 |
+
</ul>
|
29 |
+
</div>
|
30 |
+
|
31 |
+
<a class="btn btn-info pull-left" style="margin-left:20px;" href="<?php echo $gmCore->get_admin_url(array('preset_module' => $term->module['name']), array('preset')); ?>"><?php printf(__('New %s Preset', 'grand-media'), $term->module['info']['title']); ?></a>
|
32 |
+
<?php } ?>
|
33 |
+
</div>
|
34 |
+
<div class="spinner"></div>
|
35 |
+
</div>
|
admin/pages/settings/settings.php
CHANGED
@@ -11,7 +11,8 @@ if(!defined('ABSPATH')) {
|
|
11 |
|
12 |
global $user_ID, $gmDB, $gmCore, $gmGallery, $gmProcessor;
|
13 |
|
14 |
-
$url =
|
|
|
15 |
$lk = isset($gmGallery->options['license_key'])? $gmGallery->options['license_key'] : '';
|
16 |
?>
|
17 |
|
11 |
|
12 |
global $user_ID, $gmDB, $gmCore, $gmGallery, $gmProcessor;
|
13 |
|
14 |
+
$url = $gmProcessor->url;
|
15 |
+
$pk = isset($gmGallery->options['purchase_key'])? $gmGallery->options['purchase_key'] : '';
|
16 |
$lk = isset($gmGallery->options['license_key'])? $gmGallery->options['license_key'] : '';
|
17 |
?>
|
18 |
|
admin/pages/settings/tpl/common.php
CHANGED
@@ -1,8 +1,13 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Common Settings
|
4 |
-
*
|
5 |
* @var $gmGallery
|
|
|
6 |
*/
|
7 |
?>
|
8 |
<fieldset id="gmedia_settings_other" class="tab-pane">
|
@@ -93,8 +98,29 @@
|
|
93 |
<label><?php _e('Choose default module', 'grand-media') ?>:</label>
|
94 |
<select class="form-control input-sm" name="set[default_gmedia_module]">
|
95 |
<?php foreach($gmedia_modules['in'] as $mfold => $module){
|
|
|
|
|
96 |
$selected = selected($gmGallery->options['default_gmedia_module'], esc_attr($mfold), false);
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
} ?>
|
99 |
</select>
|
100 |
|
@@ -129,11 +155,10 @@
|
|
129 |
</div>
|
130 |
</div>
|
131 |
<?php
|
132 |
-
$allowed_post_types = (array)
|
133 |
-
$args = array(
|
134 |
-
|
135 |
-
|
136 |
-
'_builtin' => false
|
137 |
);
|
138 |
$output = 'objects'; // names or objects, note names is the default
|
139 |
$operator = 'and'; // 'and' or 'or'
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Common Settings
|
|
|
9 |
* @var $gmGallery
|
10 |
+
* @var $gmDB
|
11 |
*/
|
12 |
?>
|
13 |
<fieldset id="gmedia_settings_other" class="tab-pane">
|
98 |
<label><?php _e('Choose default module', 'grand-media') ?>:</label>
|
99 |
<select class="form-control input-sm" name="set[default_gmedia_module]">
|
100 |
<?php foreach($gmedia_modules['in'] as $mfold => $module){
|
101 |
+
echo '<optgroup label="' . esc_attr($module['title']) . '">';
|
102 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
|
103 |
$selected = selected($gmGallery->options['default_gmedia_module'], esc_attr($mfold), false);
|
104 |
+
$option = array();
|
105 |
+
$option[] = '<option ' . $selected . ' value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
|
106 |
+
foreach($presets as $preset){
|
107 |
+
if(!(int)$preset->global && '[' . $mfold . ']' === $preset->name){
|
108 |
+
continue;
|
109 |
+
}
|
110 |
+
$selected = selected($gmGallery->options['default_gmedia_module'], $preset->term_id, false);
|
111 |
+
$by_author = '';
|
112 |
+
if((int)$preset->global){
|
113 |
+
$by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
|
114 |
+
}
|
115 |
+
if('[' . $mfold . ']' === $preset->name){
|
116 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
|
117 |
+
} else{
|
118 |
+
$preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
|
119 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
|
120 |
+
}
|
121 |
+
}
|
122 |
+
echo implode('', $option);
|
123 |
+
echo '</optgroup>';
|
124 |
} ?>
|
125 |
</select>
|
126 |
|
155 |
</div>
|
156 |
</div>
|
157 |
<?php
|
158 |
+
$allowed_post_types = (array)$gmGallery->options['gmedia_post_types_support'];
|
159 |
+
$args = array('public' => true,
|
160 |
+
'show_ui' => true,
|
161 |
+
'_builtin' => false
|
|
|
162 |
);
|
163 |
$output = 'objects'; // names or objects, note names is the default
|
164 |
$operator = 'and'; // 'and' or 'or'
|
admin/pages/settings/tpl/license.php
CHANGED
@@ -1,26 +1,33 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* License Key
|
4 |
*/
|
5 |
?>
|
6 |
<fieldset id="gmedia_premium" class="tab-pane active">
|
7 |
-
<p><?php _e('Enter
|
8 |
|
9 |
<div class="row">
|
10 |
<div class="form-group col-xs-5">
|
11 |
-
<label><?php _e('
|
12 |
echo '<em>' . $gmGallery->options['license_name'] . '</em>';
|
13 |
} ?></label>
|
14 |
-
<input type="text" name="set[
|
15 |
|
16 |
-
<div class="manual_license_activate"<?php echo(('manual' == $gmCore->_get('license_activate'))
|
17 |
<label style="margin-top:7px;"><?php _e('License Name', 'grand-media') ?>:</label>
|
18 |
<input type="text" name="set[license_name]" id="license_name" class="form-control input-sm" value="<?php echo $gmGallery->options['license_name']; ?>"/>
|
|
|
|
|
19 |
<label style="margin-top:7px;"><?php _e('Additional Key', 'grand-media') ?>:</label>
|
20 |
<input type="text" name="set[license_key2]" id="license_key2" class="form-control input-sm" value="<?php echo $gmGallery->options['license_key2']; ?>"/>
|
21 |
</div>
|
22 |
</div>
|
23 |
-
<?php if
|
24 |
<div class="form-group col-xs-7">
|
25 |
<label> </label>
|
26 |
<button style="display:block;" class="btn btn-success btn-sm" type="submit" name="license-key-activate"><?php _e('Activate Key', 'grand-media'); ?></button>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* License Key
|
9 |
*/
|
10 |
?>
|
11 |
<fieldset id="gmedia_premium" class="tab-pane active">
|
12 |
+
<p><?php _e('Enter Gmedia Premium Key to remove backlink label from premium gallery modules.') ?></p>
|
13 |
|
14 |
<div class="row">
|
15 |
<div class="form-group col-xs-5">
|
16 |
+
<label><?php _e('Gmedia Premium Key', 'grand-media') ?>: <?php if(isset($gmGallery->options['license_name'])){
|
17 |
echo '<em>' . $gmGallery->options['license_name'] . '</em>';
|
18 |
} ?></label>
|
19 |
+
<input type="text" name="set[purchase_key]" id="purchase_key" class="form-control input-sm" value="<?php echo $pk; ?>"/>
|
20 |
|
21 |
+
<div class="manual_license_activate"<?php echo(('manual' == $gmCore->_get('license_activate'))? '' : ' style="display:none;"'); ?>>
|
22 |
<label style="margin-top:7px;"><?php _e('License Name', 'grand-media') ?>:</label>
|
23 |
<input type="text" name="set[license_name]" id="license_name" class="form-control input-sm" value="<?php echo $gmGallery->options['license_name']; ?>"/>
|
24 |
+
<label style="margin-top:7px;"><?php _e('License Key', 'grand-media') ?>:</label>
|
25 |
+
<input type="text" name="set[license_key]" id="license_key" class="form-control input-sm" value="<?php echo $lk; ?>"/>
|
26 |
<label style="margin-top:7px;"><?php _e('Additional Key', 'grand-media') ?>:</label>
|
27 |
<input type="text" name="set[license_key2]" id="license_key2" class="form-control input-sm" value="<?php echo $gmGallery->options['license_key2']; ?>"/>
|
28 |
</div>
|
29 |
</div>
|
30 |
+
<?php if(!('manual' == $gmCore->_get('license_activate') || !empty($pk))){ ?>
|
31 |
<div class="form-group col-xs-7">
|
32 |
<label> </label>
|
33 |
<button style="display:block;" class="btn btn-success btn-sm" type="submit" name="license-key-activate"><?php _e('Activate Key', 'grand-media'); ?></button>
|
admin/pages/settings/tpl/permalinks.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Permalinks and GmediaCloud page settings
|
4 |
*
|
@@ -16,6 +21,12 @@
|
|
16 |
|
17 |
<p class="help-block"><?php _e('Base for gmedia post url.', 'grand-media'); ?></p>
|
18 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
<div class="form-group">
|
20 |
<div class="checkbox" style="margin:0;">
|
21 |
<input type="hidden" name="set[gmedia_exclude_from_search]" value="0"/>
|
@@ -40,6 +51,12 @@
|
|
40 |
|
41 |
<p class="help-block"><?php _e('Base for gmedia album post url.', 'grand-media'); ?></p>
|
42 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
<div class="form-group">
|
44 |
<div class="checkbox" style="margin:0;">
|
45 |
<input type="hidden" name="set[gmedia_album_exclude_from_search]" value="0"/>
|
@@ -55,6 +72,12 @@
|
|
55 |
|
56 |
<p class="help-block"><?php _e('Base for gmedia gallery post url.', 'grand-media'); ?></p>
|
57 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
<div class="form-group">
|
59 |
<div class="checkbox" style="margin:0;">
|
60 |
<input type="hidden" name="set[gmedia_gallery_exclude_from_search]" value="0"/>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Permalinks and GmediaCloud page settings
|
9 |
*
|
21 |
|
22 |
<p class="help-block"><?php _e('Base for gmedia post url.', 'grand-media'); ?></p>
|
23 |
</div>
|
24 |
+
<div class="form-group">
|
25 |
+
<div class="checkbox" style="margin:0;">
|
26 |
+
<input type="hidden" name="set[gmedia_has_archive]" value="0"/>
|
27 |
+
<label><input type="checkbox" name="set[gmedia_has_archive]" value="1" <?php checked($gmGallery->options['gmedia_has_archive'], '1'); ?> /> <?php _e('Allow Gmedia Posts Archive page', 'grand-media'); ?> </label>
|
28 |
+
</div>
|
29 |
+
</div>
|
30 |
<div class="form-group">
|
31 |
<div class="checkbox" style="margin:0;">
|
32 |
<input type="hidden" name="set[gmedia_exclude_from_search]" value="0"/>
|
51 |
|
52 |
<p class="help-block"><?php _e('Base for gmedia album post url.', 'grand-media'); ?></p>
|
53 |
</div>
|
54 |
+
<div class="form-group">
|
55 |
+
<div class="checkbox" style="margin:0;">
|
56 |
+
<input type="hidden" name="set[gmedia_album_has_archive]" value="0"/>
|
57 |
+
<label><input type="checkbox" name="set[gmedia_album_has_archive]" value="1" <?php checked($gmGallery->options['gmedia_album_has_archive'], '1'); ?> /> <?php _e('Allow Gmedia Albums Archive page', 'grand-media'); ?> </label>
|
58 |
+
</div>
|
59 |
+
</div>
|
60 |
<div class="form-group">
|
61 |
<div class="checkbox" style="margin:0;">
|
62 |
<input type="hidden" name="set[gmedia_album_exclude_from_search]" value="0"/>
|
72 |
|
73 |
<p class="help-block"><?php _e('Base for gmedia gallery post url.', 'grand-media'); ?></p>
|
74 |
</div>
|
75 |
+
<div class="form-group">
|
76 |
+
<div class="checkbox" style="margin:0;">
|
77 |
+
<input type="hidden" name="set[gmedia_gallery_has_archive]" value="0"/>
|
78 |
+
<label><input type="checkbox" name="set[gmedia_gallery_has_archive]" value="1" <?php checked($gmGallery->options['gmedia_gallery_has_archive'], '1'); ?> /> <?php _e('Allow Gmedia Galleries Archive page', 'grand-media'); ?> </label>
|
79 |
+
</div>
|
80 |
+
</div>
|
81 |
<div class="form-group">
|
82 |
<div class="checkbox" style="margin:0;">
|
83 |
<input type="hidden" name="set[gmedia_gallery_exclude_from_search]" value="0"/>
|
admin/pages/settings/tpl/roles.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Capabilities Manager
|
4 |
*
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Capabilities Manager
|
9 |
*
|
admin/pages/settings/tpl/system.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* System info (under constraction)
|
4 |
*/
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* System info (under constraction)
|
9 |
*/
|
admin/pages/terms/functions.php
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
function gmedia_term_item_thumbnails($term_item, $qty = 7) {
|
4 |
global $gmCore, $gmDB, $gmGallery;
|
5 |
?>
|
6 |
<div class="term-images">
|
7 |
<?php
|
8 |
-
if($term_item->count) {
|
9 |
-
$term__in = str_replace('gmedia_', '', $term_item->taxonomy) . '__in';
|
10 |
-
switch($term_item->taxonomy) {
|
11 |
case 'gmedia_tag':
|
12 |
$orderby = $gmGallery->options['in_tag_orderby'];
|
13 |
$order = $gmGallery->options['in_tag_order'];
|
@@ -24,21 +24,21 @@ function gmedia_term_item_thumbnails($term_item, $qty = 7) {
|
|
24 |
$args = array(
|
25 |
'no_found_rows' => true,
|
26 |
'per_page' => $qty,
|
27 |
-
$term__in => array($term_item->term_id),
|
28 |
-
'author' => gm_user_can('show_others_media')? 0 : get_current_user_id(),
|
29 |
-
'orderby' => isset($term_item->meta['_orderby'][0])? $term_item->meta['_orderby'][0] : $orderby,
|
30 |
-
'order' => isset($term_item->meta['_order'][0])? $term_item->meta['_order'][0] : $order
|
31 |
);
|
32 |
|
33 |
-
$gmedias = $gmDB->get_gmedias($args);
|
34 |
-
if(!empty($gmedias)) {
|
35 |
-
foreach($gmedias as $gmedia_item) {
|
36 |
?>
|
37 |
-
<img style="z-index:<?php echo $qty--; ?>;" src="<?php echo $gmCore->gm_get_media_image($gmedia_item, 'thumb', false); ?>" alt="<?php echo $gmedia_item->ID; ?>" title="<?php echo esc_attr($gmedia_item->title); ?>"/>
|
38 |
<?php
|
39 |
}
|
40 |
}
|
41 |
-
if(count($gmedias) < $term_item->count) {
|
42 |
echo '...';
|
43 |
}
|
44 |
}
|
@@ -47,48 +47,50 @@ function gmedia_term_item_thumbnails($term_item, $qty = 7) {
|
|
47 |
<?php
|
48 |
}
|
49 |
|
50 |
-
function gmedia_term_item_actions($item) {
|
51 |
global $gmCore, $gmProcessor;
|
52 |
|
53 |
-
$taxterm = str_replace('gmedia_', '', $item->taxonomy);
|
54 |
$actions = array();
|
55 |
|
56 |
-
$
|
|
|
|
|
57 |
$filter_class = 'gm_filter_in_lib';
|
58 |
$count = '';
|
59 |
-
if(in_array($item->taxonomy, array('gmedia_album', 'gmedia_tag', 'gmedia_category'))) {
|
60 |
$count = '<span class="gm_term_count">' . $item->count . '</span>';
|
61 |
-
if(
|
62 |
$filter_class .= ' action-inactive';
|
63 |
}
|
64 |
}
|
65 |
-
$actions['filter'] = '<a title="' . __('Filter in Gmedia Library', 'grand-media') . '" href="' . $filter_href . '" class="' . $filter_class . '">' . $count . '<span class="glyphicon glyphicon-filter"></span></a>';
|
66 |
|
67 |
-
$cloud_link = $gmCore->gmcloudlink($item->term_id, $taxterm);
|
68 |
-
if(!empty($item->meta['_post_ID'][0])){
|
69 |
-
$post_link = get_permalink($item->meta['_post_ID'][0]);
|
70 |
} else {
|
71 |
$post_link = '';
|
72 |
}
|
73 |
$share_icon = '<span class="glyphicon glyphicon-share"></span>';
|
74 |
-
if('draft' !== $item->status) {
|
75 |
-
$actions['share'] = '<a target="_blank" data-target="#shareModal" data-share="' . $item->term_id . '" class="share-modal" title="' . __('Share', 'grand-media') . '" data-gmediacloud="' . $cloud_link . '" href="' . $post_link . '">' . $share_icon . '</a>';
|
76 |
} else {
|
77 |
$actions['share'] = "<span class='action-inactive'>$share_icon</span>";
|
78 |
}
|
79 |
|
80 |
-
if('gmedia_tag' != $item->taxonomy) {
|
81 |
$edit_icon = '<span class="glyphicon glyphicon-edit"></span>';
|
82 |
-
if($item->allow_edit) {
|
83 |
-
$actions['edit'] = '<a title="' . __('Edit', 'grand-media') . '" href="' . add_query_arg(array("edit_item" => $item->term_id), $gmProcessor->url) . '">' . $edit_icon . '</a>';
|
84 |
} else {
|
85 |
$actions['edit'] = "<span class='action-inactive'>$edit_icon</span>";
|
86 |
}
|
87 |
}
|
88 |
|
89 |
$trash_icon = '<span class="glyphicon glyphicon-trash"></span>';
|
90 |
-
if($item->allow_delete) {
|
91 |
-
$actions['delete'] = '<a class="trash-icon" title="' . __('Delete', 'grand-media') . '" href="' . wp_nonce_url(add_query_arg(array('delete' => $item->term_id), $gmProcessor->url), 'gmedia_delete') . '" data-confirm="' . __("You are about to permanently delete the selected items.\n\r'Cancel' to stop, 'OK' to delete.", "grand-media") . '">' . $trash_icon . '</a>';
|
92 |
} else {
|
93 |
$actions['delete'] = "<span class='action-inactive'>$trash_icon</span>";
|
94 |
}
|
@@ -104,67 +106,67 @@ function gmedia_term_item_actions($item) {
|
|
104 |
}*/
|
105 |
|
106 |
|
107 |
-
return apply_filters('gmedia_term_item_actions', $actions);
|
108 |
}
|
109 |
|
110 |
|
111 |
-
function gmedia_term_item_more_data(&$item) {
|
112 |
global $gmDB;
|
113 |
|
114 |
-
$meta = $gmDB->get_metadata('gmedia_term', $item->term_id);
|
115 |
$item->meta = $meta;
|
116 |
|
117 |
-
if($item->global) {
|
118 |
-
$item->author_name = get_the_author_meta('display_name', $item->global);
|
119 |
} else {
|
120 |
$item->author_name = false;
|
121 |
}
|
122 |
|
123 |
-
if('gmedia_album' == $item->taxonomy) {
|
124 |
-
$post_id
|
125 |
$item->post_id = $post_id;
|
126 |
-
if($post_id){
|
127 |
-
$post_item = get_post($post_id);
|
128 |
-
if($post_item) {
|
129 |
-
$item->slug
|
130 |
-
$item->post_password
|
131 |
-
$item->comment_count
|
132 |
$item->comment_status = $post_item->comment_status;
|
133 |
}
|
134 |
}
|
135 |
}
|
136 |
|
137 |
|
138 |
-
$item = apply_filters('gmedia_term_item_more_data', $item);
|
139 |
}
|
140 |
|
141 |
function gmedia_terms_create_album_tpl() {
|
142 |
-
include(dirname(__FILE__) . '/tpl/album-create-item.php');
|
143 |
}
|
144 |
|
145 |
function gmedia_terms_create_category_tpl() {
|
146 |
-
include(dirname(__FILE__) . '/tpl/category-create-item.php');
|
147 |
}
|
148 |
|
149 |
function gmedia_terms_create_tag_tpl() {
|
150 |
-
include(dirname(__FILE__) . '/tpl/tag-create-item.php');
|
151 |
}
|
152 |
|
153 |
function gmedia_terms_create_alert_tpl() {
|
154 |
-
include(dirname(__FILE__) . '/tpl/terms-create-alert.php');
|
155 |
}
|
156 |
|
157 |
-
add_action('gmedia_term_album_after_panel', 'gmedia_term_album_after_panel');
|
158 |
-
function gmedia_term_album_after_panel($term){
|
159 |
-
include(dirname(__FILE__) . '/tpl/album-sort-gmedia.php');
|
160 |
}
|
161 |
|
162 |
-
add_action('gmedia_term_category_after_panel', 'gmedia_term_category_after_panel');
|
163 |
-
function gmedia_term_category_after_panel($term){
|
164 |
-
include(dirname(__FILE__) . '/tpl/category-preview-gmedia.php');
|
165 |
}
|
166 |
|
167 |
-
add_action('gmedia_term_filter_after_panel', 'gmedia_term_filter_after_panel');
|
168 |
-
function gmedia_term_filter_after_panel($term){
|
169 |
-
include(dirname(__FILE__) . '/tpl/filter-preview-query.php');
|
170 |
}
|
1 |
<?php
|
2 |
|
3 |
+
function gmedia_term_item_thumbnails( $term_item, $qty = 7 ) {
|
4 |
global $gmCore, $gmDB, $gmGallery;
|
5 |
?>
|
6 |
<div class="term-images">
|
7 |
<?php
|
8 |
+
if ( $term_item->count ) {
|
9 |
+
$term__in = str_replace( 'gmedia_', '', $term_item->taxonomy ) . '__in';
|
10 |
+
switch ( $term_item->taxonomy ) {
|
11 |
case 'gmedia_tag':
|
12 |
$orderby = $gmGallery->options['in_tag_orderby'];
|
13 |
$order = $gmGallery->options['in_tag_order'];
|
24 |
$args = array(
|
25 |
'no_found_rows' => true,
|
26 |
'per_page' => $qty,
|
27 |
+
$term__in => array( $term_item->term_id ),
|
28 |
+
'author' => gm_user_can( 'show_others_media' ) ? 0 : get_current_user_id(),
|
29 |
+
'orderby' => isset( $term_item->meta['_orderby'][0] ) ? $term_item->meta['_orderby'][0] : $orderby,
|
30 |
+
'order' => isset( $term_item->meta['_order'][0] ) ? $term_item->meta['_order'][0] : $order
|
31 |
);
|
32 |
|
33 |
+
$gmedias = $gmDB->get_gmedias( $args );
|
34 |
+
if ( ! empty( $gmedias ) ) {
|
35 |
+
foreach ( $gmedias as $gmedia_item ) {
|
36 |
?>
|
37 |
+
<img style="z-index:<?php echo $qty --; ?>;" src="<?php echo $gmCore->gm_get_media_image( $gmedia_item, 'thumb', false ); ?>" alt="<?php echo $gmedia_item->ID; ?>" title="<?php echo esc_attr( $gmedia_item->title ); ?>"/>
|
38 |
<?php
|
39 |
}
|
40 |
}
|
41 |
+
if ( count( $gmedias ) < $term_item->count ) {
|
42 |
echo '...';
|
43 |
}
|
44 |
}
|
47 |
<?php
|
48 |
}
|
49 |
|
50 |
+
function gmedia_term_item_actions( $item ) {
|
51 |
global $gmCore, $gmProcessor;
|
52 |
|
53 |
+
$taxterm = str_replace( 'gmedia_', '', $item->taxonomy );
|
54 |
$actions = array();
|
55 |
|
56 |
+
$actions['shortcode'] = '<div class="term-shortcode"><input type="text" readonly value="[gm ' . $taxterm . '=' . $item->term_id . ']"><div class="input-buffer"></div></div>';
|
57 |
+
|
58 |
+
$filter_href = $gmCore->get_admin_url( array( 'page' => 'GrandMedia', "{$taxterm}__in" => $item->term_id ), array(), true );
|
59 |
$filter_class = 'gm_filter_in_lib';
|
60 |
$count = '';
|
61 |
+
if ( in_array( $item->taxonomy, array( 'gmedia_album', 'gmedia_tag', 'gmedia_category' ) ) ) {
|
62 |
$count = '<span class="gm_term_count">' . $item->count . '</span>';
|
63 |
+
if ( ! $item->count ) {
|
64 |
$filter_class .= ' action-inactive';
|
65 |
}
|
66 |
}
|
67 |
+
$actions['filter'] = '<a title="' . __( 'Filter in Gmedia Library', 'grand-media' ) . '" href="' . $filter_href . '" class="' . $filter_class . '">' . $count . '<span class="glyphicon glyphicon-filter"></span></a>';
|
68 |
|
69 |
+
$cloud_link = $gmCore->gmcloudlink( $item->term_id, $taxterm );
|
70 |
+
if ( ! empty( $item->meta['_post_ID'][0] ) ) {
|
71 |
+
$post_link = get_permalink( $item->meta['_post_ID'][0] );
|
72 |
} else {
|
73 |
$post_link = '';
|
74 |
}
|
75 |
$share_icon = '<span class="glyphicon glyphicon-share"></span>';
|
76 |
+
if ( 'draft' !== $item->status ) {
|
77 |
+
$actions['share'] = '<a target="_blank" data-target="#shareModal" data-share="' . $item->term_id . '" class="share-modal" title="' . __( 'Share', 'grand-media' ) . '" data-gmediacloud="' . $cloud_link . '" href="' . $post_link . '">' . $share_icon . '</a>';
|
78 |
} else {
|
79 |
$actions['share'] = "<span class='action-inactive'>$share_icon</span>";
|
80 |
}
|
81 |
|
82 |
+
if ( 'gmedia_tag' != $item->taxonomy ) {
|
83 |
$edit_icon = '<span class="glyphicon glyphicon-edit"></span>';
|
84 |
+
if ( $item->allow_edit ) {
|
85 |
+
$actions['edit'] = '<a title="' . __( 'Edit', 'grand-media' ) . '" href="' . add_query_arg( array( "edit_item" => $item->term_id ), $gmProcessor->url ) . '">' . $edit_icon . '</a>';
|
86 |
} else {
|
87 |
$actions['edit'] = "<span class='action-inactive'>$edit_icon</span>";
|
88 |
}
|
89 |
}
|
90 |
|
91 |
$trash_icon = '<span class="glyphicon glyphicon-trash"></span>';
|
92 |
+
if ( $item->allow_delete ) {
|
93 |
+
$actions['delete'] = '<a class="trash-icon" title="' . __( 'Delete', 'grand-media' ) . '" href="' . wp_nonce_url( add_query_arg( array( 'delete' => $item->term_id ), $gmProcessor->url ), 'gmedia_delete' ) . '" data-confirm="' . __( "You are about to permanently delete the selected items.\n\r'Cancel' to stop, 'OK' to delete.", "grand-media" ) . '">' . $trash_icon . '</a>';
|
94 |
} else {
|
95 |
$actions['delete'] = "<span class='action-inactive'>$trash_icon</span>";
|
96 |
}
|
106 |
}*/
|
107 |
|
108 |
|
109 |
+
return apply_filters( 'gmedia_term_item_actions', $actions );
|
110 |
}
|
111 |
|
112 |
|
113 |
+
function gmedia_term_item_more_data( &$item ) {
|
114 |
global $gmDB;
|
115 |
|
116 |
+
$meta = $gmDB->get_metadata( 'gmedia_term', $item->term_id );
|
117 |
$item->meta = $meta;
|
118 |
|
119 |
+
if ( $item->global ) {
|
120 |
+
$item->author_name = get_the_author_meta( 'display_name', $item->global );
|
121 |
} else {
|
122 |
$item->author_name = false;
|
123 |
}
|
124 |
|
125 |
+
if ( 'gmedia_album' == $item->taxonomy ) {
|
126 |
+
$post_id = isset( $meta['_post_ID'][0] ) ? (int) $meta['_post_ID'][0] : 0;
|
127 |
$item->post_id = $post_id;
|
128 |
+
if ( $post_id ) {
|
129 |
+
$post_item = get_post( $post_id );
|
130 |
+
if ( $post_item ) {
|
131 |
+
$item->slug = $post_item->post_name;
|
132 |
+
$item->post_password = $post_item->post_password;
|
133 |
+
$item->comment_count = $post_item->comment_count;
|
134 |
$item->comment_status = $post_item->comment_status;
|
135 |
}
|
136 |
}
|
137 |
}
|
138 |
|
139 |
|
140 |
+
$item = apply_filters( 'gmedia_term_item_more_data', $item );
|
141 |
}
|
142 |
|
143 |
function gmedia_terms_create_album_tpl() {
|
144 |
+
include( dirname( __FILE__ ) . '/tpl/album-create-item.php' );
|
145 |
}
|
146 |
|
147 |
function gmedia_terms_create_category_tpl() {
|
148 |
+
include( dirname( __FILE__ ) . '/tpl/category-create-item.php' );
|
149 |
}
|
150 |
|
151 |
function gmedia_terms_create_tag_tpl() {
|
152 |
+
include( dirname( __FILE__ ) . '/tpl/tag-create-item.php' );
|
153 |
}
|
154 |
|
155 |
function gmedia_terms_create_alert_tpl() {
|
156 |
+
include( dirname( __FILE__ ) . '/tpl/terms-create-alert.php' );
|
157 |
}
|
158 |
|
159 |
+
add_action( 'gmedia_term_album_after_panel', 'gmedia_term_album_after_panel' );
|
160 |
+
function gmedia_term_album_after_panel( $term ) {
|
161 |
+
include( dirname( __FILE__ ) . '/tpl/album-sort-gmedia.php' );
|
162 |
}
|
163 |
|
164 |
+
add_action( 'gmedia_term_category_after_panel', 'gmedia_term_category_after_panel' );
|
165 |
+
function gmedia_term_category_after_panel( $term ) {
|
166 |
+
include( dirname( __FILE__ ) . '/tpl/category-preview-gmedia.php' );
|
167 |
}
|
168 |
|
169 |
+
add_action( 'gmedia_term_filter_after_panel', 'gmedia_term_filter_after_panel' );
|
170 |
+
function gmedia_term_filter_after_panel( $term ) {
|
171 |
+
include( dirname( __FILE__ ) . '/tpl/filter-preview-query.php' );
|
172 |
}
|
admin/pages/terms/tpl/album-create-item.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Add Album Form
|
4 |
*/
|
@@ -48,6 +53,40 @@ $gmedia_url = $gmProcessor->url;
|
|
48 |
<option value="draft" <?php selected($gmGallery->options['in_album_status'], 'draft'); ?>><?php _e('Draft', 'grand-media'); ?></option>
|
49 |
</select>
|
50 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
<?php /* ?>
|
52 |
<div class="form-group">
|
53 |
<label><?php _e('Comment Status', 'grand-media'); ?></label>
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Add Album Form
|
9 |
*/
|
53 |
<option value="draft" <?php selected($gmGallery->options['in_album_status'], 'draft'); ?>><?php _e('Draft', 'grand-media'); ?></option>
|
54 |
</select>
|
55 |
</div>
|
56 |
+
<div class="form-group">
|
57 |
+
<label><?php _e('Module/Preset', 'grand-media'); ?></label>
|
58 |
+
<select class="form-control input-sm" id="term_module_preset" name="term[meta][_module_preset]">
|
59 |
+
<option value=""<?php if(empty($term->meta['_module_preset'][0])){
|
60 |
+
echo ' selected="selected"';
|
61 |
+
} ?>><?php _e('Default module in Global Settings', 'grand-media'); ?></option>
|
62 |
+
<?php global $gmDB, $user_ID;
|
63 |
+
$gmedia_modules = get_gmedia_modules(false);
|
64 |
+
foreach($gmedia_modules['in'] as $mfold => $module){
|
65 |
+
echo '<optgroup label="' . esc_attr($module['title']) . '">';
|
66 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
|
67 |
+
$option = array();
|
68 |
+
$option[] = '<option value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
|
69 |
+
foreach($presets as $preset){
|
70 |
+
if(!(int)$preset->global && '[' . $mfold . ']' === $preset->name){
|
71 |
+
continue;
|
72 |
+
}
|
73 |
+
$by_author = '';
|
74 |
+
if((int)$preset->global){
|
75 |
+
$by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
|
76 |
+
}
|
77 |
+
if('[' . $mfold . ']' === $preset->name){
|
78 |
+
$option[] = '<option value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
|
79 |
+
} else{
|
80 |
+
$preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
|
81 |
+
$option[] = '<option value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
|
82 |
+
}
|
83 |
+
}
|
84 |
+
echo implode('', $option);
|
85 |
+
echo '</optgroup>';
|
86 |
+
}
|
87 |
+
?>
|
88 |
+
</select>
|
89 |
+
</div>
|
90 |
<?php /* ?>
|
91 |
<div class="form-group">
|
92 |
<label><?php _e('Comment Status', 'grand-media'); ?></label>
|
admin/pages/terms/tpl/album-edit-item.php
CHANGED
@@ -1,7 +1,13 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Edit Album Form
|
4 |
*/
|
|
|
5 |
?>
|
6 |
<form method="post" id="gmedia-edit-term" name="gmEditTerm" class="panel-body" data-id="<?php echo $term->term_id; ?>">
|
7 |
<h4 style="margin-top:0;">
|
@@ -44,12 +50,50 @@
|
|
44 |
<option value="draft"<?php selected($term->status, 'draft'); ?>><?php _e('Draft', 'grand-media'); ?></option>
|
45 |
</select>
|
46 |
<div class="cb-help-block">
|
47 |
-
|
48 |
</div>
|
49 |
</div>
|
50 |
-
<?php /*if(isset($term->comment_status)){ ?>
|
51 |
<div class="form-group">
|
52 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
<b class="comment-count"><?php echo $term->comment_count; ?></b>
|
54 |
<span class="glyphicon glyphicon-comment"></span>
|
55 |
</a>
|
@@ -63,10 +107,10 @@
|
|
63 |
</div>
|
64 |
<div class="col-xs-6">
|
65 |
<?php if(isset($term->slug)){ ?>
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
<?php } ?>
|
71 |
<?php $cover_id = isset($term->meta['_cover'][0])? $term->meta['_cover'][0] : ''; ?>
|
72 |
<div class="form-group">
|
@@ -74,13 +118,13 @@
|
|
74 |
<input type="text" class="form-control input-sm" name="term[meta][_cover]" value="<?php echo esc_attr($cover_id); ?>" placeholder="<?php _e('Gmedia Image ID', 'grand-media'); ?>"/>
|
75 |
</div>
|
76 |
<?php
|
77 |
-
if(($cover_id = intval($cover_id)))
|
78 |
-
if(($cover = $gmDB->get_gmedia($cover_id)))
|
79 |
<div class="gm-img-thumbnail" data-gmid="<?php echo $cover->ID; ?>"><?php
|
80 |
?><img src="<?php echo $gmCore->gm_get_media_image($cover, 'thumb', true); ?>" alt="<?php echo $cover->ID; ?>" title="<?php echo esc_attr($cover->title); ?>"/><?php
|
81 |
?><span class="label label-default">ID: <?php echo $cover->ID; ?></span><?php
|
82 |
?></div>
|
83 |
-
<?php } else
|
84 |
echo '<strong class="text-danger">' . __('No image with such ID', 'grand-media') . '</strong>';
|
85 |
}
|
86 |
}
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')){
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Edit Album Form
|
9 |
*/
|
10 |
+
$_module_preset = isset($term->meta['_module_preset'][0])? $term->meta['_module_preset'][0] : '';
|
11 |
?>
|
12 |
<form method="post" id="gmedia-edit-term" name="gmEditTerm" class="panel-body" data-id="<?php echo $term->term_id; ?>">
|
13 |
<h4 style="margin-top:0;">
|
50 |
<option value="draft"<?php selected($term->status, 'draft'); ?>><?php _e('Draft', 'grand-media'); ?></option>
|
51 |
</select>
|
52 |
<div class="cb-help-block">
|
53 |
+
<div class="checkbox"><label><input type="checkbox" name="term[status_global]" value="1"> <?php _e('Apply Status for all items in album', 'grand-media'); ?> </label></div>
|
54 |
</div>
|
55 |
</div>
|
|
|
56 |
<div class="form-group">
|
57 |
+
<label><?php _e('Module/Preset', 'grand-media'); ?></label>
|
58 |
+
<select class="form-control input-sm" id="term_module_preset" name="term[meta][_module_preset]">
|
59 |
+
<option value=""<?php if('' === $_module_preset){
|
60 |
+
echo ' selected="selected"';
|
61 |
+
} ?>><?php _e('Default module in Global Settings', 'grand-media'); ?></option>
|
62 |
+
<?php global $gmDB, $user_ID, $gmGallery;
|
63 |
+
$gmedia_modules = get_gmedia_modules(false);
|
64 |
+
|
65 |
+
foreach($gmedia_modules['in'] as $mfold => $module){
|
66 |
+
echo '<optgroup label="' . esc_attr($module['title']) . '">';
|
67 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
|
68 |
+
$selected = selected($_module_preset, esc_attr($mfold), false);
|
69 |
+
$option = array();
|
70 |
+
$option[] = '<option ' . $selected . ' value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
|
71 |
+
foreach($presets as $preset){
|
72 |
+
if(!(int)$preset->global && '[' . $mfold . ']' === $preset->name){
|
73 |
+
continue;
|
74 |
+
}
|
75 |
+
$selected = selected($_module_preset, $preset->term_id, false);
|
76 |
+
$by_author = '';
|
77 |
+
if((int)$preset->global){
|
78 |
+
$by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
|
79 |
+
}
|
80 |
+
if('[' . $mfold . ']' === $preset->name){
|
81 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
|
82 |
+
} else{
|
83 |
+
$preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
|
84 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
|
85 |
+
}
|
86 |
+
}
|
87 |
+
echo implode('', $option);
|
88 |
+
echo '</optgroup>';
|
89 |
+
}
|
90 |
+
?>
|
91 |
+
</select>
|
92 |
+
</div>
|
93 |
+
<?php
|
94 |
+
/*if(isset($term->comment_status)){ ?>
|
95 |
+
<div class="form-group">
|
96 |
+
<a href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'gmediablank' => 'comments', 'gmedia_term_id' => $term->term_id), $gmProcessor->url); ?>" data-target="#previewModal" data-width="900" data-height="500" class="preview-modal gmpost-com-count pull-right" title="<?php esc_attr_e('Comments', 'grand-media'); ?>">
|
97 |
<b class="comment-count"><?php echo $term->comment_count; ?></b>
|
98 |
<span class="glyphicon glyphicon-comment"></span>
|
99 |
</a>
|
107 |
</div>
|
108 |
<div class="col-xs-6">
|
109 |
<?php if(isset($term->slug)){ ?>
|
110 |
+
<div class="form-group">
|
111 |
+
<label><?php _e('Slug', 'grand-media'); ?></label>
|
112 |
+
<input type="text" class="form-control input-sm" name="term[slug]" value="<?php echo esc_attr($term->slug); ?>"/>
|
113 |
+
</div>
|
114 |
<?php } ?>
|
115 |
<?php $cover_id = isset($term->meta['_cover'][0])? $term->meta['_cover'][0] : ''; ?>
|
116 |
<div class="form-group">
|
118 |
<input type="text" class="form-control input-sm" name="term[meta][_cover]" value="<?php echo esc_attr($cover_id); ?>" placeholder="<?php _e('Gmedia Image ID', 'grand-media'); ?>"/>
|
119 |
</div>
|
120 |
<?php
|
121 |
+
if(($cover_id = intval($cover_id))){
|
122 |
+
if(($cover = $gmDB->get_gmedia($cover_id))){ ?>
|
123 |
<div class="gm-img-thumbnail" data-gmid="<?php echo $cover->ID; ?>"><?php
|
124 |
?><img src="<?php echo $gmCore->gm_get_media_image($cover, 'thumb', true); ?>" alt="<?php echo $cover->ID; ?>" title="<?php echo esc_attr($cover->title); ?>"/><?php
|
125 |
?><span class="label label-default">ID: <?php echo $cover->ID; ?></span><?php
|
126 |
?></div>
|
127 |
+
<?php } else{
|
128 |
echo '<strong class="text-danger">' . __('No image with such ID', 'grand-media') . '</strong>';
|
129 |
}
|
130 |
}
|
admin/pages/terms/tpl/album-list-item.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Album list item
|
4 |
*
|
1 |
<?php
|
2 |
+
// don't load directly
|
3 |
+
if(!defined('ABSPATH')) {
|
4 |
+
die('-1');
|
5 |
+
}
|
6 |
+
|
7 |
/**
|
8 |
* Album list item
|
9 |
*
|
admin/pages/terms/tpl/album-sort-gmedia.php
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Sort Gmedia in Album
|
4 |
*
|
5 |
* @var $term
|
6 |
*/
|
7 |
-
|
8 |
-
return;
|
9 |
-
}
|
10 |
-
|
11 |
-
global $gmDB, $gmCore;
|
12 |
|
13 |
$_orderby = isset($term->meta['_orderby'][0])? $term->meta['_orderby'][0] : '';
|
14 |
$_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : '';
|
@@ -30,8 +30,8 @@ $pager_html = $gmDB->query_pager();
|
|
30 |
?>
|
31 |
<div class="panel panel-default">
|
32 |
<div class="panel-heading clearfix">
|
33 |
-
<h4 style="margin:7px 0;" class="pull-left"><?php _e('Sort Album'); ?></h4>
|
34 |
-
|
35 |
<?php echo $pager_html; ?>
|
36 |
|
37 |
</div>
|
@@ -115,6 +115,7 @@ $pager_html = $gmDB->query_pager();
|
|
115 |
//revert: true,
|
116 |
stop: function(event, ui) {
|
117 |
$('#gmedia_term_orderby').val('custom');
|
|
|
118 |
var cur_order, prev_order, next_order;
|
119 |
var self = ui.item,
|
120 |
prev_item = self.prev(),
|
@@ -153,6 +154,7 @@ $pager_html = $gmDB->query_pager();
|
|
153 |
|
154 |
$('input', items).on('change', function() {
|
155 |
$('#gmedia_term_orderby').val('custom');
|
|
|
156 |
sortdiv.css({height: sortdiv.height()});
|
157 |
var items = $('.gm-img-thumbnail', sortdiv);
|
158 |
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Sort Gmedia in Album
|
8 |
*
|
9 |
* @var $term
|
10 |
*/
|
11 |
+
global $gmDB, $gmCore, $gmProcessor;
|
|
|
|
|
|
|
|
|
12 |
|
13 |
$_orderby = isset($term->meta['_orderby'][0])? $term->meta['_orderby'][0] : '';
|
14 |
$_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : '';
|
30 |
?>
|
31 |
<div class="panel panel-default">
|
32 |
<div class="panel-heading clearfix">
|
33 |
+
<h4 style="margin:7px 40px 7px 0;" class="pull-left"><?php _e('Sort Album'); ?></h4>
|
34 |
+
<a class="btn btn-default" href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'album__in' => $term->term_id), $gmProcessor->url); ?>"><?php _e('Open in Gmedia Library', 'grand-media'); ?></a>
|
35 |
<?php echo $pager_html; ?>
|
36 |
|
37 |
</div>
|
115 |
//revert: true,
|
116 |
stop: function(event, ui) {
|
117 |
$('#gmedia_term_orderby').val('custom');
|
118 |
+
$('#gmedia_term_order').val('ASC');
|
119 |
var cur_order, prev_order, next_order;
|
120 |
var self = ui.item,
|
121 |
prev_item = self.prev(),
|
154 |
|
155 |
$('input', items).on('change', function() {
|
156 |
$('#gmedia_term_orderby').val('custom');
|
157 |
+
$('#gmedia_term_order').val('ASC');
|
158 |
sortdiv.css({height: sortdiv.height()});
|
159 |
var items = $('.gm-img-thumbnail', sortdiv);
|
160 |
|
admin/pages/terms/tpl/category-create-item.php
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Add Album Form
|
4 |
*/
|
5 |
global $gmProcessor, $gmGallery;
|
6 |
$gmedia_url = $gmProcessor->url;
|
7 |
|
8 |
-
$_orderby
|
9 |
-
$_order
|
10 |
?>
|
11 |
<form method="post" id="gmedia-edit-term" name="gmAddTerms" class="panel-body" action="<?php echo $gmedia_url; ?>" style="padding-bottom:0; border-bottom:1px solid #ddd;">
|
12 |
<div class="row">
|
@@ -41,14 +45,54 @@ $_order = $gmGallery->options['in_category_order'];
|
|
41 |
</select>
|
42 |
</div>
|
43 |
</div>
|
44 |
-
<div class="
|
45 |
-
<
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
</div>
|
53 |
</div>
|
54 |
</div>
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')){
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Add Album Form
|
8 |
*/
|
9 |
global $gmProcessor, $gmGallery;
|
10 |
$gmedia_url = $gmProcessor->url;
|
11 |
|
12 |
+
$_orderby = $gmGallery->options['in_category_orderby'];
|
13 |
+
$_order = $gmGallery->options['in_category_order'];
|
14 |
?>
|
15 |
<form method="post" id="gmedia-edit-term" name="gmAddTerms" class="panel-body" action="<?php echo $gmedia_url; ?>" style="padding-bottom:0; border-bottom:1px solid #ddd;">
|
16 |
<div class="row">
|
45 |
</select>
|
46 |
</div>
|
47 |
</div>
|
48 |
+
<div class="row">
|
49 |
+
<div class="col-xs-6">
|
50 |
+
<div class="form-group">
|
51 |
+
<label><?php _e('Module/Preset', 'grand-media'); ?></label>
|
52 |
+
<select class="form-control input-sm" id="term_module_preset" name="term[meta][_module_preset]">
|
53 |
+
<option value=""<?php if(empty($term->meta['_module_preset'][0])){
|
54 |
+
echo ' selected="selected"';
|
55 |
+
} ?>><?php _e('Default module in Global Settings', 'grand-media'); ?></option>
|
56 |
+
<?php global $gmDB, $user_ID;
|
57 |
+
$gmedia_modules = get_gmedia_modules(false);
|
58 |
+
foreach($gmedia_modules['in'] as $mfold => $module){
|
59 |
+
echo '<optgroup label="' . esc_attr($module['title']) . '">';
|
60 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
|
61 |
+
$option = array();
|
62 |
+
$option[] = '<option value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
|
63 |
+
foreach($presets as $preset){
|
64 |
+
if(!(int)$preset->global && '[' . $mfold . ']' === $preset->name){
|
65 |
+
continue;
|
66 |
+
}
|
67 |
+
$by_author = '';
|
68 |
+
if((int)$preset->global){
|
69 |
+
$by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
|
70 |
+
}
|
71 |
+
if('[' . $mfold . ']' === $preset->name){
|
72 |
+
$option[] = '<option value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
|
73 |
+
} else{
|
74 |
+
$preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
|
75 |
+
$option[] = '<option value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
|
76 |
+
}
|
77 |
+
}
|
78 |
+
echo implode('', $option);
|
79 |
+
echo '</optgroup>';
|
80 |
+
}
|
81 |
+
?>
|
82 |
+
</select>
|
83 |
+
</div>
|
84 |
+
</div>
|
85 |
+
<div class="col-xs-6">
|
86 |
+
<div class="form-group">
|
87 |
+
<label> </label>
|
88 |
+
<?php
|
89 |
+
wp_original_referer_field(true, 'previous');
|
90 |
+
wp_nonce_field('GmediaTerms', 'term_save_wpnonce');
|
91 |
+
?>
|
92 |
+
<input type="hidden" name="term[taxonomy]" value="gmedia_category"/>
|
93 |
+
<button style="display:block" type="submit" class="btn btn-primary btn-sm" name="gmedia_category_save"><?php _e('Add New Category', 'grand-media'); ?></button>
|
94 |
+
</div>
|
95 |
+
</div>
|
96 |
</div>
|
97 |
</div>
|
98 |
</div>
|
admin/pages/terms/tpl/category-edit-item.php
CHANGED
@@ -1,10 +1,15 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Edit Album Form
|
4 |
*/
|
5 |
|
6 |
-
$_orderby
|
7 |
-
$_order
|
|
|
8 |
?>
|
9 |
<form method="post" id="gmedia-edit-term" name="gmEditTerm" class="panel-body" data-id="<?php echo $term->term_id; ?>">
|
10 |
<h4 style="margin-top:0;">
|
@@ -20,7 +25,7 @@ $_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : $gmGal
|
|
20 |
</div>
|
21 |
<div class="form-group">
|
22 |
<label><?php _e('Description', 'grand-media'); ?></label>
|
23 |
-
<textarea class="form-control input-sm" style="height:
|
24 |
</div>
|
25 |
<div class="text-right">
|
26 |
<?php
|
@@ -53,6 +58,45 @@ $_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : $gmGal
|
|
53 |
<option value="ASC"<?php selected($_order, 'ASC'); ?>><?php _e('ASC', 'grand-media'); ?></option>
|
54 |
</select>
|
55 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
</div>
|
57 |
<div class="col-xs-6">
|
58 |
<?php $cover_id = isset($term->meta['_cover'][0])? $term->meta['_cover'][0] : ''; ?>
|
@@ -61,13 +105,13 @@ $_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : $gmGal
|
|
61 |
<input type="text" class="form-control input-sm" name="term[meta][_cover]" value="<?php echo esc_attr($cover_id); ?>" placeholder="<?php _e('Gmedia Image ID', 'grand-media'); ?>"/>
|
62 |
</div>
|
63 |
<?php
|
64 |
-
if(($cover_id = intval($cover_id)))
|
65 |
-
if(($cover = $gmDB->get_gmedia($cover_id)))
|
66 |
<div class="gm-img-thumbnail" data-gmid="<?php echo $cover->ID; ?>"><?php
|
67 |
?><img src="<?php echo $gmCore->gm_get_media_image($cover, 'thumb', true); ?>" alt="<?php echo $cover->ID; ?>" title="<?php echo esc_attr($cover->title); ?>"/><?php
|
68 |
?><span class="label label-default">ID: <?php echo $cover->ID; ?></span><?php
|
69 |
?></div>
|
70 |
-
<?php } else
|
71 |
echo '<strong class="text-danger">' . __('No image with such ID', 'grand-media') . '</strong>';
|
72 |
}
|
73 |
}
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')){
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Edit Album Form
|
8 |
*/
|
9 |
|
10 |
+
$_orderby = isset($term->meta['_orderby'][0])? $term->meta['_orderby'][0] : $gmGallery->options['in_category_orderby'];
|
11 |
+
$_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : $gmGallery->options['in_category_order'];
|
12 |
+
$_module_preset = isset($term->meta['_module_preset'][0])? $term->meta['_module_preset'][0] : '';
|
13 |
?>
|
14 |
<form method="post" id="gmedia-edit-term" name="gmEditTerm" class="panel-body" data-id="<?php echo $term->term_id; ?>">
|
15 |
<h4 style="margin-top:0;">
|
25 |
</div>
|
26 |
<div class="form-group">
|
27 |
<label><?php _e('Description', 'grand-media'); ?></label>
|
28 |
+
<textarea class="form-control input-sm" style="height:98px;" rows="2" name="term[description]"><?php echo $term->description; ?></textarea>
|
29 |
</div>
|
30 |
<div class="text-right">
|
31 |
<?php
|
58 |
<option value="ASC"<?php selected($_order, 'ASC'); ?>><?php _e('ASC', 'grand-media'); ?></option>
|
59 |
</select>
|
60 |
</div>
|
61 |
+
<?php
|
62 |
+
|
63 |
+
?>
|
64 |
+
<div class="form-group">
|
65 |
+
<label><?php _e('Module/Preset', 'grand-media'); ?></label>
|
66 |
+
<select class="form-control input-sm" id="term_module_preset" name="term[meta][_module_preset]">
|
67 |
+
<option value=""<?php if(empty($term->meta['_module_preset'][0])){
|
68 |
+
echo ' selected="selected"';
|
69 |
+
} ?>><?php _e('Default module in Global Settings', 'grand-media'); ?></option>
|
70 |
+
<?php global $gmDB, $user_ID, $gmGallery;
|
71 |
+
$gmedia_modules = get_gmedia_modules(false);
|
72 |
+
foreach($gmedia_modules['in'] as $mfold => $module){
|
73 |
+
echo '<optgroup label="' . esc_attr($module['title']) . '">';
|
74 |
+
$presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
|
75 |
+
$selected = selected($_module_preset, esc_attr($mfold), false);
|
76 |
+
$option = array();
|
77 |
+
$option[] = '<option ' . $selected . ' value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
|
78 |
+
foreach($presets as $preset){
|
79 |
+
if(!(int)$preset->global && '[' . $mfold . ']' === $preset->name){
|
80 |
+
continue;
|
81 |
+
}
|
82 |
+
$selected = selected($_module_preset, $preset->term_id, false);
|
83 |
+
$by_author = '';
|
84 |
+
if((int)$preset->global){
|
85 |
+
$by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
|
86 |
+
}
|
87 |
+
if('[' . $mfold . ']' === $preset->name){
|
88 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
|
89 |
+
} else{
|
90 |
+
$preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
|
91 |
+
$option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
|
92 |
+
}
|
93 |
+
}
|
94 |
+
echo implode('', $option);
|
95 |
+
echo '</optgroup>';
|
96 |
+
}
|
97 |
+
?>
|
98 |
+
</select>
|
99 |
+
</div>
|
100 |
</div>
|
101 |
<div class="col-xs-6">
|
102 |
<?php $cover_id = isset($term->meta['_cover'][0])? $term->meta['_cover'][0] : ''; ?>
|
105 |
<input type="text" class="form-control input-sm" name="term[meta][_cover]" value="<?php echo esc_attr($cover_id); ?>" placeholder="<?php _e('Gmedia Image ID', 'grand-media'); ?>"/>
|
106 |
</div>
|
107 |
<?php
|
108 |
+
if(($cover_id = intval($cover_id))){
|
109 |
+
if(($cover = $gmDB->get_gmedia($cover_id))){ ?>
|
110 |
<div class="gm-img-thumbnail" data-gmid="<?php echo $cover->ID; ?>"><?php
|
111 |
?><img src="<?php echo $gmCore->gm_get_media_image($cover, 'thumb', true); ?>" alt="<?php echo $cover->ID; ?>" title="<?php echo esc_attr($cover->title); ?>"/><?php
|
112 |
?><span class="label label-default">ID: <?php echo $cover->ID; ?></span><?php
|
113 |
?></div>
|
114 |
+
<?php } else{
|
115 |
echo '<strong class="text-danger">' . __('No image with such ID', 'grand-media') . '</strong>';
|
116 |
}
|
117 |
}
|
admin/pages/terms/tpl/category-list-item.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Category list item
|
4 |
*
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Category list item
|
8 |
*
|
admin/pages/terms/tpl/category-preview-gmedia.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Preview Gmedia in Category
|
4 |
*
|
@@ -8,7 +12,7 @@ if(!$term->count) {
|
|
8 |
return;
|
9 |
}
|
10 |
|
11 |
-
global $gmDB, $gmCore, $gmGallery;
|
12 |
|
13 |
$_orderby = isset($term->meta['_orderby'][0])? $term->meta['_orderby'][0] : $gmGallery->options['in_category_orderby'];
|
14 |
$_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : $gmGallery->options['in_category_order'];
|
@@ -30,7 +34,8 @@ $pager_html = $gmDB->query_pager();
|
|
30 |
?>
|
31 |
<div class="panel panel-default">
|
32 |
<div class="panel-heading clearfix">
|
33 |
-
<h4 style="margin:7px 0;" class="pull-left"><?php _e('Category Preview'); ?></h4>
|
|
|
34 |
<?php echo $pager_html; ?></div>
|
35 |
<div class="panel-body">
|
36 |
<div class="termItems clearfix" id="termItems">
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Preview Gmedia in Category
|
8 |
*
|
12 |
return;
|
13 |
}
|
14 |
|
15 |
+
global $gmDB, $gmCore, $gmGallery, $gmProcessor;
|
16 |
|
17 |
$_orderby = isset($term->meta['_orderby'][0])? $term->meta['_orderby'][0] : $gmGallery->options['in_category_orderby'];
|
18 |
$_order = isset($term->meta['_order'][0])? $term->meta['_order'][0] : $gmGallery->options['in_category_order'];
|
34 |
?>
|
35 |
<div class="panel panel-default">
|
36 |
<div class="panel-heading clearfix">
|
37 |
+
<h4 style="margin:7px 40px 7px 0;" class="pull-left"><?php _e('Category Preview'); ?></h4>
|
38 |
+
<a class="btn btn-default" href="<?php echo add_query_arg(array('page' => 'GrandMedia', 'category__in' => $term->term_id), $gmProcessor->url); ?>"><?php _e('Open in Gmedia Library', 'grand-media'); ?></a>
|
39 |
<?php echo $pager_html; ?></div>
|
40 |
<div class="panel-body">
|
41 |
<div class="termItems clearfix" id="termItems">
|
admin/pages/terms/tpl/no-items.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* No term items
|
4 |
*/
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* No term items
|
8 |
*/
|
admin/pages/terms/tpl/tag-create-item.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Create tags form
|
4 |
*/
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Create tags form
|
8 |
*/
|
admin/pages/terms/tpl/tag-list-item.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Tag list item
|
4 |
*
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Tag list item
|
8 |
*
|
admin/pages/terms/tpl/term-panel-heading.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Panel heading for term
|
4 |
*
|
@@ -22,10 +26,12 @@ $taxterm = str_replace('gmedia_', '', $gmedia_term_taxonomy);
|
|
22 |
</button>
|
23 |
<ul class="dropdown-menu" role="menu">
|
24 |
<?php $taxkey = $taxterm . '__in'; ?>
|
25 |
-
<li><a href="<?php echo add_query_arg(array('page' => 'GrandMedia', $taxkey => $term->term_id),
|
26 |
</ul>
|
27 |
</div>
|
|
|
28 |
<?php } ?>
|
29 |
</div>
|
30 |
|
|
|
31 |
</div>
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Panel heading for term
|
8 |
*
|
26 |
</button>
|
27 |
<ul class="dropdown-menu" role="menu">
|
28 |
<?php $taxkey = $taxterm . '__in'; ?>
|
29 |
+
<li><a href="<?php echo add_query_arg(array('page' => 'GrandMedia', $taxkey => $term->term_id), $gmProcessor->url); ?>"><?php _e('Show in Gmedia Library', 'grand-media'); ?></a></li>
|
30 |
</ul>
|
31 |
</div>
|
32 |
+
<div class="term-shortcode pull-left"><input type="text" title="<?php _e('Shortcode'); ?>" class="form-control pull-left" value="<?php echo "[gm {$taxterm}={$term_id}]"; ?>" readonly /><div class="input-buffer"></div></div>
|
33 |
<?php } ?>
|
34 |
</div>
|
35 |
|
36 |
+
<div class="spinner"></div>
|
37 |
</div>
|
admin/pages/terms/tpl/terms-create-alert.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Alert capability
|
4 |
*/
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Alert capability
|
8 |
*/
|
admin/pages/terms/tpl/terms-panel-heading.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Panel heading for terms
|
4 |
*
|
@@ -8,14 +12,22 @@
|
|
8 |
*/
|
9 |
?>
|
10 |
<div class="panel-heading-fake"></div>
|
11 |
-
<div class="panel-heading clearfix">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
echo $gmedia_terms_pager;
|
16 |
-
?>
|
17 |
|
18 |
-
<div class="btn-toolbar pull-left">
|
19 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
20 |
<span class="btn btn-default active"><input class="doaction" id="cb_global"
|
21 |
data-group="cb_term-object" type="checkbox"/></span>
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Panel heading for terms
|
8 |
*
|
12 |
*/
|
13 |
?>
|
14 |
<div class="panel-heading-fake"></div>
|
15 |
+
<div class="panel-heading clearfix" style="padding-bottom:2px;">
|
16 |
+
<div class="pull-right" style="margin-bottom:3px;">
|
17 |
+
<div class="clearfix">
|
18 |
+
<?php include(GMEDIA_ABSPATH . 'admin/tpl/search-form.php'); ?>
|
19 |
+
|
20 |
+
<div class="btn-toolbar pull-right" style="margin-bottom:4px; margin-left:4px;">
|
21 |
+
<a title="<?php _e('More Screen Settings', 'grand-media'); ?>" class="show-settings-link pull-right btn btn-default btn-xs"><span class="glyphicon glyphicon-cog"></span></a>
|
22 |
+
</div>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<?php echo $gmedia_terms_pager; ?>
|
26 |
|
27 |
+
<div class="spinner"></div>
|
28 |
+
</div>
|
|
|
|
|
29 |
|
30 |
+
<div class="btn-toolbar pull-left" style="margin-bottom:7px;">
|
31 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
32 |
<span class="btn btn-default active"><input class="doaction" id="cb_global"
|
33 |
data-group="cb_term-object" type="checkbox"/></span>
|
admin/processor/class.processor.addmedia.php
CHANGED
@@ -17,7 +17,7 @@ class GmediaProcessor_AddMedia extends GmediaProcessor {
|
|
17 |
global $gmCore;
|
18 |
|
19 |
$this->import = $gmCore->_get('import', false, true);
|
20 |
-
$this->url = add_query_arg(array('
|
21 |
|
22 |
}
|
23 |
|
17 |
global $gmCore;
|
18 |
|
19 |
$this->import = $gmCore->_get('import', false, true);
|
20 |
+
$this->url = add_query_arg(array('import' => $this->import), $this->url);
|
21 |
|
22 |
}
|
23 |
|
admin/processor/class.processor.galleries.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
/**
|
4 |
* GmediaProcessor_Galleries
|
5 |
*/
|
6 |
-
class GmediaProcessor_Galleries extends GmediaProcessor
|
7 |
|
8 |
public $taxonomy;
|
9 |
public static $cookie_key = false;
|
@@ -13,11 +13,11 @@ class GmediaProcessor_Galleries extends GmediaProcessor {
|
|
13 |
/**
|
14 |
* GmediaProcessor_Library constructor.
|
15 |
*/
|
16 |
-
public function __construct()
|
17 |
global $user_ID;
|
18 |
|
19 |
-
$this->taxonomy
|
20 |
-
self::$cookie_key
|
21 |
$this->selected_items = parent::selected_items(self::$cookie_key);
|
22 |
|
23 |
parent::__construct();
|
@@ -26,36 +26,36 @@ class GmediaProcessor_Galleries extends GmediaProcessor {
|
|
26 |
/**
|
27 |
* @return array
|
28 |
*/
|
29 |
-
public function query_args()
|
30 |
global $gmCore;
|
31 |
|
32 |
-
$args['status']
|
33 |
-
$args['page']
|
34 |
-
$args['number']
|
35 |
-
$args['offset']
|
36 |
-
$args['global']
|
37 |
-
$args['include']
|
38 |
-
$args['search']
|
39 |
-
$args['orderby']
|
40 |
-
$args['order']
|
41 |
-
|
42 |
-
if($args['search'] && ('#' == substr($args['search'], 0, 1)))
|
43 |
$args['include'] = substr($args['search'], 1);
|
44 |
-
$args['search']
|
45 |
}
|
46 |
|
47 |
-
if(('selected' == $gmCore->_req('filter')) && !empty($this->selected_items))
|
48 |
$args['include'] = $this->selected_items;
|
49 |
-
$args['orderby']
|
50 |
-
$args['order']
|
51 |
}
|
52 |
|
53 |
-
$query_args
|
54 |
$query_args['hide_empty'] = false;
|
55 |
|
56 |
foreach($query_args as $key => $val){
|
57 |
if(empty($val) && ('0' !== $val) && (0 !== $val)){
|
58 |
-
unset($query_args[$key]);
|
59 |
}
|
60 |
}
|
61 |
|
@@ -63,67 +63,75 @@ class GmediaProcessor_Galleries extends GmediaProcessor {
|
|
63 |
}
|
64 |
|
65 |
|
66 |
-
protected function processor()
|
67 |
-
global $user_ID, $gmCore, $gmDB;
|
68 |
|
69 |
-
if(!$gmCore->caps['gmedia_library'])
|
70 |
wp_die(__('You are not allowed to be here', 'grand-media'));
|
71 |
}
|
72 |
|
73 |
-
if(!$gmCore->caps['gmedia_gallery_manage'])
|
74 |
wp_die(__('You are not allowed to manage gmedia galleries', 'grand-media'));
|
75 |
}
|
76 |
|
77 |
include_once(GMEDIA_ABSPATH . 'admin/pages/galleries/functions.php');
|
78 |
|
79 |
-
|
|
|
|
|
80 |
$authors = $gmCore->_post('author_ids');
|
81 |
$location = $gmCore->get_admin_url(array('author' => (int)$authors));
|
82 |
wp_redirect($location);
|
83 |
exit;
|
84 |
}
|
85 |
-
if(isset($_POST['gmedia_gallery_save']))
|
86 |
check_admin_referer('GmediaGallery');
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
$edit_gallery = (int)$gmCore->_get('edit_item');
|
88 |
-
do
|
89 |
$term = $gmCore->_post('term');
|
90 |
-
if(((int)$term['global'] != $user_ID) && !$gmCore->caps['gmedia_edit_others_media'])
|
91 |
$this->error[] = __('You are not allowed to edit others media', 'grand-media');
|
92 |
break;
|
93 |
}
|
94 |
$term['name'] = trim($term['name']);
|
95 |
-
if(empty($term['name']))
|
96 |
$this->error[] = __('Gallery Name is not specified', 'grand-media');
|
97 |
break;
|
98 |
}
|
99 |
-
if($gmCore->is_digit($term['name']))
|
100 |
$this->error[] = __("Gallery name can't be only digits", 'grand-media');
|
101 |
break;
|
102 |
}
|
103 |
-
if(empty($term['module']))
|
104 |
$this->error[] = __('Something goes wrong... Choose module, please', 'grand-media');
|
105 |
break;
|
106 |
}
|
107 |
$taxonomy = 'gmedia_gallery';
|
108 |
-
if($edit_gallery && !$gmDB->term_exists($edit_gallery))
|
109 |
$this->error[] = __('A term with the id provided do not exists', 'grand-media');
|
110 |
$edit_gallery = false;
|
111 |
}
|
112 |
-
if(($term_id = $gmDB->term_exists($term['name'], $taxonomy, $term['global'])))
|
113 |
-
if($term_id != $edit_gallery)
|
114 |
$this->error[] = __('A term with the name provided already exists', 'grand-media');
|
115 |
break;
|
116 |
}
|
117 |
}
|
118 |
-
if(($meta = $gmCore->_post('meta')))
|
119 |
$term = array_merge_recursive(array('meta' => $meta), $term);
|
120 |
}
|
121 |
-
if($edit_gallery)
|
122 |
$term_id = $gmDB->update_term($edit_gallery, $term);
|
123 |
-
} else
|
124 |
$term_id = $gmDB->insert_term($term['name'], $taxonomy, $term);
|
125 |
}
|
126 |
-
if(is_wp_error($term_id))
|
127 |
$this->error[] = $term_id->get_error_message();
|
128 |
break;
|
129 |
}
|
@@ -131,63 +139,58 @@ class GmediaProcessor_Galleries extends GmediaProcessor {
|
|
131 |
$module_settings = $gmCore->_post('module', array());
|
132 |
$module_path = $gmCore->get_module_path($term['module']);
|
133 |
$default_options = array();
|
134 |
-
if(file_exists($module_path['path'] . '/settings.php'))
|
135 |
/** @noinspection PhpIncludeInspection */
|
136 |
include($module_path['path'] . '/settings.php');
|
137 |
-
} else
|
138 |
$this->error[] = sprintf(__('Can\'t load data from `%s` module'), $term['module']);
|
139 |
break;
|
140 |
}
|
141 |
$module_settings = $gmCore->array_replace_recursive($default_options, $module_settings);
|
142 |
wp_parse_str($term['query'], $_query);
|
143 |
-
$gallery_meta
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
'_settings' => array($term['module'] => $module_settings)
|
148 |
);
|
149 |
-
foreach($gallery_meta as $key => $value)
|
150 |
-
|
151 |
-
$gmDB->update_metadata('gmedia_term', $term_id, $key, $value);
|
152 |
-
} else {
|
153 |
-
$gmDB->add_metadata('gmedia_term', $term_id, $key, $value);
|
154 |
-
}
|
155 |
}
|
156 |
-
if($edit_gallery)
|
157 |
$this->msg[] = sprintf(__('Gallery #%d successfuly saved', 'grand-media'), $term_id);
|
158 |
-
} else
|
159 |
-
$location = add_query_arg(array('
|
160 |
set_transient('gmedia_new_gallery_id', $term_id, 60);
|
161 |
wp_redirect($location);
|
162 |
exit;
|
163 |
}
|
164 |
} while(0);
|
165 |
}
|
166 |
-
if(('save' == $gmCore->_get('message')) && ($term_id = $gmCore->_get('edit_item')))
|
167 |
$gmedia_new_gallery_id = get_transient('gmedia_new_gallery_id');
|
168 |
-
if(false !== $gmedia_new_gallery_id)
|
169 |
delete_transient('gmedia_new_gallery_id');
|
170 |
$this->msg[] = sprintf(__('Gallery #%d successfuly saved', 'grand-media'), $term_id);
|
171 |
}
|
172 |
}
|
173 |
|
174 |
-
if(isset($_POST['module_preset_restore_original']))
|
175 |
$preset_id = intval($gmCore->_post('preset_default', 0));
|
176 |
$gmDB->delete_term($preset_id);
|
177 |
$this->msg[] = __('Original module settings restored. Click "Reset to default" button to save original module settings for gallery', 'grand-media');
|
178 |
}
|
179 |
|
180 |
-
if(isset($_POST['gmedia_gallery_reset']))
|
181 |
check_admin_referer('GmediaGallery');
|
182 |
$edit_gallery = (int)$gmCore->_get('edit_item');
|
183 |
-
do
|
184 |
-
if(!$gmDB->term_exists($edit_gallery))
|
185 |
$this->error[] = __('A term with the id provided do not exists', 'grand-media');
|
186 |
break;
|
187 |
}
|
188 |
-
if(!$gmCore->caps['gmedia_edit_others_media'])
|
189 |
$term = $gmDB->get_term($edit_gallery);
|
190 |
-
if($term->global != $user_ID)
|
191 |
$this->error[] = __('You are not allowed to edit others media', 'grand-media');
|
192 |
break;
|
193 |
}
|
@@ -199,24 +202,28 @@ class GmediaProcessor_Galleries extends GmediaProcessor {
|
|
199 |
/**
|
200 |
* @var $default_options
|
201 |
*/
|
202 |
-
if(file_exists($module_path['path'] . '/settings.php'))
|
203 |
/** @noinspection PhpIncludeInspection */
|
204 |
include($module_path['path'] . '/settings.php');
|
|
|
|
|
|
|
|
|
|
|
205 |
$preset = $gmDB->get_term('[' . $gallery_module . ']', 'gmedia_module');
|
206 |
-
if($preset)
|
207 |
$default_preset = maybe_unserialize($preset->description);
|
208 |
$default_options = $gmCore->array_replace_recursive($default_options, $default_preset);
|
209 |
}
|
210 |
-
} else
|
211 |
$this->error[] = sprintf(__('Can\'t load data from `%s` module'), $gallery_module);
|
212 |
break;
|
213 |
}
|
214 |
|
215 |
-
$gallery_meta = array(
|
216 |
-
|
217 |
-
'_settings' => array($gallery_module => $default_options)
|
218 |
);
|
219 |
-
foreach($gallery_meta as $key => $value)
|
220 |
$gmDB->update_metadata('gmedia_term', $edit_gallery, $key, $value);
|
221 |
}
|
222 |
$this->msg[] = sprintf(__('Gallery settings are reset', 'grand-media'));
|
@@ -225,34 +232,33 @@ class GmediaProcessor_Galleries extends GmediaProcessor {
|
|
225 |
|
226 |
}
|
227 |
|
228 |
-
if(isset($_POST['
|
229 |
check_admin_referer('GmediaGallery');
|
230 |
-
do
|
231 |
$term = $gmCore->_post('term');
|
232 |
-
if(empty($term['module']))
|
233 |
$this->error[] = __('Something goes wrong... Choose module, please', 'grand-media');
|
234 |
break;
|
235 |
}
|
236 |
$module_settings = $gmCore->_post('module', array());
|
237 |
$module_path = $gmCore->get_module_path($term['module']);
|
238 |
$default_options = array();
|
239 |
-
if(file_exists($module_path['path'] . '/settings.php'))
|
240 |
/** @noinspection PhpIncludeInspection */
|
241 |
include($module_path['path'] . '/settings.php');
|
242 |
-
} else
|
243 |
$this->error[] = sprintf(__('Can\'t load data from `%s` module'), $term['module']);
|
244 |
break;
|
245 |
}
|
246 |
$module_settings = $gmCore->array_replace_recursive($default_options, $module_settings);
|
247 |
|
248 |
$preset_name = $gmCore->_post('module_preset_name', '');
|
249 |
-
if(isset($_POST['module_preset_save_default']))
|
250 |
$preset_name = '[' . $term['module'] . ']';
|
251 |
-
} else
|
252 |
$preset_name = trim($preset_name);
|
253 |
-
if(empty($preset_name))
|
254 |
-
$
|
255 |
-
break;
|
256 |
}
|
257 |
$preset_name = '[' . $term['module'] . '] ' . $preset_name;
|
258 |
}
|
@@ -260,51 +266,54 @@ class GmediaProcessor_Galleries extends GmediaProcessor {
|
|
260 |
$args['description'] = $module_settings;
|
261 |
$args['status'] = $term['module'];
|
262 |
$args['global'] = $user_ID;
|
|
|
|
|
|
|
263 |
|
264 |
$taxonomy = 'gmedia_module';
|
265 |
-
$term_id = $gmDB->term_exists($preset_name, $taxonomy, $
|
266 |
-
if($term_id)
|
267 |
$term_id = $gmDB->update_term($term_id, $args);
|
268 |
-
} else
|
269 |
$term_id = $gmDB->insert_term($preset_name, $taxonomy, $args);
|
270 |
}
|
271 |
-
if(is_wp_error($term_id))
|
272 |
$this->error[] = $term_id->get_error_message();
|
273 |
break;
|
274 |
-
} else
|
275 |
$this->msg[] = sprintf(__('Preset `%s` successfuly saved', 'grand-media'), $preset_name);
|
276 |
}
|
277 |
|
278 |
} while(0);
|
279 |
}
|
280 |
|
281 |
-
if(($delete = $gmCore->_get('delete')))
|
282 |
check_admin_referer('gmedia_delete');
|
283 |
$taxonomy = 'gmedia_gallery';
|
284 |
-
if('selected' == $delete)
|
285 |
$selected_items = $this->selected_items;
|
286 |
-
} else
|
287 |
$selected_items = wp_parse_id_list($delete);
|
288 |
}
|
289 |
-
if(!$gmCore->caps['gmedia_delete_others_media'])
|
290 |
$_selected_items = $gmDB->get_terms($taxonomy, array('fields' => 'ids', 'global' => $user_ID, 'include' => $selected_items));
|
291 |
-
if(count($_selected_items) < count($selected_items))
|
292 |
$this->error[] = __('You are not allowed to delete others media', 'grand-media');
|
293 |
}
|
294 |
$selected_items = $_selected_items;
|
295 |
}
|
296 |
-
if(($count = count($selected_items)))
|
297 |
-
foreach($selected_items as $item)
|
298 |
$delete = $gmDB->delete_term($item);
|
299 |
-
if(!$delete)
|
300 |
$this->error[] = sprintf(__('Error while delete gallery #%d', 'grand-media'), $item);
|
301 |
-
$count--;
|
302 |
-
} elseif(is_wp_error($delete))
|
303 |
$this->error[] = $delete->get_error_message();
|
304 |
-
$count--;
|
305 |
}
|
306 |
}
|
307 |
-
if($count)
|
308 |
$this->msg[] = sprintf(__('%d item(s) deleted successfuly', 'grand-media'), $count);
|
309 |
}
|
310 |
setcookie("gmuser_{$user_ID}_{$taxonomy}", '', time() - 3600);
|
3 |
/**
|
4 |
* GmediaProcessor_Galleries
|
5 |
*/
|
6 |
+
class GmediaProcessor_Galleries extends GmediaProcessor{
|
7 |
|
8 |
public $taxonomy;
|
9 |
public static $cookie_key = false;
|
13 |
/**
|
14 |
* GmediaProcessor_Library constructor.
|
15 |
*/
|
16 |
+
public function __construct(){
|
17 |
global $user_ID;
|
18 |
|
19 |
+
$this->taxonomy = 'gmedia_gallery';
|
20 |
+
self::$cookie_key = "gmuser_{$user_ID}_{$this->taxonomy}";
|
21 |
$this->selected_items = parent::selected_items(self::$cookie_key);
|
22 |
|
23 |
parent::__construct();
|
26 |
/**
|
27 |
* @return array
|
28 |
*/
|
29 |
+
public function query_args(){
|
30 |
global $gmCore;
|
31 |
|
32 |
+
$args['status'] = $gmCore->_get('status');
|
33 |
+
$args['page'] = $gmCore->_get('pager', 1);
|
34 |
+
$args['number'] = $gmCore->_get('per_page', $this->user_options['per_page_gmedia_gallery']);
|
35 |
+
$args['offset'] = ($args['page'] - 1) * $args['number'];
|
36 |
+
$args['global'] = parent::filter_by_author($gmCore->_get('author'));
|
37 |
+
$args['include'] = $gmCore->_get('include');
|
38 |
+
$args['search'] = $gmCore->_get('s');
|
39 |
+
$args['orderby'] = $gmCore->_get('orderby', $this->user_options['orderby_gmedia_gallery']);
|
40 |
+
$args['order'] = $gmCore->_get('order', $this->user_options['sortorder_gmedia_gallery']);
|
41 |
+
|
42 |
+
if($args['search'] && ('#' == substr($args['search'], 0, 1))){
|
43 |
$args['include'] = substr($args['search'], 1);
|
44 |
+
$args['search'] = false;
|
45 |
}
|
46 |
|
47 |
+
if(('selected' == $gmCore->_req('filter')) && !empty($this->selected_items)){
|
48 |
$args['include'] = $this->selected_items;
|
49 |
+
$args['orderby'] = $gmCore->_get('orderby', 'include');
|
50 |
+
$args['order'] = $gmCore->_get('order', 'ASC');
|
51 |
}
|
52 |
|
53 |
+
$query_args = apply_filters('gmedia_gallery_query_args', $args);
|
54 |
$query_args['hide_empty'] = false;
|
55 |
|
56 |
foreach($query_args as $key => $val){
|
57 |
if(empty($val) && ('0' !== $val) && (0 !== $val)){
|
58 |
+
unset($query_args[ $key ]);
|
59 |
}
|
60 |
}
|
61 |
|
63 |
}
|
64 |
|
65 |
|
66 |
+
protected function processor(){
|
67 |
+
global $user_ID, $gmCore, $gmDB, $gmGallery;
|
68 |
|
69 |
+
if(!$gmCore->caps['gmedia_library']){
|
70 |
wp_die(__('You are not allowed to be here', 'grand-media'));
|
71 |
}
|
72 |
|
73 |
+
if(!$gmCore->caps['gmedia_gallery_manage']){
|
74 |
wp_die(__('You are not allowed to manage gmedia galleries', 'grand-media'));
|
75 |
}
|
76 |
|
77 |
include_once(GMEDIA_ABSPATH . 'admin/pages/galleries/functions.php');
|
78 |
|
79 |
+
$this->query_args = $this->query_args();
|
80 |
+
|
81 |
+
if(isset($_POST['select_author'])){
|
82 |
$authors = $gmCore->_post('author_ids');
|
83 |
$location = $gmCore->get_admin_url(array('author' => (int)$authors));
|
84 |
wp_redirect($location);
|
85 |
exit;
|
86 |
}
|
87 |
+
if(isset($_POST['gmedia_gallery_save'])){
|
88 |
check_admin_referer('GmediaGallery');
|
89 |
+
|
90 |
+
if(isset($_POST['preview_bgcolor'])){
|
91 |
+
$gmGallery->options['preview_bgcolor'] = $gmCore->sanitize_hex_color($_POST['preview_bgcolor'], 'ffffff');
|
92 |
+
update_option('gmediaOptions', $gmGallery->options);
|
93 |
+
}
|
94 |
+
|
95 |
$edit_gallery = (int)$gmCore->_get('edit_item');
|
96 |
+
do{
|
97 |
$term = $gmCore->_post('term');
|
98 |
+
if(((int)$term['global'] != $user_ID) && !$gmCore->caps['gmedia_edit_others_media']){
|
99 |
$this->error[] = __('You are not allowed to edit others media', 'grand-media');
|
100 |
break;
|
101 |
}
|
102 |
$term['name'] = trim($term['name']);
|
103 |
+
if(empty($term['name'])){
|
104 |
$this->error[] = __('Gallery Name is not specified', 'grand-media');
|
105 |
break;
|
106 |
}
|
107 |
+
if($gmCore->is_digit($term['name'])){
|
108 |
$this->error[] = __("Gallery name can't be only digits", 'grand-media');
|
109 |
break;
|
110 |
}
|
111 |
+
if(empty($term['module'])){
|
112 |
$this->error[] = __('Something goes wrong... Choose module, please', 'grand-media');
|
113 |
break;
|
114 |
}
|
115 |
$taxonomy = 'gmedia_gallery';
|
116 |
+
if($edit_gallery && !$gmDB->term_exists($edit_gallery)){
|
117 |
$this->error[] = __('A term with the id provided do not exists', 'grand-media');
|
118 |
$edit_gallery = false;
|
119 |
}
|
120 |
+
if(($term_id = $gmDB->term_exists($term['name'], $taxonomy, $term['global']))){
|
121 |
+
if($term_id != $edit_gallery){
|
122 |
$this->error[] = __('A term with the name provided already exists', 'grand-media');
|
123 |
break;
|
124 |
}
|
125 |
}
|
126 |
+
if(($meta = $gmCore->_post('meta'))){
|
127 |
$term = array_merge_recursive(array('meta' => $meta), $term);
|
128 |
}
|
129 |
+
if($edit_gallery){
|
130 |
$term_id = $gmDB->update_term($edit_gallery, $term);
|
131 |
+
} else{
|
132 |
$term_id = $gmDB->insert_term($term['name'], $taxonomy, $term);
|
133 |
}
|
134 |
+
if(is_wp_error($term_id)){
|
135 |
$this->error[] = $term_id->get_error_message();
|
136 |
break;
|
137 |
}
|
139 |
$module_settings = $gmCore->_post('module', array());
|
140 |
$module_path = $gmCore->get_module_path($term['module']);
|
141 |
$default_options = array();
|
142 |
+
if(file_exists($module_path['path'] . '/settings.php')){
|
143 |
/** @noinspection PhpIncludeInspection */
|
144 |
include($module_path['path'] . '/settings.php');
|
145 |
+
} else{
|
146 |
$this->error[] = sprintf(__('Can\'t load data from `%s` module'), $term['module']);
|
147 |
break;
|
148 |
}
|
149 |
$module_settings = $gmCore->array_replace_recursive($default_options, $module_settings);
|
150 |
wp_parse_str($term['query'], $_query);
|
151 |
+
$gallery_meta = array('_edited' => gmdate('Y-m-d H:i:s'),
|
152 |
+
'_query' => $_query,
|
153 |
+
'_module' => $term['module'],
|
154 |
+
'_settings' => array($term['module'] => $module_settings)
|
|
|
155 |
);
|
156 |
+
foreach($gallery_meta as $key => $value){
|
157 |
+
$gmDB->update_metadata('gmedia_term', $term_id, $key, $value);
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
+
if($edit_gallery){
|
160 |
$this->msg[] = sprintf(__('Gallery #%d successfuly saved', 'grand-media'), $term_id);
|
161 |
+
} else{
|
162 |
+
$location = add_query_arg(array('edit_item' => $term_id, 'message' => 'save'), $this->url);
|
163 |
set_transient('gmedia_new_gallery_id', $term_id, 60);
|
164 |
wp_redirect($location);
|
165 |
exit;
|
166 |
}
|
167 |
} while(0);
|
168 |
}
|
169 |
+
if(('save' == $gmCore->_get('message')) && ($term_id = $gmCore->_get('edit_item'))){
|
170 |
$gmedia_new_gallery_id = get_transient('gmedia_new_gallery_id');
|
171 |
+
if(false !== $gmedia_new_gallery_id){
|
172 |
delete_transient('gmedia_new_gallery_id');
|
173 |
$this->msg[] = sprintf(__('Gallery #%d successfuly saved', 'grand-media'), $term_id);
|
174 |
}
|
175 |
}
|
176 |
|
177 |
+
if(isset($_POST['module_preset_restore_original'])){
|
178 |
$preset_id = intval($gmCore->_post('preset_default', 0));
|
179 |
$gmDB->delete_term($preset_id);
|
180 |
$this->msg[] = __('Original module settings restored. Click "Reset to default" button to save original module settings for gallery', 'grand-media');
|
181 |
}
|
182 |
|
183 |
+
if(isset($_POST['gmedia_gallery_reset'])){
|
184 |
check_admin_referer('GmediaGallery');
|
185 |
$edit_gallery = (int)$gmCore->_get('edit_item');
|
186 |
+
do{
|
187 |
+
if(!$gmDB->term_exists($edit_gallery)){
|
188 |
$this->error[] = __('A term with the id provided do not exists', 'grand-media');
|
189 |
break;
|
190 |
}
|
191 |
+
if(!$gmCore->caps['gmedia_edit_others_media']){
|
192 |
$term = $gmDB->get_term($edit_gallery);
|
193 |
+
if($term->global != $user_ID){
|
194 |
$this->error[] = __('You are not allowed to edit others media', 'grand-media');
|
195 |
break;
|
196 |
}
|
202 |
/**
|
203 |
* @var $default_options
|
204 |
*/
|
205 |
+
if(file_exists($module_path['path'] . '/settings.php')){
|
206 |
/** @noinspection PhpIncludeInspection */
|
207 |
include($module_path['path'] . '/settings.php');
|
208 |
+
$preset = $gmDB->get_term('[' . $gallery_module . ']', array('taxonomy' => 'gmedia_module', 'global' => '0'));
|
209 |
+
if($preset){
|
210 |
+
$default_preset = maybe_unserialize($preset->description);
|
211 |
+
$default_options = $gmCore->array_replace_recursive($default_options, $default_preset);
|
212 |
+
}
|
213 |
$preset = $gmDB->get_term('[' . $gallery_module . ']', 'gmedia_module');
|
214 |
+
if($preset){
|
215 |
$default_preset = maybe_unserialize($preset->description);
|
216 |
$default_options = $gmCore->array_replace_recursive($default_options, $default_preset);
|
217 |
}
|
218 |
+
} else{
|
219 |
$this->error[] = sprintf(__('Can\'t load data from `%s` module'), $gallery_module);
|
220 |
break;
|
221 |
}
|
222 |
|
223 |
+
$gallery_meta = array('_edited' => gmdate('Y-m-d H:i:s'),
|
224 |
+
'_settings' => array($gallery_module => $default_options)
|
|
|
225 |
);
|
226 |
+
foreach($gallery_meta as $key => $value){
|
227 |
$gmDB->update_metadata('gmedia_term', $edit_gallery, $key, $value);
|
228 |
}
|
229 |
$this->msg[] = sprintf(__('Gallery settings are reset', 'grand-media'));
|
232 |
|
233 |
}
|
234 |
|
235 |
+
if(isset($_POST['module_preset_save']) || isset($_POST['module_preset_save_default']) || isset($_POST['module_preset_save_global'])){
|
236 |
check_admin_referer('GmediaGallery');
|
237 |
+
do{
|
238 |
$term = $gmCore->_post('term');
|
239 |
+
if(empty($term['module'])){
|
240 |
$this->error[] = __('Something goes wrong... Choose module, please', 'grand-media');
|
241 |
break;
|
242 |
}
|
243 |
$module_settings = $gmCore->_post('module', array());
|
244 |
$module_path = $gmCore->get_module_path($term['module']);
|
245 |
$default_options = array();
|
246 |
+
if(file_exists($module_path['path'] . '/settings.php')){
|
247 |
/** @noinspection PhpIncludeInspection */
|
248 |
include($module_path['path'] . '/settings.php');
|
249 |
+
} else{
|
250 |
$this->error[] = sprintf(__('Can\'t load data from `%s` module'), $term['module']);
|
251 |
break;
|
252 |
}
|
253 |
$module_settings = $gmCore->array_replace_recursive($default_options, $module_settings);
|
254 |
|
255 |
$preset_name = $gmCore->_post('module_preset_name', '');
|
256 |
+
if(isset($_POST['module_preset_save_default']) || isset($_POST['module_preset_save_global'])){
|
257 |
$preset_name = '[' . $term['module'] . ']';
|
258 |
+
} else{
|
259 |
$preset_name = trim($preset_name);
|
260 |
+
if(empty($preset_name)){
|
261 |
+
$preset_name = current_time('mysql');
|
|
|
262 |
}
|
263 |
$preset_name = '[' . $term['module'] . '] ' . $preset_name;
|
264 |
}
|
266 |
$args['description'] = $module_settings;
|
267 |
$args['status'] = $term['module'];
|
268 |
$args['global'] = $user_ID;
|
269 |
+
if(current_user_can('manage_options') && isset($_POST['module_preset_save_global'])){
|
270 |
+
$args['global'] = '0';
|
271 |
+
}
|
272 |
|
273 |
$taxonomy = 'gmedia_module';
|
274 |
+
$term_id = $gmDB->term_exists($preset_name, $taxonomy, $args['global']);
|
275 |
+
if($term_id){
|
276 |
$term_id = $gmDB->update_term($term_id, $args);
|
277 |
+
} else{
|
278 |
$term_id = $gmDB->insert_term($preset_name, $taxonomy, $args);
|
279 |
}
|
280 |
+
if(is_wp_error($term_id)){
|
281 |
$this->error[] = $term_id->get_error_message();
|
282 |
break;
|
283 |
+
} else{
|
284 |
$this->msg[] = sprintf(__('Preset `%s` successfuly saved', 'grand-media'), $preset_name);
|
285 |
}
|
286 |
|
287 |
} while(0);
|
288 |
}
|
289 |
|
290 |
+
if(($delete = $gmCore->_get('delete'))){
|
291 |
check_admin_referer('gmedia_delete');
|
292 |
$taxonomy = 'gmedia_gallery';
|
293 |
+
if('selected' == $delete){
|
294 |
$selected_items = $this->selected_items;
|
295 |
+
} else{
|
296 |
$selected_items = wp_parse_id_list($delete);
|
297 |
}
|
298 |
+
if(!$gmCore->caps['gmedia_delete_others_media']){
|
299 |
$_selected_items = $gmDB->get_terms($taxonomy, array('fields' => 'ids', 'global' => $user_ID, 'include' => $selected_items));
|
300 |
+
if(count($_selected_items) < count($selected_items)){
|
301 |
$this->error[] = __('You are not allowed to delete others media', 'grand-media');
|
302 |
}
|
303 |
$selected_items = $_selected_items;
|
304 |
}
|
305 |
+
if(($count = count($selected_items))){
|
306 |
+
foreach($selected_items as $item){
|
307 |
$delete = $gmDB->delete_term($item);
|
308 |
+
if(!$delete){
|
309 |
$this->error[] = sprintf(__('Error while delete gallery #%d', 'grand-media'), $item);
|
310 |
+
$count --;
|
311 |
+
} elseif(is_wp_error($delete)){
|
312 |
$this->error[] = $delete->get_error_message();
|
313 |
+
$count --;
|
314 |
}
|
315 |
}
|
316 |
+
if($count){
|
317 |
$this->msg[] = sprintf(__('%d item(s) deleted successfuly', 'grand-media'), $count);
|
318 |
}
|
319 |
setcookie("gmuser_{$user_ID}_{$taxonomy}", '', time() - 3600);
|
admin/processor/class.processor.library.php
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
class GmediaProcessor_Library extends GmediaProcessor {
|
7 |
|
8 |
public static $cookie_key = false;
|
9 |
-
public $
|
10 |
public $selected_items = array();
|
11 |
public $stack_items = array();
|
12 |
public $query_args;
|
@@ -22,8 +22,8 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
22 |
|
23 |
$user_ID = get_current_user_id();
|
24 |
self::$cookie_key = "gmuser_{$user_ID}_library";
|
25 |
-
$this->
|
26 |
-
$this->url = add_query_arg(array('
|
27 |
$this->selected_items = parent::selected_items(self::$cookie_key);
|
28 |
$this->stack_items = parent::selected_items("gmuser_{$user_ID}_library_stack", 'stack_items');
|
29 |
|
@@ -33,7 +33,7 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
33 |
* @return array
|
34 |
*/
|
35 |
public function query_args() {
|
36 |
-
global $gmCore, $gmDB;
|
37 |
|
38 |
$args['mime_type'] = $gmCore->_get('mime_type');
|
39 |
$args['status'] = $gmCore->_get('status');
|
@@ -55,6 +55,16 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
55 |
$args['orderby'] = $gmCore->_get('orderby', $this->user_options['orderby_gmedia']);
|
56 |
$args['order'] = $gmCore->_get('order', $this->user_options['sortorder_gmedia']);
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
if($args['s'] && ('#' == substr($args['s'], 0, 1))) {
|
59 |
$args['gmedia__in'] = substr($args['s'], 1);
|
60 |
$args['s'] = false;
|
@@ -91,7 +101,9 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
91 |
if(!empty($query_args['author__in']) && $gmCore->caps['gmedia_show_others_media']) {
|
92 |
$authors_names = $query_args['author__in'];
|
93 |
foreach($authors_names as $i => $id) {
|
94 |
-
|
|
|
|
|
95 |
}
|
96 |
$this->filters['filter_author'] = array(
|
97 |
'title' => __('Filter Author', 'grand-media'),
|
@@ -174,7 +186,8 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
174 |
if(isset($_GET['display_mode'])) {
|
175 |
$display_mode = $_GET['display_mode'];
|
176 |
if(in_array($display_mode, array('grid', 'list'))) {
|
177 |
-
$
|
|
|
178 |
update_user_meta($user_ID, 'gm_screen_options', $this->user_options);
|
179 |
}
|
180 |
$location = remove_query_arg('display_mode');
|
@@ -238,32 +251,17 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
238 |
$this->error[] = $term_id->get_error_message();
|
239 |
break;
|
240 |
}
|
241 |
-
|
242 |
-
$module_settings = array($gallery_module => array());
|
243 |
-
if($gmCore->is_digit($gallery_module)) {
|
244 |
-
$preset = $gmDB->get_term($gallery_module);
|
245 |
-
if(!empty($preset) && !is_wp_error($preset)){
|
246 |
-
$gallery_module = $preset->status;
|
247 |
-
$module_settings = array(
|
248 |
-
$gallery_module => maybe_unserialize($preset->description)
|
249 |
-
);
|
250 |
-
} else {
|
251 |
-
$gallery_module = $gmGallery->options['default_gmedia_module'];
|
252 |
-
$module_settings = array(
|
253 |
-
$gallery_module => array()
|
254 |
-
);
|
255 |
-
}
|
256 |
-
}
|
257 |
$gallery['query'] = array_merge($gallery['query'], array('order' => 'ASC', 'orderby' => 'gmedia__in'));
|
258 |
|
259 |
$gallery_meta = array(
|
260 |
'_edited' => gmdate('Y-m-d H:i:s'),
|
261 |
'_query' => $gallery['query'],
|
262 |
-
'_module' => $
|
263 |
-
'_settings' => $
|
264 |
);
|
265 |
foreach($gallery_meta as $key => $value) {
|
266 |
-
$gmDB->
|
267 |
}
|
268 |
$this->msg[] = sprintf(__('Gallery "%s" successfuly saved. Shortcode: [gmedia id=%d]', 'grand-media'), esc_attr($gallery['name']), $term_id);
|
269 |
} while(0);
|
@@ -271,35 +269,35 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
271 |
|
272 |
if(isset($_POST['filter_categories'])) {
|
273 |
if(false !== ($term = $gmCore->_post('cat'))) {
|
274 |
-
$location = add_query_arg(array('
|
275 |
wp_redirect($location);
|
276 |
exit;
|
277 |
}
|
278 |
}
|
279 |
if(isset($_POST['filter_albums'])) {
|
280 |
if(false !== ($term = $gmCore->_post('alb'))) {
|
281 |
-
$location = add_query_arg(array('
|
282 |
wp_redirect($location);
|
283 |
exit;
|
284 |
}
|
285 |
}
|
286 |
if(isset($_POST['filter_tags'])) {
|
287 |
if(false !== ($term = $gmCore->_post('tag_ids'))) {
|
288 |
-
$location = add_query_arg(array('
|
289 |
wp_redirect($location);
|
290 |
exit;
|
291 |
}
|
292 |
}
|
293 |
if(isset($_POST['custom_filter'])) {
|
294 |
if(false !== ($term = $gmCore->_post('custom_filter_id'))) {
|
295 |
-
$location = add_query_arg(array('
|
296 |
wp_redirect($location);
|
297 |
exit;
|
298 |
}
|
299 |
}
|
300 |
if(isset($_POST['filter_author'])) {
|
301 |
$authors = $gmCore->_post('author_ids');
|
302 |
-
$location = add_query_arg(array('
|
303 |
wp_redirect($location);
|
304 |
exit;
|
305 |
}
|
@@ -665,7 +663,50 @@ class GmediaProcessor_Library extends GmediaProcessor {
|
|
665 |
$this->error[] = __('You are not allowed to edit media', 'grand-media');
|
666 |
}
|
667 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
668 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
if(($delete_gmedia = $gmCore->_get('delete'))) {
|
670 |
check_admin_referer('gmedia_delete');
|
671 |
if($gmCore->caps['gmedia_delete_media']) {
|
6 |
class GmediaProcessor_Library extends GmediaProcessor {
|
7 |
|
8 |
public static $cookie_key = false;
|
9 |
+
public $mode = false;
|
10 |
public $selected_items = array();
|
11 |
public $stack_items = array();
|
12 |
public $query_args;
|
22 |
|
23 |
$user_ID = get_current_user_id();
|
24 |
self::$cookie_key = "gmuser_{$user_ID}_library";
|
25 |
+
$this->mode = $gmCore->_get('mode', false);
|
26 |
+
$this->url = add_query_arg(array('mode' => $this->mode), $this->url);
|
27 |
$this->selected_items = parent::selected_items(self::$cookie_key);
|
28 |
$this->stack_items = parent::selected_items("gmuser_{$user_ID}_library_stack", 'stack_items');
|
29 |
|
33 |
* @return array
|
34 |
*/
|
35 |
public function query_args() {
|
36 |
+
global $gmCore, $gmDB, $user_ID;
|
37 |
|
38 |
$args['mime_type'] = $gmCore->_get('mime_type');
|
39 |
$args['status'] = $gmCore->_get('status');
|
55 |
$args['orderby'] = $gmCore->_get('orderby', $this->user_options['orderby_gmedia']);
|
56 |
$args['order'] = $gmCore->_get('order', $this->user_options['sortorder_gmedia']);
|
57 |
|
58 |
+
if('duplicates' === $args['gmedia__in']) {
|
59 |
+
$duplicates = $gmDB->get_duplicates();
|
60 |
+
$args['gmedia__in'] = $duplicates['duplicate_ids'];
|
61 |
+
$args['orderby'] = 'gmedia__in';
|
62 |
+
|
63 |
+
setcookie("gmuser_{$user_ID}_library", implode(',', $duplicates['duplicate_select']));
|
64 |
+
$_COOKIE["gmuser_{$user_ID}_library"] = implode(',', $duplicates['duplicate_select']);
|
65 |
+
$this->selected_items = $duplicates['duplicate_select'];
|
66 |
+
}
|
67 |
+
|
68 |
if($args['s'] && ('#' == substr($args['s'], 0, 1))) {
|
69 |
$args['gmedia__in'] = substr($args['s'], 1);
|
70 |
$args['s'] = false;
|
101 |
if(!empty($query_args['author__in']) && $gmCore->caps['gmedia_show_others_media']) {
|
102 |
$authors_names = $query_args['author__in'];
|
103 |
foreach($authors_names as $i => $id) {
|
104 |
+
if((int)$id){
|
105 |
+
$authors_names[ $i ] = get_the_author_meta('display_name', $id);
|
106 |
+
}
|
107 |
}
|
108 |
$this->filters['filter_author'] = array(
|
109 |
'title' => __('Filter Author', 'grand-media'),
|
186 |
if(isset($_GET['display_mode'])) {
|
187 |
$display_mode = $_GET['display_mode'];
|
188 |
if(in_array($display_mode, array('grid', 'list'))) {
|
189 |
+
$view = $this->gmediablank? '_frame' : '';
|
190 |
+
$this->user_options = array_merge($this->user_options, array("display_mode_gmedia{$view}" => $display_mode));
|
191 |
update_user_meta($user_ID, 'gm_screen_options', $this->user_options);
|
192 |
}
|
193 |
$location = remove_query_arg('display_mode');
|
251 |
$this->error[] = $term_id->get_error_message();
|
252 |
break;
|
253 |
}
|
254 |
+
$getModulePreset = $gmCore->getModulePreset($gallery['module']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
$gallery['query'] = array_merge($gallery['query'], array('order' => 'ASC', 'orderby' => 'gmedia__in'));
|
256 |
|
257 |
$gallery_meta = array(
|
258 |
'_edited' => gmdate('Y-m-d H:i:s'),
|
259 |
'_query' => $gallery['query'],
|
260 |
+
'_module' => $getModulePreset['module'],
|
261 |
+
'_settings' => $getModulePreset['settings']
|
262 |
);
|
263 |
foreach($gallery_meta as $key => $value) {
|
264 |
+
$gmDB->update_metadata('gmedia_term', $term_id, $key, $value);
|
265 |
}
|
266 |
$this->msg[] = sprintf(__('Gallery "%s" successfuly saved. Shortcode: [gmedia id=%d]', 'grand-media'), esc_attr($gallery['name']), $term_id);
|
267 |
} while(0);
|
269 |
|
270 |
if(isset($_POST['filter_categories'])) {
|
271 |
if(false !== ($term = $gmCore->_post('cat'))) {
|
272 |
+
$location = add_query_arg(array('category__in' => implode(',', $term)), $this->url);
|
273 |
wp_redirect($location);
|
274 |
exit;
|
275 |
}
|
276 |
}
|
277 |
if(isset($_POST['filter_albums'])) {
|
278 |
if(false !== ($term = $gmCore->_post('alb'))) {
|
279 |
+
$location = add_query_arg(array('album__in' => implode(',', $term)), $this->url);
|
280 |
wp_redirect($location);
|
281 |
exit;
|
282 |
}
|
283 |
}
|
284 |
if(isset($_POST['filter_tags'])) {
|
285 |
if(false !== ($term = $gmCore->_post('tag_ids'))) {
|
286 |
+
$location = add_query_arg(array('tag__in' => $term), $this->url);
|
287 |
wp_redirect($location);
|
288 |
exit;
|
289 |
}
|
290 |
}
|
291 |
if(isset($_POST['custom_filter'])) {
|
292 |
if(false !== ($term = $gmCore->_post('custom_filter_id'))) {
|
293 |
+
$location = add_query_arg(array('custom_filter' => $term), $this->url);
|
294 |
wp_redirect($location);
|
295 |
exit;
|
296 |
}
|
297 |
}
|
298 |
if(isset($_POST['filter_author'])) {
|
299 |
$authors = $gmCore->_post('author_ids');
|
300 |
+
$location = add_query_arg(array('author' => (int)$authors), $this->url);
|
301 |
wp_redirect($location);
|
302 |
exit;
|
303 |
}
|
663 |
$this->error[] = __('You are not allowed to edit media', 'grand-media');
|
664 |
}
|
665 |
}
|
666 |
+
if('selected' == $gmCore->_get('recreate')) {
|
667 |
+
check_admin_referer('gmedia_recreate');
|
668 |
+
if($gmCore->caps['gmedia_edit_media']) {
|
669 |
+
$selected_items = $this->selected_items;
|
670 |
+
$count = count($selected_items);
|
671 |
+
if($count) {
|
672 |
+
if(!$gmCore->caps['gmedia_edit_others_media']) {
|
673 |
+
$edit_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'mime_type' => 'image', 'gmedia__in' => $selected_items));
|
674 |
+
$selected_items = $edit_items;
|
675 |
+
} else {
|
676 |
+
$selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'mime_type' => 'image', 'gmedia__in' => $selected_items));
|
677 |
+
}
|
678 |
+
if(($count = count($selected_items))) {
|
679 |
+
$ajax_operations = get_option('gmedia_ajax_long_operations', array());
|
680 |
+
foreach($selected_items as $si){
|
681 |
+
$ajax_operations['gmedia_recreate_images'][$si] = $si;
|
682 |
+
}
|
683 |
+
update_option('gmedia_ajax_long_operations', $ajax_operations);
|
684 |
+
$this->msg[] = sprintf(__('You\'ve added 4 image(s) to the re-creation queue.', 'grand-media'), $count);
|
685 |
+
}
|
686 |
+
}
|
687 |
+
$this->selected_items = $this->clear_selected_items('library');
|
688 |
+
} else {
|
689 |
+
$this->error[] = __('You are not allowed to edit media', 'grand-media');
|
690 |
+
}
|
691 |
+
}
|
692 |
}
|
693 |
+
if(($duplicate_gmedia = $gmCore->_get('duplicate'))) {
|
694 |
+
check_admin_referer('gmedia_duplicate');
|
695 |
+
if($gmCore->caps['gmedia_upload'] || $gmCore->caps['gmedia_import']) {
|
696 |
+
$selected_items = wp_parse_id_list($duplicate_gmedia);
|
697 |
+
if(!empty($selected_items)) {
|
698 |
+
if(($count = count($selected_items))) {
|
699 |
+
foreach($selected_items as $gmid) {
|
700 |
+
$gmCore->duplicate_gmedia($gmid);
|
701 |
+
}
|
702 |
+
$this->msg[] = sprintf(__('%d item duplicated (without terms)', 'grand-media'), $count);
|
703 |
+
}
|
704 |
+
}
|
705 |
+
} else {
|
706 |
+
$this->error[] = __('You are not allowed to upload files', 'grand-media');
|
707 |
+
}
|
708 |
+
}
|
709 |
+
|
710 |
if(($delete_gmedia = $gmCore->_get('delete'))) {
|
711 |
check_admin_referer('gmedia_delete');
|
712 |
if($gmCore->caps['gmedia_delete_media']) {
|
admin/processor/class.processor.modules.php
CHANGED
@@ -3,35 +3,134 @@
|
|
3 |
/**
|
4 |
* GmediaProcessor_Modules
|
5 |
*/
|
6 |
-
class GmediaProcessor_Modules extends GmediaProcessor
|
7 |
|
8 |
-
protected function processor()
|
9 |
-
global $gmCore, $gmGallery;
|
10 |
|
11 |
-
if(!$gmCore->caps['gmedia_gallery_manage'])
|
12 |
wp_die(__('You are not allowed to manage gmedia galleries', 'grand-media'));
|
13 |
}
|
14 |
-
if(!$gmCore->caps['gmedia_module_manage'])
|
15 |
wp_die(__('You are not allowed to manage gmedia modules', 'grand-media'));
|
16 |
}
|
17 |
|
18 |
include_once(GMEDIA_ABSPATH . 'admin/pages/modules/functions.php');
|
19 |
|
20 |
-
if(isset($
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
check_admin_referer('GmediaModule');
|
23 |
-
if(!current_user_can('manage_options'))
|
24 |
wp_die(__('You are not allowed to install module ZIP', 'grand-media'));
|
25 |
}
|
26 |
$to_folder = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/';
|
27 |
-
if(!wp_mkdir_p($to_folder))
|
28 |
$this->error[] = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $to_folder);
|
29 |
|
30 |
return;
|
31 |
}
|
32 |
-
if(!is_writable($to_folder))
|
33 |
@chmod($to_folder, 0755);
|
34 |
-
if(!is_writable($to_folder))
|
35 |
//@unlink( $_FILES['modulezip']['tmp_name'] );
|
36 |
$this->error[] = sprintf(__('Directory %s is not writable by the server.', 'grand-media'), $to_folder);
|
37 |
|
@@ -41,20 +140,20 @@ class GmediaProcessor_Modules extends GmediaProcessor {
|
|
41 |
$filename = wp_unique_filename($to_folder, $_FILES['modulezip']['name']);
|
42 |
|
43 |
// Move the file to the modules dir
|
44 |
-
if(false === @move_uploaded_file($_FILES['modulezip']['tmp_name'], $to_folder . $filename))
|
45 |
$this->error[] = sprintf(__('The uploaded file could not be moved to %s', 'flag'), $to_folder . $filename);
|
46 |
-
} else
|
47 |
global $wp_filesystem;
|
48 |
// Is a filesystem accessor setup?
|
49 |
-
if(!$wp_filesystem || !is_object($wp_filesystem))
|
50 |
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
51 |
WP_Filesystem();
|
52 |
}
|
53 |
-
if(!is_object($wp_filesystem))
|
54 |
$result = new WP_Error('fs_unavailable', __('Could not access filesystem.', 'flag'));
|
55 |
-
} elseif($wp_filesystem->errors->get_error_code())
|
56 |
$result = new WP_Error('fs_error', __('Filesystem error', 'flag'), $wp_filesystem->errors);
|
57 |
-
} else
|
58 |
$maybe_folder_dir = basename($_FILES['modulezip']['name'], '.zip');
|
59 |
$maybe_folder_dir = sanitize_file_name($maybe_folder_dir);
|
60 |
if($maybe_folder_dir && is_dir($to_folder . $maybe_folder_dir)){
|
@@ -64,29 +163,29 @@ class GmediaProcessor_Modules extends GmediaProcessor {
|
|
64 |
}
|
65 |
// Once extracted, delete the package
|
66 |
unlink($to_folder . $filename);
|
67 |
-
if(is_wp_error($result))
|
68 |
$this->error[] = $result->get_error_message();
|
69 |
-
} else
|
70 |
$this->msg[] = sprintf(__("The `%s` file unzipped to module's directory", 'flag'), $filename);
|
71 |
}
|
72 |
}
|
73 |
-
} else
|
74 |
$this->error[] = __('No file specified', 'grand-media');
|
75 |
}
|
76 |
}
|
77 |
|
78 |
-
if(isset($_GET['delete_module']))
|
79 |
-
if($gmCore->_get('_wpnonce'))
|
80 |
$mfold = preg_replace('/[^a-z0-9_-]+/i', '_', $_GET['delete_module']);
|
81 |
$mpath = "{$gmCore->upload['path']}/{$gmGallery->options['folder']['module']}/{$mfold}";
|
82 |
-
if($mfold && file_exists($mpath))
|
83 |
check_admin_referer('gmedia_module_delete');
|
84 |
$gmCore->delete_folder($mpath);
|
85 |
$location = remove_query_arg(array('_wpnonce'));
|
86 |
set_transient('gmedia_module_deleted', sprintf(__("The `%s` module folder was deleted", 'flag'), $mpath), 60);
|
87 |
wp_redirect($location);
|
88 |
}
|
89 |
-
} elseif(false !== ($message = get_transient('gmedia_module_deleted')))
|
90 |
delete_transient('gmedia_module_deleted');
|
91 |
$this->msg[] = $message;
|
92 |
}
|
3 |
/**
|
4 |
* GmediaProcessor_Modules
|
5 |
*/
|
6 |
+
class GmediaProcessor_Modules extends GmediaProcessor{
|
7 |
|
8 |
+
protected function processor(){
|
9 |
+
global $gmDB, $gmCore, $gmGallery, $user_ID;
|
10 |
|
11 |
+
if(!$gmCore->caps['gmedia_gallery_manage']){
|
12 |
wp_die(__('You are not allowed to manage gmedia galleries', 'grand-media'));
|
13 |
}
|
14 |
+
if(!$gmCore->caps['gmedia_module_manage']){
|
15 |
wp_die(__('You are not allowed to manage gmedia modules', 'grand-media'));
|
16 |
}
|
17 |
|
18 |
include_once(GMEDIA_ABSPATH . 'admin/pages/modules/functions.php');
|
19 |
|
20 |
+
if(isset($_POST['module_preset_save']) || isset($_POST['module_preset_save_default']) || isset($_POST['module_preset_save_global'])){
|
21 |
+
check_admin_referer('GmediaGallery');
|
22 |
+
|
23 |
+
if(isset($_POST['preview_bgcolor'])){
|
24 |
+
$gmGallery->options['preview_bgcolor'] = $gmCore->sanitize_hex_color($_POST['preview_bgcolor'], 'ffffff');
|
25 |
+
update_option('gmediaOptions', $gmGallery->options);
|
26 |
+
}
|
27 |
+
|
28 |
+
$edit_preset = (int)$gmCore->_get('preset');
|
29 |
+
do{
|
30 |
+
$term = $gmCore->_post('term');
|
31 |
+
|
32 |
+
if(isset($term['query'])){
|
33 |
+
wp_parse_str($term['query'], $_query);
|
34 |
+
update_user_option($user_ID, 'gmedia_preset_demo_query_args', $_query);
|
35 |
+
}
|
36 |
+
|
37 |
+
if(((int)$term['global'] != $user_ID) && !$gmCore->caps['gmedia_edit_others_media']){
|
38 |
+
$this->error[] = __('You are not allowed to edit others media', 'grand-media');
|
39 |
+
break;
|
40 |
+
}
|
41 |
+
|
42 |
+
if(empty($term['module'])){
|
43 |
+
$this->error[] = __('Something goes wrong... Choose module, please', 'grand-media');
|
44 |
+
break;
|
45 |
+
}
|
46 |
+
|
47 |
+
$taxonomy = 'gmedia_module';
|
48 |
+
if(isset($_POST['module_preset_save_default']) || isset($_POST['module_preset_save_global'])){
|
49 |
+
$term['name'] = '[' . $term['module'] . ']';
|
50 |
+
if(current_user_can('manage_options') && isset($_POST['module_preset_save_global'])){
|
51 |
+
$term['global'] = '0';
|
52 |
+
}
|
53 |
+
$edit_preset = $term['term_id'] = $gmDB->term_exists($term['name'], $taxonomy, $term['global']);
|
54 |
+
} else{
|
55 |
+
$term['name'] = trim($term['name']);
|
56 |
+
if(empty($term['name'])){
|
57 |
+
$term['name'] = current_time('mysql');
|
58 |
+
}
|
59 |
+
if($gmCore->is_digit($term['name'])){
|
60 |
+
$this->error[] = __("Preset name can't be only digits", 'grand-media');
|
61 |
+
break;
|
62 |
+
}
|
63 |
+
$term['name'] = '[' . $term['module'] . '] ' . $term['name'];
|
64 |
+
|
65 |
+
if($edit_preset && !$gmDB->term_exists($edit_preset)){
|
66 |
+
$this->error[] = __('A term with the id provided do not exists', 'grand-media');
|
67 |
+
$edit_preset = false;
|
68 |
+
}
|
69 |
+
if(($term_id = $gmDB->term_exists($term['name'], $taxonomy, $term['global']))){
|
70 |
+
if($term_id != $edit_preset){
|
71 |
+
$this->error[] = __('A term with the name provided already exists', 'grand-media');
|
72 |
+
break;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
$module_settings = $gmCore->_post('module', array());
|
79 |
+
$module_path = $gmCore->get_module_path($term['module']);
|
80 |
+
$default_options = array();
|
81 |
+
if(file_exists($module_path['path'] . '/settings.php')){
|
82 |
+
/** @noinspection PhpIncludeInspection */
|
83 |
+
include($module_path['path'] . '/settings.php');
|
84 |
+
} else{
|
85 |
+
$this->error[] = sprintf(__('Can\'t load data from `%s` module'), $term['module']);
|
86 |
+
break;
|
87 |
+
}
|
88 |
+
$term['description'] = $gmCore->array_replace_recursive($default_options, $module_settings);
|
89 |
+
$term['status'] = $term['module'];
|
90 |
+
|
91 |
+
if($edit_preset){
|
92 |
+
$term_id = $gmDB->update_term($edit_preset, $term);
|
93 |
+
} else{
|
94 |
+
$term_id = $gmDB->insert_term($term['name'], $taxonomy, $term);
|
95 |
+
}
|
96 |
+
if(is_wp_error($term_id)){
|
97 |
+
$this->error[] = $term_id->get_error_message();
|
98 |
+
break;
|
99 |
+
}
|
100 |
+
|
101 |
+
if($edit_preset){
|
102 |
+
$this->msg[] = sprintf(__('Preset #%d successfuly saved', 'grand-media'), $term_id);
|
103 |
+
} else{
|
104 |
+
$location = add_query_arg(array('preset' => $term_id, 'message' => 'save'), $this->url);
|
105 |
+
set_transient('gmedia_new_preset_id', $term_id, 60);
|
106 |
+
wp_redirect($location);
|
107 |
+
exit;
|
108 |
+
}
|
109 |
+
} while(0);
|
110 |
+
}
|
111 |
+
if(('save' == $gmCore->_get('message')) && ($term_id = $gmCore->_get('preset'))){
|
112 |
+
$gmedia_new_preset_id = get_transient('gmedia_new_preset_id');
|
113 |
+
if(false !== $gmedia_new_preset_id){
|
114 |
+
delete_transient('gmedia_new_preset_id');
|
115 |
+
$this->msg[] = sprintf(__('Preset #%d successfuly saved', 'grand-media'), $term_id);
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
if(isset($_FILES['modulezip']['tmp_name'])){
|
120 |
+
if(!empty($_FILES['modulezip']['tmp_name'])){
|
121 |
check_admin_referer('GmediaModule');
|
122 |
+
if(!current_user_can('manage_options')){
|
123 |
wp_die(__('You are not allowed to install module ZIP', 'grand-media'));
|
124 |
}
|
125 |
$to_folder = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/';
|
126 |
+
if(!wp_mkdir_p($to_folder)){
|
127 |
$this->error[] = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $to_folder);
|
128 |
|
129 |
return;
|
130 |
}
|
131 |
+
if(!is_writable($to_folder)){
|
132 |
@chmod($to_folder, 0755);
|
133 |
+
if(!is_writable($to_folder)){
|
134 |
//@unlink( $_FILES['modulezip']['tmp_name'] );
|
135 |
$this->error[] = sprintf(__('Directory %s is not writable by the server.', 'grand-media'), $to_folder);
|
136 |
|
140 |
$filename = wp_unique_filename($to_folder, $_FILES['modulezip']['name']);
|
141 |
|
142 |
// Move the file to the modules dir
|
143 |
+
if(false === @move_uploaded_file($_FILES['modulezip']['tmp_name'], $to_folder . $filename)){
|
144 |
$this->error[] = sprintf(__('The uploaded file could not be moved to %s', 'flag'), $to_folder . $filename);
|
145 |
+
} else{
|
146 |
global $wp_filesystem;
|
147 |
// Is a filesystem accessor setup?
|
148 |
+
if(!$wp_filesystem || !is_object($wp_filesystem)){
|
149 |
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
150 |
WP_Filesystem();
|
151 |
}
|
152 |
+
if(!is_object($wp_filesystem)){
|
153 |
$result = new WP_Error('fs_unavailable', __('Could not access filesystem.', 'flag'));
|
154 |
+
} elseif($wp_filesystem->errors->get_error_code()){
|
155 |
$result = new WP_Error('fs_error', __('Filesystem error', 'flag'), $wp_filesystem->errors);
|
156 |
+
} else{
|
157 |
$maybe_folder_dir = basename($_FILES['modulezip']['name'], '.zip');
|
158 |
$maybe_folder_dir = sanitize_file_name($maybe_folder_dir);
|
159 |
if($maybe_folder_dir && is_dir($to_folder . $maybe_folder_dir)){
|
163 |
}
|
164 |
// Once extracted, delete the package
|
165 |
unlink($to_folder . $filename);
|
166 |
+
if(is_wp_error($result)){
|
167 |
$this->error[] = $result->get_error_message();
|
168 |
+
} else{
|
169 |
$this->msg[] = sprintf(__("The `%s` file unzipped to module's directory", 'flag'), $filename);
|
170 |
}
|
171 |
}
|
172 |
+
} else{
|
173 |
$this->error[] = __('No file specified', 'grand-media');
|
174 |
}
|
175 |
}
|
176 |
|
177 |
+
if(isset($_GET['delete_module'])){
|
178 |
+
if($gmCore->_get('_wpnonce')){
|
179 |
$mfold = preg_replace('/[^a-z0-9_-]+/i', '_', $_GET['delete_module']);
|
180 |
$mpath = "{$gmCore->upload['path']}/{$gmGallery->options['folder']['module']}/{$mfold}";
|
181 |
+
if($mfold && file_exists($mpath)){
|
182 |
check_admin_referer('gmedia_module_delete');
|
183 |
$gmCore->delete_folder($mpath);
|
184 |
$location = remove_query_arg(array('_wpnonce'));
|
185 |
set_transient('gmedia_module_deleted', sprintf(__("The `%s` module folder was deleted", 'flag'), $mpath), 60);
|
186 |
wp_redirect($location);
|
187 |
}
|
188 |
+
} elseif(false !== ($message = get_transient('gmedia_module_deleted'))){
|
189 |
delete_transient('gmedia_module_deleted');
|
190 |
$this->msg[] = $message;
|
191 |
}
|
admin/processor/class.processor.settings.php
CHANGED
@@ -3,175 +3,176 @@
|
|
3 |
/**
|
4 |
* GmediaProcessor_Settings
|
5 |
*/
|
6 |
-
class GmediaProcessor_Settings extends GmediaProcessor
|
7 |
|
8 |
-
protected function processor()
|
9 |
global $gmCore, $gmGallery, $gmDB;
|
10 |
|
11 |
-
if(!$gmCore->caps['gmedia_settings'])
|
12 |
wp_die(__('You are not allowed to change gmedia settings', 'grand-media'));
|
13 |
}
|
14 |
$lk_check = isset($_POST['license-key-activate']);
|
15 |
-
if(isset($_POST['gmedia_settings_save']))
|
16 |
check_admin_referer('GmediaSettings');
|
17 |
|
18 |
$set = $gmCore->_post('set', array());
|
19 |
|
20 |
-
if(!empty($set['
|
21 |
$lk_check = true;
|
22 |
}
|
23 |
-
if(empty($set['
|
24 |
$set['license_name'] = '';
|
|
|
25 |
$set['license_key'] = '';
|
26 |
$set['license_key2'] = '';
|
27 |
-
$this->error[] = __('License Key
|
28 |
}
|
29 |
|
30 |
$flush_rewrite_rules = false;
|
31 |
-
if(empty($set['endpoint']))
|
32 |
$set['endpoint'] = 'gmedia';
|
33 |
}
|
34 |
-
if(
|
35 |
-
$set['endpoint'] !== $gmGallery->options['endpoint'] ||
|
36 |
-
$set['gmedia_post_slug'] !== $gmGallery->options['gmedia_post_slug'] ||
|
37 |
-
$set['gmedia_album_post_slug'] !== $gmGallery->options['gmedia_album_post_slug'] ||
|
38 |
-
$set['gmedia_gallery_post_slug'] !== $gmGallery->options['gmedia_gallery_post_slug']
|
39 |
-
) {
|
40 |
$flush_rewrite_rules = true;
|
41 |
}
|
42 |
|
43 |
-
foreach($set as $key => $val)
|
44 |
-
$gmGallery->options[$key] = $val;
|
45 |
}
|
46 |
|
47 |
$capabilities = $gmCore->_post('capability', array());
|
48 |
-
if(!empty($capabilities) && current_user_can('manage_options'))
|
49 |
global $wp_roles;
|
50 |
$_roles = $wp_roles->roles;
|
51 |
$_roles = array_keys(apply_filters('editable_roles', $_roles));
|
52 |
$roles = array_flip($_roles);
|
53 |
|
54 |
// upload cap.
|
55 |
-
if($roles[$capabilities['gmedia_upload']] < $roles[$capabilities['gmedia_import']])
|
56 |
$capabilities['gmedia_import'] = $capabilities['gmedia_upload'];
|
57 |
}
|
58 |
// edit/delete cap.
|
59 |
-
if($roles[$capabilities['gmedia_edit_media']] < $roles[$capabilities['gmedia_edit_others_media']])
|
60 |
$capabilities['gmedia_edit_others_media'] = $capabilities['gmedia_edit_media'];
|
61 |
}
|
62 |
-
if($roles[$capabilities['gmedia_edit_media']] < $roles[$capabilities['gmedia_delete_media']])
|
63 |
$capabilities['gmedia_delete_media'] = $capabilities['gmedia_edit_media'];
|
64 |
}
|
65 |
-
if($roles[$capabilities['gmedia_delete_media']] < $roles[$capabilities['gmedia_delete_others_media']])
|
66 |
$capabilities['gmedia_delete_others_media'] = $capabilities['gmedia_delete_media'];
|
67 |
}
|
68 |
-
if($roles[$capabilities['gmedia_edit_others_media']] < $roles[$capabilities['gmedia_delete_others_media']])
|
69 |
$capabilities['gmedia_delete_others_media'] = $capabilities['gmedia_edit_others_media'];
|
70 |
}
|
71 |
-
if($roles[$capabilities['gmedia_show_others_media']] < $roles[$capabilities['gmedia_edit_others_media']])
|
72 |
$capabilities['gmedia_edit_others_media'] = $capabilities['gmedia_show_others_media'];
|
73 |
}
|
74 |
-
if($roles[$capabilities['gmedia_show_others_media']] < $roles[$capabilities['gmedia_delete_others_media']])
|
75 |
$capabilities['gmedia_delete_others_media'] = $capabilities['gmedia_show_others_media'];
|
76 |
}
|
77 |
// terms cap.
|
78 |
-
if($roles[$capabilities['gmedia_terms']] < $roles[$capabilities['gmedia_album_manage']])
|
79 |
$capabilities['gmedia_album_manage'] = $capabilities['gmedia_terms'];
|
80 |
}
|
81 |
-
if($roles[$capabilities['gmedia_terms']] < $roles[$capabilities['gmedia_category_manage']])
|
82 |
$capabilities['gmedia_category_manage'] = $capabilities['gmedia_terms'];
|
83 |
}
|
84 |
-
if($roles[$capabilities['gmedia_terms']] < $roles[$capabilities['gmedia_tag_manage']])
|
85 |
$capabilities['gmedia_tag_manage'] = $capabilities['gmedia_terms'];
|
86 |
}
|
87 |
-
if($roles[$capabilities['gmedia_terms']] < $roles[$capabilities['gmedia_terms_delete']])
|
88 |
$capabilities['gmedia_terms_delete'] = $capabilities['gmedia_terms'];
|
89 |
-
} else
|
90 |
-
$rolekey = max($roles[$capabilities['gmedia_album_manage']], $roles[$capabilities['gmedia_tag_manage']]);
|
91 |
-
$role = $_roles[$rolekey];
|
92 |
-
if($role < $roles[$capabilities['gmedia_terms_delete']])
|
93 |
$capabilities['gmedia_terms_delete'] = $role;
|
94 |
}
|
95 |
}
|
96 |
|
97 |
-
foreach($capabilities as $key => $val)
|
98 |
$gmDB->set_capability($val, $key);
|
99 |
}
|
100 |
}
|
101 |
|
102 |
update_option('gmediaOptions', $gmGallery->options);
|
103 |
-
if(isset($_POST['GmediaHashID_salt']))
|
104 |
update_option('GmediaHashID_salt', (string)$_POST['GmediaHashID_salt']);
|
105 |
}
|
106 |
-
if($flush_rewrite_rules)
|
107 |
flush_rewrite_rules(false);
|
108 |
}
|
109 |
$this->msg[] .= __('Settings saved', 'grand-media');
|
110 |
}
|
111 |
|
112 |
-
if($lk_check)
|
113 |
check_admin_referer('GmediaSettings');
|
114 |
$license_key = $gmCore->_post('set');
|
115 |
-
if(!empty($license_key['
|
116 |
global $wp_version;
|
117 |
$gmedia_ua = "WordPress/{$wp_version} | ";
|
118 |
$gmedia_ua .= 'Gmedia/' . constant('GMEDIA_VERSION');
|
119 |
|
120 |
-
$response = wp_remote_post('http://codeasily.com/rest/gmedia-key.php', array(
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
'httpversion' => '1.0',
|
128 |
-
'timeout' => 30
|
129 |
));
|
130 |
|
131 |
-
if(is_wp_error($response))
|
132 |
$this->error[] = $response->get_error_message();
|
133 |
$this->error[] = __('Use Help Screen (top right button) for more info', 'grand-media');
|
134 |
-
} else
|
135 |
$result = json_decode($response['body']);
|
136 |
-
if($result->error
|
137 |
-
$
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
}
|
147 |
-
update_option('gmediaOptions', $gmGallery->options);
|
148 |
}
|
149 |
-
} else
|
150 |
$this->error[] = __('Empty License Key', 'grand-media');
|
151 |
}
|
152 |
}
|
153 |
|
154 |
-
if(isset($_POST['gmedia_settings_reset']))
|
155 |
check_admin_referer('GmediaSettings');
|
156 |
include_once(GMEDIA_ABSPATH . 'config/setup.php');
|
157 |
-
$_temp_options
|
158 |
-
$gmGallery->options
|
159 |
// don't reset license
|
160 |
$gmGallery->options['license_name'] = $_temp_options['license_name'];
|
|
|
161 |
$gmGallery->options['license_key'] = $_temp_options['license_key'];
|
162 |
$gmGallery->options['license_key2'] = $_temp_options['license_key2'];
|
163 |
// don't reset mobile app
|
164 |
$gmGallery->options['site_email'] = $_temp_options['site_email'];
|
165 |
-
$gmGallery->options['site_ID']
|
166 |
$gmGallery->options['mobile_app'] = $_temp_options['mobile_app'];
|
167 |
delete_metadata('user', 0, 'gm_screen_options', '', true);
|
168 |
update_option('gmediaOptions', $gmGallery->options);
|
169 |
|
170 |
-
if($gmCore->_post('capability') && current_user_can('manage_options'))
|
171 |
$capabilities = $gmCore->plugin_capabilities();
|
172 |
$capabilities = apply_filters('gmedia_capabilities', $capabilities);
|
173 |
//$role = get_role('administrator');
|
174 |
-
foreach($capabilities as $cap)
|
175 |
$gmDB->set_capability('administrator', $cap);
|
176 |
}
|
177 |
}
|
3 |
/**
|
4 |
* GmediaProcessor_Settings
|
5 |
*/
|
6 |
+
class GmediaProcessor_Settings extends GmediaProcessor{
|
7 |
|
8 |
+
protected function processor(){
|
9 |
global $gmCore, $gmGallery, $gmDB;
|
10 |
|
11 |
+
if(!$gmCore->caps['gmedia_settings']){
|
12 |
wp_die(__('You are not allowed to change gmedia settings', 'grand-media'));
|
13 |
}
|
14 |
$lk_check = isset($_POST['license-key-activate']);
|
15 |
+
if(isset($_POST['gmedia_settings_save'])){
|
16 |
check_admin_referer('GmediaSettings');
|
17 |
|
18 |
$set = $gmCore->_post('set', array());
|
19 |
|
20 |
+
if(!empty($set['purchase_key']) && (empty($set['license_key']) || empty($set['license_key2']))){
|
21 |
$lk_check = true;
|
22 |
}
|
23 |
+
if(empty($set['purchase_key']) && (!empty($set['license_key']) || !empty($set['license_key2']))){
|
24 |
$set['license_name'] = '';
|
25 |
+
$set['purchase_key'] = '';
|
26 |
$set['license_key'] = '';
|
27 |
$set['license_key2'] = '';
|
28 |
+
$this->error[] = __('License Key empty...', 'grand-media');
|
29 |
}
|
30 |
|
31 |
$flush_rewrite_rules = false;
|
32 |
+
if(empty($set['endpoint'])){
|
33 |
$set['endpoint'] = 'gmedia';
|
34 |
}
|
35 |
+
if($set['endpoint'] !== $gmGallery->options['endpoint'] || $set['gmedia_post_slug'] !== $gmGallery->options['gmedia_post_slug'] || $set['gmedia_album_post_slug'] !== $gmGallery->options['gmedia_album_post_slug'] || $set['gmedia_gallery_post_slug'] !== $gmGallery->options['gmedia_gallery_post_slug']){
|
|
|
|
|
|
|
|
|
|
|
36 |
$flush_rewrite_rules = true;
|
37 |
}
|
38 |
|
39 |
+
foreach($set as $key => $val){
|
40 |
+
$gmGallery->options[ $key ] = $val;
|
41 |
}
|
42 |
|
43 |
$capabilities = $gmCore->_post('capability', array());
|
44 |
+
if(!empty($capabilities) && current_user_can('manage_options')){
|
45 |
global $wp_roles;
|
46 |
$_roles = $wp_roles->roles;
|
47 |
$_roles = array_keys(apply_filters('editable_roles', $_roles));
|
48 |
$roles = array_flip($_roles);
|
49 |
|
50 |
// upload cap.
|
51 |
+
if($roles[ $capabilities['gmedia_upload'] ] < $roles[ $capabilities['gmedia_import'] ]){
|
52 |
$capabilities['gmedia_import'] = $capabilities['gmedia_upload'];
|
53 |
}
|
54 |
// edit/delete cap.
|
55 |
+
if($roles[ $capabilities['gmedia_edit_media'] ] < $roles[ $capabilities['gmedia_edit_others_media'] ]){
|
56 |
$capabilities['gmedia_edit_others_media'] = $capabilities['gmedia_edit_media'];
|
57 |
}
|
58 |
+
if($roles[ $capabilities['gmedia_edit_media'] ] < $roles[ $capabilities['gmedia_delete_media'] ]){
|
59 |
$capabilities['gmedia_delete_media'] = $capabilities['gmedia_edit_media'];
|
60 |
}
|
61 |
+
if($roles[ $capabilities['gmedia_delete_media'] ] < $roles[ $capabilities['gmedia_delete_others_media'] ]){
|
62 |
$capabilities['gmedia_delete_others_media'] = $capabilities['gmedia_delete_media'];
|
63 |
}
|
64 |
+
if($roles[ $capabilities['gmedia_edit_others_media'] ] < $roles[ $capabilities['gmedia_delete_others_media'] ]){
|
65 |
$capabilities['gmedia_delete_others_media'] = $capabilities['gmedia_edit_others_media'];
|
66 |
}
|
67 |
+
if($roles[ $capabilities['gmedia_show_others_media'] ] < $roles[ $capabilities['gmedia_edit_others_media'] ]){
|
68 |
$capabilities['gmedia_edit_others_media'] = $capabilities['gmedia_show_others_media'];
|
69 |
}
|
70 |
+
if($roles[ $capabilities['gmedia_show_others_media'] ] < $roles[ $capabilities['gmedia_delete_others_media'] ]){
|
71 |
$capabilities['gmedia_delete_others_media'] = $capabilities['gmedia_show_others_media'];
|
72 |
}
|
73 |
// terms cap.
|
74 |
+
if($roles[ $capabilities['gmedia_terms'] ] < $roles[ $capabilities['gmedia_album_manage'] ]){
|
75 |
$capabilities['gmedia_album_manage'] = $capabilities['gmedia_terms'];
|
76 |
}
|
77 |
+
if($roles[ $capabilities['gmedia_terms'] ] < $roles[ $capabilities['gmedia_category_manage'] ]){
|
78 |
$capabilities['gmedia_category_manage'] = $capabilities['gmedia_terms'];
|
79 |
}
|
80 |
+
if($roles[ $capabilities['gmedia_terms'] ] < $roles[ $capabilities['gmedia_tag_manage'] ]){
|
81 |
$capabilities['gmedia_tag_manage'] = $capabilities['gmedia_terms'];
|
82 |
}
|
83 |
+
if($roles[ $capabilities['gmedia_terms'] ] < $roles[ $capabilities['gmedia_terms_delete'] ]){
|
84 |
$capabilities['gmedia_terms_delete'] = $capabilities['gmedia_terms'];
|
85 |
+
} else{
|
86 |
+
$rolekey = max($roles[ $capabilities['gmedia_album_manage'] ], $roles[ $capabilities['gmedia_tag_manage'] ]);
|
87 |
+
$role = $_roles[ $rolekey ];
|
88 |
+
if($role < $roles[ $capabilities['gmedia_terms_delete'] ]){
|
89 |
$capabilities['gmedia_terms_delete'] = $role;
|
90 |
}
|
91 |
}
|
92 |
|
93 |
+
foreach($capabilities as $key => $val){
|
94 |
$gmDB->set_capability($val, $key);
|
95 |
}
|
96 |
}
|
97 |
|
98 |
update_option('gmediaOptions', $gmGallery->options);
|
99 |
+
if(isset($_POST['GmediaHashID_salt'])){
|
100 |
update_option('GmediaHashID_salt', (string)$_POST['GmediaHashID_salt']);
|
101 |
}
|
102 |
+
if($flush_rewrite_rules){
|
103 |
flush_rewrite_rules(false);
|
104 |
}
|
105 |
$this->msg[] .= __('Settings saved', 'grand-media');
|
106 |
}
|
107 |
|
108 |
+
if($lk_check){
|
109 |
check_admin_referer('GmediaSettings');
|
110 |
$license_key = $gmCore->_post('set');
|
111 |
+
if(!empty($license_key['purchase_key'])){
|
112 |
global $wp_version;
|
113 |
$gmedia_ua = "WordPress/{$wp_version} | ";
|
114 |
$gmedia_ua .= 'Gmedia/' . constant('GMEDIA_VERSION');
|
115 |
|
116 |
+
$response = wp_remote_post('http://codeasily.com/rest/gmedia-key.php', array('body' => array('key' => $license_key['purchase_key'], 'site' => site_url()),
|
117 |
+
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; ' . 'charset=' . get_option('blog_charset'),
|
118 |
+
'Host' => 'codeasily.com',
|
119 |
+
'User-Agent' => $gmedia_ua
|
120 |
+
),
|
121 |
+
'httpversion' => '1.0',
|
122 |
+
'timeout' => 45
|
|
|
|
|
123 |
));
|
124 |
|
125 |
+
if(is_wp_error($response)){
|
126 |
$this->error[] = $response->get_error_message();
|
127 |
$this->error[] = __('Use Help Screen (top right button) for more info', 'grand-media');
|
128 |
+
} else{
|
129 |
$result = json_decode($response['body']);
|
130 |
+
if(isset($result->error)){
|
131 |
+
if($result && $result->error->code == 200){
|
132 |
+
$gmGallery->options['license_name'] = $result->content;
|
133 |
+
$gmGallery->options['purchase_key'] = $result->dkey;
|
134 |
+
$gmGallery->options['license_key'] = $result->key;
|
135 |
+
$gmGallery->options['license_key2'] = $result->key2;
|
136 |
+
$this->msg[] = sprintf(__('License Key activated successfully. You can see all activated websites with this key on your account page %s', 'grand-media'), '<a href="http://codeasily.com/my-account/" target="_blank">http://codeasily.com/my-account/</a>');
|
137 |
+
} else{
|
138 |
+
$gmGallery->options['license_name'] = '';
|
139 |
+
$gmGallery->options['purchase_key'] = '';
|
140 |
+
$gmGallery->options['license_key'] = '';
|
141 |
+
$gmGallery->options['license_key2'] = '';
|
142 |
+
$this->error[] = __('Error', 'grand-media') . ': ' . $result->error->message;
|
143 |
+
}
|
144 |
+
update_option('gmediaOptions', $gmGallery->options);
|
145 |
+
} else{
|
146 |
+
$this->error[] = __('Something went wrong.. Try again later or use Help Screen (top right button) for more info', 'grand-media');
|
147 |
}
|
|
|
148 |
}
|
149 |
+
} else{
|
150 |
$this->error[] = __('Empty License Key', 'grand-media');
|
151 |
}
|
152 |
}
|
153 |
|
154 |
+
if(isset($_POST['gmedia_settings_reset'])){
|
155 |
check_admin_referer('GmediaSettings');
|
156 |
include_once(GMEDIA_ABSPATH . 'config/setup.php');
|
157 |
+
$_temp_options = $gmGallery->options;
|
158 |
+
$gmGallery->options = gmedia_default_options();
|
159 |
// don't reset license
|
160 |
$gmGallery->options['license_name'] = $_temp_options['license_name'];
|
161 |
+
$gmGallery->options['purchase_key'] = $_temp_options['purchase_key'];
|
162 |
$gmGallery->options['license_key'] = $_temp_options['license_key'];
|
163 |
$gmGallery->options['license_key2'] = $_temp_options['license_key2'];
|
164 |
// don't reset mobile app
|
165 |
$gmGallery->options['site_email'] = $_temp_options['site_email'];
|
166 |
+
$gmGallery->options['site_ID'] = $_temp_options['site_ID'];
|
167 |
$gmGallery->options['mobile_app'] = $_temp_options['mobile_app'];
|
168 |
delete_metadata('user', 0, 'gm_screen_options', '', true);
|
169 |
update_option('gmediaOptions', $gmGallery->options);
|
170 |
|
171 |
+
if($gmCore->_post('capability') && current_user_can('manage_options')){
|
172 |
$capabilities = $gmCore->plugin_capabilities();
|
173 |
$capabilities = apply_filters('gmedia_capabilities', $capabilities);
|
174 |
//$role = get_role('administrator');
|
175 |
+
foreach($capabilities as $cap){
|
176 |
$gmDB->set_capability('administrator', $cap);
|
177 |
}
|
178 |
}
|
admin/processor/class.processor.terms.php
CHANGED
@@ -16,7 +16,7 @@ class GmediaProcessor_Terms extends GmediaProcessor {
|
|
16 |
public function __construct() {
|
17 |
parent::__construct();
|
18 |
|
19 |
-
global $user_ID
|
20 |
|
21 |
switch($this->page){
|
22 |
case 'GrandMedia_Albums':
|
@@ -42,13 +42,13 @@ class GmediaProcessor_Terms extends GmediaProcessor {
|
|
42 |
|
43 |
$args['status'] = $gmCore->_get('status');
|
44 |
$args['page'] = $gmCore->_get('pager', 1);
|
45 |
-
$args['number'] = $gmCore->_get('per_page', $this->user_options[
|
46 |
$args['offset'] = ($args['page'] - 1) * $args['number'];
|
47 |
$args['global'] = parent::filter_by_author($gmCore->_get('author'));
|
48 |
$args['include'] = $gmCore->_get('include');
|
49 |
$args['search'] = $gmCore->_get('s');
|
50 |
-
$args['orderby'] = $gmCore->_get('orderby', $this->user_options[
|
51 |
-
$args['order'] = $gmCore->_get('order', $this->user_options[
|
52 |
$args['hide_empty'] = $gmCore->_get('hide_empty');
|
53 |
|
54 |
if($args['search'] && ('#' == substr($args['search'], 0, 1))) {
|
16 |
public function __construct() {
|
17 |
parent::__construct();
|
18 |
|
19 |
+
global $user_ID;
|
20 |
|
21 |
switch($this->page){
|
22 |
case 'GrandMedia_Albums':
|
42 |
|
43 |
$args['status'] = $gmCore->_get('status');
|
44 |
$args['page'] = $gmCore->_get('pager', 1);
|
45 |
+
$args['number'] = $gmCore->_get('per_page', $this->user_options["per_page_{$this->taxonomy}"]);
|
46 |
$args['offset'] = ($args['page'] - 1) * $args['number'];
|
47 |
$args['global'] = parent::filter_by_author($gmCore->_get('author'));
|
48 |
$args['include'] = $gmCore->_get('include');
|
49 |
$args['search'] = $gmCore->_get('s');
|
50 |
+
$args['orderby'] = $gmCore->_get('orderby', $this->user_options["orderby_{$this->taxonomy}"]);
|
51 |
+
$args['order'] = $gmCore->_get('order', $this->user_options["sortorder_{$this->taxonomy}"]);
|
52 |
$args['hide_empty'] = $gmCore->_get('hide_empty');
|
53 |
|
54 |
if($args['search'] && ('#' == substr($args['search'], 0, 1))) {
|
admin/tpl/comments.php
CHANGED
@@ -2,6 +2,9 @@
|
|
2 |
/**
|
3 |
* Gmedia Comments
|
4 |
*/
|
|
|
|
|
|
|
5 |
|
6 |
require_once(ABSPATH . 'wp-admin/includes/meta-boxes.php');
|
7 |
|
2 |
/**
|
3 |
* Gmedia Comments
|
4 |
*/
|
5 |
+
if(!defined('ABSPATH')) {
|
6 |
+
exit;
|
7 |
+
} // Exit if accessed directly
|
8 |
|
9 |
require_once(ABSPATH . 'wp-admin/includes/meta-boxes.php');
|
10 |
|
admin/tpl/modal-customfield.php
CHANGED
@@ -1,22 +1,30 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
<
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</div>
|
20 |
</div>
|
21 |
</div>
|
22 |
-
|
1 |
+
<?php // don't load directly
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
+
die( '-1' );
|
4 |
+
}
|
5 |
+
|
6 |
+
if ( isset( $customfield_meta_type ) && $customfield_meta_type ) { ?>
|
7 |
+
<div class="modal fade gmedia-modal" id="newCustomFieldModal" tabindex="-1" role="dialog" aria-hidden="true">
|
8 |
+
<div class="modal-dialog">
|
9 |
+
<div class="modal-content">
|
10 |
+
<div class="modal-header">
|
11 |
+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
12 |
+
<h4 class="modal-title"><?php _e( 'Add New Custom Field' ); ?></h4>
|
13 |
+
</div>
|
14 |
+
<form class="modal-body" method="post" id="newCustomFieldForm">
|
15 |
+
<?php
|
16 |
+
echo $gmCore->meta_form( $customfield_meta_type );
|
17 |
+
wp_nonce_field( 'gmedia_custom_field', '_customfield_nonce' );
|
18 |
+
wp_referer_field();
|
19 |
+
?>
|
20 |
+
<input type="hidden" name="action" value="<?php echo $customfield_meta_type; ?>_add_custom_field"/>
|
21 |
+
<input type="hidden" class="newcustomfield-for-id" name="ID" value=""/>
|
22 |
+
</form>
|
23 |
+
<div class="modal-footer">
|
24 |
+
<button type="button" class="btn btn-primary customfieldsubmit"><?php _e( 'Add', 'grand-media' ); ?></button>
|
25 |
+
<button type="button" class="btn btn-default" data-dismiss="modal"><?php _e( 'Close', 'grand-media' ); ?></button>
|
26 |
+
</div>
|
27 |
</div>
|
28 |
</div>
|
29 |
</div>
|
30 |
+
<?php } ?>
|
admin/tpl/modal-share.php
CHANGED
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<div class="modal fade gmedia-modal" id="shareModal" tabindex="-1" role="dialog" aria-hidden="true">
|
2 |
<div class="modal-dialog">
|
3 |
<div class="modal-content">
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
?>
|
6 |
<div class="modal fade gmedia-modal" id="shareModal" tabindex="-1" role="dialog" aria-hidden="true">
|
7 |
<div class="modal-dialog">
|
8 |
<div class="modal-content">
|
admin/tpl/module-preview.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Module Preset Preview
|
4 |
+
*/
|
5 |
+
if(!defined('ABSPATH')) {
|
6 |
+
exit;
|
7 |
+
} // Exit if accessed directly
|
8 |
+
|
9 |
+
if(!is_user_logged_in() || !current_user_can('gmedia_module_manage')){
|
10 |
+
die('-1');
|
11 |
+
}
|
12 |
+
|
13 |
+
global $wp_styles, $wp_scripts, $gmCore;
|
14 |
+
$query = $gmCore->_req('query', 'limit=20');
|
15 |
+
$module = $gmCore->_req('module');
|
16 |
+
$preset = $gmCore->_req('preset');
|
17 |
+
$atts = compact('query', 'module', 'preset');
|
18 |
+
|
19 |
+
do_action('wp_enqueue_scripts');
|
20 |
+
$wp_styles->queue = array();
|
21 |
+
$wp_scripts->queue = array();
|
22 |
+
|
23 |
+
do_action('gmedia_head');
|
24 |
+
|
25 |
+
echo gmedia_shortcode($atts);
|
26 |
+
|
27 |
+
do_action('gmedia_enqueue_scripts');
|
28 |
+
do_action('gmedia_footer');
|
admin/tpl/search-form.php
CHANGED
@@ -1,13 +1,17 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Search form template
|
4 |
*/
|
5 |
global $gmCore;
|
6 |
?>
|
7 |
-
<form class="form-inline gmedia-search-form" role="search">
|
8 |
<div class="form-group">
|
9 |
<?php foreach($_GET as $key => $value) {
|
10 |
-
if(in_array($key, array('page', '
|
11 |
?>
|
12 |
<input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"/>
|
13 |
<?php
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')) {
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Search form template
|
8 |
*/
|
9 |
global $gmCore;
|
10 |
?>
|
11 |
+
<form class="form-inline gmedia-search-form" role="search" method="get">
|
12 |
<div class="form-group">
|
13 |
<?php foreach($_GET as $key => $value) {
|
14 |
+
if(in_array($key, array('page', 'mode', 'author', 'global', 'mime_type', 'tag_id', 'tag__in', 'cat', 'category__in', 'alb', 'album__in', 'term', 'chromeless', 'post_id', 'tab', 'orderby', 'order', 'number'))) {
|
15 |
?>
|
16 |
<input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"/>
|
17 |
<?php
|
admin/wpmedia.php
CHANGED
@@ -54,6 +54,7 @@ function grandWPMedia() {
|
|
54 |
</button>
|
55 |
</form>
|
56 |
<?php echo $gmDB->query_pager(); ?>
|
|
|
57 |
|
58 |
<div class="btn-toolbar pull-left">
|
59 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
54 |
</button>
|
55 |
</form>
|
56 |
<?php echo $gmDB->query_pager(); ?>
|
57 |
+
<div class="spinner"></div>
|
58 |
|
59 |
<div class="btn-toolbar pull-left">
|
60 |
<div class="btn-group gm-checkgroup" id="cb_global-btn">
|
app/access.php
CHANGED
@@ -3,16 +3,16 @@
|
|
3 |
* Application access
|
4 |
*/
|
5 |
|
6 |
-
$time = -microtime(true);
|
7 |
|
8 |
// don't load directly
|
9 |
-
if(!defined('ABSPATH'))
|
10 |
die('-1');
|
11 |
}
|
12 |
|
13 |
global $wp;
|
14 |
$gmedia_app = isset($_GET['gmedia-app'])? $_GET['gmedia-app'] : (isset($wp->query_vars['gmedia-app'])? $wp->query_vars['gmedia-app'] : false);
|
15 |
-
if(!$gmedia_app)
|
16 |
die();
|
17 |
}
|
18 |
|
@@ -22,7 +22,7 @@ $gmapp_version = isset($_GET['gmappversion'])? $_GET['gmappversion'] : 1;
|
|
22 |
$out = array();
|
23 |
|
24 |
$gmedia_options = get_option('gmediaOptions');
|
25 |
-
if(empty($gmedia_options['mobile_app']))
|
26 |
$out['error'] = array('code' => 'app_inactive', 'message' => 'Service not enabled/activated for this site');
|
27 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
28 |
echo json_encode($out);
|
@@ -30,16 +30,16 @@ if(empty($gmedia_options['mobile_app'])) {
|
|
30 |
}
|
31 |
|
32 |
|
33 |
-
if(isset($_FILES['userfile']['name']))
|
34 |
$globaldata = isset($_POST['account'])? $_POST['account'] : false;
|
35 |
-
if($globaldata)
|
36 |
$globaldata = stripslashes($globaldata);
|
37 |
}
|
38 |
-
} else
|
39 |
$globaldata = isset($GLOBALS['HTTP_RAW_POST_DATA'])? $GLOBALS['HTTP_RAW_POST_DATA'] : false;
|
40 |
}
|
41 |
|
42 |
-
if($globaldata)
|
43 |
|
44 |
$json = json_decode($globaldata);
|
45 |
|
@@ -47,56 +47,55 @@ if($globaldata) {
|
|
47 |
global $gmAuth;
|
48 |
$gmAuth = new Gmedia_JSON_API_Auth_Controller();
|
49 |
|
50 |
-
if(isset($json->counter))
|
51 |
gmedia_ios_app_counters($json->counter);
|
52 |
}
|
53 |
|
54 |
-
if(isset($json->cookie) && !empty($json->cookie))
|
55 |
$user_id = $gmAuth->validate_auth_cookie($json->cookie);
|
56 |
-
if($user_id)
|
57 |
$user = wp_set_current_user($user_id);
|
58 |
-
if(isset($json->add_term))
|
59 |
$out = gmedia_ios_app_processor('add_term', $json->add_term);
|
60 |
-
} elseif(isset($json->delete_term))
|
61 |
$out = gmedia_ios_app_processor('delete_term', $json->delete_term);
|
62 |
-
} elseif(isset($json->doLibrary))
|
63 |
$job = gmedia_ios_app_processor('do_library', $json->doLibrary);
|
64 |
$out = gmedia_ios_app_processor('library', $json->library, false);
|
65 |
$out = array_merge($out, $job);
|
66 |
-
} elseif(isset($json->library))
|
67 |
$out = gmedia_ios_app_processor('library', $json->library);
|
68 |
-
} elseif(isset($json->library_terms))
|
69 |
$args = (array)$json->library_terms;
|
70 |
-
if(isset($args['taxonomy']))
|
71 |
$out = gmedia_ios_app_library_data(array($args['taxonomy']), $args);
|
72 |
}
|
73 |
}
|
74 |
|
75 |
-
} else
|
76 |
$out['error'] = array('code' => 'wrongcookie', 'message' => 'Not Valid User');
|
77 |
}
|
78 |
-
} elseif(isset($json->login))
|
79 |
$out = gmedia_ios_app_login($json);
|
80 |
-
if(!isset($out['error']))
|
81 |
$user = wp_set_current_user($out['user']['id']);
|
82 |
|
83 |
-
$gmedia_capabilities_list = array(
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
'gmedia_terms_delete'
|
96 |
);
|
97 |
$gmedia_capabilities = array();
|
98 |
-
foreach($gmedia_capabilities_list as $cap)
|
99 |
-
$gmedia_capabilities[$cap] = current_user_can($cap);
|
100 |
}
|
101 |
|
102 |
$out['user']['gmedia_capabilities'] = $gmedia_capabilities;
|
@@ -104,23 +103,23 @@ if($globaldata) {
|
|
104 |
$data = gmedia_ios_app_library_data();
|
105 |
$out = $out + $data;
|
106 |
}
|
107 |
-
} else
|
108 |
-
if(isset($json->library))
|
109 |
$out = gmedia_ios_app_processor('library', $json->library);
|
110 |
-
} elseif(isset($json->library_terms))
|
111 |
$args = (array)$json->library_terms;
|
112 |
-
if(isset($args['taxonomy']))
|
113 |
$out = gmedia_ios_app_library_data(array($args['taxonomy']), $args);
|
114 |
}
|
115 |
-
} else
|
116 |
$out = gmedia_ios_app_library_data();
|
117 |
}
|
118 |
}
|
119 |
|
120 |
-
} elseif('lostpassword' == $gmCore->_get('action'))
|
121 |
-
if(function_exists('wp_lostpassword_url'))
|
122 |
$url = wp_lostpassword_url();
|
123 |
-
} else
|
124 |
$url = add_query_arg('action', 'lostpassword', wp_login_url());
|
125 |
}
|
126 |
wp_redirect($url);
|
@@ -133,31 +132,33 @@ if($globaldata) {
|
|
133 |
*
|
134 |
* @return array
|
135 |
*/
|
136 |
-
function gmedia_ios_app_login($json)
|
137 |
global $gmAuth;
|
138 |
|
139 |
-
do
|
140 |
-
if(empty($json->login))
|
141 |
$out['error'] = array('code' => 'nologin', 'title' => 'No Login', 'message' => 'No Login');
|
142 |
break;
|
143 |
}
|
144 |
-
if(!isset($json->password) || empty($json->password))
|
145 |
$out['error'] = array('code' => 'nopassword', 'title' => 'No Password', 'message' => 'No Password');
|
146 |
break;
|
147 |
}
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
153 |
);
|
154 |
break;
|
155 |
}
|
156 |
|
157 |
-
$args = array(
|
158 |
-
|
159 |
-
|
160 |
-
'nonce' => wp_create_nonce('auth_gmapp')
|
161 |
);
|
162 |
$out = $gmAuth->generate_auth_cookie($args);
|
163 |
|
@@ -168,25 +169,24 @@ function gmedia_ios_app_login($json) {
|
|
168 |
|
169 |
/**
|
170 |
* @param array $data
|
171 |
-
*
|
172 |
* @param $args
|
173 |
*
|
174 |
* @return array
|
175 |
*/
|
176 |
-
function gmedia_ios_app_library_data(
|
177 |
-
$
|
178 |
-
$args = array()
|
179 |
-
) {
|
180 |
-
global $user_ID, $gmCore, $gmDB, $gmGallery, $gmapp_version;
|
181 |
|
182 |
-
if(null === $data)
|
183 |
$data = array('site', 'authors', 'filter', 'gmedia_category', 'gmedia_album', 'gmedia_tag');
|
184 |
}
|
185 |
|
186 |
-
if(version_compare('3', $gmapp_version, '<='))
|
187 |
$logic = 2;
|
|
|
|
|
|
|
188 |
$terms_per_page = 40;
|
189 |
-
} else
|
190 |
$logic = 1;
|
191 |
$terms_per_page = '';
|
192 |
}
|
@@ -195,34 +195,36 @@ function gmedia_ios_app_library_data(
|
|
195 |
$out = array();
|
196 |
|
197 |
$ep = $gmGallery->options['endpoint'];
|
198 |
-
if(get_option('permalink_structure'))
|
199 |
$share_link_base = home_url(urlencode($ep) . '/$2/$1');
|
200 |
-
} else
|
201 |
$share_link_base = add_query_arg(array("$ep" => '$1', 't' => '$2'), home_url('index.php'));
|
202 |
}
|
203 |
|
204 |
-
if(in_array('site', $data))
|
205 |
-
$site_name
|
206 |
$site_description = get_bloginfo('description');
|
207 |
-
$out['site']
|
208 |
-
|
209 |
-
'description' => $site_description? $site_description : ''
|
210 |
);
|
211 |
}
|
212 |
-
if(in_array('authors', $data))
|
213 |
-
$out['authors'] = array(
|
214 |
-
'data' => array()
|
215 |
);
|
|
|
|
|
|
|
216 |
//if(current_user_can('gmedia_show_others_media') || current_user_can('gmedia_edit_others_media')){
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
$
|
221 |
-
'id' => $author->ID,
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
226 |
}
|
227 |
}
|
228 |
/*} else{
|
@@ -233,18 +235,18 @@ function gmedia_ios_app_library_data(
|
|
233 |
$out['authors']['data'][] = array('id' => $user_ID, 'displayname' => $display_name, 'firstname' => $first_name, 'lastname' => $last_name);
|
234 |
}*/
|
235 |
}
|
236 |
-
if(in_array('filter', $data))
|
237 |
$gmDB->clauses = array();
|
238 |
$out['filter'] = $gmDB->count_gmedia();
|
239 |
$out['filter'] = array_map('intval', $out['filter']);
|
240 |
}
|
241 |
-
if(in_array('gmedia_category', $data))
|
242 |
if($user_ID){
|
243 |
-
if(current_user_can('gmedia_terms_delete') && current_user_can('gmedia_delete_others_media'))
|
244 |
$cap = 4;
|
245 |
-
} elseif(current_user_can('gmedia_category_manage'))
|
246 |
$cap = 2;
|
247 |
-
} else
|
248 |
$cap = 0;
|
249 |
}
|
250 |
} else{
|
@@ -252,114 +254,111 @@ function gmedia_ios_app_library_data(
|
|
252 |
}
|
253 |
//$default_args = array('fields' => 'name=>all');
|
254 |
$default_args = array();
|
255 |
-
|
256 |
-
|
|
|
257 |
}
|
258 |
-
$
|
259 |
-
$gmediaTerms = $gmDB->get_terms('gmedia_category', $
|
260 |
-
$props = array(
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
'total_count' => $gmDB->totalResult
|
266 |
);
|
267 |
$terms = array('0' => __('Uncategorized', 'grand-media'));
|
268 |
-
$out['categories'] = array(
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
'data' => array()
|
273 |
);
|
274 |
-
if(!empty($gmediaTerms))
|
275 |
-
foreach($gmediaTerms as $i => $term)
|
276 |
$out['categories']['list']["{$term->term_id}"] = $term->name;
|
277 |
-
gmedia_ios_app_term_data_extend($gmediaTerms[$i], $share_link_base, $logic, $cap);
|
278 |
}
|
279 |
|
280 |
-
$out['categories']['data']
|
281 |
}
|
282 |
}
|
283 |
-
if(in_array('gmedia_album', $data))
|
284 |
$default_args = array();
|
285 |
-
|
|
|
286 |
$default_args['orderby'] = 'ID';
|
287 |
$default_args['order'] = 'DESC';
|
288 |
}
|
289 |
|
290 |
-
if($user_ID)
|
291 |
-
if(current_user_can('gmedia_terms_delete'))
|
292 |
$cap = 4;
|
293 |
-
} elseif(current_user_can('gmedia_album_manage'))
|
294 |
$cap = 2;
|
295 |
-
} else
|
296 |
$cap = 0;
|
297 |
}
|
298 |
/*if( !current_user_can('gmedia_edit_others_media')){
|
299 |
//$default_args = array( 'status' => array('publish', 'private') );
|
300 |
//$default_args['global'] = array( $user_ID, 0 );
|
301 |
}*/
|
302 |
-
} else
|
303 |
$cap = 0;
|
304 |
$default_args = array('status' => 'publish');
|
305 |
}
|
306 |
-
if(isset($
|
307 |
-
$
|
308 |
}
|
309 |
-
$
|
310 |
-
|
311 |
-
$gmediaTerms = $gmDB->get_terms('gmedia_album', $
|
312 |
-
$props = array(
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
'total_count' => $gmDB->totalResult
|
318 |
);
|
319 |
-
foreach($gmediaTerms as $i => $term)
|
320 |
-
gmedia_ios_app_term_data_extend($gmediaTerms[$i], $share_link_base, $logic, $cap);
|
321 |
}
|
322 |
-
$gmediaTerms
|
323 |
$props['items_count'] = count($gmediaTerms);
|
324 |
|
325 |
-
$out['albums'] = array(
|
326 |
-
|
327 |
-
|
328 |
-
'data' => array_values($gmediaTerms)
|
329 |
);
|
330 |
}
|
331 |
-
if(in_array('gmedia_tag', $data))
|
332 |
$default_args = array();
|
333 |
-
|
334 |
-
|
|
|
335 |
$cap = 4;
|
336 |
-
} elseif(current_user_can('gmedia_tag_manage'))
|
337 |
$cap = 2;
|
338 |
-
} else
|
339 |
$cap = 0;
|
340 |
}
|
341 |
-
} else
|
342 |
$cap = 0;
|
343 |
}
|
344 |
-
if(isset($
|
345 |
-
$
|
346 |
}
|
347 |
-
$
|
348 |
-
$gmediaTerms = $gmDB->get_terms('gmedia_tag', $
|
349 |
-
$props = array(
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
'total_count' => $gmDB->totalResult
|
355 |
);
|
356 |
-
foreach($gmediaTerms as $i => $term)
|
357 |
-
gmedia_ios_app_term_data_extend($gmediaTerms[$i], $share_link_base, $logic, $cap);
|
358 |
}
|
359 |
-
$out['tags'] = array(
|
360 |
-
|
361 |
-
|
362 |
-
'data' => array_values($gmediaTerms)
|
363 |
);
|
364 |
}
|
365 |
|
@@ -369,129 +368,128 @@ function gmedia_ios_app_library_data(
|
|
369 |
/**
|
370 |
* @param object $term
|
371 |
* @param string $share_link_base
|
372 |
-
*
|
373 |
* @param int $logic
|
374 |
* @param int $cap
|
375 |
*
|
376 |
* @return array
|
377 |
*/
|
378 |
-
function gmedia_ios_app_term_data_extend(&$term, $share_link_base, $logic = 0, $cap = 0)
|
379 |
global $gmCore, $gmDB, $gmGallery, $user_ID;
|
380 |
|
381 |
$taxterm = str_replace('gmedia_', '', $term->taxonomy);
|
382 |
$default_meta = array();
|
383 |
|
384 |
-
if('gmedia_album' == $term->taxonomy)
|
385 |
$author_id = (int)$term->global;
|
386 |
-
if($author_id)
|
387 |
-
if(($author_id != $user_ID) && ('draft' == $term->status) && !current_user_can('gmedia_edit_others_media'))
|
388 |
$term = null;
|
|
|
389 |
return;
|
390 |
}
|
391 |
$authordata = get_userdata($author_id);
|
392 |
-
if($authordata)
|
393 |
$display_name = $authordata->display_name;
|
394 |
$first_name = $authordata->first_name;
|
395 |
$last_name = $authordata->last_name;
|
396 |
-
} else
|
397 |
$display_name = __('Deleted User', 'grand-media');
|
398 |
$first_name = '';
|
399 |
$last_name = '';
|
400 |
}
|
401 |
-
} else
|
402 |
$display_name = __('Shared', 'grand-media');
|
403 |
$first_name = $last_name = '';
|
404 |
}
|
405 |
-
$term->user = array(
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
'lastname' => $last_name
|
410 |
);
|
411 |
|
412 |
$default_meta = array('_orderby' => 'ID', '_order' => 'DESC');
|
413 |
|
414 |
-
if(1 === $logic)
|
415 |
-
if('publish' == $term->status)
|
416 |
$term->status = 'public';
|
417 |
}
|
418 |
}
|
419 |
}
|
420 |
-
if('gmedia_category' == $term->taxonomy)
|
421 |
unset($term->global, $term->status);
|
422 |
$term->title = $term->name;
|
423 |
$default_meta = array('_orderby' => $gmGallery->options['in_category_orderby'], '_order' => $gmGallery->options['in_category_order']);
|
424 |
}
|
425 |
-
if('gmedia_tag' == $term->taxonomy)
|
426 |
unset($term->description, $term->global, $term->status);
|
427 |
|
428 |
$default_meta = array('_orderby' => $gmGallery->options['in_tag_orderby'], '_order' => $gmGallery->options['in_tag_order']);
|
429 |
}
|
430 |
|
431 |
$term_meta = $gmDB->get_metadata('gmedia_term', $term->term_id);
|
432 |
-
foreach($term_meta as $key => $value)
|
433 |
-
if(is_array($value)
|
434 |
-
$
|
|
|
|
|
|
|
|
|
435 |
}
|
436 |
}
|
437 |
$term_meta = array_merge($default_meta, $term_meta);
|
438 |
$term_meta['orderby'] = $term_meta['_orderby'];
|
439 |
$term_meta['order'] = $term_meta['_order'];
|
440 |
|
441 |
-
if(in_array($term->taxonomy, array('gmedia_album', 'gmedia_category')))
|
442 |
-
if(empty($term_meta['_cover']))
|
443 |
$term_meta['_cover'] = false;
|
444 |
-
} else
|
445 |
$term_meta['_cover'] = intval($term_meta['_cover']);
|
446 |
}
|
447 |
-
if($term_meta['_cover'])
|
448 |
$cover_id = (int)$term_meta['_cover'];
|
449 |
$cover = gmedia_ios_app_processor('library', array('gmedia__in' => array($cover_id)), false);
|
450 |
-
if(isset($cover['data'][0]))
|
451 |
$term_meta['_cover'] = $cover['data'][0];
|
452 |
$term->thumbnail = $gmCore->gm_get_media_image($cover_id, 'thumb', false);
|
453 |
-
} else
|
454 |
$term_meta['_cover'] = false;
|
455 |
}
|
456 |
}
|
457 |
-
if(!$term_meta['_cover'] && $term->count)
|
458 |
-
$gmargs = array(
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
|
|
464 |
);
|
465 |
-
if($user_ID)
|
466 |
$gmargs['status'] = array('publish', 'private');
|
467 |
-
|
468 |
-
$gmargs['status'] = '';
|
469 |
-
}
|
470 |
-
} else {
|
471 |
$gmargs['status'] = 'publish';
|
472 |
}
|
473 |
|
474 |
$termItems = $gmDB->get_gmedias($gmargs);
|
475 |
-
if(!empty($termItems))
|
476 |
-
$cover = gmedia_ios_app_processor('library', array('gmedia__in' => array($termItems[0]->ID)),
|
477 |
-
|
478 |
-
if(isset($cover['data'][0])) {
|
479 |
$term_meta['_cover'] = $cover['data'][0];
|
|
|
480 |
}
|
481 |
-
$term->thumbnail = $gmCore->gm_get_media_image($termItems[0], 'thumb', false);
|
482 |
}
|
483 |
}
|
484 |
}
|
485 |
|
486 |
$term->meta = $term_meta;
|
487 |
|
488 |
-
$t
|
489 |
-
|
490 |
-
|
491 |
-
'category' => 'k'
|
492 |
);
|
493 |
$gmedia_hashid = gmedia_hash_id_encode($term->term_id, $taxterm);
|
494 |
-
$term->sharelink = str_replace(array('$1', '$2'), array(urlencode($gmedia_hashid), $t[$taxterm]), $share_link_base);
|
495 |
|
496 |
$term->cap = (4 == $cap)? 4 : 0;
|
497 |
}
|
@@ -499,39 +497,44 @@ function gmedia_ios_app_term_data_extend(&$term, $share_link_base, $logic = 0, $
|
|
499 |
/**
|
500 |
* @param $action
|
501 |
* @param $data
|
502 |
-
*
|
503 |
* @param bool $filter
|
504 |
*
|
505 |
* @return array
|
506 |
*/
|
507 |
-
function gmedia_ios_app_processor($action, $data, $filter = true)
|
508 |
global $gmCore, $gmDB, $gmGallery, $user_ID, $gmapp_version;
|
509 |
|
510 |
$out = array();
|
511 |
|
512 |
-
if(version_compare('3', $gmapp_version, '<='))
|
513 |
$logic = 2;
|
514 |
-
|
|
|
|
|
|
|
515 |
$logic = 1;
|
516 |
}
|
517 |
|
518 |
-
$error
|
519 |
-
$
|
520 |
-
$
|
521 |
-
|
|
|
|
|
522 |
case 'do_library':
|
523 |
|
524 |
-
if(!isset($data['action']))
|
525 |
return $out;
|
526 |
}
|
527 |
-
|
|
|
|
|
528 |
|
529 |
case 'add_media':
|
530 |
-
if(!current_user_can('gmedia_upload'))
|
531 |
-
$out['error'] = array(
|
532 |
-
|
533 |
-
|
534 |
-
'message' => __('You have no permission to do this operation', 'grand-media')
|
535 |
);
|
536 |
|
537 |
return $out;
|
@@ -539,196 +542,203 @@ function gmedia_ios_app_processor($action, $data, $filter = true) {
|
|
539 |
|
540 |
usleep(10);
|
541 |
|
542 |
-
if(is_uploaded_file($_FILES['userfile']['tmp_name']))
|
543 |
$file_name = $_FILES['userfile']['name'];
|
544 |
$file_tmp = $_FILES['userfile']['tmp_name'];
|
545 |
-
} else
|
546 |
$error[] = __("Failed to move uploaded file.", 'grand-media');
|
547 |
break;
|
548 |
}
|
549 |
|
550 |
$fileinfo = $gmCore->fileinfo($file_name);
|
551 |
-
if(false === $fileinfo)
|
552 |
break;
|
553 |
}
|
554 |
|
555 |
$gmedia = (array)$data['item'];
|
556 |
-
if(!current_user_can('gmedia_terms'))
|
557 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
558 |
-
} else
|
559 |
-
if(empty($gmedia['albums']))
|
560 |
$gmedia['terms']['gmedia_album'] = '';
|
561 |
-
} else
|
562 |
$alb = isset($gmedia['albums'][0]->term_id)? $gmedia['albums'][0]->term_id : $gmedia['albums'][0]->name;
|
563 |
$gmedia['terms']['gmedia_album'] = $alb;
|
564 |
}
|
565 |
-
if(empty($gmedia['categories']))
|
566 |
$gmedia['terms']['gmedia_category'] = '';
|
567 |
-
} else
|
568 |
$categories = array();
|
569 |
-
foreach($gmedia['categories'] as $category)
|
570 |
$categories[] = isset($category->term_id)? $category->term_id : $category->name;
|
571 |
}
|
572 |
$gmedia['terms']['gmedia_category'] = implode(',', $categories);
|
573 |
}
|
574 |
-
if(empty($gmedia['tags']))
|
575 |
$gmedia['terms']['gmedia_tag'] = '';
|
576 |
-
} else
|
577 |
$tags = array();
|
578 |
-
foreach($gmedia['tags'] as $tag)
|
579 |
$tags[] = isset($tag->term_id)? $tag->term_id : $tag->name;
|
580 |
}
|
581 |
$gmedia['terms']['gmedia_tag'] = implode(',', $tags);
|
582 |
}
|
583 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
584 |
}
|
585 |
-
if(isset($gmedia['status']) && 'public' == $gmedia['status'])
|
586 |
$gmedia['status'] = 'publish';
|
587 |
}
|
588 |
|
589 |
$return = $gmCore->gmedia_upload_handler($file_tmp, $fileinfo, 'multipart', $gmedia);
|
590 |
-
if(isset($return['error']))
|
591 |
$error[] = $return['error']['message'];
|
592 |
-
} else
|
593 |
$alert[] = $return['success']['message'];
|
594 |
}
|
595 |
break;
|
596 |
|
597 |
case 'update_media':
|
|
|
|
|
|
|
|
|
598 |
$gmedia = (array)$data['item'];
|
599 |
-
if(!empty($gmedia['ID']))
|
600 |
$item = $gmDB->get_gmedia($gmedia['ID']);
|
|
|
|
|
|
|
|
|
601 |
|
602 |
unset($gmedia['date'], $gmedia['mime_type'], $gmedia['gmuid'], $gmedia['modified']);
|
603 |
//$gmedia['modified'] = current_time('mysql');
|
604 |
-
if(!current_user_can('gmedia_delete_others_media'))
|
605 |
$gmedia['author'] = $item->author;
|
606 |
}
|
607 |
-
if(isset($gmedia['status']) && 'public' == $gmedia['status'])
|
608 |
$gmedia['status'] = 'publish';
|
609 |
}
|
610 |
|
611 |
|
612 |
-
if(!current_user_can('gmedia_terms'))
|
613 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
614 |
-
} else
|
615 |
-
if(empty($gmedia['albums']))
|
616 |
$gmedia['terms']['gmedia_album'] = '';
|
617 |
-
} else
|
618 |
-
if(isset($gmedia['albums'][0]->term_id))
|
619 |
$gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->term_id;
|
620 |
-
} elseif(current_user_can('gmedia_album_manage'))
|
621 |
$gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->name;
|
622 |
}
|
623 |
}
|
624 |
-
if(empty($gmedia['categories']))
|
625 |
$gmedia['terms']['gmedia_category'] = '';
|
626 |
-
} else
|
627 |
$categories = array();
|
628 |
-
foreach($gmedia['categories'] as $category)
|
629 |
-
if(isset($category->term_id))
|
630 |
$categories[] = $category->term_id;
|
631 |
-
} elseif(current_user_can('gmedia_category_manage'))
|
632 |
$categories[] = $category->name;
|
633 |
}
|
634 |
}
|
635 |
-
$gmedia['terms']['gmedia_category'] =
|
636 |
}
|
637 |
-
if(empty($gmedia['tags']))
|
638 |
$gmedia['terms']['gmedia_tag'] = '';
|
639 |
-
} else
|
640 |
$tags = array();
|
641 |
-
foreach($gmedia['tags'] as $tag)
|
642 |
-
if(isset($tag->term_id))
|
643 |
$tags[] = $tag->term_id;
|
644 |
-
} elseif(current_user_can('gmedia_tag_manage'))
|
645 |
$tags[] = $tag->name;
|
646 |
}
|
647 |
}
|
648 |
-
$gmedia['terms']['gmedia_tag'] =
|
649 |
}
|
650 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
651 |
}
|
652 |
|
653 |
-
|
654 |
-
if(!current_user_can('gmedia_edit_media')) {
|
655 |
-
$alert[] = __('You are not allowed to edit media', 'grand-media');
|
656 |
-
}
|
657 |
-
} else {
|
658 |
-
if(!current_user_can('gmedia_edit_others_media')) {
|
659 |
-
$alert[] = __('You are not allowed to edit others media', 'grand-media');
|
660 |
-
}
|
661 |
-
}
|
662 |
-
if(empty($alert)) {
|
663 |
-
$gmDB->insert_gmedia($gmedia);
|
664 |
-
} else {
|
665 |
-
if(current_user_can('gmedia_terms') && count($gmedia['terms'])) {
|
666 |
-
foreach($gmedia['terms'] as $tax => $terms) {
|
667 |
-
$result = $gmDB->set_gmedia_terms($gmedia['ID'], $terms, $tax, $append = 0);
|
668 |
-
if(is_wp_error($result)) {
|
669 |
-
$error[] = $result->get_error_message();
|
670 |
-
}
|
671 |
-
}
|
672 |
-
}
|
673 |
-
}
|
674 |
}
|
675 |
break;
|
676 |
|
677 |
case 'assign_album':
|
678 |
-
if(!current_user_can('
|
|
|
|
|
|
|
|
|
679 |
$error[] = __('You are not allowed to manage albums', 'grand-media');
|
680 |
}
|
681 |
$term = $data['assign_album'][0];
|
682 |
$count = count($data['selected']);
|
683 |
-
if('0' == $term)
|
684 |
-
foreach($data['selected'] as $item)
|
685 |
$gmDB->delete_gmedia_term_relationships($item, 'gmedia_album');
|
686 |
}
|
687 |
$alert[] = sprintf(__('%d item(s) updated with "No Album"', 'grand-media'), $count);
|
688 |
-
} else
|
689 |
-
foreach($data['selected'] as $item)
|
|
|
|
|
|
|
|
|
690 |
$result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_album', $append = 0);
|
691 |
-
if(is_wp_error($result))
|
692 |
$error[] = $result->get_error_message();
|
693 |
-
$count--;
|
694 |
-
} elseif(!$result)
|
695 |
-
$count--;
|
696 |
}
|
697 |
}
|
698 |
-
if($gmCore->is_digit($term))
|
699 |
$alb_name = $gmDB->get_term_name($term);
|
700 |
-
} else
|
701 |
$alb_name = $term;
|
702 |
}
|
703 |
-
$alert[] = sprintf(__('Album `%s` assigned to %d item(s)', 'grand-media'), esc_html($alb_name),
|
704 |
-
$count);
|
705 |
}
|
706 |
break;
|
707 |
|
708 |
case 'assign_category':
|
709 |
-
if(!current_user_can('
|
|
|
|
|
|
|
|
|
710 |
$error[] = __('You are not allowed to manage categories', 'grand-media');
|
711 |
break;
|
712 |
}
|
713 |
-
if(empty($data['assign_category']))
|
714 |
$error[] = __('No categories provided', 'grand-media');
|
715 |
break;
|
716 |
}
|
717 |
$terms = $data['assign_category'];
|
718 |
$count = count($data['selected']);
|
719 |
-
if(1 === count($terms) && '0' == $terms[0])
|
720 |
-
foreach($data['selected'] as $item)
|
|
|
|
|
|
|
|
|
721 |
$gmDB->delete_gmedia_term_relationships($item, 'gmedia_category');
|
722 |
}
|
723 |
$alert[] = sprintf(__('%d item(s) updated with "Uncategorized"', 'grand-media'), $count);
|
724 |
-
} else
|
725 |
-
foreach($data['selected'] as $item)
|
|
|
|
|
|
|
|
|
726 |
$result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_category', $append = 0);
|
727 |
-
if(is_wp_error($result))
|
728 |
$error[] = $result->get_error_message();
|
729 |
-
$count--;
|
730 |
-
} elseif(!$result)
|
731 |
-
$count--;
|
732 |
}
|
733 |
}
|
734 |
$alert[] = sprintf(__('%d category(ies) added to %d item(s)', 'grand-media'), count($terms), $count);
|
@@ -736,174 +746,232 @@ function gmedia_ios_app_processor($action, $data, $filter = true) {
|
|
736 |
break;
|
737 |
|
738 |
case 'unassign_category':
|
739 |
-
if(!current_user_can('
|
740 |
-
$error[] = __('You are not allowed to
|
741 |
break;
|
742 |
}
|
743 |
-
if(empty($data['unassign_category']))
|
744 |
$error[] = __('No categories provided', 'grand-media');
|
745 |
break;
|
746 |
}
|
747 |
$terms = array_map('intval', $data['unassign_category']);
|
748 |
$count = count($data['selected']);
|
749 |
-
foreach($data['selected'] as $item)
|
750 |
-
$
|
751 |
-
if(
|
|
|
|
|
|
|
|
|
752 |
$error[] = $result->get_error_message();
|
753 |
-
$count--;
|
754 |
-
} elseif(!$result)
|
755 |
-
$count--;
|
756 |
}
|
757 |
}
|
758 |
$alert[] = sprintf(__('%d category(ies) deleted from %d item(s)', 'grand-media'), count($terms), $count);
|
759 |
break;
|
760 |
|
761 |
case 'add_tags':
|
762 |
-
if(!current_user_can('
|
|
|
|
|
|
|
|
|
763 |
$error[] = __('You are not allowed manage tags', 'grand-media');
|
764 |
break;
|
765 |
}
|
766 |
-
if(empty($data['add_tags']))
|
767 |
$error[] = __('No tags provided', 'grand-media');
|
768 |
break;
|
769 |
}
|
770 |
$terms = $data['add_tags'];
|
771 |
$count = count($data['selected']);
|
772 |
-
foreach($data['selected'] as $item)
|
|
|
|
|
|
|
|
|
773 |
$result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_tag', $append = 1);
|
774 |
-
if(is_wp_error($result))
|
775 |
$error[] = $result->get_error_message();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
776 |
$count--;
|
777 |
-
|
|
|
|
|
778 |
$count--;
|
|
|
|
|
|
|
|
|
|
|
|
|
779 |
}
|
780 |
}
|
781 |
-
$alert[] = sprintf(__('%d
|
782 |
break;
|
783 |
|
784 |
case 'delete_tags':
|
785 |
-
if(!current_user_can('
|
786 |
-
$error[] = __('You are not allowed to
|
787 |
break;
|
788 |
}
|
789 |
-
if(empty($data['delete_tags']))
|
790 |
$error[] = __('No tags provided', 'grand-media');
|
791 |
break;
|
792 |
}
|
793 |
$terms = array_map('intval', $data['delete_tags']);
|
794 |
$count = count($data['selected']);
|
795 |
-
foreach($data['selected'] as $item)
|
796 |
-
$
|
797 |
-
if(
|
|
|
|
|
|
|
|
|
798 |
$error[] = $result->get_error_message();
|
799 |
-
$count--;
|
800 |
-
} elseif(!$result)
|
801 |
-
$count--;
|
802 |
}
|
803 |
}
|
804 |
$alert[] = sprintf(__('%d tag(s) deleted from %d item(s)', 'grand-media'), count($terms), $count);
|
805 |
break;
|
806 |
|
807 |
case 'delete':
|
808 |
-
if(!current_user_can('gmedia_delete_media'))
|
809 |
$error[] = __('You are not allowed to delete this post.');
|
810 |
break;
|
811 |
}
|
812 |
$count = count($data['selected']);
|
813 |
-
foreach($data['selected'] as $item)
|
814 |
$gm_item = $gmDB->get_gmedia($item);
|
815 |
-
if(((int)$gm_item->author != $user_ID) && !current_user_can('gmedia_delete_others_media'))
|
816 |
-
$error[] = "#{$item}: " . __('You are not allowed to delete media others media',
|
817 |
-
'grand-media');
|
818 |
continue;
|
819 |
}
|
820 |
-
if(!$gmDB->delete_gmedia((int)$item))
|
821 |
$error[] = "#{$item}: " . __('Error in deleting...', 'grand-media');
|
822 |
-
$count--;
|
823 |
}
|
824 |
}
|
825 |
-
if($count)
|
826 |
$alert[] = sprintf(__('%d items deleted successfuly', 'grand-media'), $count);
|
827 |
}
|
828 |
break;
|
829 |
}
|
830 |
-
|
831 |
-
|
832 |
-
|
|
|
833 |
break;
|
834 |
|
835 |
case 'library':
|
836 |
$ep = $gmGallery->options['endpoint'];
|
837 |
-
if(get_option('permalink_structure'))
|
838 |
$share_link_base = home_url(urlencode($ep) . '/$2/$1');
|
839 |
-
} else
|
840 |
$share_link_base = add_query_arg(array("$ep" => '$1', 't' => '$2'), home_url('index.php'));
|
841 |
}
|
842 |
$filter = $filter? gmedia_ios_app_library_data(array('filter')) : array();
|
843 |
|
844 |
-
$
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
);
|
857 |
-
$data = wp_parse_args($data, $args);
|
858 |
-
$false_out = array_merge($filter, array(
|
859 |
-
'properties' => array(
|
860 |
-
'request' => isset($data['request'])? $data['request'] : null
|
861 |
-
),
|
862 |
-
'data' => array()
|
863 |
-
));
|
864 |
|
865 |
$terms_ids_query = array();
|
866 |
-
if(!empty($data['
|
867 |
-
$
|
|
|
|
|
|
|
|
|
868 |
}
|
869 |
-
if(!empty($data['category__in']))
|
870 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
871 |
}
|
872 |
-
if(!empty($data['
|
873 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
874 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
875 |
$terms_ids = array();
|
876 |
if(!empty($terms_ids_query)){
|
877 |
$terms_ids = $gmDB->get_terms(array('gmedia_album', 'gmedia_category', 'gmedia_tag'), array('include' => $terms_ids_query));
|
878 |
if(!empty($terms_ids) && !is_wp_error($terms_ids)){
|
879 |
foreach($terms_ids as $i => $term){
|
880 |
-
gmedia_ios_app_term_data_extend($terms_ids[$i], $share_link_base);
|
881 |
}
|
882 |
$terms_ids = array_filter($terms_ids);
|
883 |
if(empty($terms_ids)){
|
884 |
$out = $false_out;
|
885 |
break;
|
886 |
}
|
887 |
-
} else
|
888 |
$terms_ids = array();
|
889 |
}
|
890 |
}
|
891 |
$req_terms = array();
|
892 |
if(!empty($terms_ids)){
|
893 |
foreach($terms_ids as $term){
|
894 |
-
$taxterm
|
895 |
$req_terms["{$taxterm}__in"]["{$term->term_id}"] = $term;
|
896 |
}
|
897 |
}
|
898 |
|
899 |
$is_admin = isset($data['admin'])? intval($data['admin']) : 0;
|
900 |
-
if(!is_user_logged_in())
|
901 |
$logged_in = false;
|
902 |
$data['status'] = array('publish');
|
903 |
-
if(!empty($req_terms['album__in']))
|
904 |
$break = false;
|
905 |
-
foreach($req_terms['album__in'] as $alb)
|
906 |
-
if(!(isset($alb->status) && ('publish' == $alb->status)))
|
907 |
$break = true;
|
908 |
}
|
909 |
}
|
@@ -912,178 +980,215 @@ function gmedia_ios_app_processor($action, $data, $filter = true) {
|
|
912 |
break;
|
913 |
}
|
914 |
}
|
915 |
-
} else
|
916 |
$logged_in = true;
|
917 |
-
if($is_admin && !current_user_can('gmedia_library'))
|
918 |
$out = $false_out;
|
919 |
break;
|
920 |
}
|
921 |
-
if($is_admin && !current_user_can('gmedia_show_others_media'))
|
922 |
$data['author'] = $user_ID;
|
923 |
}
|
924 |
}
|
925 |
|
926 |
$_data = $data;
|
927 |
-
$_data['per_page'] = -1;
|
928 |
$_data['status'] = null;
|
929 |
$_data['fields'] = 'ids';
|
930 |
$all_gmedias_ids = $gmDB->get_gmedias($_data);
|
931 |
$gmedias = $gmDB->get_gmedias($data);
|
932 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
933 |
|
934 |
//if((!$logged_in && 'publish' != $item->status) || (!$is_admin && ('draft' == $item->status) && ((int)$user_ID != (int)$item->author))) {
|
935 |
-
if(!$is_admin && ('draft' == $item->status) && ((int)$user_ID != (int)$item->author))
|
936 |
-
unset($gmedias[$i]);
|
|
|
|
|
937 |
continue;
|
938 |
}
|
939 |
|
940 |
$author_id = $item->author;
|
941 |
$authordata = get_userdata($author_id);
|
942 |
-
if($authordata)
|
943 |
$display_name = $authordata->display_name;
|
944 |
$first_name = $authordata->first_name;
|
945 |
$last_name = $authordata->last_name;
|
946 |
-
} else
|
947 |
$display_name = __('Deleted User', 'grand-media');
|
948 |
$first_name = '';
|
949 |
$last_name = '';
|
950 |
}
|
951 |
-
$gmedias[$i]->user = array(
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
'last_name' => $last_name
|
956 |
);
|
957 |
-
$gmedias[$i]->date = strtotime($item->date);
|
958 |
|
959 |
$meta = $gmDB->get_metadata('gmedia', $item->ID);
|
960 |
//$_metadata = maybe_unserialize( $meta['_metadata'][0] );
|
961 |
-
$_metadata
|
962 |
-
$
|
963 |
-
|
964 |
-
$
|
965 |
-
$
|
966 |
-
$
|
967 |
-
|
|
|
|
|
968 |
$terms = array_values((array)$terms);
|
969 |
-
foreach($terms as $term)
|
970 |
$tags[] = array('term_id' => $term->term_id, 'name' => $term->name);
|
971 |
}
|
972 |
}
|
973 |
-
$gmedias[$i]->tags = $tags;
|
974 |
|
975 |
$terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_album');
|
976 |
$albums = array();
|
977 |
-
if($terms)
|
978 |
$terms = array_values((array)$terms);
|
979 |
-
foreach($terms as $term)
|
980 |
-
$albums[] = array(
|
981 |
-
|
982 |
-
|
983 |
-
'status' => (1 === $logic && 'publish' == $term->status)? 'public' : $term->status
|
984 |
);
|
985 |
}
|
986 |
}
|
987 |
-
$gmedias[$i]->albums = $albums;
|
988 |
|
989 |
-
if('image' == $type[0])
|
990 |
$terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_category');
|
991 |
$categories = array();
|
992 |
-
if($terms)
|
993 |
$terms = array_values((array)$terms);
|
994 |
-
foreach($terms as $term)
|
995 |
$categories[] = array('term_id' => $term->term_id, 'name' => $term->term_id, 'title' => $term->name);
|
996 |
}
|
997 |
}
|
998 |
-
$gmedias[$i]->categories = $categories;
|
999 |
|
1000 |
-
$gmedias[$i]->meta = array(
|
1001 |
-
|
1002 |
-
|
1003 |
-
'original' => $_metadata['original']
|
1004 |
);
|
1005 |
-
$gmedias[$i]->meta['thumb']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_thumb']}/{$item->gmuid}";
|
1006 |
-
$gmedias[$i]->meta['web']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image']}/{$item->gmuid}";
|
1007 |
-
$gmedias[$i]->meta['original']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_original']}/{$item->gmuid}";
|
1008 |
-
|
1009 |
-
$
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
if(
|
1017 |
-
$
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1025 |
)
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
|
|
1029 |
}
|
1030 |
}
|
1031 |
-
|
1032 |
-
|
|
|
|
|
|
|
1033 |
}
|
1034 |
-
|
1035 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1036 |
}
|
|
|
1037 |
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1043 |
}
|
1044 |
}
|
1045 |
-
$out = array_merge($filter, array(
|
1046 |
-
|
1047 |
-
'request' => isset($data['request'])? $data['request'] : null,
|
1048 |
-
'total_pages' => $gmDB->pages,
|
1049 |
-
'current_page' => $gmDB->openPage,
|
1050 |
-
'items_count' => $gmDB->resultPerPage,
|
1051 |
-
'total_count' => $gmDB->totalResult,
|
1052 |
-
'count' => count($all_gmedias_ids)
|
1053 |
-
)),
|
1054 |
-
'data' => array_values($gmedias)
|
1055 |
));
|
1056 |
break;
|
1057 |
case 'delete_term':
|
1058 |
$taxonomy = $data['taxonomy'];
|
1059 |
-
if(!empty($data['items']))
|
1060 |
-
if(!current_user_can('gmedia_terms_delete'))
|
1061 |
$error[] = __('You have no permission to do this operation', 'grand-media');
|
1062 |
break;
|
1063 |
}
|
1064 |
$count = count($data['items']);
|
1065 |
-
foreach($data['items'] as $item)
|
1066 |
-
if(!current_user_can('gmedia_edit_others_media'))
|
1067 |
-
if('gmedia_album' == $taxonomy)
|
1068 |
$term = $gmDB->get_term($item, $taxonomy);
|
1069 |
-
if((int)$term->global != (int)$user_ID)
|
1070 |
$error['delete_album'] = __('You are not allowed to edit others media', 'grand-media');
|
1071 |
-
$count--;
|
1072 |
continue;
|
1073 |
}
|
1074 |
-
} else
|
1075 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1076 |
-
$count--;
|
1077 |
continue;
|
1078 |
}
|
1079 |
}
|
1080 |
$delete = $gmDB->delete_term($item);
|
1081 |
-
if(is_wp_error($delete))
|
1082 |
$error[] = $delete->get_error_message();
|
1083 |
-
$count--;
|
1084 |
}
|
1085 |
}
|
1086 |
-
if($count)
|
1087 |
$alert[] = sprintf(__('%d items deleted successfuly', 'grand-media'), $count);
|
1088 |
}
|
1089 |
}
|
@@ -1093,207 +1198,269 @@ function gmedia_ios_app_processor($action, $data, $filter = true) {
|
|
1093 |
$taxonomy = $data['taxonomy'];
|
1094 |
$edit_term = isset($data['term_id'])? (int)$data['term_id'] : 0;
|
1095 |
$term = $data;
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
);
|
1103 |
|
1104 |
return $out;
|
1105 |
}
|
1106 |
-
|
|
|
1107 |
$term['name'] = trim($term['name']);
|
1108 |
-
if(empty($term['name']))
|
1109 |
$error[] = __('Term Name is not specified', 'grand-media');
|
1110 |
break;
|
1111 |
}
|
1112 |
-
if($gmCore->is_digit($term['name']))
|
1113 |
$error[] = __("Term Name can't be only digits", 'grand-media');
|
1114 |
break;
|
1115 |
}
|
1116 |
-
if(1 === $logic && isset($term['status']) && 'public' == $term['status'])
|
1117 |
$term['status'] = 'publish';
|
1118 |
}
|
1119 |
-
if($edit_term && !$gmDB->term_exists($edit_term, $taxonomy))
|
1120 |
$error[] = __('A term with the id provided do not exists', 'grand-media');
|
1121 |
$edit_term = false;
|
1122 |
}
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
|
|
|
|
1126 |
break;
|
1127 |
}
|
1128 |
}
|
1129 |
-
if($edit_term)
|
1130 |
$_term = $gmDB->get_term($edit_term, $taxonomy);
|
1131 |
-
if(((int)$_term->global != (int)$user_ID) && !current_user_can('gmedia_edit_others_media'))
|
1132 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1133 |
break;
|
1134 |
}
|
1135 |
$term_id = $gmDB->update_term($edit_term, $term);
|
1136 |
-
} else
|
1137 |
-
if(!current_user_can('gmedia_edit_others_media'))
|
1138 |
$term['global'] = intval($user_ID);
|
1139 |
}
|
1140 |
$term_id = $gmDB->insert_term($term['name'], $taxonomy, $term);
|
1141 |
}
|
1142 |
-
if(is_wp_error($term_id))
|
1143 |
$error[] = $term_id->get_error_message();
|
|
|
1144 |
break;
|
1145 |
}
|
1146 |
-
$
|
1147 |
-
|
|
|
1148 |
$term_meta['_orderby'] = $term['_orderby'];
|
1149 |
-
} elseif(isset($term['orderby']))
|
1150 |
$term_meta['_orderby'] = $term['orderby'];
|
1151 |
}
|
1152 |
-
if(isset($term['_order']))
|
1153 |
$term_meta['_order'] = $term['_order'];
|
1154 |
-
} elseif(isset($term['order']))
|
1155 |
$term_meta['_order'] = $term['order'];
|
1156 |
}
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
}
|
1163 |
}
|
1164 |
|
1165 |
$alert[] = sprintf(__('Album `%s` successfuly saved', 'grand-media'), $term['name']);
|
1166 |
|
1167 |
} while(0);
|
1168 |
-
$
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1175 |
);
|
1176 |
|
1177 |
return $out;
|
1178 |
}
|
1179 |
-
|
1180 |
-
|
|
|
1181 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1182 |
break;
|
1183 |
}
|
1184 |
$term['name'] = trim($term['name']);
|
1185 |
$term['term_id'] = intval($term['term_id']);
|
1186 |
-
if($term['name'] && !$gmCore->is_digit($term['name']))
|
1187 |
-
if(($term_id = $gmDB->term_exists($term['term_id'], $taxonomy)))
|
1188 |
-
|
|
|
1189 |
$term_id = $gmDB->update_term($term['term_id'], $term);
|
1190 |
-
if(is_wp_error($term_id))
|
1191 |
$error[] = $term_id->get_error_message();
|
1192 |
-
|
1193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1194 |
}
|
1195 |
-
} else
|
1196 |
-
$error[]
|
|
|
1197 |
}
|
1198 |
-
} else
|
1199 |
$error[] = __("A term with the id provided do not exists", 'grand-media');
|
1200 |
}
|
1201 |
-
} else
|
1202 |
$error[] = __("Term name can't be only digits or empty", 'grand-media');
|
1203 |
}
|
1204 |
-
} else
|
1205 |
$terms = array_filter(array_map('trim', explode(',', $term['name'])));
|
1206 |
$terms_added = 0;
|
1207 |
$terms_qty = count($terms);
|
1208 |
-
foreach($terms as $term_name)
|
1209 |
-
if($gmCore->is_digit($term_name))
|
1210 |
continue;
|
1211 |
}
|
1212 |
|
1213 |
-
if(
|
1214 |
$term_id = $gmDB->insert_term($term_name, $taxonomy);
|
1215 |
-
if(is_wp_error($term_id))
|
1216 |
$error[] = $term_id->get_error_message();
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
|
|
1220 |
}
|
1221 |
-
} else
|
1222 |
-
$alert['category_add']
|
|
|
1223 |
}
|
1224 |
}
|
1225 |
}
|
1226 |
-
$
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1233 |
);
|
1234 |
|
1235 |
return $out;
|
1236 |
}
|
1237 |
-
|
1238 |
-
|
|
|
1239 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1240 |
break;
|
1241 |
}
|
1242 |
$term['name'] = trim($term['name']);
|
1243 |
$term['term_id'] = intval($term['term_id']);
|
1244 |
-
if($term['name'] && !$gmCore->is_digit($term['name']))
|
1245 |
-
if(($term_id = $gmDB->term_exists($term['term_id'], $taxonomy)))
|
1246 |
-
if(
|
1247 |
$term_id = $gmDB->update_term($term['term_id'], $term);
|
1248 |
-
if(is_wp_error($term_id))
|
1249 |
$error[] = $term_id->get_error_message();
|
1250 |
-
|
1251 |
-
|
|
|
|
|
1252 |
}
|
1253 |
-
} else
|
1254 |
-
$error[]
|
|
|
1255 |
}
|
1256 |
-
} else
|
1257 |
$error[] = __("A term with the id provided do not exists", 'grand-media');
|
1258 |
}
|
1259 |
-
} else
|
1260 |
$error[] = __("Term name can't be only digits or empty", 'grand-media');
|
1261 |
}
|
1262 |
-
} else
|
1263 |
$terms = array_filter(array_map('trim', explode(',', $term['name'])));
|
1264 |
$terms_added = 0;
|
1265 |
$terms_qty = count($terms);
|
1266 |
-
foreach($terms as $term_name)
|
1267 |
-
if($gmCore->is_digit($term_name))
|
1268 |
continue;
|
1269 |
}
|
1270 |
|
1271 |
-
if(
|
1272 |
$term_id = $gmDB->insert_term($term_name, $taxonomy);
|
1273 |
-
if(is_wp_error($term_id))
|
1274 |
$error[] = $term_id->get_error_message();
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
|
|
1278 |
}
|
1279 |
-
} else
|
1280 |
-
$alert['tag_add']
|
|
|
1281 |
}
|
1282 |
}
|
1283 |
}
|
1284 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1285 |
}
|
1286 |
-
|
1287 |
break;
|
1288 |
default:
|
1289 |
break;
|
1290 |
}
|
1291 |
|
1292 |
-
if(!empty($error))
|
1293 |
$out['error'] = array('code' => $action, 'title' => 'ERROR', 'message' => implode("\n", $error));
|
|
|
|
|
|
|
1294 |
}
|
1295 |
-
if(!empty($alert))
|
1296 |
$out['alert'] = array('title' => 'Success', 'message' => implode("\n", $alert));
|
|
|
|
|
|
|
1297 |
}
|
1298 |
|
1299 |
return $out;
|
@@ -1303,31 +1470,31 @@ function gmedia_ios_app_processor($action, $data, $filter = true) {
|
|
1303 |
/**
|
1304 |
* @param $data
|
1305 |
*/
|
1306 |
-
function gmedia_ios_app_counters($data)
|
1307 |
global $gmDB;
|
1308 |
|
1309 |
$data = (array)$data;
|
1310 |
$items_counter = array();
|
1311 |
-
if(!empty($data['views']))
|
1312 |
-
foreach($data['views'] as $gmID)
|
1313 |
-
$items_counter[$gmID]['views'] = 1;
|
1314 |
}
|
1315 |
-
if(!empty($data['likes']))
|
1316 |
-
foreach($data['likes'] as $gmID)
|
1317 |
-
$items_counter[$gmID]['likes'] = 1;
|
1318 |
}
|
1319 |
}
|
1320 |
}
|
1321 |
|
1322 |
-
if(!empty($items_counter))
|
1323 |
-
foreach($items_counter as $gmID => $counters)
|
1324 |
-
if(null === $gmDB->get_gmedia($gmID))
|
1325 |
continue;
|
1326 |
}
|
1327 |
$counters['views'] = $gmDB->get_metadata('gmedia', $gmID, 'views', true);
|
1328 |
$counters['views'] += 1;
|
1329 |
$gmDB->update_metadata('gmedia', $gmID, 'views', $counters['views']);
|
1330 |
-
if(isset($counters['likes']))
|
1331 |
$counters['likes'] = $gmDB->get_metadata('gmedia', $gmID, 'likes', true);
|
1332 |
$counters['likes'] += 1;
|
1333 |
$gmDB->update_metadata('gmedia', $gmID, 'likes', $counters['likes']);
|
3 |
* Application access
|
4 |
*/
|
5 |
|
6 |
+
$time = - microtime(true);
|
7 |
|
8 |
// don't load directly
|
9 |
+
if(!defined('ABSPATH')){
|
10 |
die('-1');
|
11 |
}
|
12 |
|
13 |
global $wp;
|
14 |
$gmedia_app = isset($_GET['gmedia-app'])? $_GET['gmedia-app'] : (isset($wp->query_vars['gmedia-app'])? $wp->query_vars['gmedia-app'] : false);
|
15 |
+
if(!$gmedia_app){
|
16 |
die();
|
17 |
}
|
18 |
|
22 |
$out = array();
|
23 |
|
24 |
$gmedia_options = get_option('gmediaOptions');
|
25 |
+
if(empty($gmedia_options['mobile_app'])){
|
26 |
$out['error'] = array('code' => 'app_inactive', 'message' => 'Service not enabled/activated for this site');
|
27 |
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
|
28 |
echo json_encode($out);
|
30 |
}
|
31 |
|
32 |
|
33 |
+
if(isset($_FILES['userfile']['name'])){
|
34 |
$globaldata = isset($_POST['account'])? $_POST['account'] : false;
|
35 |
+
if($globaldata){
|
36 |
$globaldata = stripslashes($globaldata);
|
37 |
}
|
38 |
+
} else{
|
39 |
$globaldata = isset($GLOBALS['HTTP_RAW_POST_DATA'])? $GLOBALS['HTTP_RAW_POST_DATA'] : false;
|
40 |
}
|
41 |
|
42 |
+
if($globaldata){
|
43 |
|
44 |
$json = json_decode($globaldata);
|
45 |
|
47 |
global $gmAuth;
|
48 |
$gmAuth = new Gmedia_JSON_API_Auth_Controller();
|
49 |
|
50 |
+
if(isset($json->counter)){
|
51 |
gmedia_ios_app_counters($json->counter);
|
52 |
}
|
53 |
|
54 |
+
if(isset($json->cookie) && !empty($json->cookie)){
|
55 |
$user_id = $gmAuth->validate_auth_cookie($json->cookie);
|
56 |
+
if($user_id){
|
57 |
$user = wp_set_current_user($user_id);
|
58 |
+
if(isset($json->add_term)){
|
59 |
$out = gmedia_ios_app_processor('add_term', $json->add_term);
|
60 |
+
} elseif(isset($json->delete_term)){
|
61 |
$out = gmedia_ios_app_processor('delete_term', $json->delete_term);
|
62 |
+
} elseif(isset($json->doLibrary)){
|
63 |
$job = gmedia_ios_app_processor('do_library', $json->doLibrary);
|
64 |
$out = gmedia_ios_app_processor('library', $json->library, false);
|
65 |
$out = array_merge($out, $job);
|
66 |
+
} elseif(isset($json->library)){
|
67 |
$out = gmedia_ios_app_processor('library', $json->library);
|
68 |
+
} elseif(isset($json->library_terms)){
|
69 |
$args = (array)$json->library_terms;
|
70 |
+
if(isset($args['taxonomy'])){
|
71 |
$out = gmedia_ios_app_library_data(array($args['taxonomy']), $args);
|
72 |
}
|
73 |
}
|
74 |
|
75 |
+
} else{
|
76 |
$out['error'] = array('code' => 'wrongcookie', 'message' => 'Not Valid User');
|
77 |
}
|
78 |
+
} elseif(isset($json->login)){
|
79 |
$out = gmedia_ios_app_login($json);
|
80 |
+
if(!isset($out['error'])){
|
81 |
$user = wp_set_current_user($out['user']['id']);
|
82 |
|
83 |
+
$gmedia_capabilities_list = array('gmedia_library',
|
84 |
+
'gmedia_show_others_media',
|
85 |
+
'gmedia_edit_media',
|
86 |
+
'gmedia_edit_others_media',
|
87 |
+
'gmedia_delete_media',
|
88 |
+
'gmedia_delete_others_media',
|
89 |
+
'gmedia_upload',
|
90 |
+
'gmedia_terms',
|
91 |
+
'gmedia_album_manage',
|
92 |
+
'gmedia_category_manage',
|
93 |
+
'gmedia_tag_manage',
|
94 |
+
'gmedia_terms_delete'
|
|
|
95 |
);
|
96 |
$gmedia_capabilities = array();
|
97 |
+
foreach($gmedia_capabilities_list as $cap){
|
98 |
+
$gmedia_capabilities[ $cap ] = current_user_can($cap);
|
99 |
}
|
100 |
|
101 |
$out['user']['gmedia_capabilities'] = $gmedia_capabilities;
|
103 |
$data = gmedia_ios_app_library_data();
|
104 |
$out = $out + $data;
|
105 |
}
|
106 |
+
} else{
|
107 |
+
if(isset($json->library)){
|
108 |
$out = gmedia_ios_app_processor('library', $json->library);
|
109 |
+
} elseif(isset($json->library_terms)){
|
110 |
$args = (array)$json->library_terms;
|
111 |
+
if(isset($args['taxonomy'])){
|
112 |
$out = gmedia_ios_app_library_data(array($args['taxonomy']), $args);
|
113 |
}
|
114 |
+
} else{
|
115 |
$out = gmedia_ios_app_library_data();
|
116 |
}
|
117 |
}
|
118 |
|
119 |
+
} elseif('lostpassword' == $gmCore->_get('action')){
|
120 |
+
if(function_exists('wp_lostpassword_url')){
|
121 |
$url = wp_lostpassword_url();
|
122 |
+
} else{
|
123 |
$url = add_query_arg('action', 'lostpassword', wp_login_url());
|
124 |
}
|
125 |
wp_redirect($url);
|
132 |
*
|
133 |
* @return array
|
134 |
*/
|
135 |
+
function gmedia_ios_app_login($json){
|
136 |
global $gmAuth;
|
137 |
|
138 |
+
do{
|
139 |
+
if(empty($json->login)){
|
140 |
$out['error'] = array('code' => 'nologin', 'title' => 'No Login', 'message' => 'No Login');
|
141 |
break;
|
142 |
}
|
143 |
+
if(!isset($json->password) || empty($json->password)){
|
144 |
$out['error'] = array('code' => 'nopassword', 'title' => 'No Password', 'message' => 'No Password');
|
145 |
break;
|
146 |
}
|
147 |
+
$uid = false;
|
148 |
+
if(is_email($json->login)){
|
149 |
+
$uid = email_exists($json->login);
|
150 |
+
}
|
151 |
+
if(!$uid && !($uid = username_exists($json->login))){
|
152 |
+
$out['error'] = array('code' => 'nouser',
|
153 |
+
'title' => 'Sorry, we can\'t log you in.',
|
154 |
+
'message' => 'No User'
|
155 |
);
|
156 |
break;
|
157 |
}
|
158 |
|
159 |
+
$args = array('username' => $json->login,
|
160 |
+
'password' => $json->password,
|
161 |
+
'nonce' => wp_create_nonce('auth_gmapp')
|
|
|
162 |
);
|
163 |
$out = $gmAuth->generate_auth_cookie($args);
|
164 |
|
169 |
|
170 |
/**
|
171 |
* @param array $data
|
|
|
172 |
* @param $args
|
173 |
*
|
174 |
* @return array
|
175 |
*/
|
176 |
+
function gmedia_ios_app_library_data($data = array('site', 'authors', 'filter', 'gmedia_category', 'gmedia_album', 'gmedia_tag'), $args = array()){
|
177 |
+
global $user_ID, $wpdb, $gmDB, $gmGallery, $gmapp_version;
|
|
|
|
|
|
|
178 |
|
179 |
+
if(null === $data){
|
180 |
$data = array('site', 'authors', 'filter', 'gmedia_category', 'gmedia_album', 'gmedia_tag');
|
181 |
}
|
182 |
|
183 |
+
if(version_compare('3', $gmapp_version, '<=')){
|
184 |
$logic = 2;
|
185 |
+
if(version_compare('3.1', $gmapp_version, '<')){
|
186 |
+
$logic = 3;
|
187 |
+
}
|
188 |
$terms_per_page = 40;
|
189 |
+
} else{
|
190 |
$logic = 1;
|
191 |
$terms_per_page = '';
|
192 |
}
|
195 |
$out = array();
|
196 |
|
197 |
$ep = $gmGallery->options['endpoint'];
|
198 |
+
if(get_option('permalink_structure')){
|
199 |
$share_link_base = home_url(urlencode($ep) . '/$2/$1');
|
200 |
+
} else{
|
201 |
$share_link_base = add_query_arg(array("$ep" => '$1', 't' => '$2'), home_url('index.php'));
|
202 |
}
|
203 |
|
204 |
+
if(in_array('site', $data)){
|
205 |
+
$site_name = get_bloginfo('name');
|
206 |
$site_description = get_bloginfo('description');
|
207 |
+
$out['site'] = array('title' => $site_name? $site_name : '',
|
208 |
+
'description' => $site_description? $site_description : ''
|
|
|
209 |
);
|
210 |
}
|
211 |
+
if(in_array('authors', $data)){
|
212 |
+
$out['authors'] = array('data' => array()
|
|
|
213 |
);
|
214 |
+
$gmusers = $wpdb->get_col("SELECT DISTINCT author FROM {$wpdb->prefix}gmedia");
|
215 |
+
$gmusers2 = $wpdb->get_col("SELECT DISTINCT {$wpdb->prefix}gmedia_term.global FROM {$wpdb->prefix}gmedia_term");
|
216 |
+
$gmusers = array_filter(array_unique(array_merge($gmusers, $gmusers2)));
|
217 |
//if(current_user_can('gmedia_show_others_media') || current_user_can('gmedia_edit_others_media')){
|
218 |
+
if(!empty($gmusers)){
|
219 |
+
$authors = get_users(array('include' => $gmusers, 'orderby' => 'display_name'));
|
220 |
+
if($authors){
|
221 |
+
foreach($authors as $author){
|
222 |
+
$out['authors']['data'][] = array('id' => $author->ID,
|
223 |
+
'displayname' => $author->display_name,
|
224 |
+
'firstname' => $author->first_name,
|
225 |
+
'lastname' => $author->last_name
|
226 |
+
);
|
227 |
+
}
|
228 |
}
|
229 |
}
|
230 |
/*} else{
|
235 |
$out['authors']['data'][] = array('id' => $user_ID, 'displayname' => $display_name, 'firstname' => $first_name, 'lastname' => $last_name);
|
236 |
}*/
|
237 |
}
|
238 |
+
if(in_array('filter', $data)){
|
239 |
$gmDB->clauses = array();
|
240 |
$out['filter'] = $gmDB->count_gmedia();
|
241 |
$out['filter'] = array_map('intval', $out['filter']);
|
242 |
}
|
243 |
+
if(in_array('gmedia_category', $data)){
|
244 |
if($user_ID){
|
245 |
+
if(current_user_can('gmedia_terms_delete') && current_user_can('gmedia_delete_others_media')){
|
246 |
$cap = 4;
|
247 |
+
} elseif(current_user_can('gmedia_category_manage')){
|
248 |
$cap = 2;
|
249 |
+
} else{
|
250 |
$cap = 0;
|
251 |
}
|
252 |
} else{
|
254 |
}
|
255 |
//$default_args = array('fields' => 'name=>all');
|
256 |
$default_args = array();
|
257 |
+
$_args = $args;
|
258 |
+
if(isset($_args['per_page'])){
|
259 |
+
$_args['number'] = $_args['per_page'];
|
260 |
}
|
261 |
+
$_args = array_merge($default_args, $_args);
|
262 |
+
$gmediaTerms = $gmDB->get_terms('gmedia_category', $_args);
|
263 |
+
$props = array('per_page' => $_args['number'],
|
264 |
+
'total_pages' => $gmDB->pages,
|
265 |
+
'current_page' => $gmDB->openPage,
|
266 |
+
'items_count' => $gmDB->resultPerPage,
|
267 |
+
'total_count' => $gmDB->totalResult
|
|
|
268 |
);
|
269 |
$terms = array('0' => __('Uncategorized', 'grand-media'));
|
270 |
+
$out['categories'] = array('list' => $terms,
|
271 |
+
'cap' => $cap,
|
272 |
+
'properties' => $props,
|
273 |
+
'data' => array()
|
|
|
274 |
);
|
275 |
+
if(!empty($gmediaTerms)){
|
276 |
+
foreach($gmediaTerms as $i => $term){
|
277 |
$out['categories']['list']["{$term->term_id}"] = $term->name;
|
278 |
+
gmedia_ios_app_term_data_extend($gmediaTerms[ $i ], $share_link_base, $logic, $cap);
|
279 |
}
|
280 |
|
281 |
+
$out['categories']['data'] = array_values($gmediaTerms);
|
282 |
}
|
283 |
}
|
284 |
+
if(in_array('gmedia_album', $data)){
|
285 |
$default_args = array();
|
286 |
+
$_args = $args;
|
287 |
+
if(1 < $logic){
|
288 |
$default_args['orderby'] = 'ID';
|
289 |
$default_args['order'] = 'DESC';
|
290 |
}
|
291 |
|
292 |
+
if($user_ID){
|
293 |
+
if(current_user_can('gmedia_terms_delete')){
|
294 |
$cap = 4;
|
295 |
+
} elseif(current_user_can('gmedia_album_manage')){
|
296 |
$cap = 2;
|
297 |
+
} else{
|
298 |
$cap = 0;
|
299 |
}
|
300 |
/*if( !current_user_can('gmedia_edit_others_media')){
|
301 |
//$default_args = array( 'status' => array('publish', 'private') );
|
302 |
//$default_args['global'] = array( $user_ID, 0 );
|
303 |
}*/
|
304 |
+
} else{
|
305 |
$cap = 0;
|
306 |
$default_args = array('status' => 'publish');
|
307 |
}
|
308 |
+
if(isset($_args['per_page'])){
|
309 |
+
$_args['number'] = $_args['per_page'];
|
310 |
}
|
311 |
+
$_args = array_merge($default_args, $_args);
|
312 |
+
|
313 |
+
$gmediaTerms = $gmDB->get_terms('gmedia_album', $_args);
|
314 |
+
$props = array('per_page' => $_args['number'],
|
315 |
+
'total_pages' => $gmDB->pages,
|
316 |
+
'current_page' => $gmDB->openPage,
|
317 |
+
'items_count' => $gmDB->resultPerPage,
|
318 |
+
'total_count' => $gmDB->totalResult
|
|
|
319 |
);
|
320 |
+
foreach($gmediaTerms as $i => $term){
|
321 |
+
gmedia_ios_app_term_data_extend($gmediaTerms[ $i ], $share_link_base, $logic, $cap);
|
322 |
}
|
323 |
+
$gmediaTerms = array_filter($gmediaTerms);
|
324 |
$props['items_count'] = count($gmediaTerms);
|
325 |
|
326 |
+
$out['albums'] = array('cap' => $cap,
|
327 |
+
'properties' => $props,
|
328 |
+
'data' => array_values($gmediaTerms)
|
|
|
329 |
);
|
330 |
}
|
331 |
+
if(in_array('gmedia_tag', $data)){
|
332 |
$default_args = array();
|
333 |
+
$_args = $args;
|
334 |
+
if($user_ID){
|
335 |
+
if(current_user_can('gmedia_terms_delete') && current_user_can('gmedia_delete_others_media')){
|
336 |
$cap = 4;
|
337 |
+
} elseif(current_user_can('gmedia_tag_manage')){
|
338 |
$cap = 2;
|
339 |
+
} else{
|
340 |
$cap = 0;
|
341 |
}
|
342 |
+
} else{
|
343 |
$cap = 0;
|
344 |
}
|
345 |
+
if(isset($_args['per_page'])){
|
346 |
+
$_args['number'] = $_args['per_page'];
|
347 |
}
|
348 |
+
$_args = array_merge($default_args, $_args);
|
349 |
+
$gmediaTerms = $gmDB->get_terms('gmedia_tag', $_args);
|
350 |
+
$props = array('per_page' => $_args['number'],
|
351 |
+
'total_pages' => $gmDB->pages,
|
352 |
+
'current_page' => $gmDB->openPage,
|
353 |
+
'items_count' => $gmDB->resultPerPage,
|
354 |
+
'total_count' => $gmDB->totalResult
|
|
|
355 |
);
|
356 |
+
foreach($gmediaTerms as $i => $term){
|
357 |
+
gmedia_ios_app_term_data_extend($gmediaTerms[ $i ], $share_link_base, $logic, $cap);
|
358 |
}
|
359 |
+
$out['tags'] = array('cap' => $cap,
|
360 |
+
'properties' => $props,
|
361 |
+
'data' => array_values($gmediaTerms)
|
|
|
362 |
);
|
363 |
}
|
364 |
|
368 |
/**
|
369 |
* @param object $term
|
370 |
* @param string $share_link_base
|
|
|
371 |
* @param int $logic
|
372 |
* @param int $cap
|
373 |
*
|
374 |
* @return array
|
375 |
*/
|
376 |
+
function gmedia_ios_app_term_data_extend(&$term, $share_link_base, $logic = 0, $cap = 0){
|
377 |
global $gmCore, $gmDB, $gmGallery, $user_ID;
|
378 |
|
379 |
$taxterm = str_replace('gmedia_', '', $term->taxonomy);
|
380 |
$default_meta = array();
|
381 |
|
382 |
+
if('gmedia_album' == $term->taxonomy){
|
383 |
$author_id = (int)$term->global;
|
384 |
+
if($author_id){
|
385 |
+
if(($author_id != $user_ID) && ('draft' == $term->status) && !current_user_can('gmedia_edit_others_media')){
|
386 |
$term = null;
|
387 |
+
|
388 |
return;
|
389 |
}
|
390 |
$authordata = get_userdata($author_id);
|
391 |
+
if($authordata){
|
392 |
$display_name = $authordata->display_name;
|
393 |
$first_name = $authordata->first_name;
|
394 |
$last_name = $authordata->last_name;
|
395 |
+
} else{
|
396 |
$display_name = __('Deleted User', 'grand-media');
|
397 |
$first_name = '';
|
398 |
$last_name = '';
|
399 |
}
|
400 |
+
} else{
|
401 |
$display_name = __('Shared', 'grand-media');
|
402 |
$first_name = $last_name = '';
|
403 |
}
|
404 |
+
$term->user = array('id' => $author_id,
|
405 |
+
'displayname' => $display_name,
|
406 |
+
'firstname' => $first_name,
|
407 |
+
'lastname' => $last_name
|
|
|
408 |
);
|
409 |
|
410 |
$default_meta = array('_orderby' => 'ID', '_order' => 'DESC');
|
411 |
|
412 |
+
if(1 === $logic){
|
413 |
+
if('publish' == $term->status){
|
414 |
$term->status = 'public';
|
415 |
}
|
416 |
}
|
417 |
}
|
418 |
+
if('gmedia_category' == $term->taxonomy){
|
419 |
unset($term->global, $term->status);
|
420 |
$term->title = $term->name;
|
421 |
$default_meta = array('_orderby' => $gmGallery->options['in_category_orderby'], '_order' => $gmGallery->options['in_category_order']);
|
422 |
}
|
423 |
+
if('gmedia_tag' == $term->taxonomy){
|
424 |
unset($term->description, $term->global, $term->status);
|
425 |
|
426 |
$default_meta = array('_orderby' => $gmGallery->options['in_tag_orderby'], '_order' => $gmGallery->options['in_tag_order']);
|
427 |
}
|
428 |
|
429 |
$term_meta = $gmDB->get_metadata('gmedia_term', $term->term_id);
|
430 |
+
foreach($term_meta as $key => $value){
|
431 |
+
if(is_array($value)){
|
432 |
+
if($gmCore->is_protected_meta($key, 'gmedia_term')){
|
433 |
+
$term_meta[ $key ] = $value[0];
|
434 |
+
} elseif(1 === count($value)){
|
435 |
+
$term_meta[ $key ] = $value[0];
|
436 |
+
}
|
437 |
}
|
438 |
}
|
439 |
$term_meta = array_merge($default_meta, $term_meta);
|
440 |
$term_meta['orderby'] = $term_meta['_orderby'];
|
441 |
$term_meta['order'] = $term_meta['_order'];
|
442 |
|
443 |
+
if(in_array($term->taxonomy, array('gmedia_album', 'gmedia_category'))){
|
444 |
+
if(empty($term_meta['_cover'])){
|
445 |
$term_meta['_cover'] = false;
|
446 |
+
} else{
|
447 |
$term_meta['_cover'] = intval($term_meta['_cover']);
|
448 |
}
|
449 |
+
if($term_meta['_cover']){
|
450 |
$cover_id = (int)$term_meta['_cover'];
|
451 |
$cover = gmedia_ios_app_processor('library', array('gmedia__in' => array($cover_id)), false);
|
452 |
+
if(isset($cover['data'][0])){
|
453 |
$term_meta['_cover'] = $cover['data'][0];
|
454 |
$term->thumbnail = $gmCore->gm_get_media_image($cover_id, 'thumb', false);
|
455 |
+
} else{
|
456 |
$term_meta['_cover'] = false;
|
457 |
}
|
458 |
}
|
459 |
+
if(!$term_meta['_cover'] && $term->count){
|
460 |
+
$gmargs = array('no_found_rows' => true,
|
461 |
+
'mime_type' => 'image/*',
|
462 |
+
'per_page' => 1,
|
463 |
+
"{$taxterm}__in" => array($term->term_id),
|
464 |
+
'status' => 'publish',
|
465 |
+
'orderby' => $term_meta['orderby'],
|
466 |
+
'order' => $term_meta['order']
|
467 |
);
|
468 |
+
if($user_ID){
|
469 |
$gmargs['status'] = array('publish', 'private');
|
470 |
+
} else{
|
|
|
|
|
|
|
471 |
$gmargs['status'] = 'publish';
|
472 |
}
|
473 |
|
474 |
$termItems = $gmDB->get_gmedias($gmargs);
|
475 |
+
if(!empty($termItems)){
|
476 |
+
$cover = gmedia_ios_app_processor('library', array('gmedia__in' => array($termItems[0]->ID)), false);
|
477 |
+
if(isset($cover['data'][0])){
|
|
|
478 |
$term_meta['_cover'] = $cover['data'][0];
|
479 |
+
$term->thumbnail = $gmCore->gm_get_media_image($termItems[0], 'thumb', false);
|
480 |
}
|
|
|
481 |
}
|
482 |
}
|
483 |
}
|
484 |
|
485 |
$term->meta = $term_meta;
|
486 |
|
487 |
+
$t = array('album' => 'a',
|
488 |
+
'tag' => 't',
|
489 |
+
'category' => 'k'
|
|
|
490 |
);
|
491 |
$gmedia_hashid = gmedia_hash_id_encode($term->term_id, $taxterm);
|
492 |
+
$term->sharelink = str_replace(array('$1', '$2'), array(urlencode($gmedia_hashid), $t[ $taxterm ]), $share_link_base);
|
493 |
|
494 |
$term->cap = (4 == $cap)? 4 : 0;
|
495 |
}
|
497 |
/**
|
498 |
* @param $action
|
499 |
* @param $data
|
|
|
500 |
* @param bool $filter
|
501 |
*
|
502 |
* @return array
|
503 |
*/
|
504 |
+
function gmedia_ios_app_processor($action, $data, $filter = true){
|
505 |
global $gmCore, $gmDB, $gmGallery, $user_ID, $gmapp_version;
|
506 |
|
507 |
$out = array();
|
508 |
|
509 |
+
if(version_compare('3', $gmapp_version, '<=')){
|
510 |
$logic = 2;
|
511 |
+
if(version_compare('3.1', $gmapp_version, '<')){
|
512 |
+
$logic = 3;
|
513 |
+
}
|
514 |
+
} else{
|
515 |
$logic = 1;
|
516 |
}
|
517 |
|
518 |
+
$error = array();
|
519 |
+
$error_info = array();
|
520 |
+
$alert = array();
|
521 |
+
$alert_info = array();
|
522 |
+
$data = (array)$data;
|
523 |
+
switch($action){
|
524 |
case 'do_library':
|
525 |
|
526 |
+
if(!isset($data['action'])){
|
527 |
return $out;
|
528 |
}
|
529 |
+
$filter = array();
|
530 |
+
|
531 |
+
switch($data['action']){
|
532 |
|
533 |
case 'add_media':
|
534 |
+
if(!current_user_can('gmedia_upload')){
|
535 |
+
$out['error'] = array('code' => 'nocapability',
|
536 |
+
'title' => __("You can't do this", 'grand-media'),
|
537 |
+
'message' => __('You have no permission to do this operation', 'grand-media')
|
|
|
538 |
);
|
539 |
|
540 |
return $out;
|
542 |
|
543 |
usleep(10);
|
544 |
|
545 |
+
if(is_uploaded_file($_FILES['userfile']['tmp_name'])){
|
546 |
$file_name = $_FILES['userfile']['name'];
|
547 |
$file_tmp = $_FILES['userfile']['tmp_name'];
|
548 |
+
} else{
|
549 |
$error[] = __("Failed to move uploaded file.", 'grand-media');
|
550 |
break;
|
551 |
}
|
552 |
|
553 |
$fileinfo = $gmCore->fileinfo($file_name);
|
554 |
+
if(false === $fileinfo){
|
555 |
break;
|
556 |
}
|
557 |
|
558 |
$gmedia = (array)$data['item'];
|
559 |
+
if(!current_user_can('gmedia_terms')){
|
560 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
561 |
+
} else{
|
562 |
+
if(empty($gmedia['albums'])){
|
563 |
$gmedia['terms']['gmedia_album'] = '';
|
564 |
+
} else{
|
565 |
$alb = isset($gmedia['albums'][0]->term_id)? $gmedia['albums'][0]->term_id : $gmedia['albums'][0]->name;
|
566 |
$gmedia['terms']['gmedia_album'] = $alb;
|
567 |
}
|
568 |
+
if(empty($gmedia['categories'])){
|
569 |
$gmedia['terms']['gmedia_category'] = '';
|
570 |
+
} else{
|
571 |
$categories = array();
|
572 |
+
foreach($gmedia['categories'] as $category){
|
573 |
$categories[] = isset($category->term_id)? $category->term_id : $category->name;
|
574 |
}
|
575 |
$gmedia['terms']['gmedia_category'] = implode(',', $categories);
|
576 |
}
|
577 |
+
if(empty($gmedia['tags'])){
|
578 |
$gmedia['terms']['gmedia_tag'] = '';
|
579 |
+
} else{
|
580 |
$tags = array();
|
581 |
+
foreach($gmedia['tags'] as $tag){
|
582 |
$tags[] = isset($tag->term_id)? $tag->term_id : $tag->name;
|
583 |
}
|
584 |
$gmedia['terms']['gmedia_tag'] = implode(',', $tags);
|
585 |
}
|
586 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
587 |
}
|
588 |
+
if(isset($gmedia['status']) && 'public' == $gmedia['status']){
|
589 |
$gmedia['status'] = 'publish';
|
590 |
}
|
591 |
|
592 |
$return = $gmCore->gmedia_upload_handler($file_tmp, $fileinfo, 'multipart', $gmedia);
|
593 |
+
if(isset($return['error'])){
|
594 |
$error[] = $return['error']['message'];
|
595 |
+
} else{
|
596 |
$alert[] = $return['success']['message'];
|
597 |
}
|
598 |
break;
|
599 |
|
600 |
case 'update_media':
|
601 |
+
if(!current_user_can('gmedia_edit_media')){
|
602 |
+
$error[] = __('You are not allowed to edit media', 'grand-media');
|
603 |
+
break;
|
604 |
+
}
|
605 |
$gmedia = (array)$data['item'];
|
606 |
+
if(!empty($gmedia['ID'])){
|
607 |
$item = $gmDB->get_gmedia($gmedia['ID']);
|
608 |
+
if(!$item || ($user_ID != $item->author && !current_user_can('gmedia_edit_others_media'))){
|
609 |
+
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
610 |
+
break;
|
611 |
+
}
|
612 |
|
613 |
unset($gmedia['date'], $gmedia['mime_type'], $gmedia['gmuid'], $gmedia['modified']);
|
614 |
//$gmedia['modified'] = current_time('mysql');
|
615 |
+
if(!current_user_can('gmedia_delete_others_media')){
|
616 |
$gmedia['author'] = $item->author;
|
617 |
}
|
618 |
+
if(isset($gmedia['status']) && 'public' == $gmedia['status']){
|
619 |
$gmedia['status'] = 'publish';
|
620 |
}
|
621 |
|
622 |
|
623 |
+
if(!current_user_can('gmedia_terms')){
|
624 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
625 |
+
} else{
|
626 |
+
if(empty($gmedia['albums'])){
|
627 |
$gmedia['terms']['gmedia_album'] = '';
|
628 |
+
} else{
|
629 |
+
if(isset($gmedia['albums'][0]->term_id)){
|
630 |
$gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->term_id;
|
631 |
+
} elseif(current_user_can('gmedia_album_manage')){
|
632 |
$gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->name;
|
633 |
}
|
634 |
}
|
635 |
+
if(empty($gmedia['categories'])){
|
636 |
$gmedia['terms']['gmedia_category'] = '';
|
637 |
+
} else{
|
638 |
$categories = array();
|
639 |
+
foreach($gmedia['categories'] as $category){
|
640 |
+
if(isset($category->term_id)){
|
641 |
$categories[] = $category->term_id;
|
642 |
+
} elseif(current_user_can('gmedia_category_manage')){
|
643 |
$categories[] = $category->name;
|
644 |
}
|
645 |
}
|
646 |
+
$gmedia['terms']['gmedia_category'] = $categories;
|
647 |
}
|
648 |
+
if(empty($gmedia['tags'])){
|
649 |
$gmedia['terms']['gmedia_tag'] = '';
|
650 |
+
} else{
|
651 |
$tags = array();
|
652 |
+
foreach($gmedia['tags'] as $tag){
|
653 |
+
if(isset($tag->term_id)){
|
654 |
$tags[] = $tag->term_id;
|
655 |
+
} elseif(current_user_can('gmedia_tag_manage')){
|
656 |
$tags[] = $tag->name;
|
657 |
}
|
658 |
}
|
659 |
+
$gmedia['terms']['gmedia_tag'] = $tags;
|
660 |
}
|
661 |
unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']);
|
662 |
}
|
663 |
|
664 |
+
$gmDB->insert_gmedia($gmedia);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
665 |
}
|
666 |
break;
|
667 |
|
668 |
case 'assign_album':
|
669 |
+
if(!current_user_can('gmedia_edit_media')){
|
670 |
+
$error[] = __('You are not allowed to edit media', 'grand-media');
|
671 |
+
break;
|
672 |
+
}
|
673 |
+
if(!current_user_can('gmedia_terms')){
|
674 |
$error[] = __('You are not allowed to manage albums', 'grand-media');
|
675 |
}
|
676 |
$term = $data['assign_album'][0];
|
677 |
$count = count($data['selected']);
|
678 |
+
if('0' == $term){
|
679 |
+
foreach($data['selected'] as $item){
|
680 |
$gmDB->delete_gmedia_term_relationships($item, 'gmedia_album');
|
681 |
}
|
682 |
$alert[] = sprintf(__('%d item(s) updated with "No Album"', 'grand-media'), $count);
|
683 |
+
} else{
|
684 |
+
foreach($data['selected'] as $item){
|
685 |
+
$gm_item = $gmDB->get_gmedia($item);
|
686 |
+
if(!$gm_item || ($user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media'))){
|
687 |
+
continue;
|
688 |
+
}
|
689 |
$result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_album', $append = 0);
|
690 |
+
if(is_wp_error($result)){
|
691 |
$error[] = $result->get_error_message();
|
692 |
+
$count --;
|
693 |
+
} elseif(!$result){
|
694 |
+
$count --;
|
695 |
}
|
696 |
}
|
697 |
+
if($gmCore->is_digit($term)){
|
698 |
$alb_name = $gmDB->get_term_name($term);
|
699 |
+
} else{
|
700 |
$alb_name = $term;
|
701 |
}
|
702 |
+
$alert[] = sprintf(__('Album `%s` assigned to %d item(s)', 'grand-media'), esc_html($alb_name), $count);
|
|
|
703 |
}
|
704 |
break;
|
705 |
|
706 |
case 'assign_category':
|
707 |
+
if(!current_user_can('gmedia_edit_media')){
|
708 |
+
$error[] = __('You are not allowed to edit media', 'grand-media');
|
709 |
+
break;
|
710 |
+
}
|
711 |
+
if(!current_user_can('gmedia_terms')){
|
712 |
$error[] = __('You are not allowed to manage categories', 'grand-media');
|
713 |
break;
|
714 |
}
|
715 |
+
if(empty($data['assign_category'])){
|
716 |
$error[] = __('No categories provided', 'grand-media');
|
717 |
break;
|
718 |
}
|
719 |
$terms = $data['assign_category'];
|
720 |
$count = count($data['selected']);
|
721 |
+
if(1 === count($terms) && '0' == $terms[0]){
|
722 |
+
foreach($data['selected'] as $item){
|
723 |
+
$gm_item = $gmDB->get_gmedia($item);
|
724 |
+
if(!$gm_item || ($user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media'))){
|
725 |
+
continue;
|
726 |
+
}
|
727 |
$gmDB->delete_gmedia_term_relationships($item, 'gmedia_category');
|
728 |
}
|
729 |
$alert[] = sprintf(__('%d item(s) updated with "Uncategorized"', 'grand-media'), $count);
|
730 |
+
} else{
|
731 |
+
foreach($data['selected'] as $item){
|
732 |
+
$gm_item = $gmDB->get_gmedia($item);
|
733 |
+
if(!$gm_item || ($user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media'))){
|
734 |
+
continue;
|
735 |
+
}
|
736 |
$result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_category', $append = 0);
|
737 |
+
if(is_wp_error($result)){
|
738 |
$error[] = $result->get_error_message();
|
739 |
+
$count --;
|
740 |
+
} elseif(!$result){
|
741 |
+
$count --;
|
742 |
}
|
743 |
}
|
744 |
$alert[] = sprintf(__('%d category(ies) added to %d item(s)', 'grand-media'), count($terms), $count);
|
746 |
break;
|
747 |
|
748 |
case 'unassign_category':
|
749 |
+
if(!current_user_can('gmedia_edit_media')){
|
750 |
+
$error[] = __('You are not allowed to edit media', 'grand-media');
|
751 |
break;
|
752 |
}
|
753 |
+
if(empty($data['unassign_category'])){
|
754 |
$error[] = __('No categories provided', 'grand-media');
|
755 |
break;
|
756 |
}
|
757 |
$terms = array_map('intval', $data['unassign_category']);
|
758 |
$count = count($data['selected']);
|
759 |
+
foreach($data['selected'] as $item){
|
760 |
+
$gm_item = $gmDB->get_gmedia($item);
|
761 |
+
if(!$gm_item || ($user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media'))){
|
762 |
+
continue;
|
763 |
+
}
|
764 |
+
$result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_category', $append = - 1);
|
765 |
+
if(is_wp_error($result)){
|
766 |
$error[] = $result->get_error_message();
|
767 |
+
$count --;
|
768 |
+
} elseif(!$result){
|
769 |
+
$count --;
|
770 |
}
|
771 |
}
|
772 |
$alert[] = sprintf(__('%d category(ies) deleted from %d item(s)', 'grand-media'), count($terms), $count);
|
773 |
break;
|
774 |
|
775 |
case 'add_tags':
|
776 |
+
if(!current_user_can('gmedia_edit_media')){
|
777 |
+
$error[] = __('You are not allowed to edit media', 'grand-media');
|
778 |
+
break;
|
779 |
+
}
|
780 |
+
if(!current_user_can('gmedia_terms')){
|
781 |
$error[] = __('You are not allowed manage tags', 'grand-media');
|
782 |
break;
|
783 |
}
|
784 |
+
if(empty($data['add_tags'])){
|
785 |
$error[] = __('No tags provided', 'grand-media');
|
786 |
break;
|
787 |
}
|
788 |
$terms = $data['add_tags'];
|
789 |
$count = count($data['selected']);
|
790 |
+
foreach($data['selected'] as $item){
|
791 |
+
$gm_item = $gmDB->get_gmedia($item);
|
792 |
+
if(!$gm_item || ($user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media'))){
|
793 |
+
continue;
|
794 |
+
}
|
795 |
$result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_tag', $append = 1);
|
796 |
+
if(is_wp_error($result)){
|
797 |
$error[] = $result->get_error_message();
|
798 |
+
$count --;
|
799 |
+
} elseif(!$result){
|
800 |
+
$count --;
|
801 |
+
}
|
802 |
+
}
|
803 |
+
$alert[] = sprintf(__('%d tag(s) added to %d item(s)', 'grand-media'), count($terms), $count);
|
804 |
+
break;
|
805 |
+
|
806 |
+
case 'add_cover':
|
807 |
+
if(!current_user_can('gmedia_edit_media')){
|
808 |
+
$error[] = __('You are not allowed to edit media', 'grand-media');
|
809 |
+
break;
|
810 |
+
}
|
811 |
+
$cover = (int) $data['add_cover'];
|
812 |
+
$count = count($data['selected']);
|
813 |
+
foreach($data['selected'] as $item){
|
814 |
+
$gm_item = $gmDB->get_gmedia($item);
|
815 |
+
if(!$gm_item || ($user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media'))){
|
816 |
$count--;
|
817 |
+
continue;
|
818 |
+
}
|
819 |
+
if('image' == substr($gm_item->mime_type, 0, 5)){
|
820 |
$count--;
|
821 |
+
continue;
|
822 |
+
}
|
823 |
+
if($cover){
|
824 |
+
$gmDB->update_metadata('gmedia', $gm_item->ID, '_cover', $cover);
|
825 |
+
} else {
|
826 |
+
$gmDB->delete_metadata('gmedia', $gm_item->ID, '_cover');
|
827 |
}
|
828 |
}
|
829 |
+
$alert[] = sprintf(__('%d item(s) updated', 'grand-media'), $count);
|
830 |
break;
|
831 |
|
832 |
case 'delete_tags':
|
833 |
+
if(!current_user_can('gmedia_edit_media')){
|
834 |
+
$error[] = __('You are not allowed to edit media', 'grand-media');
|
835 |
break;
|
836 |
}
|
837 |
+
if(empty($data['delete_tags'])){
|
838 |
$error[] = __('No tags provided', 'grand-media');
|
839 |
break;
|
840 |
}
|
841 |
$terms = array_map('intval', $data['delete_tags']);
|
842 |
$count = count($data['selected']);
|
843 |
+
foreach($data['selected'] as $item){
|
844 |
+
$gm_item = $gmDB->get_gmedia($item);
|
845 |
+
if(!$gm_item || ($user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media'))){
|
846 |
+
continue;
|
847 |
+
}
|
848 |
+
$result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_tag', $append = - 1);
|
849 |
+
if(is_wp_error($result)){
|
850 |
$error[] = $result->get_error_message();
|
851 |
+
$count --;
|
852 |
+
} elseif(!$result){
|
853 |
+
$count --;
|
854 |
}
|
855 |
}
|
856 |
$alert[] = sprintf(__('%d tag(s) deleted from %d item(s)', 'grand-media'), count($terms), $count);
|
857 |
break;
|
858 |
|
859 |
case 'delete':
|
860 |
+
if(!current_user_can('gmedia_delete_media')){
|
861 |
$error[] = __('You are not allowed to delete this post.');
|
862 |
break;
|
863 |
}
|
864 |
$count = count($data['selected']);
|
865 |
+
foreach($data['selected'] as $item){
|
866 |
$gm_item = $gmDB->get_gmedia($item);
|
867 |
+
if(((int)$gm_item->author != $user_ID) && !current_user_can('gmedia_delete_others_media')){
|
868 |
+
$error[] = "#{$item}: " . __('You are not allowed to delete media others media', 'grand-media');
|
|
|
869 |
continue;
|
870 |
}
|
871 |
+
if(!$gmDB->delete_gmedia((int)$item)){
|
872 |
$error[] = "#{$item}: " . __('Error in deleting...', 'grand-media');
|
873 |
+
$count --;
|
874 |
}
|
875 |
}
|
876 |
+
if($count){
|
877 |
$alert[] = sprintf(__('%d items deleted successfuly', 'grand-media'), $count);
|
878 |
}
|
879 |
break;
|
880 |
}
|
881 |
+
if(1 === $logic){
|
882 |
+
$filter = gmedia_ios_app_library_data(array('filter', 'gmedia_category', 'gmedia_album', 'gmedia_tag'));
|
883 |
+
}
|
884 |
+
$out = array_merge($out, $filter);
|
885 |
break;
|
886 |
|
887 |
case 'library':
|
888 |
$ep = $gmGallery->options['endpoint'];
|
889 |
+
if(get_option('permalink_structure')){
|
890 |
$share_link_base = home_url(urlencode($ep) . '/$2/$1');
|
891 |
+
} else{
|
892 |
$share_link_base = add_query_arg(array("$ep" => '$1', 't' => '$2'), home_url('index.php'));
|
893 |
}
|
894 |
$filter = $filter? gmedia_ios_app_library_data(array('filter')) : array();
|
895 |
|
896 |
+
$mime_type = ($logic > 2)? array('image', 'audio') : 'image';
|
897 |
+
$args = array('mime_type' => $mime_type,
|
898 |
+
'orderby' => 'ID',
|
899 |
+
'order' => 'DESC',
|
900 |
+
'per_page' => 100,
|
901 |
+
'page' => 1,
|
902 |
+
'tag__in' => null,
|
903 |
+
'category__in' => null,
|
904 |
+
'album__in' => null,
|
905 |
+
'gmedia__in' => null,
|
906 |
+
'author' => 0,
|
907 |
+
'status' => null
|
908 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
909 |
|
910 |
$terms_ids_query = array();
|
911 |
+
if(!empty($data['tag__in'])){
|
912 |
+
if(empty($data['category__in']) && empty($data['album__in'])){
|
913 |
+
$args['orderby'] = $gmGallery->options['in_tag_orderby'];
|
914 |
+
$args['order'] = $gmGallery->options['in_tag_order'];
|
915 |
+
}
|
916 |
+
$terms_ids_query = array_merge($terms_ids_query, $data['tag__in']);
|
917 |
}
|
918 |
+
if(!empty($data['category__in'])){
|
919 |
+
$cat_ids = wp_parse_id_list($data['category__in']);
|
920 |
+
if(1 === count($cat_ids)){
|
921 |
+
$cat_meta = $gmDB->get_metadata('gmedia_term', $cat_ids[0]);
|
922 |
+
$args['orderby'] = !empty($cat_meta['_orderby'][0])? $cat_meta['_orderby'][0] : $gmGallery->options['in_category_orderby'];
|
923 |
+
$args['order'] = !empty($cat_meta['_order'][0])? $cat_meta['_order'][0] : $gmGallery->options['in_category_order'];
|
924 |
+
}
|
925 |
+
$terms_ids_query = array_merge($terms_ids_query, $cat_ids);
|
926 |
}
|
927 |
+
if(!empty($data['album__in'])){
|
928 |
+
$alb_ids = wp_parse_id_list($data['album__in']);
|
929 |
+
if(1 === count($alb_ids)){
|
930 |
+
$album_meta = $gmDB->get_metadata('gmedia_term', $alb_ids[0]);
|
931 |
+
$args['orderby'] = !empty($album_meta['_orderby'][0])? $album_meta['_orderby'][0] : $gmGallery->options['in_album_orderby'];
|
932 |
+
$args['order'] = !empty($album_meta['_order'][0])? $album_meta['_order'][0] : $gmGallery->options['in_album_order'];
|
933 |
+
}
|
934 |
+
$terms_ids_query = array_merge($terms_ids_query, $alb_ids);
|
935 |
}
|
936 |
+
|
937 |
+
$data = wp_parse_args($data, $args);
|
938 |
+
$false_out = array_merge($filter, array('properties' => array('request' => isset($data['request'])? $data['request'] : null
|
939 |
+
),
|
940 |
+
'data' => array()
|
941 |
+
));
|
942 |
+
|
943 |
$terms_ids = array();
|
944 |
if(!empty($terms_ids_query)){
|
945 |
$terms_ids = $gmDB->get_terms(array('gmedia_album', 'gmedia_category', 'gmedia_tag'), array('include' => $terms_ids_query));
|
946 |
if(!empty($terms_ids) && !is_wp_error($terms_ids)){
|
947 |
foreach($terms_ids as $i => $term){
|
948 |
+
gmedia_ios_app_term_data_extend($terms_ids[ $i ], $share_link_base);
|
949 |
}
|
950 |
$terms_ids = array_filter($terms_ids);
|
951 |
if(empty($terms_ids)){
|
952 |
$out = $false_out;
|
953 |
break;
|
954 |
}
|
955 |
+
} else{
|
956 |
$terms_ids = array();
|
957 |
}
|
958 |
}
|
959 |
$req_terms = array();
|
960 |
if(!empty($terms_ids)){
|
961 |
foreach($terms_ids as $term){
|
962 |
+
$taxterm = str_replace('gmedia_', '', $term->taxonomy);
|
963 |
$req_terms["{$taxterm}__in"]["{$term->term_id}"] = $term;
|
964 |
}
|
965 |
}
|
966 |
|
967 |
$is_admin = isset($data['admin'])? intval($data['admin']) : 0;
|
968 |
+
if(!is_user_logged_in()){
|
969 |
$logged_in = false;
|
970 |
$data['status'] = array('publish');
|
971 |
+
if(!empty($req_terms['album__in'])){
|
972 |
$break = false;
|
973 |
+
foreach($req_terms['album__in'] as $alb){
|
974 |
+
if(!(isset($alb->status) && ('publish' == $alb->status))){
|
975 |
$break = true;
|
976 |
}
|
977 |
}
|
980 |
break;
|
981 |
}
|
982 |
}
|
983 |
+
} else{
|
984 |
$logged_in = true;
|
985 |
+
if($is_admin && !current_user_can('gmedia_library')){
|
986 |
$out = $false_out;
|
987 |
break;
|
988 |
}
|
989 |
+
if($is_admin && !current_user_can('gmedia_show_others_media')){
|
990 |
$data['author'] = $user_ID;
|
991 |
}
|
992 |
}
|
993 |
|
994 |
$_data = $data;
|
995 |
+
$_data['per_page'] = - 1;
|
996 |
$_data['status'] = null;
|
997 |
$_data['fields'] = 'ids';
|
998 |
$all_gmedias_ids = $gmDB->get_gmedias($_data);
|
999 |
$gmedias = $gmDB->get_gmedias($data);
|
1000 |
+
$properties = array_merge($req_terms, array('request' => isset($data['request'])? $data['request'] : null,
|
1001 |
+
'total_pages' => $gmDB->pages,
|
1002 |
+
'current_page' => $gmDB->openPage,
|
1003 |
+
'items_count' => $gmDB->resultPerPage,
|
1004 |
+
'total_count' => $gmDB->totalResult,
|
1005 |
+
'count' => count($all_gmedias_ids)
|
1006 |
+
));
|
1007 |
+
foreach($gmedias as $i => $item){
|
1008 |
|
1009 |
//if((!$logged_in && 'publish' != $item->status) || (!$is_admin && ('draft' == $item->status) && ((int)$user_ID != (int)$item->author))) {
|
1010 |
+
if((!$is_admin || ($is_admin && !current_user_can('gmedia_edit_others_media'))) && (('draft' == $item->status) && ((int)$user_ID != (int)$item->author))){
|
1011 |
+
unset($gmedias[ $i ]);
|
1012 |
+
$properties['total_count'] --;
|
1013 |
+
$properties['items_count'] --;
|
1014 |
continue;
|
1015 |
}
|
1016 |
|
1017 |
$author_id = $item->author;
|
1018 |
$authordata = get_userdata($author_id);
|
1019 |
+
if($authordata){
|
1020 |
$display_name = $authordata->display_name;
|
1021 |
$first_name = $authordata->first_name;
|
1022 |
$last_name = $authordata->last_name;
|
1023 |
+
} else{
|
1024 |
$display_name = __('Deleted User', 'grand-media');
|
1025 |
$first_name = '';
|
1026 |
$last_name = '';
|
1027 |
}
|
1028 |
+
$gmedias[ $i ]->user = array('id' => $author_id,
|
1029 |
+
'displayname' => $display_name,
|
1030 |
+
'firstname' => $first_name,
|
1031 |
+
'last_name' => $last_name
|
|
|
1032 |
);
|
1033 |
+
$gmedias[ $i ]->date = strtotime($item->date);
|
1034 |
|
1035 |
$meta = $gmDB->get_metadata('gmedia', $item->ID);
|
1036 |
//$_metadata = maybe_unserialize( $meta['_metadata'][0] );
|
1037 |
+
$_metadata = $meta['_metadata'][0];
|
1038 |
+
unset($meta['_metadata']);
|
1039 |
+
|
1040 |
+
$type = explode('/', $item->mime_type);
|
1041 |
+
$item_url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][ $type[0] ] . '/' . $item->gmuid;
|
1042 |
+
$gmedias[ $i ]->url = $item_url;
|
1043 |
+
$terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_tag');
|
1044 |
+
$tags = array();
|
1045 |
+
if($terms){
|
1046 |
$terms = array_values((array)$terms);
|
1047 |
+
foreach($terms as $term){
|
1048 |
$tags[] = array('term_id' => $term->term_id, 'name' => $term->name);
|
1049 |
}
|
1050 |
}
|
1051 |
+
$gmedias[ $i ]->tags = $tags;
|
1052 |
|
1053 |
$terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_album');
|
1054 |
$albums = array();
|
1055 |
+
if($terms){
|
1056 |
$terms = array_values((array)$terms);
|
1057 |
+
foreach($terms as $term){
|
1058 |
+
$albums[] = array('term_id' => $term->term_id,
|
1059 |
+
'name' => $term->name,
|
1060 |
+
'status' => (1 === $logic && 'publish' == $term->status)? 'public' : $term->status
|
|
|
1061 |
);
|
1062 |
}
|
1063 |
}
|
1064 |
+
$gmedias[ $i ]->albums = $albums;
|
1065 |
|
1066 |
+
if('image' == $type[0]){
|
1067 |
$terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_category');
|
1068 |
$categories = array();
|
1069 |
+
if($terms){
|
1070 |
$terms = array_values((array)$terms);
|
1071 |
+
foreach($terms as $term){
|
1072 |
$categories[] = array('term_id' => $term->term_id, 'name' => $term->term_id, 'title' => $term->name);
|
1073 |
}
|
1074 |
}
|
1075 |
+
$gmedias[ $i ]->categories = $categories;
|
1076 |
|
1077 |
+
$gmedias[ $i ]->meta = array('thumb' => $_metadata['thumb'],
|
1078 |
+
'web' => $_metadata['web'],
|
1079 |
+
'original' => $_metadata['original']
|
|
|
1080 |
);
|
1081 |
+
$gmedias[ $i ]->meta['thumb']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_thumb']}/{$item->gmuid}";
|
1082 |
+
$gmedias[ $i ]->meta['web']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image']}/{$item->gmuid}";
|
1083 |
+
$gmedias[ $i ]->meta['original']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_original']}/{$item->gmuid}";
|
1084 |
+
|
1085 |
+
if(isset($_metadata['image_meta'])){
|
1086 |
+
$gmedias[ $i ]->meta['data'] = $_metadata['image_meta'];
|
1087 |
+
}
|
1088 |
+
unset($meta['image_meta']);
|
1089 |
+
|
1090 |
+
} else{
|
1091 |
+
$cover_gmedia = false;
|
1092 |
+
if(!empty($meta['_cover'][0])){
|
1093 |
+
$cover_gmedia = $gmDB->get_gmedia($meta['_cover'][0]);
|
1094 |
+
if($cover_gmedia){
|
1095 |
+
$cover_metadata = $gmDB->get_metadata('gmedia', $cover_gmedia->ID, '_metadata', true);
|
1096 |
+
$gmedias[ $i ]->meta = array('thumb' => $cover_metadata['thumb'],
|
1097 |
+
'web' => $cover_metadata['web'],
|
1098 |
+
'original' => $cover_metadata['original']
|
1099 |
+
);
|
1100 |
+
$gmedias[ $i ]->meta['thumb']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_thumb']}/{$cover_gmedia->gmuid}";
|
1101 |
+
$gmedias[ $i ]->meta['web']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image']}/{$cover_gmedia->gmuid}";
|
1102 |
+
$gmedias[ $i ]->meta['original']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_original']}/{$cover_gmedia->gmuid}";
|
1103 |
+
}
|
1104 |
+
}
|
1105 |
+
unset($meta['_cover']);
|
1106 |
+
|
1107 |
+
if(!$cover_gmedia){
|
1108 |
+
$gmedias[ $i ]->meta = array('thumb' => array('link' => $gmCore->gm_get_media_image($item, 'thumb', false),
|
1109 |
+
'width' => 300,
|
1110 |
+
'height' => 300
|
1111 |
)
|
1112 |
+
);
|
1113 |
+
}
|
1114 |
+
if(!empty($_metadata)){
|
1115 |
+
$gmedias[ $i ]->meta['data'] = $_metadata;
|
1116 |
}
|
1117 |
}
|
1118 |
+
|
1119 |
+
$gmedias[ $i ]->meta['views'] = 0;
|
1120 |
+
$gmedias[ $i ]->meta['likes'] = 0;
|
1121 |
+
if(isset($meta['views'][0])){
|
1122 |
+
$gmedias[ $i ]->meta['views'] = $meta['views'][0];
|
1123 |
}
|
1124 |
+
unset($meta['views']);
|
1125 |
+
|
1126 |
+
if(isset($meta['likes'][0])){
|
1127 |
+
$gmedias[ $i ]->meta['likes'] = $meta['likes'][0];
|
1128 |
+
}
|
1129 |
+
unset($meta['likes']);
|
1130 |
+
|
1131 |
+
if(!empty($meta['_gps'][0])){
|
1132 |
+
$gmedias[ $i ]->meta['data']['GPS'] = $meta['_gps'][0];
|
1133 |
}
|
1134 |
+
unset($meta['_gps']);
|
1135 |
|
1136 |
+
if(isset($meta['_rating'][0])){
|
1137 |
+
$gmedias[ $i ]->meta['rating'] = maybe_unserialize($meta['_rating'][0]);
|
1138 |
+
}
|
1139 |
+
unset($meta['_rating']);
|
1140 |
+
|
1141 |
+
if(!empty($data['meta']) && !empty($meta)){
|
1142 |
+
foreach($meta as $key => $val){
|
1143 |
+
if('_peaks' == $key){
|
1144 |
+
$gmedias[ $i ]->meta[ $key ] = json_decode($val[0]);
|
1145 |
+
} else{
|
1146 |
+
$gmedias[ $i ]->meta[ $key ] = maybe_unserialize($val);
|
1147 |
+
}
|
1148 |
+
}
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
$item_name = $item->title? $item->title : pathinfo($item->gmuid, PATHINFO_FILENAME);
|
1152 |
+
$gmedia_hashid = gmedia_hash_id_encode($item->ID, 'single');
|
1153 |
+
$gmedias[ $i ]->sharelink = str_replace(array('$1', '$2'), array(urlencode($gmedia_hashid), 's'), $share_link_base);
|
1154 |
+
if(1 === $logic && 'publish' == $item->status){
|
1155 |
+
$gmedias[ $i ]->status = 'public';
|
1156 |
}
|
1157 |
}
|
1158 |
+
$out = array_merge($filter, array('properties' => $properties,
|
1159 |
+
'data' => array_values($gmedias)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1160 |
));
|
1161 |
break;
|
1162 |
case 'delete_term':
|
1163 |
$taxonomy = $data['taxonomy'];
|
1164 |
+
if(!empty($data['items'])){
|
1165 |
+
if(!current_user_can('gmedia_terms_delete')){
|
1166 |
$error[] = __('You have no permission to do this operation', 'grand-media');
|
1167 |
break;
|
1168 |
}
|
1169 |
$count = count($data['items']);
|
1170 |
+
foreach($data['items'] as $item){
|
1171 |
+
if(!current_user_can('gmedia_edit_others_media')){
|
1172 |
+
if('gmedia_album' == $taxonomy){
|
1173 |
$term = $gmDB->get_term($item, $taxonomy);
|
1174 |
+
if((int)$term->global != (int)$user_ID){
|
1175 |
$error['delete_album'] = __('You are not allowed to edit others media', 'grand-media');
|
1176 |
+
$count --;
|
1177 |
continue;
|
1178 |
}
|
1179 |
+
} else{
|
1180 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1181 |
+
$count --;
|
1182 |
continue;
|
1183 |
}
|
1184 |
}
|
1185 |
$delete = $gmDB->delete_term($item);
|
1186 |
+
if(is_wp_error($delete)){
|
1187 |
$error[] = $delete->get_error_message();
|
1188 |
+
$count --;
|
1189 |
}
|
1190 |
}
|
1191 |
+
if($count){
|
1192 |
$alert[] = sprintf(__('%d items deleted successfuly', 'grand-media'), $count);
|
1193 |
}
|
1194 |
}
|
1198 |
$taxonomy = $data['taxonomy'];
|
1199 |
$edit_term = isset($data['term_id'])? (int)$data['term_id'] : 0;
|
1200 |
$term = $data;
|
1201 |
+
$term_id = 0;
|
1202 |
+
if('gmedia_album' == $taxonomy){
|
1203 |
+
if(!current_user_can('gmedia_album_manage')){
|
1204 |
+
$out['error'] = array('code' => 'nocapability',
|
1205 |
+
'title' => __("You can't do this", 'grand-media'),
|
1206 |
+
'message' => __('You have no permission to do this operation', 'grand-media')
|
1207 |
);
|
1208 |
|
1209 |
return $out;
|
1210 |
}
|
1211 |
+
$args = array();
|
1212 |
+
do{
|
1213 |
$term['name'] = trim($term['name']);
|
1214 |
+
if(empty($term['name'])){
|
1215 |
$error[] = __('Term Name is not specified', 'grand-media');
|
1216 |
break;
|
1217 |
}
|
1218 |
+
if($gmCore->is_digit($term['name'])){
|
1219 |
$error[] = __("Term Name can't be only digits", 'grand-media');
|
1220 |
break;
|
1221 |
}
|
1222 |
+
if(1 === $logic && isset($term['status']) && 'public' == $term['status']){
|
1223 |
$term['status'] = 'publish';
|
1224 |
}
|
1225 |
+
if($edit_term && !$gmDB->term_exists($edit_term, $taxonomy)){
|
1226 |
$error[] = __('A term with the id provided do not exists', 'grand-media');
|
1227 |
$edit_term = false;
|
1228 |
}
|
1229 |
+
$term_author = isset($term['global'])? $term['global'] : false;
|
1230 |
+
if(($term_id = $gmDB->term_exists($term['name'], $taxonomy, $term_author))){
|
1231 |
+
if($term_id != $edit_term){
|
1232 |
+
$error[] = __('A term with the name provided already exists', 'grand-media');
|
1233 |
+
$error_info['terms'][ $term_id ] = $term['name'];
|
1234 |
break;
|
1235 |
}
|
1236 |
}
|
1237 |
+
if($edit_term){
|
1238 |
$_term = $gmDB->get_term($edit_term, $taxonomy);
|
1239 |
+
if(((int)$_term->global != (int)$user_ID) && !current_user_can('gmedia_edit_others_media')){
|
1240 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1241 |
break;
|
1242 |
}
|
1243 |
$term_id = $gmDB->update_term($edit_term, $term);
|
1244 |
+
} else{
|
1245 |
+
if(!current_user_can('gmedia_edit_others_media')){
|
1246 |
$term['global'] = intval($user_ID);
|
1247 |
}
|
1248 |
$term_id = $gmDB->insert_term($term['name'], $taxonomy, $term);
|
1249 |
}
|
1250 |
+
if(is_wp_error($term_id)){
|
1251 |
$error[] = $term_id->get_error_message();
|
1252 |
+
$term_id = 0;
|
1253 |
break;
|
1254 |
}
|
1255 |
+
$alert_info['terms'][ $term_id ] = $term['name'];
|
1256 |
+
$term_meta = array();
|
1257 |
+
if(isset($term['_orderby'])){
|
1258 |
$term_meta['_orderby'] = $term['_orderby'];
|
1259 |
+
} elseif(isset($term['orderby'])){
|
1260 |
$term_meta['_orderby'] = $term['orderby'];
|
1261 |
}
|
1262 |
+
if(isset($term['_order'])){
|
1263 |
$term_meta['_order'] = $term['_order'];
|
1264 |
+
} elseif(isset($term['order'])){
|
1265 |
$term_meta['_order'] = $term['order'];
|
1266 |
}
|
1267 |
+
if(isset($term['cover_id'])){
|
1268 |
+
$term_meta['_cover'] = (int)$term['cover_id']? $term['cover_id'] : '';
|
1269 |
+
}
|
1270 |
+
foreach($term_meta as $key => $value){
|
1271 |
+
$gmDB->update_metadata('gmedia_term', $term_id, $key, $value);
|
|
|
1272 |
}
|
1273 |
|
1274 |
$alert[] = sprintf(__('Album `%s` successfuly saved', 'grand-media'), $term['name']);
|
1275 |
|
1276 |
} while(0);
|
1277 |
+
if(1 < $logic && $edit_term && $term_id){
|
1278 |
+
$lib_data = array('album__in' => array($term_id), 'admin' => 1);
|
1279 |
+
if(!empty($data['per_page'])){
|
1280 |
+
$lib_data['per_page'] = $data['per_page'];
|
1281 |
+
}
|
1282 |
+
$out = gmedia_ios_app_processor('library', $lib_data);
|
1283 |
+
} else{
|
1284 |
+
$out = gmedia_ios_app_library_data(array('filter', $taxonomy), $args);
|
1285 |
+
}
|
1286 |
+
} elseif('gmedia_category' == $taxonomy){
|
1287 |
+
if(!current_user_can('gmedia_category_manage')){
|
1288 |
+
$out['error'] = array('code' => 'nocapability',
|
1289 |
+
'title' => __("You can't do this", 'grand-media'),
|
1290 |
+
'message' => __('You have no permission to do this operation', 'grand-media')
|
1291 |
);
|
1292 |
|
1293 |
return $out;
|
1294 |
}
|
1295 |
+
$args = array();
|
1296 |
+
if($edit_term){
|
1297 |
+
if(!current_user_can('gmedia_edit_others_media')){
|
1298 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1299 |
break;
|
1300 |
}
|
1301 |
$term['name'] = trim($term['name']);
|
1302 |
$term['term_id'] = intval($term['term_id']);
|
1303 |
+
if($term['name'] && !$gmCore->is_digit($term['name'])){
|
1304 |
+
if(($term_id = $gmDB->term_exists($term['term_id'], $taxonomy))){
|
1305 |
+
$db_term = $gmDB->get_term($term_id);
|
1306 |
+
if(($db_term->name == $term['name']) || ($db_term->name != $term['name'] && !($gmDB->term_exists($term['name'], $taxonomy)))){
|
1307 |
$term_id = $gmDB->update_term($term['term_id'], $term);
|
1308 |
+
if(is_wp_error($term_id)){
|
1309 |
$error[] = $term_id->get_error_message();
|
1310 |
+
$term_id = 0;
|
1311 |
+
} else{
|
1312 |
+
$alert[] = sprintf(__("Category %d successfuly updated", 'grand-media'), $term_id);
|
1313 |
+
$alert_info['terms'][ $term_id ] = $term['name'];
|
1314 |
+
if(1 < $logic){
|
1315 |
+
$args['include'][] = $term_id;
|
1316 |
+
}
|
1317 |
+
|
1318 |
+
$term_meta = array();
|
1319 |
+
if(isset($term['_orderby'])){
|
1320 |
+
$term_meta['_orderby'] = $term['_orderby'];
|
1321 |
+
} elseif(isset($term['orderby'])){
|
1322 |
+
$term_meta['_orderby'] = $term['orderby'];
|
1323 |
+
}
|
1324 |
+
if(isset($term['_order'])){
|
1325 |
+
$term_meta['_order'] = $term['_order'];
|
1326 |
+
} elseif(isset($term['order'])){
|
1327 |
+
$term_meta['_order'] = $term['order'];
|
1328 |
+
}
|
1329 |
+
foreach($term_meta as $key => $value){
|
1330 |
+
$gmDB->update_metadata('gmedia_term', $term_id, $key, $value);
|
1331 |
+
}
|
1332 |
}
|
1333 |
+
} else{
|
1334 |
+
$error[] = __('A term with the name provided already exists', 'grand-media');
|
1335 |
+
$error_info['terms'][ $term_id ] = $term['name'];
|
1336 |
}
|
1337 |
+
} else{
|
1338 |
$error[] = __("A term with the id provided do not exists", 'grand-media');
|
1339 |
}
|
1340 |
+
} else{
|
1341 |
$error[] = __("Term name can't be only digits or empty", 'grand-media');
|
1342 |
}
|
1343 |
+
} else{
|
1344 |
$terms = array_filter(array_map('trim', explode(',', $term['name'])));
|
1345 |
$terms_added = 0;
|
1346 |
$terms_qty = count($terms);
|
1347 |
+
foreach($terms as $term_name){
|
1348 |
+
if($gmCore->is_digit($term_name)){
|
1349 |
continue;
|
1350 |
}
|
1351 |
|
1352 |
+
if(!($term_id = $gmDB->term_exists($term_name, $taxonomy))){
|
1353 |
$term_id = $gmDB->insert_term($term_name, $taxonomy);
|
1354 |
+
if(is_wp_error($term_id)){
|
1355 |
$error[] = $term_id->get_error_message();
|
1356 |
+
$term_id = 0;
|
1357 |
+
} else{
|
1358 |
+
$alert['category_add'] = sprintf(__('%d of %d categories successfuly added', 'grand-media'), ++ $terms_added, $terms_qty);
|
1359 |
+
$alert_info['terms'][ $term_id ] = $term_name;
|
1360 |
}
|
1361 |
+
} else{
|
1362 |
+
$alert['category_add'] = __('Some of provided categories are already exists', 'grand-media');
|
1363 |
+
$alert_info['terms'][ $term_id ] = $term_name;
|
1364 |
}
|
1365 |
}
|
1366 |
}
|
1367 |
+
if(1 < $logic && $edit_term && $term_id){
|
1368 |
+
$lib_data = array('category__in' => array($term_id), 'admin' => 1);
|
1369 |
+
if(!empty($data['per_page'])){
|
1370 |
+
$lib_data['per_page'] = $data['per_page'];
|
1371 |
+
}
|
1372 |
+
$out = gmedia_ios_app_processor('library', $lib_data);
|
1373 |
+
} else{
|
1374 |
+
$out = gmedia_ios_app_library_data(array('filter', $taxonomy), $args);
|
1375 |
+
}
|
1376 |
+
} elseif('gmedia_tag' == $taxonomy){
|
1377 |
+
if(!current_user_can('gmedia_tag_manage')){
|
1378 |
+
$out['error'] = array('code' => 'nocapability',
|
1379 |
+
'title' => __("You can't do this", 'grand-media'),
|
1380 |
+
'message' => __('You have no permission to do this operation', 'grand-media')
|
1381 |
);
|
1382 |
|
1383 |
return $out;
|
1384 |
}
|
1385 |
+
$args = array();
|
1386 |
+
if($edit_term){
|
1387 |
+
if(!current_user_can('gmedia_edit_others_media')){
|
1388 |
$error[] = __('You are not allowed to edit others media', 'grand-media');
|
1389 |
break;
|
1390 |
}
|
1391 |
$term['name'] = trim($term['name']);
|
1392 |
$term['term_id'] = intval($term['term_id']);
|
1393 |
+
if($term['name'] && !$gmCore->is_digit($term['name'])){
|
1394 |
+
if(($term_id = $gmDB->term_exists($term['term_id'], $taxonomy))){
|
1395 |
+
if(!($gmDB->term_exists($term['name'], $taxonomy))){
|
1396 |
$term_id = $gmDB->update_term($term['term_id'], $term);
|
1397 |
+
if(is_wp_error($term_id)){
|
1398 |
$error[] = $term_id->get_error_message();
|
1399 |
+
$term_id = 0;
|
1400 |
+
} else{
|
1401 |
+
$alert[] = sprintf(__("Tag %d successfuly updated", 'grand-media'), $term_id);
|
1402 |
+
$alert_info['terms'][ $term_id ] = $term['name'];
|
1403 |
}
|
1404 |
+
} else{
|
1405 |
+
$error[] = __('A term with the name provided already exists', 'grand-media');
|
1406 |
+
$error_info['terms'][ $term_id ] = $term['name'];
|
1407 |
}
|
1408 |
+
} else{
|
1409 |
$error[] = __("A term with the id provided do not exists", 'grand-media');
|
1410 |
}
|
1411 |
+
} else{
|
1412 |
$error[] = __("Term name can't be only digits or empty", 'grand-media');
|
1413 |
}
|
1414 |
+
} else{
|
1415 |
$terms = array_filter(array_map('trim', explode(',', $term['name'])));
|
1416 |
$terms_added = 0;
|
1417 |
$terms_qty = count($terms);
|
1418 |
+
foreach($terms as $term_name){
|
1419 |
+
if($gmCore->is_digit($term_name)){
|
1420 |
continue;
|
1421 |
}
|
1422 |
|
1423 |
+
if(!($term_id = $gmDB->term_exists($term_name, $taxonomy))){
|
1424 |
$term_id = $gmDB->insert_term($term_name, $taxonomy);
|
1425 |
+
if(is_wp_error($term_id)){
|
1426 |
$error[] = $term_id->get_error_message();
|
1427 |
+
$term_id = 0;
|
1428 |
+
} else{
|
1429 |
+
$alert['tag_add'] = sprintf(__('%d of %d tags successfuly added', 'grand-media'), ++ $terms_added, $terms_qty);
|
1430 |
+
$alert_info['terms'][ $term_id ] = $term_name;
|
1431 |
}
|
1432 |
+
} else{
|
1433 |
+
$alert['tag_add'] = __('Some of provided tags are already exists', 'grand-media');
|
1434 |
+
$alert_info['terms'][ $term_id ] = $term_name;
|
1435 |
}
|
1436 |
}
|
1437 |
}
|
1438 |
+
if(1 < $logic && $edit_term && $term_id){
|
1439 |
+
$lib_data = array('tag__in' => array($term_id), 'admin' => 1);
|
1440 |
+
if(!empty($data['per_page'])){
|
1441 |
+
$lib_data['per_page'] = $data['per_page'];
|
1442 |
+
}
|
1443 |
+
$out = gmedia_ios_app_processor('library', $lib_data);
|
1444 |
+
} else{
|
1445 |
+
$out = gmedia_ios_app_library_data(array('filter', $taxonomy), $args);
|
1446 |
+
}
|
1447 |
}
|
|
|
1448 |
break;
|
1449 |
default:
|
1450 |
break;
|
1451 |
}
|
1452 |
|
1453 |
+
if(!empty($error)){
|
1454 |
$out['error'] = array('code' => $action, 'title' => 'ERROR', 'message' => implode("\n", $error));
|
1455 |
+
if(!empty($error_info)){
|
1456 |
+
$out['error'] = array_merge($out['error'], $error_info);
|
1457 |
+
}
|
1458 |
}
|
1459 |
+
if(!empty($alert)){
|
1460 |
$out['alert'] = array('title' => 'Success', 'message' => implode("\n", $alert));
|
1461 |
+
if(!empty($alert_info)){
|
1462 |
+
$out['alert'] = array_merge($out['alert'], $alert_info);
|
1463 |
+
}
|
1464 |
}
|
1465 |
|
1466 |
return $out;
|
1470 |
/**
|
1471 |
* @param $data
|
1472 |
*/
|
1473 |
+
function gmedia_ios_app_counters($data){
|
1474 |
global $gmDB;
|
1475 |
|
1476 |
$data = (array)$data;
|
1477 |
$items_counter = array();
|
1478 |
+
if(!empty($data['views'])){
|
1479 |
+
foreach($data['views'] as $gmID){
|
1480 |
+
$items_counter[ $gmID ]['views'] = 1;
|
1481 |
}
|
1482 |
+
if(!empty($data['likes'])){
|
1483 |
+
foreach($data['likes'] as $gmID){
|
1484 |
+
$items_counter[ $gmID ]['likes'] = 1;
|
1485 |
}
|
1486 |
}
|
1487 |
}
|
1488 |
|
1489 |
+
if(!empty($items_counter)){
|
1490 |
+
foreach($items_counter as $gmID => $counters){
|
1491 |
+
if(null === $gmDB->get_gmedia($gmID)){
|
1492 |
continue;
|
1493 |
}
|
1494 |
$counters['views'] = $gmDB->get_metadata('gmedia', $gmID, 'views', true);
|
1495 |
$counters['views'] += 1;
|
1496 |
$gmDB->update_metadata('gmedia', $gmID, 'views', $counters['views']);
|
1497 |
+
if(isset($counters['likes'])){
|
1498 |
$counters['likes'] = $gmDB->get_metadata('gmedia', $gmID, 'likes', true);
|
1499 |
$counters['likes'] += 1;
|
1500 |
$gmDB->update_metadata('gmedia', $gmID, 'likes', $counters['likes']);
|
assets/wavesurfer/wavesurfer.js
ADDED
@@ -0,0 +1,2089 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function (root, factory) {
|
2 |
+
if (typeof define === 'function' && define.amd) {
|
3 |
+
// AMD. Register as an anonymous module unless amdModuleId is set
|
4 |
+
define('wavesurfer', [], function () {
|
5 |
+
return (root['WaveSurfer'] = factory());
|
6 |
+
});
|
7 |
+
} else if (typeof exports === 'object') {
|
8 |
+
// Node. Does not work with strict CommonJS, but
|
9 |
+
// only CommonJS-like environments that support module.exports,
|
10 |
+
// like Node.
|
11 |
+
module.exports = factory();
|
12 |
+
} else {
|
13 |
+
root['WaveSurfer'] = factory();
|
14 |
+
}
|
15 |
+
}(this, function () {
|
16 |
+
|
17 |
+
'use strict';
|
18 |
+
|
19 |
+
var WaveSurfer = {
|
20 |
+
defaultParams: {
|
21 |
+
height : 128,
|
22 |
+
waveColor : '#999',
|
23 |
+
progressColor : '#555',
|
24 |
+
cursorColor : '#333',
|
25 |
+
cursorWidth : 1,
|
26 |
+
skipLength : 2,
|
27 |
+
minPxPerSec : 20,
|
28 |
+
pixelRatio : window.devicePixelRatio || screen.deviceXDPI / screen.logicalXDPI,
|
29 |
+
fillParent : true,
|
30 |
+
scrollParent : false,
|
31 |
+
hideScrollbar : false,
|
32 |
+
normalize : false,
|
33 |
+
audioContext : null,
|
34 |
+
container : null,
|
35 |
+
dragSelection : true,
|
36 |
+
loopSelection : true,
|
37 |
+
audioRate : 1,
|
38 |
+
interact : true,
|
39 |
+
splitChannels : false,
|
40 |
+
mediaContainer: null,
|
41 |
+
mediaControls : false,
|
42 |
+
renderer : 'Canvas',
|
43 |
+
backend : 'WebAudio',
|
44 |
+
mediaType : 'audio',
|
45 |
+
autoCenter : true
|
46 |
+
},
|
47 |
+
|
48 |
+
init: function (params) {
|
49 |
+
// Extract relevant parameters (or defaults)
|
50 |
+
this.params = WaveSurfer.util.extend({}, this.defaultParams, params);
|
51 |
+
|
52 |
+
this.container = 'string' == typeof params.container ?
|
53 |
+
document.querySelector(this.params.container) :
|
54 |
+
this.params.container;
|
55 |
+
|
56 |
+
if (!this.container) {
|
57 |
+
throw new Error('Container element not found');
|
58 |
+
}
|
59 |
+
|
60 |
+
if (this.params.mediaContainer == null) {
|
61 |
+
this.mediaContainer = this.container;
|
62 |
+
} else if (typeof this.params.mediaContainer == 'string') {
|
63 |
+
this.mediaContainer = document.querySelector(this.params.mediaContainer);
|
64 |
+
} else {
|
65 |
+
this.mediaContainer = this.params.mediaContainer;
|
66 |
+
}
|
67 |
+
|
68 |
+
if (!this.mediaContainer) {
|
69 |
+
throw new Error('Media Container element not found');
|
70 |
+
}
|
71 |
+
|
72 |
+
// Used to save the current volume when muting so we can
|
73 |
+
// restore once unmuted
|
74 |
+
this.savedVolume = 0;
|
75 |
+
|
76 |
+
// The current muted state
|
77 |
+
this.isMuted = false;
|
78 |
+
|
79 |
+
// Will hold a list of event descriptors that need to be
|
80 |
+
// cancelled on subsequent loads of audio
|
81 |
+
this.tmpEvents = [];
|
82 |
+
|
83 |
+
// Holds any running audio downloads
|
84 |
+
this.currentAjax = null;
|
85 |
+
|
86 |
+
this.createDrawer();
|
87 |
+
this.createBackend();
|
88 |
+
},
|
89 |
+
|
90 |
+
createDrawer: function () {
|
91 |
+
var my = this;
|
92 |
+
|
93 |
+
this.drawer = Object.create(WaveSurfer.Drawer[this.params.renderer]);
|
94 |
+
this.drawer.init(this.container, this.params);
|
95 |
+
|
96 |
+
this.drawer.on('redraw', function () {
|
97 |
+
my.drawBuffer();
|
98 |
+
my.drawer.progress(my.backend.getPlayedPercents());
|
99 |
+
});
|
100 |
+
|
101 |
+
// Click-to-seek
|
102 |
+
this.drawer.on('click', function (e, progress) {
|
103 |
+
setTimeout(function () {
|
104 |
+
my.seekTo(progress);
|
105 |
+
}, 0);
|
106 |
+
});
|
107 |
+
|
108 |
+
// Relay the scroll event from the drawer
|
109 |
+
this.drawer.on('scroll', function (e) {
|
110 |
+
my.fireEvent('scroll', e);
|
111 |
+
});
|
112 |
+
},
|
113 |
+
|
114 |
+
createBackend: function () {
|
115 |
+
var my = this;
|
116 |
+
|
117 |
+
if (this.backend) {
|
118 |
+
this.backend.destroy();
|
119 |
+
}
|
120 |
+
|
121 |
+
// Back compat
|
122 |
+
if (this.params.backend == 'AudioElement') {
|
123 |
+
this.params.backend = 'MediaElement';
|
124 |
+
}
|
125 |
+
|
126 |
+
if (this.params.backend == 'WebAudio' && !WaveSurfer.WebAudio.supportsWebAudio()) {
|
127 |
+
this.params.backend = 'MediaElement';
|
128 |
+
}
|
129 |
+
|
130 |
+
this.backend = Object.create(WaveSurfer[this.params.backend]);
|
131 |
+
this.backend.init(this.params);
|
132 |
+
|
133 |
+
this.backend.on('finish', function () { my.fireEvent('finish'); });
|
134 |
+
this.backend.on('play', function () { my.fireEvent('play'); });
|
135 |
+
this.backend.on('pause', function () { my.fireEvent('pause'); });
|
136 |
+
|
137 |
+
this.backend.on('audioprocess', function (time) {
|
138 |
+
my.drawer.progress(my.backend.getPlayedPercents());
|
139 |
+
my.fireEvent('audioprocess', time);
|
140 |
+
});
|
141 |
+
},
|
142 |
+
|
143 |
+
getDuration: function () {
|
144 |
+
return this.backend.getDuration();
|
145 |
+
},
|
146 |
+
|
147 |
+
getCurrentTime: function () {
|
148 |
+
return this.backend.getCurrentTime();
|
149 |
+
},
|
150 |
+
|
151 |
+
play: function (start, end) {
|
152 |
+
this.fireEvent('interaction', this.play.bind(this, start, end));
|
153 |
+
this.backend.play(start, end);
|
154 |
+
},
|
155 |
+
|
156 |
+
pause: function () {
|
157 |
+
this.backend.pause();
|
158 |
+
},
|
159 |
+
|
160 |
+
playPause: function () {
|
161 |
+
this.backend.isPaused() ? this.play() : this.pause();
|
162 |
+
},
|
163 |
+
|
164 |
+
isPlaying: function () {
|
165 |
+
return !this.backend.isPaused();
|
166 |
+
},
|
167 |
+
|
168 |
+
skipBackward: function (seconds) {
|
169 |
+
this.skip(-seconds || -this.params.skipLength);
|
170 |
+
},
|
171 |
+
|
172 |
+
skipForward: function (seconds) {
|
173 |
+
this.skip(seconds || this.params.skipLength);
|
174 |
+
},
|
175 |
+
|
176 |
+
skip: function (offset) {
|
177 |
+
var position = this.getCurrentTime() || 0;
|
178 |
+
var duration = this.getDuration() || 1;
|
179 |
+
position = Math.max(0, Math.min(duration, position + (offset || 0)));
|
180 |
+
this.seekAndCenter(position / duration);
|
181 |
+
},
|
182 |
+
|
183 |
+
seekAndCenter: function (progress) {
|
184 |
+
this.seekTo(progress);
|
185 |
+
this.drawer.recenter(progress);
|
186 |
+
},
|
187 |
+
|
188 |
+
seekTo: function (progress) {
|
189 |
+
this.fireEvent('interaction', this.seekTo.bind(this, progress));
|
190 |
+
|
191 |
+
var paused = this.backend.isPaused();
|
192 |
+
// avoid small scrolls while paused seeking
|
193 |
+
var oldScrollParent = this.params.scrollParent;
|
194 |
+
if (paused) {
|
195 |
+
this.params.scrollParent = false;
|
196 |
+
}
|
197 |
+
this.backend.seekTo(progress * this.getDuration());
|
198 |
+
this.drawer.progress(this.backend.getPlayedPercents());
|
199 |
+
|
200 |
+
if (!paused) {
|
201 |
+
this.backend.pause();
|
202 |
+
var be = this.backend;
|
203 |
+
setTimeout(function(){
|
204 |
+
be.play();
|
205 |
+
}, 200);
|
206 |
+
}
|
207 |
+
this.params.scrollParent = oldScrollParent;
|
208 |
+
this.fireEvent('seek', progress);
|
209 |
+
},
|
210 |
+
|
211 |
+
stop: function () {
|
212 |
+
this.pause();
|
213 |
+
this.seekTo(0);
|
214 |
+
this.drawer.progress(0);
|
215 |
+
},
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Set the playback volume.
|
219 |
+
*
|
220 |
+
* @param {Number} newVolume A value between 0 and 1, 0 being no
|
221 |
+
* volume and 1 being full volume.
|
222 |
+
*/
|
223 |
+
setVolume: function (newVolume) {
|
224 |
+
this.backend.setVolume(newVolume);
|
225 |
+
},
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Set the playback rate.
|
229 |
+
*
|
230 |
+
* @param {Number} rate A positive number. E.g. 0.5 means half the
|
231 |
+
* normal speed, 2 means double speed and so on.
|
232 |
+
*/
|
233 |
+
setPlaybackRate: function (rate) {
|
234 |
+
this.backend.setPlaybackRate(rate);
|
235 |
+
},
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Toggle the volume on and off. It not currenly muted it will
|
239 |
+
* save the current volume value and turn the volume off.
|
240 |
+
* If currently muted then it will restore the volume to the saved
|
241 |
+
* value, and then rest the saved value.
|
242 |
+
*/
|
243 |
+
toggleMute: function () {
|
244 |
+
if (this.isMuted) {
|
245 |
+
// If currently muted then restore to the saved volume
|
246 |
+
// and update the mute properties
|
247 |
+
this.backend.setVolume(this.savedVolume);
|
248 |
+
this.isMuted = false;
|
249 |
+
} else {
|
250 |
+
// If currently not muted then save current volume,
|
251 |
+
// turn off the volume and update the mute properties
|
252 |
+
this.savedVolume = this.backend.getVolume();
|
253 |
+
this.backend.setVolume(0);
|
254 |
+
this.isMuted = true;
|
255 |
+
}
|
256 |
+
},
|
257 |
+
|
258 |
+
toggleScroll: function () {
|
259 |
+
this.params.scrollParent = !this.params.scrollParent;
|
260 |
+
this.drawBuffer();
|
261 |
+
},
|
262 |
+
|
263 |
+
toggleInteraction: function () {
|
264 |
+
this.params.interact = !this.params.interact;
|
265 |
+
},
|
266 |
+
|
267 |
+
drawBuffer: function () {
|
268 |
+
var nominalWidth = Math.round(
|
269 |
+
this.getDuration() * this.params.minPxPerSec * this.params.pixelRatio
|
270 |
+
);
|
271 |
+
var parentWidth = this.drawer.getWidth();
|
272 |
+
var width = nominalWidth;
|
273 |
+
|
274 |
+
// Fill container
|
275 |
+
if (this.params.fillParent && (!this.params.scrollParent || nominalWidth < parentWidth)) {
|
276 |
+
width = parentWidth;
|
277 |
+
}
|
278 |
+
|
279 |
+
var peaks = this.backend.getPeaks(width);
|
280 |
+
this.drawer.drawPeaks(peaks, width);
|
281 |
+
this.fireEvent('redraw', peaks, width);
|
282 |
+
},
|
283 |
+
|
284 |
+
zoom: function (pxPerSec) {
|
285 |
+
this.params.minPxPerSec = pxPerSec;
|
286 |
+
|
287 |
+
this.params.scrollParent = true;
|
288 |
+
|
289 |
+
this.drawBuffer();
|
290 |
+
|
291 |
+
this.seekAndCenter(
|
292 |
+
this.getCurrentTime() / this.getDuration()
|
293 |
+
);
|
294 |
+
this.fireEvent('zoom', pxPerSec);
|
295 |
+
},
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Internal method.
|
299 |
+
*/
|
300 |
+
loadArrayBuffer: function (arraybuffer) {
|
301 |
+
this.decodeArrayBuffer(arraybuffer, function (data) {
|
302 |
+
this.loadDecodedBuffer(data);
|
303 |
+
}.bind(this));
|
304 |
+
},
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Directly load an externally decoded AudioBuffer.
|
308 |
+
*/
|
309 |
+
loadDecodedBuffer: function (buffer) {
|
310 |
+
this.backend.load(buffer);
|
311 |
+
this.drawBuffer();
|
312 |
+
this.fireEvent('ready');
|
313 |
+
},
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Loads audio data from a Blob or File object.
|
317 |
+
*
|
318 |
+
* @param {Blob|File} blob Audio data.
|
319 |
+
*/
|
320 |
+
loadBlob: function (blob) {
|
321 |
+
var my = this;
|
322 |
+
// Create file reader
|
323 |
+
var reader = new FileReader();
|
324 |
+
reader.addEventListener('progress', function (e) {
|
325 |
+
my.onProgress(e);
|
326 |
+
});
|
327 |
+
reader.addEventListener('load', function (e) {
|
328 |
+
my.loadArrayBuffer(e.target.result);
|
329 |
+
});
|
330 |
+
reader.addEventListener('error', function () {
|
331 |
+
my.fireEvent('error', 'Error reading file');
|
332 |
+
});
|
333 |
+
reader.readAsArrayBuffer(blob);
|
334 |
+
this.empty();
|
335 |
+
},
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Loads audio and re-renders the waveform.
|
339 |
+
*/
|
340 |
+
load: function (url, peaks) {
|
341 |
+
//this.empty();
|
342 |
+
|
343 |
+
switch (this.params.backend) {
|
344 |
+
case 'WebAudio': return this.loadBuffer(url, peaks);
|
345 |
+
case 'MediaElement': return this.loadMediaElement(url, peaks);
|
346 |
+
}
|
347 |
+
},
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Loads audio using Web Audio buffer backend.
|
351 |
+
*/
|
352 |
+
loadBuffer: function (url, peaks) {
|
353 |
+
var load = (function (action) {
|
354 |
+
if (action) {
|
355 |
+
this.tmpEvents.push(this.once('ready', action));
|
356 |
+
}
|
357 |
+
return this.getArrayBuffer(url, this.loadArrayBuffer.bind(this));
|
358 |
+
}).bind(this);
|
359 |
+
|
360 |
+
if (peaks) {
|
361 |
+
this.backend.setPeaks(peaks);
|
362 |
+
this.drawBuffer();
|
363 |
+
this.tmpEvents.push(this.once('interaction', load));
|
364 |
+
} else {
|
365 |
+
return load();
|
366 |
+
}
|
367 |
+
},
|
368 |
+
|
369 |
+
/**
|
370 |
+
* Either create a media element, or load
|
371 |
+
* an existing media element.
|
372 |
+
* @param {String|HTMLElement} urlOrElt Either a path to a media file,
|
373 |
+
* or an existing HTML5 Audio/Video
|
374 |
+
* Element
|
375 |
+
* @param {Array} [peaks] Array of peaks. Required to bypass
|
376 |
+
* web audio dependency
|
377 |
+
*/
|
378 |
+
loadMediaElement: function (urlOrElt, peaks) {
|
379 |
+
var url = urlOrElt;
|
380 |
+
|
381 |
+
if (typeof urlOrElt === 'string') {
|
382 |
+
this.backend.load(url, this.mediaContainer, peaks);
|
383 |
+
} else {
|
384 |
+
var elt = urlOrElt;
|
385 |
+
this.backend.loadElt(elt, peaks);
|
386 |
+
|
387 |
+
// If peaks are not provided,
|
388 |
+
// url = element.src so we can get peaks with web audio
|
389 |
+
url = elt.src;
|
390 |
+
}
|
391 |
+
|
392 |
+
this.tmpEvents.push(
|
393 |
+
this.backend.once('canplay', (function () {
|
394 |
+
this.drawBuffer();
|
395 |
+
this.fireEvent('ready');
|
396 |
+
}).bind(this)),
|
397 |
+
|
398 |
+
this.backend.once('error', (function (err) {
|
399 |
+
this.fireEvent('error', err);
|
400 |
+
}).bind(this))
|
401 |
+
);
|
402 |
+
|
403 |
+
// If no pre-decoded peaks provided, attempt to download the
|
404 |
+
// audio file and decode it with Web Audio.
|
405 |
+
if (peaks) {
|
406 |
+
this.backend.setPeaks(peaks);
|
407 |
+
} else if (this.backend.supportsWebAudio()) {
|
408 |
+
this.getArrayBuffer(url, (function (arraybuffer) {
|
409 |
+
this.decodeArrayBuffer(arraybuffer, (function (buffer) {
|
410 |
+
this.backend.buffer = buffer;
|
411 |
+
this.drawBuffer();
|
412 |
+
}).bind(this));
|
413 |
+
}).bind(this));
|
414 |
+
}
|
415 |
+
},
|
416 |
+
|
417 |
+
decodeArrayBuffer: function (arraybuffer, callback) {
|
418 |
+
this.arraybuffer = arraybuffer;
|
419 |
+
|
420 |
+
this.backend.decodeArrayBuffer(
|
421 |
+
arraybuffer,
|
422 |
+
(function (data) {
|
423 |
+
if (this.arraybuffer == arraybuffer) {
|
424 |
+
callback(data);
|
425 |
+
this.arraybuffer = null;
|
426 |
+
}
|
427 |
+
}).bind(this),
|
428 |
+
this.fireEvent.bind(this, 'error', 'Error decoding audiobuffer')
|
429 |
+
);
|
430 |
+
},
|
431 |
+
|
432 |
+
getArrayBuffer: function (url, callback) {
|
433 |
+
var my = this;
|
434 |
+
|
435 |
+
var ajax = WaveSurfer.util.ajax({
|
436 |
+
url: url,
|
437 |
+
responseType: 'arraybuffer'
|
438 |
+
});
|
439 |
+
|
440 |
+
this.currentAjax = ajax;
|
441 |
+
|
442 |
+
this.tmpEvents.push(
|
443 |
+
ajax.on('progress', function (e) {
|
444 |
+
my.onProgress(e);
|
445 |
+
}),
|
446 |
+
ajax.on('success', function (data, e) {
|
447 |
+
callback(data);
|
448 |
+
my.currentAjax = null;
|
449 |
+
}),
|
450 |
+
ajax.on('error', function (e) {
|
451 |
+
my.fireEvent('error', 'XHR error: ' + e.target.statusText);
|
452 |
+
my.currentAjax = null;
|
453 |
+
})
|
454 |
+
);
|
455 |
+
|
456 |
+
return ajax;
|
457 |
+
},
|
458 |
+
|
459 |
+
onProgress: function (e) {
|
460 |
+
if (e.lengthComputable) {
|
461 |
+
var percentComplete = e.loaded / e.total;
|
462 |
+
} else {
|
463 |
+
// Approximate progress with an asymptotic
|
464 |
+
// function, and assume downloads in the 1-3 MB range.
|
465 |
+
percentComplete = e.loaded / (e.loaded + 1000000);
|
466 |
+
}
|
467 |
+
this.fireEvent('loading', Math.round(percentComplete * 100), e.target);
|
468 |
+
},
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Exports PCM data into a JSON array and opens in a new window.
|
472 |
+
*/
|
473 |
+
exportPCM: function (length, accuracy, noWindow) {
|
474 |
+
length = length || 1024;
|
475 |
+
accuracy = accuracy || 10000;
|
476 |
+
noWindow = noWindow || false;
|
477 |
+
var peaks = this.backend.getPeaks(length, accuracy);
|
478 |
+
var arr = [].map.call(peaks, function (val) {
|
479 |
+
return Math.round(val * accuracy) / accuracy;
|
480 |
+
});
|
481 |
+
var json = JSON.stringify(arr);
|
482 |
+
if (!noWindow) {
|
483 |
+
window.open('data:application/json;charset=utf-8,' +
|
484 |
+
encodeURIComponent(json));
|
485 |
+
}
|
486 |
+
return json;
|
487 |
+
},
|
488 |
+
|
489 |
+
cancelAjax: function () {
|
490 |
+
if (this.currentAjax) {
|
491 |
+
this.currentAjax.xhr.abort();
|
492 |
+
this.currentAjax = null;
|
493 |
+
}
|
494 |
+
},
|
495 |
+
|
496 |
+
clearTmpEvents: function () {
|
497 |
+
this.tmpEvents.forEach(function (e) { e.un(); });
|
498 |
+
},
|
499 |
+
|
500 |
+
/**
|
501 |
+
* Display empty waveform.
|
502 |
+
*/
|
503 |
+
empty: function () {
|
504 |
+
if (!this.backend.isPaused()) {
|
505 |
+
this.stop();
|
506 |
+
this.backend.disconnectSource();
|
507 |
+
}
|
508 |
+
this.cancelAjax();
|
509 |
+
this.clearTmpEvents();
|
510 |
+
this.drawer.progress(0);
|
511 |
+
this.drawer.setWidth(0);
|
512 |
+
this.drawer.drawPeaks({ length: this.drawer.getWidth() }, 0);
|
513 |
+
},
|
514 |
+
|
515 |
+
/**
|
516 |
+
* Remove events, elements and disconnect WebAudio nodes.
|
517 |
+
*/
|
518 |
+
destroy: function () {
|
519 |
+
this.fireEvent('destroy');
|
520 |
+
this.cancelAjax();
|
521 |
+
this.clearTmpEvents();
|
522 |
+
this.unAll();
|
523 |
+
this.backend.destroy();
|
524 |
+
this.drawer.destroy();
|
525 |
+
}
|
526 |
+
};
|
527 |
+
|
528 |
+
WaveSurfer.create = function (params) {
|
529 |
+
var wavesurfer = Object.create(WaveSurfer);
|
530 |
+
wavesurfer.init(params);
|
531 |
+
return wavesurfer;
|
532 |
+
};
|
533 |
+
|
534 |
+
WaveSurfer.util = {
|
535 |
+
extend: function (dest) {
|
536 |
+
var sources = Array.prototype.slice.call(arguments, 1);
|
537 |
+
sources.forEach(function (source) {
|
538 |
+
Object.keys(source).forEach(function (key) {
|
539 |
+
dest[key] = source[key];
|
540 |
+
});
|
541 |
+
});
|
542 |
+
return dest;
|
543 |
+
},
|
544 |
+
|
545 |
+
min: function(values) {
|
546 |
+
var min = +Infinity;
|
547 |
+
for (var i in values) {
|
548 |
+
if (values[i] < min) {
|
549 |
+
min = values[i];
|
550 |
+
}
|
551 |
+
}
|
552 |
+
|
553 |
+
return min;
|
554 |
+
},
|
555 |
+
|
556 |
+
max: function(values) {
|
557 |
+
var max = -Infinity;
|
558 |
+
for (var i in values) {
|
559 |
+
if (values[i] > max) {
|
560 |
+
max = values[i];
|
561 |
+
}
|
562 |
+
}
|
563 |
+
|
564 |
+
return max;
|
565 |
+
},
|
566 |
+
|
567 |
+
getId: function () {
|
568 |
+
return 'wavesurfer_' + Math.random().toString(32).substring(2);
|
569 |
+
},
|
570 |
+
|
571 |
+
ajax: function (options) {
|
572 |
+
var ajax = Object.create(WaveSurfer.Observer);
|
573 |
+
var xhr = new XMLHttpRequest();
|
574 |
+
var fired100 = false;
|
575 |
+
|
576 |
+
xhr.open(options.method || 'GET', options.url, true);
|
577 |
+
xhr.responseType = options.responseType || 'json';
|
578 |
+
|
579 |
+
xhr.addEventListener('progress', function (e) {
|
580 |
+
ajax.fireEvent('progress', e);
|
581 |
+
if (e.lengthComputable && e.loaded == e.total) {
|
582 |
+
fired100 = true;
|
583 |
+
}
|
584 |
+
});
|
585 |
+
|
586 |
+
xhr.addEventListener('load', function (e) {
|
587 |
+
if (!fired100) {
|
588 |
+
ajax.fireEvent('progress', e);
|
589 |
+
}
|
590 |
+
ajax.fireEvent('load', e);
|
591 |
+
|
592 |
+
if (200 == xhr.status || 206 == xhr.status) {
|
593 |
+
ajax.fireEvent('success', xhr.response, e);
|
594 |
+
} else {
|
595 |
+
ajax.fireEvent('error', e);
|
596 |
+
}
|
597 |
+
});
|
598 |
+
|
599 |
+
xhr.addEventListener('error', function (e) {
|
600 |
+
ajax.fireEvent('error', e);
|
601 |
+
});
|
602 |
+
|
603 |
+
xhr.send();
|
604 |
+
ajax.xhr = xhr;
|
605 |
+
return ajax;
|
606 |
+
}
|
607 |
+
};
|
608 |
+
|
609 |
+
/* Observer */
|
610 |
+
WaveSurfer.Observer = {
|
611 |
+
/**
|
612 |
+
* Attach a handler function for an event.
|
613 |
+
*/
|
614 |
+
on: function (event, fn) {
|
615 |
+
if (!this.handlers) { this.handlers = {}; }
|
616 |
+
|
617 |
+
var handlers = this.handlers[event];
|
618 |
+
if (!handlers) {
|
619 |
+
handlers = this.handlers[event] = [];
|
620 |
+
}
|
621 |
+
handlers.push(fn);
|
622 |
+
|
623 |
+
// Return an event descriptor
|
624 |
+
return {
|
625 |
+
name: event,
|
626 |
+
callback: fn,
|
627 |
+
un: this.un.bind(this, event, fn)
|
628 |
+
};
|
629 |
+
},
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Remove an event handler.
|
633 |
+
*/
|
634 |
+
un: function (event, fn) {
|
635 |
+
if (!this.handlers) { return; }
|
636 |
+
|
637 |
+
var handlers = this.handlers[event];
|
638 |
+
if (handlers) {
|
639 |
+
if (fn) {
|
640 |
+
for (var i = handlers.length - 1; i >= 0; i--) {
|
641 |
+
if (handlers[i] == fn) {
|
642 |
+
handlers.splice(i, 1);
|
643 |
+
}
|
644 |
+
}
|
645 |
+
} else {
|
646 |
+
handlers.length = 0;
|
647 |
+
}
|
648 |
+
}
|
649 |
+
},
|
650 |
+
|
651 |
+
/**
|
652 |
+
* Remove all event handlers.
|
653 |
+
*/
|
654 |
+
unAll: function () {
|
655 |
+
this.handlers = null;
|
656 |
+
},
|
657 |
+
|
658 |
+
/**
|
659 |
+
* Attach a handler to an event. The handler is executed at most once per
|
660 |
+
* event type.
|
661 |
+
*/
|
662 |
+
once: function (event, handler) {
|
663 |
+
var my = this;
|
664 |
+
var fn = function () {
|
665 |
+
handler.apply(this, arguments);
|
666 |
+
setTimeout(function () {
|
667 |
+
my.un(event, fn);
|
668 |
+
}, 0);
|
669 |
+
};
|
670 |
+
return this.on(event, fn);
|
671 |
+
},
|
672 |
+
|
673 |
+
fireEvent: function (event) {
|
674 |
+
if (!this.handlers) { return; }
|
675 |
+
var handlers = this.handlers[event];
|
676 |
+
var args = Array.prototype.slice.call(arguments, 1);
|
677 |
+
handlers && handlers.forEach(function (fn) {
|
678 |
+
fn.apply(null, args);
|
679 |
+
});
|
680 |
+
}
|
681 |
+
};
|
682 |
+
|
683 |
+
/* Make the main WaveSurfer object an observer */
|
684 |
+
WaveSurfer.util.extend(WaveSurfer, WaveSurfer.Observer);
|
685 |
+
|
686 |
+
WaveSurfer.WebAudio = {
|
687 |
+
scriptBufferSize: 256,
|
688 |
+
PLAYING_STATE: 0,
|
689 |
+
PAUSED_STATE: 1,
|
690 |
+
FINISHED_STATE: 2,
|
691 |
+
|
692 |
+
supportsWebAudio: function () {
|
693 |
+
return !!(window.AudioContext || window.webkitAudioContext);
|
694 |
+
},
|
695 |
+
|
696 |
+
getAudioContext: function () {
|
697 |
+
if (!WaveSurfer.WebAudio.audioContext) {
|
698 |
+
WaveSurfer.WebAudio.audioContext = new (
|
699 |
+
window.AudioContext || window.webkitAudioContext
|
700 |
+
);
|
701 |
+
}
|
702 |
+
return WaveSurfer.WebAudio.audioContext;
|
703 |
+
},
|
704 |
+
|
705 |
+
getOfflineAudioContext: function (sampleRate) {
|
706 |
+
if (!WaveSurfer.WebAudio.offlineAudioContext) {
|
707 |
+
WaveSurfer.WebAudio.offlineAudioContext = new (
|
708 |
+
window.OfflineAudioContext || window.webkitOfflineAudioContext
|
709 |
+
)(1, 2, sampleRate);
|
710 |
+
}
|
711 |
+
return WaveSurfer.WebAudio.offlineAudioContext;
|
712 |
+
},
|
713 |
+
|
714 |
+
init: function (params) {
|
715 |
+
this.params = params;
|
716 |
+
this.ac = params.audioContext || this.getAudioContext();
|
717 |
+
this.lastPlay = this.ac.currentTime;
|
718 |
+
this.startPosition = 0;
|
719 |
+
this.scheduledPause = null;
|
720 |
+
|
721 |
+
this.states = [
|
722 |
+
Object.create(WaveSurfer.WebAudio.state.playing),
|
723 |
+
Object.create(WaveSurfer.WebAudio.state.paused),
|
724 |
+
Object.create(WaveSurfer.WebAudio.state.finished)
|
725 |
+
];
|
726 |
+
|
727 |
+
this.createVolumeNode();
|
728 |
+
this.createScriptNode();
|
729 |
+
this.createAnalyserNode();
|
730 |
+
|
731 |
+
this.setState(this.PAUSED_STATE);
|
732 |
+
this.setPlaybackRate(this.params.audioRate);
|
733 |
+
},
|
734 |
+
|
735 |
+
disconnectFilters: function () {
|
736 |
+
if (this.filters) {
|
737 |
+
this.filters.forEach(function (filter) {
|
738 |
+
filter && filter.disconnect();
|
739 |
+
});
|
740 |
+
this.filters = null;
|
741 |
+
// Reconnect direct path
|
742 |
+
this.analyser.connect(this.gainNode);
|
743 |
+
}
|
744 |
+
},
|
745 |
+
|
746 |
+
setState: function (state) {
|
747 |
+
if (this.state !== this.states[state]) {
|
748 |
+
this.state = this.states[state];
|
749 |
+
this.state.init.call(this);
|
750 |
+
}
|
751 |
+
},
|
752 |
+
|
753 |
+
// Unpacked filters
|
754 |
+
setFilter: function () {
|
755 |
+
this.setFilters([].slice.call(arguments));
|
756 |
+
},
|
757 |
+
|
758 |
+
/**
|
759 |
+
* @param {Array} filters Packed ilters array
|
760 |
+
*/
|
761 |
+
setFilters: function (filters) {
|
762 |
+
// Remove existing filters
|
763 |
+
this.disconnectFilters();
|
764 |
+
|
765 |
+
// Insert filters if filter array not empty
|
766 |
+
if (filters && filters.length) {
|
767 |
+
this.filters = filters;
|
768 |
+
|
769 |
+
// Disconnect direct path before inserting filters
|
770 |
+
this.analyser.disconnect();
|
771 |
+
|
772 |
+
// Connect each filter in turn
|
773 |
+
filters.reduce(function (prev, curr) {
|
774 |
+
prev.connect(curr);
|
775 |
+
return curr;
|
776 |
+
}, this.analyser).connect(this.gainNode);
|
777 |
+
}
|
778 |
+
|
779 |
+
},
|
780 |
+
|
781 |
+
createScriptNode: function () {
|
782 |
+
if (this.ac.createScriptProcessor) {
|
783 |
+
this.scriptNode = this.ac.createScriptProcessor(this.scriptBufferSize);
|
784 |
+
} else {
|
785 |
+
this.scriptNode = this.ac.createJavaScriptNode(this.scriptBufferSize);
|
786 |
+
}
|
787 |
+
|
788 |
+
this.scriptNode.connect(this.ac.destination);
|
789 |
+
},
|
790 |
+
|
791 |
+
addOnAudioProcess: function () {
|
792 |
+
var my = this;
|
793 |
+
|
794 |
+
this.scriptNode.onaudioprocess = function () {
|
795 |
+
var time = my.getCurrentTime();
|
796 |
+
|
797 |
+
if (time >= my.getDuration()) {
|
798 |
+
my.setState(my.FINISHED_STATE);
|
799 |
+
my.fireEvent('pause');
|
800 |
+
} else if (time >= my.scheduledPause) {
|
801 |
+
my.pause();
|
802 |
+
} else if (my.state === my.states[my.PLAYING_STATE]) {
|
803 |
+
my.fireEvent('audioprocess', time);
|
804 |
+
}
|
805 |
+
};
|
806 |
+
},
|
807 |
+
|
808 |
+
removeOnAudioProcess: function () {
|
809 |
+
this.scriptNode.onaudioprocess = null;
|
810 |
+
},
|
811 |
+
|
812 |
+
createAnalyserNode: function () {
|
813 |
+
this.analyser = this.ac.createAnalyser();
|
814 |
+
this.analyser.connect(this.gainNode);
|
815 |
+
},
|
816 |
+
|
817 |
+
/**
|
818 |
+
* Create the gain node needed to control the playback volume.
|
819 |
+
*/
|
820 |
+
createVolumeNode: function () {
|
821 |
+
// Create gain node using the AudioContext
|
822 |
+
if (this.ac.createGain) {
|
823 |
+
this.gainNode = this.ac.createGain();
|
824 |
+
} else {
|
825 |
+
this.gainNode = this.ac.createGainNode();
|
826 |
+
}
|
827 |
+
// Add the gain node to the graph
|
828 |
+
this.gainNode.connect(this.ac.destination);
|
829 |
+
},
|
830 |
+
|
831 |
+
/**
|
832 |
+
* Set the gain to a new value.
|
833 |
+
*
|
834 |
+
* @param {Number} newGain The new gain, a floating point value
|
835 |
+
* between 0 and 1. 0 being no gain and 1 being maximum gain.
|
836 |
+
*/
|
837 |
+
setVolume: function (newGain) {
|
838 |
+
this.gainNode.gain.value = newGain;
|
839 |
+
},
|
840 |
+
|
841 |
+
/**
|
842 |
+
* Get the current gain.
|
843 |
+
*
|
844 |
+
* @returns {Number} The current gain, a floating point value
|
845 |
+
* between 0 and 1. 0 being no gain and 1 being maximum gain.
|
846 |
+
*/
|
847 |
+
getVolume: function () {
|
848 |
+
return this.gainNode.gain.value;
|
849 |
+
},
|
850 |
+
|
851 |
+
decodeArrayBuffer: function (arraybuffer, callback, errback) {
|
852 |
+
if (!this.offlineAc) {
|
853 |
+
this.offlineAc = this.getOfflineAudioContext(this.ac ? this.ac.sampleRate : 44100);
|
854 |
+
}
|
855 |
+
this.offlineAc.decodeAudioData(arraybuffer, (function (data) {
|
856 |
+
callback(data);
|
857 |
+
}).bind(this), errback);
|
858 |
+
},
|
859 |
+
|
860 |
+
/**
|
861 |
+
* Set pre-decoded peaks.
|
862 |
+
*/
|
863 |
+
setPeaks: function (peaks) {
|
864 |
+
this.peaks = peaks;
|
865 |
+
},
|
866 |
+
|
867 |
+
/**
|
868 |
+
* Compute the max and min value of the waveform when broken into
|
869 |
+
* <length> subranges.
|
870 |
+
* @param {Number} How many subranges to break the waveform into.
|
871 |
+
* @returns {Array} Array of 2*<length> peaks or array of arrays
|
872 |
+
* of peaks consisting of (max, min) values for each subrange.
|
873 |
+
*/
|
874 |
+
getPeaks: function (length) {
|
875 |
+
if (this.peaks) { return this.peaks; }
|
876 |
+
|
877 |
+
var sampleSize = this.buffer.length / length;
|
878 |
+
var sampleStep = ~~(sampleSize / 10) || 1;
|
879 |
+
var channels = this.buffer.numberOfChannels;
|
880 |
+
var splitPeaks = [];
|
881 |
+
var mergedPeaks = [];
|
882 |
+
|
883 |
+
for (var c = 0; c < channels; c++) {
|
884 |
+
var peaks = splitPeaks[c] = [];
|
885 |
+
var chan = this.buffer.getChannelData(c);
|
886 |
+
|
887 |
+
for (var i = 0; i < length; i++) {
|
888 |
+
var start = ~~(i * sampleSize);
|
889 |
+
var end = ~~(start + sampleSize);
|
890 |
+
var min = 0;
|
891 |
+
var max = 0;
|
892 |
+
|
893 |
+
for (var j = start; j < end; j += sampleStep) {
|
894 |
+
var value = chan[j];
|
895 |
+
|
896 |
+
if (value > max) {
|
897 |
+
max = value;
|
898 |
+
}
|
899 |
+
|
900 |
+
if (value < min) {
|
901 |
+
min = value;
|
902 |
+
}
|
903 |
+
}
|
904 |
+
|
905 |
+
peaks[2 * i] = max;
|
906 |
+
peaks[2 * i + 1] = min;
|
907 |
+
|
908 |
+
if (c == 0 || max > mergedPeaks[2 * i]) {
|
909 |
+
mergedPeaks[2 * i] = max;
|
910 |
+
}
|
911 |
+
|
912 |
+
if (c == 0 || min < mergedPeaks[2 * i + 1]) {
|
913 |
+
mergedPeaks[2 * i + 1] = min;
|
914 |
+
}
|
915 |
+
}
|
916 |
+
}
|
917 |
+
|
918 |
+
return this.params.splitChannels ? splitPeaks : mergedPeaks;
|
919 |
+
},
|
920 |
+
|
921 |
+
getPlayedPercents: function () {
|
922 |
+
return this.state.getPlayedPercents.call(this);
|
923 |
+
},
|
924 |
+
|
925 |
+
disconnectSource: function () {
|
926 |
+
if (this.source) {
|
927 |
+
this.source.disconnect();
|
928 |
+
}
|
929 |
+
},
|
930 |
+
|
931 |
+
destroy: function () {
|
932 |
+
if (!this.isPaused()) {
|
933 |
+
this.pause();
|
934 |
+
}
|
935 |
+
this.unAll();
|
936 |
+
this.buffer = null;
|
937 |
+
this.disconnectFilters();
|
938 |
+
this.disconnectSource();
|
939 |
+
this.gainNode.disconnect();
|
940 |
+
this.scriptNode.disconnect();
|
941 |
+
this.analyser.disconnect();
|
942 |
+
},
|
943 |
+
|
944 |
+
load: function (buffer) {
|
945 |
+
this.startPosition = 0;
|
946 |
+
this.lastPlay = this.ac.currentTime;
|
947 |
+
this.buffer = buffer;
|
948 |
+
this.createSource();
|
949 |
+
},
|
950 |
+
|
951 |
+
createSource: function () {
|
952 |
+
this.disconnectSource();
|
953 |
+
this.source = this.ac.createBufferSource();
|
954 |
+
|
955 |
+
//adjust for old browsers.
|
956 |
+
this.source.start = this.source.start || this.source.noteGrainOn;
|
957 |
+
this.source.stop = this.source.stop || this.source.noteOff;
|
958 |
+
|
959 |
+
this.source.playbackRate.value = this.playbackRate;
|
960 |
+
this.source.buffer = this.buffer;
|
961 |
+
this.source.connect(this.analyser);
|
962 |
+
},
|
963 |
+
|
964 |
+
isPaused: function () {
|
965 |
+
return this.state !== this.states[this.PLAYING_STATE];
|
966 |
+
},
|
967 |
+
|
968 |
+
getDuration: function () {
|
969 |
+
if (!this.buffer) {
|
970 |
+
return 0;
|
971 |
+
}
|
972 |
+
return this.buffer.duration;
|
973 |
+
},
|
974 |
+
|
975 |
+
seekTo: function (start, end) {
|
976 |
+
if (!this.buffer) { return; }
|
977 |
+
|
978 |
+
this.scheduledPause = null;
|
979 |
+
|
980 |
+
if (start == null) {
|
981 |
+
start = this.getCurrentTime();
|
982 |
+
if (start >= this.getDuration()) {
|
983 |
+
start = 0;
|
984 |
+
}
|
985 |
+
}
|
986 |
+
if (end == null) {
|
987 |
+
end = this.getDuration();
|
988 |
+
}
|
989 |
+
|
990 |
+
this.startPosition = start;
|
991 |
+
this.lastPlay = this.ac.currentTime;
|
992 |
+
|
993 |
+
if (this.state === this.states[this.FINISHED_STATE]) {
|
994 |
+
this.setState(this.PAUSED_STATE);
|
995 |
+
}
|
996 |
+
|
997 |
+
return { start: start, end: end };
|
998 |
+
},
|
999 |
+
|
1000 |
+
getPlayedTime: function () {
|
1001 |
+
return (this.ac.currentTime - this.lastPlay) * this.playbackRate;
|
1002 |
+
},
|
1003 |
+
|
1004 |
+
/**
|
1005 |
+
* Plays the loaded audio region.
|
1006 |
+
*
|
1007 |
+
* @param {Number} start Start offset in seconds,
|
1008 |
+
* relative to the beginning of a clip.
|
1009 |
+
* @param {Number} end When to stop
|
1010 |
+
* relative to the beginning of a clip.
|
1011 |
+
*/
|
1012 |
+
play: function (start, end) {
|
1013 |
+
if (!this.buffer) { return; }
|
1014 |
+
|
1015 |
+
// need to re-create source on each playback
|
1016 |
+
this.createSource();
|
1017 |
+
|
1018 |
+
var adjustedTime = this.seekTo(start, end);
|
1019 |
+
|
1020 |
+
start = adjustedTime.start;
|
1021 |
+
end = adjustedTime.end;
|
1022 |
+
|
1023 |
+
this.scheduledPause = end;
|
1024 |
+
|
1025 |
+
this.source.start(0, start, end - start);
|
1026 |
+
|
1027 |
+
this.setState(this.PLAYING_STATE);
|
1028 |
+
|
1029 |
+
this.fireEvent('play');
|
1030 |
+
},
|
1031 |
+
|
1032 |
+
/**
|
1033 |
+
* Pauses the loaded audio.
|
1034 |
+
*/
|
1035 |
+
pause: function () {
|
1036 |
+
this.scheduledPause = null;
|
1037 |
+
|
1038 |
+
this.startPosition += this.getPlayedTime();
|
1039 |
+
this.source && this.source.stop(0);
|
1040 |
+
|
1041 |
+
this.setState(this.PAUSED_STATE);
|
1042 |
+
|
1043 |
+
this.fireEvent('pause');
|
1044 |
+
},
|
1045 |
+
|
1046 |
+
/**
|
1047 |
+
* Returns the current time in seconds relative to the audioclip's duration.
|
1048 |
+
*/
|
1049 |
+
getCurrentTime: function () {
|
1050 |
+
return this.state.getCurrentTime.call(this);
|
1051 |
+
},
|
1052 |
+
|
1053 |
+
/**
|
1054 |
+
* Set the audio source playback rate.
|
1055 |
+
*/
|
1056 |
+
setPlaybackRate: function (value) {
|
1057 |
+
value = value || 1;
|
1058 |
+
if (this.isPaused()) {
|
1059 |
+
this.playbackRate = value;
|
1060 |
+
} else {
|
1061 |
+
this.pause();
|
1062 |
+
this.playbackRate = value;
|
1063 |
+
this.play();
|
1064 |
+
}
|
1065 |
+
}
|
1066 |
+
};
|
1067 |
+
|
1068 |
+
WaveSurfer.WebAudio.state = {};
|
1069 |
+
|
1070 |
+
WaveSurfer.WebAudio.state.playing = {
|
1071 |
+
init: function () {
|
1072 |
+
this.addOnAudioProcess();
|
1073 |
+
},
|
1074 |
+
getPlayedPercents: function () {
|
1075 |
+
var duration = this.getDuration();
|
1076 |
+
return (this.getCurrentTime() / duration) || 0;
|
1077 |
+
},
|
1078 |
+
getCurrentTime: function () {
|
1079 |
+
return this.startPosition + this.getPlayedTime();
|
1080 |
+
}
|
1081 |
+
};
|
1082 |
+
|
1083 |
+
WaveSurfer.WebAudio.state.paused = {
|
1084 |
+
init: function () {
|
1085 |
+
this.removeOnAudioProcess();
|
1086 |
+
},
|
1087 |
+
getPlayedPercents: function () {
|
1088 |
+
var duration = this.getDuration();
|
1089 |
+
return (this.getCurrentTime() / duration) || 0;
|
1090 |
+
},
|
1091 |
+
getCurrentTime: function () {
|
1092 |
+
return this.startPosition;
|
1093 |
+
}
|
1094 |
+
};
|
1095 |
+
|
1096 |
+
WaveSurfer.WebAudio.state.finished = {
|
1097 |
+
init: function () {
|
1098 |
+
this.removeOnAudioProcess();
|
1099 |
+
this.fireEvent('finish');
|
1100 |
+
},
|
1101 |
+
getPlayedPercents: function () {
|
1102 |
+
return 1;
|
1103 |
+
},
|
1104 |
+
getCurrentTime: function () {
|
1105 |
+
return this.getDuration();
|
1106 |
+
}
|
1107 |
+
};
|
1108 |
+
|
1109 |
+
WaveSurfer.util.extend(WaveSurfer.WebAudio, WaveSurfer.Observer);
|
1110 |
+
|
1111 |
+
WaveSurfer.MediaElement = Object.create(WaveSurfer.WebAudio);
|
1112 |
+
|
1113 |
+
WaveSurfer.util.extend(WaveSurfer.MediaElement, {
|
1114 |
+
init: function (params) {
|
1115 |
+
this.params = params;
|
1116 |
+
|
1117 |
+
// Dummy media to catch errors
|
1118 |
+
this.media = {
|
1119 |
+
currentTime: 0,
|
1120 |
+
duration: 0,
|
1121 |
+
paused: true,
|
1122 |
+
playbackRate: 1,
|
1123 |
+
play: function () {},
|
1124 |
+
pause: function () {}
|
1125 |
+
};
|
1126 |
+
|
1127 |
+
this.mediaType = params.mediaType.toLowerCase();
|
1128 |
+
this.elementPosition = params.elementPosition;
|
1129 |
+
this.setPlaybackRate(this.params.audioRate);
|
1130 |
+
this.createTimer();
|
1131 |
+
},
|
1132 |
+
|
1133 |
+
|
1134 |
+
/**
|
1135 |
+
* Create a timer to provide a more precise `audioprocess' event.
|
1136 |
+
*/
|
1137 |
+
createTimer: function () {
|
1138 |
+
var my = this;
|
1139 |
+
var playing = false;
|
1140 |
+
|
1141 |
+
var onAudioProcess = function () {
|
1142 |
+
if (my.isPaused()) { return; }
|
1143 |
+
|
1144 |
+
my.fireEvent('audioprocess', my.getCurrentTime());
|
1145 |
+
|
1146 |
+
// Call again in the next frame
|
1147 |
+
var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame;
|
1148 |
+
requestAnimationFrame(onAudioProcess);
|
1149 |
+
};
|
1150 |
+
|
1151 |
+
this.on('play', onAudioProcess);
|
1152 |
+
},
|
1153 |
+
|
1154 |
+
/**
|
1155 |
+
* Create media element with url as its source,
|
1156 |
+
* and append to container element.
|
1157 |
+
* @param {String} url path to media file
|
1158 |
+
* @param {HTMLElement} container HTML element
|
1159 |
+
* @param {Array} peaks array of peak data
|
1160 |
+
*/
|
1161 |
+
load: function (url, container, peaks) {
|
1162 |
+
var my = this;
|
1163 |
+
|
1164 |
+
var media = document.createElement(this.mediaType);
|
1165 |
+
media.controls = this.params.mediaControls;
|
1166 |
+
media.autoplay = this.params.autoplay || false;
|
1167 |
+
media.preload = 'auto';
|
1168 |
+
media.src = url;
|
1169 |
+
media.style.width = '100%';
|
1170 |
+
|
1171 |
+
var prevMedia = container.querySelector(this.mediaType);
|
1172 |
+
if (prevMedia) {
|
1173 |
+
container.removeChild(prevMedia);
|
1174 |
+
}
|
1175 |
+
container.appendChild(media);
|
1176 |
+
|
1177 |
+
this._load(media, peaks);
|
1178 |
+
},
|
1179 |
+
|
1180 |
+
/**
|
1181 |
+
* Load existing media element.
|
1182 |
+
* @param {MediaElement} elt HTML5 Audio or Video element
|
1183 |
+
* @param {Array} peaks array of peak data
|
1184 |
+
*/
|
1185 |
+
loadElt: function (elt, peaks) {
|
1186 |
+
var my = this;
|
1187 |
+
|
1188 |
+
var media = elt;
|
1189 |
+
media.controls = this.params.mediaControls;
|
1190 |
+
media.autoplay = this.params.autoplay || false;
|
1191 |
+
|
1192 |
+
this._load(media, peaks);
|
1193 |
+
},
|
1194 |
+
|
1195 |
+
/**
|
1196 |
+
* Private method called by both load (from url)
|
1197 |
+
* and loadElt (existing media element).
|
1198 |
+
* @param {MediaElement} media HTML5 Audio or Video element
|
1199 |
+
* @param {Array} peaks array of peak data
|
1200 |
+
* @private
|
1201 |
+
*/
|
1202 |
+
_load: function (media, peaks) {
|
1203 |
+
var my = this;
|
1204 |
+
|
1205 |
+
media.addEventListener('error', function () {
|
1206 |
+
my.fireEvent('error', 'Error loading media element');
|
1207 |
+
});
|
1208 |
+
|
1209 |
+
media.addEventListener('canplay', function () {
|
1210 |
+
my.fireEvent('canplay');
|
1211 |
+
});
|
1212 |
+
|
1213 |
+
media.addEventListener('ended', function () {
|
1214 |
+
my.fireEvent('finish');
|
1215 |
+
});
|
1216 |
+
|
1217 |
+
this.media = media;
|
1218 |
+
this.peaks = peaks;
|
1219 |
+
this.onPlayEnd = null;
|
1220 |
+
this.buffer = null;
|
1221 |
+
this.setPlaybackRate(this.playbackRate);
|
1222 |
+
},
|
1223 |
+
|
1224 |
+
isPaused: function () {
|
1225 |
+
return !this.media || this.media.paused;
|
1226 |
+
},
|
1227 |
+
|
1228 |
+
getDuration: function () {
|
1229 |
+
var duration = this.media.duration;
|
1230 |
+
if (duration >= Infinity) { // streaming audio
|
1231 |
+
duration = this.media.seekable.end(0);
|
1232 |
+
}
|
1233 |
+
return duration;
|
1234 |
+
},
|
1235 |
+
|
1236 |
+
getCurrentTime: function () {
|
1237 |
+
return this.media && this.media.currentTime;
|
1238 |
+
},
|
1239 |
+
|
1240 |
+
getPlayedPercents: function () {
|
1241 |
+
return (this.getCurrentTime() / this.getDuration()) || 0;
|
1242 |
+
},
|
1243 |
+
|
1244 |
+
/**
|
1245 |
+
* Set the audio source playback rate.
|
1246 |
+
*/
|
1247 |
+
setPlaybackRate: function (value) {
|
1248 |
+
this.playbackRate = value || 1;
|
1249 |
+
this.media.playbackRate = this.playbackRate;
|
1250 |
+
},
|
1251 |
+
|
1252 |
+
seekTo: function (start) {
|
1253 |
+
if (start != null) {
|
1254 |
+
this.media.currentTime = start;
|
1255 |
+
}
|
1256 |
+
this.clearPlayEnd();
|
1257 |
+
},
|
1258 |
+
|
1259 |
+
/**
|
1260 |
+
* Plays the loaded audio region.
|
1261 |
+
*
|
1262 |
+
* @param {Number} start Start offset in seconds,
|
1263 |
+
* relative to the beginning of a clip.
|
1264 |
+
* @param {Number} end End offset in seconds,
|
1265 |
+
* relative to the beginning of a clip.
|
1266 |
+
*/
|
1267 |
+
play: function (start, end) {
|
1268 |
+
this.seekTo(start);
|
1269 |
+
this.media.play();
|
1270 |
+
end && this.setPlayEnd(end);
|
1271 |
+
this.fireEvent('play');
|
1272 |
+
},
|
1273 |
+
|
1274 |
+
/**
|
1275 |
+
* Pauses the loaded audio.
|
1276 |
+
*/
|
1277 |
+
pause: function () {
|
1278 |
+
this.media && this.media.pause();
|
1279 |
+
this.clearPlayEnd();
|
1280 |
+
this.fireEvent('pause');
|
1281 |
+
},
|
1282 |
+
|
1283 |
+
setPlayEnd: function (end) {
|
1284 |
+
var my = this;
|
1285 |
+
this.onPlayEnd = function (time) {
|
1286 |
+
if (time >= end) {
|
1287 |
+
my.pause();
|
1288 |
+
my.seekTo(end);
|
1289 |
+
}
|
1290 |
+
};
|
1291 |
+
this.on('audioprocess', this.onPlayEnd);
|
1292 |
+
},
|
1293 |
+
|
1294 |
+
clearPlayEnd: function () {
|
1295 |
+
if (this.onPlayEnd) {
|
1296 |
+
this.un('audioprocess', this.onPlayEnd);
|
1297 |
+
this.onPlayEnd = null;
|
1298 |
+
}
|
1299 |
+
},
|
1300 |
+
|
1301 |
+
getPeaks: function (length) {
|
1302 |
+
if (this.buffer) {
|
1303 |
+
return WaveSurfer.WebAudio.getPeaks.call(this, length);
|
1304 |
+
}
|
1305 |
+
return this.peaks || [];
|
1306 |
+
},
|
1307 |
+
|
1308 |
+
getVolume: function () {
|
1309 |
+
return this.media.volume;
|
1310 |
+
},
|
1311 |
+
|
1312 |
+
setVolume: function (val) {
|
1313 |
+
this.media.volume = val;
|
1314 |
+
},
|
1315 |
+
|
1316 |
+
destroy: function () {
|
1317 |
+
this.pause();
|
1318 |
+
this.unAll();
|
1319 |
+
this.media && this.media.parentNode && this.media.parentNode.removeChild(this.media);
|
1320 |
+
this.media = null;
|
1321 |
+
}
|
1322 |
+
});
|
1323 |
+
|
1324 |
+
//For backwards compatibility
|
1325 |
+
WaveSurfer.AudioElement = WaveSurfer.MediaElement;
|
1326 |
+
|
1327 |
+
WaveSurfer.Drawer = {
|
1328 |
+
init: function (container, params) {
|
1329 |
+
this.container = container;
|
1330 |
+
this.params = params;
|
1331 |
+
|
1332 |
+
this.width = 0;
|
1333 |
+
this.height = params.height * this.params.pixelRatio;
|
1334 |
+
|
1335 |
+
this.lastPos = 0;
|
1336 |
+
|
1337 |
+
this.initDrawer(params);
|
1338 |
+
this.createWrapper();
|
1339 |
+
this.createElements();
|
1340 |
+
},
|
1341 |
+
|
1342 |
+
createWrapper: function () {
|
1343 |
+
this.wrapper = this.container.appendChild(
|
1344 |
+
document.createElement('wave')
|
1345 |
+
);
|
1346 |
+
|
1347 |
+
this.style(this.wrapper, {
|
1348 |
+
display: 'block',
|
1349 |
+
position: 'relative',
|
1350 |
+
userSelect: 'none',
|
1351 |
+
webkitUserSelect: 'none',
|
1352 |
+
height: this.params.height + 'px'
|
1353 |
+
});
|
1354 |
+
|
1355 |
+
if (this.params.fillParent || this.params.scrollParent) {
|
1356 |
+
this.style(this.wrapper, {
|
1357 |
+
width: '100%',
|
1358 |
+
overflowX: this.params.hideScrollbar ? 'hidden' : 'auto',
|
1359 |
+
overflowY: 'hidden'
|
1360 |
+
});
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
this.setupWrapperEvents();
|
1364 |
+
},
|
1365 |
+
|
1366 |
+
handleEvent: function (e) {
|
1367 |
+
e.preventDefault();
|
1368 |
+
|
1369 |
+
var bbox = this.wrapper.getBoundingClientRect();
|
1370 |
+
|
1371 |
+
var nominalWidth = this.width;
|
1372 |
+
var parentWidth = this.getWidth();
|
1373 |
+
|
1374 |
+
var progress;
|
1375 |
+
|
1376 |
+
if (!this.params.fillParent && nominalWidth < parentWidth) {
|
1377 |
+
progress = ((e.clientX - bbox.left) * this.params.pixelRatio / nominalWidth) || 0;
|
1378 |
+
|
1379 |
+
if (progress > 1) {
|
1380 |
+
progress = 1;
|
1381 |
+
}
|
1382 |
+
} else {
|
1383 |
+
progress = ((e.clientX - bbox.left + this.wrapper.scrollLeft) / this.wrapper.scrollWidth) || 0;
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
return progress;
|
1387 |
+
},
|
1388 |
+
|
1389 |
+
setupWrapperEvents: function () {
|
1390 |
+
var my = this;
|
1391 |
+
|
1392 |
+
this.wrapper.addEventListener('click', function (e) {
|
1393 |
+
var scrollbarHeight = my.wrapper.offsetHeight - my.wrapper.clientHeight;
|
1394 |
+
if (scrollbarHeight != 0) {
|
1395 |
+
// scrollbar is visible. Check if click was on it
|
1396 |
+
var bbox = my.wrapper.getBoundingClientRect();
|
1397 |
+
if (e.clientY >= bbox.bottom - scrollbarHeight) {
|
1398 |
+
// ignore mousedown as it was on the scrollbar
|
1399 |
+
return;
|
1400 |
+
}
|
1401 |
+
}
|
1402 |
+
|
1403 |
+
if (my.params.interact) {
|
1404 |
+
my.fireEvent('click', e, my.handleEvent(e));
|
1405 |
+
}
|
1406 |
+
});
|
1407 |
+
|
1408 |
+
this.wrapper.addEventListener('scroll', function (e) {
|
1409 |
+
my.fireEvent('scroll', e);
|
1410 |
+
});
|
1411 |
+
},
|
1412 |
+
|
1413 |
+
drawPeaks: function (peaks, length) {
|
1414 |
+
this.resetScroll();
|
1415 |
+
this.setWidth(length);
|
1416 |
+
|
1417 |
+
this.params.barWidth ?
|
1418 |
+
this.drawBars(peaks) :
|
1419 |
+
this.drawWave(peaks);
|
1420 |
+
},
|
1421 |
+
|
1422 |
+
style: function (el, styles) {
|
1423 |
+
Object.keys(styles).forEach(function (prop) {
|
1424 |
+
if (el.style[prop] !== styles[prop]) {
|
1425 |
+
el.style[prop] = styles[prop];
|
1426 |
+
}
|
1427 |
+
});
|
1428 |
+
return el;
|
1429 |
+
},
|
1430 |
+
|
1431 |
+
resetScroll: function () {
|
1432 |
+
if (this.wrapper !== null) {
|
1433 |
+
this.wrapper.scrollLeft = 0;
|
1434 |
+
}
|
1435 |
+
},
|
1436 |
+
|
1437 |
+
recenter: function (percent) {
|
1438 |
+
var position = this.wrapper.scrollWidth * percent;
|
1439 |
+
this.recenterOnPosition(position, true);
|
1440 |
+
},
|
1441 |
+
|
1442 |
+
recenterOnPosition: function (position, immediate) {
|
1443 |
+
var scrollLeft = this.wrapper.scrollLeft;
|
1444 |
+
var half = ~~(this.wrapper.clientWidth / 2);
|
1445 |
+
var target = position - half;
|
1446 |
+
var offset = target - scrollLeft;
|
1447 |
+
var maxScroll = this.wrapper.scrollWidth - this.wrapper.clientWidth;
|
1448 |
+
|
1449 |
+
if (maxScroll == 0) {
|
1450 |
+
// no need to continue if scrollbar is not there
|
1451 |
+
return;
|
1452 |
+
}
|
1453 |
+
|
1454 |
+
// if the cursor is currently visible...
|
1455 |
+
if (!immediate && -half <= offset && offset < half) {
|
1456 |
+
// we'll limit the "re-center" rate.
|
1457 |
+
var rate = 5;
|
1458 |
+
offset = Math.max(-rate, Math.min(rate, offset));
|
1459 |
+
target = scrollLeft + offset;
|
1460 |
+
}
|
1461 |
+
|
1462 |
+
// limit target to valid range (0 to maxScroll)
|
1463 |
+
target = Math.max(0, Math.min(maxScroll, target));
|
1464 |
+
// no use attempting to scroll if we're not moving
|
1465 |
+
if (target != scrollLeft) {
|
1466 |
+
this.wrapper.scrollLeft = target;
|
1467 |
+
}
|
1468 |
+
|
1469 |
+
},
|
1470 |
+
|
1471 |
+
getWidth: function () {
|
1472 |
+
return Math.round(this.container.clientWidth * this.params.pixelRatio);
|
1473 |
+
},
|
1474 |
+
|
1475 |
+
setWidth: function (width) {
|
1476 |
+
if (width == this.width) { return; }
|
1477 |
+
|
1478 |
+
this.width = width;
|
1479 |
+
|
1480 |
+
if (this.params.fillParent || this.params.scrollParent) {
|
1481 |
+
this.style(this.wrapper, {
|
1482 |
+
width: ''
|
1483 |
+
});
|
1484 |
+
} else {
|
1485 |
+
this.style(this.wrapper, {
|
1486 |
+
width: ~~(this.width / this.params.pixelRatio) + 'px'
|
1487 |
+
});
|
1488 |
+
}
|
1489 |
+
|
1490 |
+
this.updateSize();
|
1491 |
+
},
|
1492 |
+
|
1493 |
+
setHeight: function (height) {
|
1494 |
+
if (height == this.height) { return; }
|
1495 |
+
this.height = height;
|
1496 |
+
this.style(this.wrapper, {
|
1497 |
+
height: ~~(this.height / this.params.pixelRatio) + 'px'
|
1498 |
+
});
|
1499 |
+
this.updateSize();
|
1500 |
+
},
|
1501 |
+
|
1502 |
+
progress: function (progress) {
|
1503 |
+
var minPxDelta = 1 / this.params.pixelRatio;
|
1504 |
+
var pos = Math.round(progress * this.width) * minPxDelta;
|
1505 |
+
|
1506 |
+
if (pos < this.lastPos || pos - this.lastPos >= minPxDelta) {
|
1507 |
+
this.lastPos = pos;
|
1508 |
+
|
1509 |
+
if (this.params.scrollParent && this.params.autoCenter) {
|
1510 |
+
var newPos = ~~(this.wrapper.scrollWidth * progress);
|
1511 |
+
this.recenterOnPosition(newPos);
|
1512 |
+
}
|
1513 |
+
|
1514 |
+
this.updateProgress(progress);
|
1515 |
+
}
|
1516 |
+
},
|
1517 |
+
|
1518 |
+
destroy: function () {
|
1519 |
+
this.unAll();
|
1520 |
+
if (this.wrapper) {
|
1521 |
+
this.container.removeChild(this.wrapper);
|
1522 |
+
this.wrapper = null;
|
1523 |
+
}
|
1524 |
+
},
|
1525 |
+
|
1526 |
+
/* Renderer-specific methods */
|
1527 |
+
initDrawer: function () {},
|
1528 |
+
|
1529 |
+
createElements: function () {},
|
1530 |
+
|
1531 |
+
updateSize: function () {},
|
1532 |
+
|
1533 |
+
drawWave: function (peaks, max) {},
|
1534 |
+
|
1535 |
+
clearWave: function () {},
|
1536 |
+
|
1537 |
+
updateProgress: function (position) {}
|
1538 |
+
};
|
1539 |
+
|
1540 |
+
WaveSurfer.util.extend(WaveSurfer.Drawer, WaveSurfer.Observer);
|
1541 |
+
|
1542 |
+
WaveSurfer.Drawer.Canvas = Object.create(WaveSurfer.Drawer);
|
1543 |
+
|
1544 |
+
WaveSurfer.util.extend(WaveSurfer.Drawer.Canvas, {
|
1545 |
+
createElements: function () {
|
1546 |
+
var waveCanvas = this.wrapper.appendChild(
|
1547 |
+
this.style(document.createElement('canvas'), {
|
1548 |
+
position: 'absolute',
|
1549 |
+
zIndex: 1,
|
1550 |
+
left: 0,
|
1551 |
+
top: 0,
|
1552 |
+
bottom: 0
|
1553 |
+
})
|
1554 |
+
);
|
1555 |
+
this.waveCc = waveCanvas.getContext('2d');
|
1556 |
+
|
1557 |
+
this.progressWave = this.wrapper.appendChild(
|
1558 |
+
this.style(document.createElement('wave'), {
|
1559 |
+
position: 'absolute',
|
1560 |
+
zIndex: 2,
|
1561 |
+
left: 0,
|
1562 |
+
top: 0,
|
1563 |
+
bottom: 0,
|
1564 |
+
overflow: 'hidden',
|
1565 |
+
width: '0',
|
1566 |
+
display: 'none',
|
1567 |
+
boxSizing: 'border-box',
|
1568 |
+
borderRightStyle: 'solid',
|
1569 |
+
borderRightWidth: this.params.cursorWidth + 'px',
|
1570 |
+
borderRightColor: this.params.cursorColor
|
1571 |
+
})
|
1572 |
+
);
|
1573 |
+
|
1574 |
+
if (this.params.waveColor != this.params.progressColor) {
|
1575 |
+
var progressCanvas = this.progressWave.appendChild(
|
1576 |
+
document.createElement('canvas')
|
1577 |
+
);
|
1578 |
+
this.progressCc = progressCanvas.getContext('2d');
|
1579 |
+
}
|
1580 |
+
},
|
1581 |
+
|
1582 |
+
updateSize: function () {
|
1583 |
+
var width = Math.round(this.width / this.params.pixelRatio);
|
1584 |
+
|
1585 |
+
this.waveCc.canvas.width = this.width;
|
1586 |
+
this.waveCc.canvas.height = this.height;
|
1587 |
+
this.style(this.waveCc.canvas, { width: width + 'px'});
|
1588 |
+
|
1589 |
+
this.style(this.progressWave, { display: 'block'});
|
1590 |
+
|
1591 |
+
if (this.progressCc) {
|
1592 |
+
this.progressCc.canvas.width = this.width;
|
1593 |
+
this.progressCc.canvas.height = this.height;
|
1594 |
+
this.style(this.progressCc.canvas, { width: width + 'px'});
|
1595 |
+
}
|
1596 |
+
|
1597 |
+
this.clearWave();
|
1598 |
+
},
|
1599 |
+
|
1600 |
+
clearWave: function () {
|
1601 |
+
this.waveCc.clearRect(0, 0, this.width, this.height);
|
1602 |
+
if (this.progressCc) {
|
1603 |
+
this.progressCc.clearRect(0, 0, this.width, this.height);
|
1604 |
+
}
|
1605 |
+
},
|
1606 |
+
|
1607 |
+
drawBars: function (peaks, channelIndex) {
|
1608 |
+
// Split channels
|
1609 |
+
if (peaks[0] instanceof Array) {
|
1610 |
+
var channels = peaks;
|
1611 |
+
if (this.params.splitChannels) {
|
1612 |
+
this.setHeight(channels.length * this.params.height * this.params.pixelRatio);
|
1613 |
+
channels.forEach(this.drawBars, this);
|
1614 |
+
return;
|
1615 |
+
} else {
|
1616 |
+
peaks = channels[0];
|
1617 |
+
}
|
1618 |
+
}
|
1619 |
+
|
1620 |
+
// Bar wave draws the bottom only as a reflection of the top,
|
1621 |
+
// so we don't need negative values
|
1622 |
+
var hasMinVals = [].some.call(peaks, function (val) { return val < 0; });
|
1623 |
+
if (hasMinVals) {
|
1624 |
+
peaks = [].filter.call(peaks, function (_, index) { return index % 2 == 0; });
|
1625 |
+
}
|
1626 |
+
|
1627 |
+
// A half-pixel offset makes lines crisp
|
1628 |
+
var $ = 0.5 / this.params.pixelRatio;
|
1629 |
+
var width = this.width;
|
1630 |
+
var height = this.params.height * this.params.pixelRatio;
|
1631 |
+
var offsetY = height * channelIndex || 0;
|
1632 |
+
var halfH = height / 2;
|
1633 |
+
var length = peaks.length;
|
1634 |
+
var bar = this.params.barWidth * this.params.pixelRatio;
|
1635 |
+
var gap = Math.max(this.params.pixelRatio, ~~(bar / 2));
|
1636 |
+
var step = bar + gap;
|
1637 |
+
|
1638 |
+
var absmax = 1;
|
1639 |
+
if (this.params.normalize) {
|
1640 |
+
absmax = Math.max.apply(Math, peaks);
|
1641 |
+
}
|
1642 |
+
|
1643 |
+
var scale = length / width;
|
1644 |
+
|
1645 |
+
this.waveCc.fillStyle = this.params.waveColor;
|
1646 |
+
if (this.progressCc) {
|
1647 |
+
this.progressCc.fillStyle = this.params.progressColor;
|
1648 |
+
}
|
1649 |
+
|
1650 |
+
[ this.waveCc, this.progressCc ].forEach(function (cc) {
|
1651 |
+
if (!cc) { return; }
|
1652 |
+
|
1653 |
+
for (var i = 0; i < width; i += step) {
|
1654 |
+
var h = Math.round(peaks[Math.floor(i * scale)] / absmax * halfH);
|
1655 |
+
cc.fillRect(i + $, halfH - h + offsetY, bar + $, h * 2);
|
1656 |
+
}
|
1657 |
+
}, this);
|
1658 |
+
},
|
1659 |
+
|
1660 |
+
drawWave: function (peaks, channelIndex) {
|
1661 |
+
// Split channels
|
1662 |
+
if (peaks[0] instanceof Array) {
|
1663 |
+
var channels = peaks;
|
1664 |
+
if (this.params.splitChannels) {
|
1665 |
+
this.setHeight(channels.length * this.params.height * this.params.pixelRatio);
|
1666 |
+
channels.forEach(this.drawWave, this);
|
1667 |
+
return;
|
1668 |
+
} else {
|
1669 |
+
peaks = channels[0];
|
1670 |
+
}
|
1671 |
+
}
|
1672 |
+
|
1673 |
+
// Support arrays without negative peaks
|
1674 |
+
var hasMinValues = [].some.call(peaks, function (val) { return val < 0; });
|
1675 |
+
if (!hasMinValues) {
|
1676 |
+
var reflectedPeaks = [];
|
1677 |
+
for (var i = 0, len = peaks.length; i < len; i++) {
|
1678 |
+
reflectedPeaks[2 * i] = peaks[i];
|
1679 |
+
reflectedPeaks[2 * i + 1] = -peaks[i];
|
1680 |
+
}
|
1681 |
+
peaks = reflectedPeaks;
|
1682 |
+
}
|
1683 |
+
|
1684 |
+
// A half-pixel offset makes lines crisp
|
1685 |
+
var $ = 0.5 / this.params.pixelRatio;
|
1686 |
+
var height = this.params.height * this.params.pixelRatio;
|
1687 |
+
var offsetY = height * channelIndex || 0;
|
1688 |
+
var halfH = height / 2;
|
1689 |
+
var length = ~~(peaks.length / 2);
|
1690 |
+
|
1691 |
+
var scale = 1;
|
1692 |
+
if (this.params.fillParent && this.width != length) {
|
1693 |
+
scale = this.width / length;
|
1694 |
+
}
|
1695 |
+
|
1696 |
+
var absmax = 1;
|
1697 |
+
if (this.params.normalize) {
|
1698 |
+
var max = Math.max.apply(Math, peaks);
|
1699 |
+
var min = Math.min.apply(Math, peaks);
|
1700 |
+
absmax = -min > max ? -min : max;
|
1701 |
+
}
|
1702 |
+
|
1703 |
+
this.waveCc.fillStyle = this.params.waveColor;
|
1704 |
+
if (this.progressCc) {
|
1705 |
+
this.progressCc.fillStyle = this.params.progressColor;
|
1706 |
+
}
|
1707 |
+
|
1708 |
+
[ this.waveCc, this.progressCc ].forEach(function (cc) {
|
1709 |
+
if (!cc) { return; }
|
1710 |
+
|
1711 |
+
cc.beginPath();
|
1712 |
+
cc.moveTo($, halfH + offsetY);
|
1713 |
+
|
1714 |
+
for (var i = 0; i < length; i++) {
|
1715 |
+
var h = Math.round(peaks[2 * i] / absmax * halfH);
|
1716 |
+
cc.lineTo(i * scale + $, halfH - h + offsetY);
|
1717 |
+
}
|
1718 |
+
|
1719 |
+
// Draw the bottom edge going backwards, to make a single
|
1720 |
+
// closed hull to fill.
|
1721 |
+
for (var i = length - 1; i >= 0; i--) {
|
1722 |
+
var h = Math.round(peaks[2 * i + 1] / absmax * halfH);
|
1723 |
+
cc.lineTo(i * scale + $, halfH - h + offsetY);
|
1724 |
+
}
|
1725 |
+
|
1726 |
+
cc.closePath();
|
1727 |
+
cc.fill();
|
1728 |
+
|
1729 |
+
// Always draw a median line
|
1730 |
+
cc.fillRect(0, halfH + offsetY - $, this.width, $);
|
1731 |
+
}, this);
|
1732 |
+
},
|
1733 |
+
|
1734 |
+
updateProgress: function (progress) {
|
1735 |
+
var pos = Math.round(
|
1736 |
+
this.width * progress
|
1737 |
+
) / this.params.pixelRatio;
|
1738 |
+
this.style(this.progressWave, { width: pos + 'px' });
|
1739 |
+
}
|
1740 |
+
});
|
1741 |
+
|
1742 |
+
WaveSurfer.Drawer.MultiCanvas = Object.create(WaveSurfer.Drawer);
|
1743 |
+
|
1744 |
+
WaveSurfer.util.extend(WaveSurfer.Drawer.MultiCanvas, {
|
1745 |
+
|
1746 |
+
initDrawer: function (params) {
|
1747 |
+
this.maxCanvasWidth = params.maxCanvasWidth != null ? params.maxCanvasWidth : 4000;
|
1748 |
+
this.maxCanvasElementWidth = Math.round(this.maxCanvasWidth / this.params.pixelRatio);
|
1749 |
+
|
1750 |
+
if (this.maxCanvasWidth <= 1) {
|
1751 |
+
throw 'maxCanvasWidth must be greater than 1.';
|
1752 |
+
} else if (this.maxCanvasWidth % 2 == 1) {
|
1753 |
+
throw 'maxCanvasWidth must be an even number.';
|
1754 |
+
}
|
1755 |
+
|
1756 |
+
this.hasProgressCanvas = this.params.waveColor != this.params.progressColor;
|
1757 |
+
this.halfPixel = 0.5 / this.params.pixelRatio;
|
1758 |
+
this.canvases = [];
|
1759 |
+
},
|
1760 |
+
|
1761 |
+
createElements: function () {
|
1762 |
+
this.progressWave = this.wrapper.appendChild(
|
1763 |
+
this.style(document.createElement('wave'), {
|
1764 |
+
position: 'absolute',
|
1765 |
+
zIndex: 2,
|
1766 |
+
left: 0,
|
1767 |
+
top: 0,
|
1768 |
+
bottom: 0,
|
1769 |
+
overflow: 'hidden',
|
1770 |
+
width: '0',
|
1771 |
+
display: 'none',
|
1772 |
+
boxSizing: 'border-box',
|
1773 |
+
borderRightStyle: 'solid',
|
1774 |
+
borderRightWidth: this.params.cursorWidth + 'px',
|
1775 |
+
borderRightColor: this.params.cursorColor
|
1776 |
+
})
|
1777 |
+
);
|
1778 |
+
|
1779 |
+
this.addCanvas();
|
1780 |
+
},
|
1781 |
+
|
1782 |
+
updateSize: function () {
|
1783 |
+
var totalWidth = Math.round(this.width / this.params.pixelRatio),
|
1784 |
+
requiredCanvases = Math.ceil(totalWidth / this.maxCanvasElementWidth);
|
1785 |
+
|
1786 |
+
while (this.canvases.length < requiredCanvases) {
|
1787 |
+
this.addCanvas();
|
1788 |
+
}
|
1789 |
+
|
1790 |
+
while (this.canvases.length > requiredCanvases) {
|
1791 |
+
this.removeCanvas();
|
1792 |
+
}
|
1793 |
+
|
1794 |
+
for (var i in this.canvases) {
|
1795 |
+
// Add some overlap to prevent vertical white stripes, keep the width even for simplicity.
|
1796 |
+
var canvasWidth = this.maxCanvasWidth + 2 * Math.ceil(this.params.pixelRatio / 2);
|
1797 |
+
|
1798 |
+
if (i == this.canvases.length - 1) {
|
1799 |
+
canvasWidth = this.width - (this.maxCanvasWidth * (this.canvases.length - 1));
|
1800 |
+
}
|
1801 |
+
|
1802 |
+
this.updateDimensions(this.canvases[i], canvasWidth, this.height);
|
1803 |
+
this.clearWaveForEntry(this.canvases[i]);
|
1804 |
+
}
|
1805 |
+
},
|
1806 |
+
|
1807 |
+
addCanvas: function () {
|
1808 |
+
var entry = {};
|
1809 |
+
var leftOffset = this.maxCanvasElementWidth * this.canvases.length;
|
1810 |
+
|
1811 |
+
entry.wave = this.wrapper.appendChild(
|
1812 |
+
this.style(document.createElement('canvas'), {
|
1813 |
+
position: 'absolute',
|
1814 |
+
zIndex: 1,
|
1815 |
+
left: leftOffset + 'px',
|
1816 |
+
top: 0,
|
1817 |
+
bottom: 0
|
1818 |
+
})
|
1819 |
+
);
|
1820 |
+
entry.waveCtx = entry.wave.getContext('2d');
|
1821 |
+
|
1822 |
+
if (this.hasProgressCanvas) {
|
1823 |
+
entry.progress = this.progressWave.appendChild(
|
1824 |
+
this.style(document.createElement('canvas'), {
|
1825 |
+
position: 'absolute',
|
1826 |
+
left: leftOffset + 'px',
|
1827 |
+
top: 0,
|
1828 |
+
bottom: 0
|
1829 |
+
})
|
1830 |
+
);
|
1831 |
+
entry.progressCtx = entry.progress.getContext('2d');
|
1832 |
+
}
|
1833 |
+
|
1834 |
+
this.canvases.push(entry);
|
1835 |
+
},
|
1836 |
+
|
1837 |
+
removeCanvas: function () {
|
1838 |
+
var lastEntry = this.canvases.pop();
|
1839 |
+
lastEntry.wave.parentElement.removeChild(lastEntry.wave);
|
1840 |
+
if (this.hasProgressCanvas) {
|
1841 |
+
lastEntry.progress.parentElement.removeChild(lastEntry.progress);
|
1842 |
+
}
|
1843 |
+
},
|
1844 |
+
|
1845 |
+
updateDimensions: function (entry, width, height) {
|
1846 |
+
var elementWidth = Math.round(width / this.params.pixelRatio);
|
1847 |
+
|
1848 |
+
entry.waveCtx.canvas.width = width;
|
1849 |
+
entry.waveCtx.canvas.height = height;
|
1850 |
+
this.style(entry.waveCtx.canvas, { width: elementWidth + 'px'});
|
1851 |
+
|
1852 |
+
this.style(this.progressWave, { display: 'block'});
|
1853 |
+
|
1854 |
+
if (this.hasProgressCanvas) {
|
1855 |
+
entry.progressCtx.canvas.width = width;
|
1856 |
+
entry.progressCtx.canvas.height = height;
|
1857 |
+
this.style(entry.progressCtx.canvas, { width: elementWidth + 'px'});
|
1858 |
+
}
|
1859 |
+
},
|
1860 |
+
|
1861 |
+
clearWave: function () {
|
1862 |
+
for (var i in this.canvases) {
|
1863 |
+
this.clearWaveForEntry(this.canvases[i]);
|
1864 |
+
}
|
1865 |
+
},
|
1866 |
+
|
1867 |
+
clearWaveForEntry: function (entry) {
|
1868 |
+
entry.waveCtx.clearRect(0, 0, entry.waveCtx.canvas.width, entry.waveCtx.canvas.height);
|
1869 |
+
if (this.hasProgressCanvas) {
|
1870 |
+
entry.progressCtx.clearRect(0, 0, entry.progressCtx.canvas.width, entry.progressCtx.canvas.height);
|
1871 |
+
}
|
1872 |
+
},
|
1873 |
+
|
1874 |
+
drawBars: function (peaks, channelIndex) {
|
1875 |
+
// Split channels
|
1876 |
+
if (peaks[0] instanceof Array) {
|
1877 |
+
var channels = peaks;
|
1878 |
+
if (this.params.splitChannels) {
|
1879 |
+
this.setHeight(channels.length * this.params.height * this.params.pixelRatio);
|
1880 |
+
channels.forEach(this.drawBars, this);
|
1881 |
+
return;
|
1882 |
+
} else {
|
1883 |
+
peaks = channels[0];
|
1884 |
+
}
|
1885 |
+
}
|
1886 |
+
|
1887 |
+
// Bar wave draws the bottom only as a reflection of the top,
|
1888 |
+
// so we don't need negative values
|
1889 |
+
var hasMinVals = [].some.call(peaks, function (val) { return val < 0; });
|
1890 |
+
if (hasMinVals) {
|
1891 |
+
peaks = [].filter.call(peaks, function (_, index) { return index % 2 == 0; });
|
1892 |
+
}
|
1893 |
+
|
1894 |
+
// A half-pixel offset makes lines crisp
|
1895 |
+
var width = this.width;
|
1896 |
+
var height = this.params.height * this.params.pixelRatio;
|
1897 |
+
var offsetY = height * channelIndex || 0;
|
1898 |
+
var halfH = height / 2;
|
1899 |
+
var length = peaks.length;
|
1900 |
+
var bar = this.params.barWidth * this.params.pixelRatio;
|
1901 |
+
var gap = Math.max(this.params.pixelRatio, ~~(bar / 2));
|
1902 |
+
var step = bar + gap;
|
1903 |
+
|
1904 |
+
var absmax = 1;
|
1905 |
+
if (this.params.normalize) {
|
1906 |
+
absmax = WaveSurfer.util.max(peaks);
|
1907 |
+
}
|
1908 |
+
|
1909 |
+
var scale = length / width;
|
1910 |
+
|
1911 |
+
this.canvases[0].waveCtx.fillStyle = this.params.waveColor;
|
1912 |
+
if (this.canvases[0].progressCtx) {
|
1913 |
+
this.canvases[0].progressCtx.fillStyle = this.params.progressColor;
|
1914 |
+
}
|
1915 |
+
|
1916 |
+
for (var i = 0; i < width; i += step) {
|
1917 |
+
var h = Math.round(peaks[Math.floor(i * scale)] / absmax * halfH);
|
1918 |
+
this.fillRect(i + this.halfPixel, halfH - h + offsetY, bar + this.halfPixel, h * 2);
|
1919 |
+
}
|
1920 |
+
},
|
1921 |
+
|
1922 |
+
drawWave: function (peaks, channelIndex) {
|
1923 |
+
// Split channels
|
1924 |
+
if (peaks[0] instanceof Array) {
|
1925 |
+
var channels = peaks;
|
1926 |
+
if (this.params.splitChannels) {
|
1927 |
+
this.setHeight(channels.length * this.params.height * this.params.pixelRatio);
|
1928 |
+
channels.forEach(this.drawWave, this);
|
1929 |
+
return;
|
1930 |
+
} else {
|
1931 |
+
peaks = channels[0];
|
1932 |
+
}
|
1933 |
+
}
|
1934 |
+
|
1935 |
+
// Support arrays without negative peaks
|
1936 |
+
var hasMinValues = [].some.call(peaks, function (val) { return val < 0; });
|
1937 |
+
if (!hasMinValues) {
|
1938 |
+
var reflectedPeaks = [];
|
1939 |
+
for (var i = 0, len = peaks.length; i < len; i++) {
|
1940 |
+
reflectedPeaks[2 * i] = peaks[i];
|
1941 |
+
reflectedPeaks[2 * i + 1] = -peaks[i];
|
1942 |
+
}
|
1943 |
+
peaks = reflectedPeaks;
|
1944 |
+
}
|
1945 |
+
|
1946 |
+
// A half-pixel offset makes lines crisp
|
1947 |
+
var height = this.params.height * this.params.pixelRatio;
|
1948 |
+
var offsetY = height * channelIndex || 0;
|
1949 |
+
var halfH = height / 2;
|
1950 |
+
var length = ~~(peaks.length / this.canvases.length / 2);
|
1951 |
+
|
1952 |
+
var absmax = 1;
|
1953 |
+
if (this.params.normalize) {
|
1954 |
+
var max = WaveSurfer.util.max(peaks);
|
1955 |
+
var min = WaveSurfer.util.min(peaks);
|
1956 |
+
absmax = -min > max ? -min : max;
|
1957 |
+
}
|
1958 |
+
|
1959 |
+
this.drawLine(length, peaks, absmax, halfH, offsetY);
|
1960 |
+
|
1961 |
+
// Always draw a median line
|
1962 |
+
this.fillRect(0, halfH + offsetY - this.halfPixel, this.width, this.halfPixel);
|
1963 |
+
},
|
1964 |
+
|
1965 |
+
drawLine: function (length, peaks, absmax, halfH, offsetY) {
|
1966 |
+
for (var index in this.canvases) {
|
1967 |
+
var entry = this.canvases[index];
|
1968 |
+
|
1969 |
+
this.setFillStyles(entry);
|
1970 |
+
|
1971 |
+
this.drawLineToContext(entry.waveCtx, length, index, peaks, absmax, halfH, offsetY);
|
1972 |
+
this.drawLineToContext(entry.progressCtx, length, index, peaks, absmax, halfH, offsetY);
|
1973 |
+
}
|
1974 |
+
},
|
1975 |
+
|
1976 |
+
drawLineToContext: function (ctx, length, index, peaks, absmax, halfH, offsetY) {
|
1977 |
+
if (!ctx) { return; }
|
1978 |
+
|
1979 |
+
var scale = 1;
|
1980 |
+
if (this.params.fillParent && this.width != length) {
|
1981 |
+
scale = ctx.canvas.width / length;
|
1982 |
+
}
|
1983 |
+
|
1984 |
+
var first = index * length,
|
1985 |
+
last = first + length + 1;
|
1986 |
+
|
1987 |
+
ctx.beginPath();
|
1988 |
+
ctx.moveTo(this.halfPixel, halfH + offsetY);
|
1989 |
+
|
1990 |
+
for (var i = first; i < last; i++) {
|
1991 |
+
var h = Math.round(peaks[2 * i] / absmax * halfH);
|
1992 |
+
ctx.lineTo((i - first) * scale + this.halfPixel, halfH - h + offsetY);
|
1993 |
+
}
|
1994 |
+
|
1995 |
+
// Draw the bottom edge going backwards, to make a single
|
1996 |
+
// closed hull to fill.
|
1997 |
+
for (var i = last - 1; i >= first; i--) {
|
1998 |
+
var h = Math.round(peaks[2 * i + 1] / absmax * halfH);
|
1999 |
+
ctx.lineTo((i - first) * scale + this.halfPixel, halfH - h + offsetY);
|
2000 |
+
}
|
2001 |
+
|
2002 |
+
ctx.closePath();
|
2003 |
+
ctx.fill();
|
2004 |
+
},
|
2005 |
+
|
2006 |
+
fillRect: function (x, y, width, height) {
|
2007 |
+
for (var i in this.canvases) {
|
2008 |
+
var entry = this.canvases[i],
|
2009 |
+
leftOffset = i * this.maxCanvasWidth;
|
2010 |
+
|
2011 |
+
var intersection = {
|
2012 |
+
x1: Math.max(x, i * this.maxCanvasWidth),
|
2013 |
+
y1: y,
|
2014 |
+
x2: Math.min(x + width, i * this.maxCanvasWidth + entry.waveCtx.canvas.width),
|
2015 |
+
y2: y + height
|
2016 |
+
};
|
2017 |
+
|
2018 |
+
if (intersection.x1 < intersection.x2) {
|
2019 |
+
this.setFillStyles(entry);
|
2020 |
+
|
2021 |
+
this.fillRectToContext(entry.waveCtx,
|
2022 |
+
intersection.x1 - leftOffset,
|
2023 |
+
intersection.y1,
|
2024 |
+
intersection.x2 - intersection.x1,
|
2025 |
+
intersection.y2 - intersection.y1);
|
2026 |
+
|
2027 |
+
this.fillRectToContext(entry.progressCtx,
|
2028 |
+
intersection.x1 - leftOffset,
|
2029 |
+
intersection.y1,
|
2030 |
+
intersection.x2 - intersection.x1,
|
2031 |
+
intersection.y2 - intersection.y1);
|
2032 |
+
}
|
2033 |
+
}
|
2034 |
+
},
|
2035 |
+
|
2036 |
+
fillRectToContext: function (ctx, x, y, width, height) {
|
2037 |
+
if (!ctx) { return; }
|
2038 |
+
ctx.fillRect(x, y, width, height);
|
2039 |
+
},
|
2040 |
+
|
2041 |
+
setFillStyles: function (entry) {
|
2042 |
+
entry.waveCtx.fillStyle = this.params.waveColor;
|
2043 |
+
if (this.hasProgressCanvas) {
|
2044 |
+
entry.progressCtx.fillStyle = this.params.progressColor;
|
2045 |
+
}
|
2046 |
+
},
|
2047 |
+
|
2048 |
+
updateProgress: function (progress) {
|
2049 |
+
var pos = Math.round(
|
2050 |
+
this.width * progress
|
2051 |
+
) / this.params.pixelRatio;
|
2052 |
+
this.style(this.progressWave, { width: pos + 'px' });
|
2053 |
+
}
|
2054 |
+
});
|
2055 |
+
|
2056 |
+
/* Init from HTML */
|
2057 |
+
(function () {
|
2058 |
+
var init = function () {
|
2059 |
+
var containers = document.querySelectorAll('wavesurfer');
|
2060 |
+
|
2061 |
+
Array.prototype.forEach.call(containers, function (el) {
|
2062 |
+
var params = WaveSurfer.util.extend({
|
2063 |
+
container: el,
|
2064 |
+
backend: 'MediaElement',
|
2065 |
+
mediaControls: true
|
2066 |
+
}, el.dataset);
|
2067 |
+
|
2068 |
+
el.style.display = 'block';
|
2069 |
+
|
2070 |
+
var wavesurfer = WaveSurfer.create(params);
|
2071 |
+
|
2072 |
+
if (el.dataset.peaks) {
|
2073 |
+
var peaks = JSON.parse(el.dataset.peaks);
|
2074 |
+
}
|
2075 |
+
|
2076 |
+
wavesurfer.load(el.dataset.url, peaks);
|
2077 |
+
});
|
2078 |
+
};
|
2079 |
+
|
2080 |
+
if (document.readyState === 'complete') {
|
2081 |
+
init();
|
2082 |
+
} else {
|
2083 |
+
window.addEventListener('load', init);
|
2084 |
+
}
|
2085 |
+
}());
|
2086 |
+
|
2087 |
+
return WaveSurfer;
|
2088 |
+
|
2089 |
+
}));
|
assets/wavesurfer/wavesurfer.min.js
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*! wavesurfer.js 1.1.5 (Wed, 08 Jun 2016 20:40:29 GMT)
|
2 |
+
* https://github.com/katspaugh/wavesurfer.js
|
3 |
+
* @license CC-BY-3.0 */
|
4 |
+
(function(e,a){"function"===typeof define&&define.amd?define("wavesurfer",[],function(){return e.WaveSurfer=a()}):"object"===typeof exports?module.exports=a():e.WaveSurfer=a()})(this,function(){var e={defaultParams:{height:128,waveColor:"#999",progressColor:"#555",cursorColor:"#333",cursorWidth:1,skipLength:2,minPxPerSec:20,pixelRatio:window.devicePixelRatio||screen.deviceXDPI/screen.logicalXDPI,fillParent:!0,scrollParent:!1,hideScrollbar:!1,normalize:!1,audioContext:null,container:null,dragSelection:!0,
|
5 |
+
loopSelection:!0,audioRate:1,interact:!0,splitChannels:!1,mediaContainer:null,mediaControls:!1,renderer:"Canvas",backend:"WebAudio",mediaType:"audio",autoCenter:!0},init:function(a){this.params=e.util.extend({},this.defaultParams,a);this.container="string"==typeof a.container?document.querySelector(this.params.container):this.params.container;if(!this.container)throw Error("Container element not found");this.mediaContainer=null==this.params.mediaContainer?this.container:"string"==typeof this.params.mediaContainer?
|
6 |
+
document.querySelector(this.params.mediaContainer):this.params.mediaContainer;if(!this.mediaContainer)throw Error("Media Container element not found");this.savedVolume=0;this.isMuted=!1;this.tmpEvents=[];this.currentAjax=null;this.createDrawer();this.createBackend()},createDrawer:function(){var a=this;this.drawer=Object.create(e.Drawer[this.params.renderer]);this.drawer.init(this.container,this.params);this.drawer.on("redraw",function(){a.drawBuffer();a.drawer.progress(a.backend.getPlayedPercents())});
|
7 |
+
this.drawer.on("click",function(b,c){setTimeout(function(){a.seekTo(c)},0)});this.drawer.on("scroll",function(b){a.fireEvent("scroll",b)})},createBackend:function(){var a=this;this.backend&&this.backend.destroy();"AudioElement"==this.params.backend&&(this.params.backend="MediaElement");"WebAudio"!=this.params.backend||e.WebAudio.supportsWebAudio()||(this.params.backend="MediaElement");this.backend=Object.create(e[this.params.backend]);this.backend.init(this.params);this.backend.on("finish",function(){a.fireEvent("finish")});
|
8 |
+
this.backend.on("play",function(){a.fireEvent("play")});this.backend.on("pause",function(){a.fireEvent("pause")});this.backend.on("audioprocess",function(b){a.drawer.progress(a.backend.getPlayedPercents());a.fireEvent("audioprocess",b)})},getDuration:function(){return this.backend.getDuration()},getCurrentTime:function(){return this.backend.getCurrentTime()},play:function(a,b){this.fireEvent("interaction",this.play.bind(this,a,b));this.backend.play(a,b)},pause:function(){this.backend.pause()},playPause:function(){this.backend.isPaused()?
|
9 |
+
this.play():this.pause()},isPlaying:function(){return!this.backend.isPaused()},skipBackward:function(a){this.skip(-a||-this.params.skipLength)},skipForward:function(a){this.skip(a||this.params.skipLength)},skip:function(a){var b=this.getCurrentTime()||0,c=this.getDuration()||1,b=Math.max(0,Math.min(c,b+(a||0)));this.seekAndCenter(b/c)},seekAndCenter:function(a){this.seekTo(a);this.drawer.recenter(a)},seekTo:function(a){this.fireEvent("interaction",this.seekTo.bind(this,a));var b=this.backend.isPaused(),
|
10 |
+
c=this.params.scrollParent;b&&(this.params.scrollParent=!1);this.backend.seekTo(a*this.getDuration());this.drawer.progress(this.backend.getPlayedPercents());if(!b){this.backend.pause();var d=this.backend;setTimeout(function(){d.play()},200)}this.params.scrollParent=c;this.fireEvent("seek",a)},stop:function(){this.pause();this.seekTo(0);this.drawer.progress(0)},setVolume:function(a){this.backend.setVolume(a)},setPlaybackRate:function(a){this.backend.setPlaybackRate(a)},toggleMute:function(){this.isMuted?
|
11 |
+
(this.backend.setVolume(this.savedVolume),this.isMuted=!1):(this.savedVolume=this.backend.getVolume(),this.backend.setVolume(0),this.isMuted=!0)},toggleScroll:function(){this.params.scrollParent=!this.params.scrollParent;this.drawBuffer()},toggleInteraction:function(){this.params.interact=!this.params.interact},drawBuffer:function(){var a=Math.round(this.getDuration()*this.params.minPxPerSec*this.params.pixelRatio),b=this.drawer.getWidth(),c=a;this.params.fillParent&&(!this.params.scrollParent||a<
|
12 |
+
b)&&(c=b);a=this.backend.getPeaks(c);this.drawer.drawPeaks(a,c);this.fireEvent("redraw",a,c)},zoom:function(a){this.params.minPxPerSec=a;this.params.scrollParent=!0;this.drawBuffer();this.seekAndCenter(this.getCurrentTime()/this.getDuration());this.fireEvent("zoom",a)},loadArrayBuffer:function(a){this.decodeArrayBuffer(a,function(a){this.loadDecodedBuffer(a)}.bind(this))},loadDecodedBuffer:function(a){this.backend.load(a);this.drawBuffer();this.fireEvent("ready")},loadBlob:function(a){var b=this,
|
13 |
+
c=new FileReader;c.addEventListener("progress",function(a){b.onProgress(a)});c.addEventListener("load",function(a){b.loadArrayBuffer(a.target.result)});c.addEventListener("error",function(){b.fireEvent("error","Error reading file")});c.readAsArrayBuffer(a);this.empty()},load:function(a,b){switch(this.params.backend){case "WebAudio":return this.loadBuffer(a,b);case "MediaElement":return this.loadMediaElement(a,b)}},loadBuffer:function(a,b){var c=function(b){b&&this.tmpEvents.push(this.once("ready",
|
14 |
+
b));return this.getArrayBuffer(a,this.loadArrayBuffer.bind(this))}.bind(this);if(b)this.backend.setPeaks(b),this.drawBuffer(),this.tmpEvents.push(this.once("interaction",c));else return c()},loadMediaElement:function(a,b){var c=a;"string"===typeof a?this.backend.load(c,this.mediaContainer,b):(this.backend.loadElt(a,b),c=a.src);this.tmpEvents.push(this.backend.once("canplay",function(){this.drawBuffer();this.fireEvent("ready")}.bind(this)),this.backend.once("error",function(a){this.fireEvent("error",
|
15 |
+
a)}.bind(this)));b?this.backend.setPeaks(b):this.backend.supportsWebAudio()&&this.getArrayBuffer(c,function(a){this.decodeArrayBuffer(a,function(a){this.backend.buffer=a;this.drawBuffer()}.bind(this))}.bind(this))},decodeArrayBuffer:function(a,b){this.arraybuffer=a;this.backend.decodeArrayBuffer(a,function(c){this.arraybuffer==a&&(b(c),this.arraybuffer=null)}.bind(this),this.fireEvent.bind(this,"error","Error decoding audiobuffer"))},getArrayBuffer:function(a,b){var c=this,d=e.util.ajax({url:a,responseType:"arraybuffer"});
|
16 |
+
this.currentAjax=d;this.tmpEvents.push(d.on("progress",function(a){c.onProgress(a)}),d.on("success",function(a,d){b(a);c.currentAjax=null}),d.on("error",function(a){c.fireEvent("error","XHR error: "+a.target.statusText);c.currentAjax=null}));return d},onProgress:function(a){this.fireEvent("loading",Math.round(100*(a.lengthComputable?a.loaded/a.total:a.loaded/(a.loaded+1E6))),a.target)},exportPCM:function(a,b,c){b=b||1E4;c=c||!1;a=this.backend.getPeaks(a||1024,b);a=[].map.call(a,function(a){return Math.round(a*
|
17 |
+
b)/b});a=JSON.stringify(a);c||window.open("data:application/json;charset=utf-8,"+encodeURIComponent(a));return a},cancelAjax:function(){this.currentAjax&&(this.currentAjax.xhr.abort(),this.currentAjax=null)},clearTmpEvents:function(){this.tmpEvents.forEach(function(a){a.un()})},empty:function(){this.backend.isPaused()||(this.stop(),this.backend.disconnectSource());this.cancelAjax();this.clearTmpEvents();this.drawer.progress(0);this.drawer.setWidth(0);this.drawer.drawPeaks({length:this.drawer.getWidth()},
|
18 |
+
0)},destroy:function(){this.fireEvent("destroy");this.cancelAjax();this.clearTmpEvents();this.unAll();this.backend.destroy();this.drawer.destroy()},create:function(a){var b=Object.create(e);b.init(a);return b},util:{extend:function(a){Array.prototype.slice.call(arguments,1).forEach(function(b){Object.keys(b).forEach(function(c){a[c]=b[c]})});return a},min:function(a){var b=Infinity,c;for(c in a)a[c]<b&&(b=a[c]);return b},max:function(a){var b=-Infinity,c;for(c in a)a[c]>b&&(b=a[c]);return b},getId:function(){return"wavesurfer_"+
|
19 |
+
Math.random().toString(32).substring(2)},ajax:function(a){var b=Object.create(e.Observer),c=new XMLHttpRequest,d=!1;c.open(a.method||"GET",a.url,!0);c.responseType=a.responseType||"json";c.addEventListener("progress",function(a){b.fireEvent("progress",a);a.lengthComputable&&a.loaded==a.total&&(d=!0)});c.addEventListener("load",function(a){d||b.fireEvent("progress",a);b.fireEvent("load",a);200==c.status||206==c.status?b.fireEvent("success",c.response,a):b.fireEvent("error",a)});c.addEventListener("error",
|
20 |
+
function(a){b.fireEvent("error",a)});c.send();b.xhr=c;return b}},Observer:{on:function(a,b){this.handlers||(this.handlers={});var c=this.handlers[a];c||(c=this.handlers[a]=[]);c.push(b);return{name:a,callback:b,un:this.un.bind(this,a,b)}},un:function(a,b){if(this.handlers){var c=this.handlers[a];if(c)if(b)for(var d=c.length-1;0<=d;d--)c[d]==b&&c.splice(d,1);else c.length=0}},unAll:function(){this.handlers=null},once:function(a,b){var c=this,d=function(){b.apply(this,arguments);setTimeout(function(){c.un(a,
|
21 |
+
d)},0)};return this.on(a,d)},fireEvent:function(a){if(this.handlers){var b=this.handlers[a],c=Array.prototype.slice.call(arguments,1);b&&b.forEach(function(a){a.apply(null,c)})}}}};e.util.extend(e,e.Observer);e.WebAudio={scriptBufferSize:256,PLAYING_STATE:0,PAUSED_STATE:1,FINISHED_STATE:2,supportsWebAudio:function(){return!(!window.AudioContext&&!window.webkitAudioContext)},getAudioContext:function(){e.WebAudio.audioContext||(e.WebAudio.audioContext=new (window.AudioContext||window.webkitAudioContext));
|
22 |
+
return e.WebAudio.audioContext},getOfflineAudioContext:function(a){e.WebAudio.offlineAudioContext||(e.WebAudio.offlineAudioContext=new (window.OfflineAudioContext||window.webkitOfflineAudioContext)(1,2,a));return e.WebAudio.offlineAudioContext},init:function(a){this.params=a;this.ac=a.audioContext||this.getAudioContext();this.lastPlay=this.ac.currentTime;this.startPosition=0;this.scheduledPause=null;this.states=[Object.create(e.WebAudio.state.playing),Object.create(e.WebAudio.state.paused),Object.create(e.WebAudio.state.finished)];
|
23 |
+
this.createVolumeNode();this.createScriptNode();this.createAnalyserNode();this.setState(this.PAUSED_STATE);this.setPlaybackRate(this.params.audioRate)},disconnectFilters:function(){this.filters&&(this.filters.forEach(function(a){a&&a.disconnect()}),this.filters=null,this.analyser.connect(this.gainNode))},setState:function(a){this.state!==this.states[a]&&(this.state=this.states[a],this.state.init.call(this))},setFilter:function(){this.setFilters([].slice.call(arguments))},setFilters:function(a){this.disconnectFilters();
|
24 |
+
a&&a.length&&(this.filters=a,this.analyser.disconnect(),a.reduce(function(a,c){a.connect(c);return c},this.analyser).connect(this.gainNode))},createScriptNode:function(){this.scriptNode=this.ac.createScriptProcessor?this.ac.createScriptProcessor(this.scriptBufferSize):this.ac.createJavaScriptNode(this.scriptBufferSize);this.scriptNode.connect(this.ac.destination)},addOnAudioProcess:function(){var a=this;this.scriptNode.onaudioprocess=function(){var b=a.getCurrentTime();b>=a.getDuration()?(a.setState(a.FINISHED_STATE),
|
25 |
+
a.fireEvent("pause")):b>=a.scheduledPause?a.pause():a.state===a.states[a.PLAYING_STATE]&&a.fireEvent("audioprocess",b)}},removeOnAudioProcess:function(){this.scriptNode.onaudioprocess=null},createAnalyserNode:function(){this.analyser=this.ac.createAnalyser();this.analyser.connect(this.gainNode)},createVolumeNode:function(){this.gainNode=this.ac.createGain?this.ac.createGain():this.ac.createGainNode();this.gainNode.connect(this.ac.destination)},setVolume:function(a){this.gainNode.gain.value=a},getVolume:function(){return this.gainNode.gain.value},
|
26 |
+
decodeArrayBuffer:function(a,b,c){this.offlineAc||(this.offlineAc=this.getOfflineAudioContext(this.ac?this.ac.sampleRate:44100));this.offlineAc.decodeAudioData(a,function(a){b(a)}.bind(this),c)},setPeaks:function(a){this.peaks=a},getPeaks:function(a){if(this.peaks)return this.peaks;for(var b=this.buffer.length/a,c=~~(b/10)||1,d=this.buffer.numberOfChannels,e=[],f=[],g=0;g<d;g++)for(var l=e[g]=[],k=this.buffer.getChannelData(g),h=0;h<a;h++){for(var m=~~(h*b),t=~~(m+b),q=0,n=0;m<t;m+=c){var r=k[m];
|
27 |
+
r>n&&(n=r);r<q&&(q=r)}l[2*h]=n;l[2*h+1]=q;if(0==g||n>f[2*h])f[2*h]=n;if(0==g||q<f[2*h+1])f[2*h+1]=q}return this.params.splitChannels?e:f},getPlayedPercents:function(){return this.state.getPlayedPercents.call(this)},disconnectSource:function(){this.source&&this.source.disconnect()},destroy:function(){this.isPaused()||this.pause();this.unAll();this.buffer=null;this.disconnectFilters();this.disconnectSource();this.gainNode.disconnect();this.scriptNode.disconnect();this.analyser.disconnect()},load:function(a){this.startPosition=
|
28 |
+
0;this.lastPlay=this.ac.currentTime;this.buffer=a;this.createSource()},createSource:function(){this.disconnectSource();this.source=this.ac.createBufferSource();this.source.start=this.source.start||this.source.noteGrainOn;this.source.stop=this.source.stop||this.source.noteOff;this.source.playbackRate.value=this.playbackRate;this.source.buffer=this.buffer;this.source.connect(this.analyser)},isPaused:function(){return this.state!==this.states[this.PLAYING_STATE]},getDuration:function(){return this.buffer?
|
29 |
+
this.buffer.duration:0},seekTo:function(a,b){if(this.buffer)return this.scheduledPause=null,null==a&&(a=this.getCurrentTime(),a>=this.getDuration()&&(a=0)),null==b&&(b=this.getDuration()),this.startPosition=a,this.lastPlay=this.ac.currentTime,this.state===this.states[this.FINISHED_STATE]&&this.setState(this.PAUSED_STATE),{start:a,end:b}},getPlayedTime:function(){return(this.ac.currentTime-this.lastPlay)*this.playbackRate},play:function(a,b){if(this.buffer){this.createSource();var c=this.seekTo(a,
|
30 |
+
b);a=c.start;this.scheduledPause=b=c.end;this.source.start(0,a,b-a);this.setState(this.PLAYING_STATE);this.fireEvent("play")}},pause:function(){this.scheduledPause=null;this.startPosition+=this.getPlayedTime();this.source&&this.source.stop(0);this.setState(this.PAUSED_STATE);this.fireEvent("pause")},getCurrentTime:function(){return this.state.getCurrentTime.call(this)},setPlaybackRate:function(a){a=a||1;this.isPaused()?this.playbackRate=a:(this.pause(),this.playbackRate=a,this.play())}};e.WebAudio.state=
|
31 |
+
{};e.WebAudio.state.playing={init:function(){this.addOnAudioProcess()},getPlayedPercents:function(){var a=this.getDuration();return this.getCurrentTime()/a||0},getCurrentTime:function(){return this.startPosition+this.getPlayedTime()}};e.WebAudio.state.paused={init:function(){this.removeOnAudioProcess()},getPlayedPercents:function(){var a=this.getDuration();return this.getCurrentTime()/a||0},getCurrentTime:function(){return this.startPosition}};e.WebAudio.state.finished={init:function(){this.removeOnAudioProcess();
|
32 |
+
this.fireEvent("finish")},getPlayedPercents:function(){return 1},getCurrentTime:function(){return this.getDuration()}};e.util.extend(e.WebAudio,e.Observer);e.MediaElement=Object.create(e.WebAudio);e.util.extend(e.MediaElement,{init:function(a){this.params=a;this.media={currentTime:0,duration:0,paused:!0,playbackRate:1,play:function(){},pause:function(){}};this.mediaType=a.mediaType.toLowerCase();this.elementPosition=a.elementPosition;this.setPlaybackRate(this.params.audioRate);this.createTimer()},
|
33 |
+
createTimer:function(){var a=this,b=function(){a.isPaused()||(a.fireEvent("audioprocess",a.getCurrentTime()),(window.requestAnimationFrame||window.webkitRequestAnimationFrame)(b))};this.on("play",b)},load:function(a,b,c){var d=document.createElement(this.mediaType);d.controls=this.params.mediaControls;d.autoplay=this.params.autoplay||!1;d.preload="auto";d.src=a;d.style.width="100%";(a=b.querySelector(this.mediaType))&&b.removeChild(a);b.appendChild(d);this._load(d,c)},loadElt:function(a,b){a.controls=
|
34 |
+
this.params.mediaControls;a.autoplay=this.params.autoplay||!1;this._load(a,b)},_load:function(a,b){var c=this;a.addEventListener("error",function(){c.fireEvent("error","Error loading media element")});a.addEventListener("canplay",function(){c.fireEvent("canplay")});a.addEventListener("ended",function(){c.fireEvent("finish")});this.media=a;this.peaks=b;this.buffer=this.onPlayEnd=null;this.setPlaybackRate(this.playbackRate)},isPaused:function(){return!this.media||this.media.paused},getDuration:function(){var a=
|
35 |
+
this.media.duration;Infinity<=a&&(a=this.media.seekable.end(0));return a},getCurrentTime:function(){return this.media&&this.media.currentTime},getPlayedPercents:function(){return this.getCurrentTime()/this.getDuration()||0},setPlaybackRate:function(a){this.playbackRate=a||1;this.media.playbackRate=this.playbackRate},seekTo:function(a){null!=a&&(this.media.currentTime=a);this.clearPlayEnd()},play:function(a,b){this.seekTo(a);this.media.play();b&&this.setPlayEnd(b);this.fireEvent("play")},pause:function(){this.media&&
|
36 |
+
this.media.pause();this.clearPlayEnd();this.fireEvent("pause")},setPlayEnd:function(a){var b=this;this.onPlayEnd=function(c){c>=a&&(b.pause(),b.seekTo(a))};this.on("audioprocess",this.onPlayEnd)},clearPlayEnd:function(){this.onPlayEnd&&(this.un("audioprocess",this.onPlayEnd),this.onPlayEnd=null)},getPeaks:function(a){return this.buffer?e.WebAudio.getPeaks.call(this,a):this.peaks||[]},getVolume:function(){return this.media.volume},setVolume:function(a){this.media.volume=a},destroy:function(){this.pause();
|
37 |
+
this.unAll();this.media&&this.media.parentNode&&this.media.parentNode.removeChild(this.media);this.media=null}});e.AudioElement=e.MediaElement;e.Drawer={init:function(a,b){this.container=a;this.params=b;this.width=0;this.height=b.height*this.params.pixelRatio;this.lastPos=0;this.initDrawer(b);this.createWrapper();this.createElements()},createWrapper:function(){this.wrapper=this.container.appendChild(document.createElement("wave"));this.style(this.wrapper,{display:"block",position:"relative",userSelect:"none",
|
38 |
+
webkitUserSelect:"none",height:this.params.height+"px"});(this.params.fillParent||this.params.scrollParent)&&this.style(this.wrapper,{width:"100%",overflowX:this.params.hideScrollbar?"hidden":"auto",overflowY:"hidden"});this.setupWrapperEvents()},handleEvent:function(a){a.preventDefault();var b=this.wrapper.getBoundingClientRect(),c=this.width,d=this.getWidth();!this.params.fillParent&&c<d?(a=(a.clientX-b.left)*this.params.pixelRatio/c||0,1<a&&(a=1)):a=(a.clientX-b.left+this.wrapper.scrollLeft)/this.wrapper.scrollWidth||
|
39 |
+
0;return a},setupWrapperEvents:function(){var a=this;this.wrapper.addEventListener("click",function(b){var c=a.wrapper.offsetHeight-a.wrapper.clientHeight;if(0!=c){var d=a.wrapper.getBoundingClientRect();if(b.clientY>=d.bottom-c)return}a.params.interact&&a.fireEvent("click",b,a.handleEvent(b))});this.wrapper.addEventListener("scroll",function(b){a.fireEvent("scroll",b)})},drawPeaks:function(a,b){this.resetScroll();this.setWidth(b);this.params.barWidth?this.drawBars(a):this.drawWave(a)},style:function(a,
|
40 |
+
b){Object.keys(b).forEach(function(c){a.style[c]!==b[c]&&(a.style[c]=b[c])});return a},resetScroll:function(){null!==this.wrapper&&(this.wrapper.scrollLeft=0)},recenter:function(a){this.recenterOnPosition(this.wrapper.scrollWidth*a,!0)},recenterOnPosition:function(a,b){var c=this.wrapper.scrollLeft,d=~~(this.wrapper.clientWidth/2),e=a-d,f=e-c,g=this.wrapper.scrollWidth-this.wrapper.clientWidth;0!=g&&(!b&&-d<=f&&f<d&&(f=Math.max(-5,Math.min(5,f)),e=c+f),e=Math.max(0,Math.min(g,e)),e!=c&&(this.wrapper.scrollLeft=
|
41 |
+
e))},getWidth:function(){return Math.round(this.container.clientWidth*this.params.pixelRatio)},setWidth:function(a){a!=this.width&&(this.width=a,this.params.fillParent||this.params.scrollParent?this.style(this.wrapper,{width:""}):this.style(this.wrapper,{width:~~(this.width/this.params.pixelRatio)+"px"}),this.updateSize())},setHeight:function(a){a!=this.height&&(this.height=a,this.style(this.wrapper,{height:~~(this.height/this.params.pixelRatio)+"px"}),this.updateSize())},progress:function(a){var b=
|
42 |
+
1/this.params.pixelRatio,c=Math.round(a*this.width)*b;if(c<this.lastPos||c-this.lastPos>=b)this.lastPos=c,this.params.scrollParent&&this.params.autoCenter&&this.recenterOnPosition(~~(this.wrapper.scrollWidth*a)),this.updateProgress(a)},destroy:function(){this.unAll();this.wrapper&&(this.container.removeChild(this.wrapper),this.wrapper=null)},initDrawer:function(){},createElements:function(){},updateSize:function(){},drawWave:function(a,b){},clearWave:function(){},updateProgress:function(a){}};e.util.extend(e.Drawer,
|
43 |
+
e.Observer);e.Drawer.Canvas=Object.create(e.Drawer);e.util.extend(e.Drawer.Canvas,{createElements:function(){this.waveCc=this.wrapper.appendChild(this.style(document.createElement("canvas"),{position:"absolute",zIndex:1,left:0,top:0,bottom:0})).getContext("2d");this.progressWave=this.wrapper.appendChild(this.style(document.createElement("wave"),{position:"absolute",zIndex:2,left:0,top:0,bottom:0,overflow:"hidden",width:"0",display:"none",boxSizing:"border-box",borderRightStyle:"solid",borderRightWidth:this.params.cursorWidth+
|
44 |
+
"px",borderRightColor:this.params.cursorColor}));this.params.waveColor!=this.params.progressColor&&(this.progressCc=this.progressWave.appendChild(document.createElement("canvas")).getContext("2d"))},updateSize:function(){var a=Math.round(this.width/this.params.pixelRatio);this.waveCc.canvas.width=this.width;this.waveCc.canvas.height=this.height;this.style(this.waveCc.canvas,{width:a+"px"});this.style(this.progressWave,{display:"block"});this.progressCc&&(this.progressCc.canvas.width=this.width,this.progressCc.canvas.height=
|
45 |
+
this.height,this.style(this.progressCc.canvas,{width:a+"px"}));this.clearWave()},clearWave:function(){this.waveCc.clearRect(0,0,this.width,this.height);this.progressCc&&this.progressCc.clearRect(0,0,this.width,this.height)},drawBars:function(a,b){if(a[0]instanceof Array){var c=a;if(this.params.splitChannels){this.setHeight(c.length*this.params.height*this.params.pixelRatio);c.forEach(this.drawBars,this);return}a=c[0]}[].some.call(a,function(a){return 0>a})&&(a=[].filter.call(a,function(a,b){return 0==
|
46 |
+
b%2}));var d=.5/this.params.pixelRatio,e=this.width,c=this.params.height*this.params.pixelRatio,f=c*b||0,g=c/2,c=a.length,l=this.params.barWidth*this.params.pixelRatio,k=l+Math.max(this.params.pixelRatio,~~(l/2)),h=1;this.params.normalize&&(h=Math.max.apply(Math,a));var m=c/e;this.waveCc.fillStyle=this.params.waveColor;this.progressCc&&(this.progressCc.fillStyle=this.params.progressColor);[this.waveCc,this.progressCc].forEach(function(b){if(b)for(var c=0;c<e;c+=k){var n=Math.round(a[Math.floor(c*
|
47 |
+
m)]/h*g);b.fillRect(c+d,g-n+f,l+d,2*n)}},this)},drawWave:function(a,b){if(a[0]instanceof Array){var c=a;if(this.params.splitChannels){this.setHeight(c.length*this.params.height*this.params.pixelRatio);c.forEach(this.drawWave,this);return}a=c[0]}if(![].some.call(a,function(a){return 0>a})){for(var c=[],d=0,e=a.length;d<e;d++)c[2*d]=a[d],c[2*d+1]=-a[d];a=c}var f=.5/this.params.pixelRatio,c=this.params.height*this.params.pixelRatio,g=c*b||0,l=c/2,k=~~(a.length/2),h=1;this.params.fillParent&&this.width!=
|
48 |
+
k&&(h=this.width/k);var m=1;this.params.normalize&&(c=Math.max.apply(Math,a),d=Math.min.apply(Math,a),m=-d>c?-d:c);this.waveCc.fillStyle=this.params.waveColor;this.progressCc&&(this.progressCc.fillStyle=this.params.progressColor);[this.waveCc,this.progressCc].forEach(function(b){if(b){b.beginPath();b.moveTo(f,l+g);for(var c=0;c<k;c++){var d=Math.round(a[2*c]/m*l);b.lineTo(c*h+f,l-d+g)}for(c=k-1;0<=c;c--)d=Math.round(a[2*c+1]/m*l),b.lineTo(c*h+f,l-d+g);b.closePath();b.fill();b.fillRect(0,l+g-f,this.width,
|
49 |
+
f)}},this)},updateProgress:function(a){this.style(this.progressWave,{width:Math.round(this.width*a)/this.params.pixelRatio+"px"})}});e.Drawer.MultiCanvas=Object.create(e.Drawer);e.util.extend(e.Drawer.MultiCanvas,{initDrawer:function(a){this.maxCanvasWidth=null!=a.maxCanvasWidth?a.maxCanvasWidth:4E3;this.maxCanvasElementWidth=Math.round(this.maxCanvasWidth/this.params.pixelRatio);if(1>=this.maxCanvasWidth)throw"maxCanvasWidth must be greater than 1.";if(1==this.maxCanvasWidth%2)throw"maxCanvasWidth must be an even number.";
|
50 |
+
this.hasProgressCanvas=this.params.waveColor!=this.params.progressColor;this.halfPixel=.5/this.params.pixelRatio;this.canvases=[]},createElements:function(){this.progressWave=this.wrapper.appendChild(this.style(document.createElement("wave"),{position:"absolute",zIndex:2,left:0,top:0,bottom:0,overflow:"hidden",width:"0",display:"none",boxSizing:"border-box",borderRightStyle:"solid",borderRightWidth:this.params.cursorWidth+"px",borderRightColor:this.params.cursorColor}));this.addCanvas()},updateSize:function(){for(var a=
|
51 |
+
Math.ceil(Math.round(this.width/this.params.pixelRatio)/this.maxCanvasElementWidth);this.canvases.length<a;)this.addCanvas();for(;this.canvases.length>a;)this.removeCanvas();for(var b in this.canvases)a=this.maxCanvasWidth+2*Math.ceil(this.params.pixelRatio/2),b==this.canvases.length-1&&(a=this.width-this.maxCanvasWidth*(this.canvases.length-1)),this.updateDimensions(this.canvases[b],a,this.height),this.clearWaveForEntry(this.canvases[b])},addCanvas:function(){var a={},b=this.maxCanvasElementWidth*
|
52 |
+
this.canvases.length;a.wave=this.wrapper.appendChild(this.style(document.createElement("canvas"),{position:"absolute",zIndex:1,left:b+"px",top:0,bottom:0}));a.waveCtx=a.wave.getContext("2d");this.hasProgressCanvas&&(a.progress=this.progressWave.appendChild(this.style(document.createElement("canvas"),{position:"absolute",left:b+"px",top:0,bottom:0})),a.progressCtx=a.progress.getContext("2d"));this.canvases.push(a)},removeCanvas:function(){var a=this.canvases.pop();a.wave.parentElement.removeChild(a.wave);
|
53 |
+
this.hasProgressCanvas&&a.progress.parentElement.removeChild(a.progress)},updateDimensions:function(a,b,c){var d=Math.round(b/this.params.pixelRatio);a.waveCtx.canvas.width=b;a.waveCtx.canvas.height=c;this.style(a.waveCtx.canvas,{width:d+"px"});this.style(this.progressWave,{display:"block"});this.hasProgressCanvas&&(a.progressCtx.canvas.width=b,a.progressCtx.canvas.height=c,this.style(a.progressCtx.canvas,{width:d+"px"}))},clearWave:function(){for(var a in this.canvases)this.clearWaveForEntry(this.canvases[a])},
|
54 |
+
clearWaveForEntry:function(a){a.waveCtx.clearRect(0,0,a.waveCtx.canvas.width,a.waveCtx.canvas.height);this.hasProgressCanvas&&a.progressCtx.clearRect(0,0,a.progressCtx.canvas.width,a.progressCtx.canvas.height)},drawBars:function(a,b){if(a[0]instanceof Array){var c=a;if(this.params.splitChannels){this.setHeight(c.length*this.params.height*this.params.pixelRatio);c.forEach(this.drawBars,this);return}a=c[0]}[].some.call(a,function(a){return 0>a})&&(a=[].filter.call(a,function(a,b){return 0==b%2}));var c=
|
55 |
+
this.width,d=this.params.height*this.params.pixelRatio,p=d*b||0,d=d/2,f=a.length,g=this.params.barWidth*this.params.pixelRatio,l=g+Math.max(this.params.pixelRatio,~~(g/2)),k=1;this.params.normalize&&(k=e.util.max(a));f/=c;this.canvases[0].waveCtx.fillStyle=this.params.waveColor;this.canvases[0].progressCtx&&(this.canvases[0].progressCtx.fillStyle=this.params.progressColor);for(var h=0;h<c;h+=l){var m=Math.round(a[Math.floor(h*f)]/k*d);this.fillRect(h+this.halfPixel,d-m+p,g+this.halfPixel,2*m)}},drawWave:function(a,
|
56 |
+
b){if(a[0]instanceof Array){var c=a;if(this.params.splitChannels){this.setHeight(c.length*this.params.height*this.params.pixelRatio);c.forEach(this.drawWave,this);return}a=c[0]}if(![].some.call(a,function(a){return 0>a})){for(var c=[],d=0,p=a.length;d<p;d++)c[2*d]=a[d],c[2*d+1]=-a[d];a=c}var d=this.params.height*this.params.pixelRatio,c=d*b||0,d=d/2,p=~~(a.length/this.canvases.length/2),f=1;if(this.params.normalize)var f=e.util.max(a),g=e.util.min(a),f=-g>f?-g:f;this.drawLine(p,a,f,d,c);this.fillRect(0,
|
57 |
+
d+c-this.halfPixel,this.width,this.halfPixel)},drawLine:function(a,b,c,d,e){for(var f in this.canvases){var g=this.canvases[f];this.setFillStyles(g);this.drawLineToContext(g.waveCtx,a,f,b,c,d,e);this.drawLineToContext(g.progressCtx,a,f,b,c,d,e)}},drawLineToContext:function(a,b,c,d,e,f,g){if(a){var l=1;this.params.fillParent&&this.width!=b&&(l=a.canvas.width/b);c*=b;b=c+b+1;a.beginPath();a.moveTo(this.halfPixel,f+g);for(var k=c;k<b;k++){var h=Math.round(d[2*k]/e*f);a.lineTo((k-c)*l+this.halfPixel,
|
58 |
+
f-h+g)}for(k=b-1;k>=c;k--)h=Math.round(d[2*k+1]/e*f),a.lineTo((k-c)*l+this.halfPixel,f-h+g);a.closePath();a.fill()}},fillRect:function(a,b,c,d){for(var e in this.canvases){var f=this.canvases[e],g=e*this.maxCanvasWidth,l=Math.max(a,e*this.maxCanvasWidth),k=b,h=Math.min(a+c,e*this.maxCanvasWidth+f.waveCtx.canvas.width),m=b+d;l<h&&(this.setFillStyles(f),this.fillRectToContext(f.waveCtx,l-g,k,h-l,m-k),this.fillRectToContext(f.progressCtx,l-g,k,h-l,m-k))}},fillRectToContext:function(a,b,c,d,e){a&&a.fillRect(b,
|
59 |
+
c,d,e)},setFillStyles:function(a){a.waveCtx.fillStyle=this.params.waveColor;this.hasProgressCanvas&&(a.progressCtx.fillStyle=this.params.progressColor)},updateProgress:function(a){this.style(this.progressWave,{width:Math.round(this.width*a)/this.params.pixelRatio+"px"})}});(function(){var a=function(){var a=document.querySelectorAll("wavesurfer");Array.prototype.forEach.call(a,function(a){var b=e.util.extend({container:a,backend:"MediaElement",mediaControls:!0},a.dataset);a.style.display="block";
|
60 |
+
b=e.create(b);if(a.dataset.peaks)var p=JSON.parse(a.dataset.peaks);b.load(a.dataset.url,p)})};"complete"===document.readyState?a():window.addEventListener("load",a)})();return e});
|
changelog.txt
ADDED
@@ -0,0 +1,494 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
= 1.8.24 =
|
2 |
+
* Fixed: Screen Settings on pages
|
3 |
+
* Fixed: Preview of changed module
|
4 |
+
* Fixed: Google Maps JS error in admin on some installations
|
5 |
+
|
6 |
+
= 1.8.23 =
|
7 |
+
* Fixed: If gallery source is album, then set order from album (with ability to overwrite by query parameter)
|
8 |
+
|
9 |
+
= 1.8.22 =
|
10 |
+
* Fixed: Quick Galleries items order
|
11 |
+
|
12 |
+
= 1.8.21 =
|
13 |
+
* Fixed: Fatal Error on album sort
|
14 |
+
|
15 |
+
= 1.8.20 =
|
16 |
+
* Compatibility with WP 4.5
|
17 |
+
* Changed: Removed Custom Filters
|
18 |
+
* Changed: Taxonomies are now separate pages (Albums, Categories, Tags)
|
19 |
+
* Changed: Galleries are now have query builder (like in custom filters) to make custom queries
|
20 |
+
* Improved: Gallery Preview now resizable
|
21 |
+
* Improved: Isolation Mode
|
22 |
+
* Added: Custom Fields to Galleries
|
23 |
+
* Added: Settings for default albums 'status', 'order', 'orderby'
|
24 |
+
* Added: Setting for Default Module
|
25 |
+
* Added: 'category__and' query parameter
|
26 |
+
* Fixed: bugfixes
|
27 |
+
* Code refactoring and other improvements
|
28 |
+
|
29 |
+
= 1.8.14 =
|
30 |
+
* Fixed: Multiple categories in Edit Mode
|
31 |
+
|
32 |
+
= 1.8.12 =
|
33 |
+
* New: Ability to create own categories
|
34 |
+
* New: Ability to assign few categories to one item
|
35 |
+
* New: Ability to assign categories to non images
|
36 |
+
* Added: New capability for managing categories
|
37 |
+
|
38 |
+
= 1.8.10 =
|
39 |
+
* Added: Stack for Gmedia Items
|
40 |
+
* New: Selected items now cleared automatically after Action
|
41 |
+
* Changed: Numeric title from EXIF will be saved to DB
|
42 |
+
|
43 |
+
= 1.8.08 =
|
44 |
+
* Improved Phantom module
|
45 |
+
* Improved installations of modules
|
46 |
+
* Fixed Install module ZIP
|
47 |
+
* Fixed loading comments on some themes
|
48 |
+
* Removed Font-Awesome from GmediaCloud page to improve loading speed
|
49 |
+
|
50 |
+
= 1.8.07 =
|
51 |
+
* Fixed: Modules update
|
52 |
+
* Updated: Phantom module (fixed few settings)
|
53 |
+
|
54 |
+
= 1.8.06 =
|
55 |
+
* Fixed: Notice on first install
|
56 |
+
* Fixed: Ignored uninstall settings and plugin doesn't delete database records and delete all files
|
57 |
+
|
58 |
+
= 1.8.05 =
|
59 |
+
* Improved: update process
|
60 |
+
* Fixed: access point for iOS app
|
61 |
+
* Fixed: comments in Phantom module not worked on some themes
|
62 |
+
|
63 |
+
= 1.8.0 =
|
64 |
+
* Added: Comments for Gmedia Items
|
65 |
+
* Added: WP search integration for gmedia items, albums, galleries, filters
|
66 |
+
* New: Phantom module with comments support
|
67 |
+
* Fixed: gallery search in admin and a lot of other bugs that I don't remember
|
68 |
+
|
69 |
+
= 1.7.56 =
|
70 |
+
* Fixed: error "jQuery is not defined" on some themes
|
71 |
+
|
72 |
+
= 1.7.55 =
|
73 |
+
* Fixed: ajax requests required login
|
74 |
+
* Fixed: error in class.processor.php file
|
75 |
+
* Fixed: CSS conflict for forms
|
76 |
+
|
77 |
+
= 1.7.53 =
|
78 |
+
* Fixed: Import from WP Media Library
|
79 |
+
* Fixed: Image Editor
|
80 |
+
* Fixed: Create Album in Edit mode
|
81 |
+
|
82 |
+
= 1.7.52 =
|
83 |
+
* Fixed: Custom Filter in Gmedia Library
|
84 |
+
* Fixed: Limit field in Custom Filter now works properly (require re-save Custom Filter)
|
85 |
+
* Fixed: Filter with "No Album" and Uncategorised items
|
86 |
+
|
87 |
+
= 1.7.51 =
|
88 |
+
* Fixed: View/Like counter in flash modules
|
89 |
+
|
90 |
+
= 1.7.50 =
|
91 |
+
* Fixed: JS error in Library if user have no Terms capability
|
92 |
+
* Fixed: Views and Likes not count on some themes (400 error)
|
93 |
+
* Fixed: Error when file have no metadata (exif info)
|
94 |
+
* Other small fixes, new bugs and improvements
|
95 |
+
|
96 |
+
= 1.7.40 =
|
97 |
+
* Added: Grid View in Gmedia Library
|
98 |
+
* Fixed: Sorting by Title and by Date in Gmedia Library
|
99 |
+
* Added: Download link for modules
|
100 |
+
|
101 |
+
= 1.7.30 =
|
102 |
+
* Fixed: error T_PAAMAYIM_NEKUDOTAYIM
|
103 |
+
* Fixed: Compatibility with PHP 5.2
|
104 |
+
* Updated: Music Player
|
105 |
+
|
106 |
+
= 1.7.21 =
|
107 |
+
* Fixed: Import function
|
108 |
+
* Fixed: Error when image have no orientation in EXIF
|
109 |
+
|
110 |
+
= 1.7.20 =
|
111 |
+
* Added: Autorotate images based on Exif information
|
112 |
+
* Added: MP3 Title and Album from ID3Tag
|
113 |
+
* Added: Using PEL library save EXIF to Web image files
|
114 |
+
* Improved: Image Editor
|
115 |
+
* Improved: List header is now fixed while scrolling
|
116 |
+
* Other small fixes and improvements
|
117 |
+
|
118 |
+
= 1.7.10 =
|
119 |
+
* Added: Filter icons on Albums page and other terms pages
|
120 |
+
* Added: Open GmediaCloud page icon from Galleries page
|
121 |
+
* Added: Search geocode by address on map
|
122 |
+
* Improved: GmediaCloud meta tags
|
123 |
+
* Improved: Functions for iOS app
|
124 |
+
* Changed: GPS location field now editable
|
125 |
+
|
126 |
+
= 1.7.9 =
|
127 |
+
* Fixed: GmediaCloud page not worked
|
128 |
+
* Fixed: Compatibility with Jetpack plugin
|
129 |
+
|
130 |
+
= 1.7.8 =
|
131 |
+
* Fixed: Update error on some servers
|
132 |
+
|
133 |
+
= 1.7.7 =
|
134 |
+
* Added: Geolocation for photos and videos
|
135 |
+
* Added: url query params for shortcode in page
|
136 |
+
* Fixed: Image edit on multisite
|
137 |
+
* Updated: Photomania module
|
138 |
+
* Improved: Exif information
|
139 |
+
* Small fixes and improvements
|
140 |
+
|
141 |
+
= 1.7.6 =
|
142 |
+
* Added: New option called Limit in Custom Filter
|
143 |
+
* Added: Custom Filter collections in Add Media window
|
144 |
+
* Added: Feature to load any term to page gallery with url parameters
|
145 |
+
* Added: Twitter widget with latest news in admin
|
146 |
+
* Updated: Afflux module, Music Player module, Minima module, PhotoMania module, Video Player module
|
147 |
+
* Fixed: Gallery preview in admin not worked with https
|
148 |
+
* Fixed: GmediaCloud page for single item
|
149 |
+
* Changed: Plugin text domain to 'grand-media'
|
150 |
+
* Small fixes and improvements
|
151 |
+
|
152 |
+
= 1.7.4 =
|
153 |
+
* Added: German translate
|
154 |
+
* Added: Dutch translate
|
155 |
+
* Updated: Phantom module
|
156 |
+
|
157 |
+
= 1.7.3 =
|
158 |
+
* Fixed: Update error on some websites
|
159 |
+
* Fixed: Check if imported gallery title only numbers
|
160 |
+
* Updated: Phantom module
|
161 |
+
* Small fixes and improvements
|
162 |
+
|
163 |
+
= 1.7.2 =
|
164 |
+
* Fixed: Image Editor not worked on websites with hyphens
|
165 |
+
|
166 |
+
= 1.7.1 =
|
167 |
+
* Added: settings to enable/disable debug mode
|
168 |
+
* Added: Ukrainian translation
|
169 |
+
* Updated: jPlayer library
|
170 |
+
* Updated: Music Player module
|
171 |
+
* Updated: Phantom module
|
172 |
+
* Changed: disabled music cover from mp3 metainfo (required a lot of memory)
|
173 |
+
* Small fixes and improvements
|
174 |
+
|
175 |
+
= 1.7.0 =
|
176 |
+
* Fixed: compatibility with WPMobile App plugin
|
177 |
+
* Fixed: Music Player
|
178 |
+
* Fixed: Video Player
|
179 |
+
* Added: Help tab for Settings page
|
180 |
+
* Added: Support us block
|
181 |
+
|
182 |
+
= 1.6.9 =
|
183 |
+
* Fixed: Album custom sorting
|
184 |
+
|
185 |
+
= 1.6.8 =
|
186 |
+
* New: PhotoMania Module - free cool gallery module
|
187 |
+
* Changed: All Albums on Add Files page
|
188 |
+
* Fixed GmediaCloud page for Filters (if 404 page go to WP Settings -> Permalinks -> re-Save settings)
|
189 |
+
* Other improvements
|
190 |
+
|
191 |
+
= 1.6.7 =
|
192 |
+
* Added Cover for Albums
|
193 |
+
* Updated Music Player and Video Player modules to support Album Covers
|
194 |
+
* Fixed small bugs
|
195 |
+
|
196 |
+
= 1.6.6 =
|
197 |
+
* Fixed compatibility with iOS application
|
198 |
+
|
199 |
+
= 1.6.5 =
|
200 |
+
* Fixed vulnerabilities
|
201 |
+
* Added Custom fields to Albums
|
202 |
+
* Added option to hide social buttons for GmediaCloud page
|
203 |
+
|
204 |
+
= 1.6.4 =
|
205 |
+
* Fixed links for delete, upload and others
|
206 |
+
|
207 |
+
= 1.6.3 =
|
208 |
+
* Added Custom Fields for Gmedia Items
|
209 |
+
* Added Batch File Rename
|
210 |
+
* Fixed bug for HTTPS websites
|
211 |
+
* Small fixes and improvements
|
212 |
+
|
213 |
+
= 1.6.1 =
|
214 |
+
* Fixed: Edit Mode loose items album
|
215 |
+
|
216 |
+
= 1.6.0 =
|
217 |
+
* Added Custom Filters - Custom Query Builder for Gmedia Library!!!
|
218 |
+
* Small fixes and improvements
|
219 |
+
|
220 |
+
= 1.5.91 =
|
221 |
+
* Fixed compatibility with PHP v5.2
|
222 |
+
* Small fixes and improvements
|
223 |
+
|
224 |
+
= 1.5.9 =
|
225 |
+
* Fixed Batch Edit -> Custom Link
|
226 |
+
* Added sitemap integration with WP SEO by Yoast plugin
|
227 |
+
* Small fixes and improvements
|
228 |
+
|
229 |
+
= 1.5.8 =
|
230 |
+
* Fixed Upload and Import now works with .htaccess which deny *.php direct access in wp-content folder
|
231 |
+
* Improved Album Sorting
|
232 |
+
* Added settings for default gmedia sorting in tags and categories (in modules)
|
233 |
+
* Added Screen Options for Galleries, Albums, Tags. Now you can sort terms in way you need on admin pages
|
234 |
+
* Added option to sort gmedia by filename
|
235 |
+
* Added "Views / Likes" (and ratings for audio) meta information to Gmedia Library
|
236 |
+
* Added setting to add own CSS to GmediaCloud page
|
237 |
+
* Small fixes and improvements
|
238 |
+
|
239 |
+
= 1.5.7 =
|
240 |
+
* New Mosaic Gallery Module
|
241 |
+
* Fixed javascript error on Gmedia Edit Gallery page
|
242 |
+
* Fixed generating json settings for some modules
|
243 |
+
* Fixed GmediaCloud json module settings
|
244 |
+
* Fixed: iOS application loads images without status
|
245 |
+
* Added Home and Back menu buttons to GmediaCloud pages
|
246 |
+
* Small fixes and improvements
|
247 |
+
|
248 |
+
= 1.5.6 =
|
249 |
+
* Added Settings option to change module for GmediaCloud Page
|
250 |
+
* Added Settings option to add analytics code for GmediaCloud Page
|
251 |
+
* Added Social Share buttons to GmediaCloud Page
|
252 |
+
* Fixed: iOS application loads images without status
|
253 |
+
* Small fixes and improvements
|
254 |
+
|
255 |
+
= 1.5.5 =
|
256 |
+
* Added Import IPTC Keywords to image tags
|
257 |
+
* Fixed deleting tags from selected items in Gmedia Library
|
258 |
+
* Fixed tags search while typing in combobox
|
259 |
+
* Modals with forms inside now not closing on keyboard Esc
|
260 |
+
* Small fixes and improvements
|
261 |
+
|
262 |
+
= 1.5.4 =
|
263 |
+
* Fixed RealSlider not playing selfhosted video (Update RealSlider to latest version too)
|
264 |
+
* Small fixes and improvements
|
265 |
+
|
266 |
+
= 1.5.3 =
|
267 |
+
* Fixed PhotoBox module not working
|
268 |
+
* Fixed VideoPlayer module not working
|
269 |
+
* Improved flush_rewrite_rules when plugin update
|
270 |
+
* Improved GmediaCloud Template Page
|
271 |
+
|
272 |
+
= 1.5.1 =
|
273 |
+
* Fixed css not loading for modules
|
274 |
+
|
275 |
+
= 1.5.0 =
|
276 |
+
* Changed permalinks for Gmedia pages
|
277 |
+
* Added Templates for Full Page Galleries and Single Template Page
|
278 |
+
* Added "Share GmediaCloud Page" option for items in Library, terms and galleries
|
279 |
+
* Added options for changing gmedia permalink base and salt for creating unique urls
|
280 |
+
* Added actions icons for albums, tags and galleries
|
281 |
+
* Added Meta Info popup for Library items
|
282 |
+
* Added Terms search by term ID (enter # before numbers separated by comma)
|
283 |
+
* Fixed Albums with deleted authors
|
284 |
+
* Admin CSS improvemens
|
285 |
+
|
286 |
+
= 1.4.2 =
|
287 |
+
* Fixed music and video Custom Cover when image url is set instead of ID
|
288 |
+
* Fixed View Original link on Gmedia Library page
|
289 |
+
* Added option to add Gmedia button on custom posts
|
290 |
+
* Added option to add image Exif data to image description via Batch Edit
|
291 |
+
* If mp3 have ID3Tag image cover in it, this image shows automatically. (You need update metadata for music files)
|
292 |
+
* Small changes on Gmedia Library page
|
293 |
+
* Small CSS changes on admin pages
|
294 |
+
* Music player module updated to new version
|
295 |
+
|
296 |
+
= 1.4.1 =
|
297 |
+
* New: Gmedia iOS application for managing Library with your iPhone
|
298 |
+
* Fixed Gmedia Mobile Application admin page.
|
299 |
+
|
300 |
+
= 1.4.0 =
|
301 |
+
* New: Gmedia iOS application for managing Library with your iPhone
|
302 |
+
* Fixed error getting xml on Modules page
|
303 |
+
* Small fixes and improvements
|
304 |
+
|
305 |
+
= 1.3.7 =
|
306 |
+
* Fixed css on Modules page
|
307 |
+
|
308 |
+
= 1.3.6 =
|
309 |
+
* Fixed galleries to work in force SSL mode
|
310 |
+
* Added new option to Settings: Isolate Gmedia admin pages from other plugins to avoid conflicts
|
311 |
+
* Updated Bootstrap to version 3.3.1
|
312 |
+
|
313 |
+
= 1.3.5 =
|
314 |
+
* Added ability to generate gallery shortcode from collections. Just choose term, then choose module with preset and click Insert.
|
315 |
+
* Now you can show album, tag or category on fronted without creating gallery.
|
316 |
+
|
317 |
+
= 1.3.4 =
|
318 |
+
* Added Module Presets
|
319 |
+
* Added Module Default Preset
|
320 |
+
* Fixed compatibility with Wordpress MU
|
321 |
+
|
322 |
+
= 1.3.2 =
|
323 |
+
* Added French language
|
324 |
+
* Added option to Batch Edit for Description: 'replace', 'append', 'prepend'
|
325 |
+
* Added auth_redirect() function to avoid error when login session expire
|
326 |
+
|
327 |
+
= 1.3.1 =
|
328 |
+
* Added Serbian language
|
329 |
+
* Fix for roles and save album
|
330 |
+
* Fix for import files
|
331 |
+
|
332 |
+
= 1.3.0 =
|
333 |
+
* Add Set Post Featured Image
|
334 |
+
* Add Upload from Edit Post
|
335 |
+
* Change/Improve process of Gallery's Shortcode Insert
|
336 |
+
* Improve multiuser experience (Roles and Capabilities)
|
337 |
+
* Improve upload security
|
338 |
+
|
339 |
+
= 1.2.6 =
|
340 |
+
* Disable PHP error reporting on update.php file
|
341 |
+
|
342 |
+
= 1.2.5 =
|
343 |
+
* Improved "edit status" for albums and gmedia items
|
344 |
+
* New options on upload form
|
345 |
+
* Different colors depended on item status
|
346 |
+
* Fixed preview template
|
347 |
+
* Check PHP Memory Limit on update images
|
348 |
+
|
349 |
+
= 1.2.4 =
|
350 |
+
* Compatibility with WP 4.0
|
351 |
+
* Added status for gmedia files (public, private)
|
352 |
+
* Added status for albums (public, private, draft)
|
353 |
+
* Fixed compatibility with Lazy load (unveil.js) plugin and alternative gallery
|
354 |
+
* Added icon to assets
|
355 |
+
|
356 |
+
= 1.2.3 =
|
357 |
+
* Added Batch Edit in Gmedia Library
|
358 |
+
* Fixed bugs with multiauthor usage
|
359 |
+
* Fixed update from old versions
|
360 |
+
* Fixed compatibility with Visual Composer plugin
|
361 |
+
|
362 |
+
= 1.2.2 =
|
363 |
+
* Fixed Music Player in Chrome > v35
|
364 |
+
* Updated jPlayer script
|
365 |
+
* Updated Plupload script
|
366 |
+
* Forbid upload dangerous files via uploader
|
367 |
+
* Allowed to choose albums without author for Galleries
|
368 |
+
|
369 |
+
= 1.2.1 =
|
370 |
+
* Fixed galleries meta box on Posts and Pages
|
371 |
+
* Fixed check capabilities on some admin pages
|
372 |
+
* Fixed after plugin install not administrators can't access WP Dashboard
|
373 |
+
|
374 |
+
= 1.2.0 =
|
375 |
+
* Major update: Added User Role Manager
|
376 |
+
* Added Filter by Author
|
377 |
+
* Added Screen Option on Edit Mode to enable/disable quicktags panel for image description
|
378 |
+
* Improvements for touch screens
|
379 |
+
* Added quick actions for single media
|
380 |
+
* Added pager to gmedia list footer
|
381 |
+
* Added option to leave data when uninstall plugin
|
382 |
+
* Fixed PHP notices and warnings on some operations
|
383 |
+
|
384 |
+
= 1.1.3 =
|
385 |
+
* Fixed Music Player module
|
386 |
+
|
387 |
+
= 1.1.2 =
|
388 |
+
* Added search media by ID (just type # bedore digit in search field)
|
389 |
+
* Added search in Edit Mode
|
390 |
+
* Improved Preview gallery template for latest module
|
391 |
+
* Updated Phantom Module
|
392 |
+
|
393 |
+
= 1.1.1 =
|
394 |
+
* Fixed Gallery Preview
|
395 |
+
|
396 |
+
= 1.1.0 =
|
397 |
+
* Fixed Gmedia permalinks
|
398 |
+
* Gallery reset button now not showing if there is no changes
|
399 |
+
* Added option to update media metadata in database
|
400 |
+
* Removed Edit Image link from non images
|
401 |
+
* Improved Gmedia Preview Template
|
402 |
+
* Improved code for gallery settings
|
403 |
+
* Improved code for shortcodes
|
404 |
+
* Updated modules
|
405 |
+
* Small fixes and improvements
|
406 |
+
|
407 |
+
= 1.0.0 =
|
408 |
+
* Clean plugin code
|
409 |
+
* Improve image sorting in Albums
|
410 |
+
* Added permalinks for galleries
|
411 |
+
* Fixed Import errors and warnings
|
412 |
+
* Fixed compatibility with iTheme Security (Better Security) plugin
|
413 |
+
* Fix Music Player - force download button if link ends with .mp3 or .ogg
|
414 |
+
* Added Video Player with playlist
|
415 |
+
|
416 |
+
= 0.9.23 =
|
417 |
+
* Add setting to "no format" shortcode's content
|
418 |
+
* Update all modules
|
419 |
+
* Added manual height option to gallery modules
|
420 |
+
|
421 |
+
= 0.9.22 =
|
422 |
+
* Update jPlayer library to latest version
|
423 |
+
* Fix multiple Music Player instances on one page
|
424 |
+
|
425 |
+
= 0.9.21 =
|
426 |
+
* Fix Minima module
|
427 |
+
|
428 |
+
= 0.9.20 =
|
429 |
+
* Fix search in Gmedia Library
|
430 |
+
* Fix settings update with empty license key
|
431 |
+
* Added photoswipe js library
|
432 |
+
* Fix config for servers with renamed 'wp-content' folder
|
433 |
+
* Fix gallery preview theme warnings
|
434 |
+
* SEO optimisations for modules
|
435 |
+
* Fix modules for ajax themes
|
436 |
+
* Update all modules
|
437 |
+
|
438 |
+
= 0.9.16 =
|
439 |
+
* Added Image Editor (Rotate, Flip, Greyscale, Invert and 9 Filters + Restore Original Uploaded Image)
|
440 |
+
* If selected media and go to Edit Mode, then load only selected items
|
441 |
+
* Fixed error if no Exif module installed in PHP
|
442 |
+
* Update Modified date when Edit Gmedia
|
443 |
+
* Thickbox replaced with bootstrap modal
|
444 |
+
* Fixed Create and assign new Album in Gmedia Library
|
445 |
+
* Fixed Module settings checkbox not saved
|
446 |
+
|
447 |
+
= 0.9.15 =
|
448 |
+
* Fixed Import from NextGen plugin
|
449 |
+
|
450 |
+
= 0.9.14 =
|
451 |
+
* Added "Create Quick Gallery"
|
452 |
+
* Added gallery source - Gmedia IDs
|
453 |
+
* Improved assign albums
|
454 |
+
* Improved assign tags
|
455 |
+
* Improved delete tags
|
456 |
+
* Fixed assign no album
|
457 |
+
* Fixed assign no category
|
458 |
+
|
459 |
+
= 0.9.13 =
|
460 |
+
* Fix for Gallery source order not saved
|
461 |
+
* Add drag and drop to sort gallery source
|
462 |
+
* Add color picker for gallery colors settings
|
463 |
+
* Delete tags in selected items action now show only tags from selected items
|
464 |
+
* Fix gmedia item description not save multiline
|
465 |
+
* Small fixes and improvements
|
466 |
+
|
467 |
+
= 0.9.12 =
|
468 |
+
* Fix Import from Flagallery plugin
|
469 |
+
* Fix update settings with empty key
|
470 |
+
* Fix PHP Notices
|
471 |
+
* Fix uninstall function
|
472 |
+
|
473 |
+
= 0.9.11 =
|
474 |
+
* Improved plugin Update and Import functions
|
475 |
+
* Updated Minima, Afflux, Optima, Slider modules
|
476 |
+
|
477 |
+
= 0.9.10 =
|
478 |
+
* Fixed Phantom Module
|
479 |
+
|
480 |
+
= 0.9.9 =
|
481 |
+
* Fixed styles for FireFox and IE
|
482 |
+
* In Library Edit Mode images and music now opens in thickbox
|
483 |
+
|
484 |
+
= 0.9.8 =
|
485 |
+
* Fixed Gallery Delete action
|
486 |
+
|
487 |
+
= 0.9.7 =
|
488 |
+
* Added ability to edit broken galleries
|
489 |
+
|
490 |
+
= 0.9.6 =
|
491 |
+
* Whole new design
|
492 |
+
* Plugin was rewrited from scratch
|
493 |
+
* More intuitive interface
|
494 |
+
* Backup before updating. After update plugin go to Manage Modules page and update modules to latest versions. Then check your galleries.
|
config/setup.php
CHANGED
@@ -1,31 +1,38 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Setup Gmedia plugin
|
4 |
*/
|
5 |
|
6 |
/**
|
7 |
* Setup the default option array for the plugin
|
8 |
-
*
|
9 |
* @access internal
|
10 |
* @return array
|
11 |
*/
|
12 |
-
function gmedia_default_options()
|
13 |
|
14 |
$gm['site_email'] = '';
|
15 |
$gm['site_ID'] = '';
|
16 |
$gm['site_title'] = '';
|
17 |
$gm['site_description'] = '';
|
18 |
-
$gm['mobile_app'] =
|
19 |
|
20 |
$gm['gmedia_post_slug'] = 'gmedia';
|
21 |
$gm['gmedia_exclude_from_search'] = '0';
|
|
|
22 |
$gm['default_gmedia_comment_status'] = 'open'; // can be 'closed', 'open'
|
23 |
|
24 |
$gm['gmedia_album_post_slug'] = 'gmedia-album';
|
|
|
25 |
$gm['gmedia_album_exclude_from_search'] = '0';
|
26 |
|
27 |
$gm['gmedia_gallery_post_slug'] = 'gmedia-gallery';
|
|
|
28 |
$gm['gmedia_gallery_exclude_from_search'] = '0';
|
|
|
29 |
|
30 |
$gm['default_gmedia_term_comment_status'] = 'closed'; // can be 'closed', 'open'
|
31 |
|
@@ -65,6 +72,7 @@ function gmedia_default_options() {
|
|
65 |
|
66 |
$gm['modules_xml'] = 'https://dl.dropboxusercontent.com/u/6295502/gmedia_modules/modules_v1.xml';
|
67 |
$gm['license_name'] = '';
|
|
|
68 |
$gm['license_key'] = '';
|
69 |
$gm['license_key2'] = '';
|
70 |
|
@@ -82,14 +90,24 @@ function gmedia_default_options() {
|
|
82 |
$gm['gm_screen_options']['sortorder_gmedia'] = 'DESC';
|
83 |
$gm['gm_screen_options']['display_mode_gmedia'] = 'list';
|
84 |
$gm['gm_screen_options']['grid_cell_fit_gmedia'] = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
-
$gm['gm_screen_options']['
|
87 |
-
$gm['gm_screen_options']['
|
88 |
-
$gm['gm_screen_options']['
|
89 |
|
90 |
-
$gm['gm_screen_options']['
|
91 |
-
$gm['gm_screen_options']['
|
92 |
-
$gm['gm_screen_options']['
|
|
|
|
|
|
|
|
|
93 |
|
94 |
$gm['gm_screen_options']['per_page_wpmedia'] = 30;
|
95 |
$gm['gm_screen_options']['orderby_wpmedia'] = 'ID';
|
@@ -109,19 +127,19 @@ function gmedia_default_options() {
|
|
109 |
/**
|
110 |
* sets gmedia capabilities to administrator role
|
111 |
**/
|
112 |
-
function gmedia_capabilities()
|
113 |
global $gmCore;
|
114 |
// Set the capabilities for the administrator
|
115 |
$role = get_role('administrator');
|
116 |
// We need this role, no other chance
|
117 |
-
if(empty($role))
|
118 |
update_option("gmediaInitCheck", __('Sorry, Gmedia Gallery works only with a role called administrator', 'grand-media'));
|
119 |
|
120 |
return;
|
121 |
}
|
122 |
$capabilities = $gmCore->plugin_capabilities();
|
123 |
$capabilities = apply_filters('gmedia_capabilities', $capabilities);
|
124 |
-
foreach($capabilities as $cap)
|
125 |
$role->add_cap($cap);
|
126 |
}
|
127 |
}
|
@@ -129,16 +147,15 @@ function gmedia_capabilities() {
|
|
129 |
/**
|
130 |
* creates all tables for the plugin
|
131 |
* called during register_activation hook
|
132 |
-
*
|
133 |
* @access internal
|
134 |
* @return void
|
135 |
**/
|
136 |
-
function gmedia_install()
|
137 |
/** @var $wpdb wpdb */
|
138 |
global $wpdb, $gmGallery, $gmCore;
|
139 |
|
140 |
// Check for capability
|
141 |
-
if(!current_user_can('activate_plugins'))
|
142 |
return;
|
143 |
}
|
144 |
|
@@ -150,14 +167,15 @@ function gmedia_install() {
|
|
150 |
// add charset & collate like wp core
|
151 |
$charset_collate = '';
|
152 |
|
153 |
-
if($wpdb->has_cap('collation'))
|
154 |
-
if(!empty($wpdb->charset))
|
155 |
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
156 |
}
|
157 |
-
if(!empty($wpdb->collate))
|
158 |
$charset_collate .= " COLLATE $wpdb->collate";
|
159 |
}
|
160 |
}
|
|
|
161 |
|
162 |
$gmedia = $wpdb->prefix . 'gmedia';
|
163 |
$gmedia_meta = $wpdb->prefix . 'gmedia_meta';
|
@@ -165,8 +183,9 @@ function gmedia_install() {
|
|
165 |
$gmedia_term_meta = $wpdb->prefix . 'gmedia_term_meta';
|
166 |
$gmedia_term_relationships = $wpdb->prefix . 'gmedia_term_relationships';
|
167 |
|
168 |
-
if($wpdb->get_var("show tables like '$gmedia'") != $gmedia)
|
169 |
-
$sql = "
|
|
|
170 |
ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
171 |
author BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
172 |
date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
|
@@ -187,21 +206,24 @@ function gmedia_install() {
|
|
187 |
dbDelta($sql);
|
188 |
}
|
189 |
|
190 |
-
if($wpdb->get_var("show tables like '$gmedia_meta'") != $gmedia_meta)
|
191 |
-
$sql = "
|
|
|
192 |
meta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
193 |
gmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
194 |
meta_key VARCHAR(255) DEFAULT NULL,
|
195 |
meta_value LONGTEXT,
|
196 |
PRIMARY KEY (meta_id),
|
197 |
KEY gmedia_id (gmedia_id),
|
198 |
-
KEY meta_key (meta_key)
|
|
|
199 |
) {$charset_collate}";
|
200 |
dbDelta($sql);
|
201 |
}
|
202 |
|
203 |
-
if($wpdb->get_var("show tables like '$gmedia_term'") != $gmedia_term)
|
204 |
-
$sql = "
|
|
|
205 |
term_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
206 |
name VARCHAR(200) NOT NULL DEFAULT '',
|
207 |
taxonomy VARCHAR(32) NOT NULL DEFAULT '',
|
@@ -216,8 +238,9 @@ function gmedia_install() {
|
|
216 |
dbDelta($sql);
|
217 |
}
|
218 |
|
219 |
-
if($wpdb->get_var("show tables like '$gmedia_term_meta'") != $gmedia_term_meta)
|
220 |
-
$sql = "
|
|
|
221 |
meta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
222 |
gmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
223 |
meta_key VARCHAR(255) DEFAULT NULL,
|
@@ -229,8 +252,9 @@ function gmedia_install() {
|
|
229 |
dbDelta($sql);
|
230 |
}
|
231 |
|
232 |
-
if($wpdb->get_var("show tables like '$gmedia_term_relationships'") != $gmedia_term_relationships)
|
233 |
-
$sql = "
|
|
|
234 |
gmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
235 |
gmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
236 |
term_order INT(11) NOT NULL DEFAULT '0',
|
@@ -242,27 +266,27 @@ function gmedia_install() {
|
|
242 |
}
|
243 |
|
244 |
// check one table again, to be sure
|
245 |
-
if($wpdb->get_var("show tables like '$gmedia'") != $gmedia)
|
246 |
update_option("gmediaInitCheck", __('GmediaGallery: Tables could not created, please check your database settings', 'grand-media'));
|
247 |
|
248 |
return;
|
249 |
}
|
250 |
|
251 |
-
if(!get_option('GmediaHashID_salt'))
|
252 |
$ustr = wp_generate_password(12, false);
|
253 |
add_option('GmediaHashID_salt', $ustr);
|
254 |
}
|
255 |
|
256 |
// set the default settings, if we didn't upgrade
|
257 |
-
if(empty($gmGallery->options))
|
258 |
$gmGallery->options = gmedia_default_options();
|
259 |
// Set installation date
|
260 |
-
if(!get_option('gmediaInstallDate'))
|
261 |
$installDate = time();
|
262 |
add_option('gmediaInstallDate', $installDate);
|
263 |
}
|
264 |
update_option('gmediaOptions', $gmGallery->options);
|
265 |
-
} else
|
266 |
$default_options = gmedia_default_options();
|
267 |
unset($gmGallery->options['folder'], $gmGallery->options['taxonomies']);
|
268 |
$new_options = $gmCore->array_diff_key_recursive($default_options, $gmGallery->options);
|
@@ -271,7 +295,7 @@ function gmedia_install() {
|
|
271 |
}
|
272 |
|
273 |
// try to make gallery dirs if not exists
|
274 |
-
foreach($gmGallery->options['folder'] as $folder)
|
275 |
wp_mkdir_p($gmCore->upload['path'] . '/' . $folder);
|
276 |
}
|
277 |
|
@@ -283,18 +307,20 @@ function gmedia_install() {
|
|
283 |
|
284 |
/**
|
285 |
* Called via Setup and register_deactivate hook
|
286 |
-
*
|
287 |
* @access internal
|
288 |
* @return void
|
289 |
*/
|
290 |
-
function gmedia_deactivate()
|
291 |
global $gmCore;
|
292 |
|
293 |
flush_rewrite_rules(false);
|
294 |
|
295 |
wp_clear_scheduled_hook('gmedia_app_cronjob');
|
296 |
|
297 |
-
$
|
|
|
|
|
|
|
298 |
|
299 |
// remove & reset the init check option
|
300 |
delete_option('gmediaInitCheck');
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')){
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Setup Gmedia plugin
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Setup the default option array for the plugin
|
|
|
12 |
* @access internal
|
13 |
* @return array
|
14 |
*/
|
15 |
+
function gmedia_default_options(){
|
16 |
|
17 |
$gm['site_email'] = '';
|
18 |
$gm['site_ID'] = '';
|
19 |
$gm['site_title'] = '';
|
20 |
$gm['site_description'] = '';
|
21 |
+
$gm['mobile_app'] = 0;
|
22 |
|
23 |
$gm['gmedia_post_slug'] = 'gmedia';
|
24 |
$gm['gmedia_exclude_from_search'] = '0';
|
25 |
+
$gm['gmedia_has_archive'] = '1';
|
26 |
$gm['default_gmedia_comment_status'] = 'open'; // can be 'closed', 'open'
|
27 |
|
28 |
$gm['gmedia_album_post_slug'] = 'gmedia-album';
|
29 |
+
$gm['gmedia_album_has_archive'] = '1';
|
30 |
$gm['gmedia_album_exclude_from_search'] = '0';
|
31 |
|
32 |
$gm['gmedia_gallery_post_slug'] = 'gmedia-gallery';
|
33 |
+
$gm['gmedia_gallery_has_archive'] = '0';
|
34 |
$gm['gmedia_gallery_exclude_from_search'] = '0';
|
35 |
+
$gm['preview_bgcolor'] = 'ffffff';
|
36 |
|
37 |
$gm['default_gmedia_term_comment_status'] = 'closed'; // can be 'closed', 'open'
|
38 |
|
72 |
|
73 |
$gm['modules_xml'] = 'https://dl.dropboxusercontent.com/u/6295502/gmedia_modules/modules_v1.xml';
|
74 |
$gm['license_name'] = '';
|
75 |
+
$gm['purchase_key'] = '';
|
76 |
$gm['license_key'] = '';
|
77 |
$gm['license_key2'] = '';
|
78 |
|
90 |
$gm['gm_screen_options']['sortorder_gmedia'] = 'DESC';
|
91 |
$gm['gm_screen_options']['display_mode_gmedia'] = 'list';
|
92 |
$gm['gm_screen_options']['grid_cell_fit_gmedia'] = false;
|
93 |
+
$gm['gm_screen_options']['display_mode_gmedia_frame'] = 'grid';
|
94 |
+
$gm['gm_screen_options']['grid_cell_fit_gmedia_frame'] = false;
|
95 |
+
|
96 |
+
$gm['gm_screen_options']['per_page_gmedia_album'] = 30;
|
97 |
+
$gm['gm_screen_options']['orderby_gmedia_album'] = 'name';
|
98 |
+
$gm['gm_screen_options']['sortorder_gmedia_album'] = 'ASC';
|
99 |
|
100 |
+
$gm['gm_screen_options']['per_page_gmedia_category'] = 30;
|
101 |
+
$gm['gm_screen_options']['orderby_gmedia_category'] = 'name';
|
102 |
+
$gm['gm_screen_options']['sortorder_gmedia_category'] = 'ASC';
|
103 |
|
104 |
+
$gm['gm_screen_options']['per_page_gmedia_tag'] = 30;
|
105 |
+
$gm['gm_screen_options']['orderby_gmedia_tag'] = 'name';
|
106 |
+
$gm['gm_screen_options']['sortorder_gmedia_tag'] = 'ASC';
|
107 |
+
|
108 |
+
$gm['gm_screen_options']['per_page_gmedia_gallery'] = 30;
|
109 |
+
$gm['gm_screen_options']['orderby_gmedia_gallery'] = 'name';
|
110 |
+
$gm['gm_screen_options']['sortorder_gmedia_gallery'] = 'ASC';
|
111 |
|
112 |
$gm['gm_screen_options']['per_page_wpmedia'] = 30;
|
113 |
$gm['gm_screen_options']['orderby_wpmedia'] = 'ID';
|
127 |
/**
|
128 |
* sets gmedia capabilities to administrator role
|
129 |
**/
|
130 |
+
function gmedia_capabilities(){
|
131 |
global $gmCore;
|
132 |
// Set the capabilities for the administrator
|
133 |
$role = get_role('administrator');
|
134 |
// We need this role, no other chance
|
135 |
+
if(empty($role)){
|
136 |
update_option("gmediaInitCheck", __('Sorry, Gmedia Gallery works only with a role called administrator', 'grand-media'));
|
137 |
|
138 |
return;
|
139 |
}
|
140 |
$capabilities = $gmCore->plugin_capabilities();
|
141 |
$capabilities = apply_filters('gmedia_capabilities', $capabilities);
|
142 |
+
foreach($capabilities as $cap){
|
143 |
$role->add_cap($cap);
|
144 |
}
|
145 |
}
|
147 |
/**
|
148 |
* creates all tables for the plugin
|
149 |
* called during register_activation hook
|
|
|
150 |
* @access internal
|
151 |
* @return void
|
152 |
**/
|
153 |
+
function gmedia_install(){
|
154 |
/** @var $wpdb wpdb */
|
155 |
global $wpdb, $gmGallery, $gmCore;
|
156 |
|
157 |
// Check for capability
|
158 |
+
if(!current_user_can('activate_plugins')){
|
159 |
return;
|
160 |
}
|
161 |
|
167 |
// add charset & collate like wp core
|
168 |
$charset_collate = '';
|
169 |
|
170 |
+
if($wpdb->has_cap('collation')){
|
171 |
+
if(!empty($wpdb->charset)){
|
172 |
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
173 |
}
|
174 |
+
if(!empty($wpdb->collate)){
|
175 |
$charset_collate .= " COLLATE $wpdb->collate";
|
176 |
}
|
177 |
}
|
178 |
+
$charset_collate .= ' ROW_FORMAT=DYNAMIC';
|
179 |
|
180 |
$gmedia = $wpdb->prefix . 'gmedia';
|
181 |
$gmedia_meta = $wpdb->prefix . 'gmedia_meta';
|
183 |
$gmedia_term_meta = $wpdb->prefix . 'gmedia_term_meta';
|
184 |
$gmedia_term_relationships = $wpdb->prefix . 'gmedia_term_relationships';
|
185 |
|
186 |
+
if($wpdb->get_var("show tables like '$gmedia'") != $gmedia){
|
187 |
+
$sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
|
188 |
+
$sql .= "CREATE TABLE {$gmedia} (
|
189 |
ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
190 |
author BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
191 |
date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
|
206 |
dbDelta($sql);
|
207 |
}
|
208 |
|
209 |
+
if($wpdb->get_var("show tables like '$gmedia_meta'") != $gmedia_meta){
|
210 |
+
$sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
|
211 |
+
$sql .= "CREATE TABLE {$gmedia_meta} (
|
212 |
meta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
213 |
gmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
214 |
meta_key VARCHAR(255) DEFAULT NULL,
|
215 |
meta_value LONGTEXT,
|
216 |
PRIMARY KEY (meta_id),
|
217 |
KEY gmedia_id (gmedia_id),
|
218 |
+
KEY meta_key (meta_key),
|
219 |
+
INDEX `_hash` (meta_value(32))
|
220 |
) {$charset_collate}";
|
221 |
dbDelta($sql);
|
222 |
}
|
223 |
|
224 |
+
if($wpdb->get_var("show tables like '$gmedia_term'") != $gmedia_term){
|
225 |
+
$sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
|
226 |
+
$sql .= "CREATE TABLE {$gmedia_term} (
|
227 |
term_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
228 |
name VARCHAR(200) NOT NULL DEFAULT '',
|
229 |
taxonomy VARCHAR(32) NOT NULL DEFAULT '',
|
238 |
dbDelta($sql);
|
239 |
}
|
240 |
|
241 |
+
if($wpdb->get_var("show tables like '$gmedia_term_meta'") != $gmedia_term_meta){
|
242 |
+
$sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
|
243 |
+
$sql .= "CREATE TABLE {$gmedia_term_meta} (
|
244 |
meta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
245 |
gmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
246 |
meta_key VARCHAR(255) DEFAULT NULL,
|
252 |
dbDelta($sql);
|
253 |
}
|
254 |
|
255 |
+
if($wpdb->get_var("show tables like '$gmedia_term_relationships'") != $gmedia_term_relationships){
|
256 |
+
$sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
|
257 |
+
$sql .= "CREATE TABLE {$gmedia_term_relationships} (
|
258 |
gmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
259 |
gmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
260 |
term_order INT(11) NOT NULL DEFAULT '0',
|
266 |
}
|
267 |
|
268 |
// check one table again, to be sure
|
269 |
+
if($wpdb->get_var("show tables like '$gmedia'") != $gmedia){
|
270 |
update_option("gmediaInitCheck", __('GmediaGallery: Tables could not created, please check your database settings', 'grand-media'));
|
271 |
|
272 |
return;
|
273 |
}
|
274 |
|
275 |
+
if(!get_option('GmediaHashID_salt')){
|
276 |
$ustr = wp_generate_password(12, false);
|
277 |
add_option('GmediaHashID_salt', $ustr);
|
278 |
}
|
279 |
|
280 |
// set the default settings, if we didn't upgrade
|
281 |
+
if(empty($gmGallery->options)){
|
282 |
$gmGallery->options = gmedia_default_options();
|
283 |
// Set installation date
|
284 |
+
if(!get_option('gmediaInstallDate')){
|
285 |
$installDate = time();
|
286 |
add_option('gmediaInstallDate', $installDate);
|
287 |
}
|
288 |
update_option('gmediaOptions', $gmGallery->options);
|
289 |
+
} else{
|
290 |
$default_options = gmedia_default_options();
|
291 |
unset($gmGallery->options['folder'], $gmGallery->options['taxonomies']);
|
292 |
$new_options = $gmCore->array_diff_key_recursive($default_options, $gmGallery->options);
|
295 |
}
|
296 |
|
297 |
// try to make gallery dirs if not exists
|
298 |
+
foreach($gmGallery->options['folder'] as $folder){
|
299 |
wp_mkdir_p($gmCore->upload['path'] . '/' . $folder);
|
300 |
}
|
301 |
|
307 |
|
308 |
/**
|
309 |
* Called via Setup and register_deactivate hook
|
|
|
310 |
* @access internal
|
311 |
* @return void
|
312 |
*/
|
313 |
+
function gmedia_deactivate(){
|
314 |
global $gmCore;
|
315 |
|
316 |
flush_rewrite_rules(false);
|
317 |
|
318 |
wp_clear_scheduled_hook('gmedia_app_cronjob');
|
319 |
|
320 |
+
$options = get_option('gmediaOptions');
|
321 |
+
if((int)$options['mobile_app']){
|
322 |
+
$gmCore->app_service('app_deactivateplugin');
|
323 |
+
}
|
324 |
|
325 |
// remove & reset the init check option
|
326 |
delete_option('gmediaInitCheck');
|
config/update.php
CHANGED
@@ -1,9 +1,13 @@
|
|
1 |
-
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Update Gmedia plugin
|
4 |
*/
|
5 |
|
6 |
-
function gmedia_upgrade_required_admin_notice()
|
7 |
?>
|
8 |
<div id="message" class="updated gmedia-message">
|
9 |
<p><?php _e('<strong>GmediaGallery Database Update Required</strong> – We need to update your install to the latest version.', 'grand-media'); ?></p>
|
@@ -25,7 +29,7 @@ function gmedia_upgrade_required_admin_notice() {
|
|
25 |
|
26 |
}
|
27 |
|
28 |
-
function gmedia_upgrade_process_admin_notice()
|
29 |
?>
|
30 |
<div id="message" class="updated gmedia-message">
|
31 |
<p><?php _e('<strong>GmediaGallery Database Update Required</strong> – We need to update your install to the latest version.', 'grand-media'); ?></p>
|
@@ -35,7 +39,7 @@ function gmedia_upgrade_process_admin_notice() {
|
|
35 |
|
36 |
}
|
37 |
|
38 |
-
function gmedia_upgrade_progress_panel()
|
39 |
gmedia_do_update();
|
40 |
?>
|
41 |
<div id="gmediaUpdate" class="panel panel-default">
|
@@ -75,9 +79,16 @@ function gmedia_upgrade_progress_panel() {
|
|
75 |
<?php
|
76 |
}
|
77 |
|
78 |
-
function gmedia_do_update()
|
79 |
global $wpdb;
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
$info = get_transient('gmediaHeavyJob');
|
82 |
|
83 |
@ignore_user_abort(true);
|
@@ -89,21 +100,22 @@ function gmedia_do_update() {
|
|
89 |
|
90 |
// add charset & collate like wp core
|
91 |
$charset_collate = '';
|
92 |
-
|
93 |
-
|
94 |
-
if(!empty($wpdb->charset)) {
|
95 |
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
96 |
}
|
97 |
-
if(!empty($wpdb->collate))
|
98 |
$charset_collate .= " COLLATE $wpdb->collate";
|
99 |
}
|
100 |
}
|
|
|
101 |
|
102 |
$gmedia = $wpdb->prefix . 'gmedia';
|
103 |
$gmedia_term = $wpdb->prefix . 'gmedia_term';
|
104 |
$gmedia_term_relationships = $wpdb->prefix . 'gmedia_term_relationships';
|
105 |
|
106 |
-
$sql = "
|
|
|
107 |
CREATE TABLE {$gmedia} (
|
108 |
ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
109 |
author BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
@@ -145,20 +157,20 @@ function gmedia_do_update() {
|
|
145 |
";
|
146 |
dbDelta($sql);
|
147 |
|
148 |
-
if(!$info)
|
149 |
$info = array();
|
150 |
}
|
151 |
$info['db_tables'] = __('Gmedia database tables updated...', 'grand-media');
|
152 |
set_transient('gmediaHeavyJob', $info);
|
153 |
|
154 |
$upgrading = get_transient('gmediaUpgrade');
|
155 |
-
if($upgrading && (time() - $upgrading) > 20)
|
156 |
$upgrading = false;
|
157 |
}
|
158 |
-
if((defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) && !$upgrading)
|
159 |
set_transient('gmediaUpgrade', time());
|
160 |
gmedia_db_update();
|
161 |
-
} elseif(!wp_get_schedule('gmedia_db_update') && !$upgrading)
|
162 |
//delete_transient('gmediaUpgradeSteps');
|
163 |
set_transient('gmediaUpgrade', time());
|
164 |
wp_schedule_single_event(time() + 1, 'gmedia_db_update');
|
@@ -167,7 +179,7 @@ function gmedia_do_update() {
|
|
167 |
}
|
168 |
|
169 |
add_action('gmedia_db_update', 'gmedia_db_update');
|
170 |
-
function gmedia_db_update()
|
171 |
|
172 |
@ignore_user_abort(true);
|
173 |
@set_time_limit(0);
|
@@ -176,13 +188,13 @@ function gmedia_db_update() {
|
|
176 |
$db_version = get_option('gmediaDbVersion');
|
177 |
$info = get_transient('gmediaHeavyJob');
|
178 |
|
179 |
-
if(version_compare($db_version, '0.9.6', '<'))
|
180 |
gmedia_db_update__0_9_6();
|
181 |
|
182 |
-
} elseif(version_compare($db_version, '1.8.0', '<'))
|
183 |
gmedia_db_update__1_8_0();
|
184 |
|
185 |
-
} else
|
186 |
$info['update_complete'] = __('GmediaGallery plugin update complete.', 'grand-media');
|
187 |
set_transient('gmediaHeavyJob', $info);
|
188 |
|
@@ -195,7 +207,7 @@ function gmedia_db_update() {
|
|
195 |
}
|
196 |
}
|
197 |
|
198 |
-
function gmedia_db_update__0_9_6()
|
199 |
global $wpdb, $gmDB, $gmCore, $gmGallery;
|
200 |
|
201 |
$info = get_transient('gmediaHeavyJob');
|
@@ -207,7 +219,7 @@ function gmedia_db_update__0_9_6() {
|
|
207 |
$old_options = get_option('gmediaOptions');
|
208 |
require_once(dirname(__FILE__) . '/setup.php');
|
209 |
$options = gmedia_default_options();
|
210 |
-
if(isset($old_options['product_name']))
|
211 |
$options['license_name'] = $old_options['product_name'];
|
212 |
$options['license_key'] = $old_options['gmedia_key'];
|
213 |
$options['license_key2'] = $old_options['gmedia_key2'];
|
@@ -216,27 +228,26 @@ function gmedia_db_update__0_9_6() {
|
|
216 |
$gmGallery->options = $options;
|
217 |
|
218 |
$fix_files = glob($gmCore->upload['path'] . '/?*.?*', GLOB_NOSORT);
|
219 |
-
if(!empty($fix_files))
|
220 |
-
foreach($fix_files as $ff)
|
221 |
@rename($ff, $gmCore->upload['path'] . '/image/' . basename($ff));
|
222 |
}
|
223 |
}
|
224 |
|
225 |
$gmedias = $gmDB->get_gmedias(array('mime_type' => 'image/*', 'cache_results' => false));
|
226 |
$files = array();
|
227 |
-
foreach($gmedias as $gmedia)
|
228 |
-
$files[] = array(
|
229 |
-
|
230 |
-
'file' => $gmCore->upload['path'] . '/image/' . $gmedia->gmuid,
|
231 |
);
|
232 |
}
|
233 |
-
if(!empty($files))
|
234 |
gmedia_images_update($files);
|
235 |
}
|
236 |
$gmCore->delete_folder($gmCore->upload['path'] . '/link');
|
237 |
|
238 |
// try to make gallery dirs if not exists
|
239 |
-
foreach($gmGallery->options['folder'] as $folder)
|
240 |
wp_mkdir_p($gmCore->upload['path'] . '/' . $folder);
|
241 |
}
|
242 |
|
@@ -244,9 +255,9 @@ function gmedia_db_update__0_9_6() {
|
|
244 |
$wpdb->update($wpdb->prefix . 'gmedia_term', array('taxonomy' => 'gmedia_gallery'), array('taxonomy' => 'gmedia_module'));
|
245 |
|
246 |
$gmedias = $gmDB->get_gmedias(array('no_found_rows' => true, 'meta_key' => 'link', 'cache_results' => false));
|
247 |
-
foreach($gmedias as $gmedia)
|
248 |
$link = $gmDB->get_metadata('gmedia', $gmedia->ID, 'link', true);
|
249 |
-
if($link)
|
250 |
$wpdb->update($wpdb->prefix . 'gmedia', array('link' => $link), array('ID' => $gmedia->ID));
|
251 |
}
|
252 |
}
|
@@ -258,35 +269,34 @@ function gmedia_db_update__0_9_6() {
|
|
258 |
set_transient('gmediaUpgrade', time());
|
259 |
|
260 |
$galleries = $gmDB->get_terms('gmedia_gallery');
|
261 |
-
if($galleries)
|
262 |
-
foreach($galleries as $gallery)
|
263 |
$old_meta = $gmDB->get_metadata('gmedia_term', $gallery->term_id);
|
264 |
-
if(!empty($old_meta))
|
265 |
$old_meta = array_map('reset', $old_meta);
|
266 |
-
if(!isset($old_meta['gMediaQuery']))
|
267 |
continue;
|
268 |
}
|
269 |
$gmedia_category = $gmedia_tag = array();
|
270 |
-
foreach($old_meta['gMediaQuery'] as $tab)
|
271 |
-
if(isset($tab['cat']) && !empty($tab['cat']))
|
272 |
$gmedia_category[] = $tab['cat'];
|
273 |
}
|
274 |
-
if(isset($tab['tag__in']) && !empty($tab['tag__in']))
|
275 |
$gmedia_tag = array_merge($gmedia_tag, $tab['tag__in']);
|
276 |
}
|
277 |
}
|
278 |
$query = array();
|
279 |
-
if(!empty($gmedia_category))
|
280 |
$query = array('gmedia_album' => $gmedia_category);
|
281 |
-
} elseif(!empty($gmedia_tag))
|
282 |
$query = array('gmedia_tag' => $gmedia_tag);
|
283 |
}
|
284 |
-
$gallery_meta = array(
|
285 |
-
|
286 |
-
|
287 |
-
'_query' => $query
|
288 |
);
|
289 |
-
foreach($gallery_meta as $key => $value)
|
290 |
$gmDB->update_metadata('gmedia_term', $gallery->term_id, $key, $value);
|
291 |
}
|
292 |
}
|
@@ -303,12 +313,12 @@ function gmedia_db_update__0_9_6() {
|
|
303 |
gmedia_db_update();
|
304 |
}
|
305 |
|
306 |
-
function gmedia_db_update__1_8_0()
|
307 |
global $wpdb, $gmDB, $gmGallery;
|
308 |
|
309 |
$info = get_transient('gmediaHeavyJob');
|
310 |
$steps = get_transient('gmediaUpgradeSteps');
|
311 |
-
if(!isset($steps['status_update']))
|
312 |
$wpdb->update($wpdb->prefix . 'gmedia', array('status' => 'publish'), array('status' => 'public'));
|
313 |
$wpdb->update($wpdb->prefix . 'gmedia_term', array('status' => 'publish'), array('status' => 'public'));
|
314 |
$wpdb->update($wpdb->prefix . 'gmedia_term', array('global' => 0), array('taxonomy' => 'gmedia_tag'));
|
@@ -323,25 +333,32 @@ function gmedia_db_update__1_8_0() {
|
|
323 |
|
324 |
set_transient('gmediaUpgrade', time());
|
325 |
|
326 |
-
$steps['step']++;
|
327 |
|
328 |
-
if(!isset($steps['gmedia_posts']))
|
329 |
$gm_options = $gmGallery->options;
|
330 |
$step = $steps['step'];
|
331 |
|
332 |
$gmedias = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}gmedia WHERE post_id IS NULL OR post_id = '' OR post_id = 0 LIMIT 20");
|
333 |
-
if(!empty($gmedias))
|
334 |
-
$post_data = array(
|
335 |
-
|
336 |
-
'comment_status' => $gm_options['default_gmedia_comment_status']
|
337 |
);
|
338 |
$i = 0;
|
339 |
-
foreach($gmedias as $gmedia)
|
340 |
-
$i++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
$post_data['post_author'] = $gmedia->author;
|
343 |
-
$post_data['post_content'] = $
|
344 |
-
$post_data['post_title'] = (trim($
|
345 |
$post_data['post_status'] = $gmedia->status;
|
346 |
$post_data['post_name'] = $gmedia->gmuid;
|
347 |
$post_data['post_date'] = $gmedia->date;
|
@@ -349,7 +366,7 @@ function gmedia_db_update__1_8_0() {
|
|
349 |
$post_data['post_mime_type'] = $gmedia->mime_type;
|
350 |
|
351 |
$post_ID = wp_insert_post($post_data);
|
352 |
-
if($post_ID)
|
353 |
add_metadata('post', $post_ID, '_gmedia_ID', $gmedia->ID);
|
354 |
$wpdb->update($wpdb->prefix . 'gmedia', array('post_id' => $post_ID), array('ID' => $gmedia->ID));
|
355 |
|
@@ -364,12 +381,12 @@ function gmedia_db_update__1_8_0() {
|
|
364 |
$gmDB->update_gmedia_caches($gmedias, false, false);
|
365 |
|
366 |
set_transient('gmediaUpgradeSteps', $steps);
|
367 |
-
if((defined('DISABLE_WP_CRON') && DISABLE_WP_CRON))
|
368 |
set_transient('gmediaUpgrade', time() - 17);
|
369 |
-
} else
|
370 |
wp_schedule_single_event(time(), 'gmedia_db_update');
|
371 |
}
|
372 |
-
} else
|
373 |
$info['180_5'] = __('Adding other features...', 'grand-media');
|
374 |
set_transient('gmediaHeavyJob', $info);
|
375 |
|
@@ -378,34 +395,33 @@ function gmedia_db_update__1_8_0() {
|
|
378 |
}
|
379 |
}
|
380 |
|
381 |
-
if(isset($steps['gmedia_posts']) && !isset($steps['terms_posts']))
|
382 |
$step = $steps['step'];
|
383 |
$taxonomies = array('gmedia_album', 'gmedia_gallery');
|
384 |
$gmedia_terms_with_post = $wpdb->get_col("SELECT gmedia_term_id FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_post_ID' AND meta_value != ''");
|
385 |
$gmedia_terms_exclude = '';
|
386 |
-
if(!empty($gmedia_terms_with_post))
|
387 |
$gmedia_terms_exclude = "AND term_id NOT IN ('" . implode("','", $gmedia_terms_with_post) . "')";
|
388 |
}
|
389 |
$gmedia_terms = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}gmedia_term WHERE taxonomy IN('" . implode("','", $taxonomies) . "') {$gmedia_terms_exclude} LIMIT 20");
|
390 |
-
if(!empty($gmedia_terms))
|
391 |
$i = 0;
|
392 |
-
foreach($gmedia_terms as $term)
|
393 |
-
if($gmDB->get_metadata('gmedia_term', $term->term_id, '_post_ID', true))
|
394 |
continue;
|
395 |
}
|
396 |
-
$post_data = array(
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
, 'post_type' => $term->taxonomy
|
402 |
);
|
403 |
$post_ID = wp_insert_post($post_data);
|
404 |
-
if($post_ID)
|
405 |
add_metadata('post', $post_ID, '_gmedia_term_ID', $term->term_id);
|
406 |
$gmDB->add_metadata('gmedia_term', $term->term_id, '_post_ID', $post_ID);
|
407 |
|
408 |
-
$i++;
|
409 |
$info['180_6'] = sprintf(__('Updated %d terms (with author)...', 'grand-media'), ($step * $i));
|
410 |
set_transient('gmediaHeavyJob', $info);
|
411 |
set_transient('gmediaUpgrade', time());
|
@@ -413,12 +429,12 @@ function gmedia_db_update__1_8_0() {
|
|
413 |
}
|
414 |
|
415 |
set_transient('gmediaUpgradeSteps', $steps);
|
416 |
-
if((defined('DISABLE_WP_CRON') && DISABLE_WP_CRON))
|
417 |
set_transient('gmediaUpgrade', time() - 17);
|
418 |
-
} else
|
419 |
wp_schedule_single_event(time(), 'gmedia_db_update');
|
420 |
}
|
421 |
-
} else
|
422 |
$info['180_7'] = __('Update cache...', 'grand-media');
|
423 |
set_transient('gmediaHeavyJob', $info);
|
424 |
|
@@ -429,7 +445,7 @@ function gmedia_db_update__1_8_0() {
|
|
429 |
}
|
430 |
}
|
431 |
|
432 |
-
if(isset($steps['terms_posts']))
|
433 |
update_option("gmediaDbVersion", '1.8.0');
|
434 |
set_transient('gmediaUpgradeSteps', $steps);
|
435 |
//wp_schedule_single_event(time() + 2, 'gmedia_db_update');
|
@@ -441,7 +457,7 @@ function gmedia_db_update__1_8_0() {
|
|
441 |
/**
|
442 |
* @param $files
|
443 |
*/
|
444 |
-
function gmedia_images_update($files)
|
445 |
global $wpdb, $gmCore, $gmGallery;
|
446 |
|
447 |
$info = get_transient('gmediaHeavyJob');
|
@@ -449,31 +465,31 @@ function gmedia_images_update($files) {
|
|
449 |
$eol = '</pre>' . PHP_EOL;
|
450 |
$c = count($files);
|
451 |
$i = 0;
|
452 |
-
foreach($files as $file)
|
453 |
|
454 |
/**
|
455 |
* @var $file
|
456 |
* @var $id
|
457 |
*/
|
458 |
-
if(is_array($file))
|
459 |
-
if(isset($file['file']))
|
460 |
extract($file);
|
461 |
-
} else
|
462 |
_e('Something went wrong...', 'grand-media');
|
463 |
die();
|
464 |
}
|
465 |
}
|
466 |
|
467 |
-
$i++;
|
468 |
$prefix = "\n<pre style='display:block;'>$i/$c - ";
|
469 |
$prefix_ko = "\n<pre style='display:block;color:darkred;'>$i/$c - ";
|
470 |
|
471 |
-
if(!is_file($file))
|
472 |
$fileinfo = $gmCore->fileinfo($file, false);
|
473 |
-
if(is_file($fileinfo['filepath_original']))
|
474 |
@rename($fileinfo['filepath_original'], $fileinfo['filepath']);
|
475 |
-
} else
|
476 |
-
$info['img_' . $i] = $prefix_ko . sprintf(__('File not exists: %s', 'grand-media'), $file) . $eol;
|
477 |
set_transient('gmediaHeavyJob', $info);
|
478 |
continue;
|
479 |
}
|
@@ -482,17 +498,17 @@ function gmedia_images_update($files) {
|
|
482 |
$file_File = $file;
|
483 |
$fileinfo = $gmCore->fileinfo($file, false);
|
484 |
|
485 |
-
if($file_File != $fileinfo['filepath'])
|
486 |
@rename($file_File, $fileinfo['filepath']);
|
487 |
$wpdb->update($wpdb->prefix . 'gmedia', array('gmuid' => $fileinfo['basename']), array('gmuid' => basename($file_File)));
|
488 |
}
|
489 |
|
490 |
-
if('image' == $fileinfo['dirname'])
|
491 |
$size = @getimagesize($fileinfo['filepath']);
|
492 |
-
if(!file_exists($fileinfo['filepath_thumb']) && file_is_displayable_image($fileinfo['filepath']))
|
493 |
-
if(function_exists('memory_get_usage'))
|
494 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
495 |
-
switch($extensions[$size[2]])
|
496 |
case 'GIF':
|
497 |
$CHANNEL = 1;
|
498 |
break;
|
@@ -514,41 +530,44 @@ function gmedia_images_update($files) {
|
|
514 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
515 |
$current_limit = @ini_get('memory_limit');
|
516 |
$current_limit_int = intval($current_limit);
|
517 |
-
if(false !== strpos($current_limit, 'M'))
|
518 |
$current_limit_int *= $MB;
|
519 |
}
|
520 |
-
if(false !== strpos($current_limit, 'G'))
|
521 |
$current_limit_int *= 1024;
|
522 |
}
|
523 |
|
524 |
-
if(-1 != $current_limit && $memoryNeeded > $current_limit_int)
|
525 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
|
|
|
|
|
|
526 |
@ini_set('memory_limit', $newLimit . 'M');
|
527 |
}
|
528 |
}
|
529 |
|
530 |
-
if(!wp_mkdir_p($fileinfo['dirpath_thumb']))
|
531 |
-
$info['img_' . $i] = $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
532 |
set_transient('gmediaHeavyJob', $info);
|
533 |
continue;
|
534 |
}
|
535 |
-
if(!is_writable($fileinfo['dirpath_thumb']))
|
536 |
@chmod($fileinfo['dirpath_thumb'], 0755);
|
537 |
-
if(!is_writable($fileinfo['dirpath_thumb']))
|
538 |
-
$info['img_' . $i] = $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
539 |
set_transient('gmediaHeavyJob', $info);
|
540 |
continue;
|
541 |
}
|
542 |
}
|
543 |
-
if(!wp_mkdir_p($fileinfo['dirpath_original']))
|
544 |
-
$info['img_' . $i] = $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
545 |
set_transient('gmediaHeavyJob', $info);
|
546 |
continue;
|
547 |
}
|
548 |
-
if(!is_writable($fileinfo['dirpath_original']))
|
549 |
@chmod($fileinfo['dirpath_original'], 0755);
|
550 |
-
if(!is_writable($fileinfo['dirpath_original']))
|
551 |
-
$info['img_' . $i] = $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
552 |
set_transient('gmediaHeavyJob', $info);
|
553 |
continue;
|
554 |
}
|
@@ -561,32 +580,32 @@ function gmedia_images_update($files) {
|
|
561 |
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
562 |
$thumbimg['resize'] = (($thumbimg['width'] < $size[0]) || ($thumbimg['height'] < $size[1]))? true : false;
|
563 |
|
564 |
-
if($webimg['resize'])
|
565 |
rename($fileinfo['filepath'], $fileinfo['filepath_original']);
|
566 |
-
} else
|
567 |
copy($fileinfo['filepath'], $fileinfo['filepath_original']);
|
568 |
}
|
569 |
-
if($webimg['resize'] || $thumbimg['resize'])
|
570 |
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
571 |
-
if(is_wp_error($editor))
|
572 |
-
$info['img_' . $i] = $prefix_ko . $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message();
|
573 |
set_transient('gmediaHeavyJob', $info);
|
574 |
continue;
|
575 |
}
|
576 |
|
577 |
-
if($webimg['resize'])
|
578 |
$editor->set_quality($webimg['quality']);
|
579 |
|
580 |
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
581 |
-
if(is_wp_error($resized))
|
582 |
-
$info['img_' . $i] = $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})): " . $resized->get_error_message() . $eol;
|
583 |
set_transient('gmediaHeavyJob', $info);
|
584 |
continue;
|
585 |
}
|
586 |
|
587 |
$saved = $editor->save($fileinfo['filepath']);
|
588 |
-
if(is_wp_error($saved))
|
589 |
-
$info['img_' . $i] = $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->webimage): " . $saved->get_error_message() . $eol;
|
590 |
set_transient('gmediaHeavyJob', $info);
|
591 |
continue;
|
592 |
}
|
@@ -596,28 +615,28 @@ function gmedia_images_update($files) {
|
|
596 |
$editor->set_quality($thumbimg['quality']);
|
597 |
|
598 |
$resized = $editor->resize($thumbimg['width'], $thumbimg['height'], $thumbimg['crop']);
|
599 |
-
if(is_wp_error($resized))
|
600 |
-
$info['img_' . $i] = $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})): " . $resized->get_error_message() . $eol;
|
601 |
set_transient('gmediaHeavyJob', $info);
|
602 |
continue;
|
603 |
}
|
604 |
|
605 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
606 |
-
if(is_wp_error($saved))
|
607 |
-
$info['img_' . $i] = $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message() . $eol;
|
608 |
set_transient('gmediaHeavyJob', $info);
|
609 |
continue;
|
610 |
}
|
611 |
-
} else
|
612 |
copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
613 |
}
|
614 |
-
} else
|
615 |
-
$info['img_' . $i] = $prefix . $fileinfo['basename'] . ": " . __("Ignored", 'grand-media') . $eol;
|
616 |
set_transient('gmediaHeavyJob', $info);
|
617 |
continue;
|
618 |
}
|
619 |
-
} else
|
620 |
-
$info['img_' . $i] = $prefix_ko . $fileinfo['basename'] . ": " . __("Invalid image.", 'grand-media') . $eol;
|
621 |
set_transient('gmediaHeavyJob', $info);
|
622 |
continue;
|
623 |
}
|
@@ -626,7 +645,7 @@ function gmedia_images_update($files) {
|
|
626 |
// Save the data
|
627 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $gmDB->generate_gmedia_metadata($id, $fileinfo));
|
628 |
|
629 |
-
$info['img_' . $i] = $prefix . $fileinfo['basename'] . ': <span style="color:darkgreen;">' . sprintf(__('success (ID #%s)', 'grand-media'), $id) . '</span>' . $eol;
|
630 |
set_transient('gmediaHeavyJob', $info);
|
631 |
}
|
632 |
|
@@ -635,22 +654,22 @@ function gmedia_images_update($files) {
|
|
635 |
|
636 |
}
|
637 |
|
638 |
-
function gmedia_flush_rewrite_rules()
|
639 |
flush_rewrite_rules(false);
|
640 |
}
|
641 |
|
642 |
-
function gmedia_restore_original_images()
|
643 |
global $wpdb, $gmGallery, $gmCore, $gmDB;
|
644 |
|
645 |
$fix_files = glob($gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/?*.?*_backup', GLOB_NOSORT);
|
646 |
-
if(!empty($fix_files))
|
647 |
-
foreach($fix_files as $ff)
|
648 |
$gmuid = basename($ff, '_backup');
|
649 |
$id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->prefix}gmedia WHERE gmuid = %s", $gmuid));
|
650 |
-
if($id)
|
651 |
$gmDB->update_metadata('gmedia', $id, '_modified', 1);
|
652 |
@rename($ff, $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $gmuid);
|
653 |
-
} else
|
654 |
@unlink($gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $gmuid . '_backup');
|
655 |
}
|
656 |
}
|
@@ -658,59 +677,54 @@ function gmedia_restore_original_images() {
|
|
658 |
}
|
659 |
|
660 |
|
661 |
-
function gmedia_quite_update()
|
662 |
global $wpdb, $gmDB, $gmCore, $gmGallery;
|
663 |
$current_version = get_option('gmediaVersion', null);
|
664 |
//$current_db_version = get_option( 'gmediaDbVersion', null );
|
665 |
-
if((null !== $current_version))
|
666 |
$options = get_option('gmediaOptions');
|
667 |
-
if(!is_array($options))
|
668 |
$options = array();
|
669 |
}
|
670 |
require_once(dirname(__FILE__) . '/setup.php');
|
671 |
$default_options = gmedia_default_options();
|
672 |
-
if(!get_option('gmediaInstallDate'))
|
673 |
$date = $wpdb->get_var("SELECT {$wpdb->prefix}gmedia.date FROM {$wpdb->prefix}gmedia ORDER BY ID ASC");
|
674 |
-
if(!$date)
|
675 |
$date = '1 month ago';
|
676 |
}
|
677 |
$installDate = strtotime($date);
|
678 |
add_option('gmediaInstallDate', $installDate);
|
679 |
}
|
680 |
|
681 |
-
if(version_compare($current_version, '0.9.23', '<'))
|
682 |
-
if(isset($options['license_name']))
|
683 |
$default_options['license_name'] = $options['license_name'];
|
684 |
$default_options['license_key'] = $options['license_key'];
|
685 |
$default_options['license_key2'] = $options['license_key2'];
|
686 |
-
} elseif(isset($options['product_name']))
|
687 |
$default_options['license_name'] = $options['product_name'];
|
688 |
$default_options['license_key'] = $options['gmedia_key'];
|
689 |
$default_options['license_key2'] = $options['gmedia_key2'];
|
690 |
}
|
691 |
-
update_option('gmediaOptions', $default_options);
|
692 |
-
} else {
|
693 |
-
$new_options = $gmCore->array_diff_key_recursive($default_options, $options);
|
694 |
-
$gmGallery->options = $gmCore->array_replace_recursive($options, $new_options);
|
695 |
-
update_option('gmediaOptions', $gmGallery->options);
|
696 |
}
|
697 |
|
698 |
-
if(version_compare($current_version, '1.2.0', '<'))
|
699 |
gmedia_capabilities();
|
700 |
}
|
701 |
|
702 |
-
if(version_compare($current_version, '1.4.4', '<'))
|
703 |
-
if(!get_option('GmediaHashID_salt'))
|
704 |
$ustr = wp_generate_password(12, false);
|
705 |
add_option('GmediaHashID_salt', $ustr);
|
706 |
}
|
707 |
}
|
708 |
|
709 |
-
if(version_compare($current_version, '1.6.3', '<'))
|
710 |
$wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => '_cover'), array('meta_key' => 'cover'));
|
711 |
$wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => '_rating'), array('meta_key' => 'rating'));
|
712 |
}
|
713 |
-
if(version_compare($current_version, '1.6.5', '<'))
|
714 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_edited'), array('meta_key' => 'edited'));
|
715 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_settings'), array('meta_key' => 'settings'));
|
716 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_query'), array('meta_key' => 'query'));
|
@@ -718,63 +732,62 @@ function gmedia_quite_update() {
|
|
718 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_order'), array('meta_key' => 'order'));
|
719 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_orderby'), array('meta_key' => 'orderby'));
|
720 |
}
|
721 |
-
if(version_compare($current_version, '1.6.6', '<'))
|
722 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'ID'), array('meta_key' => '_orderby', 'meta_value' => ''));
|
723 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'DESC'), array('meta_key' => '_order', 'meta_value' => ''));
|
724 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'title'), array('meta_key' => '_orderby', 'meta_value' => 'title ID'));
|
725 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'date'), array('meta_key' => '_orderby', 'meta_value' => 'date ID'));
|
726 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'modified'), array('meta_key' => '_orderby', 'meta_value' => 'modified ID'));
|
727 |
}
|
728 |
-
if(version_compare($current_version, '1.7.1', '<'))
|
729 |
$gmedia_ids = $gmDB->get_gmedias(array('mime_type' => 'audio', 'fields' => 'ids'));
|
730 |
-
foreach($gmedia_ids as $id)
|
731 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $gmDB->generate_gmedia_metadata($id));
|
732 |
}
|
733 |
}
|
734 |
-
if(version_compare($current_version, '1.7.20', '<'))
|
735 |
gmedia_restore_original_images();
|
736 |
}
|
737 |
-
if(version_compare($current_version, '1.8.08', '<'))
|
738 |
-
if(file_exists($gmCore->upload['path'] . '/module/mosaic/js/mosaic.min.js'))
|
739 |
@unlink($gmCore->upload['path'] . '/module/mosaic/js/jquery.prettyPhoto-min.js');
|
740 |
@unlink($gmCore->upload['path'] . '/module/mosaic/js/mosaic.js');
|
741 |
}
|
742 |
}
|
743 |
-
if(version_compare($current_version, '1.8.12', '<'))
|
744 |
$categories = $gmDB->get_terms('gmedia_category');
|
745 |
-
if(!empty($categories))
|
746 |
-
$cats = array(
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
'wedding' => __('Wedding', 'grand-media')
|
774 |
);
|
775 |
-
foreach($categories as $c)
|
776 |
-
if(isset($cats[$c->name]))
|
777 |
-
$wpdb->update($wpdb->prefix . 'gmedia_term', array('name' => $cats[$c->name]), array('term_id' => $c->term_id));
|
778 |
$gmDB->clean_term_cache($c->term_id, 'gmedia_category');
|
779 |
}
|
780 |
}
|
@@ -783,28 +796,28 @@ function gmedia_quite_update() {
|
|
783 |
$role = $gmDB->get_role('gmedia_tag_manage');
|
784 |
$gmDB->set_capability($role, 'gmedia_category_manage');
|
785 |
}
|
786 |
-
if(version_compare($current_version, '1.8.20', '<'))
|
787 |
$queries = $wpdb->get_results("SELECT meta_id, meta_key, meta_value FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_query'", ARRAY_A);
|
788 |
-
if(!empty($queries))
|
789 |
-
foreach($queries as $query)
|
790 |
$query['meta_value'] = maybe_unserialize($query['meta_value']);
|
791 |
$gmCore->replace_array_keys($query['meta_value'], array('album__in' => 'gmedia_album', 'tag__in' => 'gmedia_tag', 'category__in' => 'gmedia_category'));
|
792 |
-
foreach($query['meta_value'] as $key => $value)
|
793 |
-
if('gmedia_filter' == $key)
|
794 |
$new_query = array();
|
795 |
-
foreach($value as $filter_id)
|
796 |
$filter_query = $gmDB->get_metadata('gmedia_term', $filter_id, '_query', true);
|
797 |
$new_query = array_merge($filter_query, $new_query);
|
798 |
}
|
799 |
-
foreach($new_query as $new_key => $new_val)
|
800 |
-
if(is_array($new_val))
|
801 |
-
$new_query[$new_key] = implode(',', $new_val);
|
802 |
}
|
803 |
}
|
804 |
$query['meta_value'] = $new_query;
|
805 |
-
} else
|
806 |
-
if(is_array($value))
|
807 |
-
$query['meta_value'][$key] = implode(',', $value);
|
808 |
}
|
809 |
}
|
810 |
}
|
@@ -812,16 +825,16 @@ function gmedia_quite_update() {
|
|
812 |
}
|
813 |
}
|
814 |
$filters = $gmDB->get_terms('gmedia_filter');
|
815 |
-
if(!empty($filters))
|
816 |
-
foreach($filters as $filter)
|
817 |
$gmDB->delete_term($filter->term_id);
|
818 |
}
|
819 |
}
|
820 |
}
|
821 |
-
if(version_compare($current_version, '1.8.22', '<'))
|
822 |
$queries = $wpdb->get_results("SELECT meta_id, meta_key, meta_value FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_query'", ARRAY_A);
|
823 |
-
if(!empty($queries))
|
824 |
-
foreach($queries as $query)
|
825 |
$query['meta_value'] = maybe_unserialize($query['meta_value']);
|
826 |
if(isset($query['meta_value']['gmedia__in'])){
|
827 |
$query['meta_value'] = $query['meta_value'] + array('order' => 'ASC', 'orderby' => 'gmedia__in');
|
@@ -830,6 +843,21 @@ function gmedia_quite_update() {
|
|
830 |
}
|
831 |
}
|
832 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
|
834 |
$gmCore->delete_folder($gmCore->upload['path'] . '/module/afflux');
|
835 |
$gmCore->delete_folder($gmCore->upload['path'] . '/module/jq-mplayer');
|
@@ -839,6 +867,8 @@ function gmedia_quite_update() {
|
|
839 |
|
840 |
update_option("gmediaVersion", GMEDIA_VERSION);
|
841 |
|
842 |
-
$
|
|
|
|
|
843 |
}
|
844 |
}
|
1 |
+
<?php // don't load directly
|
2 |
+
if(!defined('ABSPATH')){
|
3 |
+
die('-1');
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Update Gmedia plugin
|
8 |
*/
|
9 |
|
10 |
+
function gmedia_upgrade_required_admin_notice(){
|
11 |
?>
|
12 |
<div id="message" class="updated gmedia-message">
|
13 |
<p><?php _e('<strong>GmediaGallery Database Update Required</strong> – We need to update your install to the latest version.', 'grand-media'); ?></p>
|
29 |
|
30 |
}
|
31 |
|
32 |
+
function gmedia_upgrade_process_admin_notice(){
|
33 |
?>
|
34 |
<div id="message" class="updated gmedia-message">
|
35 |
<p><?php _e('<strong>GmediaGallery Database Update Required</strong> – We need to update your install to the latest version.', 'grand-media'); ?></p>
|
39 |
|
40 |
}
|
41 |
|
42 |
+
function gmedia_upgrade_progress_panel(){
|
43 |
gmedia_do_update();
|
44 |
?>
|
45 |
<div id="gmediaUpdate" class="panel panel-default">
|
79 |
<?php
|
80 |
}
|
81 |
|
82 |
+
function gmedia_do_update(){
|
83 |
global $wpdb;
|
84 |
|
85 |
+
if(isset($_GET['reset_update_process'])){
|
86 |
+
delete_transient('gmediaHeavyJob');
|
87 |
+
delete_transient('gmediaUpgrade');
|
88 |
+
delete_transient('gmediaUpgradeSteps');
|
89 |
+
sleep(1);
|
90 |
+
}
|
91 |
+
|
92 |
$info = get_transient('gmediaHeavyJob');
|
93 |
|
94 |
@ignore_user_abort(true);
|
100 |
|
101 |
// add charset & collate like wp core
|
102 |
$charset_collate = '';
|
103 |
+
if($wpdb->has_cap('collation')){
|
104 |
+
if(!empty($wpdb->charset)){
|
|
|
105 |
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
106 |
}
|
107 |
+
if(!empty($wpdb->collate)){
|
108 |
$charset_collate .= " COLLATE $wpdb->collate";
|
109 |
}
|
110 |
}
|
111 |
+
$charset_collate .= ' ROW_FORMAT=DYNAMIC';
|
112 |
|
113 |
$gmedia = $wpdb->prefix . 'gmedia';
|
114 |
$gmedia_term = $wpdb->prefix . 'gmedia_term';
|
115 |
$gmedia_term_relationships = $wpdb->prefix . 'gmedia_term_relationships';
|
116 |
|
117 |
+
$sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
|
118 |
+
$sql .= "
|
119 |
CREATE TABLE {$gmedia} (
|
120 |
ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
121 |
author BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
|
157 |
";
|
158 |
dbDelta($sql);
|
159 |
|
160 |
+
if(!$info){
|
161 |
$info = array();
|
162 |
}
|
163 |
$info['db_tables'] = __('Gmedia database tables updated...', 'grand-media');
|
164 |
set_transient('gmediaHeavyJob', $info);
|
165 |
|
166 |
$upgrading = get_transient('gmediaUpgrade');
|
167 |
+
if($upgrading && (time() - $upgrading) > 20){
|
168 |
$upgrading = false;
|
169 |
}
|
170 |
+
if((defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) && !$upgrading){
|
171 |
set_transient('gmediaUpgrade', time());
|
172 |
gmedia_db_update();
|
173 |
+
} elseif(!wp_get_schedule('gmedia_db_update') && !$upgrading){
|
174 |
//delete_transient('gmediaUpgradeSteps');
|
175 |
set_transient('gmediaUpgrade', time());
|
176 |
wp_schedule_single_event(time() + 1, 'gmedia_db_update');
|
179 |
}
|
180 |
|
181 |
add_action('gmedia_db_update', 'gmedia_db_update');
|
182 |
+
function gmedia_db_update(){
|
183 |
|
184 |
@ignore_user_abort(true);
|
185 |
@set_time_limit(0);
|
188 |
$db_version = get_option('gmediaDbVersion');
|
189 |
$info = get_transient('gmediaHeavyJob');
|
190 |
|
191 |
+
if(version_compare($db_version, '0.9.6', '<')){
|
192 |
gmedia_db_update__0_9_6();
|
193 |
|
194 |
+
} elseif(version_compare($db_version, '1.8.0', '<')){
|
195 |
gmedia_db_update__1_8_0();
|
196 |
|
197 |
+
} else{
|
198 |
$info['update_complete'] = __('GmediaGallery plugin update complete.', 'grand-media');
|
199 |
set_transient('gmediaHeavyJob', $info);
|
200 |
|
207 |
}
|
208 |
}
|
209 |
|
210 |
+
function gmedia_db_update__0_9_6(){
|
211 |
global $wpdb, $gmDB, $gmCore, $gmGallery;
|
212 |
|
213 |
$info = get_transient('gmediaHeavyJob');
|
219 |
$old_options = get_option('gmediaOptions');
|
220 |
require_once(dirname(__FILE__) . '/setup.php');
|
221 |
$options = gmedia_default_options();
|
222 |
+
if(isset($old_options['product_name'])){
|
223 |
$options['license_name'] = $old_options['product_name'];
|
224 |
$options['license_key'] = $old_options['gmedia_key'];
|
225 |
$options['license_key2'] = $old_options['gmedia_key2'];
|
228 |
$gmGallery->options = $options;
|
229 |
|
230 |
$fix_files = glob($gmCore->upload['path'] . '/?*.?*', GLOB_NOSORT);
|
231 |
+
if(!empty($fix_files)){
|
232 |
+
foreach($fix_files as $ff){
|
233 |
@rename($ff, $gmCore->upload['path'] . '/image/' . basename($ff));
|
234 |
}
|
235 |
}
|
236 |
|
237 |
$gmedias = $gmDB->get_gmedias(array('mime_type' => 'image/*', 'cache_results' => false));
|
238 |
$files = array();
|
239 |
+
foreach($gmedias as $gmedia){
|
240 |
+
$files[] = array('id' => $gmedia->ID,
|
241 |
+
'file' => $gmCore->upload['path'] . '/image/' . $gmedia->gmuid,
|
|
|
242 |
);
|
243 |
}
|
244 |
+
if(!empty($files)){
|
245 |
gmedia_images_update($files);
|
246 |
}
|
247 |
$gmCore->delete_folder($gmCore->upload['path'] . '/link');
|
248 |
|
249 |
// try to make gallery dirs if not exists
|
250 |
+
foreach($gmGallery->options['folder'] as $folder){
|
251 |
wp_mkdir_p($gmCore->upload['path'] . '/' . $folder);
|
252 |
}
|
253 |
|
255 |
$wpdb->update($wpdb->prefix . 'gmedia_term', array('taxonomy' => 'gmedia_gallery'), array('taxonomy' => 'gmedia_module'));
|
256 |
|
257 |
$gmedias = $gmDB->get_gmedias(array('no_found_rows' => true, 'meta_key' => 'link', 'cache_results' => false));
|
258 |
+
foreach($gmedias as $gmedia){
|
259 |
$link = $gmDB->get_metadata('gmedia', $gmedia->ID, 'link', true);
|
260 |
+
if($link){
|
261 |
$wpdb->update($wpdb->prefix . 'gmedia', array('link' => $link), array('ID' => $gmedia->ID));
|
262 |
}
|
263 |
}
|
269 |
set_transient('gmediaUpgrade', time());
|
270 |
|
271 |
$galleries = $gmDB->get_terms('gmedia_gallery');
|
272 |
+
if($galleries){
|
273 |
+
foreach($galleries as $gallery){
|
274 |
$old_meta = $gmDB->get_metadata('gmedia_term', $gallery->term_id);
|
275 |
+
if(!empty($old_meta)){
|
276 |
$old_meta = array_map('reset', $old_meta);
|
277 |
+
if(!isset($old_meta['gMediaQuery'])){
|
278 |
continue;
|
279 |
}
|
280 |
$gmedia_category = $gmedia_tag = array();
|
281 |
+
foreach($old_meta['gMediaQuery'] as $tab){
|
282 |
+
if(isset($tab['cat']) && !empty($tab['cat'])){
|
283 |
$gmedia_category[] = $tab['cat'];
|
284 |
}
|
285 |
+
if(isset($tab['tag__in']) && !empty($tab['tag__in'])){
|
286 |
$gmedia_tag = array_merge($gmedia_tag, $tab['tag__in']);
|
287 |
}
|
288 |
}
|
289 |
$query = array();
|
290 |
+
if(!empty($gmedia_category)){
|
291 |
$query = array('gmedia_album' => $gmedia_category);
|
292 |
+
} elseif(!empty($gmedia_tag)){
|
293 |
$query = array('gmedia_tag' => $gmedia_tag);
|
294 |
}
|
295 |
+
$gallery_meta = array('_edited' => $old_meta['last_edited'],
|
296 |
+
'_module' => $old_meta['module_name'],
|
297 |
+
'_query' => $query
|
|
|
298 |
);
|
299 |
+
foreach($gallery_meta as $key => $value){
|
300 |
$gmDB->update_metadata('gmedia_term', $gallery->term_id, $key, $value);
|
301 |
}
|
302 |
}
|
313 |
gmedia_db_update();
|
314 |
}
|
315 |
|
316 |
+
function gmedia_db_update__1_8_0(){
|
317 |
global $wpdb, $gmDB, $gmGallery;
|
318 |
|
319 |
$info = get_transient('gmediaHeavyJob');
|
320 |
$steps = get_transient('gmediaUpgradeSteps');
|
321 |
+
if(!isset($steps['status_update'])){
|
322 |
$wpdb->update($wpdb->prefix . 'gmedia', array('status' => 'publish'), array('status' => 'public'));
|
323 |
$wpdb->update($wpdb->prefix . 'gmedia_term', array('status' => 'publish'), array('status' => 'public'));
|
324 |
$wpdb->update($wpdb->prefix . 'gmedia_term', array('global' => 0), array('taxonomy' => 'gmedia_tag'));
|
333 |
|
334 |
set_transient('gmediaUpgrade', time());
|
335 |
|
336 |
+
$steps['step'] ++;
|
337 |
|
338 |
+
if(!isset($steps['gmedia_posts'])){
|
339 |
$gm_options = $gmGallery->options;
|
340 |
$step = $steps['step'];
|
341 |
|
342 |
$gmedias = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}gmedia WHERE post_id IS NULL OR post_id = '' OR post_id = 0 LIMIT 20");
|
343 |
+
if(!empty($gmedias)){
|
344 |
+
$post_data = array('post_type' => 'gmedia',
|
345 |
+
'comment_status' => $gm_options['default_gmedia_comment_status']
|
|
|
346 |
);
|
347 |
$i = 0;
|
348 |
+
foreach($gmedias as $gmedia){
|
349 |
+
$i ++;
|
350 |
+
|
351 |
+
$description = $gmedia->description;
|
352 |
+
$description = mb_convert_encoding($description, 'UTF-8', 'UTF-8');
|
353 |
+
$title = $gmedia->title;
|
354 |
+
$title = mb_convert_encoding($title, 'UTF-8', 'UTF-8');
|
355 |
+
if($description !== $gmedia->description || $title !== $gmedia->title){
|
356 |
+
$gmDB->insert_gmedia((array)$gmedia);
|
357 |
+
}
|
358 |
|
359 |
$post_data['post_author'] = $gmedia->author;
|
360 |
+
$post_data['post_content'] = $description;
|
361 |
+
$post_data['post_title'] = (trim($title)? $title : $gmedia->gmuid);
|
362 |
$post_data['post_status'] = $gmedia->status;
|
363 |
$post_data['post_name'] = $gmedia->gmuid;
|
364 |
$post_data['post_date'] = $gmedia->date;
|
366 |
$post_data['post_mime_type'] = $gmedia->mime_type;
|
367 |
|
368 |
$post_ID = wp_insert_post($post_data);
|
369 |
+
if($post_ID){
|
370 |
add_metadata('post', $post_ID, '_gmedia_ID', $gmedia->ID);
|
371 |
$wpdb->update($wpdb->prefix . 'gmedia', array('post_id' => $post_ID), array('ID' => $gmedia->ID));
|
372 |
|
381 |
$gmDB->update_gmedia_caches($gmedias, false, false);
|
382 |
|
383 |
set_transient('gmediaUpgradeSteps', $steps);
|
384 |
+
if((defined('DISABLE_WP_CRON') && DISABLE_WP_CRON)){
|
385 |
set_transient('gmediaUpgrade', time() - 17);
|
386 |
+
} else{
|
387 |
wp_schedule_single_event(time(), 'gmedia_db_update');
|
388 |
}
|
389 |
+
} else{
|
390 |
$info['180_5'] = __('Adding other features...', 'grand-media');
|
391 |
set_transient('gmediaHeavyJob', $info);
|
392 |
|
395 |
}
|
396 |
}
|
397 |
|
398 |
+
if(isset($steps['gmedia_posts']) && !isset($steps['terms_posts'])){
|
399 |
$step = $steps['step'];
|
400 |
$taxonomies = array('gmedia_album', 'gmedia_gallery');
|
401 |
$gmedia_terms_with_post = $wpdb->get_col("SELECT gmedia_term_id FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_post_ID' AND meta_value != ''");
|
402 |
$gmedia_terms_exclude = '';
|
403 |
+
if(!empty($gmedia_terms_with_post)){
|
404 |
$gmedia_terms_exclude = "AND term_id NOT IN ('" . implode("','", $gmedia_terms_with_post) . "')";
|
405 |
}
|
406 |
$gmedia_terms = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}gmedia_term WHERE taxonomy IN('" . implode("','", $taxonomies) . "') {$gmedia_terms_exclude} LIMIT 20");
|
407 |
+
if(!empty($gmedia_terms)){
|
408 |
$i = 0;
|
409 |
+
foreach($gmedia_terms as $term){
|
410 |
+
if($gmDB->get_metadata('gmedia_term', $term->term_id, '_post_ID', true)){
|
411 |
continue;
|
412 |
}
|
413 |
+
$post_data = array('post_author' => $term->global,
|
414 |
+
'post_content' => $term->description,
|
415 |
+
'post_title' => $term->name,
|
416 |
+
'post_status' => $term->status,
|
417 |
+
'post_type' => $term->taxonomy
|
|
|
418 |
);
|
419 |
$post_ID = wp_insert_post($post_data);
|
420 |
+
if($post_ID){
|
421 |
add_metadata('post', $post_ID, '_gmedia_term_ID', $term->term_id);
|
422 |
$gmDB->add_metadata('gmedia_term', $term->term_id, '_post_ID', $post_ID);
|
423 |
|
424 |
+
$i ++;
|
425 |
$info['180_6'] = sprintf(__('Updated %d terms (with author)...', 'grand-media'), ($step * $i));
|
426 |
set_transient('gmediaHeavyJob', $info);
|
427 |
set_transient('gmediaUpgrade', time());
|
429 |
}
|
430 |
|
431 |
set_transient('gmediaUpgradeSteps', $steps);
|
432 |
+
if((defined('DISABLE_WP_CRON') && DISABLE_WP_CRON)){
|
433 |
set_transient('gmediaUpgrade', time() - 17);
|
434 |
+
} else{
|
435 |
wp_schedule_single_event(time(), 'gmedia_db_update');
|
436 |
}
|
437 |
+
} else{
|
438 |
$info['180_7'] = __('Update cache...', 'grand-media');
|
439 |
set_transient('gmediaHeavyJob', $info);
|
440 |
|
445 |
}
|
446 |
}
|
447 |
|
448 |
+
if(isset($steps['terms_posts'])){
|
449 |
update_option("gmediaDbVersion", '1.8.0');
|
450 |
set_transient('gmediaUpgradeSteps', $steps);
|
451 |
//wp_schedule_single_event(time() + 2, 'gmedia_db_update');
|
457 |
/**
|
458 |
* @param $files
|
459 |
*/
|
460 |
+
function gmedia_images_update($files){
|
461 |
global $wpdb, $gmCore, $gmGallery;
|
462 |
|
463 |
$info = get_transient('gmediaHeavyJob');
|
465 |
$eol = '</pre>' . PHP_EOL;
|
466 |
$c = count($files);
|
467 |
$i = 0;
|
468 |
+
foreach($files as $file){
|
469 |
|
470 |
/**
|
471 |
* @var $file
|
472 |
* @var $id
|
473 |
*/
|
474 |
+
if(is_array($file)){
|
475 |
+
if(isset($file['file'])){
|
476 |
extract($file);
|
477 |
+
} else{
|
478 |
_e('Something went wrong...', 'grand-media');
|
479 |
die();
|
480 |
}
|
481 |
}
|
482 |
|
483 |
+
$i ++;
|
484 |
$prefix = "\n<pre style='display:block;'>$i/$c - ";
|
485 |
$prefix_ko = "\n<pre style='display:block;color:darkred;'>$i/$c - ";
|
486 |
|
487 |
+
if(!is_file($file)){
|
488 |
$fileinfo = $gmCore->fileinfo($file, false);
|
489 |
+
if(is_file($fileinfo['filepath_original'])){
|
490 |
@rename($fileinfo['filepath_original'], $fileinfo['filepath']);
|
491 |
+
} else{
|
492 |
+
$info[ 'img_' . $i ] = $prefix_ko . sprintf(__('File not exists: %s', 'grand-media'), $file) . $eol;
|
493 |
set_transient('gmediaHeavyJob', $info);
|
494 |
continue;
|
495 |
}
|
498 |
$file_File = $file;
|
499 |
$fileinfo = $gmCore->fileinfo($file, false);
|
500 |
|
501 |
+
if($file_File != $fileinfo['filepath']){
|
502 |
@rename($file_File, $fileinfo['filepath']);
|
503 |
$wpdb->update($wpdb->prefix . 'gmedia', array('gmuid' => $fileinfo['basename']), array('gmuid' => basename($file_File)));
|
504 |
}
|
505 |
|
506 |
+
if('image' == $fileinfo['dirname']){
|
507 |
$size = @getimagesize($fileinfo['filepath']);
|
508 |
+
if(!file_exists($fileinfo['filepath_thumb']) && file_is_displayable_image($fileinfo['filepath'])){
|
509 |
+
if(function_exists('memory_get_usage')){
|
510 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
511 |
+
switch($extensions[ $size[2] ]){
|
512 |
case 'GIF':
|
513 |
$CHANNEL = 1;
|
514 |
break;
|
530 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
531 |
$current_limit = @ini_get('memory_limit');
|
532 |
$current_limit_int = intval($current_limit);
|
533 |
+
if(false !== strpos($current_limit, 'M')){
|
534 |
$current_limit_int *= $MB;
|
535 |
}
|
536 |
+
if(false !== strpos($current_limit, 'G')){
|
537 |
$current_limit_int *= 1024;
|
538 |
}
|
539 |
|
540 |
+
if(- 1 != $current_limit && $memoryNeeded > $current_limit_int){
|
541 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
542 |
+
if($newLimit < 256){
|
543 |
+
$newLimit = 256;
|
544 |
+
}
|
545 |
@ini_set('memory_limit', $newLimit . 'M');
|
546 |
}
|
547 |
}
|
548 |
|
549 |
+
if(!wp_mkdir_p($fileinfo['dirpath_thumb'])){
|
550 |
+
$info[ 'img_' . $i ] = $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
551 |
set_transient('gmediaHeavyJob', $info);
|
552 |
continue;
|
553 |
}
|
554 |
+
if(!is_writable($fileinfo['dirpath_thumb'])){
|
555 |
@chmod($fileinfo['dirpath_thumb'], 0755);
|
556 |
+
if(!is_writable($fileinfo['dirpath_thumb'])){
|
557 |
+
$info[ 'img_' . $i ] = $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
558 |
set_transient('gmediaHeavyJob', $info);
|
559 |
continue;
|
560 |
}
|
561 |
}
|
562 |
+
if(!wp_mkdir_p($fileinfo['dirpath_original'])){
|
563 |
+
$info[ 'img_' . $i ] = $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
564 |
set_transient('gmediaHeavyJob', $info);
|
565 |
continue;
|
566 |
}
|
567 |
+
if(!is_writable($fileinfo['dirpath_original'])){
|
568 |
@chmod($fileinfo['dirpath_original'], 0755);
|
569 |
+
if(!is_writable($fileinfo['dirpath_original'])){
|
570 |
+
$info[ 'img_' . $i ] = $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
571 |
set_transient('gmediaHeavyJob', $info);
|
572 |
continue;
|
573 |
}
|
580 |
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
581 |
$thumbimg['resize'] = (($thumbimg['width'] < $size[0]) || ($thumbimg['height'] < $size[1]))? true : false;
|
582 |
|
583 |
+
if($webimg['resize']){
|
584 |
rename($fileinfo['filepath'], $fileinfo['filepath_original']);
|
585 |
+
} else{
|
586 |
copy($fileinfo['filepath'], $fileinfo['filepath_original']);
|
587 |
}
|
588 |
+
if($webimg['resize'] || $thumbimg['resize']){
|
589 |
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
590 |
+
if(is_wp_error($editor)){
|
591 |
+
$info[ 'img_' . $i ] = $prefix_ko . $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message();
|
592 |
set_transient('gmediaHeavyJob', $info);
|
593 |
continue;
|
594 |
}
|
595 |
|
596 |
+
if($webimg['resize']){
|
597 |
$editor->set_quality($webimg['quality']);
|
598 |
|
599 |
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
600 |
+
if(is_wp_error($resized)){
|
601 |
+
$info[ 'img_' . $i ] = $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})): " . $resized->get_error_message() . $eol;
|
602 |
set_transient('gmediaHeavyJob', $info);
|
603 |
continue;
|
604 |
}
|
605 |
|
606 |
$saved = $editor->save($fileinfo['filepath']);
|
607 |
+
if(is_wp_error($saved)){
|
608 |
+
$info[ 'img_' . $i ] = $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->webimage): " . $saved->get_error_message() . $eol;
|
609 |
set_transient('gmediaHeavyJob', $info);
|
610 |
continue;
|
611 |
}
|
615 |
$editor->set_quality($thumbimg['quality']);
|
616 |
|
617 |
$resized = $editor->resize($thumbimg['width'], $thumbimg['height'], $thumbimg['crop']);
|
618 |
+
if(is_wp_error($resized)){
|
619 |
+
$info[ 'img_' . $i ] = $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})): " . $resized->get_error_message() . $eol;
|
620 |
set_transient('gmediaHeavyJob', $info);
|
621 |
continue;
|
622 |
}
|
623 |
|
624 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
625 |
+
if(is_wp_error($saved)){
|
626 |
+
$info[ 'img_' . $i ] = $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message() . $eol;
|
627 |
set_transient('gmediaHeavyJob', $info);
|
628 |
continue;
|
629 |
}
|
630 |
+
} else{
|
631 |
copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
632 |
}
|
633 |
+
} else{
|
634 |
+
$info[ 'img_' . $i ] = $prefix . $fileinfo['basename'] . ": " . __("Ignored", 'grand-media') . $eol;
|
635 |
set_transient('gmediaHeavyJob', $info);
|
636 |
continue;
|
637 |
}
|
638 |
+
} else{
|
639 |
+
$info[ 'img_' . $i ] = $prefix_ko . $fileinfo['basename'] . ": " . __("Invalid image.", 'grand-media') . $eol;
|
640 |
set_transient('gmediaHeavyJob', $info);
|
641 |
continue;
|
642 |
}
|
645 |
// Save the data
|
646 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $gmDB->generate_gmedia_metadata($id, $fileinfo));
|
647 |
|
648 |
+
$info[ 'img_' . $i ] = $prefix . $fileinfo['basename'] . ': <span style="color:darkgreen;">' . sprintf(__('success (ID #%s)', 'grand-media'), $id) . '</span>' . $eol;
|
649 |
set_transient('gmediaHeavyJob', $info);
|
650 |
}
|
651 |
|
654 |
|
655 |
}
|
656 |
|
657 |
+
function gmedia_flush_rewrite_rules(){
|
658 |
flush_rewrite_rules(false);
|
659 |
}
|
660 |
|
661 |
+
function gmedia_restore_original_images(){
|
662 |
global $wpdb, $gmGallery, $gmCore, $gmDB;
|
663 |
|
664 |
$fix_files = glob($gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/?*.?*_backup', GLOB_NOSORT);
|
665 |
+
if(!empty($fix_files)){
|
666 |
+
foreach($fix_files as $ff){
|
667 |
$gmuid = basename($ff, '_backup');
|
668 |
$id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->prefix}gmedia WHERE gmuid = %s", $gmuid));
|
669 |
+
if($id){
|
670 |
$gmDB->update_metadata('gmedia', $id, '_modified', 1);
|
671 |
@rename($ff, $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $gmuid);
|
672 |
+
} else{
|
673 |
@unlink($gmCore->upload['path'] . '/' . $gmGallery->options['folder']['image_original'] . '/' . $gmuid . '_backup');
|
674 |
}
|
675 |
}
|
677 |
}
|
678 |
|
679 |
|
680 |
+
function gmedia_quite_update(){
|
681 |
global $wpdb, $gmDB, $gmCore, $gmGallery;
|
682 |
$current_version = get_option('gmediaVersion', null);
|
683 |
//$current_db_version = get_option( 'gmediaDbVersion', null );
|
684 |
+
if((null !== $current_version)){
|
685 |
$options = get_option('gmediaOptions');
|
686 |
+
if(!is_array($options)){
|
687 |
$options = array();
|
688 |
}
|
689 |
require_once(dirname(__FILE__) . '/setup.php');
|
690 |
$default_options = gmedia_default_options();
|
691 |
+
if(!get_option('gmediaInstallDate')){
|
692 |
$date = $wpdb->get_var("SELECT {$wpdb->prefix}gmedia.date FROM {$wpdb->prefix}gmedia ORDER BY ID ASC");
|
693 |
+
if(!$date){
|
694 |
$date = '1 month ago';
|
695 |
}
|
696 |
$installDate = strtotime($date);
|
697 |
add_option('gmediaInstallDate', $installDate);
|
698 |
}
|
699 |
|
700 |
+
if(version_compare($current_version, '0.9.23', '<')){
|
701 |
+
if(isset($options['license_name'])){
|
702 |
$default_options['license_name'] = $options['license_name'];
|
703 |
$default_options['license_key'] = $options['license_key'];
|
704 |
$default_options['license_key2'] = $options['license_key2'];
|
705 |
+
} elseif(isset($options['product_name'])){
|
706 |
$default_options['license_name'] = $options['product_name'];
|
707 |
$default_options['license_key'] = $options['gmedia_key'];
|
708 |
$default_options['license_key2'] = $options['gmedia_key2'];
|
709 |
}
|
|
|
|
|
|
|
|
|
|
|
710 |
}
|
711 |
|
712 |
+
if(version_compare($current_version, '1.2.0', '<')){
|
713 |
gmedia_capabilities();
|
714 |
}
|
715 |
|
716 |
+
if(version_compare($current_version, '1.4.4', '<')){
|
717 |
+
if(!get_option('GmediaHashID_salt')){
|
718 |
$ustr = wp_generate_password(12, false);
|
719 |
add_option('GmediaHashID_salt', $ustr);
|
720 |
}
|
721 |
}
|
722 |
|
723 |
+
if(version_compare($current_version, '1.6.3', '<')){
|
724 |
$wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => '_cover'), array('meta_key' => 'cover'));
|
725 |
$wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => '_rating'), array('meta_key' => 'rating'));
|
726 |
}
|
727 |
+
if(version_compare($current_version, '1.6.5', '<')){
|
728 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_edited'), array('meta_key' => 'edited'));
|
729 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_settings'), array('meta_key' => 'settings'));
|
730 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_query'), array('meta_key' => 'query'));
|
732 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_order'), array('meta_key' => 'order'));
|
733 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_orderby'), array('meta_key' => 'orderby'));
|
734 |
}
|
735 |
+
if(version_compare($current_version, '1.6.6', '<')){
|
736 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'ID'), array('meta_key' => '_orderby', 'meta_value' => ''));
|
737 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'DESC'), array('meta_key' => '_order', 'meta_value' => ''));
|
738 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'title'), array('meta_key' => '_orderby', 'meta_value' => 'title ID'));
|
739 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'date'), array('meta_key' => '_orderby', 'meta_value' => 'date ID'));
|
740 |
$wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'modified'), array('meta_key' => '_orderby', 'meta_value' => 'modified ID'));
|
741 |
}
|
742 |
+
if(version_compare($current_version, '1.7.1', '<')){
|
743 |
$gmedia_ids = $gmDB->get_gmedias(array('mime_type' => 'audio', 'fields' => 'ids'));
|
744 |
+
foreach($gmedia_ids as $id){
|
745 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $gmDB->generate_gmedia_metadata($id));
|
746 |
}
|
747 |
}
|
748 |
+
if(version_compare($current_version, '1.7.20', '<')){
|
749 |
gmedia_restore_original_images();
|
750 |
}
|
751 |
+
if(version_compare($current_version, '1.8.08', '<')){
|
752 |
+
if(file_exists($gmCore->upload['path'] . '/module/mosaic/js/mosaic.min.js')){
|
753 |
@unlink($gmCore->upload['path'] . '/module/mosaic/js/jquery.prettyPhoto-min.js');
|
754 |
@unlink($gmCore->upload['path'] . '/module/mosaic/js/mosaic.js');
|
755 |
}
|
756 |
}
|
757 |
+
if(version_compare($current_version, '1.8.12', '<')){
|
758 |
$categories = $gmDB->get_terms('gmedia_category');
|
759 |
+
if(!empty($categories)){
|
760 |
+
$cats = array('abstract' => __('Abstract', 'grand-media'),
|
761 |
+
'animals' => __('Animals', 'grand-media'),
|
762 |
+
'black-and-white' => __('Black and White', 'grand-media'),
|
763 |
+
'celebrities' => __('Celebrities', 'grand-media'),
|
764 |
+
'city-and-architecture' => __('City & Architecture', 'grand-media'),
|
765 |
+
'commercial' => __('Commercial', 'grand-media'),
|
766 |
+
'concert' => __('Concert', 'grand-media'),
|
767 |
+
'family' => __('Family', 'grand-media'),
|
768 |
+
'fashion' => __('Fashion', 'grand-media'),
|
769 |
+
'film' => __('Film', 'grand-media'),
|
770 |
+
'fine-art' => __('Fine Art', 'grand-media'),
|
771 |
+
'food' => __('Food', 'grand-media'),
|
772 |
+
'journalism' => __('Journalism', 'grand-media'),
|
773 |
+
'landscapes' => __('Landscapes', 'grand-media'),
|
774 |
+
'macro' => __('Macro', 'grand-media'),
|
775 |
+
'nature' => __('Nature', 'grand-media'),
|
776 |
+
'nude' => __('Nude', 'grand-media'),
|
777 |
+
'people' => __('People', 'grand-media'),
|
778 |
+
'performing-arts' => __('Performing Arts', 'grand-media'),
|
779 |
+
'sport' => __('Sport', 'grand-media'),
|
780 |
+
'still-life' => __('Still Life', 'grand-media'),
|
781 |
+
'street' => __('Street', 'grand-media'),
|
782 |
+
'transportation' => __('Transportation', 'grand-media'),
|
783 |
+
'travel' => __('Travel', 'grand-media'),
|
784 |
+
'underwater' => __('Underwater', 'grand-media'),
|
785 |
+
'urban-exploration' => __('Urban Exploration', 'grand-media'),
|
786 |
+
'wedding' => __('Wedding', 'grand-media')
|
|
|
787 |
);
|
788 |
+
foreach($categories as $c){
|
789 |
+
if(isset($cats[ $c->name ])){
|
790 |
+
$wpdb->update($wpdb->prefix . 'gmedia_term', array('name' => $cats[ $c->name ]), array('term_id' => $c->term_id));
|
791 |
$gmDB->clean_term_cache($c->term_id, 'gmedia_category');
|
792 |
}
|
793 |
}
|
796 |
$role = $gmDB->get_role('gmedia_tag_manage');
|
797 |
$gmDB->set_capability($role, 'gmedia_category_manage');
|
798 |
}
|
799 |
+
if(version_compare($current_version, '1.8.20', '<')){
|
800 |
$queries = $wpdb->get_results("SELECT meta_id, meta_key, meta_value FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_query'", ARRAY_A);
|
801 |
+
if(!empty($queries)){
|
802 |
+
foreach($queries as $query){
|
803 |
$query['meta_value'] = maybe_unserialize($query['meta_value']);
|
804 |
$gmCore->replace_array_keys($query['meta_value'], array('album__in' => 'gmedia_album', 'tag__in' => 'gmedia_tag', 'category__in' => 'gmedia_category'));
|
805 |
+
foreach($query['meta_value'] as $key => $value){
|
806 |
+
if('gmedia_filter' == $key){
|
807 |
$new_query = array();
|
808 |
+
foreach($value as $filter_id){
|
809 |
$filter_query = $gmDB->get_metadata('gmedia_term', $filter_id, '_query', true);
|
810 |
$new_query = array_merge($filter_query, $new_query);
|
811 |
}
|
812 |
+
foreach($new_query as $new_key => $new_val){
|
813 |
+
if(is_array($new_val)){
|
814 |
+
$new_query[ $new_key ] = implode(',', $new_val);
|
815 |
}
|
816 |
}
|
817 |
$query['meta_value'] = $new_query;
|
818 |
+
} else{
|
819 |
+
if(is_array($value)){
|
820 |
+
$query['meta_value'][ $key ] = implode(',', $value);
|
821 |
}
|
822 |
}
|
823 |
}
|
825 |
}
|
826 |
}
|
827 |
$filters = $gmDB->get_terms('gmedia_filter');
|
828 |
+
if(!empty($filters)){
|
829 |
+
foreach($filters as $filter){
|
830 |
$gmDB->delete_term($filter->term_id);
|
831 |
}
|
832 |
}
|
833 |
}
|
834 |
+
if(version_compare($current_version, '1.8.22', '<')){
|
835 |
$queries = $wpdb->get_results("SELECT meta_id, meta_key, meta_value FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_query'", ARRAY_A);
|
836 |
+
if(!empty($queries)){
|
837 |
+
foreach($queries as $query){
|
838 |
$query['meta_value'] = maybe_unserialize($query['meta_value']);
|
839 |
if(isset($query['meta_value']['gmedia__in'])){
|
840 |
$query['meta_value'] = $query['meta_value'] + array('order' => 'ASC', 'orderby' => 'gmedia__in');
|
843 |
}
|
844 |
}
|
845 |
}
|
846 |
+
if(version_compare($current_version, '1.8.55', '<')){
|
847 |
+
$wpdb->query("CREATE INDEX `_hash` ON {$wpdb->prefix}gmedia_meta ( meta_value(32) );");
|
848 |
+
|
849 |
+
$ajax_operations = get_option('gmedia_ajax_long_operations', array());
|
850 |
+
$ajax_operations['gmedia_hash_files'] = 'gmedia_hash_files';
|
851 |
+
update_option('gmedia_ajax_long_operations', $ajax_operations);
|
852 |
+
}
|
853 |
+
|
854 |
+
if(version_compare($current_version, '1.8.63', '<')){
|
855 |
+
$default_options['purchase_key'] = $options['license_key'];
|
856 |
+
}
|
857 |
+
|
858 |
+
$new_options = $gmCore->array_diff_key_recursive($default_options, $options);
|
859 |
+
$gmGallery->options = $gmCore->array_replace_recursive($options, $new_options);
|
860 |
+
update_option('gmediaOptions', $gmGallery->options);
|
861 |
|
862 |
$gmCore->delete_folder($gmCore->upload['path'] . '/module/afflux');
|
863 |
$gmCore->delete_folder($gmCore->upload['path'] . '/module/jq-mplayer');
|
867 |
|
868 |
update_option("gmediaVersion", GMEDIA_VERSION);
|
869 |
|
870 |
+
if((int)$gmGallery->options['mobile_app']){
|
871 |
+
$gmCore->app_service('app_updatecron');
|
872 |
+
}
|
873 |
}
|
874 |
}
|
config/wp-load.php
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Bootstrap file for getting the ABSPATH constant to wp-load.php
|
4 |
* This is requried when a plugin requires access not via the admin screen.
|
1 |
<?php
|
2 |
+
if ( preg_match( '#' . basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '#', $_SERVER['PHP_SELF'] ) ) {
|
3 |
+
die( 'You are not allowed to call this page directly.' );
|
4 |
+
}
|
5 |
+
|
6 |
/**
|
7 |
* Bootstrap file for getting the ABSPATH constant to wp-load.php
|
8 |
* This is requried when a plugin requires access not via the admin screen.
|
grand-media.php
CHANGED
@@ -3,11 +3,11 @@
|
|
3 |
* Plugin Name: Gmedia Gallery
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/grand-media/
|
5 |
* Description: Gmedia Gallery - powerful media library plugin for creating beautiful galleries and managing files.
|
6 |
-
* Version: 1.8.
|
7 |
* Author: Rattus
|
8 |
* Author URI: http://codeasily.com/
|
9 |
* Requires at least: 3.6
|
10 |
-
* Tested up to: 4.
|
11 |
* Text Domain: grand-media
|
12 |
* Domain Path: /lang
|
13 |
*
|
@@ -32,17 +32,17 @@
|
|
32 |
*/
|
33 |
|
34 |
// Stop direct call
|
35 |
-
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF']))
|
36 |
die('You are not allowed to call this page directly.');
|
37 |
}
|
38 |
|
39 |
-
if(!class_exists('Gmedia'))
|
40 |
/**
|
41 |
* Class Gmedia
|
42 |
*/
|
43 |
-
class Gmedia
|
44 |
|
45 |
-
var $version = '1.8.
|
46 |
var $dbversion = '1.8.0';
|
47 |
var $minium_WP = '3.6';
|
48 |
var $options = '';
|
@@ -53,10 +53,10 @@ if(!class_exists('Gmedia')) {
|
|
53 |
/**
|
54 |
*
|
55 |
*/
|
56 |
-
function __construct()
|
57 |
|
58 |
// Stop the plugin if we missed the requirements
|
59 |
-
if(!$this->required_version())
|
60 |
return;
|
61 |
}
|
62 |
|
@@ -71,10 +71,10 @@ if(!class_exists('Gmedia')) {
|
|
71 |
require_once(dirname(__FILE__) . '/inc/db.connect.php');
|
72 |
require_once(dirname(__FILE__) . '/inc/permalinks.php');
|
73 |
|
74 |
-
if($this->options['debug_mode'])
|
75 |
ini_set('display_errors', true);
|
76 |
error_reporting(E_ALL);
|
77 |
-
} else
|
78 |
@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
|
79 |
error_reporting(E_CORE_ERROR | E_COMPILE_ERROR | E_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);
|
80 |
}
|
@@ -112,7 +112,7 @@ if(!class_exists('Gmedia')) {
|
|
112 |
|
113 |
}
|
114 |
|
115 |
-
function start_plugin()
|
116 |
|
117 |
$this->load_dependencies();
|
118 |
$this->compatibility();
|
@@ -123,16 +123,19 @@ if(!class_exists('Gmedia')) {
|
|
123 |
// Check for upgrade
|
124 |
$this->upgrade();
|
125 |
|
|
|
|
|
|
|
126 |
// Load the admin panel or the frontend functions
|
127 |
-
if(is_admin())
|
128 |
|
129 |
// Pass the init check or show a message
|
130 |
-
if(get_option('gmediaActivated'))
|
131 |
add_action('init', array(&$this, 'gmedia_after_activation'));
|
132 |
}
|
133 |
|
134 |
// Pass the init check or show a message
|
135 |
-
if(get_option('gmediaInitCheck'))
|
136 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
137 |
}
|
138 |
|
@@ -140,7 +143,7 @@ if(!class_exists('Gmedia')) {
|
|
140 |
|
141 |
require_once(dirname(__FILE__) . '/admin/class.processor.php');
|
142 |
|
143 |
-
} else
|
144 |
|
145 |
// Add the script and style files
|
146 |
//add_action('wp_enqueue_scripts', array(&$this, 'load_scripts'), 4);
|
@@ -151,20 +154,25 @@ if(!class_exists('Gmedia')) {
|
|
151 |
add_action('wp_head', array(&$this, 'gmedia_head_meta'));
|
152 |
add_action('wp_footer', array(&$this, 'load_module_scripts'));
|
153 |
|
154 |
-
add_action('gmedia_head', array(&$this, 'gmedia_head_meta'));
|
155 |
-
add_action('gmedia_head', array(&$this, 'load_scripts'), 2);
|
156 |
-
add_action('gmedia_enqueue_scripts', array(&$this, 'load_module_scripts'));
|
157 |
}
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
}
|
160 |
|
161 |
-
function gmedia_head_meta()
|
162 |
-
$lk
|
163 |
$db_version = get_option('gmediaDbVersion');
|
164 |
echo "\n<!-- <meta name='GmediaGallery' version='{$this->version}/{$db_version}' license='{$lk}' /> -->\n";
|
165 |
}
|
166 |
|
167 |
-
function admin_notices()
|
168 |
echo '<div id="message" class="error"><p><strong>' . get_option('gmediaInitCheck') . '</strong></p></div>';
|
169 |
delete_option('gmediaInitCheck');
|
170 |
}
|
@@ -172,28 +180,25 @@ if(!class_exists('Gmedia')) {
|
|
172 |
/**
|
173 |
* @return bool
|
174 |
*/
|
175 |
-
function required_version()
|
176 |
global $wp_version;
|
177 |
|
178 |
// Check for WP version installation
|
179 |
-
if(version_compare($wp_version, $this->minium_WP, '<'))
|
180 |
-
$note = sprintf(__('Sorry, Gmedia Gallery works only under WordPress %s or higher', 'grand-media'),
|
181 |
-
$this->minium_WP);
|
182 |
update_option('gmediaInitCheck', $note);
|
183 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
184 |
|
185 |
return false;
|
186 |
}
|
187 |
-
if(version_compare('5.2', phpversion(), '>'))
|
188 |
-
$note = sprintf(__('Attention! Your server php version is: %s. Gmedia Gallery requires php version 5.2+ in order to run properly. Please upgrade your server!',
|
189 |
-
'grand-media'), phpversion());
|
190 |
update_option('gmediaInitCheck', $note);
|
191 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
192 |
}
|
193 |
-
if(version_compare('5.3', phpversion(), '>'))
|
194 |
-
if(ini_get('safe_mode'))
|
195 |
-
$note = __('Attention! Your server safe mode is: ON. Gmedia Gallery requires safe mode to be OFF in order to run properly. Please set your server safe mode option!',
|
196 |
-
'grand-media');
|
197 |
update_option('gmediaInitCheck', $note);
|
198 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
199 |
}
|
@@ -205,52 +210,52 @@ if(!class_exists('Gmedia')) {
|
|
205 |
/**
|
206 |
* Called via Setup and register_activate hook after gmedia_install() function
|
207 |
*/
|
208 |
-
function gmedia_after_activation()
|
209 |
-
global $gmCore;
|
210 |
|
211 |
delete_option('gmediaActivated');
|
212 |
|
213 |
flush_rewrite_rules(false);
|
214 |
|
215 |
-
|
216 |
}
|
217 |
|
218 |
-
function upgrade()
|
219 |
// Queue upgrades
|
220 |
$current_version = get_option('gmediaVersion', null);
|
221 |
$current_db_version = get_option('gmediaDbVersion', null);
|
222 |
|
223 |
-
if(null === $current_db_version)
|
224 |
add_option("gmediaDbVersion", GMEDIA_DBVERSION);
|
225 |
-
} elseif(version_compare($current_db_version, GMEDIA_DBVERSION, '<'))
|
226 |
require_once(dirname(__FILE__) . '/config/update.php');
|
227 |
|
228 |
-
if(get_transient('gmediaUpgrade') || (isset($_GET['do_update']) && ('gmedia' == $_GET['do_update'])))
|
229 |
add_action('admin_notices', 'gmedia_upgrade_process_admin_notice');
|
230 |
-
} else
|
231 |
add_action('admin_notices', 'gmedia_upgrade_required_admin_notice');
|
232 |
}
|
233 |
}
|
234 |
|
235 |
-
if(null === $current_version)
|
236 |
require_once(dirname(__FILE__) . '/config/update.php');
|
237 |
|
238 |
add_option("gmediaVersion", GMEDIA_VERSION);
|
239 |
add_action('init', 'gmedia_flush_rewrite_rules', 1000);
|
240 |
-
} elseif(version_compare($current_version, GMEDIA_VERSION, '<'))
|
241 |
require_once(dirname(__FILE__) . '/config/update.php');
|
242 |
|
243 |
gmedia_quite_update();
|
244 |
add_action('init', 'gmedia_flush_rewrite_rules', 1000);
|
245 |
|
246 |
-
if(!wp_get_schedule('gmedia_app_cronjob'))
|
247 |
wp_schedule_event(time(), 'gmedia_app', 'gmedia_app_cronjob');
|
248 |
}
|
249 |
}
|
250 |
|
251 |
}
|
252 |
|
253 |
-
function define_tables()
|
254 |
global $wpdb;
|
255 |
|
256 |
// add database pointer
|
@@ -262,7 +267,7 @@ if(!class_exists('Gmedia')) {
|
|
262 |
|
263 |
}
|
264 |
|
265 |
-
function define_constant()
|
266 |
|
267 |
define('GMEDIA_VERSION', $this->version);
|
268 |
// Minimum required database version
|
@@ -270,7 +275,7 @@ if(!class_exists('Gmedia')) {
|
|
270 |
|
271 |
}
|
272 |
|
273 |
-
function load_options()
|
274 |
include_once(dirname(__FILE__) . '/config/setup.php');
|
275 |
// Load the options
|
276 |
$default_options = gmedia_default_options();
|
@@ -278,65 +283,60 @@ if(!class_exists('Gmedia')) {
|
|
278 |
if(!is_array($db_options)){
|
279 |
$db_options = array();
|
280 |
}
|
281 |
-
$this->options
|
282 |
}
|
283 |
|
284 |
-
function load_dependencies()
|
285 |
|
286 |
// We didn't need all stuff during a AJAX operation
|
287 |
-
if(defined('DOING_AJAX'))
|
288 |
require_once(dirname(__FILE__) . '/admin/ajax.php');
|
289 |
-
} else
|
290 |
-
require_once(dirname(__FILE__) . '/inc/hashids.php');
|
291 |
|
292 |
// Load backend libraries
|
293 |
-
if(is_admin())
|
294 |
require_once(dirname(__FILE__) . '/inc/media-upload.php');
|
295 |
require_once(dirname(__FILE__) . '/inc/post-metabox.php');
|
296 |
|
297 |
require_once(dirname(__FILE__) . '/admin/admin.php');
|
298 |
|
299 |
// Load frontend libraries
|
300 |
-
} else {
|
301 |
-
require_once(dirname(__FILE__) . '/inc/shortcodes.php');
|
302 |
}
|
303 |
|
304 |
$current_plugins = get_option('active_plugins');
|
305 |
-
if(in_array('wordpress-seo/wp-seo.php', $current_plugins))
|
306 |
require_once(dirname(__FILE__) . '/inc/sitemap.php');
|
307 |
}
|
308 |
}
|
309 |
|
310 |
}
|
311 |
|
312 |
-
function compatibility()
|
313 |
require_once(dirname(__FILE__) . '/inc/compatibility.php');
|
314 |
}
|
315 |
|
316 |
-
function load_textdomain()
|
317 |
|
318 |
load_plugin_textdomain('grand-media', false, GMEDIA_FOLDER . '/lang/');
|
319 |
|
320 |
}
|
321 |
|
322 |
-
function register_scripts_backend()
|
323 |
global $gmCore;
|
324 |
|
325 |
-
wp_register_script('gmedia-global-backend', $gmCore->gmedia_url . '/admin/assets/js/gmedia.global.js', array('jquery'), '1.8.
|
326 |
-
wp_localize_script('gmedia-global-backend', 'GmediaGallery', array(
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
'plugin_dirurl' => $gmCore->gmedia_url
|
331 |
));
|
332 |
|
333 |
-
wp_register_style('grand-media', $gmCore->gmedia_url . '/admin/assets/css/gmedia.admin.css', array(), '1.8.
|
334 |
-
wp_register_script('grand-media', $gmCore->gmedia_url . '/admin/assets/js/gmedia.admin.js', array('jquery', 'gmedia-global-backend'), '1.8.
|
335 |
-
wp_localize_script('grand-media', 'grandMedia', array(
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
'nonce' => wp_create_nonce('grandMedia')
|
340 |
));
|
341 |
|
342 |
wp_register_style('gmedia-bootstrap', $gmCore->gmedia_url . '/assets/bootstrap/css/bootstrap.min.css', array(), '3.3.4', 'all');
|
@@ -346,45 +346,48 @@ if(!class_exists('Gmedia')) {
|
|
346 |
|
347 |
}
|
348 |
|
349 |
-
function register_scripts_frontend()
|
350 |
global $gmCore, $wp_scripts;
|
351 |
|
352 |
-
wp_register_script('gmedia-global-frontend', $gmCore->gmedia_url . '/assets/gmedia.global.front.js', array('jquery'), '1.8.
|
353 |
-
wp_localize_script('gmedia-global-frontend', 'GmediaGallery', array(
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
'license2' => $this->options['license_key2']
|
360 |
));
|
361 |
|
362 |
|
363 |
-
if(!wp_script_is('mediaelement', 'registered'))
|
364 |
wp_register_style('mediaelement', $gmCore->gmedia_url . '/assets/mediaelement/mediaelementplayer.min.css', array(), '2.13.0', 'screen');
|
365 |
wp_register_script('mediaelement', $gmCore->gmedia_url . '/assets/mediaelement/mediaelement-and-player.min.js', array('jquery'), '2.13.0', true);
|
366 |
}
|
367 |
|
368 |
-
if(!wp_script_is('
|
|
|
|
|
|
|
|
|
369 |
wp_deregister_style('magnific-popup');
|
370 |
wp_deregister_script('magnific-popup');
|
371 |
wp_register_style('magnific-popup', $gmCore->gmedia_url . '/assets/mag-popup/magnific-popup.css', array(), '1.0.2', 'screen');
|
372 |
wp_register_script('magnific-popup', $gmCore->gmedia_url . '/assets/mag-popup/jquery.magnific-popup.min.js', array('jquery'), '1.0.2', true);
|
373 |
}
|
374 |
|
375 |
-
if(!wp_script_is('photoswipe', 'registered') || version_compare($wp_scripts->registered['photoswipe']->ver, '3.0.5', '<='))
|
376 |
wp_deregister_style('photoswipe');
|
377 |
wp_deregister_script('photoswipe');
|
378 |
wp_register_style('photoswipe', $gmCore->gmedia_url . '/assets/photoswipe/photoswipe.css', array(), '3.0.5', 'screen');
|
379 |
wp_register_script('photoswipe', $gmCore->gmedia_url . '/assets/photoswipe/photoswipe.jquery.min.js', array('jquery'), '3.0.5', true);
|
380 |
}
|
381 |
|
382 |
-
if(!wp_script_is('easing', 'registered') || version_compare($wp_scripts->registered['easing']->ver, '1.3.0', '<'))
|
383 |
wp_deregister_script('easing');
|
384 |
wp_register_script('easing', $gmCore->gmedia_url . '/assets/jq-plugins/jquery.easing.js', array('jquery'), '1.3.0', true);
|
385 |
}
|
386 |
-
if(!wp_script_is('fancybox', 'registered') || version_compare($wp_scripts->registered['fancybox']->ver, '1.3.4', '<'))
|
387 |
-
if(!defined('FANCYBOX_VERSION'))
|
388 |
wp_deregister_style('fancybox');
|
389 |
wp_register_style('fancybox', $gmCore->gmedia_url . '/assets/fancybox/jquery.fancybox-1.3.4.css', array(), '1.3.4');
|
390 |
}
|
@@ -393,11 +396,11 @@ if(!class_exists('Gmedia')) {
|
|
393 |
}
|
394 |
|
395 |
|
396 |
-
if(!wp_script_is('jplayer', 'registered') || version_compare($wp_scripts->registered['jplayer']->ver, '2.6.4', '<'))
|
397 |
wp_deregister_script('jplayer');
|
398 |
wp_register_script('jplayer', $gmCore->gmedia_url . '/assets/jplayer/jquery.jplayer.min.js', array('jquery'), '2.6.4', true);
|
399 |
}
|
400 |
-
if(!wp_script_is('swfobject', 'registered') || version_compare($wp_scripts->registered['swfobject']->ver, '2.2', '<'))
|
401 |
wp_deregister_script('swfobject');
|
402 |
wp_register_script('swfobject', $gmCore->gmedia_url . '/assets/swf/swfobject.js', array(), '2.2', true);
|
403 |
wp_register_script('swfaddress', $gmCore->gmedia_url . '/assets/swf/swfaddress.js', array(), '2.4', true);
|
@@ -408,55 +411,53 @@ if(!class_exists('Gmedia')) {
|
|
408 |
$this->load_scripts();
|
409 |
}
|
410 |
|
411 |
-
function load_scripts()
|
412 |
wp_enqueue_script('jquery');
|
413 |
wp_enqueue_script('gmedia-global-frontend');
|
414 |
}
|
415 |
|
416 |
-
function load_module_scripts()
|
417 |
global $wp_styles;
|
418 |
$deps = array();
|
419 |
-
foreach($this->do_module as $m => $module)
|
420 |
$deps = array_merge($deps, explode(',', $module['info']['dependencies']));
|
421 |
$deps = apply_filters('gmedia_module_js_dependencies', $deps, $m);
|
422 |
-
foreach($deps as $handle)
|
423 |
-
if(wp_script_is($handle, 'registered'))
|
424 |
wp_enqueue_script($handle, $_src = false, $_deps = array('jquery'), $_ver = false, $_in_footer = true);
|
425 |
}
|
426 |
-
if(wp_style_is($handle, 'registered'))
|
427 |
//wp_print_styles($handle);
|
428 |
-
$this->import_styles[] = $wp_styles->registered[$handle]->src;
|
429 |
}
|
430 |
}
|
431 |
$files = glob($module['path'] . '/css/*.css', GLOB_NOSORT);
|
432 |
-
if(!empty($files))
|
433 |
$files = array_map('basename', $files);
|
434 |
-
foreach($files as $file)
|
435 |
$this->import_styles[] = "{$module['url']}/css/{$file}";
|
436 |
}
|
437 |
}
|
438 |
$files = glob($module['path'] . '/js/*.js', GLOB_NOSORT);
|
439 |
-
if(!empty($files))
|
440 |
$files = array_map('basename', $files);
|
441 |
-
foreach($files as $file)
|
442 |
wp_enqueue_script($file, "{$module['url']}/js/{$file}", array('jquery'), false, true);
|
443 |
}
|
444 |
}
|
445 |
}
|
446 |
$this->do_module = array();
|
447 |
-
if(!empty($this->import_styles))
|
448 |
-
add_action('gmedia_head', array(&$this, 'print_import_styles'));
|
449 |
-
add_action('gmedia_footer', array(&$this, 'print_import_styles'));
|
450 |
add_action('wp_print_head_scripts', array(&$this, 'print_import_styles'), 1);
|
451 |
add_action('wp_print_footer_scripts', array(&$this, 'print_import_styles'), 1);
|
452 |
}
|
453 |
}
|
454 |
|
455 |
-
function print_import_styles()
|
456 |
-
if(!empty($this->import_styles))
|
457 |
echo "\n<style type='text/css'>";
|
458 |
-
foreach($this->import_styles as $src)
|
459 |
-
if('http' !== substr($src, 0, 4))
|
460 |
$src = site_url($src);
|
461 |
}
|
462 |
echo "\n@import url('{$src}') all;";
|
@@ -476,19 +477,19 @@ if(!class_exists('Gmedia')) {
|
|
476 |
*
|
477 |
* @return void
|
478 |
*/
|
479 |
-
static function network_propagate($pfunction, $networkwide)
|
480 |
|
481 |
include_once(dirname(__FILE__) . '/config/setup.php');
|
482 |
|
483 |
-
if(function_exists('is_multisite') && is_multisite())
|
484 |
// check if it is a network activation - if so, run the activation function
|
485 |
// for each blog id
|
486 |
-
if($networkwide)
|
487 |
global $wpdb;
|
488 |
//$old_blog = $wpdb->blogid;
|
489 |
// Get all blog ids
|
490 |
$blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
|
491 |
-
foreach($blogids as $blog_id)
|
492 |
switch_to_blog($blog_id);
|
493 |
call_user_func($pfunction);
|
494 |
}
|
@@ -504,18 +505,18 @@ if(!class_exists('Gmedia')) {
|
|
504 |
/**
|
505 |
* @param $networkwide
|
506 |
*/
|
507 |
-
function activate($networkwide)
|
508 |
$this->network_propagate('gmedia_install', $networkwide);
|
509 |
}
|
510 |
|
511 |
/**
|
512 |
* @param $networkwide
|
513 |
*/
|
514 |
-
function deactivate($networkwide)
|
515 |
$this->network_propagate('gmedia_deactivate', $networkwide);
|
516 |
}
|
517 |
|
518 |
-
function gmedia_app_cronjob()
|
519 |
global $gmCore;
|
520 |
$gmCore->app_service('app_updatecron');
|
521 |
}
|
@@ -535,8 +536,8 @@ if(!class_exists('Gmedia')) {
|
|
535 |
* @param $site_id
|
536 |
* @param $meta
|
537 |
*/
|
538 |
-
function new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta)
|
539 |
-
if(is_plugin_active_for_network(GMEDIA_FOLDER . '/grand-media.php'))
|
540 |
include_once(dirname(__FILE__) . '/config/setup.php');
|
541 |
switch_to_blog($blog_id);
|
542 |
gmedia_install();
|
@@ -548,7 +549,7 @@ if(!class_exists('Gmedia')) {
|
|
548 |
* @param $user_id
|
549 |
* @param $reassign
|
550 |
*/
|
551 |
-
function reassign_media($user_id, $reassign)
|
552 |
global $gmDB;
|
553 |
$gmDB->reassign_media($user_id, $reassign);
|
554 |
}
|
@@ -556,38 +557,61 @@ if(!class_exists('Gmedia')) {
|
|
556 |
/**
|
557 |
* Register Gmedia Post Types
|
558 |
*/
|
559 |
-
function gmedia_post_type()
|
560 |
-
$args = array(
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
'rewrite' => array('slug' => $this->options['gmedia_post_slug'])
|
574 |
);
|
575 |
register_post_type('gmedia', $args);
|
576 |
|
577 |
$args['label'] = __('Gmedia Albums', 'grand-media');
|
578 |
$args['hierarchical'] = true;
|
|
|
579 |
$args['exclude_from_search'] = (bool)$this->options['gmedia_album_exclude_from_search'];
|
580 |
$args['rewrite'] = array('slug' => $this->options['gmedia_album_post_slug']);
|
581 |
register_post_type('gmedia_album', $args);
|
582 |
|
583 |
$args['label'] = __('Gmedia Galleries', 'grand-media');
|
584 |
$args['show_in_nav_menus'] = true;
|
|
|
585 |
$args['exclude_from_search'] = (bool)$this->options['gmedia_gallery_exclude_from_search'];
|
586 |
$args['rewrite'] = array('slug' => $this->options['gmedia_gallery_post_slug']);
|
587 |
register_post_type('gmedia_gallery', $args);
|
588 |
|
589 |
add_filter('get_edit_post_link', array($this, 'gmedia_post_type_edit_link'), 10, 3);
|
590 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
}
|
592 |
|
593 |
/**
|
@@ -599,29 +623,29 @@ if(!class_exists('Gmedia')) {
|
|
599 |
*
|
600 |
* @return string|void
|
601 |
*/
|
602 |
-
function gmedia_post_type_edit_link($link, $post_ID, $context)
|
603 |
$post = get_post($post_ID);
|
604 |
-
if(isset($post->ID) && 'gmedia' == substr($post->post_type, 0, 6))
|
605 |
global $gmDB;
|
606 |
-
if($post->post_type == 'gmedia')
|
607 |
$gmedia_id = get_post_meta($post->ID, '_gmedia_ID', true);
|
608 |
$gmedia = $gmDB->get_gmedia($gmedia_id);
|
609 |
-
if($gmedia)
|
610 |
-
$link = admin_url("admin.php?page=GrandMedia&
|
611 |
-
} else
|
612 |
wp_delete_post($post->ID, true);
|
613 |
$link = '#';
|
614 |
}
|
615 |
-
} else
|
616 |
-
$term_id
|
617 |
-
$term
|
618 |
-
if($term)
|
619 |
-
if($term->taxonomy == 'gmedia_album')
|
620 |
$link = admin_url("admin.php?page=GrandMedia_Albums&edit_item={$term->term_id}");
|
621 |
-
} elseif($term->taxonomy == 'gmedia_gallery')
|
622 |
$link = admin_url("admin.php?page=GrandMedia_Galleries&edit_item={$term->term_id}");
|
623 |
}
|
624 |
-
} else
|
625 |
wp_delete_post($post->ID, true);
|
626 |
$link = '#';
|
627 |
}
|
@@ -632,11 +656,10 @@ if(!class_exists('Gmedia')) {
|
|
632 |
}
|
633 |
|
634 |
|
635 |
-
function gmedia_cron_schedules(
|
636 |
-
$gmedia_shedules = array(
|
637 |
-
'gmedia_app' => array( 'interval' => 5 * DAY_IN_SECONDS, 'display' => __( 'Gmedia App Defined' ) )
|
638 |
);
|
639 |
-
$shedules
|
640 |
|
641 |
return $shedules;
|
642 |
}
|
3 |
* Plugin Name: Gmedia Gallery
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/grand-media/
|
5 |
* Description: Gmedia Gallery - powerful media library plugin for creating beautiful galleries and managing files.
|
6 |
+
* Version: 1.8.80
|
7 |
* Author: Rattus
|
8 |
* Author URI: http://codeasily.com/
|
9 |
* Requires at least: 3.6
|
10 |
+
* Tested up to: 4.5.2
|
11 |
* Text Domain: grand-media
|
12 |
* Domain Path: /lang
|
13 |
*
|
32 |
*/
|
33 |
|
34 |
// Stop direct call
|
35 |
+
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])){
|
36 |
die('You are not allowed to call this page directly.');
|
37 |
}
|
38 |
|
39 |
+
if(!class_exists('Gmedia')){
|
40 |
/**
|
41 |
* Class Gmedia
|
42 |
*/
|
43 |
+
class Gmedia{
|
44 |
|
45 |
+
var $version = '1.8.80';
|
46 |
var $dbversion = '1.8.0';
|
47 |
var $minium_WP = '3.6';
|
48 |
var $options = '';
|
53 |
/**
|
54 |
*
|
55 |
*/
|
56 |
+
function __construct(){
|
57 |
|
58 |
// Stop the plugin if we missed the requirements
|
59 |
+
if(!$this->required_version()){
|
60 |
return;
|
61 |
}
|
62 |
|
71 |
require_once(dirname(__FILE__) . '/inc/db.connect.php');
|
72 |
require_once(dirname(__FILE__) . '/inc/permalinks.php');
|
73 |
|
74 |
+
if($this->options['debug_mode']){
|
75 |
ini_set('display_errors', true);
|
76 |
error_reporting(E_ALL);
|
77 |
+
} else{
|
78 |
@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
|
79 |
error_reporting(E_CORE_ERROR | E_COMPILE_ERROR | E_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);
|
80 |
}
|
112 |
|
113 |
}
|
114 |
|
115 |
+
function start_plugin(){
|
116 |
|
117 |
$this->load_dependencies();
|
118 |
$this->compatibility();
|
123 |
// Check for upgrade
|
124 |
$this->upgrade();
|
125 |
|
126 |
+
require_once(dirname(__FILE__) . '/inc/hashids.php');
|
127 |
+
require_once(dirname(__FILE__) . '/inc/shortcodes.php');
|
128 |
+
|
129 |
// Load the admin panel or the frontend functions
|
130 |
+
if(is_admin()){
|
131 |
|
132 |
// Pass the init check or show a message
|
133 |
+
if(get_option('gmediaActivated')){
|
134 |
add_action('init', array(&$this, 'gmedia_after_activation'));
|
135 |
}
|
136 |
|
137 |
// Pass the init check or show a message
|
138 |
+
if(get_option('gmediaInitCheck')){
|
139 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
140 |
}
|
141 |
|
143 |
|
144 |
require_once(dirname(__FILE__) . '/admin/class.processor.php');
|
145 |
|
146 |
+
} else{
|
147 |
|
148 |
// Add the script and style files
|
149 |
//add_action('wp_enqueue_scripts', array(&$this, 'load_scripts'), 4);
|
154 |
add_action('wp_head', array(&$this, 'gmedia_head_meta'));
|
155 |
add_action('wp_footer', array(&$this, 'load_module_scripts'));
|
156 |
|
|
|
|
|
|
|
157 |
}
|
158 |
|
159 |
+
add_action('gmedia_head', array(&$this, 'gmedia_head_meta'));
|
160 |
+
add_action('gmedia_head', array(&$this, 'load_scripts'), 2);
|
161 |
+
add_action('gmedia_head', 'wp_print_head_scripts', 9);
|
162 |
+
add_action('gmedia_enqueue_scripts', array(&$this, 'load_module_scripts'));
|
163 |
+
|
164 |
+
add_action('gmedia_head', array(&$this, 'print_import_styles'));
|
165 |
+
add_action('gmedia_footer', array(&$this, 'print_import_styles'));
|
166 |
+
|
167 |
}
|
168 |
|
169 |
+
function gmedia_head_meta(){
|
170 |
+
$lk = strtolower($this->options['license_key']);
|
171 |
$db_version = get_option('gmediaDbVersion');
|
172 |
echo "\n<!-- <meta name='GmediaGallery' version='{$this->version}/{$db_version}' license='{$lk}' /> -->\n";
|
173 |
}
|
174 |
|
175 |
+
function admin_notices(){
|
176 |
echo '<div id="message" class="error"><p><strong>' . get_option('gmediaInitCheck') . '</strong></p></div>';
|
177 |
delete_option('gmediaInitCheck');
|
178 |
}
|
180 |
/**
|
181 |
* @return bool
|
182 |
*/
|
183 |
+
function required_version(){
|
184 |
global $wp_version;
|
185 |
|
186 |
// Check for WP version installation
|
187 |
+
if(version_compare($wp_version, $this->minium_WP, '<')){
|
188 |
+
$note = sprintf(__('Sorry, Gmedia Gallery works only under WordPress %s or higher', 'grand-media'), $this->minium_WP);
|
|
|
189 |
update_option('gmediaInitCheck', $note);
|
190 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
191 |
|
192 |
return false;
|
193 |
}
|
194 |
+
if(version_compare('5.2', phpversion(), '>')){
|
195 |
+
$note = sprintf(__('Attention! Your server php version is: %s. Gmedia Gallery requires php version 5.2+ in order to run properly. Please upgrade your server!', 'grand-media'), phpversion());
|
|
|
196 |
update_option('gmediaInitCheck', $note);
|
197 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
198 |
}
|
199 |
+
if(version_compare('5.3', phpversion(), '>')){
|
200 |
+
if(ini_get('safe_mode')){
|
201 |
+
$note = __('Attention! Your server safe mode is: ON. Gmedia Gallery requires safe mode to be OFF in order to run properly. Please set your server safe mode option!', 'grand-media');
|
|
|
202 |
update_option('gmediaInitCheck', $note);
|
203 |
add_action('admin_notices', array(&$this, 'admin_notices'));
|
204 |
}
|
210 |
/**
|
211 |
* Called via Setup and register_activate hook after gmedia_install() function
|
212 |
*/
|
213 |
+
function gmedia_after_activation(){
|
214 |
+
//global $gmCore;
|
215 |
|
216 |
delete_option('gmediaActivated');
|
217 |
|
218 |
flush_rewrite_rules(false);
|
219 |
|
220 |
+
//$gmCore->app_service('app_activateplugin');
|
221 |
}
|
222 |
|
223 |
+
function upgrade(){
|
224 |
// Queue upgrades
|
225 |
$current_version = get_option('gmediaVersion', null);
|
226 |
$current_db_version = get_option('gmediaDbVersion', null);
|
227 |
|
228 |
+
if(null === $current_db_version){
|
229 |
add_option("gmediaDbVersion", GMEDIA_DBVERSION);
|
230 |
+
} elseif(version_compare($current_db_version, GMEDIA_DBVERSION, '<')){
|
231 |
require_once(dirname(__FILE__) . '/config/update.php');
|
232 |
|
233 |
+
if(get_transient('gmediaUpgrade') || (isset($_GET['do_update']) && ('gmedia' == $_GET['do_update']))){
|
234 |
add_action('admin_notices', 'gmedia_upgrade_process_admin_notice');
|
235 |
+
} else{
|
236 |
add_action('admin_notices', 'gmedia_upgrade_required_admin_notice');
|
237 |
}
|
238 |
}
|
239 |
|
240 |
+
if(null === $current_version){
|
241 |
require_once(dirname(__FILE__) . '/config/update.php');
|
242 |
|
243 |
add_option("gmediaVersion", GMEDIA_VERSION);
|
244 |
add_action('init', 'gmedia_flush_rewrite_rules', 1000);
|
245 |
+
} elseif(version_compare($current_version, GMEDIA_VERSION, '<')){
|
246 |
require_once(dirname(__FILE__) . '/config/update.php');
|
247 |
|
248 |
gmedia_quite_update();
|
249 |
add_action('init', 'gmedia_flush_rewrite_rules', 1000);
|
250 |
|
251 |
+
if(!wp_get_schedule('gmedia_app_cronjob')){
|
252 |
wp_schedule_event(time(), 'gmedia_app', 'gmedia_app_cronjob');
|
253 |
}
|
254 |
}
|
255 |
|
256 |
}
|
257 |
|
258 |
+
function define_tables(){
|
259 |
global $wpdb;
|
260 |
|
261 |
// add database pointer
|
267 |
|
268 |
}
|
269 |
|
270 |
+
function define_constant(){
|
271 |
|
272 |
define('GMEDIA_VERSION', $this->version);
|
273 |
// Minimum required database version
|
275 |
|
276 |
}
|
277 |
|
278 |
+
function load_options(){
|
279 |
include_once(dirname(__FILE__) . '/config/setup.php');
|
280 |
// Load the options
|
281 |
$default_options = gmedia_default_options();
|
283 |
if(!is_array($db_options)){
|
284 |
$db_options = array();
|
285 |
}
|
286 |
+
$this->options = array_merge($default_options, $db_options);
|
287 |
}
|
288 |
|
289 |
+
function load_dependencies(){
|
290 |
|
291 |
// We didn't need all stuff during a AJAX operation
|
292 |
+
if(defined('DOING_AJAX')){
|
293 |
require_once(dirname(__FILE__) . '/admin/ajax.php');
|
294 |
+
} else{
|
|
|
295 |
|
296 |
// Load backend libraries
|
297 |
+
if(is_admin()){
|
298 |
require_once(dirname(__FILE__) . '/inc/media-upload.php');
|
299 |
require_once(dirname(__FILE__) . '/inc/post-metabox.php');
|
300 |
|
301 |
require_once(dirname(__FILE__) . '/admin/admin.php');
|
302 |
|
303 |
// Load frontend libraries
|
|
|
|
|
304 |
}
|
305 |
|
306 |
$current_plugins = get_option('active_plugins');
|
307 |
+
if(in_array('wordpress-seo/wp-seo.php', $current_plugins)){
|
308 |
require_once(dirname(__FILE__) . '/inc/sitemap.php');
|
309 |
}
|
310 |
}
|
311 |
|
312 |
}
|
313 |
|
314 |
+
function compatibility(){
|
315 |
require_once(dirname(__FILE__) . '/inc/compatibility.php');
|
316 |
}
|
317 |
|
318 |
+
function load_textdomain(){
|
319 |
|
320 |
load_plugin_textdomain('grand-media', false, GMEDIA_FOLDER . '/lang/');
|
321 |
|
322 |
}
|
323 |
|
324 |
+
function register_scripts_backend(){
|
325 |
global $gmCore;
|
326 |
|
327 |
+
wp_register_script('gmedia-global-backend', $gmCore->gmedia_url . '/admin/assets/js/gmedia.global.js', array('jquery'), '1.8.26');
|
328 |
+
wp_localize_script('gmedia-global-backend', 'GmediaGallery', array('ajaxurl' => admin_url('admin-ajax.php'),
|
329 |
+
'nonce' => wp_create_nonce('GmediaGallery'),
|
330 |
+
'upload_dirurl' => $gmCore->upload['url'],
|
331 |
+
'plugin_dirurl' => $gmCore->gmedia_url
|
|
|
332 |
));
|
333 |
|
334 |
+
wp_register_style('grand-media', $gmCore->gmedia_url . '/admin/assets/css/gmedia.admin.css', array(), '1.8.80', 'all');
|
335 |
+
wp_register_script('grand-media', $gmCore->gmedia_url . '/admin/assets/js/gmedia.admin.js', array('jquery', 'gmedia-global-backend'), '1.8.80');
|
336 |
+
wp_localize_script('grand-media', 'grandMedia', array('error3' => __('Disable your Popup Blocker and try again.', 'grand-media'),
|
337 |
+
'download' => __('downloading...', 'grand-media'),
|
338 |
+
'wait' => __('Working. Wait please.', 'grand-media'),
|
339 |
+
'nonce' => wp_create_nonce('grandMedia')
|
|
|
340 |
));
|
341 |
|
342 |
wp_register_style('gmedia-bootstrap', $gmCore->gmedia_url . '/assets/bootstrap/css/bootstrap.min.css', array(), '3.3.4', 'all');
|
346 |
|
347 |
}
|
348 |
|
349 |
+
function register_scripts_frontend(){
|
350 |
global $gmCore, $wp_scripts;
|
351 |
|
352 |
+
wp_register_script('gmedia-global-frontend', $gmCore->gmedia_url . '/assets/gmedia.global.front.js', array('jquery'), '1.8.24');
|
353 |
+
wp_localize_script('gmedia-global-frontend', 'GmediaGallery', array('ajaxurl' => admin_url('admin-ajax.php'),
|
354 |
+
'nonce' => wp_create_nonce('GmediaGallery'),
|
355 |
+
'upload_dirurl' => $gmCore->upload['url'],
|
356 |
+
'plugin_dirurl' => $gmCore->upload['url'],
|
357 |
+
'license' => strtolower($this->options['license_key']),
|
358 |
+
'license2' => $this->options['license_key2']
|
|
|
359 |
));
|
360 |
|
361 |
|
362 |
+
if(!wp_script_is('mediaelement', 'registered')){
|
363 |
wp_register_style('mediaelement', $gmCore->gmedia_url . '/assets/mediaelement/mediaelementplayer.min.css', array(), '2.13.0', 'screen');
|
364 |
wp_register_script('mediaelement', $gmCore->gmedia_url . '/assets/mediaelement/mediaelement-and-player.min.js', array('jquery'), '2.13.0', true);
|
365 |
}
|
366 |
|
367 |
+
if(!wp_script_is('wavesurfer', 'registered')){
|
368 |
+
wp_register_script('wavesurfer', $gmCore->gmedia_url . '/assets/wavesurfer/wavesurfer.min.js', array('jquery'), '1.1.5', true);
|
369 |
+
}
|
370 |
+
|
371 |
+
if(!wp_script_is('magnific-popup', 'registered') || version_compare($wp_scripts->registered['magnific-popup']->ver, '1.0.2', '<')){
|
372 |
wp_deregister_style('magnific-popup');
|
373 |
wp_deregister_script('magnific-popup');
|
374 |
wp_register_style('magnific-popup', $gmCore->gmedia_url . '/assets/mag-popup/magnific-popup.css', array(), '1.0.2', 'screen');
|
375 |
wp_register_script('magnific-popup', $gmCore->gmedia_url . '/assets/mag-popup/jquery.magnific-popup.min.js', array('jquery'), '1.0.2', true);
|
376 |
}
|
377 |
|
378 |
+
if(!wp_script_is('photoswipe', 'registered') || version_compare($wp_scripts->registered['photoswipe']->ver, '3.0.5', '<=')){
|
379 |
wp_deregister_style('photoswipe');
|
380 |
wp_deregister_script('photoswipe');
|
381 |
wp_register_style('photoswipe', $gmCore->gmedia_url . '/assets/photoswipe/photoswipe.css', array(), '3.0.5', 'screen');
|
382 |
wp_register_script('photoswipe', $gmCore->gmedia_url . '/assets/photoswipe/photoswipe.jquery.min.js', array('jquery'), '3.0.5', true);
|
383 |
}
|
384 |
|
385 |
+
if(!wp_script_is('easing', 'registered') || version_compare($wp_scripts->registered['easing']->ver, '1.3.0', '<')){
|
386 |
wp_deregister_script('easing');
|
387 |
wp_register_script('easing', $gmCore->gmedia_url . '/assets/jq-plugins/jquery.easing.js', array('jquery'), '1.3.0', true);
|
388 |
}
|
389 |
+
if(!wp_script_is('fancybox', 'registered') || version_compare($wp_scripts->registered['fancybox']->ver, '1.3.4', '<')){
|
390 |
+
if(!defined('FANCYBOX_VERSION')){
|
391 |
wp_deregister_style('fancybox');
|
392 |
wp_register_style('fancybox', $gmCore->gmedia_url . '/assets/fancybox/jquery.fancybox-1.3.4.css', array(), '1.3.4');
|
393 |
}
|
396 |
}
|
397 |
|
398 |
|
399 |
+
if(!wp_script_is('jplayer', 'registered') || version_compare($wp_scripts->registered['jplayer']->ver, '2.6.4', '<')){
|
400 |
wp_deregister_script('jplayer');
|
401 |
wp_register_script('jplayer', $gmCore->gmedia_url . '/assets/jplayer/jquery.jplayer.min.js', array('jquery'), '2.6.4', true);
|
402 |
}
|
403 |
+
if(!wp_script_is('swfobject', 'registered') || version_compare($wp_scripts->registered['swfobject']->ver, '2.2', '<')){
|
404 |
wp_deregister_script('swfobject');
|
405 |
wp_register_script('swfobject', $gmCore->gmedia_url . '/assets/swf/swfobject.js', array(), '2.2', true);
|
406 |
wp_register_script('swfaddress', $gmCore->gmedia_url . '/assets/swf/swfaddress.js', array(), '2.4', true);
|
411 |
$this->load_scripts();
|
412 |
}
|
413 |
|
414 |
+
function load_scripts(){
|
415 |
wp_enqueue_script('jquery');
|
416 |
wp_enqueue_script('gmedia-global-frontend');
|
417 |
}
|
418 |
|
419 |
+
function load_module_scripts(){
|
420 |
global $wp_styles;
|
421 |
$deps = array();
|
422 |
+
foreach($this->do_module as $m => $module){
|
423 |
$deps = array_merge($deps, explode(',', $module['info']['dependencies']));
|
424 |
$deps = apply_filters('gmedia_module_js_dependencies', $deps, $m);
|
425 |
+
foreach($deps as $handle){
|
426 |
+
if(wp_script_is($handle, 'registered')){
|
427 |
wp_enqueue_script($handle, $_src = false, $_deps = array('jquery'), $_ver = false, $_in_footer = true);
|
428 |
}
|
429 |
+
if(wp_style_is($handle, 'registered')){
|
430 |
//wp_print_styles($handle);
|
431 |
+
$this->import_styles[] = $wp_styles->registered[ $handle ]->src;
|
432 |
}
|
433 |
}
|
434 |
$files = glob($module['path'] . '/css/*.css', GLOB_NOSORT);
|
435 |
+
if(!empty($files)){
|
436 |
$files = array_map('basename', $files);
|
437 |
+
foreach($files as $file){
|
438 |
$this->import_styles[] = "{$module['url']}/css/{$file}";
|
439 |
}
|
440 |
}
|
441 |
$files = glob($module['path'] . '/js/*.js', GLOB_NOSORT);
|
442 |
+
if(!empty($files)){
|
443 |
$files = array_map('basename', $files);
|
444 |
+
foreach($files as $file){
|
445 |
wp_enqueue_script($file, "{$module['url']}/js/{$file}", array('jquery'), false, true);
|
446 |
}
|
447 |
}
|
448 |
}
|
449 |
$this->do_module = array();
|
450 |
+
if(!empty($this->import_styles)){
|
|
|
|
|
451 |
add_action('wp_print_head_scripts', array(&$this, 'print_import_styles'), 1);
|
452 |
add_action('wp_print_footer_scripts', array(&$this, 'print_import_styles'), 1);
|
453 |
}
|
454 |
}
|
455 |
|
456 |
+
function print_import_styles(){
|
457 |
+
if(!empty($this->import_styles)){
|
458 |
echo "\n<style type='text/css'>";
|
459 |
+
foreach($this->import_styles as $src){
|
460 |
+
if('http' !== substr($src, 0, 4)){
|
461 |
$src = site_url($src);
|
462 |
}
|
463 |
echo "\n@import url('{$src}') all;";
|
477 |
*
|
478 |
* @return void
|
479 |
*/
|
480 |
+
static function network_propagate($pfunction, $networkwide){
|
481 |
|
482 |
include_once(dirname(__FILE__) . '/config/setup.php');
|
483 |
|
484 |
+
if(function_exists('is_multisite') && is_multisite()){
|
485 |
// check if it is a network activation - if so, run the activation function
|
486 |
// for each blog id
|
487 |
+
if($networkwide){
|
488 |
global $wpdb;
|
489 |
//$old_blog = $wpdb->blogid;
|
490 |
// Get all blog ids
|
491 |
$blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
|
492 |
+
foreach($blogids as $blog_id){
|
493 |
switch_to_blog($blog_id);
|
494 |
call_user_func($pfunction);
|
495 |
}
|
505 |
/**
|
506 |
* @param $networkwide
|
507 |
*/
|
508 |
+
function activate($networkwide){
|
509 |
$this->network_propagate('gmedia_install', $networkwide);
|
510 |
}
|
511 |
|
512 |
/**
|
513 |
* @param $networkwide
|
514 |
*/
|
515 |
+
function deactivate($networkwide){
|
516 |
$this->network_propagate('gmedia_deactivate', $networkwide);
|
517 |
}
|
518 |
|
519 |
+
function gmedia_app_cronjob(){
|
520 |
global $gmCore;
|
521 |
$gmCore->app_service('app_updatecron');
|
522 |
}
|
536 |
* @param $site_id
|
537 |
* @param $meta
|
538 |
*/
|
539 |
+
function new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta){
|
540 |
+
if(is_plugin_active_for_network(GMEDIA_FOLDER . '/grand-media.php')){
|
541 |
include_once(dirname(__FILE__) . '/config/setup.php');
|
542 |
switch_to_blog($blog_id);
|
543 |
gmedia_install();
|
549 |
* @param $user_id
|
550 |
* @param $reassign
|
551 |
*/
|
552 |
+
function reassign_media($user_id, $reassign){
|
553 |
global $gmDB;
|
554 |
$gmDB->reassign_media($user_id, $reassign);
|
555 |
}
|
557 |
/**
|
558 |
* Register Gmedia Post Types
|
559 |
*/
|
560 |
+
function gmedia_post_type(){
|
561 |
+
$args = array('label' => __('Gmedia Posts', 'grand-media'),
|
562 |
+
'supports' => array('comments'),
|
563 |
+
'hierarchical' => false,
|
564 |
+
'public' => true,
|
565 |
+
'show_ui' => false,
|
566 |
+
'show_in_menu' => false,
|
567 |
+
'show_in_admin_bar' => true,
|
568 |
+
'show_in_nav_menus' => false,
|
569 |
+
'can_export' => false,
|
570 |
+
'has_archive' => (bool)$this->options['gmedia_has_archive'], //'gmedia-library',
|
571 |
+
'publicly_queryable' => true,
|
572 |
+
'exclude_from_search' => (bool)$this->options['gmedia_exclude_from_search'],
|
573 |
+
'rewrite' => array('slug' => $this->options['gmedia_post_slug'])
|
|
|
574 |
);
|
575 |
register_post_type('gmedia', $args);
|
576 |
|
577 |
$args['label'] = __('Gmedia Albums', 'grand-media');
|
578 |
$args['hierarchical'] = true;
|
579 |
+
$args['has_archive'] = (bool)$this->options['gmedia_album_has_archive'];
|
580 |
$args['exclude_from_search'] = (bool)$this->options['gmedia_album_exclude_from_search'];
|
581 |
$args['rewrite'] = array('slug' => $this->options['gmedia_album_post_slug']);
|
582 |
register_post_type('gmedia_album', $args);
|
583 |
|
584 |
$args['label'] = __('Gmedia Galleries', 'grand-media');
|
585 |
$args['show_in_nav_menus'] = true;
|
586 |
+
$args['has_archive'] = (bool)$this->options['gmedia_gallery_has_archive'];
|
587 |
$args['exclude_from_search'] = (bool)$this->options['gmedia_gallery_exclude_from_search'];
|
588 |
$args['rewrite'] = array('slug' => $this->options['gmedia_gallery_post_slug']);
|
589 |
register_post_type('gmedia_gallery', $args);
|
590 |
|
591 |
add_filter('get_edit_post_link', array($this, 'gmedia_post_type_edit_link'), 10, 3);
|
592 |
|
593 |
+
|
594 |
+
$args = array('hierarchical' => false,
|
595 |
+
'public' => true,
|
596 |
+
'show_ui' => false,
|
597 |
+
'show_admin_column' => false,
|
598 |
+
'show_in_nav_menus' => false,
|
599 |
+
'show_tagcloud' => false,
|
600 |
+
'rewrite' => array('slug' => 'gmedia-category')
|
601 |
+
);
|
602 |
+
$args['labels'] = array('name' => _x('Categories', 'Taxonomy General Name', 'grand-media'),
|
603 |
+
'singular_name' => _x('Category', 'Taxonomy Singular Name', 'grand-media'),
|
604 |
+
'menu_name' => __('Categories', 'grand-media')
|
605 |
+
);
|
606 |
+
register_taxonomy('gmedia_category', array('gmedia'), $args);
|
607 |
+
|
608 |
+
$args['rewrite'] = array('slug' => 'gmedia-tag');
|
609 |
+
$args['labels'] = array('name' => _x('Tags', 'Taxonomy General Name', 'grand-media'),
|
610 |
+
'singular_name' => _x('Tag', 'Taxonomy Singular Name', 'grand-media'),
|
611 |
+
'menu_name' => __('Tags', 'grand-media')
|
612 |
+
);
|
613 |
+
register_taxonomy('gmedia_tag', array('gmedia'), $args);
|
614 |
+
|
615 |
}
|
616 |
|
617 |
/**
|
623 |
*
|
624 |
* @return string|void
|
625 |
*/
|
626 |
+
function gmedia_post_type_edit_link($link, $post_ID, $context){
|
627 |
$post = get_post($post_ID);
|
628 |
+
if(isset($post->ID) && 'gmedia' == substr($post->post_type, 0, 6)){
|
629 |
global $gmDB;
|
630 |
+
if($post->post_type == 'gmedia'){
|
631 |
$gmedia_id = get_post_meta($post->ID, '_gmedia_ID', true);
|
632 |
$gmedia = $gmDB->get_gmedia($gmedia_id);
|
633 |
+
if($gmedia){
|
634 |
+
$link = admin_url("admin.php?page=GrandMedia&mode=edit&gmedia__in={$gmedia->ID}");
|
635 |
+
} else{
|
636 |
wp_delete_post($post->ID, true);
|
637 |
$link = '#';
|
638 |
}
|
639 |
+
} else{
|
640 |
+
$term_id = get_post_meta($post->ID, '_gmedia_term_ID', true);
|
641 |
+
$term = $gmDB->get_term($term_id);
|
642 |
+
if($term){
|
643 |
+
if($term->taxonomy == 'gmedia_album'){
|
644 |
$link = admin_url("admin.php?page=GrandMedia_Albums&edit_item={$term->term_id}");
|
645 |
+
} elseif($term->taxonomy == 'gmedia_gallery'){
|
646 |
$link = admin_url("admin.php?page=GrandMedia_Galleries&edit_item={$term->term_id}");
|
647 |
}
|
648 |
+
} else{
|
649 |
wp_delete_post($post->ID, true);
|
650 |
$link = '#';
|
651 |
}
|
656 |
}
|
657 |
|
658 |
|
659 |
+
function gmedia_cron_schedules($shedules){
|
660 |
+
$gmedia_shedules = array('gmedia_app' => array('interval' => 5 * DAY_IN_SECONDS, 'display' => __('Gmedia App Defined'))
|
|
|
661 |
);
|
662 |
+
$shedules = array_merge($shedules, $gmedia_shedules);
|
663 |
|
664 |
return $shedules;
|
665 |
}
|
inc/color.php
ADDED
@@ -0,0 +1,480 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* A color utility that helps manipulate HEX colors
|
5 |
+
*
|
6 |
+
* @link https://github.com/mexitek/phpColors/blob/master/src/Mexitek/PHPColors/Color.php
|
7 |
+
*/
|
8 |
+
class gmColor{
|
9 |
+
private $_hex;
|
10 |
+
private $_hsl;
|
11 |
+
private $_rgb;
|
12 |
+
/**
|
13 |
+
* Auto darkens/lightens by 10% for sexily-subtle gradients.
|
14 |
+
* Set this to FALSE to adjust automatic shade to be between given color
|
15 |
+
* and black (for darken) or white (for lighten)
|
16 |
+
*/
|
17 |
+
const DEFAULT_ADJUST = 10;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Instantiates the class with a HEX value
|
21 |
+
*
|
22 |
+
* @param bool|string $hex
|
23 |
+
*/
|
24 |
+
function __construct( $hex = '#000000' ) {
|
25 |
+
// Strip # sign is present
|
26 |
+
$color = str_replace( "#", "", $hex );
|
27 |
+
// Make sure it's 6 digits
|
28 |
+
$color = self::_checkHex( $color );
|
29 |
+
$this->_hsl = self::hexToHsl( $color );
|
30 |
+
$this->_hex = $color;
|
31 |
+
$this->_rgb = self::hexToRgb( $color );
|
32 |
+
}
|
33 |
+
// ====================
|
34 |
+
// = Public Interface =
|
35 |
+
// ====================
|
36 |
+
/**
|
37 |
+
* Given a HEX string returns a HSL array equivalent.
|
38 |
+
*
|
39 |
+
* @param string $color
|
40 |
+
*
|
41 |
+
* @return array HSL associative array
|
42 |
+
*/
|
43 |
+
public static function hexToHsl( $color ) {
|
44 |
+
// Sanity check
|
45 |
+
$color = self::_checkHex( $color );
|
46 |
+
// Convert HEX to DEC
|
47 |
+
$R = hexdec( $color[0] . $color[1] );
|
48 |
+
$G = hexdec( $color[2] . $color[3] );
|
49 |
+
$B = hexdec( $color[4] . $color[5] );
|
50 |
+
$HSL = array();
|
51 |
+
$var_R = ( $R / 255 );
|
52 |
+
$var_G = ( $G / 255 );
|
53 |
+
$var_B = ( $B / 255 );
|
54 |
+
$var_Min = min( $var_R, $var_G, $var_B );
|
55 |
+
$var_Max = max( $var_R, $var_G, $var_B );
|
56 |
+
$del_Max = $var_Max - $var_Min;
|
57 |
+
$L = ( $var_Max + $var_Min ) / 2;
|
58 |
+
if ( $del_Max == 0 ) {
|
59 |
+
$H = 0;
|
60 |
+
$S = 0;
|
61 |
+
} else {
|
62 |
+
if ( $L < 0.5 ) {
|
63 |
+
$S = $del_Max / ( $var_Max + $var_Min );
|
64 |
+
} else {
|
65 |
+
$S = $del_Max / ( 2 - $var_Max - $var_Min );
|
66 |
+
}
|
67 |
+
$del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
|
68 |
+
$del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
|
69 |
+
$del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
|
70 |
+
if ( $var_R == $var_Max ) {
|
71 |
+
$H = $del_B - $del_G;
|
72 |
+
} else if ( $var_G == $var_Max ) {
|
73 |
+
$H = ( 1 / 3 ) + $del_R - $del_B;
|
74 |
+
} else if ( $var_B == $var_Max ) {
|
75 |
+
$H = ( 2 / 3 ) + $del_G - $del_R;
|
76 |
+
}
|
77 |
+
if ( $H < 0 ) {
|
78 |
+
$H ++;
|
79 |
+
}
|
80 |
+
if ( $H > 1 ) {
|
81 |
+
$H --;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
$HSL['H'] = ( $H * 360 );
|
85 |
+
$HSL['S'] = $S;
|
86 |
+
$HSL['L'] = $L;
|
87 |
+
|
88 |
+
return $HSL;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Given a HSL associative array returns the equivalent HEX string
|
93 |
+
*
|
94 |
+
* @param array $hsl
|
95 |
+
*
|
96 |
+
* @return string HEX string
|
97 |
+
* @throws Exception "Bad HSL Array"
|
98 |
+
*/
|
99 |
+
public static function hslToHex( $hsl = array() ) {
|
100 |
+
// Make sure it's HSL
|
101 |
+
if ( empty( $hsl ) || ! isset( $hsl["H"] ) || ! isset( $hsl["S"] ) || ! isset( $hsl["L"] ) ) {
|
102 |
+
throw new Exception( "Param was not an HSL array" );
|
103 |
+
}
|
104 |
+
list( $H, $S, $L ) = array( $hsl['H'] / 360, $hsl['S'], $hsl['L'] );
|
105 |
+
if ( $S == 0 ) {
|
106 |
+
$r = $L * 255;
|
107 |
+
$g = $L * 255;
|
108 |
+
$b = $L * 255;
|
109 |
+
} else {
|
110 |
+
if ( $L < 0.5 ) {
|
111 |
+
$var_2 = $L * ( 1 + $S );
|
112 |
+
} else {
|
113 |
+
$var_2 = ( $L + $S ) - ( $S * $L );
|
114 |
+
}
|
115 |
+
$var_1 = 2 * $L - $var_2;
|
116 |
+
$r = round( 255 * self::_huetorgb( $var_1, $var_2, $H + ( 1 / 3 ) ) );
|
117 |
+
$g = round( 255 * self::_huetorgb( $var_1, $var_2, $H ) );
|
118 |
+
$b = round( 255 * self::_huetorgb( $var_1, $var_2, $H - ( 1 / 3 ) ) );
|
119 |
+
}
|
120 |
+
// Convert to hex
|
121 |
+
$r = dechex( $r );
|
122 |
+
$g = dechex( $g );
|
123 |
+
$b = dechex( $b );
|
124 |
+
// Make sure we get 2 digits for decimals
|
125 |
+
$r = ( strlen( "" . $r ) === 1 ) ? "0" . $r : $r;
|
126 |
+
$g = ( strlen( "" . $g ) === 1 ) ? "0" . $g : $g;
|
127 |
+
$b = ( strlen( "" . $b ) === 1 ) ? "0" . $b : $b;
|
128 |
+
|
129 |
+
return $r . $g . $b;
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Given a HEX string returns a RGB array equivalent.
|
134 |
+
*
|
135 |
+
* @param string $color
|
136 |
+
*
|
137 |
+
* @return array RGB associative array
|
138 |
+
*/
|
139 |
+
public static function hexToRgb( $color ) {
|
140 |
+
// Sanity check
|
141 |
+
$color = self::_checkHex( $color );
|
142 |
+
// Convert HEX to DEC
|
143 |
+
$R = hexdec( $color[0] . $color[1] );
|
144 |
+
$G = hexdec( $color[2] . $color[3] );
|
145 |
+
$B = hexdec( $color[4] . $color[5] );
|
146 |
+
$RGB['R'] = $R;
|
147 |
+
$RGB['G'] = $G;
|
148 |
+
$RGB['B'] = $B;
|
149 |
+
|
150 |
+
return $RGB;
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Given an RGB associative array returns the equivalent HEX string
|
155 |
+
*
|
156 |
+
* @param array $rgb
|
157 |
+
*
|
158 |
+
* @return string RGB string
|
159 |
+
* @throws Exception "Bad RGB Array"
|
160 |
+
*/
|
161 |
+
public static function rgbToHex( $rgb = array() ) {
|
162 |
+
// Make sure it's RGB
|
163 |
+
if ( empty( $rgb ) || ! isset( $rgb["R"] ) || ! isset( $rgb["G"] ) || ! isset( $rgb["B"] ) ) {
|
164 |
+
throw new Exception( "Param was not an RGB array" );
|
165 |
+
}
|
166 |
+
// https://github.com/mexitek/phpColors/issues/25#issuecomment-88354815
|
167 |
+
// Convert RGB to HEX
|
168 |
+
$hex[0] = str_pad( dechex( $rgb['R'] ), 2, '0', STR_PAD_LEFT );
|
169 |
+
$hex[1] = str_pad( dechex( $rgb['G'] ), 2, '0', STR_PAD_LEFT );
|
170 |
+
$hex[2] = str_pad( dechex( $rgb['B'] ), 2, '0', STR_PAD_LEFT );
|
171 |
+
|
172 |
+
return implode( '', $hex );
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Given a HEX value, returns a darker color. If no desired amount provided, then the color halfway between
|
177 |
+
* given HEX and black will be returned.
|
178 |
+
*
|
179 |
+
* @param int $amount
|
180 |
+
*
|
181 |
+
* @return string Darker HEX value
|
182 |
+
*/
|
183 |
+
public function darken( $amount = self::DEFAULT_ADJUST ) {
|
184 |
+
// Darken
|
185 |
+
$darkerHSL = $this->_darken( $this->_hsl, $amount );
|
186 |
+
|
187 |
+
// Return as HEX
|
188 |
+
return self::hslToHex( $darkerHSL );
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Given a HEX value, returns a lighter color. If no desired amount provided, then the color halfway between
|
193 |
+
* given HEX and white will be returned.
|
194 |
+
*
|
195 |
+
* @param int $amount
|
196 |
+
*
|
197 |
+
* @return string Lighter HEX value
|
198 |
+
*/
|
199 |
+
public function lighten( $amount = self::DEFAULT_ADJUST ) {
|
200 |
+
// Lighten
|
201 |
+
$lighterHSL = $this->_lighten( $this->_hsl, $amount );
|
202 |
+
|
203 |
+
// Return as HEX
|
204 |
+
return self::hslToHex( $lighterHSL );
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Given a HEX value, returns a mixed color. If no desired amount provided, then the color mixed by this ratio
|
209 |
+
*
|
210 |
+
* @param string $hex2 Secondary HEX value to mix with
|
211 |
+
* @param int $amount = -100..0..+100
|
212 |
+
*
|
213 |
+
* @return string mixed HEX value
|
214 |
+
*/
|
215 |
+
public function mix( $hex2, $amount = 0 ) {
|
216 |
+
$rgb2 = self::hexToRgb( $hex2 );
|
217 |
+
$mixed = $this->_mix( $this->_rgb, $rgb2, $amount );
|
218 |
+
|
219 |
+
// Return as HEX
|
220 |
+
return self::rgbToHex( $mixed );
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Creates an array with two shades that can be used to make a gradient
|
225 |
+
*
|
226 |
+
* @param int $amount Optional percentage amount you want your contrast color
|
227 |
+
*
|
228 |
+
* @return array An array with a 'light' and 'dark' index
|
229 |
+
*/
|
230 |
+
public function makeGradient( $amount = self::DEFAULT_ADJUST ) {
|
231 |
+
// Decide which color needs to be made
|
232 |
+
if ( $this->isLight() ) {
|
233 |
+
$lightColor = $this->_hex;
|
234 |
+
$darkColor = $this->darken( $amount );
|
235 |
+
} else {
|
236 |
+
$lightColor = $this->lighten( $amount );
|
237 |
+
$darkColor = $this->_hex;
|
238 |
+
}
|
239 |
+
|
240 |
+
// Return our gradient array
|
241 |
+
return array( "light" => $lightColor, "dark" => $darkColor );
|
242 |
+
}
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Returns whether or not given color is considered "light"
|
246 |
+
*
|
247 |
+
* @param string|Boolean $color
|
248 |
+
* @param int $lighterThan
|
249 |
+
*
|
250 |
+
* @return boolean
|
251 |
+
*/
|
252 |
+
public function isLight( $color = false, $lighterThan = 130 ) {
|
253 |
+
// Get our color
|
254 |
+
$color = ( $color ) ? $color : $this->_hex;
|
255 |
+
// Calculate straight from rbg
|
256 |
+
$r = hexdec( $color[0] . $color[1] );
|
257 |
+
$g = hexdec( $color[2] . $color[3] );
|
258 |
+
$b = hexdec( $color[4] . $color[5] );
|
259 |
+
|
260 |
+
return ( ( $r * 299 + $g * 587 + $b * 114 ) / 1000 > $lighterThan );
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Returns whether or not a given color is considered "dark"
|
265 |
+
*
|
266 |
+
* @param string|Boolean $color
|
267 |
+
* @param int $darkerThan
|
268 |
+
*
|
269 |
+
* @return boolean
|
270 |
+
*/
|
271 |
+
public function isDark( $color = false, $darkerThan = 130 ) {
|
272 |
+
// Get our color
|
273 |
+
$color = ( $color ) ? $color : $this->_hex;
|
274 |
+
// Calculate straight from rbg
|
275 |
+
$r = hexdec( $color[0] . $color[1] );
|
276 |
+
$g = hexdec( $color[2] . $color[3] );
|
277 |
+
$b = hexdec( $color[4] . $color[5] );
|
278 |
+
|
279 |
+
return ( ( $r * 299 + $g * 587 + $b * 114 ) / 1000 <= $darkerThan );
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Returns the complimentary color
|
284 |
+
* @return string Complementary hex color
|
285 |
+
*
|
286 |
+
*/
|
287 |
+
public function complementary() {
|
288 |
+
// Get our HSL
|
289 |
+
$hsl = $this->_hsl;
|
290 |
+
// Adjust Hue 180 degrees
|
291 |
+
$hsl['H'] += ( $hsl['H'] > 180 ) ? - 180 : 180;
|
292 |
+
|
293 |
+
// Return the new value in HEX
|
294 |
+
return self::hslToHex( $hsl );
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Returns your color's HSL array
|
299 |
+
*/
|
300 |
+
public function getHsl() {
|
301 |
+
return $this->_hsl;
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Returns your original color
|
306 |
+
*/
|
307 |
+
public function getHex() {
|
308 |
+
return $this->_hex;
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Returns your color's RGB array
|
313 |
+
*/
|
314 |
+
public function getRgb() {
|
315 |
+
return $this->_rgb;
|
316 |
+
}
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Returns the cross browser CSS3 gradient
|
320 |
+
*
|
321 |
+
* @param int $amount Optional: percentage amount to light/darken the gradient
|
322 |
+
* @param boolean $vintageBrowsers Optional: include vendor prefixes for browsers that almost died out already
|
323 |
+
* @param string $prefix Optional: prefix for every lines
|
324 |
+
* @param string $suffix Optional: suffix for every lines
|
325 |
+
*
|
326 |
+
* @link http://caniuse.com/css-gradients Resource for the browser support
|
327 |
+
* @return string CSS3 gradient for chrome, safari, firefox, opera and IE10
|
328 |
+
*/
|
329 |
+
public function getCssGradient( $amount = self::DEFAULT_ADJUST, $vintageBrowsers = false, $suffix = "", $prefix = "" ) {
|
330 |
+
// Get the recommended gradient
|
331 |
+
$g = $this->makeGradient( $amount );
|
332 |
+
$css = "";
|
333 |
+
/* fallback/image non-cover color */
|
334 |
+
$css .= "{$prefix}background-color: #" . $this->_hex . ";{$suffix}";
|
335 |
+
/* IE Browsers */
|
336 |
+
$css .= "{$prefix}filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#" . $g['light'] . "', endColorstr='#" . $g['dark'] . "');{$suffix}";
|
337 |
+
/* Safari 4+, Chrome 1-9 */
|
338 |
+
if ( $vintageBrowsers ) {
|
339 |
+
$css .= "{$prefix}background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#" . $g['light'] . "), to(#" . $g['dark'] . "));{$suffix}";
|
340 |
+
}
|
341 |
+
/* Safari 5.1+, Mobile Safari, Chrome 10+ */
|
342 |
+
$css .= "{$prefix}background-image: -webkit-linear-gradient(top, #" . $g['light'] . ", #" . $g['dark'] . ");{$suffix}";
|
343 |
+
/* Firefox 3.6+ */
|
344 |
+
if ( $vintageBrowsers ) {
|
345 |
+
$css .= "{$prefix}background-image: -moz-linear-gradient(top, #" . $g['light'] . ", #" . $g['dark'] . ");{$suffix}";
|
346 |
+
}
|
347 |
+
/* Opera 11.10+ */
|
348 |
+
if ( $vintageBrowsers ) {
|
349 |
+
$css .= "{$prefix}background-image: -o-linear-gradient(top, #" . $g['light'] . ", #" . $g['dark'] . ");{$suffix}";
|
350 |
+
}
|
351 |
+
/* Unprefixed version (standards): FF 16+, IE10+, Chrome 26+, Safari 7+, Opera 12.1+ */
|
352 |
+
$css .= "{$prefix}background-image: linear-gradient(to bottom, #" . $g['light'] . ", #" . $g['dark'] . ");{$suffix}";
|
353 |
+
|
354 |
+
// Return our CSS
|
355 |
+
return $css;
|
356 |
+
}
|
357 |
+
// ===========================
|
358 |
+
// = Private Functions Below =
|
359 |
+
// ===========================
|
360 |
+
/**
|
361 |
+
* Darkens a given HSL array
|
362 |
+
*
|
363 |
+
* @param array $hsl
|
364 |
+
* @param int $amount
|
365 |
+
*
|
366 |
+
* @return array $hsl
|
367 |
+
*/
|
368 |
+
private function _darken( $hsl, $amount = self::DEFAULT_ADJUST ) {
|
369 |
+
// Check if we were provided a number
|
370 |
+
if ( $amount ) {
|
371 |
+
if(is_string($amount) && strpos($amount, '%')){
|
372 |
+
$amount = (float) str_replace('%','',$amount);
|
373 |
+
$amount = $hsl['L'] * $amount;
|
374 |
+
}
|
375 |
+
$hsl['L'] = ( $hsl['L'] * 100 ) - $amount;
|
376 |
+
$hsl['L'] = ( $hsl['L'] < 0 ) ? 0 : $hsl['L'] / 100;
|
377 |
+
} else {
|
378 |
+
// We need to find out how much to darken
|
379 |
+
$hsl['L'] = $hsl['L'] / 2;
|
380 |
+
}
|
381 |
+
|
382 |
+
return $hsl;
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Lightens a given HSL array
|
387 |
+
*
|
388 |
+
* @param array $hsl
|
389 |
+
* @param int $amount
|
390 |
+
*
|
391 |
+
* @return array $hsl
|
392 |
+
*/
|
393 |
+
private function _lighten( $hsl, $amount = self::DEFAULT_ADJUST ) {
|
394 |
+
// Check if we were provided a number
|
395 |
+
if ( $amount ) {
|
396 |
+
if(is_string($amount) && strpos($amount, '%')){
|
397 |
+
$amount = (float) str_replace('%','',$amount);
|
398 |
+
$amount = $hsl['L'] * $amount;
|
399 |
+
}
|
400 |
+
$hsl['L'] = ( $hsl['L'] * 100 ) + $amount;
|
401 |
+
$hsl['L'] = ( $hsl['L'] > 100 ) ? 1 : $hsl['L'] / 100;
|
402 |
+
} else {
|
403 |
+
// We need to find out how much to lighten
|
404 |
+
$hsl['L'] += ( 1 - $hsl['L'] ) / 2;
|
405 |
+
}
|
406 |
+
|
407 |
+
return $hsl;
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Mix 2 rgb colors and return an rgb color
|
412 |
+
*
|
413 |
+
* @param array $rgb1
|
414 |
+
* @param array $rgb2
|
415 |
+
* @param int $amount ranged -100..0..+100
|
416 |
+
*
|
417 |
+
* @return array $rgb
|
418 |
+
*
|
419 |
+
* ported from http://phpxref.pagelines.com/nav.html?includes/class.colors.php.source.html
|
420 |
+
*/
|
421 |
+
private function _mix( $rgb1, $rgb2, $amount = 0 ) {
|
422 |
+
$r1 = ( $amount + 100 ) / 100;
|
423 |
+
$r2 = 2 - $r1;
|
424 |
+
$rmix = ( ( $rgb1['R'] * $r1 ) + ( $rgb2['R'] * $r2 ) ) / 2;
|
425 |
+
$gmix = ( ( $rgb1['G'] * $r1 ) + ( $rgb2['G'] * $r2 ) ) / 2;
|
426 |
+
$bmix = ( ( $rgb1['B'] * $r1 ) + ( $rgb2['B'] * $r2 ) ) / 2;
|
427 |
+
|
428 |
+
return array( 'R' => $rmix, 'G' => $gmix, 'B' => $bmix );
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* Given a Hue, returns corresponding RGB value
|
433 |
+
*
|
434 |
+
* @param int $v1
|
435 |
+
* @param int $v2
|
436 |
+
* @param int $vH
|
437 |
+
*
|
438 |
+
* @return int
|
439 |
+
*/
|
440 |
+
private static function _huetorgb( $v1, $v2, $vH ) {
|
441 |
+
if ( $vH < 0 ) {
|
442 |
+
$vH += 1;
|
443 |
+
}
|
444 |
+
if ( $vH > 1 ) {
|
445 |
+
$vH -= 1;
|
446 |
+
}
|
447 |
+
if ( ( 6 * $vH ) < 1 ) {
|
448 |
+
return ( $v1 + ( $v2 - $v1 ) * 6 * $vH );
|
449 |
+
}
|
450 |
+
if ( ( 2 * $vH ) < 1 ) {
|
451 |
+
return $v2;
|
452 |
+
}
|
453 |
+
if ( ( 3 * $vH ) < 2 ) {
|
454 |
+
return ( $v1 + ( $v2 - $v1 ) * ( ( 2 / 3 ) - $vH ) * 6 );
|
455 |
+
}
|
456 |
+
|
457 |
+
return $v1;
|
458 |
+
}
|
459 |
+
|
460 |
+
/**
|
461 |
+
* You need to check if you were given a good hex string
|
462 |
+
*
|
463 |
+
* @param string $hex
|
464 |
+
*
|
465 |
+
* @return string Color
|
466 |
+
* @throws Exception "Bad color format"
|
467 |
+
*/
|
468 |
+
private static function _checkHex( $hex ) {
|
469 |
+
// Strip # sign is present
|
470 |
+
$color = str_replace( "#", "", $hex );
|
471 |
+
// Make sure it's 6 digits
|
472 |
+
if ( strlen( $color ) == 3 ) {
|
473 |
+
$color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
|
474 |
+
}
|
475 |
+
// else if( strlen($color) != 6 ) {
|
476 |
+
// throw new Exception("HEX color needs to be 6 or 3 digits long");
|
477 |
+
// }
|
478 |
+
return $color;
|
479 |
+
}
|
480 |
+
}
|
inc/compatibility.php
CHANGED
@@ -7,6 +7,10 @@
|
|
7 |
*
|
8 |
* @return bool
|
9 |
*/
|
|
|
|
|
|
|
|
|
10 |
function jetpack_photon_skip_gmedia($skip, $src)
|
11 |
{
|
12 |
if (strpos($src, GMEDIA_UPLOAD_FOLDER . '/image') !== false) {
|
7 |
*
|
8 |
* @return bool
|
9 |
*/
|
10 |
+
if(!defined('ABSPATH')) {
|
11 |
+
exit;
|
12 |
+
} // Exit if accessed directly
|
13 |
+
|
14 |
function jetpack_photon_skip_gmedia($skip, $src)
|
15 |
{
|
16 |
if (strpos($src, GMEDIA_UPLOAD_FOLDER . '/image') !== false) {
|
inc/core.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<?php
|
2 |
-
if(preg_match('#' . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . '#', $_SERVER['PHP_SELF']))
|
3 |
die('You are not allowed to call this page directly.');
|
4 |
}
|
5 |
|
6 |
/**
|
7 |
* Main PHP class for the WordPress plugin GRAND Media
|
8 |
*/
|
9 |
-
class GmediaCore
|
10 |
|
11 |
var $upload;
|
12 |
var $gmedia_url;
|
@@ -16,27 +16,40 @@ class GmediaCore {
|
|
16 |
/**
|
17 |
*
|
18 |
*/
|
19 |
-
function __construct()
|
20 |
$this->upload = $this->gm_upload_dir();
|
21 |
$this->gmedia_url = plugins_url(GMEDIA_FOLDER);
|
22 |
|
23 |
add_action('init', array(&$this, 'user_capabilities'), 8);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
|
26 |
-
function user_capabilities()
|
27 |
$capabilities = $this->plugin_capabilities();
|
28 |
$capabilities = apply_filters('gmedia_capabilities', $capabilities);
|
29 |
-
if(is_multisite() && is_super_admin())
|
30 |
-
foreach($capabilities as $cap)
|
31 |
-
$this->caps[$cap] = 1;
|
32 |
}
|
33 |
-
} else
|
34 |
$curuser = wp_get_current_user();
|
35 |
-
foreach($capabilities as $cap)
|
36 |
-
if(isset($curuser->allcaps[$cap]) && intval($curuser->allcaps[$cap]))
|
37 |
-
$this->caps[$cap] = 1;
|
38 |
-
} else
|
39 |
-
$this->caps[$cap] = 0;
|
40 |
}
|
41 |
}
|
42 |
}
|
@@ -51,8 +64,8 @@ class GmediaCore {
|
|
51 |
*
|
52 |
* @return mixed
|
53 |
*/
|
54 |
-
function _get($var, $def = false, $empty2false = false)
|
55 |
-
return isset($_GET[$var])? (($empty2false && $this->is_empty($_GET[$var]))? false : $_GET[$var]) : $def;
|
56 |
}
|
57 |
|
58 |
/**
|
@@ -62,7 +75,7 @@ class GmediaCore {
|
|
62 |
*
|
63 |
* @return bool
|
64 |
*/
|
65 |
-
function is_empty($var)
|
66 |
return !(!empty($var) && !in_array(strtolower($var), array('null', 'false')));
|
67 |
}
|
68 |
|
@@ -75,8 +88,8 @@ class GmediaCore {
|
|
75 |
* @return mixed
|
76 |
*/
|
77 |
|
78 |
-
function _post($var, $def = false)
|
79 |
-
return isset($_POST[$var])? $_POST[$var] : $def;
|
80 |
}
|
81 |
|
82 |
/**
|
@@ -87,8 +100,8 @@ class GmediaCore {
|
|
87 |
*
|
88 |
* @return mixed
|
89 |
*/
|
90 |
-
function _req($var, $def = false)
|
91 |
-
return isset($_REQUEST[$var])? $_REQUEST[$var] : $def;
|
92 |
}
|
93 |
|
94 |
/**
|
@@ -100,18 +113,18 @@ class GmediaCore {
|
|
100 |
*
|
101 |
* @return string
|
102 |
*/
|
103 |
-
function tooltip($style, $params, $print = true)
|
104 |
$show_tip = 0; // TODO show tooltips checkbox in settings
|
105 |
-
if($show_tip)
|
106 |
$tooltip = " data-toggle='$style'";
|
107 |
-
if(is_array($params) && !empty($params))
|
108 |
-
foreach($params as $key => $val)
|
109 |
$tooltip .= " data-$key='$val'";
|
110 |
}
|
111 |
}
|
112 |
-
if($print)
|
113 |
echo $tooltip;
|
114 |
-
} else
|
115 |
return $tooltip;
|
116 |
}
|
117 |
}
|
@@ -123,20 +136,29 @@ class GmediaCore {
|
|
123 |
* @param array $add_args
|
124 |
* @param array $remove_args
|
125 |
* @param bool $uri
|
|
|
126 |
*
|
127 |
* @return string
|
128 |
*/
|
129 |
-
function get_admin_url($add_args = array(), $remove_args = array(), $uri = false)
|
130 |
-
if(true === $uri)
|
131 |
$uri = admin_url('admin.php');
|
132 |
}
|
133 |
$remove_args = empty($remove_args)? array() : (array)$remove_args;
|
134 |
-
$remove_args = array_unique(array_merge(array('doing_wp_cron', '_wpnonce', 'delete', 'update_meta'), $remove_args, array_keys($add_args)));
|
135 |
$new_uri = remove_query_arg($remove_args, $uri);
|
136 |
-
if(!empty($
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
$new_uri = add_query_arg($add_args, $new_uri);
|
138 |
}
|
139 |
-
|
140 |
return esc_url_raw($new_uri);
|
141 |
}
|
142 |
|
@@ -145,7 +167,7 @@ class GmediaCore {
|
|
145 |
*
|
146 |
* @return bool
|
147 |
*/
|
148 |
-
function is_crawler($userAgent)
|
149 |
$crawlers = 'Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|FeedBurner|' . 'AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|' . 'GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby|yandex|facebook';
|
150 |
$isCrawler = (preg_match("/$crawlers/i", $userAgent) > 0);
|
151 |
|
@@ -157,7 +179,7 @@ class GmediaCore {
|
|
157 |
*
|
158 |
* @return bool
|
159 |
*/
|
160 |
-
function is_browser($userAgent)
|
161 |
$browsers = 'opera|aol|msie|firefox|chrome|konqueror|safari|netscape|navigator|mosaic|lynx|amaya|omniweb|avant|camino|flock|seamonkey|mozilla|gecko';
|
162 |
$isBrowser = (preg_match("/$browsers/i", $userAgent) > 0);
|
163 |
|
@@ -180,10 +202,10 @@ class GmediaCore {
|
|
180 |
*
|
181 |
* @return array See above for description.
|
182 |
*/
|
183 |
-
function gm_upload_dir($create = true)
|
184 |
$slash = '/';
|
185 |
// If multisite (and if not the main site)
|
186 |
-
if(is_multisite() && !is_main_site())
|
187 |
$slash = '/blogs.dir/' . get_current_blog_id() . '/';
|
188 |
}
|
189 |
|
@@ -194,13 +216,13 @@ class GmediaCore {
|
|
194 |
|
195 |
$uploads = apply_filters('gm_upload_dir', array('path' => $dir, 'url' => $url, 'error' => false));
|
196 |
|
197 |
-
if($create)
|
198 |
// Make sure we have an uploads dir
|
199 |
-
if(!wp_mkdir_p($uploads['path']))
|
200 |
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $uploads['path']);
|
201 |
$uploads['error'] = $message;
|
202 |
}
|
203 |
-
} elseif(!is_dir($uploads['path']))
|
204 |
$uploads['error'] = true;
|
205 |
}
|
206 |
|
@@ -212,13 +234,13 @@ class GmediaCore {
|
|
212 |
*
|
213 |
* @return bool|null
|
214 |
*/
|
215 |
-
function delete_folder($path)
|
216 |
$path = rtrim($path, '/');
|
217 |
-
if(is_file($path))
|
218 |
return @unlink($path);
|
219 |
-
} elseif(is_dir($path))
|
220 |
$files = glob($path . '/*', GLOB_NOSORT);
|
221 |
-
if(!empty($files) && is_array($files))
|
222 |
array_map(array($this, 'delete_folder'), $files);
|
223 |
}
|
224 |
|
@@ -234,30 +256,30 @@ class GmediaCore {
|
|
234 |
* @see wp_get_attachment_image()
|
235 |
* @uses apply_filters() Calls 'gm_get_attachment_image_attributes' hook on attributes array
|
236 |
*
|
237 |
-
* @param int|object $item
|
238 |
-
* @param string $size
|
239 |
-
* @param bool $cover
|
240 |
* @param bool|string $default Optional, return if no cover
|
241 |
*
|
242 |
* @return string img url
|
243 |
*/
|
244 |
-
function gm_get_media_image($item, $size = '', $cover = true, $default = false)
|
245 |
global $gmDB, $gmGallery;
|
246 |
|
247 |
-
if(!is_object($item))
|
248 |
$item = $gmDB->get_gmedia($item);
|
249 |
}
|
250 |
-
if(empty($item))
|
251 |
-
$image = $this->gmedia_url . '/admin/assets/img/blank.gif';
|
252 |
|
253 |
return $image;
|
254 |
}
|
255 |
$type = explode('/', $item->mime_type);
|
256 |
|
257 |
-
if('image' == $type[0])
|
258 |
-
$type_folder = $this->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]];
|
259 |
|
260 |
-
switch($size)
|
261 |
case 'thumb':
|
262 |
$size_folder = '/thumb/';
|
263 |
break;
|
@@ -271,22 +293,22 @@ class GmediaCore {
|
|
271 |
}
|
272 |
|
273 |
$image = $type_folder . $size_folder . $item->gmuid;
|
274 |
-
} else
|
275 |
$ext = ltrim(strrchr($item->gmuid, '.'), '.');
|
276 |
-
if(!$type = wp_ext2type($ext))
|
277 |
$type = 'application';
|
278 |
}
|
279 |
$image = $this->gmedia_url . '/admin/assets/img/' . $type . '.png';
|
280 |
|
281 |
-
if($cover)
|
282 |
$cover = $gmDB->get_metadata('gmedia', $item->ID, '_cover', true);
|
283 |
-
if(!empty($cover))
|
284 |
-
if($this->is_digit($cover))
|
285 |
$image = $this->gm_get_media_image((int)$cover, $size, false);
|
286 |
-
} elseif(false !== filter_var($cover, FILTER_VALIDATE_URL))
|
287 |
return $cover;
|
288 |
}
|
289 |
-
} elseif(false !== $default)
|
290 |
return $default;
|
291 |
}
|
292 |
}
|
@@ -302,36 +324,34 @@ class GmediaCore {
|
|
302 |
*
|
303 |
* @return array|bool Return array( 'path', 'url' ) OR false if no module
|
304 |
*/
|
305 |
-
function get_module_path($module_name)
|
306 |
global $gmGallery;
|
307 |
-
if(empty($module_name))
|
308 |
return false;
|
309 |
}
|
310 |
-
$module_dirs = array(
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
'name' => $module_name,
|
323 |
-
'path' => get_template_directory() . '/gmedia-module/' . $module_name,
|
324 |
-
'url' => get_template_directory_uri() . '/gmedia-module/' . $module_name
|
325 |
-
)
|
326 |
);
|
327 |
-
foreach($module_dirs as $dir)
|
328 |
-
if(is_dir($dir['path']))
|
329 |
return $dir;
|
330 |
}
|
331 |
}
|
332 |
|
333 |
-
|
334 |
-
|
|
|
|
|
335 |
}
|
336 |
|
337 |
return false;
|
@@ -344,7 +364,7 @@ class GmediaCore {
|
|
344 |
*
|
345 |
* @return array|bool
|
346 |
*/
|
347 |
-
function fileinfo($file, $exists = 0)
|
348 |
global $gmGallery, $user_ID;
|
349 |
|
350 |
$file = basename($file);
|
@@ -361,25 +381,26 @@ class GmediaCore {
|
|
361 |
$allowed_ext = array_keys($allowed_ext);
|
362 |
$allowed_ext = implode('|', $allowed_ext);
|
363 |
$allowed_ext = explode('|', $allowed_ext);
|
364 |
-
if(!in_array($fileinfo['extension'], $allowed_ext))
|
365 |
return false;
|
366 |
}
|
367 |
|
368 |
-
$fileinfo['
|
369 |
-
$fileinfo['
|
370 |
-
$fileinfo['
|
371 |
-
$fileinfo['
|
|
|
372 |
list($dirname) = explode('/', $fileinfo['mime_type']);
|
373 |
$fileinfo['dirname'] = $dirname;
|
374 |
-
$fileinfo['dirpath'] = $this->upload['path'] . '/' . $gmGallery->options['folder'][$dirname];
|
375 |
-
$fileinfo['
|
376 |
-
$fileinfo['dirurl'] = $this->upload['url'] . '/' . $gmGallery->options['folder'][$dirname];
|
377 |
-
$fileinfo['dirurl_original'] = $this->upload['url'] . '/' . $gmGallery->options['folder'][$dirname];
|
378 |
$fileinfo['filepath'] = $fileinfo['dirpath'] . '/' . $fileinfo['basename'];
|
379 |
$fileinfo['filepath_original'] = $fileinfo['dirpath'] . '/' . $fileinfo['basename'];
|
380 |
$fileinfo['fileurl'] = $fileinfo['dirurl'] . '/' . $fileinfo['basename'];
|
381 |
$fileinfo['fileurl_original'] = $fileinfo['dirurl'] . '/' . $fileinfo['basename'];
|
382 |
-
if('image' == $dirname)
|
383 |
$fileinfo['dirpath_original'] = $this->upload['path'] . '/' . $gmGallery->options['folder']['image_original'];
|
384 |
$fileinfo['dirurl_original'] = $this->upload['url'] . '/' . $gmGallery->options['folder']['image_original'];
|
385 |
$fileinfo['filepath_original'] = $fileinfo['dirpath_original'] . '/' . $fileinfo['basename'];
|
@@ -390,7 +411,7 @@ class GmediaCore {
|
|
390 |
$fileinfo['fileurl_thumb'] = $fileinfo['dirurl_thumb'] . '/' . $fileinfo['basename'];
|
391 |
}
|
392 |
|
393 |
-
if((false !== $exists) && file_exists($fileinfo['filepath']))
|
394 |
$exists = absint($exists) + 1;
|
395 |
$fileinfo = $this->fileinfo($file, $exists);
|
396 |
}
|
@@ -405,14 +426,14 @@ class GmediaCore {
|
|
405 |
*
|
406 |
* @return mixed|void
|
407 |
*/
|
408 |
-
function get_file_metadata($file, $fileinfo = array())
|
409 |
|
410 |
-
if(empty($fileinfo))
|
411 |
$fileinfo = $this->fileinfo($file, false);
|
412 |
}
|
413 |
$metadata = array();
|
414 |
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
415 |
-
if(preg_match('!^image/!', $fileinfo['mime_type']) && file_is_displayable_image($fileinfo['filepath']))
|
416 |
$imagesize = getimagesize($fileinfo['filepath']);
|
417 |
$metadata['web'] = array('width' => $imagesize[0], 'height' => $imagesize[1]);
|
418 |
$imagesize = getimagesize($fileinfo['filepath_original']);
|
@@ -424,15 +445,15 @@ class GmediaCore {
|
|
424 |
|
425 |
// fetch additional metadata from exif/iptc
|
426 |
$image_meta = $this->wp_read_image_metadata($fileinfo['filepath_original']);
|
427 |
-
if($image_meta)
|
428 |
$metadata['image_meta'] = $image_meta;
|
429 |
}
|
430 |
|
431 |
-
} elseif(preg_match('#^video/#', $fileinfo['mime_type']))
|
432 |
$metadata = $this->wp_read_video_metadata($fileinfo['filepath']);
|
433 |
-
} elseif(preg_match('#^audio/#', $fileinfo['mime_type']))
|
434 |
$metadata = $this->wp_read_audio_metadata($fileinfo['filepath']);
|
435 |
-
unset($metadata['image']);
|
436 |
}
|
437 |
|
438 |
return apply_filters('generate_file_metadata', $metadata);
|
@@ -441,7 +462,6 @@ class GmediaCore {
|
|
441 |
/**
|
442 |
* Return relative path to an uploaded file.
|
443 |
* The path is relative to the current upload dir.
|
444 |
-
*
|
445 |
* @see _wp_relative_upload_path()
|
446 |
* @uses apply_filters() Calls '_gm_relative_upload_path' on file path.
|
447 |
*
|
@@ -449,12 +469,11 @@ class GmediaCore {
|
|
449 |
*
|
450 |
* @return string relative path on success, unchanged path on failure.
|
451 |
*/
|
452 |
-
function _gm_relative_upload_path($path)
|
453 |
-
global $gmCore;
|
454 |
$new_path = $path;
|
455 |
|
456 |
-
if((false === $
|
457 |
-
$new_path = str_replace($
|
458 |
$new_path = ltrim($new_path, '/');
|
459 |
}
|
460 |
|
@@ -465,7 +484,7 @@ class GmediaCore {
|
|
465 |
*
|
466 |
* @param string $new_file
|
467 |
*/
|
468 |
-
function file_chmod($new_file)
|
469 |
$stat = stat(dirname($new_file));
|
470 |
$perms = $stat['mode'] & 0000666;
|
471 |
@chmod($new_file, $perms);
|
@@ -478,13 +497,12 @@ class GmediaCore {
|
|
478 |
*
|
479 |
* @return mixed
|
480 |
*/
|
481 |
-
function clean_input($input)
|
482 |
-
$search = array(
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
//,'/\s{3,}/'
|
488 |
);
|
489 |
|
490 |
$output = preg_replace($search, '', $input);
|
@@ -499,15 +517,15 @@ class GmediaCore {
|
|
499 |
*
|
500 |
* @return mixed
|
501 |
*/
|
502 |
-
function sanitize($input)
|
503 |
$output = $input;
|
504 |
-
if(is_array($input))
|
505 |
-
foreach($input as $var => $val)
|
506 |
-
$output[$var] = $this->sanitize($val);
|
507 |
}
|
508 |
-
} else
|
509 |
/** @noinspection PhpDeprecationInspection */
|
510 |
-
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
|
511 |
$input = stripslashes($input);
|
512 |
}
|
513 |
$input = $this->clean_input($input);
|
@@ -524,12 +542,12 @@ class GmediaCore {
|
|
524 |
*
|
525 |
* @return bool
|
526 |
*/
|
527 |
-
function is_digit($digit)
|
528 |
-
if(is_int($digit))
|
529 |
return true;
|
530 |
-
} elseif(is_string($digit) && !empty($digit))
|
531 |
return ctype_digit($digit);
|
532 |
-
} else
|
533 |
// booleans, floats and others
|
534 |
return false;
|
535 |
}
|
@@ -537,11 +555,10 @@ class GmediaCore {
|
|
537 |
|
538 |
/**
|
539 |
* Check if user can select a author
|
540 |
-
*
|
541 |
* @return array
|
542 |
*/
|
543 |
-
function get_editable_user_ids()
|
544 |
-
if(current_user_can('gmedia_show_others_media') || current_user_can('gmedia_edit_others_media'))
|
545 |
return get_users(array('who' => 'authors', 'fields' => 'ID'));
|
546 |
}
|
547 |
|
@@ -556,23 +573,21 @@ class GmediaCore {
|
|
556 |
*
|
557 |
* @return string
|
558 |
*/
|
559 |
-
function gmcloudlink($id, $type)
|
560 |
$options = get_option('gmediaOptions');
|
561 |
$endpoint = $options['endpoint'];
|
562 |
$hashid = gmedia_hash_id_encode($id, $type);
|
563 |
-
$t = array(
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
'filter' => 'f',
|
570 |
-
'author' => 'u'
|
571 |
);
|
572 |
-
if(get_option('permalink_structure'))
|
573 |
$cloud_link = home_url(urlencode($endpoint) . "/{$t[$type]}/{$hashid}");
|
574 |
-
} else
|
575 |
-
$cloud_link = add_query_arg(array("$endpoint" => $hashid, 't' => $t[$type]), home_url('index.php'));
|
576 |
}
|
577 |
|
578 |
return $cloud_link;
|
@@ -586,12 +601,12 @@ class GmediaCore {
|
|
586 |
*
|
587 |
* @return string
|
588 |
*/
|
589 |
-
function filesize($file, $decimals = 2)
|
590 |
$bytes = filesize($file);
|
591 |
$sz = array('b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
|
592 |
$factor = (int)floor((strlen($bytes) - 1) / 3);
|
593 |
|
594 |
-
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sz[$factor];
|
595 |
}
|
596 |
|
597 |
/**
|
@@ -603,16 +618,16 @@ class GmediaCore {
|
|
603 |
*
|
604 |
* @return array
|
605 |
*/
|
606 |
-
function array_diff_key_recursive(array $arr1, array $arr2)
|
607 |
$diff = array_diff_key($arr1, $arr2);
|
608 |
$intersect = array_intersect_key($arr1, $arr2);
|
609 |
|
610 |
-
foreach($intersect as $k => $v)
|
611 |
-
if(is_array($arr1[$k]) && is_array($arr2[$k]))
|
612 |
-
$d = $this->array_diff_key_recursive($arr1[$k], $arr2[$k]);
|
613 |
|
614 |
-
if(!empty($d))
|
615 |
-
$diff[$k] = $d;
|
616 |
}
|
617 |
}
|
618 |
}
|
@@ -627,22 +642,22 @@ class GmediaCore {
|
|
627 |
*
|
628 |
* @return array
|
629 |
*/
|
630 |
-
function array_diff_keyval_recursive(array $arr1, array $arr2, $update = false)
|
631 |
$diff = array_diff_key($arr1, $arr2);
|
632 |
$intersect = array_intersect_key($arr1, $arr2);
|
633 |
|
634 |
-
foreach($intersect as $k => $v)
|
635 |
-
if(is_array($arr1[$k]) && is_array($arr2[$k]))
|
636 |
-
$d = $this->array_diff_keyval_recursive($arr1[$k], $arr2[$k], $update);
|
637 |
|
638 |
-
if(!empty($d))
|
639 |
-
$diff[$k] = $d;
|
640 |
}
|
641 |
-
} elseif($arr1[$k] !== $arr2[$k])
|
642 |
-
if($update)
|
643 |
-
$diff[$k] = $arr2[$k];
|
644 |
-
} else
|
645 |
-
$diff[$k] = $arr1[$k];
|
646 |
}
|
647 |
}
|
648 |
}
|
@@ -656,29 +671,29 @@ class GmediaCore {
|
|
656 |
*
|
657 |
* @return mixed
|
658 |
*/
|
659 |
-
function array_replace_recursive($base, $replacements)
|
660 |
-
if(function_exists('array_replace_recursive'))
|
661 |
return array_replace_recursive($base, $replacements);
|
662 |
}
|
663 |
|
664 |
-
foreach(array_slice(func_get_args(), 1) as $replacements)
|
665 |
$bref_stack = array(&$base);
|
666 |
$head_stack = array($replacements);
|
667 |
|
668 |
-
do
|
669 |
end($bref_stack);
|
670 |
|
671 |
-
$bref = &$bref_stack[key($bref_stack)];
|
672 |
$head = array_pop($head_stack);
|
673 |
|
674 |
-
unset($bref_stack[key($bref_stack)]);
|
675 |
|
676 |
-
foreach(array_keys($head) as $key)
|
677 |
-
if(isset($bref[$key]) && is_array($bref[$key]) && is_array($head[$key]))
|
678 |
-
$bref_stack[] = &$bref[$key];
|
679 |
-
$head_stack[] = $head[$key];
|
680 |
-
} else
|
681 |
-
$bref[$key] = $head[$key];
|
682 |
}
|
683 |
}
|
684 |
} while(count($head_stack));
|
@@ -692,14 +707,13 @@ class GmediaCore {
|
|
692 |
* @param $array
|
693 |
*
|
694 |
* @return mixed
|
695 |
-
*
|
696 |
*/
|
697 |
-
function array_map_recursive($callback, $array)
|
698 |
-
foreach($array as $key => $value)
|
699 |
-
if(is_array($array[$key]))
|
700 |
-
$array[$key] = $this->array_map_recursive($callback, $array[$key]);
|
701 |
-
} else
|
702 |
-
$array[$key] = call_user_func($callback, $array[$key]);
|
703 |
}
|
704 |
}
|
705 |
|
@@ -712,10 +726,10 @@ class GmediaCore {
|
|
712 |
*
|
713 |
* @return string
|
714 |
*/
|
715 |
-
public function alert($type = 'info', $content = '')
|
716 |
-
if(empty($content))
|
717 |
return '';
|
718 |
-
} elseif(is_array($content))
|
719 |
$content = array_filter($content);
|
720 |
$content = implode('<br />', $content);
|
721 |
}
|
@@ -729,11 +743,11 @@ class GmediaCore {
|
|
729 |
*
|
730 |
* @return array|bool
|
731 |
*/
|
732 |
-
function process_gmedit_image($photo)
|
733 |
$type = null;
|
734 |
-
if(preg_match('/^data:image\/(jpg|jpeg|png|gif)/i', $photo, $matches))
|
735 |
$type = $matches[1];
|
736 |
-
} else
|
737 |
return false;
|
738 |
}
|
739 |
// Remove the mime-type header
|
@@ -744,414 +758,412 @@ class GmediaCore {
|
|
744 |
// Use strict mode to prevent characters from outside the base64 range
|
745 |
$image = base64_decode($data, true);
|
746 |
|
747 |
-
if(!$image)
|
748 |
return false;
|
749 |
}
|
750 |
|
751 |
-
return array(
|
752 |
-
|
753 |
-
'type' => $type
|
754 |
);
|
755 |
}
|
756 |
|
757 |
/**
|
758 |
* @return bool
|
759 |
*/
|
760 |
-
function is_bot()
|
761 |
-
if(empty($_SERVER['HTTP_USER_AGENT']))
|
762 |
return false;
|
763 |
}
|
764 |
|
765 |
-
$spiders = array(
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
"...."
|
1150 |
);
|
1151 |
|
1152 |
-
foreach($spiders as $spider)
|
1153 |
//If the spider text is found in the current user agent, then return true
|
1154 |
-
if(stripos($_SERVER['HTTP_USER_AGENT'], $spider) !== false)
|
1155 |
return true;
|
1156 |
break;
|
1157 |
}
|
@@ -1163,21 +1175,20 @@ class GmediaCore {
|
|
1163 |
|
1164 |
/**
|
1165 |
* Parse ID3v2, ID3v1, and getID3 comments to extract usable data
|
1166 |
-
*
|
1167 |
* @since 3.6.0
|
1168 |
*
|
1169 |
* @param array $metadata An existing array with data
|
1170 |
-
* @param array $data
|
1171 |
*/
|
1172 |
-
function wp_add_id3_tag_data(&$metadata, $data)
|
1173 |
-
foreach(array('id3v2', 'id3v1') as $version)
|
1174 |
-
if(!empty($data[$version]['comments']))
|
1175 |
-
foreach($data[$version]['comments'] as $key => $list)
|
1176 |
-
if(!empty($list))
|
1177 |
-
$metadata[$key] = reset($list);
|
1178 |
// fix bug in byte stream analysis
|
1179 |
-
if('terms_of_use' === $key && 0 === strpos($metadata[$key], 'yright notice.'))
|
1180 |
-
$metadata[$key] = 'Cop' . $metadata[$key];
|
1181 |
}
|
1182 |
}
|
1183 |
}
|
@@ -1185,22 +1196,20 @@ class GmediaCore {
|
|
1185 |
}
|
1186 |
}
|
1187 |
|
1188 |
-
if(!empty($data['id3v2']['APIC']))
|
1189 |
$image = reset($data['id3v2']['APIC']);
|
1190 |
-
if(!empty($image['data']))
|
1191 |
-
$metadata['image'] = array(
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
'height' => $image['image_height']
|
1196 |
);
|
1197 |
}
|
1198 |
-
} elseif(!empty($data['comments']['picture']))
|
1199 |
$image = reset($data['comments']['picture']);
|
1200 |
-
if(!empty($image['data']))
|
1201 |
-
$metadata['image'] = array(
|
1202 |
-
|
1203 |
-
'mime' => $image['image_mime']
|
1204 |
);
|
1205 |
}
|
1206 |
}
|
@@ -1208,23 +1217,20 @@ class GmediaCore {
|
|
1208 |
|
1209 |
/**
|
1210 |
* Get extended image metadata, exif or iptc as available.
|
1211 |
-
*
|
1212 |
* Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso
|
1213 |
* created_timestamp, focal_length, shutter_speed, and title.
|
1214 |
-
*
|
1215 |
* The IPTC metadata that is retrieved is APP13, credit, byline, created date
|
1216 |
* and time, caption, copyright, and title. Also includes FNumber, Model,
|
1217 |
* DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.
|
1218 |
-
*
|
1219 |
-
* @todo Try other exif libraries if available.
|
1220 |
* @since 2.5.0
|
1221 |
*
|
1222 |
* @param string $file
|
1223 |
*
|
1224 |
* @return bool|array False on failure. Image metadata array on success.
|
1225 |
*/
|
1226 |
-
function wp_read_image_metadata($file)
|
1227 |
-
if(!file_exists($file))
|
1228 |
return false;
|
1229 |
}
|
1230 |
|
@@ -1236,37 +1242,37 @@ class GmediaCore {
|
|
1236 |
* Read IPTC first, since it might contain data not available in exif such
|
1237 |
* as caption, description etc.
|
1238 |
*/
|
1239 |
-
if(is_callable('iptcparse'))
|
1240 |
getimagesize($file, $info);
|
1241 |
|
1242 |
-
if(!empty($info['APP13']))
|
1243 |
$iptc = iptcparse($info['APP13']);
|
1244 |
|
1245 |
// Headline, "A brief synopsis of the caption."
|
1246 |
-
if(!empty($iptc['2#105'][0]))
|
1247 |
$meta['title'] = trim($iptc['2#105'][0]);
|
1248 |
/*
|
1249 |
* Title, "Many use the Title field to store the filename of the image,
|
1250 |
* though the field may be used in many ways."
|
1251 |
*/
|
1252 |
-
} elseif(!empty($iptc['2#005'][0]))
|
1253 |
$meta['title'] = trim($iptc['2#005'][0]);
|
1254 |
}
|
1255 |
|
1256 |
-
if(!empty($iptc['2#120'][0]))
|
1257 |
$caption = trim($iptc['2#120'][0]);
|
1258 |
-
if(empty($meta['title']))
|
1259 |
mbstring_binary_safe_encoding();
|
1260 |
$caption_length = strlen($caption);
|
1261 |
reset_mbstring_encoding();
|
1262 |
|
1263 |
// Assume the title is stored in 2:120 if it's short.
|
1264 |
-
if($caption_length < 80)
|
1265 |
$meta['title'] = $caption;
|
1266 |
-
} else
|
1267 |
$meta['caption'] = $caption;
|
1268 |
}
|
1269 |
-
} elseif($caption != $meta['title'])
|
1270 |
$meta['caption'] = $caption;
|
1271 |
}
|
1272 |
}
|
@@ -1298,108 +1304,106 @@ class GmediaCore {
|
|
1298 |
|
1299 |
/**
|
1300 |
* Filter the image types to check for exif data.
|
1301 |
-
*
|
1302 |
* @since 2.5.0
|
1303 |
*
|
1304 |
* @param array $image_types Image types to check for exif data.
|
1305 |
*/
|
1306 |
-
if(is_callable('exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(
|
1307 |
-
|
1308 |
-
|
1309 |
-
IMAGETYPE_TIFF_MM
|
1310 |
)))
|
1311 |
-
)
|
1312 |
$exif = @exif_read_data($file);
|
1313 |
unset($exif['MakerNote']);
|
1314 |
|
1315 |
// Title
|
1316 |
-
if(empty($meta['title']) && !empty($exif['Title']))
|
1317 |
$meta['title'] = trim($exif['Title']);
|
1318 |
}
|
1319 |
// Descrioption
|
1320 |
-
if(!empty($exif['ImageDescription']))
|
1321 |
mbstring_binary_safe_encoding();
|
1322 |
$description_length = strlen($exif['ImageDescription']);
|
1323 |
reset_mbstring_encoding();
|
1324 |
|
1325 |
-
if(empty($meta['title']) && $description_length < 80)
|
1326 |
// Assume the title is stored in ImageDescription
|
1327 |
$meta['title'] = trim($exif['ImageDescription']);
|
1328 |
-
if(empty($meta['caption']) && !empty($exif['COMPUTED']['UserComment']) && trim($exif['COMPUTED']['UserComment']) != $meta['title'])
|
1329 |
$meta['caption'] = trim($exif['COMPUTED']['UserComment']);
|
1330 |
}
|
1331 |
-
} elseif(empty($meta['caption']) && trim($exif['ImageDescription']) != $meta['title'])
|
1332 |
$meta['caption'] = trim($exif['ImageDescription']);
|
1333 |
}
|
1334 |
-
} elseif(empty($meta['caption']) && !empty($exif['Comments']) && trim($exif['Comments']) != $meta['title'])
|
1335 |
$meta['caption'] = trim($exif['Comments']);
|
1336 |
}
|
1337 |
// Credit
|
1338 |
-
if(empty($meta['credit']))
|
1339 |
-
if(!empty($exif['Artist']))
|
1340 |
$meta['credit'] = trim($exif['Artist']);
|
1341 |
-
} elseif(!empty($exif['Author']))
|
1342 |
$meta['credit'] = trim($exif['Author']);
|
1343 |
}
|
1344 |
}
|
1345 |
// Copyright
|
1346 |
-
if(empty($meta['copyright']) && !empty($exif['Copyright']))
|
1347 |
$meta['copyright'] = trim($exif['Copyright']);
|
1348 |
}
|
1349 |
// Camera Make
|
1350 |
-
if(!empty($exif['Make']))
|
1351 |
$meta['make'] = $exif['Make'];
|
1352 |
}
|
1353 |
// Camera Model
|
1354 |
-
if(!empty($exif['Model']))
|
1355 |
$meta['model'] = trim($exif['Model']);
|
1356 |
}
|
1357 |
// Exposure Time (shutter speed)
|
1358 |
-
if(!empty($exif['ExposureTime']))
|
1359 |
$meta['exposure'] = $exif['ExposureTime'] . 's';
|
1360 |
$meta['shutter_speed'] = (string)wp_exif_frac2dec($exif['ExposureTime']) . 's';
|
1361 |
}
|
1362 |
// Aperture
|
1363 |
-
if(!empty($exif['COMPUTED']['ApertureFNumber']))
|
1364 |
$meta['aperture'] = $exif['COMPUTED']['ApertureFNumber'];
|
1365 |
-
} elseif(!empty($exif['FNumber']))
|
1366 |
$meta['aperture'] = 'f/' . (string)round(wp_exif_frac2dec($exif['FNumber']), 2);
|
1367 |
}
|
1368 |
// ISO
|
1369 |
-
if(!empty($exif['ISOSpeedRatings']))
|
1370 |
$meta['iso'] = is_array($exif['ISOSpeedRatings'])? reset($exif['ISOSpeedRatings']) : $exif['ISOSpeedRatings'];
|
1371 |
$meta['iso'] = trim($meta['iso']);
|
1372 |
}
|
1373 |
// Date
|
1374 |
-
if(!empty($exif['DateTime']))
|
1375 |
$meta['date'] = $exif['DateTime'];
|
1376 |
}
|
1377 |
// Created TimeStamp
|
1378 |
-
if(empty($meta['created_timestamp']) && !empty($exif['DateTimeDigitized']))
|
1379 |
$meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized']);
|
1380 |
}
|
1381 |
// Lens
|
1382 |
-
if(!empty($exif['UndefinedTag:0xA434']))
|
1383 |
$meta['lens'] = $exif['UndefinedTag:0xA434'];
|
1384 |
}
|
1385 |
// Focus Distance
|
1386 |
-
if(!empty($exif['COMPUTED']['FocusDistance']))
|
1387 |
$meta['distance'] = $exif['COMPUTED']['FocusDistance'];
|
1388 |
}
|
1389 |
// Focal Length
|
1390 |
-
if(!empty($exif['FocalLength']))
|
1391 |
$meta['focallength'] = (string)round(wp_exif_frac2dec($exif['FocalLength'])) . 'mm';
|
1392 |
}
|
1393 |
// Focal Length 35mm
|
1394 |
-
if(!empty($exif['FocalLengthIn35mmFilm']))
|
1395 |
$meta['focallength35'] = $exif['FocalLengthIn35mmFilm'] . 'mm';
|
1396 |
}
|
1397 |
// Flash data
|
1398 |
-
if(!empty($exif['Flash']))
|
1399 |
// we need to interpret the result - it's given as a number and we want a human-readable description.
|
1400 |
$fdata = $exif['Flash'];
|
1401 |
|
1402 |
-
switch($fdata)
|
1403 |
case 0 :
|
1404 |
$fdata = 'No Flash';
|
1405 |
break;
|
@@ -1473,52 +1477,51 @@ class GmediaCore {
|
|
1473 |
$meta['flashdata'] = $fdata;
|
1474 |
}
|
1475 |
// Lens Make
|
1476 |
-
if(!empty($exif['UndefinedTag:0xA433']))
|
1477 |
$meta['lensmake'] = $exif['UndefinedTag:0xA433'];
|
1478 |
}
|
1479 |
// Software
|
1480 |
-
if(!empty($exif['Software']))
|
1481 |
$meta['software'] = $exif['Software'];
|
1482 |
}
|
1483 |
// Orientation
|
1484 |
-
if(!empty($exif['Orientation']))
|
1485 |
$meta['orientation'] = $exif['Orientation'];
|
1486 |
}
|
1487 |
|
1488 |
$exif_sections = @exif_read_data($file, null, true);
|
1489 |
-
if(isset($exif_sections['GPS']))
|
1490 |
$meta['GPS'] = $this->getGPSfromExif($exif_sections['GPS']);
|
1491 |
}
|
1492 |
unset($exif_sections);
|
1493 |
//$meta['exif'] = $exif;
|
1494 |
}
|
1495 |
|
1496 |
-
foreach(array('title', 'caption', 'credit', 'copyright', 'model', 'iso', 'software') as $key)
|
1497 |
-
if(!empty($meta[$key]) && !seems_utf8($meta[$key]))
|
1498 |
-
$meta[$key] = utf8_encode($meta[$key]);
|
1499 |
}
|
1500 |
}
|
1501 |
-
if(!empty($meta['keywords']))
|
1502 |
-
foreach($meta['keywords'] as $i => $key)
|
1503 |
-
if(!seems_utf8($key))
|
1504 |
-
$meta['keywords'][$i] = utf8_encode($key);
|
1505 |
}
|
1506 |
}
|
1507 |
}
|
1508 |
|
1509 |
-
foreach($meta as &$value)
|
1510 |
-
if(is_string($value))
|
1511 |
$value = wp_kses_post($value);
|
1512 |
}
|
1513 |
}
|
1514 |
|
1515 |
/**
|
1516 |
* Filter the array of meta data read from an image's exif data.
|
1517 |
-
*
|
1518 |
* @since 2.5.0
|
1519 |
*
|
1520 |
-
* @param array $meta
|
1521 |
-
* @param string $file
|
1522 |
* @param int $sourceImageType Type of image.
|
1523 |
*/
|
1524 |
return apply_filters('wp_read_image_metadata', $meta, $file, $sourceImageType);
|
@@ -1527,67 +1530,66 @@ class GmediaCore {
|
|
1527 |
|
1528 |
/**
|
1529 |
* Retrieve metadata from a video file's ID3 tags
|
1530 |
-
*
|
1531 |
* @since 3.6.0
|
1532 |
*
|
1533 |
* @param string $file Path to file.
|
1534 |
*
|
1535 |
* @return array|boolean Returns array of metadata, if found.
|
1536 |
*/
|
1537 |
-
function wp_read_video_metadata($file)
|
1538 |
-
if(!file_exists($file))
|
1539 |
return false;
|
1540 |
}
|
1541 |
|
1542 |
$metadata = array();
|
1543 |
|
1544 |
-
if(!class_exists('getID3'))
|
1545 |
require(ABSPATH . WPINC . '/ID3/getid3.php');
|
1546 |
}
|
1547 |
$id3 = new getID3();
|
1548 |
$data = $id3->analyze($file);
|
1549 |
|
1550 |
-
if(isset($data['video']['lossless']))
|
1551 |
$metadata['lossless'] = $data['video']['lossless'];
|
1552 |
}
|
1553 |
-
if(!empty($data['video']['bitrate']))
|
1554 |
$metadata['bitrate'] = (int)$data['video']['bitrate'];
|
1555 |
}
|
1556 |
-
if(!empty($data['video']['bitrate_mode']))
|
1557 |
$metadata['bitrate_mode'] = $data['video']['bitrate_mode'];
|
1558 |
}
|
1559 |
-
if(!empty($data['filesize']))
|
1560 |
$metadata['filesize'] = (int)$data['filesize'];
|
1561 |
}
|
1562 |
-
if(!empty($data['mime_type']))
|
1563 |
$metadata['mime_type'] = $data['mime_type'];
|
1564 |
}
|
1565 |
-
if(!empty($data['playtime_seconds']))
|
1566 |
$metadata['length'] = (int)ceil($data['playtime_seconds']);
|
1567 |
}
|
1568 |
-
if(!empty($data['playtime_string']))
|
1569 |
$metadata['length_formatted'] = $data['playtime_string'];
|
1570 |
}
|
1571 |
-
if(!empty($data['video']['resolution_x']))
|
1572 |
$metadata['width'] = (int)$data['video']['resolution_x'];
|
1573 |
}
|
1574 |
-
if(!empty($data['video']['resolution_y']))
|
1575 |
$metadata['height'] = (int)$data['video']['resolution_y'];
|
1576 |
}
|
1577 |
-
if(!empty($data['fileformat']))
|
1578 |
$metadata['fileformat'] = $data['fileformat'];
|
1579 |
}
|
1580 |
-
if(!empty($data['video']['dataformat']))
|
1581 |
$metadata['dataformat'] = $data['video']['dataformat'];
|
1582 |
}
|
1583 |
-
if(!empty($data['video']['encoder']))
|
1584 |
$metadata['encoder'] = $data['video']['encoder'];
|
1585 |
}
|
1586 |
-
if(!empty($data['video']['codec']))
|
1587 |
$metadata['codec'] = $data['video']['codec'];
|
1588 |
}
|
1589 |
|
1590 |
-
if(!empty($data['audio']))
|
1591 |
unset($data['audio']['streams']);
|
1592 |
$metadata['audio'] = $data['audio'];
|
1593 |
}
|
@@ -1599,49 +1601,48 @@ class GmediaCore {
|
|
1599 |
|
1600 |
/**
|
1601 |
* Retrieve metadata from a audio file's ID3 tags
|
1602 |
-
*
|
1603 |
* @since 3.6.0
|
1604 |
*
|
1605 |
* @param string $file Path to file.
|
1606 |
*
|
1607 |
* @return array|boolean Returns array of metadata, if found.
|
1608 |
*/
|
1609 |
-
function wp_read_audio_metadata($file)
|
1610 |
-
if(!file_exists($file))
|
1611 |
return false;
|
1612 |
}
|
1613 |
$metadata = array();
|
1614 |
|
1615 |
-
if(!class_exists('getID3'))
|
1616 |
require(ABSPATH . WPINC . '/ID3/getid3.php');
|
1617 |
}
|
1618 |
$id3 = new getID3();
|
1619 |
$data = $id3->analyze($file);
|
1620 |
|
1621 |
-
if(!empty($data['audio']))
|
1622 |
unset($data['audio']['streams']);
|
1623 |
$metadata = $data['audio'];
|
1624 |
}
|
1625 |
|
1626 |
-
if(!empty($data['fileformat']))
|
1627 |
$metadata['fileformat'] = $data['fileformat'];
|
1628 |
}
|
1629 |
-
if(!empty($data['filesize']))
|
1630 |
$metadata['filesize'] = (int)$data['filesize'];
|
1631 |
}
|
1632 |
-
if(!empty($data['mime_type']))
|
1633 |
$metadata['mime_type'] = $data['mime_type'];
|
1634 |
}
|
1635 |
-
if(!empty($data['playtime_seconds']))
|
1636 |
$metadata['length'] = (int)ceil($data['playtime_seconds']);
|
1637 |
}
|
1638 |
-
if(!empty($data['playtime_string']))
|
1639 |
$metadata['length_formatted'] = $data['playtime_string'];
|
1640 |
}
|
1641 |
|
1642 |
$this->wp_add_id3_tag_data($metadata, $data);
|
1643 |
|
1644 |
-
if(isset($metadata['image']['data']) && !empty($metadata['image']['data']))
|
1645 |
$image = 'data:' . $metadata['image']['mime'] . ';charset=utf-8;base64,' . base64_encode($metadata['image']['data']);
|
1646 |
$metadata['image']['data'] = $image;
|
1647 |
}
|
@@ -1659,8 +1660,8 @@ class GmediaCore {
|
|
1659 |
*
|
1660 |
* @return array
|
1661 |
*/
|
1662 |
-
function gmedia_upload_handler($file_tmp, $fileinfo, $content_type, $post_data)
|
1663 |
-
global $gmGallery, $gmDB
|
1664 |
|
1665 |
$cleanup_dir = true; // Remove old files
|
1666 |
$file_age = 5 * 3600; // Temp file age in seconds
|
@@ -1668,48 +1669,43 @@ class GmediaCore {
|
|
1668 |
$chunks = (int)$this->_req('chunks', 0);
|
1669 |
|
1670 |
// try to make grand-media dir if not exists
|
1671 |
-
if(!wp_mkdir_p($fileinfo['dirpath']))
|
1672 |
-
$return = array(
|
1673 |
-
|
1674 |
-
|
1675 |
-
"
|
1676 |
-
),
|
1677 |
-
"id" => $fileinfo['basename']
|
1678 |
);
|
1679 |
|
1680 |
return $return;
|
1681 |
}
|
1682 |
// Check if grand-media dir is writable
|
1683 |
-
if(!is_writable($fileinfo['dirpath']))
|
1684 |
@chmod($fileinfo['dirpath'], 0755);
|
1685 |
-
if(!is_writable($fileinfo['dirpath']))
|
1686 |
-
$return = array(
|
1687 |
-
|
1688 |
-
|
1689 |
-
"
|
1690 |
-
),
|
1691 |
-
"id" => $fileinfo['basename']
|
1692 |
);
|
1693 |
|
1694 |
return $return;
|
1695 |
}
|
1696 |
}
|
1697 |
// Remove old temp files
|
1698 |
-
if($cleanup_dir && is_dir($fileinfo['dirpath']) && ($_dir = opendir($fileinfo['dirpath'])))
|
1699 |
-
while(($_file = readdir($_dir)) !== false)
|
1700 |
$tmpfilePath = $fileinfo['dirpath'] . DIRECTORY_SEPARATOR . $_file;
|
1701 |
|
1702 |
// Remove temp file if it is older than the max age and is not the current file
|
1703 |
-
if(preg_match('/\.part$/', $_file) && (filemtime($tmpfilePath) < time() - $file_age) && ($tmpfilePath != $fileinfo['filepath'] . '.part'))
|
1704 |
@unlink($tmpfilePath);
|
1705 |
}
|
1706 |
}
|
1707 |
|
1708 |
closedir($_dir);
|
1709 |
-
} else
|
1710 |
-
$return = array(
|
1711 |
-
|
1712 |
-
"id" => $fileinfo['basename']
|
1713 |
);
|
1714 |
|
1715 |
return $return;
|
@@ -1717,25 +1713,25 @@ class GmediaCore {
|
|
1717 |
|
1718 |
// Open temp file
|
1719 |
$out = fopen($fileinfo['filepath'] . '.part', $chunk == 0? "wb" : "ab");
|
1720 |
-
if($out)
|
1721 |
// Read binary input stream and append it to temp file
|
1722 |
$in = fopen($file_tmp, "rb");
|
1723 |
|
1724 |
-
if($in)
|
1725 |
-
while(($buff = fread($in, 4096)))
|
1726 |
fwrite($out, $buff);
|
1727 |
}
|
1728 |
-
} else
|
1729 |
$return = array("error" => array("code" => 101, "message" => __("Failed to open input stream.", 'grand-media')), "id" => $fileinfo['basename']);
|
1730 |
|
1731 |
return $return;
|
1732 |
}
|
1733 |
fclose($in);
|
1734 |
fclose($out);
|
1735 |
-
if(strpos($content_type, "multipart") !== false)
|
1736 |
@unlink($file_tmp);
|
1737 |
}
|
1738 |
-
if(!$chunks || $chunk == ($chunks - 1))
|
1739 |
sleep(1);
|
1740 |
// Strip the temp .part suffix off
|
1741 |
rename($fileinfo['filepath'] . '.part', $fileinfo['filepath']);
|
@@ -1744,15 +1740,15 @@ class GmediaCore {
|
|
1744 |
|
1745 |
$size = false;
|
1746 |
$is_webimage = false;
|
1747 |
-
if('image' == $fileinfo['dirname'])
|
1748 |
/** WordPress Image Administration API */
|
1749 |
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
1750 |
|
1751 |
$size = @getimagesize($fileinfo['filepath']);
|
1752 |
-
if($size && file_is_displayable_image($fileinfo['filepath']))
|
1753 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
1754 |
-
if(function_exists('memory_get_usage'))
|
1755 |
-
switch($extensions[$size[2]])
|
1756 |
case 'GIF':
|
1757 |
$CHANNEL = 1;
|
1758 |
break;
|
@@ -1774,66 +1770,61 @@ class GmediaCore {
|
|
1774 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
1775 |
$current_limit = @ini_get('memory_limit');
|
1776 |
$current_limit_int = intval($current_limit);
|
1777 |
-
if(false !== strpos($current_limit, 'M'))
|
1778 |
$current_limit_int *= $MB;
|
1779 |
}
|
1780 |
-
if(false !== strpos($current_limit, 'G'))
|
1781 |
$current_limit_int *= 1024;
|
1782 |
}
|
1783 |
|
1784 |
-
if(-1 != $current_limit && $memoryNeeded > $current_limit_int)
|
1785 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
|
|
|
|
|
|
1786 |
@ini_set('memory_limit', $newLimit . 'M');
|
1787 |
}
|
1788 |
}
|
1789 |
|
1790 |
-
if(!wp_mkdir_p($fileinfo['dirpath_thumb']))
|
1791 |
-
$return = array(
|
1792 |
-
|
1793 |
-
|
1794 |
-
"
|
1795 |
-
),
|
1796 |
-
"id" => $fileinfo['basename']
|
1797 |
);
|
1798 |
|
1799 |
return $return;
|
1800 |
}
|
1801 |
-
if(!is_writable($fileinfo['dirpath_thumb']))
|
1802 |
@chmod($fileinfo['dirpath_thumb'], 0755);
|
1803 |
-
if(!is_writable($fileinfo['dirpath_thumb']))
|
1804 |
@unlink($fileinfo['filepath']);
|
1805 |
-
$return = array(
|
1806 |
-
|
1807 |
-
|
1808 |
-
"
|
1809 |
-
),
|
1810 |
-
"id" => $fileinfo['basename']
|
1811 |
);
|
1812 |
|
1813 |
return $return;
|
1814 |
}
|
1815 |
}
|
1816 |
-
if(!wp_mkdir_p($fileinfo['dirpath_original']))
|
1817 |
-
$return = array(
|
1818 |
-
|
1819 |
-
|
1820 |
-
"
|
1821 |
-
),
|
1822 |
-
"id" => $fileinfo['basename']
|
1823 |
);
|
1824 |
|
1825 |
return $return;
|
1826 |
}
|
1827 |
-
if(!is_writable($fileinfo['dirpath_original']))
|
1828 |
@chmod($fileinfo['dirpath_original'], 0755);
|
1829 |
-
if(!is_writable($fileinfo['dirpath_original']))
|
1830 |
@unlink($fileinfo['filepath']);
|
1831 |
-
$return = array(
|
1832 |
-
|
1833 |
-
|
1834 |
-
"
|
1835 |
-
),
|
1836 |
-
"id" => $fileinfo['basename']
|
1837 |
);
|
1838 |
|
1839 |
return $return;
|
@@ -1846,18 +1837,18 @@ class GmediaCore {
|
|
1846 |
|
1847 |
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
1848 |
|
1849 |
-
if($webimg['resize'])
|
1850 |
rename($fileinfo['filepath'], $fileinfo['filepath_original']);
|
1851 |
-
} else
|
1852 |
copy($fileinfo['filepath'], $fileinfo['filepath_original']);
|
1853 |
}
|
1854 |
|
1855 |
$size_ratio = $size[0] / $size[1];
|
1856 |
|
1857 |
$angle = 0;
|
1858 |
-
$image_meta = @$
|
1859 |
-
if(!empty($image_meta['orientation']))
|
1860 |
-
switch($image_meta['orientation'])
|
1861 |
case 3:
|
1862 |
$angle = 180;
|
1863 |
break;
|
@@ -1874,36 +1865,34 @@ class GmediaCore {
|
|
1874 |
|
1875 |
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
1876 |
|
1877 |
-
if($webimg['resize'] || $thumbimg['resize'] || $angle)
|
1878 |
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
1879 |
-
if(is_wp_error($editor))
|
1880 |
@unlink($fileinfo['filepath']);
|
1881 |
@unlink($fileinfo['filepath_original']);
|
1882 |
-
$return = array(
|
1883 |
-
|
1884 |
-
|
1885 |
-
"tip" => 'wp_get_image_editor'
|
1886 |
);
|
1887 |
|
1888 |
return $return;
|
1889 |
}
|
1890 |
|
1891 |
-
if($angle)
|
1892 |
$editor->rotate($angle);
|
1893 |
}
|
1894 |
|
1895 |
-
if($webimg['resize'] || $angle)
|
1896 |
$editor->set_quality($webimg['quality']);
|
1897 |
|
1898 |
-
if($webimg['resize'])
|
1899 |
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
1900 |
-
if(is_wp_error($resized))
|
1901 |
@unlink($fileinfo['filepath']);
|
1902 |
@unlink($fileinfo['filepath_original']);
|
1903 |
-
$return = array(
|
1904 |
-
|
1905 |
-
|
1906 |
-
"tip" => "editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})"
|
1907 |
);
|
1908 |
|
1909 |
return $return;
|
@@ -1911,40 +1900,38 @@ class GmediaCore {
|
|
1911 |
}
|
1912 |
|
1913 |
$saved = $editor->save($fileinfo['filepath']);
|
1914 |
-
if(is_wp_error($saved))
|
1915 |
@unlink($fileinfo['filepath']);
|
1916 |
@unlink($fileinfo['filepath_original']);
|
1917 |
-
$return = array(
|
1918 |
-
|
1919 |
-
|
1920 |
-
"tip" => 'editor->save->webimage'
|
1921 |
);
|
1922 |
|
1923 |
return $return;
|
1924 |
}
|
1925 |
|
1926 |
-
if(('JPG' == $extensions[$size[2]]) && !(extension_loaded('imagick') || class_exists("Imagick")))
|
1927 |
$this->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
1928 |
}
|
1929 |
}
|
1930 |
|
1931 |
// Thumbnail
|
1932 |
$editor->set_quality($thumbimg['quality']);
|
1933 |
-
if($thumbimg['resize'])
|
1934 |
$ed_size = $editor->get_size();
|
1935 |
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
1936 |
-
if(1 > $ed_ratio)
|
1937 |
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
1938 |
-
} else
|
1939 |
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
1940 |
}
|
1941 |
-
if(is_wp_error($resized))
|
1942 |
@unlink($fileinfo['filepath']);
|
1943 |
@unlink($fileinfo['filepath_original']);
|
1944 |
-
$return = array(
|
1945 |
-
|
1946 |
-
|
1947 |
-
"tip" => "editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})"
|
1948 |
);
|
1949 |
|
1950 |
return $return;
|
@@ -1952,27 +1939,25 @@ class GmediaCore {
|
|
1952 |
}
|
1953 |
|
1954 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
1955 |
-
if(is_wp_error($saved))
|
1956 |
@unlink($fileinfo['filepath']);
|
1957 |
@unlink($fileinfo['filepath_original']);
|
1958 |
-
$return = array(
|
1959 |
-
|
1960 |
-
|
1961 |
-
"tip" => 'editor->save->thumb'
|
1962 |
);
|
1963 |
|
1964 |
return $return;
|
1965 |
}
|
1966 |
|
1967 |
-
} else
|
1968 |
copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
1969 |
}
|
1970 |
$is_webimage = true;
|
1971 |
-
} else
|
1972 |
@unlink($fileinfo['filepath']);
|
1973 |
-
$return = array(
|
1974 |
-
|
1975 |
-
"id" => $fileinfo['basename']
|
1976 |
);
|
1977 |
|
1978 |
return $return;
|
@@ -1984,103 +1969,102 @@ class GmediaCore {
|
|
1984 |
$description = '';
|
1985 |
$link = '';
|
1986 |
$date = null;
|
1987 |
-
if(!isset($post_data['set_title']))
|
1988 |
$post_data['set_title'] = 'filename';
|
1989 |
}
|
1990 |
-
if(!isset($post_data['set_status']))
|
1991 |
$post_data['set_status'] = isset($post_data['status'])? $post_data['status'] : 'inherit';
|
1992 |
}
|
1993 |
|
1994 |
$keywords = array();
|
1995 |
// use image exif/iptc data for title and caption defaults if possible
|
1996 |
-
if($size)
|
1997 |
-
if(!empty($image_meta))
|
1998 |
-
if('exif' == $post_data['set_title'])
|
1999 |
-
if(!empty($image_meta['title']) && trim($image_meta['title']))
|
2000 |
$title = $image_meta['title'];
|
2001 |
}
|
2002 |
}
|
2003 |
-
if(!empty($image_meta['caption']) && trim($image_meta['caption']))
|
2004 |
$description = $image_meta['caption'];
|
2005 |
}
|
2006 |
-
if(!empty($image_meta['keywords']))
|
2007 |
$keywords = $image_meta['keywords'];
|
2008 |
}
|
2009 |
}
|
2010 |
-
} else
|
2011 |
$file_meta = $this->get_file_metadata($fileinfo['filepath_original'], $fileinfo);
|
2012 |
-
if(!empty($file_meta))
|
2013 |
-
if('exif' == $post_data['set_title'])
|
2014 |
-
if(!empty($file_meta['title']) && trim($file_meta['title']))
|
2015 |
$title = $file_meta['title'];
|
2016 |
}
|
2017 |
}
|
2018 |
-
if(!empty($file_meta['comment']) && trim($file_meta['comment']))
|
2019 |
$description = $file_meta['comment'];
|
2020 |
}
|
2021 |
-
if(!empty($file_meta['album']) && (!isset($post_data['terms']['gmedia_album']) || empty($post_data['terms']['gmedia_album'])))
|
2022 |
$post_data['terms']['gmedia_album'] = array($file_meta['album']);
|
2023 |
}
|
2024 |
}
|
2025 |
}
|
2026 |
-
if(('empty' != $post_data['set_title']) && empty($title))
|
2027 |
$title = $fileinfo['title'];
|
2028 |
}
|
2029 |
|
2030 |
-
if('public' == $post_data['set_status'])
|
2031 |
$post_data['set_status'] = 'publish';
|
2032 |
}
|
2033 |
|
2034 |
$status = $post_data['set_status'];
|
2035 |
-
if('inherit' == $post_data['set_status'])
|
2036 |
$gmedia_album = isset($post_data['terms']['gmedia_album'])? $post_data['terms']['gmedia_album'] : false;
|
2037 |
-
if($gmedia_album && $this->is_digit($gmedia_album))
|
2038 |
$album = $gmDB->get_term($gmedia_album);
|
2039 |
-
if(empty($album) || is_wp_error($album))
|
2040 |
$status = 'publish';
|
2041 |
-
} else
|
2042 |
$status = $album->status;
|
2043 |
}
|
2044 |
-
} else
|
2045 |
$status = 'publish';
|
2046 |
}
|
2047 |
}
|
2048 |
|
2049 |
unset($post_data['gmuid'], $post_data['mime_type'], $post_data['set_title'], $post_data['set_status']);
|
2050 |
|
2051 |
-
if(isset($post_data['terms']['gmedia_category']) && !empty($post_data['terms']['gmedia_category']))
|
2052 |
-
if(!is_array($post_data['terms']['gmedia_category']))
|
2053 |
$post_data['terms']['gmedia_category'] = explode(',', $post_data['terms']['gmedia_category']);
|
2054 |
}
|
2055 |
-
} else
|
2056 |
$post_data['terms']['gmedia_category'] = array();
|
2057 |
}
|
2058 |
|
2059 |
-
if(isset($post_data['terms']['gmedia_tag']) && !empty($post_data['terms']['gmedia_tag']))
|
2060 |
-
if(!is_array($post_data['terms']['gmedia_tag']))
|
2061 |
$post_data['terms']['gmedia_tag'] = explode(',', $post_data['terms']['gmedia_tag']);
|
2062 |
}
|
2063 |
-
} else
|
2064 |
$post_data['terms']['gmedia_tag'] = array();
|
2065 |
}
|
2066 |
-
if(!empty($keywords))
|
2067 |
$post_data['terms']['gmedia_tag'] = array_unique(array_merge($post_data['terms']['gmedia_tag'], $keywords));
|
2068 |
}
|
2069 |
|
2070 |
// Construct the media array
|
2071 |
-
$media_data = array(
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
|
2078 |
-
'date' => $date
|
2079 |
);
|
2080 |
|
2081 |
$media_data = $this->array_replace_recursive($media_data, $post_data);
|
2082 |
|
2083 |
-
if(!current_user_can('gmedia_delete_others_media'))
|
2084 |
$media_data['author'] = get_current_user_id();
|
2085 |
}
|
2086 |
|
@@ -2088,31 +2072,33 @@ class GmediaCore {
|
|
2088 |
$id = $gmDB->insert_gmedia($media_data);
|
2089 |
|
2090 |
$media_metadata = $gmDB->generate_gmedia_metadata($id, $fileinfo);
|
2091 |
-
if($size && !empty($image_meta))
|
2092 |
-
if(empty($media_metadata['image_meta']))
|
2093 |
$media_metadata['image_meta'] = $image_meta;
|
2094 |
}
|
2095 |
-
if(!empty($image_meta['created_timestamp']))
|
2096 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_created_timestamp', $image_meta['created_timestamp']);
|
2097 |
}
|
2098 |
-
if(!empty($image_meta['GPS']))
|
2099 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_gps', $image_meta['GPS']);
|
2100 |
}
|
2101 |
}
|
2102 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $media_metadata);
|
2103 |
-
|
2104 |
-
$
|
2105 |
-
|
2106 |
-
|
|
|
|
|
2107 |
);
|
2108 |
|
2109 |
return $return;
|
2110 |
-
} else
|
2111 |
$return = array("success" => array("code" => 199, "message" => $chunk . '/' . $chunks), "id" => $fileinfo['basename']);
|
2112 |
|
2113 |
return $return;
|
2114 |
}
|
2115 |
-
} else
|
2116 |
$return = array("error" => array("code" => 102, "message" => __("Failed to open output stream.", 'grand-media')), "id" => $fileinfo['basename']);
|
2117 |
|
2118 |
return $return;
|
@@ -2123,79 +2109,82 @@ class GmediaCore {
|
|
2123 |
* @param $from_file
|
2124 |
* @param $to_file
|
2125 |
*/
|
2126 |
-
function copy_exif($from_file, $to_file)
|
2127 |
|
2128 |
$size = @getimagesize($to_file);
|
2129 |
|
2130 |
-
if($size)
|
2131 |
require_once(dirname(__FILE__) . '/pel/autoload.php');
|
2132 |
-
|
2133 |
-
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
|
2138 |
-
|
2139 |
-
|
2140 |
-
|
2141 |
-
|
2142 |
-
|
2143 |
-
|
2144 |
-
|
2145 |
-
|
2146 |
-
|
2147 |
-
|
2148 |
-
|
2149 |
-
|
2150 |
-
|
|
|
2151 |
|
2152 |
-
|
2153 |
-
|
2154 |
|
2155 |
-
|
2156 |
-
|
2157 |
-
|
2158 |
-
|
2159 |
|
2160 |
-
|
2161 |
-
|
2162 |
-
|
2163 |
-
|
2164 |
-
|
2165 |
-
|
2166 |
-
|
2167 |
-
|
2168 |
-
|
2169 |
-
|
2170 |
-
|
2171 |
-
|
2172 |
-
|
2173 |
-
|
2174 |
-
|
|
|
2175 |
}
|
2176 |
-
|
2177 |
-
|
2178 |
-
|
2179 |
-
|
2180 |
-
|
2181 |
-
|
2182 |
-
|
2183 |
}
|
2184 |
-
|
2185 |
-
|
2186 |
-
|
2187 |
-
|
2188 |
-
|
2189 |
-
|
2190 |
-
|
2191 |
}
|
2192 |
-
}
|
2193 |
|
2194 |
-
|
2195 |
-
|
2196 |
|
2197 |
-
|
2198 |
-
|
|
|
|
|
2199 |
}
|
2200 |
}
|
2201 |
}
|
@@ -2207,45 +2196,45 @@ class GmediaCore {
|
|
2207 |
* @param $move
|
2208 |
* @param int|string $exists
|
2209 |
*/
|
2210 |
-
function gmedia_import_files($files, $_terms, $move, $exists = 0)
|
2211 |
-
global $
|
2212 |
|
2213 |
-
if(ob_get_level() == 0)
|
2214 |
ob_start();
|
2215 |
}
|
2216 |
$eol = '</pre>' . PHP_EOL;
|
2217 |
|
2218 |
$gmedia_album = isset($_terms['gmedia_album'])? $_terms['gmedia_album'] : false;
|
2219 |
-
if($gmedia_album && $
|
2220 |
$album = $gmDB->get_term($gmedia_album);
|
2221 |
-
if(empty($album) || is_wp_error($album))
|
2222 |
$_status = 'publish';
|
2223 |
-
} else
|
2224 |
$_status = $album->status;
|
2225 |
$album_name = $album->name;
|
2226 |
}
|
2227 |
-
} else
|
2228 |
$_status = 'publish';
|
2229 |
}
|
2230 |
|
2231 |
-
if(isset($_terms['gmedia_category']) && !empty($_terms['gmedia_category']))
|
2232 |
-
if(!is_array($_terms['gmedia_category']))
|
2233 |
$_terms['gmedia_category'] = explode(',', $_terms['gmedia_category']);
|
2234 |
}
|
2235 |
-
} else
|
2236 |
$_terms['gmedia_category'] = array();
|
2237 |
}
|
2238 |
-
if(isset($_terms['gmedia_tag']) && !empty($_terms['gmedia_tag']))
|
2239 |
-
if(!is_array($_terms['gmedia_tag']))
|
2240 |
$_terms['gmedia_tag'] = explode(',', $_terms['gmedia_tag']);
|
2241 |
}
|
2242 |
-
} else
|
2243 |
$_terms['gmedia_tag'] = array();
|
2244 |
}
|
2245 |
|
2246 |
$c = count($files);
|
2247 |
$i = 0;
|
2248 |
-
foreach($files as $file)
|
2249 |
|
2250 |
$title = '';
|
2251 |
$description = '';
|
@@ -2253,10 +2242,10 @@ class GmediaCore {
|
|
2253 |
$status = $_status;
|
2254 |
$terms = $_terms;
|
2255 |
|
2256 |
-
if(is_array($file))
|
2257 |
-
if(isset($file['file']))
|
2258 |
extract($file);
|
2259 |
-
} else
|
2260 |
_e('Something went wrong...', 'grand-media');
|
2261 |
die();
|
2262 |
}
|
@@ -2265,60 +2254,68 @@ class GmediaCore {
|
|
2265 |
wp_ob_end_flush_all();
|
2266 |
flush();
|
2267 |
|
2268 |
-
$i++;
|
2269 |
$prefix = "\n<pre>$i/$c - ";
|
2270 |
$prefix_ko = "\n<pre class='ko'>$i/$c - ";
|
2271 |
|
2272 |
-
if(!is_file($file))
|
2273 |
echo $prefix_ko . sprintf(__('File not exists: %s', 'grand-media'), $file) . $eol;
|
2274 |
continue;
|
2275 |
}
|
2276 |
|
2277 |
-
if('skip' === $exists)
|
2278 |
$file_suffix = false;
|
2279 |
-
} else
|
2280 |
$file_suffix = $exists;
|
2281 |
}
|
2282 |
-
$fileinfo = $
|
2283 |
|
2284 |
-
if(('skip' === $exists) && file_exists($fileinfo['filepath']))
|
2285 |
-
echo $prefix . $fileinfo['
|
2286 |
continue;
|
2287 |
}
|
2288 |
|
2289 |
|
2290 |
// try to make grand-media dir if not exists
|
2291 |
-
if(!wp_mkdir_p($fileinfo['dirpath']))
|
2292 |
echo $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath']) . $eol;
|
2293 |
continue;
|
2294 |
}
|
2295 |
// Check if grand-media dir is writable
|
2296 |
-
if(!is_writable($fileinfo['dirpath']))
|
2297 |
@chmod($fileinfo['dirpath'], 0755);
|
2298 |
-
if(!is_writable($fileinfo['dirpath']))
|
2299 |
echo $prefix_ko . sprintf(__('Directory `%s` or its subfolders are not writable by the server.', 'grand-media'), dirname($fileinfo['dirpath'])) . $eol;
|
2300 |
continue;
|
2301 |
}
|
2302 |
}
|
2303 |
|
2304 |
-
if(($file != $fileinfo['filepath']) && !copy($file, $fileinfo['filepath']))
|
2305 |
echo $prefix_ko . sprintf(__("Can't copy file from `%s` to `%s`", 'grand-media'), $file, $fileinfo['filepath']) . $eol;
|
2306 |
continue;
|
2307 |
}
|
2308 |
|
2309 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2310 |
|
2311 |
$size = false;
|
2312 |
$is_webimage = false;
|
2313 |
-
if('image' == $fileinfo['dirname'])
|
2314 |
/** WordPress Image Administration API */
|
2315 |
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
2316 |
|
2317 |
$size = @getimagesize($fileinfo['filepath']);
|
2318 |
-
if($size && file_is_displayable_image($fileinfo['filepath']))
|
2319 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
2320 |
-
if(function_exists('memory_get_usage'))
|
2321 |
-
switch($extensions[$size[2]])
|
2322 |
case 'GIF':
|
2323 |
$CHANNEL = 1;
|
2324 |
break;
|
@@ -2340,38 +2337,41 @@ class GmediaCore {
|
|
2340 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
2341 |
$current_limit = @ini_get('memory_limit');
|
2342 |
$current_limit_int = intval($current_limit);
|
2343 |
-
if(false !== strpos($current_limit, 'M'))
|
2344 |
$current_limit_int *= $MB;
|
2345 |
}
|
2346 |
-
if(false !== strpos($current_limit, 'G'))
|
2347 |
$current_limit_int *= 1024;
|
2348 |
}
|
2349 |
|
2350 |
-
if(-1 != $current_limit && $memoryNeeded > $current_limit_int)
|
2351 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
|
|
|
|
|
|
2352 |
@ini_set('memory_limit', $newLimit . 'M');
|
2353 |
}
|
2354 |
}
|
2355 |
|
2356 |
-
if(!wp_mkdir_p($fileinfo['dirpath_thumb']))
|
2357 |
echo $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
2358 |
continue;
|
2359 |
}
|
2360 |
-
if(!is_writable($fileinfo['dirpath_thumb']))
|
2361 |
@chmod($fileinfo['dirpath_thumb'], 0755);
|
2362 |
-
if(!is_writable($fileinfo['dirpath_thumb']))
|
2363 |
@unlink($fileinfo['filepath']);
|
2364 |
echo $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
2365 |
continue;
|
2366 |
}
|
2367 |
}
|
2368 |
-
if(!wp_mkdir_p($fileinfo['dirpath_original']))
|
2369 |
echo $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
2370 |
continue;
|
2371 |
}
|
2372 |
-
if(!is_writable($fileinfo['dirpath_original']))
|
2373 |
@chmod($fileinfo['dirpath_original'], 0755);
|
2374 |
-
if(!is_writable($fileinfo['dirpath_original']))
|
2375 |
@unlink($fileinfo['filepath']);
|
2376 |
echo $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
2377 |
continue;
|
@@ -2384,18 +2384,18 @@ class GmediaCore {
|
|
2384 |
|
2385 |
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
2386 |
|
2387 |
-
if($webimg['resize'])
|
2388 |
rename($fileinfo['filepath'], $fileinfo['filepath_original']);
|
2389 |
-
} else
|
2390 |
copy($fileinfo['filepath'], $fileinfo['filepath_original']);
|
2391 |
}
|
2392 |
|
2393 |
$size_ratio = $size[0] / $size[1];
|
2394 |
|
2395 |
$angle = 0;
|
2396 |
-
$image_meta = @$
|
2397 |
-
if(!empty($image_meta['orientation']))
|
2398 |
-
switch($image_meta['orientation'])
|
2399 |
case 3:
|
2400 |
$angle = 180;
|
2401 |
break;
|
@@ -2412,25 +2412,25 @@ class GmediaCore {
|
|
2412 |
|
2413 |
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
2414 |
|
2415 |
-
if($webimg['resize'] || $thumbimg['resize'] || $angle)
|
2416 |
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
2417 |
-
if(is_wp_error($editor))
|
2418 |
@unlink($fileinfo['filepath']);
|
2419 |
@unlink($fileinfo['filepath_original']);
|
2420 |
echo $prefix_ko . $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message() . $eol;
|
2421 |
continue;
|
2422 |
}
|
2423 |
|
2424 |
-
if($angle)
|
2425 |
$editor->rotate($angle);
|
2426 |
}
|
2427 |
|
2428 |
-
if($webimg['resize'] || $angle)
|
2429 |
$editor->set_quality($webimg['quality']);
|
2430 |
|
2431 |
-
if($webimg['resize'])
|
2432 |
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
2433 |
-
if(is_wp_error($resized))
|
2434 |
@unlink($fileinfo['filepath']);
|
2435 |
@unlink($fileinfo['filepath_original']);
|
2436 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})): " . $resized->get_error_message() . $eol;
|
@@ -2439,14 +2439,14 @@ class GmediaCore {
|
|
2439 |
}
|
2440 |
|
2441 |
$saved = $editor->save($fileinfo['filepath']);
|
2442 |
-
if(is_wp_error($saved))
|
2443 |
@unlink($fileinfo['filepath']);
|
2444 |
@unlink($fileinfo['filepath_original']);
|
2445 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->webimage): " . $saved->get_error_message() . $eol;
|
2446 |
continue;
|
2447 |
}
|
2448 |
|
2449 |
-
if(('JPG' == $extensions[$size[2]]) && !(extension_loaded('imagick') || class_exists("Imagick")))
|
2450 |
$this->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
2451 |
}
|
2452 |
|
@@ -2454,15 +2454,15 @@ class GmediaCore {
|
|
2454 |
|
2455 |
// Thumbnail
|
2456 |
$editor->set_quality($thumbimg['quality']);
|
2457 |
-
if($thumbimg['resize'])
|
2458 |
$ed_size = $editor->get_size();
|
2459 |
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
2460 |
-
if(1 > $ed_ratio)
|
2461 |
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
2462 |
-
} else
|
2463 |
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
2464 |
}
|
2465 |
-
if(is_wp_error($resized))
|
2466 |
@unlink($fileinfo['filepath']);
|
2467 |
@unlink($fileinfo['filepath_original']);
|
2468 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})): " . $resized->get_error_message() . $eol;
|
@@ -2471,17 +2471,17 @@ class GmediaCore {
|
|
2471 |
}
|
2472 |
|
2473 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
2474 |
-
if(is_wp_error($saved))
|
2475 |
@unlink($fileinfo['filepath']);
|
2476 |
@unlink($fileinfo['filepath_original']);
|
2477 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message() . $eol;
|
2478 |
continue;
|
2479 |
}
|
2480 |
-
} else
|
2481 |
copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
2482 |
}
|
2483 |
$is_webimage = true;
|
2484 |
-
} else
|
2485 |
@unlink($fileinfo['filepath']);
|
2486 |
echo $prefix_ko . $fileinfo['basename'] . ": " . __("Could not read image size. Invalid image was deleted.", 'grand-media') . $eol;
|
2487 |
continue;
|
@@ -2489,49 +2489,48 @@ class GmediaCore {
|
|
2489 |
}
|
2490 |
|
2491 |
// Write media data to DB
|
2492 |
-
if($size)
|
2493 |
-
if(!empty($image_meta))
|
2494 |
-
if(empty($title) && !empty($image_meta['title']) && trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title'])))
|
2495 |
$title = $image_meta['title'];
|
2496 |
}
|
2497 |
-
if(empty($description) && !empty($image_meta['caption']) && trim($image_meta['caption']))
|
2498 |
$description = $image_meta['caption'];
|
2499 |
}
|
2500 |
-
if(!empty($image_meta['keywords']))
|
2501 |
$terms['gmedia_tag'] = array_unique(array_merge((array)$_terms['gmedia_tag'], $image_meta['keywords']));
|
2502 |
}
|
2503 |
}
|
2504 |
-
} else
|
2505 |
$file_meta = $this->get_file_metadata($fileinfo['filepath_original'], $fileinfo);
|
2506 |
-
if(!empty($file_meta))
|
2507 |
-
if(empty($title) && !empty($file_meta['title']) && trim($file_meta['title']) && !is_numeric(sanitize_title($file_meta['title'])))
|
2508 |
$title = $file_meta['title'];
|
2509 |
}
|
2510 |
-
if(empty($description) && !empty($file_meta['comment']) && trim($file_meta['comment']))
|
2511 |
$description = $file_meta['comment'];
|
2512 |
}
|
2513 |
-
if(empty($terms['gmedia_album']) && !empty($file_meta['album']))
|
2514 |
$terms['gmedia_album'] = array($file_meta['album']);
|
2515 |
}
|
2516 |
}
|
2517 |
}
|
2518 |
|
2519 |
-
if(empty($title))
|
2520 |
$title = $fileinfo['title'];
|
2521 |
}
|
2522 |
|
2523 |
// Construct the media_data array
|
2524 |
-
$media_data = array(
|
2525 |
-
|
2526 |
-
|
2527 |
-
|
2528 |
-
|
2529 |
-
|
2530 |
-
|
2531 |
-
'terms' => $terms
|
2532 |
);
|
2533 |
|
2534 |
-
if(!current_user_can('gmedia_delete_others_media'))
|
2535 |
$media_data['author'] = get_current_user_id();
|
2536 |
}
|
2537 |
|
@@ -2539,22 +2538,25 @@ class GmediaCore {
|
|
2539 |
$id = $gmDB->insert_gmedia($media_data);
|
2540 |
|
2541 |
$media_metadata = $gmDB->generate_gmedia_metadata($id, $fileinfo);
|
2542 |
-
if($size && !empty($image_meta))
|
2543 |
-
if(empty($media_metadata['image_meta']))
|
2544 |
$media_metadata['image_meta'] = $image_meta;
|
2545 |
}
|
2546 |
-
if(!empty($image_meta['created_timestamp']))
|
2547 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_created_timestamp', $image_meta['created_timestamp']);
|
2548 |
}
|
2549 |
-
if(!empty($image_meta['GPS']))
|
2550 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_gps', $image_meta['GPS']);
|
2551 |
}
|
2552 |
}
|
2553 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $media_metadata);
|
|
|
|
|
|
|
2554 |
|
2555 |
echo $prefix . $fileinfo['basename'] . ': <span class="ok">' . sprintf(__('success (ID #%s)', 'grand-media'), $id) . '</span>' . $eol;
|
2556 |
|
2557 |
-
if($move)
|
2558 |
@unlink($file);
|
2559 |
}
|
2560 |
|
@@ -2568,21 +2570,266 @@ class GmediaCore {
|
|
2568 |
flush();
|
2569 |
}
|
2570 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2571 |
/**
|
2572 |
* @param string $service
|
2573 |
*
|
2574 |
* @return array json
|
2575 |
*/
|
2576 |
-
function app_service($service)
|
2577 |
global $gmGallery, $gmDB;
|
2578 |
|
2579 |
-
if('127.0.0.1' == $_SERVER['SERVER_ADDR'])
|
2580 |
return false;
|
2581 |
}
|
2582 |
-
if(!current_user_can('manage_options'))
|
2583 |
die('-1');
|
2584 |
}
|
2585 |
-
if(!$service)
|
2586 |
die('0');
|
2587 |
}
|
2588 |
|
@@ -2590,25 +2837,24 @@ class GmediaCore {
|
|
2590 |
$data = array();
|
2591 |
$options = $gmGallery->options;
|
2592 |
|
2593 |
-
if($service == 'app_deactivate')
|
2594 |
$options['mobile_app'] = 0;
|
2595 |
}
|
2596 |
|
2597 |
$data['site_email'] = $options['site_email'];
|
2598 |
-
if(in_array($service, array('app_updateinfo')) && !is_email($data['site_email']))
|
2599 |
$result['error'][] = __('Enter valid email, please', 'grand-media');
|
2600 |
-
} else
|
2601 |
|
2602 |
$url = home_url();
|
2603 |
$post_data = array('url' => $url);
|
2604 |
|
2605 |
-
if('app_uninstallplugin' == $service)
|
2606 |
-
if(!empty($options['site_ID']))
|
2607 |
$post_data['site_id'] = $options['site_ID'];
|
2608 |
-
wp_remote_post('http://gmediaservice.codeasily.com/?gmService=' . $service, array(
|
2609 |
-
|
2610 |
-
|
2611 |
-
'body' => $post_data
|
2612 |
));
|
2613 |
}
|
2614 |
|
@@ -2617,9 +2863,9 @@ class GmediaCore {
|
|
2617 |
|
2618 |
$hash = wp_generate_password('6', false);
|
2619 |
|
2620 |
-
if(in_array($service, array('app_activate', 'app_updateinfo')))
|
2621 |
$status = 1;
|
2622 |
-
} else
|
2623 |
$status = $options['mobile_app'];
|
2624 |
}
|
2625 |
$install_date = get_option('gmediaInstallDate');
|
@@ -2634,59 +2880,57 @@ class GmediaCore {
|
|
2634 |
$data['status'] = $status;
|
2635 |
$data['install_date'] = $install_date? $install_date : time();
|
2636 |
|
2637 |
-
$tagslist = $gmDB->get_terms('gmedia_tag', array(
|
2638 |
-
|
2639 |
-
|
2640 |
-
'no_found_rows' => true
|
2641 |
));
|
2642 |
-
if(!is_wp_error($tagslist))
|
2643 |
$data['tags'] = (array)$tagslist;
|
2644 |
-
} else
|
2645 |
$data['tags'] = array();
|
2646 |
}
|
2647 |
|
2648 |
set_transient($hash, $data, 45);
|
2649 |
|
2650 |
$post_data['hash'] = $hash;
|
2651 |
-
$gms_post = wp_remote_post('http://gmediaservice.codeasily.com/?gmService=' . $service, array(
|
2652 |
-
|
2653 |
-
|
2654 |
-
'body' => $post_data
|
2655 |
));
|
2656 |
-
if(is_wp_error($gms_post))
|
2657 |
$result['error'][] = $gms_post->get_error_message();
|
2658 |
}
|
2659 |
$gms_post_body = wp_remote_retrieve_body($gms_post);
|
2660 |
$_result = (array)json_decode($gms_post_body);
|
2661 |
-
if(isset($_result['error']))
|
2662 |
-
if(!isset($result['error']))
|
2663 |
$result['error'] = array();
|
2664 |
}
|
2665 |
$_result['error'] = (array)$_result['error'];
|
2666 |
$_result['error'] = array_filter($_result['error'], 'is_string');
|
2667 |
$result['error'] = array_merge($result['error'], $_result['error']);
|
2668 |
-
} else
|
2669 |
$result = array_merge($_result, $result);
|
2670 |
//$result['gms_post'] = $gms_post;
|
2671 |
//$result['gms_post_body'] = $gms_post_body;
|
2672 |
-
if(isset($result['message']))
|
2673 |
$result['message'] = $this->alert('info', $result['message']);
|
2674 |
}
|
2675 |
|
2676 |
-
if(isset($result['site_ID']))
|
2677 |
$options['site_ID'] = $result['site_ID'];
|
2678 |
}
|
2679 |
-
if(isset($result['mobile_app']))
|
2680 |
$options['mobile_app'] = $result['mobile_app'];
|
2681 |
}
|
2682 |
}
|
2683 |
-
if(isset($result['error']))
|
2684 |
$result['error'] = $this->alert('danger', $result['error']);
|
2685 |
}
|
2686 |
}
|
2687 |
update_option('gmediaOptions', $options);
|
2688 |
|
2689 |
-
if(in_array($service, array('app_activate', 'app_updateinfo')))
|
2690 |
wp_clear_scheduled_hook('gmedia_app_cronjob');
|
2691 |
wp_schedule_event(time(), 'gmedia_app', 'gmedia_app_cronjob');
|
2692 |
}
|
@@ -2699,80 +2943,92 @@ class GmediaCore {
|
|
2699 |
*
|
2700 |
* @return mixed
|
2701 |
*/
|
2702 |
-
function i18n_exif_name($key)
|
2703 |
$_key = strtolower($key);
|
2704 |
-
$tagnames = array(
|
2705 |
-
|
2706 |
-
|
2707 |
-
|
2708 |
-
|
2709 |
-
|
2710 |
-
|
2711 |
-
|
2712 |
-
|
2713 |
-
|
2714 |
-
|
2715 |
-
|
2716 |
-
|
2717 |
-
|
2718 |
-
|
2719 |
-
|
2720 |
-
|
2721 |
-
|
2722 |
-
|
2723 |
-
|
2724 |
-
|
2725 |
-
|
2726 |
-
|
2727 |
-
|
2728 |
-
|
2729 |
-
|
2730 |
-
|
2731 |
-
|
2732 |
-
|
2733 |
-
|
2734 |
-
|
2735 |
-
|
2736 |
-
|
2737 |
-
|
2738 |
-
|
2739 |
-
|
2740 |
-
|
2741 |
-
|
2742 |
-
|
2743 |
-
|
2744 |
-
|
2745 |
-
|
2746 |
-
|
2747 |
-
|
2748 |
-
|
2749 |
-
|
2750 |
-
'orientation' => __('Orientation', 'grand-media')
|
2751 |
);
|
2752 |
|
2753 |
-
if(isset($tagnames[$_key]))
|
2754 |
-
$key = $tagnames[$_key];
|
2755 |
}
|
2756 |
|
2757 |
return ($key);
|
2758 |
}
|
2759 |
|
2760 |
/**
|
2761 |
-
*
|
|
|
|
|
|
|
2762 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2763 |
* @since 1.6.3
|
2764 |
*
|
2765 |
* @param int $gmedia_id
|
2766 |
* @param string $meta_type
|
2767 |
*/
|
2768 |
-
function gmedia_custom_meta_box($gmedia_id, $meta_type = 'gmedia')
|
2769 |
global $gmDB;
|
2770 |
|
2771 |
-
if(empty($gmedia_id))
|
2772 |
return;
|
2773 |
}
|
2774 |
|
2775 |
-
if(!in_array($meta_type, array('gmedia', 'gmedia_term')))
|
2776 |
$meta_type = 'gmedia';
|
2777 |
}
|
2778 |
?>
|
@@ -2780,15 +3036,15 @@ class GmediaCore {
|
|
2780 |
<legend class="label label-default" style="font-size:85%;"><?php _e('Custom Fields', 'grand-media'); ?></legend>
|
2781 |
<?php
|
2782 |
$metadata = $gmDB->has_meta($gmedia_id, $meta_type);
|
2783 |
-
foreach($metadata as $key => $value)
|
2784 |
-
if(is_protected_meta($metadata[$key]['meta_key'], $meta_type))
|
2785 |
-
unset($metadata[$key]);
|
2786 |
}
|
2787 |
} ?>
|
2788 |
<div class="row">
|
2789 |
-
<?php if(!empty($metadata))
|
2790 |
//$count = 0;
|
2791 |
-
foreach($metadata as $entry)
|
2792 |
echo $this->_list_meta_item($entry);
|
2793 |
}
|
2794 |
} ?>
|
@@ -2806,12 +3062,12 @@ class GmediaCore {
|
|
2806 |
*
|
2807 |
* @return string|void
|
2808 |
*/
|
2809 |
-
function _list_meta_item($entry)
|
2810 |
-
if(is_serialized($entry['meta_value']))
|
2811 |
-
if(is_serialized_string($entry['meta_value']))
|
2812 |
// This is a serialized string, so we should display it.
|
2813 |
$entry['meta_value'] = maybe_unserialize($entry['meta_value']);
|
2814 |
-
} else
|
2815 |
// This is a serialized array/object so we should NOT display it.
|
2816 |
return;
|
2817 |
}
|
@@ -2835,17 +3091,16 @@ class GmediaCore {
|
|
2835 |
|
2836 |
/**
|
2837 |
* Prints the form in the Custom Fields meta box.
|
2838 |
-
*
|
2839 |
* @since 1.6.3
|
2840 |
*
|
2841 |
* @param string $meta_type
|
2842 |
*
|
2843 |
* @return string
|
2844 |
*/
|
2845 |
-
function meta_form($meta_type = 'gmedia')
|
2846 |
global $wpdb;
|
2847 |
|
2848 |
-
if(!in_array($meta_type, array('gmedia', 'gmedia_term')))
|
2849 |
$meta_type = 'gmedia';
|
2850 |
}
|
2851 |
|
@@ -2869,13 +3124,13 @@ class GmediaCore {
|
|
2869 |
<div class="row">
|
2870 |
<div class="form-group col-sm-6">
|
2871 |
<label>' . _x('Name', 'meta name') . '</label>';
|
2872 |
-
if($keys)
|
2873 |
natcasesort($keys);
|
2874 |
$meta_form .= '
|
2875 |
<select class="metakeyselect form-control input-sm" name="metakeyselect">
|
2876 |
<option value="">' . __('— Select —') . '</option>';
|
2877 |
-
foreach($keys as $key)
|
2878 |
-
if(is_protected_meta($key,
|
2879 |
continue;
|
2880 |
}
|
2881 |
$meta_form .= '
|
@@ -2887,7 +3142,7 @@ class GmediaCore {
|
|
2887 |
<a href="#gmediacustomstuff" class="hide-if-no-js gmediacustomstuff" onclick="jQuery(\'.metakeyinput, .metakeyselect, .enternew, .cancelnew\', \'#newmeta\').toggle();jQuery(this).parent().toggleClass(\'newcfield\');return false;">
|
2888 |
<span class="enternew">' . __('Enter new', 'grand-media') . '</span>
|
2889 |
<span class="cancelnew" style="display:none;">' . __('Cancel', 'grand-media') . '</span></a>';
|
2890 |
-
} else
|
2891 |
$meta_form .= '
|
2892 |
<input type="text" class="metakeyinput form-control input-sm" name="metakeyinput" value="" />';
|
2893 |
}
|
@@ -2912,10 +3167,10 @@ class GmediaCore {
|
|
2912 |
*
|
2913 |
* @return bool|int
|
2914 |
*/
|
2915 |
-
function add_meta($gmedia_ID, $meta_type = 'gmedia')
|
2916 |
global $gmDB;
|
2917 |
|
2918 |
-
if(!in_array($meta_type, array('gmedia', 'gmedia_term')))
|
2919 |
$meta_type = 'gmedia';
|
2920 |
}
|
2921 |
|
@@ -2924,22 +3179,22 @@ class GmediaCore {
|
|
2924 |
$metakeyselect = isset($_POST['metakeyselect'])? wp_unslash(trim($_POST['metakeyselect'])) : '';
|
2925 |
$metakeyinput = isset($_POST['metakeyinput'])? wp_unslash(trim($_POST['metakeyinput'])) : '';
|
2926 |
$metavalue = isset($_POST['metavalue'])? $_POST['metavalue'] : '';
|
2927 |
-
if(is_string($metavalue))
|
2928 |
$metavalue = trim($metavalue);
|
2929 |
}
|
2930 |
|
2931 |
-
if(('0' === $metavalue || !empty ($metavalue)) && ((!empty($metakeyselect) && !empty($metakeyselect)) || !empty ($metakeyinput)))
|
2932 |
/*
|
2933 |
* We have a key/value pair. If both the select and the input
|
2934 |
* for the key have data, the input takes precedence.
|
2935 |
*/
|
2936 |
$metakey = $metakeyselect;
|
2937 |
|
2938 |
-
if($metakeyinput)
|
2939 |
$metakey = $metakeyinput;
|
2940 |
} // default
|
2941 |
|
2942 |
-
if(is_protected_meta($metakey, $meta_type))
|
2943 |
return false;
|
2944 |
}
|
2945 |
|
@@ -2957,39 +3212,39 @@ class GmediaCore {
|
|
2957 |
*
|
2958 |
* @return array metadata[key] = array(name, value);
|
2959 |
*/
|
2960 |
-
function metadata_info($item)
|
2961 |
global $gmDB;
|
2962 |
|
2963 |
-
if(is_object($item))
|
2964 |
$item_id = $item->ID;
|
2965 |
-
} elseif($this->is_digit($item))
|
2966 |
$item_id = (int)$item;
|
2967 |
-
} else
|
2968 |
return null;
|
2969 |
}
|
2970 |
|
2971 |
$metadata = array();
|
2972 |
|
2973 |
$meta = $gmDB->get_metadata('gmedia', $item_id, '_metadata', true);
|
2974 |
-
if($meta)
|
2975 |
-
if(isset($meta['image_meta']))
|
2976 |
$metainfo = $meta['image_meta'];
|
2977 |
-
} else
|
2978 |
$metainfo = $meta;
|
2979 |
-
if(is_array($metainfo))
|
2980 |
unset($metainfo['web'], $metainfo['original'], $metainfo['thumb'], $metainfo['file']);
|
2981 |
}
|
2982 |
}
|
2983 |
|
2984 |
-
if(!empty($metainfo))
|
2985 |
-
foreach($metainfo as $key => $value)
|
2986 |
-
if(empty($value))
|
2987 |
continue;
|
2988 |
}
|
2989 |
-
$key_name
|
2990 |
-
$key_name
|
2991 |
-
$value
|
2992 |
-
$metadata[$key] = array('name' => $key_name, 'value' => $value);
|
2993 |
}
|
2994 |
}
|
2995 |
}
|
@@ -3002,21 +3257,21 @@ class GmediaCore {
|
|
3002 |
*
|
3003 |
* @return array
|
3004 |
*/
|
3005 |
-
function sanitize_meta_value($value)
|
3006 |
-
if(is_array($value) && (bool)count(array_filter(array_keys($value), 'is_string')))
|
3007 |
$value_return = array();
|
3008 |
-
foreach($value as $key => $val)
|
3009 |
-
if(empty($value))
|
3010 |
continue;
|
3011 |
}
|
3012 |
$key_name = $this->i18n_exif_name($key);
|
3013 |
$key_name = ucwords(str_replace('_', ' ', $key_name));
|
3014 |
-
if(is_array($val))
|
3015 |
$val = $this->sanitize_meta_value($val);
|
3016 |
}
|
3017 |
-
$value_return[$key] = array('name' => $key_name, 'value' => $val);
|
3018 |
}
|
3019 |
-
} else
|
3020 |
$value_return = $value;
|
3021 |
}
|
3022 |
|
@@ -3029,17 +3284,17 @@ class GmediaCore {
|
|
3029 |
*
|
3030 |
* @return string Meta text;
|
3031 |
*/
|
3032 |
-
function metadata_text($id)
|
3033 |
$metatext = '';
|
3034 |
-
if(($metadata = $this->metadata_info($id)))
|
3035 |
-
foreach($metadata as $meta)
|
3036 |
-
if($meta['name'] == 'Image')
|
3037 |
continue;
|
3038 |
}
|
3039 |
$metatext .= "<b>{$meta['name']}:</b>";
|
3040 |
-
if(!is_array($meta['value']))
|
3041 |
$metatext .= " {$meta['value']}\n";
|
3042 |
-
} else
|
3043 |
$value = $meta['value'];
|
3044 |
$this->meta_value_array_show($metatext, $value);
|
3045 |
}
|
@@ -3054,18 +3309,18 @@ class GmediaCore {
|
|
3054 |
* @param $value
|
3055 |
* @param int $pad
|
3056 |
*/
|
3057 |
-
function meta_value_array_show(&$metatext, $value, $pad = 0)
|
3058 |
-
if((bool)count(array_filter(array_keys($value), 'is_string')))
|
3059 |
-
$pad++;
|
3060 |
-
foreach($value as $val)
|
3061 |
$metatext .= "\n" . str_pad(' ', $pad) . "- <b>{$val['name']}:</b> ";
|
3062 |
-
if(is_array($val['value']))
|
3063 |
$this->meta_value_array_show($metatext, $val['value'], $pad);
|
3064 |
-
} else
|
3065 |
$metatext .= $val['value'];
|
3066 |
}
|
3067 |
}
|
3068 |
-
} else
|
3069 |
$metatext .= ' ' . implode(', ', $value);
|
3070 |
}
|
3071 |
$metatext .= "\n";
|
@@ -3077,7 +3332,7 @@ class GmediaCore {
|
|
3077 |
*
|
3078 |
* @return array
|
3079 |
*/
|
3080 |
-
function getGPSfromExif($gps)
|
3081 |
$lat = $this->getGPS($gps['GPSLatitude'], $gps['GPSLatitudeRef']);
|
3082 |
$lng = $this->getGPS($gps['GPSLongitude'], $gps['GPSLongitudeRef']);
|
3083 |
|
@@ -3090,19 +3345,19 @@ class GmediaCore {
|
|
3090 |
*
|
3091 |
* @return int
|
3092 |
*/
|
3093 |
-
function getGPS($coordinate, $hemisphere)
|
3094 |
-
for($i = 0; $i < 3; $i++)
|
3095 |
-
$part = explode('/', $coordinate[$i]);
|
3096 |
-
if(count($part) == 1)
|
3097 |
-
$coordinate[$i] = $part[0];
|
3098 |
-
} else if(count($part) == 2)
|
3099 |
-
$coordinate[$i] = floatval($part[0]) / floatval($part[1]);
|
3100 |
-
} else
|
3101 |
-
$coordinate[$i] = 0;
|
3102 |
}
|
3103 |
}
|
3104 |
list($degrees, $minutes, $seconds) = $coordinate;
|
3105 |
-
$sign = ($hemisphere == 'W' || $hemisphere == 'S')? -1 : 1;
|
3106 |
|
3107 |
return $sign * ($degrees + $minutes / 60 + $seconds / 3600);
|
3108 |
}
|
@@ -3115,13 +3370,16 @@ class GmediaCore {
|
|
3115 |
*
|
3116 |
* @return
|
3117 |
*/
|
3118 |
-
function gm_hitcounter($gmID, $meta)
|
3119 |
/** @var wpdb $wpdb */
|
3120 |
global $gmDB;
|
3121 |
-
|
|
|
|
|
|
|
3122 |
$meta['likes'] += 1;
|
3123 |
$gmDB->update_metadata('gmedia', $gmID, 'likes', $meta['likes']);
|
3124 |
-
} else
|
3125 |
$meta['views'] += 1;
|
3126 |
$gmDB->update_metadata('gmedia', $gmID, 'views', $meta['views']);
|
3127 |
}
|
@@ -3138,32 +3396,32 @@ class GmediaCore {
|
|
3138 |
* @return array
|
3139 |
* @throws Exception
|
3140 |
*/
|
3141 |
-
function replace_array_keys(&$array, $keymap)
|
3142 |
$replaced_keys = array();
|
3143 |
$skipped = $keymap;
|
3144 |
-
do
|
3145 |
$keymap = $skipped;
|
3146 |
-
foreach($keymap as $new_key => $original_key)
|
3147 |
-
if(isset($array[$original_key]))
|
3148 |
-
if(!isset($array[$new_key]) || (isset($replaced_keys[$new_key]) && !isset($replaced_keys[$original_key])))
|
3149 |
-
$array[$new_key] = $array[$original_key];
|
3150 |
-
unset($array[$original_key]);
|
3151 |
-
$replaced_keys[$original_key] = $new_key;
|
3152 |
-
unset($skipped[$new_key]);
|
3153 |
-
} elseif(isset($array[$new_key]) && array_search($new_key, $keymap) === false)
|
3154 |
throw new Exception('Trying to replace an array key with an already existing array key, without providing a new position for the existing array key in replace_array_keys().');
|
3155 |
-
} elseif(isset($array[$new_key]) && $keymap[$original_key] == $new_key && !isset($replaced_keys[$original_key]))
|
3156 |
//switch places.
|
3157 |
-
$temp
|
3158 |
-
$array[$new_key] = $array[$original_key];
|
3159 |
-
$array[$original_key] = $temp;
|
3160 |
-
$replaced_keys[$new_key] = $original_key;
|
3161 |
-
$replaced_keys[$original_key] = $new_key;
|
3162 |
-
unset($skipped[$new_key]);
|
3163 |
-
unset($skipped[$original_key]);
|
3164 |
}
|
3165 |
-
} else
|
3166 |
-
unset($skipped[$new_key]);
|
3167 |
}
|
3168 |
}
|
3169 |
} while(!empty($skipped));
|
@@ -3172,78 +3430,220 @@ class GmediaCore {
|
|
3172 |
}
|
3173 |
|
3174 |
/**
|
3175 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3176 |
*
|
3177 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3178 |
*
|
3179 |
-
* @
|
|
|
|
|
3180 |
*/
|
3181 |
-
function
|
3182 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3183 |
|
3184 |
-
|
3185 |
-
|
3186 |
-
|
3187 |
-
|
3188 |
-
|
3189 |
-
$
|
3190 |
-
$
|
3191 |
-
$
|
|
|
|
|
3192 |
}
|
3193 |
-
$rgb = array($r, $g, $b);
|
3194 |
|
3195 |
-
return $
|
3196 |
}
|
3197 |
|
3198 |
/**
|
3199 |
-
*
|
|
|
|
|
|
|
|
|
|
|
3200 |
*/
|
3201 |
-
function plugin_capabilities() {
|
3202 |
-
return
|
1 |
<?php
|
2 |
+
if(preg_match('#' . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])){
|
3 |
die('You are not allowed to call this page directly.');
|
4 |
}
|
5 |
|
6 |
/**
|
7 |
* Main PHP class for the WordPress plugin GRAND Media
|
8 |
*/
|
9 |
+
class GmediaCore{
|
10 |
|
11 |
var $upload;
|
12 |
var $gmedia_url;
|
16 |
/**
|
17 |
*
|
18 |
*/
|
19 |
+
function __construct(){
|
20 |
$this->upload = $this->gm_upload_dir();
|
21 |
$this->gmedia_url = plugins_url(GMEDIA_FOLDER);
|
22 |
|
23 |
add_action('init', array(&$this, 'user_capabilities'), 8);
|
24 |
+
|
25 |
+
add_action('clean_gmedia_cache', array(&$this, 'clear_cache'));
|
26 |
+
// add_action( 'deleted_gmedia_term_relationships', array( &$this, 'clear_cache' ) );
|
27 |
+
// add_action( 'added_gmedia_meta', array( &$this, 'clear_cache' ) );
|
28 |
+
// add_action( 'added_gmedia_term_meta', array( &$this, 'clear_cache' ) );
|
29 |
+
// add_action( 'updated_gmedia_meta', array( &$this, 'clear_cache' ) );
|
30 |
+
// add_action( 'updated_gmedia_term_meta', array( &$this, 'clear_cache' ) );
|
31 |
+
// add_action( 'deleted_gmedia_meta', array( &$this, 'clear_cache' ) );
|
32 |
+
// add_action( 'deleted_gmedia_term_meta', array( &$this, 'clear_cache' ) );
|
33 |
+
add_action('created_gmedia_term', array(&$this, 'clear_cache'));
|
34 |
+
add_action('edited_gmedia_term', array(&$this, 'clear_cache'));
|
35 |
+
add_action('deleted_gmedia_term', array(&$this, 'clear_cache'));
|
36 |
+
// add_action( 'gmedia_clean_object_term_cache', array( &$this, 'clear_cache' ) );
|
37 |
}
|
38 |
|
39 |
+
function user_capabilities(){
|
40 |
$capabilities = $this->plugin_capabilities();
|
41 |
$capabilities = apply_filters('gmedia_capabilities', $capabilities);
|
42 |
+
if(is_multisite() && is_super_admin()){
|
43 |
+
foreach($capabilities as $cap){
|
44 |
+
$this->caps[ $cap ] = 1;
|
45 |
}
|
46 |
+
} else{
|
47 |
$curuser = wp_get_current_user();
|
48 |
+
foreach($capabilities as $cap){
|
49 |
+
if(isset($curuser->allcaps[ $cap ]) && intval($curuser->allcaps[ $cap ])){
|
50 |
+
$this->caps[ $cap ] = 1;
|
51 |
+
} else{
|
52 |
+
$this->caps[ $cap ] = 0;
|
53 |
}
|
54 |
}
|
55 |
}
|
64 |
*
|
65 |
* @return mixed
|
66 |
*/
|
67 |
+
function _get($var, $def = false, $empty2false = false){
|
68 |
+
return isset($_GET[ $var ])? (($empty2false && $this->is_empty($_GET[ $var ]))? false : $_GET[ $var ]) : $def;
|
69 |
}
|
70 |
|
71 |
/**
|
75 |
*
|
76 |
* @return bool
|
77 |
*/
|
78 |
+
function is_empty($var){
|
79 |
return !(!empty($var) && !in_array(strtolower($var), array('null', 'false')));
|
80 |
}
|
81 |
|
88 |
* @return mixed
|
89 |
*/
|
90 |
|
91 |
+
function _post($var, $def = false){
|
92 |
+
return isset($_POST[ $var ])? $_POST[ $var ] : $def;
|
93 |
}
|
94 |
|
95 |
/**
|
100 |
*
|
101 |
* @return mixed
|
102 |
*/
|
103 |
+
function _req($var, $def = false){
|
104 |
+
return isset($_REQUEST[ $var ])? $_REQUEST[ $var ] : $def;
|
105 |
}
|
106 |
|
107 |
/**
|
113 |
*
|
114 |
* @return string
|
115 |
*/
|
116 |
+
function tooltip($style, $params, $print = true){
|
117 |
$show_tip = 0; // TODO show tooltips checkbox in settings
|
118 |
+
if($show_tip){
|
119 |
$tooltip = " data-toggle='$style'";
|
120 |
+
if(is_array($params) && !empty($params)){
|
121 |
+
foreach($params as $key => $val){
|
122 |
$tooltip .= " data-$key='$val'";
|
123 |
}
|
124 |
}
|
125 |
+
if($print){
|
126 |
echo $tooltip;
|
127 |
+
} else{
|
128 |
return $tooltip;
|
129 |
}
|
130 |
}
|
136 |
* @param array $add_args
|
137 |
* @param array $remove_args
|
138 |
* @param bool $uri
|
139 |
+
* @param array $preserve_args
|
140 |
*
|
141 |
* @return string
|
142 |
*/
|
143 |
+
function get_admin_url($add_args = array(), $remove_args = array(), $uri = false, $preserve_args = array()){
|
144 |
+
if(true === $uri){
|
145 |
$uri = admin_url('admin.php');
|
146 |
}
|
147 |
$remove_args = empty($remove_args)? array() : (array)$remove_args;
|
148 |
+
$remove_args = array_unique(array_merge(array('doing_wp_cron', '_wpnonce', 'delete', 'duplicate', 'update_meta', 'recreate'), $remove_args, array_keys($add_args)));
|
149 |
$new_uri = remove_query_arg($remove_args, $uri);
|
150 |
+
if(!empty($preserve_args)){
|
151 |
+
$_add_args = array();
|
152 |
+
foreach($preserve_args as $key){
|
153 |
+
if(($value = $this->_get($key)) !== false){
|
154 |
+
$_add_args[ $key ] = $value;
|
155 |
+
}
|
156 |
+
}
|
157 |
+
$new_uri = add_query_arg($_add_args, $new_uri);
|
158 |
+
}
|
159 |
+
if(!empty($add_args)){
|
160 |
$new_uri = add_query_arg($add_args, $new_uri);
|
161 |
}
|
|
|
162 |
return esc_url_raw($new_uri);
|
163 |
}
|
164 |
|
167 |
*
|
168 |
* @return bool
|
169 |
*/
|
170 |
+
function is_crawler($userAgent){
|
171 |
$crawlers = 'Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|FeedBurner|' . 'AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|' . 'GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby|yandex|facebook';
|
172 |
$isCrawler = (preg_match("/$crawlers/i", $userAgent) > 0);
|
173 |
|
179 |
*
|
180 |
* @return bool
|
181 |
*/
|
182 |
+
function is_browser($userAgent){
|
183 |
$browsers = 'opera|aol|msie|firefox|chrome|konqueror|safari|netscape|navigator|mosaic|lynx|amaya|omniweb|avant|camino|flock|seamonkey|mozilla|gecko';
|
184 |
$isBrowser = (preg_match("/$browsers/i", $userAgent) > 0);
|
185 |
|
202 |
*
|
203 |
* @return array See above for description.
|
204 |
*/
|
205 |
+
function gm_upload_dir($create = true){
|
206 |
$slash = '/';
|
207 |
// If multisite (and if not the main site)
|
208 |
+
if(is_multisite() && !is_main_site()){
|
209 |
$slash = '/blogs.dir/' . get_current_blog_id() . '/';
|
210 |
}
|
211 |
|
216 |
|
217 |
$uploads = apply_filters('gm_upload_dir', array('path' => $dir, 'url' => $url, 'error' => false));
|
218 |
|
219 |
+
if($create){
|
220 |
// Make sure we have an uploads dir
|
221 |
+
if(!wp_mkdir_p($uploads['path'])){
|
222 |
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $uploads['path']);
|
223 |
$uploads['error'] = $message;
|
224 |
}
|
225 |
+
} elseif(!is_dir($uploads['path'])){
|
226 |
$uploads['error'] = true;
|
227 |
}
|
228 |
|
234 |
*
|
235 |
* @return bool|null
|
236 |
*/
|
237 |
+
function delete_folder($path){
|
238 |
$path = rtrim($path, '/');
|
239 |
+
if(is_file($path)){
|
240 |
return @unlink($path);
|
241 |
+
} elseif(is_dir($path)){
|
242 |
$files = glob($path . '/*', GLOB_NOSORT);
|
243 |
+
if(!empty($files) && is_array($files)){
|
244 |
array_map(array($this, 'delete_folder'), $files);
|
245 |
}
|
246 |
|
256 |
* @see wp_get_attachment_image()
|
257 |
* @uses apply_filters() Calls 'gm_get_attachment_image_attributes' hook on attributes array
|
258 |
*
|
259 |
+
* @param int|object $item Image object.
|
260 |
+
* @param string $size Optional, default is empty string, could be 'thumb', 'original'
|
261 |
+
* @param bool $cover Optional, try to get cover url
|
262 |
* @param bool|string $default Optional, return if no cover
|
263 |
*
|
264 |
* @return string img url
|
265 |
*/
|
266 |
+
function gm_get_media_image($item, $size = '', $cover = true, $default = false){
|
267 |
global $gmDB, $gmGallery;
|
268 |
|
269 |
+
if(!is_object($item)){
|
270 |
$item = $gmDB->get_gmedia($item);
|
271 |
}
|
272 |
+
if(empty($item)){
|
273 |
+
$image = $default? $default : $this->gmedia_url . '/admin/assets/img/blank.gif';
|
274 |
|
275 |
return $image;
|
276 |
}
|
277 |
$type = explode('/', $item->mime_type);
|
278 |
|
279 |
+
if('image' == $type[0]){
|
280 |
+
$type_folder = $this->upload['url'] . '/' . $gmGallery->options['folder'][ $type[0] ];
|
281 |
|
282 |
+
switch($size){
|
283 |
case 'thumb':
|
284 |
$size_folder = '/thumb/';
|
285 |
break;
|
293 |
}
|
294 |
|
295 |
$image = $type_folder . $size_folder . $item->gmuid;
|
296 |
+
} else{
|
297 |
$ext = ltrim(strrchr($item->gmuid, '.'), '.');
|
298 |
+
if(!$type = wp_ext2type($ext)){
|
299 |
$type = 'application';
|
300 |
}
|
301 |
$image = $this->gmedia_url . '/admin/assets/img/' . $type . '.png';
|
302 |
|
303 |
+
if($cover){
|
304 |
$cover = $gmDB->get_metadata('gmedia', $item->ID, '_cover', true);
|
305 |
+
if(!empty($cover)){
|
306 |
+
if($this->is_digit($cover)){
|
307 |
$image = $this->gm_get_media_image((int)$cover, $size, false);
|
308 |
+
} elseif(false !== filter_var($cover, FILTER_VALIDATE_URL)){
|
309 |
return $cover;
|
310 |
}
|
311 |
+
} elseif(false !== $default){
|
312 |
return $default;
|
313 |
}
|
314 |
}
|
324 |
*
|
325 |
* @return array|bool Return array( 'path', 'url' ) OR false if no module
|
326 |
*/
|
327 |
+
function get_module_path($module_name){
|
328 |
global $gmGallery;
|
329 |
+
if(empty($module_name)){
|
330 |
return false;
|
331 |
}
|
332 |
+
$module_dirs = array('upload' => array('name' => $module_name,
|
333 |
+
'path' => $this->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/' . $module_name,
|
334 |
+
'url' => $this->upload['url'] . '/' . $gmGallery->options['folder']['module'] . '/' . $module_name
|
335 |
+
),
|
336 |
+
'plugin' => array('name' => $module_name,
|
337 |
+
'path' => GMEDIA_ABSPATH . 'module/' . $module_name,
|
338 |
+
'url' => plugins_url(GMEDIA_FOLDER) . '/module/' . $module_name
|
339 |
+
),
|
340 |
+
'theme' => array('name' => $module_name,
|
341 |
+
'path' => get_template_directory() . '/gmedia-module/' . $module_name,
|
342 |
+
'url' => get_template_directory_uri() . '/gmedia-module/' . $module_name
|
343 |
+
)
|
|
|
|
|
|
|
|
|
344 |
);
|
345 |
+
foreach($module_dirs as $dir){
|
346 |
+
if(is_dir($dir['path'])){
|
347 |
return $dir;
|
348 |
}
|
349 |
}
|
350 |
|
351 |
+
$getModulePreset = $this->getModulePreset();
|
352 |
+
|
353 |
+
if($module_name != $getModulePreset['module']){
|
354 |
+
return $this->get_module_path($getModulePreset['module']);
|
355 |
}
|
356 |
|
357 |
return false;
|
364 |
*
|
365 |
* @return array|bool
|
366 |
*/
|
367 |
+
function fileinfo($file, $exists = 0){
|
368 |
global $gmGallery, $user_ID;
|
369 |
|
370 |
$file = basename($file);
|
381 |
$allowed_ext = array_keys($allowed_ext);
|
382 |
$allowed_ext = implode('|', $allowed_ext);
|
383 |
$allowed_ext = explode('|', $allowed_ext);
|
384 |
+
if(!in_array($fileinfo['extension'], $allowed_ext)){
|
385 |
return false;
|
386 |
}
|
387 |
|
388 |
+
$fileinfo['basename_original'] = $pathinfo['filename'] . '.' . $fileinfo['extension'];
|
389 |
+
$fileinfo['filename'] = $pathinfo['filename'] . $suffix;
|
390 |
+
$fileinfo['basename'] = $fileinfo['filename'] . '.' . $fileinfo['extension'];
|
391 |
+
$fileinfo['title'] = ucwords(str_replace('_', ' ', esc_sql($title)));
|
392 |
+
$fileinfo['mime_type'] = (empty($filetype['type']))? 'application/' . $fileinfo['extension'] : $filetype['type'];
|
393 |
list($dirname) = explode('/', $fileinfo['mime_type']);
|
394 |
$fileinfo['dirname'] = $dirname;
|
395 |
+
$fileinfo['dirpath'] = $this->upload['path'] . '/' . $gmGallery->options['folder'][ $dirname ];
|
396 |
+
$fileinfo['dirpath_original'] = $this->upload['path'] . '/' . $gmGallery->options['folder'][ $dirname ];
|
397 |
+
$fileinfo['dirurl'] = $this->upload['url'] . '/' . $gmGallery->options['folder'][ $dirname ];
|
398 |
+
$fileinfo['dirurl_original'] = $this->upload['url'] . '/' . $gmGallery->options['folder'][ $dirname ];
|
399 |
$fileinfo['filepath'] = $fileinfo['dirpath'] . '/' . $fileinfo['basename'];
|
400 |
$fileinfo['filepath_original'] = $fileinfo['dirpath'] . '/' . $fileinfo['basename'];
|
401 |
$fileinfo['fileurl'] = $fileinfo['dirurl'] . '/' . $fileinfo['basename'];
|
402 |
$fileinfo['fileurl_original'] = $fileinfo['dirurl'] . '/' . $fileinfo['basename'];
|
403 |
+
if('image' == $dirname){
|
404 |
$fileinfo['dirpath_original'] = $this->upload['path'] . '/' . $gmGallery->options['folder']['image_original'];
|
405 |
$fileinfo['dirurl_original'] = $this->upload['url'] . '/' . $gmGallery->options['folder']['image_original'];
|
406 |
$fileinfo['filepath_original'] = $fileinfo['dirpath_original'] . '/' . $fileinfo['basename'];
|
411 |
$fileinfo['fileurl_thumb'] = $fileinfo['dirurl_thumb'] . '/' . $fileinfo['basename'];
|
412 |
}
|
413 |
|
414 |
+
if((false !== $exists) && file_exists($fileinfo['filepath'])){
|
415 |
$exists = absint($exists) + 1;
|
416 |
$fileinfo = $this->fileinfo($file, $exists);
|
417 |
}
|
426 |
*
|
427 |
* @return mixed|void
|
428 |
*/
|
429 |
+
function get_file_metadata($file, $fileinfo = array()){
|
430 |
|
431 |
+
if(empty($fileinfo)){
|
432 |
$fileinfo = $this->fileinfo($file, false);
|
433 |
}
|
434 |
$metadata = array();
|
435 |
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
436 |
+
if(preg_match('!^image/!', $fileinfo['mime_type']) && file_is_displayable_image($fileinfo['filepath'])){
|
437 |
$imagesize = getimagesize($fileinfo['filepath']);
|
438 |
$metadata['web'] = array('width' => $imagesize[0], 'height' => $imagesize[1]);
|
439 |
$imagesize = getimagesize($fileinfo['filepath_original']);
|
445 |
|
446 |
// fetch additional metadata from exif/iptc
|
447 |
$image_meta = $this->wp_read_image_metadata($fileinfo['filepath_original']);
|
448 |
+
if($image_meta){
|
449 |
$metadata['image_meta'] = $image_meta;
|
450 |
}
|
451 |
|
452 |
+
} elseif(preg_match('#^video/#', $fileinfo['mime_type'])){
|
453 |
$metadata = $this->wp_read_video_metadata($fileinfo['filepath']);
|
454 |
+
} elseif(preg_match('#^audio/#', $fileinfo['mime_type'])){
|
455 |
$metadata = $this->wp_read_audio_metadata($fileinfo['filepath']);
|
456 |
+
//unset($metadata['image']);
|
457 |
}
|
458 |
|
459 |
return apply_filters('generate_file_metadata', $metadata);
|
462 |
/**
|
463 |
* Return relative path to an uploaded file.
|
464 |
* The path is relative to the current upload dir.
|
|
|
465 |
* @see _wp_relative_upload_path()
|
466 |
* @uses apply_filters() Calls '_gm_relative_upload_path' on file path.
|
467 |
*
|
469 |
*
|
470 |
* @return string relative path on success, unchanged path on failure.
|
471 |
*/
|
472 |
+
function _gm_relative_upload_path($path){
|
|
|
473 |
$new_path = $path;
|
474 |
|
475 |
+
if((false === $this->upload['error']) && (0 === strpos($new_path, $this->upload['path']))){
|
476 |
+
$new_path = str_replace($this->upload['path'], '', $new_path);
|
477 |
$new_path = ltrim($new_path, '/');
|
478 |
}
|
479 |
|
484 |
*
|
485 |
* @param string $new_file
|
486 |
*/
|
487 |
+
function file_chmod($new_file){
|
488 |
$stat = stat(dirname($new_file));
|
489 |
$perms = $stat['mode'] & 0000666;
|
490 |
@chmod($new_file, $perms);
|
497 |
*
|
498 |
* @return mixed
|
499 |
*/
|
500 |
+
function clean_input($input){
|
501 |
+
$search = array(/*'@<[\/\!]*?[^<>]*?>@si'*/ /* Strip out HTML tags */
|
502 |
+
'@<script' . '[^>]*?>.*?</script>@si' /* Strip out javascript */,
|
503 |
+
'@<style' . '[^>]*?>.*?</style>@siU' /* Strip style tags properly */,
|
504 |
+
'@<![\s\S]*?--[ \t\n\r]*>@' /* Strip multi-line comments */
|
505 |
+
//,'/\s{3,}/'
|
|
|
506 |
);
|
507 |
|
508 |
$output = preg_replace($search, '', $input);
|
517 |
*
|
518 |
* @return mixed
|
519 |
*/
|
520 |
+
function sanitize($input){
|
521 |
$output = $input;
|
522 |
+
if(is_array($input)){
|
523 |
+
foreach($input as $var => $val){
|
524 |
+
$output[ $var ] = $this->sanitize($val);
|
525 |
}
|
526 |
+
} else{
|
527 |
/** @noinspection PhpDeprecationInspection */
|
528 |
+
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()){
|
529 |
$input = stripslashes($input);
|
530 |
}
|
531 |
$input = $this->clean_input($input);
|
542 |
*
|
543 |
* @return bool
|
544 |
*/
|
545 |
+
function is_digit($digit){
|
546 |
+
if(is_int($digit)){
|
547 |
return true;
|
548 |
+
} elseif(is_string($digit) && !empty($digit)){
|
549 |
return ctype_digit($digit);
|
550 |
+
} else{
|
551 |
// booleans, floats and others
|
552 |
return false;
|
553 |
}
|
555 |
|
556 |
/**
|
557 |
* Check if user can select a author
|
|
|
558 |
* @return array
|
559 |
*/
|
560 |
+
function get_editable_user_ids(){
|
561 |
+
if(current_user_can('gmedia_show_others_media') || current_user_can('gmedia_edit_others_media')){
|
562 |
return get_users(array('who' => 'authors', 'fields' => 'ID'));
|
563 |
}
|
564 |
|
573 |
*
|
574 |
* @return string
|
575 |
*/
|
576 |
+
function gmcloudlink($id, $type){
|
577 |
$options = get_option('gmediaOptions');
|
578 |
$endpoint = $options['endpoint'];
|
579 |
$hashid = gmedia_hash_id_encode($id, $type);
|
580 |
+
$t = array('gallery' => 'g',
|
581 |
+
'album' => 'a',
|
582 |
+
'tag' => 't',
|
583 |
+
'single' => 's',
|
584 |
+
'category' => 'k',
|
585 |
+
'author' => 'u'
|
|
|
|
|
586 |
);
|
587 |
+
if(get_option('permalink_structure')){
|
588 |
$cloud_link = home_url(urlencode($endpoint) . "/{$t[$type]}/{$hashid}");
|
589 |
+
} else{
|
590 |
+
$cloud_link = add_query_arg(array("$endpoint" => $hashid, 't' => $t[ $type ]), home_url('index.php'));
|
591 |
}
|
592 |
|
593 |
return $cloud_link;
|
601 |
*
|
602 |
* @return string
|
603 |
*/
|
604 |
+
function filesize($file, $decimals = 2){
|
605 |
$bytes = filesize($file);
|
606 |
$sz = array('b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
|
607 |
$factor = (int)floor((strlen($bytes) - 1) / 3);
|
608 |
|
609 |
+
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sz[ $factor ];
|
610 |
}
|
611 |
|
612 |
/**
|
618 |
*
|
619 |
* @return array
|
620 |
*/
|
621 |
+
function array_diff_key_recursive(array $arr1, array $arr2){
|
622 |
$diff = array_diff_key($arr1, $arr2);
|
623 |
$intersect = array_intersect_key($arr1, $arr2);
|
624 |
|
625 |
+
foreach($intersect as $k => $v){
|
626 |
+
if(is_array($arr1[ $k ]) && is_array($arr2[ $k ])){
|
627 |
+
$d = $this->array_diff_key_recursive($arr1[ $k ], $arr2[ $k ]);
|
628 |
|
629 |
+
if(!empty($d)){
|
630 |
+
$diff[ $k ] = $d;
|
631 |
}
|
632 |
}
|
633 |
}
|
642 |
*
|
643 |
* @return array
|
644 |
*/
|
645 |
+
function array_diff_keyval_recursive(array $arr1, array $arr2, $update = false){
|
646 |
$diff = array_diff_key($arr1, $arr2);
|
647 |
$intersect = array_intersect_key($arr1, $arr2);
|
648 |
|
649 |
+
foreach($intersect as $k => $v){
|
650 |
+
if(is_array($arr1[ $k ]) && is_array($arr2[ $k ])){
|
651 |
+
$d = $this->array_diff_keyval_recursive($arr1[ $k ], $arr2[ $k ], $update);
|
652 |
|
653 |
+
if(!empty($d)){
|
654 |
+
$diff[ $k ] = $d;
|
655 |
}
|
656 |
+
} elseif($arr1[ $k ] !== $arr2[ $k ]){
|
657 |
+
if($update){
|
658 |
+
$diff[ $k ] = $arr2[ $k ];
|
659 |
+
} else{
|
660 |
+
$diff[ $k ] = $arr1[ $k ];
|
661 |
}
|
662 |
}
|
663 |
}
|
671 |
*
|
672 |
* @return mixed
|
673 |
*/
|
674 |
+
function array_replace_recursive($base, $replacements){
|
675 |
+
if(function_exists('array_replace_recursive')){
|
676 |
return array_replace_recursive($base, $replacements);
|
677 |
}
|
678 |
|
679 |
+
foreach(array_slice(func_get_args(), 1) as $replacements){
|
680 |
$bref_stack = array(&$base);
|
681 |
$head_stack = array($replacements);
|
682 |
|
683 |
+
do{
|
684 |
end($bref_stack);
|
685 |
|
686 |
+
$bref = &$bref_stack[ key($bref_stack) ];
|
687 |
$head = array_pop($head_stack);
|
688 |
|
689 |
+
unset($bref_stack[ key($bref_stack) ]);
|
690 |
|
691 |
+
foreach(array_keys($head) as $key){
|
692 |
+
if(isset($bref[ $key ]) && is_array($bref[ $key ]) && is_array($head[ $key ])){
|
693 |
+
$bref_stack[] = &$bref[ $key ];
|
694 |
+
$head_stack[] = $head[ $key ];
|
695 |
+
} else{
|
696 |
+
$bref[ $key ] = $head[ $key ];
|
697 |
}
|
698 |
}
|
699 |
} while(count($head_stack));
|
707 |
* @param $array
|
708 |
*
|
709 |
* @return mixed
|
|
|
710 |
*/
|
711 |
+
function array_map_recursive($callback, $array){
|
712 |
+
foreach($array as $key => $value){
|
713 |
+
if(is_array($array[ $key ])){
|
714 |
+
$array[ $key ] = $this->array_map_recursive($callback, $array[ $key ]);
|
715 |
+
} else{
|
716 |
+
$array[ $key ] = call_user_func($callback, $array[ $key ]);
|
717 |
}
|
718 |
}
|
719 |
|
726 |
*
|
727 |
* @return string
|
728 |
*/
|
729 |
+
public function alert($type = 'info', $content = ''){
|
730 |
+
if(empty($content)){
|
731 |
return '';
|
732 |
+
} elseif(is_array($content)){
|
733 |
$content = array_filter($content);
|
734 |
$content = implode('<br />', $content);
|
735 |
}
|
743 |
*
|
744 |
* @return array|bool
|
745 |
*/
|
746 |
+
function process_gmedit_image($photo){
|
747 |
$type = null;
|
748 |
+
if(preg_match('/^data:image\/(jpg|jpeg|png|gif)/i', $photo, $matches)){
|
749 |
$type = $matches[1];
|
750 |
+
} else{
|
751 |
return false;
|
752 |
}
|
753 |
// Remove the mime-type header
|
758 |
// Use strict mode to prevent characters from outside the base64 range
|
759 |
$image = base64_decode($data, true);
|
760 |
|
761 |
+
if(!$image){
|
762 |
return false;
|
763 |
}
|
764 |
|
765 |
+
return array('data' => $image,
|
766 |
+
'type' => $type
|
|
|
767 |
);
|
768 |
}
|
769 |
|
770 |
/**
|
771 |
* @return bool
|
772 |
*/
|
773 |
+
function is_bot(){
|
774 |
+
if(empty($_SERVER['HTTP_USER_AGENT'])){
|
775 |
return false;
|
776 |
}
|
777 |
|
778 |
+
$spiders = array("abot",
|
779 |
+
"dbot",
|
780 |
+
"ebot",
|
781 |
+
"hbot",
|
782 |
+
"kbot",
|
783 |
+
"lbot",
|
784 |
+
"mbot",
|
785 |
+
"nbot",
|
786 |
+
"obot",
|
787 |
+
"pbot",
|
788 |
+
"rbot",
|
789 |
+
"sbot",
|
790 |
+
"tbot",
|
791 |
+
"vbot",
|
792 |
+
"ybot",
|
793 |
+
"zbot",
|
794 |
+
"bot.",
|
795 |
+
"bot/",
|
796 |
+
"_bot",
|
797 |
+
".bot",
|
798 |
+
"/bot",
|
799 |
+
"-bot",
|
800 |
+
":bot",
|
801 |
+
"(bot",
|
802 |
+
"crawl",
|
803 |
+
"slurp",
|
804 |
+
"spider",
|
805 |
+
"seek",
|
806 |
+
"accoona",
|
807 |
+
"acoon",
|
808 |
+
"adressendeutschland",
|
809 |
+
"ah-ha.com",
|
810 |
+
"ahoy",
|
811 |
+
"altavista",
|
812 |
+
"ananzi",
|
813 |
+
"anthill",
|
814 |
+
"appie",
|
815 |
+
"arachnophilia",
|
816 |
+
"arale",
|
817 |
+
"araneo",
|
818 |
+
"aranha",
|
819 |
+
"architext",
|
820 |
+
"aretha",
|
821 |
+
"arks",
|
822 |
+
"asterias",
|
823 |
+
"atlocal",
|
824 |
+
"atn",
|
825 |
+
"atomz",
|
826 |
+
"augurfind",
|
827 |
+
"backrub",
|
828 |
+
"bannana_bot",
|
829 |
+
"baypup",
|
830 |
+
"bdfetch",
|
831 |
+
"big brother",
|
832 |
+
"biglotron",
|
833 |
+
"bjaaland",
|
834 |
+
"blackwidow",
|
835 |
+
"blaiz",
|
836 |
+
"blog",
|
837 |
+
"blo.",
|
838 |
+
"bloodhound",
|
839 |
+
"boitho",
|
840 |
+
"booch",
|
841 |
+
"bradley",
|
842 |
+
"butterfly",
|
843 |
+
"calif",
|
844 |
+
"cassandra",
|
845 |
+
"ccubee",
|
846 |
+
"cfetch",
|
847 |
+
"charlotte",
|
848 |
+
"churl",
|
849 |
+
"cienciaficcion",
|
850 |
+
"cmc",
|
851 |
+
"collective",
|
852 |
+
"comagent",
|
853 |
+
"combine",
|
854 |
+
"computingsite",
|
855 |
+
"csci",
|
856 |
+
"curl",
|
857 |
+
"cusco",
|
858 |
+
"daumoa",
|
859 |
+
"deepindex",
|
860 |
+
"delorie",
|
861 |
+
"depspid",
|
862 |
+
"deweb",
|
863 |
+
"die blinde kuh",
|
864 |
+
"digger",
|
865 |
+
"ditto",
|
866 |
+
"dmoz",
|
867 |
+
"docomo",
|
868 |
+
"download express",
|
869 |
+
"dtaagent",
|
870 |
+
"dwcp",
|
871 |
+
"ebiness",
|
872 |
+
"ebingbong",
|
873 |
+
"e-collector",
|
874 |
+
"ejupiter",
|
875 |
+
"emacs-w3 search engine",
|
876 |
+
"esther",
|
877 |
+
"evliya celebi",
|
878 |
+
"ezresult",
|
879 |
+
"falcon",
|
880 |
+
"felix ide",
|
881 |
+
"ferret",
|
882 |
+
"fetchrover",
|
883 |
+
"fido",
|
884 |
+
"findlinks",
|
885 |
+
"fireball",
|
886 |
+
"fish search",
|
887 |
+
"fouineur",
|
888 |
+
"funnelweb",
|
889 |
+
"gazz",
|
890 |
+
"gcreep",
|
891 |
+
"genieknows",
|
892 |
+
"getterroboplus",
|
893 |
+
"geturl",
|
894 |
+
"glx",
|
895 |
+
"goforit",
|
896 |
+
"golem",
|
897 |
+
"grabber",
|
898 |
+
"grapnel",
|
899 |
+
"gralon",
|
900 |
+
"griffon",
|
901 |
+
"gromit",
|
902 |
+
"grub",
|
903 |
+
"gulliver",
|
904 |
+
"hamahakki",
|
905 |
+
"harvest",
|
906 |
+
"havindex",
|
907 |
+
"helix",
|
908 |
+
"heritrix",
|
909 |
+
"hku www octopus",
|
910 |
+
"homerweb",
|
911 |
+
"htdig",
|
912 |
+
"html index",
|
913 |
+
"html_analyzer",
|
914 |
+
"htmlgobble",
|
915 |
+
"hubater",
|
916 |
+
"hyper-decontextualizer",
|
917 |
+
"ia_archiver",
|
918 |
+
"ibm_planetwide",
|
919 |
+
"ichiro",
|
920 |
+
"iconsurf",
|
921 |
+
"iltrovatore",
|
922 |
+
"image.kapsi.net",
|
923 |
+
"imagelock",
|
924 |
+
"incywincy",
|
925 |
+
"indexer",
|
926 |
+
"infobee",
|
927 |
+
"informant",
|
928 |
+
"ingrid",
|
929 |
+
"inktomisearch.com",
|
930 |
+
"inspector web",
|
931 |
+
"intelliagent",
|
932 |
+
"internet shinchakubin",
|
933 |
+
"ip3000",
|
934 |
+
"iron33",
|
935 |
+
"israeli-search",
|
936 |
+
"ivia",
|
937 |
+
"jack",
|
938 |
+
"jakarta",
|
939 |
+
"javabee",
|
940 |
+
"jetbot",
|
941 |
+
"jumpstation",
|
942 |
+
"katipo",
|
943 |
+
"kdd-explorer",
|
944 |
+
"kilroy",
|
945 |
+
"knowledge",
|
946 |
+
"kototoi",
|
947 |
+
"kretrieve",
|
948 |
+
"labelgrabber",
|
949 |
+
"lachesis",
|
950 |
+
"larbin",
|
951 |
+
"legs",
|
952 |
+
"libwww",
|
953 |
+
"linkalarm",
|
954 |
+
"link validator",
|
955 |
+
"linkscan",
|
956 |
+
"lockon",
|
957 |
+
"lwp",
|
958 |
+
"lycos",
|
959 |
+
"magpie",
|
960 |
+
"mantraagent",
|
961 |
+
"mapoftheinternet",
|
962 |
+
"marvin/",
|
963 |
+
"mattie",
|
964 |
+
"mediafox",
|
965 |
+
"mediapartners",
|
966 |
+
"mercator",
|
967 |
+
"merzscope",
|
968 |
+
"microsoft url control",
|
969 |
+
"minirank",
|
970 |
+
"miva",
|
971 |
+
"mj12",
|
972 |
+
"mnogosearch",
|
973 |
+
"moget",
|
974 |
+
"monster",
|
975 |
+
"moose",
|
976 |
+
"motor",
|
977 |
+
"multitext",
|
978 |
+
"muncher",
|
979 |
+
"muscatferret",
|
980 |
+
"mwd.search",
|
981 |
+
"myweb",
|
982 |
+
"najdi",
|
983 |
+
"nameprotect",
|
984 |
+
"nationaldirectory",
|
985 |
+
"nazilla",
|
986 |
+
"ncsa beta",
|
987 |
+
"nec-meshexplorer",
|
988 |
+
"nederland.zoek",
|
989 |
+
"netcarta webmap engine",
|
990 |
+
"netmechanic",
|
991 |
+
"netresearchserver",
|
992 |
+
"netscoop",
|
993 |
+
"newscan-online",
|
994 |
+
"nhse",
|
995 |
+
"nokia6682/",
|
996 |
+
"nomad",
|
997 |
+
"noyona",
|
998 |
+
"nutch",
|
999 |
+
"nzexplorer",
|
1000 |
+
"objectssearch",
|
1001 |
+
"occam",
|
1002 |
+
"omni",
|
1003 |
+
"open text",
|
1004 |
+
"openfind",
|
1005 |
+
"openintelligencedata",
|
1006 |
+
"orb search",
|
1007 |
+
"osis-project",
|
1008 |
+
"pack rat",
|
1009 |
+
"pageboy",
|
1010 |
+
"pagebull",
|
1011 |
+
"page_verifier",
|
1012 |
+
"panscient",
|
1013 |
+
"parasite",
|
1014 |
+
"partnersite",
|
1015 |
+
"patric",
|
1016 |
+
"pear.",
|
1017 |
+
"pegasus",
|
1018 |
+
"peregrinator",
|
1019 |
+
"pgp key agent",
|
1020 |
+
"phantom",
|
1021 |
+
"phpdig",
|
1022 |
+
"picosearch",
|
1023 |
+
"piltdownman",
|
1024 |
+
"pimptrain",
|
1025 |
+
"pinpoint",
|
1026 |
+
"pioneer",
|
1027 |
+
"piranha",
|
1028 |
+
"plumtreewebaccessor",
|
1029 |
+
"pogodak",
|
1030 |
+
"poirot",
|
1031 |
+
"pompos",
|
1032 |
+
"poppelsdorf",
|
1033 |
+
"poppi",
|
1034 |
+
"popular iconoclast",
|
1035 |
+
"psycheclone",
|
1036 |
+
"publisher",
|
1037 |
+
"python",
|
1038 |
+
"rambler",
|
1039 |
+
"raven search",
|
1040 |
+
"roach",
|
1041 |
+
"road runner",
|
1042 |
+
"roadhouse",
|
1043 |
+
"robbie",
|
1044 |
+
"robofox",
|
1045 |
+
"robozilla",
|
1046 |
+
"rules",
|
1047 |
+
"salty",
|
1048 |
+
"sbider",
|
1049 |
+
"scooter",
|
1050 |
+
"scoutjet",
|
1051 |
+
"scrubby",
|
1052 |
+
"search.",
|
1053 |
+
"searchprocess",
|
1054 |
+
"semanticdiscovery",
|
1055 |
+
"senrigan",
|
1056 |
+
"sg-scout",
|
1057 |
+
"shai'hulud",
|
1058 |
+
"shark",
|
1059 |
+
"shopwiki",
|
1060 |
+
"sidewinder",
|
1061 |
+
"sift",
|
1062 |
+
"silk",
|
1063 |
+
"simmany",
|
1064 |
+
"site searcher",
|
1065 |
+
"site valet",
|
1066 |
+
"sitetech-rover",
|
1067 |
+
"skymob.com",
|
1068 |
+
"sleek",
|
1069 |
+
"smartwit",
|
1070 |
+
"sna-",
|
1071 |
+
"snappy",
|
1072 |
+
"snooper",
|
1073 |
+
"sohu",
|
1074 |
+
"speedfind",
|
1075 |
+
"sphere",
|
1076 |
+
"sphider",
|
1077 |
+
"spinner",
|
1078 |
+
"spyder",
|
1079 |
+
"steeler/",
|
1080 |
+
"suke",
|
1081 |
+
"suntek",
|
1082 |
+
"supersnooper",
|
1083 |
+
"surfnomore",
|
1084 |
+
"sven",
|
1085 |
+
"sygol",
|
1086 |
+
"szukacz",
|
1087 |
+
"tach black widow",
|
1088 |
+
"tarantula",
|
1089 |
+
"templeton",
|
1090 |
+
"/teoma",
|
1091 |
+
"t-h-u-n-d-e-r-s-t-o-n-e",
|
1092 |
+
"theophrastus",
|
1093 |
+
"titan",
|
1094 |
+
"titin",
|
1095 |
+
"tkwww",
|
1096 |
+
"toutatis",
|
1097 |
+
"t-rex",
|
1098 |
+
"tutorgig",
|
1099 |
+
"twiceler",
|
1100 |
+
"twisted",
|
1101 |
+
"ucsd",
|
1102 |
+
"udmsearch",
|
1103 |
+
"url check",
|
1104 |
+
"updated",
|
1105 |
+
"vagabondo",
|
1106 |
+
"valkyrie",
|
1107 |
+
"verticrawl",
|
1108 |
+
"victoria",
|
1109 |
+
"vision-search",
|
1110 |
+
"volcano",
|
1111 |
+
"voyager/",
|
1112 |
+
"voyager-hc",
|
1113 |
+
"w3c_validator",
|
1114 |
+
"w3m2",
|
1115 |
+
"w3mir",
|
1116 |
+
"walker",
|
1117 |
+
"wallpaper",
|
1118 |
+
"wanderer",
|
1119 |
+
"wauuu",
|
1120 |
+
"wavefire",
|
1121 |
+
"web core",
|
1122 |
+
"web hopper",
|
1123 |
+
"web wombat",
|
1124 |
+
"webbandit",
|
1125 |
+
"webcatcher",
|
1126 |
+
"webcopy",
|
1127 |
+
"webfoot",
|
1128 |
+
"weblayers",
|
1129 |
+
"weblinker",
|
1130 |
+
"weblog monitor",
|
1131 |
+
"webmirror",
|
1132 |
+
"webmonkey",
|
1133 |
+
"webquest",
|
1134 |
+
"webreaper",
|
1135 |
+
"websitepulse",
|
1136 |
+
"websnarf",
|
1137 |
+
"webstolperer",
|
1138 |
+
"webvac",
|
1139 |
+
"webwalk",
|
1140 |
+
"webwatch",
|
1141 |
+
"webwombat",
|
1142 |
+
"webzinger",
|
1143 |
+
"wget",
|
1144 |
+
"whizbang",
|
1145 |
+
"whowhere",
|
1146 |
+
"wild ferret",
|
1147 |
+
"worldlight",
|
1148 |
+
"wwwc",
|
1149 |
+
"wwwster",
|
1150 |
+
"xenu",
|
1151 |
+
"xget",
|
1152 |
+
"xift",
|
1153 |
+
"xirq",
|
1154 |
+
"yandex",
|
1155 |
+
"yanga",
|
1156 |
+
"yeti",
|
1157 |
+
"yodao",
|
1158 |
+
"zao/",
|
1159 |
+
"zippp",
|
1160 |
+
"zyborg",
|
1161 |
+
"...."
|
|
|
1162 |
);
|
1163 |
|
1164 |
+
foreach($spiders as $spider){
|
1165 |
//If the spider text is found in the current user agent, then return true
|
1166 |
+
if(stripos($_SERVER['HTTP_USER_AGENT'], $spider) !== false){
|
1167 |
return true;
|
1168 |
break;
|
1169 |
}
|
1175 |
|
1176 |
/**
|
1177 |
* Parse ID3v2, ID3v1, and getID3 comments to extract usable data
|
|
|
1178 |
* @since 3.6.0
|
1179 |
*
|
1180 |
* @param array $metadata An existing array with data
|
1181 |
+
* @param array $data Data supplied by ID3 tags
|
1182 |
*/
|
1183 |
+
function wp_add_id3_tag_data(&$metadata, $data){
|
1184 |
+
foreach(array('id3v2', 'id3v1') as $version){
|
1185 |
+
if(!empty($data[ $version ]['comments'])){
|
1186 |
+
foreach($data[ $version ]['comments'] as $key => $list){
|
1187 |
+
if(!empty($list)){
|
1188 |
+
$metadata[ $key ] = reset($list);
|
1189 |
// fix bug in byte stream analysis
|
1190 |
+
if('terms_of_use' === $key && 0 === strpos($metadata[ $key ], 'yright notice.')){
|
1191 |
+
$metadata[ $key ] = 'Cop' . $metadata[ $key ];
|
1192 |
}
|
1193 |
}
|
1194 |
}
|
1196 |
}
|
1197 |
}
|
1198 |
|
1199 |
+
if(!empty($data['id3v2']['APIC'])){
|
1200 |
$image = reset($data['id3v2']['APIC']);
|
1201 |
+
if(!empty($image['data'])){
|
1202 |
+
$metadata['image'] = array('data' => $image['data'],
|
1203 |
+
'mime' => $image['image_mime'],
|
1204 |
+
'width' => $image['image_width'],
|
1205 |
+
'height' => $image['image_height']
|
|
|
1206 |
);
|
1207 |
}
|
1208 |
+
} elseif(!empty($data['comments']['picture'])){
|
1209 |
$image = reset($data['comments']['picture']);
|
1210 |
+
if(!empty($image['data'])){
|
1211 |
+
$metadata['image'] = array('data' => $image['data'],
|
1212 |
+
'mime' => $image['image_mime']
|
|
|
1213 |
);
|
1214 |
}
|
1215 |
}
|
1217 |
|
1218 |
/**
|
1219 |
* Get extended image metadata, exif or iptc as available.
|
|
|
1220 |
* Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso
|
1221 |
* created_timestamp, focal_length, shutter_speed, and title.
|
|
|
1222 |
* The IPTC metadata that is retrieved is APP13, credit, byline, created date
|
1223 |
* and time, caption, copyright, and title. Also includes FNumber, Model,
|
1224 |
* DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.
|
1225 |
+
* @todo Try other exif libraries if available.
|
|
|
1226 |
* @since 2.5.0
|
1227 |
*
|
1228 |
* @param string $file
|
1229 |
*
|
1230 |
* @return bool|array False on failure. Image metadata array on success.
|
1231 |
*/
|
1232 |
+
function wp_read_image_metadata($file){
|
1233 |
+
if(!file_exists($file)){
|
1234 |
return false;
|
1235 |
}
|
1236 |
|
1242 |
* Read IPTC first, since it might contain data not available in exif such
|
1243 |
* as caption, description etc.
|
1244 |
*/
|
1245 |
+
if(is_callable('iptcparse')){
|
1246 |
getimagesize($file, $info);
|
1247 |
|
1248 |
+
if(!empty($info['APP13'])){
|
1249 |
$iptc = iptcparse($info['APP13']);
|
1250 |
|
1251 |
// Headline, "A brief synopsis of the caption."
|
1252 |
+
if(!empty($iptc['2#105'][0])){
|
1253 |
$meta['title'] = trim($iptc['2#105'][0]);
|
1254 |
/*
|
1255 |
* Title, "Many use the Title field to store the filename of the image,
|
1256 |
* though the field may be used in many ways."
|
1257 |
*/
|
1258 |
+
} elseif(!empty($iptc['2#005'][0])){
|
1259 |
$meta['title'] = trim($iptc['2#005'][0]);
|
1260 |
}
|
1261 |
|
1262 |
+
if(!empty($iptc['2#120'][0])){ // description / legacy caption
|
1263 |
$caption = trim($iptc['2#120'][0]);
|
1264 |
+
if(empty($meta['title'])){
|
1265 |
mbstring_binary_safe_encoding();
|
1266 |
$caption_length = strlen($caption);
|
1267 |
reset_mbstring_encoding();
|
1268 |
|
1269 |
// Assume the title is stored in 2:120 if it's short.
|
1270 |
+
if($caption_length < 80){
|
1271 |
$meta['title'] = $caption;
|
1272 |
+
} else{
|
1273 |
$meta['caption'] = $caption;
|
1274 |
}
|
1275 |
+
} elseif($caption != $meta['title']){
|
1276 |
$meta['caption'] = $caption;
|
1277 |
}
|
1278 |
}
|
1304 |
|
1305 |
/**
|
1306 |
* Filter the image types to check for exif data.
|
|
|
1307 |
* @since 2.5.0
|
1308 |
*
|
1309 |
* @param array $image_types Image types to check for exif data.
|
1310 |
*/
|
1311 |
+
if(is_callable('exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG,
|
1312 |
+
IMAGETYPE_TIFF_II,
|
1313 |
+
IMAGETYPE_TIFF_MM
|
|
|
1314 |
)))
|
1315 |
+
){
|
1316 |
$exif = @exif_read_data($file);
|
1317 |
unset($exif['MakerNote']);
|
1318 |
|
1319 |
// Title
|
1320 |
+
if(empty($meta['title']) && !empty($exif['Title'])){
|
1321 |
$meta['title'] = trim($exif['Title']);
|
1322 |
}
|
1323 |
// Descrioption
|
1324 |
+
if(!empty($exif['ImageDescription'])){
|
1325 |
mbstring_binary_safe_encoding();
|
1326 |
$description_length = strlen($exif['ImageDescription']);
|
1327 |
reset_mbstring_encoding();
|
1328 |
|
1329 |
+
if(empty($meta['title']) && $description_length < 80){
|
1330 |
// Assume the title is stored in ImageDescription
|
1331 |
$meta['title'] = trim($exif['ImageDescription']);
|
1332 |
+
if(empty($meta['caption']) && !empty($exif['COMPUTED']['UserComment']) && trim($exif['COMPUTED']['UserComment']) != $meta['title']){
|
1333 |
$meta['caption'] = trim($exif['COMPUTED']['UserComment']);
|
1334 |
}
|
1335 |
+
} elseif(empty($meta['caption']) && trim($exif['ImageDescription']) != $meta['title']){
|
1336 |
$meta['caption'] = trim($exif['ImageDescription']);
|
1337 |
}
|
1338 |
+
} elseif(empty($meta['caption']) && !empty($exif['Comments']) && trim($exif['Comments']) != $meta['title']){
|
1339 |
$meta['caption'] = trim($exif['Comments']);
|
1340 |
}
|
1341 |
// Credit
|
1342 |
+
if(empty($meta['credit'])){
|
1343 |
+
if(!empty($exif['Artist'])){
|
1344 |
$meta['credit'] = trim($exif['Artist']);
|
1345 |
+
} elseif(!empty($exif['Author'])){
|
1346 |
$meta['credit'] = trim($exif['Author']);
|
1347 |
}
|
1348 |
}
|
1349 |
// Copyright
|
1350 |
+
if(empty($meta['copyright']) && !empty($exif['Copyright'])){
|
1351 |
$meta['copyright'] = trim($exif['Copyright']);
|
1352 |
}
|
1353 |
// Camera Make
|
1354 |
+
if(!empty($exif['Make'])){
|
1355 |
$meta['make'] = $exif['Make'];
|
1356 |
}
|
1357 |
// Camera Model
|
1358 |
+
if(!empty($exif['Model'])){
|
1359 |
$meta['model'] = trim($exif['Model']);
|
1360 |
}
|
1361 |
// Exposure Time (shutter speed)
|
1362 |
+
if(!empty($exif['ExposureTime'])){
|
1363 |
$meta['exposure'] = $exif['ExposureTime'] . 's';
|
1364 |
$meta['shutter_speed'] = (string)wp_exif_frac2dec($exif['ExposureTime']) . 's';
|
1365 |
}
|
1366 |
// Aperture
|
1367 |
+
if(!empty($exif['COMPUTED']['ApertureFNumber'])){
|
1368 |
$meta['aperture'] = $exif['COMPUTED']['ApertureFNumber'];
|
1369 |
+
} elseif(!empty($exif['FNumber'])){
|
1370 |
$meta['aperture'] = 'f/' . (string)round(wp_exif_frac2dec($exif['FNumber']), 2);
|
1371 |
}
|
1372 |
// ISO
|
1373 |
+
if(!empty($exif['ISOSpeedRatings'])){
|
1374 |
$meta['iso'] = is_array($exif['ISOSpeedRatings'])? reset($exif['ISOSpeedRatings']) : $exif['ISOSpeedRatings'];
|
1375 |
$meta['iso'] = trim($meta['iso']);
|
1376 |
}
|
1377 |
// Date
|
1378 |
+
if(!empty($exif['DateTime'])){
|
1379 |
$meta['date'] = $exif['DateTime'];
|
1380 |
}
|
1381 |
// Created TimeStamp
|
1382 |
+
if(empty($meta['created_timestamp']) && !empty($exif['DateTimeDigitized'])){
|
1383 |
$meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized']);
|
1384 |
}
|
1385 |
// Lens
|
1386 |
+
if(!empty($exif['UndefinedTag:0xA434'])){
|
1387 |
$meta['lens'] = $exif['UndefinedTag:0xA434'];
|
1388 |
}
|
1389 |
// Focus Distance
|
1390 |
+
if(!empty($exif['COMPUTED']['FocusDistance'])){
|
1391 |
$meta['distance'] = $exif['COMPUTED']['FocusDistance'];
|
1392 |
}
|
1393 |
// Focal Length
|
1394 |
+
if(!empty($exif['FocalLength'])){
|
1395 |
$meta['focallength'] = (string)round(wp_exif_frac2dec($exif['FocalLength'])) . 'mm';
|
1396 |
}
|
1397 |
// Focal Length 35mm
|
1398 |
+
if(!empty($exif['FocalLengthIn35mmFilm'])){
|
1399 |
$meta['focallength35'] = $exif['FocalLengthIn35mmFilm'] . 'mm';
|
1400 |
}
|
1401 |
// Flash data
|
1402 |
+
if(!empty($exif['Flash'])){
|
1403 |
// we need to interpret the result - it's given as a number and we want a human-readable description.
|
1404 |
$fdata = $exif['Flash'];
|
1405 |
|
1406 |
+
switch($fdata){
|
1407 |
case 0 :
|
1408 |
$fdata = 'No Flash';
|
1409 |
break;
|
1477 |
$meta['flashdata'] = $fdata;
|
1478 |
}
|
1479 |
// Lens Make
|
1480 |
+
if(!empty($exif['UndefinedTag:0xA433'])){
|
1481 |
$meta['lensmake'] = $exif['UndefinedTag:0xA433'];
|
1482 |
}
|
1483 |
// Software
|
1484 |
+
if(!empty($exif['Software'])){
|
1485 |
$meta['software'] = $exif['Software'];
|
1486 |
}
|
1487 |
// Orientation
|
1488 |
+
if(!empty($exif['Orientation'])){
|
1489 |
$meta['orientation'] = $exif['Orientation'];
|
1490 |
}
|
1491 |
|
1492 |
$exif_sections = @exif_read_data($file, null, true);
|
1493 |
+
if(isset($exif_sections['GPS'])){
|
1494 |
$meta['GPS'] = $this->getGPSfromExif($exif_sections['GPS']);
|
1495 |
}
|
1496 |
unset($exif_sections);
|
1497 |
//$meta['exif'] = $exif;
|
1498 |
}
|
1499 |
|
1500 |
+
foreach(array('title', 'caption', 'credit', 'copyright', 'model', 'iso', 'software') as $key){
|
1501 |
+
if(!empty($meta[ $key ]) && !seems_utf8($meta[ $key ])){
|
1502 |
+
$meta[ $key ] = utf8_encode($meta[ $key ]);
|
1503 |
}
|
1504 |
}
|
1505 |
+
if(!empty($meta['keywords'])){
|
1506 |
+
foreach($meta['keywords'] as $i => $key){
|
1507 |
+
if(!seems_utf8($key)){
|
1508 |
+
$meta['keywords'][ $i ] = utf8_encode($key);
|
1509 |
}
|
1510 |
}
|
1511 |
}
|
1512 |
|
1513 |
+
foreach($meta as &$value){
|
1514 |
+
if(is_string($value)){
|
1515 |
$value = wp_kses_post($value);
|
1516 |
}
|
1517 |
}
|
1518 |
|
1519 |
/**
|
1520 |
* Filter the array of meta data read from an image's exif data.
|
|
|
1521 |
* @since 2.5.0
|
1522 |
*
|
1523 |
+
* @param array $meta Image meta data.
|
1524 |
+
* @param string $file Path to image file.
|
1525 |
* @param int $sourceImageType Type of image.
|
1526 |
*/
|
1527 |
return apply_filters('wp_read_image_metadata', $meta, $file, $sourceImageType);
|
1530 |
|
1531 |
/**
|
1532 |
* Retrieve metadata from a video file's ID3 tags
|
|
|
1533 |
* @since 3.6.0
|
1534 |
*
|
1535 |
* @param string $file Path to file.
|
1536 |
*
|
1537 |
* @return array|boolean Returns array of metadata, if found.
|
1538 |
*/
|
1539 |
+
function wp_read_video_metadata($file){
|
1540 |
+
if(!file_exists($file)){
|
1541 |
return false;
|
1542 |
}
|
1543 |
|
1544 |
$metadata = array();
|
1545 |
|
1546 |
+
if(!class_exists('getID3')){
|
1547 |
require(ABSPATH . WPINC . '/ID3/getid3.php');
|
1548 |
}
|
1549 |
$id3 = new getID3();
|
1550 |
$data = $id3->analyze($file);
|
1551 |
|
1552 |
+
if(isset($data['video']['lossless'])){
|
1553 |
$metadata['lossless'] = $data['video']['lossless'];
|
1554 |
}
|
1555 |
+
if(!empty($data['video']['bitrate'])){
|
1556 |
$metadata['bitrate'] = (int)$data['video']['bitrate'];
|
1557 |
}
|
1558 |
+
if(!empty($data['video']['bitrate_mode'])){
|
1559 |
$metadata['bitrate_mode'] = $data['video']['bitrate_mode'];
|
1560 |
}
|
1561 |
+
if(!empty($data['filesize'])){
|
1562 |
$metadata['filesize'] = (int)$data['filesize'];
|
1563 |
}
|
1564 |
+
if(!empty($data['mime_type'])){
|
1565 |
$metadata['mime_type'] = $data['mime_type'];
|
1566 |
}
|
1567 |
+
if(!empty($data['playtime_seconds'])){
|
1568 |
$metadata['length'] = (int)ceil($data['playtime_seconds']);
|
1569 |
}
|
1570 |
+
if(!empty($data['playtime_string'])){
|
1571 |
$metadata['length_formatted'] = $data['playtime_string'];
|
1572 |
}
|
1573 |
+
if(!empty($data['video']['resolution_x'])){
|
1574 |
$metadata['width'] = (int)$data['video']['resolution_x'];
|
1575 |
}
|
1576 |
+
if(!empty($data['video']['resolution_y'])){
|
1577 |
$metadata['height'] = (int)$data['video']['resolution_y'];
|
1578 |
}
|
1579 |
+
if(!empty($data['fileformat'])){
|
1580 |
$metadata['fileformat'] = $data['fileformat'];
|
1581 |
}
|
1582 |
+
if(!empty($data['video']['dataformat'])){
|
1583 |
$metadata['dataformat'] = $data['video']['dataformat'];
|
1584 |
}
|
1585 |
+
if(!empty($data['video']['encoder'])){
|
1586 |
$metadata['encoder'] = $data['video']['encoder'];
|
1587 |
}
|
1588 |
+
if(!empty($data['video']['codec'])){
|
1589 |
$metadata['codec'] = $data['video']['codec'];
|
1590 |
}
|
1591 |
|
1592 |
+
if(!empty($data['audio'])){
|
1593 |
unset($data['audio']['streams']);
|
1594 |
$metadata['audio'] = $data['audio'];
|
1595 |
}
|
1601 |
|
1602 |
/**
|
1603 |
* Retrieve metadata from a audio file's ID3 tags
|
|
|
1604 |
* @since 3.6.0
|
1605 |
*
|
1606 |
* @param string $file Path to file.
|
1607 |
*
|
1608 |
* @return array|boolean Returns array of metadata, if found.
|
1609 |
*/
|
1610 |
+
function wp_read_audio_metadata($file){
|
1611 |
+
if(!file_exists($file)){
|
1612 |
return false;
|
1613 |
}
|
1614 |
$metadata = array();
|
1615 |
|
1616 |
+
if(!class_exists('getID3')){
|
1617 |
require(ABSPATH . WPINC . '/ID3/getid3.php');
|
1618 |
}
|
1619 |
$id3 = new getID3();
|
1620 |
$data = $id3->analyze($file);
|
1621 |
|
1622 |
+
if(!empty($data['audio'])){
|
1623 |
unset($data['audio']['streams']);
|
1624 |
$metadata = $data['audio'];
|
1625 |
}
|
1626 |
|
1627 |
+
if(!empty($data['fileformat'])){
|
1628 |
$metadata['fileformat'] = $data['fileformat'];
|
1629 |
}
|
1630 |
+
if(!empty($data['filesize'])){
|
1631 |
$metadata['filesize'] = (int)$data['filesize'];
|
1632 |
}
|
1633 |
+
if(!empty($data['mime_type'])){
|
1634 |
$metadata['mime_type'] = $data['mime_type'];
|
1635 |
}
|
1636 |
+
if(!empty($data['playtime_seconds'])){
|
1637 |
$metadata['length'] = (int)ceil($data['playtime_seconds']);
|
1638 |
}
|
1639 |
+
if(!empty($data['playtime_string'])){
|
1640 |
$metadata['length_formatted'] = $data['playtime_string'];
|
1641 |
}
|
1642 |
|
1643 |
$this->wp_add_id3_tag_data($metadata, $data);
|
1644 |
|
1645 |
+
if(isset($metadata['image']['data']) && !empty($metadata['image']['data'])){
|
1646 |
$image = 'data:' . $metadata['image']['mime'] . ';charset=utf-8;base64,' . base64_encode($metadata['image']['data']);
|
1647 |
$metadata['image']['data'] = $image;
|
1648 |
}
|
1660 |
*
|
1661 |
* @return array
|
1662 |
*/
|
1663 |
+
function gmedia_upload_handler($file_tmp, $fileinfo, $content_type, $post_data){
|
1664 |
+
global $gmGallery, $gmDB;
|
1665 |
|
1666 |
$cleanup_dir = true; // Remove old files
|
1667 |
$file_age = 5 * 3600; // Temp file age in seconds
|
1669 |
$chunks = (int)$this->_req('chunks', 0);
|
1670 |
|
1671 |
// try to make grand-media dir if not exists
|
1672 |
+
if(!wp_mkdir_p($fileinfo['dirpath'])){
|
1673 |
+
$return = array("error" => array("code" => 100,
|
1674 |
+
"message" => sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath'])
|
1675 |
+
),
|
1676 |
+
"id" => $fileinfo['basename_original']
|
|
|
|
|
1677 |
);
|
1678 |
|
1679 |
return $return;
|
1680 |
}
|
1681 |
// Check if grand-media dir is writable
|
1682 |
+
if(!is_writable($fileinfo['dirpath'])){
|
1683 |
@chmod($fileinfo['dirpath'], 0755);
|
1684 |
+
if(!is_writable($fileinfo['dirpath'])){
|
1685 |
+
$return = array("error" => array("code" => 100,
|
1686 |
+
"message" => sprintf(__('Directory %s or its subfolders are not writable by the server.', 'grand-media'), dirname($fileinfo['dirpath']))
|
1687 |
+
),
|
1688 |
+
"id" => $fileinfo['basename_original']
|
|
|
|
|
1689 |
);
|
1690 |
|
1691 |
return $return;
|
1692 |
}
|
1693 |
}
|
1694 |
// Remove old temp files
|
1695 |
+
if($cleanup_dir && is_dir($fileinfo['dirpath']) && ($_dir = opendir($fileinfo['dirpath']))){
|
1696 |
+
while(($_file = readdir($_dir)) !== false){
|
1697 |
$tmpfilePath = $fileinfo['dirpath'] . DIRECTORY_SEPARATOR . $_file;
|
1698 |
|
1699 |
// Remove temp file if it is older than the max age and is not the current file
|
1700 |
+
if(preg_match('/\.part$/', $_file) && (filemtime($tmpfilePath) < time() - $file_age) && ($tmpfilePath != $fileinfo['filepath'] . '.part')){
|
1701 |
@unlink($tmpfilePath);
|
1702 |
}
|
1703 |
}
|
1704 |
|
1705 |
closedir($_dir);
|
1706 |
+
} else{
|
1707 |
+
$return = array("error" => array("code" => 100, "message" => sprintf(__('Failed to open directory: %s', 'grand-media'), $fileinfo['dirpath'])),
|
1708 |
+
"id" => $fileinfo['basename_original']
|
|
|
1709 |
);
|
1710 |
|
1711 |
return $return;
|
1713 |
|
1714 |
// Open temp file
|
1715 |
$out = fopen($fileinfo['filepath'] . '.part', $chunk == 0? "wb" : "ab");
|
1716 |
+
if($out){
|
1717 |
// Read binary input stream and append it to temp file
|
1718 |
$in = fopen($file_tmp, "rb");
|
1719 |
|
1720 |
+
if($in){
|
1721 |
+
while(($buff = fread($in, 4096))){
|
1722 |
fwrite($out, $buff);
|
1723 |
}
|
1724 |
+
} else{
|
1725 |
$return = array("error" => array("code" => 101, "message" => __("Failed to open input stream.", 'grand-media')), "id" => $fileinfo['basename']);
|
1726 |
|
1727 |
return $return;
|
1728 |
}
|
1729 |
fclose($in);
|
1730 |
fclose($out);
|
1731 |
+
if(strpos($content_type, "multipart") !== false){
|
1732 |
@unlink($file_tmp);
|
1733 |
}
|
1734 |
+
if(!$chunks || $chunk == ($chunks - 1)){
|
1735 |
sleep(1);
|
1736 |
// Strip the temp .part suffix off
|
1737 |
rename($fileinfo['filepath'] . '.part', $fileinfo['filepath']);
|
1740 |
|
1741 |
$size = false;
|
1742 |
$is_webimage = false;
|
1743 |
+
if('image' == $fileinfo['dirname']){
|
1744 |
/** WordPress Image Administration API */
|
1745 |
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
1746 |
|
1747 |
$size = @getimagesize($fileinfo['filepath']);
|
1748 |
+
if($size && file_is_displayable_image($fileinfo['filepath'])){
|
1749 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
1750 |
+
if(function_exists('memory_get_usage')){
|
1751 |
+
switch($extensions[ $size[2] ]){
|
1752 |
case 'GIF':
|
1753 |
$CHANNEL = 1;
|
1754 |
break;
|
1770 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
1771 |
$current_limit = @ini_get('memory_limit');
|
1772 |
$current_limit_int = intval($current_limit);
|
1773 |
+
if(false !== strpos($current_limit, 'M')){
|
1774 |
$current_limit_int *= $MB;
|
1775 |
}
|
1776 |
+
if(false !== strpos($current_limit, 'G')){
|
1777 |
$current_limit_int *= 1024;
|
1778 |
}
|
1779 |
|
1780 |
+
if(- 1 != $current_limit && $memoryNeeded > $current_limit_int){
|
1781 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
1782 |
+
if($newLimit < 256){
|
1783 |
+
$newLimit = 256;
|
1784 |
+
}
|
1785 |
@ini_set('memory_limit', $newLimit . 'M');
|
1786 |
}
|
1787 |
}
|
1788 |
|
1789 |
+
if(!wp_mkdir_p($fileinfo['dirpath_thumb'])){
|
1790 |
+
$return = array("error" => array("code" => 100,
|
1791 |
+
"message" => sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_thumb'])
|
1792 |
+
),
|
1793 |
+
"id" => $fileinfo['basename']
|
|
|
|
|
1794 |
);
|
1795 |
|
1796 |
return $return;
|
1797 |
}
|
1798 |
+
if(!is_writable($fileinfo['dirpath_thumb'])){
|
1799 |
@chmod($fileinfo['dirpath_thumb'], 0755);
|
1800 |
+
if(!is_writable($fileinfo['dirpath_thumb'])){
|
1801 |
@unlink($fileinfo['filepath']);
|
1802 |
+
$return = array("error" => array("code" => 100,
|
1803 |
+
"message" => sprintf(__('Directory %s is not writable by the server.', 'grand-media'), $fileinfo['dirpath_thumb'])
|
1804 |
+
),
|
1805 |
+
"id" => $fileinfo['basename']
|
|
|
|
|
1806 |
);
|
1807 |
|
1808 |
return $return;
|
1809 |
}
|
1810 |
}
|
1811 |
+
if(!wp_mkdir_p($fileinfo['dirpath_original'])){
|
1812 |
+
$return = array("error" => array("code" => 100,
|
1813 |
+
"message" => sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_original'])
|
1814 |
+
),
|
1815 |
+
"id" => $fileinfo['basename']
|
|
|
|
|
1816 |
);
|
1817 |
|
1818 |
return $return;
|
1819 |
}
|
1820 |
+
if(!is_writable($fileinfo['dirpath_original'])){
|
1821 |
@chmod($fileinfo['dirpath_original'], 0755);
|
1822 |
+
if(!is_writable($fileinfo['dirpath_original'])){
|
1823 |
@unlink($fileinfo['filepath']);
|
1824 |
+
$return = array("error" => array("code" => 100,
|
1825 |
+
"message" => sprintf(__('Directory %s is not writable by the server.', 'grand-media'), $fileinfo['dirpath_original'])
|
1826 |
+
),
|
1827 |
+
"id" => $fileinfo['basename']
|
|
|
|
|
1828 |
);
|
1829 |
|
1830 |
return $return;
|
1837 |
|
1838 |
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
1839 |
|
1840 |
+
if($webimg['resize']){
|
1841 |
rename($fileinfo['filepath'], $fileinfo['filepath_original']);
|
1842 |
+
} else{
|
1843 |
copy($fileinfo['filepath'], $fileinfo['filepath_original']);
|
1844 |
}
|
1845 |
|
1846 |
$size_ratio = $size[0] / $size[1];
|
1847 |
|
1848 |
$angle = 0;
|
1849 |
+
$image_meta = @$this->wp_read_image_metadata($fileinfo['filepath_original']);
|
1850 |
+
if(!empty($image_meta['orientation'])){
|
1851 |
+
switch($image_meta['orientation']){
|
1852 |
case 3:
|
1853 |
$angle = 180;
|
1854 |
break;
|
1865 |
|
1866 |
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
1867 |
|
1868 |
+
if($webimg['resize'] || $thumbimg['resize'] || $angle){
|
1869 |
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
1870 |
+
if(is_wp_error($editor)){
|
1871 |
@unlink($fileinfo['filepath']);
|
1872 |
@unlink($fileinfo['filepath_original']);
|
1873 |
+
$return = array("error" => array("code" => $editor->get_error_code(), "message" => $editor->get_error_message()),
|
1874 |
+
"id" => $fileinfo['basename'],
|
1875 |
+
"tip" => 'wp_get_image_editor'
|
|
|
1876 |
);
|
1877 |
|
1878 |
return $return;
|
1879 |
}
|
1880 |
|
1881 |
+
if($angle){
|
1882 |
$editor->rotate($angle);
|
1883 |
}
|
1884 |
|
1885 |
+
if($webimg['resize'] || $angle){
|
1886 |
$editor->set_quality($webimg['quality']);
|
1887 |
|
1888 |
+
if($webimg['resize']){
|
1889 |
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
1890 |
+
if(is_wp_error($resized)){
|
1891 |
@unlink($fileinfo['filepath']);
|
1892 |
@unlink($fileinfo['filepath_original']);
|
1893 |
+
$return = array("error" => array("code" => $resized->get_error_code(), "message" => $resized->get_error_message()),
|
1894 |
+
"id" => $fileinfo['basename'],
|
1895 |
+
"tip" => "editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})"
|
|
|
1896 |
);
|
1897 |
|
1898 |
return $return;
|
1900 |
}
|
1901 |
|
1902 |
$saved = $editor->save($fileinfo['filepath']);
|
1903 |
+
if(is_wp_error($saved)){
|
1904 |
@unlink($fileinfo['filepath']);
|
1905 |
@unlink($fileinfo['filepath_original']);
|
1906 |
+
$return = array("error" => array("code" => $saved->get_error_code(), "message" => $saved->get_error_message()),
|
1907 |
+
"id" => $fileinfo['basename'],
|
1908 |
+
"tip" => 'editor->save->webimage'
|
|
|
1909 |
);
|
1910 |
|
1911 |
return $return;
|
1912 |
}
|
1913 |
|
1914 |
+
if(('JPG' == $extensions[ $size[2] ]) && !(extension_loaded('imagick') || class_exists("Imagick"))){
|
1915 |
$this->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
1916 |
}
|
1917 |
}
|
1918 |
|
1919 |
// Thumbnail
|
1920 |
$editor->set_quality($thumbimg['quality']);
|
1921 |
+
if($thumbimg['resize']){
|
1922 |
$ed_size = $editor->get_size();
|
1923 |
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
1924 |
+
if(1 > $ed_ratio){
|
1925 |
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
1926 |
+
} else{
|
1927 |
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
1928 |
}
|
1929 |
+
if(is_wp_error($resized)){
|
1930 |
@unlink($fileinfo['filepath']);
|
1931 |
@unlink($fileinfo['filepath_original']);
|
1932 |
+
$return = array("error" => array("code" => $resized->get_error_code(), "message" => $resized->get_error_message()),
|
1933 |
+
"id" => $fileinfo['basename'],
|
1934 |
+
"tip" => "editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})"
|
|
|
1935 |
);
|
1936 |
|
1937 |
return $return;
|
1939 |
}
|
1940 |
|
1941 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
1942 |
+
if(is_wp_error($saved)){
|
1943 |
@unlink($fileinfo['filepath']);
|
1944 |
@unlink($fileinfo['filepath_original']);
|
1945 |
+
$return = array("error" => array("code" => $saved->get_error_code(), "message" => $saved->get_error_message()),
|
1946 |
+
"id" => $fileinfo['basename'],
|
1947 |
+
"tip" => 'editor->save->thumb'
|
|
|
1948 |
);
|
1949 |
|
1950 |
return $return;
|
1951 |
}
|
1952 |
|
1953 |
+
} else{
|
1954 |
copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
1955 |
}
|
1956 |
$is_webimage = true;
|
1957 |
+
} else{
|
1958 |
@unlink($fileinfo['filepath']);
|
1959 |
+
$return = array("error" => array("code" => 104, "message" => __("Could not read image size. Invalid image was deleted.", 'grand-media')),
|
1960 |
+
"id" => $fileinfo['basename_original']
|
|
|
1961 |
);
|
1962 |
|
1963 |
return $return;
|
1969 |
$description = '';
|
1970 |
$link = '';
|
1971 |
$date = null;
|
1972 |
+
if(!isset($post_data['set_title'])){
|
1973 |
$post_data['set_title'] = 'filename';
|
1974 |
}
|
1975 |
+
if(!isset($post_data['set_status'])){
|
1976 |
$post_data['set_status'] = isset($post_data['status'])? $post_data['status'] : 'inherit';
|
1977 |
}
|
1978 |
|
1979 |
$keywords = array();
|
1980 |
// use image exif/iptc data for title and caption defaults if possible
|
1981 |
+
if($size){
|
1982 |
+
if(!empty($image_meta)){
|
1983 |
+
if('exif' == $post_data['set_title']){
|
1984 |
+
if(!empty($image_meta['title']) && trim($image_meta['title'])){
|
1985 |
$title = $image_meta['title'];
|
1986 |
}
|
1987 |
}
|
1988 |
+
if(!empty($image_meta['caption']) && trim($image_meta['caption'])){
|
1989 |
$description = $image_meta['caption'];
|
1990 |
}
|
1991 |
+
if(!empty($image_meta['keywords'])){
|
1992 |
$keywords = $image_meta['keywords'];
|
1993 |
}
|
1994 |
}
|
1995 |
+
} else{
|
1996 |
$file_meta = $this->get_file_metadata($fileinfo['filepath_original'], $fileinfo);
|
1997 |
+
if(!empty($file_meta)){
|
1998 |
+
if('exif' == $post_data['set_title']){
|
1999 |
+
if(!empty($file_meta['title']) && trim($file_meta['title'])){
|
2000 |
$title = $file_meta['title'];
|
2001 |
}
|
2002 |
}
|
2003 |
+
if(!empty($file_meta['comment']) && trim($file_meta['comment'])){
|
2004 |
$description = $file_meta['comment'];
|
2005 |
}
|
2006 |
+
if(!empty($file_meta['album']) && (!isset($post_data['terms']['gmedia_album']) || empty($post_data['terms']['gmedia_album']))){
|
2007 |
$post_data['terms']['gmedia_album'] = array($file_meta['album']);
|
2008 |
}
|
2009 |
}
|
2010 |
}
|
2011 |
+
if(('empty' != $post_data['set_title']) && empty($title)){
|
2012 |
$title = $fileinfo['title'];
|
2013 |
}
|
2014 |
|
2015 |
+
if('public' == $post_data['set_status']){
|
2016 |
$post_data['set_status'] = 'publish';
|
2017 |
}
|
2018 |
|
2019 |
$status = $post_data['set_status'];
|
2020 |
+
if('inherit' == $post_data['set_status']){
|
2021 |
$gmedia_album = isset($post_data['terms']['gmedia_album'])? $post_data['terms']['gmedia_album'] : false;
|
2022 |
+
if($gmedia_album && $this->is_digit($gmedia_album)){
|
2023 |
$album = $gmDB->get_term($gmedia_album);
|
2024 |
+
if(empty($album) || is_wp_error($album)){
|
2025 |
$status = 'publish';
|
2026 |
+
} else{
|
2027 |
$status = $album->status;
|
2028 |
}
|
2029 |
+
} else{
|
2030 |
$status = 'publish';
|
2031 |
}
|
2032 |
}
|
2033 |
|
2034 |
unset($post_data['gmuid'], $post_data['mime_type'], $post_data['set_title'], $post_data['set_status']);
|
2035 |
|
2036 |
+
if(isset($post_data['terms']['gmedia_category']) && !empty($post_data['terms']['gmedia_category'])){
|
2037 |
+
if(!is_array($post_data['terms']['gmedia_category'])){
|
2038 |
$post_data['terms']['gmedia_category'] = explode(',', $post_data['terms']['gmedia_category']);
|
2039 |
}
|
2040 |
+
} else{
|
2041 |
$post_data['terms']['gmedia_category'] = array();
|
2042 |
}
|
2043 |
|
2044 |
+
if(isset($post_data['terms']['gmedia_tag']) && !empty($post_data['terms']['gmedia_tag'])){
|
2045 |
+
if(!is_array($post_data['terms']['gmedia_tag'])){
|
2046 |
$post_data['terms']['gmedia_tag'] = explode(',', $post_data['terms']['gmedia_tag']);
|
2047 |
}
|
2048 |
+
} else{
|
2049 |
$post_data['terms']['gmedia_tag'] = array();
|
2050 |
}
|
2051 |
+
if(!empty($keywords)){
|
2052 |
$post_data['terms']['gmedia_tag'] = array_unique(array_merge($post_data['terms']['gmedia_tag'], $keywords));
|
2053 |
}
|
2054 |
|
2055 |
// Construct the media array
|
2056 |
+
$media_data = array('mime_type' => $fileinfo['mime_type'],
|
2057 |
+
'gmuid' => $fileinfo['basename'],
|
2058 |
+
'title' => $title,
|
2059 |
+
'link' => $link,
|
2060 |
+
'description' => $description,
|
2061 |
+
'status' => $status,
|
2062 |
+
'date' => $date
|
|
|
2063 |
);
|
2064 |
|
2065 |
$media_data = $this->array_replace_recursive($media_data, $post_data);
|
2066 |
|
2067 |
+
if(!current_user_can('gmedia_delete_others_media')){
|
2068 |
$media_data['author'] = get_current_user_id();
|
2069 |
}
|
2070 |
|
2072 |
$id = $gmDB->insert_gmedia($media_data);
|
2073 |
|
2074 |
$media_metadata = $gmDB->generate_gmedia_metadata($id, $fileinfo);
|
2075 |
+
if($size && !empty($image_meta)){
|
2076 |
+
if(empty($media_metadata['image_meta'])){
|
2077 |
$media_metadata['image_meta'] = $image_meta;
|
2078 |
}
|
2079 |
+
if(!empty($image_meta['created_timestamp'])){
|
2080 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_created_timestamp', $image_meta['created_timestamp']);
|
2081 |
}
|
2082 |
+
if(!empty($image_meta['GPS'])){
|
2083 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_gps', $image_meta['GPS']);
|
2084 |
}
|
2085 |
}
|
2086 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $media_metadata);
|
2087 |
+
$hash_file = hash_file('md5', $fileinfo['filepath_original']);
|
2088 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_hash', $hash_file);
|
2089 |
+
$file_size = filesize($fileinfo['filepath_original']);
|
2090 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_size', $file_size);
|
2091 |
+
$return = array("success" => array("code" => 200, "message" => sprintf(__('File uploaded successful. Assigned ID: %s', 'grand-media'), $id)),
|
2092 |
+
"id" => $fileinfo['basename']
|
2093 |
);
|
2094 |
|
2095 |
return $return;
|
2096 |
+
} else{
|
2097 |
$return = array("success" => array("code" => 199, "message" => $chunk . '/' . $chunks), "id" => $fileinfo['basename']);
|
2098 |
|
2099 |
return $return;
|
2100 |
}
|
2101 |
+
} else{
|
2102 |
$return = array("error" => array("code" => 102, "message" => __("Failed to open output stream.", 'grand-media')), "id" => $fileinfo['basename']);
|
2103 |
|
2104 |
return $return;
|
2109 |
* @param $from_file
|
2110 |
* @param $to_file
|
2111 |
*/
|
2112 |
+
function copy_exif($from_file, $to_file){
|
2113 |
|
2114 |
$size = @getimagesize($to_file);
|
2115 |
|
2116 |
+
if($size){
|
2117 |
require_once(dirname(__FILE__) . '/pel/autoload.php');
|
2118 |
+
try{
|
2119 |
+
Pel::setJPEGQuality(100);
|
2120 |
+
/*
|
2121 |
+
* We want the raw JPEG data from $scaled. Luckily, one can create a
|
2122 |
+
* PelJpeg object from an image resource directly:
|
2123 |
+
*/
|
2124 |
+
$input_jpeg = new PelJpeg($from_file);
|
2125 |
+
/* Retrieve the original Exif data in $jpeg (if any). */
|
2126 |
+
$input_exif = $input_jpeg->getExif();
|
2127 |
+
/* If no Exif data was present, then $input_exif is null. */
|
2128 |
+
if($input_exif != null){
|
2129 |
+
|
2130 |
+
$input_tiff = $input_exif->getTiff();
|
2131 |
+
if($input_tiff == null){
|
2132 |
+
return;
|
2133 |
+
}
|
2134 |
+
$input_ifd0 = $input_tiff->getIfd();
|
2135 |
+
if($input_ifd0 == null){
|
2136 |
+
return;
|
2137 |
+
}
|
2138 |
|
2139 |
+
$input_exif_ifd = $input_ifd0->getSubIfd(PelIfd::EXIF);
|
2140 |
+
$input_inter_ifd = $input_ifd0->getSubIfd(PelIfd::INTEROPERABILITY);
|
2141 |
|
2142 |
+
$orientation = $input_ifd0->getEntry(PelTag::ORIENTATION);
|
2143 |
+
if($orientation != null){
|
2144 |
+
$orientation->setValue(1);
|
2145 |
+
}
|
2146 |
|
2147 |
+
if(!empty($input_ifd0)){
|
2148 |
+
/*$x_resolution = $input_ifd0->getEntry( PelTag::X_RESOLUTION );
|
2149 |
+
$y_resolution = $input_ifd0->getEntry( PelTag::Y_RESOLUTION );
|
2150 |
+
if ( $x_resolution != null && $y_resolution != null ) {
|
2151 |
+
//$x_res = $x_resolution->getValue();
|
2152 |
+
//$y_res = $y_resolution->getValue();
|
2153 |
+
$x_resolution->setValue( $y_res );
|
2154 |
+
$y_resolution->setValue( $x_res );
|
2155 |
+
}*/
|
2156 |
+
|
2157 |
+
$image_width = $input_ifd0->getEntry(PelTag::IMAGE_WIDTH);
|
2158 |
+
$image_length = $input_ifd0->getEntry(PelTag::IMAGE_LENGTH);
|
2159 |
+
if($image_width != null && $image_length != null){
|
2160 |
+
$image_width->setValue($size[0]);
|
2161 |
+
$image_length->setValue($size[1]);
|
2162 |
+
}
|
2163 |
}
|
2164 |
+
if(!empty($input_exif_ifd)){
|
2165 |
+
$x_dimention = $input_exif_ifd->getEntry(PelTag::PIXEL_X_DIMENSION);
|
2166 |
+
$y_dimention = $input_exif_ifd->getEntry(PelTag::PIXEL_Y_DIMENSION);
|
2167 |
+
if($x_dimention != null && $y_dimention != null){
|
2168 |
+
$x_dimention->setValue($size[0]);
|
2169 |
+
$y_dimention->setValue($size[1]);
|
2170 |
+
}
|
2171 |
}
|
2172 |
+
if(!empty($input_inter_ifd)){
|
2173 |
+
$rel_image_width = $input_inter_ifd->getEntry(PelTag::RELATED_IMAGE_WIDTH);
|
2174 |
+
$rel_image_length = $input_inter_ifd->getEntry(PelTag::RELATED_IMAGE_LENGTH);
|
2175 |
+
if($rel_image_width != null && $rel_image_length != null){
|
2176 |
+
$rel_image_width->setValue($size[0]);
|
2177 |
+
$rel_image_length->setValue($size[1]);
|
2178 |
+
}
|
2179 |
}
|
|
|
2180 |
|
2181 |
+
$output_jpeg = new PelJpeg($to_file);
|
2182 |
+
$output_jpeg->setExif($input_exif);
|
2183 |
|
2184 |
+
/* We can now save the image with input_exif. */
|
2185 |
+
$output_jpeg->saveFile($to_file);
|
2186 |
+
}
|
2187 |
+
} catch(PelException $e){
|
2188 |
}
|
2189 |
}
|
2190 |
}
|
2196 |
* @param $move
|
2197 |
* @param int|string $exists
|
2198 |
*/
|
2199 |
+
function gmedia_import_files($files, $_terms, $move, $exists = 0){
|
2200 |
+
global $wpdb, $gmGallery, $gmDB;
|
2201 |
|
2202 |
+
if(ob_get_level() == 0){
|
2203 |
ob_start();
|
2204 |
}
|
2205 |
$eol = '</pre>' . PHP_EOL;
|
2206 |
|
2207 |
$gmedia_album = isset($_terms['gmedia_album'])? $_terms['gmedia_album'] : false;
|
2208 |
+
if($gmedia_album && $this->is_digit($gmedia_album)){
|
2209 |
$album = $gmDB->get_term($gmedia_album);
|
2210 |
+
if(empty($album) || is_wp_error($album)){
|
2211 |
$_status = 'publish';
|
2212 |
+
} else{
|
2213 |
$_status = $album->status;
|
2214 |
$album_name = $album->name;
|
2215 |
}
|
2216 |
+
} else{
|
2217 |
$_status = 'publish';
|
2218 |
}
|
2219 |
|
2220 |
+
if(isset($_terms['gmedia_category']) && !empty($_terms['gmedia_category'])){
|
2221 |
+
if(!is_array($_terms['gmedia_category'])){
|
2222 |
$_terms['gmedia_category'] = explode(',', $_terms['gmedia_category']);
|
2223 |
}
|
2224 |
+
} else{
|
2225 |
$_terms['gmedia_category'] = array();
|
2226 |
}
|
2227 |
+
if(isset($_terms['gmedia_tag']) && !empty($_terms['gmedia_tag'])){
|
2228 |
+
if(!is_array($_terms['gmedia_tag'])){
|
2229 |
$_terms['gmedia_tag'] = explode(',', $_terms['gmedia_tag']);
|
2230 |
}
|
2231 |
+
} else{
|
2232 |
$_terms['gmedia_tag'] = array();
|
2233 |
}
|
2234 |
|
2235 |
$c = count($files);
|
2236 |
$i = 0;
|
2237 |
+
foreach($files as $file){
|
2238 |
|
2239 |
$title = '';
|
2240 |
$description = '';
|
2242 |
$status = $_status;
|
2243 |
$terms = $_terms;
|
2244 |
|
2245 |
+
if(is_array($file)){
|
2246 |
+
if(isset($file['file'])){
|
2247 |
extract($file);
|
2248 |
+
} else{
|
2249 |
_e('Something went wrong...', 'grand-media');
|
2250 |
die();
|
2251 |
}
|
2254 |
wp_ob_end_flush_all();
|
2255 |
flush();
|
2256 |
|
2257 |
+
$i ++;
|
2258 |
$prefix = "\n<pre>$i/$c - ";
|
2259 |
$prefix_ko = "\n<pre class='ko'>$i/$c - ";
|
2260 |
|
2261 |
+
if(!is_file($file)){
|
2262 |
echo $prefix_ko . sprintf(__('File not exists: %s', 'grand-media'), $file) . $eol;
|
2263 |
continue;
|
2264 |
}
|
2265 |
|
2266 |
+
if('skip' === $exists){
|
2267 |
$file_suffix = false;
|
2268 |
+
} else{
|
2269 |
$file_suffix = $exists;
|
2270 |
}
|
2271 |
+
$fileinfo = $this->fileinfo($file, $file_suffix);
|
2272 |
|
2273 |
+
if(('skip' === $exists) && file_exists($fileinfo['filepath'])){
|
2274 |
+
echo $prefix . $fileinfo['basename_original'] . ': ' . __('file with the same name already exists', 'grand-media') . $eol;
|
2275 |
continue;
|
2276 |
}
|
2277 |
|
2278 |
|
2279 |
// try to make grand-media dir if not exists
|
2280 |
+
if(!wp_mkdir_p($fileinfo['dirpath'])){
|
2281 |
echo $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath']) . $eol;
|
2282 |
continue;
|
2283 |
}
|
2284 |
// Check if grand-media dir is writable
|
2285 |
+
if(!is_writable($fileinfo['dirpath'])){
|
2286 |
@chmod($fileinfo['dirpath'], 0755);
|
2287 |
+
if(!is_writable($fileinfo['dirpath'])){
|
2288 |
echo $prefix_ko . sprintf(__('Directory `%s` or its subfolders are not writable by the server.', 'grand-media'), dirname($fileinfo['dirpath'])) . $eol;
|
2289 |
continue;
|
2290 |
}
|
2291 |
}
|
2292 |
|
2293 |
+
if(($file != $fileinfo['filepath']) && !copy($file, $fileinfo['filepath'])){
|
2294 |
echo $prefix_ko . sprintf(__("Can't copy file from `%s` to `%s`", 'grand-media'), $file, $fileinfo['filepath']) . $eol;
|
2295 |
continue;
|
2296 |
}
|
2297 |
|
2298 |
+
$this->file_chmod($fileinfo['filepath']);
|
2299 |
+
|
2300 |
+
$hash_file = hash_file('md5', $fileinfo['filepath']);
|
2301 |
+
$duplicate_id = $wpdb->get_var($wpdb->prepare("SELECT gmedia_id FROM {$wpdb->prefix}gmedia_meta WHERE meta_key = '_hash' AND meta_value = %s LIMIT 1;", $hash_file));
|
2302 |
+
if($duplicate_id){
|
2303 |
+
@unlink($fileinfo['filepath']);
|
2304 |
+
echo $prefix_ko . $fileinfo['basename_original'] . ": " . sprintf(__("Seems like it is duplicate of file with ID #%d", 'grand-media'), $duplicate_id) . $eol;
|
2305 |
+
continue;
|
2306 |
+
}
|
2307 |
|
2308 |
$size = false;
|
2309 |
$is_webimage = false;
|
2310 |
+
if('image' == $fileinfo['dirname']){
|
2311 |
/** WordPress Image Administration API */
|
2312 |
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
2313 |
|
2314 |
$size = @getimagesize($fileinfo['filepath']);
|
2315 |
+
if($size && file_is_displayable_image($fileinfo['filepath'])){
|
2316 |
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
2317 |
+
if(function_exists('memory_get_usage')){
|
2318 |
+
switch($extensions[ $size[2] ]){
|
2319 |
case 'GIF':
|
2320 |
$CHANNEL = 1;
|
2321 |
break;
|
2337 |
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
2338 |
$current_limit = @ini_get('memory_limit');
|
2339 |
$current_limit_int = intval($current_limit);
|
2340 |
+
if(false !== strpos($current_limit, 'M')){
|
2341 |
$current_limit_int *= $MB;
|
2342 |
}
|
2343 |
+
if(false !== strpos($current_limit, 'G')){
|
2344 |
$current_limit_int *= 1024;
|
2345 |
}
|
2346 |
|
2347 |
+
if(- 1 != $current_limit && $memoryNeeded > $current_limit_int){
|
2348 |
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
2349 |
+
if($newLimit < 256){
|
2350 |
+
$newLimit = 256;
|
2351 |
+
}
|
2352 |
@ini_set('memory_limit', $newLimit . 'M');
|
2353 |
}
|
2354 |
}
|
2355 |
|
2356 |
+
if(!wp_mkdir_p($fileinfo['dirpath_thumb'])){
|
2357 |
echo $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
2358 |
continue;
|
2359 |
}
|
2360 |
+
if(!is_writable($fileinfo['dirpath_thumb'])){
|
2361 |
@chmod($fileinfo['dirpath_thumb'], 0755);
|
2362 |
+
if(!is_writable($fileinfo['dirpath_thumb'])){
|
2363 |
@unlink($fileinfo['filepath']);
|
2364 |
echo $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_thumb']) . $eol;
|
2365 |
continue;
|
2366 |
}
|
2367 |
}
|
2368 |
+
if(!wp_mkdir_p($fileinfo['dirpath_original'])){
|
2369 |
echo $prefix_ko . sprintf(__('Unable to create directory `%s`. Is its parent directory writable by the server?', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
2370 |
continue;
|
2371 |
}
|
2372 |
+
if(!is_writable($fileinfo['dirpath_original'])){
|
2373 |
@chmod($fileinfo['dirpath_original'], 0755);
|
2374 |
+
if(!is_writable($fileinfo['dirpath_original'])){
|
2375 |
@unlink($fileinfo['filepath']);
|
2376 |
echo $prefix_ko . sprintf(__('Directory `%s` is not writable by the server.', 'grand-media'), $fileinfo['dirpath_original']) . $eol;
|
2377 |
continue;
|
2384 |
|
2385 |
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
2386 |
|
2387 |
+
if($webimg['resize']){
|
2388 |
rename($fileinfo['filepath'], $fileinfo['filepath_original']);
|
2389 |
+
} else{
|
2390 |
copy($fileinfo['filepath'], $fileinfo['filepath_original']);
|
2391 |
}
|
2392 |
|
2393 |
$size_ratio = $size[0] / $size[1];
|
2394 |
|
2395 |
$angle = 0;
|
2396 |
+
$image_meta = @$this->wp_read_image_metadata($fileinfo['filepath_original']);
|
2397 |
+
if(!empty($image_meta['orientation'])){
|
2398 |
+
switch($image_meta['orientation']){
|
2399 |
case 3:
|
2400 |
$angle = 180;
|
2401 |
break;
|
2412 |
|
2413 |
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
2414 |
|
2415 |
+
if($webimg['resize'] || $thumbimg['resize'] || $angle){
|
2416 |
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
2417 |
+
if(is_wp_error($editor)){
|
2418 |
@unlink($fileinfo['filepath']);
|
2419 |
@unlink($fileinfo['filepath_original']);
|
2420 |
echo $prefix_ko . $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message() . $eol;
|
2421 |
continue;
|
2422 |
}
|
2423 |
|
2424 |
+
if($angle){
|
2425 |
$editor->rotate($angle);
|
2426 |
}
|
2427 |
|
2428 |
+
if($webimg['resize'] || $angle){
|
2429 |
$editor->set_quality($webimg['quality']);
|
2430 |
|
2431 |
+
if($webimg['resize']){
|
2432 |
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
2433 |
+
if(is_wp_error($resized)){
|
2434 |
@unlink($fileinfo['filepath']);
|
2435 |
@unlink($fileinfo['filepath_original']);
|
2436 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})): " . $resized->get_error_message() . $eol;
|
2439 |
}
|
2440 |
|
2441 |
$saved = $editor->save($fileinfo['filepath']);
|
2442 |
+
if(is_wp_error($saved)){
|
2443 |
@unlink($fileinfo['filepath']);
|
2444 |
@unlink($fileinfo['filepath_original']);
|
2445 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->webimage): " . $saved->get_error_message() . $eol;
|
2446 |
continue;
|
2447 |
}
|
2448 |
|
2449 |
+
if(('JPG' == $extensions[ $size[2] ]) && !(extension_loaded('imagick') || class_exists("Imagick"))){
|
2450 |
$this->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
2451 |
}
|
2452 |
|
2454 |
|
2455 |
// Thumbnail
|
2456 |
$editor->set_quality($thumbimg['quality']);
|
2457 |
+
if($thumbimg['resize']){
|
2458 |
$ed_size = $editor->get_size();
|
2459 |
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
2460 |
+
if(1 > $ed_ratio){
|
2461 |
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
2462 |
+
} else{
|
2463 |
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
2464 |
}
|
2465 |
+
if(is_wp_error($resized)){
|
2466 |
@unlink($fileinfo['filepath']);
|
2467 |
@unlink($fileinfo['filepath_original']);
|
2468 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})): " . $resized->get_error_message() . $eol;
|
2471 |
}
|
2472 |
|
2473 |
$saved = $editor->save($fileinfo['filepath_thumb']);
|
2474 |
+
if(is_wp_error($saved)){
|
2475 |
@unlink($fileinfo['filepath']);
|
2476 |
@unlink($fileinfo['filepath_original']);
|
2477 |
echo $prefix_ko . $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message() . $eol;
|
2478 |
continue;
|
2479 |
}
|
2480 |
+
} else{
|
2481 |
copy($fileinfo['filepath'], $fileinfo['filepath_thumb']);
|
2482 |
}
|
2483 |
$is_webimage = true;
|
2484 |
+
} else{
|
2485 |
@unlink($fileinfo['filepath']);
|
2486 |
echo $prefix_ko . $fileinfo['basename'] . ": " . __("Could not read image size. Invalid image was deleted.", 'grand-media') . $eol;
|
2487 |
continue;
|
2489 |
}
|
2490 |
|
2491 |
// Write media data to DB
|
2492 |
+
if($size){
|
2493 |
+
if(!empty($image_meta)){
|
2494 |
+
if(empty($title) && !empty($image_meta['title']) && trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))){
|
2495 |
$title = $image_meta['title'];
|
2496 |
}
|
2497 |
+
if(empty($description) && !empty($image_meta['caption']) && trim($image_meta['caption'])){
|
2498 |
$description = $image_meta['caption'];
|
2499 |
}
|
2500 |
+
if(!empty($image_meta['keywords'])){
|
2501 |
$terms['gmedia_tag'] = array_unique(array_merge((array)$_terms['gmedia_tag'], $image_meta['keywords']));
|
2502 |
}
|
2503 |
}
|
2504 |
+
} else{
|
2505 |
$file_meta = $this->get_file_metadata($fileinfo['filepath_original'], $fileinfo);
|
2506 |
+
if(!empty($file_meta)){
|
2507 |
+
if(empty($title) && !empty($file_meta['title']) && trim($file_meta['title']) && !is_numeric(sanitize_title($file_meta['title']))){
|
2508 |
$title = $file_meta['title'];
|
2509 |
}
|
2510 |
+
if(empty($description) && !empty($file_meta['comment']) && trim($file_meta['comment'])){
|
2511 |
$description = $file_meta['comment'];
|
2512 |
}
|
2513 |
+
if(empty($terms['gmedia_album']) && !empty($file_meta['album'])){
|
2514 |
$terms['gmedia_album'] = array($file_meta['album']);
|
2515 |
}
|
2516 |
}
|
2517 |
}
|
2518 |
|
2519 |
+
if(empty($title)){
|
2520 |
$title = $fileinfo['title'];
|
2521 |
}
|
2522 |
|
2523 |
// Construct the media_data array
|
2524 |
+
$media_data = array('mime_type' => $fileinfo['mime_type'],
|
2525 |
+
'gmuid' => $fileinfo['basename'],
|
2526 |
+
'title' => $title,
|
2527 |
+
'link' => $link,
|
2528 |
+
'description' => $description,
|
2529 |
+
'status' => $status,
|
2530 |
+
'terms' => $terms
|
|
|
2531 |
);
|
2532 |
|
2533 |
+
if(!current_user_can('gmedia_delete_others_media')){
|
2534 |
$media_data['author'] = get_current_user_id();
|
2535 |
}
|
2536 |
|
2538 |
$id = $gmDB->insert_gmedia($media_data);
|
2539 |
|
2540 |
$media_metadata = $gmDB->generate_gmedia_metadata($id, $fileinfo);
|
2541 |
+
if($size && !empty($image_meta)){
|
2542 |
+
if(empty($media_metadata['image_meta'])){
|
2543 |
$media_metadata['image_meta'] = $image_meta;
|
2544 |
}
|
2545 |
+
if(!empty($image_meta['created_timestamp'])){
|
2546 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_created_timestamp', $image_meta['created_timestamp']);
|
2547 |
}
|
2548 |
+
if(!empty($image_meta['GPS'])){
|
2549 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_gps', $image_meta['GPS']);
|
2550 |
}
|
2551 |
}
|
2552 |
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $media_metadata);
|
2553 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_hash', $hash_file);
|
2554 |
+
$file_size = filesize($fileinfo['filepath_original']);
|
2555 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_size', $file_size);
|
2556 |
|
2557 |
echo $prefix . $fileinfo['basename'] . ': <span class="ok">' . sprintf(__('success (ID #%s)', 'grand-media'), $id) . '</span>' . $eol;
|
2558 |
|
2559 |
+
if($move){
|
2560 |
@unlink($file);
|
2561 |
}
|
2562 |
|
2570 |
flush();
|
2571 |
}
|
2572 |
|
2573 |
+
/**
|
2574 |
+
* @param $gmid
|
2575 |
+
*/
|
2576 |
+
function duplicate_gmedia($gmid){
|
2577 |
+
global $gmDB;
|
2578 |
+
|
2579 |
+
$gmedia = $gmDB->get_gmedia($gmid);
|
2580 |
+
if(!$gmedia || is_wp_error($gmedia)){
|
2581 |
+
return;
|
2582 |
+
}
|
2583 |
+
|
2584 |
+
$fileinfo = $this->fileinfo($gmedia->gmuid);
|
2585 |
+
$file = $fileinfo['dirpath_original'] . '/' . $gmedia->gmuid;
|
2586 |
+
|
2587 |
+
if(!copy($file, $fileinfo['filepath_original'])){
|
2588 |
+
return;
|
2589 |
+
}
|
2590 |
+
|
2591 |
+
if('image' == $fileinfo['dirname']){
|
2592 |
+
copy($fileinfo['dirpath'] . '/' . $gmedia->gmuid, $fileinfo['filepath']);
|
2593 |
+
copy($fileinfo['dirpath_thumb'] . '/' . $gmedia->gmuid, $fileinfo['filepath_thumb']);
|
2594 |
+
}
|
2595 |
+
|
2596 |
+
// Construct the media_data array
|
2597 |
+
$media_data = array('mime_type' => $fileinfo['mime_type'],
|
2598 |
+
'gmuid' => $fileinfo['basename'],
|
2599 |
+
'title' => $gmedia->title,
|
2600 |
+
'link' => $gmedia->link,
|
2601 |
+
'description' => $gmedia->description,
|
2602 |
+
'status' => $gmedia->status
|
2603 |
+
);
|
2604 |
+
|
2605 |
+
$media_data['author'] = get_current_user_id();
|
2606 |
+
|
2607 |
+
// Save the data
|
2608 |
+
$id = $gmDB->insert_gmedia($media_data);
|
2609 |
+
|
2610 |
+
$media_metadata = $gmDB->get_metadata('gmedia', $gmedia->ID);
|
2611 |
+
|
2612 |
+
$metadata_keys = array('_metadata', '_created_timestamp', '_gps', '_cover', '_hash', '_size', '_peaks');
|
2613 |
+
foreach($metadata_keys as $key){
|
2614 |
+
if(isset($media_metadata[ $key ][0])){
|
2615 |
+
$gmDB->add_metadata($meta_type = 'gmedia', $id, $key, $media_metadata[ $key ][0]);
|
2616 |
+
}
|
2617 |
+
}
|
2618 |
+
|
2619 |
+
}
|
2620 |
+
|
2621 |
+
/**
|
2622 |
+
* @param $gmid
|
2623 |
+
*
|
2624 |
+
* @return array
|
2625 |
+
*/
|
2626 |
+
function recreate_images_from_original($gmid){
|
2627 |
+
global $gmDB, $gmGallery;
|
2628 |
+
|
2629 |
+
$item = $gmDB->get_gmedia($gmid);
|
2630 |
+
if(!empty($item)){
|
2631 |
+
|
2632 |
+
$type = explode('/', $item->mime_type);
|
2633 |
+
$type = $type[0];
|
2634 |
+
if('image' !== $type){
|
2635 |
+
$out = array('error' => $this->alert('danger', sprintf(__('#%d: Not image type', 'grand-media'), $item->ID)));
|
2636 |
+
|
2637 |
+
return $out;
|
2638 |
+
}
|
2639 |
+
|
2640 |
+
$gmedia = array();
|
2641 |
+
$fail = '';
|
2642 |
+
$success = '';
|
2643 |
+
|
2644 |
+
if((int)$item->author != get_current_user_id()){
|
2645 |
+
if(!current_user_can('gmedia_edit_others_media')){
|
2646 |
+
$out = array('error' => $this->alert('danger', __('You are not allowed to edit others media', 'grand-media')));
|
2647 |
+
|
2648 |
+
return $out;
|
2649 |
+
}
|
2650 |
+
}
|
2651 |
+
$meta = $gmDB->get_metadata('gmedia', $item->ID);
|
2652 |
+
$metadata = $meta['_metadata'][0];
|
2653 |
+
$gmedia['ID'] = $gmid;
|
2654 |
+
$gmedia['date'] = $item->date;
|
2655 |
+
$gmedia['modified'] = current_time('mysql');
|
2656 |
+
$gmedia['author'] = $item->author;
|
2657 |
+
|
2658 |
+
$webimg = $gmGallery->options['image'];
|
2659 |
+
$thumbimg = $gmGallery->options['thumb'];
|
2660 |
+
|
2661 |
+
$fileinfo = $this->fileinfo($item->gmuid, false);
|
2662 |
+
|
2663 |
+
$size = @getimagesize($fileinfo['filepath_original']);
|
2664 |
+
|
2665 |
+
do{
|
2666 |
+
$extensions = array('1' => 'GIF', '2' => 'JPG', '3' => 'PNG', '6' => 'BMP');
|
2667 |
+
if(function_exists('memory_get_usage')){
|
2668 |
+
switch($extensions[ $size[2] ]){
|
2669 |
+
case 'GIF':
|
2670 |
+
$CHANNEL = 1;
|
2671 |
+
break;
|
2672 |
+
case 'JPG':
|
2673 |
+
$CHANNEL = $size['channels'];
|
2674 |
+
break;
|
2675 |
+
case 'PNG':
|
2676 |
+
$CHANNEL = 3;
|
2677 |
+
break;
|
2678 |
+
case 'BMP':
|
2679 |
+
default:
|
2680 |
+
$CHANNEL = 6;
|
2681 |
+
break;
|
2682 |
+
}
|
2683 |
+
$MB = 1048576; // number of bytes in 1M
|
2684 |
+
$K64 = 65536; // number of bytes in 64K
|
2685 |
+
$TWEAKFACTOR = 1.8; // Or whatever works for you
|
2686 |
+
$memoryNeeded = round(($size[0] * $size[1] * $size['bits'] * $CHANNEL / 8 + $K64) * $TWEAKFACTOR);
|
2687 |
+
$memoryNeeded = memory_get_usage() + $memoryNeeded;
|
2688 |
+
$current_limit = @ini_get('memory_limit');
|
2689 |
+
$current_limit_int = intval($current_limit);
|
2690 |
+
if(false !== strpos($current_limit, 'M')){
|
2691 |
+
$current_limit_int *= $MB;
|
2692 |
+
}
|
2693 |
+
if(false !== strpos($current_limit, 'G')){
|
2694 |
+
$current_limit_int *= 1024;
|
2695 |
+
}
|
2696 |
+
|
2697 |
+
if(- 1 != $current_limit && $memoryNeeded > $current_limit_int){
|
2698 |
+
$newLimit = $current_limit_int / $MB + ceil(($memoryNeeded - $current_limit_int) / $MB);
|
2699 |
+
if($newLimit < 256){
|
2700 |
+
$newLimit = 256;
|
2701 |
+
}
|
2702 |
+
@ini_set('memory_limit', $newLimit . 'M');
|
2703 |
+
}
|
2704 |
+
}
|
2705 |
+
|
2706 |
+
$size_ratio = $size[0] / $size[1];
|
2707 |
+
|
2708 |
+
$angle = 0;
|
2709 |
+
$image_meta = @$this->wp_read_image_metadata($fileinfo['filepath_original']);
|
2710 |
+
if(!empty($image_meta['orientation'])){
|
2711 |
+
switch($image_meta['orientation']){
|
2712 |
+
case 3:
|
2713 |
+
$angle = 180;
|
2714 |
+
break;
|
2715 |
+
case 6:
|
2716 |
+
$angle = 270;
|
2717 |
+
$size_ratio = $size[1] / $size[0];
|
2718 |
+
break;
|
2719 |
+
case 8:
|
2720 |
+
$angle = 90;
|
2721 |
+
$size_ratio = $size[1] / $size[0];
|
2722 |
+
break;
|
2723 |
+
}
|
2724 |
+
}
|
2725 |
+
|
2726 |
+
$webimg['resize'] = (($webimg['width'] < $size[0]) || ($webimg['height'] < $size[1]))? true : false;
|
2727 |
+
$thumbimg['resize'] = (((1 >= $size_ratio) && ($thumbimg['width'] > $size[0])) || ((1 <= $size_ratio) && ($thumbimg['height'] > $size[1])))? false : true;
|
2728 |
+
|
2729 |
+
if($webimg['resize'] || $thumbimg['resize'] || $angle){
|
2730 |
+
|
2731 |
+
$editor = wp_get_image_editor($fileinfo['filepath_original']);
|
2732 |
+
if(is_wp_error($editor)){
|
2733 |
+
$fail = $fileinfo['basename'] . " (wp_get_image_editor): " . $editor->get_error_message();
|
2734 |
+
break;
|
2735 |
+
}
|
2736 |
+
|
2737 |
+
if($angle){
|
2738 |
+
$editor->rotate($angle);
|
2739 |
+
}
|
2740 |
+
|
2741 |
+
if($webimg['resize'] || $angle){
|
2742 |
+
// Web-image
|
2743 |
+
$editor->set_quality($webimg['quality']);
|
2744 |
+
|
2745 |
+
if($webimg['resize']){
|
2746 |
+
$resized = $editor->resize($webimg['width'], $webimg['height'], $webimg['crop']);
|
2747 |
+
if(is_wp_error($resized)){
|
2748 |
+
$fail = $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->webimage({$webimg['width']}, {$webimg['height']}, {$webimg['crop']})): " . $resized->get_error_message();
|
2749 |
+
break;
|
2750 |
+
}
|
2751 |
+
}
|
2752 |
+
|
2753 |
+
$saved = $editor->save($fileinfo['filepath']);
|
2754 |
+
if(is_wp_error($saved)){
|
2755 |
+
$fail = $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->webimage): " . $saved->get_error_message();
|
2756 |
+
break;
|
2757 |
+
}
|
2758 |
+
if(('JPG' == $extensions[ $size[2] ]) && !(extension_loaded('imagick') || class_exists("Imagick"))){
|
2759 |
+
$this->copy_exif($fileinfo['filepath_original'], $fileinfo['filepath']);
|
2760 |
+
}
|
2761 |
+
} else{
|
2762 |
+
@copy($fileinfo['filepath_original'], $fileinfo['filepath']);
|
2763 |
+
}
|
2764 |
+
|
2765 |
+
// Thumbnail
|
2766 |
+
$editor->set_quality($thumbimg['quality']);
|
2767 |
+
if($thumbimg['resize']){
|
2768 |
+
$ed_size = $editor->get_size();
|
2769 |
+
$ed_ratio = $ed_size['width'] / $ed_size['height'];
|
2770 |
+
if(1 > $ed_ratio){
|
2771 |
+
$resized = $editor->resize($thumbimg['width'], 0, $thumbimg['crop']);
|
2772 |
+
} else{
|
2773 |
+
$resized = $editor->resize(0, $thumbimg['height'], $thumbimg['crop']);
|
2774 |
+
}
|
2775 |
+
if(is_wp_error($resized)){
|
2776 |
+
$fail = $fileinfo['basename'] . " (" . $resized->get_error_code() . " | editor->resize->thumb({$thumbimg['width']}, {$thumbimg['height']}, {$thumbimg['crop']})): " . $resized->get_error_message();
|
2777 |
+
break;
|
2778 |
+
}
|
2779 |
+
}
|
2780 |
+
|
2781 |
+
$saved = $editor->save($fileinfo['filepath_thumb']);
|
2782 |
+
if(is_wp_error($saved)){
|
2783 |
+
$fail = $fileinfo['basename'] . " (" . $saved->get_error_code() . " | editor->save->thumb): " . $saved->get_error_message();
|
2784 |
+
break;
|
2785 |
+
}
|
2786 |
+
|
2787 |
+
} else{
|
2788 |
+
@copy($fileinfo['filepath_original'], $fileinfo['filepath']);
|
2789 |
+
@copy($fileinfo['filepath_original'], $fileinfo['filepath_thumb']);
|
2790 |
+
}
|
2791 |
+
|
2792 |
+
$id = $gmDB->insert_gmedia($gmedia);
|
2793 |
+
|
2794 |
+
$new_metadata = $gmDB->generate_gmedia_metadata($id, $fileinfo);
|
2795 |
+
$metadata['web'] = $new_metadata['web'];
|
2796 |
+
$metadata['original'] = $new_metadata['original'];
|
2797 |
+
$metadata['thumb'] = $new_metadata['thumb'];
|
2798 |
+
|
2799 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $metadata);
|
2800 |
+
$gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_modified', 0);
|
2801 |
+
|
2802 |
+
$success = sprintf(__('Image "%d" restored from backup and saved', 'grand-media'), $id);
|
2803 |
+
} while(0);
|
2804 |
+
|
2805 |
+
if(empty($fail)){
|
2806 |
+
$out = array('msg' => $this->alert('info', $success), 'modified' => $gmedia['modified']);
|
2807 |
+
} else{
|
2808 |
+
$out = array('error' => $this->alert('danger', $fail));
|
2809 |
+
}
|
2810 |
+
|
2811 |
+
} else{
|
2812 |
+
$out = array('error' => $this->alert('danger', sprintf(__('#%d: No image in database', 'grand-media'), $gmid)));
|
2813 |
+
}
|
2814 |
+
|
2815 |
+
return $out;
|
2816 |
+
}
|
2817 |
+
|
2818 |
/**
|
2819 |
* @param string $service
|
2820 |
*
|
2821 |
* @return array json
|
2822 |
*/
|
2823 |
+
function app_service($service){
|
2824 |
global $gmGallery, $gmDB;
|
2825 |
|
2826 |
+
if('127.0.0.1' == $_SERVER['SERVER_ADDR']){
|
2827 |
return false;
|
2828 |
}
|
2829 |
+
if(!current_user_can('manage_options')){
|
2830 |
die('-1');
|
2831 |
}
|
2832 |
+
if(!$service){
|
2833 |
die('0');
|
2834 |
}
|
2835 |
|
2837 |
$data = array();
|
2838 |
$options = $gmGallery->options;
|
2839 |
|
2840 |
+
if($service == 'app_deactivate'){
|
2841 |
$options['mobile_app'] = 0;
|
2842 |
}
|
2843 |
|
2844 |
$data['site_email'] = $options['site_email'];
|
2845 |
+
if(in_array($service, array('app_updateinfo')) && !is_email($data['site_email'])){
|
2846 |
$result['error'][] = __('Enter valid email, please', 'grand-media');
|
2847 |
+
} else{
|
2848 |
|
2849 |
$url = home_url();
|
2850 |
$post_data = array('url' => $url);
|
2851 |
|
2852 |
+
if('app_uninstallplugin' == $service){
|
2853 |
+
if(!empty($options['site_ID'])){
|
2854 |
$post_data['site_id'] = $options['site_ID'];
|
2855 |
+
wp_remote_post('http://gmediaservice.codeasily.com/?gmService=' . $service, array('method' => 'POST',
|
2856 |
+
'timeout' => 5,
|
2857 |
+
'body' => $post_data
|
|
|
2858 |
));
|
2859 |
}
|
2860 |
|
2863 |
|
2864 |
$hash = wp_generate_password('6', false);
|
2865 |
|
2866 |
+
if(in_array($service, array('app_activate', 'app_updateinfo'))){
|
2867 |
$status = 1;
|
2868 |
+
} else{
|
2869 |
$status = $options['mobile_app'];
|
2870 |
}
|
2871 |
$install_date = get_option('gmediaInstallDate');
|
2880 |
$data['status'] = $status;
|
2881 |
$data['install_date'] = $install_date? $install_date : time();
|
2882 |
|
2883 |
+
$tagslist = $gmDB->get_terms('gmedia_tag', array('hide_empty' => true,
|
2884 |
+
'fields' => 'names',
|
2885 |
+
'no_found_rows' => true
|
|
|
2886 |
));
|
2887 |
+
if(!is_wp_error($tagslist)){
|
2888 |
$data['tags'] = (array)$tagslist;
|
2889 |
+
} else{
|
2890 |
$data['tags'] = array();
|
2891 |
}
|
2892 |
|
2893 |
set_transient($hash, $data, 45);
|
2894 |
|
2895 |
$post_data['hash'] = $hash;
|
2896 |
+
$gms_post = wp_remote_post('http://gmediaservice.codeasily.com/?gmService=' . $service, array('method' => 'POST',
|
2897 |
+
'timeout' => 45,
|
2898 |
+
'body' => $post_data
|
|
|
2899 |
));
|
2900 |
+
if(is_wp_error($gms_post)){
|
2901 |
$result['error'][] = $gms_post->get_error_message();
|
2902 |
}
|
2903 |
$gms_post_body = wp_remote_retrieve_body($gms_post);
|
2904 |
$_result = (array)json_decode($gms_post_body);
|
2905 |
+
if(isset($_result['error'])){
|
2906 |
+
if(!isset($result['error'])){
|
2907 |
$result['error'] = array();
|
2908 |
}
|
2909 |
$_result['error'] = (array)$_result['error'];
|
2910 |
$_result['error'] = array_filter($_result['error'], 'is_string');
|
2911 |
$result['error'] = array_merge($result['error'], $_result['error']);
|
2912 |
+
} else{
|
2913 |
$result = array_merge($_result, $result);
|
2914 |
//$result['gms_post'] = $gms_post;
|
2915 |
//$result['gms_post_body'] = $gms_post_body;
|
2916 |
+
if(isset($result['message'])){
|
2917 |
$result['message'] = $this->alert('info', $result['message']);
|
2918 |
}
|
2919 |
|
2920 |
+
if(isset($result['site_ID'])){
|
2921 |
$options['site_ID'] = $result['site_ID'];
|
2922 |
}
|
2923 |
+
if(isset($result['mobile_app'])){
|
2924 |
$options['mobile_app'] = $result['mobile_app'];
|
2925 |
}
|
2926 |
}
|
2927 |
+
if(isset($result['error'])){
|
2928 |
$result['error'] = $this->alert('danger', $result['error']);
|
2929 |
}
|
2930 |
}
|
2931 |
update_option('gmediaOptions', $options);
|
2932 |
|
2933 |
+
if(in_array($service, array('app_activate', 'app_updateinfo'))){
|
2934 |
wp_clear_scheduled_hook('gmedia_app_cronjob');
|
2935 |
wp_schedule_event(time(), 'gmedia_app', 'gmedia_app_cronjob');
|
2936 |
}
|
2943 |
*
|
2944 |
* @return mixed
|
2945 |
*/
|
2946 |
+
function i18n_exif_name($key){
|
2947 |
$_key = strtolower($key);
|
2948 |
+
$tagnames = array('aperture' => __('Aperture', 'grand-media'),
|
2949 |
+
'credit' => __('Credit', 'grand-media'),
|
2950 |
+
'camera' => __('Camera', 'grand-media'),
|
2951 |
+
'model' => __('Camera', 'grand-media'),
|
2952 |
+
'lens' => __('Lens', 'grand-media'),
|
2953 |
+
'lensmake' => __('Lens Make', 'grand-media'),
|
2954 |
+
'caption' => __('Caption', 'grand-media'),
|
2955 |
+
'date' => __('Date/Time', 'grand-media'),
|
2956 |
+
'created_timestamp' => __('Timestamp', 'grand-media'),
|
2957 |
+
'created_date' => __('Date Created', 'grand-media'),
|
2958 |
+
'created_time' => __('Time Created', 'grand-media'),
|
2959 |
+
'copyright' => __('Copyright', 'grand-media'),
|
2960 |
+
'focallength' => __('Focal length', 'grand-media'),
|
2961 |
+
'focallength35' => __('Focal length in 35mm Film', 'grand-media'),
|
2962 |
+
'iso' => __('ISO', 'grand-media'),
|
2963 |
+
'exposure' => __('Exposure Time', 'grand-media'),
|
2964 |
+
'shutter_speed' => __('Shutter speed', 'grand-media'),
|
2965 |
+
'title' => __('Title', 'grand-media'),
|
2966 |
+
'author' => __('Author', 'grand-media'),
|
2967 |
+
'tags' => __('Tags', 'grand-media'),
|
2968 |
+
'subject' => __('Subject', 'grand-media'),
|
2969 |
+
'make' => __('Make', 'grand-media'),
|
2970 |
+
'status' => __('Edit Status', 'grand-media'),
|
2971 |
+
'category' => __('Category', 'grand-media'),
|
2972 |
+
'keywords' => __('Keywords', 'grand-media'),
|
2973 |
+
'position' => __('Author Position', 'grand-media'),
|
2974 |
+
'GPS' => __('GPS', 'grand-media'),
|
2975 |
+
'lat' => __('Latitude', 'grand-media'),
|
2976 |
+
'lng' => __('Longtitude', 'grand-media'),
|
2977 |
+
'city' => __('City', 'grand-media'),
|
2978 |
+
'location' => __('Location', 'grand-media'),
|
2979 |
+
'state' => __('Province/State', 'grand-media'),
|
2980 |
+
'country_code' => __('Country code', 'grand-media'),
|
2981 |
+
'country' => __('Country', 'grand-media'),
|
2982 |
+
'headline' => __('Headline', 'grand-media'),
|
2983 |
+
'source' => __('Source', 'grand-media'),
|
2984 |
+
'contact' => __('Contact', 'grand-media'),
|
2985 |
+
'last_modfied' => __('Last modified', 'grand-media'),
|
2986 |
+
'tool' => __('Program tool', 'grand-media'),
|
2987 |
+
'software' => __('Software', 'grand-media'),
|
2988 |
+
'format' => __('Format', 'grand-media'),
|
2989 |
+
'width' => __('Width', 'grand-media'),
|
2990 |
+
'height' => __('Height', 'grand-media'),
|
2991 |
+
'flash' => __('Flash', 'grand-media'),
|
2992 |
+
'flashdata' => __('Flash', 'grand-media'),
|
2993 |
+
'orientation' => __('Orientation', 'grand-media')
|
|
|
2994 |
);
|
2995 |
|
2996 |
+
if(isset($tagnames[ $_key ])){
|
2997 |
+
$key = $tagnames[ $_key ];
|
2998 |
}
|
2999 |
|
3000 |
return ($key);
|
3001 |
}
|
3002 |
|
3003 |
/**
|
3004 |
+
* Determine whether a meta key is protected.
|
3005 |
+
*
|
3006 |
+
* @param string $meta_key Meta key
|
3007 |
+
* @param string|null $meta_type
|
3008 |
*
|
3009 |
+
* @return bool True if the key is protected, false otherwise.
|
3010 |
+
*/
|
3011 |
+
function is_protected_meta($meta_key, $meta_type = null){
|
3012 |
+
$protected = ('_' == $meta_key[0]);
|
3013 |
+
|
3014 |
+
return apply_filters('is_protected_gmedia_meta', $protected, $meta_key, $meta_type);
|
3015 |
+
}
|
3016 |
+
|
3017 |
+
/**
|
3018 |
+
* Display custom fields form fields.
|
3019 |
* @since 1.6.3
|
3020 |
*
|
3021 |
* @param int $gmedia_id
|
3022 |
* @param string $meta_type
|
3023 |
*/
|
3024 |
+
function gmedia_custom_meta_box($gmedia_id, $meta_type = 'gmedia'){
|
3025 |
global $gmDB;
|
3026 |
|
3027 |
+
if(empty($gmedia_id)){
|
3028 |
return;
|
3029 |
}
|
3030 |
|
3031 |
+
if(!in_array($meta_type, array('gmedia', 'gmedia_term'))){
|
3032 |
$meta_type = 'gmedia';
|
3033 |
}
|
3034 |
?>
|
3036 |
<legend class="label label-default" style="font-size:85%;"><?php _e('Custom Fields', 'grand-media'); ?></legend>
|
3037 |
<?php
|
3038 |
$metadata = $gmDB->has_meta($gmedia_id, $meta_type);
|
3039 |
+
foreach($metadata as $key => $value){
|
3040 |
+
if($this->is_protected_meta($metadata[ $key ]['meta_key'], $meta_type)){
|
3041 |
+
unset($metadata[ $key ]);
|
3042 |
}
|
3043 |
} ?>
|
3044 |
<div class="row">
|
3045 |
+
<?php if(!empty($metadata)){
|
3046 |
//$count = 0;
|
3047 |
+
foreach($metadata as $entry){
|
3048 |
echo $this->_list_meta_item($entry);
|
3049 |
}
|
3050 |
} ?>
|
3062 |
*
|
3063 |
* @return string|void
|
3064 |
*/
|
3065 |
+
function _list_meta_item($entry){
|
3066 |
+
if(is_serialized($entry['meta_value'])){
|
3067 |
+
if(is_serialized_string($entry['meta_value'])){
|
3068 |
// This is a serialized string, so we should display it.
|
3069 |
$entry['meta_value'] = maybe_unserialize($entry['meta_value']);
|
3070 |
+
} else{
|
3071 |
// This is a serialized array/object so we should NOT display it.
|
3072 |
return;
|
3073 |
}
|
3091 |
|
3092 |
/**
|
3093 |
* Prints the form in the Custom Fields meta box.
|
|
|
3094 |
* @since 1.6.3
|
3095 |
*
|
3096 |
* @param string $meta_type
|
3097 |
*
|
3098 |
* @return string
|
3099 |
*/
|
3100 |
+
function meta_form($meta_type = 'gmedia'){
|
3101 |
global $wpdb;
|
3102 |
|
3103 |
+
if(!in_array($meta_type, array('gmedia', 'gmedia_term'))){
|
3104 |
$meta_type = 'gmedia';
|
3105 |
}
|
3106 |
|
3124 |
<div class="row">
|
3125 |
<div class="form-group col-sm-6">
|
3126 |
<label>' . _x('Name', 'meta name') . '</label>';
|
3127 |
+
if($keys){
|
3128 |
natcasesort($keys);
|
3129 |
$meta_form .= '
|
3130 |
<select class="metakeyselect form-control input-sm" name="metakeyselect">
|
3131 |
<option value="">' . __('— Select —') . '</option>';
|
3132 |
+
foreach($keys as $key){
|
3133 |
+
if($this->is_protected_meta($key, $meta_type)){
|
3134 |
continue;
|
3135 |
}
|
3136 |
$meta_form .= '
|
3142 |
<a href="#gmediacustomstuff" class="hide-if-no-js gmediacustomstuff" onclick="jQuery(\'.metakeyinput, .metakeyselect, .enternew, .cancelnew\', \'#newmeta\').toggle();jQuery(this).parent().toggleClass(\'newcfield\');return false;">
|
3143 |
<span class="enternew">' . __('Enter new', 'grand-media') . '</span>
|
3144 |
<span class="cancelnew" style="display:none;">' . __('Cancel', 'grand-media') . '</span></a>';
|
3145 |
+
} else{
|
3146 |
$meta_form .= '
|
3147 |
<input type="text" class="metakeyinput form-control input-sm" name="metakeyinput" value="" />';
|
3148 |
}
|
3167 |
*
|
3168 |
* @return bool|int
|
3169 |
*/
|
3170 |
+
function add_meta($gmedia_ID, $meta_type = 'gmedia'){
|
3171 |
global $gmDB;
|
3172 |
|
3173 |
+
if(!in_array($meta_type, array('gmedia', 'gmedia_term'))){
|
3174 |
$meta_type = 'gmedia';
|
3175 |
}
|
3176 |
|
3179 |
$metakeyselect = isset($_POST['metakeyselect'])? wp_unslash(trim($_POST['metakeyselect'])) : '';
|
3180 |
$metakeyinput = isset($_POST['metakeyinput'])? wp_unslash(trim($_POST['metakeyinput'])) : '';
|
3181 |
$metavalue = isset($_POST['metavalue'])? $_POST['metavalue'] : '';
|
3182 |
+
if(is_string($metavalue)){
|
3183 |
$metavalue = trim($metavalue);
|
3184 |
}
|
3185 |
|
3186 |
+
if(('0' === $metavalue || !empty ($metavalue)) && ((!empty($metakeyselect) && !empty($metakeyselect)) || !empty ($metakeyinput))){
|
3187 |
/*
|
3188 |
* We have a key/value pair. If both the select and the input
|
3189 |
* for the key have data, the input takes precedence.
|
3190 |
*/
|
3191 |
$metakey = $metakeyselect;
|
3192 |
|
3193 |
+
if($metakeyinput){
|
3194 |
$metakey = $metakeyinput;
|
3195 |
} // default
|
3196 |
|
3197 |
+
if($this->is_protected_meta($metakey, $meta_type)){
|
3198 |
return false;
|
3199 |
}
|
3200 |
|
3212 |
*
|
3213 |
* @return array metadata[key] = array(name, value);
|
3214 |
*/
|
3215 |
+
function metadata_info($item){
|
3216 |
global $gmDB;
|
3217 |
|
3218 |
+
if(is_object($item)){
|
3219 |
$item_id = $item->ID;
|
3220 |
+
} elseif($this->is_digit($item)){
|
3221 |
$item_id = (int)$item;
|
3222 |
+
} else{
|
3223 |
return null;
|
3224 |
}
|
3225 |
|
3226 |
$metadata = array();
|
3227 |
|
3228 |
$meta = $gmDB->get_metadata('gmedia', $item_id, '_metadata', true);
|
3229 |
+
if($meta){
|
3230 |
+
if(isset($meta['image_meta'])){
|
3231 |
$metainfo = $meta['image_meta'];
|
3232 |
+
} else{
|
3233 |
$metainfo = $meta;
|
3234 |
+
if(is_array($metainfo)){
|
3235 |
unset($metainfo['web'], $metainfo['original'], $metainfo['thumb'], $metainfo['file']);
|
3236 |
}
|
3237 |
}
|
3238 |
|
3239 |
+
if(!empty($metainfo)){
|
3240 |
+
foreach($metainfo as $key => $value){
|
3241 |
+
if(empty($value)){
|
3242 |
continue;
|
3243 |
}
|
3244 |
+
$key_name = $this->i18n_exif_name($key);
|
3245 |
+
$key_name = ucwords(str_replace('_', ' ', $key_name));
|
3246 |
+
$value = $this->sanitize_meta_value($value);
|
3247 |
+
$metadata[ $key ] = array('name' => $key_name, 'value' => $value);
|
3248 |
}
|
3249 |
}
|
3250 |
}
|
3257 |
*
|
3258 |
* @return array
|
3259 |
*/
|
3260 |
+
function sanitize_meta_value($value){
|
3261 |
+
if(is_array($value) && (bool)count(array_filter(array_keys($value), 'is_string'))){
|
3262 |
$value_return = array();
|
3263 |
+
foreach($value as $key => $val){
|
3264 |
+
if(empty($value)){
|
3265 |
continue;
|
3266 |
}
|
3267 |
$key_name = $this->i18n_exif_name($key);
|
3268 |
$key_name = ucwords(str_replace('_', ' ', $key_name));
|
3269 |
+
if(is_array($val)){
|
3270 |
$val = $this->sanitize_meta_value($val);
|
3271 |
}
|
3272 |
+
$value_return[ $key ] = array('name' => $key_name, 'value' => $val);
|
3273 |
}
|
3274 |
+
} else{
|
3275 |
$value_return = $value;
|
3276 |
}
|
3277 |
|
3284 |
*
|
3285 |
* @return string Meta text;
|
3286 |
*/
|
3287 |
+
function metadata_text($id){
|
3288 |
$metatext = '';
|
3289 |
+
if(($metadata = $this->metadata_info($id))){
|
3290 |
+
foreach($metadata as $meta){
|
3291 |
+
if($meta['name'] == 'Image'){
|
3292 |
continue;
|
3293 |
}
|
3294 |
$metatext .= "<b>{$meta['name']}:</b>";
|
3295 |
+
if(!is_array($meta['value'])){
|
3296 |
$metatext .= " {$meta['value']}\n";
|
3297 |
+
} else{
|
3298 |
$value = $meta['value'];
|
3299 |
$this->meta_value_array_show($metatext, $value);
|
3300 |
}
|
3309 |
* @param $value
|
3310 |
* @param int $pad
|
3311 |
*/
|
3312 |
+
function meta_value_array_show(&$metatext, $value, $pad = 0){
|
3313 |
+
if((bool)count(array_filter(array_keys($value), 'is_string'))){
|
3314 |
+
$pad ++;
|
3315 |
+
foreach($value as $val){
|
3316 |
$metatext .= "\n" . str_pad(' ', $pad) . "- <b>{$val['name']}:</b> ";
|
3317 |
+
if(is_array($val['value'])){
|
3318 |
$this->meta_value_array_show($metatext, $val['value'], $pad);
|
3319 |
+
} else{
|
3320 |
$metatext .= $val['value'];
|
3321 |
}
|
3322 |
}
|
3323 |
+
} else{
|
3324 |
$metatext .= ' ' . implode(', ', $value);
|
3325 |
}
|
3326 |
$metatext .= "\n";
|
3332 |
*
|
3333 |
* @return array
|
3334 |
*/
|
3335 |
+
function getGPSfromExif($gps){
|
3336 |
$lat = $this->getGPS($gps['GPSLatitude'], $gps['GPSLatitudeRef']);
|
3337 |
$lng = $this->getGPS($gps['GPSLongitude'], $gps['GPSLongitudeRef']);
|
3338 |
|
3345 |
*
|
3346 |
* @return int
|
3347 |
*/
|
3348 |
+
function getGPS($coordinate, $hemisphere){
|
3349 |
+
for($i = 0; $i < 3; $i ++){
|
3350 |
+
$part = explode('/', $coordinate[ $i ]);
|
3351 |
+
if(count($part) == 1){
|
3352 |
+
$coordinate[ $i ] = $part[0];
|
3353 |
+
} else if(count($part) == 2){
|
3354 |
+
$coordinate[ $i ] = floatval($part[0]) / floatval($part[1]);
|
3355 |
+
} else{
|
3356 |
+
$coordinate[ $i ] = 0;
|
3357 |
}
|
3358 |
}
|
3359 |
list($degrees, $minutes, $seconds) = $coordinate;
|
3360 |
+
$sign = ($hemisphere == 'W' || $hemisphere == 'S')? - 1 : 1;
|
3361 |
|
3362 |
return $sign * ($degrees + $minutes / 60 + $seconds / 3600);
|
3363 |
}
|
3370 |
*
|
3371 |
* @return
|
3372 |
*/
|
3373 |
+
function gm_hitcounter($gmID, $meta){
|
3374 |
/** @var wpdb $wpdb */
|
3375 |
global $gmDB;
|
3376 |
+
|
3377 |
+
$like = $this->_post('vote');
|
3378 |
+
$like = $this->_post('like', $like);
|
3379 |
+
if((int)$like == 1){
|
3380 |
$meta['likes'] += 1;
|
3381 |
$gmDB->update_metadata('gmedia', $gmID, 'likes', $meta['likes']);
|
3382 |
+
} else{
|
3383 |
$meta['views'] += 1;
|
3384 |
$gmDB->update_metadata('gmedia', $gmID, 'views', $meta['views']);
|
3385 |
}
|
3396 |
* @return array
|
3397 |
* @throws Exception
|
3398 |
*/
|
3399 |
+
function replace_array_keys(&$array, $keymap){
|
3400 |
$replaced_keys = array();
|
3401 |
$skipped = $keymap;
|
3402 |
+
do{
|
3403 |
$keymap = $skipped;
|
3404 |
+
foreach($keymap as $new_key => $original_key){
|
3405 |
+
if(isset($array[ $original_key ])){
|
3406 |
+
if(!isset($array[ $new_key ]) || (isset($replaced_keys[ $new_key ]) && !isset($replaced_keys[ $original_key ]))){
|
3407 |
+
$array[ $new_key ] = $array[ $original_key ];
|
3408 |
+
unset($array[ $original_key ]);
|
3409 |
+
$replaced_keys[ $original_key ] = $new_key;
|
3410 |
+
unset($skipped[ $new_key ]);
|
3411 |
+
} elseif(isset($array[ $new_key ]) && array_search($new_key, $keymap) === false){
|
3412 |
throw new Exception('Trying to replace an array key with an already existing array key, without providing a new position for the existing array key in replace_array_keys().');
|
3413 |
+
} elseif(isset($array[ $new_key ]) && $keymap[ $original_key ] == $new_key && !isset($replaced_keys[ $original_key ])){
|
3414 |
//switch places.
|
3415 |
+
$temp = $array[ $new_key ];
|
3416 |
+
$array[ $new_key ] = $array[ $original_key ];
|
3417 |
+
$array[ $original_key ] = $temp;
|
3418 |
+
$replaced_keys[ $new_key ] = $original_key;
|
3419 |
+
$replaced_keys[ $original_key ] = $new_key;
|
3420 |
+
unset($skipped[ $new_key ]);
|
3421 |
+
unset($skipped[ $original_key ]);
|
3422 |
}
|
3423 |
+
} else{
|
3424 |
+
unset($skipped[ $new_key ]);
|
3425 |
}
|
3426 |
}
|
3427 |
} while(!empty($skipped));
|
3430 |
}
|
3431 |
|
3432 |
/**
|
3433 |
+
* @return array Gmedia Capabilities
|
3434 |
+
*/
|
3435 |
+
function plugin_capabilities(){
|
3436 |
+
return array('gmedia_library',
|
3437 |
+
'gmedia_show_others_media',
|
3438 |
+
'gmedia_edit_media',
|
3439 |
+
'gmedia_edit_others_media',
|
3440 |
+
'gmedia_delete_media',
|
3441 |
+
'gmedia_delete_others_media',
|
3442 |
+
'gmedia_upload',
|
3443 |
+
'gmedia_import',
|
3444 |
+
'gmedia_terms',
|
3445 |
+
'gmedia_album_manage',
|
3446 |
+
'gmedia_category_manage',
|
3447 |
+
'gmedia_tag_manage',
|
3448 |
+
'gmedia_terms_delete',
|
3449 |
+
'gmedia_gallery_manage',
|
3450 |
+
'gmedia_module_manage',
|
3451 |
+
'gmedia_settings'
|
3452 |
+
);
|
3453 |
+
}
|
3454 |
+
|
3455 |
+
/**
|
3456 |
+
* @return array Gmedia Capabilities
|
3457 |
+
*/
|
3458 |
+
function modules_order(){
|
3459 |
+
return array('phantom' => '',
|
3460 |
+
'phantom-pro' => '',
|
3461 |
+
'phototravlr' => '',
|
3462 |
+
'realslider' => '',
|
3463 |
+
'mosaic' => '',
|
3464 |
+
'photobox' => '',
|
3465 |
+
'wavesurfer' => '',
|
3466 |
+
'photomania' => '',
|
3467 |
+
'jq-mplayer' => '',
|
3468 |
+
'wp-videoplayer' => '',
|
3469 |
+
'photo-pro' => '',
|
3470 |
+
'optima' => '',
|
3471 |
+
'afflux' => '',
|
3472 |
+
'slider' => '',
|
3473 |
+
'green-style' => '',
|
3474 |
+
'photo-blog' => '',
|
3475 |
+
'minima' => '',
|
3476 |
+
'sphere' => '',
|
3477 |
+
'cube' => '',
|
3478 |
+
'flatwall' => ''
|
3479 |
+
);
|
3480 |
+
}
|
3481 |
+
|
3482 |
+
/**
|
3483 |
+
* @param int|string $module
|
3484 |
+
* @param string $set_module_callback
|
3485 |
*
|
3486 |
+
* @return array [module, settings]
|
3487 |
+
*/
|
3488 |
+
function getModulePreset($module = '', $set_module_callback = ''){
|
3489 |
+
global $gmDB, $gmGallery;
|
3490 |
+
|
3491 |
+
if(!$set_module_callback){
|
3492 |
+
$set_module_callback = 'phantom';
|
3493 |
+
}
|
3494 |
+
if(!$module){
|
3495 |
+
return $this->getModulePreset($gmGallery->options['default_gmedia_module'], $set_module_callback);
|
3496 |
+
}
|
3497 |
+
|
3498 |
+
if($this->is_digit($module)){
|
3499 |
+
$preset = $gmDB->get_term($module);
|
3500 |
+
if($preset && !is_wp_error($preset)){
|
3501 |
+
$module = $preset->status;
|
3502 |
+
$module_settings = array($module => (array)maybe_unserialize($preset->description)
|
3503 |
+
);
|
3504 |
+
} else{
|
3505 |
+
return $this->getModulePreset($set_module_callback);
|
3506 |
+
}
|
3507 |
+
} else{
|
3508 |
+
$preset = $gmDB->get_term('[' . $module . ']', array('taxonomy' => 'gmedia_module', 'global' => '0'));
|
3509 |
+
if($preset && !is_wp_error($preset)){
|
3510 |
+
$module = $preset->status;
|
3511 |
+
$module_settings = array($module => (array)maybe_unserialize($preset->description)
|
3512 |
+
);
|
3513 |
+
} else{
|
3514 |
+
$module_settings = array($module => array());
|
3515 |
+
}
|
3516 |
+
}
|
3517 |
+
|
3518 |
+
return array('module' => $module, 'settings' => $module_settings);
|
3519 |
+
}
|
3520 |
+
|
3521 |
+
/**
|
3522 |
+
* Clear the caches!
|
3523 |
+
*/
|
3524 |
+
function clear_cache(){
|
3525 |
+
// if W3 Total Cache is being used, clear the cache
|
3526 |
+
if(function_exists('w3tc_pgcache_flush')){
|
3527 |
+
w3tc_pgcache_flush();
|
3528 |
+
} // if WP Super Cache is being used, clear the cache
|
3529 |
+
else if(function_exists('wp_cache_clean_cache')){
|
3530 |
+
global $file_prefix, $supercachedir;
|
3531 |
+
if(empty($supercachedir) && function_exists('get_supercache_dir')){
|
3532 |
+
$supercachedir = get_supercache_dir();
|
3533 |
+
}
|
3534 |
+
wp_cache_clean_cache($file_prefix);
|
3535 |
+
} else if(class_exists('WpeCommon')){
|
3536 |
+
//be extra careful, just in case 3rd party changes things on us
|
3537 |
+
if(method_exists('WpeCommon', 'purge_memcached')){
|
3538 |
+
WpeCommon::purge_memcached();
|
3539 |
+
}
|
3540 |
+
if(method_exists('WpeCommon', 'purge_memcached')){
|
3541 |
+
WpeCommon::clear_maxcdn_cache();
|
3542 |
+
}
|
3543 |
+
if(method_exists('WpeCommon', 'purge_memcached')){
|
3544 |
+
WpeCommon::purge_varnish_cache();
|
3545 |
+
}
|
3546 |
+
} else if(class_exists('WpFastestCache')){
|
3547 |
+
global $wp_fastest_cache;
|
3548 |
+
if(method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)){
|
3549 |
+
$wp_fastest_cache->deleteCache();
|
3550 |
+
}
|
3551 |
+
}
|
3552 |
+
}
|
3553 |
+
|
3554 |
+
/**
|
3555 |
+
* Converts IDN in given url address to its ASCII form, also known as punycode, if possible.
|
3556 |
+
* This function silently returns unmodified address if:
|
3557 |
+
* - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
|
3558 |
+
* - Conversion to punycode is impossible (e.g. required PHP functions are not available)
|
3559 |
+
* or fails for any reason (e.g. domain has characters not allowed in an IDN)
|
3560 |
+
* @see PHPMailer::$CharSet
|
3561 |
*
|
3562 |
+
* @param string $url The url to convert
|
3563 |
+
*
|
3564 |
+
* @return string The encoded url in ASCII form
|
3565 |
*/
|
3566 |
+
public function punyencode($url){
|
3567 |
+
$url_host = parse_url($url, PHP_URL_HOST);
|
3568 |
+
|
3569 |
+
if((boolean)preg_match('/[\x80-\xFF]/', $url_host)){
|
3570 |
+
if(function_exists('mb_convert_encoding')){
|
3571 |
+
$host = mb_convert_encoding($url_host, 'UTF-8');
|
3572 |
+
} else{
|
3573 |
+
$host = $url_host;
|
3574 |
+
}
|
3575 |
+
if(function_exists('idn_to_ascii')){
|
3576 |
+
$options = 0;
|
3577 |
+
if(($punycode = defined('INTL_IDNA_VARIANT_UTS46')? idn_to_ascii($host, $options, INTL_IDNA_VARIANT_UTS46) : idn_to_ascii($host)) !== false){
|
3578 |
+
$new_url = str_replace($url_host, $punycode, $url);
|
3579 |
|
3580 |
+
return $new_url;
|
3581 |
+
}
|
3582 |
+
}
|
3583 |
+
|
3584 |
+
require_once(dirname(__FILE__) . '/punycode.php');
|
3585 |
+
$gmPunycode = new gmPunycode();
|
3586 |
+
$punycode = $gmPunycode->encode($host);
|
3587 |
+
$new_url = str_replace($url_host, $punycode, $url);
|
3588 |
+
|
3589 |
+
return $new_url;
|
3590 |
}
|
|
|
3591 |
|
3592 |
+
return $url;
|
3593 |
}
|
3594 |
|
3595 |
/**
|
3596 |
+
* Sanitizes a hex color
|
3597 |
+
*
|
3598 |
+
* @param $color
|
3599 |
+
* @param $def
|
3600 |
+
*
|
3601 |
+
* @return string
|
3602 |
*/
|
|
|
|