function testContentLinkInjections()
 {
     $field = new Text();
     // External links injection.
     $field->setValue('<a href="http://newzealand.govt.nz">New Zealand Government</a>');
     $this->assertEquals($field->RichLinks(), '<a class="external" rel="external" title="Open external link" href="http://newzealand.govt.nz">New Zealand Government ' . '<span class="nonvisual-indicator">(external link)</span> </a>', 'Injects attributes to external link without target.');
     $field->setValue('<a href="http://newzealand.govt.nz" target="_blank">New Zealand Government</a>');
     $this->assertEquals($field->RichLinks(), '<a class="external" rel="external" title="Open external link" href="http://newzealand.govt.nz" target="_blank">New Zealand Government ' . '<span class="nonvisual-indicator">(external link)</span> </a>', 'Injects attributes to external link with target, while keeping the existing attributes.');
     // Check the normal links are not affected.
     $field->setValue('<a href="[sitetree_link,id=1]">Internal</a>');
     $this->assertEquals($field->RichLinks(), '<a href="[sitetree_link,id=1]">Internal</a>', 'Regular link is not modified.');
 }
Exemplo n.º 2
0
 /**
  *
  * @param string $value Date in format YYYY-MM-DD
  * @return type
  * @throws \Exception
  */
 public function setValue($value)
 {
     if (empty($value)) {
         return;
     }
     /**
      * Below deals with an integer and tries to identify if it is a timestamp
      * or date formatted.
      */
     if (is_int($value)) {
         $value = 333923;
         $date_string_test = strftime('%Y%m%d', $value);
         if ($date_string_test < 19700101) {
             $date_string_test2 = strftime('%Y%m%d', strtotime($value));
             if ($date_string_test2 < 19700101) {
                 throw new \Exception('Bad integer value sent to Form\\Input\\Date');
             } else {
                 $value = strftime('%Y-%m-%d', strtotime($value));
             }
         } else {
             $value = strftime('%Y-%m-%d', $value);
         }
     }
     if (!preg_match('/\\d{4}-\\d{2}-\\d{2}/', $value)) {
         throw new \Exception(t('Date format is YYYY-MM-DD: %s', $value));
     }
     parent::setValue($value);
 }
 /**
  * Gets a list of all the items in the RSS feed given a user-provided URL, limit, and date format
  *
  * @return ArrayList
  */
 public function RSSItems()
 {
     if (!$this->FeedURL) {
         return false;
     }
     $doc = new DOMDocument();
     @$doc->load($this->FeedURL);
     $items = $doc->getElementsByTagName('item');
     $feeds = array();
     foreach ($items as $node) {
         $itemRSS = array('title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue);
         $feeds[] = $itemRSS;
     }
     $output = ArrayList::create(array());
     $count = 0;
     foreach ($feeds as $item) {
         if ($count >= $this->Count) {
             break;
         }
         // Cast the Date
         $date = new Date('Date');
         $date->setValue($item['date']);
         // Cast the Title
         $title = new Text('Title');
         $title->setValue($item['title']);
         $output->push(new ArrayData(array('Title' => $title, 'Date' => $date->Format($this->DateFormat), 'Link' => $item['link'])));
         $count++;
     }
     return $output;
 }
Exemplo n.º 4
0
 public function setValue($value)
 {
     if ($value && !preg_match("@^(https?|ftp)://@", $value)) {
         $value = "http://{$value}";
     }
     return parent::setValue($value);
 }
 public function setValue($value, $record = null)
 {
     if (!is_string($value)) {
         $value = json_encode($value);
     }
     return parent::setValue($value, $record);
 }
Exemplo n.º 6
0
	function FeedItems() {
		$output = new DataObjectSet();
		
		include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));
		
		$t1 = microtime(true);
		$this->feed = new SimplePie($this->AbsoluteRssUrl, TEMP_FOLDER);
		$this->feed->init();
		if($items = $this->feed->get_items(0, $this->NumberToShow)) {
			foreach($items as $item) {
				
				// Cast the Date
				$date = new Date('Date');
				$date->setValue($item->get_date());

				// Cast the Title
				$title = new Text('Title');
				$title->setValue($item->get_title());

				$output->push(new ArrayData(array(
					'Title' => $title,
					'Date' => $date,
					'Link' => $item->get_link()
				)));
			}
			return $output;
		}
	}
Exemplo n.º 7
0
 /**
  * Test {@link Text->LimitWordCountXML()}
  */
 function testLimitWordCountXML()
 {
     $cases = array('<p>Stuff & stuff</p>' => 'Stuff &amp;...', "Stuff\nBlah Blah Blah" => "Stuff<br />Blah Blah...", "Stuff<Blah Blah" => "Stuff&lt;Blah Blah", "Stuff>Blah Blah" => "Stuff&gt;Blah Blah");
     foreach ($cases as $originalValue => $expectedValue) {
         $textObj = new Text('Test');
         $textObj->setValue($originalValue);
         $this->assertEquals($expectedValue, $textObj->LimitWordCountXML(3));
     }
 }
Exemplo n.º 8
0
 public function setValue($value)
 {
     if (is_int($value)) {
         $value = date($this->format, $value);
     } elseif ($time = strtotime($value)) {
         $value = date($this->format, $time);
     }
     return parent::setValue($value);
 }
Exemplo n.º 9
0
 /**
  * Test {@link Text->LimitSentences()}
  */
 public function testLimitSentences()
 {
     $cases = array('' => '', 'First sentence.' => 'First sentence.', 'First sentence. Second sentence' => 'First sentence. Second sentence.', '<p>First sentence.</p>' => 'First sentence.', '<p>First sentence. Second sentence. Third sentence</p>' => 'First sentence. Second sentence.', '<p>First sentence. <em>Second sentence</em>. Third sentence</p>' => 'First sentence. Second sentence.', '<p>First sentence. <em class="dummyClass">Second sentence</em>. Third sentence</p>' => 'First sentence. Second sentence.');
     foreach ($cases as $originalValue => $expectedValue) {
         $textObj = new Text('Test');
         $textObj->setValue($originalValue);
         $this->assertEquals($expectedValue, $textObj->LimitSentences(2));
     }
 }
Exemplo n.º 10
0
 public function setValue($value)
 {
     if (!is_null($value)) {
         $tmp = preg_replace('/[^\\d]/', '', $value);
         if (strlen($tmp)) {
             $value = $tmp;
             if ($value[0] != '0') {
                 $value = "0{$value}";
             }
         }
     }
     return parent::setValue($value);
 }
 /**
  * Adds the part for 'download search' to the breadcrumbs. Sets the link for
  * The default action in breadcrumbs.
  *
  * @param int  $maxDepth       maximum levels
  * @param bool $unlinked       link breadcrumbs elements
  * @param bool $stopAtPageType name of PageType to stop at
  * @param bool $showHidden     show pages that will not show in menus
  * 
  * @return string
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 27.06.2011
  */
 public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false)
 {
     $page = $this;
     $pages = array();
     while ($page && (!$maxDepth || count($pages) < $maxDepth) && (!$stopAtPageType || $page->ClassName != $stopAtPageType)) {
         if ($showHidden || $page->ShowInMenus || $page->ID == $this->ID) {
             $pages[] = $page;
         }
         $page = $page->Parent;
     }
     if (Controller::curr()->getAction() == 'results') {
         $title = new Text();
         $title->setValue(_t('SilvercartDownloadPageHolder.SearchResults'));
         array_unshift($pages, new ArrayData(array('MenuTitle' => $title, 'Title' => $title, 'Link' => '')));
     }
     $template = new SSViewer('BreadcrumbsTemplate');
     return $template->process($this->customise(new ArrayData(array('Pages' => new ArrayList(array_reverse($pages))))));
 }
Exemplo n.º 12
0
 /**
  * Overload set value
  *
  * @param mixed $value
  * @return $this
  */
 public function setValue($value)
 {
     if (!empty($value)) {
         try {
             $date = substr($value, 0, strlen(date($this->getFormatDisplay())));
             $value = \Carbon\Carbon::createFromFormat($this->getFormatDisplay(), $date);
         } catch (\InvalidArgumentException $e) {
             try {
                 $date = substr($value, 0, strlen(date($this->getFormatStore())));
                 $value = \Carbon\Carbon::createFromFormat($this->getFormatStore(), $date);
             } catch (\InvalidArgumentException $e) {
                 throw $e;
             }
         } finally {
             $value = $value instanceof \Carbon\Carbon ? $value->format($this->getFormatStore()) : '';
         }
     }
     return parent::setValue($value);
 }
 /**
  * Overrides the ContentControllerSearchExtension and adds snippets to results.
  */
 function results($data, $form, $request)
 {
     $this->linkToAllSiteRSSFeed();
     $results = $form->getResults();
     $query = $form->getSearchQuery();
     // Add context summaries based on the queries.
     foreach ($results as $result) {
         $contextualTitle = new Text();
         $contextualTitle->setValue($result->MenuTitle ? $result->MenuTitle : $result->Title);
         $result->ContextualTitle = $contextualTitle->ContextSummary(300, $query);
         if (!$result->Content && $result->ClassName == 'File') {
             // Fake some content for the files.
             $result->ContextualContent = "A file named \"{$result->Name}\" ({$result->Size}).";
         } else {
             $result->ContextualContent = $result->obj('Content')->ContextSummary(300, $query);
         }
     }
     $rssLink = HTTP::setGetVar('rss', '1');
     // Render the result.
     $data = array('Results' => $results, 'Query' => $query, 'Title' => _t('SearchForm.SearchResults', 'Search Results'), 'RSSLink' => $rssLink);
     // Choose the delivery method - rss or html.
     if (!$this->owner->request->getVar('rss')) {
         // Add RSS feed to normal search.
         RSSFeed::linkToFeed($rssLink, "Search results for query \"{$query}\".");
         return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
     } else {
         // De-paginate and reorder. Sort-by-relevancy doesn't make sense in RSS context.
         $fullList = $results->getList()->sort('LastEdited', 'DESC');
         // Get some descriptive strings
         $siteName = SiteConfig::current_site_config()->Title;
         $siteTagline = SiteConfig::current_site_config()->Tagline;
         if ($siteName) {
             $title = "{$siteName} search results for query \"{$query}\".";
         } else {
             $title = "Search results for query \"{$query}\".";
         }
         // Generate the feed content.
         $rss = new RSSFeed($fullList, $this->owner->request->getURL(), $title, $siteTagline, "Title", "ContextualContent", null);
         $rss->setTemplate('Page_results_rss');
         return $rss->outputToBrowser();
     }
 }
Exemplo n.º 14
0
 function FeedItems()
 {
     $output = new DataObjectSet();
     // Protection against infinite loops when an RSS widget pointing to this page is added to this page
     if (stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) {
         return $output;
     }
     include_once Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.inc');
     $t1 = microtime(true);
     $feed = new SimplePie($this->AbsoluteRssUrl, TEMP_FOLDER);
     $feed->init();
     if ($items = $feed->get_items(0, $this->NumberToShow)) {
         foreach ($items as $item) {
             // Cast the Date
             $date = new Date('Date');
             $date->setValue($item->get_date());
             // Cast the Title
             $title = new Text('Title');
             $title->setValue($item->get_title());
             $output->push(new ArrayData(array('Title' => $title, 'Date' => $date, 'Link' => $item->get_link())));
         }
         return $output;
     }
 }
 function testHasValue()
 {
     $varcharField = new Varchar("testfield");
     $this->assertTrue($varcharField->getNullifyEmpty());
     $varcharField->setValue('abc');
     $this->assertTrue($varcharField->hasValue());
     $varcharField->setValue('');
     $this->assertFalse($varcharField->hasValue());
     $varcharField->setValue(null);
     $this->assertFalse($varcharField->hasValue());
     $varcharField = new Varchar("testfield", 50, array('nullifyEmpty' => false));
     $this->assertFalse($varcharField->getNullifyEmpty());
     $varcharField->setValue('abc');
     $this->assertTrue($varcharField->hasValue());
     $varcharField->setValue('');
     $this->assertTrue($varcharField->hasValue());
     $varcharField->setValue(null);
     $this->assertFalse($varcharField->hasValue());
     $textField = new Text("testfield");
     $this->assertTrue($textField->getNullifyEmpty());
     $textField->setValue('abc');
     $this->assertTrue($textField->hasValue());
     $textField->setValue('');
     $this->assertFalse($textField->hasValue());
     $textField->setValue(null);
     $this->assertFalse($textField->hasValue());
     $textField = new Text("testfield", array('nullifyEmpty' => false));
     $this->assertFalse($textField->getNullifyEmpty());
     $textField->setValue('abc');
     $this->assertTrue($textField->hasValue());
     $textField->setValue('');
     $this->assertTrue($textField->hasValue());
     $textField->setValue(null);
     $this->assertFalse($textField->hasValue());
 }
 public function upload()
 {
     $form = new Form('form-upload', Router::getInstance()->build('UploadController', 'upload'));
     $form->setAttribute('data-noajax', 'true');
     $form->setEnctype();
     $fieldset = new Fieldset(System::getLanguage()->_('General'));
     $folderInput = new Select('folder', System::getLanguage()->_('ChooseFolder'), Folder::getAll());
     $folderInput->selected_value = Utils::getGET('parent', NULL);
     $fieldset->addElements($folderInput);
     $form->addElements($fieldset);
     $fieldset = new Fieldset(System::getLanguage()->_('FileUpload'));
     $fileInput = new FileUpload('file', System::getLanguage()->_('ChooseFile'), false);
     $fieldset->addElements($fileInput);
     $form->addElements($fieldset);
     if (DOWNLOAD_VIA_SERVER) {
         $fieldset = new Fieldset(System::getLanguage()->_('UploadFromURL'));
         $url = new Text('url', System::getLanguage()->_('EnterURL'), false);
         $name = new Text('name', System::getLanguage()->_('Name'), false);
         $name->setValue(System::getLanguage()->_('DownloadedFile'));
         $fieldset->addElements($url, $name);
         $form->addElements($fieldset);
     }
     $fieldset = new Fieldset(System::getLanguage()->_('PermissionSetting'));
     $permissionInput = new Select('permissions', System::getLanguage()->_('Permission'), FilePermissions::getAll());
     $permissionInput->selected_value = DEFAULT_FILE_PERMISSION;
     $password = new Password('password', System::getLanguage()->_('Password'), false);
     $fieldset->addElements($permissionInput, $password);
     $form->addElements($fieldset);
     if (Utils::getPOST('submit', false) != false) {
         if ($permissionInput->selected_value == 2 && empty($password->value)) {
             $password->error = System::getLanguage()->_('ErrorEmptyTextfield');
         } else {
             if ($form->validate() && (!empty($url->value) || !empty($fileInput->uploaded_file))) {
                 // Specify input control for error display
                 $err = empty($url->value) ? $fileInput : $url;
                 try {
                     $folder = Folder::find('_id', $folderInput->selected_value);
                     $file = new File();
                     $file->folder = $folder;
                     $file->permission = $permissionInput->selected_value;
                     $file->password = $password->value;
                     if (empty($url->value)) {
                         $file->filename = $fileInput->filename;
                         $file->upload($fileInput->uploaded_file);
                     } else {
                         $file->filename = $name->value;
                         $file->remote($url->value);
                     }
                     $file->save();
                     System::forwardToRoute(Router::getInstance()->build('BrowserController', 'show', $folder));
                     exit;
                 } catch (UploadException $e) {
                     $fileInput->filename = '';
                     $fileInput->uploaded_file = '';
                     $err->error = $e->getMessage();
                     if ($e->getCode() != 0) {
                         $err->error .= ' Code: ' . $e->getCode();
                     }
                 } catch (QuotaExceededException $e) {
                     $err->error = System::getLanguage()->_('ErrorQuotaExceeded');
                 } catch (Exception $e) {
                     $fileInput->filename = '';
                     $fileInput->uploaded_file = '';
                     $err->error = System::getLanguage()->_('ErrorWhileUpload') . ' ' . $e->getMessage();
                 }
             }
         }
     }
     $form->setSubmit(new Button(System::getLanguage()->_('Upload'), 'open'));
     if ($folderInput->selected_value == 0) {
         $form->addButton(new Button(System::getLanguage()->_('Cancel'), '', Router::getInstance()->build('BrowserController', 'index')));
     } else {
         $form->addButton(new Button(System::getLanguage()->_('Cancel'), '', Router::getInstance()->build('BrowserController', 'show', new Folder($folderInput->selected_value))));
     }
     $smarty = new Template();
     $smarty->assign('title', System::getLanguage()->_('Upload'));
     $smarty->assign('heading', System::getLanguage()->_('FileUpload'));
     $smarty->assign('form', $form->__toString());
     $smarty->assign('BODY_CLASS', 'preventreload');
     $smarty->requireResource('upload');
     $smarty->display('form.tpl');
 }
Exemplo n.º 17
0
 /**
  * Get the Title of the FlowState
  *
  * @return string
  */
 public function getTitle()
 {
     $title = $this->TitleText;
     if ($title == '') {
         $title = "New state";
     }
     $textObj = new Text('TitleText');
     $textObj->setValue($title);
     return $textObj->LimitWordCount(10);
 }
 /**
  * manipulates the parts the pages breadcrumbs if a product detail view is 
  * requested.
  *
  * @param int    $maxDepth         maximum depth level of shown pages in breadcrumbs
  * @param bool   $unlinked         true, if the breadcrumbs should be displayed without links
  * @param string $stopAtPageType   name of pagetype to stop at
  * @param bool   $showHidden       true, if hidden pages should be displayed in breadcrumbs
  * @param bool   $showProductTitle true, if product title should be displayed in breadcrumbs
  * 
  * @return ArrayList
  * 
  * @author Sebastian Diel <*****@*****.**>, Patrick Schneider <*****@*****.**>
  * @since 09.10.2012
  */
 public function BreadcrumbParts($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false, $showProductTitle = false)
 {
     $parts = parent::BreadcrumbParts($maxDepth, $unlinked, $stopAtPageType, $showHidden);
     if ($this->isProductDetailView()) {
         if ($showProductTitle) {
             $title = new Text();
             $title->setValue($this->getDetailViewProduct()->Title);
             $parts->push(new ArrayData(array('MenuTitle' => $title, 'Title' => $title, 'Link' => '')));
         }
     }
     $this->extend('updateBreadcrumbParts', $parts);
     return $parts;
 }
Exemplo n.º 19
0
 public function testSetValue()
 {
     $value = 'foo';
     $this->text->setValue($value);
     $this->assertEquals($value, $this->text->getValue());
 }
 /**
  * Set the value on the field.
  * Optionally takes the whole record as an argument,
  * to pick other values.
  *
  * @param mixed $value
  * @param array $record
  */
 public function setValue($value, $record = null)
 {
     FrontendEditing::setValue($this, $value, $record);
     parent::setValue($value, $record);
 }
Exemplo n.º 21
0
 /**
  * This method is best explained through an example:
  * <code>
  * // Get the DBField for SummaryTitle. If it is blank, check
  * // Title. If both are blank a DBField with a NULL value
  * // will be returened.
  * $title = $newsPage->OneFieldFrom('SummaryTitle', 'Title');
  * </code>
  * Or, used in a template:
  * <code>
  * // Same as above.
  * $OneFieldFrom(SummaryTitle Title)
  * </code>
  * 
  * This makes it possible to get user data from a desired
  * field and getting less desired data if that field is
  * blank, without cluttering the code with conditional
  * statements.
  * 
  * @param string s1
  * @param string s2
  * @param string ...
  * @param string sN
  * 
  * @return DBField
  */
 public function OneFieldFrom()
 {
     $args = func_get_args();
     $fields = count($args) == 1 && is_string($args[0]) ? explode(' ', $args[0]) : $args;
     foreach ($fields as $field) {
         if ($this->hasField($field) && $this->{$field}) {
             return $this->dbObject($field);
         }
     }
     $nullField = new Text('__NULL__');
     $nullField->setValue(null);
     return $nullField;
 }
 /**
  * Load feed xml and return items
  * 
  * @param boolean $refresh
  * @return ArrayList or boolean false
  */
 function Items($refresh = false)
 {
     if (!$this->FeedURL) {
         return false;
     }
     if (!($xml = $this->loadXml())) {
         return false;
     }
     $result = new ArrayList();
     $counter = (int) $this->Results;
     if (!$counter) {
         $counter = -1;
     }
     // Return all posts
     foreach ($xml->channel->item as $item) {
         // Date
         $date = new SS_Datetime('Date');
         $date->setValue((string) $item->pubDate);
         // Title
         $itemTitle = (string) $item->title;
         $itemTitle = html_entity_decode($itemTitle);
         $title = new Text('Title');
         $title->setValue($itemTitle);
         // Description
         $itemDescription = (string) $item->description;
         $itemDescription = html_entity_decode($itemDescription);
         $description = new Text('Description');
         if ($this->Striptags) {
             $itemDescription = strip_tags($itemDescription);
         }
         $description->setValue($itemDescription);
         // Link
         $link = (string) $item->link;
         // Summary
         $summary = $itemDescription;
         $summary = strip_tags($summary);
         $summary = trim($summary);
         // Get first paragraph
         $summary = explode("\n", $summary);
         $summary = array_shift($summary);
         // Truncate summary if necessary
         $maxLength = (int) $this->SummaryMaxLength;
         if ($maxLength && strlen($summary) > $maxLength) {
             $summary = substr($summary, 0, $maxLength) . '...';
         }
         // Add to result list
         $result->push(new ArrayData(array('Title' => $title, 'Date' => $date, 'Link' => $link, 'Description' => $description, 'Summary' => $summary)));
         if ($counter) {
             $counter--;
             if (!$counter) {
                 break;
             }
         }
     }
     // Apply custom modifier function to each entry
     if (count($result) && !empty($this->Modifier) && $this->ClassName != __CLASS__ && method_exists($this->ClassName, $this->Modifier)) {
         try {
             $m = $this->Modifier;
             foreach ($result as $item) {
                 $this->{$m}($item);
             }
         } catch (Exception $e) {
             // Ignore
         }
     }
     // Return items
     return $result;
 }
Exemplo n.º 23
0
 protected function generateXml()
 {
     $hotelRes = new \C2is\OTA\Model\HotelRes\HotelRes();
     $hotelRes->setEchoToken($this->getParam('echo'));
     $hotelRes->setRequestorId($this->getParam('requestor.id'));
     $hotelRes->setRequestorType($this->getParam('requestor.type'));
     $hotelRes->setRequestorCompanyName($this->getParam('company_name'));
     $hotelRes->setVersion($this->getParam('ota.version'));
     $hotelRes->setXmlns($this->getParam('ota.namespace'));
     $hotelRes->setBookingType($this->getParam('booking.type'));
     $hotelRes->setBookingCompanyCode($this->getParam('booking.company_code'));
     $hotelRes->setBookingCompanyName($this->getParam('booking.company_name'));
     $hotelRes->setStatus($this->getParam('status'));
     foreach ($this->getParam('reservations') as $reservation) {
         $hotelRes->addReservation($hotelReservation = new HotelReservation());
         if ($hotelRes->getStatus() == 'Initiate') {
             $hotelReservation->setCreateDateTime(new \DateTime());
         } elseif ($hotelRes->getStatus() == 'Modify') {
             $hotelReservation->setLastModifyDateTime(new \DateTime());
         }
         foreach ($reservation['room_stays'] as $roomStay) {
             $hotelReservation->addRoomStay($objRoomStay = new RoomStay());
             foreach ($roomStay['room_types'] as $roomType) {
                 $objRoomStay->addRoomType($objRoomType = new RoomType());
                 $objRoomType->setCode($roomType['code']);
                 $objRoomType->setNumberOfUnits($roomType['number_of_units']);
             }
             foreach ($roomStay['room_rates'] as $roomRate) {
                 $objRoomStay->addRoomRate($objRoomRate = new RoomRate());
                 $objRoomRate->setNumberOfUnits($roomRate['number_of_units']);
                 if ($roomRate['rate_plan_category'] != 'RAC') {
                     $objRoomRate->setCode($roomRate['rate_plan_code']);
                 }
                 $objRoomRate->setCategory($roomRate['rate_plan_category']);
                 foreach ($roomRate['rates'] as $rate) {
                     $objRoomRate->addRate($objRate = new Rate());
                     $objRate->setEffectiveDate($rate['start_date']);
                     $objRate->setExpireDate($rate['end_date']);
                     $objRate->setBase($objBase = new Base());
                     $base = $rate['base'];
                     $objBase->setAmountAfterTax($base['after_tax']);
                     $objBase->setAmountBeforeTax($base['before_tax']);
                     $objBase->setCurrency($base['currency']);
                     if (isset($rate['extensions'])) {
                         $objBase->setExtensions($objExtensions = new Extensions());
                         $objExtensions->setRedeemedNights($objRedeemedNights = new RedeemedNights());
                         $extensions = $rate['extensions'];
                         $objRedeemedNights->setProgramId($extensions['program_id']);
                         foreach ($extensions['nights'] as $night) {
                             $objRedeemedNights->addRedeemedNight($objRedeemedNight = new RedeemedNight());
                             $objRedeemedNight->setDate($night['date']);
                         }
                     }
                 }
             }
             foreach ($roomStay['guest_counts'] as $guestCount) {
                 $objRoomStay->addGuestCount($objGuestCount = new GuestCount());
                 $objGuestCount->setAge($guestCount['age']);
                 $objGuestCount->setAgeCode($guestCount['age_code']);
                 $objGuestCount->setCount($guestCount['count']);
             }
             if (isset($roomStay['timespan'])) {
                 $objRoomStay->setTimespan($objTimespan = new Timespan());
                 $objTimespan->setStart($roomStay['timespan']['start']);
                 $objTimespan->setEnd($roomStay['timespan']['end']);
             }
             if (isset($roomStay['total'])) {
                 $objTotal = $objRoomStay->getTotal();
                 $objTotal->setBeforeTax($roomStay['total']['before_tax']);
                 $objTotal->setAfterTax($roomStay['total']['after_tax']);
                 $objTotal->setCurrency($roomStay['total']['currency']);
                 foreach ($roomStay['total']['taxes'] as $tax) {
                     $objTotal->addTax($objTax = new Tax());
                     $objTax->setAmount($tax['amount']);
                     foreach ($tax['description'] as $taxDescription) {
                         $objTax->addDescription($objDescription = new TaxDescription());
                         $objDescription->setDescription($taxDescription['description']);
                         $objDescription->setLanguage($taxDescription['lang']);
                     }
                 }
             }
             if (isset($roomStay['hotel'])) {
                 $objBasicPropertyInfo = $objRoomStay->getBasicPropertyInfo();
                 $objBasicPropertyInfo->setChainCode($roomStay['hotel']['chain_code']);
                 $objBasicPropertyInfo->setHotelCode($roomStay['hotel']['code']);
             }
             if (isset($roomStay['services'])) {
                 foreach ($roomStay['services'] as $service) {
                     $objRoomStay->addServiceRph($objServiceRph = new ServiceRph());
                     $objServiceRph->setIsPerRoom($service['per_room']);
                     $objServiceRph->setRph($service['rph']);
                 }
             }
         }
         foreach ($reservation['services'] as $service) {
             $hotelReservation->addService($objService = new Service());
             $objService->setRph($service['rph']);
             $objService->setInventoryCode($service['inventory_code']);
             $objService->setPricingType($service['pricing_type']);
             $objService->setQuantity($service['quantity']);
             $amount = $service['amount'];
             $objBase = $objService->getPrice()->getBase();
             if (isset($amount['after_tax'])) {
                 $objBase->setAfterTax($amount['after_tax']);
             }
             if (isset($amount['before_tax'])) {
                 $objBase->setBeforeTax($amount['before_tax']);
             }
             if (isset($amount['currency'])) {
                 $objBase->setCurrency($amount['currency']);
             }
             if (in_array($objService->getPricingType(), array(Service::PRICING_TYPE_PER_NIGHT, Service::PRICING_TYPE_PER_PERSON_PER_NIGHT)) and isset($service['details'])) {
                 $details = $service['details'];
                 if (isset($details['duration'])) {
                     $objService->getDetails()->getTimespan()->setDuration($details['duration']);
                 }
             }
         }
         foreach ($reservation['guests'] as $guest) {
             $hotelReservation->addGuest($objGuest = new Guest());
             $objGuest->setRph($guest['rph']);
             $objGuest->addCustomer($objCustomer = new Guest\Customer());
             $objCustomer->setEmail($guest['email']);
             $objCustomer->setCurrency($guest['currency']);
             $objCustomer->setGender($guest['gender']);
             if (isset($guest['person_name'])) {
                 $objCustomer->setPersonName($objPersonName = new Guest\PersonName());
                 $objPersonName->setGivenName($guest['person_name']['given_name']);
                 $objPersonName->setSurName($guest['person_name']['surname']);
             }
             if (isset($guest['address'])) {
                 $objCustomer->setAddress($objAddress = new Guest\Address());
                 $objAddress->setLine($guest['address']['line']);
                 $objAddress->setCity($guest['address']['city']);
                 $objAddress->setPostalCode($guest['address']['postal_code']);
                 if (isset($guest['address']['country'])) {
                     $objAddress->setCountryName($guest['address']['country']['name']);
                     $objAddress->setCountryCode($guest['address']['country']['code']);
                 }
             }
             if (isset($guest['telephone'])) {
                 $objCustomer->setTelephone($objTelephone = new Guest\Telephone());
                 $objTelephone->setCountryAccessCode($guest['telephone']['country_access_code']);
                 $objTelephone->setNumber($guest['telephone']['number']);
             }
             if (isset($guest['loyalty'])) {
                 $objCustomer->setLoyalty($objLoyalty = new Guest\Loyalty());
                 $objLoyalty->setMembershipId($guest['loyalty']['membership_id']);
                 $objLoyalty->setProgramId($guest['loyalty']['program_id']);
             }
             if (isset($guest['comments'])) {
                 foreach ($guest['comments'] as $comment) {
                     if (isset($comment['message'])) {
                         $objGuest->addComment($objComment = new Comment());
                         $objComment->addText($objText = new Text());
                         $objText->setValue($comment['message']);
                         if (isset($comment['lang'])) {
                             $objText->setLang($comment['lang']);
                         }
                         if (isset($comment['originator_code'])) {
                             $objComment->setOriginatorCode($comment['originator_code']);
                         }
                         if (isset($comment['viewable'])) {
                             $objComment->setGuestViewable($comment['viewable']);
                         }
                     }
                 }
             }
         }
     }
     if ($globalInfo = $this->getParam('global_info')) {
         $hotelReservation->setGlobalInfo($objGlobalInfo = new GlobalInfo());
         if (isset($globalInfo['guarantee'])) {
             $objGlobalInfo->setGuarantee($objGuarantee = new Guarantee());
             if (isset($globalInfo['guarantee']['guarantees_accepted'])) {
                 foreach ($globalInfo['guarantee']['guarantees_accepted'] as $guaranteeAccepted) {
                     $objGuarantee->addPaymentCard($objPaymentCard = new PaymentCard());
                     $objPaymentCard->setCardHolderName($guaranteeAccepted['card_holder_name']);
                     $objPaymentCard->setCardNumber($guaranteeAccepted['card_number']);
                     $objPaymentCard->setCardType($guaranteeAccepted['card_type']);
                     $objPaymentCard->setExpireDate($guaranteeAccepted['card_expire_date']);
                     $objPaymentCard->setSeriesCode($guaranteeAccepted['card_series_code']);
                 }
             }
         }
         if (isset($globalInfo['total'])) {
             $objGlobalInfo->setTotal($objTotal = new Total());
             $objTotal->setAfterTax($globalInfo['total']['after_tax']);
             $objTotal->setBeforeTax($globalInfo['total']['before_tax']);
             if (isset($globalInfo['total']['currency'])) {
                 $objTotal->setCurrency($globalInfo['total']['currency']);
             }
             if (isset($globalInfo['total']['taxes'])) {
                 foreach ($globalInfo['total']['taxes'] as $tax) {
                     $objTotal->addTax($objTax = new Tax());
                     $objTax->setAmount($tax['amount']);
                     $objTax->setPercent($tax['percent']);
                 }
             }
         }
         if (isset($globalInfo['hotel_reservation_ids'])) {
             foreach ($globalInfo['hotel_reservation_ids'] as $hotelReservationId) {
                 $objGlobalInfo->addHotelReservationId($objHotelReservationId = new HotelReservationId());
                 $objHotelReservationId->setSource($hotelReservationId['source']);
                 $objHotelReservationId->setValue($hotelReservationId['value']);
             }
         }
         if (isset($globalInfo['comments'])) {
             foreach ($globalInfo['comments'] as $comment) {
                 if (isset($comment['message'])) {
                     $objGlobalInfo->addComment($objComment = new Comment());
                     $objComment->addText($objText = new Text());
                     $objText->setValue($comment['message']);
                     if (isset($comment['lang'])) {
                         $objText->setLang($comment['lang']);
                     }
                     if (isset($comment['originator_code'])) {
                         $objComment->setOriginatorCode($comment['originator_code']);
                     }
                     if (isset($comment['viewable'])) {
                         $objComment->setGuestViewable($comment['viewable']);
                     }
                 }
             }
         }
     }
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     return $serializer->serialize($hotelRes, 'xml');
 }
 /**
  * This method is copied 2015-11-24 from  theplumpss/twitter module (https://github.com/plumpss/twitter/blob/master/code/PlumpTwitterFeed.php)
  * Also some other parts of this module has used theplumpss/twitter as an example, but tweet_to_array() is the
  * only direct copy - although it has some modifications too, regarding to format of the return value.
  * @param $tweet
  * @return mixed
  */
 private static function tweet_to_array($tweet)
 {
     $date = new SS_Datetime();
     $date->setValue(strtotime($tweet->created_at));
     $html = $tweet->text;
     if ($tweet->entities) {
         //url links
         if ($tweet->entities->urls) {
             foreach ($tweet->entities->urls as $url) {
                 $html = str_replace($url->url, '<a href="' . $url->url . '" target="_blank">' . $url->url . '</a>', $html);
             }
         }
         //hashtag links
         if ($tweet->entities->hashtags) {
             foreach ($tweet->entities->hashtags as $hashtag) {
                 $html = str_replace('#' . $hashtag->text, '<a target="_blank" href="https://twitter.com/search?q=%23' . $hashtag->text . '">#' . $hashtag->text . '</a>', $html);
             }
         }
         //user links
         if ($tweet->entities->user_mentions) {
             foreach ($tweet->entities->user_mentions as $mention) {
                 $html = str_replace('@' . $mention->screen_name, '<a target="_blank" href="https://twitter.com/' . $mention->screen_name . '">@' . $mention->screen_name . '</a>', $html);
             }
         }
     }
     $title = new Text();
     $title->setValue($tweet->text);
     return array('LastEdited' => (string) $date, 'Created' => (string) $date, 'Fetched' => SS_Datetime::now(), 'SoMeAuthor' => $tweet->user->screen_name, 'SoMeUsername' => self::config()->username, 'Avatar' => $tweet->user->profile_image_url, 'Content' => $html, 'Title' => preg_replace('/\\.$/', '', $title->Summary(self::config()->title_length)), 'TwitterID' => $tweet->id, 'Locale' => $tweet->lang, 'Source' => 'Twitter');
 }