Exemplo n.º 1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // action to execute
     $id = SpoonFilter::getGetValue('id', null, 0);
     // no id's provided
     if (empty($id) || !BackendMailmotorModel::existsMailing($id)) {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=mailing-does-not-exist');
     } else {
         // get the mailing and reset some fields
         $mailing = BackendMailmotorModel::getMailing($id);
         $mailing['status'] = 'concept';
         $mailing['send_on'] = null;
         $mailing['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
         $mailing['edited_on'] = $mailing['created_on'];
         $mailing['data'] = serialize($mailing['data']);
         unset($mailing['recipients'], $mailing['id'], $mailing['cm_id'], $mailing['send_on_raw']);
         // set groups
         $groups = $mailing['groups'];
         unset($mailing['groups']);
         // create a new mailing based on the old one
         $newId = BackendMailmotorModel::insertMailing($mailing);
         // update groups for this mailing
         BackendMailmotorModel::updateGroupsForMailing($newId, $groups);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_copy_mailing', array('item' => $mailing));
     }
     // redirect
     $this->redirect(BackendModel::createURLForAction('index') . '&report=mailing-copied&var=' . $mailing['name']);
 }
Exemplo n.º 2
0
 /**
  * Parse the form
  */
 protected function parse()
 {
     parent::parse();
     // prevent XSS
     $filter = \SpoonFilter::arrayMapRecursive('htmlspecialchars', $this->filter);
     $this->tpl->assign($filter);
 }
Exemplo n.º 3
0
 /**
  * Parse the correct messages into the template
  */
 protected function parse()
 {
     parent::parse();
     // grab the error-type from the parameters
     $errorType = $this->getParameter('type');
     // set correct headers
     switch ($errorType) {
         case 'module-not-allowed':
         case 'action-not-allowed':
             SpoonHTTP::setHeadersByCode(403);
             break;
         case 'not-found':
             SpoonHTTP::setHeadersByCode(404);
             break;
     }
     // querystring provided?
     if ($this->getParameter('querystring') !== null) {
         // split into file and parameters
         $chunks = explode('?', $this->getParameter('querystring'));
         // get extension
         $extension = SpoonFile::getExtension($chunks[0]);
         // if the file has an extension it is a non-existing-file
         if ($extension != '' && $extension != $chunks[0]) {
             // set correct headers
             SpoonHTTP::setHeadersByCode(404);
             // give a nice error, so we can detect which file is missing
             echo 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.';
             // stop script execution
             exit;
         }
     }
     // assign the correct message into the template
     $this->tpl->assign('message', BL::err(SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
 }
Exemplo n.º 4
0
 /**
  * Loads the settings form
  */
 private function loadForm()
 {
     // init settings form
     $this->frm = new BackendForm('settings');
     // get current settings
     $this->settings = BackendSearchModel::getModuleSettings();
     // add field for pagination
     $this->frm->addDropdown('overview_num_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'overview_num_items', 20));
     $this->frm->addDropdown('autocomplete_num_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'autocomplete_num_items', 20));
     $this->frm->addDropdown('autosuggest_num_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'autosuggest_num_items', 20));
     // modules that, no matter what, can not be searched
     $disallowedModules = array('search');
     // loop modules
     foreach (BackendModel::getModulesForDropDown() as $module => $label) {
         // check if module is searchable
         if (!in_array($module, $disallowedModules) && is_callable(array('Frontend' . SpoonFilter::toCamelCase($module) . 'Model', 'search'))) {
             // add field to decide wether or not this module is searchable
             $this->frm->addCheckbox('search_' . $module, isset($this->settings[$module]) ? $this->settings[$module]['searchable'] == 'Y' : false);
             // add field to decide weight for this module
             $this->frm->addText('search_' . $module . '_weight', isset($this->settings[$module]) ? $this->settings[$module]['weight'] : 1);
             // field disabled?
             if (!isset($this->settings[$module]) || $this->settings[$module]['searchable'] != 'Y') {
                 $this->frm->getField('search_' . $module . '_weight')->setAttribute('disabled', 'disabled');
                 $this->frm->getField('search_' . $module . '_weight')->setAttribute('class', 'inputText disabled');
             }
             // add to list of modules
             $this->modules[] = array('module' => $module, 'id' => $this->frm->getField('search_' . $module)->getAttribute('id'), 'label' => $label, 'chk' => $this->frm->getField('search_' . $module)->parse(), 'txt' => $this->frm->getField('search_' . $module . '_weight')->parse(), 'txtError' => '');
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $formId = \SpoonFilter::getPostValue('form_id', null, '', 'int');
     $newIdSequence = trim(\SpoonFilter::getPostValue('new_id_sequence', null, '', 'string'));
     // invalid form id
     if (!BackendFormBuilderModel::exists($formId)) {
         $this->output(self::BAD_REQUEST, null, 'form does not exist');
     } else {
         // list id
         $ids = (array) explode('|', rtrim($newIdSequence, '|'));
         // loop id's and set new sequence
         foreach ($ids as $i => $id) {
             $id = (int) $id;
             // get field
             $field = BackendFormBuilderModel::getField($id);
             // from this form and not a submit button
             if (!empty($field) && $field['form_id'] == $formId && $field['type'] != 'submit') {
                 BackendFormBuilderModel::updateField($id, array('sequence' => $i + 1));
             }
         }
         $this->output(self::OK, null, 'sequence updated');
     }
 }
Exemplo n.º 6
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $charset = $this->getContainer()->getParameter('kernel.charset');
     $searchTerm = \SpoonFilter::getPostValue('term', null, '');
     $term = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($searchTerm) : \SpoonFilter::htmlentities($searchTerm);
     $limit = (int) $this->get('fork.settings')->get('Search', 'autocomplete_num_items', 10);
     // validate
     if ($term == '') {
         $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
     } else {
         // get matches
         $matches = FrontendSearchModel::getStartsWith($term, FRONTEND_LANGUAGE, $limit);
         // get search url
         $url = FrontendNavigation::getURLForBlock('Search');
         // loop items and set search url
         foreach ($matches as &$match) {
             $match['url'] = $url . '?form=search&q=' . $match['term'];
         }
         // output
         $this->output(self::OK, $matches);
     }
 }
Exemplo n.º 7
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendBlogModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // set category id
         $this->categoryId = SpoonFilter::getGetValue('category', null, null, 'int');
         if ($this->categoryId == 0) {
             $this->categoryId = null;
         }
         // get data
         $this->record = (array) BackendBlogModel::get($this->id);
         // delete item
         BackendBlogModel::delete($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         // delete search indexes
         if (is_callable(array('BackendSearchModel', 'removeIndex'))) {
             BackendSearchModel::removeIndex($this->getModule(), $this->id);
         }
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['title']);
         // append to redirect URL
         if ($this->categoryId != null) {
             $redirectUrl .= '&category=' . $this->categoryId;
         }
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
     }
 }
Exemplo n.º 8
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $charset = $this->getContainer()->getParameter('kernel.charset');
     $searchTerm = \SpoonFilter::getPostValue('term', null, '');
     $term = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($searchTerm) : \SpoonFilter::htmlentities($searchTerm);
     // validate search term
     if ($term == '') {
         $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
     } else {
         // previous search result
         $previousTerm = \SpoonSession::exists('searchTerm') ? \SpoonSession::get('searchTerm') : '';
         \SpoonSession::set('searchTerm', '');
         // save this term?
         if ($previousTerm != $term) {
             // format data
             $this->statistics = array();
             $this->statistics['term'] = $term;
             $this->statistics['language'] = LANGUAGE;
             $this->statistics['time'] = FrontendModel::getUTCDate();
             $this->statistics['data'] = serialize(array('server' => $_SERVER));
             $this->statistics['num_results'] = FrontendSearchModel::getTotal($term);
             // save data
             FrontendSearchModel::save($this->statistics);
         }
         // save current search term in cookie
         \SpoonSession::set('searchTerm', $term);
         // output
         $this->output(self::OK);
     }
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // action to execute
     $action = SpoonFilter::getGetValue('action', array('delete', 'export'), '');
     $this->groupId = SpoonFilter::getGetValue('group_id', null, '');
     // no id's provided
     if (!$action) {
         $this->redirect(BackendModel::createURLForAction('addresses') . '&error=no-action-selected');
     }
     if (!isset($_GET['emails'])) {
         $this->redirect(BackendModel::createURLForAction('addresses') . '&error=no-items-selected');
     } else {
         // redefine id's
         $this->emails = (array) $_GET['emails'];
         // evaluate $action, see what action was triggered
         switch ($action) {
             case 'delete':
                 $this->deleteAddresses();
                 break;
             case 'export':
                 $this->exportAddresses();
                 break;
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // get vars
     $title = \SpoonFilter::ucfirst(FL::msg('BlogAllComments'));
     $link = SITE_URL . FrontendNavigation::getURLForBlock('Blog');
     $detailLink = SITE_URL . FrontendNavigation::getURLForBlock('Blog', 'Detail');
     $description = null;
     // create new rss instance
     $rss = new FrontendRSS($title, $link, $description);
     // loop articles
     foreach ($this->items as $item) {
         // init vars
         $title = $item['author'] . ' ' . FL::lbl('On') . ' ' . $item['post_title'];
         $link = $detailLink . '/' . $item['post_url'] . '/#comment-' . $item['id'];
         $description = $item['text'];
         // create new instance
         $rssItem = new FrontendRSSItem($title, $link, $description);
         // set item properties
         $rssItem->setPublicationDate($item['created_on']);
         $rssItem->setAuthor($item['author']);
         // add item
         $rss->addItem($rssItem);
     }
     $rss->parse();
 }
Exemplo n.º 11
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $id = SpoonFilter::getPostValue('id', null, '', 'int');
     $name = trim(SpoonFilter::getPostValue('value', null, '', 'string'));
     // validate
     if ($name == '') {
         $this->output(self::BAD_REQUEST, null, 'no name provided');
     }
     // get existing id
     $existingId = BackendMailmotorModel::getCampaignId($name);
     // existing campaign
     if ($existingId !== 0 && $id !== $existingId) {
         $this->output(self::ERROR, array('id' => $existingId, 'error' => true), BL::err('CampaignExists', $this->getModule()));
     }
     // build array
     $item = array();
     $item['id'] = $id;
     $item['name'] = $name;
     $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
     // get page
     $rows = BackendMailmotorModel::updateCampaign($item);
     // trigger event
     BackendModel::triggerEvent($this->getModule(), 'edited_campaign', array('item' => $item));
     // output
     if ($rows !== 0) {
         $this->output(self::OK, array('id' => $id), BL::msg('CampaignEdited', $this->getModule()));
     } else {
         $this->output(self::ERROR, null, BL::err('CampaignNotEdited', $this->getModule()));
     }
 }
Exemplo n.º 12
0
 /**
  * Loads the form.
  */
 private function loadForm()
 {
     // init var
     $modules = array();
     $checkedModules = SpoonSession::exists('modules') ? SpoonSession::get('modules') : array();
     // loop required modules
     foreach ($this->modules['required'] as $module) {
         // add to the list
         $modules[] = array('label' => SpoonFilter::toCamelCase($module), 'value' => $module, 'attributes' => array('disabled' => 'disabled'));
         // update $_POST if needed
         if (!isset($_POST['modules']) || !is_array($_POST['modules']) || !in_array($module, $_POST['modules'])) {
             $_POST['modules'][] = $module;
         }
     }
     // loop optional modules
     foreach ($this->modules['optional'] as $module) {
         // add to the list
         $modules[] = array('label' => SpoonFilter::toCamelCase($module), 'value' => $module);
     }
     // add multi checkbox
     $this->frm->addMultiCheckbox('modules', $modules, array_unique(array_merge($this->modules['required'], $checkedModules)));
     // example data
     $this->frm->addCheckbox('example_data', SpoonSession::exists('example_data') ? SpoonSession::get('example_data') : true);
     // debug mode
     $this->frm->addCheckbox('debug_mode', SpoonSession::exists('debug_mode') ? SpoonSession::get('debug_mode') : false);
     // specific debug email address
     $this->frm->addCheckbox('different_debug_email', SpoonSession::exists('different_debug_email') ? SpoonSession::get('different_debug_email') : false);
     // specific debug email address text
     $this->frm->addText('debug_email', SpoonSession::exists('debug_email') ? SpoonSession::get('debug_email') : '');
 }
Exemplo n.º 13
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $mailingId = SpoonFilter::getPostValue('mailing_id', null, '', 'int');
     $sendOnDate = SpoonFilter::getPostValue('send_on_date', null, BackendModel::getUTCDate('d/m/Y'));
     $sendOnTime = SpoonFilter::getPostValue('send_on_time', null, BackendModel::getUTCDate('H:i'));
     $messageDate = $sendOnDate;
     // validate mailing ID
     if ($mailingId == '') {
         $this->output(self::BAD_REQUEST, null, 'Provide a valid mailing ID');
     }
     if ($sendOnDate == '' || $sendOnTime == '') {
         $this->output(self::BAD_REQUEST, null, 'Provide a valid send date date provided');
     }
     // record is empty
     if (!BackendMailmotorModel::existsMailing($mailingId)) {
         $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', 'mailmotor'));
     }
     // reverse the date and make it a proper
     $explodedDate = explode('/', $sendOnDate);
     $sendOnDate = $explodedDate[2] . '-' . $explodedDate[1] . '-' . $explodedDate[0];
     // calc full send timestamp
     $sendTimestamp = strtotime($sendOnDate . ' ' . $sendOnTime);
     // build data
     $item['id'] = $mailingId;
     $item['send_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $sendTimestamp);
     $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
     // update mailing
     BackendMailmotorModel::updateMailing($item);
     // trigger event
     BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step4', array('item' => $item));
     // output
     $this->output(self::OK, array('mailing_id' => $mailingId, 'timestamp' => $sendTimestamp), sprintf(BL::msg('SendOn', $this->getModule()), $messageDate, $sendOnTime));
 }
Exemplo n.º 14
0
 public function __construct()
 {
     // define the Named Application
     if (!defined('NAMED_APPLICATION')) {
         define('NAMED_APPLICATION', 'backend');
     }
     // set the module
     $this->setModule(SpoonFilter::getGetValue('module', null, ''));
     // set the requested file
     $this->setFile(SpoonFilter::getGetValue('file', null, ''));
     // set the language
     $this->setLanguage(SpoonFilter::getGetValue('language', array_keys(BackendLanguage::getWorkingLanguages()), SITE_DEFAULT_LANGUAGE));
     // build the path
     if ($this->module == 'core') {
         $path = BACKEND_CORE_PATH . '/js/' . $this->getFile();
     } else {
         $path = BACKEND_MODULES_PATH . '/' . $this->getModule() . '/js/' . $this->getFile();
     }
     // set correct headers
     SpoonHTTP::setHeaders('content-type: application/javascript');
     // create a new template instance (this will handle all stuff for us)
     $tpl = new BackendTemplate();
     // enable addslashes on each locale
     $tpl->setAddSlashes(true);
     // display
     $tpl->display($path, true);
 }
Exemplo n.º 15
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // form was sent?
     if ($this->URL->getParameter('sent') == 'true') {
         // show message
         $this->tpl->assign('unsubscribeIsSuccess', true);
         // hide form
         $this->tpl->assign('unsubscribeHideForm', true);
     }
     // unsubscribe was issued for a specific group/address
     if (SpoonFilter::isEmail($this->email) && FrontendMailmotorModel::existsGroup($this->group)) {
         // unsubscribe the address from this group
         if (FrontendMailmotorModel::unsubscribe($this->email, $this->group)) {
             // hide form
             $this->tpl->assign('unsubscribeHideForm', true);
             // show message
             $this->tpl->assign('unsubscribeIsSuccess', true);
         } else {
             // show message
             $this->tpl->assign('unsubscribeHasError', true);
         }
     }
     // parse the form
     $this->frm->parse($this->tpl);
 }
Exemplo n.º 16
0
 /**
  * Parse the correct messages into the template
  */
 protected function parse()
 {
     parent::parse();
     // grab the error-type from the parameters
     $errorType = $this->getParameter('type');
     // set correct headers
     switch ($errorType) {
         case 'module-not-allowed':
         case 'action-not-allowed':
             $this->statusCode = Response::HTTP_FORBIDDEN;
             break;
         case 'not-found':
             $this->statusCode = Response::HTTP_NOT_FOUND;
             break;
         default:
             $this->statusCode = Response::HTTP_BAD_REQUEST;
             break;
     }
     // querystring provided?
     if ($this->getParameter('querystring') !== null) {
         // split into file and parameters
         $chunks = explode('?', $this->getParameter('querystring'));
         // get extension
         $extension = pathinfo($chunks[0], PATHINFO_EXTENSION);
         // if the file has an extension it is a non-existing-file
         if ($extension != '' && $extension != $chunks[0]) {
             // give a nice error, so we can detect which file is missing
             throw new ExitException('File not found', 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.', Response::HTTP_NOT_FOUND);
         }
     }
     // assign the correct message into the template
     $this->tpl->assign('message', BL::err(\SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
 }
Exemplo n.º 17
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $formId = trim(SpoonFilter::getPostValue('form_id', null, '', 'int'));
     $fieldId = trim(SpoonFilter::getPostValue('field_id', null, '', 'int'));
     // invalid form id
     if (!BackendFormBuilderModel::exists($formId)) {
         $this->output(self::BAD_REQUEST, null, 'form does not exist');
     }
     // invalid fieldId
     if (!BackendFormBuilderModel::existsField($fieldId, $formId)) {
         $this->output(self::BAD_REQUEST, null, 'field does not exist');
     }
     // get field
     $field = BackendFormBuilderModel::getField($fieldId);
     // submit button cannot be deleted
     if ($field['type'] == 'submit') {
         $this->output(self::BAD_REQUEST, null, 'submit button cannot be deleted');
     } else {
         // delete field
         BackendFormBuilderModel::deleteField($fieldId);
         // success output
         $this->output(self::OK, null, 'field deleted');
     }
 }
Exemplo n.º 18
0
 /**
  * @param string $type The type of init to load, possible values: backend, backend_ajax, backend_cronjob, backend_js
  */
 public function __construct($type)
 {
     $allowedTypes = array('api');
     $type = (string) $type;
     // check if this is a valid type
     if (!in_array($type, $allowedTypes)) {
         exit('Invalid init-type');
     }
     // set type
     $this->type = $type;
     // register the autoloader
     spl_autoload_register(array('APIInit', 'autoLoader'));
     // set some ini-options
     ini_set('memory_limit', '64M');
     // set a default timezone if no one was set by PHP.ini
     if (ini_get('date.timezone') == '') {
         date_default_timezone_set('Europe/Brussels');
     }
     /**
      * At first we enable the error reporting. Later on it will be disabled based on the
      * value of SPOON_DEBUG, but for now it's required to see possible errors while trying
      * to include the globals file(s).
      */
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', 'On');
     $this->requireGlobals();
     $this->definePaths();
     $this->setIncludePath();
     $this->setDebugging();
     // get spoon
     require_once 'spoon/spoon.php';
     $this->requireAPIClasses();
     SpoonFilter::disableMagicQuotes();
     $this->initSession();
 }
Exemplo n.º 19
0
 /**
  * Loads the datagrids
  */
 private function loadDataGrids()
 {
     /*
      * DataGrid for the subscriptions that are awaiting moderation.
      */
     $this->dgModeration = new BackendDataGridDB(BackendAgendaModel::QRY_DATAGRID_BROWSE_SUBSCRIPTIONS, array('moderation', BL::getWorkingLanguage()));
     // active tab
     $this->dgModeration->setActiveTab('tabModeration');
     // num items per page
     $this->dgModeration->setPagingLimit(30);
     // header labels
     $this->dgModeration->setHeaderLabels(array('created_on' => \SpoonFilter::ucfirst(BL::lbl('Date'))));
     // add the multi-checkbox column
     $this->dgModeration->setMassActionCheckboxes('checkbox', '[id]');
     // assign column functions
     $this->dgModeration->setColumnFunction(array(new BackendDataGridFunctions(), 'getTimeAgo'), '[created_on]', 'created_on', true);
     // sorting
     $this->dgModeration->setSortingColumns(array('created_on', 'name'), 'created_on');
     $this->dgModeration->setSortParameter('desc');
     // add mass action drop-down
     $ddmMassAction = new \SpoonFormDropdown('action', array('subscribed' => BL::lbl('MoveToSubscribed'), 'delete' => BL::lbl('Delete')), 'subscribed');
     $ddmMassAction->setAttribute('id', 'actionModeration');
     $ddmMassAction->setOptionAttributes('delete', array('data-message-id' => 'confirmDeleteModeration'));
     $ddmMassAction->setOptionAttributes('subscribe', array('data-message-id' => 'confirmSubscribedModeration'));
     $this->dgModeration->setMassAction($ddmMassAction);
     // check if this action is allowed
     if (BackendAuthentication::isAllowedAction('edit_subscription')) {
         $this->dgModeration->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit_subscription') . '&id=[id]', BL::lbl('Edit'));
     }
     // check if this action is allowed
     if (BackendAuthentication::isAllowedAction('mass_subscriptions_action')) {
         $this->dgModeration->addColumn('approve', null, BL::lbl('Approve'), BackendModel::createURLForAction('mass_subscriptions_action') . '&id=[id]&from=subscribed&action=subscribed', BL::lbl('Approve'));
     }
     /*
      * DataGrid for the subscriptions that are marked as subscribed
      */
     $this->dgSubscribed = new BackendDataGridDB(BackendAgendaModel::QRY_DATAGRID_BROWSE_SUBSCRIPTIONS, array('subscribed', BL::getWorkingLanguage()));
     // active tab
     $this->dgSubscribed->setActiveTab('tabSubscriptions');
     // num items per page
     $this->dgSubscribed->setPagingLimit(30);
     // header labels
     $this->dgSubscribed->setHeaderLabels(array('created_on' => \SpoonFilter::ucfirst(BL::lbl('Date'))));
     // add the multi-checkbox column
     $this->dgSubscribed->setMassActionCheckboxes('checkbox', '[id]');
     // assign column functions
     $this->dgSubscribed->setColumnFunction(array(new BackendDataGridFunctions(), 'getTimeAgo'), '[created_on]', 'created_on', true);
     // sorting
     $this->dgSubscribed->setSortingColumns(array('created_on', 'name'), 'created_on');
     $this->dgSubscribed->setSortParameter('desc');
     // add mass action drop-down
     $ddmMassAction = new \SpoonFormDropdown('action', array('moderation' => BL::lbl('MoveToModeration'), 'delete' => BL::lbl('Delete')), 'published');
     $ddmMassAction->setAttribute('id', 'actionSubscriptions');
     $ddmMassAction->setOptionAttributes('delete', array('data-message-id' => 'confirmDeleteSubscribed'));
     $this->dgSubscribed->setMassAction($ddmMassAction);
     // check if this action is allowed
     if (BackendAuthentication::isAllowedAction('edit_subscription')) {
         $this->dgSubscribed->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit_subscription') . '&id=[id]', BL::lbl('Edit'));
     }
 }
Exemplo n.º 20
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // action to execute
     $action = \SpoonFilter::getGetValue('action', array('delete'), '');
     // form id
     $formId = \SpoonFilter::getGetValue('form_id', null, '', 'int');
     // no id's provided
     if (!isset($_GET['id'])) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-items-selected');
     } elseif ($action == '') {
         // no action provided
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-action-selected');
     } elseif (!BackendFormBuilderModel::exists($formId)) {
         // valid form id
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     } else {
         // redefine id's
         $ids = (array) $_GET['id'];
         // delete comment(s)
         if ($action == 'delete') {
             BackendFormBuilderModel::deleteData($ids);
         }
         // define report
         $report = count($ids) > 1 ? 'items-' : 'item-';
         // init var
         if ($action == 'delete') {
             $report .= 'deleted';
         }
         // redirect
         $this->redirect(BackendModel::createURLForAction('Data') . '&id=' . $formId . '&report=' . $report);
     }
 }
Exemplo n.º 21
0
 /**
  * Load the data, don't forget to validate the incoming data
  *
  * @return	void
  */
 private function getData()
 {
     // get categories
     $categories = FrontendBlogModel::getAllCategories();
     $possibleCategories = array();
     foreach ($categories as $category) {
         $possibleCategories[$category['url']] = $category['id'];
     }
     // requested category
     $requestedCategory = SpoonFilter::getValue($this->URL->getParameter(1, 'string'), array_keys($possibleCategories), 'false');
     // requested page
     $requestedPage = $this->URL->getParameter('page', 'int', 1);
     // validate category
     if ($requestedCategory == 'false') {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // set category
     $this->category = $categories[$possibleCategories[$requestedCategory]];
     // set URL and limit
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('blog', 'category') . '/' . $requestedCategory;
     $this->pagination['limit'] = FrontendModel::getModuleSetting('blog', 'overview_num_items', 10);
     // populate count fields in pagination
     $this->pagination['num_items'] = FrontendBlogModel::getAllForCategoryCount($requestedCategory);
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // redirect if the request page doesn't exists
     if ($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get articles
     $this->items = FrontendBlogModel::getAllForCategory($requestedCategory, $this->pagination['limit'], $this->pagination['offset']);
 }
Exemplo n.º 22
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $id = \SpoonFilter::getPostValue('id', null, 0, 'int');
     $tag = trim(\SpoonFilter::getPostValue('value', null, '', 'string'));
     // validate id
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     } else {
         // validate tag name
         if ($tag === '') {
             $this->output(self::BAD_REQUEST, null, BL::err('NameIsRequired'));
         } else {
             // check if tag exists
             if (BackendTagsModel::existsTag($tag)) {
                 $this->output(self::BAD_REQUEST, null, BL::err('TagAlreadyExists'));
             } else {
                 $item['id'] = $id;
                 $item['tag'] = \SpoonFilter::htmlspecialchars($tag);
                 $item['url'] = BackendTagsModel::getURL(CommonUri::getUrl(\SpoonFilter::htmlspecialcharsDecode($item['tag'])), $id);
                 BackendTagsModel::update($item);
                 $this->output(self::OK, $item, vsprintf(BL::msg('Edited'), array($item['tag'])));
             }
         }
     }
 }
Exemplo n.º 23
0
 /**
  * The user is allowed on this page
  *
  * @return bool
  */
 private function isUserAllowed()
 {
     // catch the key and e-mail address from GET
     $this->email = urldecode(\SpoonFilter::getGetValue('email', null, ''));
     $this->key = \SpoonFilter::getGetValue('key', null, '');
     // if the email or the key aren't set, redirect the user
     if ($this->email !== '' && $this->key !== '') {
         // fetch the user
         $userId = BackendUsersModel::getIdByEmail($this->email);
         $this->user = new BackendUser($userId);
         $requestTime = $this->user->getSetting('reset_password_timestamp');
         // check if the request was made within 24 hours
         if (time() - $requestTime > 86400) {
             // remove the reset_password_key and reset_password_timestamp usersettings
             BackendUsersModel::deleteResetPasswordSettings($userId);
             // redirect to the login form, with a timeout error
             $this->redirect(BackendModel::createURLForAction('Index', null, null, array('reset' => 'timeout')));
         }
         // check if the provided key matches the one in the user record
         if ($this->key === $this->user->getSetting('reset_password_key')) {
             return true;
         }
     }
     // if we made it here the user is not allowed to access this page
     return false;
 }
Exemplo n.º 24
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $formId = trim(\SpoonFilter::getPostValue('form_id', null, '', 'int'));
     $fieldId = trim(\SpoonFilter::getPostValue('field_id', null, '', 'int'));
     // invalid form id
     if (!BackendFormBuilderModel::exists($formId)) {
         $this->output(self::BAD_REQUEST, null, 'form does not exist');
     } else {
         // invalid fieldId
         if (!BackendFormBuilderModel::existsField($fieldId, $formId)) {
             $this->output(self::BAD_REQUEST, null, 'field does not exist');
         } else {
             // get field
             $field = BackendFormBuilderModel::getField($fieldId);
             if ($field['type'] == 'radiobutton') {
                 $values = array();
                 foreach ($field['settings']['values'] as $value) {
                     $values[] = $value['label'];
                 }
                 $field['settings']['values'] = $values;
             }
             // success output
             $this->output(self::OK, array('field' => $field));
         }
     }
 }
Exemplo n.º 25
0
 /**
  * Parses the data to make the line chart
  *
  * @param array $metricsPerDay All needed metrics grouped by day.
  */
 private function parseLineChartData($metricsPerDay)
 {
     $maxYAxis = 2;
     $metrics = array('pageviews');
     $graphData = array();
     foreach ($metrics as $i => $metric) {
         // build graph data array
         $graphData[$i] = array();
         $graphData[$i]['title'] = $metric;
         $graphData[$i]['label'] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($metric)));
         $graphData[$i]['data'] = array();
         foreach ($metricsPerDay as $j => $data) {
             // cast SimpleXMLElement to array
             $data = (array) $data;
             $graphData[$i]['data'][$j]['date'] = (int) $data['timestamp'];
             $graphData[$i]['data'][$j]['value'] = (string) $data[$metric];
         }
     }
     // loop the metrics
     foreach ($graphData as $metric) {
         foreach ($metric['data'] as $data) {
             // get the maximum value
             if ((int) $data['value'] > $maxYAxis) {
                 $maxYAxis = (int) $data['value'];
             }
         }
     }
     $this->tpl->assign('maxYAxis', $maxYAxis);
     $this->tpl->assign('tickInterval', $maxYAxis == 2 ? '1' : '');
     $this->tpl->assign('lineGraphData', $graphData);
 }
Exemplo n.º 26
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the ids as array
     $ids = \SpoonFilter::getPostValue('ids', null, '', 'array');
     //--Set module
     $module = (string) \SpoonFilter::getPostValue('mediaModule', null, '', 'string');
     //--Set action
     $action = (string) \SpoonFilter::getPostValue('mediaAction', null, '', 'string');
     //--Set the id
     $id = (int) \SpoonFilter::getPostValue('mediaId', null, '', 'int');
     //--Set the type
     $type = (string) \SpoonFilter::getPostValue('mediaType', null, '', 'string');
     //--Create media object
     $media = new BackendMediaHelper(new BackendForm('add_image', null, 'post', false), $module, $id, $action, $type);
     //--Check if the ids is not empty
     if (!empty($ids)) {
         foreach ($ids as $id) {
             //--Link mediaitem with id to item
             $media->linkMediaToModule($id);
         }
     }
     // success output
     $this->output(self::OK, null, 'files added');
 }
Exemplo n.º 27
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // fetch record
     $this->record = FrontendTagsModel::get($this->URL->getParameter(1));
     // validate record
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // fetch modules
     $this->modules = FrontendTagsModel::getModulesForTag($this->record['id']);
     // loop modules
     foreach ($this->modules as $module) {
         // get the ids of the items linked to the tag
         $otherIds = (array) $this->get('database')->getColumn('SELECT other_id
              FROM modules_tags
              WHERE module = ? AND tag_id = ?', array($module, $this->record['id']));
         // set module class
         $class = 'Frontend\\Modules\\' . $module . '\\Engine\\Model';
         // get the items that are linked to the tags
         $items = (array) FrontendTagsModel::callFromInterface($module, $class, 'getForTags', $otherIds);
         // add into results array
         if (!empty($items)) {
             $this->results[] = array('name' => $module, 'label' => FL::lbl(\SpoonFilter::ucfirst($module)), 'items' => $items);
         }
     }
 }
Exemplo n.º 28
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // gender dropdown values
     $genderValues = array('male' => \SpoonFilter::ucfirst(BL::getLabel('Male')), 'female' => \SpoonFilter::ucfirst(BL::getLabel('Female')));
     // birthdate dropdown values
     $days = range(1, 31);
     $months = \SpoonLocale::getMonths(BL::getInterfaceLanguage());
     $years = range(date('Y'), 1900);
     // create form
     $this->frm = new BackendForm('add');
     // create elements
     $this->frm->addText('email')->setAttribute('type', 'email');
     $this->frm->addPassword('password');
     $this->frm->addText('display_name');
     $this->frm->addText('first_name');
     $this->frm->addText('last_name');
     $this->frm->addText('city');
     $this->frm->addDropdown('gender', $genderValues);
     $this->frm->addDropdown('day', array_combine($days, $days));
     $this->frm->addDropdown('month', $months);
     $this->frm->addDropdown('year', array_combine($years, $years));
     $this->frm->addDropdown('country', Intl::getRegionBundle()->getCountryNames(BL::getInterfaceLanguage()));
     // set default elements dropdowns
     $this->frm->getField('gender')->setDefaultElement('');
     $this->frm->getField('day')->setDefaultElement('');
     $this->frm->getField('month')->setDefaultElement('');
     $this->frm->getField('year')->setDefaultElement('');
     $this->frm->getField('country')->setDefaultElement('');
 }
 /**
  * Load the datagrids
  *
  * @return  void
  */
 private function loadDataGrids()
 {
     // load all categories that are in use
     $categories = BackendSlideshowModel::getActiveCategories(true);
     // run over categories and create datagrid for each one
     foreach ($categories as $categoryId => $categoryTitle) {
         // create datagrid
         $dataGrid = new BackendDataGridDB(BackendSlideshowModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage(), $categoryId));
         // disable paging
         $dataGrid->setPaging(false);
         // set colum URLs
         $dataGrid->setColumnURL('title', BackendModel::createURLForAction('Edit') . '&amp;id=[id]');
         // set column functions
         $dataGrid->setColumnFunction(array(new BackendDataGridFunctions(), 'getLongDate'), array('[publish_on]'), 'publish_on', true);
         $dataGrid->setColumnFunction(array(new BackendDataGridFunctions(), 'getUser'), array('[user_id]'), 'user_id', true);
         // set headers
         $dataGrid->setHeaderLabels(array('user_id' => \SpoonFilter::ucfirst(BL::lbl('Author')), 'publish_on' => \SpoonFilter::ucfirst(BL::lbl('PublishedOn'))));
         // enable drag and drop
         $dataGrid->enableSequenceByDragAndDrop();
         // our JS needs to know an id, so we can send the new order
         $dataGrid->setRowAttributes(array('id' => '[id]'));
         $dataGrid->setAttributes(array('data-action' => "GallerySequence"));
         // create a column #images
         $dataGrid->addColumn('images', ucfirst(BL::lbl('Images')));
         $dataGrid->setColumnFunction(array('Backend\\Modules\\Slideshow\\Engine\\Model', 'getImagesByGallery'), array('[id]', true), 'images', true);
         // hide columns
         $dataGrid->setColumnsHidden(array('category_id', 'sequence', 'filename'));
         // add edit column
         $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('Edit') . '&amp;id=[id]', BL::lbl('Edit'));
         // set column order
         $dataGrid->setColumnsSequence('dragAndDropHandle', 'title', 'images', 'user_id', 'publish_on', 'edit');
         // add dataGrid to list
         $this->dataGrids[] = array('id' => $categoryId, 'title' => $categoryTitle, 'content' => $dataGrid->getContent());
     }
 }
Exemplo n.º 30
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // create bogus form
     $frm = new BackendForm('meta');
     // get parameters
     $URL = \SpoonFilter::getPostValue('url', null, '', 'string');
     $metaId = \SpoonFilter::getPostValue('meta_id', null, null);
     $baseFieldName = \SpoonFilter::getPostValue('baseFieldName', null, '', 'string');
     $custom = \SpoonFilter::getPostValue('custom', null, false, 'bool');
     $className = \SpoonFilter::getPostValue('className', null, '', 'string');
     $methodName = \SpoonFilter::getPostValue('methodName', null, '', 'string');
     $parameters = \SpoonFilter::getPostValue('parameters', null, '', 'string');
     // cleanup values
     $metaId = $metaId ? (int) $metaId : null;
     $parameters = @unserialize($parameters);
     // meta object
     $this->meta = new BackendMeta($frm, $metaId, $baseFieldName, $custom);
     // set callback for generating an unique URL
     $this->meta->setUrlCallback($className, $methodName, $parameters);
     // fetch generated meta url
     $URL = urldecode($this->meta->generateURL($URL));
     // output
     $this->output(self::OK, $URL);
 }