public
Last active

Patch to WPSupersized plugin that suppresses navigation controls if only one slide is available

  • Download Gist
WPSupersized.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
<?php
/*
* class WPSupersized
*
* Contains the functions for the plugin
* WP Supersized that
* adds Supersized 3.2.7 to WordPress
*
*/
 
if ( !class_exists('WPSupersized') ):
class WPSupersized
{
const plugin_name = 'WP Supersized';
const plugin_version = '3.0.2';
const min_php_version = '5.2';
const min_wordpress_version = '3.1';
const supersized_theme_name = 'shutter'; // should eventually be replaced by an option
const supersized_version = '3.2.7';
const supersized_core_version = '3.2.1';
const supersized_flickr_version = '1.1.2';
const supersized_jquery_easing_version = '2.0';
/*
*
* initialize()
* This is the initialisation of the plugin
* The required scripts and css files are registered here for later use
*/
public static function initialize() {
WPSupersized_Test::min_php_version(self::min_php_version, self::plugin_name);
WPSupersized_Test::min_wordpress_version(self::min_wordpress_version, self::plugin_name);
self::load_translation_file();
wp_register_style('supersized', content_url().'/plugins/wp-supersized/css/supersized.css');
wp_register_style('supersized_core', content_url().'/plugins/wp-supersized/css/supersized.core.css');
wp_register_style('supersized_flickr', content_url().'/plugins/wp-supersized/css/supersized.flickr.css'); // for the flickr version 1.1.2, old css still needed
wp_register_style('supersized_theme_css', content_url().'/plugins/wp-supersized/theme/supersized.'.self::supersized_theme_name.'.css');
wp_register_script('WPSupersized_standard', content_url().'/plugins/wp-supersized/js/supersized.'.self::supersized_version.'.min.js',array('jquery'),self::supersized_version);
wp_register_script('WPSupersized_core', content_url().'/plugins/wp-supersized/js/supersized.core.'.self::supersized_core_version.'.min.js',array('jquery'),self::supersized_core_version);
wp_register_script('WPSupersized_flickr', content_url().'/plugins/wp-supersized/js/supersized.flickr.'.self::supersized_flickr_version.'.js',array('jquery'),self::supersized_flickr_version);
wp_register_script('WPSupersized_theme_js', content_url().'/plugins/wp-supersized/theme/supersized.'.self::supersized_theme_name.'.min.js',array('jquery'));
wp_register_script('WPSupersized_theme_visible_tray_js', content_url().'/plugins/wp-supersized/theme/supersized.'.self::supersized_theme_name.'.visible_tray.min.js',array('jquery'));
wp_register_script('jquery_easing', content_url().'/plugins/wp-supersized/js/jquery.easing.min.js',array('jquery'),self::supersized_jquery_easing_version);
}
 
/*
* Controller that generates admin page
*/
 
 
public static function generate_admin_page()
{
include('admin_page.php');
}
 
/*
* Adds a menu item inside the WordPress admin
*/
 
public static function add_menu_item()
{
add_options_page(
'WP Supersized Configuration', // page title
'WP Supersized', // menu title
'manage_options', // permissions
'wp-supersized', // page-name (used in the URL)
'WPSupersized::generate_admin_page' // clicking callback function
);
}
 
/*
* is_chosen_page
*
* Check for chosen page for display
* @return boolean Simple true/false as to whether the current page is chosen or not.
*/
public static function is_chosen_page() {
$where = get_option('wp-supersized_options');
global $wp_query;
$postid = $wp_query->post->ID;
$custom_field_exists = get_post_meta($postid, 'SupersizedDir', true); // gets custom field outside of the loop
if ($custom_field_exists && $custom_field_exists != '' && (is_single() || is_page())) // use Supersized if the custom field SupersizedDir exists (only for pages or posts)
return true; // This will then override other options
if($where['show_on_page']['everywhere'] == true)
return true;
if($where['show_in_page_id']['0'] !== '')
{
foreach ($where['show_in_page_id'] as $pageindex => $pageid)
{
if (is_page($pageid))
return true;
}
}
if($where['show_in_template'])
{
$condition= false;
foreach ($where['show_in_template'] as $i => $template_is_set)
{
if($template_is_set == true)
{
$condition = true;}
}
 
if ($condition)
{
$templates_array = $where['templates_list'];
reset($where['show_in_template']);
foreach ($templates_array as $template_name => $template_filename)
{
if (is_page_template($template_filename) && $where['show_in_template'][$template_name])
{
return true; }
}
}
}
if($where['show_in_post_id'][0] !== '')
{
foreach ($where['show_in_post_id'] as $postindex => $postid)
{
if (is_single($postid))
return true;
}
}
if($where['show_in_category_id'][0] !== '')
{
if ((in_category($where['show_in_category_id']) || self::post_is_in_descendant_category($where['show_in_category_id'])) && is_single()) // checks for category or subcategory ID
return true;
}
 
if($where['show_in_tag_id'][0] !== '')
{
if (has_tag($where['show_in_tag_id']) && is_single())
return true;
}
 
return(($where['show_on_page']['tag_archive'] && is_tag()) || ($where['show_on_page']['category_archive'] && is_category()) || ($where['show_on_page']['sticky_post'] && is_sticky()) || ($where['show_on_page']['allposts'] && is_single()) || ($where['show_on_page']['allpages'] && is_page()) || ($where['show_on_page']['homepage'] && is_home()) || ($where['show_on_page']['front_only'] && is_front_page()) || ($where['show_on_page']['404_page'] && is_404()) || ($where['show_on_page']['search_results'] && is_search()) || ($where['show_on_page']['date_archive'] && is_date()) || ($where['show_on_page']['any_archive'] && is_archive())) ;
 
}
 
/*
*
* _Supersized_scripts
*
*/
public static function _Supersized_scripts() {
if (!is_admin() && self::is_chosen_page()) // conditional scripts enqueing - registering done in initialize
{
$options = get_option('wp-supersized_options');
 
$customXml = self::get_custom_dir($options['default_dir']); // to set up the right script for the slideshow selected in the xml file
if (self::is_xml_file($customXml)) { // checks if custom dir is an xml file
global $customOptions; // $customOptions set to global to avoid parsing the xml file by calling custom_options_from_xml() each time it is needed
if (isset($customOptions['slideshow'])) { // if custom option 'slideshow' from xml file is present
$options['slideshow'] = $customOptions['slideshow']; // replaces general option by corresponding custom option from xml file
}
}
 
switch($options['slideshow'])
{
case 1:
wp_enqueue_script('jquery');
wp_enqueue_script('jquery_easing');
wp_enqueue_script('WPSupersized_standard');
if($options['tray_visible']) wp_enqueue_script('WPSupersized_theme_visible_tray_js');
else wp_enqueue_script('WPSupersized_theme_js');
break;
case 2:
wp_enqueue_script('jquery');
wp_enqueue_script('WPSupersized_core');
break;
case 3:
wp_enqueue_script('jquery');
wp_enqueue_script('WPSupersized_flickr');
break;
}
}
}
/*
*
* _Supersized_styles
*
*/
public static function _Supersized_styles() {
if (!is_admin() && self::is_chosen_page()) // conditional css enqueing - registering done in initialize
{
$options = get_option('wp-supersized_options');
$customXml = self::get_custom_dir($options['default_dir']); // to set up the right style for the slideshow selected in the xml file
if (self::is_xml_file($customXml)) { // checks if custom dir is an xml file
global $customOptions; // $customOptions set to global to avoid parsing the xml file by calling custom_options_from_xml() each time it is needed
$customOptions = self::custom_options_from_xml($customXml); // only one call to custom_options_from_xml here, global $customOptions makes it unnecessary later
if (isset($customOptions['slideshow'])) { // if custom options from xml file are present
$options['slideshow'] = $customOptions['slideshow']; // replaces general option by corresponding custom option from xml file
}
}
switch($options['slideshow'])
{
case 1:
wp_enqueue_style('supersized');
wp_enqueue_style('supersized_theme_css');
break;
case 2:
wp_enqueue_style('supersized_core');
 
break;
case 3:
wp_enqueue_style('supersized_flickr'); //uses the old css for flickr
 
break;
}
}
}
/*
*
* This is the Supersized Header part.
* Outputs all scripts and options.
*/
public static function addHeaderCode() {
 
if (!is_admin() && self::is_chosen_page())
{
$options = get_option('wp-supersized_options');
$options = self::convert_empty_options_to_zero($options);
$customXml = self::get_custom_dir($options['default_dir']);
if (self::is_xml_file($customXml)) { // checks if custom dir is an xml file
global $customOptions; // $customOptions set to global to avoid parsing the xml file by calling custom_options_from_xml() each time it is needed
if (is_array($customOptions) && count($customOptions) != 0) { // if custom options from xml file are present
foreach($customOptions as $key => $value) {
if ($options[$key] != $customOptions[$key])
$options[$key] = $customOptions[$key]; // replaces general option by corresponding custom option from xml file
}
}
}
?>
<!--
Supersized <?php echo self::supersized_version; ?> - Fullscreen Background jQuery Plugin
www.buildinternet.com/project/supersized
By Sam Dunn / One Mighty Roar (www.onemightyroar.com)
Released under MIT License / GPL License
Adapted for Wordpress (<?php echo self::plugin_name.' '.self::plugin_version; ?>) by Benoit De Boeck / World in my Eyes (www.worldinmyeyes.be)
-->
<script type="text/javascript">
jQuery(document).ready(function($) {
$.supersized({
<?php
if ($options['slideshow'] !== '2') // Some options not needed for Single image mode
{
?>
slideshow : <?php echo $options['slideshow']; ?>,
autoplay : <?php echo $options['autoplay']; ?>,
<?php
}
?>
start_slide : <?php echo $options['start_slide']; ?>,
<?php
if ($options['slideshow'] !== '2') // Some options not needed for Single image mode
{
?>
random : <?php echo $options['random']; ?>,
slide_interval : <?php echo $options['slide_interval']; ?>,
transition : <?php echo $options['transition']; ?>,
transition_speed : <?php echo $options['transition_speed']; ?>,
new_window : <?php echo $options['new_window']; ?>,
pause_hover : <?php echo $options['pause_hover']; ?>,
stop_loop : <?php echo $options['stop_loop']; ?>,
keyboard_nav : <?php echo $options['keyboard_nav']; ?>,
performance : <?php echo $options['performance']; ?>,
<?php
}
?>
image_protect : <?php echo $options['image_protect']; ?>,
image_path : '<?php echo content_url()?>/plugins/wp-supersized/<?php if($options['slideshow'] == '3') echo 'flickr_';?>img/',
min_width : <?php echo $options['min_width']; ?>,
min_height : <?php echo $options['min_height']; ?>,
vertical_center : <?php echo $options['vertical_center']; ?>,
horizontal_center : <?php echo $options['horizontal_center']; ?>,
fit_always : <?php echo $options['fit_always']; ?>,
fit_portrait : <?php echo $options['fit_portrait']; ?>,
fit_landscape : <?php echo $options['fit_landscape']; ?>,
<?php
if ($options['slideshow'] !== '2') // Some options not needed for Single image mode
{
?>
thumbnail_navigation : <?php echo $options['thumbnail_navigation']; ?>,
thumb_links : <?php echo $options['thumb_links']; ?>,
slide_counter : <?php echo $options['slide_counter']; ?>,
slide_captions : <?php echo $options['slide_captions']; ?>,
<?php
}
if ($options['slideshow'] == '3') // Options for Flickr mode
{
?> source : <?php echo $options['flickr_source']; ?>,
set : '<?php echo $options['flickr_set']; ?>',
user : '<?php echo $options['flickr_user']; ?>',
group : '<?php echo $options['flickr_group']; ?>',
tags : '<?php echo $options['flickr_tags']; ?>',
total_slides : <?php echo $options['flickr_total_slides']; ?>,
image_size : '<?php echo $options['flickr_size']; ?>',
api_key : '<?php echo $options['flickr_api_key']; ?>'
<?php
}
if ($options['slideshow'] !== '3') // Options not needed for old Flickr mode
{
?>
slides : [<?php self::slides_list(); //outputs the list of slides in the correct format
?>],
slide_links : '<?php echo $options['slide_links']; ?>',
progress_bar : <?php echo $options['progress_bar']; ?>,
mouse_scrub : <?php echo $options['mouse_scrub']; }?>
});
});
</script>
<?php
 
}
}
/*
*
* This is the Supersized Footer part.
* Adds the Navigation.
*/
public static function addFooterCode() {
if (!is_admin() && self::is_chosen_page()) // only on the right pages
{
$options = get_option('wp-supersized_options');
$options = self::convert_empty_options_to_zero($options);
$customXml = self::get_custom_dir($options['default_dir']);
if (self::is_xml_file($customXml)) { // checks if custom dir is an xml file
global $customOptions; // $customOptions set to global to avoid parsing the xml file by calling custom_options_from_xml() each time it is needed
if (is_array($customOptions) && count($customOptions) != 0) { // if custom options from xml file are present
foreach($customOptions as $key => $value) {
if ($options[$key] != $customOptions[$key])
$options[$key] = $customOptions[$key]; // replaces general option by corresponding custom option from xml file
}
}
}
if ($options['navigation'] && $options['slideshow'] == '3') { // only for old flickr look
?>
<!--Thumbnail Navigation-->
<div id="prevthumb"></div> <div id="nextthumb"></div>
 
<!--Control Bar-->
<div id="controls-wrapper">
<div id="controls">
<?php
if ($options['slide_counter']) // Needed to get rid of the slide counter if switched off
{
?>
<!--Slide counter-->
<div id="slidecounter">
<span class="slidenumber"></span>/<span class="totalslides"></span>
</div>
<?php
}
?>
<!--Slide captions displayed here-->
<div id="slidecaption"></div>
<?php
if ($options['navigation_controls']) // If true, show navigation controls
{
?>
<!--Navigation-->
<div id="navigation">
<img id="prevslide" src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-supersized/flickr_img/back_dull.png"/><img id="pauseplay" src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-supersized/flickr_img/pause_dull.png"/><img id="nextslide" src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-supersized/flickr_img/forward_dull.png"/>
</div>
 
<?php
}
?> </div>
</div> <?php // closing the controls-wrapper and controls
} // end of the old flickr part
else {
if ($options['navigation'] && $options['slideshow'] == '1') // to get rid of all navigation if switched off or when in Single image mode
{
?>
<!--Thumbnail Navigation-->
<div id="prevthumb"></div>
<div id="nextthumb"></div>
<?php
}
global $slides_array_list;
if ($options['navigation_controls'] && $options['slideshow'] == '1' && $slides_array_list > 1) // If true, show navigation arrows
{
?>
<!-- Arrow Navigation -->
<a id="prevslide" class="load-item"></a>
<a id="nextslide" class="load-item"></a>
<?php
}
if ($options['navigation'] && $options['slideshow'] == '1') // to get rid of all navigation if switched off or when in Single image mode
{
?>
 
<div id="thumb-tray" class="load-item">
<div id="thumb-back"></div>
<div id="thumb-forward"></div>
</div>
<?php
if ($options['progress_bar'])
{
?>
<!--Time Bar-->
<div id="progress-back" class="load-item">
<div id="progress-bar"></div>
</div>
<?php
}
?>
<!--Control Bar-->
<div id="controls-wrapper" class="load-item">
<div id="controls">
<a id="play-button"><img id="pauseplay" src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/wp-supersized/img/pause.png"/></a>
<?php
if ($options['slide_counter']) // If true, show slide counter
{
?>
<!--Slide counter-->
<div id="slidecounter">
<span class="slidenumber"></span>/<span class="totalslides"></span>
</div>
<?php
}
}
if ($options['slide_captions'] && !$options['navigation'] && $options['slideshow'] == '1') // Show slide caption (when the navigation option is off)
{ // if navigation is off and the caption is still shown, set controls-wrapper background to none: only the caption is shown. Useful for html.
?>
<div id="controls-wrapper" style="background: none;">
<!--Slide captions displayed here-->
<div id="slidecaption"></div>
</div>
<?php
}
elseif ($options['slide_captions'] && $options['navigation'] && $options['slideshow'] == '1') // Show captions when navigation is on
{
?>
<!--Slide captions displayed here-->
<div id="slidecaption"></div>
<?php
}
if ($options['navigation'] && $options['slideshow'] == '1') // to get rid of all navigation if switched off or when in Single image mode
{
if ($options['thumb_tray']) // If true, show thumb tray button
{
?>
<!--Thumb Tray button-->
<a id="tray-button"><img style="height:42px;" id="tray-arrow" src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/wp-supersized/img/button-tray-';
echo $options['tray_visible'] ? 'down' : 'up'; ?>.png"/></a>
<?php
}
if ($options['slide_links']) {
?>
<!--Navigation-->
<ul id="slide-list"></ul>
<?php } ?>
</div>
</div>
<?php
}
}
}
}
 
/*
*
* Reads and outputs the list of slides
*
*/
public static function slides_list()
{
$options = get_option('wp-supersized_options');
if (substr($options['default_dir'],0,11) != 'ngg-gallery_')
$full_dir = self::get_custom_dir($options['default_dir']); // if no NextGEN gallery has been selected as default, then go through the normal routine
else
$full_dir = $options['default_dir']; // if a NextGEN gallery has been selected as default
if ($full_dir == 'not_found_error') {
self::output_error_image('not_found'); // if the directory does not exists, display error image (directory/file not found)
return;
}
if ($full_dir == 'not_readable_error') {
self::output_error_image('not_readable'); // if the directory cannot be read (permissions), display error image (check permissions)
return;
}
 
if (self::is_xml_file($full_dir)) { // checks if custom dir is an xml file
$xml_file = WP_CONTENT_DIR.'/'.$full_dir;
$xml = simplexml_load_file($xml_file);
global $xmlSlidesArray; // global to avoid parsing the xml file each time it is needed
$xmlSlidesArray = $xml->xpath('//slide');
if (is_array($xmlSlidesArray) && count($xmlSlidesArray) > 0) { // if there are slides defined in the xml file, display them, rtrim() is needed because the 'slide' array contains a few spaces even if there are no slides (bug of xmlLib ?)
self::slides_list_from_xml();
return;
}
else $full_dir = $options['default_dir']; // if there are no slides defined in the xml file, display the default ones
}
if ($full_dir == 'wp-gallery') { // does the user want to use the Wordpress Media gallery ?
self::images_from_wpgallery($post_ID);
return;
}
if ($full_dir == 'ngg-gallery' && method_exists('nggdb','get_gallery')) { // does the user want to use the NextGen gallery ? (only if NextGen is installed and the function get_gallery exists)
global $wp_query;
$postid = $wp_query->post->ID;
$nggGallery_ID = get_post_meta($postid, 'SupersizedNextGenGallery', true); // gets custom field outside of the loop
self::images_from_ngg_gallery($nggGallery_ID);
return;
}
if (substr($full_dir,0,12) == 'ngg-gallery_' && substr($full_dir,12) != '' && method_exists('nggdb','get_gallery')) { // use a NextGEN gallery if it was selected as default in the options.
$nggGallery_ID = substr($full_dir, 12);
self::images_from_ngg_gallery($nggGallery_ID);
return;
}
if ($full_dir) {
$dir = self::build_wpcontent_dir()."/".$full_dir."/";
$thumbs_dir = $dir."thumbs/";
$dirArray = glob($dir."*.{jpg,JPG,png,PNG,gif,GIF,jpeg,JPEG}",GLOB_BRACE);
if(empty($dirArray)) $dirArray = array_merge((array)glob($dir."*.jpg"),(array)glob($dir."*.JPG"),(array)glob($dir."*.png"),(array)glob($dir."*.PNG"),(array)glob($dir."*.gif"),(array)glob($dir."*.GIF"),(array)glob($dir."*.jpeg"),(array)glob($dir."*.JPEG")); // if the BRACE option does not work, use array_merge
asort($dirArray); //dirArray is sorted to make sure that it is in alphabetical order
}
else {
$thumbsdirArray = $dirArray = $thumbs_dir = $dir = '';
}
if ($options['debugging_mode']) {
echo '/*'."\n";
echo 'site_url = '.site_url()."\n";
echo 'home_url = '.home_url()."\n";
echo 'full_dir = '.$full_dir."\n".'dir = '.$dir."\n".'thumbs_dir = '.$thumbs_dir."\n".'dirArray = ';
print_r($dirArray);
echo "\n".'*/'."\n"; //debugging mode
}
if (file_exists($thumbs_dir) && !self::is_empty_dir($thumbs_dir)) {
$thumbsdirArray = array_merge((array)glob($thumbs_dir."*.jpg"),(array)glob($thumbs_dir."*.JPG"),(array)glob($thumbs_dir."*.png"),(array)glob($thumbs_dir."*.PNG"),(array)glob($thumbs_dir."*.gif"),(array)glob($thumbs_dir."*.GIF"),(array)glob($thumbs_dir."*.jpeg"),(array)glob($thumbs_dir."*.JPEG")); // $thumbsdirArray = glob($thumbs_dir."*.{jpg,JPG,png,PNG,gif,GIF,jpeg,JPEG}",GLOB_BRACE);
if(empty($thumbsdirArray)) $thumbsdirArray = glob($thumbs_dir."*.{jpg,JPG,png,PNG,gif,GIF,jpeg,JPEG}",GLOB_BRACE); // if the array_merge method does not work, use the BRACE option
asort($thumbsdirArray); //thumbsdirArray is sorted to make sure that it is in alphabetical order
foreach ($thumbsdirArray as $key => $path) {
$shortthumbsdirArray[$key] = str_ireplace(self::build_wpcontent_dir(), '', $path); // removes the wp-content part of the path to allow the use of content_url()
}
}
else $shortthumbsdirArray = $thumbsdirArray = $thumbs_dir = '';
foreach ($dirArray as $key => $path) {
$short_dirArray[$key] = str_ireplace(self::build_wpcontent_dir(), '', $path);
}
$indexCount = count($dirArray);
if ($options['background_url'])
$full_background_url = "http://".$options['background_url'];
else $full_background_url = '';
 
// loops through the array of files and print them all
if ($indexCount >= 1 && $dir) // only show the slides if there is at least 1 and there is a dir containing images
{
for($index=0; $index < $indexCount-1; $index++) {
$iptc_caption = self::_show_iptc_caption($dirArray[$index]);
$converted_caption = self::asciitothmlcode($iptc_caption);
if ($thumbs_dir && file_exists($thumbs_dir))
$thumbnail_link = content_url().$shortthumbsdirArray[$index];
else $thumbnail_link = '';
echo "\n{image : '" . content_url().$short_dirArray[$index] . "', title : '".$converted_caption."', thumb : '".$thumbnail_link."', url : '" . $full_background_url . "'},";
}
$iptc_caption = self::_show_iptc_caption($dirArray[$index]);
$converted_caption = self::asciitothmlcode($iptc_caption);
if ($thumbs_dir && file_exists($thumbs_dir))
$thumbnail_link = content_url().$shortthumbsdirArray[$index];
else $thumbnail_link = '';
echo "\n{image : '" . content_url().$short_dirArray[$index] . "', title : '" . $converted_caption ."', thumb : '".$thumbnail_link . "', url : '" . $full_background_url . "'}"; // The last line MUST be without comma
}
else // otherwise show the original Supersized examples
echo "\n{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.1/slides/quietchaos-kitty.jpg', title : 'Quiet Chaos by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'},\n{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.1/slides/wanderers-kitty.jpg', title : 'Wanderers by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'}";
}
/*
*
* output_error_image($errorType)
* Shows an error image in case a problem was detected
* The image shown depends on $errorType
*
*/
public static function output_error_image($errorType) {
switch ($errorType) {
case 'not_found' :
echo "\n{image : '".plugins_url()."/wp-supersized/img/error_img/cannot_find_your_dir_or_file_please_check_that_it_exists.jpg', title : 'Cannot find your dir or file please check that it exists', url : ''}\n";
break;
case 'not_readable' :
echo "\n{image : '".plugins_url()."/wp-supersized/img/error_img/cannot_read_your_dir_or_file_please_check_access_rights.jpg', title : 'Cannot read your dir or file please check access rights', url : ''}\n";
break;
case 'wp-gallery_images_not_present' :
echo "\n{image : '".plugins_url()."/wp-supersized/img/error_img/cannot_find_wp_media_gallery_images.jpg', title : 'Cannot find WP Gallery images attached to this post/page', url : ''}\n";
break;
case 'nextgen-gallery_images_not_present' :
echo "\n{image : '".plugins_url()."/wp-supersized/img/error_img/cannot_find_nextgen_gallery_images_requested.jpg', title : 'Cannot find WP Gallery images attached to this post/page', url : ''}\n";
break;
}
}
/*
*
* Reads and outputs the list of slides from an XML file from which the contents have been copied in the global array $xmlSlidesArray
*
*/
public static function slides_list_from_xml() {
global $xmlSlidesArray; // global to avoid parsing the xml file each time it is needed
$xmlArray = $xmlSlidesArray;
$indexCount = count($xmlArray);
global $slides_array_list;
$slides_array_list = $indexCount;
// loops through the array of files and prints them all
if ($indexCount >= 1) // only show the slides if there is at least 1
{
for($index=0; $index < $indexCount-1; $index++) {
echo "\n{image : '" . $xmlArray[$index]->slide_link . "', title : '".$xmlArray[$index]->title."', thumb : '".$xmlArray[$index]->thumb_link."', url : '" . $xmlArray[$index]->url . "'},";
}
echo "\n{image : '" . $xmlArray[$index]->slide_link . "', title : '".$xmlArray[$index]->title."', thumb : '".$xmlArray[$index]->thumb_link."', url : '" . $xmlArray[$index]->url . "'}";
}
else // otherwise show the original Supersized examples - this should never be reached as there is already a check earlier
echo "\n{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.1/slides/quietchaos-kitty.jpg', title : 'Quiet Chaos by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'},\n{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.1/slides/wanderers-kitty.jpg', title : 'Wanderers by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'}";
}
 
/*
*
* custom_options_from_xml($customXml)
* Gets the custom options from the xml file $customXml
* Returns the array $customOptions
*/
public static function custom_options_from_xml($customXml) {
// $xml_file = content_url().'/'.$customXml;
$xml_file = WP_CONTENT_DIR.'/'.$customXml;
$xml = simplexml_load_file($xml_file);
$optionsXml = $xml->xpath('//options');
$optionsFromXml = array();
foreach($optionsXml[0] as $key => $value) {
$optionsFromXml[$key] = (int) $value; // converts the object $value into a integer
}
return $optionsFromXml;
}
/*
*
* get_custom_dir ($default_dir)
* checks if default dir and custom dir exist
* and returns the correct dir for display
*
*/
public static function get_custom_dir($default_dir) {
global $post; // $wp_query;
$postid = $post->ID; //$wp_query->post->ID;
$custom_dir = get_post_meta($postid, 'SupersizedDir', true); // gets custom field outside of the loop
$full_custom_dir = self::build_wpcontent_dir().'/'.$custom_dir;
$full_default_dir = self::build_wpcontent_dir().'/'.$default_dir;
if (self::is_xml_file($custom_dir) && file_exists($full_custom_dir) && (is_single() || is_page())) // checks if custom dir is an xml file
return $custom_dir;
 
if ((strtolower($custom_dir) == 'wp-gallery' || strtolower($custom_dir) == 'wpgallery' || strtolower($custom_dir) == 'wp_gallery') && (is_single() || is_page())) {
$custom_dir = 'wp-gallery';
return $custom_dir; // checks if the user wants to use the Wordpress Media Gallery
}
if ((strtolower($custom_dir) == 'ngg-gallery' || strtolower($custom_dir) == 'ngggallery' || strtolower($custom_dir) == 'ngg_gallery') && (is_single() || is_page())) {
$custom_dir = 'ngg-gallery';
return $custom_dir; // checks if the user wants to use the NextGen Gallery
}
if (substr($custom_dir,0,12) == 'ngg-gallery_' && substr($custom_dir,12) != '' && (is_single() || is_page())) { // use a NextGEN gallery if it was selected as default in the options.
return $custom_dir;
}
$options = get_option('wp-supersized_options');
if ($options['debugging_mode']) {
echo "\n".'/*'."\n".'custom_dir = '.$custom_dir."\n".'full_custom_dir = '.$full_custom_dir."\n".'full_default_dir = '.$full_default_dir."\n".'content_url = '.content_url()."\n".' */'."\n"; //debugging mode
}
if ($custom_dir && (!is_dir($full_custom_dir) || !file_exists($full_custom_dir)) && (is_single() || is_page()))
return 'not_found_error'; // if the directory does not exist, return an error
if ($custom_dir && (!is_readable($full_custom_dir)) && (is_single() || is_page()))
return 'not_readable_error'; // if the directory is not readable (due to access rights), return an error
if ($default_dir && is_dir($full_default_dir) && (is_tag() || is_category() || is_archive() || is_date())) // to make sure that the Tag or category archive gets the right dir
return $default_dir;
if ($custom_dir && is_dir($full_custom_dir) && (is_single() || is_page())) // to make sure that the custom dir images only appear on single posts/pages and not in tag or category archives
return $custom_dir;
return $default_dir; // if no other choice, return default dir
}
 
/*
*
* build_wpcontent_dir()
* Builds the correct wp-content directory path
* Returns $wpContentDir
*
*/
public static function build_wpcontent_dir(){
$home_url = home_url();
if (defined('ICL_SITEPRESS_VERSION')) // checks for the presence of WPML
$home_url = self::clean_wpml_home_url();
$wordpressDir = ltrim(str_replace($home_url,'',site_url()),"/"); // removes the root url and the leading slash if present
if ($wordpressDir !== '') $slash="/";
else $slash='';
$wpContentDir = $wordpressDir.$slash.'wp-content';
return $wpContentDir;
}
/*
*
* images_from_wpgallery($post_ID)
* generates and outputs the list of slides from Wordpress Media Gallery images attached to the post $post_ID
* @param type $post_ID
*/
public static function images_from_wpgallery($post_ID) {
global $wp_query;
$postid = $wp_query->post->ID;
$options = get_option('wp-supersized_options');
if ($options['background_url'])
$full_background_url = "http://".$options['background_url'];
else $full_background_url = '';
$full_output ='';
$images = get_children(array( // gets images attached to the post/page
'post_parent' => $postid,
'post_type' => 'attachment',
'numberposts' => -1, // show all
'post_status' => null,
'post_mime_type' => 'image',
));
global $slides_array_list;
$slides_array_list = sizeof($images);
if($images) {
$images = self::sort_wpgallery_array($images); // sorts the images according to the menu order defined in Wordpress Media Gallery
foreach($images as $image) {
$wpgallery_url = wp_get_attachment_url($image->ID); // full link to the full size image
$wpgallery_thumburl = wp_get_attachment_thumb_url($image->ID); // full link to the thumbnail
$wpgallery_title = apply_filters('the_title',$image->post_title); // image title
$wpgallery_caption = apply_filters('post_excerpt',$image->post_excerpt); // image caption
if ($wpgallery_caption == '')
$wpgallery_caption = $wpgallery_title; // if there is no caption, use title instead
 
$full_output = $full_output."\n{image : '" . $wpgallery_url . "', title : '".$wpgallery_caption."', thumb : '".$wpgallery_thumburl."', url : '" . $full_background_url . "'},";
}
$full_output = substr( $full_output, 0, -1 )."\n"; // removes the trailing comma to avoid trouble in IE
echo $full_output;
 
}
else self::output_error_image('wp-gallery_images_not_present'); // if there are no WP Gallery images attached to the post/page, display error image
 
}
/*
*
* images_from_ngg_gallery($nggAlbum_ID)
* generates and outputs the list of slides from NextGen Gallery album $nggAlbum_ID
* @param type $nggAlbum_ID
*/
public static function images_from_ngg_gallery($nggGallery_ID) {
if (method_exists('nggdb','get_gallery')) { // if NextGen is installed and the function get_gallery exists
$options = get_option('wp-supersized_options');
if ($options['background_url'])
$full_background_url = "http://".$options['background_url'];
else $full_background_url = '';
$full_output ='';
 
$imagesList = nggdb::get_gallery($nggGallery_ID, 'sortorder', 'ASC'); // calls the NextGen Gallery function to retrieve the content of the NextGen gallery with ID $nggGallery_ID. Images are sorted in ascending order of Sort Order.
 
global $slides_array_list;
$slides_array_list = sizeof($imagesList);
if($imagesList) { // if there are images in the gallery
foreach($imagesList as $image) {
$ngggallery_url = $image->imageURL; // full link to the full size image
$ngggallery_thumburl = $image->thumbURL; // full link to the thumbnail
$ngggallery_title = $image->alttext; // image title
$ngggallery_caption = $image->description; // image caption
if ($ngggallery_caption == '')
$ngggallery_caption = $ngggallery_title; // if there is no caption, use title instead
 
$full_output = $full_output."\n{image : '" . $ngggallery_url . "', title : '".$ngggallery_caption."', thumb : '".$ngggallery_thumburl."', url : '" . $full_background_url . "'},";
}
$full_output = substr( $full_output, 0, -1 )."\n"; // removes the trailing comma to avoid trouble in IE
echo $full_output;
 
}
else self::output_error_image('nextgen-gallery_images_not_present'); // if the requested NextGEN Gallery images are not present, display error image
}
}
/*
*
* is_xml_file($dir)
* Checks if dir is an xml file
*
*/
public static function is_xml_file($dir)
{
if (substr($dir, strlen($dir)-4,4) == '.xml') // checks if dir is an xml file
return true;
else return false;
}
 
/*
*
* convert_empty_options_to_zero($options)
* Converts empty values of options to 0 and false to 1
* Returns $options with correct 0 or 1 values
*
*/
public static function convert_empty_options_to_zero($options) {
foreach($options as $key => $value) {
switch($value)
{
case 'true': // replaces true by 1
$options[$key] = '1';
break;
case '': // and false by 0
$options[$key] = '0';
break;
}
}
return $options;
}
/*
*
* is_empty_dir($dir)
* Checks if a folder is empty
*
*/
public static function is_empty_dir($dir)
{
if (($files = @scandir($dir)) && count($files) <= 2) {
return true;
}
return false;
}
 
/*
*
* clean_wpml_home_url()
* Transforms the wpml home url into a correct home url
* Returns $home_url
*
*/
 
public static function clean_wpml_home_url()
{
$home_url = rtrim(icl_get_home_url(),'/');
$search_string = '/'.ICL_LANGUAGE_CODE;
$home_url = str_replace($search_string,'',$home_url); // gets rid of the language code at the end of the url generated by wpml
$search_string = '?lang='.ICL_LANGUAGE_CODE;
$home_url = str_replace($search_string,'',$home_url); // in case it was the other option of wpml, gets rid of the language code at the end of the url generated by wpml
return $home_url;
}
 
/*
*
* _show_iptc_caption($filename)
* gets IPTC caption and returns it
*
*/
public static function _show_iptc_caption($filename) {
$size = getimagesize($filename, $info);
if(isset($info['APP13']))
{
$iptc = iptcparse($info['APP13']);
if (is_array($iptc)) {
$caption = $iptc['2#120'][0];
}
}
return $caption; }
/*
*
* sort_wpgallery_array($images)
* Sorts the array of images from the Wordpress Media Gallery according to the order defined in the gallery
* Returns the sorted array
*
*/
public static function sort_wpgallery_array($arrImages) {
 
$arrKeys = array_keys($arrImages); // Get array keys representing attached image numbers
// Put all image objects into new array with standard numeric keys (new array only needed while we sort the keys)
foreach($arrImages as $oImage) {
$arrNewImages[] = $oImage;
}
// Bubble sort image object array by menu_order
for($i = 0; $i < sizeof($arrNewImages) - 1; $i++) {
for($j = 0; $j < sizeof($arrNewImages) - 1; $j++) {
if((int)$arrNewImages[$j]->menu_order > (int)$arrNewImages[$j + 1]->menu_order) {
$oTemp = $arrNewImages[$j];
$arrNewImages[$j] = $arrNewImages[$j + 1];
$arrNewImages[$j + 1] = $oTemp;
}
}
}
return $arrNewImages;
}
/*
*
* Installation - Sets the options defaults
* Done only once at activation
*
*/
public static function install () {
$previous_options = get_option('wp-supersized_options');
if ($previous_options['reset_options'] || !is_array($previous_options)) { // if reset or fresh install
$newoptions['slideshow'] = '1';
$newoptions['autoplay'] = 'true';
$newoptions['start_slide'] = '1';
$newoptions['random'] = '';
$newoptions['slide_interval'] = '3000';
$newoptions['transition'] = '1';
$newoptions['transition_speed'] = '500';
$newoptions['new_window'] = 'true';
$newoptions['pause_hover'] = '';
$newoptions['keyboard_nav'] = 'true';
$newoptions['performance'] = '1';
$newoptions['image_protect'] = '';
$newoptions['min_width'] = '0';
$newoptions['min_height'] = '0';
$newoptions['vertical_center'] = 'true';
$newoptions['horizontal_center'] = 'true';
$newoptions['fit_portrait'] = 'true';
$newoptions['fit_landscape'] = '';
$newoptions['navigation'] = 'true';
$newoptions['background_url'] = ''; // new option for version 1.2
$newoptions['thumbnail_navigation'] = '';
$newoptions['navigation_controls'] = 'true';
$newoptions['slide_counter'] = 'true';
$newoptions['slide_captions'] = 'true';
$newoptions['flickr_source'] = '3';
$newoptions['flickr_set'] = '';
$newoptions['flickr_user'] = '';
$newoptions['flickr_group'] = '';
$newoptions['flickr_tags'] = ''; // new option for version 1.1.1
$newoptions['flickr_total_slides'] = '100';
$newoptions['flickr_size'] = 'z';
$newoptions['flickr_api_key'] = '';
$newoptions['show_on_page'] = array(
'allposts' => '',
'homepage' => '',
'allpages' => '',
'front_only' => '',
'sticky_post' => '',
'404_page' => '',
'search_results' => '', // new option for version 1.2
'category_archive' => '', // new option for version 1.1
'tag_archive' => '', // new option for version 1.1
'only_custom' => '', // new option for version 1.1 NOW DEPRECATED
'any_archive' => '', // new option for version 1.2
'date_archive' => '', // new option for version 1.2
'everywhere' => '' // new option for version 1.2
);
$newoptions['templates_list'] = get_page_templates();
foreach ($newoptions['templates_list'] as $templateID => $templatefilename)
{
$newoptions['show_in_template'][$templateID] = '';
}
$newoptions['show_in_page_id'] = array('0' => '');
$newoptions['show_in_post_id'] = array('0' => '');
$newoptions['show_in_category_id'] = array('0' => ''); // new option for version 1.1
$newoptions['show_in_tag_id'] = array('0' => ''); // new option for version 1.1
$newoptions['stop_loop'] = ''; //new option for version 1.1
$newoptions['fit_always'] = ''; //new option for version 1.1
$newoptions['slide_links'] = 'blank'; //new option for version 1.1
$newoptions['thumb_links'] = 'true'; //new option for version 1.1
$newoptions['thumbnail_suffix'] = '-1'; //new option for version 1.1
$newoptions['progress_bar'] = 'true'; //new option for version 1.1
$newoptions['mouse_scrub'] = ''; //new option for version 1.1
$newoptions['thumb_tray'] = 'true'; //new option for version 1.1
$newoptions['default_dir'] = 'supersized-slides'; //new option for version 1.1
$newoptions['debugging_mode'] = ''; //new option for version 1.3
$newoptions['reset_options'] = ''; //new option for version 1.1
$newoptions['tray_visible'] = ''; //new option for version 3.1
}
elseif (is_array($previous_options) && !array_key_exists('default_dir', $previous_options)) { // if options already set for previous version, sets defaults for new options only
foreach ($previous_options as $option_key => $option_value) // keep the previous options
{
$newoptions[$option_key] = $previous_options[$option_key];
}
$newoptions['show_on_page'] = array(
'category_archive' => '', // new option for version 1.1
'tag_archive' => '', // new option for version 1.1
'only_custom' => '', // new option for version 1.1 NOW DEPRECATED
'search_results' => '', // new option for version 1.2
'any_archive' => '', // new option for version 1.2
'date_archive' => '', // new option for version 1.2
'everywhere' => '' // new option for version 1.2
);
$newoptions['show_in_category_id'] = array('0' => ''); // new option for version 1.1
$newoptions['show_in_tag_id'] = array('0' => ''); // new option for version 1.1
$newoptions['stop_loop'] = ''; //new option for version 1.1
$newoptions['fit_always'] = ''; //new option for version 1.1
$newoptions['slide_links'] = 'blank'; //new option for version 1.1
$newoptions['thumb_links'] = ''; //new option for version 1.1
$newoptions['thumbnail_suffix'] = '-1'; //new option for version 1.1
$newoptions['progress_bar'] = 'true'; //new option for version 1.1
$newoptions['mouse_scrub'] = ''; //new option for version 1.1
$newoptions['thumb_tray'] = 'true'; //new option for version 1.1
$newoptions['default_dir'] = 'supersized-slides'; //new option for version 1.1
$newoptions['debugging_mode'] = ''; //new option for version 1.3
$newoptions['reset_options'] = ''; //new option for version 1.1
$newoptions['flickr_tags'] = ''; // new option for version 1.1.1
$newoptions['background_url'] = ''; // new option for version 1.2
$newoptions['tray_visible'] = ''; //new option for version 3.1
}
elseif (is_array($previous_options) && !array_key_exists('flickr_tags', $previous_options)) {
foreach ($previous_options as $option_key => $option_value) // keep the previous options
{
$newoptions[$option_key] = $previous_options[$option_key];
}
$newoptions['flickr_tags'] = ''; // new option for version 1.1.1
$newoptions['show_on_page']['search_results'] = ''; // new option for version 1.2
$newoptions['show_on_page']['everywhere'] = ''; // new option for version 1.2
$newoptions['show_on_page']['any_archive'] = ''; // new option for version 1.2
$newoptions['show_on_page']['date_archive'] = ''; // new option for version 1.2
$newoptions['background_url'] = ''; // new option for version 1.2
$newoptions['debugging_mode'] = ''; //new option for version 1.3
$newoptions['tray_visible'] = ''; //new option for version 3.1
}
elseif (is_array($previous_options) && !array_key_exists('everywhere', $previous_options)) {
foreach ($previous_options as $option_key => $option_value) // keep the previous options
{
$newoptions[$option_key] = $previous_options[$option_key];
}
$newoptions['show_on_page']['everywhere'] = ''; // new option for version 1.2
$newoptions['show_on_page']['search_results'] = ''; // new option for version 1.2
$newoptions['show_on_page']['any_archive'] = ''; // new option for version 1.2
$newoptions['show_on_page']['date_archive'] = ''; // new option for version 1.2
$newoptions['background_url'] = ''; // new option for version 1.2
$newoptions['debugging_mode'] = ''; //new option for version 1.3
$newoptions['tray_visible'] = ''; //new option for version 3.1
}
elseif (is_array($previous_options) && !array_key_exists('debugging_mode', $previous_options)) {
foreach ($previous_options as $option_key => $option_value) // keep the previous options
{
$newoptions[$option_key] = $previous_options[$option_key];
}
$newoptions['debugging_mode'] = ''; //new option for version 1.3
$newoptions['tray_visible'] = ''; //new option for version 3.1
}
elseif (is_array($previous_options) && !array_key_exists('tray_visible', $previous_options)) {
foreach ($previous_options as $option_key => $option_value) // keep the previous options
{
$newoptions[$option_key] = $previous_options[$option_key];
}
$newoptions['tray_visible'] = ''; //new option for version 3.1
}
else return; // do not modify the existing options
 
update_option('wp-supersized_options', $newoptions); // Sets defaults for options
}
//uninstall all options
/*
*
* Delete options when uninstalling the plugin
*
*/
public static function uninstall () {
delete_option('wp-supersized_options');
}
 
/*
*
* Adds the settings link for the plugin
*
*/
 
public static function add_plugin_settings_link($links, $file)
{
$settings_link = sprintf('<a href="%s">%s</a>', admin_url( 'options-general.php?page=wp-supersized' ), 'Settings');
array_unshift( $links, $settings_link );
return $links;
}
/*
*
* asciitohtmlcode ($string)
* Replaces special characters by their html equivalents
* Returns $string
*
*/
 
public static function asciitothmlcode($string) {
 
$asciiarray[] = 39; $htmlarray[] = "&#39;";
$asciiarray[] = 192; $htmlarray[] = "&#192;";
$asciiarray[] = 193; $htmlarray[] = "&#193;";
$asciiarray[] = 194; $htmlarray[] = "&#194;";
$asciiarray[] = 195; $htmlarray[] = "&#195;";
$asciiarray[] = 196; $htmlarray[] = "&#196;";
$asciiarray[] = 197; $htmlarray[] = "&#197;";
$asciiarray[] = 198; $htmlarray[] = "&#198;";
$asciiarray[] = 199; $htmlarray[] = "&#199;";
$asciiarray[] = 200; $htmlarray[] = "&#200;";
$asciiarray[] = 201; $htmlarray[] = "&#201;";
$asciiarray[] = 202; $htmlarray[] = "&#202;";
$asciiarray[] = 203; $htmlarray[] = "&#203;";
$asciiarray[] = 204; $htmlarray[] = "&#204;";
$asciiarray[] = 205; $htmlarray[] = "&#205;";
$asciiarray[] = 206; $htmlarray[] = "&#206;";
$asciiarray[] = 207; $htmlarray[] = "&#207;";
$asciiarray[] = 208; $htmlarray[] = "&#208;";
$asciiarray[] = 209; $htmlarray[] = "&#209;";
$asciiarray[] = 210; $htmlarray[] = "&#210;";
$asciiarray[] = 211; $htmlarray[] = "&#211;";
$asciiarray[] = 212; $htmlarray[] = "&#212;";
$asciiarray[] = 213; $htmlarray[] = "&#213;";
$asciiarray[] = 214; $htmlarray[] = "&#214;";
$asciiarray[] = 215; $htmlarray[] = "&#215;";
$asciiarray[] = 216; $htmlarray[] = "&#216;";
$asciiarray[] = 217; $htmlarray[] = "&#217;";
$asciiarray[] = 218; $htmlarray[] = "&#218;";
$asciiarray[] = 219; $htmlarray[] = "&#219;";
$asciiarray[] = 220; $htmlarray[] = "&#220;";
$asciiarray[] = 221; $htmlarray[] = "&#221;";
$asciiarray[] = 222; $htmlarray[] = "&#222;";
$asciiarray[] = 223; $htmlarray[] = "&#223;";
$asciiarray[] = 224; $htmlarray[] = "&#224;";
$asciiarray[] = 225; $htmlarray[] = "&#225;";
$asciiarray[] = 226; $htmlarray[] = "&#226;";
$asciiarray[] = 227; $htmlarray[] = "&#227;";
$asciiarray[] = 228; $htmlarray[] = "&#228;";
$asciiarray[] = 229; $htmlarray[] = "&#229;";
$asciiarray[] = 230; $htmlarray[] = "&#230;";
$asciiarray[] = 231; $htmlarray[] = "&#231;";
$asciiarray[] = 232; $htmlarray[] = "&#232;";
$asciiarray[] = 233; $htmlarray[] = "&#233;";
$asciiarray[] = 234; $htmlarray[] = "&#234;";
$asciiarray[] = 235; $htmlarray[] = "&#235;";
$asciiarray[] = 236; $htmlarray[] = "&#236;";
$asciiarray[] = 237; $htmlarray[] = "&#237;";
$asciiarray[] = 238; $htmlarray[] = "&#238;";
$asciiarray[] = 239; $htmlarray[] = "&#239;";
$asciiarray[] = 240; $htmlarray[] = "&#240;";
$asciiarray[] = 241; $htmlarray[] = "&#241;";
$asciiarray[] = 242; $htmlarray[] = "&#242;";
$asciiarray[] = 243; $htmlarray[] = "&#243;";
$asciiarray[] = 244; $htmlarray[] = "&#244;";
$asciiarray[] = 245; $htmlarray[] = "&#245;";
$asciiarray[] = 246; $htmlarray[] = "&#246;";
$asciiarray[] = 247; $htmlarray[] = "&#247;";
$asciiarray[] = 248; $htmlarray[] = "&#248;";
$asciiarray[] = 249; $htmlarray[] = "&#249;";
$asciiarray[] = 250; $htmlarray[] = "&#250;";
$asciiarray[] = 251; $htmlarray[] = "&#251;";
$asciiarray[] = 252; $htmlarray[] = "&#252;";
$asciiarray[] = 253; $htmlarray[] = "&#253;";
$asciiarray[] = 254; $htmlarray[] = "&#254;";
$asciiarray[] = 255; $htmlarray[] = "&#255;";
 
$i = 0;
while ($i < sizeof ($asciiarray)){
$string = str_replace(chr($asciiarray[$i]), $htmlarray[$i], $string);
$i++;
}
return $string;
 
}
 
/*
*
* load_translation_file()
* Loads the translation files during initialization
*
*/
public static function load_translation_file()
{
if (is_admin()) {
$plugin_path = dirname(plugin_basename(__FILE__)).'/lang';
load_plugin_textdomain('WPSupersized',false,$plugin_path);
}
}
 
/**
* Tests if any of a post's assigned categories are descendants of target categories
*
* @param int|array $cats The target categories. Integer ID or array of integer IDs
* @param int|object $_post The post. Omit to test the current post in the Loop or main query
* @return bool True if at least 1 of the post's categories is a descendant of any of the target
categories
* @see get_term_by() You can get a category by name or slug, then pass ID to this function
* @uses get_term_children() Passes $cats
* @uses in_category() Passes $_post (can be empty)
* @version 2.7
*/
public static function post_is_in_descendant_category( $cats, $_post = null )
{
foreach ( (array) $cats as $cat ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children( (int) $cat, 'category' );
if ( $descendants && in_category( $descendants, $_post ) )
return true;
}
return false;
}
 
}
endif;
 
/**
* class WPSupersized_Test
*
* Basic version testing (at installation).
*/
if ( !class_exists('WPSupersized_Test') ):
class WPSupersized_Test
{
/**
* min_php_version
*
* Test that your PHP version is at least that of the $min_php_version.
* @param $min_php_version string representing the minimum required version of PHP, e.g. '5.3.2'
* @param $plugin_name string Name of the plugin for messaging purposes.
* @return none Exit with messaging if PHP version is too old.
*/
static function min_php_version($min_php_version, $plugin_name) {
$exit_msg = "The $plugin_name plugin requires PHP $min_php_version or newer. Contact your system administrator about updating your version of PHP";
if (version_compare( phpversion(),$min_php_version,'<'))
{
exit ($exit_msg);
}
}
/**
* Checks that the current version of WordPress is current enough.
*
* @return none exit on fail.
*/
static function min_wordpress_version($min_wordpress_version, $plugin_name) {
global $wp_version;
$exit_msg = __("The $plugin_name plugin requires WordPress $min_wordpress_version or newer.
<a href='http://codex.wordpress.org/Upgrading_WordPress'>Please update!</a>");
if (version_compare($wp_version,$min_wordpress_version,'<'))
{
exit ($exit_msg);
}
}
}
endif;
 
/**
* class WPSupersized_Metabox
*
* Takes care of the metabox for WP Supersized options in the page/post admin.
*
*/
 
if ( !class_exists('WPSupersized_Metabox') ):
class WPSupersized_Metabox
{
private $displaySupersizedDir;
/*
* custom_meta_box
*
* Creates a custom meta box in the page/post admin to allow the user to select which source of images he/she wants to use
*
*/
function custom_meta_box() {
$postType = array ('post', 'page');
foreach ($postType as $type) {
add_meta_box(
'wpsupersized_custom_meta_box', // $id
'WP Supersized source of images', // $title
array('WPSupersized_Metabox','generate_metabox_content'), // $callback
$type, // $page
'normal', // $context
'high'); // $priority
}
}
/*
*
* generate_metabox_content()
*
* Generates the WP Supersized metabox content
*
*/
function generate_metabox_content() {
 
$testDir = new WPSupersized_Metabox(); // $testDir is initialized as a class-limited global variable
global $post;
wp_nonce_field(basename(__FILE__), 'custom_meta_box_nonce');
$supersizedDir = get_post_meta($post->ID, 'SupersizedDir', true);
$testDir->displaySupersizedDir = $supersizedDir;
if (strtolower($supersizedDir) == 'wp-gallery' || strtolower($supersizedDir) == 'wpgallery' || strtolower($supersizedDir) == 'wp_gallery') $supersizedDir = 'wp-gallery';
if (strtolower($supersizedDir) == 'ngg-gallery' || strtolower($supersizedDir) == 'ngggallery' || strtolower($supersizedDir) == 'ngg_gallery') $supersizedDir = 'ngg-gallery';
$supersizedNextGenGallery = get_post_meta($post->ID, 'SupersizedNextGenGallery', true);
echo '<table class="form-table">';
echo '<tr><th><label for="SupersizedSource">Origin of WP Supersized images</label></th><td>';
echo '<input type="radio" name="SZSource" id="SZSource" value="none" ',$supersizedDir == '' ? ' checked="checked"' : '',' /> <label for"SupersizedDir">None (leaves the general options intact. This page/post will have a background slideshow only if you defined it in the <a href="'.get_admin_url().'/options-general.php?page=wp-supersized&tab=origin">WP Supersized options</a>).</label><br />';
echo '<input type="radio" name="SZSource" id="SZSource" value="custom" ',$supersizedDir != 'wp-gallery' && $supersizedDir != 'ngg-gallery' && $supersizedDir !='' && !WPSupersized::is_xml_file($supersizedDir) ? ' checked="checked"' : '',' /> <label for"SupersizedDir">Custom directory (select your custom directory below)</label><br />';
echo '<input type="radio" name="SZSource" id="SZSource" value="wp-gallery" ',$supersizedDir == 'wp-gallery' ? ' checked="checked"' : '',' /> <label for"SupersizedDir">WP Media Gallery (images from the WP Media gallery attached to this page/post will be used)</label><br />';
echo '<input type="radio" name="SZSource" id="SZSource" value="ngg-gallery" ',$supersizedDir == 'ngg-gallery' ? ' checked="checked"' : '',' /> <label for"SupersizedDir">NextGEN Gallery (images from the NextGEN gallery that you choose below will be used)</label><br />';
echo '<input type="radio" name="SZSource" id="SZSource" value="xml" ', WPSupersized::is_xml_file($supersizedDir) == true ? ' checked="checked"' : '',' /> <label for"SupersizedDir">XML file (enter below the path to your xml file)</label><br />';
echo '</td></tr>';
echo '<tr><th><label for="SupersizedCustomDir">XML file path<br />(within wp-content)</label></th><td>';
if (!WPSupersized::is_xml_file($supersizedDir)) $testDir->displaySupersizedDir = '';
echo '<input type="text" name="SupersizedCustomDir" id="SupersizedCustomDir" value="'.$testDir->displaySupersizedDir.'" size="50" />';
echo '<br /><span class="description">Enter here your XML file path (e.g. my_wpsupersized_slides_definitions/my_slides_list_and_options.xml).</span>';
echo '</td></tr>';
echo '<tr><th><label for="SupersizedNextGenGallery">NextGEN gallery to use</label></th><td>';
if (is_plugin_active('nextgen-gallery/nggallery.php') && method_exists('nggdb','find_all_galleries')) {
echo '<select name="SupersizedNextGenGallery" id="SupersizedNextGenGallery">';
global $nggdb;
$nggGalleries = $nggdb->find_all_galleries();
if($supersizedDir != 'ngg-gallery') $testDir->displayNggSelection = 'none';
else $testDir->displayNggSelection = $supersizedNextGenGallery;
if ($supersizedDir != 'ngg-gallery') echo '<option selected="selected" value="">none</option>';
foreach ($nggGalleries as $gallery )
{
echo '<option', $testDir->displayNggSelection == $gallery->gid ? ' selected="selected"' : '', ' value="'.$gallery->gid.'">'.$gallery->name.'</option>';
}
echo '</select><br /><span class="description">Select here the NextGEN gallery that you want to use.</span>';
}
else echo '<span class="description">NextGEN Gallery does not seem to be installed.</span>';
echo '</td></tr>';
echo '<tr><th><label for ="ListFolders">Select your custom directory. Click on folder name to show contained folders.</label></th><td>';
$wpContentFolder = WP_CONTENT_DIR;
if($supersizedDir != 'wp-gallery' && $supersizedDir != 'ngg-gallery' && $supersizedDir !='' && !WPSupersized::is_xml_file($supersizedDir))
echo '<span class="description">Your currently selected custom directory is: '.content_url().'/'.$supersizedDir.'</span>';
$listFolders = self::directory_list($wpContentFolder,false,true,'.|..|.svn|cache|plugins|upgrade|themes|languages',true);
echo '<ul>';
self::display_array($listFolders, $supersizedDir);
echo '</ul>';
echo '</td></tr>';
echo '</table>'; // end table
self::output_script();
}
 
/*
*
* save_custom_meta($post_id)
*
* Saves the data in the custom field
*
*/
function save_custom_meta($post_id, $post) {
 
if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__)))
return $post_id;
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
// check permissions
$post_type = get_post_type_object($post->post_type);
if ('page' == $post_type || 'post' == $post_type) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
// save the data
$newSZSource = $_POST['SZSource'];
$oldSupersizedDir = get_post_meta($post_id, 'SupersizedDir', true);
switch ($newSZSource) {
case 'none' : $newSupersizedDir ='';
break;
case 'custom' : if(!WPSupersized::is_xml_file(trim($_POST['SupersizedCustomDir'],' /'))) {
$newSupersizedDir = trim($_POST['SupersizedCustomDir'],' /'); // removes any space or slash at the beginning or end of the path
}
else $newSupersizedDir = '';
break;
case 'wp-gallery' : $newSupersizedDir = 'wp-gallery';
break;
case 'ngg-gallery' : $newSupersizedDir = 'ngg-gallery';
break;
case 'xml' : if(WPSupersized::is_xml_file(trim($_POST['SupersizedCustomDir'],' /'))) {
$newSupersizedDir = trim($_POST['SupersizedCustomDir'],' /'); // removes any space or slash at the beginning or end of the path
}
else $newSupersizedDir = '';
}
 
if ($newSupersizedDir != $oldSupersizedDir) {
update_post_meta($post_id, 'SupersizedDir', $newSupersizedDir);
}
 
$newSupersizedNextGenGallery = $_POST['SupersizedNextGenGallery'];
$oldSupersizedNextGenGallery = get_post_meta($post_id, 'SupersizedNextGenGallery', true);
if ($newSupersizedNextGenGallery && $newSupersizedNextGenGallery != $oldSupersizedNextGenGallery) {
update_post_meta($post_id, 'SupersizedNextGenGallery', $newSupersizedNextGenGallery);
} elseif ('' == $newSupersizedNextGenGallery && $oldSupersizedNextGenGallery) {
delete_post_meta($post_id, 'SupersizedNextGenGallery', $oldSupersizedNextGenGallery);
}
}
/*
*
* display_array($listFolders, $customFolder)
* recursive display of directories contained in the array $listFolders
*
*/
function display_array($listFolders, $customFolder) {
foreach($listFolders as $key => $value) {
if(is_array($value[0]) && !empty($value[0])) {
echo '<li class="wpsztoggle"><div class="wpszbutton" style="display:inline;">'.$key.'</div>';
echo ' <input type="radio" name="SupersizedCustomDir" value="'.$value[1].'"';
if($customFolder == $value[1] ){ echo ' checked="checked" '; }
echo '></input>';
echo '</li><ul>';
self::display_array($value[0], $customFolder);
echo '</ul>';
}
else {
echo '<li>'.$key.' <input type="radio" name="SupersizedCustomDir" value="'.$value[1].'"';
if($customFolder == $value[1] ){ echo ' checked="checked" '; }
echo '></input> ';
}
echo '</li>';
}
}
/*
* directory_list($directory_base_path, $filter_dir = false, $filter_files = false, $exclude = ".|..|.DS_Store|.svn", $recursive = true)
* returns an array containing optionally all files, only directiories or only files at a file system path
* @author cgray The Metamedia Corporation www.metamedia.us
*
* @param $base_path string either absolute or relative path
* @param $filter_dir boolean Filter directories from result (ignored except in last directory if $recursive is true)
* @param $filter_files boolean Filter files from result
* @param $exclude string Pipe delimited string of files to always ignore
* @param $recursive boolean Descend directory to the bottom?
* @return $result_list array Nested array or false
* @access public
* @license GPL v3
*/
function directory_list($directory_base_path, $filter_dir = false, $filter_files = false, $exclude = ".|..|.DS_Store|.svn", $recursive = true){
$directory_base_path = rtrim($directory_base_path, "/") . "/";
 
if (!is_dir($directory_base_path)){
error_log(__FUNCTION__ . "File at: $directory_base_path is not a directory.");
return false;
}
 
$result_list = array();
$exclude_array = explode("|", $exclude);
 
if (!$folder_handle = opendir($directory_base_path)) {
// error_log(__FUNCTION__ . "Could not open directory at: $directory_base_path");
return false;
}else{
while(false !== ($filename = readdir($folder_handle))) {
if(!in_array($filename, $exclude_array)) {
if(is_dir($directory_base_path . $filename . "/")) {
if($recursive && strcmp($filename, ".")!=0 && strcmp($filename, "..")!=0 ){ // prevent infinite recursion
// error_log($directory_base_path . $filename . "/");
$result_list[$filename] = array(self::directory_list("$directory_base_path$filename/", $filter_dir, $filter_files, $exclude, $recursive), ltrim(str_replace(WP_CONTENT_DIR, '',$directory_base_path.$filename),'/'));
}elseif(!$filter_dir){
$result_list[] = array($filename, $directory_base_path.$filename);
}
}elseif(!$filter_files){
$result_list[] = array($filename, $directory_base_path.$filename);
}
}
}
closedir($folder_handle);
return $result_list;
}
}
 
/*
* Displays the folder list with interactive folder opening and content display
* Acts on the div with id wp-supersized-folder-list
* (adapted from http://www.lateralcode.com/directory-trees-with-php-and-jquery/)
*/
function output_script() {
echo '<script type="text/javascript">
jQuery(function () {
jQuery("li.wpsztoggle").next().hide();
jQuery("li.wpsztoggle").hover(function () {
jQuery(this).stop().animate({
fontSize: "17px",
paddingLeft: "10px",
color: "black"
}, 100);
}, function () {
jQuery(this).stop().animate({
fontSize: "14px",
paddingLeft: "0",
color: "#808080"
}, 100);
});
jQuery("li.wpsztoggle").css("cursor", "pointer");
jQuery("li.wpsztoggle > div.wpszbutton").prepend("+ ");
jQuery("div.wpszbutton").click(function () {
jQuery(this).parent().next().toggle(300);
var v = jQuery(this).html().substring(0, 1);
if (v == "+") jQuery(this).html("-" + jQuery(this).html().substring(1));
else if (v == "-") jQuery(this).html("+" + jQuery(this).html().substring(1));
});
});</script>';
// end of script
}
 
}
endif;
/* EOF */

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.