diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Edit.php b/lib/Alchemy/Phrasea/Controller/Prod/Edit.php index 0177670ac9..25933800c0 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Edit.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Edit.php @@ -202,7 +202,7 @@ class Edit implements ControllerProviderInterface $thumbnail = $record->get_thumbnail(); $elements[$indice]['subdefs']['thumbnail'] = array( - 'url' => $thumbnail->get_url() + 'url' => (string) $thumbnail->get_url() , 'w' => $thumbnail->get_width() , 'h' => $thumbnail->get_height() ); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Records.php b/lib/Alchemy/Phrasea/Controller/Prod/Records.php index aae7f085eb..0fa37b5080 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Records.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Records.php @@ -272,7 +272,7 @@ class Records implements ControllerProviderInterface $renewed = array(); foreach ($records as $record) { - $renewed[$record->get_serialize_key()] = $record->get_preview()->renew_url(); + $renewed[$record->get_serialize_key()] = (string) $record->get_preview()->renew_url(); }; return $app->json($renewed); diff --git a/lib/classes/API/V1/adapter.php b/lib/classes/API/V1/adapter.php index 7e6f0756c2..334ba53356 100644 --- a/lib/classes/API/V1/adapter.php +++ b/lib/classes/API/V1/adapter.php @@ -1728,6 +1728,9 @@ class API_V1_adapter extends API_V1_Abstract */ protected function list_permalink(media_Permalink_Adapter $permalink, registryInterface $registry) { + $downloadUrl = $permalink->get_url(); + $downloadUrl->getQuery()->set('download', '1'); + return array( 'created_on' => $permalink->get_created_on()->format(DATE_ATOM), 'id' => $permalink->get_id(), @@ -1735,8 +1738,8 @@ class API_V1_adapter extends API_V1_Abstract 'label' => $permalink->get_label(), 'updated_on' => $permalink->get_last_modified()->format(DATE_ATOM), 'page_url' => $permalink->get_page(), - 'download_url' => $permalink->get_url() . '&download', - 'url' => $permalink->get_url() + 'download_url' => (string) $downloadUrl, + 'url' => (string) $permalink->get_url() ); } diff --git a/lib/classes/Feed/XML/Abstract.php b/lib/classes/Feed/XML/Abstract.php index eab96e17f6..9895900274 100644 --- a/lib/classes/Feed/XML/Abstract.php +++ b/lib/classes/Feed/XML/Abstract.php @@ -294,7 +294,7 @@ abstract class Feed_XML_Abstract if ($preview_permalink) { $preview = $this->addTag($document, $group, 'media:content'); - $preview->setAttribute('url', $preview_permalink->get_url()); + $preview->setAttribute('url', (string) $preview_permalink->get_url()); $preview->setAttribute('fileSize', $preview_sd->get_size()); $preview->setAttribute('type', $preview_sd->get_mime()); $preview->setAttribute('medium', $medium); @@ -312,7 +312,7 @@ abstract class Feed_XML_Abstract if ($thumbnail_permalink) { $thumbnail = $this->addTag($document, $group, 'media:thumbnail'); - $thumbnail->setAttribute('url', $thumbnail_permalink->get_url()); + $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url()); if ($thumbnail_sd->get_width()) $thumbnail->setAttribute('width', $thumbnail_sd->get_width()); @@ -321,7 +321,7 @@ abstract class Feed_XML_Abstract $thumbnail = $this->addTag($document, $group, 'media:content'); - $thumbnail->setAttribute('url', $thumbnail_permalink->get_url()); + $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url()); $thumbnail->setAttribute('fileSize', $thumbnail_sd->get_size()); $thumbnail->setAttribute('type', $thumbnail_sd->get_mime()); $thumbnail->setAttribute('medium', $medium); diff --git a/lib/classes/Feed/XML/Cooliris.php b/lib/classes/Feed/XML/Cooliris.php index a5e32ae656..284a55f06d 100644 --- a/lib/classes/Feed/XML/Cooliris.php +++ b/lib/classes/Feed/XML/Cooliris.php @@ -394,7 +394,7 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface if ($preview_permalink) { $preview = $this->addTag($document, $item, 'media:content'); - $preview->setAttribute('url', $preview_permalink->get_url()); + $preview->setAttribute('url', (string) $preview_permalink->get_url()); $preview->setAttribute('fileSize', $preview_sd->get_size()); $preview->setAttribute('type', $preview_sd->get_mime()); $preview->setAttribute('medium', $medium); @@ -412,7 +412,7 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface if ($thumbnail_permalink) { $thumbnail = $this->addTag($document, $item, 'media:thumbnail'); - $thumbnail->setAttribute('url', $thumbnail_permalink->get_url()); + $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url()); if ($thumbnail_sd->get_width()) $thumbnail->setAttribute('width', $thumbnail_sd->get_width()); @@ -421,7 +421,7 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface $thumbnail = $this->addTag($document, $item, 'media:content'); - $thumbnail->setAttribute('url', $thumbnail_permalink->get_url()); + $thumbnail->setAttribute('url', (string) $thumbnail_permalink->get_url()); $thumbnail->setAttribute('fileSize', $thumbnail_sd->get_size()); $thumbnail->setAttribute('type', $thumbnail_sd->get_mime()); $thumbnail->setAttribute('medium', $medium); diff --git a/lib/classes/media/Permalink/Adapter.php b/lib/classes/media/Permalink/Adapter.php index 313b3dc740..cc5f3c444c 100644 --- a/lib/classes/media/Permalink/Adapter.php +++ b/lib/classes/media/Permalink/Adapter.php @@ -11,6 +11,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Exception\RuntimeException; +use Guzzle\Http\Url; /** * @@ -142,19 +143,19 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea /** * - * @return string + * @return Url */ public function get_url() { $label = $this->get_label() . '.' . pathinfo($this->media_subdef->get_file(), PATHINFO_EXTENSION); - return $this->app->url('permalinks_permalink', array( + return Url::factory($this->app->url('permalinks_permalink', array( 'sbas_id' => $this->media_subdef->get_sbas_id(), 'record_id' => $this->media_subdef->get_record_id(), 'subdef' => $this->media_subdef->get_name(), 'label' => $label, 'token' => $this->get_token(), - )); + ))); } /** diff --git a/lib/classes/media/abstract.php b/lib/classes/media/abstract.php index 73f699a577..c9f4b32ca5 100644 --- a/lib/classes/media/abstract.php +++ b/lib/classes/media/abstract.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Guzzle\Http\Url; + /** * * @package subdefs @@ -19,7 +21,7 @@ abstract class media_abstract { /** * - * @var string + * @var Url */ protected $url; @@ -45,7 +47,7 @@ abstract class media_abstract * @param int $height * @return media */ - public function __construct($url, $width, $height) + public function __construct(Url $url, $width, $height) { $this->url = $url; $this->height = (int) $height; @@ -65,7 +67,7 @@ abstract class media_abstract /** * - * @return string + * @return Url */ public function get_url() { diff --git a/lib/classes/media/subdef.php b/lib/classes/media/subdef.php index 0849875302..9fdb5145fb 100644 --- a/lib/classes/media/subdef.php +++ b/lib/classes/media/subdef.php @@ -13,6 +13,7 @@ use Alchemy\Phrasea\Application; use MediaAlchemyst\Alchemyst; use MediaVorus\MediaVorus; use MediaVorus\Media\MediaInterface; +use Guzzle\Http\Url; /** * @@ -231,7 +232,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface , 'height' => $this->height , 'etag' => $this->etag , 'path' => $this->path - , 'url' => $this->url . ($this->is_physically_present ? '?etag=' . $this->etag : '') + , 'url' => $this->url , 'file' => $this->file , 'physically_present' => $this->is_physically_present , 'is_substituted' => $this->is_substituted @@ -280,7 +281,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $this->height = 256; $this->path = $this->app['root.path'] . '/www/skins/icons/substitution/'; $this->file = 'regroup_thumb.png'; - $this->url = '/skins/icons/substitution/regroup_thumb.png'; + $this->url = Url::factory('/skins/icons/substitution/regroup_thumb.png'); } else { $mime = $this->record->get_mime(); $mime = trim($mime) != '' ? str_replace('/', '_', $mime) : 'application_octet-stream'; @@ -290,7 +291,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $this->height = 256; $this->path = $this->app['root.path'] . '/www/skins/icons/substitution/'; $this->file = str_replace('+', '%20', $mime) . '.png'; - $this->url = '/skins/icons/substitution/' . $this->file; + $this->url = Url::factory('/skins/icons/substitution/' . $this->file); } $this->is_physically_present = false; @@ -298,7 +299,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface if ( ! file_exists($this->path . $this->file)) { $this->path = $this->app['root.path'] . '/www/skins/icons/'; $this->file = 'substitution.png'; - $this->url = '/skins/icons/' . $this->file; + $this->url = Url::factory('/skins/icons/' . $this->file); } return $this; @@ -367,9 +368,11 @@ class media_subdef extends media_abstract implements cache_cacheableInterface public function get_url() { $url = parent::get_url(); - $etag = $this->getEtag(); + if (null !== $this->getEtag()) { + $url->getQuery()->set('etag', $this->getEtag()); + } - return $url . ($etag ? '?etag=' . $etag : ''); + return $url; } /** @@ -747,9 +750,9 @@ class media_subdef extends media_abstract implements cache_cacheableInterface } } - $this->url = "/datafiles/" . $this->record->get_sbas_id() + $this->url = Url::factory("/datafiles/" . $this->record->get_sbas_id() . "/" . $this->record->get_record_id() . "/" - . $this->get_name() . "/"; + . $this->get_name() . "/"); return; } diff --git a/lib/classes/module/report/nav.php b/lib/classes/module/report/nav.php index 1e499c8d45..194398ad5f 100644 --- a/lib/classes/module/report/nav.php +++ b/lib/classes/module/report/nav.php @@ -520,7 +520,7 @@ class module_report_nav extends module_report $this->result[] = array( 'photo' => "" + src='" . (string) $x->get_url() . "'>" , 'record_id' => $record->get_record_id() , 'date' => $this->app['date-formatter']->getPrettyString($document->get_creation_date()) , 'type' => $document->get_mime() diff --git a/lib/classes/p4file.php b/lib/classes/p4file.php index 0af334c3f0..d57234130b 100644 --- a/lib/classes/p4file.php +++ b/lib/classes/p4file.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Guzzle\Http\Url; + class p4file { @@ -52,7 +54,7 @@ class p4file } } - return $ret; + return Url::factory($ret); } } diff --git a/lib/classes/record/preview.php b/lib/classes/record/preview.php index b5c41c1351..4d98ab3257 100644 --- a/lib/classes/record/preview.php +++ b/lib/classes/record/preview.php @@ -11,6 +11,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; +use Guzzle\Http\Url; /** * @@ -479,7 +480,7 @@ class record_preview extends record_adapter $width = 350; $height = 150; - $url = 'http://chart.apis.google.com/chart?' . + $url = Url::factory('http://chart.apis.google.com/chart?' . 'chs=' . $width . 'x' . $height . '&chd=t:' . implode(',', $views) . '&cht=lc' . @@ -492,7 +493,7 @@ class record_preview extends record_adapter . date_format(new DateTime(), 'd M') . '|1:|0|' . round($top / 2, 2) . '|' . $top . '|2:|min|average|max' . - '&chxp=2,' . $min . ',' . $average . ',' . $max; + '&chxp=2,' . $min . ',' . $average . ',' . $max); $this->view_popularity = new media_adapter($url, $width, $height); @@ -559,12 +560,12 @@ class record_preview extends record_adapter $width = 550; $height = 100; - $url = 'http://chart.apis.google.com/chart?' + $url = Url::factory('http://chart.apis.google.com/chart?' . 'cht=p3&chf=bg,s,00000000&chd=t:' . implode(',', $referrers) . '&chs=' . $width . 'x' . $height . '&chl=' - . urlencode(implode('|', array_keys($referrers))) . ''; + . urlencode(implode('|', array_keys($referrers)))); $this->refferer_popularity = new media_adapter($url, $width, $height); @@ -635,7 +636,7 @@ class record_preview extends record_adapter $width = 250; $height = 150; - $url = 'http://chart.apis.google.com/chart?' . + $url = Url::factory('http://chart.apis.google.com/chart?' . 'chs=' . $width . 'x' . $height . '&chd=t:' . implode(',', $dwnls) . '&cht=lc' . @@ -645,7 +646,7 @@ class record_preview extends record_adapter '&chxl=0:|' . date_format(new DateTime('-30 days'), 'd M') . '|' . date_format(new DateTime('-15 days'), 'd M') . '|' . date_format(new DateTime(), 'd M') . '|1:|0|' - . round($top / 2) . '|' . $top . ''; + . round($top / 2) . '|' . $top); $ret = new media_adapter($url, $width, $height); $this->download_popularity = $ret; diff --git a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php index 4a8b36f024..f3b179ba62 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php @@ -2226,7 +2226,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $expected = $subdef->get_permalink()->get_last_modified(); $found = \DateTime::createFromFormat(DATE_ATOM, $permalink['updated_on']); - + $this->assertLessThanOrEqual(1, $expected->diff($found)->format('U')); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['updated_on']); $this->assertDateAtom($permalink['updated_on']); @@ -2244,7 +2244,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->assertArrayHasKey("download_url", $permalink); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['download_url']); - $this->assertEquals($subdef->get_permalink()->get_url() . '&download', $permalink['download_url']); + $this->assertEquals((string) $subdef->get_permalink()->get_url() . '&download=1', $permalink['download_url']); $this->checkUrlCode200($permalink['download_url']); $this->assertPermalinkHeaders($permalink['download_url'], $subdef, "download_url"); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php index ddc12da773..6bfa68f6b8 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php @@ -561,7 +561,7 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract foreach ($current_attributes as $attribute => $value) { switch ($attribute) { case "url": - $this->assertEquals($permalink->get_url(), $value); + $this->assertEquals((string) $permalink->get_url(), $value); break; case "fileSize": $this->assertEquals($ressource->get_size(), $value); diff --git a/tests/classes/media/Permalink/media_Permalink_AdapterTest.php b/tests/classes/media/Permalink/media_Permalink_AdapterTest.php index 3d15bb6cbf..d188ce8078 100644 --- a/tests/classes/media/Permalink/media_Permalink_AdapterTest.php +++ b/tests/classes/media/Permalink/media_Permalink_AdapterTest.php @@ -56,7 +56,7 @@ class media_Permalink_AdapterTest extends PhraseanetPHPUnitAbstract . '.' . pathinfo(self::$DI['record_1']->get_subdef('document')->get_file(), PATHINFO_EXTENSION) . '?token=' . static::$object->get_token(); - $this->assertEquals($url, static::$object->get_url()); + $this->assertEquals($url, (string) static::$object->get_url()); } public function testGet_Previewurl() @@ -72,7 +72,7 @@ class media_Permalink_AdapterTest extends PhraseanetPHPUnitAbstract . '.' . pathinfo(self::$DI['record_1']->get_subdef('preview')->get_file(), PATHINFO_EXTENSION) . '?token=' . $previewPermalink->get_token(); - $this->assertEquals($url, $previewPermalink->get_url()); + $this->assertEquals($url, (string) $previewPermalink->get_url()); } public function testGet_page() diff --git a/tests/classes/media/media_subdefTest.php b/tests/classes/media/media_subdefTest.php index 230d437d88..9ad3a7e4c2 100644 --- a/tests/classes/media/media_subdefTest.php +++ b/tests/classes/media/media_subdefTest.php @@ -91,8 +91,10 @@ class media_subdefTest extends \PhraseanetPHPUnitAbstract */ public function testGet_url() { - $this->assertEquals('/skins/icons/substitution/image_jpeg.png', self::$objectNotPresent->get_url()); - $this->assertRegExp('#\/datafiles\/' . self::$objectPresent->get_sbas_id() . '\/' . self::$objectPresent->get_record_id() . '\/preview\/\?etag=[0-9a-f]{32}#', self::$objectPresent->get_url()); + $this->assertInstanceOf('Guzzle\Http\Url', self::$objectNotPresent->get_url()); + $this->assertInstanceOf('Guzzle\Http\Url', self::$objectPresent->get_url()); + $this->assertEquals('/skins/icons/substitution/image_jpeg.png', (string) self::$objectNotPresent->get_url()); + $this->assertRegExp('#\/datafiles\/' . self::$objectPresent->get_sbas_id() . '\/' . self::$objectPresent->get_record_id() . '\/preview\/\?etag=[0-9a-f]{32}#', (string) self::$objectPresent->get_url()); } /** @@ -253,8 +255,8 @@ class media_subdefTest extends \PhraseanetPHPUnitAbstract */ public function testRenew_url() { - $this->assertInternalType('string', self::$objectPresent->renew_url()); - $this->assertInternalType('string', self::$objectNotPresent->renew_url()); + $this->assertInstanceOf('Guzzle\Http\Url', self::$objectPresent->renew_url()); + $this->assertInstanceOf('Guzzle\Http\Url', self::$objectNotPresent->renew_url()); } /**