Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 124 lines (108 sloc) 4.148 kb
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
1 <?php
2 /**
3 * Performs an Automatic Link Verification over all the faq records
4 *
5 * You can set a cron entry:
6 * a. using PHP CLI
7 * b. using a Web Hit to this file
8 *
3daad47 @thorsten PHP 5.3
authored
9 * PHP Version 5.3
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
10 *
59bd780 @winks Bump licence to MPL 2.0
winks authored
11 * This Source Code Form is subject to the terms of the Mozilla Public License,
12 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
13 * obtain one at http://mozilla.org/MPL/2.0/.
6470782 @thorsten Fixed PHPDoc
authored
14 *
15 * @category phpMyFAQ
16 * @package CLI
17 * @author Matteo Scaramuccia <matteo@phpmyfaq.de>
18 * @author Thorsten Rinne <thorsten@phpmyfaq.de>
cca3459 @winks Bump copyright to 2012
winks authored
19 * @copyright 2006-2012 phpMyFAQ Team
59bd780 @winks Bump licence to MPL 2.0
winks authored
20 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
6470782 @thorsten Fixed PHPDoc
authored
21 * @link http://www.phpmyfaq.de
22 * @since 2006-09-17
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
23 */
24
25 /**
26 * This is the flag with which you define the language of this cron script
27 *
28 * @var const en
29 */
30 define('LANGCODE', 'en');
31
32 // Do not change anything below this line!
82a60c1 @thorsten Replace dirname(__FILE__) with __DIR__
authored
33 define('PMF_ROOT_DIR', __DIR__);
62da904 Code cleanup
thorsten authored
34 $output = '';
35 $isCronRequest = false;
36 $isRequestedByCLI = isset($_SERVER['argv']) && (isset($_SERVER['argv'][0]));
37 $isRequestedByWebLocalhost = isset($_SERVER['REMOTE_ADDR']) && ('127.0.0.1' == $_SERVER['REMOTE_ADDR']);
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
38
39 $isCronRequest = $isRequestedByCLI || $isRequestedByWebLocalhost;
40
93a0a69 Added new paths for new configuration
thorsten authored
41 if ($isCronRequest && file_exists(PMF_ROOT_DIR.'/config/database.php')) {
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
42 // Hack: set dummy values for those entries evaluated during a Web request but not during a CLI request
43 if ($isRequestedByCLI) {
62da904 Code cleanup
thorsten authored
44 $_SERVER['HTTP_HOST'] = '';
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
45 $_SERVER['HTTP_USER_AGENT'] = '';
46 }
62da904 Code cleanup
thorsten authored
47
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
48 define('IS_VALID_PHPMYFAQ', null);
f96fe88 @thorsten Include bootstrap file instead PMF_Init
authored
49
50 require_once PMF_ROOT_DIR. '/inc/Bootstrap.php';
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
51 PMF_Init::cleanRequest();
52
53 // Preload English strings
4dafef4 fixed type in require operator
anatoliy authored
54 require_once PMF_ROOT_DIR . '/lang/language_en.php';
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
55
8bb9ce5 Corrected class name
thorsten authored
56 if ((LANGCODE != 'en') && PMF_Language::isASupportedLanguage(LANGCODE)) {
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
57 // Overwrite English strings with the ones we have in the current language
58 require_once(PMF_ROOT_DIR.'/lang/language_'.LANGCODE.'.php');
59 }
60
61 require_once(PMF_ROOT_DIR.'/inc/Linkverifier.php');
6e42d6e Code cleanup
thorstenr authored
62 require_once(PMF_ROOT_DIR.'/inc/Faq.php');
2220f13 @thorsten PMF_LinkVerifier now using DIC
authored
63 $oLnk = new PMF_Linkverifier($faqConfig);
7e705a7 @thorsten Major refactoring of PMF_Faq class
authored
64 $faq = new PMF_Faq($faqConfig);
d1a09cd Now using PHP5 microtime()
thorstenr authored
65 $totStart = microtime(true);
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
66
67 // Read the data directly from the faqdata table (all faq records in all languages)
62da904 Code cleanup
thorsten authored
68 $start = microtime(true);
9e1f78e Enh: (minor) Some improvements.
matteo authored
69 $output .= ($isRequestedByWebLocalhost ? '' : "\n");
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
70 $output .= 'Extracting faq records...';
62da904 Code cleanup
thorsten authored
71
8c7cf20 Fix: v1.8 is broken: getAllRecords loads the faq into faqRecords prop…
matteo authored
72 $faq->getAllRecords();
73 $_records = $faq->faqRecords;
62da904 Code cleanup
thorsten authored
74 $tot = count($_records);
75 $end = microtime(true);
76 $output .= ' #'.$tot.', done in '.round($end - $start, 4).' sec.'.($isRequestedByWebLocalhost ? '' : "\n");;
77 $output .= ($isRequestedByWebLocalhost ? '' : "\n");
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
78 if ($isRequestedByWebLocalhost) {
6a79b16 Fix: (minor) Avoid multiple '<pre />' tags when calling it from a bro…
matteo authored
79 print '<pre>';
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
80 }
6a79b16 Fix: (minor) Avoid multiple '<pre />' tags when calling it from a bro…
matteo authored
81 $output = $output."\n";
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
82 print($output);
c7bd7c1 @thorsten Enabled Gzip compression by default
authored
83 ob_flush();
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
84
85 $i = 0;
86 foreach ($_records as $_r) {
87 $i++;
88 $output = '';
76af0a6 Using PMF_Utils::makeShortText()
thorstenr authored
89 $output .= sprintf('%0'.strlen((string)$tot).'d', $i).'/'.$tot.'. Checking '.$_r['solution_id'].' ('.PMF_Utils::makeShorterText(strip_tags($_r['title']), 8).'):';
d1a09cd Now using PHP5 microtime()
thorstenr authored
90 $start = microtime(true);
7f464b2 Enh: (minor) Let the PMF admin choose the links expiration time window.
matteo authored
91 if ($oLnk->getEntryState($_r['id'], $_r['lang'], true) === true) {
7002566 Fix: Move verifyArticleURL() to be a method of PMF_Linkverifier.
matteo authored
92 $output .= $oLnk->verifyArticleURL($_r['content'], $_r['id'], $_r['lang'], true);
7f464b2 Enh: (minor) Let the PMF admin choose the links expiration time window.
matteo authored
93 }
d1a09cd Now using PHP5 microtime()
thorstenr authored
94 $end = microtime(true);
9e1f78e Enh: (minor) Some improvements.
matteo authored
95 $output .= ' done in '.round($end - $start, 4).' sec.';
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
96 $output .= ($isRequestedByWebLocalhost ? '' : "\n");
97 if ($isRequestedByWebLocalhost) {
6a79b16 Fix: (minor) Avoid multiple '<pre />' tags when calling it from a bro…
matteo authored
98 $output = $output."\n";
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
99 }
100 print($output);
c7bd7c1 @thorsten Enabled Gzip compression by default
authored
101 ob_flush();
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
102 }
9e1f78e Enh: (minor) Some improvements.
matteo authored
103
104 $output = '';
d1a09cd Now using PHP5 microtime()
thorstenr authored
105 $totEnd = microtime(true);
9e1f78e Enh: (minor) Some improvements.
matteo authored
106 $output .= ($isRequestedByWebLocalhost ? '' : "\n");
107 $output .= 'Done in '.round($totEnd - $totStart, 4).' sec.';
108 $output .= ($isRequestedByWebLocalhost ? '' : "\n");
109 if ($isRequestedByWebLocalhost) {
6a79b16 Fix: (minor) Avoid multiple '<pre />' tags when calling it from a bro…
matteo authored
110 $output = $output."\n";
9e1f78e Enh: (minor) Some improvements.
matteo authored
111 }
112 print($output);
6a79b16 Fix: (minor) Avoid multiple '<pre />' tags when calling it from a bro…
matteo authored
113
114 if ($isRequestedByWebLocalhost) {
115 print '</pre>';
116 }
c7bd7c1 @thorsten Enabled Gzip compression by default
authored
117 ob_flush();
c5e2517 Enh: Setup a cron entry for scheduling link verification, using a PHP…
matteo authored
118 }
7002566 Fix: Move verifyArticleURL() to be a method of PMF_Linkverifier.
matteo authored
119
120 //
121 // Disconnect from database
122 //
d730615 @thorsten Removed usage of access global $db object
authored
123 $faqConfig->getDb()->close();
Something went wrong with that request. Please try again.