| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; /* Exit if accessed directly */ |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Plugin Name: Filter Gallery - 0.1.9 |
| 8 |
* Plugin URI: https://wpfrank.com/ |
| 9 |
* Description: Create portfolio gallery on website with responsive layout and fiters |
| 10 |
* Version: 0.1.9 |
| 11 |
* Requires at least: 4.0 |
| 12 |
* Requires PHP: 4.0 |
| 13 |
* Author: FARAZFRANK |
| 14 |
* Author URI: https://profiles.wordpress.org/farazfrank/ |
| 15 |
* License: GPL v2 or later |
| 16 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 17 |
* Text Domain: filter-gallery |
| 18 |
* Domain Path: /languages |
| 19 |
|
| 20 |
Filter Gallery is free software: you can redistribute it and/or modify |
| 21 |
it under the terms of the GNU General Public License as published by |
| 22 |
the Free Software Foundation, either version 2 of the License, or |
| 23 |
any later version. |
| 24 |
|
| 25 |
Filter Gallery is distributed in the hope that it will be useful, |
| 26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
GNU General Public License for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU General Public License |
| 31 |
along with Filter Gallery. If not, see https://wpfrank.com/. |
| 32 |
*/ |
| 33 |
|
| 34 |
// custom image size |
| 35 |
add_image_size( 'ufg_200_200', 200, 200, true ); |
| 36 |
add_image_size( 'ufg_300_300', 300, 300, true ); |
| 37 |
add_image_size( 'ufg_400_400', 400, 400, true ); |
| 38 |
|
| 39 |
/* FG activation */ |
| 40 |
function ufg_activation() { |
| 41 |
/* update current plugin version */ |
| 42 |
if ( is_admin() ) { |
| 43 |
if ( ! function_exists( 'get_plugin_data' ) ) { |
| 44 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 45 |
} |
| 46 |
$ufg_plugin_data = get_plugin_data( __FILE__ ); |
| 47 |
if ( isset( $ufg_plugin_data['Version'] ) ) { |
| 48 |
$ufg_plugin_version = $ufg_plugin_data['Version']; |
| 49 |
update_option( 'ufg_current_version', $ufg_plugin_version ); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
register_activation_hook( __FILE__, 'ufg_activation' ); |
| 54 |
|
| 55 |
// FG deactivation |
| 56 |
function ufg_deactivation(){ |
| 57 |
// update last active plugin version |
| 58 |
$ufg_last_version = get_option('ufg_current_version'); |
| 59 |
if($ufg_last_version !== ""){ |
| 60 |
update_option('ufg_last_version', $ufg_last_version); |
| 61 |
} |
| 62 |
} |
| 63 |
register_deactivation_hook( __FILE__, 'ufg_deactivation' ); |
| 64 |
|
| 65 |
// FG uninstall |
| 66 |
function ufg_uninstall(){ |
| 67 |
} |
| 68 |
register_uninstall_hook(__FILE__, 'ufg_uninstall'); |
| 69 |
|
| 70 |
// load translation |
| 71 |
function ufg_load_translation() { |
| 72 |
load_plugin_textdomain( 'filter-gallery', false, dirname( plugin_basename(__FILE__) ) .'/languages' ); |
| 73 |
} |
| 74 |
add_action( 'plugins_loaded', 'ufg_load_translation'); |
| 75 |
|
| 76 |
// FG menu |
| 77 |
function ufg_menu_page() { |
| 78 |
// add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); |
| 79 |
add_menu_page( |
| 80 |
__( 'Filter Gallery', 'filter-gallery' ), |
| 81 |
'Filter Gallery', |
| 82 |
'manage_options', |
| 83 |
'filter-gallery', |
| 84 |
'ufg_main', |
| 85 |
'dashicons-format-gallery', |
| 86 |
65 |
| 87 |
); |
| 88 |
|
| 89 |
//add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', int $position ) |
| 90 |
add_submenu_page( 'filter-gallery', 'Mange Gallery', 'Mange Gallery', 'manage_options', 'ufg-manage-gallery', 'ufg_manage_gallery' ); |
| 91 |
} |
| 92 |
add_action( 'admin_menu', 'ufg_menu_page' ); |
| 93 |
|
| 94 |
// FG main page body |
| 95 |
function ufg_main(){ |
| 96 |
require 'admin/galleries.php'; |
| 97 |
} |
| 98 |
|
| 99 |
// FG sub menu filters page body |
| 100 |
function ufg_manage_gallery(){ |
| 101 |
require 'admin/manage-gallery.php'; |
| 102 |
} |
| 103 |
|
| 104 |
//get / create next gallery id |
| 105 |
function ufg_get_next_id(){ |
| 106 |
global $wpdb; |
| 107 |
$ufg_gallery_key = "ufg_gallery_"; |
| 108 |
// reference : https://wordpress.stackexchange.com/questions/8825/how-do-you-properly-prepare-a-like-sql-statement |
| 109 |
$ufg_gallery_count_res = $wpdb->get_row( |
| 110 |
$wpdb->prepare("SELECT option_name FROM `$wpdb->options` WHERE `option_name` LIKE %s ORDER BY option_id DESC LIMIT 1", '%'.$ufg_gallery_key.'%'), ARRAY_N |
| 111 |
); |
| 112 |
|
| 113 |
if($wpdb->num_rows) { |
| 114 |
$ufg_gallery_last_key = $ufg_gallery_count_res[0]; |
| 115 |
$ufg_underscore_pos = strrpos($ufg_gallery_last_key, '_'); |
| 116 |
$ufg_last_slider_id = (int) substr($ufg_gallery_last_key, ($ufg_underscore_pos + 1)); |
| 117 |
return ($ufg_last_slider_id + 1); |
| 118 |
} else { |
| 119 |
return 1; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
// 1. save filters ajax |
| 124 |
function ufg_gallery_filters_callback(){ |
| 125 |
if ( current_user_can( 'manage_options' ) ) { |
| 126 |
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'add-filters' ) ) { |
| 127 |
// save filters |
| 128 |
//print_r($_POST); |
| 129 |
$filters = array(); |
| 130 |
$ufg_gallery_id = sanitize_text_field(($_POST['id'])); |
| 131 |
$ufg_gallery_name = sanitize_text_field($_POST['gallery_name']); |
| 132 |
$filters = json_decode(stripslashes($_POST['filters'])); |
| 133 |
|
| 134 |
/* echo "<pre>"; |
| 135 |
print_r($filters); |
| 136 |
echo "</pre>"; */ |
| 137 |
// making same name fitters unique start |
| 138 |
$counter = 1; |
| 139 |
if(is_array($filters) && $filters_count = count($filters)) { |
| 140 |
|
| 141 |
//unset the blank filters |
| 142 |
foreach($filters as $filters_key => $filters_value ){ |
| 143 |
$parent_filters = sanitize_text_field($filters[$filters_key]->title); |
| 144 |
$parent_filters_text = sanitize_text_field($filters[$filters_key]->text); // this will be unique all time |
| 145 |
if(strlen($parent_filters)){ |
| 146 |
// do nothing |
| 147 |
} else { |
| 148 |
unset($filters[$filters_key]); |
| 149 |
} |
| 150 |
} |
| 151 |
// array_values will recreate all filter index value in assanding order after unsetting blank filters |
| 152 |
$filters = array_values($filters); |
| 153 |
|
| 154 |
//make unique filters |
| 155 |
foreach($filters as $filters_key => $filters_value ){ |
| 156 |
$parent_filters = sanitize_text_field($filters[$filters_key]->title); |
| 157 |
$parent_filters_text = sanitize_text_field($filters[$filters_key]->text); // this will be unique all time |
| 158 |
//$filters[$filters_key]->title = $parent_filters."-".$filters_key; // it was adding key again and again |
| 159 |
|
| 160 |
// adding index value at the end of text to make it unique and same name filter can be possible |
| 161 |
$filters[$filters_key]->title = $parent_filters_text."-".$filters_key; |
| 162 |
} |
| 163 |
} |
| 164 |
/* echo "<pre>"; |
| 165 |
print_r($filters); |
| 166 |
echo "</pre>"; */ |
| 167 |
// making same name fitters unique end |
| 168 |
update_option("ufg_filters_".$ufg_gallery_id, $filters); |
| 169 |
|
| 170 |
$ufg_details = array('ufg_gallery_id' => $ufg_gallery_id, 'gallery_name' => $ufg_gallery_name); |
| 171 |
update_option("ufg_details_".$ufg_gallery_id, $ufg_details); |
| 172 |
} else { |
| 173 |
die; |
| 174 |
} |
| 175 |
die; |
| 176 |
} |
| 177 |
} |
| 178 |
add_action( 'wp_ajax_ufg_gallery_filters', 'ufg_gallery_filters_callback' ); |
| 179 |
|
| 180 |
// 2. add images to the gallery |
| 181 |
function ufg_li_generate_ajax_callback() { |
| 182 |
if ( isset($_POST['attachment_id']) && isset($_POST['ufg_gallery_id']) ) { |
| 183 |
wp_enqueue_script( 'ufg-uploader-js', plugins_url( 'assets/js/ufg-uploader.js', __FILE__ ), array('jquery'), '1.10.0' ); |
| 184 |
|
| 185 |
//defaults |
| 186 |
$ufg_title = $ufg_alt = $ufg_description = $ufg_url = ""; |
| 187 |
//load values |
| 188 |
$ufg_attachment_id = sanitize_text_field($_POST['attachment_id']); |
| 189 |
$ufg_title = get_the_title($ufg_attachment_id); |
| 190 |
$ufg_alt = get_post_meta($ufg_attachment_id, '_wp_attachment_image_alt', TRUE); |
| 191 |
//wp_get_attachment_image_src ( int $ufg_attachment_id, string|array $size = 'thumbnail', bool $icon = false ) |
| 192 |
//thumb, thumbnail, medium, large, post-thumbnail |
| 193 |
$medium = wp_get_attachment_image_src($ufg_attachment_id, 'medium', true); // attachment medium URL |
| 194 |
$attachment = get_post( $ufg_attachment_id ); |
| 195 |
$ufg_description = $attachment->post_content; // attachment description |
| 196 |
//get saved filters |
| 197 |
$ufg_gallery_id = sanitize_text_field($_POST['ufg_gallery_id']); |
| 198 |
$filters = get_option("ufg_filters_".$ufg_gallery_id); |
| 199 |
?> |
| 200 |
<script> |
| 201 |
jQuery(document).ready(function () { |
| 202 |
jQuery(function(jQuery) { |
| 203 |
jQuery('.ufg-image-filters').multiselect({ |
| 204 |
buttonWidth: '100%', |
| 205 |
enableFiltering: true, |
| 206 |
nonSelectedText: "<?php esc_html_e( 'Select Filters', 'filter-gallery' ); ?>" |
| 207 |
}); |
| 208 |
}); |
| 209 |
}); |
| 210 |
</script> |
| 211 |
<li class="col-md-2 border border-dark rounded-lg bg-light p-2 m-4 ufg-image-<?php echo esc_attr($ufg_attachment_id); ?>" data-position="<?php echo esc_attr($ufg_attachment_id); ?>"> |
| 212 |
<div class="form-group"> |
| 213 |
<input type="hidden" class="form-control ufg-attachment-id" id="ufg-attachment-id" name="ufg-attachment-id[<?php echo esc_attr($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_attachment_id); ?>"> |
| 214 |
<img src="<?php echo esc_url($medium[0]); ?>" class="card-img-top" width="150px" height="150px"> |
| 215 |
<span class="badge badge-primary">Image ID: <?php echo esc_attr($ufg_attachment_id); ?></span> |
| 216 |
</div> |
| 217 |
<div class="form-group"> |
| 218 |
<input type="text" class="form-control ufg-title" id="ufg-title" name="ufg-title[<?php echo esc_attr($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_title); ?>" placeholder="<?php esc_html_e( 'Image Title', 'filter-gallery' ); ?>"> |
| 219 |
</div> |
| 220 |
<div class="form-group"> |
| 221 |
<input type="text" class="form-control ufg-alt" id="ufg-alt" name="ufg-alt[<?php echo esc_attr($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_alt); ?>" placeholder="<?php esc_html_e( 'Image Alternative Text', 'filter-gallery' ); ?>"> |
| 222 |
</div> |
| 223 |
<div class="form-group"> |
| 224 |
<?php |
| 225 |
$ufg_get_filter_list_results = ufg_get_filter_list($ufg_attachment_id, $filters, array()); |
| 226 |
$ufg_get_filter_list_allowed = array( |
| 227 |
'select' => array( 'id' => array(), 'name' => array(), 'class' => array(), 'data-max' => array(), 'multiple' => array() ), |
| 228 |
'option' => array ( 'value' => array(), 'selected' => array()), |
| 229 |
); |
| 230 |
echo wp_kses($ufg_get_filter_list_results, $ufg_get_filter_list_allowed); |
| 231 |
?> |
| 232 |
</div> |
| 233 |
<div class="form-group text-center"> |
| 234 |
<button type="button" id="ufg-remove-image" onclick="return removeImage('<?php echo esc_attr($ufg_attachment_id); ?>');" class="btn btn-sm btn-danger"><?php esc_html_e( 'Remove', 'filter-gallery' ); ?></button> |
| 235 |
</div> |
| 236 |
</li> |
| 237 |
<?php |
| 238 |
wp_die(); // this is required to terminate immediately and return a proper response |
| 239 |
} |
| 240 |
} |
| 241 |
add_action( 'wp_ajax_ufg_image_id', 'ufg_li_generate_ajax_callback' ); |
| 242 |
|
| 243 |
// generate filter select list |
| 244 |
function ufg_get_filter_list($ufg_attachment_id, $filters, $selected_filters){ |
| 245 |
/* echo "<pre>"; |
| 246 |
print_r($filters); |
| 247 |
echo "</pre>"; */ |
| 248 |
|
| 249 |
/* echo "<pre>"; |
| 250 |
print_r($selected_filters); |
| 251 |
echo "</pre>"; */ |
| 252 |
|
| 253 |
$ufg_filters_list = ""; |
| 254 |
if(is_array($filters) && $filters_count = count($filters)) { |
| 255 |
$ufg_filters_list .= '<select id="ufg-image-filters" name="ufg-image-filters['.$ufg_attachment_id.'][]" class="ufg-image-filters" data-max="" multiple="multiple">'; |
| 256 |
$filters_count_end = 4; // for free |
| 257 |
if($filters_count < $filters_count_end) $filters_count_end = $filters_count; |
| 258 |
/* for($i = 0; $i <= $filters_count_end; $i++){ |
| 259 |
$text_zero = sanitize_text_field($filters[$i]->text); |
| 260 |
$value_zero = str_replace(" ","-", strtolower($filters[$i]->title)); |
| 261 |
if(in_array($value_zero, $selected_filters) === TRUE) $selected = "selected=selected"; else $selected = ""; |
| 262 |
if($text_zero != "") $ufg_filters_list .= "<option value='$value_zero' $selected>$text_zero</option>"; |
| 263 |
} */ |
| 264 |
foreach($filters as $filters_key => $filters_value){ |
| 265 |
$text_zero = sanitize_text_field($filters[$filters_key]->text); |
| 266 |
$value_zero = str_replace(" ","-", strtolower($filters[$filters_key]->title)); |
| 267 |
if(in_array($value_zero, $selected_filters) === TRUE) $selected = "selected=selected"; else $selected = ""; |
| 268 |
if($text_zero != "") $ufg_filters_list .= "<option value='$value_zero' $selected>$text_zero</option>"; |
| 269 |
} |
| 270 |
$ufg_filters_list .= '</select>'; |
| 271 |
return $ufg_filters_list; |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
// 3. save gallery images |
| 276 |
function ufg_save_gallery_callback(){ |
| 277 |
if ( current_user_can( 'manage_options' ) ) { |
| 278 |
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'save-gallery' ) ) { |
| 279 |
// defaults |
| 280 |
$ufg_gallery_id = sanitize_text_field($_POST['id']); |
| 281 |
$ufg_image_id = $ufg_image_title = $ufg_image_alt = $ufg_image_filters = $ufg_gallery = array(); |
| 282 |
|
| 283 |
/* echo "<pre>"; |
| 284 |
echo "posted <br>"; |
| 285 |
print_r($_POST['image_id']); |
| 286 |
echo "<hr>"; |
| 287 |
$ufg_image_id = $_POST['image_id']; |
| 288 |
|
| 289 |
echo "url decode <br>"; |
| 290 |
print_r($ufg_image_id = urldecode_deep($ufg_image_id)); |
| 291 |
echo "<hr>"; |
| 292 |
|
| 293 |
echo "parsed <br>"; |
| 294 |
parse_str($ufg_image_id, $ufg_image_id); |
| 295 |
print_r($ufg_image_id); |
| 296 |
echo "<hr>"; |
| 297 |
|
| 298 |
echo "sanitize <br>"; |
| 299 |
print_r(sanitize_text_field($ufg_image_id)); |
| 300 |
echo "</pre>"; */ |
| 301 |
|
| 302 |
// decode URL string and parse and sanitize |
| 303 |
sanitize_text_field(parse_str(urldecode_deep($_POST['image_id']), $ufg_image_id)); |
| 304 |
sanitize_text_field(parse_str(urldecode_deep($_POST['image_title']), $ufg_image_title)); |
| 305 |
sanitize_text_field(parse_str(urldecode_deep($_POST['image_alt']), $ufg_image_alt)); |
| 306 |
sanitize_text_field(parse_str(urldecode_deep($_POST['image_filters']), $ufg_image_filters)); |
| 307 |
|
| 308 |
// sanitize each array keys via array_map |
| 309 |
isset( $_POST['image_id'] ) ? (array) array_map('sanitize_text_field', $ufg_image_id) : array(); |
| 310 |
isset( $_POST['image_title'] ) ? (array) array_map('sanitize_text_field', $ufg_image_title) : array(); |
| 311 |
isset( $_POST['image_alt'] ) ? (array) array_map('sanitize_text_field', $ufg_image_alt) : array(); |
| 312 |
isset( $_POST['image_filters'] ) ? (array) array_map('sanitize_text_field', $ufg_image_filters) : array(); |
| 313 |
|
| 314 |
// save gallery |
| 315 |
//update attachment meta - title, alt, description |
| 316 |
$i = 0; |
| 317 |
if(is_array($ufg_image_id['ufg-attachment-id'])){ |
| 318 |
foreach($ufg_image_id['ufg-attachment-id'] as $ufg_id) { |
| 319 |
$ufg_title = $ufg_image_title['ufg-title'][$ufg_id]; |
| 320 |
$ufg_alt = $ufg_image_alt['ufg-alt'][$ufg_id]; |
| 321 |
$ufg_image_update = array( |
| 322 |
'ID' => $ufg_id, |
| 323 |
'post_title' => $ufg_title, |
| 324 |
); |
| 325 |
wp_update_post( $ufg_image_update ); |
| 326 |
update_post_meta( $ufg_id, '_wp_attachment_image_alt', sanitize_text_field( $ufg_alt ) ); |
| 327 |
$i++; |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
$ufg_gallery = array_merge($ufg_image_id, $ufg_image_title, $ufg_image_alt, $ufg_image_filters); |
| 332 |
update_option("ufg_gallery_".$ufg_gallery_id, $ufg_gallery); |
| 333 |
die; |
| 334 |
} else { |
| 335 |
die; |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
add_action( 'wp_ajax_ufg_save_gallery', 'ufg_save_gallery_callback' ); |
| 340 |
|
| 341 |
// 4. load gallery images |
| 342 |
function ufg_load_gallery_callback($ufg_gallery_id){ |
| 343 |
if ( current_user_can( 'manage_options' ) ) { |
| 344 |
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'load-gallery' ) ) { |
| 345 |
//get / create next gallery id |
| 346 |
if(isset($_POST['id'])){ |
| 347 |
$ufg_gallery_id = sanitize_text_field($_POST['id']); |
| 348 |
|
| 349 |
// load filters and gallery options |
| 350 |
$ufg_filters = get_option("ufg_filters_".$ufg_gallery_id); |
| 351 |
$ufg_gallery = get_option("ufg_gallery_".$ufg_gallery_id); |
| 352 |
|
| 353 |
/* echo "<pre>"; |
| 354 |
print_r($ufg_gallery); |
| 355 |
echo "</pre>"; */ |
| 356 |
|
| 357 |
//defaults |
| 358 |
$ufg_title = $ufg_alt = $ufg_description = $ufg_url = ""; |
| 359 |
if(is_array($ufg_gallery['ufg-attachment-id'])){ |
| 360 |
foreach($ufg_gallery['ufg-attachment-id'] as $key => $value){ |
| 361 |
$ufg_attachment_id = $key; |
| 362 |
//load values |
| 363 |
$ufg_title = get_the_title($ufg_attachment_id); |
| 364 |
$ufg_alt = get_post_meta($ufg_attachment_id, '_wp_attachment_image_alt', TRUE); |
| 365 |
//wp_get_attachment_image_src ( int $ufg_attachment_id, string|array $size = 'thumbnail', bool $icon = false ) |
| 366 |
//thumb, thumbnail, medium, large, post-thumbnail |
| 367 |
$medium = wp_get_attachment_image_src($ufg_attachment_id, 'medium', true); // attachment medium URL |
| 368 |
$attachment = get_post( $ufg_attachment_id ); |
| 369 |
$ufg_description = $attachment->post_content; // attachment description |
| 370 |
//get saved filters |
| 371 |
$filters = get_option("ufg_filters_".$ufg_gallery_id); |
| 372 |
?> |
| 373 |
<li class="col-md-2 border border-dark rounded-lg bg-light p-2 m-4 ufg-image-<?php echo esc_attr($ufg_attachment_id); ?>" data-position="<?php echo esc_attr($ufg_attachment_id); ?>"> |
| 374 |
<div class="form-group"> |
| 375 |
<input type="hidden" class="form-control ufg-attachment-id" id="ufg-attachment-id" name="ufg-attachment-id[<?php echo esc_attr($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_attachment_id); ?>"> |
| 376 |
<img src="<?php echo esc_url($medium[0]); ?>" class="card-img-top" width="150px" height="150px"> |
| 377 |
<span class="badge badge-primary">Image ID: <?php echo esc_attr($ufg_attachment_id); ?></span> |
| 378 |
</div> |
| 379 |
<div class="form-group"> |
| 380 |
<input type="text" class="form-control ufg-title" name="ufg-title[<?php echo esc_attr($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_title); ?>" placeholder="<?php esc_html_e( 'Image Title', 'filter-gallery' ); ?>"> |
| 381 |
</div> |
| 382 |
<div class="form-group"> |
| 383 |
<input type="text" class="form-control ufg-alt" name="ufg-alt[<?php echo esc_attr($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_alt); ?>" placeholder="<?php esc_html_e( 'Image Alternative Text', 'filter-gallery' ); ?>"> |
| 384 |
</div> |
| 385 |
<div class="form-group"> |
| 386 |
<?php |
| 387 |
if(isset($ufg_gallery['ufg-image-filters'][$key])) |
| 388 |
$selected_filters = $ufg_gallery['ufg-image-filters'][$key]; |
| 389 |
else |
| 390 |
$selected_filters = array(); |
| 391 |
?> |
| 392 |
<?php |
| 393 |
$ufg_get_filter_list_results = ufg_get_filter_list($ufg_attachment_id, $filters, $selected_filters); |
| 394 |
$ufg_get_filter_list_allowed = array( |
| 395 |
'select' => array( 'id' => array(), 'name' => array(), 'class' => array(), 'data-max' => array(), 'multiple' => array() ), |
| 396 |
'option' => array ( 'value' => array(), 'selected' => array()), |
| 397 |
); |
| 398 |
echo wp_kses($ufg_get_filter_list_results, $ufg_get_filter_list_allowed); |
| 399 |
?> |
| 400 |
</div> |
| 401 |
<div class="form-group text-center"> |
| 402 |
<button type="button" id="ufg-remove-image" onclick="return removeImage('<?php echo esc_attr($ufg_attachment_id); ?>');" class="btn btn-sm btn-danger"><?php esc_html_e( 'Remove', 'filter-gallery' ); ?></button> |
| 403 |
</div> |
| 404 |
</li> |
| 405 |
<?php |
| 406 |
} |
| 407 |
} |
| 408 |
?> |
| 409 |
<script> |
| 410 |
jQuery(document).ready(function () { |
| 411 |
jQuery(function(jQuery) { |
| 412 |
jQuery('.ufg-image-filters').multiselect ({ |
| 413 |
buttonWidth: '100%', |
| 414 |
enableFiltering: true, |
| 415 |
nonSelectedText: "<?php esc_html_e( 'Select Filters', 'filter-gallery' ); ?>", |
| 416 |
}); |
| 417 |
}); |
| 418 |
}); |
| 419 |
</script> |
| 420 |
<?php |
| 421 |
die; |
| 422 |
} |
| 423 |
} else { |
| 424 |
die; |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
add_action( 'wp_ajax_ufg_load_gallery', 'ufg_load_gallery_callback' ); |
| 429 |
|
| 430 |
|
| 431 |
// 5. save gallery settings |
| 432 |
function ufg_save_setting_callback(){ |
| 433 |
if ( current_user_can( 'manage_options' ) ) { |
| 434 |
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'save-setting' ) ) { |
| 435 |
$ufg_gallery_id = sanitize_text_field($_POST['ufg_gallery_id']); |
| 436 |
$settings = array( |
| 437 |
//gallery details |
| 438 |
'ufg_gallery_id' => sanitize_text_field($_POST['ufg_gallery_id']), |
| 439 |
|
| 440 |
//filters settings |
| 441 |
'show_filters' => sanitize_text_field($_POST['show_filters']), |
| 442 |
'show_all_button' => sanitize_text_field($_POST['show_all_button']), |
| 443 |
'all_button_text' => sanitize_text_field($_POST['all_button_text']), |
| 444 |
'all_button_color' => sanitize_text_field($_POST['all_button_color']), |
| 445 |
'all_button_bg_color' => sanitize_text_field($_POST['all_button_bg_color']), |
| 446 |
'parent_button_color' => sanitize_text_field($_POST['parent_button_color']), |
| 447 |
'parent_button_bg_color' => sanitize_text_field($_POST['parent_button_bg_color']), |
| 448 |
|
| 449 |
//gallery settings |
| 450 |
'columns_desktop' => sanitize_text_field($_POST['columns_desktop']), |
| 451 |
'columns_tab' => sanitize_text_field($_POST['columns_tab']), |
| 452 |
'columns_mobile_landscape' => sanitize_text_field($_POST['columns_mobile_landscape']), |
| 453 |
'columns_mobile_portrait' => sanitize_text_field($_POST['columns_mobile_portrait']), |
| 454 |
'thumbnail_image_size' => sanitize_text_field($_POST['thumbnail_image_size']), |
| 455 |
'thumbnail_border' => sanitize_text_field($_POST['thumbnail_border']), |
| 456 |
'thumbnail_border_thickness' => sanitize_text_field($_POST['thumbnail_border_thickness']), |
| 457 |
'thumbnail_border_color' => sanitize_text_field($_POST['thumbnail_border_color']), |
| 458 |
'image_title' => sanitize_text_field($_POST['image_title']), |
| 459 |
'image_title_font_size' => sanitize_text_field($_POST['image_title_font_size']), |
| 460 |
'image_title_color' => sanitize_text_field($_POST['image_title_color']), |
| 461 |
'image_title_bg_color' => sanitize_text_field($_POST['image_title_bg_color']), |
| 462 |
'image_sorting' => sanitize_text_field($_POST['image_sorting']), |
| 463 |
'custom_css' => sanitize_text_field($_POST['custom_css']), |
| 464 |
|
| 465 |
//lightbox settings |
| 466 |
'lightbox' => sanitize_text_field($_POST['lightbox']), |
| 467 |
'lightbox_title' => sanitize_text_field($_POST['lightbox_title']), |
| 468 |
); |
| 469 |
update_option("ufg_settings_".$ufg_gallery_id, $settings); |
| 470 |
die; |
| 471 |
} else { |
| 472 |
die; |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
add_action( 'wp_ajax_ufg_save_setting', 'ufg_save_setting_callback' ); |
| 477 |
|
| 478 |
/* 6. remove gallery/galleries start */ |
| 479 |
function ufg_remove_gallery_callback() { |
| 480 |
if ( current_user_can( 'manage_options' ) ) { |
| 481 |
if ( $_POST['nonce'] && wp_verify_nonce( $_POST['nonce'], 'ufg-remove-gallery' ) ) { |
| 482 |
/* verified action */ |
| 483 |
if(isset($_POST['ufg_gallery_id']) && isset($_POST['do_action'])){ |
| 484 |
|
| 485 |
$ufg_gallery_id = $_POST['ufg_gallery_id']; |
| 486 |
$ufg_do_action = sanitize_text_field($_POST['do_action']); |
| 487 |
|
| 488 |
/* single gallery delete. */ |
| 489 |
if ( $ufg_do_action == 'single' ) { |
| 490 |
delete_option( 'ufg_filters_' . $ufg_gallery_id ); |
| 491 |
delete_option( 'ufg_gallery_' . $ufg_gallery_id ); |
| 492 |
delete_option( 'ufg_settings_' . $ufg_gallery_id ); |
| 493 |
} |
| 494 |
|
| 495 |
/* multiple gallery delete. */ |
| 496 |
if ( $ufg_do_action == 'multiple' ) { |
| 497 |
foreach ( $ufg_gallery_id as $ufg_single_id ) { |
| 498 |
delete_option( 'ufg_filters_' . $ufg_single_id ); |
| 499 |
delete_option( 'ufg_gallery_' . $ufg_single_id ); |
| 500 |
delete_option( 'ufg_settings_' . $ufg_single_id ); |
| 501 |
} |
| 502 |
} |
| 503 |
} |
| 504 |
wp_die(); |
| 505 |
} else { |
| 506 |
echo esc_html( 'Nonce not verified.' ); |
| 507 |
die; |
| 508 |
} |
| 509 |
} |
| 510 |
} |
| 511 |
add_action( 'wp_ajax_ufg_remove_gallery', 'ufg_remove_gallery_callback' ); |
| 512 |
/* 6. remove gallery/galleries end */ |
| 513 |
|
| 514 |
// 7. clone gallery start |
| 515 |
function ufg_clone_gallery_callback(){ |
| 516 |
if ( current_user_can( 'manage_options' ) ) { |
| 517 |
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'ufg-clone-gallery' ) ) { |
| 518 |
// verified action |
| 519 |
if(isset( $_POST['ufg_gallery_id'] ) && isset( $_POST['ufg_gallery_counter'] )){ |
| 520 |
$ufg_gallery_id = sanitize_text_field($_POST['ufg_gallery_id']); |
| 521 |
$ufg_gallery_counter = sanitize_text_field($_POST['ufg_gallery_counter']); |
| 522 |
|
| 523 |
//get cloning gallery data |
| 524 |
$ufg_cloning_filters = get_option("ufg_filters_".$ufg_gallery_id); |
| 525 |
$ufg_cloning_gallery = get_option("ufg_gallery_".$ufg_gallery_id); |
| 526 |
$ufg_cloning_setting = get_option("ufg_settings_".$ufg_gallery_id); |
| 527 |
$ufg_cloning_details = get_option("ufg_details_".$ufg_gallery_id); |
| 528 |
|
| 529 |
//generate new gallery id for clone |
| 530 |
$new_ufg_gallery_edit_nonce = wp_create_nonce( 'edit-gallery' ); |
| 531 |
$new_ufg_gallery_id = ufg_get_next_id(); |
| 532 |
$new_ufg_gallery_name = sanitize_text_field($ufg_cloning_details['gallery_name'].' - Clone'); |
| 533 |
|
| 534 |
// update clone id into gallery data |
| 535 |
foreach($ufg_cloning_gallery as $key => $value){ |
| 536 |
$ufg_cloning_setting['ufg_gallery_id'] = sanitize_text_field($new_ufg_gallery_id); |
| 537 |
} |
| 538 |
|
| 539 |
// update gallery details |
| 540 |
$ufg_cloning_details = array('ufg_gallery_id' => $ufg_gallery_id, 'gallery_name' => $new_ufg_gallery_name); |
| 541 |
|
| 542 |
if($new_ufg_gallery_id > $ufg_gallery_id){ |
| 543 |
add_option('ufg_filters_'.$new_ufg_gallery_id, $ufg_cloning_filters); |
| 544 |
add_option('ufg_gallery_'.$new_ufg_gallery_id, $ufg_cloning_gallery); |
| 545 |
add_option('ufg_settings_'.$new_ufg_gallery_id, $ufg_cloning_setting); |
| 546 |
update_option('ufg_details_'.$new_ufg_gallery_id, $ufg_cloning_details); |
| 547 |
$ufg_do_action = "'single'"; |
| 548 |
|
| 549 |
echo (' |
| 550 |
<tr id='.esc_attr( $new_ufg_gallery_id ).'> |
| 551 |
<th scope="row">'.esc_attr( $ufg_gallery_counter ).'</th> |
| 552 |
<td>'.esc_attr( $new_ufg_gallery_name ).'</td> |
| 553 |
<td> |
| 554 |
<input type="text" id="ufg-shortcode-'.esc_attr( $new_ufg_gallery_id ).'" class="btn btn-info btn-sm" value="[ufg id='.esc_attr($new_ufg_gallery_id).']"> |
| 555 |
<button type="button" id="ufg-shortcode-'.esc_attr($new_ufg_gallery_id).'" class="btn btn-info btn-sm" title="Click To Copy Gallery Shortcode" onclick="return UFGCopyShortcode('.esc_attr($new_ufg_gallery_id).')">Copy</button> |
| 556 |
<button class="btn btn-sm btn-success d-none ufg-copied-'.esc_attr($new_ufg_gallery_id).'">Copied</button> |
| 557 |
</td> |
| 558 |
<td> |
| 559 |
<button type="button" id="ufg-clone" class="btn btn-warning btn-sm" title="Clone Gallery" value="'.esc_attr($new_ufg_gallery_id).'" onclick="return UFGCloneGallery('.esc_attr($new_ufg_gallery_id).', '.esc_attr($ufg_gallery_counter).');"><i class="fas fa-copy"></i></button> |
| 560 |
<a href="?page=ufg-manage-gallery&id='.esc_attr($new_ufg_gallery_id).'&ufg-nonce='.esc_attr($new_ufg_gallery_edit_nonce).'" class="btn btn-primary btn-sm" href="#"><i class="fas fa-edit"></i></a> |
| 561 |
<button id="ufg-delete-gallery" class="btn btn-danger btn-sm" title="Delete Gallery" value="'.esc_attr($new_ufg_gallery_id).'" onclick="return UFGRemoveGallery('.esc_attr($new_ufg_gallery_id).', '.esc_attr($ufg_do_action).');"><i class="fas fa-trash-alt"></i></button> |
| 562 |
</td> |
| 563 |
<td class="text-center"> |
| 564 |
<input type="checkbox" id="ufg-gallery-id" name="ufg-gallery-id" value="'.esc_attr($new_ufg_gallery_id).'" title="Select Gallery"> |
| 565 |
</td> |
| 566 |
</tr> |
| 567 |
'); |
| 568 |
} |
| 569 |
} |
| 570 |
wp_die(); |
| 571 |
} else { |
| 572 |
echo esc_html("Nonce not verified action."); |
| 573 |
die; |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
add_action( 'wp_ajax_ufg_clone_gallery', 'ufg_clone_gallery_callback' ); |
| 578 |
// 7. clone gallery end |
| 579 |
|
| 580 |
// register sf scripts |
| 581 |
function ufg_register_scripts(){ |
| 582 |
wp_enqueue_script('jquery'); |
| 583 |
wp_register_style( 'ufg-bootstrap-frontend-css', plugin_dir_url(__FILE__).'admin/assets/bootstrap-4.6.0/css/ufg-bootstrap-frontend-min.css'); |
| 584 |
wp_register_style( 'ufg-fontawesome-css', plugin_dir_url(__FILE__). 'admin/assets/fontawesome-free-5.3.1-web/css/all.min.css'); |
| 585 |
//lightbox JS and CSS |
| 586 |
wp_register_style( 'ufg-lightbox-css', plugin_dir_url(__FILE__). 'admin/assets/lightbox/lokesh/css/lightbox.css'); |
| 587 |
wp_register_script( 'ufg-lightbox-js', plugin_dir_url(__FILE__). 'admin/assets/lightbox/lokesh/js/lightbox.js', array('jquery'), '4.5.2' ); |
| 588 |
} |
| 589 |
add_action( 'wp_enqueue_scripts', 'ufg_register_scripts' ); |
| 590 |
|
| 591 |
include('shortcode.php'); |
| 592 |
|
| 593 |
// Gallery Text Widget Support |
| 594 |
add_filter( 'widget_text', 'do_shortcode' ); |
| 595 |
|
| 596 |
//display pro plugin details |
| 597 |
function ufg_pro_details(){ |
| 598 |
$ufg_current_page = get_current_screen(); |
| 599 |
/* echo "<pre>"; |
| 600 |
print_r($ufg_current_page = get_current_screen()); |
| 601 |
echo "</pre>"; */ |
| 602 |
if($ufg_current_page->id == "toplevel_page_filter-gallery") { |
| 603 |
?> |
| 604 |
<style> |
| 605 |
.ufg-pattern { |
| 606 |
background-color: #000000; |
| 607 |
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Cpath fill='%239c7ccf' fill-opacity='0.35' d='M1 3h1v1H1V3zm2-2h1v1H3V1z'%3E%3C/path%3E%3C/svg%3E"); |
| 608 |
} |
| 609 |
</style> |
| 610 |
<div class="ufg-pattern m-3"> |
| 611 |
<div class="container-fluid"> |
| 612 |
<div class="row" style="--bs-gutter-x: 0rem;"> |
| 613 |
<div class="col-12 p-3"> |
| 614 |
<div class="text-center"> |
| 615 |
<h1 class="text-light">Filter Gallery Pro (FEATURES)</h1> |
| 616 |
</div> |
| 617 |
</div> |
| 618 |
</div> |
| 619 |
<div class="row"> |
| 620 |
<div class="col-md-2 p-3"> |
| 621 |
<div class="text-center"> |
| 622 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-bars"></i> Parent & Child Filters</button> |
| 623 |
</div> |
| 624 |
</div> |
| 625 |
<div class="col-md-2 p-3"> |
| 626 |
<div class="text-center"> |
| 627 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-infinity"></i> Unlimited Filters</button> |
| 628 |
</div> |
| 629 |
</div> |
| 630 |
<div class="col-md-2 p-3"> |
| 631 |
<div class="text-center"> |
| 632 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-th"></i> Grid & Columns</button> |
| 633 |
</div> |
| 634 |
</div> |
| 635 |
<div class="col-md-2 p-3"> |
| 636 |
<div class="text-center"> |
| 637 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-search-plus"></i> Image Lightbox</button> |
| 638 |
</div> |
| 639 |
</div> |
| 640 |
<div class="col-md-2 p-3"> |
| 641 |
<div class="text-center"> |
| 642 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-tablet-alt"></i> Responsive Gallery</button> |
| 643 |
</div> |
| 644 |
</div> |
| 645 |
<div class="col-md-2 p-3"> |
| 646 |
<div class="text-center"> |
| 647 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-link"></i> Linking Option</button> |
| 648 |
</div> |
| 649 |
</div> |
| 650 |
<div class="col-md-2 p-3"> |
| 651 |
<div class="text-center"> |
| 652 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-palette"></i> Color Customization</button> |
| 653 |
</div> |
| 654 |
</div> |
| 655 |
<div class="col-md-2 p-3"> |
| 656 |
<div class="text-center"> |
| 657 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-paint-brush"></i> Interactive Design</button> |
| 658 |
</div> |
| 659 |
</div> |
| 660 |
<div class="col-md-2 p-3"> |
| 661 |
<div class="text-center"> |
| 662 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-tasks"></i> Filter Settings</button> |
| 663 |
</div> |
| 664 |
</div> |
| 665 |
<div class="col-md-2 p-3"> |
| 666 |
<div class="text-center"> |
| 667 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-cogs"></i> Gallery Settings</button> |
| 668 |
</div> |
| 669 |
</div> |
| 670 |
<div class="col-md-2 p-3"> |
| 671 |
<div class="text-center"> |
| 672 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fab fa-youtube"></i> Video Docs</button> |
| 673 |
</div> |
| 674 |
</div> |
| 675 |
<div class="col-md-2 p-3"> |
| 676 |
<div class="text-center"> |
| 677 |
<button type="buttom" class="btn btn-lg btn-light btn-block"><i class="fas fa-headset"></i> Fast Support</button> |
| 678 |
</div> |
| 679 |
</div> |
| 680 |
|
| 681 |
</div> |
| 682 |
<div class="row"> |
| 683 |
<div class="col-md-6 p-3"> |
| 684 |
<div class="text-center"> |
| 685 |
<a href="https://wpfrank.com/demo/filter-gallery-pro/" target="_blank" class="btn btn-lg btn-danger btn-block"><i class="fas fa-desktop"></i> Check Live Demo</a> |
| 686 |
</div> |
| 687 |
</div> |
| 688 |
<div class="col-md-6 p-3"> |
| 689 |
<div class="text-center"> |
| 690 |
<a href="https://wpfrank.com/account/signup/filter-gallery-pro" target="_blank" class="btn btn-lg btn-danger btn-block"><i class="fas fa-shopping-cart"></i> Buy Pro Plugin</a> |
| 691 |
</div> |
| 692 |
</div> |
| 693 |
</div> |
| 694 |
|
| 695 |
</div> |
| 696 |
</div> |
| 697 |
<?php |
| 698 |
} |
| 699 |
} |
| 700 |
add_action('in_admin_header','ufg_pro_details'); |
| 701 |
|