예제 #1
0
/**
 * @param  string  $text
 * @param  sfAsset $asset
 * @return string
 */
function link_to_asset_action($text, $asset)
{
    $user = sfContext::getInstance()->getUser();
    if ($user->hasAttribute('popup', 'sf_admin/sf_asset/navigation')) {
        switch ($user->getAttribute('popup', null, 'sf_admin/sf_asset/navigation')) {
            case 1:
                // popup called from a Rich Text Editor (ex: TinyMCE)
                #return link_to($text, '@sf_asset_library_tiny_config?id=' . $asset->getId(), 'title=' . $asset->getFilename());
                throw new sfAssetException('this option should be unused...');
            case 2:
                // popup called from a simple form input (or via input_sf_asset_tag)
                return link_to_function($text, "setImageField('" . $asset->getUrl() . "','" . $asset->getUrl('small') . "'," . $asset->getId() . ')');
        }
    } else {
        // case : sf view (i.e. module sfAsset, view list)
        return link_to($text, '@sf_asset_library_edit?id=' . $asset->getId(), 'title=' . $asset->getFilename());
    }
}
 $t->diag('sfAsset::getUrl()');
 $t->is($sfAsset->getUrl(), '/' . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getUrl() returns the asset URL');
 $t->is($sfAsset->getUrl('small'), '/' . sfConfig::get('app_sfAssetsLibrary_upload_dir') . '/thumbnail/small_filename.jpg', 'getUrl(\'small\') returns the small thumbnail url');
 $t->is($sfAsset->getUrl('large'), '/' . sfConfig::get('app_sfAssetsLibrary_upload_dir') . '/thumbnail/large_filename.jpg', 'getUrl(\'large\') returns the large thumbnail url');
 $t->diag('sfAsset::create()');
 $assets_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
 $test_asset = $assets_path . 'raikkonen.jpg';
 $folder1 = new sfAssetFolder();
 $folder1->getNode()->insertAsFirstChildOf($root);
 $folder1->setName('Test_Directory');
 $folder1->save();
 $asset1 = new sfAsset();
 $asset1->setFolder($folder1);
 $asset1->create($test_asset, false);
 $asset_file_size = (int) (filesize($test_asset) / 1024);
 $t->is($asset1->getFilename(), 'raikkonen.jpg', 'create() sets the object filename according to the given asset');
 $t->is($asset1->getFilesize(), 18, 'create() sets the object filesize according to the given asset');
 $t->ok($asset1->isImage(), 'create() sets the object type according to the given asset');
 $t->is($asset1->getUrl(), $folder1->getUrl() . '/' . $asset1->getFilename(), 'create() sets the object url according to the given asset and folder object');
 $t->ok(is_file($asset1->getFullPath()), 'create() physically copies asset');
 $t->ok(is_file($asset1->getFullPath('large')), 'create() physically creates thumbnail');
 $t->diag('sfAsset::move()');
 $old_path = $asset1->getFullPath();
 $old_thumb_path = $asset1->getFullPath('large');
 $asset1->move($root, 'raikkonen2.jpg');
 $t->is($asset1->getFilename(), 'raikkonen2.jpg', 'move() changes filename');
 $t->is($asset1->getUrl(), $root->getUrl() . '/' . $asset1->getFilename(), 'move() changes the object url according to the new folder');
 $t->ok(is_file($asset1->getFullPath()), 'move() physically moves asset to the new location');
 $t->ok(!is_file($old_path), 'move() physically removes asset from the previous location');
 $t->ok(is_file($asset1->getFullPath('large')), 'move() physically moves thumbnail to the new location');
 $t->ok(!is_file($old_thumb_path), 'move() physically removes thumbnail from the previous location');
예제 #3
0
 $t->isa_ok($sfAsset->getsfAssetFolder(), 'sfAssetFolder', 'sfAsset can have root as folder');
 $sfAsset->setFilename('filename.jpg');
 $t->is($sfAsset->getRelativePath(), sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getRelativePath() gives correct result');
 //  sfConfig::set('sf_web_dir', 'var/www/myproject');
 sfConfig::set('app_sfAssetsLibrary_upload_dir', 'medias');
 $t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getFullPath() gives complete path');
 $t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'thumbnail/large_filename.jpg', 'getFullPath() gives correct thumbnail path');
 $t->is($sfAsset->getUrl(), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getUrl() gives correct url');
 $t->is($sfAsset->getUrl('small'), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'thumbnail/small_filename.jpg', 'getUrl() gives correctthumbnail url');
 $assets_path = dirname(__FILE__) . '/../assets/';
 $test_asset = $assets_path . 'raikkonen.jpg';
 $t->ok(is_file($test_asset), 'test asset found');
 $sfAsset = new sfAsset();
 $sfAsset->setsfAssetFolder(sfAssetFolderPeer::getRoot());
 $sfAsset->create($test_asset, false);
 $t->is($sfAsset->getFilename(), 'raikkonen.jpg', 'create() gives correct filename');
 $t->is($sfAsset->getFilesize(), 18, 'create() gives correct size');
 $t->ok($sfAsset->isImage(), 'create() gives correct type');
 $t->ok(is_file($sfAsset->getFullPath()), 'create() physically copies asset');
 $t->ok(is_file($sfAsset->getFullPath('large')), 'create() physically creates thumbnail');
 $old_path = $sfAsset->getFullPath();
 $old_thumb_path = $sfAsset->getFullPath('large');
 $sfAsset->move(sfAssetFolderPeer::getRoot(), 'raikkonen2.jpg');
 $t->is($sfAsset->getFilename(), 'raikkonen2.jpg', 'move() changes filename');
 $t->ok(is_file($sfAsset->getFullPath()), 'move() physically moves asset');
 $t->ok(!is_file($old_path), 'move() physically moves asset');
 $t->ok(is_file($sfAsset->getFullPath('large')), 'move() physically moves thumbnail');
 $t->ok(!is_file($old_thumb_path), 'move() physically moves thumbnail');
 $old_path = $sfAsset->getFullPath();
 $old_thumb_path = $sfAsset->getFullPath('large');
 $old_id = $sfAsset->getId();