function testProxifyCss() { $proxy = new ProxyWriter(); $proxy->setSrcUrl('http://www.xataface.com/'); $proxy->setProxyUrl('http://en.xataface.com/path/en/'); $strs = array('div { background-image: url(foo); }' => 'div { background-image: url(foo); }', 'div { background-image: url(/foo); }' => 'div { background-image: url(/path/en/foo); }'); foreach ($strs as $k => $v) { $this->assertEquals($v, $proxy->proxifyCss($k)); } }
/** * Tests foreign keys but checks using ProxyWriter. * * @return void */ public function testFKInspect() { $faultyWriter = new \FaultyWriter(R::getDatabaseAdapter()); try { $null = \ProxyWriter::callMethod($faultyWriter, 'getForeignKeyForTypeProperty', 'test', 'test'); pass(); } catch (\Exception $e) { fail(); } asrt(is_null($null), TRUE); $writer = R::getWriter(); R::nuke(); $book = R::dispense('book'); $page = R::dispense('page'); $book->xownPage[] = $page; R::store($book); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'book_id'); asrt(is_array($keys), TRUE); asrt($keys['on_delete'], 'CASCADE'); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'id'); asrt(is_null($keys), TRUE); R::nuke(); $book = R::dispense('book'); $page = R::dispense('page'); $book->ownPage[] = $page; R::store($book); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'book_id'); asrt(is_array($keys), TRUE); asrt($keys['on_delete'], 'SET NULL'); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'id'); asrt(is_null($keys), TRUE); R::nuke(); $book = R::dispense('book'); $page = R::dispense('page'); $book->alias('magazine')->xownPage[] = $page; R::store($book); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'magazine_id'); asrt(is_array($keys), TRUE); asrt($keys['on_delete'], 'CASCADE'); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'book_id'); asrt(is_null($keys), TRUE); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'id'); asrt(is_null($keys), TRUE); R::nuke(); $book = R::dispense('book'); $page = R::dispense('page'); $book->cover = $page; R::store($book); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book', 'cover_id'); asrt(is_array($keys), TRUE); asrt($keys['on_delete'], 'SET NULL'); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book', 'page_id'); asrt(is_null($keys), TRUE); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book', 'id'); asrt(is_null($keys), TRUE); R::nuke(); $book = R::dispense('book'); $category = R::dispense('category'); $book->sharedTag[] = $category; R::store($book); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book_category', 'book_id'); asrt(is_array($keys), TRUE); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book_category', 'category_id'); asrt(is_array($keys), TRUE); $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book_category', 'id'); asrt(is_null($keys), TRUE); }
/** * @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; }
/** * @brief Applies translations from a translation memory to the webpage contents. It returns another SweteWebpage * object representing the same webpage but in the destination language of the translation memory. * No changes are saved to the database.. you need to save the resulting SweteWebpage to make the changes * persist. * * Note: If there are no matches in the translation memory, then the resulting object will just contain * the source language. This could be overwriting a previous translation so be very careful before * saving. * * @param XFTranslationMemory $mem The translation memory to apply to the webpage contents. * @param array &$stats Out array of stats from the translation. This array contains the following * keys: * <ul> * <li><b>misses</b> - The number of strings for which there were no translations in the memory.</li> * <li><b>matches</b> - The number of strings that were replaced with a translation.</li> * </ul> * @param int $minStatus The minimum approval status to accept for a translation. * @param int $maxStatus The maximum approval status to accept for a translation. * @returns SweteWebpage A webpage in the destination language including the translations. */ public function applyTranslationsFromMemory(XFTranslationMemory $mem, &$stats, $minStatus = 3, $maxStatus = 5) { if ($mem->getSourceLanguage() != $this->getLanguage()) { throw new Exception("Translation memory language does not match the record language."); } import('inc/ProxyWriter.php'); $proxy = new ProxyWriter(); $proxy->setTranslationMemory($mem); $proxy->setMinTranslationStatus($minStatus); $proxy->setMaxTranslationStatus($maxStatus); $html = $proxy->translateHtml($this->_rec->val('webpage_content'), $stats); $out = $this->getTranslation($mem->getDestinationLanguage()); $out->getRecord()->setValue('webpage_content', $html); return $out; }