'sorter');
var $cnt_rows = array();
var $totalIndex = 0;
protected $_nl = "\n";
function exec($Doc)
{
$this->Doc = $Doc;
if (array_key_exists('xml', $this->options)) {
$this->_showXml();
exit;
}
$this->_showHtml();
}
protected function _showHtml()
{
require_once 'class/DB/Lang/DLang.php';
$DLang = new DLang();
$list = $DLang->getList4Grid();
if ($list['num_rows'] > 1) {
$parentAlias = $this->options['lang'].'/';
} else {
$parentAlias = '';
}
$site_map = $this->getSiteMap($parentAlias);
$this->_cleanUp($site_map);
$announcement = SiteMap::getObj('Announcement/Announcement.php');
$posts = $announcement->getList4SiteMap(array('order_by' => 'sorter'));
$site_map[] = array(
'alias' => 'blog',
'title' => 'MNCAR Focus',
'block_cnt' => 1,
'sub' => $posts,
);
$totalPages = array_sum($this->cnt_rows) + count($site_map) + count($posts);
$this->_calculatePageBreak($site_map, $totalPages/2);
$this->Doc->prepareMainMenu($site_map);
$this->Doc->addContent(
array(
'tpl' => SiteMap::getPath('CMS/tpl/site_map/site_map.tpl'),
'siteMap' => $site_map
)
);
return $this;;
}
protected function _showXml()
{
$site_map = $this->getSiteMap();
$this->_cleanUp($site_map);
$announcement = SiteMap::getObj('Announcement/Announcement.php');
$site_map[] = array(
'alias' => 'blog',
'title' => 'MNCAR Focus',
'block_cnt' => 1,
'sub' => $announcement->getList4SiteMap(array('order_by' => 'sorter')),
);
$this->_startXml();
$this->_printXml($site_map);
$this->_finishXml();
}
protected function _escapeXml($data)
{
return htmlspecialchars($data);
}
protected function _startXml()
{
header('Content-Type: text/xml');
echo '' . $this->_nl;
echo '' . $this->_nl;
return $this;
}
protected function _finishXml()
{
echo '' . $this->_nl;
return $this;
}
protected function _printXml($sitemap)
{
if (is_array($sitemap) && !empty($sitemap)) {
foreach ($sitemap as $page) {
echo ' ' . $this->_nl;
echo ' ' . $this->_escapeXml(BASE_URL . '/' . htmlspecialchars($page['alias'])) . '' . $this->_nl;
echo ' ' . $this->_escapeXml(date('c', strtotime($page['changed']))) . '' . $this->_nl;
echo ' ' . $this->_nl;
$this->_printXml($page['sub']);
}
}
return $this;
}
function getSiteMap($parentAlias = '', $id_parent = 0, $all = false, $deniedPages = array())
{
require_once('class/DB/Lang/DLang.php');
$DLang = new DLang();
$this->opt['lang'] = $DLang->validName($this->options['lang']);
$DocObj = SiteMap::getObj('CMS/Doc/DocObj.php', $id_parent);
if (!$all) {
if (!is_array($this->opt['addonWhere'])) {
$this->opt['addonWhere'] = array();
}
$this->opt['addonWhere']['system'] = 'n';
}
if (is_array($deniedPages) && !empty($deniedPages)) {
$this->opt['addonWhereSql'] = "
AND {$DocObj->tableName}.id NOT IN (".implode(',', $deniedPages).")
";
}
// ����� ����� ����ު Ҳ���� ��� ����������� �������
// �������� �� ������� ����� �������
$_list = $DocObj->getList4SiteMap($this->opt);
$list = array();
foreach($_list as $k=>$v) {
$list[$v['id_parent']][] = $v;
}
// ��������� ������� ����
$siteMap = $list[$id_parent];
unset($list[$id_parent]);
// ���������� ������� �� ���� �� �����
if (is_array($siteMap) && !empty($siteMap)) {
$this->_prepareSiteMap(&$siteMap, &$list, $parentAlias);
}
return $siteMap;
}
function _prepareSiteMap(&$siteMap, &$list, $parentAlias = '')
{
foreach ($siteMap as $k=>&$v) {
$v['alias'] = rtrim($parentAlias, '/').(($parentAlias)?'/':'').$v['alias'];
if (isset($list[$v['id']])) {
$v['sub'] = $list[$v['id']];
$this->cnt_rows[$v['id']] = count($v['sub']);
unset($list[$v['id']]);
$this->_prepareSiteMap($v['sub'], &$list, $v['alias']);
}
//adding 'Our Volunteer' Sub Items to volunteer page
$adminPage = 0 === strpos(CURR_PAGE, 'admin');
if (!$adminPage && 297 == $v['id']) {
$v['sub'] = isset($v['sub']) ? $v['sub'] : array();
$v['sub'] = array_merge($v['sub'], $this->_getVolunteerGroups($v['alias']));
}
}
}
protected function _getVolunteerGroups($alias = '')
{
require_once('app/Volunteer/Volunteer.php');
return Volunteer::getInstance()->getVolunteers4Menu($alias);
}
protected function _cleanUp(&$siteMap)
{
foreach ($siteMap as $key => &$page) {
if ($page['alias'] == 'home.htm') {
$page['alias'] = '';
}
if ($page['member_page'] == 'y') {
unset($siteMap[$key]);
if (isset($page['sub'])) {
$this->_cleanUp($page['sub']);
}
}
}
}
protected function _calculatePageBreak(&$siteMap, $total, $nesting = 0)
{
foreach ($siteMap as &$page) {
$counter++;
if (isset($page['sub'])) {
$counter += $this->_calculatePageBreak($page['sub'], $total, $nesting + 1);
}
if (!$nesting && $counter >= $total) {
$page['break'] = true;
return true;
}
}
return $counter;
}
}