|
From: Verdon V. <ve...@us...> - 2008-07-07 21:01:58
|
Update of /cvsroot/phpwebsite-comm/modules/sitemap/class In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27962/class Modified Files: SM_Forms.php Sitemap.php Log Message: 0.5.0 updates Index: Sitemap.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/sitemap/class/Sitemap.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Sitemap.php 1 Jul 2008 03:43:59 -0000 1.2 --- Sitemap.php 7 Jul 2008 21:01:35 -0000 1.3 *************** *** 179,182 **** --- 179,190 ---- PHPWS_Settings::set('sitemap', 'allow_feed', 0); + isset($_POST['addkeys']) ? + PHPWS_Settings::set('sitemap', 'addkeys', 1) : + PHPWS_Settings::set('sitemap', 'addkeys', 0); + + isset($_POST['include_fc']) ? + PHPWS_Settings::set('sitemap', 'include_fc', 1) : + PHPWS_Settings::set('sitemap', 'include_fc', 0); + $cache_timeout = (int)$_POST['cache_timeout']; if ((int)$cache_timeout <= 7200) { *************** *** 281,285 **** } ! $content = $this->buildXML($menus, $lastmod); if (PHPWS_Settings::get('sitemap', 'cache_timeout') > 0) { PHPWS_Cache::save($cache_key, $content); --- 289,293 ---- } ! $content = $this->buildXML($menus, $lastmod, PHPWS_Settings::get('sitemap', 'addkeys')); if (PHPWS_Settings::get('sitemap', 'cache_timeout') > 0) { PHPWS_Cache::save($cache_key, $content); *************** *** 303,307 **** $lastmod = null; } ! $content = $this->buildXML($menus, $lastmod); if ($_REQUEST['build_type']) { /* save to server */ --- 311,320 ---- $lastmod = null; } ! if (isset($_REQUEST['addkeys'])) { ! $addkeys = $_REQUEST['addkeys']; ! } else { ! $addkeys = null; ! } ! $content = $this->buildXML($menus, $lastmod, $addkeys); if ($_REQUEST['build_type']) { /* save to server */ *************** *** 321,329 **** } ! function buildXML($menus, $lastmod=null) { ! $final = null; $content = null; if (!empty($menus) && is_array($menus)) { --- 334,421 ---- } ! function buildXML($menus, $lastmod=null, $addkeys=null) { ! $menuitems = array(); ! $otheritems = array(); $content = null; + + /* get the menu items */ + if (!empty($menus) && is_array($menus)) { + $menuitems = $this->getMenuItems($menus); + // print_r($menuitems); //exit; + } + + /* get other keyed items */ + if ($addkeys) { + $otheritems = $this->getOtherItems(); + // print_r($otheritems); //exit; + /* compare the arrays for dupes and return the cleaned array */ + $menuitems = array_udiff($menuitems, $otheritems, array($this, 'compareURL')); + // print_r($menuitems); exit; + } + + /* merge the two arrays */ + $allitems = array_merge($menuitems, $otheritems); + // print_r($allitems); exit; + + if (!empty($allitems) && is_array($allitems)) { + + /* make a template array of what's left */ + foreach ($allitems as $link) { + + /* loc */ + $link_tpl['LOC'] = htmlspecialchars($link['url']); + + /* lastmod */ + if (PHPWS_Settings::get('sitemap', 'use_lastmod')) { + if ($link['key_id']) { + $link_tpl['LASTMOD'] = date("Y-m-d", $link['update_date']); + } else { + $link_tpl['LASTMOD'] = $lastmod; + } + } + + /* changefreq */ + if (PHPWS_Settings::get('sitemap', 'use_change')) { + $link_tpl['CHANGE_FREQ'] = $this->getChangeFreq(PHPWS_Settings::get('sitemap', 'change_freq')); + } + /* priority */ + if (PHPWS_Settings::get('sitemap', 'use_priority')) { + $basep = 0.5; + if (!$link['parent']) { + $basep = $basep + 0.5; + } + if (($link['link_order'] > 1) && ($link['link_order'] < 5)) { + if ($link['link_order'] == 2) { + $basep = $basep - 0.1; + } elseif ($link['link_order'] == 3) { + $basep = $basep - 0.2; + } elseif ($link['link_order'] == 4) { + $basep = $basep - 0.3; + } + } elseif ($link['link_order'] > 4) { + $basep = $basep - 0.4; + } + $link_tpl['USE_PRIORITY'] = $basep; + } + + $tpl['links-listing'][] = $link_tpl; + } + + + // print_r($tpl['links-listing']); exit; + $content = PHPWS_Template::process($tpl, 'sitemap', 'sitemap.tpl'); + return $content; + + } else { + return false; + } + } + + + function getMenuItems($menus) + { + $final = null; if (!empty($menus) && is_array($menus)) { *************** *** 374,378 **** if (PHPWS_Settings::get('sitemap', 'local_only')) { if (!$link['local']) { ! $link = null; } } --- 466,471 ---- if (PHPWS_Settings::get('sitemap', 'local_only')) { if (!$link['local']) { ! // $link = null; ! $tidy = null; } } *************** *** 381,388 **** if (PHPWS_Settings::get('sitemap', 'respect_privs')) { if ($link['key_id'] && !$link['active']) { ! $link = null; } if ($link['key_id'] && $link['restricted']) { ! $link = null; } } --- 474,483 ---- if (PHPWS_Settings::get('sitemap', 'respect_privs')) { if ($link['key_id'] && !$link['active']) { ! // $link = null; ! $tidy = null; } if ($link['key_id'] && $link['restricted']) { ! // $link = null; ! $tidy = null; } } *************** *** 397,462 **** } ! $final[$link['id']] = $link; } ! /* filter out the null ones and get the cleaned array */ $final = array_filter($final); ! /* make a template array of what's left */ ! foreach ($final as $link) { ! /* loc */ ! $link_tpl['LOC'] = htmlspecialchars($link['url']); ! /* lastmod */ ! if (PHPWS_Settings::get('sitemap', 'use_lastmod')) { ! if ($link['key_id']) { ! $link_tpl['LASTMOD'] = date("Y-m-d", $link['update_date']); ! } else { ! $link_tpl['LASTMOD'] = $lastmod; ! } } ! /* changefreq */ ! if (PHPWS_Settings::get('sitemap', 'use_change')) { ! $link_tpl['CHANGE_FREQ'] = $this->getChangeFreq(PHPWS_Settings::get('sitemap', 'change_freq')); } ! ! /* priority */ ! if (PHPWS_Settings::get('sitemap', 'use_priority')) { ! $basep = 0.5; ! if (!$link['parent']) { ! $basep = $basep + 0.5; ! } ! if (($link['link_order'] > 1) && ($link['link_order'] < 5)) { ! if ($link['link_order'] == 2) { ! $basep = $basep - 0.1; ! } elseif ($link['link_order'] == 3) { ! $basep = $basep - 0.2; ! } elseif ($link['link_order'] == 4) { ! $basep = $basep - 0.3; ! } ! } elseif ($link['link_order'] > 4) { ! $basep = $basep - 0.4; ! } ! $link_tpl['USE_PRIORITY'] = $basep; } ! ! $tpl['links-listing'][] = $link_tpl; } ! // print_r(array_filter($template['links'])); exit; ! // print_r($tpl['links']); exit; ! $content = PHPWS_Template::process($tpl, 'sitemap', 'sitemap.tpl'); ! return $content; ! ! } else { ! return false; } } function getChangeFreq($id) { --- 492,604 ---- } + $tidy['url'] = $link['url']; + $tidy['key_id'] = $link['key_id']; + $tidy['update_date'] = $link['update_date']; + $tidy['parent'] = $link['parent']; + $tidy['link_order'] = $link['link_order']; ! $final[] = $tidy; } ! /* filter out the null ones and get the cleaned array */ $final = array_filter($final); + //print_r($final); exit; + + return $final; + } else { + return false; + } + } + + + function getOtherItems() + { + $final = null; + $db = new PHPWS_DB('phpws_key'); + + if (!PHPWS_Settings::get('sitemap', 'include_fc')) { + $db->addWhere('module', 'filecabinet', '!='); + } + $db->addOrder('id'); + $db->setIndexBy('id'); + // $db->setTestMode(); + $result = $db->select(); + + if (empty($result) || PHPWS_Error::logIfError($result)) { + return false; + } + + /* pre-process the menu links */ + foreach ($result as $link) { ! $link['local'] = 1; ! /* get rid of leading .'s */ ! if ($link['url'][0] == '.') { ! $link['url'] = substr($link['url'], 1); ! } ! ! /* get rid of leading /'s */ ! if ($link['url'][0] == '/') { ! $link['url'] = substr($link['url'], 1); ! } ! ! /* check for local vs remote */ ! if ($this->checkURL($link['url'])) { ! $link['local'] = 0; ! } ! /* optionally remove remote links */ ! if (PHPWS_Settings::get('sitemap', 'local_only')) { ! if (!$link['local']) { ! // $link = null; ! $tidy = null; } + } ! /* optionally remove private and non-active keyed items */ ! if (PHPWS_Settings::get('sitemap', 'respect_privs')) { ! if (!$link['active']) { ! // $link = null; ! $tidy = null; } ! if ($link['restricted']) { ! // $link = null; ! $tidy = null; } ! } ! ! /* now put the http part on local links */ ! if ($link['local']) { ! $pre = 'http://' . $_SERVER['HTTP_HOST']; ! if (dirname($_SERVER['PHP_SELF']) !== '/') { ! $pre .= dirname($_SERVER['PHP_SELF']); ! } ! $link['url'] = $pre . '/' . $link['url']; } + $tidy['url'] = $link['url']; + $tidy['key_id'] = $link['id']; + $tidy['update_date'] = $link['update_date']; + $tidy['parent'] = -1; + $tidy['link_order'] = 5; ! $final[] = $tidy; } + + /* filter out the null ones and get the cleaned array */ + $final = array_filter($final); + //print_r($final); exit; + + return $final; } + function compareURL($a, $b) + { + return strcmp($a['url'], $b['url']); + } + + function getChangeFreq($id) { Index: SM_Forms.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/sitemap/class/SM_Forms.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SM_Forms.php 1 Jul 2008 03:43:59 -0000 1.2 --- SM_Forms.php 7 Jul 2008 21:01:35 -0000 1.3 *************** *** 72,75 **** --- 72,79 ---- } + $form->addCheckbox('addkeys', 1); + $form->setMatch('addkeys', PHPWS_Settings::get('sitemap', 'addkeys')); + $form->setLabel('addkeys', dgettext('sitemap', 'Include keyed items not in menus in your sitemap')); + $form->addRadio('build_type', array(0, 1)); $form->setLabel('build_type', array(dgettext('sitemap', 'Download'), sprintf(dgettext('sitemap', 'Save to server (%s)'), PHPWS_Core::getHomeHttp() . 'sitemap.xml'))); *************** *** 128,131 **** --- 132,143 ---- $form->setLabel('allow_feed', dgettext('sitemap', 'Allow live xml feed*** of all non-restricted menus')); + $form->addCheckbox('addkeys', 1); + $form->setMatch('addkeys', PHPWS_Settings::get('sitemap', 'addkeys')); + $form->setLabel('addkeys', dgettext('sitemap', 'Include keyed items not in menus in your sitemap')); + + $form->addCheckbox('include_fc', 1); + $form->setMatch('include_fc', PHPWS_Settings::get('sitemap', 'include_fc')); + $form->setLabel('include_fc', dgettext('sitemap', 'Include file cabinet items within keyed items')); + $form->addText('cache_timeout', PHPWS_Settings::get('sitemap', 'cache_timeout')); $form->setSize('cache_timeout', 4, 4); |