public function onDispatchChanges(iUmiEventPoint $oEvent) { $sTemplate = "default"; try { list($sTemplateSubject, $sTemplateMessage) = def_module::loadTemplatesForMail("forum/mails/".$sTemplate, "mail_subject", "mail_message"); } catch (publicException $e) { return false; } $iTopicId = $oEvent->getParam("topic_id"); $iMessageId = $oEvent->getParam("message_id"); $message = umiHierarchy::getInstance()->getElement($iMessageId); $sel = new selector('objects'); $sel->types('object-type')->name("users", "user"); $sel->where('subscribed_pages')->equals($iTopicId); if (!$sel->length()) return false; $hierarchy = umiHierarchy::getInstance(); $block_arr = Array(); $sTemplateSubject = def_module::parseTemplateForMail($sTemplateSubject, $block_arr, $iMessageId); $sFromEmail = regedit::getInstance()->getVal("//settings/email_from"); $sFromFio = regedit::getInstance()->getVal("//settings/fio_from"); $oMail = new umiMail(); $oMail->setFrom($sFromEmail, $sFromFio); $oMail->setSubject($sTemplateSubject); foreach($sel->result() as $oUser) { $oMailUser = clone $oMail; $sUserMail = $oUser->getValue('e-mail'); $block_arr['h1'] = $message->getValue('h1'); $block_arr['message'] = $message->getValue('message'); $hierarchy->forceAbsolutePath(true); $block_arr['unsubscribe_link'] = $hierarchy->getPathById($iTopicId) . "?unsubscribe=" . base64_encode($iUserId); $sTemplateMessageUser = def_module::parseTemplateForMail($sTemplateMessage, $block_arr, $iMessageId); $oMailUser->setContent($sTemplateMessageUser); $hierarchy->forceAbsolutePath(false); if (umiMail::checkEmail($sUserMail)) { $sUserFio = $oUser->getValue('lname') . " ". $oUser->getValue('fname') . " " . $oUser->getValue('father_name'); $oMailUser->addRecipient($sUserMail, $sUserFio); $oMailUser->commit(); $oMailUser->send(); } else continue; } return true; }
/** * Создать новый пустой заказ * @return Integer $order id нового заказа */ public static function create($useDummyOrder = false) { $objectTypes = umiObjectTypesCollection::getInstance(); $objects = umiObjectsCollection::getInstance(); $permissions = permissionsCollection::getInstance(); $cmsController = cmsController::getInstance(); $domain = $cmsController->getCurrentDomain(); $domainId = $domain->getId(); $orderTypeId = $objectTypes->getBaseType('emarket', 'order'); if ($useDummyOrder) { $sel = new selector('objects'); $sel->types('object-type')->name('emarket', 'order'); $sel->where('name')->equals('dummy'); $sel->limit(0, 1); if ($sel->length()) { $orderId = $sel->first->id; } else { $orderTypeId = $objectTypes->getBaseType('emarket', 'order'); $orderId = $objects->addObject('dummy', $orderTypeId); $order = $objects->getObject($orderId); if ($order instanceof iUmiObject == false) { throw new publicException("Can't load dummy object for order #{$orderId}"); } else { $order->setValue('domain_id', $domainId); $order->commit(); } } return self::get($orderId); } $managerId = 0; $statusId = self::getStatusByCode('basket'); $customer = customer::get(); $createTime = time(); $orderId = $objects->addObject('', $orderTypeId); $order = $objects->getObject($orderId); if ($order instanceof iUmiObject == false) { throw new publicException("Can't load created object for order #{$orderId}"); } $order->domain_id = $domainId; $order->manager_id = $managerId; $order->status_id = $statusId; $order->customer_id = $customer->getId(); $order->order_create_date = $createTime; $order->commit(); $customer->setLastOrder($orderId, $domainId); return self::get($orderId); }
public function list_files($element_id = false, $template = "default", $per_page = false, $ignore_paging = false) { if(!$template) $template = "default"; list($template_block, $template_line) = def_module::loadTemplates("filemanager/".$template, "list_files", "list_files_row"); $block_arr = Array(); $element_id = $this->analyzeRequiredPath($element_id); if(!$per_page) $per_page = $this->per_page; $curr_page = (int) getRequest('p'); if($ignore_paging) $curr_page = 0; $sel = new selector('pages'); $sel->types('hierarchy-type')->name('filemanager', 'shared_file'); $sel->where('hierarchy')->page($element_id)->childs(100); $sel->limit($curr_page, $per_page); $result = $sel->result(); $total = $sel->length(); $lines = Array(); foreach($result as $element) { $line_arr = Array(); $next_element_id = $element->getId(); $line_arr['attribute:id'] = $element->getId(); $line_arr['attribute:name'] = $element->getName(); $line_arr['attribute:link'] = umiHierarchy::getInstance()->getPathById($next_element_id); $line_arr['attribute:downloads-count'] = $element->getValue('downloads_counter'); $line_arr['xlink:download-link'] = $this->pre_lang . "/filemanager/download/" . $next_element_id; $line_arr['xlink:href'] = "upage://" . $next_element_id; $line_arr['node:desc'] = $element->getValue("content"); $this->pushEditable("filemanager", "shared_file", $next_element_id); $lines[] = self::parseTemplate($template_line, $line_arr, $next_element_id); } $block_arr['nodes:items'] = $block_arr['void:lines'] = $lines; $block_arr['per_page'] = $per_page; $block_arr['total'] = $total; return self::parseTemplate($template_block, $block_arr); }
public function albums($template = "default", $limit = false, $ignore_paging = false, $parentElementId = false, $order = 'asc') { list($template_block, $template_block_empty, $template_line) = def_module::loadTemplates("photoalbum/" . $template, "albums_list_block", "albums_list_block_empty", "albums_list_block_line"); $block_arr = array(); $curr_page = (int) getRequest('p'); if ($ignore_paging) { $curr_page = 0; } $offset = $limit * $curr_page; $sel = new selector('pages'); $sel->types('hierarchy-type')->name('photoalbum', 'album'); $sel->where('permissions'); if ($parentElementId) { $sel->where('hierarchy')->page($parentElementId)->childs(1); } if (in_array($order, array('asc', 'desc', 'rand'))) { $sel->order('ord')->{$order}(); } $sel->limit($offset, $limit); $result = $sel->result; $total = $sel->length(); $lines = array(); if ($total > 0) { foreach ($result as $element) { $line_arr = array(); $element_id = $element->getId(); $line_arr['attribute:id'] = $element_id; $line_arr['attribute:link'] = umiHierarchy::getInstance()->getPathById($element_id); $line_arr['xlink:href'] = "upage://" . $element_id; $line_arr['node:name'] = $element->getName(); $this->pushEditable("photoalbum", "album", $element_id); $lines[] = self::parseTemplate($template_line, $line_arr, $element_id); } } else { return self::parseTemplate($template_block_empty, $block_arr); } $block_arr['subnodes:items'] = $block_arr['void:lines'] = $lines; $block_arr['total'] = $total; $block_arr['per_page'] = $limit; return self::parseTemplate($template_block, $block_arr); }
/** * Возвращает страницу "Заказ оформлен/Неудалось оформить" * @param order $order * @param String $step - результат оформления заказа (успешно/нет) * @param $mode * @param String $template * @return Array */ public function result(order $order, $step, $mode, $template) { list($tpl_successful, $tpl_failed) = def_module::loadTemplates("emarket/" . $template, 'purchase_successful', 'purchase_failed'); $tpl_block = $step == 'successful' ? $tpl_successful : $tpl_failed; if ($order->isEmpty()) { $customer = customer::get(); $domain = cmsController::getInstance()->getCurrentDomain(); $domainId = $domain->getId(); $sel = new selector('objects'); $sel->types('object-type')->name('emarket', 'order'); $sel->where('customer_id')->equals($customer->getId()); $sel->where('domain_id')->equals($domainId); $sel->order('id')->desc(); if ($sel->length()) { $orderId = $sel->first->id; } } else { $orderId = $order->getId(); } $result = array('status' => $step, 'order' => array('attribute:id' => $orderId), 'void:order_id' => $orderId); return def_module::parseTemplate($tpl_block, $result); }
public function release_send() { $buffer = outputBuffer::current('HTTPOutputBuffer'); $buffer->charset('utf-8'); $buffer->contentType('text/xml'); $buffer->push('<?xml version="1.0" encoding="utf-8"?>'); $iDispId = (int) getRequest('param0'); $iReleaseId = $this->getNewReleaseInstanceId($iDispId); $arrPostData = getRequest("data_values"); $objectsColl = umiObjectsCollection::getinstance(); $controller = cmsController::getInstance(); $oDispatch = $objectsColl->getObject($iDispId); $oRelease = $objectsColl->getObject($iReleaseId); if (!$oDispatch instanceof umiObject || !$oRelease instanceof umiObject) { $buffer->push("<error>Не указан идентификатор рассылки</error>"); $buffer->end(); } if ($oRelease->getValue('status')) { $buffer->push("<error>Этот выпуск уже был отправлен</error>"); $buffer->end(); } $arrRecipients = array(); if (!getSession('umi_send_list_' . $iReleaseId)) { $sel = new selector('objects'); $sel->types("object-type")->name("dispatches", "subscriber"); $sel->where("subscriber_dispatches")->equals($iDispId); $sel->option('return')->value('id'); $sel->group("name"); foreach ($sel->result() as $recipient) { $arrRecipients[] = $recipient['id']; } $_SESSION['umi_send_list_' . $iReleaseId] = $arrRecipients; $_SESSION['umi_send_list_' . $iReleaseId . '_count'] = count($arrRecipients); } else { $arrRecipients = getSession('umi_send_list_' . $iReleaseId); } $delay = getSession('umi_send_list_' . $iReleaseId . '_delay'); $iTotal = (int) getSession('umi_send_list_' . $iReleaseId . '_count'); if ($delay and time() < $delay) { $iSended = $iTotal - count($arrRecipients); $sResult = <<<END <release dispatch="{$iDispId}"> \t<total>{$iTotal}</total> \t<sended>{$iSended}</sended> </release> END; $buffer->push($sResult); $buffer->end(); } $sHost = $controller->getCurrentDomain()->getHost(); $oMailer = new umiMail(); $arrMailBlocks = array(); $arrMailBlocks['header'] = $oDispatch->getName(); $arrMailBlocks['messages'] = ""; list($sReleaseFrm, $sMessageFrm) = def_module::loadTemplatesForMail("dispatches/release", "release_body", "release_message"); $sel = new selector('objects'); $sel->types("object-type")->name("dispatches", "message"); $sel->where("release_reference")->equals($iReleaseId); if ($sel->length()) { foreach ($sel->result() as $oNextMsg) { if ($oNextMsg instanceof umiObject) { $arrMsgBlocks = array(); $arrMsgBlocks['body'] = $oNextMsg->getValue('body'); $arrMsgBlocks['header'] = $oNextMsg->getValue('header'); $arrMailBlocks['messages'] .= def_module::parseTemplateForMail($sMessageFrm, $arrMsgBlocks, false, $oNextMsg->getId()); $oNextAttach = $oNextMsg->getValue('attach_file'); if ($oNextAttach instanceof umiFile && !$oNextAttach->getIsBroken()) { $oMailer->attachFile($oNextAttach); } } } } else { unset($_SESSION[$iDispId . '_new_templater']); $buffer->push("<error>В выпуске нет сообщений</error>"); $buffer->end(); } $oMailer->setFrom(regedit::getInstance()->getVal("//settings/email_from"), regedit::getInstance()->getVal("//settings/fio_from")); $oMailer->setSubject($arrMailBlocks['header']); $delay = 0; $max_messages = (int) mainConfiguration::getinstance()->get('modules', 'dispatches.max_messages_in_hour'); if ($max_messages && $iTotal >= $max_messages) { $delay = floor(3600 / $max_messages); } $aSended = array(); $iPacketSize = 5; //TODO: add to settings foreach ($arrRecipients as $recipient_id) { --$iPacketSize; $oNextMailer = clone $oMailer; $oNextSbs = new umiSubscriber($recipient_id); $sRecipientName = $oNextSbs->getValue('lname') . " " . $oNextSbs->getValue('fname') . " " . $oNextSbs->getValue('father_name'); $mail = $oNextSbs->getValue('email'); if (!strlen($mail)) { $mail = $oNextSbs->getName(); } $arrMailBlocks['unsubscribe_link'] = "http://" . $sHost . "/dispatches/unsubscribe/" . $oNextSbs->getId() . '/?email=' . $mail; $sMailBody = def_module::parseTemplateForMail($sReleaseFrm, $arrMailBlocks, false, $oNextSbs->getId()); $oNextMailer->setContent($sMailBody); $oNextMailer->addRecipient($mail, $sRecipientName); if (!(defined('CURRENT_VERSION_LINE') && CURRENT_VERSION_LINE == 'demo')) { $oNextMailer->commit(); $oNextMailer->send(); } $aSended[] = $recipient_id; //Unload temporary objects unset($oNextMailer); if ($iPacketSize === 0) { break; } if ($delay) { $_SESSION['umi_send_list_' . $iReleaseId . '_delay'] = $delay + time(); $_SESSION['umi_send_list_' . $iReleaseId] = array_diff($arrRecipients, $aSended); $iTotal = (int) getSession('umi_send_list_' . $iReleaseId . '_count'); $iSended = $iTotal - (count($arrRecipients) - count($aSended)); $sResult = <<<END <release dispatch="{$iDispId}"> \t<total>{$iTotal}</total> \t<sended>{$iSended}</sended> </release> END; $buffer->push($sResult); $buffer->end(); } } umiMail::clearFilesCache(); $_SESSION['umi_send_list_' . $iReleaseId] = array_diff($arrRecipients, $aSended); if (!count(getSession('umi_send_list_' . $iReleaseId))) { $oRelease->setValue('status', true); $oDate = new umiDate(time()); $oRelease->setValue('date', $oDate); $oRelease->setName($oDate->getFormattedDate('d-m-Y H:i')); $oRelease->commit(); $oDispatch->setValue('disp_last_release', $oDate); $oDispatch->commit(); } $iTotal = (int) getSession('umi_send_list_' . $iReleaseId . '_count'); $iSended = $iTotal - (count($arrRecipients) - count($aSended)); usleep(500000); $sResult = <<<END <release dispatch="{$iDispId}"> \t<total>{$iTotal}</total> \t<sended>{$iSended}</sended> </release> END; unset($_SESSION[$iDispId . '_new_templater']); $buffer->push($sResult); $buffer->end(); }
public function listGroup($elementPath, $level = 1) { // Сделать выборку по групповым элементам $pages = new selector('pages'); $pages->types('hierarchy-type')->name('modulelements', 'groupelements'); // Если не указан каталог то вывести корневые каталоги if ((string) $elementPath != '0') { $elementPath = $this->analyzeRequiredPath($elementPath); $pages->where('hierarchy')->page($elementPath)->childs($level); } else { $pages->where('hierarchy')->page('root'); } $block_arr = array(); $lines = array(); $hierarchy = umiHierarchy::getInstance(); foreach ($pages as $page) { $element_id = $page->id; $element = $hierarchy->getElement($element_id); if (!$element) { continue; } // just for safe code $line_arr = array(); $line_arr['attribute:id'] = $page->id; $line_arr['attribute:name'] = $element->getName(); $line_arr['attribute:link'] = $hierarchy->getPathById($element_id); $line_arr['xlink:href'] = 'upage://' . $element_id; if ($cur_page_id == $element_id) { $line_arr['attribute:active'] = '1'; } $lines[] = $line_arr; } $block_arr['subnodes:items'] = $lines; $block_arr['total'] = $pages->length(); return $this->parseTemplate('', $block_arr, null); }
public function widget() { $buffer = outputBuffer::current(); $buffer->contentType('text/javascript'); $buffer->option('generation-time', false); $buffer->clear(); $permissions = permissionsCollection::getInstance(); $objects = umiObjectsCollection::getInstance(); $controller = cmsController::getInstance(); $regedit = regedit::getInstance(); $host = "http://" . $controller->getCurrentDomain()->getHost(); $interval = $regedit->getVal("//modules/stat/request-time"); $interval = $interval > 0 ? $interval : 600; $regExp = "^" . str_replace('.', '\\\\.', $host) . "\/.*"; $showTips = (bool) $regedit->getVal("//modules/stat/tips"); $answer = <<<EOD { "version": 3, "update_interval": $interval, "update_url_regexps": [ "$regExp" ], "buttons": [ EOD; $userId = $permissions->getUserId(); $comma = false; if ($userId != $objects->getObjectIdByGUID('system-guest')) { //пользователи if ($regedit->getVal("//modules/stat/users-user") && $controller->getModule("users") && $permissions->isAllowedMethod($userId, "users", "users_list_all")) { $sel = new selector('objects'); $sel->types('object-type')->name('users', 'user'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-users-user') : ''; $answer .= self::getWidgetPart('users', $label, "{$host}/images/cms/admin/toolbar/users.png", "{$host}/admin/users/users_list_all/", $result, $comma); $comma = true; } //заказы if ($regedit->getVal("//modules/stat/emarket-order") && $controller->getModule("emarket") && $permissions->isAllowedMethod($userId, "emarket", "orders")) { $sel = new selector('objects'); $sel->types('object-type')->name('emarket', 'order'); $sel->where('name')->isNull(false); $sel->where('name')->notequals('dummy'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-emarket-order') : ''; $answer .= self::getWidgetPart('orders', $label, "{$host}/images/cms/admin/toolbar/orders.png", "{$host}/admin/emarket/orders/", $result, $comma); $comma = true; } //сообщения обратной связи if ($regedit->getVal("//modules/stat/webforms-message") && $controller->getModule("webforms") && $permissions->isAllowedMethod($userId, "webforms", "messages")) { $sel = new selector('objects'); $sel->types('object-type')->name('webforms', 'form'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-webforms-message') : ''; $answer .= self::getWidgetPart('webforms_messages', $label, "{$host}/images/cms/admin/toolbar/messages.png", "{$host}/admin/webforms/messages/", $result, $comma); $comma = true; } //комментарии if ($regedit->getVal("//modules/stat/comments-comment") && $controller->getModule("comments") && $permissions->isAllowedMethod($userId, "comments", "view_comments")) { $sel = new selector('pages'); $sel->types('hierarchy-type')->name('comments', 'comment'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-comments-comment') : ''; $answer .= self::getWidgetPart('comments', $label, "{$host}/images/cms/admin/toolbar/comments.png", "{$host}/admin/comments/view_comments/", $result, $comma); $comma = true; } //голосования if ($regedit->getVal("//modules/stat/vote-poll_item") && $controller->getModule("vote") && $permissions->isAllowedMethod($userId, "vote", "lists")) { $sel = new selector('objects'); $sel->types('object-type')->name('vote', 'poll_item'); $polls = $sel->result(); $result = 0; foreach ($polls as $pollItem) { $result += (int) $pollItem->getValue('count'); } $label = $showTips ? getLabel('option-vote-poll_item') : ''; $answer .= self::getWidgetPart('votes', $label, "{$host}/images/cms/admin/toolbar/votes.png", "{$host}/admin/vote/lists/", $result, $comma); $comma = true; } if ($controller->getModule("blogs20")){ //посты блога if ($regedit->getVal("//modules/stat/blogs20-post") && $permissions->isAllowedMethod($userId, "blogs20", "posts")) { $sel = new selector('pages'); $sel->types('hierarchy-type')->name('blogs20', 'post'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-blogs20-post') : ''; $answer .= self::getWidgetPart('blogs_posts', $label, "{$host}/images/cms/admin/toolbar/blog_posts.png", "{$host}/admin/blogs20/posts/", $result, $comma); $comma = true; } //комментарии блога if ($regedit->getVal("//modules/stat/blogs20-comment") && $permissions->isAllowedMethod($userId, "blogs20", "comments")) { $sel = new selector('pages'); $sel->types('hierarchy-type')->name('blogs20', 'comment'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-blogs20-comment') : ''; $answer .= self::getWidgetPart('blogs_comments', $label, "{$host}/images/cms/admin/toolbar/blog_comments.png", "{$host}/admin/blogs20/comments/", $result, $comma); $comma = true; } } //вопросы if ($regedit->getVal("//modules/stat/faq-question") && $controller->getModule("faq") && $permissions->isAllowedMethod($userId, "faq", "projects_list")) { $sel = new selector('pages'); $sel->types('hierarchy-type')->name('faq', 'question'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-faq-question') : ''; $answer .= self::getWidgetPart('faq', $label, "{$host}/images/cms/admin/toolbar/questions.png", "{$host}/admin/faq/projects_list/", $result, $comma); $comma = true; } if ($controller->getModule("forum")){ //Топики в форуме if($regedit->getVal("//modules/stat/forum-topic") && $permissions->isAllowedMethod($userId, "forum", "lists")) { $sel = new selector('pages'); $sel->types('hierarchy-type')->name('forum', 'topic'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-forum-topic') : ''; $answer .= self::getWidgetPart('forums_topics', $label, "{$host}/images/cms/admin/toolbar/forum_topics.png", "{$host}/admin/forum/lists/", $result, $comma); $comma = true; } //Сообщения в форуме if($regedit->getVal("//modules/stat/forum-message") && $permissions->isAllowedMethod($userId, "forum", "last_messages")) { $sel = new selector('pages'); $sel->types('hierarchy-type')->name('forum', 'message'); $sel->option('return')->value('id'); $result = $sel->length(); $label = $showTips ? getLabel('option-forum-message') : ''; $answer .= self::getWidgetPart('forums_messages', $label, "{$host}/images/cms/admin/toolbar/forum_messages.png", "{$host}/admin/forum/last_messages/", $result, $comma); $comma = true; } } } else { $answer .= <<<EOD { "id": "auth", "appearance": { "type": "combined", "label": "Войти", "icon": "{$host}/images/cms/admin/toolbar/umi.png" }, "onclick": { "action": "openurl", "params": { "url": "{$host}/admin/" } } } EOD; } $answer .= "\n\t]\n}"; $buffer->push($answer); $buffer->end(); }
/** * @desc */ private function placeComments($parentId, $templateString, umiHierarchy $hierarchy, $commentHType, &$total) { static $postHType = 0; if (!$postHType) { $postHType = umiHierarchyTypesCollection::getInstance()->getTypeByName('blogs20', 'post')->getId(); } $parent = $hierarchy->getElement($parentId, true); if (!$parent instanceof umiHierarchyElement) { throw new publicException("Unknown parent element for comments"); } $rootComments = $parent->getTypeId() == $postHType; $sel = new selector('pages'); $sel->where('hierarchy')->page($parentId)->childs(1); $sel->types('hierarchy-type')->id($commentHType); $sel->where('is_spam')->notequals(1); if ($rootComments) { $page = (int) getRequest('p'); $sel->limit($page * $this->comments_per_page, $this->comments_per_page); } $result = $sel->result(); $total = $sel->length(); $aLines = array(); foreach ($result as $oComment) { $commentId = $oComment->getId(); $temp = 0; $pubTime = $oComment->getValue('publish_time'); $aLineParam = array(); $aLineParam['attribute:cid'] = $commentId; $aLineParam['name'] = $oComment->getName(); $aLineParam['content'] = $this->prepareContent($oComment->getValue('content')); $aLineParam['author_id'] = $oComment->getValue('author_id'); $aLineParam['publish_time'] = $pubTime instanceof umiDate ? $pubTime->getFormattedDate('U') : time(); $aLineParam['subnodes:subcomments'] = $this->placeComments($commentId, $templateString, $hierarchy, $commentHType, $temp); $aLines[] = self::parseTemplate($templateString, $aLineParam, $commentId); } return $aLines; }