Beispiel #1
0
 public function __construct()
 {
     $URL = new BackendURL();
     new BackendTemplate();
     new BackendNavigation();
     new BackendHeader();
     $action = new BackendAction($URL->getAction(), $URL->getModule());
     $action->execute();
 }
Beispiel #2
0
 /**
  * Display, this wil output the template to the browser
  * If no template is specified we build the path form the current module and action
  *
  * @return	void
  * @param	string[optional] $template	The template to use, if not provided it will be based on the action.
  */
 public function display($template = null)
 {
     // parse header
     $this->header->parse();
     // if no template is specified, we have to build the path ourself
     // the default template is based on the name of the current action
     if ($template === null) {
         $template = BACKEND_MODULE_PATH . '/layout/templates/' . $this->URL->getAction() . '.tpl';
     }
     // display
     $this->tpl->display($template);
 }
Beispiel #3
0
 /**
  * Default constructor
  *
  * @return	void
  */
 public function __construct()
 {
     // create URL-object to handle the URL
     $URL = new BackendURL();
     // create new template so we have a reference that will be available on every module/action
     new BackendTemplate();
     // create a navigation object
     new BackendNavigation();
     // create a header-object
     new BackendHeader();
     // create a new action
     $action = new BackendAction($URL->getAction(), $URL->getModule());
     // execute the action
     $action->execute();
 }
Beispiel #4
0
 /**
  * Add a JS-file.
  * If you don't specify a module, the current one will be used
  * If you set parseThroughPHP to true, the JS will be parsed by PHP (labels and vars will be assignes)
  * If you set overwritePath to true we expect a full path (It has to start with a /)
  *
  * @param string $fileName The file to load.
  * @param string[optional] $module The module wherin the file is located.
  * @param bool[optional] $parseThroughPHP Should the file be parsed by PHP?
  * @param bool[optional] $overwritePath Should we overwrite the full path?
  * @param bool[optional] $addTimestamp May we add a timestamp for caching purposes?
  */
 public function addJS($fileName, $module = null, $parseThroughPHP = false, $overwritePath = false, $addTimestamp = null)
 {
     $fileName = (string) $fileName;
     $module = (string) ($module !== null) ? $module : $this->URL->getModule();
     $parseThroughPHP = (bool) $parseThroughPHP;
     $overwritePath = (bool) $overwritePath;
     // validate parameters
     if ($parseThroughPHP && $overwritePath) {
         throw new BackendException('parseThroughPHP and overwritePath can\'t be both true.');
     }
     // init var
     $realPath = '';
     // is the given path the real path?
     if ($overwritePath) {
         $realPath = $fileName;
     } elseif ($parseThroughPHP) {
         $realPath = '/backend/js.php?module=' . $module . '&file=' . $fileName . '&language=' . BackendLanguage::getWorkingLanguage();
     } elseif ($module !== 'core') {
         $realPath = '/backend/modules/' . $module . '/js/' . $fileName;
     } else {
         $realPath = '/backend/core/js/' . $fileName;
     }
     // add if not already added
     if (!in_array(array('path' => $realPath, 'add_timestamp' => $addTimestamp), $this->jsFiles)) {
         $this->jsFiles[] = array('path' => $realPath, 'add_timestamp' => $addTimestamp);
     }
 }
Beispiel #5
0
 /**
  * @param string[optional] $name Name of the form.
  * @param string[optional] $action The action (URL) whereto the form will be submitted, if not provided it will be autogenerated.
  * @param string[optional] $method The method to use when submiting the form, default is POST.
  * @param bool[optional] $useToken Should we automagically add a formtoken?
  * @param bool[optional] $useGlobalError Should we automagically show a global error?
  */
 public function __construct($name = null, $action = null, $method = 'post', $useToken = true, $useGlobalError = true)
 {
     if (Spoon::exists('url')) {
         $this->URL = Spoon::get('url');
     }
     if (Spoon::exists('header')) {
         $this->header = Spoon::get('header');
     }
     $this->useGlobalError = (bool) $useGlobalError;
     // build a name if there wasn't one provided
     $name = $name === null ? SpoonFilter::toCamelCase($this->URL->getModule() . '_' . $this->URL->getAction(), '_', true) : (string) $name;
     // build the action if it wasn't provided
     $action = $action === null ? '/' . $this->URL->getQueryString() : (string) $action;
     // call the real form-class
     parent::__construct($name, $action, $method, $useToken);
     // add default classes
     $this->setParameter('id', $name);
     $this->setParameter('class', 'forkForms submitWithLink');
 }
Beispiel #6
0
 public function __construct()
 {
     // check if the user is logged in
     $this->validateLogin();
     // named application
     if (!defined('NAMED_APPLICATION')) {
         define('NAMED_APPLICATION', 'backend_ajax');
     }
     // get values from the GET-parameters
     $module = isset($_GET['fork']['module']) ? $_GET['fork']['module'] : '';
     $action = isset($_GET['fork']['action']) ? $_GET['fork']['action'] : '';
     $language = isset($_GET['fork']['language']) ? $_GET['fork']['language'] : SITE_DEFAULT_LANGUAGE;
     // overrule the values with the ones provided through POST
     $module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : $module;
     $action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : $action;
     $language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : $language;
     // create URL instance, since the template modifiers need this object
     $URL = new BackendURL();
     $URL->setModule($module);
     $this->setModule($module);
     $this->setAction($action);
     $this->setLanguage($language);
     // create a new action
     $action = new BackendAJAXAction();
     $action->setModule($this->getModule());
     $action->setAction($this->getAction());
     try {
         $action->execute();
     } catch (Exception $e) {
         // set correct headers
         SpoonHTTP::setHeadersByCode(500);
         // if we are debugging we should see the exceptions
         if (SPOON_DEBUG) {
             throw $e;
         }
         // output
         $fakeAction = new BackendBaseAJAXAction();
         $fakeAction->output(BackendBaseAJAXAction::ERROR, null, $e->getMessage());
     }
 }
Beispiel #7
0
 /**
  * @param BackendForm $form An instance of Backendform, the elements will be parsed in here.
  * @param int[optional] $metaId The metaID to load.
  * @param string[optional] $baseFieldName The field where the URL should be based on.
  * @param bool[optional] $custom Add/show custom-meta.
  */
 public function __construct(BackendForm $form, $metaId = null, $baseFieldName = 'title', $custom = false)
 {
     // check if URL is available from the referene
     if (!Spoon::exists('url')) {
         throw new BackendException('URL should be available in the reference.');
     }
     // get BackendURL instance
     $this->URL = Spoon::get('url');
     // should we use meta-custom
     $this->custom = (bool) $custom;
     // set form instance
     $this->frm = $form;
     // set base field name
     $this->baseFieldName = (string) $baseFieldName;
     // metaId was specified, so we should load the item
     if ($metaId !== null) {
         $this->loadMeta($metaId);
     }
     // set default callback
     $this->setUrlCallback('Backend' . SpoonFilter::toCamelCase($this->URL->getModule()) . 'Model', 'getURL');
     // load the form
     $this->loadForm();
 }
 /**
  * Parse some vars
  */
 private function parseVars()
 {
     // assign a placeholder var
     $this->assign('var', '');
     // assign current timestamp
     $this->assign('timestamp', time());
     // assign body ID
     if ($this->URL instanceof BackendURL) {
         $this->assign('bodyID', SpoonFilter::toCamelCase($this->URL->getModule(), '_', true));
         // build classes
         $bodyClass = SpoonFilter::toCamelCase($this->URL->getModule() . '_' . $this->URL->getAction(), '_', true);
         // special occasions
         if ($this->URL->getAction() == 'add' || $this->URL->getAction() == 'edit') {
             $bodyClass = $this->URL->getModule() . 'AddEdit';
         }
         // assign
         $this->assign('bodyClass', $bodyClass);
     }
 }
Beispiel #9
0
 /**
  * Add a JS-file.
  * If you don't specify a module, the current one will be used
  * If you set parseThroughPHP to true, the JS will be parsed by PHP (labels and vars will be assignes)
  * If you set overwritePath to true we expect a full path (It has to start with a /)
  *
  * @param string $file The file to load.
  * @param string[optional] $module The module wherin the file is located.
  * @param bool[optional] $minify Should the module be minified?
  * @param bool[optional] $parseThroughPHP Should the file be parsed by PHP?
  * @param bool[optional] $overwritePath Should we overwrite the full path?
  * @param bool[optional] $addTimestamp May we add a timestamp for caching purposes?
  */
 public function addJS($file, $module = null, $minify = true, $parseThroughPHP = false, $overwritePath = false, $addTimestamp = false)
 {
     $file = (string) $file;
     $module = (string) ($module !== null) ? $module : $this->URL->getModule();
     $minify = (bool) $minify;
     $parseThroughPHP = (bool) $parseThroughPHP;
     $overwritePath = (bool) $overwritePath;
     $addTimestamp = (bool) $addTimestamp;
     // validate parameters
     if ($parseThroughPHP && $overwritePath) {
         throw new BackendException('parseThroughPHP and overwritePath can\'t be both true.');
     }
     // no minifying when debugging
     if (SPOON_DEBUG) {
         $minify = false;
     }
     // no minifying when parsing through PHP
     if ($parseThroughPHP) {
         $minify = false;
     }
     // is the given path the real path?
     if (!$overwritePath) {
         // should we parse the js-file? as in assign variables
         if ($parseThroughPHP) {
             $file = '/backend/js.php?module=' . $module . '&file=' . $file . '&language=' . BL::getWorkingLanguage();
         } elseif ($module !== 'core') {
             $file = '/backend/modules/' . $module . '/js/' . $file;
         } else {
             $file = '/backend/core/js/' . $file;
         }
     }
     // try to minify
     if ($minify) {
         $file = $this->minifyJS($file);
     }
     // already in array?
     if (!in_array(array('file' => $file, 'add_timestamp' => $addTimestamp), $this->jsFiles)) {
         // add to files
         $this->jsFiles[] = array('file' => $file, 'add_timestamp' => $addTimestamp);
     }
 }
Beispiel #10
0
 /**
  * Try to determine the selected state
  *
  * @return	mixed
  * @param	array $value			The value.
  * @param	int $key				The key.
  * @param	array[optional] $keys	The previous marked keys.
  */
 private function compareURL(array $value, $key, $keys = array())
 {
     // create active url
     $activeURL = $this->URL->getModule() . '/' . $this->URL->getAction();
     // add current key
     $keys[] = $key;
     // sub action?
     if (isset($value['selected_for']) && in_array($activeURL, (array) $value['selected_for'])) {
         return $keys;
     }
     // if the URL is available and same as the active one we have what we need.
     if (isset($value['url']) && $value['url'] == $activeURL) {
         if (isset($value['children'])) {
             // loop the childs
             foreach ($value['children'] as $key => $value) {
                 // recursive here...
                 $subKeys = $this->compareURL($value, $key, $keys);
                 // wrap it up
                 if (!empty($subKeys)) {
                     return $subKeys;
                 }
             }
         }
         // fallback
         return $keys;
     }
     // any children
     if (isset($value['children'])) {
         // loop the childs
         foreach ($value['children'] as $key => $value) {
             // recursive here...
             $subKeys = $this->compareURL($value, $key, $keys);
             // wrap it up
             if (!empty($subKeys)) {
                 return $subKeys;
             }
         }
     }
 }
Beispiel #11
0
 /**
  * Set module
  *
  * @param string $value The module to use.
  */
 private function setModule($value)
 {
     // set property
     $this->module = (string) $value;
     // core is a module that contains general stuff, so it has to be allowed
     if ($this->module !== 'core') {
         // is this module allowed?
         if (!BackendAuthentication::isAllowedModule($this->module)) {
             // set correct headers
             SpoonHTTP::setHeadersByCode(403);
             // stop script execution
             exit;
         }
     }
     // create URL instance, the templatemodifiers need this object
     $URL = new BackendURL();
     // set the module
     $URL->setModule($this->module);
 }
Beispiel #12
0
 /**
  * Set module
  *
  * @return	void
  * @param	string $value	The module to use.
  */
 public function setModule($value)
 {
     // set property
     $this->module = (string) $value;
     // is this module allowed?
     if (!BackendAuthentication::isAllowedModule($this->module)) {
         // set correct headers
         SpoonHTTP::setHeadersByCode(403);
         // output
         $fakeAction = new BackendBaseAJAXAction('', '');
         $fakeAction->output(BackendBaseAJAXAction::FORBIDDEN, null, 'Module not allowed.');
     }
     // create URL instance, the templatemodifiers need this object
     $URL = new BackendURL();
     // set the module
     $URL->setModule($this->module);
 }
Beispiel #13
0
 /**
  * Validates the form
  * It checks if there is a value when a checkbox is checked
  *
  * @return	void
  */
 public function validate()
 {
     // no callback set by user?
     if (empty($this->callback)) {
         // build class- & method-name
         $className = 'Backend' . SpoonFilter::toCamelCase($this->URL->getModule()) . 'Model';
         $methodName = 'getURL';
         // set
         $this->setUrlCallback($className, $methodName);
     }
     // page title overwrite is checked
     if ($this->frm->getField('page_title_overwrite')->isChecked()) {
         $this->frm->getField('page_title')->isFilled(BL::err('FieldIsRequired'));
     }
     // meta description overwrite is checked
     if ($this->frm->getField('meta_description_overwrite')->isChecked()) {
         $this->frm->getField('meta_description')->isFilled(BL::err('FieldIsRequired'));
     }
     // meta keywords overwrite is checked
     if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) {
         $this->frm->getField('meta_keywords')->isFilled(BL::err('FieldIsRequired'));
     }
     // URL overwrite is checked
     if ($this->frm->getField('url_overwrite')->isChecked()) {
         // filled
         $this->frm->getField('url')->isFilled(BL::err('FieldIsRequired'));
         // fetch url
         $URL = SpoonFilter::urlise($this->frm->getField('url')->getValue());
         // build parameters for use in the callback
         $parameters[] = $URL;
         // add parameters set by user
         if (!empty($this->callback['parameters'])) {
             foreach ($this->callback['parameters'] as $parameter) {
                 $parameters[] = $parameter;
             }
         }
         // get the real url
         $generatedUrl = call_user_func_array(array($this->callback['class'], $this->callback['method']), $parameters);
         // check if urls are different
         if ($URL != $generatedUrl) {
             $this->frm->getField('url')->addError(BL::err('URLAlreadyExists'));
         }
     }
     // if the form was submitted correctly the data array should be populated
     if ($this->frm->isCorrect()) {
         // no callback set by user?
         if (empty($this->callback)) {
             // build class- & method-name
             $className = 'Backend' . SpoonFilter::toCamelCase($this->URL->getModule()) . 'Model';
             $methodName = 'getURL';
             // set
             $this->setUrlCallback($className, $methodName);
         }
         // get meta keywords
         if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) {
             $keywords = $this->frm->getField('meta_keywords')->getValue();
         } else {
             $keywords = $this->frm->getField($this->baseFieldName)->getValue();
         }
         // get meta description
         if ($this->frm->getField('meta_description_overwrite')->isChecked()) {
             $description = $this->frm->getField('meta_description')->getValue();
         } else {
             $description = $this->frm->getField($this->baseFieldName)->getValue();
         }
         // get page title
         if ($this->frm->getField('page_title_overwrite')->isChecked()) {
             $title = $this->frm->getField('page_title')->getValue();
         } else {
             $title = $this->frm->getField($this->baseFieldName)->getValue();
         }
         // get URL
         if ($this->frm->getField('url_overwrite')->isChecked()) {
             $URL = SpoonFilter::urlise(SpoonFilter::htmlspecialcharsDecode($this->frm->getField('url')->getValue()));
         } else {
             $URL = SpoonFilter::urlise(SpoonFilter::htmlspecialcharsDecode($this->frm->getField($this->baseFieldName)->getValue()));
         }
         // build parameters for use in the callback
         $parameters[] = $URL;
         // add parameters set by user
         if (!empty($this->callback['parameters'])) {
             foreach ($this->callback['parameters'] as $parameter) {
                 $parameters[] = $parameter;
             }
         }
         // get the real URL
         $URL = call_user_func_array(array($this->callback['class'], $this->callback['method']), $parameters);
         // get meta custom
         if ($this->custom && $this->frm->getField('meta_custom')->isFilled()) {
             $custom = $this->frm->getField('meta_custom')->getValue();
         } else {
             $custom = null;
         }
         // set data
         $this->data['keywords'] = $keywords;
         $this->data['keywords_overwrite'] = $this->frm->getField('meta_keywords_overwrite')->isChecked() ? 'Y' : 'N';
         $this->data['description'] = $description;
         $this->data['description_overwrite'] = $this->frm->getField('meta_description_overwrite')->isChecked() ? 'Y' : 'N';
         $this->data['title'] = $title;
         $this->data['title_overwrite'] = $this->frm->getField('page_title_overwrite')->isChecked() ? 'Y' : 'N';
         $this->data['url'] = $URL;
         $this->data['url_overwrite'] = $this->frm->getField('url_overwrite')->isChecked() ? 'Y' : 'N';
         $this->data['custom'] = $custom;
         if ($this->frm->getField('seo_index')->getValue() == 'none') {
             unset($this->data['data']['seo_index']);
         } else {
             $this->data['data']['seo_index'] = $this->frm->getField('seo_index')->getValue();
         }
         if ($this->frm->getField('seo_follow')->getValue() == 'none') {
             unset($this->data['data']['seo_follow']);
         } else {
             $this->data['data']['seo_follow'] = $this->frm->getField('seo_follow')->getValue();
         }
     }
 }