language = \OC::$server->getL10N('printer'); } /** * callback function to get md5 hash of a file * @NoAdminRequired * @param (string) $source - filename * @param (string) $orientation - Orientation of printed file */ public function printfile($source, $orientation) { if(!$this->checkAlgorithmType($type)) { return new JSONResponse( array( 'response' => 'error', 'msg' => $this->language->t('Print failed!') ) ); } if($hash = $this->getHash($source, $type)){ return new JSONResponse( array( 'response' => 'success', 'msg' => $this->language->t('Print succeeded!') ) ); } else { return new JSONResponse( array( 'response' => 'error', 'msg' => $this->language->t('File to print not found.') ) ); }; } protected function getHash($source, $type) { if($info = Filesystem::getLocalFile($source)) { return hash_file($type, $info); } return false; } protected function checkAlgorithmType($type) { $list_algos = hash_algos(); return in_array($type, $this->getAllowedAlgorithmTypes()) && in_array($type, $list_algos); } protected function getAllowedAlgorithmTypes() { return array( 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'crc32' ); } }