Esempio n. 1
0
function gmedia_add_media_terms()
{
    global $user_ID, $gmCore, $gmDB, $gmGallery;
    $post_id = intval($gmCore->_get('post_id'));
    $url = add_query_arg(array('post_id' => $post_id, 'tab' => 'gmedia_terms', 'chromeless' => true), admin_url('media-upload.php'));
    $taxonomy = $gmCore->_get('term', 'gmedia_album');
    if (!in_array($taxonomy, array('gmedia_album', 'gmedia_tag', 'gmedia_category'))) {
        $taxonomy = 'gmedia_album';
    }
    $gm_screen_options = get_user_meta($user_ID, 'gm_screen_options', true);
    if (!is_array($gm_screen_options)) {
        $gm_screen_options = array();
    }
    $gm_screen_options = array_merge($gmGallery->options['gm_screen_options'], $gm_screen_options);
    $orderby = !empty($gm_screen_options["orderby_{$taxonomy}"]) ? $gm_screen_options["orderby_{$taxonomy}"] : 'name';
    $order = !empty($gm_screen_options["sortorder_{$taxonomy}"]) ? $gm_screen_options["sortorder_{$taxonomy}"] : 'ASC';
    $per_page = !empty($gm_screen_options["per_page_{$taxonomy}"]) ? $gm_screen_options["per_page_{$taxonomy}"] : 30;
    $search_string = $gmCore->_get('s', '');
    $args = array('orderby' => $gmCore->_get('orderby', $orderby), 'order' => $gmCore->_get('order', $order), 'search' => $search_string, 'number' => $gmCore->_get('number', $per_page), 'hide_empty' => $gmCore->_get('hide_empty', 0), 'page' => $gmCore->_get('pager', 1));
    $args['offset'] = ($args['page'] - 1) * $args['number'];
    switch ($taxonomy) {
        case 'gmedia_album':
            $args['status'] = array('publish', 'private');
            $args['global'] = $gmCore->_get('author', $gmCore->caps['gmedia_edit_others_media'] ? '' : array(0, $user_ID));
            if (!$gmCore->caps['gmedia_show_others_media']) {
                $args['global'] = wp_parse_id_list($args['global']);
                $args['global'] = array_intersect(array(0, $user_ID), $args['global']);
                if (empty($args['global'])) {
                    $args['global'] = array(0, $user_ID);
                }
            }
            break;
        case 'gmedia_category':
        case 'gmedia_tag':
            if ('global' == $args['orderby']) {
                $args['orderby'] = 'id';
            }
            break;
    }
    $gmediaTerms = $gmDB->get_terms($taxonomy, $args);
    $alert = '';
    if (is_wp_error($gmediaTerms)) {
        $alert = $gmCore->alert('danger', $gmediaTerms->get_error_message());
        $gmediaTerms = array();
    }
    $gmedia_modules = get_gmedia_modules(false);
    ?>

    <div class="panel panel-default">
        <div class="panel-heading clearfix">
            <?php 
    include GMEDIA_ABSPATH . 'admin/tpl/search-form.php';
    ?>
            <div class="pull-right">
                <?php 
    echo $gmDB->query_pager();
    ?>
            </div>

            <div class="btn-group" style="margin-right:20px;">
                <a class="btn btn<?php 
    echo 'gmedia_album' == $taxonomy ? "-primary active" : '-default';
    ?>
"
                   href="<?php 
    echo add_query_arg(array('term' => 'gmedia_album'), $url);
    ?>
"><?php 
    _e('Albums', 'grand-media');
    ?>
</a>
                <a class="btn btn<?php 
    echo 'gmedia_category' == $taxonomy ? "-primary active" : '-default';
    ?>
"
                   href="<?php 
    echo add_query_arg(array('term' => 'gmedia_category'), $url);
    ?>
"><?php 
    _e('Categories', 'grand-media');
    ?>
</a>
                <a class="btn btn<?php 
    echo 'gmedia_tag' == $taxonomy ? "-primary active" : '-default';
    ?>
"
                   href="<?php 
    echo add_query_arg(array('term' => 'gmedia_tag'), $url);
    ?>
"><?php 
    _e('Tags', 'grand-media');
    ?>
</a>
            </div>

        </div>
        <div class="panel-body" id="gmedia-msg-panel"><?php 
    echo $alert;
    ?>
</div>
        <div class="panel-body" id="gm-list-table">
            <div class="row">
                <div class="col-xs-7 col-md-9" style="padding: 0">
                    <div class="list-group" id="gm-list-table" style="margin-bottom:4px;">
                        <?php 
    if (count($gmediaTerms)) {
        $author = $gmCore->caps['gmedia_show_others_media'] ? 0 : $user_ID;
        $allow_edit = $gmCore->caps['gmedia_edit_others_media'];
        foreach ($gmediaTerms as $item) {
            $author_name = $owner = '';
            $list_row_class = $row_class = '';
            $termItems = array();
            $per_page = 10;
            $item_name = $item->name;
            if ('gmedia_album' == $taxonomy) {
                if ($item->global) {
                    $owner = get_the_author_meta('display_name', $item->global);
                    $author_name .= sprintf(__('by %s', 'grand-media'), $owner);
                    if ($item->global == $user_ID) {
                        $row_class .= ' current_user';
                        $allow_edit = $gmCore->caps['gmedia_album_manage'];
                    } else {
                        $row_class .= ' other_user';
                        $allow_edit = $gmCore->caps['gmedia_edit_others_media'];
                    }
                } else {
                    $owner = '&#8212;';
                    $author_name .= '(' . __('shared', 'grand-media') . ')';
                    $row_class .= ' shared';
                    $allow_edit = $gmCore->caps['gmedia_edit_others_media'];
                }
                if ('publish' != $item->status) {
                    $author_name .= ' [' . $item->status . ']';
                    if ('private' == $item->status) {
                        $list_row_class = ' list-group-item-info';
                    } elseif ('draft' == $item->status) {
                        //$list_row_class = ' list-group-item-warning';
                        continue;
                    }
                }
            }
            if ($item->count) {
                if ('gmedia_album' == $taxonomy) {
                    $term_meta = $gmDB->get_metadata('gmedia_term', $item->term_id);
                    $term_meta = array_map('reset', $term_meta);
                    $term_meta = array_merge(array('_orderby' => $gmGallery->options['in_album_orderby'], '_order' => $gmGallery->options['in_album_order']), $term_meta);
                    $args = array('no_found_rows' => true, 'per_page' => $per_page, 'album__in' => array($item->term_id), 'author' => $author, 'orderby' => $term_meta['_orderby'], 'order' => $term_meta['_order']);
                } elseif ('gmedia_category' == $taxonomy) {
                    $term_meta = $gmDB->get_metadata('gmedia_term', $item->term_id);
                    $term_meta = array_map('reset', $term_meta);
                    $term_meta = array_merge(array('_orderby' => $gmGallery->options['in_category_orderby'], '_order' => $gmGallery->options['in_category_order']), $term_meta);
                    $args = array('no_found_rows' => true, 'per_page' => $per_page, 'category__in' => $item->term_id, 'author' => $author, 'orderby' => $term_meta['_orderby'], 'order' => $term_meta['_order']);
                } elseif ('gmedia_tag' == $taxonomy) {
                    $args = array('no_found_rows' => true, 'per_page' => $per_page, 'tag_id' => $item->term_id, 'author' => $author, 'orderby' => $gmGallery->options['in_tag_orderby'], 'order' => $gmGallery->options['in_tag_order']);
                }
                $termItems = $gmDB->get_gmedias($args);
            }
            if ('gmedia_tag' != $taxonomy) {
                $_module_preset = isset($term_meta['_module_preset'][0]) ? $term_meta['_module_preset'][0] : $gmGallery->options['default_gmedia_module'];
            } else {
                $_module_preset = $gmGallery->options['default_gmedia_module'];
            }
            $by_author = '';
            $preset_name = __('Default Settings');
            if ($gmCore->is_digit($_module_preset)) {
                $preset = $gmDB->get_term($_module_preset);
                $mfold = $preset->status;
                if ((int) $preset->global) {
                    $by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
                }
                if ('[' . $mfold . ']' !== $preset->name) {
                    $preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
                }
            } else {
                $mfold = $_module_preset;
            }
            $module_preset = $gmedia_modules['in'][$mfold]['title'] . $by_author . ' - ' . $preset_name;
            ?>
                                <div class="list-group-item term-list-item d-row<?php 
            echo $list_row_class;
            ?>
">
                                    <div class="row<?php 
            echo $row_class;
            ?>
">
                                        <div class="col-xs-5 term-label">
                                            <div class="no-checkbox">
                                                <span class="term_name"><?php 
            echo esc_html($item_name);
            ?>
</span>
                                                <span class="term_info_author"><?php 
            echo $author_name;
            ?>
</span>
                                                <span class="badge pull-right"><?php 
            echo $item->count;
            ?>
</span>
                                            </div>
                                        </div>
                                        <div class="col-xs-7">
                                            <div class="term-images">
                                                <?php 
            if (!empty($termItems)) {
                foreach ($termItems as $i) {
                    ?>
                                                        <img style="z-index:<?php 
                    echo $per_page--;
                    ?>
;"
                                                             src="<?php 
                    echo $gmCore->gm_get_media_image($i, 'thumb', false);
                    ?>
"
                                                             alt="<?php 
                    echo $i->ID;
                    ?>
"
                                                             title="<?php 
                    esc_attr_e($i->title);
                    ?>
"/>
                                                        <?php 
                }
            }
            if (count($termItems) < $item->count) {
                echo '...';
            }
            ?>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="term-info hidden">
                                        <?php 
            $term_meta = $gmDB->get_metadata('gmedia_term', $item->term_id);
            $term_meta = array_map('reset', $term_meta);
            $term_meta = array_merge(array('_orderby' => 'ID', '_order' => 'DESC'), $term_meta);
            $tax_name = array('gmedia_album' => __('Album', 'grand-media'), 'gmedia_tag' => __('Tag', 'grand-media'), 'gmedia_category' => __('Category', 'grand-media'));
            $lib_arg = array('gmedia_album' => 'album__in', 'gmedia_tag' => 'tag__in', 'gmedia_category' => 'category__in');
            ?>
                                        <input type="hidden" name="taxonomy" value="<?php 
            echo $taxonomy;
            ?>
"/>
                                        <input type="hidden" name="term_id" value="<?php 
            echo $item->term_id;
            ?>
"/>

                                        <p><strong><?php 
            echo $tax_name[$taxonomy];
            ?>
:</strong> <?php 
            echo esc_html($item_name);
            ?>
                                            <br/><strong><?php 
            _e('ID', 'grand-media');
            ?>
:</strong> <?php 
            echo $item->term_id;
            ?>
                                            <?php 
            if ('gmedia_tag' != $taxonomy) {
                $orderby = array('custom' => __('user defined', 'grand-media'), 'ID' => __('by ID', 'grand-media'), 'title' => __('by title', 'grand-media'), 'gmuid' => __('by filename', 'grand-media'), 'date' => __('by date', 'grand-media'), 'modified' => __('by last modified date', 'grand-media'), 'rand' => __('Random', 'grand-media'));
                ?>
                                                <br/><strong><?php 
                _e('Order', 'grand-media');
                ?>
:</strong> <?php 
                echo $orderby[$term_meta['_orderby']];
                ?>
                                                <br/><strong><?php 
                _e('Sort order', 'grand-media');
                ?>
:</strong> <?php 
                echo $term_meta['_order'];
                ?>
                                                <?php 
                if ('gmedia_album' == $taxonomy) {
                    ?>
                                                    <br/><strong><?php 
                    _e('Status', 'grand-media');
                    ?>
:</strong> <?php 
                    echo $item->status;
                    ?>
                                                <br/><strong><?php 
                    _e('Author', 'grand-media');
                    ?>
:</strong> <?php 
                    echo $owner;
                    ?>
                                                <?php 
                }
                ?>
                                            <?php 
            }
            ?>
                                            <br/><strong><?php 
            _e('Module/Preset', 'grand-media');
            ?>
:</strong> <?php 
            echo $module_preset;
            ?>
                                        </p>

                                        <p>
                                            <a href="<?php 
            echo add_query_arg(array('page' => 'GrandMedia', $lib_arg[$taxonomy] => $item->term_id), admin_url('admin.php'));
            ?>
" target="_blank"><?php 
            _e('View in Gmedia Library', 'grand-media');
            ?>
</a>
                                            <?php 
            if ('gmedia_album' == $taxonomy && $allow_edit) {
                ?>
                                                &nbsp; | &nbsp; <a href="<?php 
                echo add_query_arg(array('page' => 'GrandMedia_Albums', 'edit_term' => $item->term_id), admin_url('admin.php'));
                ?>
" target="_blank"><?php 
                _e('Edit Album', 'grand-media');
                ?>
</a>
                                            <?php 
            } elseif ('gmedia_category' == $taxonomy && $allow_edit) {
                ?>
                                                &nbsp; | &nbsp; <a href="<?php 
                echo add_query_arg(array('page' => 'GrandMedia_Categories', 'edit_term' => $item->term_id), admin_url('admin.php'));
                ?>
" target="_blank"><?php 
                _e('Edit Category', 'grand-media');
                ?>
</a>
                                            <?php 
            }
            ?>
                                        </p>
                                    </div>
                                    <?php 
            /*if(!empty($item->description)) { ?>
                  <div class="term-description"><?php echo esc_html(nl2br($item->description)); ?></div>
              <?php }*/
            ?>
                                </div>
                                <?php 
        }
    } else {
        ?>
                            <div class="list-group-item">
                                <div class="well well-lg text-center">
                                    <h4><?php 
        _e('No items to show.', 'grand-media');
        ?>
</h4>
                                </div>
                            </div>
                        <?php 
    }
    ?>
                    </div>
                </div>
                <div class="col-xs-5 col-md-3 media-upload-sidebar">
                    <form method="post" id="gmedia-form" role="form">
                        <div class="media-upload-form-container">
                            <div class="form-group">
                                <label><?php 
    _e('Overwrite Module/Preset', 'grand-media');
    ?>
</label>
                                <select class="form-control input-sm" id="module_preset" name="module_preset">
                                    <option value=""><?php 
    _e('Do not overwrite', 'grand-media');
    ?>
</option>
                                    <?php 
    foreach ($gmedia_modules['in'] as $mfold => $module) {
        echo '<optgroup label="' . esc_attr($module['title']) . '">';
        $presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
        $option = array();
        $option[] = '<option value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
        foreach ($presets as $preset) {
            if (!(int) $preset->global && '[' . $mfold . ']' === $preset->name) {
                continue;
            }
            $by_author = '';
            if ((int) $preset->global) {
                $by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
            }
            if ('[' . $mfold . ']' === $preset->name) {
                $option[] = '<option value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
            } else {
                $preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
                $option[] = '<option value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
            }
        }
        echo implode('', $option);
        echo '</optgroup>';
    }
    ?>
                                </select>
                                <p class="help-block"><?php 
    _e('Overwrite Module/Preset of chosen term via shortcode parameters. Create Presets on Modules page or while edit/create some galleries.', 'grand-media');
    ?>
</p>
                            </div>
                            <div id="media-upload-form-container"></div>
                        </div>
                        <div class="panel-footer">
                            <input type="hidden" name="post_id" id="post_id" value="<?php 
    echo $post_id;
    ?>
"/>
                            <?php 
    wp_nonce_field('media-form');
    ?>
                            <button type="submit" id="media-upload-form-submit" disabled class="btn btn-primary pull-right" name="gmedia_term_insert"><?php 
    _e('Insert into post', 'grand-media');
    ?>
</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            jQuery(function($) {
                function divFrame() {
                    $('.panel-body').css({top: $('.panel-heading').outerHeight()});
                }

                divFrame();
                $(window).on('resize', function() {
                    divFrame();
                });
                $('.term-list-item').on('click', function() {
                    $(this).addClass('gm-selected').siblings().removeClass('gm-selected');
                    var info = $('.term-info', this).clone();
                    $('#media-upload-form-container').html(info.html());
                    $('#media-upload-form-submit').prop('disabled', false);
                });
                /*$('#module_preset').on('change', function () {
                 if ($(this).val() && $('#media-upload-form-container').text()) {
                 $('#media-upload-form-submit').prop('disabled', false);
                 } else {
                 $('#media-upload-form-submit').prop('disabled', true);
                 }
                 });*/
            });
        </script>
    </div>
    <?php 
}
Esempio n. 2
0
function gmedia_get_modal()
{
    global $gmDB, $gmCore, $gmGallery;
    check_ajax_referer("GmediaGallery");
    $user_ID = get_current_user_id();
    $button_class = 'btn-primary';
    $gm_terms = array();
    $modal = $gmCore->_post('modal');
    $ckey = $gmCore->_post('ckey');
    switch ($modal) {
        case 'quick_gallery':
            if (!current_user_can('gmedia_gallery_manage')) {
                die('-1');
            }
            //$ckey         = "gmedia_library";
            $modal_title = __('Quick Gallery from selected items', 'grand-media');
            $modal_button = __('Create Quick Gallery', 'grand-media');
            break;
        case 'quick_gallery_stack':
            if (!current_user_can('gmedia_gallery_manage')) {
                die('-1');
            }
            //$ckey         = "gmedia_{$user_ID}_libstack";
            $modal_title = __('Quick Gallery from Stack', 'grand-media');
            $modal_button = __('Create Quick Gallery', 'grand-media');
            break;
        case 'exclude_categories':
        case 'filter_categories':
            $modal_title = __('Show Images from Categories', 'grand-media');
            $modal_button = __('Show Selected', 'grand-media');
            break;
        case 'assign_category':
            if (!current_user_can('gmedia_terms')) {
                die('-1');
            }
            $modal_title = __('Assign Category for Selected Images', 'grand-media');
            $modal_button = __('Assign Category', 'grand-media');
            break;
        case 'unassign_category':
            if (!current_user_can('gmedia_terms')) {
                die('-1');
            }
            $button_class = 'btn-danger';
            $modal_title = __('Unassign Categories from Selected Items', 'grand-media');
            $modal_button = __('Unassign Categories', 'grand-media');
            break;
        case 'exclude_albums':
        case 'filter_albums':
            $modal_title = __('Filter Albums', 'grand-media');
            $modal_button = __('Show Selected', 'grand-media');
            break;
        case 'assign_album':
            if (!current_user_can('gmedia_terms')) {
                die('-1');
            }
            $modal_title = __('Assign Album for Selected Items', 'grand-media');
            $modal_button = __('Assign Album', 'grand-media');
            break;
        case 'exclude_tags':
        case 'filter_tags':
            $modal_title = __('Filter by Tags', 'grand-media');
            $modal_button = __('Show Selected', 'grand-media');
            break;
        case 'add_tags':
            if (!current_user_can('gmedia_terms')) {
                die('-1');
            }
            $modal_title = __('Add Tags to Selected Items', 'grand-media');
            $modal_button = __('Add Tags', 'grand-media');
            break;
        case 'delete_tags':
            if (!current_user_can('gmedia_terms')) {
                die('-1');
            }
            $button_class = 'btn-danger';
            $modal_title = __('Delete Tags from Selected Items', 'grand-media');
            $modal_button = __('Delete Tags', 'grand-media');
            break;
        case 'custom_filter':
            $modal_title = __('Custom Filters', 'grand-media');
            $modal_button = __('Show Selected', 'grand-media');
            break;
        case 'filter_author':
            $modal_title = __('Filter by Author', 'grand-media');
            if ($gmCore->caps['gmedia_show_others_media']) {
                $modal_button = __('Show Selected', 'grand-media');
            } else {
                $modal_button = false;
            }
            break;
        case 'select_author':
            $modal_title = __('Select Author', 'grand-media');
            if ($gmCore->caps['gmedia_show_others_media']) {
                $modal_button = __('Select', 'grand-media');
            } else {
                $modal_button = false;
            }
            break;
        case 'batch_edit':
            if (!current_user_can('gmedia_edit_media')) {
                die('-1');
            }
            $modal_title = __('Batch Edit', 'grand-media');
            $modal_button = __('Batch Save', 'grand-media');
            break;
        default:
            $modal_title = ' ';
            $modal_button = false;
            break;
    }
    $form_action = !empty($_SERVER['HTTP_REFERER']) ? $gmCore->get_admin_url(array(), array(), $_SERVER['HTTP_REFERER']) : '';
    ?>
    <form class="modal-content" id="ajax-modal-form" autocomplete="off" method="post" action="<?php 
    echo $form_action;
    ?>
">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title"><?php 
    echo $modal_title;
    ?>
</h4>
        </div>
        <div class="modal-body">
            <?php 
    switch ($modal) {
        case 'quick_gallery':
        case 'quick_gallery_stack':
            if (!empty($ckey)) {
                $selected_in_library = isset($_COOKIE[$ckey]) ? str_replace('.', ',', $_COOKIE[$ckey]) : '';
            }
            if (empty($selected_in_library)) {
                _e('No selected Gmedia. Select at least one item in library.', 'grand-media');
                break;
            }
            $gmedia_modules = get_gmedia_modules(false);
            ?>
                <div class="form-group">
                    <label><?php 
            _e('Gallery Name', 'grand-media');
            ?>
</label>
                    <input type="text" class="form-control input-sm" name="gallery[name]" placeholder="<?php 
            esc_attr_e(__('Gallery Name', 'grand-media'));
            ?>
" value="" required="required"/>
                </div>
                <div class="form-group">
                    <label><?php 
            _e('Modue', 'grand-media');
            ?>
</label>
                    <select class="form-control input-sm" name="gallery[module]">
                        <?php 
            foreach ($gmedia_modules['in'] as $mfold => $module) {
                echo '<optgroup label="' . esc_attr($module['title']) . '">';
                $presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
                $selected = selected($gmGallery->options['default_gmedia_module'], esc_attr($mfold), false);
                $option = array();
                $option[] = '<option ' . $selected . ' value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
                foreach ($presets as $preset) {
                    if (!(int) $preset->global && '[' . $mfold . ']' === $preset->name) {
                        continue;
                    }
                    $selected = selected($gmGallery->options['default_gmedia_module'], $preset->term_id, false);
                    $by_author = '';
                    if ((int) $preset->global) {
                        $by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
                    }
                    if ('[' . $mfold . ']' === $preset->name) {
                        $option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . __('Default Settings') . '</option>';
                    } else {
                        $preset_name = str_replace('[' . $mfold . '] ', '', $preset->name);
                        $option[] = '<option ' . $selected . ' value="' . $preset->term_id . '">' . $module['title'] . $by_author . ' - ' . $preset_name . '</option>';
                    }
                }
                echo implode('', $option);
                echo '</optgroup>';
            }
            ?>
                    </select>
                </div>
                <div class="form-group">
                    <label><?php 
            _e('Selected IDs', 'grand-media');
            ?>
</label>
                    <input type="text" name="gallery[query][gmedia__in]" class="form-control input-sm" value="<?php 
            echo $selected_in_library;
            ?>
" required="required"/>
                </div>
            <?php 
            break;
        case 'exclude_albums':
        case 'filter_albums':
            if ($gmCore->caps['gmedia_show_others_media']) {
                $args = array();
            } else {
                $args = array('global' => array(0, $user_ID), 'orderby' => 'global_desc_name');
            }
            $gm_terms = $gmDB->get_terms('gmedia_album', $args);
            ?>
                <div class="checkbox"><label><input type="checkbox" name="alb[]" value="0"> <?php 
            _e('No Album', 'grand-media');
            ?>
</label></div>
            <hr/>
                <?php 
            if (count($gm_terms)) {
                foreach ($gm_terms as $term) {
                    $author_name = '';
                    if ($term->global) {
                        if ($gmCore->caps['gmedia_show_others_media']) {
                            $author_name .= sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $term->global));
                        }
                    } else {
                        $author_name .= '(' . __('shared', 'grand-media') . ')';
                    }
                    if ('publish' != $term->status) {
                        $author_name .= ' [' . $term->status . ']';
                    }
                    if ($author_name) {
                        $author_name = " <small>{$author_name}</small>";
                    }
                    ?>
                <div class="checkbox">
                    <label><input type="checkbox" name="alb[]" value="<?php 
                    echo $term->term_id;
                    ?>
"> <?php 
                    echo esc_html($term->name) . $author_name;
                    ?>
</label>
                    <span class="badge pull-right"><?php 
                    echo $term->count;
                    ?>
</span>
                </div>
            <?php 
                }
            } else {
                $modal_button = false;
            }
            break;
        case 'assign_album':
            if ($gmCore->caps['gmedia_edit_others_media']) {
                $args = array();
            } else {
                $args = array('global' => array(0, $user_ID), 'orderby' => 'global_desc_name');
            }
            $gm_terms = $gmDB->get_terms('gmedia_album', $args);
            $terms_album = '';
            if (count($gm_terms)) {
                foreach ($gm_terms as $term) {
                    $author_name = '';
                    if ($term->global) {
                        if ($gmCore->caps['gmedia_edit_others_media']) {
                            $author_name .= ' &nbsp; ' . sprintf(__('by %s', 'grand-media'), get_the_author_meta('display_name', $term->global));
                        }
                    } else {
                        $author_name .= ' &nbsp; (' . __('shared', 'grand-media') . ')';
                    }
                    if ('publish' != $term->status) {
                        $author_name .= ' [' . $term->status . ']';
                    }
                    $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";
                }
            }
            ?>
                <div class="form-group">
                    <label><?php 
            _e('Move to Album', 'grand-media');
            ?>
 </label>
                    <select id="combobox_gmedia_album" name="alb" class="form-control" placeholder="<?php 
            _e('Album Name...', 'grand-media');
            ?>
">
                        <option></option>
                        <option value="0"><?php 
            _e('No Album', 'grand-media');
            ?>
</option>
                        <?php 
            echo $terms_album;
            ?>
                    </select>
                    <small class="help-block" style="margin-top:0;"><?php 
            _e('Choose "No Album" to delete albums from selected items', 'grand-media');
            ?>
</small>
                </div>
                <div class="form-group">
                    <div class="checkbox">
                        <label><input type="checkbox" name="status_global" value="1" checked> <?php 
            _e('Make status of selected items be the same as Album status', 'grand-media');
            ?>
                        </label></div>
                </div>
                <script type="text/javascript">
                    jQuery(function($) {
                        var albums = $('#combobox_gmedia_album');
                        var albums_data = $('option', albums);
                        //noinspection JSDuplicatedDeclaration
                        albums.selectize({
                            <?php 
            if ($gmCore->caps['gmedia_album_manage']) {
                ?>
                            create: function(input) {
                                return {
                                    value: input,
                                    text: input
                                }
                            },
                            createOnBlur: true,
                            <?php 
            } else {
                ?>
                            create: false,
                            <?php 
            }
            ?>
                            persist: false,
                            render: {
                                item: function(item, escape) {
                                    if(0 === (parseInt(item.value, 10) || 0)) {
                                        return '<div>' + escape(item.text) + '</div>';
                                    }
                                    if(item.$order) {
                                        var data = $(albums_data[item.$order]).data();
                                        return '<div>' + escape(data.name) + ' <small>' + escape(data.meta) + '</small></div>';
                                    }
                                },
                                option: function(item, escape) {
                                    if(0 === (parseInt(item.value) || 0)) {
                                        return '<div>' + escape(item.text) + '</div>';
                                    }
                                    if(item.$order) {
                                        var data = $(albums_data[item.$order]).data();
                                        return '<div>' + escape(data.name) + ' <small>' + escape(data.meta) + '</small>' + ' <span class="badge pull-right">' + escape(data.count) + '</span></div>';
                                    }
                                }
                            }

                        });
                    });
                </script>
            <?php 
            break;
        case 'exclude_categories':
        case 'filter_categories':
            $gm_terms = $gmDB->get_terms('gmedia_category');
            ?>
                <div class="checkbox"><label><input type="checkbox" name="cat[]" value="0"> <?php 
            _e('Uncategorized', 'grand-media');
            ?>
</label></div>
                <?php 
            if (count($gm_terms)) {
                foreach ($gm_terms as $term) {
                    if ($term->count) {
                        ?>
                <div class="checkbox">
                    <label><input type="checkbox" name="cat[]" value="<?php 
                        echo $term->term_id;
                        ?>
"> <?php 
                        echo esc_html($term->name);
                        ?>
</label>
                    <span class="badge pull-right"><?php 
                        echo $term->count;
                        ?>
</span>
                </div>
            <?php 
                    }
                }
            }
            break;
        case 'assign_category':
            $gm_terms = $gmDB->get_terms('gmedia_category', array('fields' => 'names_count'));
            $gm_terms = array_values($gm_terms);
            ?>
                <div class="form-group">
                    <input id="combobox_gmedia_category" name="cat_names" class="form-control input-sm" value="" placeholder="<?php 
            _e('Add to Categories...', 'grand-media');
            ?>
"/>
                </div>
                <script type="text/javascript">
                    jQuery(function($) {
                        var gm_terms = <?php 
            echo json_encode($gm_terms);
            ?>
;
                        //noinspection JSUnusedAssignment
                        var items = gm_terms.map(function(x) {
                            //noinspection JSUnresolvedVariable
                            return {id: x.term_id, name: x.name, count: x.count};
                        });
                        //noinspection JSDuplicatedDeclaration
                        $('#combobox_gmedia_category').selectize({
                            delimiter: ',',
                            maxItems: null,
                            openOnFocus: true,
                            labelField: 'name',
                            hideSelected: true,
                            options: items,
                            searchField: ['name'],
                            valueField: 'name',
                            persist: false,
                            <?php 
            if ($gmCore->caps['gmedia_category_manage']) {
                ?>
                            createOnBlur: true,
                            create: function(input) {
                                return {
                                    name: input
                                }
                            },
                            <?php 
            } else {
                ?>
                            create: false,
                            <?php 
            }
            ?>
                            render: {
                                item: function(item, escape) {
                                    return '<div>' + escape(item.name) + '</div>';
                                },
                                option: function(item, escape) {
                                    return '<div>' + escape(item.name) + ' <span class="badge">' + escape(item.count) + '</span></div>';
                                }
                            }
                        });
                    });
                </script>
            <?php 
            break;
        case 'unassign_category':
            // get selected items in Gmedia Library
            $selected_items = !empty($ckey) ? array_filter(explode('.', $_COOKIE[$ckey]), 'is_numeric') : false;
            if (!empty($selected_items)) {
                $gm_terms = $gmDB->get_gmedia_terms($selected_items, 'gmedia_category');
            }
            if (count($gm_terms)) {
                foreach ($gm_terms as $term) {
                    ?>
                <div class="checkbox">
                    <label><input type="checkbox" name="category_id[]" value="<?php 
                    echo $term->term_id;
                    ?>
"> <?php 
                    echo esc_html($term->name);
                    ?>
</label>
                    <span class="badge pull-right"><?php 
                    echo $term->count;
                    ?>
</span>
                </div>
                <?php 
                }
            } else {
                $modal_button = false;
                ?>
                <p class="noterms"><?php 
                _e('No categories', 'grand-media');
                ?>
</p>
            <?php 
            }
            break;
        case 'exclude_tags':
        case 'filter_tags':
            $gm_terms = $gmDB->get_terms('gmedia_tag', array('fields' => 'names_count'));
            $gm_terms = array_values($gm_terms);
            if (count($gm_terms)) {
                ?>
                <div class="form-group">
                    <input id="combobox_gmedia_tag" name="tag_ids" class="form-control input-sm" value="" placeholder="<?php 
                _e('Filter Tags...', 'grand-media');
                ?>
"/></div>
                <script type="text/javascript">
                    jQuery(function($) {
                        var gm_terms = <?php 
                echo json_encode($gm_terms);
                ?>
;
                        //noinspection JSUnusedAssignment
                        var items = gm_terms.map(function(x) {
                            //noinspection JSUnresolvedVariable
                            return {id: x.term_id, name: x.name, count: x.count};
                        });
                        $('#combobox_gmedia_tag').selectize({
                            delimiter: ',',
                            maxItems: null,
                            openOnFocus: true,
                            labelField: 'name',
                            hideSelected: true,
                            options: items,
                            searchField: ['name'],
                            valueField: 'id',
                            create: false,
                            render: {
                                item: function(item, escape) {
                                    return '<div>' + escape(item.name) + '</div>';
                                },
                                option: function(item, escape) {
                                    return '<div>' + escape(item.name) + ' <span class="badge">' + escape(item.count) + '</span></div>';
                                }
                            }
                        });
                    });
                </script>
            <?php 
            } else {
                $modal_button = false;
                ?>
                <p class="noterms"><?php 
                _e('No tags', 'grand-media');
                ?>
</p>
            <?php 
            }
            break;
        case 'add_tags':
            $gm_terms = $gmDB->get_terms('gmedia_tag', array('fields' => 'names_count'));
            $gm_terms = array_values($gm_terms);
            ?>
                <div class="form-group">
                    <input id="combobox_gmedia_tag" name="tag_names" class="form-control input-sm" value="" placeholder="<?php 
            _e('Add Tags...', 'grand-media');
            ?>
"/>
                </div>
                <div class="checkbox">
                    <label><input type="checkbox" name="iptc_tags" value="1"> <?php 
            _e('Import IPTC Keywords from selected images to Tags');
            ?>
</label>
                </div>
                <script type="text/javascript">
                    jQuery(function($) {
                        var gm_terms = <?php 
            echo json_encode($gm_terms);
            ?>
;
                        //noinspection JSUnusedAssignment
                        var items = gm_terms.map(function(x) {
                            //noinspection JSUnresolvedVariable
                            return {id: x.term_id, name: x.name, count: x.count};
                        });
                        //noinspection JSDuplicatedDeclaration
                        $('#combobox_gmedia_tag').selectize({
                            delimiter: ',',
                            maxItems: null,
                            openOnFocus: true,
                            labelField: 'name',
                            hideSelected: true,
                            options: items,
                            searchField: ['name'],
                            valueField: 'name',
                            persist: false,
                            <?php 
            if ($gmCore->caps['gmedia_tag_manage']) {
                ?>
                            createOnBlur: true,
                            create: function(input) {
                                return {
                                    name: input
                                }
                            },
                            <?php 
            } else {
                ?>
                            create: false,
                            <?php 
            }
            ?>
                            render: {
                                item: function(item, escape) {
                                    return '<div>' + escape(item.name) + '</div>';
                                },
                                option: function(item, escape) {
                                    return '<div>' + escape(item.name) + ' <span class="badge">' + escape(item.count) + '</span></div>';
                                }
                            }
                        });
                    });
                </script>
            <?php 
            break;
        case 'delete_tags':
            // get selected items in Gmedia Library
            $selected_items = !empty($ckey) ? array_filter(explode('.', $_COOKIE[$ckey]), 'is_numeric') : false;
            if (!empty($selected_items)) {
                $gm_terms = $gmDB->get_gmedia_terms($selected_items, 'gmedia_tag');
            }
            if (count($gm_terms)) {
                foreach ($gm_terms as $term) {
                    ?>
                <div class="checkbox">
                    <label><input type="checkbox" name="tag_id[]" value="<?php 
                    echo $term->term_id;
                    ?>
"> <?php 
                    echo esc_html($term->name);
                    ?>
</label>
                    <span class="badge pull-right"><?php 
                    echo $term->count;
                    ?>
</span>
                </div>
                <?php 
                }
            } else {
                $modal_button = false;
                ?>
                <p class="noterms"><?php 
                _e('No tags', 'grand-media');
                ?>
</p>
            <?php 
            }
            break;
        case 'filter_author':
        case 'select_author':
            if ($gmCore->caps['gmedia_show_others_media']) {
                ?>
                <div class="form-group">
                    <label><?php 
                _e('Choose Author', 'grand-media');
                ?>
</label>
                    <?php 
                $user_ids = $gmCore->get_editable_user_ids();
                if ($user_ids) {
                    if (!in_array($user_ID, $user_ids)) {
                        array_push($user_ids, $user_ID);
                    }
                    wp_dropdown_users(array('show_option_all' => ' &#8212; ', 'include' => $user_ids, 'include_selected' => true, 'name' => 'author_ids', 'selected' => $user_ID, 'class' => 'form-control'));
                } else {
                    echo '<div>' . get_the_author_meta('display_name', $user_ID) . '</div>';
                }
                ?>
                </div>
            <?php 
            } else {
                echo '<p>' . __('You are not allowed to see others media') . '</p>';
                echo '<p><strong>' . get_the_author_meta('display_name', $user_ID) . '</strong></p>';
            }
            break;
        case 'batch_edit':
            ?>
                <p><?php 
            _e('Note, data will be saved to all selected items in Gmedia Library.');
            ?>
</p>
                <div class="form-group">
                    <label><?php 
            _e('Filename', 'grand-media');
            ?>
</label>
                    <select class="form-control input-sm batch_set" name="batch_filename">
                        <option value=""><?php 
            _e('Skip. Do not change', 'grand-media');
            ?>
</option>
                        <option value="custom"><?php 
            _e('Custom', 'grand-media');
            ?>
</option>
                    </select>

                    <div class="batch_set_custom" style="margin-top:5px;display:none;">
                        <input class="form-control input-sm" name="batch_filename_custom" value="" placeholder="<?php 
            echo 'newname_{id}';
            ?>
"/>

                        <div><?php 
            _e('Variables: <b>{filename}</b> - original file name; <b>{id}</b> - Gmedia #ID in database; <b>{index:001}</b> - index of selected file in order you select (set start number after colon).');
            ?>
</div>
                    </div>
                </div>
                <div class="form-group">
                    <label><?php 
            _e('Title', 'grand-media');
            ?>
</label>
                    <select class="form-control input-sm batch_set" name="batch_title">
                        <option value=""><?php 
            _e('Skip. Do not change', 'grand-media');
            ?>
</option>
                        <option value="empty"><?php 
            _e('Empty Title', 'grand-media');
            ?>
</option>
                        <option value="filename"><?php 
            _e('From Filename', 'grand-media');
            ?>
</option>
                        <option value="custom"><?php 
            _e('Custom', 'grand-media');
            ?>
</option>
                    </select>
                    <input class="form-control input-sm batch_set_custom" style="margin-top:5px;display:none;" name="batch_title_custom" value="" placeholder="<?php 
            _e('Enter custom title here', 'grand-media');
            ?>
"/>
                </div>
                <div class="form-group">
                    <label><?php 
            _e('Description', 'grand-media');
            ?>
</label>
                    <select class="form-control input-sm batch_set" name="batch_description">
                        <option value=""><?php 
            _e('Skip. Do not change', 'grand-media');
            ?>
</option>
                        <option value="metadata"><?php 
            _e('Add MetaInfo to Description', 'grand-media');
            ?>
</option>
                        <option value="empty"><?php 
            _e('Empty Description', 'grand-media');
            ?>
</option>
                        <option value="custom"><?php 
            _e('Custom', 'grand-media');
            ?>
</option>
                    </select>

                    <div class="batch_set_custom" style="margin-top:5px;display:none;">
                        <select class="form-control input-sm" name="what_description_custom" style="margin-bottom:5px;">
                            <option value="replace"><?php 
            _e('Replace', 'grand-media');
            ?>
</option>
                            <option value="append"><?php 
            _e('Append', 'grand-media');
            ?>
</option>
                            <option value="prepend"><?php 
            _e('Prepend', 'grand-media');
            ?>
</option>
                        </select>
                        <textarea class="form-control input-sm" cols="30" rows="3" name="batch_description_custom" placeholder="<?php 
            _e('Enter description here', 'grand-media');
            ?>
"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label><?php 
            _e('Link', 'grand-media');
            ?>
</label>
                    <select class="form-control input-sm batch_set" name="batch_link">
                        <option value=""><?php 
            _e('Skip. Do not change', 'grand-media');
            ?>
</option>
                        <option value="empty"><?php 
            _e('Empty Link', 'grand-media');
            ?>
</option>
                        <option value="self"><?php 
            _e('Link to original file', 'grand-media');
            ?>
</option>
                        <option value="custom"><?php 
            _e('Custom', 'grand-media');
            ?>
</option>
                    </select>
                    <input class="form-control input-sm batch_set_custom" style="margin-top:5px;display:none;" name="batch_link_custom" value="" placeholder="<?php 
            _e('Enter url here');
            ?>
"/>
                </div>
                <div class="form-group">
                    <label><?php 
            _e('Status', 'grand-media');
            ?>
</label>
                    <select class="form-control input-sm batch_set" name="batch_status">
                        <option value=""><?php 
            _e('Skip. Do not change', 'grand-media');
            ?>
</option>
                        <option value="publish"><?php 
            _e('Public', 'grand-media');
            ?>
</option>
                        <option value="private"><?php 
            _e('Private', 'grand-media');
            ?>
</option>
                        <option value="draft"><?php 
            _e('Draft', 'grand-media');
            ?>
</option>
                    </select>
                </div>
                <div class="form-group">
                    <label><?php 
            _e('Comment Status', 'grand-media');
            ?>
</label>
                    <select class="form-control input-sm batch_set" name="batch_comment_status">
                        <option value=""><?php 
            _e('Skip. Do not change', 'grand-media');
            ?>
</option>
                        <option value="open"><?php 
            _e('Open', 'grand-media');
            ?>
</option>
                        <option value="closed"><?php 
            _e('Closed', 'grand-media');
            ?>
</option>
                    </select>
                </div>
            <?php 
            $user_ids = current_user_can('gmedia_delete_others_media') ? $gmCore->get_editable_user_ids() : false;
            if ($user_ids) {
                if (!in_array($user_ID, $user_ids)) {
                    array_push($user_ids, $user_ID);
                }
                ?>
                <div class="form-group">
                    <label><?php 
                _e('Author', 'grand-media');
                ?>
</label>
                    <?php 
                wp_dropdown_users(array('show_option_none' => __('Skip. Do not change', 'grand-media'), 'include' => $user_ids, 'include_selected' => true, 'name' => 'batch_author', 'selected' => -1, 'class' => 'input-sm form-control'));
                ?>
                </div>
            <?php 
            }
            ?>
                <script type="text/javascript">
                    jQuery(function($) {
                        $('select.batch_set').change(function() {
                            if('custom' == $(this).val()) {
                                $(this).next().css({display: 'block'});
                            } else {
                                $(this).next().css({display: 'none'});
                            }
                        });
                    });
                </script>
                <?php 
            break;
        default:
            _e('Ops! Something wrong.', 'grand-media');
            break;
    }
    ?>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal"><?php 
    _e('Cancel', 'grand-media');
    ?>
</button>
            <?php 
    if ($modal_button) {
        ?>
                <input type="hidden" name="<?php 
        echo $modal;
        ?>
"/>
                <button type="button" onclick="jQuery('#ajax-modal-form').submit()" class="btn <?php 
        echo $button_class;
        ?>
"><?php 
        echo $modal_button;
        ?>
</button>
                <?php 
    }
    wp_nonce_field('gmedia_action');
    ?>
        </div>
    </form><!-- /.modal-content -->
    <?php 
    die;
}
Esempio n. 3
0
 /**
  * @param null $modules
  */
 function modules_update($modules = null)
 {
     $wp_installing = (bool) (defined('WP_INSTALLING') && WP_INSTALLING);
     if ($wp_installing) {
         return;
     }
     if (!is_array($modules)) {
         $modules = get_gmedia_modules();
     }
     if (isset($modules['error'])) {
         return;
     }
     global $gmGallery;
     $modules_update_count = 0;
     foreach ($modules['in'] as $module) {
         if (!empty($module['update']) && 'remote' != $module['place']) {
             $modules_update_count++;
         }
     }
     $gmGallery->options = get_option('gmediaOptions');
     $gmGallery->options['modules_update'] = $modules_update_count;
     update_option('gmediaOptions', $gmGallery->options);
 }
Esempio n. 4
0
_e('Module/Preset', 'grand-media');
?>
</label>
                        <select class="form-control input-sm" id="term_module_preset" name="term[meta][_module_preset]">
                            <option value=""<?php 
if (empty($term->meta['_module_preset'][0])) {
    echo ' selected="selected"';
}
?>
><?php 
_e('Default module in Global Settings', 'grand-media');
?>
</option>
                            <?php 
global $gmDB, $user_ID, $gmGallery;
$gmedia_modules = get_gmedia_modules(false);
foreach ($gmedia_modules['in'] as $mfold => $module) {
    echo '<optgroup label="' . esc_attr($module['title']) . '">';
    $presets = $gmDB->get_terms('gmedia_module', array('status' => $mfold));
    $selected = selected($_module_preset, esc_attr($mfold), false);
    $option = array();
    $option[] = '<option ' . $selected . ' value="' . esc_attr($mfold) . '">' . $module['title'] . ' - ' . __('Default Settings') . '</option>';
    foreach ($presets as $preset) {
        if (!(int) $preset->global && '[' . $mfold . ']' === $preset->name) {
            continue;
        }
        $selected = selected($_module_preset, $preset->term_id, false);
        $by_author = '';
        if ((int) $preset->global) {
            $by_author = ' [' . get_the_author_meta('display_name', $preset->global) . ']';
        }
 protected function processor()
 {
     global $gmDB, $gmCore, $gmGallery, $user_ID;
     if (!$gmCore->caps['gmedia_gallery_manage']) {
         wp_die(__('You are not allowed to manage gmedia galleries', 'grand-media'));
     }
     if (!$gmCore->caps['gmedia_module_manage']) {
         wp_die(__('You are not allowed to manage gmedia modules', 'grand-media'));
     }
     include_once GMEDIA_ABSPATH . 'admin/pages/modules/functions.php';
     if (isset($_POST['module_preset_save']) || isset($_POST['module_preset_save_default']) || isset($_POST['module_preset_save_global'])) {
         check_admin_referer('GmediaGallery');
         if (isset($_POST['preview_bgcolor'])) {
             $gmGallery->options['preview_bgcolor'] = $gmCore->sanitize_hex_color($_POST['preview_bgcolor'], 'ffffff');
             update_option('gmediaOptions', $gmGallery->options);
         }
         $edit_preset = (int) $gmCore->_get('preset');
         do {
             $term = $gmCore->_post('term');
             if (isset($term['query'])) {
                 wp_parse_str($term['query'], $_query);
                 update_user_option($user_ID, 'gmedia_preset_demo_query_args', $_query);
             }
             if ((int) $term['global'] != $user_ID && !$gmCore->caps['gmedia_edit_others_media']) {
                 $this->error[] = __('You are not allowed to edit others media', 'grand-media');
                 break;
             }
             if (empty($term['module'])) {
                 $this->error[] = __('Something goes wrong... Choose module, please', 'grand-media');
                 break;
             }
             $taxonomy = 'gmedia_module';
             if (isset($_POST['module_preset_save_default']) || isset($_POST['module_preset_save_global'])) {
                 $term['name'] = '[' . $term['module'] . ']';
                 if (current_user_can('manage_options') && isset($_POST['module_preset_save_global'])) {
                     $term['global'] = '0';
                 }
                 $edit_preset = $term['term_id'] = $gmDB->term_exists($term['name'], $taxonomy, $term['global']);
             } else {
                 $term['name'] = trim($term['name']);
                 if (empty($term['name'])) {
                     $term['name'] = current_time('mysql');
                 }
                 if ($gmCore->is_digit($term['name'])) {
                     $this->error[] = __("Preset name can't be only digits", 'grand-media');
                     break;
                 }
                 $term['name'] = '[' . $term['module'] . '] ' . $term['name'];
                 if ($edit_preset && !$gmDB->term_exists($edit_preset)) {
                     $this->error[] = __('A term with the id provided does not exists', 'grand-media');
                     $edit_preset = false;
                 }
                 if ($term_id = $gmDB->term_exists($term['name'], $taxonomy, $term['global'])) {
                     if ($term_id != $edit_preset) {
                         $this->error[] = __('A term with the name provided already exists', 'grand-media');
                         break;
                     }
                 }
             }
             $module_settings = $gmCore->_post('module', array());
             $module_path = $gmCore->get_module_path($term['module']);
             $default_options = array();
             if (is_file($module_path['path'] . '/settings.php')) {
                 /** @noinspection PhpIncludeInspection */
                 include $module_path['path'] . '/settings.php';
             } else {
                 $this->error[] = sprintf(__('Can\'t load data from `%s` module'), $term['module']);
                 break;
             }
             $term['description'] = $gmCore->array_replace_recursive($default_options, $module_settings);
             $term['status'] = $term['module'];
             if ($edit_preset) {
                 $term_id = $gmDB->update_term($edit_preset, $term);
             } else {
                 $term_id = $gmDB->insert_term($term['name'], $taxonomy, $term);
             }
             if (is_wp_error($term_id)) {
                 $this->error[] = $term_id->get_error_message();
                 break;
             }
             if ($edit_preset) {
                 $this->msg[] = sprintf(__('Preset #%d successfuly saved', 'grand-media'), $term_id);
             } else {
                 $location = add_query_arg(array('preset' => $term_id, 'message' => 'save'), $this->url);
                 set_transient('gmedia_new_preset_id', $term_id, 60);
                 wp_redirect($location);
                 exit;
             }
         } while (0);
     }
     if ('save' == $gmCore->_get('message') && ($term_id = $gmCore->_get('preset'))) {
         $gmedia_new_preset_id = get_transient('gmedia_new_preset_id');
         if (false !== $gmedia_new_preset_id) {
             delete_transient('gmedia_new_preset_id');
             $this->msg[] = sprintf(__('Preset #%d successfuly saved', 'grand-media'), $term_id);
         }
     }
     if (isset($_FILES['modulezip']['tmp_name'])) {
         if (!empty($_FILES['modulezip']['tmp_name'])) {
             check_admin_referer('GmediaModule');
             if (!current_user_can('manage_options')) {
                 wp_die(__('You are not allowed to install module ZIP', 'grand-media'));
             }
             $to_folder = $gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/';
             if (!wp_mkdir_p($to_folder)) {
                 $this->error[] = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'grand-media'), $to_folder);
                 return;
             }
             if (!is_writable($to_folder)) {
                 @chmod($to_folder, 0755);
                 if (!is_writable($to_folder)) {
                     //@unlink( $_FILES['modulezip']['tmp_name'] );
                     $this->error[] = sprintf(__('Directory %s is not writable by the server.', 'grand-media'), $to_folder);
                     return;
                 }
             }
             $filename = wp_unique_filename($to_folder, $_FILES['modulezip']['name']);
             // Move the file to the modules dir
             if (false === @move_uploaded_file($_FILES['modulezip']['tmp_name'], $to_folder . $filename)) {
                 $this->error[] = sprintf(__('The uploaded file could not be moved to %s', 'flag'), $to_folder . $filename);
             } else {
                 global $wp_filesystem;
                 // Is a filesystem accessor setup?
                 if (!$wp_filesystem || !is_object($wp_filesystem)) {
                     require_once ABSPATH . 'wp-admin/includes/file.php';
                     WP_Filesystem();
                 }
                 if (!is_object($wp_filesystem)) {
                     $result = new WP_Error('fs_unavailable', __('Could not access filesystem.', 'flag'));
                 } elseif ($wp_filesystem->errors->get_error_code()) {
                     $result = new WP_Error('fs_error', __('Filesystem error', 'flag'), $wp_filesystem->errors);
                 } else {
                     $maybe_folder_dir = basename($_FILES['modulezip']['name'], '.zip');
                     $maybe_folder_dir = sanitize_file_name($maybe_folder_dir);
                     if ($maybe_folder_dir && is_dir($to_folder . $maybe_folder_dir)) {
                         $gmCore->delete_folder($to_folder . $maybe_folder_dir);
                     }
                     $result = unzip_file($to_folder . $filename, $to_folder);
                 }
                 // Once extracted, delete the package
                 unlink($to_folder . $filename);
                 if (is_wp_error($result)) {
                     $this->error[] = $result->get_error_message();
                 } else {
                     $this->msg[] = sprintf(__("The `%s` file unzipped to module's directory", 'flag'), $filename);
                 }
             }
         } else {
             $this->error[] = __('No file specified', 'grand-media');
         }
     }
     if (isset($_GET['delete_module'])) {
         if ($gmCore->_get('_wpnonce')) {
             $mfold = preg_replace('/[^a-z0-9_-]+/i', '_', $_GET['delete_module']);
             $mpath = "{$gmCore->upload['path']}/{$gmGallery->options['folder']['module']}/{$mfold}";
             if ($mfold && file_exists($mpath)) {
                 check_admin_referer('gmedia_module_delete');
                 $gmCore->delete_folder($mpath);
                 $location = remove_query_arg(array('_wpnonce'));
                 set_transient('gmedia_module_deleted', sprintf(__("The `%s` module folder was deleted", 'flag'), $mpath), 60);
                 wp_redirect($location);
             }
         } elseif (false !== ($message = get_transient('gmedia_module_deleted'))) {
             delete_transient('gmedia_module_deleted');
             $this->msg[] = $message;
         }
     }
     $this->modules = get_gmedia_modules();
     wp_clear_scheduled_hook('gmedia_modules_update');
     wp_schedule_event(time(), 'daily', 'gmedia_modules_update');
     $gmCore->modules_update($this->modules);
 }