Example #1
0
 private function log($message, $objects)
 {
     // in php, both arrays and objects can have key->val
     // in json, arrays cannot have key->val
     // this'll change the interior "arrays" from the "response" which appear in json as objects, into objects
     $objects = json_encode($objects);
     $objects = json_decode($objects);
     // prevent logging of passwords
     // if (property_exists($objects, "data") && property_exists($objects->data, "password")) {
     if (isset($objects->data) && isset($objects->data->password)) {
         $objects->data->password = '******';
     }
     if (is_array($objects)) {
         $tidyObjects = array();
         foreach ($objects as $object) {
             $tidyObjects[] = $this->tidyObject($object);
         }
     } else {
         $tidyObjects = $this->tidyObject($objects);
     }
     $output = json_encode($tidyObjects);
     // record the user's last activity
     $userName = "******";
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $userName = $_SERVER['REMOTE_ADDR'];
     }
     if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $userName = $_SERVER['HTTP_X_FORWARDED_FOR'];
     }
     if ($currentUser = $this->plugin->Auth->getUserID()) {
         $model = $this->plugin->MvcQuery->getModel('User');
         $results = $model->read(array('id' => $currentUser));
         if (sizeof($results)) {
             $user = $results[0];
             $userName = $user['email'];
         }
     }
     \application\helper\DebugHelper::logToFile('api.log', "{$userName} {$message} {$output}");
 }
 public function getVideoDuration($filename, $seconds = true)
 {
     $ffmpeg_dir = Nutshell::getInstance()->config->plugin->Plupload->ffmpeg_dir;
     if (!$ffmpeg_dir) {
         return;
     }
     ob_start();
     $command = "\"{$ffmpeg_dir}ffmpeg\" -i \"{$filename}\" 2>&1";
     \application\helper\DebugHelper::traceToFileShort('output.log', $command);
     passthru($command);
     $result = ob_get_contents();
     ob_end_clean();
     preg_match('/Duration: (.*?),/', $result, $matches);
     if (sizeof($matches) < 2) {
         throw new PluploadException("Failed to get video duration of {$filename}", $command, $result, $matches);
     }
     $duration = $matches[1];
     if ($seconds) {
         $duration_array = explode(':', $duration);
         $duration = $duration_array[0] * 3600 + $duration_array[1] * 60 + $duration_array[2];
     }
     return $duration;
 }