add('name', PLUGIN_STATICPAGELIST_NAME);
$propbag->add('description', PLUGIN_STATICPAGELIST_NAME_DESC);
$propbag->add('author', "Rob Antonishen, Falk Doering, Ian (Timbalu)");
$propbag->add('stackable', true);
$propbag->add('version', '1.18');
$propbag->add('configuration', array(
'title',
'limit',
'parentsonly',
'frontpage',
'smartify',
'showIcons',
'useIcons',
'imgdir'
));
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('groups', array('FRONTEND_VIEWS'));
$this->dependencies = array(
'serendipity_event_staticpage' => 'keep',
'serendipity_plugin_multilingual' => 'keep'
);
}
function introspect_config_item($name, &$propbag) {
global $serendipity;
switch($name) {
case 'title':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_STATICPAGELIST_TITLE);
$propbag->add('description', PLUGIN_STATICPAGELIST_TITLE_DESC);
$propbag->add('default', PLUGIN_STATICPAGELIST_TITLE_DEFAULT);
break;
case 'limit':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_STATICPAGELIST_LIMIT);
$propbag->add('description', PLUGIN_STATICPAGELIST_LIMIT_DESC);
$propbag->add('default', 0);
break;
case 'parentsonly':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_STATICPAGELIST_PARENTSONLY);
$propbag->add('description', PLUGIN_STATICPAGELIST_PARENTSONLY_DESC);
$propbag->add('default', 'false');
break;
case 'frontpage':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_STATICPAGELIST_FRONTPAGE_NAME);
$propbag->add('description', PLUGIN_STATICPAGELIST_FRONTPAGE_DESC);
$propbag->add('default', 'true');
break;
case 'smartify':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_STATICPAGELIST_SMARTIFY);
$propbag->add('description', PLUGIN_STATICPAGELIST_SMARTIFY_BLAHBLAH);
$propbag->add('default', 'false');
break;
case 'useIcons':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_STATICPAGELIST_IMG_NAME);
$propbag->add('description', '');
$propbag->add('default', 'true');
break;
case 'imgdir':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_LINKS_IMGDIR);
$propbag->add('description', PLUGIN_LINKS_IMGDIR_BLAHBLAH);
$propbag->add('default', $serendipity['baseURL'] . 'plugins/' . basename(dirname(__FILE__)));
break;
case 'showIcons':
$propbag->add('type', 'radio');
$propbag->add('name', PLUGIN_STATICPAGELIST_SHOWICONS_NAME);
$propbag->add('description', PLUGIN_STATICPAGELIST_SHOWICONS_DESC);
$propbag->add('radio', array(
'value' => array('true', 'false'),
'desc' => array(PLUGIN_STATICPAGELIST_ICON, PLUGIN_STATICPAGELIST_TEXT)
));
$propbag->add('default', 'false');
break;
default:
return false;
}
return true;
}
function generate_content(&$title) {
$title = STATICPAGE_TITLE;
// do not load the tpl in backend
if(!defined('IN_serendipity_admin')) {
$this->show_content();
}
}
function show_content() {
global $serendipity;
static $smartify = null;
if ($smartify === null) {
$smartify = serendipity_db_bool($this->get_config('smartify'));
}
$title = $this->get_config('title');
$frontpage = serendipity_db_bool($this->get_config('frontpage', true));
$plugin_dir = basename(dirname(__FILE__));
$smartcar = array();
$str = '';
if (!serendipity_db_bool($this->get_config('showIcons'))) {
if ($frontpage) {
if ($smartify) {
$serendipity['smarty']->assign('frontpage_path', $serendipity['serendipityHTTPPath'] . $serendipity['indexFile']);
} else {
$str .= ''.PLUGIN_STATICPAGELIST_FRONTPAGE_LINKNAME . '
';
}
}
if ($smartify) {
$smartcar = $this->displayPageList($this->get_config('limit'), serendipity_db_bool($this->get_config('parentsonly')), $smartify);
} else {
$str .= $this->displayPageList($this->get_config('limit'), serendipity_db_bool($this->get_config('parentsonly')));
}
} else {
if (!isset($serendipity['staticpageplugin']['JS_init'])) {
$str .= '';
$serendipity['staticpageplugin']['JS_init'] = true;
}
$imgdir = $this->get_config('imgdir');
if ($imgdir === "true") {
$imgdir = $serendipity['baseURL'] . 'plugins/' . $plugin_dir;
}
$fdid = str_replace(':', '_', $this->instance);
$str .= '';
}
if ($smartify) {
$serendipity['smarty']->assign(array(
'staticpage_jsStr' => $str,
'staticpage_listContent' => $smartcar
));
$filename = 'plugin_staticpage_sidebar.tpl';
// use serendipity's own function here! ;-)
$content = $this->parseTemplate($filename);
echo $content;
} else {
echo $str;
}
}
function getPageList($parentsonly = false) {
global $serendipity;
$q = 'SELECT id, headline, parent_id, permalink, pagetitle, is_startpage
FROM '.$serendipity['dbPrefix'].'staticpages
WHERE showonnavi = 1
AND publishstatus = 1
AND (language = \''.$serendipity['lang'].'\'
OR language = \'\'
OR language = \'all\')';
if($parentsonly) {
$q .= ' AND parent_id = 0';
}
$q .= ' ORDER BY parent_id, pageorder';
$pagelist = serendipity_db_query($q, false, 'assoc');
if (is_array($pagelist)) {
serendipity_plugin_staticpage::iteratePageList($pagelist);
$pagelist = serendipity_walkRecursive($pagelist, 'id', 'parent_id', VIEWMODE_THREADED);
return $pagelist;
}
return false;
}
function addJSTags(&$pagelist) {
global $serendipity;
$pc_count = count($pagelist);
for ($i = 0; $i < $pc_count; $i++) {
$p = array(
'type' => 'open',
'tag' => ($pagelist[$i]['parent_id'] == 0) ? 'link' : 'dir'
);
$pagelist[$i] = array_merge($pagelist[$i], $p);
}
}
function iteratePageList(&$pagelist) {
global $serendipity;
if (is_array($pagelist)) {
foreach($pagelist AS $idx => $page) {
if ($page['is_startpage'] > 0) {
$pagelist[$idx]['permalink'] = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'];
}
}
}
return true;
}
function displayPageList($limit, $parentsonly, $tpl=false) {
global $serendipity;
$q = 'SELECT id, headline, parent_id, permalink, pagetitle, is_startpage
FROM '.$serendipity['dbPrefix'].'staticpages
WHERE showonnavi = 1
AND publishstatus = 1
AND (language = \''.$serendipity['lang'].'\'
OR language = \'\'
OR language = \'all\')';
if($parentsonly) {
$q .= ' AND parent_id = 0';
}
$q .= ' ORDER BY parent_id, pageorder';
if($limit) {
$q .= ' LIMIT '.$limit;
}
$pagelist = serendipity_db_query($q, false, 'assoc');
if(is_array($pagelist)) {
serendipity_plugin_staticpage::iteratePageList($pagelist);
$pagelist = serendipity_walkRecursive($pagelist, 'id', 'parent_id', VIEWMODE_THREADED);
$content = ($tpl ? array() : (string)'');
foreach($pagelist as $page) {
if(is_array($content)) {
/* smartify the staticpage sidebar plugin */
$content[] = array(
'id' => $page['id'],
'headline' => (!empty($page['headline']) ? htmlspecialchars($page['headline']) : htmlspecialchars($page['pagetitle'])),
'parent_id' => $page['parent_id'],
'permalink' => (!empty($page['permalink']) ? $page['permalink'] : NULL),
'pagetitle' => (!empty($page['permalink']) ? htmlspecialchars($page['pagetitle']) : NULL),
'is_startpage' => $page['is_startpage'],
'depth' => $page['depth']*10
);
} elseif(is_string($content)) {
$content .= (!empty($page['permalink'])
? sprintf(
"%s
\n",
$page['permalink'],
htmlspecialchars($page['pagetitle']),
$page['depth']*10,
(!empty($page['headline']) ? htmlspecialchars($page['headline']) : htmlspecialchars($page['pagetitle'])))
: sprintf(
"