Bezahlung: PayPal, bzw. am liebsten auf Rechnung!
Für Fragen stehe ich gerne zur Verfügung.
Angebote bitte per PM.
Fertigstellung: schön wäre noch diese Woche

Fortsetzung nächster Beitrag ...
Moderator: Moderatoren
Code: Alles auswählen
<?php
* @version 1.0.0
* @author Rudi Bieller
* @copyright four for business AG <www.4fb.de>
if (!isset($tpl) || !is_object($tpl)) {
$tpl = new Template();
}
if ($contenido && ($view == "edit")) {
echo "CMS_HTML[1]";
} else {
$mask[0] = '<img src="{src}" width="{width}" height="{height}" alt="{alt}" title="{title}" class="{class}" />';
$mask[1] = '<a href="{origSrc}"><img src="{src}" width="{width}" height="{height}" alt="{alt}" />{title}</a>>';
cInclude('frontend', 'includes/atelierq.imageResize.class.inc.php');
$atqImageResize = new atqImageResize("CMS_HTML[1]", "CMS_VALUE[1]", "CMS_VALUE[2]", $mask, $db);
echo $atqImageResize->getOutput();
}
?>
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : Article Semi-AutoPageBreak
* Author(s) : Stefan Seifarth <info@polycoder.de>
* Copyright : www.polycoder.de / www.htcm.de
* Created : 2006-06-17
************************************************/
// include pagebreak class
cInclude("frontend", "includes/class.articlepagebreak.php");
$strAnchorName = "CMS_VALUE[210]";
$strArticle = "CMS_HTML[1]";
$strDelimiter = '<a name="' . $strAnchorName . '"></a>';
// initialize class
// parameter delimiter for article spliting
$oArticlePageBreak = new ArticlePageBreak( $strDelimiter );
// set article
$oArticlePageBreak->setArticle( $strArticle );
// set current page for output
$intCurrentPage = 0;
if ( isset($_REQUEST[$oArticlePageBreak->strPageParameter]) && !empty($_REQUEST[$oArticlePageBreak->strPageParameter]) && (int)$_REQUEST[$oArticlePageBreak->strPageParameter] > 0 ) {
$intCurrentPage = (int)$_REQUEST[$oArticlePageBreak->strPageParameter];
}
$oArticlePageBreak->setCurrentPage($intCurrentPage);
// set Textlinks
$oArticlePageBreak->setTextFirstPage( mi18n("Erste Seite") );
$oArticlePageBreak->setTextPreviousPage( mi18n("Vorhergehende Seite") );
$oArticlePageBreak->setTextNextPage( mi18n("Nächste Seite") );
$oArticlePageBreak->setTextLastPage( mi18n("Letzte Seite") );
$oArticlePageBreak->setTextPreviousRange( mi18n("Zurück") );
$oArticlePageBreak->setTextNextRange( mi18n("Weiter") );
$oArticlePageBreak->setTextPageTitle( mi18n("Gehe zu Seite ") );
// output the current article part
if ($edit && empty($_REQUEST['edit'])) { // Edit-Mode
if ( preg_match("/^<([^>]*)>/i", $strDelimiter, $arrTagInlay) ) {
$bolDelimiterIsTag = $arrTagInlay[1];
}
if ( $bolDelimiterIsTag && strlen($bolDelimiterIsTag) > 0 ) {
$strReplacePattern = '';
$arrTagParts = explode(" ", $bolDelimiterIsTag);
if (is_array($arrTagParts)) {
$arrTagParts = array_filter($arrTagParts);
$strReplacePattern = '/<' . implode("[^>]*", $arrTagParts) . '[^>]*>/i';
$strArticle = preg_replace($strReplacePattern,"<div style=\"border:1px dashed #900; color:#a22; text-align:center; padding:0px;\" title=\"An dieser Stelle wird die Seite in blätterbare Folgeseiten getrennt. Siehe Vorschau!\">< -- Seitenumbruch -- ></div>",$strArticle);
}
}
else{
$strArticle = preg_replace($strDelimiter,"<div style=\"border:1px dashed #900; color:#a22; text-align:center; padding:0px;\" title=\"An dieser Stelle wird die Seite in blätterbare Folgeseiten getrennt. Siehe Vorschau!\">< -- Seitenumbruch -- ></div>",$strArticle);
}
echo $strArticle;
}
else{ // Publish-Mode
print $oArticlePageBreak->getArticle();
// get pagination for article
print "<div class=\"articlePagination\">".$oArticlePageBreak->getPagination()."</div>";
}
/*
// xml output
// add custom xml tags
// (class xmlObject is located in class.articlepagebreak.php)
//
$oHeadline = new xmlObject(
"headline", // tag name
"", // attributes (given as array)
"headlinetext", // content of element
true // usage of cdata for content
);
// store the above configured tag into class
$oArticlePageBreak->setXMLAdditionalContentTag($oHeadline);
// output complete xml
print $oArticlePageBreak->getXMLComplete();
*/
?>
Code: Alles auswählen
$mask[0] = '<img src="{src}" width="{width}" height="{height}" alt="{alt}" title="{title}" class="{class}" />';
$mask[1] = '<a href="{origSrc}"><img src="{src}" width="{width}" height="{height}" alt="{alt}" />{title}</a>>';
cInclude('frontend', 'includes/atelierq.imageResize.class.inc.php');
$atqImageResize = new atqImageResize("CMS_HTML[1]", "CMS_VALUE[1]", "CMS_VALUE[2]", $mask, $db);
echo $atqImageResize->getOutput();
Code: Alles auswählen
<?php
/**
* @abstract ImageResizeHTML (atqImageResize)
* @version 1.1.2
* @since 1.1.2 - 05.10.2007
* @since 1.1.1 - 05.10.2007
* @since 1.1.0 - 03.10.2007
* @author Andreas Kummer, atelierQ Kummer
* @copyright Copyright © 2007, atelierQ Kummer
*/
class atqImageResize {
var $htmlContent;
function atqImageResize($content, $maxWidth, $maxHeight, $mask, & $db) {
$this->thumbDir = "thumbs";
$this->db = $db;
if (!is_array($mask)) {
$this->mask[0] = $mask;
$this->mask[1] = $mask;
} else {
$this->mask = $mask;
}
$this->maxWidth = (empty ($maxWidth)) ? (9999) : ((int) $maxWidth);
$this->maxHeight = (empty ($maxHeight)) ? (9999) : ((int) $maxHeight);
preg_match_all('(<img.*?>)', $content, $match);
for ($i = 0; $i < count($match[0]); $i++) {
$newPath = $this->resize($match[0][$i]);
if ($newPath != $match[0][$i]) {
/*
* Das Bild wurde skaliert...
*/
$content = str_replace($match[0][$i], $newPath, $content);
}
}
$this->htmlContent = $content;
}
function getOutput() {
return $this->htmlContent;
}
function resize($imageTag) {
global $cfgClient, $client;
preg_match_all('(([a-zA-Z]*)="(.*?)")', $imageTag, $match);
foreach ($match[1] as $key => $value) {
$position[$value] = $key;
}
if (!isset ($position['src']) || empty ($match[2][$position['src']])) {
/*
* Abbruch, weil keine Bildquelle bezeichnet ist.
*/
return $imageTag;
}
$width = min($this->maxWidth, (isset ($position['width'])) ? ($match[2][$position['width']]) : (99999));
$height = min($this->maxHeight, (isset ($position['height'])) ? ($match[2][$position['height']]) : (99999));
$imageSourceHtml = $cfgClient[$client]['path']['htmlpath'] . $match[2][$position['src']];
if (substr($match[2][$position['src']], 0, 4) != 'http') {
$imageSource = $cfgClient[$client]['path']['frontend'] . $match[2][$position['src']];
} else {
$imageSource = $cfgClient[$client]['path']['frontend'] . str_replace($cfgClient[$client]['path']['htmlpath'], '', $match[2][$position['src']]);
}
$targetName = str_replace('/', '_', $match[2][$position['src']]) . '.' . $width . 'x' . $height . '.jpg';
if (!file_exists($imageSource)) {
/*
* Wenn die Originaldatei nicht vorhanden ist, ist abzubrechen.
*/
return $imageTag;
}
$imageSourceDimensions = getimagesize($imageSource);
$origImageSourceDimensions = $imageSourceDimensions;
if (file_exists($cfgClient[$client]['upl']['path'] . $this->thumbDir . '/' . $targetName)) {
/*
* Skaliertes Bild liegt bereits vor und wird zurückgegeben.
*/
$imageSourceDimensions = getimagesize($cfgClient[$client]['upl']['path'] . $this->thumbDir . '/' . $targetName);
if (isset ($position['width'])) {
$match[0][$position['width']] = 'width="' . $imageSourceDimensions[0] . '"';
}
if (isset ($position['height'])) {
$match[0][$position['height']] = 'height="' . $imageSourceDimensions[1] . '"';
}
$match[0][$position['src']] = 'src="' . $cfgClient[$client]['upl']['htmlpath'] . $this->thumbDir . '/' . $targetName . '"';
$parts['src'] = $cfgClient[$client]['upl']['htmlpath'] . $this->thumbDir . '/' . $targetName;
$parts['height'] = $imageSourceDimensions[1];
$parts['width'] = $imageSourceDimensions[0];
$parts['origHeight'] = $origImageSourceDimensions[1];
$parts['origWidth'] = $origImageSourceDimensions[0];
$parts['title'] = (isset ($position['title'])) ? ($match[2][$position['title']]) : ('');
$parts['titleUrl'] = urlencode($parts['title']);
$parts['alt'] = (isset ($position['alt'])) ? ($match[2][$position['alt']]) : ('');
return $this->getFilledMask($parts, $imageSourceHtml, $this->mask[1], $match);
}
if ($imageSourceDimensions[0] <= $width && $imageSourceDimensions[1] <= $height) {
/*
* Das Bild muss nicht skaliert werden.
*/
$parts['src'] = $match[2][$position['src']];
$parts['height'] = $imageSourceDimensions[1];
$parts['width'] = $imageSourceDimensions[0];
$parts['origHeight'] = $imageSourceDimensions[1];
$parts['origWidth'] = $imageSourceDimensions[0];
$parts['title'] = (isset ($position['title'])) ? ($match[2][$position['title']]) : ('');
$parts['titleUrl'] = urlencode($parts['title']);
$parts['alt'] = (isset ($position['alt'])) ? ($match[2][$position['alt']]) : ('');
return $this->getFilledMask($parts, $imageSourceHtml, $this->mask[0], $match);
}
/*
* Zielgrösse des Bildes ermitteln.
*/
$slopeSource = $imageSourceDimensions[1] / $imageSourceDimensions[0];
$slopeTarget = $height / $width;
if ($slopeSource < $slopeTarget) {
/*
* Auf Breite skalieren
*/
$targetWidth = (int) $width;
$targetHeight = (int) round(($targetWidth / $imageSourceDimensions[0]) * $imageSourceDimensions[1]);
} else {
/*
* Auf Höhe skalieren
*/
$targetHeight = (int) $height;
$targetWidth = (int) round(($targetHeight / $imageSourceDimensions[1]) * $imageSourceDimensions[0]);
}
$sourcePath = $dst_im = imagecreatetruecolor($targetWidth, $targetHeight);
$weiss = ImageColorAllocate($dst_im, 255, 255, 255);
imagefill($dst_im, 0, 0, $weiss);
if ($imageSourceDimensions[2] == 1) {
$src_im = imagecreatefromGIF($imageSource);
}
elseif ($imageSourceDimensions[2] == 2) {
$src_im = ImageCreateFromJPEG($imageSource);
}
elseif ($imageSourceDimensions[2] == 3) {
$src_im = ImageCreateFromPNG($imageSource);
} else {
$src_im = imagecreatefromgd($imageSource);
}
imagecopyresampled($dst_im, $src_im, 0, 0, 0, 0, $targetWidth, $targetHeight, $imageSourceDimensions[0], $imageSourceDimensions[1]);
imagejpeg($dst_im, $cfgClient[$client]['upl']['path'] . $this->thumbDir . '/' . $targetName, 100);
if (isset ($position['width'])) {
$match[0][$position['width']] = 'width="' . $targetWidth . '"';
}
if (isset ($position['height'])) {
$match[0][$position['height']] = 'height="' . $targetHeight . '"';
}
$match[0][$position['src']] = 'src="' . $cfgClient[$client]['upl']['htmlpath'] . $this->thumbDir . '/' . $targetName . '"';
$parts['src'] = $cfgClient[$client]['upl']['htmlpath'] . $this->thumbDir . '/' . $targetName;
$parts['height'] = $targetHeight;
$parts['width'] = $targetWidth;
$parts['origHeight'] = $imageSourceDimensions[1];
$parts['origWidth'] = $imageSourceDimensions[0];
$parts['title'] = (isset ($position['title'])) ? ($match[2][$position['title']]) : ('');
$parts['titleUrl'] = urlencode($parts['title']);
$parts['alt'] = (isset ($position['alt'])) ? ($match[2][$position['alt']]) : ('');
return $this->getFilledMask($parts, $imageSourceHtml, $this->mask[1], $match);
}
function getFilledMask($parts, $imageSourceHtml, $mask, $match) {
global $cfgClient, $client;
$returnValue = $mask;
/*
* Alle übertragenen Platzhalter ersetzen.
*/
foreach ($parts as $key => $value) {
$returnValue = str_replace('{' . $key . '}', $value, $returnValue);
}
/*
* Description aus der Datenbank auslesen und in der Maske ersetzen.
*/
$this->db->query("" .
"SELECT description " .
"FROM con_upl " .
"WHERE CONCAT('{$cfgClient[$client]['upload']}', dirname, filename) = '{$imageSourceHtml}' " .
"");
if ($this->db->next_record()) {
$returnValue = str_replace('{description}', urldecode($this->db->f('description')), $returnValue);
} else {
$returnValue = str_replace('{description}', '', $returnValue);
}
$returnValue = str_replace('{origSrc}', $imageSourceHtml, $returnValue);
/*
* Alle im Image-Tag allenfalls sonst noch vorhandenen Tags auslesen und - sofern
* in der Maske vorhanden - ersetzen.
*/
for ($i = 0; $i < count($match[1]); $i++) {
$returnValue = str_replace('{' . $match[1][$i] . '}', $match[2][$i], $returnValue);
}
/*
* Allenfalls immer noch vorhandene Platzhalter, die nicht haben ersetzt werden können, sind zu löschen.
*/
$returnValue = preg_replace('/{.*?}/', '', $returnValue);
return $returnValue;
}
}
?>
Code: Alles auswählen
<?php
/**
* ArticlePageBreak
*
* class handles various methods to split an article
* and generate different types of pageinations
* for Contenido Articles
*
* @author stefan seifarth <info@polycoder.de>
* @copyright 2006 stefan seifarth, munich
* @name ArticlePageBreak
* @version 1.3 2006-06-17
* @access public
*
* @example
* // create Object
* $obj = new ArticlePageBreak('splitDelimiter');
* // set text to split
* $obj->setArticle ( "Some text to split" );
* // set current page for output
* $intCurrentPage = 0;
* if (
* isset($_REQUEST[$obj->strPageParameter]) &&
* !empty($_REQUEST[$obj->strPageParameter]) &&
* (int)$_REQUEST[$obj->strPageParameter] > 0 ) {
* $intCurrentPage = (int)$_REQUEST[$obj->strPageParameter];
* }
* $obj->setCurrentPage($intCurrentPage);
* // set text for next or previous links of pagination
* $obj->setTextNextPage('naechste Seite');
* $obj->setTextPreviousPage('vorhergehende Seite');
*
* // output the current article part
* print $obj->getArticle();
*
* // output the pagination
* print $obj->getPagination();
* // to set up pagination type (default = 1)
* // use 1, 2 or 3 as parameter:
* print $obj->getPagination(2);
*
* // some css settings and other settings can be set
* // look at class and methods which names starting with "set"
*/
class ArticlePageBreak {
var $strDelimiter;
var $bolDelimiterIsTag = false;
var $strArticle;
var $strPageParameter = 'page';
var $arrSplittedArticle;
var $intCurrentPage = 0;
var $intTotalPages;
var $intPaginationType = 1;
var $intPaginationRange = 10;
var $strTextFirstPage = "First Page";
var $strTextLastPage = "Last Page";
var $strTextPreviousPage = "Previous";
var $strTextNextPage = "Next";
var $strTextNextRange = "Next 10";
var $strTextPreviousRange = "Previous 10";
var $strTextPageTitle = "Goto page ";
var $strPageJoinParameter = ', ';
var $intPaginationUseList = 0;
var $intPaginationActivePageUseStrong = 1;
var $strCSSPageClass = '';
var $strCSSPageStyle = '';
var $strCSSActivePageClass = '';
var $strCSSActivePageStyle = '';
var $strCSSTextLinkClass = '';
var $strCSSTextLinkStyle = '';
var $strCSSULId = '';
var $strCSSULClass = '';
var $strCSSULStyle = '';
var $strCSSLIClass = '';
var $strCSSLIStyle = '';
var $strCSSLIActiveClass = '';
var $strCSSLIActiveStyle = '';
var $arrPagination = array();
var $arrXML = array();
var $strXMLCharset = 'utf-8';
var $strXMLAllowedTags = 'a,i,b,u,br';
/**
* Class Constructor
*
* @param string $strDelimiter Delimiter for Article
* @return ArticlePageBreak Object
*/
function ArticlePageBreak( $strDelimiter = "" ) {
$this->strDelimiter = $strDelimiter;
// check if delimiter is a tag
if ( preg_match("/^<([^>]*)>/i", $strDelimiter, $arrTagInlay) ) {
$this->bolDelimiterIsTag = $arrTagInlay[1];
}
}
/**
* Split the Article and Fill Variables for Output
*
*/
function splitArticle () {
// if tag, build replace pattern and replace delimiter
// including attributes with clear delimiter
if ( $this->bolDelimiterIsTag && strlen($this->bolDelimiterIsTag) > 0 ) {
$strReplacePattern = '';
$arrTagParts = explode(" ", $this->bolDelimiterIsTag);
if (is_array($arrTagParts)) {
$arrTagParts = array_filter($arrTagParts);
$strReplacePattern = '/<' . implode("[^>]*", $arrTagParts) . '[^>]*>/i';
$this->strArticle = preg_replace($strReplacePattern, $this->strDelimiter, $this->strArticle);
}
}
$this->arrSplittedArticle = explode( $this->strDelimiter, $this->strArticle );
if ( is_array( $this->arrSplittedArticle ) ) {
$this->intTotalPages = count ( $this->arrSplittedArticle );
} else {
$this->intTotalPages = 1;
}
}
/**
* get the pagination
*
* you can set the pagination type by enter one of following numbers
* 1 = display all pages (e.g. first previous 1 2 3 4 5 6 7 8 9 10 11 next last)
* 2 = display page range 1 - 10 ( e.g. first previous10 1 2 3 4 5 6 7 8 9 10 next10 last )
* 3 = display pages in tripple groups with ... ( e.g. first previous 1 2 3 ... 6 7 8 ... 14 15 16
*
* @param integer $intPaginationType
* @param string $strOutputType (html/xml)
* @return string HTML Code of pagination
*/
function getPagination( $intPaginationType = false, $strOutputType = "html" ) {
global $sess, $idcat, $idart, $lang, $client;
if ( $this->intTotalPages < 2) {
return '';
}
if ($intPaginationType && (int)$intPaginationType > 0) {
$this->setPaginationType($intPaginationType);
}
// check if current page in range with pages
if ($this->intCurrentPage >= $this->intTotalPages ) {
$this->intCurrentPage = $this->intTotalPages-1;
} else if ( $this->intCurrentPage < 0 ) {
$this->intCurrentPage = 0;
}
// reinitialize variables
$arrOutput = array();
$arrPagination = array();
$i = 0;
if ( $this->intCurrentPage > 0 ) {
// add first page link
// page parameter for link
$intPageParameter = "0";
$arrOutput[$i] = array();
// add page attribute info
$arrOutput[$i][$this->strPageParameter] = $intPageParameter;
$arrOutput[$i]['title'] = $this->strTextFirstPage;
$arrOutput[$i]['uri'] = $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart .
"&" . $this->strPageParameter . "=" . $intPageParameter
);
$arrOutput[$i]['attr_class'] = $this->strCSSTextLinkClass;
$arrOutput[$i]['attr_style'] = $this->strCSSTextLinkStyle;
$arrOutput[$i]['attr_liclass'] = $this->strCSSLIClass;
$arrOutput[$i]['attr_listyle'] = $this->strCSSLIStyle;
$i++;
if ( $this->intPaginationType != 2 ) {
// add previous page link
// page parameter for link
$intPageParameter = ( $this->intCurrentPage - 1);
$arrOutput[$i] = array();
// add page attribute info
$arrOutput[$i][$this->strPageParameter] = $intPageParameter;
$arrOutput[$i]['title'] = $this->strTextPreviousPage;
$arrOutput[$i]['uri'] = $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart .
"&" . $this->strPageParameter . "=" . $intPageParameter
);
$arrOutput[$i]['attr_class'] = $this->strCSSTextLinkClass;
$arrOutput[$i]['attr_style'] = $this->strCSSTextLinkStyle;
$arrOutput[$i]['attr_liclass'] = $this->strCSSLIClass;
$arrOutput[$i]['attr_listyle'] = $this->strCSSLIStyle;
$i++;
} else if ( $this->intPaginationType == 2 && $this->intCurrentPage > ($this->intPaginationRange - 1) ) {
// add previous page range link
// page parameter for link
$intPageParameter = ( (floor($this->intCurrentPage / $this->intPaginationRange) * $this->intPaginationRange ) - 1 );
$arrOutput[$i] = array();
// add page attribute info
$arrOutput[$i][$this->strPageParameter] = $intPageParameter;
$arrOutput[$i]['title'] = $this->strTextPreviousRange;
$arrOutput[$i]['uri'] = $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart .
"&" . $this->strPageParameter . "=" . $intPageParameter
);
$arrOutput[$i]['attr_class'] = $this->strCSSTextLinkClass;
$arrOutput[$i]['attr_style'] = $this->strCSSTextLinkStyle;
$arrOutput[$i]['attr_liclass'] = $this->strCSSLIClass;
$arrOutput[$i]['attr_listyle'] = $this->strCSSLIStyle;
$i++;
}
}
// get all page elements
if ( count($this->arrPagination) == 0 ) {
$this->getPaginationTypeAll();
}
$arrOutput[$i]["pages"] = array();
// switch pagination type and generate different paginations
switch ( $this->intPaginationType ) {
case 2:
// get range
$intHighestRange = ( ( (ceil( ($this->intCurrentPage) / $this->intPaginationRange ) * $this->intPaginationRange ) - 1) + (( $this->intCurrentPage % $this->intPaginationRange == 0 ) ? $this->intPaginationRange : 0 ) );
$intLowestRange = ((floor($this->intCurrentPage / $this->intPaginationRange) * $this->intPaginationRange ) );
for ( $z = $intLowestRange; $z <= $intHighestRange; $z++) {
if ($z == $this->intTotalPages) {
break;
}
$arrOutput[$i]["pages"][] = $this->arrPagination[$z];
}
break;
case 3:
// display pages in tripple groups
if ( $this->intTotalPages > 10) {
for ($z = 0; $z < $this->intTotalPages; $z++) {
// check is current site in range of displayed pages
if ( $z <= 2 ||
( $z == $this->intCurrentPage || $z == $this->intCurrentPage - 1 || $z == $this->intCurrentPage + 1 ) ||
$z >= ($this->intTotalPages - 3 )
) {
$arrPagination[] = $this->arrPagination[$z];
} else {
// element should be empty
$arrPagination[] = "[[empty]]";
}
}
// search for following [[empty]] elements and set them to false for removing
$intValue = false;
for ( $z = 0; $z < count($arrPagination); $z++) {
if ( $arrPagination[$z] == "[[empty]]" && $intValue == false ) {
$intValue = true;
} else if ( $arrPagination[$z] == "[[empty]]" && $intValue == true ) {
$arrPagination[$z] = false;
} else if ( $arrPagination[$z] != "[[empty]]" && $intValue == true ) {
$intValue = false;
}
}
// filter array and remove false elements
$arrOutput[$i]["pages"] = array_filter($arrPagination);
} else {
// not enough pages for this pagination
$arrOutput[$i]["pages"] = $this->arrPagination;
}
break;
default:
// display all pages
// join pages
$arrOutput[$i]["pages"] = $this->arrPagination;
break;
}
$i++;
// add next post
if ( $this->intPaginationType != 2 && $this->intCurrentPage < ($this->intTotalPages - 1) ) {
// page parameter for link
$intPageParameter = ($this->intCurrentPage + 1);
$arrOutput[$i] = array();
// add page attribute info
$arrOutput[$i][$this->strPageParameter] = $intPageParameter;
$arrOutput[$i]['title'] = $this->strTextNextPage;
$arrOutput[$i]['uri'] = $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart .
"&" . $this->strPageParameter . "=" . $intPageParameter
);
$arrOutput[$i]['attr_class'] = $this->strCSSTextLinkClass;
$arrOutput[$i]['attr_style'] = $this->strCSSTextLinkStyle;
$arrOutput[$i]['attr_liclass'] = $this->strCSSLIClass;
$arrOutput[$i]['attr_listyle'] = $this->strCSSLIStyle;
$i++;
// set next page range
} else if (
$this->intPaginationType == 2 &&
ceil( ($this->intCurrentPage + 1 ) / $this->intPaginationRange) * $this->intPaginationRange < ($this->intTotalPages - 1)
) {
// page parameter for link
$intPageParameter = (ceil( ($this->intCurrentPage + 1 ) / $this->intPaginationRange) * $this->intPaginationRange);
$arrOutput[$i] = array();
// add page attribute info
$arrOutput[$i][$this->strPageParameter] = $intPageParameter;
$arrOutput[$i]['title'] = $this->strTextNextRange;
$arrOutput[$i]['uri'] = $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart .
"&" . $this->strPageParameter . "=" . $intPageParameter
);
$arrOutput[$i]['attr_class'] = $this->strCSSTextLinkClass;
$arrOutput[$i]['attr_style'] = $this->strCSSTextLinkStyle;
$arrOutput[$i]['attr_liclass'] = $this->strCSSLIClass;
$arrOutput[$i]['attr_listyle'] = $this->strCSSLIStyle;
$i++;
}
// add last post
if ( $this->intCurrentPage < ($this->intTotalPages - 1) ) {
// page parameter for link
$intPageParameter = ($this->intTotalPages - 1);
$arrOutput[$i] = array();
// add page attribute info
$arrOutput[$i][$this->strPageParameter] = $intPageParameter;
$arrOutput[$i]['title'] = $this->strTextLastPage;
$arrOutput[$i]['uri'] = $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart .
"&" . $this->strPageParameter . "=" . $intPageParameter
);
$arrOutput[$i]['attr_class'] = $this->strCSSTextLinkClass;
$arrOutput[$i]['attr_style'] = $this->strCSSTextLinkStyle;
$arrOutput[$i]['attr_liclass'] = $this->strCSSLIClass;
$arrOutput[$i]['attr_listyle'] = $this->strCSSLIStyle;
$i++;
}
// return correct pagination
if ( $strOutputType == "xml" ) {
$this->generateXMLPaginationArray( $arrOutput );
return $this->generateXMLPagination();
} else {
return $this->generateHTMLPaginationFromArray( $arrOutput );
}
}
/**
* Return XHTML Valid Output of Navigation
*
* @param array $arrElements all pagination elements
* @return string xhtml code
*/
function generateHTMLPaginationFromArray( $arrElements = array() ) {
$strOutput = '';
$arrOutput = array();
$arrPages = array();
// set joining parameter
$strJoinParameter = '';
if ( strlen($this->strPageJoinParameter) > 0 ) {
$strJoinParameter = $this->strPageJoinParameter;
}
$i = 0;
// add ul tag
if ($this->intPaginationUseList == 1) {
$arrOutput[$i] = '<ul';
// add id
$arrOutput[$i].= ( strlen($this->strCSSULId) > 0 ) ? ' id="' . $this->strCSSULId . '"' : '';
// add class
$arrOutput[$i].= ( strlen($this->strCSSULClass) > 0 ) ? ' class="' . $this->strCSSULClass . '"' : '';
// add style
$arrOutput[$i].= ( strlen($this->strCSSULStyle) > 0 ) ? ' style="' . $this->strCSSULStyle . '"' : '';
$arrOutput[$i].= '>' . "\n";
$i++;
}
// internal element counter
// add all elements
foreach ( $arrElements as $e ) {
if ( isset($e["pages"]) && is_array($e["pages"]) ) {
// internal page counter
$z = 0;
// go through each page
foreach ( $e["pages"] as $arrPage ) {
// is an empty element for pagination type 2
// will be replaced with " ... " after foreach
if ( !is_array($arrPage) && $arrPage == "[[empty]]" ) {
$arrPages[$z] = "[[empty]]";
$z++;
continue;
}
// initialize
$arrPages[$z] = '';
// clean variables
$arrPage = array_filter($arrPage);
// add list element
if ($this->intPaginationUseList == 1) {
$arrPages[$z].= '<li';
$arrPages[$z].= ( isset($arrPage["attr_liclass"]) ) ? ' class="' . $arrPage["attr_liclass"] . '"' : '';
$arrPages[$z].= ( isset($arrPage["attr_listyle"]) ) ? ' style="' . $arrPage["attr_listyle"] . '"' : '';
$arrPages[$z].= '>';
}
// add url
$arrPages[$z].= '<a href="' . htmlentities($arrPage["uri"]) . '"';
$arrPages[$z].= ( isset($arrPage["attr_class"]) ) ? ' class="' . $arrPage["attr_class"] . '"' : '';
$arrPages[$z].= ( isset($arrPage["attr_style"]) ) ? ' style="' . $arrPage["attr_style"] . '"' : '';
$arrPages[$z].= ( isset($arrPage["attr_title"]) ) ? ' title="' . $arrPage["attr_title"] . '"' : '';
$arrPages[$z].= '>';
// css style settings
$strLinkText = '%s';
if ( isset($arrPage["active"]) && $this->intPaginationActivePageUseStrong == 1) {
$strLinkText = '<strong>%s</strong>';
}
$arrPages[$z].= sprintf($strLinkText, $arrPage['title']);
$arrPages[$z].= '</a>';
// close list element
if ($this->intPaginationUseList == 1) {
$arrPages[$z].= '</li>';
}
// add line break for cool html source
$arrPages[$z].= "\n";
$z++;
}
// join array elements
$arrOutput[$i] = implode($strJoinParameter, $arrPages);
$arrOutput[$i] = str_replace($strJoinParameter . "[[empty]]" . $strJoinParameter, " ... ", $arrOutput[$i]);
$i++;
} else {
// add text links
// clean array
$e = array_filter($e);
$arrOutput[$i] = '';
// add list element
if ($this->intPaginationUseList == 1) {
$arrOutput[$i].= '<li';
$arrOutput[$i].= ( isset($e["attr_liclass"]) ) ? ' class="' . $e["attr_liclass"] . '"' : '';
$arrOutput[$i].= ( isset($e["attr_listyle"]) ) ? ' style="' . $e["attr_listyle"] . '"' : '';
$arrOutput[$i].= '>';
}
// add url
$arrOutput[$i].= '<a href="' . htmlentities($e["uri"]) . '"';
$arrOutput[$i].= ( isset($e["attr_class"]) ) ? ' class="' . $e["attr_class"] . '"' : '';
$arrOutput[$i].= ( isset($e["attr_style"]) ) ? ' style="' . $e["attr_style"] . '"' : '';
$arrOutput[$i].= '>';
// css style settings
$arrOutput[$i].= $e["title"];
$arrOutput[$i].= '</a>';
// close list element
if ($this->intPaginationUseList == 1) {
$arrOutput[$i].= '</li>';
}
// add line break for cool html source
$arrOutput[$i].= "\n";
$i++;
}
}
// close ul tag if necessary
if ($this->intPaginationUseList == 1) {
$arrOutput[$i].= '</ul>' . "\n";
}
$strOutput = implode( "", $arrOutput );
// set xhtml valid entities
return $strOutput;
}
/**
* store all page elements with urls and if necessary
* list elements in a global array for further usage
*
*/
function getPaginationTypeAll() {
global $sess, $idcat, $idart, $lang, $client;
// initialize
$this->arrPagination = array();
for ( $i = 0; $i < $this->intTotalPages; $i++ ) {
$this->arrPagination[$i] = Array();
// add page attribute info
$this->arrPagination[$i][$this->strPageParameter] = $i;
// add regular url elements
$this->arrPagination[$i]['title'] = ($i + 1);
$this->arrPagination[$i]['uri'] = $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart .
"&" . $this->strPageParameter . "=" . $i
);
// style settings
$this->arrPagination[$i]['attr_liclass'] = $this->strCSSLIClass;
$this->arrPagination[$i]['attr_listyle'] = $this->strCSSLIStyle;
$this->arrPagination[$i]['attr_class'] = $this->strCSSPageClass;
$this->arrPagination[$i]['attr_style'] = $this->strCSSPageStyle;
$this->arrPagination[$i]['attr_title'] = $this->strTextPageTitle . ( $i + 1 );
// override style settings if active
if ( $i == $this->intCurrentPage ){
$this->arrPagination[$i]['active'] = "1";
$this->arrPagination[$i]['attr_liclass'] = $this->strCSSLIActiveClass;
$this->arrPagination[$i]['attr_listyle'] = $this->strCSSLIActiveStyle;
$this->arrPagination[$i]['attr_class'] = $this->strCSSActivePageClass;
$this->arrPagination[$i]['attr_style'] = $this->strCSSActivePageStyle;
}
}
}
/**
* return the current Article Part
*
* @return string Current Article Part
*/
function getArticle() {
// article part is array and current page is valid array element
if (
is_array( $this->arrSplittedArticle )
&& ( count($this->arrSplittedArticle) - 1 ) >= $this->intCurrentPage
&& $this->intCurrentPage >= 0
) {
return trim($this->arrSplittedArticle[$this->intCurrentPage]);
// article part is array but current page is higher than array parts
} else if (
is_array( $this->arrSplittedArticle )
&& ( count($this->arrSplittedArticle) - 1 ) < $this->intCurrentPage
) {
return trim($this->arrSplittedArticle[count($this->arrSplittedArticle) - 1]);
// article part is array but current page is negative
} else if (is_array( $this->arrSplittedArticle )
&& $this->intCurrentPage < 0
) {
return trim($this->arrSplittedArticle[0]);
// article part is not an array, return as string
} else if ( !is_array( $this->arrSplittedArticle ) ) {
return trim($this->arrSplittedArticle);
}
return false;
}
/**
* XML Functions
*/
/**
* generate array for xml output
*
* @param array $arrElements array with all elements
*/
function generateXMLPaginationArray ( $arrElements = array() ) {
global $idart, $idcat, $client, $lang, $sess;
if ( count($arrElements) == 0 ) return true;
// create pagination xml object
$objPagination = new xmlObject("pagination");
// add attributes
$objPagination->addMultipleAttributes(
array(
"totalPages" => $this->intTotalPages,
"currentPage" => $this->intCurrentPage,
"pageParameter" => $this->strPageParameter,
"idart" => $idart,
"idcat" => $idcat,
"client" => $client,
"lang" => $lang,
"uri" => $sess->url(
"front_content.php?" .
"client=" . $client .
"&changelang=" . $lang .
"&idcat=" . $idcat .
"&idart=" . $idart
)
)
);
foreach ( $arrElements as $e ) {
// site page
if ( isset($e["pages"]) && is_array($e["pages"]) ) {
// get every page
foreach ( $e["pages"] as $arrPage ) {
;
$strContent = '';
$arrAttributes = array();
// clean attributes
$arrPage = array_filter($arrPage);
// prepare xml stuff
foreach ($arrPage as $strKey => $strValue ) {
if ($strKey == 'title') {
$strContent = $strValue;
continue;
}
$arrAttributes[ str_replace( 'attr_', '', $strKey) ] = $strValue;
}
if ( !isset($arrAttributes[$this->strPageParameter])) {
$arrAttributes[$this->strPageParameter] = "0";
}
// add content to object
$objPagination->addContent(
new xmlObject('element', $arrAttributes, strval($strContent))
);
}
} else {
// text links
$strContent = '';
$arrAttributes = array();
// clean attributes
if ( !is_array($e) ) {
continue;
}
$e = array_filter($e);
// prepare xml stuff
foreach ($e as $strKey => $strValue ) {
if ($strKey == 'title') {
$strContent = $strValue;
continue;
}
$arrAttributes[ str_replace( 'attr_', '', $strKey) ] = $strValue;
}
// add content to object
$objPagination->addContent(
new xmlObject('element', $arrAttributes, strval($strContent), true)
);
}
}
$this->arrXML["pagination"] = $objPagination;
return true;
}
/**
* generate array from article properties for output
*
*/
function generateXMLArticleArray () {
// get current content
$strContent = $this->getArticle();
$strContent = strip_tags( $strContent, $this->strXMLAllowedTags );
// check if other parameter set
if (!isset($this->arrXML["content"])) {
$this->arrXML["content"] = array();
}
$this->arrXML["content"][] = new xmlObject("article", array("length" => strlen ( strip_tags($strContent) )), $strContent, true);
}
/**
* open XML container and output header
*
* @param string $strCharset charset
* @return string xml container
*/
function getXMLHeader() {
// output header
header ("Content-type: text/xml; charset=" . $this->strXMLCharset );
// output doctype
$strOutput = '<?xml version="1.0" encoding="' . $this->strXMLCharset . '" ?>' . "\n";
return $strOutput;
}
/**
* generate xml schema for article
*
* @return string xml schema
*/
function generateXMLContent () {
// get data
$this->generateXMLArticleArray();
// check again for data
if ( count ( $this->arrXML["content"] ) == 0 ) {
return '';
}
$objContent = new xmlObject('content');
foreach ( $this->arrXML["content"] as $objElement ) {
$objContent->addContent($objElement);
}
return $objContent->toHTML();
}
/**
* generate xml schema for pagination
*
* @return string xml schema
*/
function generateXMLPagination() {
// check for data
if (
!isset($this->arrXML["pagination"]) ||
!is_object($this->arrXML["pagination"])
) {
$this->generateXMLPaginationArray();
}
// check again for data
if ( !isset($this->arrXML["pagination"]) || !is_object($this->arrXML["pagination"]) ) {
return '';
}
return $this->arrXML["pagination"]->toHTML();
}
/**
* return complete xml scheme for article only
*
* @return string xml scheme
*/
function getXMLContent () {
$objXmlContainer = new xmlObject(
"articlepagebreak",
array( "encoding" => $this->strXMLCharset ),
$this->generateXMLContent()
);
$strOutput = $this->getXMLHeader();
$strOutput.= $objXmlContainer->toHTML();
return $strOutput;
}
/**
* return complete xml scheme for pagination only
*
* @return string xml scheme
*/
function getXMLPagination () {
$objXmlContainer = new xmlObject(
"articlepagebreak",
array("encoding" => $this->strXMLCharset),
$this->getPagination($this->intPaginationType, "xml")
);
$strOutput = $this->getXMLHeader();
$strOutput.= $objXmlContainer->toHTML();
return $strOutput;
}
/**
* return complete xml scheme for article and pagination
*
* @return string xml scheme
*/
function getXMLComplete () {
$objXmlContainer = new xmlObject(
"articlepagebreak",
array("encoding" => $this->strXMLCharset),
array (
$this->generateXMLContent(),
$this->getPagination($this->intPaginationType, "xml")
)
);
$strOutput = $this->getXMLHeader();
$strOutput.= $objXmlContainer->toHTML();
return $strOutput;
}
/**
* adds an additional XML Object for output in
* content tag in generating xml
*
* @see class xmlObject
* @param object $objElement xmlObject
*/
function setXMLAdditionalContentTag ( $objElement ) {
if ( is_object($objElement) && strtolower(get_class($objElement)) == strtolower('xmlObject') ) {
// check if other parameter set
if (!isset($this->arrXML["content"])) {
$this->arrXML["content"] = array();
}
$this->arrXML["content"][] = $objElement;
}
}
/**
* set the article content to class
*
* @param string $strArticle Article Content
*/
function setArticle ( $strArticle = "" ) {
$this->strArticle = $strArticle;
// split article
$this->splitArticle();
}
/**
* Set URI parameter for page break
*
* @param string $strPageParameter Parameter Name
*/
function setPageParameter ( $strPageParameter = "page" ) {
$this->strPageParameter = $strPageParameter;
}
/**
* Set the current page for output
*
* @param integer $intCurrentPage
*/
function setCurrentPage ( $intCurrentPage = 0 ) {
$this->intCurrentPage = (int)$intCurrentPage;
}
/**
* Sets pagination type
* 1 = display all pages (e.g. first previous 1 2 3 4 5 6 7 8 9 10 11 next last)
* 2 = display page range 1 - 10 ( e.g. first previous10 1 2 3 4 5 6 7 8 9 10 next10 last )
* 3 = display pages in tripple groups with ... ( e.g. first previous 1 2 3 ... 6 7 8 ... 14 15 16
*
* @param integer $intPaginationType PageType
*/
function setPaginationType ( $intPaginationType = 1 ) {
if ( (int)$intPaginationType < 1 || (int)$intPaginationType > 3 ) {
$this->intPaginationType = 1;
} else {
$this->intPaginationType = (int)$intPaginationType;
}
}
/**
* Sets pagination range for Pagination Type 2
*
* @param integer $intPaginationRange
*/
function setPaginationRange ( $intPaginationRange = 10 ) {
$this->intPaginationRange = (int)$intPaginationRange;
}
/**
* set text for first page of pagination
*
* @param string $strTextFirstPage
*/
function setTextFirstPage ( $strTextFirstPage = "First Page" ) {
$this->strTextFirstPage = $strTextFirstPage;
}
/**
* set text for last page of pagination
*
* @param string $strTextLastPage
*/
function setTextLastPage ( $strTextLastPage = "Last Page" ) {
$this->strTextLastPage = $strTextLastPage;
}
/**
* set text for previous page of pagination
*
* @param string $strTextPreviousPage
*/
function setTextPreviousPage ( $strTextPreviousPage = "Previous" ) {
$this->strTextPreviousPage = $strTextPreviousPage;
}
/**
* set text for next page of pagination
*
* @param string $strTextNextPage
*/
function setTextNextPage ( $strTextNextPage = "Next" ) {
$this->strTextNextPage = $strTextNextPage;
}
/**
* set text for next range of pagination type 2
*
* @param string $strTextNextRange
*/
function setTextNextRange ( $strTextNextRange = "Next 10" ) {
$this->strTextNextRange = $strTextNextRange;
}
/**
* set text for previous range of pagination type 2
*
* @param string $strTextPreviousRange
*/
function setTextPreviousRange ( $strTextPreviousRange = "Previous 10" ) {
$this->strTextPreviousRange = $strTextPreviousRange;
}
/**
* set title tag text for a tag of pages
*
* @param string $strTextPageTitle
*/
function setTextPageTitle ( $strTextPageTitle = "Goto page ") {
$this->strTextPageTitle = $strTextPageTitle;
}
/**
* set CSS style settings for pagination
*/
/**
* Use unordered list for navigation
* 0 = false
* 1 = true
*
* @param integer $intPaginationUseList
*/
function setPaginationUseList ( $intPaginationUseList = 0 ) {
$this->intPaginationUseList = (int)$intPaginationUseList;
}
/**
* Use strong-tag for active page
* 0 = false
* 1 = true (default)
*
* @param integer $intPaginationActivePageUseStrong
*/
function setPaginationActivePageUseStrong ( $intPaginationActivePageUseStrong = 1 ) {
$this->intPaginationActivePageUseStrong = ( (int)$intPaginationActivePageUseStrong == 1 ) ? 1 : 0;
}
/**
* set css class for default page links
*
* @param string $strCSSPageClass
*/
function setCSSPageClass ( $strCSSPageClass = '' ) {
$this->strCSSPageClass = $strCSSPageClass;
}
/**
* set css style for default page links
*
* @param string $strCSSPageStyle
*/
function setCSSPageStyle ( $strCSSPageStyle = '' ) {
$this->strCSSPageStyle = $strCSSPageStyle;
}
/**
* set css class for active page
*
* @param string $strCSSActivePageClass
*/
function setCSSActivePageClass ( $strCSSActivePageClass = '' ) {
$this->strCSSActivePageClass = $strCSSActivePageClass;
}
/**
* set css style for active page
*
* @param string $strCSSActivePageStyle
*/
function setCSSActivePageStyle ( $strCSSActivePageStyle = '' ) {
$this->strCSSActivePageStyle = $strCSSActivePageStyle;
}
/**
* set css class for text links like next, previous, last and first
*
* @param string $strCSSTextLinkClass
*/
function setCSSTextLinkClass ( $strCSSTextLinkClass = '' ) {
$this->strCSSTextLinkClass = $strCSSTextLinkClass;
}
/**
* set css style for text links like next, previous, last and first
*
* @param string $strCSSTextLinkStyle
*/
function setCSSTextLinkStyle ( $strCSSTextLinkStyle = '' ) {
$this->strCSSTextLinkStyle = $strCSSTextLinkStyle;
}
/**
* set id attribute for ul element
*
* @param string $strCSSULId
*/
function setCSSULId ( $strCSSULId = '' ) {
$this->strCSSULId = $strCSSULId;
}
/**
* set css class for ul element
*
* @param string $strCSSULClass
*/
function setCSSULClass ( $strCSSULClass = '' ) {
$this->strCSSULClass = $strCSSULClass;
}
/**
* set css style for ul element
*
* @param string $strCSSULStyle
*/
function setCSSULStyle ( $strCSSULStyle = '' ) {
$this->strCSSULStyle = $strCSSULStyle;
}
/**
* set css class for li element
*
* @param string $strCSSLIClass
*/
function setCSSLIClass ( $strCSSLIClass = '' ) {
$this->strCSSLIClass = $strCSSLIClass;
}
/**
* set css style for li element
*
* @param string $strCSSLIStyle
*/
function setCSSLIStyle ( $strCSSLIStyle = '' ) {
$this->strCSSLIStyle = $strCSSLIStyle;
}
/**
* set css class for active page li element
*
* @param string $strCSSLIActiveClass
*/
function setCSSLIActiveClass ( $strCSSLIActiveClass = '' ) {
$this->strCSSLIActiveClass = $strCSSLIActiveClass;
}
/**
* set css style for active page li element
*
* @param string $strCSSLIActiveStyle
*/
function setCSSLIActiveStyle ( $strCSSLIActiveStyle = '' ) {
$this->strCSSLIActiveStyle = $strCSSLIActiveStyle;
}
/**
* set join parameter for joining page elements if no list is used
*
* @param string $strPageJoinParameter
*/
function setPageJoinParameter ( $strPageJoinParameter = ', ' ) {
$this->strPageJoinParameter = $strPageJoinParameter;
}
/**
* set allowed tags for xml output of content
* seperate different tags with comma
* default: a,i,b,u,br
*
* @param string $strXMLAllowedTags allowed tags
*/
function setXMLAllowedTags ( $strXMLAllowedTags = '' ) {
$this->strXMLAllowedTags = $strXMLAllowedTags;
}
/**
* set encoding charset for XML output
*
* @param string $strXMLCharset
*/
function setXMLCharset ( $strXMLCharset = 'utf-8' ) {
$this->strXMLCharset = $strXMLCharset;
}
}
/**
* xmlObject
*
* class handles stored data to convert them in
* xml tags
*
* @author stefan seifarth <info@polycoder.de>
* @copyright 2006 stefan seifarth, munich
* @name xmlObject
* @version 1.0 2006-06-17
* @access public
*
* @example
* // create Object
* $obj = new xmlObject ('tagname');
* // set single attribute
* $obj->addSingleAttribute ( "attribute name", "attribute value" );
* // set multiple attributes
* $obj->addMultipleAttributes(
* array( "attrName" => "value", "attrName2" => "value2" )
* );
* // set content
* $obj->addContent ( "some text in tag" );
* // return xml form
* print $obj->toHTML();
*
*
* // alternative usage for shorttags
*
* $obj = new xmlObject("content");
* $obj->addMultipleAttributes(
* array(
* "count" => "1",
* "page" => "23"
* )
* );
* $obj->addContent(
* array(
* new xmlObject("article", array(), "text1"),
* new xmlObject("article", array(), "text2"),
* new xmlObject("article", array("pages" => "2"),
* array(
* new xmlObject("page", array(), "text3_1", true),
* new xmlObject("page", array(), "text3_2", true)
* )
* )
* )
* );
* print $obj->toHTML();
*/
class xmlObject {
var $arrAttributes = array();
var $arrContent = array();
var $strTagName;
var $bolUseCDATA = false;
/**
* class constructor
*
* @param string $strTagName xml tag name
* @param string/object/array $content content
* @param array $arrAttributes attributes
* @param boolean $bolUseCDATA flag for usage of cdata
* @return xmlObject
*/
function xmlObject( $strTagName, $arrAttributes = array(), $content = array(), $bolUseCDATA = false ) {
$this->strTagName = $strTagName;
// set cdata usage
$this->bolUseCDATA = $bolUseCDATA;
// add attributes if set
if (is_array($arrAttributes) && count($arrAttributes) > 0) {
foreach ( $arrAttributes as $strName => $strValue ) {
$this->arrAttributes[$strName] = $strValue;
}
}
// add content if set
if (!is_array($content) && (is_object($content) || strlen($content) > 0 ) ) {
$this->arrContent[] = $content;
} else if (is_array($content) && count($content) > 0) {
// range of objects
$intCounter = count($this->arrContent);
foreach ( $content as $objElement ) {
$this->arrContent[$intCounter] = $objElement;
$intCounter++;
}
}
}
/**
* add a single argument for tag name
*
* @param string $strName name of argument
* @param string $strValue value of argument
*/
function addSingleAttribute ( $strName, $strValue = "" ) {
$this->arrAttributes[$strName] = $strValue;
}
/**
* add multiple attributes at once like
* array("name" => "value", "name2" => "value2")
*
* @param array $arrAttributes argument list
*/
function addMultipleAttributes ( $arrAttributes = array() ) {
if (!is_array($arrAttributes)) return false;
foreach ( $arrAttributes as $strName => $strValue ) {
$this->arrAttributes[$strName] = $strValue;
}
return true;
}
/**
* add content to xml tag
* use array for multiple contents
* array( $objectTag1, $objectTag2 )
*
* @param string/object/array $objContent value of content
*/
function addContent ( $objContent = "" ) {
if (!is_array($objContent)) {
$this->arrContent[] = $objContent;
} else {
// range of objects
$intCounter = count($this->arrContent);
foreach ( $objContent as $objElement ) {
$this->arrContent[$intCounter] = $objElement;
$intCounter++;
}
}
}
/**
* return complete xml object as string with tags
*
* @return unknown
*/
function toHTML () {
$strOutput = '<' . utf8_encode($this->strTagName);
// add tag attributes
if (is_array($this->arrAttributes) && count($this->arrAttributes) > 0 ) {
foreach ( $this->arrAttributes as $strName => $strValue ) {
$strOutput.= ' ' . utf8_encode($strName) . '="' . utf8_encode(htmlentities($strValue)) . '"';
}
}
$strOutput.= ">";
// add content
if ( is_array($this->arrContent) && count($this->arrContent) > 0 ) {
foreach ($this->arrContent as $objElement ) {
if ( is_object($objElement) && get_class($objElement) == get_class($this) ) {
$strOutput.="\n" . $objElement->toHTML();
} else if ( is_string($objElement) && strlen($objElement) > 0 ) {
// cdata usage?
if ( $this->bolUseCDATA == true ) {
$strOutput.= '<![CDATA[' . utf8_encode($objElement) . ']]>';
} else {
$strOutput.= utf8_encode($objElement);
}
}
}
} else if ( is_object($this->arrContent) && get_class($this->arrContent) == get_class($this) ) {
$strOutput.= "\n" . $this->arrContent->toHTML();
} else if ( is_string($this->arrContent) && strlen($this->arrContent) > 0 ) {
$strOutput.= utf8_encode($this->arrContent);
}
// close tag
$strOutput.= '</' . utf8_encode($this->strTagName) . ">\n";
// remove double linebreaks
$strOutput = str_replace("\n\n","\n", $strOutput);
return $strOutput;
}
/**
* set flag for using cdata in tag
*
* @param boolean $bolUseCDATA true/false
*/
function setCDATA ( $bolUseCDATA = false ) {
$this->bolUseCDATA = $bolUseCDATA;
}
}
?>