/** * Validate for unique file hash * @return \Illuminate\Validation\Validator */ public function getValidatorInstance() { $validator = parent::getValidatorInstance(); $validator->after(function () use($validator) { if ($this->isMethod('POST')) { if ($this->file('file')->isValid()) { $file = $this->file('file'); $hash = getFileHash($file->getPathName()); $contractService = app('App\\Nrgi\\Services\\Contract\\ContractService'); if ($contract = $contractService->getContractIfFileHashExist($hash)) { $message = trans("The contract file is already present in our system. Please check the following Title of contract with which the uploaded file is linked and make necessary updates."); $message .= sprintf("<div><a target='_blank' href='%s'>%s</a></div>", route('contract.show', $contract->id), $contract->title); $validator->errors()->add('file', $message); } } else { $validator->errors()->add('file', $this->file('file')->getError()); } } }); return $validator; }
function getFileHref($tid, $localid = null) { $component_name = JRequest::getVar('option', 'com_onepage'); // no hacking here: $component_name = urlencode(urlencode($component_name)); $hash = getFileHash($tid); if (defined(SECUREURL)) { if (substr(SECUREURL, strlen(SECUREURL) - 1, 1) != '/') { $url = SECUREURL . '/'; } else { $url = SECUREURL; } } $kk = URL; if (empty($url) && !empty($kk)) { if (substr(URL, strlen(URL) - 1, 1) != '/') { $url = URL . '/'; } else { $url = URL; } } if (empty($url)) { $url = JURI::base(); } $href = $this->getTemplateLink(urlencode(trim($tid))); return $href; }
/** * Download Pdfs * * @param $import_key */ public function download($import_key) { $contracts = $this->getJsonData($import_key); foreach ($contracts as $contract) { $this->updateContractJsonByID($import_key, $contract->id, ['download_status' => static::PROCESSING]); if (empty($contract->pdf_url)) { $this->updateContractJsonByID($import_key, $contract->id, ['download_remarks' => trans('Pdf file url is required'), 'download_status' => static::FAILED]); continue; } $file = $this->downloadPdf($import_key, $contract->pdf_url); if (is_null($file)) { $this->updateContractJsonByID($import_key, $contract->id, ['download_remarks' => trans('File could not be downloaded'), 'download_status' => static::FAILED]); continue; } $fileHash = getFileHash($this->getFilePath($import_key, $file)); if ($con = $this->contract->getContractByFileHash($fileHash)) { $title = sprintf('<a href="%s" target="_blank">%s</a>', route('contract.show', $con->id), str_limit($con->title, 25)); $this->updateContractJsonByID($import_key, $contract->id, ['download_remarks' => trans('contract.import.exist', ['link' => $title]), 'file' => $file, 'download_status' => static::FAILED]); $this->deleteFile($import_key, $file); continue; } $filePath = $this->getFilePath($import_key, $file); $this->updateContractJsonByID($import_key, $contract->id, ['file' => $file, 'filehash' => $fileHash, 'file_size' => filesize($filePath), 'download_status' => static::COMPLETED]); } }
$result = $cssTidy->parse($core_files[$core_name]); if($result){ $core_files[$core_name] = $cssTidy->print->plain(); } else { $errors[] = "Error compressing with CSS Tidy!"; } die(); } * */ } } // Load, concat and minify js foreach ($scripts['js'] as $core_name => $core_group) { $core_files[$core_name] = ""; $script_hash[$core_name] = getFileHash($pathToCore . "/{$core_name}"); $script_size[$core_name] = getFileSize($pathToCore . "/{$core_name}"); $full_script_size[$core_name] = 0; foreach ($core_group as $script) { $filePath = $pathToRoot . $script; if (file_exists($filePath)) { $contents = file_get_contents($filePath); //$core_files[$core_name] .= JSMin::minify(file_get_contents($filePath)); //$core_files[$core_name] .= Minify_YUICompressor::minifyJs(file_get_contents($filePath), array()); $full_script_size[$core_name] += getFileSize($filePath); //$core_files[$core_name] .= JSMin::minify(file_get_contents($filePath)); $core_files[$core_name] .= $contents; //$test = array(); //if(preg_match('/(^|;|{)\s*console\.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\s*\(/',$contents,$test,PREG_OFFSET_CAPTURE)){ // //print_r($test); // list($before) = str_split($contents, $test[2][1]+1); // fetches all the text before the match
function handleHash($f, $outDir, $inputFile = null) { if ($inputFile == null) { $inputFile = $f; } $s = file_get_contents($inputFile); if (preg_match('/\\.html/', $f)) { $s = preg_replace_callback('/ ^.*WEBCC_BEGIN.*$ (?:.|\\n)*? (?:^.*WEBCC_USE_THIS.*$[\\r\\n]* ((?:.|\\n)*?) )? ^.*WEBCC_END.*$[\\r\\n]* /xm', function ($ms) { return $ms[1] ?: ""; }, $s); } $s = preg_replace_callback('/"([^"]+)\\?__HASH__(?:,([^"]+))?"/', function ($ms) use($f, $outDir) { $relativeDir = @$ms[2]; $hash = getFileHash($f, $ms[1], $outDir, $relativeDir); return '"' . $ms[1] . '?v=' . $hash . '"'; }, $s); $outf = $outDir . "/" . $f; @mkdir(dirname($outf), 0777, true); // echo("=== hash $f\n"); file_put_contents($outf, $s); }
/** * Upload contract file * * @param UploadedFile $file * @return array */ protected function uploadContract(UploadedFile $file) { if ($file->isValid()) { $fileName = $file->getClientOriginalName(); $file_type = $file->getClientOriginalExtension(); $newFileName = sprintf("%s.%s", sha1($fileName . time()), $file_type); try { $data = $this->storage->disk('s3')->put($newFileName, $this->filesystem->get($file)); } catch (Exception $e) { $this->logger->error(sprintf('File could not be uploaded : %s', $e->getMessage())); return false; } if ($data) { return ['name' => $newFileName, 'size' => $file->getSize(), 'hash' => getFileHash($file->getPathName())]; } } return false; }
$rewrite_cache = true; $cache[$filename]['hash'] = getFileHash("loops/" . $filename); } if (!isset($cache[$filename]['bitRate'])) { $revalidate = true; } } if ($revalidate) { $cache[$filename]['size'] = round($fileInfo->getSize() / 1024, 1); $cache[$filename]['modified'] = date('M. jS, Y, H:i T', $fileInfo->getMTime()); $streamData = json_decode(shell_exec("ffprobe -v quiet -print_format json -show_format -show_streams \"loops/" . str_replace("\$", "\$", $filename) . "\""), true); $cache[$filename]['bitRate'] = floor($streamData['format']['bit_rate'] / 1000); $cache[$filename]['channels'] = $streamData['streams'][0]['channel_layout']; $cache[$filename]['rate'] = round($streamData['streams'][0]['sample_rate'] / 1000, 1); $cache[$filename]['length'] = intval(gmdate("i", $streamData['streams'][0]['duration'])) . ":" . gmdate("s", $streamData['streams'][0]['duration']); $cache[$filename]['hash'] = getFileHash("loops/" . $filename); } echo '<tr>'; echo '<td><i file="' . $filename . '" class="fa fa-fw fa-play play"></i><a href="loops/' . $filename . '" class="fa fa-fw fa-download"></a></td>'; if ($cache[$filename]['channels'] == "stereo") { $channels = '<span style="color: #f00; font-weight: 700;">stereo</span>'; } else { $channels = 'mono'; } echo '<td> <span class="filename">' . $filename . '</span> <span class="details">' . $cache[$filename]['bitRate'] . ' kbps <div class="sep"></div> ' . $channels . ' <div class="sep"></div> ' . $cache[$filename]['rate'] . ' kHz <div class="sep"></div> ' . $cache[$filename]['length'] . '</span> </td>'; echo '<td>' . $cache[$filename]['size'] . ' KiB</td>'; echo '<td>' . $cache[$filename]['modified'] . '</td>'; echo '</tr>';