PageRenderTime 41ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/LayerSlider/classes/class.ls.sources.php

https://gitlab.com/webkod3r/tripolis
PHP | 253 lines | 160 code | 34 blank | 59 comment | 9 complexity | 8be401b6dd5be16f4346e760a7c5fe3d MD5 | raw file
  1. <?php
  2. class LS_Sources {
  3. // handle => path
  4. public static $skins = array();
  5. public static $sliders = array();
  6. public static $transitions = array();
  7. private function __construct() {
  8. }
  9. /**
  10. * Adds the skins from the directory provided, so
  11. * users can select them in the slider settings.
  12. *
  13. * @since 5.3.0
  14. * @access public
  15. * @param string $path Path to directory that holds your skins. It's assumed to be a direct skin folder if it contains a skin.css file.
  16. * @return void
  17. */
  18. public static function addSkins($path) {
  19. $skinsPath = $skins = array();
  20. $path = rtrim($path, '/\\');
  21. // It's a direct skin folder
  22. if(file_exists($path.'/skin.css')) {
  23. $skinsPath = array($path);
  24. } else { // Get all children if it's a parent directory
  25. $skinsPath = glob($path.'/*', GLOB_ONLYDIR);
  26. }
  27. // Iterate over the skins
  28. foreach($skinsPath as $key => $path) {
  29. // Exclude non-valid skins
  30. if( !file_exists($path.'/skin.css') ) { continue; }
  31. // Gather skin data
  32. $handle = strtolower(basename($path));
  33. $skins[$handle] = array(
  34. 'name' => $handle,
  35. 'handle' => $handle,
  36. 'dir' => $path,
  37. 'file' => $path.DIRECTORY_SEPARATOR.'skin.css'
  38. );
  39. // Get skin info (if any)
  40. if(file_exists($path.'/info.json')) {
  41. $skins[$handle]['info'] = json_decode(file_get_contents($path.'/info.json'), true);
  42. $skins[$handle]['name'] = $skins[$handle]['info']['name'];
  43. }
  44. }
  45. self::$skins = array_merge(self::$skins, $skins);
  46. ksort( self::$skins );
  47. }
  48. /**
  49. * Removes a previously added skin by its folder name as being $handle.
  50. *
  51. * @since 5.3.0
  52. * @access public
  53. * @param string $skin The name of the skin/folder
  54. * @return void
  55. */
  56. public static function removeSkin($handle) {
  57. unset( self::$skins[ strtolower($handle) ] );
  58. }
  59. /**
  60. * Returns skin information by its folder name as being $handle.
  61. *
  62. * @since 5.3.0
  63. * @access public
  64. * @param string $skin The name of the skin/folder
  65. * @return array Skin details
  66. */
  67. public static function getSkin($handle) {
  68. return self::$skins[ strtolower($handle) ];
  69. }
  70. /**
  71. * Returns all skins.
  72. *
  73. * @since 5.3.0
  74. * @access public
  75. * @return array Array of all skins
  76. */
  77. public static function getSkins() {
  78. return self::$skins;
  79. }
  80. /**
  81. * Returns the directory path of a skin by its folder name as being $handle
  82. *
  83. * @since 5.3.0
  84. * @access public
  85. * @param string $skin The name of the skin/folder
  86. * @return string Path for the skin's directory
  87. */
  88. public static function pathForSkin($handle) {
  89. return self::$skins[ strtolower($handle) ]['dir'] . DIRECTORY_SEPARATOR;
  90. }
  91. /**
  92. * Returns the directory path of a skin by its folder name as being $handle
  93. *
  94. * @since 5.3.0
  95. * @access public
  96. * @param string $skin The name of the skin/folder
  97. * @return string URL for the skin's directory
  98. */
  99. public static function urlForSkin($handle) {
  100. $path = self::$skins[ strtolower($handle) ]['dir'];
  101. $url = content_url() . str_replace(realpath(WP_CONTENT_DIR), '', $path).'/';
  102. return str_replace('\\', '/', $url);
  103. }
  104. // ---------------------------------------------
  105. /**
  106. * Adds an exported ZIP to the list of importable sample sliders.
  107. *
  108. * @since 5.3.0
  109. * @access public
  110. * @param string $path Path to the .zip file
  111. * @return void
  112. */
  113. public static function addDemoSlider( $path ) {
  114. $slidersPath = $sliders = array();
  115. $path = rtrim($path, '/\\');
  116. // It's a direct slider folder
  117. if(file_exists($path.'/slider.zip')) {
  118. $slidersPath = array($path);
  119. } else { // Get all children if it's a parent directory
  120. $slidersPath = glob($path.'/*', GLOB_ONLYDIR);
  121. }
  122. // Iterate over the sliders
  123. foreach($slidersPath as $key => $path) {
  124. // Exclude non-valid demo sliders
  125. if( !file_exists($path.'/slider.zip') ) { continue; }
  126. // Gather slider data
  127. $handle = strtolower(basename($path));
  128. $sliders[$handle] = array(
  129. 'name' => $handle,
  130. 'handle' => $handle,
  131. 'dir' => $path,
  132. 'file' => $path.DIRECTORY_SEPARATOR.'slider.zip'
  133. );
  134. // Get skin info (if any)
  135. if(file_exists($path.'/info.json')) {
  136. $sliders[$handle]['info'] = json_decode(file_get_contents($path.'/info.json'), true);
  137. $sliders[$handle]['name'] = $sliders[$handle]['info']['name'];
  138. }
  139. // Get preview (if any)
  140. if(file_exists($path.'/preview.png')) {
  141. $url = content_url() . str_replace(realpath(WP_CONTENT_DIR), '', $path).'/preview.png';
  142. $sliders[$handle]['preview'] = str_replace('\\', '/', $url);
  143. }
  144. }
  145. self::$sliders = array_merge(self::$sliders, $sliders);
  146. ksort( self::$sliders );
  147. }
  148. /**
  149. * Removes a previously added demo slider export by its folder name as being $handle
  150. *
  151. * @since 5.3.0
  152. * @access public
  153. * @param string $path Path to the .zip file
  154. * @return void
  155. */
  156. public static function removeDemoSlider( $handle ) {
  157. unset( self::$sliders[ strtolower($handle) ] );
  158. }
  159. /**
  160. * Retrieves a previously added demo slider by its folder name as being $handle
  161. *
  162. * @since 5.3.0
  163. * @access public
  164. * @param string $path Path to the .zip file
  165. * @return array Array of previously added demo slider paths
  166. */
  167. public static function getDemoSlider( $handle ) {
  168. return self::$sliders[ strtolower($handle) ];
  169. }
  170. /**
  171. * Retrieves all demo sliders added previously.
  172. *
  173. * @since 5.3.0
  174. * @access public
  175. * @param string $path Path to the .zip file
  176. * @return array Array of previously added demo slider paths
  177. */
  178. public static function getDemoSliders() {
  179. return self::$sliders;
  180. }
  181. /**
  182. * Returns the directory path of a previously added demo slider export by its folder name as being $handle
  183. *
  184. * @since 5.3.0
  185. * @access public
  186. * @param string $path Path to the .zip file
  187. * @return string Path to the .zip file
  188. */
  189. public static function pathForDemoSlider( $handle ) {
  190. return self::$sliders[ strtolower($handle) ]['dir'] . DIRECTORY_SEPARATOR;
  191. }
  192. // ---------------------------------------------
  193. }
  194. ?>