protected function _validate(array $fields) { $defaults = ['checkpasswordedrar' => false, 'ffmpegpath' => '', 'mediainfopath' => '', 'nzbpath' => '', 'tmpunrarpath' => '', 'unrarpath' => '', 'yydecoderpath' => '']; $fields += $defaults; // Make sure keys exist to avoid error notices. ksort($fields); // Validate settings $fields['nzbpath'] = Text::trailingSlash($fields['nzbpath']); $error = null; switch (true) { case $fields['mediainfopath'] != '' && !is_file($fields['mediainfopath']): $error = Settings::ERR_BADMEDIAINFOPATH; break; case $fields['ffmpegpath'] != '' && !is_file($fields['ffmpegpath']): $error = Settings::ERR_BADFFMPEGPATH; break; case $fields['unrarpath'] != '' && !is_file($fields['unrarpath']): $error = Settings::ERR_BADUNRARPATH; break; case empty($fields['nzbpath']): $error = Settings::ERR_BADNZBPATH_UNSET; break; case !file_exists($fields['nzbpath']) || !is_dir($fields['nzbpath']): $error = Settings::ERR_BADNZBPATH; break; case !is_readable($fields['nzbpath']): $error = Settings::ERR_BADNZBPATH_UNREADABLE; break; case $fields['checkpasswordedrar'] == 1 && !is_file($fields['unrarpath']): $error = Settings::ERR_DEEPNOUNRAR; break; case $fields['tmpunrarpath'] != '' && !file_exists($fields['tmpunrarpath']): $error = Settings::ERR_BADTMPUNRARPATH; break; case $fields['yydecoderpath'] != '' && $fields['yydecoderpath'] !== 'simple_php_yenc_decode' && !file_exists($fields['yydecoderpath']): $error = Settings::ERR_BAD_YYDECODER_PATH; } return $error; }
public static function setCoversConstant($path) { if (!defined('nZEDb_COVERS')) { switch (true) { case substr($path, 0, 1) == '/' || substr($path, 1, 1) == ':' || substr($path, 0, 1) == '\\': define('nZEDb_COVERS', Text::trailingSlash($path)); break; case strlen($path) > 0 && substr($path, 0, 1) != '/' && substr($path, 1, 1) != ':' && substr($path, 0, 1) != '\\': define('nZEDb_COVERS', realpath(nZEDb_ROOT . Text::trailingSlash($path))); break; case empty($path): // Default to resources location. // Default to resources location. default: define('nZEDb_COVERS', nZEDb_RES . 'covers' . DS); } } }
public function updateSchemaData(array $options = []) { $changed = false; $default = ['file' => '10-settings.tsv', 'path' => 'resources' . DS . 'db' . DS . 'schema' . DS . 'data' . DS, 'regex' => '#^(?P<section>.*)\\t(?P<subsection>.*)\\t(?P<name>.*)\\t(?P<value>.*)\\t(?P<hint>.*)\\t(?P<setting>.*)$#', 'value' => function (array $matches) { return "{$matches['section']}\t{$matches['subsection']}\t{$matches['name']}\t{$matches['value']}\t{$matches['hint']}\t{$matches['setting']}"; }]; $options += $default; $file = []; $filespec = Text::trailingSlash($options['path']) . $options['path']; if (file_exists($filespec) && ($file = file($filespec, FILE_IGNORE_NEW_LINES))) { $count = count($file); $index = 0; while ($index < $count) { if (preg_match($options['regex'], $file[$index], $matches)) { if (VERBOSE) { echo $this->log->primary("Matched: " . $file[$index]); } $index++; if (is_callable($options['value'])) { $file[$index] = $options['value']($matches); } else { $file[$index] = $options['value']; } $changed = true; } } } if ($changed) { if (file_put_contents($filespec, implode("\n", $file)) === false) { echo $this->log->error("Error writing file to disc!!"); } } }
if (!isset($argv[1])) { $message = <<<HELP This script can export a predb dump file. You may use the full path, or a relative path. For exporting, the path must be writeable by mysql, any existing file will be overwritten. Filename is optional, if not included it defaults to predb_export_YYYYMMDDhhmmss.tsv where YYYYMMDDhhmmss is the current UTC date-time. php {$argv[0]} /path/to/write/to/[<file-name>] ...: To export. HELP; exit($message); } else { $path = !preg_match('#^/#', $argv[1]) ? realpath($argv[1]) : $argv[1]; } if (file_exists($path) && is_file($path)) { unlink($path); } else { if (is_dir($path)) { $path = Text::trailingSlash($path) . 'predb_export_' . strftime('%Y%m%d%H%M%S') . '.tsv'; } } Misc::clearScreen(); $table = isset($argv[2]) ? $argv[2] : 'predb'; $predb = new PreDb(); if (nZEDb_ECHOCLI) { echo "Exporting table: {$table} to '{$path}'\n"; } $result = $predb->executeExport(['enclosed' => '', 'fields' => '\\t\\t', 'limit' => 0, 'lines' => '\\r\\n', 'path' => $path]); if ($result == false) { echo "ERROR: Failed to export file!\nMake sure the MySQL user has permission to write to the location.\n"; }