@@ -17,15 +17,15 @@ discard block |
||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function get_js() { |
| 20 | - return file_get_contents(dirname(__FILE__) . "/share.js"); |
|
| 20 | + return file_get_contents(dirname(__FILE__)."/share.js"); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function get_css() { |
| 24 | - return file_get_contents(dirname(__FILE__) . "/share.css"); |
|
| 24 | + return file_get_contents(dirname(__FILE__)."/share.css"); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function get_prefs_js() { |
| 28 | - return file_get_contents(dirname(__FILE__) . "/share_prefs.js"); |
|
| 28 | + return file_get_contents(dirname(__FILE__)."/share_prefs.js"); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | public function hook_prefs_tab_section($id) { |
| 43 | 43 | if ($id == "prefFeedsPublishedGenerated") { |
| 44 | 44 | |
| 45 | - print "<h3>" . __("You can disable all articles shared by unique URLs here.") . "</h3>"; |
|
| 45 | + print "<h3>".__("You can disable all articles shared by unique URLs here.")."</h3>"; |
|
| 46 | 46 | |
| 47 | 47 | print "<button class='alt-danger' dojoType='dijit.form.Button' onclick=\"return Plugins.Share.clearKeys()\">". |
| 48 | 48 | __('Unshare all articles')."</button> "; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $sth->execute([$uuid, $param, $_SESSION['uid']]); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - print "<header>" . __("You can share this article by the following unique URL:") . "</header>"; |
|
| 103 | + print "<header>".__("You can share this article by the following unique URL:")."</header>"; |
|
| 104 | 104 | |
| 105 | 105 | $url_path = get_self_url_prefix(); |
| 106 | 106 | $url_path .= "/public.php?op=share&key=$uuid"; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function get_js() { |
| 21 | - return file_get_contents(dirname(__FILE__) . "/mail.js"); |
|
| 21 | + return file_get_contents(dirname(__FILE__)."/mail.js"); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function save() { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
| 36 | 36 | title=\"<i class='material-icons'>mail</i> ".__('Mail plugin')."\">"; |
| 37 | 37 | |
| 38 | - print "<p>" . __("You can set predefined email addressed here (comma-separated list):") . "</p>"; |
|
| 38 | + print "<p>".__("You can set predefined email addressed here (comma-separated list):")."</p>"; |
|
| 39 | 39 | |
| 40 | 40 | print "<form dojoType=\"dijit.form.Form\">"; |
| 41 | 41 | |
@@ -115,17 +115,17 @@ discard block |
||
| 115 | 115 | $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
| 116 | 116 | |
| 117 | 117 | if (count($ids) > 1) { |
| 118 | - $subject = __("[Forwarded]") . " " . __("Multiple articles"); |
|
| 118 | + $subject = __("[Forwarded]")." ".__("Multiple articles"); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | while ($line = $sth->fetch()) { |
| 122 | 122 | |
| 123 | 123 | if (!$subject) |
| 124 | - $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
| 124 | + $subject = __("[Forwarded]")." ".htmlspecialchars($line["title"]); |
|
| 125 | 125 | |
| 126 | 126 | $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); |
| 127 | 127 | $tnote = strip_tags($line["note"]); |
| 128 | - if( $tnote != ''){ |
|
| 128 | + if ($tnote != '') { |
|
| 129 | 129 | $tpl->setVariable('ARTICLE_NOTE', $tnote, true); |
| 130 | 130 | $tpl->addBlock('note'); |
| 131 | 131 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | "message" => $message]); |
| 211 | 211 | |
| 212 | 212 | if (!$rc) { |
| 213 | - $reply['error'] = $mailer->error(); |
|
| 213 | + $reply['error'] = $mailer->error(); |
|
| 214 | 214 | } else { |
| 215 | 215 | //save_email_address($destination); |
| 216 | 216 | $reply['message'] = "UPDATE_COUNTERS"; |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function hook_prefs_tab($args) { |
| 33 | - if ($args != "prefPrefs") return; |
|
| 33 | + if ($args != "prefPrefs") { |
|
| 34 | + return; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
| 36 | 38 | title=\"<i class='material-icons'>mail</i> ".__('Mail plugin')."\">"; |
@@ -94,7 +96,9 @@ discard block |
||
| 94 | 96 | $user_name = htmlspecialchars($row['full_name']); |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | - if (!$user_name) $user_name = $_SESSION['name']; |
|
| 99 | + if (!$user_name) { |
|
| 100 | + $user_name = $_SESSION['name']; |
|
| 101 | + } |
|
| 98 | 102 | |
| 99 | 103 | print_hidden("from_email", "$user_email"); |
| 100 | 104 | print_hidden("from_name", "$user_name"); |
@@ -120,8 +124,9 @@ discard block |
||
| 120 | 124 | |
| 121 | 125 | while ($line = $sth->fetch()) { |
| 122 | 126 | |
| 123 | - if (!$subject) |
|
| 124 | - $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
| 127 | + if (!$subject) { |
|
| 128 | + $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
| 129 | + } |
|
| 125 | 130 | |
| 126 | 131 | $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); |
| 127 | 132 | $tnote = strip_tags($line["note"]); |
@@ -19,9 +19,9 @@ discard block |
||
| 19 | 19 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
| 20 | 20 | $host->add_hook($host::HOOK_PREFS_TAB, $this); |
| 21 | 21 | |
| 22 | - require_once __DIR__ . "/filter_base.php"; |
|
| 22 | + require_once __DIR__."/filter_base.php"; |
|
| 23 | 23 | |
| 24 | - $filters = array_merge(glob(__DIR__ . "/filters.local/*.php"), glob(__DIR__ . "/filters/*.php")); |
|
| 24 | + $filters = array_merge(glob(__DIR__."/filters.local/*.php"), glob(__DIR__."/filters/*.php")); |
|
| 25 | 25 | $names = []; |
| 26 | 26 | |
| 27 | 27 | foreach ($filters as $file) { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
| 51 | 51 | title=\"<i class='material-icons'>photo</i> ".__('Feeds supported by af_comics')."\">"; |
| 52 | 52 | |
| 53 | - print "<p>" . __("The following comics are currently supported:") . "</p>"; |
|
| 53 | + print "<p>".__("The following comics are currently supported:")."</p>"; |
|
| 54 | 54 | |
| 55 | 55 | $comics = array("GoComics"); |
| 56 | 56 | |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | return $feed_data; |
| 94 | 94 | |
| 95 | 95 | if (preg_match('#^https?://(?:feeds\.feedburner\.com/uclick|www\.gocomics\.com)/([-a-z0-9]+)$#i', $fetch_url, $comic)) { |
| 96 | - $site_url = 'https://www.gocomics.com/' . $comic[1]; |
|
| 96 | + $site_url = 'https://www.gocomics.com/'.$comic[1]; |
|
| 97 | 97 | |
| 98 | - $article_link = $site_url . date('/Y/m/d'); |
|
| 98 | + $article_link = $site_url.date('/Y/m/d'); |
|
| 99 | 99 | |
| 100 | 100 | $body = fetch_file_contents(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false)); |
| 101 | 101 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $title = date('l, F d, Y'); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - foreach (['srcset', 'sizes', 'data-srcset', 'width'] as $attr ) { |
|
| 134 | + foreach (['srcset', 'sizes', 'data-srcset', 'width'] as $attr) { |
|
| 135 | 135 | $node->removeAttribute($attr); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -45,7 +45,9 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function hook_prefs_tab($args) { |
| 48 | - if ($args != "prefFeeds") return; |
|
| 48 | + if ($args != "prefFeeds") { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
| 51 | 53 | title=\"<i class='material-icons'>photo</i> ".__('Feeds supported by af_comics')."\">"; |
@@ -77,8 +79,9 @@ discard block |
||
| 77 | 79 | |
| 78 | 80 | public function hook_article_filter($article) { |
| 79 | 81 | foreach ($this->filters as $f) { |
| 80 | - if ($f->process($article)) |
|
| 81 | - break; |
|
| 82 | + if ($f->process($article)) { |
|
| 83 | + break; |
|
| 84 | + } |
|
| 82 | 85 | } |
| 83 | 86 | |
| 84 | 87 | return $article; |
@@ -89,8 +92,9 @@ discard block |
||
| 89 | 92 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 90 | 93 | */ |
| 91 | 94 | public function hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass) { |
| 92 | - if ($auth_login || $auth_pass) |
|
| 93 | - return $feed_data; |
|
| 95 | + if ($auth_login || $auth_pass) { |
|
| 96 | + return $feed_data; |
|
| 97 | + } |
|
| 94 | 98 | |
| 95 | 99 | if (preg_match('#^https?://(?:feeds\.feedburner\.com/uclick|www\.gocomics\.com)/([-a-z0-9]+)$#i', $fetch_url, $comic)) { |
| 96 | 100 | $site_url = 'https://www.gocomics.com/' . $comic[1]; |
@@ -153,29 +157,35 @@ discard block |
||
| 153 | 157 | |
| 154 | 158 | $tpl->addBlock('feed'); |
| 155 | 159 | |
| 156 | - if ($tpl->generateOutputToString($tmp_data)) |
|
| 157 | - $feed_data = $tmp_data; |
|
| 160 | + if ($tpl->generateOutputToString($tmp_data)) { |
|
| 161 | + $feed_data = $tmp_data; |
|
| 162 | + } |
|
| 158 | 163 | } |
| 159 | 164 | |
| 160 | 165 | return $feed_data; |
| 161 | 166 | } |
| 162 | 167 | |
| 163 | 168 | public function hook_subscribe_feed($contents, $url, $auth_login, $auth_pass) { |
| 164 | - if ($auth_login || $auth_pass) |
|
| 165 | - return $contents; |
|
| 169 | + if ($auth_login || $auth_pass) { |
|
| 170 | + return $contents; |
|
| 171 | + } |
|
| 166 | 172 | |
| 167 | - if (preg_match('#^https?://www\.gocomics\.com/([-a-z0-9]+)$#i', $url)) |
|
| 168 | - return '<?xml version="1.0" encoding="utf-8"?>'; // Get is_html() to return false. |
|
| 173 | + if (preg_match('#^https?://www\.gocomics\.com/([-a-z0-9]+)$#i', $url)) { |
|
| 174 | + return '<?xml version="1.0" encoding="utf-8"?>'; |
|
| 175 | + } |
|
| 176 | + // Get is_html() to return false. |
|
| 169 | 177 | |
| 170 | 178 | return $contents; |
| 171 | 179 | } |
| 172 | 180 | |
| 173 | 181 | public function hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass) { |
| 174 | - if ($auth_login || $auth_pass) |
|
| 175 | - return $basic_info; |
|
| 182 | + if ($auth_login || $auth_pass) { |
|
| 183 | + return $basic_info; |
|
| 184 | + } |
|
| 176 | 185 | |
| 177 | - if (preg_match('#^https?://www\.gocomics\.com/([-a-z0-9]+)$#i', $fetch_url, $matches)) |
|
| 178 | - $basic_info = array('title' => ucfirst($matches[1]), 'site_url' => $matches[0]); |
|
| 186 | + if (preg_match('#^https?://www\.gocomics\.com/([-a-z0-9]+)$#i', $fetch_url, $matches)) { |
|
| 187 | + $basic_info = array('title' => ucfirst($matches[1]), 'site_url' => $matches[0]); |
|
| 188 | + } |
|
| 179 | 189 | |
| 180 | 190 | return $basic_info; |
| 181 | 191 | } |
@@ -14,11 +14,11 @@ |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function get_css() { |
| 17 | - return file_get_contents(__DIR__ . "/init.css"); |
|
| 17 | + return file_get_contents(__DIR__."/init.css"); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function get_js() { |
| 21 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 21 | + return file_get_contents(__DIR__."/init.js"); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function api_version() { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | user_error("Your PHP has a separate systemwide Sphinx client installed which conflicts with the client library used by tt-rss. Either remove the system library or disable Sphinx support."); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - require_once __DIR__ . "/sphinxapi.php"; |
|
| 20 | + require_once __DIR__."/sphinxapi.php"; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function hook_search($search) { |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | $sphinxpair = explode(":", SPHINX_SERVER, 2); |
| 30 | 30 | |
| 31 | - $sphinxClient->SetServer($sphinxpair[0], (int)$sphinxpair[1]); |
|
| 31 | + $sphinxClient->SetServer($sphinxpair[0], (int) $sphinxpair[1]); |
|
| 32 | 32 | $sphinxClient->SetConnectTimeout(1); |
| 33 | 33 | |
| 34 | 34 | $sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30, |
@@ -53,10 +53,11 @@ |
||
| 53 | 53 | |
| 54 | 54 | $ids = join(",", $ids); |
| 55 | 55 | |
| 56 | - if ($ids) |
|
| 57 | - return array("ref_id IN ($ids)", array()); |
|
| 58 | - else |
|
| 59 | - return array("ref_id = -1", array()); |
|
| 56 | + if ($ids) { |
|
| 57 | + return array("ref_id IN ($ids)", array()); |
|
| 58 | + } else { |
|
| 59 | + return array("ref_id = -1", array()); |
|
| 60 | + } |
|
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | public function api_version() { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function get_js() { |
| 44 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 44 | + return file_get_contents(__DIR__."/init.js"); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function showrelated() { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | print "</div>"; |
| 100 | 100 | |
| 101 | - print "<div style='text-align : right' class='text-muted'>" . smart_date_time(strtotime($line["updated"])) . "</div>"; |
|
| 101 | + print "<div style='text-align : right' class='text-muted'>".smart_date_time(strtotime($line["updated"]))."</div>"; |
|
| 102 | 102 | |
| 103 | 103 | print "</li>"; |
| 104 | 104 | } |
@@ -163,24 +163,24 @@ discard block |
||
| 163 | 163 | print_hidden("method", "save"); |
| 164 | 164 | print_hidden("plugin", "af_psql_trgm"); |
| 165 | 165 | |
| 166 | - print "<h2>" . __("Global settings") . "</h2>"; |
|
| 166 | + print "<h2>".__("Global settings")."</h2>"; |
|
| 167 | 167 | |
| 168 | 168 | print_notice("Enable for specific feeds in the feed editor."); |
| 169 | 169 | |
| 170 | 170 | print "<fieldset>"; |
| 171 | 171 | |
| 172 | - print "<label>" . __("Minimum similarity:") . "</label> "; |
|
| 172 | + print "<label>".__("Minimum similarity:")."</label> "; |
|
| 173 | 173 | print "<input dojoType=\"dijit.form.NumberSpinner\" |
| 174 | 174 | placeholder=\"0.75\" id='psql_trgm_similarity' |
| 175 | 175 | required=\"1\" name=\"similarity\" value=\"$similarity\">"; |
| 176 | 176 | |
| 177 | - print "<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>" . |
|
| 178 | - __("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking.") . |
|
| 177 | + print "<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>". |
|
| 178 | + __("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking."). |
|
| 179 | 179 | "</div>"; |
| 180 | 180 | |
| 181 | 181 | print "</fieldset><fieldset>"; |
| 182 | 182 | |
| 183 | - print "<label>" . __("Minimum title length:") . "</label> "; |
|
| 183 | + print "<label>".__("Minimum title length:")."</label> "; |
|
| 184 | 184 | print "<input dojoType=\"dijit.form.NumberSpinner\" |
| 185 | 185 | placeholder=\"32\" |
| 186 | 186 | required=\"1\" name=\"min_title_length\" value=\"$min_title_length\">"; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | print "<label class='checkbox'>"; |
| 191 | 191 | print_checkbox("enable_globally", $enable_globally); |
| 192 | - print " " . __("Enable for all feeds:"); |
|
| 192 | + print " ".__("Enable for all feeds:"); |
|
| 193 | 193 | print "</label>"; |
| 194 | 194 | |
| 195 | 195 | print "</fieldset>"; |
@@ -204,14 +204,14 @@ discard block |
||
| 204 | 204 | $this->host->set($this, "enabled_feeds", $enabled_feeds); |
| 205 | 205 | |
| 206 | 206 | if (count($enabled_feeds) > 0) { |
| 207 | - print "<h3>" . __("Currently enabled for (click to edit):") . "</h3>"; |
|
| 207 | + print "<h3>".__("Currently enabled for (click to edit):")."</h3>"; |
|
| 208 | 208 | |
| 209 | 209 | print "<ul class=\"panel panel-scrollable list list-unstyled\">"; |
| 210 | 210 | foreach ($enabled_feeds as $f) { |
| 211 | - print "<li>" . |
|
| 211 | + print "<li>". |
|
| 212 | 212 | "<i class='material-icons'>rss_feed</i> <a href='#' |
| 213 | - onclick='CommonDialogs.editFeed($f)'>" . |
|
| 214 | - Feeds::getFeedTitle($f) . "</a></li>"; |
|
| 213 | + onclick='CommonDialogs.editFeed($f)'>". |
|
| 214 | + Feeds::getFeedTitle($f)."</a></li>"; |
|
| 215 | 215 | } |
| 216 | 216 | print "</ul>"; |
| 217 | 217 | } |
@@ -15,10 +15,16 @@ discard block |
||
| 15 | 15 | $min_title_length = (int) $_POST["min_title_length"]; |
| 16 | 16 | $enable_globally = checkbox_to_sql_bool($_POST["enable_globally"]); |
| 17 | 17 | |
| 18 | - if ($similarity < 0) $similarity = 0; |
|
| 19 | - if ($similarity > 1) $similarity = 1; |
|
| 18 | + if ($similarity < 0) { |
|
| 19 | + $similarity = 0; |
|
| 20 | + } |
|
| 21 | + if ($similarity > 1) { |
|
| 22 | + $similarity = 1; |
|
| 23 | + } |
|
| 20 | 24 | |
| 21 | - if ($min_title_length < 0) $min_title_length = 0; |
|
| 25 | + if ($min_title_length < 0) { |
|
| 26 | + $min_title_length = 0; |
|
| 27 | + } |
|
| 22 | 28 | |
| 23 | 29 | $similarity = sprintf("%.2f", $similarity); |
| 24 | 30 | |
@@ -121,7 +127,9 @@ discard block |
||
| 121 | 127 | } |
| 122 | 128 | |
| 123 | 129 | public function hook_prefs_tab($args) { |
| 124 | - if ($args != "prefFeeds") return; |
|
| 130 | + if ($args != "prefFeeds") { |
|
| 131 | + return; |
|
| 132 | + } |
|
| 125 | 133 | |
| 126 | 134 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
| 127 | 135 | title=\"<i class='material-icons'>extension</i> ".__('Mark similar articles as read')."\">"; |
@@ -140,8 +148,12 @@ discard block |
||
| 140 | 148 | $min_title_length = $this->host->get($this, "min_title_length"); |
| 141 | 149 | $enable_globally = $this->host->get($this, "enable_globally"); |
| 142 | 150 | |
| 143 | - if (!$similarity) $similarity = '0.75'; |
|
| 144 | - if (!$min_title_length) $min_title_length = '32'; |
|
| 151 | + if (!$similarity) { |
|
| 152 | + $similarity = '0.75'; |
|
| 153 | + } |
|
| 154 | + if (!$min_title_length) { |
|
| 155 | + $min_title_length = '32'; |
|
| 156 | + } |
|
| 145 | 157 | |
| 146 | 158 | print "<form dojoType=\"dijit.form.Form\">"; |
| 147 | 159 | |
@@ -198,7 +210,9 @@ discard block |
||
| 198 | 210 | print "</form>"; |
| 199 | 211 | |
| 200 | 212 | $enabled_feeds = $this->host->get($this, "enabled_feeds"); |
| 201 | - if (!array($enabled_feeds)) $enabled_feeds = array(); |
|
| 213 | + if (!array($enabled_feeds)) { |
|
| 214 | + $enabled_feeds = array(); |
|
| 215 | + } |
|
| 202 | 216 | |
| 203 | 217 | $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds); |
| 204 | 218 | $this->host->set($this, "enabled_feeds", $enabled_feeds); |
@@ -225,7 +239,9 @@ discard block |
||
| 225 | 239 | print "<section>"; |
| 226 | 240 | |
| 227 | 241 | $enabled_feeds = $this->host->get($this, "enabled_feeds"); |
| 228 | - if (!array($enabled_feeds)) $enabled_feeds = array(); |
|
| 242 | + if (!array($enabled_feeds)) { |
|
| 243 | + $enabled_feeds = array(); |
|
| 244 | + } |
|
| 229 | 245 | |
| 230 | 246 | $key = array_search($feed_id, $enabled_feeds); |
| 231 | 247 | $checked = $key !== FALSE ? "checked" : ""; |
@@ -242,7 +258,9 @@ discard block |
||
| 242 | 258 | |
| 243 | 259 | public function hook_prefs_save_feed($feed_id) { |
| 244 | 260 | $enabled_feeds = $this->host->get($this, "enabled_feeds"); |
| 245 | - if (!is_array($enabled_feeds)) $enabled_feeds = array(); |
|
| 261 | + if (!is_array($enabled_feeds)) { |
|
| 262 | + $enabled_feeds = array(); |
|
| 263 | + } |
|
| 246 | 264 | |
| 247 | 265 | $enable = checkbox_to_sql_bool($_POST["trgm_similarity_enabled"]); |
| 248 | 266 | $key = array_search($feed_id, $enabled_feeds); |
@@ -262,24 +280,34 @@ discard block |
||
| 262 | 280 | |
| 263 | 281 | public function hook_article_filter($article) { |
| 264 | 282 | |
| 265 | - if (DB_TYPE != "pgsql") return $article; |
|
| 283 | + if (DB_TYPE != "pgsql") { |
|
| 284 | + return $article; |
|
| 285 | + } |
|
| 266 | 286 | |
| 267 | 287 | $res = $this->pdo->query("select 'similarity'::regproc"); |
| 268 | - if (!$res->fetch()) return $article; |
|
| 288 | + if (!$res->fetch()) { |
|
| 289 | + return $article; |
|
| 290 | + } |
|
| 269 | 291 | |
| 270 | 292 | $enable_globally = $this->host->get($this, "enable_globally"); |
| 271 | 293 | |
| 272 | 294 | if (!$enable_globally) { |
| 273 | 295 | $enabled_feeds = $this->host->get($this, "enabled_feeds"); |
| 274 | 296 | $key = array_search($article["feed"]["id"], $enabled_feeds); |
| 275 | - if ($key === FALSE) return $article; |
|
| 297 | + if ($key === FALSE) { |
|
| 298 | + return $article; |
|
| 299 | + } |
|
| 276 | 300 | } |
| 277 | 301 | |
| 278 | 302 | $similarity = (float) $this->host->get($this, "similarity"); |
| 279 | - if ($similarity < 0.01) return $article; |
|
| 303 | + if ($similarity < 0.01) { |
|
| 304 | + return $article; |
|
| 305 | + } |
|
| 280 | 306 | |
| 281 | 307 | $min_title_length = (int) $this->host->get($this, "min_title_length"); |
| 282 | - if (mb_strlen($article["title"]) < $min_title_length) return $article; |
|
| 308 | + if (mb_strlen($article["title"]) < $min_title_length) { |
|
| 309 | + return $article; |
|
| 310 | + } |
|
| 283 | 311 | |
| 284 | 312 | $owner_uid = $article["owner_uid"]; |
| 285 | 313 | $entry_guid = $article["guid_hashed"]; |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function get_js() { |
| 19 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 19 | + return file_get_contents(__DIR__."/init.js"); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public function hook_main_toolbar_button() { |
@@ -5,9 +5,9 @@ discard block |
||
| 5 | 5 | require_once "..".DIRECTORY_SEPARATOR."config.php"; |
| 6 | 6 | |
| 7 | 7 | set_include_path(dirname(__FILE__).PATH_SEPARATOR. |
| 8 | - dirname(dirname(__FILE__)).PATH_SEPARATOR. |
|
| 9 | - dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR. |
|
| 10 | - get_include_path()); |
|
| 8 | + dirname(dirname(__FILE__)).PATH_SEPARATOR. |
|
| 9 | + dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR. |
|
| 10 | + get_include_path()); |
|
| 11 | 11 | |
| 12 | 12 | chdir(".."); |
| 13 | 13 | |
@@ -24,33 +24,33 @@ discard block |
||
| 24 | 24 | ini_set("session.gc_maxlifetime", 86400); |
| 25 | 25 | |
| 26 | 26 | if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT && |
| 27 | - function_exists("ob_gzhandler")) { |
|
| 27 | + function_exists("ob_gzhandler")) { |
|
| 28 | 28 | |
| 29 | - ob_start("ob_gzhandler"); |
|
| 29 | + ob_start("ob_gzhandler"); |
|
| 30 | 30 | } else { |
| 31 | - ob_start(); |
|
| 31 | + ob_start(); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $input = file_get_contents("php://input"); |
| 35 | 35 | |
| 36 | 36 | if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) { |
| 37 | - // Override $_REQUEST with JSON-encoded data if available |
|
| 38 | - // fallback on HTTP parameters |
|
| 39 | - if ($input) { |
|
| 40 | - $input = json_decode($input, true); |
|
| 41 | - if ($input) $_REQUEST = $input; |
|
| 42 | - } |
|
| 37 | + // Override $_REQUEST with JSON-encoded data if available |
|
| 38 | + // fallback on HTTP parameters |
|
| 39 | + if ($input) { |
|
| 40 | + $input = json_decode($input, true); |
|
| 41 | + if ($input) $_REQUEST = $input; |
|
| 42 | + } |
|
| 43 | 43 | } else { |
| 44 | - // Accept JSON only |
|
| 45 | - $input = json_decode($input, true); |
|
| 46 | - $_REQUEST = $input; |
|
| 44 | + // Accept JSON only |
|
| 45 | + $input = json_decode($input, true); |
|
| 46 | + $_REQUEST = $input; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if ($_REQUEST["sid"]) { |
| 50 | - session_id($_REQUEST["sid"]); |
|
| 51 | - @session_start(); |
|
| 50 | + session_id($_REQUEST["sid"]); |
|
| 51 | + @session_start(); |
|
| 52 | 52 | } else if (defined('_API_DEBUG_HTTP_ENABLED')) { |
| 53 | - @session_start(); |
|
| 53 | + @session_start(); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | startup_gettext(); |
@@ -58,17 +58,17 @@ discard block |
||
| 58 | 58 | if (!init_plugins()) return; |
| 59 | 59 | |
| 60 | 60 | if ($_SESSION["uid"]) { |
| 61 | - if (!validate_session()) { |
|
| 62 | - header("Content-Type: text/json"); |
|
| 61 | + if (!validate_session()) { |
|
| 62 | + header("Content-Type: text/json"); |
|
| 63 | 63 | |
| 64 | - print json_encode(array("seq" => -1, |
|
| 65 | - "status" => 1, |
|
| 66 | - "content" => array("error" => "NOT_LOGGED_IN"))); |
|
| 64 | + print json_encode(array("seq" => -1, |
|
| 65 | + "status" => 1, |
|
| 66 | + "content" => array("error" => "NOT_LOGGED_IN"))); |
|
| 67 | 67 | |
| 68 | - return; |
|
| 69 | - } |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - load_user_plugins( $_SESSION["uid"]); |
|
| 71 | + load_user_plugins( $_SESSION["uid"]); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $method = strtolower($_REQUEST["op"]); |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | $handler = new API($_REQUEST); |
| 77 | 77 | |
| 78 | 78 | if ($handler->before($method)) { |
| 79 | - if ($method && method_exists($handler, $method)) { |
|
| 80 | - $handler->$method(); |
|
| 81 | - } else if (method_exists($handler, 'index')) { |
|
| 82 | - $handler->index($method); |
|
| 83 | - } |
|
| 84 | - $handler->after(); |
|
| 79 | + if ($method && method_exists($handler, $method)) { |
|
| 80 | + $handler->$method(); |
|
| 81 | + } else if (method_exists($handler, 'index')) { |
|
| 82 | + $handler->index($method); |
|
| 83 | + } |
|
| 84 | + $handler->after(); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | header("Api-Content-Length: " . ob_get_length()); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - load_user_plugins( $_SESSION["uid"]); |
|
| 71 | + load_user_plugins($_SESSION["uid"]); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $method = strtolower($_REQUEST["op"]); |
@@ -84,6 +84,6 @@ discard block |
||
| 84 | 84 | $handler->after(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | -header("Api-Content-Length: " . ob_get_length()); |
|
| 87 | +header("Api-Content-Length: ".ob_get_length()); |
|
| 88 | 88 | |
| 89 | 89 | ob_end_flush(); |
@@ -38,7 +38,9 @@ discard block |
||
| 38 | 38 | // fallback on HTTP parameters |
| 39 | 39 | if ($input) { |
| 40 | 40 | $input = json_decode($input, true); |
| 41 | - if ($input) $_REQUEST = $input; |
|
| 41 | + if ($input) { |
|
| 42 | + $_REQUEST = $input; |
|
| 43 | + } |
|
| 42 | 44 | } |
| 43 | 45 | } else { |
| 44 | 46 | // Accept JSON only |
@@ -55,7 +57,9 @@ discard block |
||
| 55 | 57 | |
| 56 | 58 | startup_gettext(); |
| 57 | 59 | |
| 58 | -if (!init_plugins()) return; |
|
| 60 | +if (!init_plugins()) { |
|
| 61 | + return; |
|
| 62 | +} |
|
| 59 | 63 | |
| 60 | 64 | if ($_SESSION["uid"]) { |
| 61 | 65 | if (!validate_session()) { |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | #!/usr/bin/env php |
| 2 | 2 | <?php |
| 3 | 3 | set_include_path(dirname(__FILE__) .DIRECTORY_SEPARATOR."include" . PATH_SEPARATOR . |
| 4 | - get_include_path()); |
|
| 4 | + get_include_path()); |
|
| 5 | 5 | |
| 6 | 6 | declare(ticks = 1); |
| 7 | 7 | chdir(dirname(__FILE__)); |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | require_once "db-prefs.php"; |
| 24 | 24 | |
| 25 | 25 | if (!function_exists('pcntl_fork')) { |
| 26 | - die("error: This script requires PHP compiled with PCNTL module.\n"); |
|
| 26 | + die("error: This script requires PHP compiled with PCNTL module.\n"); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | $options = getopt(""); |
| 30 | 30 | |
| 31 | 31 | if (!is_array($options)) { |
| 32 | - die("error: getopt() failed. ". |
|
| 33 | - "Most probably you are using PHP CGI to run this script ". |
|
| 34 | - "instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ". |
|
| 35 | - "additional information.\n"); |
|
| 32 | + die("error: getopt() failed. ". |
|
| 33 | + "Most probably you are using PHP CGI to run this script ". |
|
| 34 | + "instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ". |
|
| 35 | + "additional information.\n"); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -44,137 +44,137 @@ discard block |
||
| 44 | 44 | $last_checkpoint = -1; |
| 45 | 45 | |
| 46 | 46 | function reap_children() { |
| 47 | - global $children; |
|
| 48 | - global $ctimes; |
|
| 47 | + global $children; |
|
| 48 | + global $ctimes; |
|
| 49 | 49 | |
| 50 | - $tmp = array(); |
|
| 50 | + $tmp = array(); |
|
| 51 | 51 | |
| 52 | - foreach ($children as $pid) { |
|
| 53 | - if (pcntl_waitpid($pid, $status, WNOHANG) != $pid) { |
|
| 52 | + foreach ($children as $pid) { |
|
| 53 | + if (pcntl_waitpid($pid, $status, WNOHANG) != $pid) { |
|
| 54 | 54 | |
| 55 | - if (file_is_locked("update_daemon-$pid.lock")) { |
|
| 56 | - array_push($tmp, $pid); |
|
| 57 | - } else { |
|
| 58 | - Debug::log("[reap_children] child $pid seems active but lockfile is unlocked."); |
|
| 59 | - unset($ctimes[$pid]); |
|
| 55 | + if (file_is_locked("update_daemon-$pid.lock")) { |
|
| 56 | + array_push($tmp, $pid); |
|
| 57 | + } else { |
|
| 58 | + Debug::log("[reap_children] child $pid seems active but lockfile is unlocked."); |
|
| 59 | + unset($ctimes[$pid]); |
|
| 60 | 60 | |
| 61 | - } |
|
| 62 | - } else { |
|
| 63 | - Debug::log("[reap_children] child $pid reaped."); |
|
| 64 | - unset($ctimes[$pid]); |
|
| 65 | - } |
|
| 66 | - } |
|
| 61 | + } |
|
| 62 | + } else { |
|
| 63 | + Debug::log("[reap_children] child $pid reaped."); |
|
| 64 | + unset($ctimes[$pid]); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $children = $tmp; |
|
| 68 | + $children = $tmp; |
|
| 69 | 69 | |
| 70 | - return count($tmp); |
|
| 70 | + return count($tmp); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | function check_ctimes() { |
| 74 | - global $ctimes; |
|
| 74 | + global $ctimes; |
|
| 75 | 75 | |
| 76 | - foreach (array_keys($ctimes) as $pid) { |
|
| 77 | - $started = $ctimes[$pid]; |
|
| 76 | + foreach (array_keys($ctimes) as $pid) { |
|
| 77 | + $started = $ctimes[$pid]; |
|
| 78 | 78 | |
| 79 | - if (time() - $started > MAX_CHILD_RUNTIME) { |
|
| 80 | - Debug::log("[MASTER] child process $pid seems to be stuck, aborting..."); |
|
| 81 | - posix_kill($pid, SIGKILL); |
|
| 82 | - } |
|
| 83 | - } |
|
| 79 | + if (time() - $started > MAX_CHILD_RUNTIME) { |
|
| 80 | + Debug::log("[MASTER] child process $pid seems to be stuck, aborting..."); |
|
| 81 | + posix_kill($pid, SIGKILL); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | function sigchld_handler($signal) { |
| 87 | - $running_jobs = reap_children(); |
|
| 87 | + $running_jobs = reap_children(); |
|
| 88 | 88 | |
| 89 | - Debug::log("[SIGCHLD] jobs left: $running_jobs"); |
|
| 89 | + Debug::log("[SIGCHLD] jobs left: $running_jobs"); |
|
| 90 | 90 | |
| 91 | - pcntl_waitpid(-1, $status, WNOHANG); |
|
| 91 | + pcntl_waitpid(-1, $status, WNOHANG); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | function shutdown($caller_pid) { |
| 95 | - if ($caller_pid == posix_getpid()) { |
|
| 96 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { |
|
| 97 | - Debug::log("removing lockfile (master)..."); |
|
| 98 | - unlink(LOCK_DIRECTORY . "/update_daemon.lock"); |
|
| 99 | - } |
|
| 100 | - } |
|
| 95 | + if ($caller_pid == posix_getpid()) { |
|
| 96 | + if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { |
|
| 97 | + Debug::log("removing lockfile (master)..."); |
|
| 98 | + unlink(LOCK_DIRECTORY . "/update_daemon.lock"); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function task_shutdown() { |
| 104 | - $pid = posix_getpid(); |
|
| 104 | + $pid = posix_getpid(); |
|
| 105 | 105 | |
| 106 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) { |
|
| 107 | - Debug::log("removing lockfile ($pid)..."); |
|
| 108 | - unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock"); |
|
| 109 | - } |
|
| 106 | + if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) { |
|
| 107 | + Debug::log("removing lockfile ($pid)..."); |
|
| 108 | + unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock"); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | function sigint_handler() { |
| 113 | - Debug::log("[MASTER] SIG_INT received.\n"); |
|
| 114 | - shutdown(posix_getpid()); |
|
| 115 | - die; |
|
| 113 | + Debug::log("[MASTER] SIG_INT received.\n"); |
|
| 114 | + shutdown(posix_getpid()); |
|
| 115 | + die; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | function task_sigint_handler() { |
| 119 | - Debug::log("[TASK] SIG_INT received.\n"); |
|
| 120 | - task_shutdown(); |
|
| 121 | - die; |
|
| 119 | + Debug::log("[TASK] SIG_INT received.\n"); |
|
| 120 | + task_shutdown(); |
|
| 121 | + die; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | pcntl_signal(SIGCHLD, 'sigchld_handler'); |
| 125 | 125 | |
| 126 | 126 | $longopts = array( |
| 127 | - "log:", |
|
| 128 | - "log-level:", |
|
| 129 | - "tasks:", |
|
| 130 | - "interval:", |
|
| 131 | - "quiet", |
|
| 132 | - "help" |
|
| 127 | + "log:", |
|
| 128 | + "log-level:", |
|
| 129 | + "tasks:", |
|
| 130 | + "interval:", |
|
| 131 | + "quiet", |
|
| 132 | + "help" |
|
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | 135 | $options = getopt("", $longopts); |
| 136 | 136 | |
| 137 | 137 | if (isset($options["help"]) ) { |
| 138 | - print "Tiny Tiny RSS update daemon.\n\n"; |
|
| 139 | - print "Options:\n"; |
|
| 140 | - print " --log FILE - log messages to FILE\n"; |
|
| 141 | - print " --log-level N - log verbosity level\n"; |
|
| 142 | - print " --tasks N - amount of update tasks to spawn\n"; |
|
| 143 | - print " default: " . MAX_JOBS . "\n"; |
|
| 144 | - print " --interval N - task spawn interval\n"; |
|
| 145 | - print " default: " . SPAWN_INTERVAL . " seconds.\n"; |
|
| 146 | - print " --quiet - don't output messages to stdout\n"; |
|
| 147 | - return; |
|
| 138 | + print "Tiny Tiny RSS update daemon.\n\n"; |
|
| 139 | + print "Options:\n"; |
|
| 140 | + print " --log FILE - log messages to FILE\n"; |
|
| 141 | + print " --log-level N - log verbosity level\n"; |
|
| 142 | + print " --tasks N - amount of update tasks to spawn\n"; |
|
| 143 | + print " default: " . MAX_JOBS . "\n"; |
|
| 144 | + print " --interval N - task spawn interval\n"; |
|
| 145 | + print " default: " . SPAWN_INTERVAL . " seconds.\n"; |
|
| 146 | + print " --quiet - don't output messages to stdout\n"; |
|
| 147 | + return; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | Debug::set_enabled(true); |
| 151 | 151 | |
| 152 | 152 | if (isset($options["log-level"])) { |
| 153 | - Debug::set_loglevel((int)$options["log-level"]); |
|
| 153 | + Debug::set_loglevel((int)$options["log-level"]); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if (isset($options["log"])) { |
| 157 | - Debug::set_quiet(isset($options['quiet'])); |
|
| 158 | - Debug::set_logfile($options["log"]); |
|
| 159 | - Debug::log("Logging to " . $options["log"]); |
|
| 157 | + Debug::set_quiet(isset($options['quiet'])); |
|
| 158 | + Debug::set_logfile($options["log"]); |
|
| 159 | + Debug::log("Logging to " . $options["log"]); |
|
| 160 | 160 | } else { |
| 161 | - if (isset($options['quiet'])) { |
|
| 162 | - Debug::set_loglevel(Debug::$LOG_DISABLED); |
|
| 163 | - } |
|
| 161 | + if (isset($options['quiet'])) { |
|
| 162 | + Debug::set_loglevel(Debug::$LOG_DISABLED); |
|
| 163 | + } |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | if (isset($options["tasks"])) { |
| 167 | - Debug::log("Set to spawn " . $options["tasks"] . " children."); |
|
| 168 | - $max_jobs = $options["tasks"]; |
|
| 167 | + Debug::log("Set to spawn " . $options["tasks"] . " children."); |
|
| 168 | + $max_jobs = $options["tasks"]; |
|
| 169 | 169 | } else { |
| 170 | - $max_jobs = MAX_JOBS; |
|
| 170 | + $max_jobs = MAX_JOBS; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | if (isset($options["interval"])) { |
| 174 | - Debug::log("Spawn interval: " . $options["interval"] . " seconds."); |
|
| 175 | - $spawn_interval = $options["interval"]; |
|
| 174 | + Debug::log("Spawn interval: " . $options["interval"] . " seconds."); |
|
| 175 | + $spawn_interval = $options["interval"]; |
|
| 176 | 176 | } else { |
| 177 | - $spawn_interval = SPAWN_INTERVAL; |
|
| 177 | + $spawn_interval = SPAWN_INTERVAL; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // let's enforce a minimum spawn interval as to not forkbomb the host |
@@ -182,22 +182,22 @@ discard block |
||
| 182 | 182 | Debug::log("Spawn interval: $spawn_interval sec"); |
| 183 | 183 | |
| 184 | 184 | if (file_is_locked("update_daemon.lock")) { |
| 185 | - die("error: Can't create lockfile. ". |
|
| 186 | - "Maybe another daemon is already running.\n"); |
|
| 185 | + die("error: Can't create lockfile. ". |
|
| 186 | + "Maybe another daemon is already running.\n"); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Try to lock a file in order to avoid concurrent update. |
| 190 | 190 | $lock_handle = make_lockfile("update_daemon.lock"); |
| 191 | 191 | |
| 192 | 192 | if (!$lock_handle) { |
| 193 | - die("error: Can't create lockfile. ". |
|
| 194 | - "Maybe another daemon is already running.\n"); |
|
| 193 | + die("error: Can't create lockfile. ". |
|
| 194 | + "Maybe another daemon is already running.\n"); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $schema_version = get_schema_version(); |
| 198 | 198 | |
| 199 | 199 | if ($schema_version != SCHEMA_VERSION) { |
| 200 | - die("Schema version is wrong, please upgrade the database.\n"); |
|
| 200 | + die("Schema version is wrong, please upgrade the database.\n"); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // Protip: children close shared database handle when terminating, it's a bad idea to |
@@ -205,56 +205,56 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | while (true) { |
| 207 | 207 | |
| 208 | - // Since sleep is interupted by SIGCHLD, we need another way to |
|
| 209 | - // respect the spawn interval |
|
| 210 | - $next_spawn = $last_checkpoint + $spawn_interval - time(); |
|
| 211 | - |
|
| 212 | - if ($next_spawn % 60 == 0) { |
|
| 213 | - $running_jobs = count($children); |
|
| 214 | - Debug::log("[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec."); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - if ($last_checkpoint + $spawn_interval < time()) { |
|
| 218 | - check_ctimes(); |
|
| 219 | - reap_children(); |
|
| 220 | - |
|
| 221 | - for ($j = count($children); $j < $max_jobs; $j++) { |
|
| 222 | - $pid = pcntl_fork(); |
|
| 223 | - if ($pid == -1) { |
|
| 224 | - die("fork failed!\n"); |
|
| 225 | - } else if ($pid) { |
|
| 226 | - |
|
| 227 | - if (!$master_handlers_installed) { |
|
| 228 | - Debug::log("[MASTER] installing shutdown handlers"); |
|
| 229 | - pcntl_signal(SIGINT, 'sigint_handler'); |
|
| 230 | - pcntl_signal(SIGTERM, 'sigint_handler'); |
|
| 231 | - register_shutdown_function('shutdown', posix_getpid()); |
|
| 232 | - $master_handlers_installed = true; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - Debug::log("[MASTER] spawned client $j [PID:$pid]..."); |
|
| 236 | - array_push($children, $pid); |
|
| 237 | - $ctimes[$pid] = time(); |
|
| 238 | - } else { |
|
| 239 | - pcntl_signal(SIGCHLD, SIG_IGN); |
|
| 240 | - pcntl_signal(SIGINT, 'task_sigint_handler'); |
|
| 241 | - |
|
| 242 | - register_shutdown_function('task_shutdown'); |
|
| 243 | - |
|
| 244 | - $quiet = (isset($options["quiet"])) ? "--quiet" : ""; |
|
| 245 | - $log = function_exists("flock") && isset($options['log']) ? '--log '.$options['log'] : ''; |
|
| 246 | - |
|
| 247 | - $my_pid = posix_getpid(); |
|
| 248 | - |
|
| 249 | - passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); |
|
| 250 | - |
|
| 251 | - sleep(1); |
|
| 252 | - |
|
| 253 | - // We exit in order to avoid fork bombing. |
|
| 254 | - exit(0); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - $last_checkpoint = time(); |
|
| 258 | - } |
|
| 259 | - sleep(1); |
|
| 208 | + // Since sleep is interupted by SIGCHLD, we need another way to |
|
| 209 | + // respect the spawn interval |
|
| 210 | + $next_spawn = $last_checkpoint + $spawn_interval - time(); |
|
| 211 | + |
|
| 212 | + if ($next_spawn % 60 == 0) { |
|
| 213 | + $running_jobs = count($children); |
|
| 214 | + Debug::log("[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec."); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + if ($last_checkpoint + $spawn_interval < time()) { |
|
| 218 | + check_ctimes(); |
|
| 219 | + reap_children(); |
|
| 220 | + |
|
| 221 | + for ($j = count($children); $j < $max_jobs; $j++) { |
|
| 222 | + $pid = pcntl_fork(); |
|
| 223 | + if ($pid == -1) { |
|
| 224 | + die("fork failed!\n"); |
|
| 225 | + } else if ($pid) { |
|
| 226 | + |
|
| 227 | + if (!$master_handlers_installed) { |
|
| 228 | + Debug::log("[MASTER] installing shutdown handlers"); |
|
| 229 | + pcntl_signal(SIGINT, 'sigint_handler'); |
|
| 230 | + pcntl_signal(SIGTERM, 'sigint_handler'); |
|
| 231 | + register_shutdown_function('shutdown', posix_getpid()); |
|
| 232 | + $master_handlers_installed = true; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + Debug::log("[MASTER] spawned client $j [PID:$pid]..."); |
|
| 236 | + array_push($children, $pid); |
|
| 237 | + $ctimes[$pid] = time(); |
|
| 238 | + } else { |
|
| 239 | + pcntl_signal(SIGCHLD, SIG_IGN); |
|
| 240 | + pcntl_signal(SIGINT, 'task_sigint_handler'); |
|
| 241 | + |
|
| 242 | + register_shutdown_function('task_shutdown'); |
|
| 243 | + |
|
| 244 | + $quiet = (isset($options["quiet"])) ? "--quiet" : ""; |
|
| 245 | + $log = function_exists("flock") && isset($options['log']) ? '--log '.$options['log'] : ''; |
|
| 246 | + |
|
| 247 | + $my_pid = posix_getpid(); |
|
| 248 | + |
|
| 249 | + passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); |
|
| 250 | + |
|
| 251 | + sleep(1); |
|
| 252 | + |
|
| 253 | + // We exit in order to avoid fork bombing. |
|
| 254 | + exit(0); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + $last_checkpoint = time(); |
|
| 258 | + } |
|
| 259 | + sleep(1); |
|
| 260 | 260 | } |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | #!/usr/bin/env php |
| 2 | 2 | <?php |
| 3 | -set_include_path(dirname(__FILE__) .DIRECTORY_SEPARATOR."include" . PATH_SEPARATOR . |
|
| 3 | +set_include_path(dirname(__FILE__).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR. |
|
| 4 | 4 | get_include_path()); |
| 5 | 5 | |
| 6 | -declare(ticks = 1); |
|
| 6 | +declare(ticks=1); |
|
| 7 | 7 | chdir(dirname(__FILE__)); |
| 8 | 8 | |
| 9 | 9 | define('DISABLE_SESSIONS', true); |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | function shutdown($caller_pid) { |
| 95 | 95 | if ($caller_pid == posix_getpid()) { |
| 96 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { |
|
| 96 | + if (file_exists(LOCK_DIRECTORY."/update_daemon.lock")) { |
|
| 97 | 97 | Debug::log("removing lockfile (master)..."); |
| 98 | - unlink(LOCK_DIRECTORY . "/update_daemon.lock"); |
|
| 98 | + unlink(LOCK_DIRECTORY."/update_daemon.lock"); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | function task_shutdown() { |
| 104 | 104 | $pid = posix_getpid(); |
| 105 | 105 | |
| 106 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) { |
|
| 106 | + if (file_exists(LOCK_DIRECTORY."/update_daemon-$pid.lock")) { |
|
| 107 | 107 | Debug::log("removing lockfile ($pid)..."); |
| 108 | - unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock"); |
|
| 108 | + unlink(LOCK_DIRECTORY."/update_daemon-$pid.lock"); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
@@ -134,15 +134,15 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | $options = getopt("", $longopts); |
| 136 | 136 | |
| 137 | -if (isset($options["help"]) ) { |
|
| 137 | +if (isset($options["help"])) { |
|
| 138 | 138 | print "Tiny Tiny RSS update daemon.\n\n"; |
| 139 | 139 | print "Options:\n"; |
| 140 | 140 | print " --log FILE - log messages to FILE\n"; |
| 141 | 141 | print " --log-level N - log verbosity level\n"; |
| 142 | 142 | print " --tasks N - amount of update tasks to spawn\n"; |
| 143 | - print " default: " . MAX_JOBS . "\n"; |
|
| 143 | + print " default: ".MAX_JOBS."\n"; |
|
| 144 | 144 | print " --interval N - task spawn interval\n"; |
| 145 | - print " default: " . SPAWN_INTERVAL . " seconds.\n"; |
|
| 145 | + print " default: ".SPAWN_INTERVAL." seconds.\n"; |
|
| 146 | 146 | print " --quiet - don't output messages to stdout\n"; |
| 147 | 147 | return; |
| 148 | 148 | } |
@@ -150,13 +150,13 @@ discard block |
||
| 150 | 150 | Debug::set_enabled(true); |
| 151 | 151 | |
| 152 | 152 | if (isset($options["log-level"])) { |
| 153 | - Debug::set_loglevel((int)$options["log-level"]); |
|
| 153 | + Debug::set_loglevel((int) $options["log-level"]); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if (isset($options["log"])) { |
| 157 | 157 | Debug::set_quiet(isset($options['quiet'])); |
| 158 | 158 | Debug::set_logfile($options["log"]); |
| 159 | - Debug::log("Logging to " . $options["log"]); |
|
| 159 | + Debug::log("Logging to ".$options["log"]); |
|
| 160 | 160 | } else { |
| 161 | 161 | if (isset($options['quiet'])) { |
| 162 | 162 | Debug::set_loglevel(Debug::$LOG_DISABLED); |
@@ -164,14 +164,14 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | if (isset($options["tasks"])) { |
| 167 | - Debug::log("Set to spawn " . $options["tasks"] . " children."); |
|
| 167 | + Debug::log("Set to spawn ".$options["tasks"]." children."); |
|
| 168 | 168 | $max_jobs = $options["tasks"]; |
| 169 | 169 | } else { |
| 170 | 170 | $max_jobs = MAX_JOBS; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | if (isset($options["interval"])) { |
| 174 | - Debug::log("Spawn interval: " . $options["interval"] . " seconds."); |
|
| 174 | + Debug::log("Spawn interval: ".$options["interval"]." seconds."); |
|
| 175 | 175 | $spawn_interval = $options["interval"]; |
| 176 | 176 | } else { |
| 177 | 177 | $spawn_interval = SPAWN_INTERVAL; |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | $my_pid = posix_getpid(); |
| 248 | 248 | |
| 249 | - passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); |
|
| 249 | + passthru(PHP_EXECUTABLE." update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); |
|
| 250 | 250 | |
| 251 | 251 | sleep(1); |
| 252 | 252 | |