コード例 #1
0
ファイル: test_ProxyWriter.php プロジェクト: gtoffoli/swete
 function testProxifyUrl()
 {
     $proxy = new ProxyWriter();
     $proxy->setSrcUrl(df_absolute_url(DATAFACE_SITE_URL . '/tests/testsites/site1/'));
     $proxy->setProxyUrl(df_absolute_url(DATAFACE_SITE_URL . '/tests/proxysites/site1/'));
     $expected = df_absolute_urL(DATAFACE_SITE_URL . '/tests/testsites/site1/index.html');
     $src = df_absolute_urL(DATAFACE_SITE_URL . '/tests/proxysites/site1/index.html');
     $this->assertEquals($expected, $proxy->unproxifyUrl($src));
     $proxy = new ProxyWriter();
     $proxy->setSrcUrl('http://www.xataface.com/');
     $proxy->setProxyUrl('http://en.xataface.com/path/en/');
     $strs = array('foo' => 'foo', '/foo' => '/path/en/foo', 'http://www.xataface.com/foo' => 'http://en.xataface.com/path/en/foo', 'http://www.xataface.com/foo?bar=1' => 'http://en.xataface.com/path/en/foo?bar=1', 'https://www.xataface.com/foo' => 'https://www.xataface.com/foo', 'http://www.foo.bar/foo' => 'http://www.foo.bar/foo');
     foreach ($strs as $k => $v) {
         $this->assertEquals($v, $proxy->proxifyUrl($k));
         $this->assertEquals($k, $proxy->unproxifyUrl($v));
     }
     $proxy = new ProxyWriter();
     $proxy->setSrcUrl('http://www.xataface.com/');
     $proxy->setProxyUrl('http://en.xataface.com/path/en/');
     $proxy->addAlias('foo', 'roof');
     $strs = array('foo' => 'roof', '/foo' => '/path/en/roof', 'http://www.xataface.com/foo' => 'http://en.xataface.com/path/en/roof', 'https://www.xataface.com/foo' => 'https://www.xataface.com/foo', 'http://www.foo.bar/foo' => 'http://www.foo.bar/foo', 'foo/overview' => 'roof/overview', '/foo/overview' => '/path/en/roof/overview', 'http://www.xataface.com/foo/overview' => 'http://en.xataface.com/path/en/roof/overview', 'https://www.xataface.com/foo/overview' => 'https://www.xataface.com/foo/overview');
     foreach ($strs as $k => $v) {
         $this->assertEquals($v, $proxy->proxifyUrl($k));
         $this->assertEquals($k, $proxy->unproxifyUrl($v));
     }
     $proxy = new ProxyWriter();
     $proxy->setSrcUrl('http://www.xataface.com/siteroot/');
     $proxy->setProxyUrl('http://en.xataface.com/path/en/');
     $proxy->addAlias('foo', 'roof');
     $strs = array('foo' => 'roof', '/foo' => '/foo', 'http://www.xataface.com/siteroot/foo' => 'http://en.xataface.com/path/en/roof', 'https://www.xataface.com/siteroot/foo' => 'https://www.xataface.com/siteroot/foo', 'http://www.foo.bar/siteroot/foo' => 'http://www.foo.bar/siteroot/foo', 'foo/overview' => 'roof/overview', '/siteroot/foo/overview' => '/path/en/roof/overview', 'http://www.xataface.com/siteroot/foo/overview' => 'http://en.xataface.com/path/en/roof/overview', 'https://www.xataface.com/foo/overview' => 'https://www.xataface.com/foo/overview');
     foreach ($strs as $k => $v) {
         $this->assertEquals($v, $proxy->proxifyUrl($k));
         $this->assertEquals($k, $proxy->unproxifyUrl($v));
     }
 }
コード例 #2
0
ファイル: SweteSite.class.php プロジェクト: gtoffoli/swete
 /**
  * @brief Obtains the default @ref ProxyWriter object for this site.  The ProxyWriter
  * is responsible for actually converting the source HTML that is returned from
  * the source site into proxified and translated HTML that is output to the user.
  *
  * <p>The proxy writer is built and cached on the first request so that
  * this can be called multiple times to retrieve the same @ref ProxyWriter object.</p>
  *
  * @returns ProxyWriter The proxy writer for this class.
  */
 public function getProxyWriter()
 {
     if (!isset($this->_proxyWriter)) {
         import('inc/ProxyWriter.php');
         $proxy = new ProxyWriter();
         if ($this->_rec->val('translation_parser_version')) {
             $proxy->translationParserVersion = intval($this->_rec->val('translation_parser_version'));
         }
         $proxy->setProxyUrl($this->getProxyUrl());
         $proxy->setSrcUrl($this->getSiteUrl());
         $res = SweteDb::q("select `name`,`alias` from path_aliases where website_id='" . addslashes($this->_rec->val('website_id')) . "'");
         while ($row = mysql_fetch_assoc($res)) {
             $proxy->addAlias($row['name'], $row['alias']);
         }
         $proxy->setSourceLanguage($this->getSourceLanguage());
         $proxy->setProxyLanguage($this->getDestinationLanguage());
         $proxy->sourceDateLocale = $this->_rec->val('source_date_locale');
         $proxy->targetDateLocale = $this->_rec->val('target_date_locale');
         $this->_proxyWriter = $proxy;
     }
     return $this->_proxyWriter;
 }