Esempio n. 1
0
 /**
  * DOCUMENT ME
  * @param mixed $args
  * @param mixed $options
  */
 protected function execute($args = array(), $options = array())
 {
     $conn = 'doctrine';
     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams($this->configuration, $conn));
     $dataDir = aFiles::getWritableDataFolder();
     $uploadDir = aFiles::getUploadFolder();
     // $dataDir will be a_writable, sf_data_dir is its parent, so we can put things there and
     // trust that they are not crushed by the unzip
     $dataZip = sfConfig::get('sf_data_dir') . '/apostrophedemo-awritable.zip';
     if (!copy('http://content.apostrophenow.com/uploads/apostrophedemo-awritable.zip', $dataZip)) {
         throw new sfException("Unable to copy http://content.apostrophenow.com/uploads/apostrophedemo-awritable.zip to {$dataZip}");
     }
     $uploadZip = sfConfig::get('sf_data_dir') . '/apostrophedemo-uploads.zip';
     if (!copy("http://content.apostrophenow.com/uploads/apostrophedemo-uploads.zip", $uploadZip)) {
         throw new sfException('Unable to copy http://content.apostrophenow.com/uploads/apostrophedemo-uploads.zip to $dataZip');
     }
     $this->unzip($dataDir, $dataZip, $options);
     $this->unzip($uploadDir, $uploadZip, $options);
     // Yes, you need to have mysql to use this feature.
     // However you can set app_syncContent_mysql to
     // the path of your mysql utility if it is called something
     // else or not in the PATH
     $mysql = sfConfig::get('app_syncContent_mysql', 'mysql');
     system(escapeshellarg($mysql) . " {$params} < " . escapeshellarg($dataDir . '/ademocontent.sql'), $result);
     if ($result != 0) {
         throw new sfException("mysql failed. Maybe you don't have it in your PATH");
     }
     // Undo the little dance we did to send the demo password across without forcing the use
     // of a known password salt or a particular encryption scheme on the receiving site.
     // The demo password is no secret, but new passwords set later should be, so we don't
     // want to force a salt when generating the demo dump. See aSyncActions for details
     if ($options['verbose']) {
         echo "Postprocessing users\n";
     }
     $users = Doctrine::getTable('sfGuardUser')->findAll();
     foreach ($users as $user) {
         // If there is a salt, and no password, it's really a hint to turn the cleartext password
         // into a proper one and establish a salt
         if (!strlen($user->getPassword())) {
             $demoPassword = $user->getSalt();
             if (strlen($demoPassword)) {
                 $user->setSalt('');
                 $user->setPassword($demoPassword);
                 $user->save();
             }
         }
     }
     if ($options['verbose']) {
         echo "Content loaded.\n";
     }
     system('./symfony apostrophe:rebuild-search-index', $result);
     if ($result != 0) {
         throw new sfException('Problem executing apostrophe:rebuild-search-index task.');
     }
 }
Esempio n. 2
0
function _a_get_assets_body($type, $assets)
{
    $gzip = sfConfig::get('app_a_minify_gzip', false);
    sfConfig::set('symfony.asset.' . $type . '_included', true);
    $html = '';
    // We need our own copy of the trivial case here because we rewrote the asset list
    // for stylesheets after LESS compilation, and there is no way to
    // reset the list in the response object
    if (!sfConfig::get('app_a_minify', false)) {
        // This branch is seen only for CSS, because javascript calls the original Symfony
        // functionality when minify is off
        foreach ($assets as $file => $options) {
            $html .= stylesheet_tag($file, $options);
        }
        return $html;
    }
    $sets = array();
    foreach ($assets as $file => $options) {
        if (preg_match('/^http(s)?:/', $file) || isset($options['data-minify']) && $options['data-minify'] === 0) {
            // Nonlocal URL or minify was explicitly shut off.
            // Don't get cute with it, otherwise things
            // like Addthis and ckeditor don't work
            if ($type === 'stylesheets') {
                $html .= stylesheet_tag($file, $options);
            } else {
                $html .= javascript_include_tag($file, $options);
            }
            continue;
        }
        /*
         *
         * Guts borrowed from stylesheet_tag and javascript_tag. We still do a tag if it's
         * a conditional stylesheet
         *
         */
        $absolute = false;
        if (isset($options['absolute']) && $options['absolute']) {
            unset($options['absolute']);
            $absolute = true;
        }
        $condition = null;
        if (isset($options['condition'])) {
            $condition = $options['condition'];
            unset($options['condition']);
        }
        if (!isset($options['raw_name'])) {
            if ($type === 'stylesheets') {
                $file = stylesheet_path($file, $absolute);
            } else {
                $file = javascript_path($file, $absolute);
            }
        } else {
            unset($options['raw_name']);
        }
        if (is_null($options)) {
            $options = array();
        }
        if ($type === 'stylesheets') {
            $options = array_merge(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => $file), $options);
        } else {
            $options = array_merge(array('type' => 'text/javascript', 'src' => $file), $options);
        }
        if (null !== $condition) {
            $tag = tag('link', $options);
            $tag = comment_as_conditional($condition, $tag);
            $html .= $tag . "\n";
        } else {
            unset($options['href'], $options['src']);
            $optionGroupKey = json_encode($options);
            $set[$optionGroupKey][] = $file;
        }
        // echo($file);
        // $html .= "<style>\n";
        // $html .= file_get_contents(sfConfig::get('sf_web_dir') . '/' . $file);
        // $html .= "</style>\n";
    }
    // CSS files with the same options grouped together to be loaded together
    foreach ($set as $optionsJson => $files) {
        $groupFilename = aAssets::getGroupFilename($files);
        $groupFilename .= $type === 'stylesheets' ? '.css' : '.js';
        if ($gzip) {
            $groupFilename .= 'gz';
        }
        $dir = aFiles::getUploadFolder(array('asset-cache'));
        if (!file_exists($dir . '/' . $groupFilename)) {
            $content = '';
            foreach ($files as $file) {
                $path = null;
                if (sfConfig::get('app_a_stylesheet_cache_http', false)) {
                    $url = sfContext::getRequest()->getUriPrefix() . $file;
                    $fileContent = file_get_contents($url);
                } else {
                    $path = sfConfig::get('sf_web_dir') . $file;
                    $fileContent = file_get_contents($path);
                }
                if ($type === 'stylesheets') {
                    $options = array();
                    if (!is_null($path)) {
                        // Rewrite relative URLs in CSS files.
                        // This trick is available only when we don't insist on
                        // pulling our CSS files via http rather than the filesystem
                        // dirname would resolve symbolic links, we don't want that
                        $fdir = preg_replace('/\\/[^\\/]*$/', '', $path);
                        $options['currentDir'] = $fdir;
                        $options['docRoot'] = sfConfig::get('sf_web_dir');
                    }
                    if (sfConfig::get('app_a_minify', false)) {
                        $fileContent = Minify_CSS::minify($fileContent, $options);
                    }
                } else {
                    // Trailing carriage return makes behavior more consistent with
                    // JavaScript's behavior when loading separate files. For instance,
                    // a missing trailing semicolon should be tolerated to the same
                    // degree it would be with separate files. The minifier is not
                    // a lint tool and should not surprise you with breakage
                    $fileContent = JSMin::minify($fileContent) . "\n";
                }
                $content .= $fileContent;
            }
            if ($gzip) {
                _gz_file_put_contents($dir . '/' . $groupFilename . '.tmp', $content);
            } else {
                file_put_contents($dir . '/' . $groupFilename . '.tmp', $content);
            }
            @rename($dir . '/' . $groupFilename . '.tmp', $dir . '/' . $groupFilename);
        }
        $options = json_decode($optionsJson, true);
        // Use stylesheet_path and javascript_path so we can respect relative_root_dir
        if ($type === 'stylesheets') {
            $options['href'] = stylesheet_path(sfConfig::get('app_a_assetCacheUrl', '/uploads/asset-cache') . '/' . $groupFilename);
            $html .= tag('link', $options);
        } else {
            $options['src'] = javascript_path(sfConfig::get('app_a_assetCacheUrl', '/uploads/asset-cache') . '/' . $groupFilename);
            $html .= content_tag('script', '', $options);
        }
    }
    return $html;
}
 /**
  * DOCUMENT ME
  * @param mixed $value
  * @param mixed $imagePreview
  * @return mixed
  */
 public function getPreviewUrl($value, $imagePreview = array())
 {
     list($exists, $persistid, $extension) = $this->getExistsPersistidAndExtension($value);
     // hasOption just verifies that the option is valid, it doesn't check what,
     // if anything, was passed. Thanks to Lucjan Wilczewski
     $defaultPreview = $this->hasOption('default-preview') ? $this->getOption('default-preview') : false;
     if ($exists) {
         $defaultPreview = false;
     }
     if ($exists || $defaultPreview) {
         // Note change of key
         $urlStem = sfConfig::get('app_aPersistentFileUpload_preview_url', '/uploads/uploaded_image_preview');
         $urlStem = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . $urlStem;
         // This is the corresponding directory path. You have to override one
         // if you override the other. You override this one by setting
         // app_aToolkit_upload_uploaded_image_preview_dir
         $dir = aFiles::getUploadFolder("uploaded_image_preview");
         // While we're here age off stale previews
         aValidatorFilePersistent::removeOldFiles($dir);
         if ($exists) {
             $info = aValidatorFilePersistent::getFileInfo($persistid);
             $source = $info['tmp_name'];
         } else {
             $source = $defaultPreview;
         }
         $info = aImageConverter::getInfo($source, array('format-only' => true));
         $previewable = false;
         if ($info && in_array($info['format'], array('jpg', 'png', 'gif'))) {
             $previewable = true;
             $info = aImageConverter::getInfo($source);
         }
         if ($previewable) {
             $iwidth = $info['width'];
             $iheight = $info['height'];
             // This is safe - based on sniffed file contents and not a user supplied extension
             $format = $info['format'];
             $dimensions = aDimensions::constrain($iwidth, $iheight, $format, $imagePreview);
             // A simple filename reveals less
             $imagename = "{$persistid}.{$format}";
             $url = "{$urlStem}/{$imagename}";
             $output = "{$dir}/{$imagename}";
             if (isset($info['newfile']) && $info['newfile'] || !file_exists($output)) {
                 if ($imagePreview['resizeType'] === 'c') {
                     $method = 'cropOriginal';
                 } else {
                     $method = 'scaleToFit';
                 }
                 sfContext::getInstance()->getLogger()->info("YY calling converter method {$method} width " . $dimensions['width'] . ' height ' . $dimensions['height']);
                 aImageConverter::$method($source, $output, $dimensions['width'], $dimensions['height']);
                 sfContext::getInstance()->getLogger()->info("YY after converter");
             }
         } else {
             // Don't try to provide an icon alternative to the preview here,
             // it's better to do that at the project and/or apostrophePlugin level
             // where we can style it better... the less we fake templating inside
             // a widget the better. See getFormat
             $url = false;
         }
         return $url;
     }
     return false;
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The value displayed in this widget
  *                             (i.e. the browser-side filename submitted
  *                             on a previous partially successful
  *                             validation of this form)
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $exists = false;
     if (isset($value['persistid']) && strlen($value['persistid'])) {
         $persistid = $value['persistid'];
         $info = aValidatorFilePersistent::getFileInfo($persistid);
         if ($info) {
             $exists = true;
         }
     } else {
         // One implementation, not two (to inevitably drift apart)
         $persistid = aGuid::generate();
     }
     $result = '';
     // hasOption just verifies that the option is valid, it doesn't check what,
     // if anything, was passed. Thanks to Lucjan Wilczewski
     $preview = $this->hasOption('image-preview') ? $this->getOption('image-preview') : false;
     $defaultPreview = $this->hasOption('default-preview') ? $this->getOption('default-preview') : false;
     if ($exists) {
         $defaultPreview = false;
     }
     if ($exists || $defaultPreview) {
         if ($preview) {
             // Note change of key
             $urlStem = sfConfig::get('app_aPersistentFileUpload_preview_url', '/uploads/uploaded_image_preview');
             // This is the corresponding directory path. You have to override one
             // if you override the other. You override this one by setting
             // app_aToolkit_upload_uploaded_image_preview_dir
             $dir = aFiles::getUploadFolder("uploaded_image_preview");
             // While we're here age off stale previews
             aValidatorFilePersistent::removeOldFiles($dir);
             $imagePreview = $this->getOption('image-preview');
             if ($exists) {
                 $source = $info['tmp_name'];
             } else {
                 $source = $defaultPreview;
             }
             $info = aImageConverter::getInfo($source);
             if ($info) {
                 $iwidth = $info['width'];
                 $height = $info['height'];
                 // This is safe - based on sniffed file contents and not a user supplied extension
                 $format = $info['format'];
                 list($iwidth, $iheight) = getimagesize($source);
                 $dimensions = aDimensions::constrain($iwidth, $iheight, $format, $imagePreview);
                 // A simple filename reveals less
                 $imagename = "{$persistid}.{$format}";
                 $url = "{$urlStem}/{$imagename}";
                 $output = "{$dir}/{$imagename}";
                 if (isset($info['newfile']) && $info['newfile'] || !file_exists($output)) {
                     if ($imagePreview['resizeType'] === 'c') {
                         $method = 'cropOriginal';
                     } else {
                         $method = 'scaleToFit';
                     }
                     sfContext::getInstance()->getLogger()->info("YY calling converter method {$method} width " . $dimensions['width'] . ' height ' . $dimensions['height']);
                     aImageConverter::$method($source, $output, $dimensions['width'], $dimensions['height']);
                     sfContext::getInstance()->getLogger()->info("YY after converter");
                 }
             }
             if (isset($imagePreview['markup'])) {
                 $markup = $imagePreview['markup'];
             } else {
                 $markup = '<img src="%s" />';
             }
             $result .= sprintf($markup, $url);
         }
         $result .= $this->getOption('existing-html');
     }
     return $result . $this->renderTag('input', array_merge(array('type' => $this->getOption('type'), 'name' => $name . '[newfile]'), $attributes)) . $this->renderTag('input', array('type' => 'hidden', 'name' => $name . '[persistid]', 'value' => $persistid));
 }
Esempio n. 5
0
 public static function clearAssetCache(sfFilesystem $fileSystem)
 {
     $assetDir = aFiles::getUploadFolder(array('asset-cache'));
     $fileSystem->remove(sfFinder::type('file')->in($assetDir));
     $cache = aAssets::getCache();
     $cache->clean();
 }
Esempio n. 6
0
 /**
  * DOCUMENT ME
  * @return mixed
  */
 public static function getDirectory()
 {
     return aFiles::getUploadFolder('media_items');
 }
Esempio n. 7
0
 public function executeZipDemo(sfWebRequest $request)
 {
     if (!$this->get('zip_demo', false)) {
         throw new sfException('Zip demo feature is not enabled in properties.ini');
     }
     $uploads = aFiles::getUploadFolder();
     $uploadsDemo = "{$uploads}/apostrophedemo-uploads.zip";
     file_put_contents("{$uploads}/readme.txt", "This is the Symfony uploads folder. This file is here so that zipping this folder does not\nresult in an error when it happens to be empty. Move along, nothing to see here.");
     $this->zip($uploadsDemo, $uploads);
     // Has to be in the writable folder or we won't be able to write to it in many cases
     $data = aFiles::getWritableDataFolder();
     $dump = "{$data}/ademocontent.sql";
     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams(sfContext::getInstance()->getConfiguration(), 'doctrine'));
     // Yes, you need to have mysql and mysqldump to use this feature.
     // However you can set app_syncContent_mysqldump to
     // the path of your mysqldump utility if it is called something
     // else or not in the PATH
     $mysql = sfConfig::get('app_syncContent_mysql', 'mysql');
     $mysqldump = sfConfig::get('app_syncContent_mysqldump', 'mysqldump');
     $cmd = escapeshellarg($mysqldump) . " --skip-opt --add-drop-table --create-options " . "--disable-keys --extended-insert --set-charset {$params} > " . escapeshellarg($dump);
     system($cmd, $result);
     if ($result != 0) {
         throw new sfException("mysqldump failed");
     }
     // You can explicitly set demo_password to an empty string to keep
     // the passwords in your demo unchanged
     $demoPassword = $this->get('demo_password', 'demo');
     if (!preg_match('/^\\w+$/', $demoPassword)) {
         throw new sfException("demo_password must contain only alphanumeric characters and underscores");
     }
     if ($demoPassword) {
         // New set of parameters for a temporary database in which we'll fix the passwords so that
         // the demo doesn't allow dictionary attacks on your real passwords
         $params = array();
         $params['dbname'] = $this->get('demo_tempdb');
         $params['username'] = $this->get('demo_tempuser');
         $params['password'] = $this->get('demo_temppassword');
         $params['host'] = $this->get('demo_temphost');
         $params = sfSyncContentTools::shellDatabaseParams($params);
         $cmd = escapeshellarg($mysql) . ' ' . $params . ' < ' . escapeshellarg($dump);
         system($cmd, $result);
         if ($result != 0) {
             throw new sfException("Unable to load sql into tempdb for password alteration. Did you configure tempdb, tempuser, temppassword and temphost in properties.ini?");
         }
         // I really ought to PDO this
         $cmd = escapeshellarg($mysql) . ' ' . $params;
         $out = popen($cmd, "w");
         // If we set the salt here, everyone who starts from the demo has the same salt.
         // If they change their passwords to real passwords, they are still vulnerable to
         // dictionary attack if their databases are compromised.
         // That's no good, so we'll fix the passwords with a clever trick in the demo fixtures
         // task that imports all this. We stash the demo password (not a secret) in the salt field
         // as cleartext for now, and the demo fixtures task grabs that, clears the salt field and
         // calls setPassword, resulting in a new, robustly unique salt on the new site.
         fwrite($out, "UPDATE sf_guard_user SET salt = '{$demoPassword}';\n");
         fwrite($out, "UPDATE sf_guard_user SET password = '';\n");
         $result = pclose($out);
         $cmd = escapeshellarg($mysqldump) . " --skip-opt --add-drop-table --create-options " . "--disable-keys --extended-insert --set-charset {$params} > " . escapeshellarg($dump);
         system($cmd, $result);
         if ($result != 0) {
             throw new sfException('Second mysqldump failed after password adjustment');
         }
     }
     $dataDemo = "{$uploads}/apostrophedemo-awritable.zip";
     $this->zip($dataDemo, $data);
     unlink($dump);
 }