Skip to content

Commit aebfd17

Browse files
committed
Initial Commit
Initial Commit
0 parents  commit aebfd17

3 files changed

Lines changed: 356 additions & 0 deletions

File tree

admin.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<h2 class="render-title"><?php _e('Sitemap Plugin Settings', 'sitemap_plugin'); ?></h2>
2+
<p>This plugin is created by <a href="http://tuffclassified.com">Navjot Tomer</a> for OSclass community.</p>
3+
<div id="left-side" class="well ui-rounded-corners" style="width:410px;">
4+
<form action="<?php echo osc_admin_render_plugin_url('oc-content/plugins/sitemap_plugin/admin.php'); ?>" method="post">
5+
<input type="hidden" name="action_specific" value="sitemap" />
6+
<fieldset>
7+
<div class="form-horizontal">
8+
<div class="form-row">
9+
<div class="form-label"><?php _e('Sitemap URL number', 'sitemap_plugin'); ?></div>
10+
<div class="form-controls"><input type="text" class="xlarge" name="sitemap_number" value="<?php echo osc_esc_html( osc_get_preference('sitemap_number', 'sitemap_plugin') ); ?>"></div>
11+
<div class="help-box"><?php _e('Please enter number of URLs you want to show in your xml sitemap', 'sitemap_plugin'); ?></div>
12+
</div>
13+
<br />
14+
<div class="form-row">
15+
<div class="form-label"><?php _e('Include Categories','sitemap_plugin'); ?></div>
16+
<div class="form-label-checkbox"><input type="checkbox" name="sitemap_categories" value="1" <?php echo (osc_get_preference('sitemap_categories', 'sitemap_plugin') ? 'checked' : ''); ?> > </div>
17+
<div class="help-box"><?php _e('Please Check if you want to include Categories in your list', 'sitemap_plugin'); ?></div>
18+
</div>
19+
<br />
20+
<div class="form-row">
21+
<div class="form-label"><?php _e('Include Countries','sitemap_plugin'); ?></div>
22+
<div class="form-label-checkbox"><input type="checkbox" name="sitemap_countries" value="1" <?php echo (osc_get_preference('sitemap_countries', 'sitemap_plugin') ? 'checked' : ''); ?> > </div>
23+
<div class="help-box"><?php _e('Please Check if you want to include Countries in your list', 'sitemap_plugin'); ?></div>
24+
</div>
25+
<br />
26+
<div class="form-row">
27+
<div class="form-label"><?php _e('Include Regions','sitemap_plugin'); ?></div>
28+
<div class="form-label-checkbox"><input type="checkbox" name="sitemap_regions" value="1" <?php echo (osc_get_preference('sitemap_regions', 'sitemap_plugin') ? 'checked' : ''); ?> > </div>
29+
<div class="help-box"><?php _e('Please Check if you want to include Regions in your list', 'sitemap_plugin'); ?></div>
30+
</div>
31+
<br />
32+
<div class="form-row">
33+
<div class="form-label"><?php _e('Include Cities','sitemap_plugin'); ?></div>
34+
<div class="form-label-checkbox"><input type="checkbox" name="sitemap_cities" value="1" <?php echo (osc_get_preference('sitemap_cities', 'sitemap_plugin') ? 'checked' : ''); ?> > </div>
35+
<div class="help-box"><?php _e('Please Check if you want to include Cities in your list', 'sitemap_plugin'); ?></div>
36+
</div>
37+
</div>
38+
39+
40+
<input type="submit" value="<?php _e('Save changes', 'sitemap_plugin'); ?>" class="btn btn-submit" />
41+
42+
</div>
43+
</fieldset>
44+
</form>
45+
</div>
46+
<div style="margin-top:10px">
47+
<form action="<?php echo osc_admin_render_plugin_url('oc-content/plugins/sitemap_plugin/admin.php'); ?>" method="post">
48+
<input type="hidden" name="action_specific" value="generate_sitemap" />
49+
<fieldset>
50+
<input type="submit" value="<?php _e('Generate Sitemap', 'sitemap_plugin'); ?>" class="btn btn-submit" />
51+
</fieldset>
52+
</form></div>

index.php

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?php
2+
/*
3+
Plugin Name: Sitemap Plugin
4+
Plugin URI: http://tuffclassified.com
5+
Description: Display browser and search engine friendly XML Sitemap
6+
Version: 1.0.0
7+
Author: Navjot Tomer
8+
Author URI: http://tuffclassified.com/
9+
Short Name: sitemap_plugin
10+
*/
11+
12+
function sitemap_plugin_call_after_install() {
13+
14+
osc_set_preference('sitemap_number', 5000, 'sitemap_plugin');
15+
osc_set_preference('sitemap_categories', false, 'sitemap_plugin');
16+
osc_set_preference('sitemap_countries', false, 'sitemap_plugin');
17+
osc_set_preference('sitemap_regions', false, 'sitemap_plugin');
18+
osc_set_preference('sitemap_cities', false, 'sitemap_plugin');
19+
20+
osc_reset_preferences();
21+
}
22+
function sitemap_plugin_call_after_uninstall() {
23+
24+
osc_delete_preference('sitemap_number', 'sitemap_plugin');
25+
osc_delete_preference('sitemap_categories', 'sitemap_plugin');
26+
osc_delete_preference('sitemap_countries', 'sitemap_plugin');
27+
osc_delete_preference('sitemap_regions', 'sitemap_plugin');
28+
osc_delete_preference('sitemap_cities', 'sitemap_plugin');
29+
30+
osc_reset_preferences();
31+
}
32+
33+
34+
function sitemap_actions_admin() {
35+
36+
switch( Params::getParam('action_specific') ) {
37+
38+
case('sitemap'):
39+
$enabledcat = Params::getParam('sitemap_categories');
40+
$enabledcountries = Params::getParam('sitemap_countries');
41+
$enabledregions = Params::getParam('sitemap_regions');
42+
$enabledcities = Params::getParam('sitemap_cities');
43+
osc_set_preference('sitemap_categories', ($enabledcat ? '1' : '0'), 'sitemap_plugin');
44+
osc_set_preference('sitemap_countries', ($enabledcountries ? '1' : '0'), 'sitemap_plugin');
45+
osc_set_preference('sitemap_regions', ($enabledregions ? '1' : '0'), 'sitemap_plugin');
46+
osc_set_preference('sitemap_cities', ($enabledcities ? '1' : '0'), 'sitemap_plugin');
47+
osc_set_preference('sitemap_number', Params::getParam('sitemap_number'), 'sitemap_plugin');
48+
49+
osc_add_flash_ok_message(__('Sitemap settings updated correctly', 'sitemap_plugin'), 'admin');
50+
header('Location: ' . osc_admin_render_plugin_url('sitemap_plugin/admin.php')); exit;
51+
break;
52+
case('generate_sitemap'):
53+
generate_sitemap();
54+
osc_add_flash_ok_message(__('Your XML sitemap generated successfull', 'sitemap_plugin'), 'admin');
55+
header('Location: ' . osc_admin_render_plugin_url('sitemap_plugin/admin.php')); exit;
56+
break;
57+
58+
}
59+
}
60+
osc_add_hook('init_admin', 'sitemap_actions_admin');
61+
62+
//Sitemap Function Start
63+
64+
function sitemap_add_url($url = '', $date = '', $freq = 'daily') {
65+
if( preg_match('|\?(.*)|', $url, $match) ) {
66+
$sub_url = $match[1];
67+
$param = explode('&', $sub_url);
68+
foreach($param as &$p) {
69+
list($key, $value) = explode('=', $p);
70+
$p = $key . '=' . urlencode($value);
71+
}
72+
$sub_url = implode('&', $param);
73+
$url = preg_replace('|\?.*|', '?' . $sub_url, $url);
74+
}
75+
76+
$filename = osc_base_path() . 'sitemap.xml';
77+
$xml = ' <url>' . PHP_EOL;
78+
$xml .= ' <loc>' . htmlentities($url, ENT_QUOTES, "UTF-8") . '</loc>' . PHP_EOL;
79+
$xml .= ' <lastmod>' . $date . '</lastmod>' . PHP_EOL;
80+
$xml .= ' <changefreq>' . $freq . '</changefreq>' . PHP_EOL;
81+
$xml .= ' </url>' . PHP_EOL;
82+
file_put_contents($filename, $xml, FILE_APPEND);
83+
}
84+
85+
86+
87+
function ping_engines() {
88+
89+
// GOOGLE
90+
osc_doRequest( 'http://www.google.com/webmasters/sitemaps/ping?sitemap='.urlencode(osc_base_url() . 'sitemap.xml.gz'), array());
91+
// BING
92+
osc_doRequest( 'http://www.bing.com/webmaster/ping.aspx?siteMap='.urlencode(osc_base_url() . 'sitemap.xml.gz'), array());
93+
// YAHOO!
94+
osc_doRequest( 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid='.osc_page_title().'&url='.urlencode(osc_base_url() . 'sitemap.xml.gz'), array());
95+
}
96+
97+
function generate_sitemap() {
98+
99+
$min = 1;
100+
$numurl = osc_get_preference('sitemap_number', 'sitemap_plugin');
101+
$locales = osc_get_locales();
102+
103+
$filename = osc_base_path() . 'sitemap.xml';
104+
@unlink($filename);
105+
$start_xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . '<?xml-stylesheet type="text/xsl" href="' . osc_base_url() .'oc-content/plugins/sitemap_plugin/xmlsitemap.xsl"?>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
106+
file_put_contents($filename, $start_xml);
107+
108+
// INDEX
109+
sitemap_add_url(osc_base_url(), date('Y-m-d'), 'always');
110+
111+
// Category
112+
if( osc_get_preference('sitemap_categories', 'sitemap_plugin') ) {
113+
if(osc_count_categories () > 0) {
114+
while ( osc_has_categories() ) {
115+
sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly');
116+
if ( osc_count_subcategories() > 0 ) {
117+
while ( osc_has_subcategories() ) {
118+
sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly');
119+
}
120+
}
121+
}
122+
}
123+
}
124+
125+
// countries
126+
if( osc_get_preference('sitemap_countries', 'sitemap_plugin') ) {
127+
if(osc_count_list_countries() > 0) {
128+
while ( osc_has_list_countries() ) {
129+
sitemap_add_url(osc_list_country_url(), date('Y-m-d'), 'weekly');
130+
}
131+
}
132+
}
133+
// Regions
134+
if( osc_get_preference('sitemap_regions', 'sitemap_plugin') ) {
135+
if(osc_count_list_regions() > 0) {
136+
while ( osc_has_list_regions() ) {
137+
sitemap_add_url(osc_list_region_url(), date('Y-m-d'), 'weekly');
138+
}
139+
}
140+
}
141+
// Cities
142+
if( osc_get_preference('sitemap_cities', 'sitemap_plugin') ) {
143+
if(osc_count_list_cities() > 0) {
144+
while ( osc_has_list_cities() ) {
145+
sitemap_add_url(osc_list_city_url(), date('Y-m-d'), 'weekly');
146+
}
147+
}
148+
}
149+
150+
// ITEMS
151+
$mSearch = new Search() ;
152+
$mSearch->limit(0,$numurl) ; // fetch number of item for sitemap
153+
$aItems = $mSearch->doSearch();
154+
View::newInstance()->_exportVariableToView('items', $aItems); //exporting our searched item array
155+
156+
if(osc_count_items() > 0) {
157+
while(osc_has_items()) {
158+
159+
sitemap_add_url(osc_item_url(), substr(osc_item_mod_date()!=''?osc_item_mod_date():osc_item_pub_date(), 0, 10), 'daily');
160+
161+
}
162+
}
163+
164+
165+
166+
167+
$end_xml = '</urlset>';
168+
file_put_contents($filename, $end_xml, FILE_APPEND); //create sitemap.xml
169+
@unlink(osc_base_path() . 'sitemap.xml.gz'); //remove old sitemap.xml.gz
170+
file_put_contents(osc_base_path() .'sitemap.xml.gz', gzencode( file_get_contents(osc_base_path() . 'sitemap.xml'),9)); //create sitemap.xml gzip version
171+
// PING SEARCH ENGINES
172+
ping_engines();
173+
174+
}
175+
176+
177+
function sitemap_admin() {
178+
osc_admin_render_plugin('sitemap_plugin/admin.php') ;
179+
}
180+
181+
182+
osc_admin_menu_plugins('Sitemap Plugin', osc_admin_render_plugin_url('sitemap_plugin/admin.php'), 'sitemap_plugin_submenu');
183+
// This is needed in order to be able to activate the plugin
184+
osc_register_plugin(osc_plugin_path(__FILE__), 'sitemap_plugin_call_after_install');
185+
// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel)
186+
osc_add_hook(osc_plugin_path(__FILE__)."_uninstall", 'sitemap_plugin_call_after_uninstall');
187+
osc_add_hook(osc_plugin_path(__FILE__)."_configure", 'sitemap_admin');
188+
189+
190+
?>

xmlsitemap.xsl

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet version="2.0"
3+
xmlns:html="http://www.w3.org/TR/REC-html40"
4+
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
5+
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
6+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7+
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
8+
<xsl:template match="/">
9+
<html xmlns="http://www.w3.org/1999/xhtml">
10+
<head>
11+
<title>XML Sitemap</title>
12+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
13+
<style type="text/css">
14+
body {
15+
font-family: Helvetica, Arial, sans-serif;
16+
font-size: 14px;
17+
color: #545353;
18+
}
19+
table {
20+
border: none;
21+
border-collapse: collapse;
22+
}
23+
#sitemap tr.odd {
24+
background-color: #eee;
25+
}
26+
#sitemap tbody tr:hover {
27+
background-color: #ccc;
28+
}
29+
#sitemap tbody tr:hover td, #sitemap tbody tr:hover td a {
30+
color: #000;
31+
}
32+
#content {
33+
margin: 0 auto;
34+
width: 1000px;
35+
}
36+
.expl {
37+
margin: 10px 3px;
38+
line-height: 1.3em;
39+
}
40+
.expl a {
41+
color: #da3114;
42+
font-weight: bold;
43+
}
44+
a {
45+
color: #000;
46+
text-decoration: none;
47+
}
48+
a:hover {
49+
text-decoration: underline;
50+
}
51+
td {
52+
font-size:12px;
53+
}
54+
th {
55+
text-align:left;
56+
padding-right:30px;
57+
font-size:11px;
58+
}
59+
thead th {
60+
border-bottom: 1px solid #000;
61+
cursor: pointer;
62+
}
63+
</style>
64+
</head>
65+
<body>
66+
<div id="content">
67+
<h1>XML Sitemap</h1>
68+
<p class="expl">
69+
This is a XML Sitemap which is supposed to be processed by search engines which follow the XML Sitemap standard like Ask.com, Bing, Google and Yahoo.
70+
It was generated using the classified-software <a href="http://www.osclass.org">OSclass</a> and <strong>OSclass Sitemap plugin</strong> by <a href="http://tuffclassified.com" title="Navjot Tomer">Navjot Tomer</a>.
71+
</p>
72+
<p class="expl">
73+
You can find more information about XML sitemaps on <a href="http://sitemaps.org">sitemaps.org</a>.
74+
</p>
75+
<p class="expl">
76+
This sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> URLs.
77+
</p>
78+
<table id="sitemap" cellpadding="3">
79+
<thead>
80+
<tr>
81+
<th width="75%">URL</th>
82+
83+
<th width="5%">Change Freq.</th>
84+
<th width="10%">Last Change</th>
85+
</tr>
86+
</thead>
87+
<tbody>
88+
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
89+
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
90+
<xsl:for-each select="sitemap:urlset/sitemap:url">
91+
<tr>
92+
<td>
93+
<xsl:variable name="itemURL">
94+
<xsl:value-of select="sitemap:loc"/>
95+
</xsl:variable>
96+
<a href="{$itemURL}">
97+
<xsl:value-of select="sitemap:loc"/>
98+
</a>
99+
</td>
100+
<td>
101+
<xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/>
102+
</td>
103+
<td>
104+
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
105+
</td>
106+
</tr>
107+
</xsl:for-each>
108+
</tbody>
109+
</table>
110+
</div>
111+
</body>
112+
</html>
113+
</xsl:template>
114+
</xsl:stylesheet>

0 commit comments

Comments
 (0)