Mixin_Fs_Instance_Methods

The NextGEN Gallery Mixin Fs Instance Methods class.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/fs/package.module.fs.php  
  1. class Mixin_Fs_Instance_Methods extends Mixin 
  2. function add_trailing_slash($path) 
  3. return rtrim($path, "/\\") . DIRECTORY_SEPARATOR; 
  4. /** 
  5. * Returns a calculated path to a file 
  6. * @param string $path 
  7. * @param string $module 
  8. * @param boolean $relpath 
  9. * @returns string 
  10. */ 
  11. function get_abspath($path, $module = FALSE, $relpath = FALSE) 
  12. // Wel'l assume that we're to calculate the path relative to 
  13. // the site document root 
  14. $retval = $path; 
  15. if (strpos($path, $this->get_document_root()) === FALSE) { 
  16. $retval = $this->join_paths($this->get_document_root(), $path); 
  17. // If a module is provided, then we should calculate the path 
  18. // relative to the module directory 
  19. if ($module) { 
  20. if ($module_dir = $this->get_registry()->get_module_dir($module)) { 
  21. $retval = $this->join_paths($module_dir, $path); 
  22. } else { 
  23. $retval = $this->join_path($this->get_document_root(), $module, $path); 
  24. // Return the calculated path relative to the document root 
  25. if ($relpath) { 
  26. $retval = $this->object->remove_path_segment($retval, $this->get_document_root()); 
  27. return $retval; 
  28. /** 
  29. * Returns a calculated relpath to a particular file 
  30. * @param string $path 
  31. * @param string $module 
  32. * @return string 
  33. */ 
  34. function get_relpath($path, $module = FALSE) 
  35. return $this->object->get_abspath($path, $module, TRUE); 
  36. /** 
  37. * Removes a path segment from a url or filesystem path 
  38. * @param string $path 
  39. * @param string $segment 
  40. * @return string 
  41. */ 
  42. function remove_path_segment($path, $segment) 
  43. $parts = explode($segment, rtrim($path, "/\\")); 
  44. return $this->join_paths($parts); 
  45. /** 
  46. * Gets the absolute path to a file/directory for a specific Pope product 
  47. * If the path doesn't exist, then NULL is returned 
  48. * @param string $path 
  49. * @param string $module 
  50. * @returns string|NULL 
  51. */ 
  52. function find_abspath($path, $module = FALSE, $relpath = FALSE, $search_paths = array()) 
  53. $retval = NULL; 
  54. // Ensure that we weren't passed a module id in the path 
  55. if (!$module) { 
  56. list($path, $module) = $this->object->parse_formatted_path($path); 
  57. if (@file_exists($path)) { 
  58. $retval = $path; 
  59. } else { 
  60. // Ensure that we know where to search for the file 
  61. if (!$search_paths) { 
  62. $search_paths = $this->object->get_search_paths($path, $module); 
  63. // See if the file is located under one of the search paths directly 
  64. foreach ($search_paths as $dir) { 
  65. if (@file_exists($this->join_paths($dir, $path))) { 
  66. $retval = $this->join_paths($dir, $path); 
  67. break; 
  68. // Use rglob to find the file 
  69. if (!$retval) { 
  70. foreach ($search_paths as $dir) { 
  71. if ($retval = $this->object->_rglob($dir, $path)) { 
  72. break; 
  73. // Return the relative path if we're to do so 
  74. if ($relpath) { 
  75. $retval = $this->object->remove_path_segment($retval, $this->get_document_root()); 
  76. return $retval; 
  77. /** 
  78. * Returns a list of directories to search for a particular filename 
  79. * @param string $path 
  80. * @param string $module 
  81. * @return array 
  82. */ 
  83. function get_search_paths($path, $module = FALSE) 
  84. $append_module = FALSE; 
  85. // Ensure that we weren't passed a module id in the path 
  86. if (!$module) { 
  87. list($path, $module) = $this->object->parse_formatted_path($path); 
  88. // Directories to search 
  89. $directories = array(); 
  90. // If a name of a module has been provided, then we need to search within 
  91. // that directory first 
  92. if ($module) { 
  93. // Were we given a module id? 
  94. if ($module_dir = $this->get_registry()->get_module_dir($module)) { 
  95. $directories[] = $module_dir; 
  96. } else { 
  97. $append_module = TRUE; 
  98. // Add product's module directories 
  99. foreach ($this->get_registry()->get_product_list() as $product_id) { 
  100. $product_dir = $this->get_registry()->get_product_module_path($product_id); 
  101. if ($append_module) { 
  102. $directories[] = $this->join_paths($product_dir, $module); 
  103. $directories[] = $product_dir; 
  104. // If all else fails, we search from the document root 
  105. $directories[] = $this->get_document_root(); 
  106. return $directories; 
  107. /** 
  108. * Searches for a file recursively 
  109. * @param string $base_path 
  110. * @param string $file 
  111. * @return string 
  112. */ 
  113. function _rglob($base_path, $file) 
  114. $retval = NULL; 
  115. $results = @file_exists($this->join_paths($base_path, $file)); 
  116. // Must be located in a sub-directory 
  117. if (!$results) { 
  118. // the modules cache a list of all their files when they are initialized. Ask POPE for our current 
  119. // modules and inspect their file listing to determine which module provides what we need 
  120. $modules = $this->object->get_registry()->get_module_list(); 
  121. foreach ($modules as $module) { 
  122. $module_file_list = array_values($this->object->get_registry()->get_module($module)->get_type_list()); 
  123. $module_dir = $this->object->get_registry()->get_module_dir($module); 
  124. $variations = array($file, ltrim($file, DIRECTORY_SEPARATOR)); 
  125. foreach ($variations as $variant) { 
  126. if (in_array($variant, $module_file_list)) { 
  127. $retval = $this->join_paths($module_dir, $variant); 
  128. break 2; 
  129. } else { 
  130. $retval = $this->join_paths($base_path, $file); 
  131. return $retval; 
  132. /** 
  133. * Gets the relative path to a file/directory for a specific Pope product. 
  134. * If the path doesn't exist, then NULL is returned 
  135. * @param type $path 
  136. * @param type $module 
  137. * @returns string|NULL 
  138. */ 
  139. function find_relpath($path, $module = FALSE) 
  140. return $this->object->find_abspath($path, $module, TRUE); 
  141. function delete($abspath) 
  142. $retval = FALSE; 
  143. if (file_exists($abspath)) { 
  144. // Delete single file 
  145. if (is_file($abspath)) { 
  146. @unlink($abspath); 
  147. } else { 
  148. foreach (scandir($abspath) as $relpath) { 
  149. if (in_array($relpath, array('.', '..'))) { 
  150. continue; 
  151. $sub_abspath = $this->join_paths($abspath, $relpath); 
  152. $this->object->delete($sub_abspath); 
  153. $retval = !file_exists($abspath); 
  154. return $retval; 
  155. /** 
  156. * Joins multiple path segments together 
  157. * @return string 
  158. */ 
  159. function join_paths() 
  160. $segments = array(); 
  161. $retval = array(); 
  162. $protocol = NULL; 
  163. $params = func_get_args(); 
  164. $this->_flatten_array($params, $segments); 
  165. foreach ($segments as $segment) { 
  166. $segment = trim($segment, "/\\"); 
  167. $pieces = array_values(preg_split('#[/\\\\]#', $segment)); 
  168. // determine if each piece should be appended to $retval 
  169. foreach ($pieces as $ndx => $val) { 
  170. if ($val === '') { 
  171. continue; 
  172. $one = array_search($val, $retval); 
  173. $two = array_search($val, $pieces); 
  174. $one = FALSE === $one ? 0 : count($one) + 1; 
  175. $two = FALSE === $two ? 0 : count($two) + 1; 
  176. if (!empty($protocol)) { 
  177. $existing_val = isset($retval[$ndx]) ? $retval[$ndx] : NULL; 
  178. if ($existing_val !== $val || $two >= $one) { 
  179. $retval[] = $val; 
  180. } else { 
  181. $existing_val = isset($retval[$ndx]) ? $retval[$ndx] : NULL; 
  182. if ($existing_val !== $val && $two >= $one) { 
  183. $retval[] = $val; 
  184. // Join the paths together 
  185. $retval = implode(DIRECTORY_SEPARATOR, $retval); 
  186. if (strpos($retval, $this->get_document_root()) !== 0 && strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { 
  187. $retval = DIRECTORY_SEPARATOR . trim($retval, "/\\"); 
  188. // Check for and adjust Windows UNC paths (\\server\share\) for network mounted sites 
  189. if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && substr($this->get_document_root(), 0, 2) === '\\\\') { 
  190. $retval = '\\\\' . $retval; 
  191. return $retval; 
  192. function _flatten_array($obj, &$arr) 
  193. if (is_array($obj)) { 
  194. foreach ($obj as $inner_obj) { 
  195. $this->_flatten_array($inner_obj, $arr); 
  196. } elseif ($obj) { 
  197. $arr[] = $obj; 
  198. /** 
  199. * Parses the path for a module and filename 
  200. * @param string $str 
  201. */ 
  202. function parse_formatted_path($str) 
  203. $module = FALSE; 
  204. $path = $str; 
  205. $parts = explode('#', $path); 
  206. if (count($parts) > 1) { 
  207. $module = array_shift($parts); 
  208. $path = array_shift($parts); 
  209. return array($path, $module); 
  210. /** 
  211. * Gets the document root for this application 
  212. * @return string 
  213. */ 
  214. function get_document_root($type = 'root') 
  215. $retval = NULL; 
  216. switch ($type) { 
  217. case 'plugins': 
  218. case 'plugin': 
  219. $retval = WP_PLUGIN_DIR; 
  220. break; 
  221. case 'plugins_mu': 
  222. case 'plugin_mu': 
  223. $retval = WPMU_PLUGIN_DIR; 
  224. break; 
  225. case 'templates': 
  226. case 'template': 
  227. case 'themes': 
  228. case 'theme': 
  229. $retval = get_template_directory(); 
  230. break; 
  231. case 'styles': 
  232. case 'style': 
  233. case 'stylesheets': 
  234. case 'stylesheet': 
  235. $retval = get_stylesheet_directory(); 
  236. break; 
  237. case 'content': 
  238. $retval = WP_CONTENT_DIR; 
  239. break; 
  240. case 'gallery': 
  241. case 'galleries': 
  242. $root_type = defined('NGG_GALLERY_ROOT_TYPE') ? NGG_GALLERY_ROOT_TYPE : 'site'; 
  243. if ($root_type == 'content') { 
  244. $retval = WP_CONTENT_DIR; 
  245. } else { 
  246. $retval = $this->_document_root; 
  247. break; 
  248. default: 
  249. $retval = $this->_document_root; 
  250. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 
  251. $retval = str_replace('/', DIRECTORY_SEPARATOR, $retval); 
  252. return $retval; 
  253. /** 
  254. * Sets the document root for this application 
  255. * @param type $value 
  256. * @return type 
  257. */ 
  258. function set_document_root($value) 
  259. // some web servers like home.pl and PhpStorm put the document root in "/" or (even weirder) "//" 
  260. if ($value == DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) { 
  261. $value = DIRECTORY_SEPARATOR; 
  262. if ($value !== DIRECTORY_SEPARATOR) { 
  263. $value = rtrim($value, "/\\"); 
  264. return $this->_document_root = $value;