forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
4.3 KiB
155 lines
4.3 KiB
<?php |
|
|
|
namespace app\Middleware; |
|
|
|
use app\Core\CoreMedia; |
|
use app\Middleware\Http; |
|
use app\Middleware\ApiAgente; |
|
use app\Providers\Positus; |
|
use app\Providers\WebHeader; |
|
use app\Providers\Whatsapp; |
|
|
|
/** |
|
* Description of WppController |
|
* |
|
* @author Lucas Awade |
|
*/ |
|
class Middleware extends Http |
|
{ |
|
|
|
/** @var array request */ |
|
private $request; |
|
|
|
/** @class WebHeader */ |
|
private $header; |
|
|
|
/** @var String local downloads image|document|video|sticker|audio */ |
|
private $link; |
|
|
|
public function __construct($config = null) |
|
{ |
|
$this->link = $config['LINK_UPLOAD']; |
|
$this->header = new WebHeader($config); |
|
$this->api(); |
|
$this->hook(); |
|
} |
|
|
|
/** |
|
* Start API headers |
|
* @param array $config |
|
*/ |
|
public function api($contentType = "application/json; charset=UTF-8") |
|
{ |
|
$this->header->API($contentType); |
|
} |
|
|
|
/** |
|
* Redirect request to media Social |
|
* @return null |
|
*/ |
|
private function router() |
|
{ |
|
$coremedia = new CoreMedia(); |
|
$this->baseUri(); |
|
switch (strtolower($this->param()[1])) { |
|
case 'whatsapp': |
|
$provedor = returnChannel('whatsapp'); |
|
$coremedia->inicia($this->request, $provedor); |
|
$this->api($provedor->getContentType()); |
|
echo ''; |
|
return null; |
|
case 'api': |
|
$this->api(); |
|
switch ($this->param()[2]) { |
|
case 'agente': |
|
$apiAgente = new ApiAgente(); |
|
$apiAgente->router($this->param()[3], $this->request); |
|
return null; |
|
case 'supervisor': |
|
$apiSupervisor = new ApiSupervisor(); |
|
$apiSupervisor->router($this->param()[3], $this->request); |
|
return null; |
|
default: |
|
echo 'erro'; |
|
} |
|
case 'link': |
|
$this->api(); |
|
$this->header->fileTransfer($this->param()[2], CONF_PATH_FILES . $this->param()[2], base64_decode($this->param()[3])); |
|
exit(0); |
|
case 'info': |
|
$this->api(); |
|
$apiInfo = new ApiInfo(); |
|
$apiInfo->router($this->param()[3], $this->request); |
|
exit(0); |
|
default: |
|
$this->header->redirect(); |
|
exit(0); |
|
} |
|
} |
|
|
|
/** |
|
* Read input requests |
|
*/ |
|
private function hook() |
|
{ |
|
$this->request = file_get_contents('php://input'); |
|
$this->router(); |
|
} |
|
|
|
/** |
|
* Create file and download in browser |
|
*/ |
|
private function download($file = null) |
|
{ |
|
if ($file) { |
|
$this->header->fileTransfer($this->param()[3], $file, base64_decode($this->param()[4])); |
|
exit(0); |
|
} |
|
|
|
if ($this->param()[3] && $this->param()[4]) { |
|
return ["FILE" => strtolower($this->param()[3]), "MIMETYPE" => $this->param()[4]]; |
|
} else { |
|
return null; |
|
} |
|
} |
|
|
|
######################################################################## |
|
##### FUNCTION UTIL ##### |
|
######################################################################## |
|
|
|
private function formatLink() |
|
{ |
|
$link = str_split($this->link); |
|
if (strpos($this->link, 'http://') === false && strpos($this->link, 'http://') === false) { |
|
$this->link = "http://" . $this->link; |
|
} |
|
|
|
if (end($link) != "/") { |
|
$this->link .= "/"; |
|
} |
|
} |
|
|
|
######################################################################## |
|
##### FUNCTION CLASS ##### |
|
######################################################################## |
|
|
|
/** |
|
* Set new link download |
|
* @param string $link |
|
*/ |
|
public function setLink($link) |
|
{ |
|
$this->link = $link; |
|
$this->formatLink(); |
|
} |
|
|
|
/** |
|
* Get link download |
|
* @return string |
|
*/ |
|
public function getLink() |
|
{ |
|
$this->formatLink(); |
|
return $this->link; |
|
} |
|
} |