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;
 }
 /**
  * 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);
 }
示例#3
0
            }
            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>');
        $content = $domDocument->saveHTML();
        $content = Server::updateAssetsUrls($content, false);
        if (strpos($content, '{body}') !== false) {
            $content = str_replace('{body}', '<component src="data:base64,' . base64_encode($response->content) . '"/>', $content);
        } elseif (strpos($content, '{jsonEncodedBody}') !== false) {
            $content = str_replace('{jsonEncodedBody}', json_encode($app->components->process($response->content)), $content);
        }
        $response->content = $app->components->process($content);
    } else {
        $response = new App\Response\TemporaryUnavailable();
    }
}, ['priority' => 1000]);
if (Options::hasServer() && (Options::hasFeature('USERS') || Options::hasFeature('USERS_LOGIN_*'))) {
    $app->hooks->add('responseCreated', function () {
        Cookies::update();
    }, ['priority' => 1001]);
}
 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('');
         }
     }
 }