-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,69 @@ | ||
<?php | ||
|
||
namespace OCA\Printer\Controller; | ||
|
||
use OCP\AppFramework\Controller; | ||
use OCP\IRequest; | ||
use OC\Files\Filesystem; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IRequest; | ||
use Symfony\Component\Process\Process; | ||
|
||
class PrinterController extends Controller | ||
{ | ||
protected $language; | ||
|
||
public function __construct($appName, IRequest $request) | ||
{ | ||
parent::__construct($appName, $request); | ||
|
||
$this->language = \OC::$server->getL10N('printer'); | ||
} | ||
|
||
/** | ||
* callback function to get md5 hash of a file. | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param (string) $sourcefile - filename | ||
* @param (string) $orientation - Orientation of printed file | ||
*/ | ||
public function printfile($sourcefile, $orientation) | ||
{ | ||
$filefullpath = \OC\Files\Filesystem::getLocalFile($sourcefile); | ||
|
||
$options = [ | ||
'landscape' => [ | ||
'lpr', | ||
$filefullpath, | ||
], | ||
'portrait' => [ | ||
'lpr', | ||
'-o', | ||
'orientation-requested=4', | ||
$filefullpath, | ||
], | ||
]; | ||
|
||
$success = [ | ||
'response' => 'success', | ||
'msg' => $this->language->t('Print succeeded!'), | ||
]; | ||
|
||
$error = [ | ||
'response' => 'error', | ||
'msg' => $this->language->t('Print failed'), | ||
]; | ||
|
||
if (!isset($options[$orientation])) { | ||
return new JSONResponse($error); | ||
} | ||
|
||
$process = new Process($options[$orientation]); | ||
$process->run(); | ||
|
||
if ($process->isSuccessful()) { | ||
return new JSONResponse($success); | ||
} | ||
|
||
class PrinterController extends Controller { | ||
|
||
protected $language; | ||
|
||
public function __construct($appName, IRequest $request) { | ||
|
||
parent::__construct($appName, $request); | ||
|
||
// get i10n | ||
$this->language = \OC::$server->getL10N('printer'); | ||
|
||
} | ||
|
||
/** | ||
* callback function to get md5 hash of a file | ||
* @NoAdminRequired | ||
* @param (string) $sourcefile - filename | ||
* @param (string) $orientation - Orientation of printed file | ||
*/ | ||
public function printfile($sourcefile, $orientation) { | ||
if($orientation === "landscape") { | ||
$filefullpath = \OC\Files\Filesystem::getLocalFile($sourcefile); | ||
exec('lpr "' . $filefullpath . '"'); | ||
return new JSONResponse( | ||
array( | ||
'response' => 'success', | ||
'msg' => $this->language->t('Print succeeded!') | ||
) | ||
); | ||
} | ||
|
||
if($orientation === "portrait"){ | ||
$filefullpath = \OC\Files\Filesystem::getLocalFile($sourcefile); | ||
exec('lpr -o orientation-requested=4 "' . $filefullpath . '"'); | ||
return new JSONResponse( | ||
array( | ||
'response' => 'success', | ||
'msg' => $this->language->t('Print succeeded!') | ||
) | ||
); | ||
} else { | ||
return new JSONResponse( | ||
array( | ||
'response' => 'error', | ||
'msg' => $this->language->t('Print failed') | ||
) | ||
); | ||
}; | ||
} | ||
return new JSONResponse($error); | ||
} | ||
} |