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+ ?>
0 commit comments