Version: 1.2
Contenido: 4.6.x
Autor: Stefan Seifarth
Installationsgrad: Einfach
Modifikationsgrad: Mittel
Szenario:
Sie haben sehr lange Artikel und wollen diese auf mehrere Seiten verteilen
aber nur in einem regulären Artikel editieren. Allerdings kommt eine
automatische Aufteilung nicht in Frage, da Sie auch Bilder und ähnliche
Elemente auf Ihrer Website einsetzen, die die Seitenlänge Ihres Textes
beeinflussen.
Die Lösung: Es werden von Ihnen an den zu umbrechenden Stellen im
Artikel HTML-Anker mit bestimmten Namen platziert, die die Trennung des
Artikels bewirken.
Nachtrag 08.06.06
Ich habe die Klasse dahingehend erweitert, dass sie auf Wunsch auch XML Daten raushaut, damit man die Daten auch ordentlich in Flash importieren kann. Werden die wenigsten brauchen ist aber äußerst nützlich!
der Aufruf erfolgt im Modul folgendermaßen:
Code: Alles auswählen
print $oArticlePageBreak->getXMLComplete();
Demonstration und Download aller Dateien unter www.polycoder.de
Klasse class.articlepagebreak.php
Bitte in [mandantenverzeichnis]/includes ablegen!
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;
}
}
?>
Code: Alles auswählen
Article Semi-AutoPageBreak
Semi-Automatic page break of an article.
Uses userdefined anchor tags to split article in several pages and generate a pagination.
@author stefan seifarth <info@polycoder.de>
@copyright 2006 stefan seifarth, munich
@name ArticlePageBreak
@version 1.3 2006-06-17
Features:
- can be returned as unordered list (ul-tag)
- full customizable with customizied CSS styles
(see method-names starting with "set" in class.articlepagebreak.php)
- full customized text for first, previous, next last buttons
- three types of paginations:
1: list all pages e.g.:
[first page] [previous page] 1, 2, 3, 4 [next page] [last page]
2: list in 10page groups
[first page] [previous] 10, 11, 12, 13
3: list pages in tripple groups like phpbb pagination:
[first page] [previous page] 1, 2, 3 ... 6, 7, 8 ... 14, 15, 16 [next page] [last page]
- page parameter for url can be changed
- full xml output
- additional xml elements can be added in xml output
Code: Alles auswählen
?>
<?php
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname : Article Semi-AutoPageBreak
* Author(s) : Stefan Seifarth <info@polycoder.de>
* Copyright : www.polycoder.de / www.htcm.de
* Created : 2006-06-04
************************************************/
print mi18n("Ankername für Seitenwechsel") . ":\n<br>";
print '<input type="text" name="CMS_VAR[210]" value="CMS_VALUE[210]">' . "\n";
?>
<?php
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", "classes/class.articlepagebreak_neu.php");
$strAnchorName = "CMS_VALUE[210]";
$strArticle = "CMS_HTML[1]";
$strDelimiter = '<a name="' . $strAnchorName . '"></a>';
if ($edit) {
print $strArticle;
} else {
// 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
print $oArticlePageBreak->getArticle();
print '<br /><br />';
// get pagination for article
print $oArticlePageBreak->getPagination();
/*
// 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();
*/
}
?>