Exemple #1
0
 protected function env_copy($from, $to)
 {
     // Check for symlinks
     if (is_link($from)) {
         return symlink(readlink($from), $to);
     }
     // Simple copy for a file
     if (is_file($from)) {
         $this->stdout("Copying " . $from . "\n");
         return copy($from, $to);
     }
     // Make destination directory
     if (!is_dir($to)) {
         $this->stdout("mkdir " . $to . "\n");
         mkdir($to);
     }
     $dir = dir($from);
     while (false !== ($entry = $dir->read())) {
         if ($entry == '.' || $entry == '..' || $entry == '.git') {
             continue;
         }
         // Deep copy directories
         $this->env_copy($from . "/" . $entry, $to . "/" . $entry);
     }
     // Clean up
     $dir->close();
 }
Exemple #2
0
 public function __construct($environment, $debug)
 {
     if (!ini_get('date.timezone') || !date_default_timezone_get()) {
         $timezone = "Europe/Berlin";
         if (is_link('/etc/localtime')) {
             // Mac OS X (and older Linuxes)
             // /etc/localtime is a symlink to the
             // timezone in /usr/share/zoneinfo.
             $filename = readlink('/etc/localtime');
             if (strpos($filename, '/usr/share/zoneinfo/') === 0) {
                 $timezone = substr($filename, 20);
             }
         } elseif (file_exists('/etc/timezone')) {
             // Ubuntu / Debian.
             $data = file_get_contents('/etc/timezone');
             if ($data) {
                 $timezone = $data;
             }
         } elseif (file_exists('/etc/sysconfig/clock')) {
             // RHEL / CentOS
             $data = parse_ini_file('/etc/sysconfig/clock');
             if (!empty($data['ZONE'])) {
                 $timezone = $data['ZONE'];
             }
         }
         $timezone = preg_replace("/[\\n\\r]+/", "", $timezone);
         date_default_timezone_set($timezone);
     }
     parent::__construct($environment, $debug);
 }
 /**
  * Recursive copy function
  * @param str src source path
  * @param str dst source path
  * @return bool
  */
 public static function cp_r($src, $dst)
 {
     if (is_link($src)) {
         $l = readlink($src);
         if (!symlink($l, $dst)) {
             return false;
         }
     } elseif (is_dir($src)) {
         if (!mkdir($dst)) {
             return false;
         }
         $objects = scandir($src);
         if ($objects === false) {
             return false;
         }
         foreach ($objects as $file) {
             if ($file == "." || $file == "..") {
                 continue;
             }
             if (!self::cp_r($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file)) {
                 return false;
             }
         }
     } else {
         if (!copy($src, $dst)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Set the default timezone.
  *
  * PHP 5.4 has removed the autodetection of the system timezone,
  * so it needs to be done manually.
  * UTC is the fallback in case autodetection fails.
  */
 protected function setDefaultTimezone()
 {
     $timezone = 'UTC';
     if (is_link('/etc/localtime')) {
         // Mac OS X (and older Linuxes)
         // /etc/localtime is a symlink to the timezone in /usr/share/zoneinfo.
         $filename = readlink('/etc/localtime');
         if (strpos($filename, '/usr/share/zoneinfo/') === 0) {
             $timezone = substr($filename, 20);
         }
     } elseif (file_exists('/etc/timezone')) {
         // Ubuntu / Debian.
         $data = file_get_contents('/etc/timezone');
         if ($data) {
             $timezone = trim($data);
         }
     } elseif (file_exists('/etc/sysconfig/clock')) {
         // RHEL/CentOS
         $data = parse_ini_file('/etc/sysconfig/clock');
         if (!empty($data['ZONE'])) {
             $timezone = trim($data['ZONE']);
         }
     }
     date_default_timezone_set($timezone);
 }
 public function generatePhpbbLink($varValue, DataContainer $dc)
 {
     if (is_link($dc->activeRecord->phpbb_alias) && readlink($dc->activeRecord->phpbb_alias) == $varValue) {
         Message::addInfo("Path to forum already set");
         return $varValue;
     }
     if (is_link($dc->activeRecord->phpbb_alias) !== false && readlink($dc->activeRecord->phpbb_alias) != $varValue) {
         Message::addInfo("Removing old link");
         unlink($dc->activeRecord->phpbb_alias);
     }
     Message::addInfo("Trying to set Forum Symlink");
     if (file_exists($varValue . "/viewtopic.php")) {
         Message::addInfo("Forum found. Setting Link");
         $result = symlink($varValue, $dc->activeRecord->phpbb_alias);
         if ($result === true) {
             Message::addInfo("Link Set");
         }
         if (!is_link($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') || readlink($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') != "../../contao/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia") {
             Message::addInfo("Setting Vendor Link");
             symlink(TL_ROOT . "/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia", $dc->activeRecord->phpbb_alias . '/ext/ctsmedia');
         }
         Message::addInfo("Please activate the contao extension in the phpbb backend");
     } else {
         //Message::addError("Forum could not be found: ".$varValue . "/viewtopic.php");
         throw new Exception("Forum could not be found: " . $varValue . "/viewtopic.php");
     }
     return $varValue;
 }
function absolutePath($path)
{
    $isEmptyPath = strlen($path) == 0;
    $isRelativePath = $path[0] != '/';
    $isWindowsPath = !(strpos($path, ':') === false);
    if (($isEmptyPath || $isRelativePath) && !$isWindowsPath) {
        $path = getcwd() . DIRECTORY_SEPARATOR . $path;
    }
    // resolve path parts (single dot, double dot and double delimiters)
    $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
    $pathParts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
    $absolutePathParts = array();
    foreach ($pathParts as $part) {
        if ($part == '.') {
            continue;
        }
        if ($part == '..') {
            array_pop($absolutePathParts);
        } else {
            $absolutePathParts[] = $part;
        }
    }
    $path = implode(DIRECTORY_SEPARATOR, $absolutePathParts);
    // resolve any symlinks
    if (file_exists($path) && is_link($path)) {
        $path = readlink($path);
    }
    // put initial separator that could have been lost
    $path = !$isWindowsPath ? '/' . $path : $path;
    return $path;
}
 public function make($object, $recursive = true)
 {
     $this->checkDirectory();
     if (!$object) {
         $this->safeClean();
         return $this->directory;
     }
     $realDirectory = null;
     if (is_link($this->directory)) {
         $realDirectory = readlink($this->directory);
         if ($realDirectory === false) {
             throw new WrongStateException('invalid pointer: ' . $this->directory);
         }
     }
     $reversePath = $this->identityMap->reverseLookup($object);
     if (!$reversePath && is_link($this->directory)) {
         throw new WrongStateException('you must always store your object somewhere ' . 'before you going to update pointer ' . $this->directory);
     }
     if ($reversePath && file_exists($this->directory) && !$realDirectory && $this->directory != $reversePath) {
         throw new WrongStateException('you should relocate object ' . $this->directory . ' to ' . $reversePath . ' by yourself.' . ' cannot replace object with a link');
     }
     if ($reversePath && (!file_exists($this->directory) || $realDirectory)) {
         if (!$realDirectory || $realDirectory != $reversePath) {
             $this->safeClean();
             $status = symlink($reversePath, $this->directory);
             if ($status !== true) {
                 throw new WrongStateException('error creating symlink');
             }
         }
         return $reversePath;
     }
     $result = parent::make($object, $recursive);
     $this->identityMap->bind($result, $object);
     return $result;
 }
 /**
  * Remove symlinks from each plugin to app/webroot
  *
  * @return void
  */
 public function remove()
 {
     chdir(realpath(WWW_ROOT));
     $paths = $this->_getPaths();
     foreach ($paths as $plugin => $config) {
         $this->out('Processing plugin: <info>' . $plugin . '</info>');
         if (!file_exists($config['public'])) {
             $this->out('--> <error>Skipping</error>, symlink does not exists (' . Nodes\Common::stripRealPaths($config['public']) . ')');
             continue;
         }
         if (!is_link($config['public'])) {
             $this->out('--> <error>Skipping, target is not a symlink</error>');
             continue;
         }
         $symlinkTarget = readlink($config['public']);
         $this->out('----> Current target is ' . $symlinkTarget);
         if ($config['relative_private'] !== $symlinkTarget) {
             $this->out('--> <error>Skipping, symlink source does not match ours</error>');
             continue;
         }
         if (unlink($config['public'])) {
             $this->out(sprintf('--> <info>OK</info>, symlink removed (%s => %s)', \Nodes\Common::stripRealPaths($config['private']), \Nodes\Common::stripRealPaths($config['public'])));
         } else {
             $this->out('--> <error>Error</error>');
         }
     }
 }
 public static function symlink()
 {
     /* WP FileSystem API does not support symlink creation
        global $wp_filesystem;
        */
     $muplugin = dirname(WPF2B_PATH) . self::$muplugin_rel;
     $symlink = WPMU_PLUGIN_DIR . self::$symlink_rel;
     if (!file_exists(WPMU_PLUGIN_DIR)) {
         if (!mkdir(WPMU_PLUGIN_DIR, 0755, true)) {
             return false;
         }
     }
     if (is_link($symlink) || file_exists($symlink)) {
         // Correct symbolic link
         if (is_link($symlink) && readlink($symlink) === $muplugin) {
             return true;
         } else {
             /* is_writable() does not detect broken symlinks, unlink() must be @muted
                // Incorrect and unwritable
                if ( ! is_writable( $symlink ) ) {
                    return false;
                }
                */
             // Remove symbolic link
             if (!@unlink($symlink)) {
                 return false;
             }
         }
     }
     $linking = symlink($muplugin, $symlink);
     return $linking;
 }
	function convert ($format, $attr, $showMessages=false) {
		$currentFormat = $this->format();
		$format = strtolower(trim($format));
		if ($format == '')
			return false;
		if ($currentFormat == $format)
			return $this;
			
		$name = file_strip_extension($this->fname);  // remove file extension		
		$mo = MediaObjectFactory::createMediaObject($this->pagename, "$name.$format");
		if (!$mo->exists() || $mo->olderThan($this)) {
			if ($showMessages)
				message("creating FIG image in ".strtoupper($format)." format", 'start');
			// fig2dev doesn't like DOS/Win newlines => convert newlines to UNIX format
			// if $this->path() is a symbolic link we convert the actual fig file (link target)
			$path = $this->path();
			if (is_link($path))
				$path = readlink($path);
			RunTool('dos2unix', "IN=$path");
			$resfile = $this->fig2format($this->path(), $format);
			return $resfile ? $mo : false;

		}
		return $mo;
	}
Exemple #11
0
 /**
  * Given /^I copy all files from "(?P<source>.*)" to "(?P<destination>.)*)"$/
  */
 public function recursiveCopy($source, $dest, $permissions = 0755)
 {
     $this->_logger()->logInfo("Copying: {$source} to {$dest}");
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         return copy($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest, $permissions);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         if (!$this->recursiveCopy("{$source}/{$entry}", "{$dest}/{$entry}")) {
             // Error!
             return false;
         }
     }
     // Clean up
     $dir->close();
     return true;
 }
 protected function installCore(PackageInterface $package)
 {
     $installPath = $this->getInstallPath($package);
     // find core, might vary, depending on download type
     if (file_exists($installPath . '/web/concrete')) {
         // source
         $coreSourcePath = $installPath . '/web/concrete';
     } else {
         // dist
         $coreSourcePath = $installPath . '/concrete';
     }
     $coreInstallPath = $this->getCoreInstallPath($package);
     // make sure we have absolute paths
     $coreSourcePath = realpath($coreSourcePath);
     $coreInstallPath = realpath('') . '/' . rtrim($coreInstallPath, '/');
     // make sure parent core path exists
     $parentPath = dirname($coreInstallPath);
     $this->filesystem->ensureDirectoryExists($parentPath);
     // check for existing core path
     if (file_exists($coreInstallPath) && !is_link($coreInstallPath)) {
         throw new \RuntimeException('Can\'t create concrete5 symlink as folder already exists. Please remove ' . $coreInstallPath);
     } else {
         if (is_link($coreInstallPath)) {
             if (realpath(readlink($coreInstallPath)) == $coreSourcePath) {
                 // already has correct symlink, done here
                 return;
             }
             // remove existing incorrect symlink
             $this->filesystem->unlink($coreInstallPath);
         }
         $this->io->write(sprintf('    Creating concrete5 symlink %s - %s', $coreInstallPath, $this->filesystem->relativeSymlink($coreSourcePath, $coreInstallPath) ? '<info>created</info>' : '<error>not created</error>'));
         $this->io->write('');
     }
 }
Exemple #13
0
 public static function xsymlink($source, $dest, $permissions = 0755)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Symlink file
     if (is_file($source)) {
         return symlink($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest, $permissions);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         self::xsymlink("{$source}/{$entry}", "{$dest}/{$entry}", $permissions);
     }
     // Clean up
     $dir->close();
     return true;
 }
Exemple #14
0
function list_mac()
{
    global $sdir;
    // Display client MAC address scripts
    chdir($sdir);
    $dir_handle = @opendir($sdir) or die("Unable to open {$sdir}");
    $bgcolor = "#BDBDBD";
    echo "<a href=\"?view=clients&add=true\">Add a MAC address</a><br>";
    echo "<table border=\"0\" cellspacing=\"0\"><tr bgcolor=\"#1A73CC\"><td><b>MAC Address</b></td><td></td><td><b>Config File</b></td><td></td></tr><br>";
    //running the while loop
    while ($file = readdir($dir_handle)) {
        if ("{$file}" == ".." or "{$file}" == "." or is_dir($file) or !is_link($file)) {
            continue;
        }
        // Get the file sym-link target
        $cfg = readlink($file);
        $mac = strstr($file, '.cfg', true);
        echo "<tr bgcolor=\"{$bgcolor}\" border=0><td>{$mac}</td><td>&nbsp;<b>></b>&nbsp;</td><td>{$cfg}</td><td>&nbsp; - <a href=\"?view=clients&del={$file}\">Remove</a></td>";
        if ($bgcolor == "#BDBDBD") {
            $bgcolor = "#FFFFFF";
        } else {
            $bgcolor = "#BDBDBD";
        }
    }
    echo "</table>";
}
 /**
  * Autoloading logic
  * 
  * @param  String  $class Class name
  * @return Boolean        Whether the loading succeded.
  */
 public static function load($class)
 {
     clearstatcache();
     // figure out namespace and halt process if not in our namespace
     $namespace = self::discover_namespace($class);
     if ($namespace === '') {
         return;
     }
     $class = self::normalize_class($class, $namespace);
     foreach (self::$directories[$namespace] as $dir) {
         $file = $dir . DIRECTORY_SEPARATOR . $class;
         // if( $dir === end(self::$directories) )
         // {
         // 	require $file;
         // 	return true;
         // }
         if (is_link($file)) {
             $file = readlink($file);
         }
         // $real = realpath($file);
         // if($real) $file = $real;
         if (is_file($file)) {
             require $file;
             return true;
         }
     }
 }
 /**
  * Deploy build.
  *
  * @throws runtime_exception If deployment failed
  * @return $this
  */
 public function deploy_build()
 {
     if (!$this->fs->exists($this->build_dir)) {
         return $this;
     }
     $this->build_parents();
     $current_build = false;
     if ($this->fs->exists($this->production_link)) {
         if (is_link($this->production_link)) {
             $current_build = readlink($this->production_link);
         }
     }
     try {
         $new_build = $this->repo_dir . 'prod_' . time();
         $this->fs->rename($this->build_dir, $new_build);
         $this->fs->remove($this->production_link);
         $this->fs->symlink($new_build, $this->production_link);
     } catch (\Exception $e) {
         $this->fs->remove($this->production_link);
         if ($current_build) {
             $this->fs->symlink($current_build, $this->production_link);
         }
         throw new runtime_exception('PACKAGES_BUILD_DEPLOYMENT_FAILED');
     }
     if ($current_build) {
         $this->fs->remove($current_build);
     }
     return $this;
 }
 /**
  * On Windows, fileXtime functions see only changes
  * on the symlink file and not the original one.
  *
  * @param string $path
  *
  * @return string
  */
 private function fixWindowsPath($path)
 {
     if (is_link($path) && defined('PHP_WINDOWS_VERSION_MAJOR')) {
         $path = readlink($path);
     }
     return $path;
 }
Exemple #18
0
 /**
  * Returns true if the path is a "valid" path and is writable (even if the complete path does not yet exist).
  * @param string $path
  * @return boolean
  */
 public function validatePath($path)
 {
     $absPath = $this->getAbsolutePath($path);
     $absPathParts = preg_split('/\\//', preg_replace('/(^\\/|\\/$)/', '', $absPath));
     $nSteps = count($absPath);
     $tmpPath = '';
     $prevReadable = false;
     $prevWritable = false;
     for ($i = 0; $i < $nSteps; $i++) {
         $tmpPath .= '/' . $absPathParts[$i];
         if (file_exists($tmpPath)) {
             if (!is_dir($tmpPath)) {
                 if (is_link($tmpPath)) {
                     $linkPath = readlink($tmpPath);
                     if (false === $linkPath || !is_dir($linkPath)) {
                         return false;
                     }
                     $tmpPath = $linkPath;
                 } else {
                     return false;
                 }
             }
             $prevReadable = is_readable($tmpPath);
             $prevWritable = is_writable($tmpPath);
         } else {
             return $prevReadable && $prevWritable;
         }
     }
     return true;
 }
/** 
 * This function is to replace PHP's extremely buggy realpath(). 
 * @param string The original path, can be relative etc. 
 * @return string The resolved path, it might not exist. 
 */
function truepath($path)
{
    // whether $path is unix or not
    $unipath = strlen($path) == 0 || $path[0] != '/';
    // attempts to detect if path is relative in which case, add cwd
    if (strpos($path, ':') === false && $unipath) {
        $path = getcwd() . DIRECTORY_SEPARATOR . $path;
    }
    // resolve path parts (single dot, double dot and double delimiters)
    $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
    $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
    $absolutes = array();
    foreach ($parts as $part) {
        if ('.' == $part) {
            continue;
        }
        if ('..' == $part) {
            array_pop($absolutes);
        } else {
            $absolutes[] = $part;
        }
    }
    $path = implode(DIRECTORY_SEPARATOR, $absolutes);
    // resolve any symlinks
    if (file_exists($path) && linkinfo($path) > 0) {
        $path = readlink($path);
    }
    // put initial separator that could have been lost
    $path = !$unipath ? '/' . $path : $path;
    return $path;
}
Exemple #20
0
 /**
  * Copy a directory recursively and optionally use a extension whitelist
  *
  * @param string $source
  * @param string $dest
  * @param array $allowedExtensions
  * @return bool|null
  */
 protected function recursiveCopy($source, $dest, $allowedExtensions = [])
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         // Filter files not matching the extension whitelist
         if (!empty($allowedExtensions) and !in_array(pathinfo($source, PATHINFO_EXTENSION), $allowedExtensions)) {
             return null;
         }
         return copy($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         $this->recursiveCopy("{$source}/{$entry}", "{$dest}/{$entry}", $allowedExtensions);
     }
     // Clean up
     $dir->close();
     return true;
 }
function setTimezone($default)
{
    $timezone = "";
    // On many systems (Mac, for instance) "/etc/localtime" is a symlink
    // to the file with the timezone info
    if (is_link("/etc/localtime")) {
        // If it is, that file's name is actually the "Olsen" format timezone
        $filename = readlink("/etc/localtime");
        $pos = strpos($filename, "zoneinfo");
        if ($pos) {
            // When it is, it's in the "/usr/share/zoneinfo/" folder
            $timezone = substr($filename, $pos + strlen("zoneinfo/"));
        } else {
            // If not, bail
            $timezone = $default;
        }
    } else {
        // On other systems, like Ubuntu, there's file with the Olsen time
        // right inside it.
        $timezone = file_get_contents("/etc/timezone");
        if (!strlen($timezone)) {
            $timezone = $default;
        }
    }
    date_default_timezone_set($timezone);
}
 function main($source, $dest, $nested = 1)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // notify user
     $this->notify($source, $dest, $nested);
     // Simple copy for a file
     if (is_file($source)) {
         return copy($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if (substr($entry, 0, 1) == '.' || $entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         $this->main("{$source}/{$entry}", "{$dest}/{$entry}", $nested + 1);
     }
     // Clean up
     $dir->close();
     return true;
 }
/**
 * Recursively copies from one directory to another
 *
 * @access	public
 * @param 	string
 * @param 	string
 * @return	array
 */
function copyr($source, $dest)
{
    // Simple copy for a file
    if (is_file($source)) {
        return copy($source, $dest);
    }
    // Make destination directory
    if (!is_dir($dest)) {
        mkdir($dest);
    }
    // If the source is a symlink
    if (is_link($source)) {
        $link_dest = readlink($source);
        return symlink($link_dest, $dest);
    }
    // Loop through the folder
    $dir = dir($source);
    if (!is_object($dir)) {
        return FALSE;
    }
    while (false !== ($entry = $dir->read())) {
        // Skip pointers
        if ($entry == '.' or $entry == '..') {
            continue;
        }
        // Deep copy directories
        if ($dest !== "{$source}/{$entry}") {
            copyr("{$source}/{$entry}", "{$dest}/{$entry}");
        }
    }
    // Clean up
    $dir->close();
    return true;
}
Exemple #24
0
 /**
  * Copies assets recursively
  *
  * @param $source
  * @param $dest
  * @param int $permissions
  * @return bool
  * @internal
  */
 private function copyRecursive($source, $dest, $permissions = 0755)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         if (is_file($dest)) {
             $this->putWarning("Cannot copy {$source}. File already exists.");
             return false;
         } else {
             return copy($source, $dest);
         }
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest, $permissions);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         $this->copyRecursive("{$source}/{$entry}", "{$dest}/{$entry}");
     }
     // Clean up
     $dir->close();
     return true;
 }
 /**
  * https://bojanz.wordpress.com/2014/03/11/detecting-the-system-timezone-php/
  */
 public function getTimeZone()
 {
     /*
      * Mac OS X (and older Linuxes)
      * /etc/localtime is a symlink to the
      * timezone in /usr/share/zoneinfo.
      */
     if (is_link('/etc/localtime')) {
         $filename = readlink('/etc/localtime');
         if (strpos($filename, '/usr/share/zoneinfo/') === 0) {
             return substr($filename, 20);
         }
         /*
          * Ubuntu / Debian.
          */
     } elseif (file_exists('/etc/timezone')) {
         $data = file_get_contents('/etc/timezone');
         if ($data) {
             return $data;
         }
         /*
          * RHEL / CentOS
          */
     } elseif (file_exists('/etc/sysconfig/clock')) {
         $data = parse_ini_file('/etc/sysconfig/clock');
         if (!empty($data['ZONE'])) {
             return $data['ZONE'];
         }
     }
 }
Exemple #26
0
 /**
  * Copy all folders and files in given path to another location.
  * @param string $source Directory to copy.
  * @param string $dest Directory to copy $source to.
  * @param bool $recursive Should it be created recursively. 
  * @return bool true if successfull, otherwise false.
  */
 public static function copy($source, $dest, $recursive = false)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         return @copy($source, $dest);
     }
     // It's a directoy, should we recurse?
     if (false === $recursive) {
         return false;
     }
     // Make destination directory
     if (false === is_dir($dest)) {
         mkdir($dest);
     }
     // Loop through the folder
     if ($dir = @dir($source)) {
         while (false !== ($entry = $dir->read())) {
             // Skip pointers
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             // Deep copy directories
             $this->copy($source . DIRECTORY_SEPARATOR . $entry, $dest . DIRECTORY_SEPARATOR . $entry);
         }
         // Clean up
         $dir->close();
         return true;
     }
     return false;
 }
 function copyr($source, $dest)
 {
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     if (is_file($source)) {
         $copied = copy($source, $dest);
         $content = file_get_contents($dest);
         $content = str_replace("Forone\\Admin\\Controllers", "App\\Http\\Controllers\\Forone\\Admin\\Controllers", $content);
         file_put_contents($dest, $content);
         return $copied;
     }
     if (!is_dir($dest)) {
         mkdir($dest, 0777, true);
     }
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         copyr("{$source}/{$entry}", "{$dest}/{$entry}");
     }
     $dir->close();
     return true;
 }
Exemple #28
0
 function __getTemplates()
 {
     // populate $this->_choices with a list of directories
     $list = array();
     $_dir = DOKU_INC . 'lib/tpl/';
     $_pattern = '/^[\\w-]+$/';
     if ($dh = @opendir($_dir)) {
         while (false !== ($entry = readdir($dh))) {
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             if ($_pattern && !preg_match($_pattern, $entry)) {
                 continue;
             }
             $file = is_link($_dir . $entry) ? readlink($_dir . $entry) : $entry;
             if (is_dir($_dir . $file)) {
                 $list[] = $entry;
             }
         }
         closedir($dh);
     }
     sort($list);
     return $list;
 }
/**
 * Copy a file, or recursively copy a folder and its contents
 *
 * @author      Aidan Lister <*****@*****.**>
 * @version     1.0.1
 * @link        http://aidanlister.com/2004/04/recursively-copying-directories-in-php/
 * @param       string   $source    Source path
 * @param       string   $dest      Destination path
 * @return      bool     Returns TRUE on success, FALSE on failure
 */
function copyr($source, $dest)
{
    // Check for symlinks
    if (is_link($source)) {
        return symlink(readlink($source), $dest);
    }
    // Simple copy for a file
    if (is_file($source)) {
        return copy($source, $dest);
    }
    // Make destination directory
    if (!is_dir($dest)) {
        mkdir($dest);
    }
    // Loop through the folder
    $dir = dir($source);
    while (false !== ($entry = $dir->read())) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        // Deep copy directories
        copyr("{$source}/{$entry}", "{$dest}/{$entry}");
    }
    // Clean up
    $dir->close();
    return true;
}
function list_files($dir, $follow_links)
{
    $result = array();
    if (TRUE == is_dir($dir)) {
        $files = array_diff(scandir($dir), array('.', '..'));
        foreach ($files as $file) {
            if (TRUE == is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
                $result = array_merge(list_files($dir . DIRECTORY_SEPARATOR . $file, $follow_links), $result);
            } else {
                if (TRUE == is_file($dir . DIRECTORY_SEPARATOR . $file)) {
                    $result[] = $dir . DIRECTORY_SEPARATOR . $file;
                } else {
                    if (TRUE == is_link($dir . DIRECTORY_SEPARATOR . $file)) {
                        if (TRUE == $follow_links) {
                            if (TRUE == is_file(readlink($dir . DIRECTORY_SEPARATOR . $file))) {
                                $result[] = readlink($dir . DIRECTORY_SEPARATOR . $file);
                            } else {
                                if (TRUE == is_dir(readlink($dir . DIRECTORY_SEPARATOR . $file))) {
                                    $result = array_merge(list_files(readlink($dir . DIRECTORY_SEPARATOR . $file), $follow_links), $result);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $result;
}