/**
  * Get the files path for a given page (whether it exists or not) - static
  *
  * @param Page $page
  * @param bool $extended Whether to force use of extended paths, primarily for recursive use by this function only
  * @return string 
  *
  */
 public static function _path(Page $page, $extended = false)
 {
     $config = wire('config');
     $path = $config->paths->files;
     $securePrefix = $config->pagefileSecurePathPrefix;
     if (!strlen($securePrefix)) {
         $securePrefix = self::defaultSecurePathPrefix;
     }
     if ($extended) {
         $publicPath = $path . self::_dirExtended($page->id);
         $securePath = $path . self::_dirExtended($page->id, $securePrefix);
     } else {
         $publicPath = $path . $page->id . '/';
         $securePath = $path . $securePrefix . $page->id . '/';
     }
     if ($page->isPublic() || !$config->pagefileSecure) {
         // use the public path, renaming a secure path to public if it exists
         if (is_dir($securePath) && !is_dir($publicPath)) {
             @rename($securePath, $publicPath);
         }
         $filesPath = $publicPath;
     } else {
         // use the secure path, renaming the public to secure if it exists
         $hasSecurePath = is_dir($securePath);
         if (is_dir($publicPath) && !$hasSecurePath) {
             @rename($publicPath, $securePath);
         } else {
             if (!$hasSecurePath && self::defaultSecurePathPrefix != $securePrefix) {
                 // we track this just in case the prefix was newly added to config.php, this prevents
                 // losing track of the original directories
                 $securePath2 = $extended ? $path . self::_dirExtended($page->id, self::defaultSecurePathPrefix) : $path . self::defaultSecurePathPrefix . $page->id . '/';
                 if (is_dir($securePath2)) {
                     // if the secure path prefix has been changed from undefined to defined
                     @rename($securePath2, $securePath);
                 }
             }
         }
         $filesPath = $securePath;
     }
     if (!$extended && $config->pagefileExtendedPaths && !is_dir($filesPath)) {
         // if directory doesn't exist and extended mode is possible, specify use of the extended one
         $filesPath = self::_path($page, true);
     }
     return $filesPath;
 }
 /**
  * Get the files path for a given page (whether it exists or not) - static
  *
  * @param Page $page
  * @return string 
  *
  */
 public static function _path(Page $page)
 {
     $config = wire('config');
     $path = $config->paths->files;
     $publicPath = $path . (int) $page->id . '/';
     $securePrefix = $config->pagefileSecurePathPrefix;
     if (!strlen($securePrefix)) {
         $securePrefix = self::defaultSecurePathPrefix;
     }
     // securePath has the page ID preceded with a prefix which PW's htaccess blocks http requests to
     $securePath = $path . $securePrefix . (int) $page->id . '/';
     // we track this just in case the prefix was newly added to config.php, this prevents
     // losing track of the original directories
     $securePath2 = $path . self::defaultSecurePathPrefix . (int) $page->id . '/';
     if ($page->isPublic() || !$config->pagefileSecure) {
         // use the public path, renaming a secure path to public if it exists
         if (is_dir($securePath) && !is_dir($publicPath)) {
             @rename($securePath, $publicPath);
         }
         return $publicPath;
     } else {
         // use the secure path, renaming the public to secure if it exists
         $hasSecurePath = is_dir($securePath);
         if (is_dir($publicPath) && !$hasSecurePath) {
             @rename($publicPath, $securePath);
         } else {
             if (!$hasSecurePath && is_dir($securePath2)) {
                 // if the secure path prefix has been changed from undefined to defined
                 @rename($securePath2, $securePath);
             }
         }
         return $securePath;
     }
 }