null, ]; $options += $defaults; $this->_db = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); if (defined('NN_VERSIONS')) { try { $this->_versions = new Versions(NN_VERSIONS); } catch (\Exception $e) { $this->_versions = false; } } } public function version() { return "0.4.1 nn-tmux-regexless"; } public function update($form) { $site = $this->row2Object($form); if (substr($site->nzbpath, strlen($site->nzbpath) - 1) != '/') $site->nzbpath = $site->nzbpath . "/"; // // Validate site settings // if ($site->mediainfopath != "" && !is_file($site->mediainfopath)) return Sites::ERR_BADMEDIAINFOPATH; if ($site->ffmpegpath != "" && !is_file($site->ffmpegpath)) return Sites::ERR_BADFFMPEGPATH; if ($site->unrarpath != "" && !is_file($site->unrarpath)) return Sites::ERR_BADUNRARPATH; if ($site->nzbpath != "" && !file_exists($site->nzbpath)) return Sites::ERR_BADNZBPATH; if ($site->checkpasswordedrar == 2 && !is_file($site->unrarpath)) return Sites::ERR_DEEPNOUNRAR; if ($site->tmpunrarpath != "" && !file_exists($site->tmpunrarpath)) return Sites::ERR_BADTMPUNRARPATH; if ($site->lamepath != "" && !file_exists($site->lamepath)) return Sites::ERR_BADLAMEPATH; if ($site->sabcompletedir != "" && !file_exists($site->sabcompletedir)) return Sites::ERR_SABCOMPLETEPATH; $sql = $sqlKeys = []; foreach ($form as $settingK => $settingV) { $sql[] = sprintf("WHEN %s THEN %s", $this->_db->escapeString($settingK), $this->_db->escapeString(trim($settingV))); $sqlKeys[] = $this->_db->escapeString($settingK); } $this->_db->exec(sprintf("update site SET value = CASE setting %s END WHERE setting IN (%s)", implode(' ', $sql), implode(', ', $sqlKeys))); return $this->get(true); } public function get($refresh = false) { $sql = "select * from site"; if ($refresh) { $cache = new Cache(); $cache->delete($sql); } $rows = $this->_db->query($sql, true, NN_CACHE_EXPIRY_MEDIUM); if ($rows === false) return false; return $this->rows2Object($rows); } public function rows2Object($rows) { $obj = new \stdClass; foreach ($rows as $row) $obj->{$row['setting']} = $row['value']; $obj->{'version'} = $this->version(); return $obj; } public function row2Object($row) { $obj = new \stdClass; $rowKeys = array_keys($row); foreach ($rowKeys as $key) $obj->{$key} = $row[$key]; return $obj; } public function getUnappliedPatches($site) { preg_match("/\d+/", $site->dbversion, $matches); $currentrev = $matches[0]; $patchpath = NN_WWW . "../db/patch/0.2.3/"; $patchfiles = glob($patchpath . "*.sql"); $missingpatch = []; foreach ($patchfiles as $file) { $filecontents = file_get_contents($file); if (preg_match("/Rev\: (\d+)/", $filecontents, $matches)) { $patchrev = $matches[1]; if ($patchrev > $currentrev) $missingpatch[] = $file; } } return $missingpatch; } public function updateItem($setting, $value) { $sql = sprintf("update settings set value = %s where setting = %s", $this->_db->escapeString($value), $this->_db->escapeString($setting)); return $this->_db->exec($sql); } public function updateLatestRegexRevision($rev) { return $this->updateItem("latestregexrevision", $rev); } public function getLicense($html = false) { $n = "\r\n"; if ($html) $n = "
"; return $n . "newznab " . $this->version() . " Copyright (C) " . date("Y") . " newznab.com" . $n . " This program is distributed with a commercial licence. See LICENCE.txt for further details." . $n; } }