From 56262d8382b7866e19f91afaa4333d9617dc64ab Mon Sep 17 00:00:00 2001 From: voltan Date: Mon, 11 Aug 2014 11:34:30 +0430 Subject: [PATCH] Update sitemap module --- config/config.php | 2 +- config/database.php | 2 +- config/module.php | 4 +- config/navigation.php | 2 +- sql/mysql.sql | 46 ++---- src/Api/Sitemap.php | 145 ++++++++++++++---- src/Controller/Admin/IndexController.php | 89 +++-------- src/Form/GenerateFilter.php | 3 +- src/Form/GenerateForm.php | 3 +- src/Form/TopFilter.php | 8 +- src/Form/TopForm.php | 24 ++- src/Installer/Action/Install.php | 4 +- src/Installer/Action/Update.php | 117 ++++++++++++++ src/Lib/Generate.php | 43 +++--- src/Validator/FileValidation.php | 3 +- template/admin/index_list.phtml | 32 +++- template/admin/index_top.phtml | 28 +++- ...{index_topadd.phtml => index_update.phtml} | 0 18 files changed, 384 insertions(+), 171 deletions(-) create mode 100644 src/Installer/Action/Update.php rename template/admin/{index_topadd.phtml => index_update.phtml} (100%) diff --git a/config/config.php b/config/config.php index 18e572f..59a2a24 100644 --- a/config/config.php +++ b/config/config.php @@ -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 */ /** diff --git a/config/database.php b/config/database.php index 94cdc0a..6418b1d 100644 --- a/config/database.php +++ b/config/database.php @@ -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 */ /** diff --git a/config/module.php b/config/module.php index 442727a..4a77461 100644 --- a/config/module.php +++ b/config/module.php @@ -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 */ /** @@ -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', diff --git a/config/navigation.php b/config/navigation.php index aef9711..3da177c 100644 --- a/config/navigation.php +++ b/config/navigation.php @@ -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 */ /** diff --git a/sql/mysql.sql b/sql/mysql.sql index 0f7541c..294b074 100644 --- a/sql/mysql.sql +++ b/sql/mysql.sql @@ -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`) diff --git a/src/Api/Sitemap.php b/src/Api/Sitemap.php index 71ce6f3..6409e47 100644 --- a/src/Api/Sitemap.php +++ b/src/Api/Sitemap.php @@ -4,27 +4,28 @@ * * @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 */ - 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 @@ -32,8 +33,91 @@ class Sitemap extends AbstractApi * @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; @@ -44,7 +128,7 @@ 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); @@ -52,35 +136,40 @@ public function add($module, $table, $item, $loc) } /** - * 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); + } } \ No newline at end of file diff --git a/src/Controller/Admin/IndexController.php b/src/Controller/Admin/IndexController.php index 15998b0..3ce0a84 100644 --- a/src/Controller/Admin/IndexController.php +++ b/src/Controller/Admin/IndexController.php @@ -4,13 +4,12 @@ * * @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 */ - namespace Module\Sitemap\Controller\Admin; use Pi; @@ -18,18 +17,12 @@ use Pi\Paginator\Paginator; use Module\Sitemap\Form\TopForm; use Module\Sitemap\Form\TopFilter; -//use Module\Sitemap\Form\GenerateForm; -//use Module\Sitemap\Form\GenerateFilter; use Module\Sitemap\Lib\Generate; class IndexController extends ActionController { protected $listColumns = array( - 'id', 'loc', 'lastmod', 'changefreq', 'priority', 'time_create', 'module', 'table', 'item', 'status' - ); - - protected $topColumns = array( - 'id', 'loc', 'lastmod', 'changefreq', 'priority', 'time_create', 'order' + 'id', 'loc', 'lastmod', 'changefreq', 'priority', 'time_create', 'module', 'table', 'item', 'status', 'top' ); protected $generateColumns = array( @@ -79,27 +72,9 @@ public function indexAction() 'file' => 'sitemap.xml' )); } - // Set Generate Form - /* $form = new GenerateForm('generate'); - if ($this->request->isPost()) { - $data = $this->request->getPost(); - $form->setInputFilter(new GenerateFilter); - $form->setData($data); - if ($form->isValid()) { - $values = $form->getData(); - $url = array( - 'action' => 'generate', - 'file' => $values['file'], - 'start' => $values['start'], - 'end' => $values['end'], - ); - $this->jump($url, ''); - } - } */ // Set view $this->view()->setTemplate('index_index'); $this->view()->assign('generate', $generate); - //$this->view()->assign('form', $form); } public function generateAction() @@ -193,12 +168,13 @@ public function topAction() $module = $this->params('module'); $page = $this->params('page', 1); // Set info + $where = array('top' => 1); $order = array('id DESC', 'time_create DESC'); $limit = intval($this->config('admin_perpage')); $offset = (int)($page - 1) * $this->config('admin_perpage'); // Get info - $select = $this->getModel('url_top')->select()->order($order)->offset($offset)->limit($limit); - $rowset = $this->getModel('url_top')->selectWith($select); + $select = $this->getModel('url_list')->select()->where($where)->order($order)->offset($offset)->limit($limit); + $rowset = $this->getModel('url_list')->selectWith($select); // Make list foreach ($rowset as $row) { $link[$row->id] = $row->toArray(); @@ -206,8 +182,8 @@ public function topAction() } // Set paginator $count = array('count' => new \Zend\Db\Sql\Predicate\Expression('count(*)')); - $select = $this->getModel('url_top')->select()->columns($count); - $count = $this->getModel('url_top')->selectWith($select)->current()->count; + $select = $this->getModel('url_list')->select()->columns($count); + $count = $this->getModel('url_list')->selectWith($select)->current()->count; $paginator = Paginator::factory(intval($count)); $paginator->setItemCountPerPage($this->config('admin_perpage')); $paginator->setCurrentPageNumber($page); @@ -229,7 +205,7 @@ public function topAction() /** * Top update action */ - public function topupdateAction() + public function updateAction() { // Get id $id = $this->params('id'); @@ -244,17 +220,18 @@ public function topupdateAction() $values = $form->getData(); // Set just story fields foreach (array_keys($values) as $key) { - if (!in_array($key, $this->topColumns)) { + if (!in_array($key, $this->listColumns)) { unset($values[$key]); } } // Add / update time $values['time_create'] = time(); + $values['top'] = 1; // Save values if (!empty($values['id'])) { - $row = $this->getModel('url_top')->find($values['id']); + $row = $this->getModel('url_list')->find($values['id']); } else { - $row = $this->getModel('url_top')->createRow(); + $row = $this->getModel('url_list')->createRow(); } $row->assign($values); $row->save(); @@ -265,52 +242,28 @@ public function topupdateAction() } } else { if ($id) { - $values = $this->getModel('url_top')->find($id)->toArray(); + $values = $this->getModel('url_list')->find($id)->toArray(); $form->setData($values); } } // Set view - $this->view()->setTemplate('index_topadd'); + $this->view()->setTemplate('index_update'); $this->view()->assign('form', $form); $this->view()->assign('title', __('Add a link')); } - - /** - * Top update action - */ - public function topdeleteAction() - { - $this->view()->setTemplate(false); - $id = $this->params('id'); - $row = $this->getModel('url_top')->find($id); - if ($row) { - $row->delete(); - $this->jump(array('action' => 'top'), __('This link deleted')); - } else { - $this->jump(array('action' => 'top'), __('Please select link')); - } - } /** - * List update action + * Add to top action */ public function topaddAction() { // Set view $this->view()->setTemplate(false); $id = $this->params('id'); - $row_list = $this->getModel('url_list')->find($id); - if ($row_list) { - $values['loc'] = $row_list->loc; - $values['lastmod'] = $row_list->lastmod; - $values['changefreq'] = $row_list->changefreq; - $values['priority'] = $row_list->priority; - $values['time_create'] = time(); - // Save - $row_top = $this->getModel('url_top')->createRow(); - $row_top->assign($values); - $row_top->save(); - $row_list->delete(); + $row = $this->getModel('url_list')->find($id); + if ($row) { + $row->top = 1; + $row->save(); // jump $this->jump(array('action' => 'list'), __('This link add as top link')); } else { @@ -362,9 +315,9 @@ public function listAction() } /** - * Top update action + * delete link action */ - public function listdeleteAction() + public function deleteLinkAction() { $this->view()->setTemplate(false); $id = $this->params('id'); diff --git a/src/Form/GenerateFilter.php b/src/Form/GenerateFilter.php index 2613d69..9eae295 100644 --- a/src/Form/GenerateFilter.php +++ b/src/Form/GenerateFilter.php @@ -4,13 +4,12 @@ * * @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 */ - namespace Module\Sitemap\Form; use Pi; diff --git a/src/Form/GenerateForm.php b/src/Form/GenerateForm.php index 6fbbd82..d5556e2 100644 --- a/src/Form/GenerateForm.php +++ b/src/Form/GenerateForm.php @@ -4,13 +4,12 @@ * * @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 */ - namespace Module\Sitemap\Form; use Pi; diff --git a/src/Form/TopFilter.php b/src/Form/TopFilter.php index f35dba3..3a6e62e 100644 --- a/src/Form/TopFilter.php +++ b/src/Form/TopFilter.php @@ -4,13 +4,12 @@ * * @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 */ - namespace Module\Sitemap\Form; use Pi; @@ -65,5 +64,10 @@ public function __construct() ), ), )); + // status + $this->add(array( + 'name' => 'status', + 'required' => true, + )); } } \ No newline at end of file diff --git a/src/Form/TopForm.php b/src/Form/TopForm.php index 2fcb32c..3942be6 100644 --- a/src/Form/TopForm.php +++ b/src/Form/TopForm.php @@ -4,13 +4,12 @@ * * @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 */ - namespace Module\Sitemap\Form; use Pi; @@ -49,6 +48,7 @@ public function init() ), 'attributes' => array( 'type' => 'text', + 'required' => true, ) )); // lastmod @@ -60,6 +60,7 @@ public function init() 'attributes' => array( 'type' => 'text', 'value' => date("Y-m-d H:i:s"), + 'required' => true, ) )); // changefreq @@ -80,6 +81,7 @@ public function init() ), 'attributes' => array( 'value' => 'daily', + 'required' => true, ), )); // priority @@ -92,6 +94,24 @@ public function init() 'type' => 'text', ) )); + // status + $this->add(array( + 'name' => 'status', + 'type' => 'select', + 'options' => array( + 'label' => __('Status'), + 'value_options' => array( + 1 => __('Published'), + 2 => __('Pending review'), + 3 => __('Edit by user'), + 4 => __('Draft'), + 5 => __('Delete'), + ), + ), + 'attributes' => array( + 'required' => true, + ) + )); // Save $this->add(array( 'name' => 'submit', diff --git a/src/Installer/Action/Install.php b/src/Installer/Action/Install.php index b68fb03..15bcaa9 100644 --- a/src/Installer/Action/Install.php +++ b/src/Installer/Action/Install.php @@ -4,14 +4,14 @@ * * @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 */ - namespace Module\Sitemap\Installer\Action; + use Pi; use Pi\Application\Installer\Action\Install as BasicInstall; use Zend\EventManager\Event; diff --git a/src/Installer/Action/Update.php b/src/Installer/Action/Update.php new file mode 100644 index 0000000..17ec621 --- /dev/null +++ b/src/Installer/Action/Update.php @@ -0,0 +1,117 @@ + + */ +namespace Module\Sitemap\Installer\Action; + +use Pi; +use Pi\Application\Installer\Action\Update as BasicUpdate; +use Pi\Application\Installer\SqlSchema; +use Zend\EventManager\Event; + +class Update extends BasicUpdate +{ + /** + * {@inheritDoc} + */ + protected function attachDefaultListeners() + { + $events = $this->events; + $events->attach('update.pre', array($this, 'updateSchema')); + parent::attachDefaultListeners(); + + return $this; + } + + /** + * {@inheritDoc} + */ + public function updateSchema(Event $e) + { + $moduleVersion = $e->getParam('version'); + + // Set url_list model + $listModel = Pi::model('url_list', $this->module); + $listTable = $listModel->getTable(); + $listAdapter = $listModel->getAdapter(); + + // Update to version 1.2.0 + if (version_compare($moduleVersion, '1.2.0', '<')) { + + // Set url_top model + $topModel = Pi::model('url_top', $this->module); + $topTable = $topModel->getTable(); + $topAdapter = $topModel->getAdapter(); + + // Alter table drop index `loc_unique` + $sql = sprintf("ALTER TABLE %s DROP INDEX loc_unique;", + $listTable); + try { + $listAdapter->query($sql, 'execute'); + } catch (\Exception $exception) { + $this->setResult('db', array( + 'status' => false, + 'message' => 'Table alter query failed: ' + . $exception->getMessage(), + )); + return false; + } + + // Alter table add field `top` + $sql = sprintf("ALTER TABLE %s ADD `top` tinyint(1) unsigned NOT NULL default '0' , ADD INDEX (`top`) ;", + $listTable); + try { + $listAdapter->query($sql, 'execute'); + } catch (\Exception $exception) { + $this->setResult('db', array( + 'status' => false, + 'message' => 'Table alter query failed: ' + . $exception->getMessage(), + )); + return false; + } + + // insert information from url_top to url_list + $select = $topModel->select(); + $rowset = $topModel->selectWith($select); + foreach ($rowset as $row) { + // Add link + $listData = array( + 'loc' => $row->loc, + 'lastmod' => $row->lastmod, + 'changefreq' => $row->changefreq, + 'priority' => $row->priority, + 'time_create' => $row->time_create, + 'module' => '', + 'table' => '', + 'item' => '', + 'status' => 1, + 'top' => 1, + ); + $listModel->insert($listData); + } + + // Drop not used `url_top` table + try { + $sql = sprintf('DROP TABLE IF EXISTS %s', + $topTable); + $topAdapter->query($sql, 'execute'); + } catch (\Exception $exception) { + $this->setResult('db', array( + 'status' => false, + 'message' => 'Table drop failed: ' + . $exception->getMessage(), + )); + return false; + } + } + } +} \ No newline at end of file diff --git a/src/Lib/Generate.php b/src/Lib/Generate.php index f6f278b..e7e9b3d 100644 --- a/src/Lib/Generate.php +++ b/src/Lib/Generate.php @@ -4,13 +4,12 @@ * * @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 */ - namespace Module\Sitemap\Lib; use Pi; @@ -83,7 +82,7 @@ public function write($xml) */ public function indexUrl($content) { - $content[] = array( + $content[0] = array( 'uri' => Pi::url('www'), 'lastmod' => date("Y-m-d H:i:s"), 'changefreq' => 'daily', @@ -93,22 +92,22 @@ public function indexUrl($content) } /** - * Add links from url_top table on content array + * Add top links from url_list table on content array * @param array * @return array */ public function topUrl($content) { + $where = array('top' => 1); $order = array('id DESC', 'time_create DESC'); - $select = Pi::model('url_top', 'sitemap')->select()->order($order); - $rowset = Pi::model('url_top', 'sitemap')->selectWith($select); + $select = Pi::model('url_list', 'sitemap')->select()->where($where)->order($order); + $rowset = Pi::model('url_list', 'sitemap')->selectWith($select); foreach ($rowset as $row) { - $url_top[$row->id] = $row->toArray(); - $link['uri'] = $url_top[$row->id]['loc']; - $link['lastmod'] = $url_top[$row->id]['lastmod']; - $link['changefreq'] = $url_top[$row->id]['changefreq']; - $link['priority'] = $url_top[$row->id]['priority']; - $content[] = $link; + $link['uri'] = $row->loc; + $link['lastmod'] = $row->lastmod; + $link['changefreq'] = $row->changefreq; + $link['priority'] = $row->priority; + $content[$row->id] = $link; } return $content; } @@ -126,22 +125,22 @@ public function listUrl($content) // Set start and end if (!empty($this->start) && !empty($this->end) && ($this->end > $this->start)) { $where = array( - 'status' => 1, - 'id < ?' => $this->end, - 'id >= ?' => $this->start, + 'status' => 1, + 'top' => 0, + 'id < ?' => $this->end, + 'id >= ?' => $this->start, ); } else { - $where = array('status' => 1); + $where = array('status' => 1, 'top' => 0); } $select = Pi::model('url_list', 'sitemap')->select()->where($where)->order($order)->limit($limit); $rowset = Pi::model('url_list', 'sitemap')->selectWith($select); foreach ($rowset as $row) { - $url_top[$row->id] = $row->toArray(); - $link['uri'] = $url_top[$row->id]['loc']; - $link['lastmod'] = $url_top[$row->id]['lastmod']; - $link['changefreq'] = $url_top[$row->id]['changefreq']; - $link['priority'] = $url_top[$row->id]['priority']; - $content[] = $link; + $link['uri'] = $row->loc; + $link['lastmod'] = $row->lastmod; + $link['changefreq'] = $row->changefreq; + $link['priority'] = $row->priority; + $content[$row->id] = $link; } return $content; } diff --git a/src/Validator/FileValidation.php b/src/Validator/FileValidation.php index 760a08a..ce58912 100644 --- a/src/Validator/FileValidation.php +++ b/src/Validator/FileValidation.php @@ -4,13 +4,12 @@ * * @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 */ - namespace Module\Sitemap\Validator; use Pi; diff --git a/template/admin/index_list.phtml b/template/admin/index_list.phtml index fc4d051..7605e5d 100644 --- a/template/admin/index_list.phtml +++ b/template/admin/index_list.phtml @@ -9,25 +9,53 @@ + - escape($link['id']); ?> + escape($link['id']); ?>

: escape($link['loc']); ?>

: escape($link['time_create']); ?> + : escape($link['module']); ?> + + : escape($link['table']); ?> + + : escape($link['item']); ?> +

+ - + +
paginationControl($paginator, 'Sliding', 'paginator.phtml'); ?>
+

+ + + + + +

diff --git a/template/admin/index_top.phtml b/template/admin/index_top.phtml index 3866144..bc15034 100644 --- a/template/admin/index_top.phtml +++ b/template/admin/index_top.phtml @@ -1,7 +1,7 @@ css($this->assetModule('css/admin.css')); ?>

- +

@@ -14,19 +14,39 @@ + - escape($link['id']); ?> + escape($link['id']); ?> escape($link['loc']); ?> escape($link['changefreq']); ?> escape($link['time_create']); ?> - - + +
paginationControl($paginator, 'Sliding', 'paginator.phtml'); ?>
+

+ + + + + +

diff --git a/template/admin/index_topadd.phtml b/template/admin/index_update.phtml similarity index 100% rename from template/admin/index_topadd.phtml rename to template/admin/index_update.phtml