@@ -531,6 +531,10 @@ |
||
| 531 | 531 | final private function _getSiteRateLimit() : int { |
| 532 | 532 | return (int) ($this->cache->get("{$this->site}_ratelimit") ?: 0); |
| 533 | 533 | } |
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * @param integer $rateLimit |
|
| 537 | + */ |
|
| 534 | 538 | final private function _setSiteRateLimit(?int $rateLimit = NULL) : bool { |
| 535 | 539 | //We would just use increment(), but we can't set ttl with it... |
| 536 | 540 | $currentRateLimit = $rateLimit ?: $this->_getSiteRateLimit(); |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
|
| 1 | +<?php declare(strict_types = 1); defined('BASEPATH') OR exit('No direct script access allowed'); |
|
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * Class Tracker_Sites_Model |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | $ch = curl_init(); |
| 183 | 183 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 184 | - curl_setopt($ch, CURLOPT_ENCODING , "gzip"); |
|
| 184 | + curl_setopt($ch, CURLOPT_ENCODING, "gzip"); |
|
| 185 | 185 | //curl_setopt($ch, CURLOPT_VERBOSE, 1); |
| 186 | 186 | curl_setopt($ch, CURLOPT_HEADER, 1); |
| 187 | 187 | |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | curl_setopt($ch, CURLOPT_URL, $url); |
| 204 | 204 | |
| 205 | 205 | if($isPost) { |
| 206 | - curl_setopt($ch,CURLOPT_POST, count($postFields)); |
|
| 207 | - curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($postFields)); |
|
| 206 | + curl_setopt($ch, CURLOPT_POST, count($postFields)); |
|
| 207 | + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields)); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | $response = curl_exec($ch); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | $result = shell_exec('python '.APPPATH.'../_scripts/get_cloudflare_cookie.py '.escapeshellarg(json_encode($urlData))); |
| 252 | 252 | $cookieData = json_decode($result, TRUE); |
| 253 | 253 | |
| 254 | - $this->cache->save("cloudflare_{$this->site}", $cookieData['cookies'], 31536000 /* 1 year, or until we renew it */); |
|
| 254 | + $this->cache->save("cloudflare_{$this->site}", $cookieData['cookies'], 31536000 /* 1 year, or until we renew it */); |
|
| 255 | 255 | log_message('debug', "Saving CloudFlare Cookies for {$this->site}"); |
| 256 | 256 | |
| 257 | 257 | $refresh = TRUE; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | $dom = new DOMDocument(); |
| 311 | 311 | libxml_use_internal_errors(TRUE); |
| 312 | - $dom->loadHTML('<?xml encoding="utf-8" ?>' . $data); |
|
| 312 | + $dom->loadHTML('<?xml encoding="utf-8" ?>'.$data); |
|
| 313 | 313 | libxml_use_internal_errors(FALSE); |
| 314 | 314 | |
| 315 | 315 | $xpath = new DOMXPath($dom); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | if($nodes_title->length === 1) { |
| 319 | 319 | if($nodes_row->length === 1) { |
| 320 | 320 | $firstRow = $nodes_row->item(0); |
| 321 | - $nodes_latest = $xpath->query($node_latest_string, $firstRow); |
|
| 321 | + $nodes_latest = $xpath->query($node_latest_string, $firstRow); |
|
| 322 | 322 | |
| 323 | 323 | if($node_chapter_string !== '') { |
| 324 | 324 | $nodes_chapter = $xpath->query($node_chapter_string, $firstRow); |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | final private function _setSiteRateLimit(?int $rateLimit = NULL) : bool { |
| 535 | 535 | //We would just use increment(), but we can't set ttl with it... |
| 536 | 536 | $currentRateLimit = $rateLimit ?: $this->_getSiteRateLimit(); |
| 537 | - return $this->cache->save("{$this->site}_ratelimit", $currentRateLimit + 1,3600); |
|
| 537 | + return $this->cache->save("{$this->site}_ratelimit", $currentRateLimit + 1, 3600); |
|
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | $chapter_parts = explode('/', $chapter); //returns #LANG#/#VOLUME#/#CHAPTER#/#CHAPTER_EXTRA#(/#PAGE#/) |
| 552 | 552 | return [ |
| 553 | 553 | 'url' => $this->getChapterURL($title_url, $chapter), |
| 554 | - 'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '') . "c{$chapter_parts[2]}" . (isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/ |
|
| 554 | + 'number' => ($chapter_parts[1] !== '0' ? "v{$chapter_parts[1]}/" : '')."c{$chapter_parts[2]}".(isset($chapter_parts[3]) ? ".{$chapter_parts[3]}" : '')/*)*/ |
|
| 555 | 555 | ]; |
| 556 | 556 | } |
| 557 | 557 | public function getChapterURL(string $title_url, string $chapter) : string { |
@@ -733,9 +733,9 @@ discard block |
||
| 733 | 733 | |
| 734 | 734 | $dateString = str_replace('/', '-', trim($nodes_latest->item(0)->nodeValue)); //NOTE: We replace slashes here as it stops strtotime interpreting the date as US date format. |
| 735 | 735 | if($dateString == 'T') { |
| 736 | - $dateString = date("Y-m-d",now()); |
|
| 736 | + $dateString = date("Y-m-d", now()); |
|
| 737 | 737 | } |
| 738 | - $titleData['last_updated'] = date("Y-m-d H:i:s", strtotime($dateString . ' 00:00')); |
|
| 738 | + $titleData['last_updated'] = date("Y-m-d H:i:s", strtotime($dateString.' 00:00')); |
|
| 739 | 739 | |
| 740 | 740 | $titleDataList[$title_url] = $titleData; |
| 741 | 741 | } |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | //For whatever reason, DOMDocument breaks the <link> element we need to grab the chapter, so we have to grab it elsewhere. |
| 791 | 791 | $titleData['latest_chapter'] = preg_replace('/^.*? - ([0-9\.]+) - .*?$/', '$1', trim($data['nodes_chapter']->textContent)); |
| 792 | 792 | |
| 793 | - $titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->textContent)); |
|
| 793 | + $titleData['last_updated'] = date("Y-m-d H:i:s", strtotime((string) $data['nodes_latest']->textContent)); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | return (!empty($titleData) ? $titleData : NULL); |
@@ -896,11 +896,11 @@ discard block |
||
| 896 | 896 | "" |
| 897 | 897 | ); |
| 898 | 898 | if($data) { |
| 899 | - $titleData['title'] = trim(preg_replace('/ Added on .*$/','', $data['nodes_title']->textContent)); |
|
| 899 | + $titleData['title'] = trim(preg_replace('/ Added on .*$/', '', $data['nodes_title']->textContent)); |
|
| 900 | 900 | $titleData['latest_chapter'] = preg_replace('/^.*\/([0-9\.]+)$/', '$1', (string) $data['nodes_chapter']->getAttribute('href')); |
| 901 | 901 | |
| 902 | - $dateString = preg_replace('/^Added (?:on )?/', '',$data['nodes_latest']->textContent); |
|
| 903 | - $titleData['last_updated'] = date("Y-m-d H:i:s", strtotime($dateString)); |
|
| 902 | + $dateString = preg_replace('/^Added (?:on )?/', '', $data['nodes_latest']->textContent); |
|
| 903 | + $titleData['last_updated'] = date("Y-m-d H:i:s", strtotime($dateString)); |
|
| 904 | 904 | } |
| 905 | 905 | return (!empty($titleData) ? $titleData : NULL); |
| 906 | 906 | } |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | //Make sure last_checked is always updated on successful run. |
| 160 | 160 | //CHECK: Is there a reason we aren't just doing this in updateByID? |
| 161 | 161 | $this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE) |
| 162 | - ->where('id', $row->title_id) |
|
| 163 | - ->update('tracker_titles'); |
|
| 162 | + ->where('id', $row->title_id) |
|
| 163 | + ->update('tracker_titles'); |
|
| 164 | 164 | |
| 165 | 165 | print " - ({$titleData['latest_chapter']})\n"; |
| 166 | 166 | } else { |
@@ -174,8 +174,8 @@ discard block |
||
| 174 | 174 | //Make sure last_checked is always updated on successful run. |
| 175 | 175 | //CHECK: Is there a reason we aren't just doing this in updateByID? |
| 176 | 176 | $this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE) |
| 177 | - ->where('id', $row->title_id) |
|
| 178 | - ->update('tracker_titles'); |
|
| 177 | + ->where('id', $row->title_id) |
|
| 178 | + ->update('tracker_titles'); |
|
| 179 | 179 | |
| 180 | 180 | print " - (No chapters found?)\n"; |
| 181 | 181 | } else { |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | public function updateCustom() { |
| 205 | 205 | $query = $this->db->select('*') |
| 206 | - ->from('tracker_sites') |
|
| 207 | - ->where('tracker_sites.status', 'enabled') |
|
| 208 | - ->where('tracker_sites.use_custom', 'Y') |
|
| 209 | - ->get(); |
|
| 206 | + ->from('tracker_sites') |
|
| 207 | + ->where('tracker_sites.status', 'enabled') |
|
| 208 | + ->where('tracker_sites.use_custom', 'Y') |
|
| 209 | + ->get(); |
|
| 210 | 210 | |
| 211 | 211 | $sites = $query->result_array(); |
| 212 | 212 | foreach ($sites as $site) { |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | //Make sure last_checked is always updated on successful run. |
| 224 | 224 | //CHECK: Is there a reason we aren't just doing this in updateByID? |
| 225 | 225 | $this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE) |
| 226 | - ->where('id', $titleID) |
|
| 227 | - ->update('tracker_titles'); |
|
| 226 | + ->where('id', $titleID) |
|
| 227 | + ->update('tracker_titles'); |
|
| 228 | 228 | |
| 229 | 229 | print " - ({$titleData['latest_chapter']})\n"; |
| 230 | 230 | } else { |
@@ -253,13 +253,13 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | public function refollowCustom() { |
| 255 | 255 | $query = $this->db->select('tracker_titles.id, tracker_titles.title_url, tracker_sites.site_class') |
| 256 | - ->from('tracker_titles') |
|
| 257 | - ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 258 | - ->where('tracker_titles.followed','N') |
|
| 259 | - ->where('tracker_titles !=', '255') |
|
| 260 | - ->where('tracker_sites.status', 'enabled') |
|
| 261 | - ->where('tracker_sites.use_custom', 'Y') |
|
| 262 | - ->get(); |
|
| 256 | + ->from('tracker_titles') |
|
| 257 | + ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 258 | + ->where('tracker_titles.followed','N') |
|
| 259 | + ->where('tracker_titles !=', '255') |
|
| 260 | + ->where('tracker_sites.status', 'enabled') |
|
| 261 | + ->where('tracker_sites.use_custom', 'Y') |
|
| 262 | + ->get(); |
|
| 263 | 263 | |
| 264 | 264 | if($query->num_rows() > 0) { |
| 265 | 265 | foreach($query->result() as $row) { |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | if(!empty($titleData)) { |
| 272 | 272 | $this->db->set($titleData) |
| 273 | - ->where('id', $row->id) |
|
| 274 | - ->update('tracker_titles'); |
|
| 273 | + ->where('id', $row->id) |
|
| 274 | + ->update('tracker_titles'); |
|
| 275 | 275 | |
| 276 | 276 | print "> {$row->site_class}:{$row->id}:{$row->title_url} FOLLOWED\n"; |
| 277 | 277 | } else { |
@@ -291,14 +291,14 @@ discard block |
||
| 291 | 291 | $date = $temp_now->format('Y-m-d'); |
| 292 | 292 | |
| 293 | 293 | $query = $this->db->select('1') |
| 294 | - ->from('site_stats') |
|
| 295 | - ->where('date', $date) |
|
| 296 | - ->get(); |
|
| 294 | + ->from('site_stats') |
|
| 295 | + ->where('date', $date) |
|
| 296 | + ->get(); |
|
| 297 | 297 | |
| 298 | 298 | if($query->num_rows() > 0) { |
| 299 | 299 | $this->db->set('total_requests', 'total_requests+1', FALSE) |
| 300 | - ->where('date', $date) |
|
| 301 | - ->update('site_stats'); |
|
| 300 | + ->where('date', $date) |
|
| 301 | + ->update('site_stats'); |
|
| 302 | 302 | } else { |
| 303 | 303 | $this->db->insert('site_stats', [ |
| 304 | 304 | 'date' => $date, |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
|
| 1 | +<?php declare(strict_types = 1); defined('BASEPATH') OR exit('No direct script access allowed'); |
|
| 2 | 2 | |
| 3 | 3 | class Tracker_Admin_Model extends Tracker_Base_Model { |
| 4 | 4 | public function __construct() { |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $query = $query->get(); |
| 78 | 78 | |
| 79 | 79 | if($query->num_rows() > 0) { |
| 80 | - foreach ($query->result() as $row) { |
|
| 80 | + foreach($query->result() as $row) { |
|
| 81 | 81 | $this->handleUpdate($row); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $query = $query->get(); |
| 135 | 135 | |
| 136 | 136 | if($query->num_rows() > 0) { |
| 137 | - foreach ($query->result() as $row) { |
|
| 137 | + foreach($query->result() as $row) { |
|
| 138 | 138 | $this->handleUpdate($row); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -209,10 +209,10 @@ discard block |
||
| 209 | 209 | ->get(); |
| 210 | 210 | |
| 211 | 211 | $sites = $query->result_array(); |
| 212 | - foreach ($sites as $site) { |
|
| 212 | + foreach($sites as $site) { |
|
| 213 | 213 | $siteClass = $this->sites->{$site['site_class']}; |
| 214 | 214 | if($titleDataList = $siteClass->doCustomUpdate()) { |
| 215 | - foreach ($titleDataList as $titleURL => $titleData) { |
|
| 215 | + foreach($titleDataList as $titleURL => $titleData) { |
|
| 216 | 216 | $titleURL = (string) $titleURL; //Number only keys get converted to int for some reason, so we need to fix that. |
| 217 | 217 | print "> {$titleData['title']} <{$site['site_class']}>"; //Print this prior to doing anything so we can more easily find out if something went wrong |
| 218 | 218 | if(is_array($titleData) && !is_null($titleData['latest_chapter'])) { |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | $query = $this->db->select('tracker_titles.id, tracker_titles.title_url, tracker_sites.site_class') |
| 256 | 256 | ->from('tracker_titles') |
| 257 | 257 | ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
| 258 | - ->where('tracker_titles.followed','N') |
|
| 258 | + ->where('tracker_titles.followed', 'N') |
|
| 259 | 259 | ->where('tracker_titles !=', '255') |
| 260 | 260 | ->where('tracker_sites.status', 'enabled') |
| 261 | 261 | ->where('tracker_sites.use_custom', 'Y') |
@@ -184,8 +184,7 @@ |
||
| 184 | 184 | print " - Something went wrong?\n"; |
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | - } |
|
| 188 | - else { |
|
| 187 | + } else { |
|
| 189 | 188 | log_message('error', "{$row->site_class} | {$row->title} ({$row->title_url}) | Failed to update."); |
| 190 | 189 | $this->Tracker->title->updateFailedChecksByID((int) $row->title_id); |
| 191 | 190 | |