Exemplo n.º 1
0
 static function handleFileUpload()
 {
     $app = App::$instance;
     if (isset($_FILES['Filedata']) && isset($_FILES['Filedata']["name"]) && !$_FILES['Filedata']["error"] && is_file($_FILES['Filedata']["tmp_name"])) {
         $originalFilename = strtolower($_FILES['Filedata']["name"]);
         $pathinfo = pathinfo($originalFilename);
         $fileExtension = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';
         $tempFilename = md5('fileupload' . uniqid()) . (isset($fileExtension[0]) ? '.' . $fileExtension : '');
         $filename = $app->data->getFilename('.temp/bearcms/files/' . $tempFilename);
         $pathinfo = pathinfo($filename);
         if (isset($pathinfo['dirname'])) {
             if (!is_dir($pathinfo['dirname'])) {
                 mkdir($pathinfo['dirname'], 0777, true);
             }
         }
         move_uploaded_file($_FILES['Filedata']["tmp_name"], $filename);
         if (is_file($filename)) {
             $response = Server::call('fileupload', array('tempFilename' => $tempFilename, 'requestData' => json_encode($_GET)));
             if (isset($response['result'])) {
                 return new App\Response\JSON($response['result']);
             } else {
                 return new App\Response\TemporaryUnavailable();
             }
         }
     }
     $response = new App\Response();
     $response->headers['contentType'] = 'Content-Type: text/json; charset=UTF-8';
     $response->headers['serviceUnavailable'] = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1') . ' 400 Bad Request';
     return $response;
 }
Exemplo n.º 2
0
 /**
  * Login a user without email and password validation. This methods must be enabled on the CMS server.
  * 
  * @param string $userID
  * @throws \InvalidArgumentException
  */
 public function login($userID)
 {
     if (!is_string($userID)) {
         throw new \InvalidArgumentException('');
     }
     \BearCMS\Internal\Server::call('login', ['userID' => $userID], true);
 }
Exemplo n.º 3
0
 }
 $cacheKey = json_encode(['adminUI', $app->request->base, $requestArguments, $app->bearCMS->currentUser->getSessionKey(), $app->bearCMS->currentUser->getPermissions(), get_class_vars('\\BearCMS\\Internal\\Options'), $serverCookies]);
 $adminUIData = $app->cache->get($cacheKey);
 if (!is_array($adminUIData)) {
     $adminUIData = Server::call('adminui', $requestArguments, true);
     $app->cache->set($cacheKey, $adminUIData, is_array($adminUIData) && isset($adminUIData['result']) ? 99999 : 10);
 }
 if (is_array($adminUIData) && isset($adminUIData['result']) && is_array($adminUIData['result']) && isset($adminUIData['result']['content']) && strlen($adminUIData['result']['content']) > 0) {
     $content = $adminUIData['result']['content'];
     if ((Options::hasFeature('ELEMENTS') || Options::hasFeature('ELEMENTS_*')) && !empty(ElementsHelper::$editorData)) {
         $requestArguments = [];
         $requestArguments['data'] = json_encode(ElementsHelper::$editorData);
         $cacheKey = json_encode(['elementsEditor', $app->request->base, $requestArguments, $app->bearCMS->currentUser->getSessionKey(), $app->bearCMS->currentUser->getPermissions(), get_class_vars('\\BearCMS\\Internal\\Options'), Cookies::getList(Cookies::TYPE_SERVER)]);
         $elementsEditorData = $app->cache->get($cacheKey);
         if (!is_array($elementsEditorData)) {
             $elementsEditorData = Server::call('elementseditor', $requestArguments, true);
             $app->cache->set($cacheKey, $elementsEditorData, is_array($elementsEditorData) && isset($elementsEditorData['result']) ? 99999 : 10);
         }
         if (is_array($elementsEditorData) && isset($elementsEditorData['result']) && is_array($elementsEditorData['result']) && isset($elementsEditorData['result']['content'])) {
             $domDocument = new HTML5DOMDocument();
             $domDocument->loadHTML($content);
             $domDocument->insertHTML($elementsEditorData['result']['content']);
             $content = $domDocument->saveHTML();
         } else {
             $response = new App\Response\TemporaryUnavailable();
         }
     }
     // It's needed even when there is no editable zone on the current page (editing a blog post for instance)
     $domDocument = new HTML5DOMDocument();
     $domDocument->loadHTML($content);
     $domDocument->insertHTML('<html><body><script src="' . htmlentities($context->assets->getUrl('assets/HTML5DOMDocument.min.js')) . '"></script></body></html>');
 static function elementsEditor($data, $response)
 {
     if (!empty(ElementsHelper::$editorData)) {
         $requestArguments = [];
         $requestArguments['data'] = json_encode(ElementsHelper::$editorData);
         $requestArguments['jsMode'] = 1;
         $elementsEditorData = Server::call('elementseditor', $requestArguments, true);
         if (is_array($elementsEditorData) && isset($elementsEditorData['result'], $elementsEditorData['result']['content'])) {
             $response['body'] = json_encode(Server::mergeAjaxResponses(json_decode($response['body'], true), json_decode($elementsEditorData['result']['content'], true)));
         } else {
             throw new \Exception('');
         }
     }
 }