Skip to content

Commit

Permalink
Update sitemap module
Browse files Browse the repository at this point in the history
  • Loading branch information
voltan committed Aug 11, 2014
1 parent 1839305 commit 56262d8
Show file tree
Hide file tree
Showing 18 changed files with 384 additions and 171 deletions.
2 changes: 1 addition & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @link http://code.pialog.org for the Pi Engine source repository
* @copyright Copyright (c) Pi Engine http://pialog.org
* @license http://pialog.org/license.txt New BSD License
* @license http://pialog.org/license.txt BSD 3-Clause License
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @link http://code.pialog.org for the Pi Engine source repository
* @copyright Copyright (c) Pi Engine http://pialog.org
* @license http://pialog.org/license.txt New BSD License
* @license http://pialog.org/license.txt BSD 3-Clause License
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions config/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @link http://code.pialog.org for the Pi Engine source repository
* @copyright Copyright (c) Pi Engine http://pialog.org
* @license http://pialog.org/license.txt New BSD License
* @license http://pialog.org/license.txt BSD 3-Clause License
*/

/**
Expand All @@ -15,7 +15,7 @@
'meta' => array(
'title' => _a('Sitemap'),
'description' => _a('For generate sitemap.xml.'),
'version' => '1.1.1',
'version' => '1.2.0',
'license' => 'New BSD',
'logo' => 'image/logo.png',
'readme' => 'docs/readme.txt',
Expand Down
2 changes: 1 addition & 1 deletion config/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @link http://code.pialog.org for the Pi Engine source repository
* @copyright Copyright (c) Pi Engine http://pialog.org
* @license http://pialog.org/license.txt New BSD License
* @license http://pialog.org/license.txt BSD 3-Clause License
*/

/**
Expand Down
46 changes: 16 additions & 30 deletions sql/mysql.sql
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
CREATE TABLE `{url_list}` (
`id` int(10) unsigned NOT NULL auto_increment,
`loc` varchar(255) NOT NULL,
`lastmod` varchar(64) NOT NULL,
`changefreq` varchar(64) NOT NULL,
`priority` varchar(64) NOT NULL,
`time_create` int(10) unsigned NOT NULL,
`module` varchar(64) NOT NULL,
`table` varchar(64) NOT NULL,
`item` int(10) unsigned NOT NULL,
`status` tinyint(1) unsigned NOT NULL,
`loc` varchar(255) NOT NULL default '',
`lastmod` varchar(64) NOT NULL default '',
`changefreq` varchar(64) NOT NULL default '',
`priority` varchar(64) NOT NULL default '',
`time_create` int(10) unsigned NOT NULL default '0',
`module` varchar(64) NOT NULL default '',
`table` varchar(64) NOT NULL default '',
`item` int(10) unsigned NOT NULL default '0',
`status` tinyint(1) unsigned NOT NULL default '0',
`top` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `loc` (`loc`),
UNIQUE KEY `loc_unique` (`module`, `table`, `item`),
KEY `status` (`status`),
KEY `time_create` (`time_create`),
KEY `module` (`module`),
KEY `table` (`table`),
KEY `item` (`item`),
KEY `top` (`top`),
KEY `create_id` (`id`, `time_create`, `status`),
KEY `module_table` (`module`, `table`)
);

CREATE TABLE `{url_top}` (
`id` int(10) unsigned NOT NULL auto_increment,
`loc` varchar(255) NOT NULL,
`lastmod` varchar(64) NOT NULL,
`changefreq` varchar(64) NOT NULL,
`priority` varchar(64) NOT NULL,
`time_create` int(10) unsigned NOT NULL,
`order` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `loc` (`loc`),
KEY `time_create` (`time_create`),
KEY `create_id` (`id`, `time_create`),
KEY `order_id` (`id`, `order`)
);

CREATE TABLE `{generate}` (
`id` int(10) unsigned NOT NULL auto_increment,
`file` varchar(64) NOT NULL,
`time_create` int(10) unsigned NOT NULL,
`time_update` int(10) unsigned NOT NULL,
`start` int(10) unsigned NOT NULL,
`end` int(10) unsigned NOT NULL,
`file` varchar(64) NOT NULL default '',
`time_create` int(10) unsigned NOT NULL default '0',
`time_update` int(10) unsigned NOT NULL default '0',
`start` int(10) unsigned NOT NULL default '0',
`end` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `file` (`file`),
KEY `time_create` (`time_create`)
Expand Down
145 changes: 117 additions & 28 deletions src/Api/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,120 @@
*
* @link http://code.pialog.org for the Pi Engine source repository
* @copyright Copyright (c) Pi Engine http://pialog.org
* @license http://pialog.org/license.txt New BSD License
* @license http://pialog.org/license.txt BSD 3-Clause License
*/

/**
* @author Hossein Azizabadi <[email protected]>
*/

namespace Module\Sitemap\Api;

use Pi;
use Pi\Application\Api\AbstractApi;
use Module\Sitemap\Lib\Generat;
use Zend\Validator\Uri as UriValidator;

/**
* Pi::api('sitemap', 'sitemap')->add($module, $table, $item, $loc);
* Pi::api('sitemap', 'sitemap')->update($module, $table, $item, $loc);
* Pi::api('sitemap', 'sitemap')->singleLink($loc, $status, $module, $table, $item);
* Pi::api('sitemap', 'sitemap')->groupLink($loc, $status, $module, $table, $item);
* Pi::api('sitemap', 'sitemap')->remove($loc);
* Pi::api('sitemap', 'sitemap')->removeAll($module, $table);
*/
class Sitemap extends AbstractApi
{
/**
/**
* Old method , will remove
* Add new link to url_list table
*
* @param string $module
* @param string $table
* @param int $item
* @param string $loc
*/
public function add($module, $table, $item, $loc)
public function add($module, $table, $item, $loc, $status = 1)
{
$this->singleLink($loc, $status, $module, $table, $item);
}

/**
* Old method , will remove
* Update link to url_list table
*
* @param string $module
* @param string $table
* @param int $item
* @param string $loc
*/
public function update($module, $table, $item, $loc, $status = 1)
{
$this->singleLink($loc, $status, $module, $table, $item);
}

/**
* Add or Update link to url_list table
*
* @param string $loc
* @param int $status
* @param string $module
* @param string $table
* @param int $item
*/
public function singleLink($loc, $status = 1, $module = '', $table = '', $item = '')
{
// Check loc not empty
if (empty($loc)) {
return '';
}
// Check loc is valid
$validator = new UriValidator;
if (!$validator->isValid($loc)) {
return '';
}
// Check loc exist or not
$row = Pi::model('url_list', 'sitemap')->find($loc, 'loc');
if (!empty($row) && is_object($row)) {
$row->loc = $loc;
$row->lastmod = date("Y-m-d H:i:s");
$row->status = intval($status);
$row->save();
} else {
// Set
$values = array();
$values['loc'] = $loc;
$values['lastmod'] = date("Y-m-d H:i:s");
$values['changefreq'] = 'daily';
$values['priority'] = '';
$values['time_create'] = time();
$values['module'] = $module;
$values['table'] = $table;
$values['item'] = intval($item);
$values['status'] = intval($status);
// Save
$row = Pi::model('url_list', 'sitemap')->createRow();
$row->assign($values);
$row->save();
}
}

/**
* Add group of links to url_list table whitout check is exist or not
*
* @param string $loc
* @param int $status
* @param string $module
* @param string $table
* @param int $item
*/
public function groupLink($loc, $status = 1, $module = '', $table = '', $item = '')
{
// Check loc not empty
if (empty($loc)) {
return '';
}
// Check loc is valid
$validator = new UriValidator;
if (!$validator->isValid($loc)) {
return '';
}
// Set
$values = array();
$values['loc'] = $loc;
Expand All @@ -44,43 +128,48 @@ public function add($module, $table, $item, $loc)
$values['module'] = $module;
$values['table'] = $table;
$values['item'] = intval($item);
$values['status'] = 1;
$values['status'] = intval($status);
// Save
$row = Pi::model('url_list', 'sitemap')->createRow();
$row->assign($values);
$row->save();
}

/**
* Update link to url_list table
* Remove link from url_list table
*
* @param string $module
* @param string $table
* @param int $item
* @param string $loc
*/
public function update($module, $table, $item, $loc)
public function remove($loc)
{
$where = array('module' => $module, 'table' => $table, 'item' => $item);
$select = Pi::model('url_list', 'sitemap')->select()->where($where)->limit(1);
$row = Pi::model('url_list', 'sitemap')->selectWith($select)->current();
if (!empty($row) && is_object($row)) {
$row->loc = $loc;
$row->lastmod = date("Y-m-d H:i:s");
$row->save();
} else {
$this->add($module, $table, $item, $loc);
// Check module
if (empty($loc)) {
return '';
}
}
// Remove
$where = array('loc' => $loc);
Pi::model('url_list', 'sitemap')->delete($where);
}

/**
* Remove link from url_list table
*
* @param string $loc
* @param string $module
* @param string $table
*/
public function remove($loc)
public function removeAll($module, $table = '')
{
$row = Pi::model('url_list', 'sitemap')->find($loc, 'loc');
$row->delete();
}
// Check module
if (empty($module)) {
return '';
}
// Check table
if (empty($table)) {
$where = array('module' => $module);
} else {
$where = array('module' => $module, 'table' => $table);
}
// Remove
Pi::model('url_list', 'sitemap')->delete($where);
}
}
Loading

0 comments on commit 56262d8

Please sign in to comment.