|
From: Verdon V. <ve...@us...> - 2008-07-01 03:44:23
|
Update of /cvsroot/phpwebsite-comm/modules/sitemap/class In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4182/class Modified Files: SM_Forms.php Sitemap.php Log Message: tweaks and fixes to prepare for release Index: Sitemap.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/sitemap/class/Sitemap.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Sitemap.php 30 Jun 2008 02:10:34 -0000 1.1.1.1 --- Sitemap.php 1 Jul 2008 03:43:59 -0000 1.2 *************** *** 30,34 **** var $panel = null; var $message = null; ! var $map = null; var $title = null; var $content = null; --- 30,34 ---- var $panel = null; var $message = null; ! var $map = null; var $title = null; var $content = null; *************** *** 50,67 **** } ! if ($this->buildXML()) { ! ! /* ! if (PHPWS_Error::logIfError($this->file->save())) { ! $this->forwardMessage(dgettext('sitemap', 'Error occurred when saving file.')); ! PHPWS_Core::reroute('index.php?module=sitemap&aop=list'); ! } else { ! $this->forwardMessage(dgettext('sitemap', 'File saved successfully.')); ! PHPWS_Core::reroute('index.php?module=sitemap&aop=list'); ! } ! */ ! echo 'success'; } else { ! $this->loadForm('new'); } --- 50,59 ---- } ! if (PHPWS_Error::logIfError($this->buildFile())) { ! $this->forwardMessage(dgettext('sitemap', 'Error occurred when creating file.')); ! PHPWS_Core::reroute('index.php?module=sitemap&aop=menu&tab=new'); } else { ! $this->forwardMessage(dgettext('sitemap', 'File created successfully.')); ! PHPWS_Core::reroute('index.php?module=sitemap&aop=menu&tab=new'); } *************** *** 179,190 **** PHPWS_Settings::set('sitemap', 'use_lastmod', 0); - if (!empty($_POST['lastmod_default'])) { - PHPWS_Settings::set('sitemap', 'lastmod_default', PHPWS_Text::parseInput(strip_tags($_POST['lastmod_default']))); - } - isset($_POST['use_priority']) ? PHPWS_Settings::set('sitemap', 'use_priority', 1) : PHPWS_Settings::set('sitemap', 'use_priority', 0); if (isset($errors)) { $this->message = implode('<br />', $errors); --- 171,189 ---- PHPWS_Settings::set('sitemap', 'use_lastmod', 0); isset($_POST['use_priority']) ? PHPWS_Settings::set('sitemap', 'use_priority', 1) : PHPWS_Settings::set('sitemap', 'use_priority', 0); + isset($_POST['allow_feed']) ? + PHPWS_Settings::set('sitemap', 'allow_feed', 1) : + PHPWS_Settings::set('sitemap', 'allow_feed', 0); + + $cache_timeout = (int)$_POST['cache_timeout']; + if ((int)$cache_timeout <= 7200) { + PHPWS_Settings::set('sitemap', 'cache_timeout', $cache_timeout); + } else { + PHPWS_Settings::reset('sitemap', 'cache_timeout'); + } + if (isset($errors)) { $this->message = implode('<br />', $errors); *************** *** 201,204 **** --- 200,215 ---- + function getMenuIds() + { + $db = new PHPWS_DB('menus'); + $db->addWhere('restricted', 0); + $result = $db->select(); + foreach ($result as $menu) { + $menus[] = $menu['id']; + } + return $menus; + } + + function getMenus($match=null, $select_name='menus', $multiple=true, $count=true) { *************** *** 249,265 **** } ! function buildXML() { $menus = $_REQUEST['menus']; if ($_REQUEST['build_type']) { /* save to server */ ! // print_r(array_filter($template['links'])); exit; ! // print_r($tpl['links']); exit; } else { /* download */ $filename = 'sitemap' . date('Ymd') . '.xml'; - $content = $this->buildMap($menus); Header('Content-Disposition: attachment; filename=' . $filename); Header('Content-Length: ' . strlen($content)); --- 260,315 ---- } + + + function mapIt() + { + if (PHPWS_Settings::get('sitemap', 'allow_feed')) { + /* what menus for auto, all non-restricted */ + $menus = $this->getMenuIds(); + + /* what to do about lastmod, nothing except for keyed items */ + $lastmod = null; + + if (PHPWS_Settings::get('sitemap', 'cache_timeout') > 0) { + $cache_key = 'sitemap_cache_key'; + $content = PHPWS_Cache::get($cache_key, PHPWS_Settings::get('sitemap', 'cache_timeout')); + if (!empty($content)) { + header('Content-type: text/xml'); + echo $content; + exit(); + } + } + + $content = $this->buildXML($menus, $lastmod); + if (PHPWS_Settings::get('sitemap', 'cache_timeout') > 0) { + PHPWS_Cache::save($cache_key, $content); + } + header('Content-type: text/xml'); + echo $content; + exit(); + } else { + PHPWS_Core::reroute(); + } + } ! ! function buildFile() { $menus = $_REQUEST['menus']; + if (isset($_REQUEST['lastmod_default'])) { + $lastmod = $_REQUEST['lastmod_default']; + } else { + $lastmod = null; + } + $content = $this->buildXML($menus, $lastmod); if ($_REQUEST['build_type']) { /* save to server */ ! $filename = 'sitemap.xml'; ! PHPWS_Core::initCoreClass('File.php'); ! return PHPWS_File::writeFile(PHPWS_HOME_DIR.$filename, $content, true); } else { /* download */ $filename = 'sitemap' . date('Ymd') . '.xml'; Header('Content-Disposition: attachment; filename=' . $filename); Header('Content-Length: ' . strlen($content)); *************** *** 271,275 **** } ! function buildMap($menus) { $final = null; --- 321,325 ---- } ! function buildXML($menus, $lastmod=null) { $final = null; *************** *** 365,369 **** $link_tpl['LASTMOD'] = date("Y-m-d", $link['update_date']); } else { ! $link_tpl['LASTMOD'] = PHPWS_Settings::get('sitemap', 'lastmod_default'); } } --- 415,419 ---- $link_tpl['LASTMOD'] = date("Y-m-d", $link['update_date']); } else { ! $link_tpl['LASTMOD'] = $lastmod; } } *************** *** 420,424 **** $pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/'; preg_match($pattern, $link, $matches); - // print_r($matches); exit; if ($matches[1]) { --- 470,473 ---- *************** *** 430,437 **** - - - - } ?> --- 479,482 ---- Index: SM_Forms.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/sitemap/class/SM_Forms.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SM_Forms.php 30 Jun 2008 02:10:34 -0000 1.1.1.1 --- SM_Forms.php 1 Jul 2008 03:43:59 -0000 1.2 *************** *** 66,73 **** $mMatch = null; } $form->addRadio('build_type', array(0, 1)); ! $form->setLabel('build_type', array(dgettext('sitemap', 'Download'), dgettext('sitemap', 'Save to server'))); $form->setMatch('build_type', $bMatch); $tpl = $form->getTemplate(); --- 66,84 ---- $mMatch = null; } + if ($_REQUEST['lastmod_default']) { + $dMatch = $_REQUEST['lastmod_default']; + } else { + $dMatch = null; + } $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'))); $form->setMatch('build_type', $bMatch); + + if (PHPWS_Settings::get('sitemap', 'use_lastmod')) { + $form->addText('lastmod_default', $dMatch); + $form->setLabel('lastmod_default', dgettext('sitemap', 'Lastmod date for non-keyed items (YYYY-MM-DD) or leave empty')); + $form->setSize('lastmod_default', 30); + } $tpl = $form->getTemplate(); *************** *** 98,102 **** $form->addCheckbox('use_change', 1); $form->setMatch('use_change', PHPWS_Settings::get('sitemap', 'use_change')); ! $form->setLabel('use_change', dgettext('sitemap', 'Add change frequency to sitemap')); $freqs= array('1'=>'always', '2'=>'hourly', '3'=>'daily', '4'=>'weekly', '5'=>'monthly', '6'=>'yearly', '7'=>'never'); --- 109,113 ---- $form->addCheckbox('use_change', 1); $form->setMatch('use_change', PHPWS_Settings::get('sitemap', 'use_change')); ! $form->setLabel('use_change', dgettext('sitemap', 'Add optional* change frequency to sitemap')); $freqs= array('1'=>'always', '2'=>'hourly', '3'=>'daily', '4'=>'weekly', '5'=>'monthly', '6'=>'yearly', '7'=>'never'); *************** *** 107,119 **** $form->addCheckbox('use_lastmod', 1); $form->setMatch('use_lastmod', PHPWS_Settings::get('sitemap', 'use_lastmod')); ! $form->setLabel('use_lastmod', dgettext('sitemap', 'Add lastmod date to sitemap')); ! ! $form->addText('lastmod_default', PHPWS_Settings::get('rolodex', 'lastmod_default')); ! $form->setLabel('lastmod_default', dgettext('sitemap', 'Lastmod date for non-keyed items (YYYY-MM-DD) or leave empty')); ! $form->setSize('lastmod_default', 30); $form->addCheckbox('use_priority', 1); $form->setMatch('use_priority', PHPWS_Settings::get('sitemap', 'use_priority')); ! $form->setLabel('use_priority', dgettext('sitemap', 'Add priority to sitemap (calculated on menu level)')); $form->addSubmit('save', dgettext('sitemap', 'Save settings')); --- 118,134 ---- $form->addCheckbox('use_lastmod', 1); $form->setMatch('use_lastmod', PHPWS_Settings::get('sitemap', 'use_lastmod')); ! $form->setLabel('use_lastmod', dgettext('sitemap', 'Add optional* lastmod date to sitemap')); $form->addCheckbox('use_priority', 1); $form->setMatch('use_priority', PHPWS_Settings::get('sitemap', 'use_priority')); ! $form->setLabel('use_priority', dgettext('sitemap', 'Add optional* priority** to sitemap')); ! ! $form->addCheckbox('allow_feed', 1); ! $form->setMatch('allow_feed', PHPWS_Settings::get('sitemap', 'allow_feed')); ! $form->setLabel('allow_feed', dgettext('sitemap', 'Allow live xml feed*** of all non-restricted menus')); ! ! $form->addText('cache_timeout', PHPWS_Settings::get('sitemap', 'cache_timeout')); ! $form->setSize('cache_timeout', 4, 4); ! $form->setLabel('cache_timeout', dgettext('sitemap', 'Cache duration in seconds for xml feed (0-7200, set to 0 to disable cache)')); $form->addSubmit('save', dgettext('sitemap', 'Save settings')); *************** *** 121,124 **** --- 136,142 ---- $tpl = $form->getTemplate(); $tpl['SETTINGS_LABEL'] = dgettext('sitemap', 'General Settings'); + $tpl['FOOTNOTE_1'] = sprintf(dgettext('sitemap', '* More information on the Sitemap protocal is available %s'), '<a href="http://www.sitemaps.org/protocol.php" target="new">'. dgettext('sitemap', 'here') .'</a>'); + $tpl['FOOTNOTE_2'] = dgettext('sitemap', '** I do a rough calculation to achieve this. Everything starts as the average 0.5. I add 0.5 to top-level itmes. I then subtract 0.1 for each step down the menu order. Nothing is scored above 1.0 or below 0.1.'); + $tpl['FOOTNOTE_3'] = dgettext('sitemap', '*** The feed respects the settings above. Lastmod date of non-keyed items will be null.'); $this->sitemap->title = dgettext('sitemap', 'Settings'); *************** *** 132,140 **** $tpl['TITLE'] = dgettext('sitemap', 'Important Information'); $tpl['INFO_1_LABEL'] = dgettext('sitemap', 'About this module:'); ! $tpl['INFO_1'] = dgettext('sitemap', 'This is the first release of sitemap for the new 1.x series phpwebsite. It\'s pretty simple and there may not be any further releases, unless bugs are found. I wrote this for a specific need I had and thought it may be of use to others also.'); ! $tpl['INFO_2_LABEL'] = dgettext('sitemap', 'Caution'); ! $tpl['INFO_2'] = dgettext('sitemap', 'This module could be dangerous. You are expected to have some idea of what you are doing, if you are going to use it. It could be used to do nasty or stupid things. I have intentionally not included file upload abilites to it. If you do not have access to the server, you should not be using this.'); ! $tpl['INFO_3_LABEL'] = null; ! $tpl['INFO_3'] = null; $tpl['INFO_4_LABEL'] = null; $tpl['INFO_4'] = null; --- 150,163 ---- $tpl['TITLE'] = dgettext('sitemap', 'Important Information'); $tpl['INFO_1_LABEL'] = dgettext('sitemap', 'About this module:'); ! $tpl['INFO_1'] = dgettext('sitemap', 'This is the first release of sitemap for the new 1.x series phpwebsite. I wrote this for a specific need I had and thought it may be of use to others also.'); ! $tpl['INFO_2_LABEL'] = dgettext('sitemap', 'What it does:'); ! $tpl['INFO_2'] = sprintf(dgettext('sitemap', 'Sitemap is used to generate a sitmap.xml file, following the standards at %s. These sitemap files are used by google and other popular search engines to help them index your website. Sitemap does this by gathering all the links from one or more of your menus, filtering and preparing according to your settings, and then writing the xml for you.'), '<a href="http://www.sitemaps.org/protocol.php" target="new">sitemaps.org</a>'); ! $tpl['INFO_3_LABEL'] = dgettext('sitemap', 'How to use it:'); ! if (MOD_REWRITE_ENABLED) { ! $modlink = 'sitemap'; ! } else { ! $modlink = 'index.php?module=sitemap'; ! } ! $tpl['INFO_3'] = sprintf(dgettext('sitemap', 'First, review the settings. Then, you can either download a sitemap file for using later, save a sitemap file to the server at %s, or allow a live and dynamic sitemap feed at %s'), PHPWS_Core::getHomeHttp() . 'sitemap.xml', PHPWS_Core::getHomeHttp() . $modlink); $tpl['INFO_4_LABEL'] = null; $tpl['INFO_4'] = null; |