-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
384 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.