Skip to content

Commit

Permalink
#24 #23 make optional element really optional
Browse files Browse the repository at this point in the history
  • Loading branch information
svanschu committed Jun 20, 2017
1 parent 20fe49a commit 24336d1
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ DATE_NEVER="Never"
SCHUWEB_SITEMAP_INTROTEXT_LABEL="Intro Text"
SCHUWEB_SITEMAP_INTROTEXT_DESC="Enter the text that will be displayed above the site map"
SCHUWEB_SITEMAP_PRIORITY="Priority"
SCHUWEB_SITEMAP_PRIORITY_DESC="The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites—it only lets the search engines know which pages you deem most important for the crawlers. The default priority of a page is 0.5. Please note that the priority you assign to a page is not likely to influence the position of your URLs in a search engine's result pages. Search engines may use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your most important pages are present in a search index. Also, please note that assigning a high priority to all of the URLs on your site is not likely to help you. Since the priority is relative, it is only used to select between URLs on your site."
SCHUWEB_SITEMAP_CHANGE_FREQUENCY="Change Frequency"
SCHUWEB_SITEMAP_CHANGE_FREQUENCY_DESC="How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page. Valid values are: always, hourly, daily, weekly, monthly, yearly, never. The value "always" should be used to describe documents that change each time they are accessed. The value "never" should be used to describe archived URLs. Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers may consider this information when making decisions, they may crawl pages marked "hourly" less frequently than that, and they may crawl pages marked "yearly" more frequently than that. Crawlers may periodically crawl pages marked "never" so that they can handle unexpected changes to those pages."
SCHUWEB_SITEMAP_PAGE_ADD_SITEMAP="New Sitemap"
SCHUWEB_SITEMAP_PAGE_EDIT_SITEMAP="Edit Sitemap"
SCHUWEB_SITEMAP_SITEMAP_DETAILS_FIELDSET="Sitemap Details"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,28 @@
<option value="0">No</option>
<option value="1">Yes</option>
</field>
<field
name="xmlInsertChangeFreq"
type="radio"
class="btn-group"
label="SCHUWEB_SITEMAP_CHANGE_FREQUENCY"
description="SCHUWEB_SITEMAP_CHANGE_FREQUENCY_DESC"
labelclass="control-label"
default="1">
<option value="0">No</option>
<option value="1">Yes</option>
</field>
<field
name="xmlInsertPriority"
type="radio"
class="btn-group"
label="SCHUWEB_SITEMAP_PRIORITY"
description="SCHUWEB_SITEMAP_PRIORITY_DESC2"
labelclass="control-label"
default="1">
<option value="0">No</option>
<option value="1">Yes</option>
</field>
</fieldset>

<fieldset name="news" label="SCHUWEB_SITEMAP_FIELDSET_NEWS_OPTIONS">
Expand Down
2 changes: 2 additions & 0 deletions components/com_schuweb_sitemap/displayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ protected function printMenuTree($menu,&$items)
$node->modified = @$item->modified;
$node->secure = $item->params->get('secure');
$node->lastmod = $item->lastmod;
$node->xmlInsertChangeFreq = $item->xmlInsertChangeFreq;
$node->xmlInsertPriority = $item->xmlInsertPriority;

// New on SchuWeb_Sitemap 2.0: send the menu params
$node->params =& $item->params;
Expand Down
4 changes: 4 additions & 0 deletions components/com_schuweb_sitemap/helpers/schuweb_sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ public static function &getMenuItems($selections)
$item->priority = $menuOptions['priority'];
$item->changefreq = $menuOptions['changefreq'];
$item->lastmod = $menuOptions['lastmod'];
$item->xmlInsertChangeFreq = $menuOptions['xmlInsertChangeFreq'];
$item->xmlInsertPriority = $menuOptions['xmlInsertPriority'];

SchuWeb_SitemapHelper::prepareMenuItem($item);
} else {
$item->priority = null;
$item->changefreq = null;
$item->lastmod = null;
$item->xmlInsertChangeFreq = null;
$item->xmlInsertPriority = null;
}

if ($item->parent_id > 1) {
Expand Down
4 changes: 4 additions & 0 deletions components/com_schuweb_sitemap/models/sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,16 @@ public function &getItem($pk = null)
$data->selections = $registry->toArray();

$lastmod = $data->params->get('xmlLastMod');
$xmlInsertChangeFreq = $data->params->get('xmlInsertChangeFreq');
$xmlInsertPriority = $data->params->get('xmlInsertPriority');
// only display the Menüs which are activated
foreach ($data->selections as $key => $selection) {
if (!isset($selection["enabled"]) || is_null($selection["enabled"]) || $selection["enabled"] != 1) {
unset($data->selections[$key]);
} else {
$data->selections[$key]["lastmod"] = $lastmod;
$data->selections[$key]["xmlInsertChangeFreq"] = $xmlInsertChangeFreq;
$data->selections[$key]["xmlInsertPriority"] =$xmlInsertPriority;
}
}

Expand Down
47 changes: 27 additions & 20 deletions components/com_schuweb_sitemap/views/xml/tmpl/default_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Guillermo Vargas ([email protected])
*/
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
defined('_JEXEC') or die('Restricted access');

require_once(JPATH_COMPONENT . '/displayer.php');

Expand Down Expand Up @@ -47,7 +47,7 @@ function __construct($config, $sitemap)
$this->uids = array();

$this->defaultLanguage = strtolower(JFactory::getLanguage()->getTag());
if (preg_match('/^([a-z]+)-.*/',$this->defaultLanguage,$matches) && !in_array($this->defaultLanguage, array(' zh-cn',' zh-tw')) ) {
if (preg_match('/^([a-z]+)-.*/', $this->defaultLanguage, $matches) && !in_array($this->defaultLanguage, array(' zh-cn', ' zh-tw'))) {
$this->defaultLanguage = $matches[1];
}

Expand All @@ -68,7 +68,7 @@ function __construct($config, $sitemap)
function printNode(&$node)
{
$node->isExcluded = false;
if ($this->isExcluded($node->id,$node->uid)) {
if ($this->isExcluded($node->id, $node->uid)) {
if (!$this->showExcluded || !$this->canEdit) {
return false;
}
Expand All @@ -91,7 +91,8 @@ function printNode(&$node)
$node->browserNav = 0;

if ($node->browserNav != 3 // ignore "no link"
&& empty($this->_links[$link])) { // ignore links that have been added already
&& empty($this->_links[$link])
) { // ignore links that have been added already
$this->count++;
$this->_links[$link] = 1;

Expand All @@ -102,17 +103,21 @@ function printNode(&$node)
$node->changefreq = 'daily';

// Get the chancefrequency and priority for this item
$changefreq = $this->getProperty('changefreq', $node->changefreq, $node->id, 'xml', $node->uid);
$priority = $this->getProperty('priority', $node->priority, $node->id, 'xml', $node->uid);
$changefreq = null;
if ($node->xmlInsertChangeFreq != 0)
$changefreq = $this->getProperty('changefreq', $node->changefreq, $node->id, 'xml', $node->uid);
$priority = null;
if ($node->xmlInsertPriority != 0)
$priority = $this->getProperty('priority', $node->priority, $node->id, 'xml', $node->uid);

echo '<url>' . "\n";
echo '<loc>', $link, '</loc>' . "\n";
if ($this->canEdit) {
if ($this->showTitle) {
echo '<title><![CDATA['.$node->name.']]></title>' . "\n";
echo '<title><![CDATA[' . $node->name . ']]></title>' . "\n";
}
if ($this->showExcluded) {
echo '<rowclass>',($node->isExcluded? 'excluded':''),'</rowclass>';
echo '<rowclass>', ($node->isExcluded ? 'excluded' : ''), '</rowclass>';
}
echo '<uid>', $node->uid, '</uid>' . "\n";
echo '<itemid>', $node->id, '</itemid>' . "\n";
Expand Down Expand Up @@ -145,16 +150,18 @@ function printNode(&$node)
echo '<image:title />';
}
if (isset($image->license) && $image->license) {
echo '<image:license>',str_replace('&', '&amp;',html_entity_decode($image->license, ENT_NOQUOTES, 'UTF-8')),'</image:license>',"\n";
echo '<image:license>', str_replace('&', '&amp;', html_entity_decode($image->license, ENT_NOQUOTES, 'UTF-8')), '</image:license>', "\n";
}
echo '</image:image>', "\n";
}
} else {
if ($modified){
if ($modified) {
echo '<lastmod>', $modified, '</lastmod>' . "\n";
}
echo '<changefreq>', $changefreq, '</changefreq>' . "\n";
echo '<priority>', $priority, '</priority>' . "\n";
if ($changefreq)
echo '<changefreq>', $changefreq, '</changefreq>' . "\n";
if ($priority)
echo '<priority>', $priority, '</priority>' . "\n";
}
} else {
if (isset($node->keywords)) {
Expand All @@ -168,12 +175,12 @@ function printNode(&$node)
}

echo "<news:news>\n";
echo '<news:publication>'."\n";
echo ' <news:name>'.(htmlspecialchars($this->sitemap->params->get('news_publication_name'))).'</news:name>'."\n";
echo ' <news:language>'.$node->language.'</news:language>'."\n";
echo '</news:publication>'."\n";
echo '<news:publication>' . "\n";
echo ' <news:name>' . (htmlspecialchars($this->sitemap->params->get('news_publication_name'))) . '</news:name>' . "\n";
echo ' <news:language>' . $node->language . '</news:language>' . "\n";
echo '</news:publication>' . "\n";
echo '<news:publication_date>', $modified, '</news:publication_date>' . "\n";
echo '<news:title><![CDATA['.$node->name.']]></news:title>' . "\n";
echo '<news:title><![CDATA[' . $node->name . ']]></news:title>' . "\n";
if ($keywords) {
echo '<news:keywords>', $keywords, '</news:keywords>' . "\n";
}
Expand All @@ -190,9 +197,9 @@ function printNode(&$node)
*
* @param string $property The property that is needed
* @param string $value The default value if the property is not found
* @param int $Itemid The menu item id
* @param string $view (xml / html)
* @param int $uid Unique id of the element on the sitemap
* @param int $Itemid The menu item id
* @param string $view (xml / html)
* @param int $uid Unique id of the element on the sitemap
* (the id asigned by the extension)
* @return string
*/
Expand Down
20 changes: 14 additions & 6 deletions components/com_schuweb_sitemap/views/xml/tmpl/default_xsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,14 @@ function checkToggleExcluded(result,xmlResponse) {
<td><?php echo ($showTitle? JText::_('COM_SCHUWEB_SITEMAP_TITLE').' / ' : ''); ?><?php echo JText::_('COM_SCHUWEB_SITEMAP_URL'); ?></td>
<?php if (!$this->isImages): ?>
<?php if ($this->item->params->get('xmlLastMod') != 0) : ?>
<td><?php echo JText::_('COM_SCHUWEB_SITEMAP_LASTMOD'); ?></td>
<td><?php echo JText::_('COM_SCHUWEB_SITEMAP_LASTMOD'); ?></td>
<?php endif ?>
<?php if ($this->item->params->get('xmlInsertChangeFreq') != 0) : ?>
<td><?php echo JText::_('COM_SCHUWEB_SITEMAP_CHANGEFREQ'); ?></td>
<?php endif; ?>
<?php if ($this->item->params->get('xmlInsertPriority') != 0) : ?>
<td><?php echo JText::_('COM_SCHUWEB_SITEMAP_PRIORITY'); ?></td>
<?php endif ?>
<td><?php echo JText::_('COM_SCHUWEB_SITEMAP_CHANGEFREQ'); ?></td>
<td><?php echo JText::_('COM_SCHUWEB_SITEMAP_PRIORITY'); ?></td>
<?php endif ?>
</tr>
<xsl:for-each select="xna:urlset/xna:url">
Expand Down Expand Up @@ -458,14 +462,18 @@ function checkToggleExcluded(result,xmlResponse) {
</td>
<?php if (!$this->isImages): ?>
<?php if ($this->item->params->get('xmlLastMod') != 0) : ?>
<td><xsl:value-of select="xna:lastmod"/></td>
<td><xsl:value-of select="xna:lastmod"/></td>
<?php endif; ?>
<?php if ($this->canEdit): ?>
<td class="editable" onClick="showOptions(this,'changefreq','{$UID}','{$ItemID}',event);" ><xsl:value-of select="xna:changefreq"/></td>
<td class="editable" onClick="showOptions(this,'priority','{$UID}','{$ItemID}',event);"><xsl:value-of select="xna:priority"/></td>
<?php else: ?>
<td><xsl:value-of select="xna:changefreq"/></td>
<td><xsl:value-of select="xna:priority"/></td>
<?php if ($this->item->params->get('xmlInsertChangeFreq') != 0) : ?>
<td><xsl:value-of select="xna:changefreq"/></td>
<?php endif; ?>
<?php if ($this->item->params->get('xmlInsertPriority') != 0) : ?>
<td><xsl:value-of select="xna:priority"/></td>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</tr>
Expand Down

0 comments on commit 24336d1

Please sign in to comment.