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
Roumen Damianoff
committed
Sep 16, 2012
1 parent
4c67fd4
commit be59bc2
Showing
8 changed files
with
149 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,66 @@ | ||
<?php if (!defined('BASEPATH')) exit ('No direct script access allowed'); | ||
/** | ||
* Sitemap class for ci-sitemap library. | ||
* | ||
* | ||
* @author Roumen Damianoff <roumen@dawebs.com> | ||
* @version 1.1 | ||
* @link https://github.com/RoumenMe/ci-sitemap GitHub | ||
* @version 1.2 | ||
* @link http://roumen.me/projects/ci-sitemap | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
class Sitemap | ||
{ | ||
|
||
public $records = array(); | ||
public $items = array(); | ||
public $title; | ||
public $link; | ||
|
||
|
||
/** | ||
* Add new sitemap item to $records array | ||
* Add new sitemap item to $items array | ||
* | ||
* @param string $loc | ||
* @param string $lastmod | ||
* @param string $priority | ||
* @param string $freq | ||
* @param string $title | ||
* | ||
* @return void | ||
*/ | ||
public function add($loc, $lastmod = null, $priority = '0.50', $freq = 'monthly') | ||
public function add($loc, $lastmod = null, $priority = '0.50', $freq = 'monthly', $title = null) | ||
{ | ||
$this->records[] = array( | ||
'loc' => $loc, | ||
'lastmod' => $lastmod, | ||
'priority' => $priority, | ||
'freq'=> $freq | ||
'freq' => $freq, | ||
'title' => $title | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Returns xml document with all sitemap items from $records array | ||
* Returns document with all sitemap items from $items array | ||
* | ||
* @param string $format (options: xml, html, txt, ror-rss, ror-rdf) | ||
* | ||
* @return View | ||
*/ | ||
public function render() | ||
public function render($format = 'xml') | ||
{ | ||
$CI =& get_instance(); | ||
$data['records'] = $this->records; | ||
|
||
$CI->load->view('sitemap/view', $data); | ||
|
||
if (empty($this->link)) $this->link = $CI->config->item('base_url'); | ||
if (empty($this->title)) $this->title = 'Sitemap for ' . $this->link; | ||
|
||
$data['channel'] = array( | ||
'title' => $this->title, | ||
'link' => $this->link | ||
); | ||
|
||
$data['items'] = $this->items; | ||
|
||
$CI->load->view('sitemap/'.$format, $data); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php header("Content-type: text/html; charset=utf-8"); ?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title><?php echo $channel['title']; ?></title> | ||
</head> | ||
<body> | ||
<h1><a href="<?php echo $channel['link']; ?>"><?php echo $channel['title']; ?></a></h1> | ||
<ul> | ||
<?php foreach($items as $item): ?> | ||
<li> | ||
<a href="<?php echo $item['loc']; ?>"><?php echo (empty($item['title'])) ? $item['loc'] : $item['title']; ?></a> | ||
<small>(last updated: <?php echo date('Y-m-d\TH:i:sP', strtotime($item['lastmod'])) ?>)</small> | ||
</li> | ||
<?php endforeach; ?> | ||
</ul> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php header("Content-type: text/rdf+xml; charset=utf-8"); ?> | ||
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; ?> | ||
<rdf:RDF xmlns="http://rorweb.com/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> | ||
<Resource rdf:about="sitemap"> | ||
<title><?php echo $channel['title']; ?></title> | ||
<url><?php echo $channel['link']; ?></url> | ||
<type>sitemap</type> | ||
</Resource> | ||
<?php foreach($items as $item): ?> | ||
<Resource> | ||
<url><?php echo $item['loc'] ?></url> | ||
<title><?php echo $item['title'] ?></title> | ||
<updated><?php echo date('Y-m-d\TH:i:sP', strtotime($item['lastmod'])) ?></updated> | ||
<updatePeriod><?php echo $item['freq'] ?></updatePeriod> | ||
<sortOrder><?php echo $item['priority'] ?></sortOrder> | ||
<resourceOf rdf:resource="sitemap"/> | ||
</Resource> | ||
<?php endforeach; ?> | ||
</rdf:RDF> |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php header("Content-type: text/rss+xml; charset=utf-8"); ?> | ||
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; ?> | ||
<rss version="2.0" xmlns:ror="http://rorweb.com/0.1/" > | ||
<channel> | ||
<title><?php echo $channel['title']; ?></title> | ||
<link><?php echo $channel['link']; ?></link> | ||
<?php foreach($items as $item): ?> | ||
<item> | ||
<link><?php echo $item['loc'] ?></link> | ||
<title><?php echo $item['title'] ?></title> | ||
<ror:updated><?php echo date('Y-m-d\TH:i:sP', strtotime($item['lastmod'])) ?></ror:updated> | ||
<ror:updatePeriod><?php echo $item['freq'] ?></ror:updatePeriod> | ||
<ror:sortOrder><?php echo $item['priority'] ?></ror:sortOrder> | ||
<ror:resourceOf>sitemap</ror:resourceOf> | ||
</item> | ||
<?php endforeach; ?> | ||
</channel> | ||
</rss> |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
header("Content-type: text/plain"); | ||
foreach($items as $item) echo $item['loc']."\n"; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php header("Content-type: text/xml; charset=utf-8"); ?> | ||
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; ?> | ||
<urlset | ||
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 | ||
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> | ||
<?php foreach($items as $item): ?> | ||
<url> | ||
<loc><?php echo $item['loc'] ?></loc> | ||
<priority><?php echo $item['priority'] ?></priority> | ||
<lastmod><?php echo date('Y-m-d\TH:i:sP', strtotime($item['lastmod'])) ?></lastmod> | ||
<changefreq><?php echo $item['freq'] ?></changefreq> | ||
</url> | ||
<?php endforeach; ?> | ||
</urlset> |