2013-02-01 01:32:43 -08:00
< ? php
/*
* e107 website system
*
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
*/
if ( ! defined ( 'e107_INIT' )) { exit ; }
class page_shortcodes extends e_shortcode
{
2013-05-29 15:33:39 -07:00
protected $request ;
function __construct ()
2013-02-01 01:32:43 -08:00
{
2013-05-29 15:33:39 -07:00
$this -> request = e107 :: getRegistry ( 'core/pages/request' );
2013-05-30 14:16:49 -07:00
$action = varset ( $this -> request [ 'action' ]);
if (( $action == 'listPages' || $action == 'listChapters' ) && vartrue ( $this -> request [ 'id' ]))
2013-05-29 15:33:39 -07:00
{
2014-01-10 18:27:42 -08:00
$this -> var = e107 :: getDb () -> retrieve ( 'page_chapters' , 'chapter_name, chapter_meta_description, chapter_sef' , 'chapter_id = ' . intval ( $this -> request [ 'id' ]) . ' LIMIT 1' );
2013-06-01 14:03:18 -07:00
}
if ( $action == 'showPage' && vartrue ( $this -> request [ 'id' ])) // get chapter and description from current.
{
$query = " SELECT p.page_id,c.chapter_name,c.chapter_meta_description FROM #page AS p LEFT JOIN #page_chapters AS c ON p.page_chapter = c.chapter_id WHERE p.page_id = " . intval ( $this -> request [ 'id' ]) . " LIMIT 1 " ;
$rows = e107 :: getDb () -> retrieve ( $query , true );
$this -> var = $rows [ 0 ];
}
2013-05-29 15:33:39 -07:00
}
/**
* Page Navigation
* @ example { PAGE_NAVIGATION : template = navdoc & auto = 1 } in your Theme template .
*/
function sc_page_navigation ( $parm = '' ) // TODO when No $parm provided, auto-detect based on URL which book/chapters to display.
{
// $parm = eHelper::scParams($parm);
2013-05-30 14:16:49 -07:00
2013-05-29 23:00:55 -07:00
$tmpl = e107 :: getCoreTemplate ( 'chapter' , vartrue ( $parm [ 'template' ], 'nav' ), true , true ); // always merge
$template = $tmpl [ 'showPage' ];
2013-05-29 15:33:39 -07:00
$request = $this -> request ;
if ( $request && is_array ( $request ))
{
switch ( $request [ 'action' ])
{
2013-05-30 14:16:49 -07:00
case 'listBooks' :
$parm [ 'cbook' ] = 'all' ;
$template = $tmpl [ 'listBooks' ];
if ( e107 :: getPref ( 'listBooks' , false ) == false ) // List Books has been disabled.
{
return false ;
}
break ;
2013-05-29 15:33:39 -07:00
case 'listChapters' :
$parm [ 'cbook' ] = $request [ 'id' ];
2013-05-29 23:00:55 -07:00
$template = $tmpl [ 'listChapters' ];
2013-05-29 15:33:39 -07:00
break ;
case 'listPages' :
$parm [ 'cchapter' ] = $request [ 'id' ];
2013-05-29 23:00:55 -07:00
$template = $tmpl [ 'listPages' ];
2013-05-30 14:16:49 -07:00
2013-05-29 15:33:39 -07:00
break ;
case 'showPage' :
$parm [ 'cpage' ] = $request [ 'id' ];
break ;
}
}
if ( $parm )
{
$parm = http_build_query ( $parm , null , '&' );
}
else
{
$parm = '' ;
}
2013-05-30 14:16:49 -07:00
2013-05-29 15:33:39 -07:00
$links = e107 :: getAddon ( 'page' , 'e_sitelink' );
2013-05-29 23:00:55 -07:00
$data = $links -> pageNav ( $parm );
2013-05-29 15:33:39 -07:00
2013-02-14 15:37:42 +02:00
if ( isset ( $data [ 'title' ]) && ! vartrue ( $template [ 'noAutoTitle' ]))
{
2013-05-29 15:33:39 -07:00
// use chapter title
$template [ 'caption' ] = $data [ 'title' ];
2013-02-14 15:37:42 +02:00
$data = $data [ 'body' ];
2013-05-29 15:33:39 -07:00
}
if ( empty ( $data )){ return ; }
2013-02-01 01:32:43 -08:00
return e107 :: getNav () -> render ( $data , $template ) ;
2013-05-29 15:33:39 -07:00
2013-02-01 01:32:43 -08:00
}
2013-03-11 05:12:45 -07:00
2013-05-29 15:33:39 -07:00
function sc_page_chapter_name ( $parm = '' )
2013-06-01 14:03:18 -07:00
{
2013-05-29 15:33:39 -07:00
return e107 :: getParser () -> toHtml ( $this -> var [ 'chapter_name' ]);
}
function sc_page_chapter_description ( $parm = '' )
{
return e107 :: getParser () -> toHtml ( $this -> var [ 'chapter_meta_description' ], true );
}
2013-03-11 05:12:45 -07:00
/**
* New in v2 . x . eg . { CMENU = feature - 1 } Renders a menu called 'feature-1' as found in the e107_page table See admin Pages / Menus .
*/
2013-05-29 15:33:39 -07:00
function sc_cmenu ( $parm = '' )
2013-03-11 05:12:45 -07:00
{
2014-01-15 17:11:09 +02:00
return e107 :: getMenu () -> renderMenu ( $parm , false , false , true );
2013-03-11 05:12:45 -07:00
}
2013-02-01 01:32:43 -08:00
}