本文整理汇总了PHP中nzedb\utility\Misc类的典型用法代码示例。如果您正苦于以下问题:PHP Misc类的具体用法?PHP Misc怎么用?PHP Misc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Misc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param Settings $pdo
*/
public function __construct(Settings $pdo = null)
{
parent::__construct($pdo);
$this->_git = new \nzedb\utility\Git();
// Do not remove the full namespace/ PHP gets confused for some reason without it.
$this->_vers = Misc::getValidVersionsFile();
$this->_setColourMasks();
}
示例2: fetchImage
/**
* Get a URL or file image and convert it to string.
*
* @param string $imgLoc URL or file location.
*
* @return bool|mixed|string
*/
protected function fetchImage($imgLoc)
{
$img = false;
if (strpos(strtolower($imgLoc), 'http:') === 0 || strpos(strtolower($imgLoc), 'https:') === 0) {
$img = Misc::getUrl(['url' => $imgLoc]);
} else {
if (is_file($imgLoc)) {
$img = @file_get_contents($imgLoc);
}
}
if ($img !== false) {
$im = @imagecreatefromstring($img);
if ($im !== false) {
imagedestroy($im);
return $img;
}
}
return false;
}
示例3: realpath
<?php
require_once realpath(dirname(dirname(dirname(dirname(__DIR__)))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\Tmux;
use nzedb\db\Settings;
use nzedb\utility\Misc;
$pdo = new Settings();
$DIR = nZEDb_MISC;
// Check that Db patch level is current. Also checks nZEDb.xml is valid.
Misc::isPatched();
Misc::clearScreen();
$patch = $pdo->getSetting('sqlpatch');
$patch = $patch != '' ? $patch : 0;
$delaytimet = $pdo->getSetting('delaytime');
$delaytimet = $delaytimet ? (int) $delaytimet : 2;
$nntpproxy = $pdo->getSetting('nntpproxy');
echo "Starting Tmux...\n";
// Create a placeholder session so tmux commands do not throw server not found errors.
exec('tmux new-session -ds placeholder 2>/dev/null');
// Search for NNTPProxy session that might be running from a user threaded.php run. Setup a clean environment to run in.
exec("tmux list-session | grep NNTPProxy", $nntpkill);
if (count($nntpkill) !== 0) {
exec("tmux kill-session -t NNTPProxy");
echo $pdo->log->notice("Found NNTPProxy tmux session and killing it.");
} else {
exec("tmux list-session", $session);
}
$t = new Tmux();
$tmux = $t->get();
$tmux_session = isset($tmux->tmux_session) ? $tmux->tmux_session : 0;
$seq = isset($tmux->sequential) ? $tmux->sequential : 0;
示例4: getValidVersionsFile
public function getValidVersionsFile($filepath = null)
{
$filepath = empty($filepath) ? $this->_filespec : $filepath;
$temp = libxml_use_internal_errors(true);
$this->_xml = simplexml_load_file($filepath);
libxml_use_internal_errors($temp);
if ($this->_xml === false) {
if (Misc::isCLI()) {
$this->out->error("Your versions XML file ({$filepath}) is broken, try updating from git.");
}
throw new \Exception("Failed to open versions XML file '{$filepath}'");
}
if ($this->_xml->count() > 0) {
$vers = $this->_xml->xpath('/nzedb/versions');
if ($vers[0]->count() == 0) {
$this->out->error("Your versions XML file ({nZEDb_VERSIONS}) does not contain version info, try updating from git.");
throw new \Exception("Failed to find versions node in XML file '{$filepath}'");
} else {
$this->out->primary("Your versions XML file ({nZEDb_VERSIONS}) looks okay, continuing.");
$this->_vers =& $this->_xml->versions;
}
} else {
throw new \RuntimeException("No elements in file!\n");
}
return $this->_xml;
}
示例5: addFromXml
public function addFromXml($releaseID, $xml)
{
$xmlObj = @simplexml_load_string($xml);
$arrXml = Misc::objectsIntoArray($xmlObj);
$containerformat = '';
$overallbitrate = '';
if (isset($arrXml['File']) && isset($arrXml['File']['track'])) {
foreach ($arrXml['File']['track'] as $track) {
if (isset($track['@attributes']) && isset($track['@attributes']['type'])) {
if ($track['@attributes']['type'] == 'General') {
if (isset($track['Format'])) {
$containerformat = $track['Format'];
}
if (isset($track['Overall_bit_rate'])) {
$overallbitrate = $track['Overall_bit_rate'];
}
} else {
if ($track['@attributes']['type'] == 'Video') {
$videoduration = $videoformat = $videocodec = $videowidth = $videoheight = $videoaspect = $videoframerate = $videolibrary = '';
if (isset($track['Duration'])) {
$videoduration = $track['Duration'];
}
if (isset($track['Format'])) {
$videoformat = $track['Format'];
}
if (isset($track['Codec_ID'])) {
$videocodec = $track['Codec_ID'];
}
if (isset($track['Width'])) {
$videowidth = preg_replace('/[^0-9]/', '', $track['Width']);
}
if (isset($track['Height'])) {
$videoheight = preg_replace('/[^0-9]/', '', $track['Height']);
}
if (isset($track['Display_aspect_ratio'])) {
$videoaspect = $track['Display_aspect_ratio'];
}
if (isset($track['Frame_rate'])) {
$videoframerate = str_replace(' fps', '', $track['Frame_rate']);
}
if (isset($track['Writing_library'])) {
$videolibrary = $track['Writing_library'];
}
$this->addVideo($releaseID, $containerformat, $overallbitrate, $videoduration, $videoformat, $videocodec, $videowidth, $videoheight, $videoaspect, $videoframerate, $videolibrary);
} else {
if ($track['@attributes']['type'] == 'Audio') {
$audioID = 1;
$audioformat = $audiomode = $audiobitratemode = $audiobitrate = $audiochannels = $audiosamplerate = $audiolibrary = $audiolanguage = $audiotitle = '';
if (isset($track['@attributes']['streamid'])) {
$audioID = $track['@attributes']['streamid'];
}
if (isset($track['Format'])) {
$audioformat = $track['Format'];
}
if (isset($track['Mode'])) {
$audiomode = $track['Mode'];
}
if (isset($track['Bit_rate_mode'])) {
$audiobitratemode = $track['Bit_rate_mode'];
}
if (isset($track['Bit_rate'])) {
$audiobitrate = $track['Bit_rate'];
}
if (isset($track['Channel_s_'])) {
$audiochannels = $track['Channel_s_'];
}
if (isset($track['Sampling_rate'])) {
$audiosamplerate = $track['Sampling_rate'];
}
if (isset($track['Writing_library'])) {
$audiolibrary = $track['Writing_library'];
}
if (isset($track['Language'])) {
$audiolanguage = $track['Language'];
}
if (isset($track['Title'])) {
$audiotitle = $track['Title'];
}
$this->addAudio($releaseID, $audioID, $audioformat, $audiomode, $audiobitratemode, $audiobitrate, $audiochannels, $audiosamplerate, $audiolibrary, $audiolanguage, $audiotitle);
} else {
if ($track['@attributes']['type'] == 'Text') {
$subsID = 1;
$subslanguage = 'Unknown';
if (isset($track['@attributes']['streamid'])) {
$subsID = $track['@attributes']['streamid'];
}
if (isset($track['Language'])) {
$subslanguage = $track['Language'];
}
$this->addSubs($releaseID, $subsID, $subslanguage);
}
}
}
}
}
}
}
}
示例6: yahooSearch
/**
* Try to find a IMDB id on yahoo.com
*
* @return bool
*/
protected function yahooSearch()
{
$buffer = Misc::getUrl(['url' => "http://search.yahoo.com/search?n=10&ei=UTF-8&va_vt=title&vo_vt=any&ve_vt=any&vp_vt=any&vf=all&vm=p&fl=0&fr=fp-top&p=intitle:" . urlencode('intitle:' . implode(' intitle:', explode(' ', preg_replace('/\\s+/', ' ', preg_replace('/\\W/', ' ', $this->currentTitle)))) . ' intitle:' . $this->currentYear) . '&vs=' . urlencode('www.imdb.com/title/')]);
if ($buffer !== false) {
$this->yahooLimit++;
if ($this->doMovieUpdate($buffer, 'Yahoo.com', $this->currentRelID) !== false) {
return true;
}
}
return false;
}
示例7: resumeAll
/**
* Resume all NZB's in the SAB queue.
*
* @return bool|mixed
*/
public function resumeAll()
{
return Misc::getUrl(['url' => $this->url . "api?mode=resume" . "&apikey=" . $this->apikey, 'verifycert' => false]);
}
示例8: isNFO
/**
* Confirm this is an NFO file.
*
* @param string $possibleNFO The nfo.
* @param string $guid The guid of the release.
*
* @return bool True on success, False on failure.
*
* @access public
*/
public function isNFO(&$possibleNFO, $guid)
{
if ($possibleNFO === false) {
return false;
}
// Make sure it's not too big or small, size needs to be at least 12 bytes for header checking. Ignore common file types.
$size = strlen($possibleNFO);
if ($size < 65535 && $size > 11 && !preg_match('/\\A(\\s*<\\?xml|=newz\\[NZB\\]=|RIFF|\\s*[RP]AR|.{0,10}(JFIF|matroska|ftyp|ID3))|;\\s*Generated\\s*by.*SF\\w/i', $possibleNFO)) {
// File/GetId3 work with files, so save to disk.
$tmpPath = $this->tmpPath . $guid . '.nfo';
file_put_contents($tmpPath, $possibleNFO);
$result = Misc::fileInfo($tmpPath);
if (!empty($result)) {
// Check if it's text.
if (preg_match('/(ASCII|ISO-8859|UTF-(8|16|32).*?)\\s*text/', $result)) {
@unlink($tmpPath);
return true;
// Or binary.
} else {
if (preg_match('/^(JPE?G|Parity|PNG|RAR|XML|(7-)?[Zz]ip)/', $result) || preg_match('/[\\x00-\\x08\\x12-\\x1F\\x0B\\x0E\\x0F]/', $possibleNFO)) {
@unlink($tmpPath);
return false;
}
}
}
// If above checks couldn't make a categorical identification, Use GetId3 to check if it's an image/video/rar/zip etc..
$check = (new \getid3())->analyze($tmpPath);
@unlink($tmpPath);
if (isset($check['error'])) {
// Check if it's a par2.
$par2info = new \Par2Info();
$par2info->setData($possibleNFO);
if ($par2info->error) {
// Check if it's an SFV.
$sfv = new \SfvInfo();
$sfv->setData($possibleNFO);
if ($sfv->error) {
return true;
}
}
}
}
return false;
}
示例9: setCovers
public function setCovers()
{
$path = $this->getSetting(['section' => 'site', 'subsection' => 'main', 'name' => 'coverspath', 'setting' => 'coverspath']);
Misc::setCoversConstant($path);
}
示例10: isset
$relData = $releases->searchbyRageId(isset($_GET['rid']) ? $_GET['rid'] : '-1', isset($_GET['season']) ? $_GET['season'] : '', isset($_GET['ep']) ? $_GET['ep'] : '', $offset, limit(), isset($_GET['q']) ? $_GET['q'] : '', categoryID(), $maxAge);
addLanguage($relData, $page->settings);
printOutput($relData, $outputXML, $page, $offset);
break;
// Search movie releases.
// Search movie releases.
case 'm':
verifyEmptyParameter('q');
verifyEmptyParameter('imdbid');
$maxAge = maxAge();
$page->users->addApiRequest($uid, $_SERVER['REQUEST_URI']);
$offset = offset();
$imdbId = isset($_GET['imdbid']) ? $_GET['imdbid'] : '-1';
$relData = $releases->searchbyImdbId($imdbId, $offset, limit(), isset($_GET['q']) ? $_GET['q'] : '', categoryID(), $maxAge);
addCoverURL($relData, function ($release) {
return Misc::getCoverURL(['type' => 'movies', 'id' => $release['imdbid']]);
});
addLanguage($relData, $page->settings);
printOutput($relData, $outputXML, $page, $offset);
break;
// Get NZB.
// Get NZB.
case 'g':
if (!isset($_GET['id'])) {
showApiError(200, 'Missing parameter (id is required for downloading an NZB)');
}
$relData = $releases->getByGuid($_GET['id']);
if ($relData) {
header('Location:' . WWW_TOP . '/getnzb?i=' . $uid . '&r=' . $apiKey . '&id=' . $relData['guid'] . (isset($_GET['del']) && $_GET['del'] == '1' ? '&del=1' : ''));
} else {
showApiError(300, 'No such item (the guid you provided has no release in our database)');
示例11: _initiateYEncSettings
/**
* Check the Admin settings for yEnc and process them accordingly.
*
* @void
*
* @access protected
*/
protected function _initiateYEncSettings()
{
// Check if the user wants to use yyDecode or the simple_php_yenc_decode extension.
$this->_yyDecoderPath = $this->pdo->getSetting('yydecoderpath') != '' ? (string) $this->pdo->getSetting('yydecoderpath') : false;
if (strpos((string) $this->_yyDecoderPath, 'simple_php_yenc_decode') !== false) {
if (extension_loaded('simple_php_yenc_decode')) {
$this->_yEncExtension = true;
} else {
$this->_yyDecoderPath = false;
}
} else {
if ($this->_yyDecoderPath !== false) {
$this->_yEncSilence = Misc::isWin() ? '' : ' > /dev/null 2>&1';
$this->_yEncTempInput = nZEDb_TMP . 'yEnc' . DS;
$this->_yEncTempOutput = $this->_yEncTempInput . 'output';
$this->_yEncTempInput .= 'input';
// Test if the user can read/write to the yEnc path.
if (!is_file($this->_yEncTempInput)) {
@file_put_contents($this->_yEncTempInput, 'x');
}
if (!is_file($this->_yEncTempInput) || !is_readable($this->_yEncTempInput) || !is_writable($this->_yEncTempInput)) {
$this->_yyDecoderPath = false;
}
if (is_file($this->_yEncTempInput)) {
@unlink($this->_yEncTempInput);
}
}
}
}
示例12: exit
<?php
require_once './config.php';
use nzedb\NZBExport;
use nzedb\Releases;
use nzedb\utility\Misc;
if (Misc::isCLI()) {
exit('This script is only for exporting from the web, use the script in misc/testing' . PHP_EOL);
}
$page = new AdminPage();
$rel = new Releases(['Settings' => $page->settings]);
$folder = $group = $fromDate = $toDate = $gzip = $output = '';
if ($page->isPostBack()) {
$folder = $_POST["folder"];
$fromDate = isset($_POST["postfrom"]) ? $_POST["postfrom"] : '';
$toDate = isset($_POST["postto"]) ? $_POST["postto"] : '';
$group = $_POST["group"];
$gzip = $_POST["gzip"];
if ($folder != '') {
$output = (new NZBExport(['Browser' => true, 'Settings' => $page->settings, 'Releases' => $rel]))->beginExport([$folder, $fromDate, $toDate, $_POST["group"] === '-1' ? 0 : (int) $_POST["group"], $_POST["gzip"] === '1' ? true : false]);
} else {
$output = 'Error, a path is required!';
}
} else {
$fromDate = $rel->getEarliestUsenetPostDate();
$toDate = $rel->getLatestUsenetPostDate();
}
$page->title = "Export Nzbs";
$page->smarty->assign(['output' => $output, 'folder' => $folder, 'fromdate' => $fromDate, 'todate' => $toDate, 'group' => $group, 'gzip' => $gzip, 'gziplist' => [1 => 'True', 0 => 'False'], 'grouplist' => $rel->getReleasedGroupsForSelect(true)]);
$page->content = $page->smarty->fetch('nzb-export.tpl');
$page->render();
示例13: count
}
$total = count($data);
$predb = new PreDb();
$progress = $predb->progress(settings_array());
foreach ($data as $file) {
if (preg_match("#^https://raw\\.githubusercontent\\.com/nZEDb/nZEDbPre_Dumps/master/dumps/{$filePattern}\$#", $file['download_url'])) {
if (preg_match("#^{$filePattern}\$#", $file['name'], $match)) {
$timematch = $progress['last'];
// Skip patches the user does not want.
if ($match[1] < $timematch) {
echo 'Skipping dump ' . $match[2] . ', as your minimum unix time argument is ' . $timematch . PHP_EOL;
--$total;
continue;
}
// Download the dump.
$dump = Misc::getUrl(['url' => $file['download_url']]);
echo "Downloading: {$file['download_url']}\n";
if (!$dump) {
echo "Error downloading dump {$match[2]} you can try manually importing it." . PHP_EOL;
continue;
} else {
if (nZEDb_DEBUG) {
echo "Dump {$match[2]} downloaded\n";
}
}
// Make sure we didn't get an HTML page.
if (strpos($dump, '<!DOCTYPE html>') !== false) {
echo "The dump file {$match[2]} might be missing from GitHub." . PHP_EOL;
continue;
}
// Decompress.
示例14: getJsonArray
/**
* Download JSON from Trakt, convert to array.
*
* @param string $URI URI to download.
* @param string $extended Extended info from trakt tv.
* Valid values:
* 'min' Returns enough info to match locally. (Default)
* 'images' Minimal info and all images.
* 'full' Complete info for an item.
* 'full,images' Complete info and all images.
*
* @return bool|mixed
*/
private function getJsonArray($URI, $extended = 'min')
{
if (!empty($this->clientID)) {
$json = Misc::getUrl(['url' => $URI . "?extended={$extended}", 'requestheaders' => $this->requestHeaders]);
if ($json !== false) {
$json = json_decode($json, true);
if (!is_array($json) || isset($json['status']) && $json['status'] === 'failure') {
return false;
}
return $json;
}
}
return false;
}
示例15: dirname
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see LICENSE.txt in the base directory. If
* not, see:
*
* @link <http://www.gnu.org/licenses/>.
* @author niel
* @copyright 2015 nZEDb
*/
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'indexer.php';
use nzedb\db\DbUpdate;
use nzedb\utility\Git;
use nzedb\utility\Misc;
if (!Misc::isCLI()) {
exit;
}
$error = false;
$git = new Git();
$branch = $git->active_branch();
if (in_array($branch, $git->mainBranches())) {
// Only update patches, etc. on specific branches to lessen conflicts
try {
// Run DbUpdates to make sure we're up to date.
$DbUpdater = new DbUpdate(['git' => $git]);
$DbUpdater->newPatches(['safe' => false]);
} catch (\Exception $e) {
$error = 1;
echo "Error while checking patches!\n";
echo $e->getMessage() . "\n";