/** * @see sfValidatorBase */ protected function doClean($value) { $clean = $value; mysfLog::log($this, "{$clean}"); // check for active user if (sfGuardUserPeer::retrieveByUsername($clean, true)) { throw new sfValidatorError($this, 'used', array('value' => $value)); } // check for not active user if (sfGuardUserPeer::retrieveByUsername($clean, false)) { throw new sfValidatorError($this, 'used', array('value' => $value)); } return $clean; }
/** This is executed when searched for related tracks and metadata */ public function executeRelatedtrack(sfWebRequest $request) { $this->getContext()->getConfiguration()->loadHelpers('Url'); $empty_metadatafilteredquery = false; $distances = NULL; $files = NULL; // get request parameters $metadataquery = $request->getParameter('metadataquery'); $tracknr = $request->getParameter('tracknr'); $limit = $request->getParameter('limit', $this->getContext()->getConfiguration()->getSmintMaxQueryResults()); $offset = $request->getParameter('offset', 0); $id_prefix = $request->getParameter('id_prefix', '') . smintTools::generateHtmlId($tracknr) . "_"; $omit_empty_metadataquery = $request->getParameter('omit_empty_metadataquery', false); $distancetypeid = sfConfig::get('app_defaults_distancetypeid', 0); $featurevectortypeid = sfConfig::get('app_defaults_featurevectortypeid', 0); mysfLog::logRequest($this, $request); //get file via external key $file = FilePeer::getFileByExternalKey($tracknr); //only if the file was found in the smafestore db if ($file) { // run query $fileTrackId = $file->getTrackid(); $relatedCriteria = $this->buildRelatedQuery($fileTrackId, $featurevectortypeid, $distancetypeid, $limit, $offset, $metadataquery); $related = FilePeer::doSelect($relatedCriteria); // if omit empty metadataquery is true if ($omit_empty_metadataquery) { if (count($related) > 0) { // if the query returned results $distances = DistancePeer::doSelect($relatedCriteria); } else { // if the query returned no results -> retry without metadata $empty_metadatafilteredquery = true; $relatedCriteria = $this->buildRelatedQuery($fileTrackId, $featurevectortypeid, $distancetypeid, $limit, $offset); $related = FilePeer::doSelect($relatedCriteria); $distances = DistancePeer::doSelect($relatedCriteria); } } else { $distances = DistancePeer::doSelect($relatedCriteria); } } $files = FiledescPeer::doSelect($relatedCriteria); // add duration // $fileDownloadURL = url_for("getAudioFile/download") . "?tracknr=" . rawurlencode($tracknr); $queryFileMetadata = FiledescPeer::retrieveByPk($tracknr); $fileInfoName = $queryFileMetadata->getTitle() . " - " . $queryFileMetadata->getPerformers(); $uploadedFilePHPUrl_incomplete = url_for("getAudioFile/download", true) . "?tracknr=" . rawurlencode($tracknr); $uploadedFileURL = smintUploadFileHelper::getDirectFileUrl($file->getUri()); return $this->renderPartial('search/result', array('render' => 'related', 'uploadedFilePHPUrl_incomplete' => $uploadedFilePHPUrl_incomplete, 'uploadedFileURL' => $uploadedFileURL, 'seedLabel' => $fileInfoName, 'id_prefix' => $id_prefix, 'tracknr' => $tracknr, 'files' => $files, 'distances' => $distances, 'limit' => $limit, 'offset' => $offset, 'metadataquery' => $metadataquery, 'empty_metadatafilteredquery' => $empty_metadatafilteredquery, 'aSegmSearch' => $aSegmSearch)); }
/** Performs live query with Smafe * Also tries to start the server if it seems to be down. In this case, an exception is thrown with explanation * @param $filepath The file to query (local file path) * @param $aSegmSearch Associative array with data about segmented search * @param $autostart if true, the server is tried to started if it seems to be down. Default = true */ public static function queryFile($filepath, $aSegmSearch, $autorestart = true) { // The command $exec_command; if ($aSegmSearch['enabled']) { // segmented search $command = mysfConfig::get('app_live_settings_command_segmentedsearch', ""); $command = str_replace('$LIVEFILE', $filepath, $command); $command = str_replace('$BEGINTIME', smintTools::convertTimeMsToMM_SS_HH($aSegmSearch['startSegment']), $command); $command = str_replace('$ENDTIME', smintTools::convertTimeMsToMM_SS_HH($aSegmSearch['endSegment']), $command); $exec_command = $command; } else { // normal search $command = mysfConfig::get('app_live_settings_command', ""); $command = str_replace('$LIVEFILE', $filepath, $command); $exec_command = $command; } $exec_output = array(); $exec_err = array(); mysfLog::log(self::$context, "INFO - executing live query: {$exec_command}"); exec($exec_command, $exec_output, $exec_result); if ($exec_result != 0) { if ($autorestart) { // try to start server try { mysfLog::log(self::$context, "INFO: Server seems not to be running. STARTING the SERVER."); self::restartServer($aSegmSearch['enabled']); throw new Exception("Server was restarted. Try again in a few minutes. Log: " . print_r($exec_output, true)); } catch (Exception $e) { // restart failed mysfLog::log(self::$context, "STARTING the SERVER failed: " . $e->getMessage()); throw new Exception($e->getMessage()); } } else { // do not start the smafedistd server but return error message $result_array = array("command" => $exec_command, "result" => $exec_result, "error" => $exec_output); $error_message = "ERROR during live query. " . print_r($result_array, true); mysfLog::log(self::$context, $error_message); throw new Exception($error_message); } } $result_array = array("output" => $exec_output, "result" => $exec_result); return $result_array; }
/** * Sends a mail. * It uses the Swiftmail library, but not the symfony wrapper around it (the wrapper did not work) * @param options assoc array with options: * = mandatory * - subject* * - parameters* assoc array for partial rendering * - to_email* * - to_name* * - text* either a symfony partial view or the text directly * - html either a symfony partial view or the html text directly * - from_email* * - from_name* * - cc * - bcc * - attachments * @return number of emails sent * @throws Exception if an error occurs or sfException if a mandatory option is not set */ public static function mail($options) { sfProjectConfiguration::getActive()->loadHelpers('Partial'); $required = array('subject', 'parameters', 'to_email', 'to_name', 'text', 'from_email', 'from_name'); foreach ($required as $option) { if (!isset($options[$option])) { throw new sfException("Required option {$option} not supplied to " . self::$context . "::mail"); } } // Create the Transport $transport = Swift_SmtpTransport::newInstance(sfConfig::get('app_mail_host', "!!specify host in app.yml!!"), sfConfig::get('app_mail_port', 25))->setUsername(sfConfig::get('app_mail_username', "!!Please set username in app.yml!!"))->setPassword(sfConfig::get('app_mail_password', "***")); // check for encryption if ($tmpenc = sfConfig::get('app_mail_encryption', '~') != '~') { if (in_array($tmpenc, stream_get_transports())) { $transport->setEncryption($tmpenc); mysfLog::log(self::$context, "Encryption {$tmpenc} enabled."); } else { mysfLog::log(self::$context, "WARNING: Encryption {$tmpenc} NOT enabled since it is not in stream_get_transports() result which is: " . print_r(stream_get_transports(), true)); } } // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); /* // Or to use the Echo Logger $logger = new Swift_Plugins_Loggers_EchoLogger(); $mailer -> registerPlugin(new Swift_Plugins_LoggerPlugin($logger)); * */ $address = array(); $address['fullname'] = $options['from_name']; $address['email'] = $options['from_email']; if (!isset($options['body_is_partial']) || $options['body_is_partial'] == true) { $message = Swift_Message::newInstance()->setFrom(array($address['email'] => $address['fullname']))->setTo(array($options['to_email'] => $options['to_name']))->setSubject($options['subject']); if (isset($options['html'])) { $message->setBody(get_partial($options['html'], $options['parameters']), 'text/html')->addPart(get_partial($options['text'], $options['parameters']), 'text/plain'); } else { $message->setBody(get_partial($options['text'], $options['parameters']), 'text/plain'); } //$message = Swift_Message::newInstance() -> setFrom(array($address['email'] => $address['fullname'])) -> setTo(array($options['to_email'] => $options['to_name'])) -> setSubject($options['subject']) -> setBody('test'); } else { $message = Swift_Message::newInstance()->setFrom(array($address['email'] => $address['fullname']))->setTo(array($options['to_email'] => $options['to_name']))->setSubject($options['subject']); if (isset($options['html'])) { $message->setBody($options['html'], 'text/html')->addPart($options['text'], 'text/plain'); } else { $message->setBody($options['text'], 'text/plain'); } } if (isset($options['cc']) && !is_null($options['cc'])) { if (is_array($options['cc'])) { foreach ($options['cc'] as $key => $value) { if (!is_number($key)) { $message->addCc($key, $value); } else { $message->addCc($value); } } } elseif (is_string($options['cc'])) { $message->addCc($options['cc']); } } if (isset($options['bcc']) && !is_null($options['bcc'])) { if (is_array($options['bcc'])) { foreach ($options['bcc'] as $key => $value) { if (!is_number($key)) { $message->addBcc($key, $value); } else { $message->addBcc($value); } } } elseif (is_string($options['bcc'])) { $message->addBcc($options['bcc']); } } if (isset($options['attachments'])) { $atts = $options['attachments']; if (is_array($atts)) { foreach ($atts as $att) { $message->attach(Swift_Attachment::fromPath($att)); } } elseif (is_string($atts)) { $message->attach(Swift_Attachment::fromPath($atts)); } } try { $failedRecipients = array(); $ret = $mailer->send($message, $failedRecipients); mysfLog::log(self::$context, "DEBUG: " . print_r($failedRecipients, TRUE)); return $ret; } catch (Exception $e) { throw new Exception("Error when sending mail: " . $e->getMessage()); } }
/** provides the file as download/streaming * Request params: * - tracknr * - fileid * - uploaded * ( either tracknr or fileid or uploaded is required) * - format optional. One of: mp3, ogg. If format is given, the file is converted to the given format, using command line invocations that are configured in app.yml * * */ public function executeDownload(sfWebRequest $request) { // write session, so it won't lock other requests session_write_close(); $reqparamUploaded = $this->getRequestParameter('uploaded'); if ($reqparamUploaded) { $filename = smintUploadFileHelper::getUploadPath() . $reqparamUploaded; } else { $tracknr = $this->getRequestParameter('tracknr'); if ($tracknr) { $file = FilePeer::getFileByExternalKey($tracknr); $filekey = $tracknr; } else { # check if file.id is given $fileid = $this->getRequestParameter('fileid'); $file = FilePeer::retrieveByPK($fileid); $filekey = $fileid; } //check if a file was found matching tracknr, else exit with 404 if ($file) { $filename = $file->getUri(); } else { $this->forward404("file not found in database."); } } //check if a tracknr is given, otherwise exit with 404 if (!$filename) { $this->forward404("Invalid query! Provide tracknr, fileid or uploaded to get a file."); } if (file_exists($filename)) { //check if file is inside the folder configured in smint/config/app.yml // or inside the upload folder $mp3Path = dirname(sfConfig::get('app_files_mp3path') . "/file"); if (strpos($filename, $mp3Path) === false && strpos($filename, smintUploadFileHelper::getUploadPath()) === false) { $this->forward404("file: {$filename} is outside of the configured path (app.yml): {$mp3Path}. Accessing files outside the path is not allowed. Check app.yml and URI in file table."); } // ----------------------------------------------- // -------------- check for format -------------- // if no format is given, $reqparamFormat = $this->getRequestParameter('format'); if ($reqparamFormat) { if (substr($filename, -3) === $reqparamFormat) { mysfLog::log($this, "INFO: format parameter equals original audio file suffix. No conversion."); if ($reqparamFormat === "mp3") { $contenttype = "audio/mpeg"; } else { $contenttype = "audio/{$reqparamFormat}"; } } else { // conversion if ($reqparamFormat === "ogg") { $filename = smintFileserverHelper::doFileConversion($filename, $reqparamFormat); $contenttype = "audio/ogg"; } else { if ($reqparamFormat === "mp3") { $filename = smintFileserverHelper::doFileConversion($filename, $reqparamFormat); $contenttype = "audio/mpeg"; } else { if ($reqparamFormat === "waveform") { $filename = smintFileserverHelper::doFileConversion($filename, $reqparamFormat); $contenttype = "application/txt"; } else { if ($reqparamFormat === "png") { $waveformfilename = smintFileserverHelper::doFileConversion($filename, "waveform"); $wfdata = split(", ", file_get_contents($waveformfilename)); //mysfLog::log($this, print_r($wfdata, true)); // how much detail we want. Larger number means less detail // (basically, how many bytes/frames to skip processing) // the lower the number means longer processing time // EP: in SMINT we do not chagne this. To change the detail, edit your waveform_resolution // config param in app.yml! define("DETAIL", 1); // get user vars from form $width = $this->getRequestParameter('width') ? rawurldecode($this->getRequestParameter('width')) : 640; $height = $this->getRequestParameter('height') ? rawurldecode($this->getRequestParameter('height')) : 100; $foreground = $this->getRequestParameter('fg') ? rawurldecode($this->getRequestParameter('fg')) : "#4D4D4D"; $background = $this->getRequestParameter('bg') ? rawurldecode($this->getRequestParameter('bg')) : "#ffffff"; $maxval = 0; $factor = sfConfig::get('app_defaults_waveform_factor', 0.8); // create original image width based on amount of detail $img = imagecreatetruecolor(sizeof($wfdata) / DETAIL, $height); // apply factor to the data //$wfdata_factor = array_map("this->pow_func", $wfdata); for ($i = 0; $i < sizeof($wfdata); $i += DETAIL) { $wfdata[$i] = pow(abs($wfdata[$i]), $factor); } $datamaxval = max(array_map("abs", $wfdata)); $normconstant = doubleval($height) / doubleval($datamaxval); for ($i = 0; $i < sizeof($wfdata); $i += DETAIL) { $wfdata[$i] = $wfdata[$i] * $normconstant; } /* for ($i = 0; $i < sizeof($wfdata); $i += DETAIL) { if (abs($wfdata[$i]) > $maxval) { $maxval = $wfdata[$i]; } } if ($maxval < 40) { for ($i = 0; $i < sizeof($wfdata); $i += DETAIL) { $wfdata[$i] = pow(abs($wfdata[$i]), 1.4); } } * */ // fill background of image if ($background == "") { imagesavealpha($img, true); $transparentColor = imagecolorallocatealpha($img, 0, 0, 0, 127); imagefill($img, 0, 0, $transparentColor); } else { list($r, $g, $b) = smintTools::html2rgb($background); imagefilledrectangle($img, 0, 0, sizeof($wfdata) / DETAIL, $height, imagecolorallocate($img, $r, $g, $b)); } // generate foreground color list($r, $g, $b) = smintTools::html2rgb($foreground); // loop through frames/bytes of wav data as genearted above for ($d = 0; $d < sizeof($wfdata); $d += DETAIL) { // relative value based on height of image being generated // data values can range between -127 and 128 $v = $wfdata[$d]; //$v = pow($v, sfConfig::get('app_defaults_waveform_factor', 0.8)); // draw the line on the image using the $v value and centering it vertically on the canvas imageline($img, $d / DETAIL, ($height - $v) / 2, $d / DETAIL, ($height + $v) / 2, imagecolorallocate($img, $r, $g, $b)); } // want it resized? if ($width != imagesx($img)) { // resample the image to the proportions defined in the form $rimg = imagecreatetruecolor($width, $height); // save alpha from original image imagesavealpha($rimg, true); imagealphablending($rimg, false); // copy to resized imagecopyresampled($rimg, $img, 0, 0, 0, 0, $width, $height, sizeof($wfdata) / DETAIL, $height); $img = $rimg; } $contenttype = "image/png"; header("Content-type: {$contenttype}"); imagepng($img); imagedestroy($img); // dont render view return sfView::NONE; } else { $error_message = "ERROR: Format {$reqparamFormat} not valid"; mysfLog::log($this, $error_message); throw new Exception($error_message); } } } } } } else { mysfLog::log($this, "INFO: format parameter not given, sending the original file "); // assuming file ending as content type. Just an approximation $contenttype = "audio/" . substr($filename, -3); } // do a redirect to file to have apache handle it $this->redirect(smintUploadFileHelper::getDirectFileUrl_for_uploads($filename)); /* alternate version of redirect (not using symf framework) * does not work better :-( * $url = smintUploadFileHelper::getDirectFileUrl_for_uploads($filename); $statusCode = 302; // redirect $response = $this->context->getResponse(); $response->clearHttpHeaders(); $response->setStatusCode($statusCode); $response->setHttpHeader('Location', $url); $response->send(); throw new sfStopException(); // we do not reach this part b/o the redirect! * */ // ------------ delegate to helper for download // serves file, obeying the range header smintFileserverHelper::serve_file_resumable($this->getResponse(), $filename, $contenttype); // dont render view return sfView::NONE; //return sfView::HEADER_ONLY; } else { $missingfile = $filename ? $filename : "No filename found!"; $this->forward404("file for tracknr: not found: " . $missingfile); } }
public function executeConfirm() { $validate = $this->getRequestParameter('validate'); $c = new Criteria(); // 0.6.3: oops, this was in sfGuardUserProfilePeer in my application // and therefore never got shipped with the plugin until I built // a second site and spotted it! $c->add(SmintUserPeer::VALIDATE, $validate); $c->addJoin(sfGuardUserPeer::ID, SmintUserPeer::SF_GUARD_USER_ID); $sfGuardUser = sfGuardUserPeer::doSelectOne($c); if (!$sfGuardUser) { return 'Invalid'; } $type = self::getValidationType($validate); if (!strlen($validate)) { return 'Invalid'; } $profile = $sfGuardUser->getProfile(); $profile->setValidate(null); $profile->save(); if ($type == 'New') { $sfGuardUser->setIsActive(true); $sfGuardUser->save(); $this->getUser()->signIn($sfGuardUser); // Email start $opts = array(); $opts['from_name'] = sfConfig::get('app_mail_fromname', "Spectralmind"); $opts['from_email'] = sfConfig::get('app_mail_from', "*****@*****.**"); // the password is not plaintext, so we do not show it in the mail! $opts['parameters'] = array('username' => $sfGuardUser->getUsername(), 'pwd' => $sfGuardUser->getPassword()); $opts['body_is_partial'] = true; $opts['to_name'] = $profile->getName(); $opts['to_email'] = $profile->getEmail(); $opts['subject'] = sfConfig::get('app_mail_subjectwelcomemail', "Welcome to SEARCH by Sound portal"); //$opts['html'] = "sendValidateNew"; $opts['text'] = "sendWelcomeEmail"; /* // Or to use the Echo Logger $logger = new Swift_Plugins_Loggers_EchoLogger(); $this->getMailer()->registerPlugin(new Swift_Plugins_LoggerPlugin($logger)); * */ $numSent = smintMailHelper::mail($opts); // not sent? react accordingly if ($numSent != 1) { mysfLog::log($this, "ERROR: welcome email not sent. Return value was {$numSent}"); return 'Error'; } } if ($type == 'Reset') { $this->getUser()->setAttribute('Reset', $sfGuardUser->getId(), 'sfApplyPlugin'); return $this->redirect('sfApply/reset'); } }
/** Returns appropriate JS code for mp3 player config. * @param $files Array of Filedesc instances * @param $aSegmSearch Array with segmentation information * */ public static function getMp3PlayerConfig($files = array(), $aSegmSearch = array()) { //needed for javascript_tag use_helper('JavascriptBase'); $player = sfConfig::get('app_mp3player_defaultplayer', 'worldpress'); switch ($player) { case 'flash-mp3-player': return ''; break; case 'worldpress': $playerConfig = sfConfig::get('app_mp3player_worldpress'); $autostart = isset($playerConfig['autostart']) ? $playerConfig['autostart'] : 'yes'; $width = isset($playerConfig['width']) ? $playerConfig['width'] : '200'; $skin = $playerConfig['skin']; return javascript_tag("AudioPlayer.setup('" . public_path('audio-player/player.swf') . "', \n {\n width: '{$width}', \n autostart: '{$autostart}', \n animation: 'no', \n {$skin},\n });"); break; case 'smintplayer': default: // get configuration $playerConfig = sfConfig::get('app_mp3player_smintplayer'); // build options array of array. First dimension is list of files, second is assoc array with values for the player $options = array(); if (!isset($aSegmSearch['enabled'])) { $aSegmSearch['enabled'] = false; } foreach ($files as $i => $filedesc) { $filerec = FilePeer::getFileByExternalKey($filedesc->getTracknr()); if (!isset($filerec)) { // no recrod returned - maybe no metadata in the db? $tmparray = array('text' => "(No metadata available)", 'audiofile_mp3' => url_for("getAudioFile/download", true) . "?fileid=" . rawurlencode($filedesc->getTracknr()) . "&format=mp3", 'audiofile_ogg' => url_for("getAudioFile/download", true) . "?tracknr=" . rawurlencode($filedesc->getTracknr()) . "&format=ogg", 'waveformfile' => url_for("getAudioFile/download", true) . "?tracknr=" . rawurlencode($filedesc->getTracknr()) . "&format=waveform", 'duration' => isset($iDurationMs) ? $iDurationMs : 0, 'segments' => $aSegmSearch['enabled'] ? $aSegmSearch['resultsegments'][$i] : array(), 'searchsimilarfunc' => 'smint_' . smintTools::generateHtmlId($filedesc->getTracknr()) . '()', 'backlinktext' => "License track from gettyimages music", 'backlinkurl' => url_for("search/redirect") . "?url=" . rawurlencode("http://www.gettyimages.at/music/download-songs/" . $filedesc->getTracknr() . "?ref=spec")); } else { $iBitrate = $filerec->getBitrate(); $sUri = $filerec->getUri(); // estimate duration if (file_exists($sUri)) { $iSize = filesize($sUri); if ($iSize) { // file size divided by bytes per second, times 1000 to get ms. // bitrate is k bits per second, so multiply by 1024 to get bits, and divide by 8 to get bytes $iDurationMs = intval($iSize / ($iBitrate * 1024 / 8) * 1000); } else { mysfLog::log($this, "DEBUG Could not read file size: {$sUri}"); $iDurationMs = 0; } } else { mysfLog::log($this, "WARNING File does not exist: {$sUri}"); $iDurationMs = 0; } $tmparray = array('text' => $filedesc->getTitle() . ' | ' . $filedesc->getPerformers() . ' | ' . $filedesc->getGenre(), 'audiofile_mp3' => smintUploadFileHelper::getDirectFileUrl($filerec->getUri()), 'audiofile_ogg' => url_for("getAudioFile/download", true) . "?tracknr=" . rawurlencode($filedesc->getTracknr()) . "&format=ogg", 'waveformfile' => url_for("getAudioFile/download", true) . "?tracknr=" . rawurlencode($filedesc->getTracknr()) . "&format=waveform", 'duration' => isset($iDurationMs) ? $iDurationMs : 0, 'segments' => $aSegmSearch['enabled'] ? $aSegmSearch['resultsegments'][$i] : array(), 'searchsimilarfunc' => 'smint_' . smintTools::generateHtmlId($filedesc->getTracknr()) . '()', 'backlinktext' => "License track from gettyimages music", 'backlinkurl' => url_for("search/redirect") . "?url=" . rawurlencode("http://www.gettyimages.at/music/download-songs/" . $filedesc->getTracknr() . "?ref=spec")); } $options[] = $tmparray; } // we cannot put all these fields into one array since the output format must be like // , A: XXXX, B: XXX // and not //, {A: XXXX, B: XXX} return ", playlist: " . smintTools::my_options_for_javascript($options) . ", waveform_resolution: " . intval(sfConfig::get('app_defaults_waveform_resolution')) . ', waveform_factor: ' . doubleval(sfConfig::get('app_defaults_waveform_factor')); break; } }
/** * Performs the file conversion, ie, calls external tool, checks if it worked correctly, and returns the filename of the output file * Note that the output files can be deleted safely. On the other hand this function also checks if the file has already been converted. * If so, it will not be converted a second time. * @param filename the filename including path (local) * @param formatcode Currently these codes are supported: * - ogg * - mp3 * - waveform * - waveformpng * * * To add another type: * - Add command_XXX in app.yml. The command must follow the same conventions as command_mp3 and _ogg ($INfile, ...) * - XXX is also used as the file suffix for the output file */ public static function doFileConversion($filename, $formatcode = "ogg") { $exec_output = array(); $exec_err = array(); $current_date = date("_Ymd_His_"); // get command as configured in app.yml $exec_cmd_raw = mysfConfig::get('app_conversion_setting_command_' . $formatcode, ""); // replace placeholder with real file name, infile $exec_cmd = str_replace('$INfile', escapeshellcmd($filename), $exec_cmd_raw); // replace outfile placeholder. outfile is : upload dir, basename of infile, and ogg suffix if ($formatcode === 'waveform') { // extra file ending for waveform, since waveform is not recognized by apache $outfile = smintUploadFileHelper::getUploadPath() . basename($filename) . "." . $formatcode . ".txt"; } else { $outfile = smintUploadFileHelper::getUploadPath() . basename($filename) . "." . $formatcode; } $exec_cmd = str_replace('$OUTfile', escapeshellcmd($outfile), $exec_cmd); // check for pixels per second variable. If found, replace it with config param if (substr_count($exec_cmd, '$PIXELSPERSECOND') > 0) { $pixelspersecond = sfConfig::get('app_defaults_waveform_resolution'); $exec_cmd = str_replace('$PIXELSPERSECOND', escapeshellcmd($pixelspersecond), $exec_cmd); } $exec_cmd_escaped = $exec_cmd; // before conversion check if file exists already if (file_exists($outfile)) { mysfLog::log(self::$context, "INFO: file {$outfile} exists, using it."); } else { mysfLog::log(self::$context, "INFO: starting conversion. Command = {$exec_cmd_escaped}"); // executing, redirecting stderr to stdout exec($exec_cmd_escaped . " 2>&1", $exec_err, $exec_result); if ($exec_result != 0 || !file_exists($outfile)) { $result_array = array("command" => $exec_cmd_escaped, "result" => $exec_result, "error" => $exec_err); $error_message = "ERROR during conversion. " . print_r($result_array, true); mysfLog::log(self::$context, $error_message); throw new Exception($error_message); } mysfLog::log(self::$context, "INFO: conversion done"); } return $outfile; }