/**
  * Retrieve the unique URL for an teamMember
  *
  * @param string $url
  * @param int $id The id of the teamMember to ignore.
  * @return string
  */
 public static function getUrl($url, $id = null)
 {
     $url = CommonUri::getUrl((string) $url);
     $database = BackendModel::get('database');
     if ($id === null) {
         $urlExists = (bool) $database->getVar('SELECT 1
                FROM team_members AS i
                     INNER JOIN meta AS m
                     ON i.meta_id = m.id
               WHERE i.language = ? AND m.url = ?
               LIMIT 1', [Language::getWorkingLanguage(), $url]);
     } else {
         $urlExists = (bool) $database->getVar('SELECT 1
                FROM team_members AS i
                     INNER JOIN meta AS m
                     ON i.meta_id = m.id
               WHERE i.language = ? AND m.url = ? AND i.id != ?
               LIMIT 1', [Language::getWorkingLanguage(), $url, $id]);
     }
     if ($urlExists) {
         $url = Model::addNumber($url);
         return self::getUrl($url, $id);
     }
     return $url;
 }
Example #2
0
 /**
  * Loads the settings form
  */
 private function loadForm()
 {
     // init settings form
     $this->frm = new BackendForm('settings');
     $settings = BackendModel::get('fork.settings')->getForModule('Agenda');
     $this->frm->addText('width1', $settings['width1']);
     $this->frm->addText('height1', $settings['height1']);
     $this->frm->addCheckbox('allow_enlargment1', $settings['allow_enlargment1']);
     $this->frm->addCheckbox('force_aspect_ratio1', $settings['force_aspect_ratio1']);
     $this->frm->addText('width1', $settings['width2']);
     $this->frm->addText('height1', $settings['height2']);
     $this->frm->addCheckbox('allow_enlargment2', $settings['allow_enlargment2']);
     $this->frm->addCheckbox('force_aspect_ratio2', $settings['force_aspect_ratio2']);
     $this->frm->addText('width3', $settings['width3']);
     $this->frm->addText('height3', $settings['height3']);
     $this->frm->addCheckbox('allow_enlargment3', $settings['allow_enlargment3']);
     $this->frm->addCheckbox('force_aspect_ratio3', $settings['force_aspect_ratio3']);
     $this->frm->addCheckbox('allow_subscriptions', $settings['allow_subscriptions']);
     $this->frm->addCheckbox('moderation', $settings['moderation']);
     $this->frm->addCheckbox('notify_by_email_on_new_subscription_to_moderate', $settings['notify_by_email_on_new_subscription_to_moderate']);
     $this->frm->addCheckbox('notify_by_email_on_new_subscription', $settings['notify_by_email_on_new_subscription']);
     $this->frm->addText('cache_timeout', $settings['cache_timeout']);
     $this->frm->addDropdown('zoom_level', array_combine(array_merge(array('auto'), range(3, 18)), array_merge(array(BL::lbl('Auto', $this->getModule())), range(3, 18))), $this->get('fork.settings')->get($this->URL->getModule(), 'zoom_level_widget', 13));
     $this->frm->addText('width', $this->get('fork.settings')->get($this->URL->getModule(), 'width'));
     $this->frm->addText('height', $this->get('fork.settings')->get($this->URL->getModule(), 'height'));
     $this->frm->addDropdown('map_type', array('ROADMAP' => BL::lbl('Roadmap', $this->getModule()), 'SATELLITE' => BL::lbl('Satellite', $this->getModule()), 'HYBRID' => BL::lbl('Hybrid', $this->getModule()), 'TERRAIN' => BL::lbl('Terrain', $this->getModule())), $this->get('fork.settings')->get($this->URL->getModule(), 'map_type_widget', 'roadmap'));
 }
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['language'] = BL::getWorkingLanguage();
             $item['meta_id'] = $this->meta->save();
             $item['sequence'] = BackendCatalogModel::getMaximumSpecificationSequence() + 1;
             // save the data
             $item['id'] = BackendCatalogModel::insertSpecification($item);
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue();
                 BackendCatalogModel::insertSpecificationLanguage($itemLanguage);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_specification', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('specifications') . '&report=added-specification&var=' . urlencode($this->frm->getField('title_nl')->getValue()) . '&highlight=row-' . $item['id']);
         }
     }
 }
Example #4
0
 /**
  * @param string $query             The query to retrieve the data.
  * @param array  $parameters        The parameters to be used inside the query.
  * @param string $resultsQuery      The optional count query, used to calculate the number of results.
  * @param array  $resultsParameters The parameters to be used inside the results query.
  */
 public function __construct($query, $parameters = array(), $resultsQuery = null, $resultsParameters = array())
 {
     // results query?
     $results = $resultsQuery !== null ? array($resultsQuery, $resultsParameters) : null;
     // create a new source-object
     $source = new \SpoonDatagridSourceDB(BackendModel::get('database'), array($query, (array) $parameters), $results);
     parent::__construct($source);
 }
Example #5
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // only one category allowed, so we redirect
     if (!BackendModel::get('fork.settings')->getForModule('Agenda', 'allow_multiple_categories', true)) {
         $this->redirect(BackendModel::createURLForAction('categories') . '&error=only-one-category-allowed');
     }
     parent::execute();
     $this->loadForm();
     $this->validateForm();
     $this->parse();
     $this->display();
 }
Example #6
0
 public function configureOptions(OptionsResolver $optionsResolver)
 {
     $optionsResolver->setDefaults(['attr' => ['class' => 'inputEditor']]);
     if (!Model::has('header')) {
         return;
     }
     // add the needed javascript to the header;
     $header = Model::get('header');
     // we add JS because we need CKEditor
     $header->addJS('ckeditor/ckeditor.js', 'Core', false);
     $header->addJS('ckeditor/adapters/jquery.js', 'Core', false);
     $header->addJS('ckfinder/ckfinder.js', 'Core', false);
     // add the internal link lists-file
     if (is_file(FRONTEND_CACHE_PATH . '/Navigation/editor_link_list_' . Language::getWorkingLanguage() . '.js')) {
         $timestamp = @filemtime(FRONTEND_CACHE_PATH . '/Navigation/editor_link_list_' . Language::getWorkingLanguage() . '.js');
         $header->addJS('/src/Frontend/Cache/Navigation/editor_link_list_' . Language::getWorkingLanguage() . '.js?m=' . $timestamp, null, false, true, false);
     }
 }
Example #7
0
 /**
  * Install the module
  */
 public function install()
 {
     // add the schema of the entity to the database
     Model::get('fork.entity.create_schema')->forEntityClass(ContentBlock::class);
     // add 'content_blocks' as a module
     $this->addModule('ContentBlocks');
     // import locale
     $this->importLocale(__DIR__ . '/Data/locale.xml');
     // general settings
     $this->setSetting($this->getModule(), 'max_num_revisions', 20);
     // module rights
     $this->setModuleRights(1, $this->getModule());
     // action rights
     $this->setActionRights(1, $this->getModule(), 'Add');
     $this->setActionRights(1, $this->getModule(), 'Delete');
     $this->setActionRights(1, $this->getModule(), 'Edit');
     $this->setActionRights(1, $this->getModule(), 'Index');
     // set navigation
     $navigationModulesId = $this->setNavigation(null, 'Modules');
     $this->setNavigation($navigationModulesId, $this->getModule(), 'content_blocks/index', ['content_blocks/add', 'content_blocks/edit']);
 }
Example #8
0
 /**
  * @param $email
  * @param $postedFields
  * @param $form
  * @param $dataId
  */
 public static function mailEndUser($email, $postedFields, $form, $dataId)
 {
     $field_info = '';
     foreach ($postedFields as $field) {
         $label = isset($field['label']) ? $field['label'] : '';
         $value = isset($field['value']) ? unserialize($field['value']) : '';
         $field_info .= $label . ': ' . $value . "\n";
     }
     $title = sprintf(BL::getLabel('Subject', self::MODULE_NAME), $form['name']);
     $data = array('title' => $title, 'fields' => $field_info);
     $translations = array('ReceivedData', 'Greetings');
     foreach ($translations as $translation) {
         $data[$translation] = BL::getLabel($translation, self::MODULE_NAME);
     }
     /** @var $mailer Mailer */
     $mailer = BackendModel::get('mailer');
     if ($mailer) {
         // @TODO remove this when https://github.com/forkcms/forkcms/issues/716 is fixed.
         define('FRONTEND_LANGUAGE', SITE_DEFAULT_LANGUAGE);
         // work around
         $result = $mailer->addEmail($title, BACKEND_MODULES_PATH . '/' . self::MODULE_NAME . '/Layout/Templates/Mails/Notification.tpl', $data, $email);
     }
     $useLog = BackendModel::getModuleSetting(self::MODULE_NAME, 'log', true);
     if ($useLog) {
         $logger = BackendModel::get('logger');
         if ($logger) {
             $logger->notice(sprintf('Sending email to %s, status %s', $email, $result ? 'OK' : 'FAILED'), $data);
         }
     }
     $addExtraData = BackendModel::getModuleSetting(self::MODULE_NAME, 'add_data', true);
     $error = BL::getLabel('Error', self::MODULE_NAME);
     $success = BL::getLabel('OK', self::MODULE_NAME);
     if ($addExtraData) {
         $label = BL::getLabel('DataLabel', self::MODULE_NAME);
         $item = array('data_id' => $dataId, 'label' => $label, 'value' => serialize($email . ' - ' . ($result ? $success : $error)));
         /** @var $db SpoonDatabase */
         $db = BackendModel::getContainer()->get('database');
         $db->insert('forms_data_fields', $item);
     }
 }
Example #9
0
 /**
  * Loads the dataGrid
  */
 private function loadDataGrid()
 {
     // are multiple categories allowed?
     $this->multipleCategoriesAllowed = BackendModel::get('fork.settings')->getForModule('Agenda', 'allow_multiple_categories', true);
     // create dataGrid
     $this->dataGrid = new BackendDataGridDB(BackendAgendaModel::QRY_DATAGRID_BROWSE_CATEGORIES, BL::getWorkingLanguage());
     $this->dataGrid->setHeaderLabels(array('num_items' => ucfirst(BL::lbl('Amount'))));
     if ($this->multipleCategoriesAllowed) {
         $this->dataGrid->enableSequenceByDragAndDrop();
     } else {
         $this->dataGrid->setColumnsHidden(array('sequence'));
     }
     $this->dataGrid->setRowAttributes(array('id' => '[id]'));
     $this->dataGrid->setPaging(false);
     // check if this action is allowed
     if (BackendAuthentication::isAllowedAction('Index')) {
         $this->dataGrid->setColumnFunction(array(__CLASS__, 'setClickableCount'), array('[num_items]', BackendModel::createURLForAction('index') . '&category=[id]'), 'num_items', true);
     }
     // check if this action is allowed
     if (BackendAuthentication::isAllowedAction('EditCategory')) {
         $this->dataGrid->setColumnURL('title', BackendModel::createURLForAction('edit_category') . '&id=[id]');
         $this->dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit_category') . '&id=[id]', BL::lbl('Edit'));
     }
 }
 /**
  * Fetches all selected folders
  *
  * @return array Selected folders and their path
  */
 public static function getAllFolders()
 {
     return (array) BackendModel::get('database')->getRecords('SELECT i.id, i.title, i.path, UNIX_TIMESTAMP(i.created_on) AS created_on
          FROM compression_folders AS i');
 }
Example #11
0
 /**
  * Delete a certain link to mediaitem
  *
  * @param int $id
  */
 public static function deleteLink($id)
 {
     BackendModel::get('database')->delete("media_modules", "id=?", array($id));
 }
Example #12
0
    public function linkMediaToModule($media_id)
    {
        $exists = (bool) BackendModel::get('database')->getVar('SELECT 1
			 FROM media_modules AS i
			 WHERE i.module = ? AND other_id = ? AND type = ? AND i.media_id = ?
			 LIMIT 1', array((int) $this->module, $this->id, $this->type, $media_id));
        if (!$exists) {
            if ($this->module != "" && $this->id > 0) {
                //--Calculate sequence
                $sequence = (int) BackendModel::getContainer()->get('database')->getVar('SELECT MAX(i.sequence)
			 FROM media_modules AS i
			 WHERE i.module = ? AND other_id = ? AND type = ?', array((int) $this->module, $this->id, $this->type));
                $sequence += 1;
                $insert = array();
                $insert["media_id"] = $media_id;
                $insert["module"] = $this->module;
                $insert["other_id"] = $this->id;
                $insert["type"] = $this->type;
                $insert["identifier"] = 0;
                $insert["sequence"] = $sequence;
                $insert["language"] = BackendLanguage::getWorkingLanguage();
                $insert["title"] = "";
                $insert["linktype"] = 0;
                //--Add record to db
                return BackendModel::getContainer()->get('database')->insert("media_modules", $insert);
            }
        }
        return false;
    }
Example #13
0
ATTENTION: The trailing slash is required.
*/
$baseDir = $kernel->getContainer()->getParameter('site.path_www') . $baseUrl;
/*
 * ### Advanced Settings
 */
/*
Thumbnails : thumbnails settings. All thumbnails will end up in the same
directory, no matter the resource type.
*/
$config['Thumbnails'] = array('url' => $baseUrl . '_thumbs', 'directory' => $baseDir . '_thumbs', 'enabled' => true, 'directAccess' => true, 'maxWidth' => 96, 'maxHeight' => 96, 'bmpSupported' => false, 'quality' => 100);
/*
Set the maximum size of uploaded images. If an uploaded image is larger, it
gets scaled down proportionally. Set to 0 to disable this feature.
*/
$config['Images'] = array('maxWidth' => BackendModel::get('fork.settings')->get('Core', 'ckfinder_image_max_width'), 'maxHeight' => BackendModel::get('fork.settings')->get('Core', 'ckfinder_image_max_height'), 'quality' => 100);
/*
RoleSessionVar : the session variable name that CKFinder must use to retrieve
the "role" of the current user. The "role", can be used in the "AccessControl"
settings (bellow in this page).

To be able to use this feature, you must initialize the session data by
uncommenting the following "session_start()" call.
*/
$config['RoleSessionVar'] = 'CKFinder_UserRole';
//session_start();
/*
AccessControl : used to restrict access or features to specific folders.

Many "AccessControl" entries can be added. All attributes are optional.
Subfolders inherit their default settings from their parents' definitions.
Example #14
0
 /**
  * Logout the current user
  */
 public static function logout()
 {
     // remove all rows owned by the current user
     BackendModel::get('database')->delete('users_sessions', 'session_id = ?', \SpoonSession::getSessionId());
     // reset values. We can't destroy the session because session-data can be used on the site.
     \SpoonSession::set('backend_logged_in', false);
     \SpoonSession::set('backend_secret_key', '');
     \SpoonSession::set('csrf_token', '');
 }
 /**
  * Get the access token from the settings
  *
  * @return String Access token
  */
 private static function getAccessToken()
 {
     return BackendModel::get('fork.settings')->get('Instagram', 'access_token');
 }
Example #16
0
 /**
  * Add a Microsoft device to a user.
  *
  * @param string $uri   The uri of the channel opened for the device.
  * @param string $email The emailaddress for the user to link the device to.
  */
 public static function microsoftAddDevice($uri, $email)
 {
     if (BaseAPI::isAuthorized()) {
         // redefine
         $uri = (string) $uri;
         // validate
         if ($uri == '') {
             BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No uri-parameter provided.'));
         }
         if ($email == '') {
             BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No email-parameter provided.'));
         }
         // we should tell the ForkAPI that we registered a device
         $publicKey = Model::get('fork.settings')->get('Core', 'fork_api_public_key', '');
         $privateKey = Model::get('fork.settings')->get('Core', 'fork_api_private_key', '');
         // validate keys
         if ($publicKey == '' || $privateKey == '') {
             BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'Invalid key for the Fork API, configure them in the backend.'));
         }
         try {
             // load user
             $user = new User(null, $email);
             // get current uris
             $uris = (array) $user->getSetting('microsoft_channel_uri');
             // not already in array?
             if (!in_array($uri, $uris)) {
                 $uris[] = $uri;
             }
             // require the class
             require_once PATH_LIBRARY . '/external/fork_api.php';
             // create instance
             $forkAPI = new \ForkAPI($publicKey, $privateKey);
             // make the call
             $forkAPI->microsoftRegisterDevice($uris);
             // store
             if (!empty($uris)) {
                 $user->setSetting('microsoft_channel_uri', $uris);
             }
         } catch (Exception $e) {
             BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Can\'t authenticate you.'));
         }
     }
 }
Example #17
0
 /**
  * Process the module's information XML and return an array with the information.
  *
  * @param \SimpleXMLElement $xml
  *
  * @return array
  */
 public static function processModuleXml(\SimpleXMLElement $xml)
 {
     $information = array();
     // fetch theme node
     $module = $xml->xpath('/module');
     if (isset($module[0])) {
         $module = $module[0];
     }
     // fetch general module info
     $information['name'] = (string) $module->name;
     $information['version'] = (string) $module->version;
     $information['requirements'] = (array) $module->requirements;
     $information['description'] = (string) $module->description;
     $information['cronjobs'] = array();
     // authors
     foreach ($xml->xpath('/module/authors/author') as $author) {
         $information['authors'][] = (array) $author;
     }
     // cronjobs
     foreach ($xml->xpath('/module/cronjobs/cronjob') as $cronjob) {
         $attributes = $cronjob->attributes();
         if (!isset($attributes['action'])) {
             continue;
         }
         // build cronjob information
         $item = array();
         $item['minute'] = isset($attributes['minute']) ? $attributes['minute'] : '*';
         $item['hour'] = isset($attributes['hour']) ? $attributes['hour'] : '*';
         $item['day-of-month'] = isset($attributes['day-of-month']) ? $attributes['day-of-month'] : '*';
         $item['month'] = isset($attributes['month']) ? $attributes['month'] : '*';
         $item['day-of-week'] = isset($attributes['day-of-week']) ? $attributes['day-of-week'] : '*';
         $item['action'] = $attributes['action'];
         $item['description'] = $cronjob[0];
         // check if cronjob has already been run
         $cronjobs = (array) BackendModel::get('fork.settings')->get('Core', 'cronjobs');
         $item['active'] = in_array($information['name'] . '.' . $attributes['action'], $cronjobs);
         $information['cronjobs'][] = $item;
     }
     // events
     foreach ($xml->xpath('/module/events/event') as $event) {
         $attributes = $event->attributes();
         // build event information and add it to the list
         $information['events'][] = array('application' => isset($attributes['application']) ? $attributes['application'] : '', 'name' => isset($attributes['name']) ? $attributes['name'] : '', 'description' => $event[0]);
     }
     return $information;
 }
Example #18
0
 /**
  * Parse some vars
  */
 private function parseVars()
 {
     // assign a placeholder var
     $this->assign('var', '');
     // assign current timestamp
     $this->assign('timestamp', time());
     // check on url object
     if (Model::getContainer()->has('url')) {
         $url = Model::get('url');
         if ($url instanceof Url) {
             $this->assign('bodyID', \SpoonFilter::toCamelCase($url->getModule(), '_', true));
             // build classes
             $bodyClass = \SpoonFilter::toCamelCase($url->getModule() . '_' . $url->getAction(), '_', true);
             // special occasions
             if ($url->getAction() == 'add' || $url->getAction() == 'edit') {
                 $bodyClass = $url->getModule() . 'AddEdit';
             }
             // assign
             $this->assign('bodyClass', $bodyClass);
         }
     }
     if (Model::has('navigation')) {
         $navigation = Model::get('navigation');
         if ($navigation instanceof Navigation) {
             $navigation->parse($this);
         }
     }
     foreach ($this->forms as $form) {
         if ($form->isSubmitted() && !$form->isCorrect()) {
             $this->assign('form_error', true);
             break;
         }
     }
     $this->assign('cookies', Model::get('request')->cookies->all());
 }
Example #19
0
 /**
  * Returns the CampaignMonitor object.
  *
  * @return \CampaignMonitor
  */
 public static function getCM()
 {
     // campaignmonitor reference exists
     if (!BackendModel::getContainer()->has('campaignmonitor')) {
         // check if the CampaignMonitor class exists
         if (!is_file(PATH_LIBRARY . '/external/campaignmonitor.php')) {
             // the class doesn't exist, so throw an exception
             throw new BackendException(BL::err('ClassDoesNotExist', 'Mailmotor'));
         }
         // require CampaignMonitor class
         require_once PATH_LIBRARY . '/external/campaignmonitor.php';
         // set login data
         $url = BackendModel::get('fork.settings')->get('Mailmotor', 'cm_url');
         $username = BackendModel::get('fork.settings')->get('Mailmotor', 'cm_username');
         $password = BackendModel::get('fork.settings')->get('Mailmotor', 'cm_password');
         // init CampaignMonitor object
         $cm = new \CampaignMonitor($url, $username, $password, 60, self::getClientId());
         // set CampaignMonitor object reference
         BackendModel::getContainer()->set('campaignmonitor', $cm);
     }
     return BackendModel::getContainer()->get('campaignmonitor');
 }
Example #20
0
 /**
  * Build the language files
  *
  * @param string $language    The language to build the locale-file for.
  * @param string $application The application to build the locale-file for.
  */
 public static function buildCache($language, $application)
 {
     $cacheBuilder = new CacheBuilder(BackendModel::get('database'));
     $cacheBuilder->buildCache($language, $application);
 }
Example #21
0
 /**
  * Update a page
  *
  * @param array $page The new data for the page.
  *
  * @return int
  */
 public static function update(array $page)
 {
     // get db
     $db = BackendModel::getContainer()->get('database');
     // update old revisions
     if ($page['status'] != 'draft') {
         $db->update('pages', array('status' => 'archive'), 'id = ? AND language = ?', array((int) $page['id'], $page['language']));
     } else {
         $db->delete('pages', 'id = ? AND user_id = ? AND status = ? AND language = ?', array((int) $page['id'], BackendAuthentication::getUser()->getUserId(), 'draft', $page['language']));
     }
     // insert
     $page['revision_id'] = (int) $db->insert('pages', $page);
     // how many revisions should we keep
     $rowsToKeep = (int) BackendModel::get('fork.settings')->get('Pages', 'max_num_revisions', 20);
     // get revision-ids for items to keep
     $revisionIdsToKeep = (array) $db->getColumn('SELECT i.revision_id
          FROM pages AS i
          WHERE i.id = ? AND i.status = ?
          ORDER BY i.edited_on DESC
          LIMIT ?', array((int) $page['id'], 'archive', $rowsToKeep));
     // delete other revisions
     if (!empty($revisionIdsToKeep)) {
         // because blocks are linked by revision we should get all revisions we want to delete
         $revisionsToDelete = (array) $db->getColumn('SELECT i.revision_id
              FROM pages AS i
              WHERE i.id = ? AND i.status = ? AND i.revision_id NOT IN(' . implode(', ', $revisionIdsToKeep) . ')', array((int) $page['id'], 'archive'));
         // any revisions to delete
         if (!empty($revisionsToDelete)) {
             $db->delete('pages', 'revision_id IN(' . implode(', ', $revisionsToDelete) . ')');
             $db->delete('pages_blocks', 'revision_id IN(' . implode(', ', $revisionsToDelete) . ')');
         }
     }
     // return the new revision id
     return $page['revision_id'];
 }
Example #22
0
 /**
  * Generate an url, using the predefined callback.
  *
  * @param string $url The base-url to start from.
  *
  * @throws Exception When the function does not exist
  *
  * @return string
  *
  * @deprecated use the generateUrl method on the meta repository
  */
 public function generateURL($url)
 {
     return Model::get('fork.repository.meta')->generateURL($url, $this->callback['class'], $this->callback['method'], $this->callback['parameters']);
 }
Example #23
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         $fields = $this->frm->getFields();
         // email is present
         if (!$this->user->isGod()) {
             if ($fields['email']->isFilled(BL::err('EmailIsRequired'))) {
                 // is this an email-address
                 if ($fields['email']->isEmail(BL::err('EmailIsInvalid'))) {
                     // was this emailaddress deleted before
                     if (BackendUsersModel::emailDeletedBefore($fields['email']->getValue())) {
                         $fields['email']->addError(sprintf(BL::err('EmailWasDeletedBefore'), BackendModel::createURLForAction('UndoDelete', null, null, array('email' => $fields['email']->getValue()))));
                     } elseif (BackendUsersModel::existsEmail($fields['email']->getValue(), $this->id)) {
                         // email already exists
                         $fields['email']->addError(BL::err('EmailAlreadyExists'));
                     }
                 }
             }
         }
         // required fields
         if ($this->user->isGod() && $fields['email']->getValue() != '' && $this->user->getEmail() != $fields['email']->getValue()) {
             $fields['email']->addError(BL::err('CantChangeGodsEmail'));
         }
         if (!$this->user->isGod()) {
             $fields['email']->isEmail(BL::err('EmailIsInvalid'));
         }
         $fields['nickname']->isFilled(BL::err('NicknameIsRequired'));
         $fields['name']->isFilled(BL::err('NameIsRequired'));
         $fields['surname']->isFilled(BL::err('SurnameIsRequired'));
         $fields['interface_language']->isFilled(BL::err('FieldIsRequired'));
         $fields['date_format']->isFilled(BL::err('FieldIsRequired'));
         $fields['time_format']->isFilled(BL::err('FieldIsRequired'));
         $fields['number_format']->isFilled(BL::err('FieldIsRequired'));
         if ($this->allowUserRights) {
             $fields['groups']->isFilled(BL::err('FieldIsRequired'));
         }
         if (isset($fields['new_password']) && $fields['new_password']->isFilled()) {
             if ($fields['new_password']->getValue() !== $fields['confirm_password']->getValue()) {
                 $fields['confirm_password']->addError(BL::err('ValuesDontMatch'));
             }
         }
         // validate avatar
         if ($fields['avatar']->isFilled()) {
             // correct extension
             if ($fields['avatar']->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) {
                 // correct mimetype?
                 $fields['avatar']->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build user-array
             $user['id'] = $this->id;
             if (!$this->user->isGod()) {
                 $user['email'] = $fields['email']->getValue(true);
             }
             if ($this->authenticatedUser->getUserId() != $this->record['id']) {
                 $user['active'] = $fields['active']->isChecked() ? 'Y' : 'N';
             }
             // user is now de-activated, we now remove all sessions for this user so he is logged out immediately
             if (isset($user['active']) && $user['active'] === 'N' && $this->record['active'] !== $user['active']) {
                 // delete all sessions for user
                 BackendModel::get('database')->delete('users_sessions', 'user_id = ?', array($this->user->getUserId()));
             }
             // build settings-array
             $settings['nickname'] = $fields['nickname']->getValue();
             $settings['name'] = $fields['name']->getValue();
             $settings['surname'] = $fields['surname']->getValue();
             $settings['interface_language'] = $fields['interface_language']->getValue();
             $settings['date_format'] = $fields['date_format']->getValue();
             $settings['time_format'] = $fields['time_format']->getValue();
             $settings['datetime_format'] = $settings['date_format'] . ' ' . $settings['time_format'];
             $settings['number_format'] = $fields['number_format']->getValue();
             $settings['csv_split_character'] = $fields['csv_split_character']->getValue();
             $settings['csv_line_ending'] = $fields['csv_line_ending']->getValue();
             $settings['api_access'] = $this->allowUserRights ? (bool) $fields['api_access']->getChecked() : $this->record['settings']['api_access'];
             // update password (only if filled in)
             if (isset($fields['new_password']) && $fields['new_password']->isFilled()) {
                 $user['password'] = BackendAuthentication::getEncryptedString($fields['new_password']->getValue(), $this->record['settings']['password_key']);
                 // the password has changed
                 if ($this->record['password'] != $user['password']) {
                     // save the login timestamp in the user's settings
                     $lastPasswordChange = BackendUsersModel::getSetting($user['id'], 'current_password_change');
                     $settings['current_password_change'] = time();
                     if ($lastPasswordChange) {
                         $settings['last_password_change'] = $lastPasswordChange;
                     }
                     // save the password strength
                     $passwordStrength = BackendAuthentication::checkPassword($fields['new_password']->getValue());
                     $settings['password_strength'] = $passwordStrength;
                 }
             }
             // get user groups when allowed to edit
             if ($this->allowUserRights) {
                 // get selected groups
                 $groups = $fields['groups']->getChecked();
                 // init var
                 $newSequence = BackendGroupsModel::getSetting($groups[0], 'dashboard_sequence');
                 // loop through groups and collect all dashboard widget sequences
                 foreach ($groups as $group) {
                     $sequences[] = BackendGroupsModel::getSetting($group, 'dashboard_sequence');
                 }
                 // loop through sequences
                 foreach ($sequences as $sequence) {
                     // loop through modules inside a sequence
                     foreach ($sequence as $moduleKey => $module) {
                         // loop through widgets inside a module
                         foreach ($module as $widgetKey => $widget) {
                             // if widget present set true
                             if ($widget['present']) {
                                 $newSequence[$moduleKey][$widgetKey]['present'] = true;
                             }
                         }
                     }
                 }
                 // add new sequence to settings
                 $settings['dashboard_sequence'] = $newSequence;
             }
             // has the user submitted an avatar?
             if ($fields['avatar']->isFilled()) {
                 // init vars
                 $avatarsPath = FRONTEND_FILES_PATH . '/backend_users/avatars';
                 // delete old avatar if it isn't the default-image
                 if ($this->record['settings']['avatar'] != 'no-avatar.jpg' && $this->record['settings']['avatar'] != '') {
                     $fs = new Filesystem();
                     $fs->remove($avatarsPath . '/source/' . $this->record['settings']['avatar']);
                     $fs->remove($avatarsPath . '/128x128/' . $this->record['settings']['avatar']);
                     $fs->remove($avatarsPath . '/64x64/' . $this->record['settings']['avatar']);
                     $fs->remove($avatarsPath . '/32x32/' . $this->record['settings']['avatar']);
                 }
                 // create new filename
                 $filename = rand(0, 3) . '_' . $user['id'] . '.' . $fields['avatar']->getExtension();
                 // add into settings to update
                 $settings['avatar'] = $filename;
                 // resize (128x128)
                 $fields['avatar']->createThumbnail($avatarsPath . '/128x128/' . $filename, 128, 128, true, false, 100);
                 // resize (64x64)
                 $fields['avatar']->createThumbnail($avatarsPath . '/64x64/' . $filename, 64, 64, true, false, 100);
                 // resize (32x32)
                 $fields['avatar']->createThumbnail($avatarsPath . '/32x32/' . $filename, 32, 32, true, false, 100);
             }
             // save changes
             BackendUsersModel::update($user, $settings);
             // save groups
             if ($this->allowUserRights) {
                 BackendGroupsModel::insertMultipleGroups($this->id, $groups);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $user));
             // can only edit own profile
             if (!BackendAuthentication::isAllowedAction('Index')) {
                 // everything is saved, so redirect to the edit page
                 $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $this->id . '&report=edited&var=' . $settings['nickname']);
             } else {
                 // everything is saved, so redirect to the overview
                 $this->redirect(BackendModel::createURLForAction('Index') . '&report=edited&var=' . $settings['nickname'] . '&highlight=row-' . $user['id']);
             }
         }
     }
 }
Example #24
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         // validate the image
         if ($this->frm->getField('image')->isFilled()) {
             // image extension and mime type
             $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
         }
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['company'] = $fields['company']->getValue();
             $item['name'] = $fields['name']->getValue();
             $item['firstname'] = $fields['firstname']->getValue();
             $item['email'] = $fields['email']->getValue();
             $item['address'] = $fields['address']->getValue();
             $item['zipcode'] = $fields['zipcode']->getValue();
             $item['city'] = $fields['city']->getValue();
             $item['country'] = $fields['country']->getValue();
             $item['phone'] = $fields['phone']->getValue();
             $item['fax'] = $fields['fax']->getValue();
             $item['website'] = str_replace("http://", "", $fields['website']->getValue());
             $item['text'] = $fields['text']->getValue();
             $item['zipcodes'] = $fields['zipcodes']->getValue();
             $item['remark'] = $fields['remark']->getValue();
             //$item['assort'] = $fields['assort']->getValue();
             //$item['open'] = $fields['open']->getValue();
             //$item['closed'] = $fields['closed']->getValue();
             //$item['visit'] = $fields['visit']->getValue();
             //$item['size'] = $fields['size']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['hidden'] = $fields['hidden']->getValue();
             if ($item['country'] == '') {
                 $item['country'] = 'BE';
             }
             //--Create url
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             //--Get lat
             $geocode = json_decode(\SpoonHTTP::getContent($url));
             //--Sleep between the requests
             sleep(0.05);
             //--Check result
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                 \SpoonDirectory::create($imagePath . '/Source');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                 \SpoonDirectory::create($imagePath . '/400x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             // image provided?
             if ($this->frm->getField('image')->isFilled()) {
                 // build the image name
                 $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             }
             $item['id'] = BackendAddressesModel::insert($item);
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue();
                 BackendAddressesModel::insertLanguage($itemLanguage);
             }
             if (isset($fields["groups"])) {
                 //--Get all the groups
                 $groups = $fields["groups"]->getValue();
                 foreach ($groups as $value) {
                     $groupAddress = array();
                     $groupAddress["address_id"] = $item['id'];
                     $groupAddress["group_id"] = $value;
                     //--Add user to the group
                     BackendAddressesModel::insertAddressToGroup($groupAddress);
                 }
             }
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name']));
             BackendModel::triggerEvent($this->getModule(), 'after_add', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
Example #25
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         // required fields
         $fields['category_id']->isFilled(BL::err('FieldIsRequired'));
         if ($fields['category_id']->getValue() == 'no_category') {
             $fields['category_id']->addError(BL::err('FieldIsRequired'));
         }
         // validate meta
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build the item
             $item['language'] = BL::getWorkingLanguage();
             $item['price'] = $fields['price']->getValue();
             $item['summary'] = $fields['summary_nl']->getValue();
             $item['text'] = $fields['text_nl']->getValue();
             $item['allow_comments'] = $fields['allow_comments']->getChecked() ? 'Y' : 'N';
             $item['num_comments'] = 0;
             $item['sequence'] = BackendCatalogModel::getMaximumSequence() + 1;
             $item['category_id'] = $fields['category_id']->getValue();
             $item['brand_id'] = $fields['brand_id']->getValue();
             $item['meta_id'] = $this->meta->save();
             $item['ballcolor'] = $fields['ballcolor']->getValue();
             $item['frontpage'] = $fields['frontpage']->getChecked();
             $item['contact'] = $fields['contact']->getChecked();
             // insert it
             $item['id'] = BackendCatalogModel::insert($item);
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue();
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), null, $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::insertLanguage($itemLanguage);
             }
             $specificationArray = array();
             // loop trough specifications and insert values
             foreach ($this->specifications as $specification) {
                 // build the specification
                 $specificationArray['product_id'] = $item['id'];
                 $specificationArray['specification_id'] = $specification['id'];
                 foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                     $field = 'specification' . $specification['id'] . '_' . $language;
                     // check if there is an value
                     if ($fields[$field]->getValue() != null) {
                         $specificationArray['value'] = $fields[$field]->getValue();
                         $specificationArray['language'] = $language;
                         // insert specification with product id and value
                         BackendCatalogModel::insertSpecificationValue($specificationArray);
                     }
                 }
             }
             // save the tags
             BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule());
             // save the related products
             BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue());
             // add search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $this->frm->getField('title_nl')->getValue(), 'summary' => $this->frm->getField('summary_nl')->getValue(), 'text' => $this->frm->getField('text_nl')->getValue()));
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', $item);
             // redirect page
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
Example #26
0
 /**
  * Update an existing item.
  *
  * @param array $item The new data.
  * @return int
  */
 public static function update(array $item)
 {
     $db = BackendModel::getContainer()->get('database');
     // update extra
     BackendModel::updateExtra($item['extra_id'], 'data', array('id' => $item['id'], 'extra_label' => $item['title'], 'language' => $item['language'], 'edit_url' => BackendModel::createURLForAction('Edit') . '&id=' . $item['id']));
     // archive all older content_block versions
     $db->update('content_blocks', array('status' => 'archived'), 'id = ? AND language = ?', array($item['id'], BL::getWorkingLanguage()));
     // insert new version
     $item['revision_id'] = $db->insert('content_blocks', $item);
     // how many revisions should we keep
     $rowsToKeep = (int) BackendModel::get('fork.settings')->get('ContentBlocks', 'max_num_revisions', 20);
     // get revision-ids for items to keep
     $revisionIdsToKeep = (array) $db->getColumn('SELECT i.revision_id
          FROM content_blocks AS i
          WHERE i.id = ? AND i.language = ? AND i.status = ?
          ORDER BY i.edited_on DESC
          LIMIT ?', array($item['id'], BL::getWorkingLanguage(), 'archived', $rowsToKeep));
     // delete other revisions
     if (!empty($revisionIdsToKeep)) {
         $db->delete('content_blocks', 'id = ? AND language = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], BL::getWorkingLanguage(), 'archived'));
     }
     // return the new revision_id
     return $item['revision_id'];
 }
Example #27
0
 /**
  * Update an existing item
  *
  * @param array $item The new data.
  *
  * @return int
  */
 public static function update(array $item)
 {
     $db = BackendModel::getContainer()->get('database');
     // check if new version is active
     if ($item['status'] == 'active') {
         // archive all older active versions
         $db->update('blog_posts', array('status' => 'archived'), 'id = ? AND status = ?', array($item['id'], $item['status']));
         // get the record of the exact item we're editing
         $revision = self::getRevision($item['id'], $item['revision_id']);
         // assign values
         $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $revision['created_on']);
         $item['num_comments'] = $revision['num_comments'];
         // if it used to be a draft that we're now publishing, remove drafts
         if ($revision['status'] == 'draft') {
             $db->delete('blog_posts', 'id = ? AND status = ?', array($item['id'], $revision['status']));
         }
     }
     // don't want revision id
     unset($item['revision_id']);
     // how many revisions should we keep
     $rowsToKeep = (int) BackendModel::get('fork.settings')->get('Blog', 'max_num_revisions', 20);
     // set type of archive
     $archiveType = $item['status'] == 'active' ? 'archived' : $item['status'];
     // get revision-ids for items to keep
     $revisionIdsToKeep = (array) $db->getColumn('SELECT i.revision_id
          FROM blog_posts AS i
          WHERE i.id = ? AND i.status = ? AND i.language = ?
          ORDER BY i.edited_on DESC
          LIMIT ?', array($item['id'], $archiveType, BL::getWorkingLanguage(), $rowsToKeep));
     // delete other revisions
     if (!empty($revisionIdsToKeep)) {
         // get meta-ids that will be deleted
         $metasIdsToRemove = (array) $db->getColumn('SELECT i.meta_id
              FROM blog_posts AS i
              WHERE i.id = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id']));
         // get all the images of the revisions that will NOT be deleted
         $imagesToKeep = $db->getColumn('SELECT image FROM blog_posts
              WHERE id = ? AND revision_id IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id']));
         // get the images of the revisions that will be deleted
         $imagesOfDeletedRevisions = $db->getColumn('SELECT image FROM blog_posts
             WHERE id = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], $archiveType));
         // make sure that an image that will be deleted, is not used by a revision that is not to be deleted
         foreach ($imagesOfDeletedRevisions as $imageOfDeletedRevision) {
             if (!in_array($imageOfDeletedRevision, $imagesToKeep)) {
                 BackendModel::deleteThumbnails(FRONTEND_FILES_PATH . '/blog/images', $imageOfDeletedRevision);
             }
         }
         $db->delete('blog_posts', 'id = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], $archiveType));
         if (!empty($metasIdsToRemove)) {
             $db->delete('meta', 'id IN (' . implode(', ', $metasIdsToRemove) . ')');
         }
     }
     // insert new version
     $item['revision_id'] = BackendModel::getContainer()->get('database')->insert('blog_posts', $item);
     // return the new revision id
     return $item['revision_id'];
 }
Example #28
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         //            $fields['title']->isFilled(BL::err('FieldIsRequired'));
         //            $fields['summary']->isFilled(BL::err('FieldIsRequired'));
         $fields['category_id']->isFilled(BL::err('FieldIsRequired'));
         if ($fields['category_id']->getValue() == 'no_category') {
             $fields['category_id']->addError(BL::err('FieldIsRequired'));
         }
         // validate meta
         $this->meta->validate();
         //--Validate Media
         $this->media->validate();
         if ($this->frm->isCorrect()) {
             $item['id'] = $this->id;
             $item['language'] = BL::getWorkingLanguage();
             $item['price'] = $fields['price']->getValue();
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['brand_id'] = $fields['brand_id']->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['frontpage'] = $this->frm->getField('frontpage')->getChecked();
             $item['contact'] = $this->frm->getField('contact')->getChecked();
             $item['meta_id'] = $this->meta->save();
             $item['ballcolor'] = $fields['ballcolor']->getValue();
             BackendCatalogModel::update($item);
             $item['id'] = $this->id;
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue();
                 $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), $item['id'], $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::updateLanguage($itemLanguage, $language);
             }
             $specificationArray = array();
             // loop trough specifications and insert values
             foreach ($this->specifications as $specification) {
                 foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                     $field = 'specification' . $specification['id'] . '_' . $language;
                     $specificationArray['value'] = $fields[$field]->getValue();
                     $specificationArray['language'] = $language;
                     $specificationArray['product_id'] = $item['id'];
                     $specificationArray['specification_id'] = $specification['id'];
                     // when specification value already exists. update value
                     if (BackendCatalogModel::existsSpecificationValue($item['id'], $specification['id'], $language) != false) {
                         // update specification with product id and value
                         BackendCatalogModel::updateSpecificationValue($specification['id'], $item['id'], $language, $specificationArray);
                     } else {
                         // when specification value doesnt exists, insert new value
                         BackendCatalogModel::insertSpecificationValue($specificationArray);
                     }
                 }
             }
             // save the tags
             BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule());
             // add search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $this->frm->getField('title_nl')->getValue(), 'summary' => $this->frm->getField('summary_nl')->getValue(), 'text' => $this->frm->getField('text_nl')->getValue()));
             // save related projects
             BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue(), $this->relatedProducts);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Example #29
0
 /**
  * @param int $userId
  */
 private function loadGroups($userId)
 {
     $this->groups = (array) BackendModel::get('database')->getColumn('SELECT group_id
          FROM users_groups
          WHERE user_id = ?', array((int) $userId));
 }
Example #30
0
 /**
  * Get avatar
  *
  * @param int    $id    The id for the profile we want to get the avatar from.
  * @param string $email The email from the user we can use for gravatar.
  * @return string $avatar            The absolute path to the avatar.
  */
 public static function getAvatar($id, $email = null)
 {
     // redefine id
     $id = (int) $id;
     // return avatar from cache
     if (isset(self::$avatars[$id])) {
         return self::$avatars[$id];
     }
     // define avatar path
     $avatarPath = FRONTEND_FILES_URL . '/Profiles/Avatars/32x32/';
     // get avatar for profile
     $avatar = self::getSetting($id, 'avatar');
     // if no email is given
     if (!$email) {
         // get user
         $user = self::get($id);
         // redefine email
         $email = $user['email'];
     }
     // no custom avatar defined, get gravatar if allowed
     if (empty($avatar) && BackendModel::get('fork.settings')->get('Profiles', 'allow_gravatar', true)) {
         // define hash
         $hash = md5(strtolower(trim('d' . $email)));
         // define avatar url
         $avatar = 'http://www.gravatar.com/avatar/' . $hash;
         // when email not exists, it has to show our custom no-avatar image
         $avatar .= '?d=' . SITE_URL . $avatarPath . 'no-avatar.gif';
     } elseif (empty($avatar)) {
         // define avatar as not found
         $avatar = SITE_URL . $avatarPath . 'no-avatar.gif';
     } else {
         // define custom avatar path
         $avatar = $avatarPath . $avatar;
     }
     // set avatar in cache
     self::$avatars[$id] = $avatar;
     // return avatar image path
     return $avatar;
 }