2006-12-02 04:36:16 +00:00
< ? php
/*
2011-12-07 21:07:21 +00:00
* e107 website system
*
2017-02-10 22:34:17 +00:00
* Copyright ( C ) 2008 - 2017 e107 Inc ( e107 . org )
2011-12-07 21:07:21 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
2017-02-10 22:34:17 +00:00
*/
2006-12-02 04:36:16 +00:00
require_once ( " class2.php " );
2011-12-07 21:07:21 +00:00
e107 :: coreLan ( 'page' );
$e107CorePage = new pageClass ( false );
2009-08-28 15:30:25 +00:00
2013-02-14 13:06:16 +02:00
// Important - save request BEFORE any output (header footer) - used in navigation menu
2006-12-02 04:36:16 +00:00
if ( ! e_QUERY )
{
2013-02-14 13:06:16 +02:00
$e107CorePage -> setRequest ( 'listBooks' );
2014-07-24 16:50:56 +03:00
$e107CorePage -> listBooks ();
2021-01-19 09:50:02 -08:00
e107 :: canonical ( 'page/list/index' );
2006-12-02 04:36:16 +00:00
require_once ( HEADERF );
2014-07-24 16:50:56 +03:00
e107 :: getRender () -> tablerender ( $e107CorePage -> pageOutput [ 'caption' ], $e107CorePage -> pageOutput [ 'text' ], " cpage-full-list " );
2012-10-24 22:02:18 +00:00
// $tmp = $e107CorePage->listPages();
2014-07-24 16:50:56 +03:00
//$tmp = $e107CorePage->listBooks();
2013-02-06 00:20:11 -08:00
// $text = $tp->parseTemplate("{PAGE_NAVIGATION=book=2}",true);
2014-07-24 16:50:56 +03:00
/* if ( is_array ( $tmp ))
2006-12-02 04:36:16 +00:00
{
2014-06-13 04:41:45 -07:00
$ns -> tablerender ( $tmp [ 'title' ], $text , 'cpage-full-list' );
2014-07-24 16:50:56 +03:00
} */
2015-01-10 16:13:32 -08:00
2013-03-19 20:44:46 -07:00
require_once ( FOOTERF );
exit ;
2006-12-02 04:36:16 +00:00
}
2013-02-01 18:00:53 -08:00
elseif ( vartrue ( $_GET [ 'bk' ])) // List Chapters within a specific Book
{
2021-01-19 09:50:02 -08:00
$id = $e107CorePage -> setRequest ( 'listChapters' );
$e107CorePage -> listChapters ( $id );
e107 :: canonical ( 'page/book/index' , $e107CorePage -> getChapterData ( $id ));
2013-02-14 13:06:16 +02:00
2013-02-01 18:00:53 -08:00
require_once ( HEADERF );
2014-07-24 16:50:56 +03:00
e107 :: getRender () -> tablerender ( $e107CorePage -> pageOutput [ 'caption' ], $e107CorePage -> pageOutput [ 'text' ], 'cpage-chapter-list' );
2013-02-01 18:00:53 -08:00
require_once ( FOOTERF );
exit ;
}
elseif ( vartrue ( $_GET [ 'ch' ])) // List Pages within a specific Chapter
{
2021-01-19 09:50:02 -08:00
$id = $e107CorePage -> setRequest ( 'listPages' );
$e107CorePage -> listPages ( $id );
2021-01-19 15:00:08 -08:00
$chData = $e107CorePage -> getChapterData ( $id );
e107 :: canonical ( 'page/chapter/index' , $chData );
2021-01-19 09:50:02 -08:00
unset ( $row );
2014-07-24 16:50:56 +03:00
require_once ( HEADERF );
e107 :: getRender () -> tablerender ( $e107CorePage -> pageOutput [ 'caption' ], $e107CorePage -> pageOutput [ 'text' ], 'cpage-page-list' );
2013-02-01 18:00:53 -08:00
require_once ( FOOTERF );
exit ;
}
2006-12-02 04:36:16 +00:00
else
{
2013-02-14 13:06:16 +02:00
$e107CorePage -> setRequest ( 'showPage' );
2011-12-07 21:07:21 +00:00
$e107CorePage -> processViewPage ();
2014-07-10 13:36:58 +03:00
$e107CorePage -> setPage ();
2021-01-19 15:00:08 -08:00
$canRoute = empty ( $e107CorePage -> page [ 'page_chapter' ]) ? 'page/view/other' : 'page/view' ;
e107 :: canonical ( $canRoute , $e107CorePage -> page );
2011-12-07 21:07:21 +00:00
require_once ( HEADERF );
2017-11-01 19:24:01 -07:00
$ns = e107 :: getRender ();
if ( ! empty ( $e107CorePage -> pageOutput [ 'title' ]))
{
2018-12-16 10:56:00 -08:00
$ns -> setContent ( 'title' , $e107CorePage -> pageOutput [ 'title' ]);
2017-11-01 19:24:01 -07:00
}
2018-12-16 10:56:00 -08:00
$ns -> tablerender ( $e107CorePage -> pageOutput [ 'caption' ], $e107CorePage -> pageOutput [ 'text' ], $e107CorePage -> pageOutput [ 'mode' ]);
2011-12-07 21:07:21 +00:00
require_once ( FOOTERF );
exit ;
2006-12-02 04:36:16 +00:00
}
/* EOF */
class pageClass
{
2011-12-07 21:07:21 +00:00
public $bullet ; /* bullet image */
public $pageText ; /* main text of selected page, not parsed */
public $multipageFlag ; /* flag - true if multiple page page, false if not */
public $pageTitles ; /* array containing page titles */
public $pageID ; /* id number of page to be displayed */
public $pageSelected ; /* selected page of multiple page page */
public $pageToRender ; /* parsed page to be sent to screen */
public $debug ; /* temp debug flag */
public $title ; /* title of page, it if has one (as defined in [newpage=title] tag */
public $page ; /* page DB data */
2014-07-24 16:50:56 +03:00
/**
* @ var cpage_shortcodes
*/
public $batch ; /* shortcode batch object */
2011-12-07 21:07:21 +00:00
public $template ; /* current template array */
protected $authorized ; /* authorized status */
public $cacheString ; /* current page cache string */
public $cacheTitleString ; /* current page title and comment flag cache string */
public $cacheData = null ; /* cache data */
2014-01-10 18:27:42 -08:00
protected $chapterSef ; /* authorized status */
2014-01-15 07:02:10 -08:00
protected $chapterParent ;
2014-06-13 03:39:41 -07:00
2014-01-15 07:02:10 -08:00
protected $chapterData = array ();
2011-12-07 21:07:21 +00:00
2014-07-09 16:42:24 +03:00
protected $displayAllMode = false ; // set to True when no book/chapter/page has been defined by the url/query.
2014-07-24 16:50:56 +03:00
public $pageOutput = array (); // Output storage - text and caption
protected $renderMode ; // Page render mode to be used on view page
2016-04-02 10:51:18 -07:00
protected $templateID = null ;
2014-06-13 03:39:41 -07:00
2011-12-07 21:07:21 +00:00
function __construct ( $debug = FALSE )
2006-12-02 04:36:16 +00:00
{
/* constructor */
2013-02-01 18:00:53 -08:00
if ( ! vartrue ( $_GET [ 'id' ])) // legacy URLs /page.php?x
{
$tmp = explode ( " . " , e_QUERY );
2020-12-12 11:32:23 -08:00
$this -> pageID = ( int ) $tmp [ 0 ];
$this -> pageSelected = ( isset ( $tmp [ 1 ]) ? ( int ) $tmp [ 1 ] : 0 );
2013-02-01 18:00:53 -08:00
$this -> pageTitles = array ();
$this -> bullet = '' ;
}
2014-06-16 18:21:51 -07:00
else // NEW URLS /page.php?id=x
2013-02-01 18:00:53 -08:00
{
$tmp = explode ( " . " , e_QUERY );
2020-12-12 11:32:23 -08:00
$this -> pageID = ( int ) $_GET [ 'id' ];
$this -> pageSelected = ( isset ( $tmp [ 1 ]) ? ( int ) $tmp [ 1 ] : 0 ); // Not sure what this is?
2013-02-01 18:00:53 -08:00
$this -> pageTitles = array ();
$this -> bullet = '' ; // deprecated - use CSS instead.
}
2011-12-07 21:07:21 +00:00
// TODO nq_ (no query) cache string
$this -> cacheString = 'page_' . $this -> pageID . '_' . $this -> pageSelected ;
$this -> cacheTitleString = 'page-t_' . $this -> pageID . '_' . $this -> pageSelected ;
2009-08-23 10:57:51 +00:00
if ( defined ( 'BULLET' ))
2006-12-02 04:36:16 +00:00
{
2012-07-21 05:07:21 +00:00
$this -> bullet = " <img src=' " . THEME_ABS . " images/ " . BULLET . " ' alt='' class='icon' /> " ;
2006-12-02 04:36:16 +00:00
}
2009-08-23 10:57:51 +00:00
elseif ( file_exists ( THEME . 'images/bullet2.gif' ))
2006-12-02 04:36:16 +00:00
{
2012-07-21 05:07:21 +00:00
$this -> bullet = " <img src=' " . THEME_ABS . " images/bullet2.gif' alt='' class='icon' /> " ;
}
elseif ( file_exists ( THEME . 'images/bullet2.png' ))
{
$this -> bullet = " <img src=' " . THEME_ABS . " images/bullet2.png' alt='' class='icon' /> " ;
2006-12-02 04:36:16 +00:00
}
2011-12-07 21:07:21 +00:00
$this -> debug = $debug ;
2006-12-02 04:36:16 +00:00
2011-12-07 21:07:21 +00:00
if ( $this -> debug )
2006-12-02 04:36:16 +00:00
{
2011-12-07 21:07:21 +00:00
$this -> debug = " <b>PageID</b> " . $this -> pageID . " <br /> " ;
$this -> debug .= " <b>pageSelected</b> " . $this -> pageSelected . " <br /> " ;
2006-12-02 04:36:16 +00:00
}
2011-12-07 21:07:21 +00:00
2016-02-29 20:22:14 -08:00
$books = e107 :: getDb () -> retrieve ( " SELECT chapter_id,chapter_sef,chapter_name,chapter_parent FROM #page_chapters ORDER BY chapter_id ASC " , true );
2014-01-10 18:27:42 -08:00
foreach ( $books as $row )
{
2014-01-15 07:02:10 -08:00
$id = $row [ 'chapter_id' ];
$this -> chapterData [ $id ] = $row ;
2014-01-10 18:27:42 -08:00
}
2011-12-07 21:07:21 +00:00
2006-12-02 04:36:16 +00:00
}
2013-02-14 13:06:16 +02:00
public function setRequest ( $request )
{
switch ( $request )
{
case 'listChapters' :
2020-12-12 11:32:23 -08:00
$id = ( int ) $_GET [ 'bk' ];
2013-02-14 13:06:16 +02:00
break ;
case 'listPages' :
2020-12-12 11:32:23 -08:00
$id = ( int ) $_GET [ 'ch' ];
2013-02-14 13:06:16 +02:00
break ;
case 'showPage' :
$id = $this -> pageID ;
break ;
case 'listBooks' :
default :
$id = 0 ;
break ;
}
2016-02-28 20:50:09 -08:00
e107 :: setRegistry ( 'core/page/request' , array ( 'action' => $request , 'id' => $id ));
2021-01-19 09:50:02 -08:00
return $id ;
2013-02-14 13:06:16 +02:00
}
2021-01-19 09:50:02 -08:00
/**
* @ param $chapter
* @ return array | mixed
*/
public function getChapterData ( $chapter )
{
if ( ! isset ( $this -> chapterData [ $chapter ]))
{
return array ();
}
$row = $this -> chapterData [ $chapter ];
2021-01-19 15:00:08 -08:00
$row [ 'book_sef' ] = $this -> getSef ( $row [ 'chapter_parent' ]);
2021-01-19 09:50:02 -08:00
$row [ 'book_id' ] = ( int ) $row [ 'chapter_parent' ];
$row [ 'book_name' ] = $this -> getName ( $row [ 'chapter_parent' ]);
$row [ 'book_icon' ] = $this -> getIcon ( $row [ 'chapter_parent' ]);
$row [ 'book_description' ] = $this -> getDescription ( $row [ 'chapter_parent' ]);
return $row ;
}
2014-01-10 18:27:42 -08:00
private function getSef ( $chapter )
{
2014-01-15 07:02:10 -08:00
return vartrue ( $this -> chapterData [ $chapter ][ 'chapter_sef' ], '--sef-not-assigned--' );
}
private function getParent ( $chapter )
{
return varset ( $this -> chapterData [ $chapter ][ 'chapter_parent' ], false );
}
private function getName ( $chapter )
{
return varset ( $this -> chapterData [ $chapter ][ 'chapter_name' ], false );
}
private function getDescription ( $chapter )
{
return varset ( $this -> chapterData [ $chapter ][ 'chapter_meta_description' ], false );
}
private function getIcon ( $chapter )
{
return varset ( $this -> chapterData [ $chapter ][ 'chapter_icon' ], false );
2014-01-10 18:27:42 -08:00
}
2012-10-24 22:02:18 +00:00
2013-05-30 14:16:49 -07:00
/**
* @ todo Check userclasses
* @ todo sef urls
*/
2012-10-24 22:02:18 +00:00
function listBooks ()
{
$sql = e107 :: getDb ( 'sql2' );
$tp = e107 :: getParser ();
2013-05-30 14:16:49 -07:00
$frm = e107 :: getForm ();
2014-06-13 03:39:41 -07:00
$this -> displayAllMode = true ;
2013-05-30 14:16:49 -07:00
$text = " " ;
2012-10-24 22:02:18 +00:00
2013-05-30 14:16:49 -07:00
2014-02-08 16:57:34 -08:00
if ( e107 :: getPref ( 'listBooks' , false ) && $sql -> select ( " page_chapters " , " * " , " chapter_parent ='0' AND chapter_visibility IN ( " . USERCLASS_LIST . " ) ORDER BY chapter_order ASC " ))
2012-10-24 22:02:18 +00:00
{
2013-05-30 14:16:49 -07:00
$layout = e107 :: getPref ( 'listBooksTemplate' , 'default' );
$tml = e107 :: getCoreTemplate ( 'chapter' , '' , true , true ); // always merge
$tmpl = varset ( $tml [ $layout ]);
$template = $tmpl [ 'listBooks' ];
$text = $template [ 'start' ];
2014-06-13 19:00:51 -07:00
2013-05-29 23:00:55 -07:00
while ( $row = $sql -> fetch ())
2012-10-24 22:02:18 +00:00
{
2014-01-10 18:27:42 -08:00
$sef = $row ;
$sef [ 'book_sef' ] = $this -> getSef ( $row [ 'chapter_id' ]);
$sef [ 'page_sef' ] = $this -> getSef ( $row [ 'chapter_id' ]);
2014-06-13 19:00:51 -07:00
$listChapters = $this -> listChapters ( intval ( $row [ 'chapter_id' ]), $row [ 'chapter_sef' ]);
2013-05-30 14:16:49 -07:00
$var = array (
2019-02-26 12:22:36 -08:00
'BOOK_NAME' => $tp -> toHTML ( $row [ 'chapter_name' ]),
2013-05-30 14:16:49 -07:00
'BOOK_ANCHOR' => $frm -> name2id ( $row [ 'chapter_name' ]),
2013-07-12 09:07:56 -07:00
'BOOK_ICON' => $this -> chapterIcon ( $row [ 'chapter_icon' ]),
2019-02-26 12:22:36 -08:00
'BOOK_DESCRIPTION' => $tp -> toHTML ( $row [ 'chapter_meta_description' ], true , 'BODY' ),
2014-06-13 19:00:51 -07:00
'CHAPTERS' => $listChapters [ 'text' ],
2014-06-16 18:21:51 -07:00
'BOOK_URL' => e107 :: getUrl () -> create ( 'page/book/index' , $sef , 'allow=chapter_id,chapter_sef,book_sef,page_sef' )
2013-05-30 14:16:49 -07:00
);
$text .= $tp -> simpleParse ( $template [ 'item' ], $var );
2012-10-24 22:02:18 +00:00
}
}
2013-05-30 14:16:49 -07:00
if ( e107 :: getPref ( 'listPages' , false ))
{
2015-06-19 11:26:01 +03:00
$text .= " <h3> " . LAN_PAGE_14 . " </h3> " ; // Book Title.
2013-12-21 21:53:38 -08:00
$tmp = $this -> listPages ( 0 );
$text .= $tmp [ 'text' ]; // Pages unassigned to Book/Chapters.
2013-05-30 14:16:49 -07:00
} //
if ( $text )
{
2018-02-03 10:34:18 -08:00
$caption = isset ( $template [ 'caption' ]) ? $template [ 'caption' ] : LAN_PAGE_15 ;
2014-07-24 16:50:56 +03:00
$this -> pageOutput = array ( 'caption' => $caption , 'text' => $text );
//e107::getRender()->tablerender($caption, $text, "cpage_list");
2013-05-30 14:16:49 -07:00
}
else
{
2014-07-24 16:50:56 +03:00
$this -> pageOutput = array ( 'caption' => LAN_ERROR , 'text' => LAN_PAGE_1 );
//message_handler("MESSAGE", LAN_PAGE_1);
//require_once(FOOTERF); // prevent message from showing twice and still listing chapters
//exit;
2013-05-30 14:16:49 -07:00
}
2012-10-24 22:02:18 +00:00
}
2013-05-29 23:00:55 -07:00
/**
2016-02-09 19:13:25 -08:00
* Parse the Book / Chapter " listChapters' template
* @ param int $book
* @ return array
2013-05-29 23:00:55 -07:00
*/
2012-10-24 22:02:18 +00:00
function listChapters ( $book = 1 )
{
2013-02-01 18:00:53 -08:00
$sql = e107 :: getDb ( 'chap' );
2012-10-24 22:02:18 +00:00
$tp = e107 :: getParser ();
2013-05-30 14:16:49 -07:00
$frm = e107 :: getForm ();
2012-10-24 22:02:18 +00:00
2014-06-13 19:00:51 -07:00
// retrieve book information.
2019-09-17 14:45:38 +02:00
if ( ! $brow = $sql -> retrieve ( 'page_chapters' , 'chapter_name,chapter_template,chapter_meta_description,chapter_meta_keywords' , 'chapter_id = ' . intval ( $book ) . ' AND chapter_visibility IN (' . USERCLASS_LIST . ') LIMIT 1' ))
2013-05-29 23:00:55 -07:00
{
$layout = 'default' ;
}
2014-06-13 19:00:51 -07:00
else
{
$layout = $brow [ 'chapter_template' ];
}
2021-01-19 09:50:02 -08:00
2013-05-29 23:00:55 -07:00
2014-06-13 03:39:41 -07:00
if ( $this -> displayAllMode === true )
{
$layout = e107 :: getPref ( 'listBooksTemplate' );
}
2021-01-19 09:50:02 -08:00
if ( empty ( $layout ) && ADMIN )
{
e107 :: getMessage () -> addError ( " Admin Only Message: The chapter template is empty. Reverting to 'default'. " ); // NO LAN
$layout = 'default' ;
}
2013-05-29 23:00:55 -07:00
$tml = e107 :: getCoreTemplate ( 'chapter' , '' , true , true ); // always merge
2014-06-13 19:00:51 -07:00
$error = array ( 'listChapters' => array ( 'start' => " Chapter template not found: " . $layout ));
2014-06-13 03:39:41 -07:00
$tmpl = varset ( $tml [ $layout ], $error );
2013-05-29 19:37:06 -07:00
2013-05-29 23:00:55 -07:00
$template = $tmpl [ 'listChapters' ];
2014-06-13 19:00:51 -07:00
$bvar = array (
2019-02-26 12:22:36 -08:00
'BOOK_NAME' => $tp -> toHTML ( $brow [ 'chapter_name' ]),
2014-06-13 19:00:51 -07:00
'BOOK_ANCHOR' => $frm -> name2id ( $brow [ 'chapter_name' ]),
'BOOK_ICON' => $this -> chapterIcon ( $brow [ 'chapter_icon' ]),
2019-02-26 12:22:36 -08:00
'BOOK_DESCRIPTION' => $tp -> toHTML ( $brow [ 'chapter_meta_description' ], true , 'BODY' ),
2014-06-13 19:00:51 -07:00
);
$caption = $tp -> simpleParse ( $template [ 'caption' ], $bvar );
2014-07-09 16:42:24 +03:00
if ( $brow )
{
define ( 'e_PAGETITLE' , eHelper :: formatMetaTitle ( $brow [ 'chapter_name' ]));
if ( $brow [ 'chapter_meta_description' ]) define ( 'META_DESCRIPTION' , eHelper :: formatMetaDescription ( $brow [ 'chapter_meta_description' ]));
if ( $brow [ 'chapter_meta_keywords' ]) define ( 'META_KEYWORDS' , eHelper :: formatMetaKeys ( $brow [ 'chapter_meta_keywords' ]));
}
2014-06-13 19:00:51 -07:00
2014-02-08 16:57:34 -08:00
if ( $sql -> select ( " page_chapters " , " * " , " chapter_parent = " . intval ( $book ) . " AND chapter_visibility IN ( " . USERCLASS_LIST . " ) ORDER BY chapter_order ASC " ))
2012-10-24 22:02:18 +00:00
{
2016-02-09 19:13:25 -08:00
$text = $tp -> simpleParse ( $template [ 'start' ], $bvar );
2013-05-29 23:00:55 -07:00
while ( $row = $sql -> fetch ())
2012-10-24 22:02:18 +00:00
{
2014-01-15 02:56:39 -08:00
$tmp = $this -> listPages ( intval ( $row [ 'chapter_id' ]));
2014-01-10 18:27:42 -08:00
2014-01-15 07:02:10 -08:00
$row [ 'book_sef' ] = $this -> getSef ( $row [ 'chapter_parent' ]);
$row [ 'book_name' ] = $this -> getName ( $row [ 'chapter_parent' ]);
$row [ 'book_icon' ] = $this -> getIcon ( $row [ 'chapter_parent' ]);
$row [ 'book_description' ] = $this -> getDescription ( $row [ 'chapter_parent' ]);
2013-05-29 19:37:06 -07:00
$var = array (
2019-02-26 12:22:36 -08:00
'BOOK_NAME' => $tp -> toHTML ( $row [ 'book_name' ]),
2014-01-15 07:02:10 -08:00
'BOOK_ANCHOR' => $frm -> name2id ( $row [ 'book_name' ]),
'BOOK_ICON' => $this -> chapterIcon ( $row [ 'book_icon' ]),
2019-02-26 12:22:36 -08:00
'BOOK_DESCRIPTION' => $tp -> toHTML ( $row [ 'book_description' ], true , 'BODY' ),
2014-01-15 07:02:10 -08:00
2019-02-26 12:22:36 -08:00
'CHAPTER_NAME' => $tp -> toHTML ( $row [ 'chapter_name' ]),
2013-05-30 14:16:49 -07:00
'CHAPTER_ANCHOR' => $frm -> name2id ( $row [ 'chapter_name' ]),
2013-07-12 09:07:56 -07:00
'CHAPTER_ICON' => $this -> chapterIcon ( $row [ 'chapter_icon' ]),
2019-04-03 11:48:05 -07:00
'CHAPTER_IMAGE' => $tp -> toImage ( $row [ 'chapter_image' ]),
2019-02-26 12:22:36 -08:00
'CHAPTER_DESCRIPTION' => $tp -> toHTML ( $row [ 'chapter_meta_description' ], true , 'BODY' ),
2014-01-15 07:02:10 -08:00
'PAGES' => $tmp [ 'text' ],
2014-06-16 18:21:51 -07:00
'CHAPTER_URL' => e107 :: getUrl () -> create ( 'page/chapter/index' , $row , 'allow=chapter_id,chapter_sef,book_sef' )
2013-05-29 19:37:06 -07:00
);
$text .= $tp -> simpleParse ( $template [ 'item' ], $var );
2013-05-29 23:00:55 -07:00
2013-05-29 19:37:06 -07:00
}
2013-05-29 23:00:55 -07:00
2016-02-01 23:13:45 +02:00
$text .= $tp -> simpleParse ( $template [ 'end' ], $bvar );
2013-05-29 23:00:55 -07:00
}
else
{
2015-06-19 11:26:01 +03:00
$text = e107 :: getMessage () -> addInfo ( LAN_PAGE_16 ) -> render ();
2012-10-24 22:02:18 +00:00
}
2014-06-13 19:00:51 -07:00
2014-07-09 16:42:24 +03:00
#return array('caption'=>$caption, 'text'=>$text);
$this -> pageOutput = array ( 'caption' => $caption , 'text' => $text );
2014-07-24 16:50:56 +03:00
return $this -> pageOutput ;
2012-10-24 22:02:18 +00:00
}
2013-07-12 09:07:56 -07:00
/**
2016-02-09 19:13:25 -08:00
* Handle Chapter Icon Glyphs .
* @ param $icon
* @ return null | string
2013-07-12 09:07:56 -07:00
*/
private function chapterIcon ( $icon )
{
$tp = e107 :: getParser ();
if ( ! vartrue ( $icon ))
{
2016-02-09 19:13:25 -08:00
return null ;
2013-07-12 09:07:56 -07:00
}
2013-07-12 13:52:39 -07:00
if ( $glyph = $tp -> toGlyph ( $icon ))
2013-07-12 09:07:56 -07:00
{
return $glyph ;
}
else
{
2013-07-12 13:52:39 -07:00
return $tp -> toIcon ( $icon );
2013-07-12 09:07:56 -07:00
}
}
2013-05-29 23:00:55 -07:00
2013-05-29 19:37:06 -07:00
function listPages ( $chapt = 0 )
2006-12-02 04:36:16 +00:00
{
2013-05-29 01:22:11 -07:00
$sql = e107 :: getDb ( 'pg' );
$tp = e107 :: getParser ();
$this -> batch = e107 :: getScBatch ( 'page' , null , 'cpage' );
2013-12-19 22:46:24 -08:00
$frm = e107 :: getForm ();
2013-05-29 23:00:55 -07:00
// retrieve the template to use for this chapter.
2019-09-17 14:45:38 +02:00
$row = $sql -> retrieve ( 'page_chapters' , 'chapter_id,chapter_icon,chapter_name,chapter_parent, chapter_image, chapter_meta_description,chapter_meta_keywords,chapter_template' , 'chapter_id = ' . intval ( $chapt ) . ' LIMIT 1' );
2014-06-13 03:39:41 -07:00
if ( $this -> displayAllMode === true )
{
$layout = e107 :: getPref ( 'listBooksTemplate' );
}
else
{
$layout = vartrue ( $row [ 'chapter_template' ], 'default' );
}
2014-07-09 16:42:24 +03:00
if ( $row )
{
define ( 'e_PAGETITLE' , eHelper :: formatMetaTitle ( $row [ 'chapter_name' ]));
if ( $row [ 'chapter_meta_description' ]) define ( 'META_DESCRIPTION' , eHelper :: formatMetaDescription ( $row [ 'chapter_meta_description' ]));
if ( $row [ 'chapter_meta_keywords' ]) define ( 'META_KEYWORDS' , eHelper :: formatMetaKeys ( $row [ 'chapter_meta_keywords' ]));
}
2013-05-29 23:00:55 -07:00
2016-02-09 19:13:25 -08:00
//$bookId = $row['chapter_parent'];
2014-01-10 18:27:42 -08:00
$bookSef = $this -> getSef ( $row [ 'chapter_parent' ]);
2014-06-13 19:00:51 -07:00
$bookTitle = $this -> getName ( $row [ 'chapter_parent' ]);
2016-02-29 22:01:58 -08:00
2014-06-13 19:00:51 -07:00
$urlData = array (
'chapter_id' => $row [ 'chapter_id' ],
2019-02-26 12:22:36 -08:00
'chapter_name' => $tp -> toHTML ( $row [ 'chapter_name' ]),
2014-06-13 19:00:51 -07:00
'chapter_sef' => $bookSef ,
'book_sef' => $bookSef ,
2017-10-03 12:51:20 -07:00
'page_sef' => '' ,
'book_id' => $row [ 'chapter_parent' ]
2014-06-13 19:00:51 -07:00
);
2021-01-19 09:50:02 -08:00
2014-06-13 19:00:51 -07:00
//print_a($this->chapterData);
2014-01-10 18:27:42 -08:00
2013-05-29 23:00:55 -07:00
$tml = e107 :: getCoreTemplate ( 'chapter' , '' , true , true ); // always merge
$tmpl = varset ( $tml [ $layout ]);
2014-06-13 19:00:51 -07:00
$bread = array (
2019-02-26 12:22:36 -08:00
0 => array ( 'text' => $tp -> toHTML ( $bookTitle ), 'url' => e107 :: getUrl () -> create ( 'page/book/index' , $urlData , 'allow=chapter_id,chapter_sef,book_id,book_sef,page_sef' ))
2014-06-13 19:00:51 -07:00
);
2013-05-29 23:00:55 -07:00
2013-12-19 22:46:24 -08:00
$var = array (
2019-02-26 12:22:36 -08:00
'CHAPTER_NAME' => $tp -> toHTML ( $row [ 'chapter_name' ]),
2013-12-19 22:46:24 -08:00
'CHAPTER_ANCHOR' => $frm -> name2id ( $row [ 'chapter_name' ]),
'CHAPTER_ICON' => $this -> chapterIcon ( $row [ 'chapter_icon' ]),
2019-04-03 11:48:05 -07:00
'CHAPTER_IMAGE' => $tp -> toImage ( $row [ 'chapter_image' ]),
2019-02-26 12:22:36 -08:00
'CHAPTER_DESCRIPTION' => $tp -> toHTML ( $row [ 'chapter_meta_description' ], true , 'BODY' ),
2015-01-10 16:13:32 -08:00
'CHAPTER_BREADCRUMB' => ! empty ( $_GET [ 'ch' ]) ? $frm -> breadcrumb ( $bread ) : ''
2013-12-19 22:46:24 -08:00
);
2013-05-29 23:00:55 -07:00
// $tmpl = e107::getCoreTemplate('chapter','docs', true, true); // always merge
2014-06-16 18:21:51 -07:00
$template = $tmpl [ 'listPages' ];
2013-05-29 23:00:55 -07:00
2014-06-28 00:08:35 -07:00
$pageOnly = ( $layout == 'panel' ) ? " menu_class IN ( " . USERCLASS_LIST . " ) " : " page_title !='' AND page_class IN ( " . USERCLASS_LIST . " ) " ; // When in 'panel' mode, allow Menus to be rendered while checking menu_class.
2014-06-16 18:21:51 -07:00
2014-06-28 00:13:38 -07:00
if ( ! $count = $sql -> select ( " page " , " * " , $pageOnly . " AND page_chapter= " . intval ( $chapt ) . " ORDER BY page_order ASC " ))
2006-12-02 04:36:16 +00:00
{
2014-01-15 02:56:39 -08:00
return array ( 'text' => " <em> " . ( LAN_PAGE_2 ) . " </em> " );
2013-05-29 23:00:55 -07:00
// $text = "<ul class='page-pages-list page-pages-none'><li>".LAN_PAGE_2."</li></ul>";
2006-12-02 04:36:16 +00:00
}
else
{
2013-05-29 01:22:11 -07:00
2011-12-07 21:07:21 +00:00
$pageArray = $sql -> db_getList ();
2013-05-29 19:37:06 -07:00
2013-12-19 22:46:24 -08:00
$header = $tp -> simpleParse ( $template [ 'start' ], $var );
2016-02-09 19:13:25 -08:00
$text = $tp -> parseTemplate ( $header , true ); // for parsing {SETIMAGE} etc.
2013-05-29 01:22:11 -07:00
2006-12-02 04:36:16 +00:00
foreach ( $pageArray as $page )
{
2016-02-09 19:13:25 -08:00
/* $data = array (
2013-05-29 01:22:11 -07:00
'title' => $page [ 'page_title' ],
2019-02-26 12:22:36 -08:00
'text' => $tp -> toHTML ( $page [ 'page_text' ], true )
2016-02-09 19:13:25 -08:00
); */
2016-02-29 22:01:58 -08:00
$page [ 'chapter_id' ] = $page [ 'page_chapter' ];
$page [ 'chapter_name' ] = $this -> getName ( $page [ 'page_chapter' ]);
2016-02-29 20:22:14 -08:00
$page [ 'chapter_parent' ] = $this -> getParent ( $page [ 'page_chapter' ]);
2014-01-10 18:27:42 -08:00
$page [ 'chapter_sef' ] = $this -> getSef ( $page [ 'page_chapter' ]); // $chapter_sef;
2016-02-29 22:01:58 -08:00
$page [ 'book_id' ] = $page [ 'chapter_parent' ];
$page [ 'book_name' ] = $this -> getName ( $page [ 'chapter_parent' ]);
2016-02-29 20:22:14 -08:00
$page [ 'book_sef' ] = $bookSef ;
2014-01-10 18:27:42 -08:00
2014-06-13 03:39:41 -07:00
// $this->page = $page;
$this -> batch -> setVars ( $page );
2019-06-15 10:12:00 -07:00
$this -> batch -> breadcrumb ();
2014-06-13 03:39:41 -07:00
// $this->batch->setVars(new e_vars($data))->setScVar('page', $this->page);
2016-02-29 20:22:14 -08:00
2014-06-13 03:39:41 -07:00
2013-05-29 01:22:11 -07:00
2014-01-10 18:27:42 -08:00
// $url = e107::getUrl()->create('page/view', $page, 'allow=page_id,page_sef,chapter_sef,book_sef');
2019-02-26 12:22:36 -08:00
// $text .= "<li><a href='".$url."'>".$tp->toHTML($page['page_title'])."</a></li>";
2013-05-29 01:22:11 -07:00
$text .= e107 :: getParser () -> parseTemplate ( $template [ 'item' ], true , $this -> batch );
2006-12-02 04:36:16 +00:00
}
2013-05-29 01:22:11 -07:00
2014-06-13 03:39:41 -07:00
$text .= $tp -> simpleParse ( $template [ 'end' ], $var );
2013-05-29 01:22:11 -07:00
2013-05-29 19:37:06 -07:00
2012-10-24 22:02:18 +00:00
// $caption = ($title !='')? $title: LAN_PAGE_11;
// e107::getRender()->tablerender($caption, $text,"cpage_list");
2006-12-02 04:36:16 +00:00
}
2013-05-30 14:16:49 -07:00
2014-06-13 04:41:45 -07:00
2014-06-13 03:39:41 -07:00
$caption = $tp -> simpleParse ( $template [ 'caption' ], $var );
2014-07-09 16:42:24 +03:00
#return array('caption'=>$caption, 'text'=> $text);
$this -> pageOutput = array ( 'caption' => $caption , 'text' => $text );
2014-07-24 16:50:56 +03:00
return $this -> pageOutput ;
2006-12-02 04:36:16 +00:00
}
2011-12-07 21:07:21 +00:00
function processViewPage ()
2006-12-02 04:36:16 +00:00
{
2014-06-16 18:21:51 -07:00
2011-12-07 21:07:21 +00:00
if ( $this -> checkCache ())
{
return ;
}
$sql = e107 :: getDb ();
2013-06-01 14:03:18 -07:00
2011-12-07 21:07:21 +00:00
$query = " SELECT p.*, u.user_id, u.user_name, user_login FROM #page AS p
2006-12-02 04:36:16 +00:00
LEFT JOIN #user AS u ON p.page_author = u.user_id
2011-12-07 21:07:21 +00:00
WHERE p . page_id = " .intval( $this->pageID ); // REMOVED AND p.page_class IN ( " . USERCLASS_LIST . " ) - permission check is done later
2006-12-02 04:36:16 +00:00
2016-02-09 19:13:25 -08:00
2014-06-16 18:21:51 -07:00
2013-06-01 14:03:18 -07:00
if ( ! $sql -> gen ( $query ))
2006-12-02 04:36:16 +00:00
{
2015-02-05 20:25:28 -08:00
header ( " HTTP/1.0 404 Not Found " );
// exit;
2014-06-13 03:39:41 -07:00
/*
2006-12-02 04:36:16 +00:00
$ret [ 'title' ] = LAN_PAGE_12 ; // ***** CHANGED
2011-12-07 21:07:21 +00:00
$ret [ 'sub_title' ] = '' ;
2006-12-02 04:36:16 +00:00
$ret [ 'text' ] = LAN_PAGE_3 ;
2011-12-07 21:07:21 +00:00
$ret [ 'comments' ] = '' ;
$ret [ 'rating' ] = '' ;
$ret [ 'np' ] = '' ;
2006-12-02 04:36:16 +00:00
$ret [ 'err' ] = TRUE ;
2011-12-07 21:07:21 +00:00
$ret [ 'cachecontrol' ] = false ;
2014-06-13 03:39:41 -07:00
*/
// ---------- New (to replace values above) ----
$this -> page [ 'page_title' ] = LAN_PAGE_12 ; // ***** CHANGED
$this -> page [ 'sub_title' ] = '' ;
$this -> page [ 'page_text' ] = LAN_PAGE_3 ;
$this -> page [ 'comments' ] = '' ;
$this -> page [ 'rating' ] = '' ;
$this -> page [ 'np' ] = '' ;
$this -> page [ 'err' ] = TRUE ;
$this -> page [ 'cachecontrol' ] = false ;
2016-02-29 20:22:14 -08:00
2014-06-13 03:39:41 -07:00
// -------------------------------------
2011-12-07 21:07:21 +00:00
$this -> authorized = 'nf' ;
$this -> template = e107 :: getCoreTemplate ( 'page' , 'default' );
2014-06-16 18:21:51 -07:00
// $this->batch = e107::getScBatch('page',null,'cpage')->setVars(new e_vars($ret))->setScVar('page', array()); ///Upgraded to setVars() array. (not using '$this->page')
2016-05-28 19:03:08 -07:00
2016-04-02 10:51:18 -07:00
$this -> batch = e107 :: getScBatch ( 'page' , null , 'cpage' ) -> setVars ( $this -> page ) -> wrapper ( 'page/' . $this -> templateID );
2019-06-15 10:12:00 -07:00
$this -> batch -> breadcrumb ();
2014-06-13 03:39:41 -07:00
2011-12-07 21:07:21 +00:00
2014-06-13 03:39:41 -07:00
define ( " e_PAGETITLE " , $this -> page [ 'page_title' ]);
2013-06-01 14:03:18 -07:00
2011-12-07 21:07:21 +00:00
return ;
2006-12-02 04:36:16 +00:00
}
2013-06-01 14:03:18 -07:00
$this -> page = $sql -> fetch ();
2006-12-02 04:36:16 +00:00
2016-12-22 10:00:37 -08:00
2016-04-02 10:51:18 -07:00
// setting override to true breaks default.
$this -> templateID = vartrue ( $this -> page [ 'page_template' ], 'default' );
$this -> template = e107 :: getCoreTemplate ( 'page' , $this -> templateID , true , true );
2014-06-13 03:39:41 -07:00
2013-10-16 18:46:41 +03:00
if ( ! $this -> template )
{
// switch to default
$this -> template = e107 :: getCoreTemplate ( 'page' , 'default' , false , false );
2016-04-02 10:51:18 -07:00
$this -> templateID = 'default' ;
2013-10-16 18:46:41 +03:00
}
2013-06-01 14:03:18 -07:00
if ( empty ( $this -> template ))
{
$this -> template = e107 :: getCoreTemplate ( 'page' , 'default' );
2016-04-02 10:51:18 -07:00
$this -> templateID = 'default' ;
2013-06-01 14:03:18 -07:00
}
2016-05-28 19:03:08 -07:00
$editable = array (
'table' => 'page' ,
'pid' => 'page_id' ,
'perms' => '5' ,
'shortcodes' => array (
'cpagetitle' => array ( 'field' => 'page_subtitle' , 'type' => 'text' , 'container' => 'span' ),
'cpagebody' => array ( 'field' => 'page_text' , 'type' => 'html' , 'container' => 'div' ),
)
);
2013-02-01 18:00:53 -08:00
$this -> batch = e107 :: getScBatch ( 'page' , null , 'cpage' );
2016-04-02 10:51:18 -07:00
$this -> batch -> wrapper ( 'page/' . $this -> templateID );
2016-05-28 19:03:08 -07:00
$this -> batch -> editable ( $editable );
2019-06-15 10:12:00 -07:00
$this -> batch -> breadcrumb ();
2011-12-07 21:07:21 +00:00
$this -> pageText = $this -> page [ 'page_text' ];
2006-12-02 04:36:16 +00:00
2011-12-07 21:07:21 +00:00
$this -> pageCheckPerms ( $this -> page [ 'page_class' ], $this -> page [ 'page_password' ], $this -> page [ 'page_title' ]);
2006-12-02 04:36:16 +00:00
2011-12-07 21:07:21 +00:00
if ( $this -> debug )
2006-12-02 04:36:16 +00:00
{
2011-12-07 21:07:21 +00:00
echo " <b>pageText</b> " . $this -> pageText . " <br /> " ;
2006-12-02 04:36:16 +00:00
}
2011-12-07 21:07:21 +00:00
$this -> parsePage ();
2006-12-02 04:36:16 +00:00
2011-12-07 21:07:21 +00:00
$pagenav = $rating = $comments = '' ;
if ( $this -> authorized === true )
{
$pagenav = $this -> pageIndex ();
$rating = $this -> pageRating ( $this -> page [ 'page_rating_flag' ]);
$comments = $this -> pageComment ( $this -> page [ 'page_comment_flag' ]);
}
2014-06-13 03:39:41 -07:00
/*
2011-12-07 21:07:21 +00:00
$ret [ 'title' ] = $this -> page [ 'page_title' ];
$ret [ 'sub_title' ] = $this -> title ;
$ret [ 'text' ] = $this -> pageToRender ;
$ret [ 'np' ] = $pagenav ;
$ret [ 'rating' ] = $rating ;
$ret [ 'comments' ] = $comments ;
$ret [ 'err' ] = FALSE ;
$ret [ 'cachecontrol' ] = ( isset ( $this -> page [ 'page_password' ]) && ! $this -> page [ 'page_password' ] && $this -> authorized === true ); // Don't cache password protected pages
2014-06-13 03:39:41 -07:00
*/
// $this->batch->setVars(new e_vars($ret))->setScVar('page', $this->page); // Removed in favour of $this->var (cross-compatible with menus and other parts of e107 that use the same shortcodes)
// ---- New --- -
2016-02-29 20:22:14 -08:00
$this -> page [ 'page_text' ] = $this -> pageToRender ;
$this -> page [ 'np' ] = $pagenav ;
$this -> page [ 'rating' ] = $rating ;
$this -> page [ 'comments' ] = $comments ;
$this -> page [ 'err' ] = false ;
$this -> page [ 'cachecontrol' ] = ( isset ( $this -> page [ 'page_password' ]) && ! $this -> page [ 'page_password' ] && $this -> authorized === true );
$this -> page [ 'chapter_id' ] = $this -> page [ 'page_chapter' ];
$this -> page [ 'chapter_name' ] = $this -> getName ( $this -> page [ 'page_chapter' ]);
$this -> page [ 'chapter_sef' ] = $this -> getSef ( $this -> page [ 'page_chapter' ]);
$this -> page [ 'chapter_parent' ] = $this -> getParent ( $this -> page [ 'page_chapter' ]);
$this -> page [ 'book_id' ] = $this -> page [ 'chapter_parent' ];
$this -> page [ 'book_parent' ] = $this -> getParent ( $this -> page [ 'chapter_parent' ]);
$this -> page [ 'book_sef' ] = $this -> getSef ( $this -> page [ 'chapter_parent' ]);
$this -> page [ 'book_name' ] = $this -> getName ( $this -> page [ 'chapter_parent' ]);
2014-06-13 03:39:41 -07:00
// -----------------
2016-02-29 20:22:14 -08:00
2016-12-22 10:00:37 -08:00
e107 :: getEvent () -> trigger ( 'user_page_item_viewed' , $this -> page );
2016-02-29 20:22:14 -08:00
2014-06-13 03:39:41 -07:00
$this -> batch -> setVars ( $this -> page );
2019-06-15 10:12:00 -07:00
$this -> batch -> breadcrumb ();
2016-12-22 10:00:37 -08:00
2021-01-19 09:50:02 -08:00
e107 :: title ( eHelper :: formatMetaTitle ( $this -> page [ 'page_title' ]));
2013-04-02 09:29:11 +03:00
if ( $this -> page [ 'page_metadscr' ]) define ( 'META_DESCRIPTION' , eHelper :: formatMetaDescription ( $this -> page [ 'page_metadscr' ]));
2019-07-05 15:12:39 -07:00
if ( ! empty ( $this -> page [ 'page_metakeys' ]))
{
e107 :: meta ( 'keywords' , eHelper :: formatMetaKeys ( $this -> page [ 'page_metakeys' ]));
}
2015-11-22 13:04:21 -08:00
2019-12-02 13:32:21 -08:00
if ( ! empty ( $this -> page [ 'page_metarobots' ]))
{
e107 :: meta ( 'robots' , $this -> page [ 'page_metarobots' ]);
}
2015-11-22 13:04:21 -08:00
$tp = e107 :: getParser ();
if ( $tp -> isImage ( $this -> page [ 'menu_image' ]))
{
$mimg = $tp -> thumbUrl ( $this -> page [ 'menu_image' ], 'w=800' , false , true );
e107 :: meta ( 'og:image' , $mimg );
}
2016-01-27 12:05:15 -08:00
$images = e107 :: getBB () -> getContent ( 'img' , $this -> pageText );
foreach ( $images as $im )
{
$im = $tp -> ampEncode ( $im );
e107 :: meta ( 'og:image' ,( $im ));
}
2015-11-22 13:04:21 -08:00
//return $ret;
2011-12-07 21:07:21 +00:00
}
2009-05-03 22:16:20 +00:00
2011-12-07 21:07:21 +00:00
public function checkCache ()
{
$e107cache = e107 :: getCache ();
$cacheData = $e107cache -> retrieve ( $this -> cacheString );
if ( false !== $cacheData )
2006-12-02 04:36:16 +00:00
{
2011-12-07 21:07:21 +00:00
$this -> cacheData = array ();
$this -> cacheData [ 'PAGE' ] = $cacheData ;
2011-12-09 02:08:04 +00:00
list ( $pagetitle , $comment_flag , $meta_keys , $meta_dscr ) = explode ( " ^^^ " , $e107cache -> retrieve ( $this -> cacheTitleString ), 4 );
2011-12-07 21:07:21 +00:00
$this -> cacheData [ 'TITLE' ] = $pagetitle ;
$this -> cacheData [ 'COMMENT_FLAG' ] = $comment_flag ;
2011-12-09 02:08:04 +00:00
$this -> cacheData [ 'META_KEYS' ] = $meta_keys ;
$this -> cacheData [ 'META_DSCR' ] = $meta_dscr ;
2014-07-10 13:15:19 +03:00
return true ;
2006-12-02 04:36:16 +00:00
}
2014-07-10 13:15:19 +03:00
return false ;
2011-12-07 21:07:21 +00:00
}
public function setCache ( $data , $title , $comment_flag )
{
$e107cache = e107 :: getCache ();
$e107cache -> set ( $this -> cacheString , $data );
2011-12-09 02:08:04 +00:00
$e107cache -> set ( $this -> cacheTitleString , $title . " ^^^ " . $this -> page [ 'page_comment_flag' ] . " ^^^ " . $this -> page [ 'page_metakeys' ] . " ^^^ " . $this -> page [ 'page_metadscr' ]);
2011-12-07 21:07:21 +00:00
}
2006-12-02 04:36:16 +00:00
2011-12-07 21:07:21 +00:00
public function renderCache ()
{
$comments = '' ;
if ( $this -> cacheData [ 'COMMENT_FLAG' ])
{
$vars = new e_vars ( array ( 'comments' => $this -> pageComment ( true )));
2019-04-06 12:11:05 -07:00
/** @var cpage_shortcodes $sc */
$sc = e107 :: getScBatch ( 'page' , null , 'cpage' );
$sc -> setVars ( $vars );
2019-06-15 10:12:00 -07:00
$sc -> breadcrumb ();
2019-04-06 12:11:05 -07:00
$comments = $sc -> cpagecomments ();
2011-12-07 21:07:21 +00:00
}
2011-12-09 02:08:04 +00:00
define ( 'e_PAGETITLE' , eHelper :: formatMetaTitle ( $this -> cacheData [ 'TITLE' ]));
define ( 'META_DESCRIPTION' , $this -> cacheData [ 'META_DSCR' ]);
define ( 'META_KEYWORDS' , $this -> cacheData [ 'META_KEYS' ]);
2011-12-07 21:07:21 +00:00
if ( $this -> debug )
2006-12-02 04:36:16 +00:00
{
2011-12-07 21:07:21 +00:00
echo " <b>Reading page from cache</b><br /> " ;
2006-12-02 04:36:16 +00:00
}
2011-12-07 21:07:21 +00:00
return str_replace ( '[[PAGECOMMENTS]]' , $comments , $this -> cacheData [ 'PAGE' ]);
}
2006-12-02 04:36:16 +00:00
2014-07-10 13:36:58 +03:00
public function setPage ()
2011-12-07 21:07:21 +00:00
{
if ( null !== $this -> cacheData )
{
return $this -> renderCache ();
}
if ( true === $this -> authorized )
{
2013-06-01 14:03:18 -07:00
2011-12-07 21:07:21 +00:00
$vars = $this -> batch -> getParserVars ();
$template = str_replace ( '{PAGECOMMENTS}' , '[[PAGECOMMENTS]]' , $this -> template [ 'start' ] . $this -> template [ 'body' ] . $this -> template [ 'end' ]);
2016-02-09 19:13:25 -08:00
$arr = $this -> renderPage ( $template );
2013-06-01 14:03:18 -07:00
2011-12-07 21:07:21 +00:00
if ( ! empty ( $this -> template [ 'page' ]))
{
2016-02-09 19:13:25 -08:00
$ret = str_replace ( array ( '{PAGE}' , '{PAGECOMMENTS}' ), array ( $arr [ 'text' ], '[[PAGECOMMENTS]]' ), $this -> template [ 'page' ]);
2011-12-07 21:07:21 +00:00
}
2016-02-09 19:13:25 -08:00
else
{
$ret = $arr [ 'text' ];
}
2011-12-07 21:07:21 +00:00
$ret = e107 :: getParser () -> parseTemplate ( $ret , true , $this -> batch );
2006-12-02 04:36:16 +00:00
2016-02-12 19:28:35 -08:00
if ( is_object ( $vars ) && $vars -> cachecontrol ) $this -> setCache ( $ret , $this -> batch -> sc_cpagetitle (), $this -> page [ 'page_comment_flag' ]);
2011-12-07 21:07:21 +00:00
2014-07-10 13:36:58 +03:00
//return str_replace('[[PAGECOMMENTS]]', $this->batch->cpagecomments(), $ret);
2017-11-01 19:24:01 -07:00
$this -> pageOutput = array ( 'text' => str_replace ( '[[PAGECOMMENTS]]' , $this -> batch -> cpagecomments (), $ret ), 'caption' => $arr [ 'caption' ], 'mode' => $arr [ 'mode' ], 'title' => $this -> page [ 'page_metadscr' ]);
2016-02-09 19:13:25 -08:00
return null ;
2011-12-07 21:07:21 +00:00
}
$extend = new e_vars ;
2014-07-24 16:50:56 +03:00
$vars = new e_vars ( $this -> batch -> getParserVars ());
2011-12-07 21:07:21 +00:00
// reset batch data
2014-06-13 03:39:41 -07:00
// $this->batch->setVars(null)->setScVar('page', array());
2011-12-07 21:07:21 +00:00
// copy some data
2014-07-24 16:50:56 +03:00
$extend -> title = $vars -> page_title ;
2011-12-07 21:07:21 +00:00
$extend -> message = e107 :: getMessage () -> render ();
2014-07-24 16:50:56 +03:00
$tp = e107 :: getParser ();
2016-05-28 19:03:08 -07:00
2011-12-07 21:07:21 +00:00
switch ( $this -> authorized )
{
case 'class' :
$extend -> text = LAN_PAGE_6 ;
2014-07-24 16:50:56 +03:00
$template = $tp -> parseTemplate ( $this -> template [ 'start' ], true ) . $this -> template [ 'restricted' ] . $tp -> parseTemplate ( $this -> template [ 'end' ] , true );
$this -> renderMode = 'cpage-restricted' ;
2011-12-07 21:07:21 +00:00
break ;
case 'pw' :
$frm = e107 :: getForm ();
$extend -> caption = LAN_PAGE_8 ;
2015-07-02 14:33:04 +01:00
$extend -> label = LAN_PASSWORD ;
2015-02-07 01:45:36 -08:00
$extend -> password = $frm -> password ( 'page_pw' , '' , 50 , 'size=xlarge&required=1' );
2011-12-07 21:07:21 +00:00
$extend -> icon = e_IMAGE_ABS . 'generic/password.png' ;
2017-02-10 22:34:17 +00:00
$extend -> submit = $frm -> submit ( 'submit_page_pw' , LAN_SUBMIT );
2011-12-07 21:07:21 +00:00
// FIXME - add form open/close e_form methods
2015-02-07 01:45:36 -08:00
$extend -> form_open = '<form method="post" class="form-inline" action="' . e_REQUEST_URI . '" id="pwform">' ;
2011-12-07 21:07:21 +00:00
$extend -> form_close = '</form>' ;
2014-07-24 16:50:56 +03:00
$template = $tp -> parseTemplate ( $this -> template [ 'start' ], true ) . $this -> template [ 'authorize' ] . $tp -> parseTemplate ( $this -> template [ 'end' ] , true );
$this -> renderMode = 'cpage-authorize' ;
2011-12-07 21:07:21 +00:00
break ;
case 'nf' :
default :
2014-07-24 16:50:56 +03:00
$extend -> text = $vars -> page_text ;
$template = $tp -> parseTemplate ( $this -> template [ 'start' ], true ) . $this -> template [ 'notfound' ] . $tp -> parseTemplate ( $this -> template [ 'end' ] , true );
$this -> renderMode = 'cpage-notfound' ;
2011-12-07 21:07:21 +00:00
break ;
}
2014-07-24 16:50:56 +03:00
2014-07-10 13:36:58 +03:00
// return $this->renderPage($template, $extend);
2016-02-09 19:13:25 -08:00
$tmp = $this -> renderPage ( $template , $extend );
2017-11-01 19:24:01 -07:00
$this -> pageOutput = array ( 'text' => $tmp [ 'text' ], 'caption' => $tmp [ 'caption' ], 'mode' => $tmp [ 'mode' ], 'title' => $tmp [ 'title' ]);
2011-12-07 21:07:21 +00:00
}
public function renderPage ( $template , $vars = null )
{
2016-04-02 10:51:18 -07:00
2011-12-07 21:07:21 +00:00
if ( null === $vars )
{
$ret = e107 :: getParser () -> parseTemplate ( $template , true , $this -> batch );
}
else
{
$ret = e107 :: getParser () -> simpleParse ( $template , $vars );
}
2014-07-24 16:50:56 +03:00
if ( $this -> renderMode )
{
$mode = $this -> renderMode ;
}
else
{
$mode = vartrue ( $this -> template [ 'tableRender' ], 'cpage-page-view' );
}
2017-11-01 19:24:01 -07:00
// var_dump($this->batch->page_metadescr);
return array ( 'caption' => $this -> page [ 'page_title' ], 'text' => $ret , 'mode' => $mode , 'title' => $this -> page [ 'page_metadscr' ]);
2016-02-09 19:13:25 -08:00
// return e107::getRender()->tablerender($this->page['page_title'], $ret, $mode, true); //table style not parsed in hearder yet.
2014-06-13 03:39:41 -07:00
2006-12-02 04:36:16 +00:00
}
2014-06-13 03:39:41 -07:00
2014-06-16 18:21:51 -07:00
public function parsePage ()
2006-12-02 04:36:16 +00:00
{
2011-12-07 21:07:21 +00:00
$tp = e107 :: getParser ();
2012-07-09 01:54:43 +00:00
e107 :: getBB () -> setClass ( " page " );
2011-12-07 21:07:21 +00:00
$this -> pageTitles = array (); // Notice removal
2007-01-01 10:27:49 +00:00
2014-07-24 16:50:56 +03:00
if ( preg_match_all ( '/\[newpage.*?\]/si' , $this -> pageText , $pt ))
2006-12-02 04:36:16 +00:00
{
2010-09-16 13:05:11 +00:00
if ( substr ( $this -> pageText , 0 , 6 ) == '[html]' )
{ // Need to strip html bbcode from wysiwyg on multi-page docs (handled automatically on single pages)
if ( substr ( $this -> pageText , - 7 , 7 ) == '[/html]' )
{
$this -> pageText = substr ( $this -> pageText , 6 , - 7 );
}
else
{
$this -> pageText = substr ( $this -> pageText , 6 );
}
}
2011-12-07 21:07:21 +00:00
$pages = preg_split ( " / \ [newpage.*? \ ]/si " , $this -> pageText , - 1 , PREG_SPLIT_NO_EMPTY );
$this -> multipageFlag = TRUE ;
2006-12-02 04:36:16 +00:00
}
else
{
2014-07-09 17:55:57 +03:00
// $this->pageToRender = $tp->toHTML($this->pageText, TRUE, 'BODY');
// Remove double parsing - it breaks HTML (inserts <br> as [html] is already removed)
$this -> pageToRender = $this -> pageText ;
2006-12-02 04:36:16 +00:00
return ;
}
2009-05-03 22:16:20 +00:00
2006-12-02 04:36:16 +00:00
foreach ( $pt [ 0 ] as $title )
{
2011-12-07 21:07:21 +00:00
$this -> pageTitles [] = $title ;
2006-12-02 04:36:16 +00:00
}
if ( ! trim ( $pages [ 0 ]))
{
$count = 0 ;
foreach ( $pages as $page )
{
$pages [ $count ] = $pages [( $count + 1 )];
$count ++ ;
}
unset ( $pages [( count ( $pages ) - 1 )]);
}
$pageCount = count ( $pages );
2011-12-07 21:07:21 +00:00
$titleCount = count ( $this -> pageTitles );
2006-12-02 04:36:16 +00:00
/* if the vars above don't match, page 1 has no [newpage] tag, so we need to create one ... */
if ( $pageCount != $titleCount )
{
2011-12-07 21:07:21 +00:00
array_unshift ( $this -> pageTitles , " [newpage] " );
2006-12-02 04:36:16 +00:00
}
/* ok, titles now match pages, rename the titles if needed ... */
$count = 0 ;
2011-12-07 21:07:21 +00:00
foreach ( $this -> pageTitles as $title )
2006-12-02 04:36:16 +00:00
{
$titlep = preg_replace ( " / \ [newpage=(.*?) \ ]/ " , " \\ 1 " , $title );
2011-12-07 21:07:21 +00:00
$this -> pageTitles [ $count ] = ( $titlep == " [newpage] " ? LAN_PAGE_13 . " " . ( $count + 1 ) : $tp -> toHTML ( $titlep , TRUE , 'TITLE' ));
2006-12-02 04:36:16 +00:00
$count ++ ;
}
2011-12-07 21:07:21 +00:00
$this -> pageToRender = $tp -> toHTML ( $pages [ $this -> pageSelected ], TRUE , 'BODY' );
$this -> title = ( substr ( $this -> pageTitles [ $this -> pageSelected ], - 1 ) == " ; " ? " " : $this -> pageTitles [ $this -> pageSelected ]);
2006-12-02 04:36:16 +00:00
2011-12-07 21:07:21 +00:00
if ( $this -> debug )
2006-12-02 04:36:16 +00:00
{
2011-12-07 21:07:21 +00:00
echo " <b>multipageFlag</b> " . $this -> multipageFlag . " <br /> " ;
if ( $this -> multipageFlag )
2006-12-02 04:36:16 +00:00
{
echo " <pre> " ; print_r ( $pages ); echo " </pre> " ;
echo " <b>pageCount</b> " . $pageCount . " <br /> " ;
echo " <b>titleCount</b> " . $titleCount . " <br /> " ;
2011-12-07 21:07:21 +00:00
echo " <pre> " ; print_r ( $this -> pageTitles ); echo " </pre> " ;
2006-12-02 04:36:16 +00:00
}
}
2012-07-09 01:54:43 +00:00
e107 :: getBB () -> clearClass ();
2006-12-02 04:36:16 +00:00
}
2014-06-13 03:39:41 -07:00
2006-12-02 04:36:16 +00:00
function pageIndex ()
{
2011-12-07 21:07:21 +00:00
// Use always nextprev shortcode (with a special default 'page' tempalte)
$titles = implode ( " | " , $this -> pageTitles );
$total_items = count ( $this -> pageTitles );
//$parms = $total_items.",1,".$this->pageSelected.",".e_SELF."?".$this->pageID.".[FROM],,$titles";
$row = $this -> page ;
$row [ 'page' ] = '--FROM--' ;
$url = rawurlencode ( e107 :: getUrl () -> create ( 'page/view' , $row , 'allow=page_id,page_title,page_sef,page' ));
$parms = 'nonavcount&bullet=' . rawurlencode ( $this -> bullet . ' ' ) . '&caption=<!-- Empty -->&' . 'pagetitle=' . rawurlencode ( $titles ) . '&tmpl_prefix=' . deftrue ( 'PAGE_NEXTPREV_TMPL' , 'page' ) . '&total=' . $total_items . '&amount=1¤t=' . $this -> pageSelected . '&url=' . $url ;
$itext = ( $total_items ) ? e107 :: getParser () -> parseTemplate ( " { NEXTPREV= { $parms } } " ) : " " ;
2006-12-02 04:36:16 +00:00
return $itext ;
}
2011-12-07 21:07:21 +00:00
// FIXME most probably will fail when cache enabled
2006-12-02 04:36:16 +00:00
function pageRating ( $page_rating_flag )
{
2012-05-27 10:42:16 +00:00
2006-12-02 04:36:16 +00:00
if ( $page_rating_flag )
{
2012-05-27 10:42:16 +00:00
return " <br /><div style='text-align:right'> " . e107 :: getRate () -> render ( " page " , $this -> pageID , array ( 'label' => LAN_PAGE_4 )) . " </div> " ;
2006-12-02 04:36:16 +00:00
}
2012-05-27 10:42:16 +00:00
// return $rate_text;
2006-12-02 04:36:16 +00:00
}
2014-06-13 03:39:41 -07:00
2006-12-02 04:36:16 +00:00
function pageComment ( $page_comment_flag )
{
if ( $page_comment_flag )
{
2014-06-13 03:39:41 -07:00
$cobj = e107 :: getComment ();
2006-12-02 04:36:16 +00:00
if ( isset ( $_POST [ 'commentsubmit' ]))
{
2019-04-06 12:11:05 -07:00
$pid = null ; //FIXME ?
2011-12-07 21:07:21 +00:00
$cobj -> enter_comment ( $_POST [ 'author_name' ], $_POST [ 'comment' ], " page " , $this -> pageID , $pid , $_POST [ 'subject' ]);
$e107cache = e107 :: getCache ();
$e107cache -> clear ( " comment.page. " . $this -> pageID );
$e107cache -> clear ( $this -> cacheString );
2006-12-02 04:36:16 +00:00
}
2017-10-10 15:18:53 -07:00
return $cobj -> compose_comment ( " page " , " comment " , $this -> pageID , 0 , $this -> page [ 'page_title' ], false , true );
2006-12-02 04:36:16 +00:00
}
}
2014-06-13 03:39:41 -07:00
2006-12-22 20:51:32 +00:00
function pageCheckPerms ( $page_class , $page_password , $page_title = " " )
2006-12-02 04:36:16 +00:00
{
2007-08-03 18:40:52 +00:00
global $ns , $tp , $pref , $HEADER , $FOOTER , $sql ; // $tp added - also $pref - used by footer
2006-12-22 20:51:32 +00:00
2006-12-02 04:36:16 +00:00
if ( ! check_class ( $page_class ))
{
2011-12-07 21:07:21 +00:00
$this -> authorized = 'class' ;
return false ;
2006-12-02 04:36:16 +00:00
}
if ( ! $page_password )
{
2011-12-07 21:07:21 +00:00
$this -> authorized = true ;
$cookiename = $this -> getCookieName ();
if ( isset ( $_COOKIE [ $cookiename ])) cookie ( $cookiename , '' , ( time () - 2592000 ));
return true ;
2006-12-02 04:36:16 +00:00
}
2007-01-01 10:27:49 +00:00
if ( isset ( $_POST [ 'submit_page_pw' ]))
2006-12-02 04:36:16 +00:00
{
2015-02-07 01:45:36 -08:00
2006-12-02 04:36:16 +00:00
if ( $_POST [ 'page_pw' ] == $page_password )
{
2011-12-07 21:07:21 +00:00
$this -> setPageCookie ();
$this -> authorized = true ;
return true ;
}
else
{
2016-02-24 17:43:38 +00:00
e107 :: getMessage () -> addError ( LAN_INCORRECT_PASSWORD );
2006-12-02 04:36:16 +00:00
}
}
else
{
2011-12-07 21:07:21 +00:00
// TODO - e_COOKIE
$cookiename = $this -> getCookieName ();
2006-12-02 04:36:16 +00:00
2007-01-01 12:00:50 +00:00
if ( isset ( $_COOKIE [ $cookiename ]) && ( $_COOKIE [ $cookiename ] == md5 ( $page_password . USERID )))
2006-12-02 04:36:16 +00:00
{
2011-12-07 21:07:21 +00:00
$this -> authorized = true ;
2006-12-02 04:36:16 +00:00
return TRUE ;
}
2006-12-22 20:51:32 +00:00
// Invalid/empty password here
2006-12-02 04:36:16 +00:00
}
2011-12-07 21:07:21 +00:00
$this -> authorized = 'pw' ;
return false ;
}
2006-12-02 04:36:16 +00:00
2014-06-13 03:39:41 -07:00
2011-12-07 21:07:21 +00:00
function getCookieName ()
{
return e_COOKIE . '_page_' . $this -> pageID ;
2006-12-02 04:36:16 +00:00
}
2014-06-13 03:39:41 -07:00
2006-12-02 04:36:16 +00:00
function setPageCookie ()
{
2011-12-07 21:07:21 +00:00
if ( ! $this -> pageID || ! vartrue ( $_POST [ 'page_pw' ])) return ;
$pref = e107 :: getPref ();
2006-12-02 04:36:16 +00:00
$pref [ 'pageCookieExpire' ] = max ( $pref [ 'pageCookieExpire' ], 120 );
$hash = md5 ( $_POST [ 'page_pw' ] . USERID );
2011-12-07 21:07:21 +00:00
cookie ( $this -> getCookieName (), $hash , ( time () + $pref [ 'pageCookieExpire' ]));
//header("location:".e_SELF."?".e_QUERY);
//exit;
2006-12-02 04:36:16 +00:00
}
}
2021-01-19 09:50:02 -08:00