/wp-content/plugins/wysija-newsletters/helpers/bookmarks.php

https://gitlab.com/Gashler/sg · PHP · 113 lines · 88 code · 11 blank · 14 comment · 15 complexity · 9b638d654ffd01c641de6db49f78779d MD5 · raw file

  1. <?php
  2. defined('WYSIJA') or die('Restricted access');
  3. class WYSIJA_help_bookmarks extends WYSIJA_object {
  4. function WYSIJA_help_bookmarks() {
  5. }
  6. /**
  7. * Get all bookmarks based on size
  8. * @param string $size
  9. * @return array
  10. */
  11. function getAll($size = 'medium', $theme = 'default') {
  12. $fileHelper = WYSIJA::get('file', 'helper');
  13. $dirHandle = $fileHelper->exists('bookmarks'.DS.$size);
  14. if($dirHandle['result'] === FALSE) {
  15. return array();
  16. } else {
  17. $bookmarks = array();
  18. // if size is medium and the current theme is not default, load theme's bookmarks
  19. if($size === 'medium' and $theme !== 'default') {
  20. $themeIcons = $this->getAllByTheme($theme, 'url');
  21. if(!empty($themeIcons)) {
  22. $bookmarks['00'] = $themeIcons;
  23. }
  24. }
  25. $sourceDir = $dirHandle['file'];
  26. $iconsets = scandir($sourceDir);
  27. foreach($iconsets as $iconset) {
  28. // loop through each iconset
  29. if(in_array($iconset, array('.', '..', '.DS_Store', 'Thumbs.db')) === FALSE and is_dir($sourceDir.DS.$iconset)) {
  30. // get all icons from current iconset
  31. $icons = scandir($sourceDir.DS.$iconset);
  32. foreach($icons as $icon) {
  33. if(in_array($icon, array('.', '..', '.DS_Store', 'Thumbs.db')) === FALSE and strrpos($icon, '.txt') === FALSE) {
  34. $info = pathinfo($sourceDir.DS.$iconset.DS.$icon);
  35. $bookmarks[$iconset][basename($icon, '.'.$info['extension'])] = $fileHelper->url($icon, 'bookmarks'.DS.$size.DS.$iconset);
  36. }
  37. }
  38. }
  39. }
  40. return $bookmarks;
  41. }
  42. }
  43. /**
  44. * Get all bookmarks based on size for a given iconset
  45. * @param string $size
  46. * @param string $iconset
  47. * @return array
  48. */
  49. function getAllByIconset($size = 'medium', $iconset)
  50. {
  51. $fileHelper = WYSIJA::get('file', 'helper');
  52. $dirHandle = $fileHelper->exists('bookmarks'.DS.$size.DS.$iconset);
  53. if($dirHandle['result'] === FALSE) {
  54. return array();
  55. } else {
  56. $bookmarks = array();
  57. $sourceDir = $dirHandle['file'];
  58. $icons = scandir($sourceDir);
  59. foreach($icons as $icon) {
  60. if(in_array($icon, array('.', '..', '.DS_Store', 'Thumbs.db')) === FALSE and strrpos($icon, '.txt') === FALSE) {
  61. $info = pathinfo($sourceDir.DS.$icon);
  62. $dimensions = @getimagesize($sourceDir.DS.$icon);
  63. $bookmarks[basename($icon, '.'.$info['extension'])] = array(
  64. 'src' => $fileHelper->url($icon, 'bookmarks/'.$size.'/'.$iconset),
  65. 'width' => $dimensions[0],
  66. 'height' => $dimensions[1]
  67. );
  68. }
  69. }
  70. return $bookmarks;
  71. }
  72. }
  73. function getAllByTheme($theme, $type = 'all')
  74. {
  75. $fileHelper = WYSIJA::get('file', 'helper');
  76. $dirHandle = $fileHelper->exists('themes'.DS.$theme.DS.'bookmarks');
  77. if($dirHandle['result'] === FALSE) {
  78. return array();
  79. } else {
  80. $bookmarks = array();
  81. $sourceDir = $dirHandle['file'];
  82. $icons = scandir($sourceDir);
  83. foreach($icons as $icon) {
  84. if(in_array($icon, array('.', '..', '.DS_Store', 'Thumbs.db')) === FALSE and strrpos($icon, '.txt') === FALSE) {
  85. if($type === 'all') {
  86. $info = pathinfo($sourceDir.DS.$icon);
  87. $dimensions = @getimagesize($sourceDir.DS.$icon);
  88. $bookmarks[basename($icon, '.'.$info['extension'])] = array(
  89. 'src' => $fileHelper->url($icon, 'themes/'.$theme.'/bookmarks'),
  90. 'width' => $dimensions[0],
  91. 'height' => $dimensions[1]
  92. );
  93. } else if($type === 'url') {
  94. $info = pathinfo($sourceDir.DS.$icon);
  95. $bookmarks[basename($icon, '.'.$info['extension'])] = $fileHelper->url($icon, 'themes/'.$theme.'/bookmarks');
  96. }
  97. }
  98. }
  99. return $bookmarks;
  100. }
  101. }
  102. }