$fuser = $fuser[0];
     //hier könnte man noch eine email oder dgl. schicken
     if ($fuser != $txtUID) {
         $error = 3;
     }
 }
 unset($mfiles);
 if (!$VLAN) {
     $VLAN = 'S';
 }
 if (!$error) {
     if ($VLAN != 'S') {
         $mac_result = 3;
     } else {
         if ($VLAN == 'S') {
             $mfiles = new File_SearchReplace("/.*?\\sS\\s{$txtUID}\\s(.*)?\\snb-{$txtUID}\\s(.*)/", "{$mac} S {$txtUID} \$1 nb-{$txtUID} {$name}", $filename_dat, '', 0, array("#", ";"));
             $mfiles->setSearchFunction('preg');
             if (preg_match("/[A-Fa-f0-9]{12}/", $mac) && $mac != '' && mb_strlen($mac) == 12) {
                 $mfiles->doSearch();
                 // neuen eintrag erzeugen und ip hochzählen
                 if ($mfiles->occurences == 0) {
                     //$content = file($filename_dat, "r");
                     //$content = implode('', $content);
                     $content = file_get_contents($filename_dat);
                     //$ip = file($filename_ip);
                     //$ip = trim($ip[0]);
                     $ip = file_get_contents($filename_ip);
                     $ip = trim($ip);
                     $ip = ip_increment($ip);
                     // nachschauen ob, die mac adresse schon
                     // einmal gespeichert wurde
    $files_to_search = array();
    $directories = get_all_dir('blank-theme');
    $strings_to_replace = array('theme_name' => array($default_values['theme_name']['default'], $theme_name), 'text_domain' => array($default_values['text_domain']['default'], $text_domain), 'prefix' => array($default_values['prefix']['default'], $prefix), 'author_uri' => array($default_values['author_uri']['default'], $author_uri), 'css_prefix' => array("{$default_values['css_prefix']['default']}-", $css_prefix . '-'), 'js_class_name' => array($default_values['js_class_name']['default'], $js_class_name), 'constant_name' => array($default_values['constant_name']['default'], $constant_name), 'author_name' => array($default_values['author_name']['default'], $author_name), 'theme_decription' => array($default_values['theme_decription']['default'], "Description: {$theme_decription}"), 'more_name' => array('blank theme', $theme_name));
    $file_names_to_rename = array('blank-theme', 'blank_theme');
    $change_log = array();
    foreach ($strings_to_replace as $data) {
        $search_string = $data[0];
        $replace_string = $data[1];
        foreach ($directories as $dir_to_search) {
            //Rename File Names
            if ($handle = opendir($dir_to_search)) {
                while (false !== ($fileName = readdir($handle))) {
                    foreach ($file_names_to_rename as $file_prefix) {
                        if (strpos($fileName, $file_prefix) !== false) {
                            $newName = str_replace($file_prefix, $text_domain, $fileName);
                            rename($dir_to_search . $fileName, $dir_to_search . $newName);
                        }
                    }
                }
                closedir($handle);
            }
            //Change strings
            $snr = new File_SearchReplace($search_string, $replace_string, $files_to_search, $dir_to_search, true);
            // 'true' to search subdirectories
            $snr->doSearch();
            $change_log[] = array('search_string' => $search_string, 'replace_string' => $replace_string, 'number_of_occurences' => $snr->getNumOccurences(), 'directory' => $dir_to_search);
        }
    }
} else {
    $string_values = $default_values;
}
<?php

require_once dirname(__FILE__) . '/../bootstrap/unit.php';
$cloneFrom = nbConfig::get('symfony_project-clone_from');
$cloneTo = nbConfig::get('symfony_project-clone_to');
$name = nbConfig::get('symfony_project-clone_name');
$t = new lime_test(5);
$t->comment('Symfony Project Clone');
$cmd = new nbSymfonyCloneProjectCommand();
$commandLine = sprintf('%s %s %s', $cloneFrom, $cloneTo, $name);
$finder = nbFileFinder::create('any');
$appFiles = $finder->add('*.*')->remove('.')->remove('..')->relative()->in($cloneFrom);
$t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'Symfony project cloned successfully');
$t->ok(file_exists($cloneTo . '/' . $name), 'project is cloned');
//TODO rivedere directory cache e il test in generale 20???
$t->comment('Total files are 46 with cache and log directories');
$clonedAppFiles = $finder->add('*.*')->remove('.')->remove('..')->relative()->in($cloneTo . '/' . $name);
$t->is(count($clonedAppFiles), 46, 'All files (cache and log are excluded) are cloned');
$fsr = new File_SearchReplace($name, '', $cloneTo . '/' . $name . '/symfony/config/properties.ini', '', false);
$fsr->doSearch();
$t->is($fsr->getNumOccurences(), 1, 'File properties.ini modified');
$fsr = new File_SearchReplace($name, '', $cloneTo . '/' . $name . '/symfony/config/databases.yml', '', false);
$fsr->doSearch();
$t->is($fsr->getNumOccurences(), 2, 'File databases.yml modified');
$fileSystem->rmdir($cloneTo . '/' . $name, true);
Example #4
0
 /**
  * BEARスケルトンアプリ作成
  *
  * @param string $path  アプリケーシン絶対or相対パス
  * @param string $pearc .pearrcパス
  *
  * @return void
  */
 private function _initApp($path, $pearc = '')
 {
     $bearPath = _BEAR_BEAR_HOME;
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         throw Exception("Windows is not supported for init-app, copy data/app instaed.\n");
         exit;
     }
     $config = new PEAR_Config($pearc);
     $pearPath = $config->get('php_dir');
     $pearDataPath = $config->get('data_dir');
     //usr/share/php/data
     $source = "{$pearDataPath}/BEAR/data/app";
     if (!file_exists($source)) {
         $source = _BEAR_BEAR_HOME . '/data/app';
     }
     if (!file_exists($source)) {
         die("error: no valid app folder\n{$source}\n");
     }
     $exec = "/bin/cp -R {$source} {$path}";
     // コピー先エラーチェック
     if (file_exists($path)) {
         die("'{$path}' already exists\n");
     }
     $result = shell_exec($exec);
     if ($result) {
         die("cp error. src=[{$source}] dest=[{$path}]");
     }
     // 属性変更
     $dirs = array();
     $dirs[] = "{$path}/logs";
     $dirs[] = "{$path}/tmp";
     $dirs[] = "{$path}/tmp/cache_lite";
     $dirs[] = "{$path}/tmp/session";
     $dirs[] = "{$path}/tmp/smarty_cache";
     $dirs[] = "{$path}/tmp/smarty_templates_c";
     $dirs[] = "{$path}/tmp/upload";
     $dirs[] = "{$path}/tmp/misc";
     foreach ($dirs as $dir) {
         if (chmod($dir, 0777) == false) {
             die("chmod fault path=[{$dir}]\n");
         }
     }
     // .htaccess
     $htacessPath = "{$path}/htdocs/htaccess.txt";
     $htacessPathNew = "{$path}/htdocs/.htaccess";
     if (!file_exists($htacessPath)) {
         die("[ERROR] htaccss missing error = [{$htacessPath}]\n");
     }
     // symlink
     $from = "{$pearDataPath}/BEAR/data/htdocs/__bear";
     $to = "{$path}/htdocs/__bear";
     $result = symlink($from, $to);
     if ($result === false) {
         rmdir($to);
         echo "Please make symlink manually.\n'ln -s {$from} {$to}'\n";
     }
     $from = "{$pearDataPath}/BEAR/data/htdocs/__edit";
     $to = "{$path}/htdocs/__edit";
     $result = symlink($from, $to);
     if ($result === false) {
         rmdir($to);
         echo "Please make symlink manually.\n'ln -s {$from} {$to}'\n";
     }
     $from = "{$pearDataPath}/Panda/data/htdocs/__panda";
     $to = "{$path}/htdocs/__panda";
     $result = symlink($from, $to);
     if ($result === false) {
         rmdir($to);
         echo "Please make symlink manually.\n'ln -s {$from} {$to}'\n";
     }
     // 置換
     $files = array($htacessPath);
     $ignoreline = array("#", ":");
     $err = error_reporting();
     error_reporting(0);
     $snr = new File_SearchReplace('@APP-DIR@', $path, $files, "{$path}/htdocs/", false, $ignoreline);
     $snr->doSearch();
     $snr = new File_SearchReplace('@VENDORS-PEAR-DIR@', "{$bearPath}/BEAR/vendors/PEAR", $files, "{$path}/htdocs/", false, $ignoreline);
     $snr->doSearch();
     $snr = new File_SearchReplace('/opt/local/lib/php', $pearPath, $files, "{$path}/htdocs/", false, $ignoreline);
     $snr->doSearch();
     error_reporting($err);
     //mv htaccess.txt .htaccess
     $result = rename($htacessPath, $htacessPathNew);
     if (!$result) {
         echo "htaccess rename error [{$htacessPath}] to [{$htacessPathNew}]\n";
     }
     echo "BEAR App files are made at '{$path}'.\n";
     echo "Thank you for using BEAR.";
 }
Example #5
0
 /**
  * This method find-replace a string or more strings.
  *
  * @param string $search_string  The string or array of strings to search.
  * @param string $replace_string  The string or array of strings to replace.
  * @param $file
  */
 public static function replaceTokens($search_string, $replace_string, $file)
 {
     $fsr = new File_SearchReplace($search_string, $replace_string, $file, '', false);
     if (!$fsr) {
         throw new Exception('[nbFileSystem::replaceTokens] replaceTokens command failed');
     }
     $fsr->doSearch();
 }