2009-11-20 05:01:51 +00:00
< ? php
/*
* e107 website system
*
2012-12-18 01:32:33 -08:00
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
2009-11-20 05:01:51 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
*/
2012-12-18 01:32:33 -08:00
if ( ! defined ( 'e107_INIT' )) { exit ; }
2009-11-20 05:01:51 +00:00
2013-02-26 03:43:52 -08:00
class page_sitelink // include plugin-folder in the name.
2009-11-20 05:01:51 +00:00
{
function config ()
{
$links = array ();
2013-10-28 21:30:24 -07:00
$sql = e107 :: getDb ();
$links [] = array (
'name' => " All Books " ,
'function' => " bookNav " ,
'description' => " A list of all books "
);
$books = $sql -> retrieve ( " SELECT * FROM #page_chapters WHERE chapter_parent =0 ORDER BY chapter_order ASC " , true );
foreach ( $books as $row )
{
$links [] = array (
'name' => " All Chapters from " . $row [ 'chapter_name' ],
'function' => " chapterNav " ,
'parm' => $row [ 'chapter_id' ],
'description' => " A list of all chapters from the book " . $row [ 'chapter_name' ]
);
}
2009-11-20 05:01:51 +00:00
$links [] = array (
'name' => " All Pages " ,
2012-12-17 04:21:16 -08:00
'function' => " pageNav " ,
2013-10-28 21:30:24 -07:00
'parm' => " " ,
'description' => " A list of all pages "
2009-11-20 05:01:51 +00:00
);
return $links ;
}
2013-10-28 21:30:24 -07:00
/**
* Return a tree of all books and their chapters .
*/
public function bookNav ( $book )
{
return $this -> pageNav ( 'book=0' );
}
2009-11-20 05:01:51 +00:00
2013-10-28 21:30:24 -07:00
/**
* Return a list of all chapters from a sepcific book .
*/
public function chapterNav ( $book )
{
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
if ( $sql -> select ( " page_chapters " , " * " , " chapter_parent = " . intval ( $book ) . " ORDER BY chapter_order ASC " ))
{
$sublinks = array ();
while ( $row = $sql -> fetch ())
{
$sublinks [] = array (
'link_name' => $tp -> toHtml ( $row [ 'chapter_name' ], '' , 'TITLE' ),
'link_url' => 'page.php?ch=' . $row [ 'chapter_id' ], //TODO FIXME chapter_sef support
'link_description' => '' ,
'link_button' => '' ,
'link_category' => '' ,
'link_order' => '' ,
'link_parent' => $row [ 'chapter_parent' ],
'link_open' => '' ,
'link_class' => 0
);
}
return $sublinks ;
}
}
2009-11-20 05:01:51 +00:00
2012-12-19 02:03:34 -08:00
function pageNav ( $parm = '' )
2009-11-20 05:01:51 +00:00
{
2013-05-29 01:22:11 -07:00
$frm = e107 :: getForm ();
2013-02-14 13:06:16 +02:00
$options = array ();
2012-12-19 02:03:34 -08:00
if ( vartrue ( $parm ))
{
parse_str ( $parm , $options );
}
2012-12-17 12:14:52 -08:00
$sql = e107 :: getDb ();
$sublinks = array ();
2013-02-14 15:37:42 +02:00
$arr = array ();
2013-03-08 13:08:06 +02:00
// map current when in auto mode
if ( vartrue ( $options [ 'auto' ]))
{
// current book found, top book not set
if ( vartrue ( $options [ 'cbook' ]) && ! vartrue ( $options [ 'book' ]))
{
$options [ 'book' ] = $options [ 'cbook' ];
}
// current chapter found, top chapter not set
if ( vartrue ( $options [ 'cchapter' ]) && ! vartrue ( $options [ 'chapter' ]))
{
$options [ 'chapter' ] = $options [ 'cchapter' ];
}
// current chapter found, top chapter not set
if ( vartrue ( $options [ 'cpage' ]) && ! vartrue ( $options [ 'page' ]))
{
$options [ 'page' ] = $options [ 'cpage' ];
}
}
2013-02-14 15:37:42 +02:00
// find the chapter if required
if ( vartrue ( $options [ 'page' ]) && ! vartrue ( $options [ 'chapter' ]))
{
$options [ 'chapter' ] = $sql -> retrieve ( 'page' , 'page_chapter' , 'page_id=' . intval ( $options [ 'page' ]));
}
2012-12-19 02:03:34 -08:00
$query = " SELECT * FROM #page WHERE " ;
2013-04-02 09:29:11 +03:00
$q = array ();
2013-05-29 01:22:11 -07:00
2013-02-14 15:37:42 +02:00
if ( vartrue ( $options [ 'chapter' ]))
{
2013-05-29 01:22:11 -07:00
$q [] = " page_title !='' AND page_chapter = " . intval ( $options [ 'chapter' ]);
2013-02-14 15:37:42 +02:00
}
elseif ( vartrue ( $options [ 'book' ]))
{
2013-05-29 19:37:06 -07:00
$q [] = " page_title !='' && page_chapter IN (SELECT chapter_id FROM #page_chapters WHERE chapter_parent= " . intval ( $options [ 'book' ]) . " ) " ;
2013-02-14 15:37:42 +02:00
}
2013-04-02 09:29:11 +03:00
// XXX discuss FIXED remove DB check, use default title - AND page_title !=''
$q [] = " page_class IN ( " . USERCLASS_LIST . " ) " ;
$query .= implode ( ' AND ' , $q ) . " ORDER BY page_order " ;
2012-12-19 02:03:34 -08:00
2012-12-17 12:14:52 -08:00
$data = $sql -> retrieve ( $query , true );
2013-02-14 13:06:16 +02:00
$_pdata = array ();
2013-02-14 15:37:42 +02:00
2012-12-17 04:21:16 -08:00
foreach ( $data as $row )
2009-11-20 05:01:51 +00:00
{
2012-12-17 12:14:52 -08:00
$pid = $row [ 'page_chapter' ];
2013-02-14 13:06:16 +02:00
$sublinks [ $pid ][] = $_pdata [] = array (
2012-12-17 04:21:16 -08:00
'link_id' => $row [ 'page_id' ],
2013-04-02 09:29:11 +03:00
'link_name' => $row [ 'page_title' ] ? $row [ 'page_title' ] : 'No title' , // FIXME lan
2013-02-13 17:03:53 +02:00
'link_url' => e107 :: getUrl () -> create ( 'page/view' , $row , array ( 'allow' => 'page_sef,page_title,page_id' )),
2009-11-20 05:01:51 +00:00
'link_description' => '' ,
'link_button' => '' ,
'link_category' => '' ,
2012-12-17 04:21:16 -08:00
'link_order' => $row [ 'page_order' ],
2012-12-17 12:14:52 -08:00
'link_parent' => $row [ 'page_chapter' ],
2009-11-20 05:01:51 +00:00
'link_open' => '' ,
2013-02-14 15:37:42 +02:00
'link_class' => intval ( $row [ 'page_class' ]),
2013-05-29 01:22:11 -07:00
'link_active' => ( $options [ 'cpage' ] && $row [ 'page_id' ] == $options [ 'cpage' ])
2009-11-20 05:01:51 +00:00
);
}
2012-12-19 02:03:34 -08:00
$filter = 1 ;
if ( vartrue ( $options [ 'chapter' ]))
{
2013-02-14 13:06:16 +02:00
//$filter = "chapter_id > ".intval($options['chapter']);
2013-05-29 23:00:55 -07:00
2013-02-14 15:37:42 +02:00
$title = $sql -> retrieve ( 'page_chapters' , 'chapter_name' , 'chapter_id=' . intval ( $options [ 'chapter' ]));
2013-02-14 13:06:16 +02:00
$outArray = array ();
2013-02-14 15:37:42 +02:00
if ( ! $title ) return e107 :: getNav () -> compile ( $_pdata , $outArray , $options [ 'chapter' ]);
return array ( 'title' => $title , 'body' => e107 :: getNav () -> compile ( $_pdata , $outArray , $options [ 'chapter' ]));
2012-12-19 02:03:34 -08:00
}
2013-02-14 15:37:42 +02:00
$parent = 0 ;
$title = false ;
2012-12-19 02:03:34 -08:00
if ( vartrue ( $options [ 'book' ]))
{
2013-05-30 14:16:49 -07:00
2013-02-14 15:37:42 +02:00
// XXX discuss the idea here
//$filter = "chapter_id > ".intval($options['book']);
$filter = " chapter_parent = " . intval ( $options [ 'book' ]);
$parent = intval ( $options [ 'book' ]);
$title = $sql -> retrieve ( 'page_chapters' , 'chapter_name' , 'chapter_id=' . intval ( $options [ 'book' ]));
2013-05-30 14:16:49 -07:00
// print_a('parent='.$parent);
2012-12-19 02:03:34 -08:00
}
$books = $sql -> retrieve ( " SELECT * FROM #page_chapters WHERE " . $filter . " ORDER BY chapter_order ASC " , true );
2012-12-17 12:14:52 -08:00
foreach ( $books as $row )
{
2013-05-29 23:00:55 -07:00
2012-12-17 12:14:52 -08:00
$arr [] = array (
'link_id' => $row [ 'chapter_id' ],
'link_name' => $row [ 'chapter_name' ],
2013-02-01 18:00:53 -08:00
//TODO SEFURLS using chapter_sef.
'link_url' => ( $row [ 'chapter_parent' ] == 0 ) ? 'page.php?bk=' . $row [ 'chapter_id' ] : 'page.php?ch=' . $row [ 'chapter_id' ],
// 'link_url' => vartrue($row['chapter_sef'],'#'),
2012-12-17 12:14:52 -08:00
'link_description' => '' ,
'link_button' => '' ,
'link_category' => '' ,
'link_order' => $row [ 'chapter_order' ],
'link_parent' => $row [ 'chapter_parent' ],
'link_open' => '' ,
'link_class' => 0 ,
2013-05-29 23:00:55 -07:00
'link_sub' => ( ! vartrue ( $options [ 'book' ]) && ! vartrue ( $options [ 'auto' ])) ? varset ( $sublinks [ $row [ 'chapter_id' ]]) : '' , //XXX always test with docs template in bootstrap before changing.
2013-03-08 13:08:06 +02:00
'link_active' => $row [ 'chapter_parent' ] == 0 ? $options [ 'cbook' ] && $options [ 'cbook' ] == $row [ 'chapter_id' ] : $options [ 'cchapter' ] && $options [ 'cchapter' ] == $row [ 'chapter_id' ],
2012-12-17 12:14:52 -08:00
);
}
2012-12-17 04:21:16 -08:00
2013-05-30 14:16:49 -07:00
2012-12-17 04:21:16 -08:00
$outArray = array ();
2013-05-30 14:16:49 -07:00
$parent = vartrue ( $options [ 'book' ]) ? intval ( $options [ 'book' ]) : 0 ;
2012-12-19 02:03:34 -08:00
$ret = e107 :: getNav () -> compile ( $arr , $outArray , $parent );
2013-05-30 14:16:49 -07:00
2013-02-14 15:37:42 +02:00
if ( ! $title ) return $ret ;
return array ( 'title' => $title , 'body' => $ret );
2009-11-20 05:01:51 +00:00
}
}