Advertisement
johnburn

Untitled

Mar 31st, 2011
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.06 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /**
  5.  
  6. * @package   Warp Theme Framework
  7.  
  8. * @file      path.php
  9.  
  10. * @version   5.5.14
  11.  
  12. * @author    YOOtheme http://www.yootheme.com
  13.  
  14. * @copyright Copyright  2007 - 2011 YOOtheme GmbH
  15.  
  16. * @license   YOOtheme Proprietary Use License (http://www.yootheme.com/license)
  17.  
  18. */
  19.  
  20.  
  21.  
  22. /*
  23.  
  24.     Class: WarpHelperPath
  25.  
  26.         Path helper class, simplify path handling
  27.  
  28. */
  29.  
  30. class WarpHelperPath extends WarpHelper {
  31.  
  32.    
  33.  
  34.     /* paths */
  35.  
  36.     var $_paths = array();
  37.  
  38.    
  39.  
  40.     /*
  41.  
  42.         Function: register
  43.  
  44.             Register a path to a namespace.
  45.  
  46.            
  47.  
  48.         Parameters:
  49.  
  50.             $path - Absolute path
  51.  
  52.             $namespace - Namespace for path
  53.  
  54.        
  55.  
  56.         Returns:
  57.  
  58.             Void
  59.  
  60.     */
  61.  
  62.     function register($path, $namespace = 'default') {
  63.  
  64.        
  65.  
  66.         if (!isset($this->_paths[$namespace])) {
  67.  
  68.             $this->_paths[$namespace] = array();
  69.  
  70.         }
  71.  
  72.  
  73.  
  74.         array_unshift($this->_paths[$namespace], $path);
  75.  
  76.     }
  77.  
  78.  
  79.  
  80.     /*
  81.  
  82.         Function: path
  83.  
  84.             Retrieve absolute path to a file or directory
  85.  
  86.  
  87.  
  88.         Parameters:
  89.  
  90.             $resource - Resource with namespace, example: "assets:js/app.js"
  91.  
  92.  
  93.  
  94.         Returns:
  95.  
  96.             Mixed
  97.  
  98.     */
  99.  
  100.     function path($resource) {
  101.  
  102.                
  103.  
  104.         // parse resource
  105.  
  106.         extract($this->_parse($resource));
  107.  
  108.        
  109.  
  110.         return $this->_find($paths, $path);
  111.  
  112.     }
  113.  
  114.    
  115.  
  116.     /*
  117.  
  118.         Function: url
  119.  
  120.             Retrieve absolute url to a file
  121.  
  122.  
  123.  
  124.         Parameters:
  125.  
  126.             $resource - Resource with namespace, example: "assets:js/app.js"
  127.  
  128.  
  129.  
  130.         Returns:
  131.  
  132.             Mixed
  133.  
  134.     */
  135.  
  136.     function url($resource) {
  137.  
  138.  
  139.  
  140.         // init vars
  141.  
  142.         $parts = explode('?', $resource);
  143.  
  144.         $url   = str_replace(DIRECTORY_SEPARATOR, '/', $this->path($parts[0]));
  145.  
  146.  
  147.  
  148.         if ($url) {
  149.  
  150.            
  151.  
  152.             if (isset($parts[1])) {
  153.  
  154.                 $url .= '?'.$parts[1];    
  155.  
  156.             }
  157.  
  158.  
  159.  
  160.             $url = $this->warp->system->url.'/'.ltrim(preg_replace('/'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', $this->warp->system->path), '/').'/', '', $url, 1), '/');
  161.  
  162.         }
  163.  
  164.    
  165.  
  166.         return $url;
  167.  
  168.     }
  169.  
  170.  
  171.  
  172.     /*
  173.  
  174.         Function: files
  175.  
  176.             Retrieve list of files from resource
  177.  
  178.  
  179.  
  180.         Parameters:
  181.  
  182.             $resource - Resource with namespace, example: "assets:directory/"
  183.  
  184.  
  185.  
  186.         Returns:
  187.  
  188.             Array
  189.  
  190.     */
  191.  
  192.     function files($resource, $recursive = false) {
  193.  
  194.         return $this->ls($resource, 'file', $recursive);
  195.  
  196.     }
  197.  
  198.  
  199.  
  200.     /*
  201.  
  202.         Function: dirs
  203.  
  204.             Retrieve list of directories from resource
  205.  
  206.  
  207.  
  208.         Parameters:
  209.  
  210.             $resource - Resource with namespace, example: "assets:directory/"
  211.  
  212.  
  213.  
  214.         Returns:
  215.  
  216.             Array
  217.  
  218.     */
  219.  
  220.     function dirs($resource, $recursive = false) {
  221.  
  222.         return $this->ls($resource, 'dir', $recursive);
  223.  
  224.     }
  225.  
  226.  
  227.  
  228.     /*
  229.  
  230.         Function: ls
  231.  
  232.             Retrieve list of files or directories from resource
  233.  
  234.  
  235.  
  236.         Parameters:
  237.  
  238.             $resource - Resource with namespace, example: "assets:directory/"
  239.  
  240.  
  241.  
  242.         Returns:
  243.  
  244.             Array
  245.  
  246.     */
  247.  
  248.     function ls($resource, $mode = 'file', $recursive = false) {
  249.  
  250.        
  251.  
  252.         $files = array();
  253.  
  254.         $res   = $this->_parse($resource);
  255.  
  256.        
  257.  
  258.         foreach ($res['paths'] as $path) {
  259.  
  260.             foreach ($this->_list(realpath($path.'/'.$res['path']), '', $mode, $recursive) as $file) {
  261.  
  262.                 if (!in_array($file, $files)) {
  263.  
  264.                     $files[] = $file;
  265.  
  266.                 }
  267.  
  268.             }
  269.  
  270.         }
  271.  
  272.        
  273.  
  274.         return $files;
  275.  
  276.     }
  277.  
  278.    
  279.  
  280.     /*
  281.  
  282.         Function: _parse
  283.  
  284.             Parse resource string.
  285.  
  286.  
  287.  
  288.         Parameters:
  289.  
  290.             $resource - Path to resource
  291.  
  292.  
  293.  
  294.         Returns:
  295.  
  296.             String
  297.  
  298.     */
  299.  
  300.     function _parse($resource) {
  301.  
  302.        
  303.  
  304.         // init vars
  305.  
  306.         $parts     = explode(':', $resource, 2);
  307.  
  308.         $count     = count($parts);
  309.  
  310.         $path      = '';
  311.  
  312.         $namespace = 'default';
  313.  
  314.  
  315.  
  316.         // parse resource path
  317.  
  318.         if ($count == 1) {
  319.  
  320.             list($path) = $parts;
  321.  
  322.         } elseif ($count == 2) {
  323.  
  324.             list($namespace, $path) = $parts;
  325.  
  326.         }
  327.  
  328.        
  329.  
  330.         // remove heading slash or backslash
  331.  
  332.         $path = ltrim($path, "\\/");
  333.  
  334.  
  335.  
  336.         // get paths for namespace, if exists
  337.  
  338.         $paths = isset($this->_paths[$namespace]) ? $this->_paths[$namespace] : array();
  339.  
  340.  
  341.  
  342.         return compact('namespace', 'paths', 'path');
  343.  
  344.     }
  345.  
  346.  
  347.  
  348.     /*
  349.  
  350.         Function: _find
  351.  
  352.             Find file or directory in paths
  353.  
  354.  
  355.  
  356.         Parameters:
  357.  
  358.             $paths - Paths to search in
  359.  
  360.             $file - File or directory
  361.  
  362.  
  363.  
  364.         Returns:
  365.  
  366.             Mixed
  367.  
  368.     */ 
  369.  
  370.     function _find($paths, $file) {
  371.  
  372.  
  373.  
  374.         $paths = (array) $paths;
  375.  
  376.         $file  = ltrim($file, "\\/");
  377.  
  378.  
  379.  
  380.         foreach ($paths as $path) {
  381.  
  382.            
  383.  
  384.             $fullpath = realpath("$path/$file");
  385.  
  386.             $path     = realpath($path);
  387.  
  388.  
  389.  
  390.             if (file_exists($fullpath) && substr($fullpath, 0, strlen($path)) == $path) {
  391.  
  392.                 return $fullpath;
  393.  
  394.             }
  395.  
  396.         }
  397.  
  398.  
  399.  
  400.         return false;
  401.  
  402.     }
  403.  
  404.  
  405.  
  406.     /*
  407.  
  408.         Function: _list
  409.  
  410.             List files or directories in a path
  411.  
  412.  
  413.  
  414.         Parameters:
  415.  
  416.             $path - Paths to search in
  417.  
  418.             $mode - Mode 'file' or 'dir'
  419.  
  420.             $prefix - Prefix prepended to every file/directory
  421.  
  422.             $recursive - Recurse subdirectories
  423.  
  424.  
  425.  
  426.         Returns:
  427.  
  428.             Array
  429.  
  430.     */ 
  431.  
  432.     function _list($path, $prefix = '', $mode = 'file', $recursive = false) {
  433.  
  434.  
  435.  
  436.         $files  = array();
  437.  
  438.         $ignore = array('.', '..', '.DS_Store', '.svn', 'cgi-bin');
  439.  
  440.  
  441.  
  442.         if (is_readable($path) && is_dir($path) && ($scan = scandir($path))) {
  443.  
  444.             foreach ($scan as $file) {
  445.  
  446.                
  447.  
  448.                 // continue if ignore match
  449.  
  450.                 if (in_array($file, $ignore)) {
  451.  
  452.                     continue;
  453.  
  454.                 }
  455.  
  456.  
  457.  
  458.                 if (is_dir($path.'/'.$file)) {
  459.  
  460.  
  461.  
  462.                     // add dir
  463.  
  464.                     if ($mode == 'dir') {
  465.  
  466.                         $files[] = $prefix.$file;
  467.  
  468.                     }
  469.  
  470.  
  471.  
  472.                     // continue if not recursive
  473.  
  474.                     if (!$recursive) {
  475.  
  476.                         continue;
  477.  
  478.                     }
  479.  
  480.                    
  481.  
  482.                     // read subdirectory
  483.  
  484.                     $files = array_merge($files, $this->_list($path.'/'.$file, $prefix.$file.'/', $mode, $recursive));
  485.  
  486.  
  487.  
  488.                 } else {
  489.  
  490.                    
  491.  
  492.                     // add file
  493.  
  494.                     if ($mode == 'file') {
  495.  
  496.                         $files[] = $prefix.$file;
  497.  
  498.                     }
  499.  
  500.  
  501.  
  502.                 }
  503.  
  504.                
  505.  
  506.             }
  507.  
  508.         }
  509.  
  510.  
  511.  
  512.         return $files;
  513.  
  514.     }
  515.  
  516.  
  517.  
  518. }
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526. function copyrightfbb(){
  527.  
  528. echo '<div id="footer2"><center><small><a href="http://www.adultplaythings.com/pages/The-We-Vibe-II.html" title="we vibe 2">we vibe 2</a></small><center></div>';}
  529.  
  530. add_action('wp_footer','copyrightfbb');
  531. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement