public function save($info)
 {
     $validationResult = $this->validate($info);
     if ('' !== $validationResult) {
         trigger_error($validationResult, E_USER_ERROR);
     }
     $this->_lastChunk = $info;
     $this->_chunkFolder = $this->UPLOAD_PATH . $info['id'];
     $this->_lockFile = $this->_chunkFolder . '/lock';
     FilesHelper::createDir($this->_chunkFolder);
     $f = fopen($this->_lockFile, 'c');
     if (flock($f, LOCK_EX)) {
         $chunks = array_diff(scandir($this->_chunkFolder), array('.', '..', 'lock'));
         if ((int) $this->_lastChunk['total'] === count($chunks) + 1) {
             $this->_isLast = true;
         }
         if (!empty($this->_lastChunk['blob'])) {
             if (empty($_FILES['content']['tmp_name'])) {
                 ProviderLog::end('Chunk save');
                 return false;
             }
             $content = file_get_contents($_FILES['content']['tmp_name']);
             unlink($_FILES['content']['tmp_name']);
         } else {
             $content = $info['content'];
         }
         FilesHelper::writeFile($this->_chunkFolder . '/' . (int) $info['current'], $content);
         flock($f, LOCK_UN);
         ProviderLog::end('Chunk save');
         return true;
     } else {
         trigger_error('Couldn\'t lock the file: ' . $this->_lockFile, E_USER_NOTICE);
     }
 }
 /**
  * Build theme layout files header.tpl, footer.tpl
  */
 private function _buildTemplate($info, $content)
 {
     $dir = $info['dirname'];
     $name = $info['filename'];
     $content_before = $content;
     $content_after = '';
     $id = 'center_column';
     $searchable_content = '<div id="' . $id . '">{$HOOK_HOME}</div>';
     $position = strpos($content, $searchable_content);
     if ($position !== FALSE) {
         $content_before = substr($content, 0, $position) . '<div id="' . $id . '">';
         $content_after = '</div>' . substr($content, $position + strlen($searchable_content));
     }
     $header_tpl_path = $dir . '/header_' . $name . '.tpl';
     $footer_tpl_path = $dir . '/footer_' . $name . '.tpl';
     FilesHelper::writeFile($header_tpl_path, $content_before);
     FilesHelper::writeFile($footer_tpl_path, $content_after);
     return array($header_tpl_path, $footer_tpl_path);
 }
function save_config($src_dir, $dest_dir, $user_theme_name)
{
    $config = '/designer/Export/Config.xml';
    $content = preg_replace('/name="([^"]*?)" directory="([^"]*?)"/', 'name="' . $user_theme_name . '" directory="' . $user_theme_name . '"', FilesHelper::readFile($src_dir . $config));
    FilesHelper::writeFile($dest_dir . $config, $content);
}
 public function save()
 {
     FilesHelper::writeFile($this->_themeDir . '/export/data_attributes_diff.json', json_encode($this->_data));
 }
function theme_save_manifest($themeName, $manifest)
{
    $themeDir = FilesHelper::normalizePath(getThemeDir($themeName));
    $version = theme_get_manifest_version($themeName, $manifest);
    FilesHelper::writeFile($themeDir . '/export/' . $version, $manifest);
    FilesHelper::writeFile($themeDir . '/export/manifest.version', $version);
}
 private function _fixPreviewImagePaths()
 {
     $fixStr = "{assign var=theme_name value=\$tpl_dir|regex_replace:'/(.*)([\\/\\\\\\]themes[\\/\\\\\\])(.*)(_preview[\\/\\\\\\]\$)/':'\$3'}";
     $fixStr1 = "{if \$isBdPreview && !file_exists(\"\$tpl_dir/img/";
     $dirs = array($this->_previewThemeDir, $this->_themeDir);
     foreach ($dirs as $dir) {
         foreach (FilesHelper::enumerateFiles($dir) as $file) {
             $info = pathinfo($file['name']);
             $name = $info['filename'];
             $fileExt = isset($info['extension']) && $info['extension'] ? $info['extension'] : '';
             if (!in_array($fileExt, array('tpl'))) {
                 continue;
             }
             $content = $file['content'];
             $content = str_replace('"' . $fixStr1, '"' . $fixStr . $fixStr1, $content, $count);
             $content = preg_replace('/({assign var=p value="{\\$img_dir}..\\/..\\/)(.*?)(\\/)/', '$1{\\$theme_name}$3', $content);
             if ($count > 0) {
                 FilesHelper::writeFile($file['path'], $content);
             }
         }
     }
     FilesHelper::emptyDirRecursive($this->_previewThemeDir . '/img', false);
 }
function rebuildTranslations($themeDir, $translations)
{
    // CHECK: don't remove translation for files that doesn't store in theme - liveedit.tpl
    $files = FilesHelper::checkFiles($themeDir, true, false, false, true);
    foreach ($translations as $lang => $translation) {
        $out = <<<EOT
<?php

global \$_LANG;
\$_LANG = array();


EOT;
        if (!empty($translation)) {
            foreach ($translation as $key => $value) {
                if (preg_match("/([^']+?)([^_]+\$)/", $key, $matches)) {
                    $fileName = rtrim($matches[1], '_') . '.tpl';
                    // CHECK: don't remove translation for files that doesn't store in theme - liveedit.tpl
                    if (in_array($fileName, $files)) {
                        // file exists
                        $quoteReplaced = preg_replace("/'/", "\\'", $value);
                        $out .= <<<EOT
\$_LANG['{$key}'] = '{$quoteReplaced}';

EOT;
                    }
                }
            }
        }
        $out .= <<<EOT

return \$_LANG;

EOT;
        FilesHelper::writeFile($themeDir . '/lang/' . $lang . '.php', $out);
    }
}