Example #1
0
 public function generateCache($languageId)
 {
     $event = new BASE_CLASS_EventCollector('base.add_global_lang_keys');
     OW::getEventManager()->trigger($event);
     $globalVars = call_user_func_array('array_merge', $event->getData());
     $values = $this->keyDao->findAllWithValues($languageId);
     $result = array();
     // fix begin
     // remove cache files from \ow_pluginfiles\base\lang_{1,2}.php and open site in debug mode
     $valuesReserv = $this->keyDao->findAllWithValues($languageId == 1 ? 2 : 1);
     foreach ($valuesReserv as $v) {
         $key = $v['prefix'] . '+' . $v['key'];
         $v['value'] = UTIL_String::replaceVars($v['value'], $globalVars);
         $result[$key] = $v['value'];
     }
     // fix end
     foreach ($values as $v) {
         $key = $v['prefix'] . '+' . $v['key'];
         $v['value'] = UTIL_String::replaceVars($v['value'], $globalVars);
         $result[$key] = $v['value'];
     }
     $cacheContent = "<?php\n\$language[{$languageId}] = " . var_export($result, true) . ";\n?>";
     $filename = $this->languageCacheDir . 'lang_' . $languageId . '.php';
     file_put_contents($filename, $cacheContent);
     @chmod($filename, 0666);
     $this->loadFromCahce();
 }
Example #2
0
 public function text($prefix, $key, array $vars = null)
 {
     if (empty($prefix) || empty($key)) {
         return $prefix . '+' . $key;
     }
     $text = null;
     try {
         $text = BOL_LanguageService::getInstance()->getText(BOL_LanguageService::getInstance()->getCurrent()->getId(), $prefix, $key);
     } catch (Exception $e) {
         return $prefix . '+' . $key;
     }
     if ($text === null) {
         return $prefix . '+' . $key;
     }
     $text = UTIL_String::replaceVars($text, $vars);
     return $text;
 }
Example #3
0
 public function text($prefix, $key, array $vars = null)
 {
     if (empty($prefix) || empty($key)) {
         return $prefix . '+' . $key;
     }
     $text = null;
     try {
         $text = BOL_LanguageService::getInstance()->getText(BOL_LanguageService::getInstance()->getCurrent()->getId(), $prefix, $key);
     } catch (Exception $e) {
         return $prefix . '+' . $key;
     }
     if ($text === null) {
         return $prefix . '+' . $key;
     }
     $event = new OW_Event("core.get_text", array("prefix" => $prefix, "key" => $key, "vars" => $vars));
     $this->eventManager->trigger($event);
     if ($event->getData() !== null) {
         return $event->getData();
     }
     $text = UTIL_String::replaceVars($text, $vars);
     return $text;
 }
Example #4
0
 /**
  * @param int $languageId
  * @param string $prefix
  * @param string $key
  * @param array $vars
  * @return string
  */
 public function getText($languageId, $prefix, $key, $vars = array())
 {
     $text = $this->getTextTemplate($languageId, $prefix, $key);
     if (!empty($vars) && is_array($vars)) {
         foreach ($vars as $key => &$value) {
             if (UTIL_Serialize::isSerializedObject($value)) {
                 $object = UTIL_Serialize::unserialize($value);
                 if (empty($object) || !$object instanceof BASE_CLASS_LanguageParams) {
                     $value = '';
                 }
                 $value = $object->fetch();
             }
         }
     }
     $event = new OW_Event("core.get_text", array("prefix" => $prefix, "key" => $key, "vars" => $vars));
     OW::getEventManager()->trigger($event);
     if ($event->getData() !== null) {
         return $event->getData();
     }
     $text = UTIL_String::replaceVars($text, $vars);
     return $text;
 }
Example #5
0
function sendVerificationMail($type, $params)
{
    global $getConfig;
    global $getFeedback;
    //global $getRouter;
    global $language;
    global $getMailer;
    global $EmailVerifyService;
    $subject = $params['subject'];
    $template_html = $params['body_html'];
    $template_text = $params['body_text'];
    switch ($type) {
        case "user":
            $user = $params['user'];
            $email = $user->email;
            $userId = $user->id;
            break;
        case "site":
            $email = $getConfig->getValue('base', 'unverify_site_email');
            $userId = 0;
            break;
        default:
            $getFeedback->error($language->text('base', 'email_verify_verify_mail_was_not_sent'));
            return;
    }
    $emailVerifiedData = $EmailVerifyService->findByEmailAndUserId($email, $userId, $type);
    if ($emailVerifiedData !== null) {
        $timeLimit = 60 * 60 * 24 * 3;
        // 3 days
        if (time() - (int) $emailVerifiedData->createStamp >= $timeLimit) {
            $emailVerifiedData = null;
        }
    }
    if ($emailVerifiedData === null) {
        $emailVerifiedData = new BOL_EmailVerify();
        $emailVerifiedData->userId = $userId;
        $emailVerifiedData->email = trim($email);
        $emailVerifiedData->hash = randomNumber();
        $emailVerifiedData->createStamp = time();
        $emailVerifiedData->type = $type;
        $EmailVerifyService->batchReplace(array($emailVerifiedData));
    }
    $vars = array('code' => $emailVerifiedData->hash);
    $language = $language;
    $subject = UTIL_String::replaceVars($subject, $vars);
    $template_html = UTIL_String::replaceVars($template_html, $vars);
    $template_text = UTIL_String::replaceVars($template_text, $vars);
    $mail = $getMailer->createMail();
    $mail->addRecipientEmail($emailVerifiedData->email);
    $mail->setSubject($subject);
    $mail->setHtmlContent($template_html);
    $mail->setTextContent($template_text);
    $getMailer->send($mail);
    if (!isset($params['feedback']) || $params['feedback'] !== false) {
        $getFeedback->info($language->text('base', 'email_verify_verify_mail_was_sent'));
    }
}
Example #6
0
 public function index($params = array())
 {
     $userService = BOL_UserService::getInstance();
     $language = OW::getLanguage();
     $this->setPageHeading($language->text('admin', 'massmailing'));
     $this->setPageHeadingIconClass('ow_ic_script');
     $massMailingForm = new Form('massMailingForm');
     $massMailingForm->setId('massMailingForm');
     $rolesList = BOL_AuthorizationService::getInstance()->getRoleList();
     $userRoles = new CheckboxGroup('userRoles');
     $userRoles->setLabel($language->text('admin', 'massmailing_user_roles_label'));
     foreach ($rolesList as $role) {
         if ($role->name != 'guest') {
             $userRoles->addOption($role->name, $language->text('base', 'authorization_role_' . $role->name));
         }
     }
     $massMailingForm->addElement($userRoles);
     $emailFormat = new Selectbox('emailFormat');
     $emailFormat->setLabel($language->text('admin', 'massmailing_email_format_label'));
     $emailFormat->setOptions(array(self::EMAIL_FORMAT_TEXT => $language->text('admin', 'massmailing_email_format_text'), self::EMAIL_FORMAT_HTML => $language->text('admin', 'massmailing_email_format_html')));
     $emailFormat->setValue(self::EMAIL_FORMAT_TEXT);
     $emailFormat->setHasInvitation(false);
     if (!empty($_POST['emailFormat'])) {
         $emailFormat->setValue($_POST['emailFormat']);
     }
     $massMailingForm->addElement($emailFormat);
     $subject = new TextField('subject');
     $subject->addAttribute('class', 'ow_text');
     $subject->addAttribute('style', 'width: auto;');
     $subject->setRequired();
     $subject->setLabel($language->text('admin', 'massmailing_subject_label'));
     if (!empty($_POST['subject'])) {
         $subject->setValue($_POST['subject']);
     }
     $massMailingForm->addElement($subject);
     $body = new Textarea('body');
     if ($emailFormat->getValue() == self::EMAIL_FORMAT_HTML) {
         $body = new WysiwygTextarea('body');
         $body->forceAddButtons(array(BOL_TextFormatService::WS_BTN_IMAGE, BOL_TextFormatService::WS_BTN_HTML));
     }
     $body->addAttribute('class', 'ow_text');
     $body->addAttribute('style', 'width: auto;');
     $body->setRequired();
     $body->setLabel($language->text('admin', 'massmailing_body_label'));
     if (!empty($_POST['body'])) {
         $body->setValue($_POST['body']);
     }
     $massMailingForm->addElement($body);
     $submit = new Submit('startMailing');
     $submit->addAttribute('class', 'ow_button');
     $submit->setValue($language->text('admin', 'massmailing_start_mailing_button'));
     $massMailingForm->addElement($submit);
     $this->addForm($massMailingForm);
     $ignoreUnsubscribe = false;
     $isActive = true;
     if (defined('OW_PLUGIN_XP')) {
         $massMailingTimestamp = OW::getConfig()->getValue('admin', 'mass_mailing_timestamp');
         $timeout = $massMailingTimestamp + 60 * 60 * 24 - time();
         if ($timeout > 0) {
             $isActive = false;
             $this->assign('expireText', $language->text('admin', 'massmailing_expire_text', array('hours' => (int) ceil($timeout / (60 * 60)))));
         }
     }
     $this->assign('isActive', $isActive);
     $total = $userService->findMassMailingUserCount($ignoreUnsubscribe);
     if (OW::getRequest()->isPost() && $isActive && isset($_POST['startMailing'])) {
         if ($massMailingForm->isValid($_POST)) {
             $data = $massMailingForm->getValues();
             $start = 0;
             $count = self::MAILS_ARRAY_MAX_RECORDS;
             $mailCount = 0;
             $total = $userService->findMassMailingUserCount($ignoreUnsubscribe, $data['userRoles']);
             while ($start < $total) {
                 $result = $this->userService->findMassMailingUsers($start, $count, $ignoreUnsubscribe, $data['userRoles']);
                 $mails = array();
                 $userIdList = array();
                 foreach ($result as $user) {
                     $userIdList[] = $user->id;
                 }
                 $displayNameList = $this->userService->getDisplayNamesForList($userIdList);
                 $event = new BASE_CLASS_EventCollector('base.add_global_lang_keys');
                 OW::getEventManager()->trigger($event);
                 $vars = call_user_func_array('array_merge', $event->getData());
                 foreach ($result as $key => $user) {
                     $vars['user_email'] = $user->email;
                     $mail = OW::getMailer()->createMail();
                     $mail->addRecipientEmail($user->email);
                     $vars['user_name'] = $displayNameList[$user->id];
                     $code = md5($user->username . $user->password);
                     $link = OW::getRouter()->urlForRoute('base_massmailing_unsubscribe', array('id' => $user->id, 'code' => $code));
                     $subjectText = UTIL_String::replaceVars($data['subject'], $vars);
                     $mail->setSubject($subjectText);
                     if ($data['emailFormat'] === self::EMAIL_FORMAT_HTML) {
                         $htmlContent = UTIL_String::replaceVars($data['body'], $vars);
                         $htmlContent .= $language->text('admin', 'massmailing_unsubscribe_link_html', array('link' => $link));
                         $mail->setHtmlContent($htmlContent);
                         $textContent = preg_replace("/\\<br\\s*[\\/]?\\s*\\>/", "\n", $htmlContent);
                         $textContent = strip_tags($textContent);
                         $mail->setTextContent($textContent);
                     } else {
                         $textContent = UTIL_String::replaceVars($data['body'], $vars);
                         $textContent .= "\n\n" . $language->text('admin', 'massmailing_unsubscribe_link_text', array('link' => $link));
                         $mail->setTextContent($textContent);
                     }
                     $mails[] = $mail;
                     $mailCount++;
                 }
                 $start += $count;
                 //printVar($mails);
                 OW::getMailer()->addListToQueue($mails);
             }
             OW::getFeedback()->info($language->text('admin', 'massmailing_send_mails_message', array('count' => $mailCount)));
             if (defined('OW_PLUGIN_XP')) {
                 OW::getConfig()->saveConfig('admin', 'mass_mailing_timestamp', time());
             }
             $this->redirect();
         }
     }
     $this->assign('userCount', $total);
     $language->addKeyForJs('admin', 'questions_empty_lang_value');
     $language->addKeyForJs('admin', 'massmailing_total_members');
     $script = ' window.massMailing = new MassMailing(\'' . $this->ajaxResponderUrl . '\'); ';
     OW::getDocument()->addOnloadScript($script);
     $jsDir = OW::getPluginManager()->getPlugin("admin")->getStaticJsUrl();
     OW::getDocument()->addScript($jsDir . "mass_mailing.js");
 }
Example #7
0
 /**
  * @see FormElement::renderInput()
  *
  * @param array $params
  * @return string
  */
 public function renderInput($params = null)
 {
     $html = parent::renderInput($params);
     $template = '
                     <div class="clearfix question_value_block" style="cursor:move;">
                             <span class="tag">
                                 <input type="hidden" value="{$value}">
                                 <span class="label" style="max-width:250px;overflow:hidden;">{$label}</span>
                                 <a title=' . json_encode(OW::getLanguage()->text('admin', 'remove_value')) . ' class="remove" href="javascript://"></a>
                             </span>
                     </div>';
     $template = UTIL_String::replaceVars($template, array('label' => '', 'value' => 0));
     $json = json_encode(array('tagFieldId' => $this->tag->getId(), 'dataFieldId' => $this->getId(), 'value' => $this->value, 'order' => array_keys($this->value), 'template' => $template));
     OW::getDocument()->addOnloadScript("\n            if ( !window.addInfiniteQuestionValues )\n            {\n                window.addInfiniteQuestionValues = {};\n            }\n\n            window.addInfiniteQuestionValues[" . json_encode($this->getId()) . "] = new infiniteQuestionValuesField(" . $json . "); ");
     return $html;
 }
Example #8
0
 /**
  * @see FormElement::renderInput()
  *
  * @param array $params
  * @return string
  */
 public function renderInput($params = null)
 {
     if ($this->disabled) {
         $attributes = $this->attributes;
         unset($attributes['name']);
         $message = OW::getLanguage()->text('admin', 'possible_values_disable_message');
         $event = new OW_Event('admin.get.possible_values_disable_message', array('name' => $this->getName(), 'id' => $this->getId()), $message);
         OW::getEventManager()->trigger($event);
         $message = $event->getData();
         return UTIL_HtmlTag::generateTag('div', $attributes, true, $message);
     }
     parent::renderInput($params);
     $template = '
                     <div class="clearfix question_value_block" style="cursor:move;">
                             <span class="tag">
                                 <input type="hidden" value="{$value}">
                                 <span class="label" style="max-width:250px;overflow:hidden;">{$label}</span>
                                 <a title=' . json_encode(OW::getLanguage()->text('admin', 'remove_value')) . ' class="remove" href="javascript://"></a>
                             </span>
                     </div>';
     $values = '';
     if (!empty($this->value) && is_array($this->value)) {
         foreach ($this->value as $value => $label) {
             $data = $template;
             $values .= UTIL_String::replaceVars($data, array('label' => $label, 'value' => $value));
         }
     }
     $template = UTIL_String::replaceVars($template, array('label' => '', 'value' => 0));
     $addButtonName = $this->getName() . '_add_button';
     $jsDir = OW::getPluginManager()->getPlugin("admin")->getStaticJsUrl();
     OW::getDocument()->addScript($jsDir . "questions.js");
     $json = json_encode(array('tagFieldId' => $this->tag->getId(), 'dataFieldId' => $this->getId(), 'value' => $this->value, 'order' => array_keys($this->value), 'template' => $template));
     OW::getDocument()->addOnloadScript("\n            if ( !window.addQuestionValues )\n            {\n                window.addQuestionValues = {};\n            }\n\n            window.addQuestionValues[" . json_encode($this->getId()) . "] = new questionValuesField(" . $json . "); ");
     OW::getLanguage()->addKeyForJs('admin', 'questions_edit_delete_value_confirm_message');
     $inputValues = array();
     foreach ($this->value as $key => $val) {
         $inputValues[] = array($key => $val);
     }
     $html = '<div class="values_list">
             </div>
             <input type="hidden" id=' . json_encode($this->getId()) . ' name=' . json_encode($this->getName()) . ' value=' . json_encode($inputValues) . ' />
             <input type="hidden" id=' . json_encode($this->getId() . "_deleted_values") . ' name=' . json_encode($this->getName() . "_deleted_values") . ' value="" />
             <div style="padding-left: 4px;" class="ow_smallmargin">' . OW::getLanguage()->text('admin', 'add_question_value_description') . '</div>
             <div class="clearfix">
                 <div class="ow_left" style="width: 260px;">' . $this->tag->renderInput() . '</div>
                 <div class="ow_right">
                     <span class="ow_button">
                         <span class="ow_ic_add">
                             <input type="button" value=' . json_encode(OW::getLanguage()->text('admin', 'add_button')) . ' class="ow_ic_add" name="' . $addButtonName . '">
                         </span>
                     </span>
                 </div>
             </div>';
     return $html;
 }
Example #9
0
 public function sendVerificationMail($type, $params)
 {
     $subject = $params['subject'];
     $template_html = $params['body_html'];
     $template_text = $params['body_text'];
     switch ($type) {
         case self::TYPE_USER_EMAIL:
             $user = $params['user'];
             $email = $user->email;
             $userId = $user->id;
             break;
         case self::TYPE_SITE_EMAIL:
             $email = OW::getConfig()->getValue('base', 'unverify_site_email');
             $userId = 0;
             break;
         default:
             OW::getFeedback()->error($language->text('base', 'email_verify_verify_mail_was_not_sent'));
             return;
     }
     $emailVerifiedData = BOL_EmailVerifyService::getInstance()->findByEmailAndUserId($email, $userId, $type);
     if ($emailVerifiedData !== null) {
         $timeLimit = 60 * 60 * 24 * 3;
         // 3 days
         if (time() - (int) $emailVerifiedData->createStamp >= $timeLimit) {
             $emailVerifiedData = null;
         }
     }
     if ($emailVerifiedData === null) {
         $emailVerifiedData = new BOL_EmailVerify();
         $emailVerifiedData->userId = $userId;
         $emailVerifiedData->email = trim($email);
         $emailVerifiedData->hash = BOL_EmailVerifyService::getInstance()->generateHash();
         $emailVerifiedData->createStamp = time();
         $emailVerifiedData->type = $type;
         BOL_EmailVerifyService::getInstance()->batchReplace(array($emailVerifiedData));
     }
     $vars = array('code' => $emailVerifiedData->hash, 'url' => OW::getRouter()->urlForRoute('base_email_verify_code_check', array('code' => $emailVerifiedData->hash)), 'verification_page_url' => OW::getRouter()->urlForRoute('base_email_verify_code_form'));
     $language = OW::getLanguage();
     $subject = UTIL_String::replaceVars($subject, $vars);
     $template_html = UTIL_String::replaceVars($template_html, $vars);
     $template_text = UTIL_String::replaceVars($template_text, $vars);
     $mail = OW::getMailer()->createMail();
     $mail->addRecipientEmail($emailVerifiedData->email);
     $mail->setSubject($subject);
     $mail->setHtmlContent($template_html);
     $mail->setTextContent($template_text);
     OW::getMailer()->send($mail);
     if (!isset($params['feedback']) || $params['feedback'] !== false) {
         OW::getFeedback()->info($language->text('base', 'email_verify_verify_mail_was_sent'));
     }
 }