/**
  * Create a zip-archive from a list of files
  *
  * @param array $files
  * @param string $destination full path of zip file
  * @param boolean $overwrite
  * @return boolean TRUE, if zip file was created
  */
 public static function makeZipFile($files = array(), $destination = '', $overwrite = FALSE)
 {
     if (!extension_loaded('zip')) {
         tx_rnbase::load('tx_rnbase_util_Logger');
         tx_rnbase_util_Logger::warn('PHP zip extension not loaded!', 'rn_base');
         return false;
     }
     //if the zip file already exists and overwrite is FALSE, return FALSE
     if (file_exists($destination) && !$overwrite) {
         return FALSE;
     }
     //vars
     $valid_files = array();
     //if files were passed in...
     if (!is_array($files)) {
         return FALSE;
     }
     foreach ($files as $file) {
         if (file_exists($file)) {
             $valid_files[] = $file;
         }
     }
     //if we have good files...
     if (!count($valid_files)) {
         return FALSE;
     }
     //create the archive
     $zip = new ZipArchive();
     if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== TRUE) {
         return FALSE;
     }
     //add the files
     foreach ($valid_files as $file) {
         $filename = basename($file);
         $zip->addFile($file, iconv('UTF-8', 'IBM850', $filename));
     }
     //close the zip -- done!
     $zip->close();
     //check to make sure the file exists
     return file_exists($destination);
 }
示例#2
0
 /**
  *
  * @return integer the number of recipients who were accepted for delivery
  */
 public function send()
 {
     /* @var $mail TYPO3\CMS\Core\Mail\MailMessage */
     $mail = tx_rnbase::makeInstance(tx_rnbase_util_Typo3Classes::getMailMessageClass());
     $mail->setFrom($this->from, $this->fromName);
     foreach ($this->to as $email => $name) {
         $mail->addTo($email, $name);
     }
     $mail->setSubject($this->subject);
     if ($this->replyTo) {
         $mail->addReplyTo($this->replyTo, $this->replyToName);
     }
     // Or set it after like this
     if ($this->htmlPart) {
         $mail->setBody($this->htmlPart, 'text/html');
     }
     // Add alternative parts with addPart()
     if ($this->textPart) {
         $mail->addPart($this->textPart, 'text/plain');
     }
     if (!empty($this->attachments)) {
         foreach ($this->attachments as $attachment) {
             if (!$mail->attach(Swift_Attachment::fromPath($attachment['src']))) {
                 tx_rnbase_util_Logger::warn('Adding attachment failed!', 'rn_base', array('subject' => $mail->subject, 'to' => $this->toAsString, 'attachment' => $attachment));
             }
         }
     }
     return $this->sendMessage($mail);
 }
 /**
  * Kürzt die Elemente auf die gewünschte Größe.
  *
  * Es wird eine Warnung in die Devlog geschrieben,
  * wenn mehr als die angegebene Anzahl Element enthalten ist.
  *
  * Wenn keine Warnung erzeugt werden soll,
  * muss bei dem $this->search() Aufruf ein Limit mitgegebenwerden
  * um die Elemente zu beschränken! Oder auch $this->searchSingle aufrufen.
  *
  * @param array $items
  * @param unknown_type $limit
  * @param array $options
  * @return array
  */
 protected function limitResults(array $items, $limit, array $options = array())
 {
     // Leer, wir haben nichts zu tun.
     if (empty($items)) {
         return $items;
     }
     $count = count($items);
     // Nur bearbeiten, wenn mehr Elemente vorhanden sind, als notwendig.
     if ($count > $limit) {
         // Wir kürzen die Elemente.
         $items = array_slice($items, 0, $limit);
         // Wir Schreiben einen Log-Eintrag um den Fehler zu melden.
         tx_rnbase::load('tx_rnbase_util_Logger');
         tx_rnbase_util_Logger::warn('There are more elements(' . $count . ') for limitResults supplied than expected(' . $limit . ').', 'mkhoga');
     }
     return $items;
 }
示例#4
0
 /**
  *
  * @param array
  * @return \TYPO3\CMS\Core\Database\DatabaseConnection|tx_rnbase_util_db_IDatabase
  */
 public function getDatabaseConnection($options = NULL)
 {
     if (is_array($options) && !empty($options['db'])) {
         $dbConfig =& $options['db'];
         if (is_string($dbConfig)) {
             $db = $this->getDatabase($dbConfig);
         } elseif (is_object($dbConfig)) {
             $db = $dbConfig;
         }
         if (!$db instanceof tx_rnbase_util_db_IDatabase) {
             tx_rnbase::load('tx_rnbase_util_Logger');
             tx_rnbase_util_Logger::warn('The db "' . get_class($db) . '" has to implement' . ' the tx_rnbase_util_db_IDatabase interface', 'rn_base');
             $db = NULL;
         }
     }
     return is_object($db) ? $db : $GLOBALS['TYPO3_DB'];
 }
 /**
  * creates a lock file and stores the current time.
  *
  * @return boolean
  */
 private function createLockFile()
 {
     $fileName = $this->getFile();
     if (!is_dir(dirname($fileName))) {
         tx_rnbase_util_Files::mkdir_deep(dirname($fileName));
     }
     file_put_contents($fileName, time());
     if (!is_readable($fileName)) {
         tx_rnbase::load('tx_rnbase_util_Logger');
         tx_rnbase_util_Logger::warn('Lock file could not be created for "' . $this->getName() . '" process!', 'rn_base', array('process_name' => $this->getName(), 'life_time' => $this->getLifeTime(), 'lock_file' => $fileName));
         return FALSE;
     }
     return TRUE;
 }
 /**
  * Optionen aus der TS-Config setzen
  *
  * @param array $options
  * @param tx_rnbase_configurations $configurations
  * @param string $confId Id der TS-Config z.B. myview.options.
  */
 static function setConfigOptions(&$options, $configurations, $confId)
 {
     $cfgOptions = $configurations->get($confId);
     if (is_array($cfgOptions)) {
         foreach ($cfgOptions as $option => $cfg) {
             // Auf einfache Option ohne Klammerung prüfen
             if (substr($option, -1) != '.') {
                 $options[$option] = $cfg;
                 continue;
             }
             // Ohne Angaben nix zu tun
             if (!is_array($cfg)) {
                 continue;
             }
             // Zuerst den Namen der Option holen. Dieser ist immer klein
             // Beispiel orderby, count...
             $optionName = strtolower(substr($option, 0, strlen($option) - 1));
             // Hier jetzt die Implementierung für orderby. da gibt es mehr
             // Angaben als z.B. bei count.
             while (list($table, $data) = each($cfg)) {
                 /*
                  * was, wenn im ts etwas wie folgt angegeben ist?
                  * options.limit = 5
                  * options.limit.override = 10
                  * das führt zu php offset fehlern,
                  * da limit bereits 5 ist und deshalb kein array werden kann.
                  * der code sieht aktuell nur eines der beiden methoden vor.
                  * entweder eine zuweisung als array oder skalaren Wert.
                  * Wir ignorieren daher bereits existierende skalare Werte
                  * und schreiben eine Log, es sei denn es sind bekannte Werte
                  * wie override oder force, dann wird direkt ignoriert
                  */
                 if (isset($options[$optionName]) && !is_array($options[$optionName])) {
                     if (!in_array($optionName, array('override', 'force'))) {
                         tx_rnbase::load('tx_rnbase_util_Logger');
                         tx_rnbase_util_Logger::warn('Invalid configuration for config option "' . $optionName . '".', 'rn_base', array('option_name' => $optionName, 'cfg' => $cfg));
                     }
                     continue;
                 }
                 $tableAlias = strtoupper(substr($table, 0, strlen($table) - 1));
                 if (is_array($data) && $option == 'searchdef.') {
                     foreach ($data as $col => $value) {
                         $options[$optionName][strtolower($tableAlias)][substr($col, 0, strlen($col) - 1)] = $value;
                     }
                 } elseif (is_array($data)) {
                     foreach ($data as $col => $value) {
                         $options[$optionName][$tableAlias . '.' . $col] = $value;
                     }
                 } else {
                     // Ohne Array erfolgt direkt eine Ausgabe (Beispiel RAND = 1)
                     $options[$optionName][$table] = $data;
                 }
             }
         }
     }
 }