BEdita API doc | 3-corylus
  • Class
  • Tree
  • Deprecated
  • Download

Classes

  • Addon
  • AddressbookController
  • AddressbookShell
  • AdminController
  • Alias
  • Annotation
  • ApiAuthComponent
  • ApiBaseController
  • ApiFormatterComponent
  • ApiUploadComponent
  • ApiValidatorComponent
  • AppController
  • AppError
  • AppHelper
  • Application
  • AppModel
  • Area
  • AreasController
  • Audio
  • AuthenticationsController
  • BannedIp
  • BEAppModel
  • BEAppObjectModel
  • BeAuthComponent
  • BeAuthFacebookComponent
  • BeAuthGoogleComponent
  • BeAuthTwitterComponent
  • BeCallbackManager
  • BeConfigure
  • BeCustomPropertyComponent
  • BeditaAnnotationModel
  • BeditaBaseShell
  • BeditaCollectionModel
  • BeditaContentModel
  • BeditaExportFilter
  • BeditaImportFilter
  • BeditaObjectModel
  • BeditaProductModel
  • BeditaShell
  • BeditaSimpleObjectModel
  • BeditaSimpleStreamModel
  • BeditaStreamModel
  • BeEmbedFlashHelper
  • BeEmbedHtml5Helper
  • BeEmbedMediaHelper
  • BeErrorCode
  • BeExceptionHandler
  • BEFile
  • BeFileHandlerComponent
  • BeFormHelper
  • BeFrontHelper
  • BeHashComponent
  • BeHtmlHelper
  • BeLangTextComponent
  • BeLib
  • BeMailComponent
  • BEObject
  • BeObjectCache
  • BePaginatorToolbarHelper
  • BeSchema
  • BeSecurityComponent
  • BeSystem
  • BeSystemComponent
  • BeThumb
  • BeTimeHelper
  • BeToolbarHelper
  • BeTreeComponent
  • BeTreeHelper
  • BeUploadToObjComponent
  • BeurlHelper
  • BeVimeoComponent
  • BeYoutubeComponent
  • BuildFilterBehavior
  • CacheableBehavior
  • CacheShell
  • CallbackBehavior
  • CaptchaComponent
  • Caption
  • CaptionsBehavior
  • Card
  • CardsImportFilter
  • Category
  • CleanupDataTask
  • CleanupTask
  • Comment
  • CommentsController
  • CompactResultBehavior
  • Content
  • CreateIndexFieldsBehavior
  • DataShell
  • DataTransfer
  • DateItem
  • DbadminShell
  • DeleteDependentObjectBehavior
  • DeleteObjectBehavior
  • DeployShell
  • Document
  • DocumentsController
  • DumpModel
  • EditorialContentsShell
  • EditorNote
  • Event
  • EventLog
  • EventsController
  • FilesController
  • ForeignDependenceSaveBehavior
  • FrontendController
  • FrontendShell
  • GalleriesController
  • Gallery
  • GeoTag
  • GettextShell
  • Git
  • GravatarHelper
  • Group
  • HashJob
  • History
  • HomeController
  • Image
  • ImageInfoHelper
  • JsonExportFilter
  • JsonImportFilter
  • JsonView
  • LangText
  • Link
  • MailGroup
  • MailGroupCard
  • MailJob
  • MailLog
  • MailMessage
  • MailShell
  • MailTemplate
  • Mask
  • MediaShell
  • MigrateDumpModel
  • MigrateShell
  • Migration
  • MigrationBase
  • MigrationDateItemsShell
  • Module
  • ModulesController
  • ModuleShell
  • MultimediaController
  • NewsController
  • NewsletterController
  • NewsletterShell
  • NotifyBehavior
  • ObjectEditor
  • ObjectProperty
  • ObjectRelation
  • ObjectType
  • ObjectUser
  • PagesController
  • Permission
  • PermissionModule
  • PermsHelper
  • Product
  • Property
  • PropertyOption
  • PublicationShell
  • RedisShell
  • RelationCheck
  • RelationRepair
  • RelationShell
  • RelationStats
  • RemoveDummyNameBehavior
  • ResponseHandlerComponent
  • RestClientModel
  • Revision
  • RevisionObjectBehavior
  • SearchText
  • SearchTextSaveBehavior
  • Section
  • SectionDummy
  • SessionFilterComponent
  • SessionFilterHelper
  • ShortNews
  • SmartyView
  • SoapClientModel
  • SplitterSql
  • StatisticsController
  • Stream
  • StreamLog
  • StreamsController
  • Svn
  • TagsController
  • ThemeSmartyView
  • ThumbnailHelper
  • ThumbShell
  • TransactionComponent
  • TransactionFS
  • TranslationsController
  • Tree
  • TrHelper
  • User
  • UserProperty
  • UsersController
  • Utility
  • Version
  • Video
  • VimeoHelper
  • WebmarksController
  • XmlExportFilter
  • XmlImportFilter
  • XmlJsonConverter
  • XmlView
  • YoutubeHelper

Interfaces

  • ApiAuthInterface
  • MediaProviderInterface
  • UploadableInterface

Exceptions

  • BeditaAjaxException
  • BEditaAllowURLException
  • BeditaBadRequestException
  • BeditaConflictException
  • BEditaDeleteStreamObjException
  • BeditaException
  • BEditaFileExistException
  • BeditaForbiddenException
  • BeditaFrontAccessException
  • BeditaHashException
  • BEditaInfoException
  • BeditaInternalErrorException
  • BEditaIOException
  • BeditaLengthRequiredException
  • BeditaMailException
  • BEditaMediaProviderException
  • BeditaMethodNotAllowedException
  • BEditaMIMEException
  • BeditaNotFoundException
  • BeditaNotImplementedException
  • BeditaPublicationException
  • BeditaRuntimeException
  • BEditaSaveStreamObjException
  • BeditaServiceUnavailableException
  • BeditaUnauthorizedException
  • BEditaUploadPHPException
  • BEditaURLException
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 
<?php
/*-----8<--------------------------------------------------------------------
 * 
 * BEdita - a semantic content management framework
 * 
 * Copyright 2011-2015 ChannelWeb Srl, Chialab Srl
 * 
 * This file is part of BEdita: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published 
 * by the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 * BEdita is distributed WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License 
 * version 3 along with BEdita (see LICENSE.LGPL).
 * If not, see <http://gnu.org/licenses/lgpl-3.0.html>.
 * 
 *------------------------------------------------------------------->8-----
 */

App::import('Core', 'Error');

/**
 * BEdita/cake error handler (backends+frontends)
 */
class AppError extends ErrorHandler {

    /**
     * CakePHP errors that will be treated as 404 http errors
     * All other CakePHP errors will be treated as 500 http errors
     *
     * @var array
     */
    protected $error404 = array('missingController', 'missingAction');

    /**
     * The exception error trace
     *
     * @var string
     */
    protected $errorTrace = '';

    /**
     * Current app debug level
     * @var int
     */
    protected $debugLevel;

    /**
     * The Exception that has been thrown
     *
     * @var Exception
     */
    protected $exception = null;

    /**
     * Error data set for View
     * It is set also as '_serialize' view var so that ResponseHandlerComponent can use it to send to the client as payload
     * In json/xml requests
     *
     * Options are
     *
     * ```
     * 'status' => null, // the http status code
     * 'code' => null, // the error code
     * 'message' => null, // the error message
     * 'details' => null, // the error details
     * 'moreInfo' => null, // other useful information
     * 'url' => null // the url that has caused the error
     * ```
     *
     * @var array
     */
    protected $error = array(
        'status' => null,
        'code' => null,
        'message' => null,
        'details' => null,
        'more_info' => null,
        'url' => null
    );

    /**
     * The layout to use (default is 'error')
     *
     * @var string
     */
    protected $layout = 'error';

    function __construct($method, $messages, Exception $exception = null) {
        $this->setLayout();
        try {
            $this->debugLevel = Configure::read('debug');
            Configure::write('debug', 1);
            if (!empty($exception)) {
                App::import('Core', 'Sanitize');
                $options = array('escape' => false);
                $this->error['message'] = Sanitize::clean($exception->getMessage(), $options);
                if ($exception instanceof BeditaException) {
                    $this->error['status'] = $exception->getHttpCode();
                    $this->error['details'] = Sanitize::clean($exception->getDetails(), $options);
                    $errorCode = $exception->getErrorCode();
                    $this->error['code'] = !empty($errorCode) ? $errorCode->code() : null;
                    $this->error['more_info'] = !empty($errorCode) ? $errorCode->info() : null;
                    $messages['result'] = $exception->result;
                    $this->errorTrace = $exception->errorTrace();
                } else {
                    $messages['result'] = 'ERROR';
                    $this->errorTrace = get_class($exception) . ' - ' . $exception->getMessage()
                        . " \nFile: " . $exception->getFile() . ' - line: ' . $exception->getLine()
                        . " \nTrace:\n" . $exception->getTraceAsString();
                }
                $this->exception = $exception;
            }
            $this->error['url'] = $this->getUrl();
            parent::__construct($method, $messages);
        } catch (Exception $e) { // error 500 if another exception is thrown here
            $this->controller->view = 'Smarty';
            $this->controller->output = '';
            $this->setError(array(
                'message' => $e->getMessage(),
                'details' => null,
                'status' => 500,
                'moreInfo' => null
            ));
            // log error
            $this->errorTrace = get_class($e). ": ". $e->getMessage()."\nFile: ".$e->getFile().
                " - line: ".$e->getLine()."\nTrace:\n". $e->getTraceAsString();
            $this->log($e->getMessage() .  ' url: ' . $this->getUrl());
            $this->log($this->errorTrace, 'exception');
            $this->sendMail($this->errorTrace);
            $this->controller->set($messages);
            $this->controller->render(null, $this->layout, $this->getViewFile());
            echo $this->controller->output;
            $this->_stop();
        }
    }

    public function restoreDebugLevel() {
        if(isset($this->debugLevel)) {
            Configure::write('debug', $this->debugLevel); // restore level
        }
    }

    /**
     * Check if Controller has basic initialization
     *
     * * Check if params are defined
     * * Check if RequestHandler and ResponseHandler components are initialized
     * * Add BeFront helper in frontend apps
     * * Add $conf to viewVars if missing
     *
     * @return void
     */
    private function checkController() {
        if (empty($this->controller->params)) {
            $this->controller->params = Router::getParams();
        }
        $components = array('RequestHandler', 'ResponseHandler');
        foreach ($components as $name) {
            if (empty($this->controller->$name)) {
                if (App::import('Component', $name)) {
                    $completeName = $name . 'Component';
                    $this->controller->$name = new $completeName();
                    if ($name == 'ResponseHandler') {
                        $this->controller->$name->RequestHandler = $this->controller->RequestHandler;
                    }
                    $this->controller->$name->initialize($this->controller);
                    $this->controller->$name->startup($this->controller);
                } else {
                    $this->log('AppError: Fail to load ' . $name . ' component.');
                }
            }
        }

        // assure that ResponseHandler is enabled
        $this->controller->ResponseHandler->enabled = true;

        if (BACKEND_APP) {
            // check backend helpers
            $checkHelpers = array('Beurl', 'BeForm', 'Session', 'SessionFilter');
            // assure to use Smarty view
            $this->controller->view = 'Smarty';
        } else {
            // check frontend helpers
            $checkHelpers = array('BeFront');
        }

        foreach ($checkHelpers as $helperName) {
            if (!in_array($helperName, $this->controller->helpers)) {
                $this->controller->helpers[] = $helperName;
            }
        }

        // assure to have $conf in viewVars
        if (empty($this->controller->viewVars['conf'])) {
            $this->controller->set('conf', Configure::getInstance());
        }
    }

    /**
     * Set the layout to use
     * If Request is ajax set ajax layout
     *
     * @param string $layout
     * @return void
     */
    protected function setLayout($layout = 'error') {
        if (env('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest') {
            $layout = 'ajax';
        }
        $this->layout = $layout;
    }

    /**
     * Set self::error to View vars and add also it to '_serialize' for ResponseHandlerComponent
     *
     * @param array $error
     */
    protected function setError(array $error = array()) {
        if (!empty($error)) {
            $this->error = $error + $this->error;
        }
        // default http status code to 500
        if (empty($this->error['status'])) {
            $this->error['status'] = 500;
        }
        $this->controller->ResponseHandler->sendStatus($this->error['status']);
        $this->controller->set(array(
            'error' => $this->error,
            '_serialize' => array('error')
        ));
    }

    /**
     * Return the error template to use
     * The template depends from http status code triggered from Exception
     *
     * First it checks if exists 'views/errors/error' . self::exception::httpCode() . '.tpl' (or .ctp)
     * If it not exists then it return the more general 'views/errors/error.tpl' (or .ctp)
     *
     * @return string
     */
    protected function getViewFile() {
        $baseFileName = 'error';
        $httpCode = (method_exists($this->exception, 'getHttpCode')) ? $this->exception->getHttpCode() : '';
        $fileName = VIEWS . 'errors/' . $baseFileName . $httpCode . $this->controller->ext;
        if (file_exists($fileName)) {
            return $fileName;
        } else {
            return VIEWS . 'errors/' . $baseFileName . $this->controller->ext;
        }
    }

    public function handleException(array $messages) {
        $this->checkController();
        if ($this->controller->RequestHandler->isAjax() && BACKEND_APP) {
            $messages['output'] = ($this->controller->ResponseHandler->getType() == 'json') ? 'json' : 'beditaMsg';
            return $this->handleBeditaAjaxException($messages);
        }
        $this->restoreDebugLevel();
        $url = AppController::usedUrl();
        $current = AppController::currentController();
        if (isset($current)) {
            $this->controller = $current;
            $this->checkController();
            $this->controller->setResult($messages['result']);
            $this->controller->handleError($this->error['details'], $this->error['message'], $this->errorTrace);
            $this->setError();
            if (BACKEND_APP) {
                $this->controller->render($this->controller->action);
            } else {
                $this->controller->render(null, $this->layout, $this->getViewFile());
            }
            $this->controller->afterFilter();
        } else {
            $this->setError();
            $this->log($this->error['details'] . $url);
            $this->log($this->errorTrace, 'exception');
            $this->controller->render(null, $this->layout,  $this->getViewFile());
            $this->sendMail($this->errorTrace);
        }
        echo $this->controller->output;
    }
    
    public function handleSmartyException(array $messages) {
        $this->error['message'] = 'Smarty error';
        $this->error['details'] = $this->exception->getMessage();
        $this->handleException($messages);
    }

    /**
     * handle ajax exception
     * 
     * @param array $messages 
     *              'msg' => the exception message
     *              'details' => the error detail
     *              'output' => the output type. It can be:
     *                          'html' (default) BEdita html standard error message from elements/message.tpl
     *                          'json' json object is built in view as:
     *                                  {
     *                                      errorMsg: exception message, 
     *                                      htmlMsg: BEdita html standard error message from see elements/message.tpl
     *                                  }
     *                          'beditaMsg' output the BEdita html standard error message and trigger it
     *                          'reload' javascript: location.reload(); used for example when the session expired in a ajax call
     *              'headers' => server headers (usually header error): if it's not set or === null no headers error will be sent
     *                                                                  if it's set and empty use "HTTP/1.1 500 Internal Server Error"
     */
    public function handleBeditaAjaxException(array $messages) {
        $isBeditaAjaxException = (get_class($this->exception) == 'BeditaAjaxException') ? true : false;
        if (empty($messages['output']) && $isBeditaAjaxException) {
            $messages['output'] = $this->exception->getOutputType();
        }

        $headers = null;
        if (!empty($messages['headers'])) {
            $headers = $messages['headers'];
        } elseif ($isBeditaAjaxException) {
            $headers = $this->exception->getHeaders();
        }

        if ($headers !== null) {
            if (empty($headers)) {
                $headers = array('HTTP/1.1 500 Internal Server Error');
            } elseif (is_string($headers)) {
                $headers = array($headers);
            }
            // output headers
            foreach ($headers as $header) {
                header($header);
            }
        } else {
            $status = !empty($this->error['status']) ? $this->error['status'] : 500;
            $this->controller->ResponseHandler->sendStatus($status);
        }

        $this->controller->set("output", $messages['output']);
        // html (default fallback)
        $usrMsgParams = array("layout" => "", "params" => array());
        if ($messages['output'] == "beditaMsg" || $messages['output'] == "reload") {
            $usrMsgParams = array();
        } elseif ($messages['output'] == "json") {
            header("Content-Type: application/json");
            $this->controller->set("errorMsg",  $this->error['message']);
            $usrMsgParams = array();
        }
        $this->restoreDebugLevel();
        $this->controller->handleError($this->error['details'], $this->error['message'], $this->errorTrace, $usrMsgParams);
        App::import('View', "Smarty");
        $viewObj = new SmartyView($this->controller);
        echo $viewObj->render(null, "ajax", VIEWS."errors/error_ajax.tpl");
    }
    
    /**
     * @deprecated
     * @param array $messages
     * @return void
     */
    public function handleExceptionRuntime(array $messages) {
        $current = AppController::currentController();
        if(isset($current)) {
            $this->controller = $current;
            $this->controller->handleError($messages['details'], $messages['msg'], $this->errorTrace);
        }
        header('HTTP/1.1 500 Internal Server Error');
        $this->controller->set($messages);
        $this->restoreDebugLevel();
        App::import('View', "Smarty");
        $viewObj = new SmartyView($this->controller);
        echo $viewObj->render(null, $this->layout, VIEWS."errors/error500.tpl");                
    }
    
    /**
     * @deprecated
     * @param array $messages
     * @return void
     */
    public function handleExceptionFrontend(array $messages) {
        $current = AppController::currentController();
        if(isset($current)) {
            $this->controller = $current;
            $this->controller->handleError($messages['details'], $messages['msg'], $this->errorTrace);
        }
        header('HTTP/1.1 404 Not Found');
        $this->controller->set($messages);
        $this->restoreDebugLevel();
        App::import('View', "Smarty");
        $viewObj = new SmartyView($this->controller);
        echo $viewObj->render(null, $this->layout, VIEWS."errors/error404.tpl");                
    }
    
    /**
     * @deprecated
     * @param array $messages
     * @return void
     */
    public function handleExceptionFrontAccess(array $messages) {
        if (isset($messages['headers']) && $messages['headers'] !== null) {
            if (empty($messages['headers'])) {
                $messages['headers'] = array("HTTP/1.1 401 Unauthorized");
            } elseif (is_string($messages['headers'])) {
                $messages['headers'] = array($messages['headers']);
            }
            // output headers
            foreach ($messages['headers'] as $header) {
                header($header);
            }
        }
        $currentController = AppController::currentController();
        $currentController->set($messages);
        $this->restoreDebugLevel();
        $currentController->handleError($messages['details'], $messages['msg'], $this->errorTrace);
        if ($messages["errorType"] == "unlogged") {
            $viewName = "login";
        } else {
            $viewName = $messages["errorType"];
        }
        $viewFile = (file_exists(VIEWS."pages".DS.$viewName.".tpl"))? VIEWS."pages".DS.$viewName.".tpl" : VIEWS."pages".DS.$viewName.".ctp";
        echo $currentController->render(null,null,$viewFile);
    }
    
    private function sendMail($mailMsg) {
        $mailSupport = Configure::read('mailSupport');
        if (!empty($mailSupport['to'])) {
            $jobModel = ClassRegistry::init("MailJob");
            $jobModel->containLevel("default");
            $data = array();
            $data["status"] = "unsent";
            $data["mail_params"] = serialize(array(
                        "sender" => $mailSupport['from'], 
                        "subject" => $mailSupport['subject'],
            ));
            $data["mail_body"] = $mailMsg;
            $dest = explode(',', $mailSupport['to']);
            foreach ($dest as $d) {
                $data["recipient"] = $d;
                $jobModel->create();
                if (!$jobModel->save($data)) {
                    $this->log(__("Error creating mail job") . "-" . print_r($data,true),true);
                }
            }

        }
    }

    // use cake output only in debug mode
    function _outputMessage($template) {
        $this->__outputMessage($template);
    }
    
    function __outputMessage($template) {
        $this->checkController();
        $tpl = "";
        $vars = array();
        $vars['url'] = $this->error['url'] = $this->getUrl();
        $this->error['message'] = $this->getMessage();
        if (in_array($template, $this->error404)) {
            $this->error['status'] = 404;
            if (!empty($this->controller->viewVars["BEAuthUser"])) {
                // remove unwanted data
                $vars["userid"] = $this->controller->viewVars["BEAuthUser"]["userid"];
            }
            if (!empty($this->controller->viewVars["controller"])) {
                $vars["controller"] = $this->controller->viewVars["controller"];
            }
            $tpl = "error404.tpl";
            $this->log(" 404 Not Found - $template: " . var_export($vars, TRUE));
        } else {
            $this->error['status'] = 500;
            $vars = array_merge($vars, $this->controller->viewVars);
            if (!empty($vars["conf"])) {
                unset($vars["conf"]);
            }
            if (!empty($_POST)) {
                $vars["post"] = $_POST;
            }
            $tpl = "error500.tpl";
            $errMsg = " 500 Internal Error - $template: " . var_export($vars, TRUE);
            $this->log($errMsg);
            $this->sendMail($errMsg);
        }
        if (empty($this->controller->viewVars["errorType"])) {
            $this->controller->set("errorType", $template);
        }
        $this->restoreDebugLevel();
        $this->setError();
        $this->controller->render(null, $this->layout, VIEWS."errors/" . $tpl);
        $this->controller->afterFilter();
        echo $this->controller->output;
    }

    /**
     * Return the request url
     *
     * @return string|null
     */
    public function getUrl() {
        $url = env('REQUEST_URI');
        if (empty($url)) {
            if (!empty($this->controller->params['url']['url'])) {
                $url = $this->controller->params['url']['url'];
            } elseif (!empty($_GET['url'])) {
                $url = $_GET['url'];
            } elseif (!empty($_POST['url'])) {
                $url = $_POST['url'];
            }
        }
        $url = Router::normalize($url);
        return Router::url($url, true);
    }

    /**
     * Return the error message
     * If an exception has created the error use its message
     * else try to read some View vars set by CakePHP
     *
     * @return string
     */
    public function getMessage() {
        $message = '';
        if ($this->exception) {
            $message = $this->exception->getMessage();
        } elseif (!empty($this->controller->viewVars['name'])) {
            $message = $this->controller->viewVars['name'];
        } elseif (!empty($this->controller->viewVars['message'])) {
            $message = $this->controller->viewVars['message'];
        } elseif (!empty($this->controller->viewVars['title'])) {
            $message = $this->controller->viewVars['title'];
        }
        return $message;
    }
}
BEdita API doc | 3-corylus API documentation generated by ApiGen