1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BoxBilling |
4
|
|
|
* |
5
|
|
|
* @copyright BoxBilling, Inc (http://www.boxbilling.com) |
6
|
|
|
* @license Apache-2.0 |
7
|
|
|
* |
8
|
|
|
* Copyright BoxBilling, Inc |
9
|
|
|
* This source file is subject to the Apache-2.0 License that is bundled |
10
|
|
|
* with this source code in the file LICENSE |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Box\Mod\Seo; |
14
|
|
|
|
15
|
|
|
use Box\InjectionAwareInterface; |
16
|
|
|
|
17
|
|
|
class Service implements InjectionAwareInterface |
18
|
|
|
{ |
19
|
|
|
protected $di; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param mixed $di |
23
|
|
|
*/ |
24
|
|
|
public function setDi($di) |
25
|
|
|
{ |
26
|
|
|
$this->di = $di; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return mixed |
31
|
|
|
*/ |
32
|
|
|
public function getDi() |
33
|
|
|
{ |
34
|
|
|
return $this->di; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function pingSitemap($config) |
38
|
|
|
{ |
39
|
|
|
$systemService = $this->di['mod_service']('system'); |
40
|
|
|
|
41
|
|
|
$key = 'mod_seo_last_sitemap_submit'; |
42
|
|
|
$last_time = $systemService->getParamValue($key); |
43
|
|
|
|
44
|
|
|
if ($last_time && (time() - strtotime($last_time)) < 86400) { |
45
|
|
|
return false; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$url = urldecode(BB_URL . 'sitemap.xml'); |
49
|
|
|
if (isset($config['sitemap_google']) && $config['sitemap_google']) { |
50
|
|
|
try{ |
51
|
|
|
$link = "http://www.google.com/ping?sitemap=" . $url; |
52
|
|
|
$this->di['guzzle_client']->get($link); |
53
|
|
|
error_log('Submitted sitemap to Google'); |
54
|
|
|
}catch (\Exception $e){ |
55
|
|
|
error_log('Exception :('); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (isset($config['sitemap_bing']) && $config['sitemap_bing']) { |
60
|
|
|
$link = "http://www.bing.com/ping?sitemap=" . $url; |
61
|
|
|
$this->di['guzzle_client']->get($link); |
62
|
|
|
error_log('Submitted sitemap to Bing'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$systemService->updateParams(array($key => date('Y-m-d H:i:s'))); |
66
|
|
|
|
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function pingRss($config) |
71
|
|
|
{ |
72
|
|
|
//@todo |
73
|
|
|
return false; |
74
|
|
|
|
75
|
|
|
$rss = ''; |
|
|
|
|
76
|
|
|
$title = ''; |
77
|
|
|
$homepage = BB_URL; |
78
|
|
|
|
79
|
|
|
$rss = urldecode($rss); |
80
|
|
|
$title = urldecode($title); |
81
|
|
|
$homepage = urldecode($homepage); |
82
|
|
|
|
83
|
|
|
$fp = @fopen("http://rpc.weblogs.com/pingSiteForm?name=$title&url=" . $rss, "r"); |
84
|
|
|
@fclose($fp); |
85
|
|
|
$fp = @fopen("http://pingomatic.com/ping/?title=$title&blogurl=$homepage&rssurl=" . $rss . "&chk_weblogscom=on&chk_blogs=on&chk_feedburner=on&chk_syndic8=on&chk_newsgator=on&chk_myyahoo=on&chk_pubsubcom=on&chk_blogdigger=on&chk_blogstreet=on&chk_moreover=on&chk_weblogalot=on&chk_icerocket=on&chk_newsisfree=on&chk_topicexchange=on&chk_google=on&chk_tailrank=on&chk_postrank=on&chk_skygrid=on&chk_collecta=on&chk_superfeedr=on&chk_audioweblogs=on&chk_rubhub=on&chk_geourl=on&chk_a2b=on&chk_blogshares=on", "r"); |
86
|
|
|
@fclose($fp); |
87
|
|
|
|
88
|
|
|
return true; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public static function onBeforeAdminCronRun(\Box_Event $event) |
92
|
|
|
{ |
93
|
|
|
$di = $event->getDi(); |
94
|
|
|
$extensionService = $di['mod_service']('extension'); |
95
|
|
|
$config = $extensionService->getConfig("mod_seo"); |
96
|
|
|
|
97
|
|
|
try { |
98
|
|
|
$seoService = $di['mod_service']('seo'); |
99
|
|
|
$seoService->setDi($di); |
100
|
|
|
$seoService->pingSitemap( $config); |
101
|
|
|
$seoService->pingRss($config); |
102
|
|
|
} catch (\Exception $e) { |
103
|
|
|
error_log($e->getMessage()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return true; |
107
|
|
|
} |
108
|
|
|
} |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.