示例#1
0
 public function __construct()
 {
     // Check background services
     if (isset($_GET['cms_is_running_background']) && $_GET['cms_is_running_background'] == 1) {
         ServiceManager::checkNeeded();
         exit;
     }
     // Try updating CMS
     if (isset($_GET['key']) && $_GET['key'] == Configuration::getInstance()->get('cms')['unique_key'] && count($_GET) === 2) {
         $updater = Updater::getInstance();
         // Update files from repo
         $updater->updateSourceCode(isset($_GET['branch']) ? $_GET['branch'] : NULL);
         // Update composer only if required
         if (isset($_GET['composer'])) {
             $updater->updateComposerVendors();
         }
         // Update database
         $updater->runMigrations();
         // Run PHPUnit tests
         $updater->runTests();
         // Output
         $out = $updater->getResult();
         $text = json_encode($out, JSON_FORCE_OBJECT);
         echo $text;
         if (stripos($text, 'Code Coverage Report') === false) {
             Mailer::getInstance()->setMessage('Did not find "Code Coverage Report" in updater response:<br><br>' . $text)->setRecipient(CMS_SUPPORT_EMAIL)->setSender(Settings::getCommonEmail(), Configuration::getInstance()->get('site')['name'] . ' - AutoUpdater')->setSubject('Error found during update')->send();
         }
         exit;
     }
     // Else - running usual Admin panel
     // Proceed with request
     $this->parseUrl();
     // Save log
     if (Users::getInstance()->isLogged() && Settings::get('save_back_access_log') && !IS_AJAX_REQUEST) {
         $users_log = new UserLog();
         $users_log->save();
     }
     // Init page data
     if (Users::getInstance()->isLogged()) {
         define('LNG', Users::getInstance()->getUserLng());
     }
     $this->sendHeaders();
     $this->prepareHead();
     $this->parseMenu();
     // Post-scripts
     Page::setTail(PageTail::getInstance());
     // Flush application log
     App::flushLog();
     $this->generateContent();
 }
 public static function addNewFeedback(array $data, $need_to_save_in_db = true, $send_to_emails = [], $files = [])
 {
     $send_to_emails = (array) $send_to_emails;
     $cacher = Cacher::getInstance()->getDefaultCacher();
     $cache_key = 'module_feedback_add_new_feedback_last_send_ts' . VISITOR_HASH;
     // Check message is not sent too quick
     $last_sent_ts = $cacher->get($cache_key);
     if (NOW - $last_sent_ts < self::$sending_period_seconds) {
         return false;
     }
     // Autocreate db
     $feedbacks = new FeedbackRepository();
     $feedback = NULL;
     // Save to Db
     if ($need_to_save_in_db) {
         $feedback = new Feedback();
         $feedback->loadDataFromArray($data);
         $feedback->save();
     }
     // Send email to manager
     if ($send_to_emails) {
         $msg = '<table><tr><th>Field</th><th>Value</th></tr>';
         foreach ($data as $k => $v) {
             if ($v) {
                 $msg .= '<tr><td>' . $k . '</td><td>' . htmlspecialchars($v) . '</td></tr>';
             }
         }
         $msg .= '</table>';
         $mailer = Mailer::getInstance()->setSubject('New feedback from ' . CFG_DOMAIN)->setSender(Settings::getCommonEmail())->setMessage($msg);
         foreach ($send_to_emails as $email) {
             $mailer->setRecipient($email);
         }
         foreach ($files as $file) {
             $mailer->addAttachment($file);
         }
         $mailer->send();
     }
     // Save last send ts
     $cacher->set($cache_key, NOW);
     return $feedback;
 }