/**
  * Loads the settings form
  */
 private function loadForm()
 {
     $this->frm = new BackendForm('settings');
     $this->frm->addCheckbox('enabled', BackendModel::getModuleSetting($this->URL->getModule(), 'enabled', false));
     $this->frm->addCheckbox('log', BackendModel::getModuleSetting($this->URL->getModule(), 'log', true));
     $this->frm->addCheckbox('add_data', BackendModel::getModuleSetting($this->URL->getModule(), 'add_data', true));
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // Get api key
     $this->apiKey = BackendModel::getModuleSetting($this->getModule(), 'api_key', null);
     // Get uncompressed images list
     $this->images = BackendCompressionModel::getImagesFromFolders();
     if (!empty($this->images)) {
         // Compress each image from each folder
         $output = 'Compressing ' . count($this->images) . ' images...' . "<br />\r\n";
         BackendCompressionModel::writeToCacheFile($output, true);
         foreach ($this->images as $image) {
             $tinyPNGApi = new TinyPNGApi($this->apiKey);
             // Shrink the image and check if succesful
             if ($tinyPNGApi->shrink($image['full_path'])) {
                 // Check if the file was successfully downloaded.
                 if ($tinyPNGApi->download($image['full_path'])) {
                     $output = 'Compression succesful for image ' . $image['filename'] . '. Saved ' . number_format($tinyPNGApi->getSavingSize() / 1024, 2) . ' KB' . ' bytes. (' . $tinyPNGApi->getSavingPercentage() . '%)';
                     BackendCompressionModel::writeToCacheFile($output);
                     // Save to db
                     $imageInfo = array('filename' => $image['filename'], 'path' => $image['full_path'], 'original_size' => $tinyPNGApi->getInputSize(), 'compressed_size' => $tinyPNGApi->getOutputSize(), 'saved_bytes' => $tinyPNGApi->getSavingSize(), 'saved_percentage' => $tinyPNGApi->getSavingPercentage(), 'checksum_hash' => sha1_file($image['full_path']), 'compressed_on' => BackendModel::getUTCDate());
                     BackendCompressionModel::insertImageHistory($imageInfo, $image['file_compressed_before']);
                 }
             } else {
                 BackendCompressionModel::writeToCacheFile($tinyPNGApi->getErrorMessage());
             }
         }
         BackendCompressionModel::writeToCacheFile("...Done!");
     } else {
         BackendCompressionModel::writeToCacheFile('There are no images that can be compressed.', true);
     }
     // Print the output for debug purposes
     $output = BackendCompressionModel::readCacheFile();
     print $output;
 }
Example #3
0
 /**
  * Load the form
  */
 protected function loadForm()
 {
     // create form
     $this->frm = new BackendForm('settings');
     // get categories
     $groups = BackendMailengineModel::getAllGroupsForDropdown();
     $groups = array("0" => "") + $groups;
     // multiple categories?
     $default_group = BackendModel::getModuleSetting($this->URL->getModule(), 'default_group');
     $default_group = $default_group > 0 ? $default_group : 0;
     // create element
     $this->frm->addDropdown('default_group', $groups, BackendModel::getModuleSetting($this->URL->getModule(), 'default_group'));
 }
 /**
  * Get the api key
  */
 private function getCompressionParameters()
 {
     $remove = $this->getParameter('remove');
     // something has to be removed before proceeding
     if (!empty($remove)) {
         // the session token has te be removed
         if ($remove == 'api_key') {
             BackendModel::setModuleSetting($this->getModule(), 'api_key', null);
         }
         // account was deleted, so redirect
         $this->redirect(BackendModel::createURLForAction('Settings') . '&report=deleted');
     }
     $this->apiKey = BackendModel::getModuleSetting($this->getModule(), 'api_key', null);
 }
Example #5
0
 /**
  * Loads the settings form
  */
 private function loadForm()
 {
     // init settings form
     $this->frm = new BackendForm('settings');
     // add fields for pagination
     $this->frm->addDropdown('overview_number_of_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'overview_num_items', 10));
     $this->frm->addDropdown('recent_products_full_number_of_items', array_combine(range(1, 10), range(1, 10)), BackendModel::getModuleSetting($this->URL->getModule(), 'recent_products_full_num_items', 5));
     //$this->frm->addDropdown('recent_products_list_number_of_items', array_combine(range(1, 10), range(1, 10)), BackendModel::getModuleSetting($this->URL->getModule(), 'recent_articles_list_num_items', 5));
     // add fields for spam
     $this->frm->addCheckbox('spamfilter', BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false));
     // no Akismet-key, so we can't enable spam-filter
     if (BackendModel::getModuleSetting('core', 'akismet_key') == '') {
         $this->frm->getField('spamfilter')->setAttribute('disabled', 'disabled');
         $this->tpl->assign('noAkismetKey', true);
     }
     // add fields for comments
     $this->frm->addCheckbox('allow_comments', BackendModel::getModuleSetting($this->URL->getModule(), 'allow_comments', false));
     $this->frm->addCheckbox('moderation', BackendModel::getModuleSetting($this->URL->getModule(), 'moderation', false));
     // add fields for notifications
     $this->frm->addCheckbox('notify_by_email_on_new_comment_to_moderate', BackendModel::getModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment_to_moderate', false));
     $this->frm->addCheckbox('notify_by_email_on_new_comment', BackendModel::getModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment', false));
     // add fields for images
     $this->frm->addText('width1', BackendModel::getModuleSetting($this->URL->getModule(), 'width1', false));
     $this->frm->addText('height1', BackendModel::getModuleSetting($this->URL->getModule(), 'height1', false));
     $this->frm->addCheckbox('allow_enlargment1', BackendModel::getModuleSetting($this->URL->getModule(), 'allow_enlargment1', false));
     $this->frm->addCheckbox('force_aspect_ratio1', BackendModel::getModuleSetting($this->URL->getModule(), 'force_aspect_ratio1', false));
     $this->frm->addText('width2', BackendModel::getModuleSetting($this->URL->getModule(), 'width2', false));
     $this->frm->addText('height2', BackendModel::getModuleSetting($this->URL->getModule(), 'height2', false));
     $this->frm->addCheckbox('allow_enlargment2', BackendModel::getModuleSetting($this->URL->getModule(), 'allow_enlargment2', false));
     $this->frm->addCheckbox('force_aspect_ratio2', BackendModel::getModuleSetting($this->URL->getModule(), 'force_aspect_ratio2', false));
     $this->frm->addText('width3', BackendModel::getModuleSetting($this->URL->getModule(), 'width3', false));
     $this->frm->addText('height3', BackendModel::getModuleSetting($this->URL->getModule(), 'height3', false));
     $this->frm->addCheckbox('allow_enlargment3', BackendModel::getModuleSetting($this->URL->getModule(), 'allow_enlargment3', false));
     $this->frm->addCheckbox('force_aspect_ratio3', BackendModel::getModuleSetting($this->URL->getModule(), 'force_aspect_ratio3', false));
     $this->frm->addCheckbox('allow_multiple_categories', BackendModel::getModuleSetting($this->URL->getModule(), 'allow_multiple_categories', false));
 }
Example #6
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the mailings which are ready to send
     $mails = BackendMailengineModel::getWaitingMailings();
     if (!empty($mails)) {
         //--Loop the mails
         foreach ($mails as $mail) {
             //--Get mailer-email to send the mail to
             $arrFrom = BackendModel::getModuleSetting('Core', 'mailer_from');
             //--Create variables array
             $variables = array();
             $variables['sentOn'] = time();
             $variables['dateFormatLong'] = BackendModel::getModuleSetting('Core', 'date_format_long') . " " . BackendModel::getModuleSetting('Core', 'time_format');
             $variables['subject'] = $mail['subject'];
             //--Send start mail
             /* $message = \Common\Mailer\Message::newInstance(
                    'Mailing started "' . $mail['subject'] . '"'
                )
                    ->setFrom(array($arrFrom['email'] => $arrFrom['name']))
                    ->setTo(array($arrFrom['email']))
                    ->parseHtml(
                        BACKEND_MODULES_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingStart.tpl',
                        $variables
                    )
                ;
                $this->get('mailer')->send($message);*/
             //				$this->get('mailer')->addEmail('Mailing started "' . $mail['subject'] . '"', BACKEND_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingStart.tpl', $variables, $arrFrom["email"], $arrFrom["name"]);
             //--Insert mail in stats
             $data = array();
             $data['id'] = $mail['id'];
             $data['mail_id'] = $mail['mail_id'];
             $data['domain'] = $mail['domain'];
             $data['subject'] = $mail['subject'];
             $data['text'] = $mail['text'];
             $data['start_time'] = $mail['start_time'];
             $data['end_time'] = $mail['end_time'];
             $data['from_name'] = $mail['from_name'];
             $data['from_email'] = $mail['from_email'];
             $data['reply_name'] = $mail['reply_name'];
             $data['reply_email'] = $mail['reply_email'];
             BackendMailengineModel::insertMailToStats($data);
             $mail['from_name'] = html_entity_decode($mail['from_name']);
             $mail['reply_name'] = html_entity_decode($mail['reply_name']);
             //--Update status
             BackendMailengineModel::updateStatusMailing($mail['id'], array('status' => 'busy'));
             //--Get the users for the mailing
             $users = BackendMailengineModel::getUsersForWaitingMail($mail['id']);
             if (!empty($users)) {
                 $count = 0;
                 //--Loop the users
                 foreach ($users as $user) {
                     //--Translate the text and subject with the user-vars
                     $text = BackendMailengineModel::translateUserVars($mail['text'], $user);
                     $subject = BackendMailengineModel::translateUserVars($mail['subject'], $user);
                     //--Send the mail
                     if (BackendMailengineModel::sendMail(html_entity_decode($subject), $text, $user['email'], $user['name'], $mail)) {
                         $data = array();
                         $data['send_id'] = $mail['id'];
                         $data['user_id'] = $user['id'];
                         //--Save the send-data for the mails
                         BackendMailengineModel::insertMailUsers($data);
                     }
                     //--Add count
                     $count++;
                     //--Let the script sleep for an instant after sending x-numbers of mails
                     if ($count % 50 == 0) {
                         sleep(5);
                         set_time_limit(120);
                     }
                 }
                 //--Update status
                 BackendMailengineModel::updateStatusMailing($mail['id'], array('status' => 'finished', 'end_time' => BackendModel::getUTCDate()));
                 //--Create variables array
                 $variables = array();
                 $variables['sentOn'] = time();
                 $variables['dateFormatLong'] = BackendModel::getModuleSetting('Core', 'date_format_long') . " " . BackendModel::getModuleSetting('Core', 'time_format');
                 $variables['subject'] = $mail['subject'];
                 $variables['users'] = count($users);
                 /*$message = \Common\Mailer\Message::newInstance(
                       'Mailing ended "' . $mail['subject'] . '"'
                   )
                       ->setFrom(array($arrFrom['email'] => $arrFrom['name']))
                       ->setTo(array($arrFrom['email']))
                       ->parseHtml(
                           BACKEND_MODULES_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingEnd.tpl',
                           $variables
                       )
                   ;
                   $this->get('mailer')->send($message);*/
                 //--Send start mail
                 //					$this->get('mailer')->addEmail('Mailing ended "' . $mail['subject'] . '"', BACKEND_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingEnd.tpl', $variables, $arrFrom["email"], $arrFrom["name"]);
             }
         }
     }
 }
Example #7
0
 /**
  * @param array $ids
  */
 public static function deleteImage(array $ids)
 {
     if (empty($ids)) {
         return;
     }
     foreach ($ids as $id) {
         $item = self::getImage($id);
         $product = self::get($item['product_id']);
         // delete image reference from db
         BackendModel::getContainer()->get('database')->delete('catalog_images', 'id = ?', array($id));
         // delete image from disk
         $basePath = FRONTEND_FILES_PATH . '/catalog/' . $item['product_id'];
         \SpoonFile::delete($basePath . '/source/' . $item['filename']);
         \SpoonFile::delete($basePath . '/64x64/' . $item['filename']);
         \SpoonFile::delete($basePath . '/128x128/' . $item['filename']);
         \SpoonFile::delete($basePath . '/' . BackendModel::getModuleSetting('catalog', 'width1') . 'x' . BackendModel::getModuleSetting('catalog', 'height1') . '/' . $item['filename']);
         \SpoonFile::delete($basePath . '/' . BackendModel::getModuleSetting('catalog', 'width2') . 'x' . BackendModel::getModuleSetting('catalog', 'height2') . '/' . $item['filename']);
         \SpoonFile::delete($basePath . '/' . BackendModel::getModuleSetting('catalog', 'width3') . 'x' . BackendModel::getModuleSetting('catalog', 'height3') . '/' . $item['filename']);
     }
     BackendModel::invalidateFrontendCache('slideshowCache');
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // current status
     $from = \SpoonFilter::getGetValue('from', array('published', 'moderation', 'spam'), 'published');
     // action to execute
     $action = \SpoonFilter::getGetValue('action', array('published', 'moderation', 'spam', 'delete'), 'spam');
     // no id's provided
     if (!isset($_GET['id'])) {
         $this->redirect(BackendModel::createURLForAction('comments') . '&error=no-comments-selected');
     }
     // redefine id's
     $ids = (array) $_GET['id'];
     // delete comment(s)
     if ($action == 'delete') {
         BackendCatalogModel::deleteComments($ids);
     } elseif ($action == 'spam') {
         // is the spamfilter active?
         if (BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false)) {
             // get data
             $comments = BackendCatalogModel::getComments($ids);
             // loop comments
             foreach ($comments as $row) {
                 // unserialize data
                 $row['data'] = unserialize($row['data']);
                 // check if needed data is available
                 if (!isset($row['data']['server']['REMOTE_ADDR'])) {
                     continue;
                 }
                 if (!isset($row['data']['server']['HTTP_USER_AGENT'])) {
                     continue;
                 }
                 // build vars
                 $userIp = $row['data']['server']['REMOTE_ADDR'];
                 $userAgent = $row['data']['server']['HTTP_USER_AGENT'];
                 $content = $row['text'];
                 $author = $row['author'];
                 $email = $row['email'];
                 $url = isset($row['website']) && $row['website'] != '' ? $row['website'] : null;
                 $referrer = isset($row['data']['server']['HTTP_REFERER']) ? $row['data']['server']['HTTP_REFERER'] : null;
                 $others = $row['data']['server'];
                 // submit as spam
                 BackendModel::submitSpam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others);
             }
         }
         // set new status
         BackendCatalogModel::updateCommentStatuses($ids, $action);
     } else {
         // other actions data
         // published?
         if ($action == 'published') {
             // is the spamfilter active?
             if (BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false)) {
                 // get data
                 $comments = BackendCatalogModel::getComments($ids);
                 // loop comments
                 foreach ($comments as $row) {
                     // previous status is spam
                     if ($row['status'] == 'spam') {
                         // unserialize data
                         $row['data'] = unserialize($row['data']);
                         // check if needed data is available
                         if (!isset($row['data']['server']['REMOTE_ADDR'])) {
                             continue;
                         }
                         if (!isset($row['data']['server']['HTTP_USER_AGENT'])) {
                             continue;
                         }
                         // build vars
                         $userIp = $row['data']['server']['REMOTE_ADDR'];
                         $userAgent = $row['data']['server']['HTTP_USER_AGENT'];
                         $content = $row['text'];
                         $author = $row['author'];
                         $email = $row['email'];
                         $url = isset($row['website']) && $row['website'] != '' ? $row['website'] : null;
                         $referrer = isset($row['data']['server']['HTTP_REFERER']) ? $row['data']['server']['HTTP_REFERER'] : null;
                         $others = $row['data']['server'];
                         // submit as spam
                         BackendModel::submitHam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others);
                     }
                 }
             }
         }
         // set new status
         BackendCatalogModel::updateCommentStatuses($ids, $action);
     }
     // define report
     $report = count($ids) > 1 ? 'comments-' : 'comment-';
     // init var
     if ($action == 'published') {
         $report .= 'moved-published';
     }
     if ($action == 'moderation') {
         $report .= 'moved-moderation';
     }
     if ($action == 'spam') {
         $report .= 'moved-spam';
     }
     if ($action == 'delete') {
         $report .= 'deleted';
     }
     // redirect
     $this->redirect(BackendModel::createURLForAction('comments') . '&report=' . $report . '#tab' . ucfirst($from));
 }
Example #9
0
    /**
     * Is this category allowed to be deleted?
     *
     * @return    bool
     * @param    int $id The category id to check.
     */
    public static function deleteCategoryAllowed($id)
    {
        // get result
        $result = BackendModel::getContainer()->get('database')->getVar('SELECT 1
	                 FROM agenda AS i
	                 WHERE i.category_id = ?
	                 LIMIT 1', array((int) $id));
        // exception
        if (!BackendModel::getModuleSetting('agenda', 'allow_multiple_categories', true) && self::getCategoryCount() == 1) {
            return false;
        } else {
            return $result;
        }
    }
Example #10
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $image = $this->frm->getField('image');
         $this->frm->getField('title')->isFilled(BL::err('NameIsRequired'));
         $image->isFilled(BL::err('FieldIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build image record to insert
             $item['product_id'] = $this->product['id'];
             $item['title'] = $this->frm->getField('title')->getValue();
             // set files path for this record
             $path = FRONTEND_FILES_PATH . '/' . $this->module . '/' . $item['product_id'];
             // set formats
             $formats = array();
             $formats[] = array('size' => '64x64', 'allow_enlargement' => true, 'force_aspect_ratio' => false);
             $formats[] = array('size' => '128x128', 'allow_enlargement' => true, 'force_aspect_ratio' => false);
             $formats[] = array('size' => BackendModel::getModuleSetting($this->URL->getModule(), 'width1') . 'x' . BackendModel::getModuleSetting($this->URL->getModule(), 'height1'), 'allow_enlargement' => BackendModel::getModuleSetting($this->URL->getModule(), 'allow_enlargment1'), 'force_aspect_ratio' => BackendModel::getModuleSetting($this->URL->getModule(), 'force_aspect_ratio1'));
             $formats[] = array('size' => BackendModel::getModuleSetting($this->URL->getModule(), 'width2') . 'x' . BackendModel::getModuleSetting($this->URL->getModule(), 'height2'), 'allow_enlargement' => BackendModel::getModuleSetting($this->URL->getModule(), 'allow_enlargment2'), 'force_aspect_ratio' => BackendModel::getModuleSetting($this->URL->getModule(), 'force_aspect_ratio2'));
             $formats[] = array('size' => BackendModel::getModuleSetting($this->URL->getModule(), 'width3') . 'x' . BackendModel::getModuleSetting($this->URL->getModule(), 'height3'), 'allow_enlargement' => BackendModel::getModuleSetting($this->URL->getModule(), 'allow_enlargment3'), 'force_aspect_ratio' => BackendModel::getModuleSetting($this->URL->getModule(), 'force_aspect_ratio3'));
             // set the filename
             $item['filename'] = time() . '.' . $image->getExtension();
             $item['sequence'] = BackendCatalogModel::getMaximumImagesSequence($item['product_id']) + 1;
             // add images
             BackendCatalogHelper::addImages($image, $path, $item['filename'], $formats);
             // save the item
             $item['id'] = BackendCatalogModel::saveImage($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_image', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('media') . '&product_id=' . $item['product_id'] . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Example #11
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 #12
0
 /**
  * Load form
  */
 private function loadForm()
 {
     $this->frm = new BackendForm("update");
     $this->frm->addDropdown('number_of_items', array_combine(range(10, 100, 10), range(10, 100, 10)), BackendModel::getModuleSetting($this->URL->getModule(), 'overview_num_items', 10));
 }