/** * Fetch the next result row and create the model * * @return boolean True if there was another row */ protected function fetchNext() { if ($this->objResult->next() == false) { return false; } $strClass = $this->getModelClassFromTable($this->strTable); $this->arrModels[$this->intIndex + 1] = new $strClass($this->objResult); return true; }
/** * Parse one or more items and return them as array * @param Database_Result * @param boolean * @return array */ protected function parseArticles(Database_Result $objArticles, $blnAddArchive=false) { if ($objArticles->numRows < 1) { return array(); } global $objPage; $this->import('String'); $arrArticles = array(); $limit = $objArticles->numRows; $count = 0; $imgSize = false; // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0) { $imgSize = $this->imgSize; } } while ($objArticles->next()) { $objTemplate = new FrontendTemplate($this->news_template); $objTemplate->setData($objArticles->row()); $objTemplate->count = ++$count; $objTemplate->class = (($objArticles->cssClass != '') ? ' ' . $objArticles->cssClass : '') . (($count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'); $objTemplate->newsHeadline = $objArticles->headline; $objTemplate->subHeadline = $objArticles->subheadline; $objTemplate->hasSubHeadline = $objArticles->subheadline ? true : false; $objTemplate->linkHeadline = $this->generateLink($objArticles->headline, $objArticles, $blnAddArchive); $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['more'], $objArticles, $blnAddArchive, true); $objTemplate->link = $this->generateNewsUrl($objArticles, $blnAddArchive); $objTemplate->archive = $objArticles->archive; // Clean the RTE output if ($objArticles->teaser != '') { if ($objPage->outputFormat == 'xhtml') { $objArticles->teaser = $this->String->toXhtml($objArticles->teaser); } else { $objArticles->teaser = $this->String->toHtml5($objArticles->teaser); } $objTemplate->teaser = $this->String->encodeEmail($objArticles->teaser); } // Display the "read more" button for external/article links if (($objArticles->source == 'external' || $objArticles->source == 'article') && $objArticles->text == '') { $objTemplate->text = true; } // Encode e-mail addresses else { // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objArticles->text = $this->String->toXhtml($objArticles->text); } else { $objArticles->text = $this->String->toHtml5($objArticles->text); } $objTemplate->text = $this->String->encodeEmail($objArticles->text); } $arrMeta = $this->getMetaFields($objArticles); // Add meta information $objTemplate->date = $arrMeta['date']; $objTemplate->hasMetaFields = !empty($arrMeta); $objTemplate->numberOfComments = $arrMeta['ccount']; $objTemplate->commentCount = $arrMeta['comments']; $objTemplate->timestamp = $objArticles->date; $objTemplate->author = $arrMeta['author']; $objTemplate->datetime = date('Y-m-d\TH:i:sP', $objArticles->date); $objTemplate->addImage = false; // Add an image if ($objArticles->addImage && is_file(TL_ROOT . '/' . $objArticles->singleSRC)) { if ($imgSize) { $objArticles->size = $imgSize; } $this->addImageToTemplate($objTemplate, $objArticles->row()); } $objTemplate->enclosure = array(); // Add enclosures if ($objArticles->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $objArticles->row()); } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['parseArticles']) && is_array($GLOBALS['TL_HOOKS']['parseArticles'])) { foreach ($GLOBALS['TL_HOOKS']['parseArticles'] as $callback) { $this->import($callback[0]); $this->$callback[0]->$callback[1]($objTemplate, $objArticles->row(), $this); } } $arrArticles[] = $objTemplate->parse(); } return $arrArticles; }
/** * Get rows * * @param \Database_Result $objRecords * * @return array */ public function getRows($objRecords) { if (!$objRecords->numRows) { return array(); } $arrRows = array(); $objRecords->reset(); while ($objRecords->next()) { $arrField = $objRecords->row(); foreach ($this->fields as $field) { $arrField[$field] = Format::dcaValue($this->foreignTable, $field, $objRecords->{$field}); } $arrRows[] = $arrField; } return $arrRows; }
/** * Parse one or more items and return them as array * * @param Database_Result $objArticles * @param bool|Template $objTemplate * @return array */ protected function parseArticles(Database_Result $objArticles, $objTemplate = false) { if ($objArticles->numRows < 1) { return array(); } global $objPage; $this->import('String'); $this->import('News4wardHelper'); $arrArticles = array(); $limit = $objArticles->numRows; $count = 0; while ($objArticles->next()) { // init FrontendTemplate if theres no object given if (!$objTemplate) { $objTemplate = new FrontendTemplate($this->news4ward_template); } $objTemplate->setData($objArticles->row()); $objTemplate->count = ++$count; $objTemplate->class = (strlen($objArticles->cssClass) ? ' ' . $objArticles->cssClass : '') . ($count == 1 ? ' first' : '') . ($count == $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even') . ($objArticles->highlight ? ' highlight' : ''); $objTemplate->link = $this->News4wardHelper->generateUrl($objArticles); $objTemplate->archive = $objArticles->archive; // Clean the RTE output for the TEASER if ($objArticles->teaser != '') { if ($objPage->outputFormat == 'xhtml') { $objArticles->teaser = $this->String->toXhtml($objArticles->teaser); } else { $objArticles->teaser = $this->String->toHtml5($objArticles->teaser); } $objTemplate->teaser = $this->String->encodeEmail($objArticles->teaser); } // Generate ContentElements $objContentelements = $this->Database->prepare('SELECT id FROM tl_content WHERE pid=? AND do="news4ward" ' . (!BE_USER_LOGGED_IN ? " AND invisible=''" : "") . ' ORDER BY sorting ')->execute($objArticles->id); $strContent = ''; while ($objContentelements->next()) { $strContent .= $this->getContentElement($objContentelements->id); } // Clean the RTE output for the CONTENT if ($strContent != '') { // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $strContent = $this->String->toXhtml($strContent); } else { $strContent = $this->String->toHtml5($strContent); } $strContent = $this->String->encodeEmail($strContent); } $objTemplate->content = $strContent; // Add meta information $arrMeta = $this->getMetaFields($objArticles); $objTemplate->date = $arrMeta['date']; $objTemplate->hasMetaFields = count($arrMeta) ? true : false; $objTemplate->timestamp = $objArticles->start; $objTemplate->author = $arrMeta['author']; $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objArticles->start); // Add teaser image if ($objArticles->teaserImage && is_file(TL_ROOT . '/' . $objArticles->teaserImage)) { $imgSize = deserialize($this->imgSize, true); $objTemplate->arrSize = $imgSize; if (count($imgSize) > 1) { $objTemplate->teaserImage = $this->getImage($objArticles->teaserImage, $imgSize[0], $imgSize[1], $imgSize[2]); } else { $objTemplate->teaserImage = $objArticles->teaserImage; } $objTemplate->teaserImageRaw = $objTemplate->teaserImag; } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['News4wardParseArticle']) && is_array($GLOBALS['TL_HOOKS']['News4wardParseArticle'])) { foreach ($GLOBALS['TL_HOOKS']['News4wardParseArticle'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this, $objArticles, $objTemplate); } } $arrArticles[] = $objTemplate->parse(); } return $arrArticles; }