Ejemplo n.º 1
0
 /**
  * Clears the queue.
  */
 public function clearQueue()
 {
     if (Config::getInstance()->isMod($this->getSender())) {
         cliLog("Queue cleared.", 'QUEUE');
         $this->__aNicks = array();
         $this->setReturnMessage(Config::getInstance()->lang('QUEUE_CLEARED'));
     }
 }
Ejemplo n.º 2
0
<?php

namespace Slimpd\modules\database;

try {
    $app->container->singleton('db', function ($app) {
        try {
            mysqli_report(MYSQLI_REPORT_STRICT);
            $dbh = new \mysqli($app->config['database']['host'], $app->config['database']['username'], $app->config['database']['password'], $app->config['database']['database']);
        } catch (\Exception $e) {
            $app = \Slim\Slim::getInstance();
            if (PHP_SAPI === 'cli') {
                cliLog($app->ll->str('database.connect'), 1, 'red');
                $app->stop();
            }
            $app->flash('error', $app->ll->str('database.connect'));
            $app->redirect('/');
        }
        /*
        $dbh = new \PDO(
        	"mysql:host=".$app->config['database']['host'] .
        	";dbname=".$app->config['database']['database'],
        	$app->config['database']['username'],
        	$app->config['database']['password']
        );  
        $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        */
        return $dbh;
    });
} catch (\Exception $e) {
    if ($debug) {
Ejemplo n.º 3
0
 private function getNumberScheme($value, $idx = NULL)
 {
     $value = str_replace(array("of", " ", ".", ","), "/", $value);
     if ($value == '') {
         return 'missing';
     }
     if (intval($value) == strval($value) && is_numeric($value) === TRUE) {
         $this->extractedTrackNumbers[$idx] = $value;
         $this->recommend($idx, array('number' => $value));
         return 'simple';
         // 1, 2, 3
     }
     if (ltrim($value, '0') != strval($value)) {
         $this->extractedTrackNumbers[$idx] = intval($value);
         $this->recommend($idx, array('number' => intval($value)));
         return 'leadingzero';
         // 01, 02
     }
     if (preg_match("/^(\\d*)\\/(\\d*)\$/", $value, $m)) {
         $this->extractedTrackNumbers[$idx] = intval($m[1]);
         $this->extractedTotalTracks[$idx] = intval($m[2]);
         $this->recommend($idx, array('number' => intval($m[1])));
         $this->recommend('album', array('totalTracks' => intval($m[2])));
         return 'slashsplit';
         // 01/12 , 2/12
     }
     if (preg_match("/^([a-zA-Z]{1,2})(?:[\\/-]{1})(\\d*)\$/", $value)) {
         if ($idx !== NULL) {
             $this->extractedTrackNumbers[$idx] = $value;
             $this->recommend($idx, array('number' => $value, 'source' => 'Vinyl'));
             $this->recommend('album', array('source' => 'Vinyl'));
         }
         return 'vinyl';
         // AA1, B2, C34, A-1, A/4
     }
     cliLog(__FUNCTION__ . "(" . $value . ") unknown", 6, 'red');
     return 'unknown';
 }
Ejemplo n.º 4
0
 public function waitForMpd()
 {
     $this->jobPhase = 1;
     $recursionInterval = 3;
     // seconds
     $mpd = new \Slimpd\modules\mpd\mpd();
     $status = $mpd->cmd('status');
     if (isset($status['updating_db'])) {
         if ($this->waitingLoop === 0) {
             $this->waitingLoop = time();
             // fake total items with total seconds
             $this->itemCountTotal = (int) $this->maxWaitingTime;
             $this->beginJob(array(), __FUNCTION__);
         }
         if (time() - $this->waitingLoop > $this->maxWaitingTime) {
             cliLog('max waiting time (' . $this->maxWaitingTime . ' sec) for mpd reached. exiting now...', 1, 'red', TRUE);
             $this->finishJob(NULL, __FUNCTION__);
             \Slim\Slim::getInstance()->stop();
         }
         $this->itemCountProcessed = time() - $this->waitingLoop;
         $this->itemCountChecked = time() - $this->waitingLoop;
         $this->updateJob(array(), __FUNCTION__);
         //cliLog('waiting '. (time()-$this->waitingLoop - $this->maxWaitingTime)*-1 .' sec. until mpd\'s internal database-update has finished');
         sleep($recursionInterval);
         // recursion
         return $this->waitForMpd();
     }
     if ($this->waitingLoop > 0) {
         $this->itemCountProcessed = $this->itemCountTotal;
         cliLog('mpd seems to be ready. continuing...', 1, 'green');
         $this->finishJob(NULL, __FUNCTION__);
     }
     return;
 }
Ejemplo n.º 5
0
 /**
  * Parses configs/config.ini file and saves it to an array
  */
 public function __construct()
 {
     $this->__aConfig = parse_ini_file(getBasePath() . 'configs/config.ini', false, INI_SCANNER_NORMAL);
     cliLog("Configuration loaded from configs/config.ini", 'SETUP');
 }
Ejemplo n.º 6
0
 /**
  * Can be used as hook after a command is executed.
  *
  * @return void
  */
 public function onAfterExecute()
 {
     cliLog("Trigger " . __METHOD__, 'COMMANDER');
 }
Ejemplo n.º 7
0
 /**
  * Checks if the message matches a command and returns the output from the command, if some is returned.
  *
  * @param $sMessage
  * @param $sFrom
  *
  * @return string
  */
 public function processMessage($sMessage, $sFrom)
 {
     $sReturn = '';
     // Checking for static command
     $aMessage = explode(' ', $sMessage);
     if (is_array($aMessage) && in_array(substr($aMessage[0], 1), array_keys($this->getStaticCommands()))) {
         cliLog("Static command found: " . $aMessage[0], 'COMMANDER');
         $sReturn = sprintf($this->getStaticCommand(substr($aMessage[0], 1)), '@' . $sFrom);
     }
     // Checking for dynamic command
     foreach ($this->getCommands() as $aCommand) {
         if (preg_match($aCommand['sPattern'], $sMessage)) {
             cliLog("Command found: " . $aCommand['sReadablePattern'], 'COMMANDER');
             $sReturn = $aCommand['oCommand']->execute($sMessage, $sFrom);
             break;
         }
     }
     return $sReturn;
 }
Ejemplo n.º 8
0
 /**
  * Displays stuff to the broswer and sends data to the server.
  *
  * @param string $sCommand
  * @param null   $sMessage
  */
 public function sendData($sCommand, $sMessage = null)
 {
     $sPut = $sCommand;
     if (!empty($sMessage)) {
         $sPut .= ' ' . $sMessage;
     }
     cliLog($sPut, 'SENDING');
     fputs($this->getSocket(), $sPut . "\r\n");
 }