Example #1
0
 protected function bindFields(\PDOStatement $statment, File $file)
 {
     $statment->bindValue(':fileName', $file->getFileName());
     $statment->bindValue(':fileType', $file->getFileType());
     $statment->bindValue(':fileSize', $file->getFileSize());
     $statment->bindValue(':fileMediaInfo', $file->getFileMediaInfo());
     $statment->bindValue(':fileKey', $file->getFileKey());
 }
Example #2
0
 public function discernCheckCode()
 {
     $fileArray = File::getFileName($this->dataPath);
     $main = new MyMain();
     $im = $main->getCheckCode();
     $imageArray = $main->getImageArray($im);
     YImageTool::save($im, $this->tempFile);
     for ($index = 0; $index < $this->codeLenth; $index++) {
         $image = new YImage($imageArray[$index]);
         $image->quzhao();
         $image = $image->getDataAray();
         foreach ($fileArray as $value) {
             $im = imagecreatefromjpeg($this->dataPath . "" . $value . ".jpg");
             $tagImage = new YImage($im);
             $tagImage->quzhao();
             if ($tagImage->compare($image)) {
                 $this->checkCode = $this->checkCode . substr_replace($value, '', 1);
                 break;
             }
         }
     }
     return $this->checkCode;
 }
Example #3
0
 /**
  * @covers spriebsch\PHPca\File::getFilename
  */
 public function testGetFileName()
 {
     $file = new File('filename', 'sourcecode');
     $this->assertEquals('filename', $file->getFileName());
 }
Example #4
0
 public function saveImage($image)
 {
     $file = new File($image);
     if ($file->upload()) {
         $this->setImage($file->getFileName());
     }
     return $this;
 }
 /**
  * Callback for private messages (for default mood).
  *
  * @param   &peer.irc.IRCConnection connection
  * @param   string nick
  * @param   string target
  * @param   string message
  */
 public function handlePrivateMessageDefault($connection, $nick, $target, $message)
 {
     // Commands
     if (sscanf($message, "!%s %[^\r]", $command, $params)) {
         switch (strtolower($command)) {
             case '@reload':
                 if ($this->doPrivileged($connection, $nick, $params)) {
                     $this->reloadConfiguration();
                     $connection->sendAction($nick, 'received SIGHUP and reloads his configuration');
                 }
                 break;
             case '@shutdown':
                 if ($this->doPrivileged($connection, $nick, $params)) {
                     $this->storeConfiguration();
                     $connection->writeln('QUIT %s scheisst auf euch', $connection->user->getNick());
                     $connection->close();
                     // Needed, because the IRCConnection is used in while (1) ...
                     exit;
                 }
                 break;
             case '@sleep':
                 list($duration, $password) = explode(' ', $params);
                 if ($this->doPrivileged($connection, $nick, $password)) {
                     $this->doSleep($connection, $duration);
                 }
                 break;
             case '@changenick':
                 list($new_nick, $password) = explode(' ', $params);
                 if ($this->doPrivileged($connection, $nick, $password)) {
                     $connection->setNick($new_nick);
                 }
                 break;
             case '@karma':
                 if ($this->doPrivileged($connection, $nick, $params)) {
                     foreach ($this->karma as $name => $value) {
                         $connection->sendMessage($nick, '%s: %d', $name, $value);
                     }
                 }
                 break;
             case '@setkarma':
                 list($who, $value, $password) = explode(' ', $params);
                 if ($this->doPrivileged($connection, $nick, $password)) {
                     $this->setKarma($who, (int) $value);
                 }
                 break;
             case '@kick':
                 list($channel, $victim, $password) = explode(' ', $params);
                 if ($this->doPrivileged($connection, $nick, $password)) {
                     $connection->writeln('KICK %s %s :%s', $channel, $victim, sprintf($this->lists['karma.dislike'][rand(0, sizeof($this->lists['karma.dislike']) - 1)], $victim));
                 }
                 break;
             case '@join':
                 list($channel, $channelpass, $password) = explode(' ', $params);
                 if (empty($password)) {
                     $password = $channelpass;
                     $channelpass = NULL;
                 }
                 if ($this->doPrivileged($connection, $nick, $password)) {
                     $connection->join($channel, $channelpass);
                 }
                 break;
             case '@part':
                 list($channel, $password) = explode(' ', $params);
                 if ($this->doPrivileged($connection, $nick, $password)) {
                     $connection->part($channel);
                     unset($this->operator[$channel]);
                     unset($this->channels[$channel]);
                 }
                 break;
             case '@channels':
                 if ($this->doPrivileged($connection, $nick, $params)) {
                     $chans = '';
                     foreach (array_keys($this->channels) as $c) {
                         $chans .= sprintf('%s%s ', $this->operator[$c] ? '@' : '', $c);
                     }
                     $connection->sendMessage($nick, $chans);
                 }
                 break;
             case '@op':
             case '@deop':
                 list($channel, $nickname, $password) = explode(' ', $params);
                 if ($this->doPrivileged($connection, $nick, $password)) {
                     if (isset($this->operator[$channel]) && TRUE === $this->operator[$channel]) {
                         $connection->writeln('MODE %s %s %s', $channel, strtolower($command) == '@op' ? '+o' : '-o', $nickname);
                     } else {
                         $connection->sendMessage($nick, 'Ich bin kein Operator in %s', $channel);
                     }
                 }
                 break;
             case 'karma':
                 $this->setKarma($nick, 0);
                 // Make sure array is initialized
                 $connection->sendMessage($target, 'Karma für %s: %d', $nick, $this->karma[$nick]);
                 break;
             case 'uptime':
                 $delta = time() - $this->tstart;
                 // Break it up into days, hours and minutes
                 $days = $delta / 86400;
                 $delta -= (int) $days * 86400;
                 $hours = $delta / 3600;
                 $delta -= (int) $hours * 3600;
                 $minutes = $delta / 60;
                 $connection->writeln('NOTICE %s :Uptime: %d Tag(e), %d Stunde(n) und %d Minute(n)', $target, $days, $hours, $minutes);
                 $this->setKarma($nick, 1, '@@uptime');
                 break;
             case 'quote':
                 try {
                     if ($this->quote->connect()) {
                         do {
                             if (!($buf = $this->quote->readLine())) {
                                 continue;
                             }
                             $connection->sendMessage($target, '%s%s', IRCColor::forCode(IRC_COLOR_YELLOW), $buf);
                         } while (!$this->quote->eof());
                     }
                     $this->quote->close();
                 } catch (IOException $e) {
                     $e->printStackTrace();
                     $connection->sendMessage($target, '!%s', $e->getMessage());
                     break;
                 }
                 break;
             case 'whatis':
                 try {
                     if ($this->dictc->connect('dict.org', 2628)) {
                         $definitions = $this->dictc->getDefinition($params, '*');
                     }
                     $this->dictc->close();
                 } catch (Exception $e) {
                     $e->printStackTrace();
                     $connection->sendMessage($target, '!%s', $e->getMessage());
                     break;
                 }
                 // Check if we found something
                 if (empty($definitions)) {
                     $connection->sendMessage($target, '"%s": No match found', $params);
                     break;
                 }
                 // Make definitions available via www
                 $file = new File(sprintf('%s%swhatis_%s.html', rtrim($this->config->readString('whatis_www', 'document_root'), DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, strtolower(preg_replace('/[^a-z0-9_]/i', '_', $params))));
                 try {
                     $file->open(FILE_MODE_WRITE);
                     $file->write('<h1>What is "' . $params . '"?</h1>');
                     $file->write('<ol>');
                     for ($i = 0, $s = sizeof($definitions); $i < $s; $i++) {
                         $file->write('<li>Definition: ' . $definitions[$i]->getDatabase() . ')<br/>');
                         $file->write('<pre>' . $definitions[$i]->getDefinition() . '</pre>');
                         $file->write('</li>');
                     }
                     $file->write('</ol>');
                     $file->write('<hr/><small>Generated by ' . $connection->user->getNick() . ' at ' . date('r') . '</small>');
                     $file->close();
                 } catch (IOException $e) {
                     $e->printStackTrace();
                     $connection->sendMessage($target, '- %s', $e->getMessage());
                     break;
                 }
                 $connection->sendMessage($target, '"%s": Definitions @ %s%s', $params, $this->config->readString('whatis_www', 'base_href'), urlencode($file->getFileName()));
                 break;
             case 'say':
                 list($dest, $message) = explode(' ', $params, 2);
                 $connection->sendMessage($dest, $message);
                 break;
             case 'do':
                 list($dest, $action) = explode(' ', $params, 2);
                 $connection->sendAction($dest, $action);
                 break;
             case 'schwob':
                 $connection->sendMessage($target, Swabian::translate($params));
                 break;
             case 'bite':
                 $connection->sendAction($target, 'beißt %s', $params);
                 break;
             case 'beep':
             case 'hup':
                 $connection->sendAction($target, 'hupt (%s)' . "", $params);
                 break;
             case 'falsch':
                 $connection->sendMessage($target, '%s ist zwar süß, ABER %sFALSCH!', $params, IRCColor::forCode(IRC_COLOR_RED));
                 break;
             case 'kap0tt':
             case 'kaputt':
                 $connection->sendMessage($target, '%s ist zwar toll, ABER %sKAP0TT!', $params, IRCColor::forCode(IRC_COLOR_YELLOW));
                 break;
             case 'maul':
                 $this->sendRandomMessage($connection, $target, 'shutup', $params, NULL);
                 break;
             case 'i':
             case 'idiot':
                 if ('#' == $params[0]) {
                     // Allow #<channel>/<nick> so private messages work
                     list($target, $params) = explode('/', $params);
                 }
                 // Don't insult yourself - instead, insult the user:) Check on similar text
                 // so people can't get away with misspelling the name. We might accidentally
                 // also insult users with similar names than ours, but, hey, their fault.
                 similar_text(strtolower($params), strtolower($connection->user->getNick()), $percent);
                 if ($percent >= 75) {
                     $params = $nick;
                     $format = '%s, du bist %s';
                     $this->setKarma($nick, -5, '@@idiot');
                     $connection->sendAction($target, 'beleidigt sich nicht selbst');
                 } else {
                     $format = '%s ist %s';
                 }
                 $connection->sendMessage($target, $format, $params, $this->lists['swears'][rand(0, sizeof($this->lists['swears']) - 1)]);
                 break;
             case 'i+':
             case 'idiot+':
                 if (stristr($params, $connection->user->getNick())) {
                     $connection->sendAction($target, 'wird seinen eigenen Namen nicht als Schimpfwort akzeptieren');
                     $this->setKarma($nick, -2, '@@lamer');
                     return;
                 }
                 // Don't accept new swears from disliked nicks.
                 if ($this->karma[$nick] < 0) {
                     $connection->sendAction($target, 'hörte weg, als %s das Schimpfwort in den Raum wurf.', $nick);
                     $this->setKarma($nick, -1, '@@lamer');
                     return;
                 }
                 if (in_array($params, $this->lists['swears'])) {
                     $connection->sendAction($target, 'kannte das Schimpfwort >%s%s%s< schon', IRCColor::forCode(IRC_COLOR_ORANGE), $params, IRCColor::forCode(IRC_COLOR_DEFAULT));
                     break;
                 }
                 // Update swears array
                 $this->lists['swears'][] = $params;
                 // Also update the swears file
                 $f = new File(sprintf('%s%s%s', dirname($this->config->getFilename()), DIRECTORY_SEPARATOR, $this->config->readString('lists', 'swears')));
                 try {
                     $f->open(FILE_MODE_APPEND);
                     $f->write($params . "\n");
                     $f->close();
                 } catch (IOException $e) {
                     $connection->sendMessage($target, '! ' . $e->getMessage());
                     break;
                 }
                 $connection->sendAction($target, 'hat jetzt %d Schimpfwörter', sizeof($this->lists['swears']));
                 break;
             case 'i-':
             case 'idiot-':
                 // Don't accept swear removals from disliked nicks.
                 if ($this->karma[$nick] < 0) {
                     $connection->sendAction($target, 'hörte weg, als %s das Schimpfwort in den Raum wurf.', $nick);
                     $this->setKarma($nick, -1, '@@lamer');
                     return;
                 }
                 if (FALSE === ($index = array_search($params, $this->lists['swears']))) {
                     $connection->sendAction($target, 'kennt kein solches Wort.');
                     break;
                 }
                 // Remove from memory list.
                 unset($this->lists['swears'][$index]);
                 // Store the removed word
                 $f = new File(sprintf('%s%s%s.deleted', dirname($this->config->getFilename()), DIRECTORY_SEPARATOR, $this->config->readString('lists', 'swears')));
                 try {
                     $f->open(FILE_MODE_APPEND);
                     $f->write($params . "\n");
                     $f->close();
                 } catch (IOException $e) {
                     $connection->sendMessage($target, '! ' . $e->getMessage());
                     break;
                 }
                 // Also update the swears file
                 $f = new File(sprintf('%s%s%s', dirname($this->config->getFilename()), DIRECTORY_SEPARATOR, $this->config->readString('lists', 'swears')));
                 try {
                     $f->open(FILE_MODE_WRITE);
                     $f->write(implode("\n", $this->lists['swears']));
                     $f->close();
                 } catch (IOException $e) {
                     $connection->sendMessage($target, '! ' . $e->getMessage());
                     break;
                 }
                 $connection->sendMessage($target, 'Und wieder bin ich ein Stückchen anständiger geworden.');
                 break;
             case 'ascii':
                 $connection->sendMessage($target, 'ASCII #%d = %s', $params, chr($params));
                 break;
         }
         return;
     }
     // Any other phrase containing my name
     if (stristr($message, $connection->user->getNick())) {
         $karma = 0;
         $recognized = FALSE;
         // See if we can recognize something here and calculate karma - multiplied
         // by a random value because this message is directed at me.
         foreach ($this->recognition as $pattern => $delta) {
             if (!preg_match($pattern, $message)) {
                 continue;
             }
             $karma = rand(1, 5) * $delta[1];
             $recognized = TRUE;
             $this->setKarma($nick, $karma, $pattern);
         }
         // Check our bad words list
         if (!$recognized && ($swear = $this->containsSwear($message))) {
             $this->cat && $this->cat->debug($nick, 'said', $swear, 'to me, no good');
             $karma = rand(-5, -1);
             $recognized = TRUE;
             $this->setKarma($nick, $karma, '@@swear');
         }
         // Don't know what to do with this, say something random
         if (!$recognized) {
             $this->sendRandomMessage($connection, $target, 'talkback', $nick, $message);
             return;
         }
         // Send a karma-based message
         $this->sendRandomMessage($connection, $target, $karma < 0 ? 'karma.dislike' : 'karma.like', $nick, $message);
         return;
     }
     // Random actions
     switch (rand(0, 30)) {
         case 2:
             if (!$this->operator[$target]) {
                 break;
             }
             // Kick a random person with a very bad karma
             $victim = array_rand($this->karma);
             if ($this->karma[$victim] < -50) {
                 $connection->writeln('KICK %s %s :%s', $target, $victim, sprintf($this->lists['karma.dislike'][rand(0, sizeof($this->lists['karma.dislike']) - 1)], $victim));
             }
             break;
         case 10:
             if ($swear = $this->containsSwear($message)) {
                 $this->setKarma($nick, -1, $pattern, $swear);
             }
             break;
         case 15:
             $this->sendRandomMessage($connection, $target, 'noise', $nick, $message);
             break;
         case 16:
             $this->sendRandomMessage($connection, $target, $this->karma[array_rand($this->karma)] < 0 ? 'karma.dislike' : 'karma.like', $nick, $message);
             break;
     }
     // Karma recognition
     foreach ($this->recognition as $pattern => $delta) {
         if (!preg_match($pattern, $message)) {
             continue;
         }
         $this->setKarma($nick, $delta[0], $pattern);
     }
 }
Example #6
0
 /**
  * function return set file to user
  *
  * @param File $oFile file object
  *
  * @param bool $dispositionInline if true then diposition is 'inline' else
  * 									disposition is 'attachment', default -
  * 									true (disposition 'inline')
  * @return bool is file sent
  */
 function downloadFile($oFile, $dispositionInline = false)
 {
     if (empty($oFile)) {
         $this->farrErrors[] = "File not set";
         return false;
     }
     if (!$oFile->getFileMimeType()) {
         $this->farrErrors[] = "File mime type not set";
         return false;
     }
     $disposition = $dispositionInline ? $disposition = 'inline' : ($disposition = 'attachment');
     header('Content-type: ' . $oFile->getFileMimeType());
     header('Content-Disposition: ' . $disposition . '; filename="' . $oFile->getFileUserName() . '"');
     header('Content-Length: ' . $oFile->getFileSize());
     readfile($oFile->getFilePath() . $oFile->getFileName());
     return true;
 }
Example #7
0
 public function scan($id)
 {
     $scanner = new ScanAssets();
     $file_id = (int) $id;
     $file = new File();
     $file->findFileById($file_id);
     $success = false;
     $icon = File::getIconFromMime($file->getMime());
     if ($scanner->scanFile($file->getId())) {
         $success = true;
     }
     if ($icon === false) {
         $icon = $file->getUrl();
     }
     if ($success) {
         // we need to reload the file because scanner might have updated fields
         // and our object is out of date
         $file->findFileById($file_id);
         // move file to S3
         try {
             File::s3Upload($file->getRealPath(), APP_ATTACHMENT_PATH . $file->getFileName(), true, $file->getTitle());
             $file->setUrl(APP_ATTACHMENT_URL . $file->getFileName());
             $file->save();
             // delete the physical file now it is in S3
             unlink($file->getRealPath());
         } catch (Exception $e) {
             $success = false;
             $error = 'There was a problem uploading your file';
             error_log(__FILE__ . ": Error uploading images to S3:\n{$e}");
         }
     }
     return $this->setOutput(array('success' => $success, 'error' => isset($error) ? $error : '', 'fileid' => $file->getId(), 'url' => $file->getUrl(), 'icon' => $icon));
 }
Example #8
0
 /**
  * Функция конвертации 
  * xml, tsv, html, json файлов в csv
  * 
  * @param  [string] $infile  [входной файл]
  * @param  [string] $outfile [выходной файл]
  * @return [void]
  */
 public static function convertOtherFormats($infile, $pathToConvert)
 {
     //проверить существование входящего файла
     if (!file_exists($infile)) {
         throw new Exception("Входящий файл " . basename($infile) . " не существует");
     }
     $ext = File::getFileExtension($infile);
     if (!in_array($ext, ['xml', 'tsv', 'html', 'json', 'xlt', 'xls', 'xlsx', 'doc', 'docx'])) {
         throw new Exception("Файл данного формата ({$ext}) не поддерживается");
     }
     if (in_array($ext, ['doc', 'docx'])) {
         shell_exec("HOME=/var/www/new.marketrf.ru/www_system soffice --headless --convert-to html --outdir " . dirname($infile) . " {$infile}");
         $infile = substr($infile, 0, strpos($infile, "." . $ext)) . ".html";
         $ext = 'html';
     }
     $path = Yii::getPathOfAlias('core.extensions.SimpleExcel');
     require_once $path . DS . "SimpleExcel.php";
     $inFileType = SimpleExcel::identity($infile);
     $file = new SimpleExcel($inFileType);
     $file->parser->loadFile($infile);
     $slugger = new SlugBehavior();
     $infileName = File::getFileName($infile);
     $outFileName = $slugger->makeSlug(basename($infileName)) . ".csv";
     $outfile = $pathToConvert . DS . $outFileName;
     $file->convertTo('CSV');
     File::checkPermissions($pathToConvert);
     $file->writer->saveFile($outFileName, $outfile);
     unset($file);
     //удаляем временный html файл если входной был doc, docx
     if (in_array($ext, ['doc', 'docx'])) {
         unlink($infile);
     }
     return [['filename' => $outfile]];
     //тут именно так и нужно, что с другой фунцией они возвращали одинаковый результат
 }