Преглед изворни кода

Ticket #515 - Attachable Email Templates feature in Convos module and its usage in Timeline -> Send to Friend.

AntonLV пре 9 година
родитељ
комит
62387ccee2

+ 1 - 0
install/sql/system.sql

@@ -235,6 +235,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_template_cache_image_max_size', '_adm_stg_cpt_option_sys_template_cache_image_max_size', '5', 'digit', '', '', '', 21),
 
 (@iCategoryId, 'sys_email_confirmation', '_adm_stg_cpt_option_sys_email_confirmation', 'on', 'checkbox', '', '', '', 30),
+(@iCategoryId, 'sys_email_attachable_email_templates', '_adm_stg_cpt_option_sys_email_attachable_email_templates', '', 'digit', '', '', '', 31),
 
 (@iCategoryId, 'sys_redirect_after_account_added', '_adm_stg_cpt_option_sys_redirect_after_account_added', 'page.php?i=account-profile-switcher', 'digit', '', '', '', 40),
 

+ 24 - 1
modules/boonex/convos/classes/BxCnvFormEntry.php

@@ -140,7 +140,30 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
             $a = array_unique(BxDolFormCheckerHelper::passInt($a));
             if ($a)
                 $aValues['recipients'] = array_merge(empty($aValues['recipients']) ? array() : $aValues['recipients'], $a);            
-        }        
+        }
+
+        $sEt = bx_get('et');
+        if($sEt !== false) { // if 'attachable email template' was specified, process it
+            $aEt = unserialize(base64_decode(urldecode($sEt)));
+
+            if(!empty($aEt) && is_array($aEt) && !empty($aEt['name'])) {
+                $sName = bx_process_input($aEt['name']);
+                $aParams = isset($aEt['params']) ? bx_process_input($aEt['params']) : array();
+
+                $sAet = getParam('sys_email_attachable_email_templates');
+                if(strpos($sAet, $sName) !== false) {
+                    $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($sName, $aParams);
+                    if(!empty($aTemplate) && is_array($aTemplate)) {
+                        if(isset($this->aInputs[$CNF['FIELD_TITLE']]) && empty($this->aInputs[$CNF['FIELD_TITLE']]['value']))
+                            $this->aInputs[$CNF['FIELD_TITLE']]['value'] = $aTemplate['Subject'];
+
+                        if(isset($this->aInputs[$CNF['FIELD_TEXT']]) && empty($this->aInputs[$CNF['FIELD_TEXT']]['value']))
+                            $this->aInputs[$CNF['FIELD_TEXT']]['value'] = $aTemplate['Body'];
+                    }
+                }
+            }
+            
+        }
 
         return parent::initChecker ($aValues, $aSpecificValues);
     }

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1218,6 +1218,7 @@
 	<string name="_adm_stg_cpt_option_sys_cache_memcache_port"><![CDATA[Memcached server port]]></string>
 	<string name="_adm_stg_cpt_option_sys_captcha_default"><![CDATA[Сaptcha object]]></string>
 	<string name="_adm_stg_cpt_option_sys_email_confirmation"><![CDATA[Enable email confirmation]]></string>
+	<string name="_adm_stg_cpt_option_sys_email_attachable_email_templates"><![CDATA[Attachable email templates list]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Enable DB cache]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_engine"><![CDATA[DB cache engine (other than File option may require custom server setup)]]></string>
 	<string name="_adm_stg_cpt_option_sys_default_payment"><![CDATA[Payment module]]></string>

+ 8 - 0
modules/boonex/russian/data/langs/bx_timeline/ru.xml

@@ -153,5 +153,13 @@
 	<string name="_bx_timeline_txt_err_already_reposted"><![CDATA[Вы уже сделали репост этого элемента.]]></string>
 	<string name="_bx_timeline_txt_msg_success_repost"><![CDATA[Репост данного элемента был сделан успешно.]]></string>
 
+    <!-- EMAIL TEMPLATES -->
+    <string name="_bx_timeline_et_txt_name_send"><![CDATA[Послать другу.]]></string>
+    <string name="_bx_timeline_et_txt_subject_send"><![CDATA[Это может быть интересно для вас.]]></string>
+    <string name="_bx_timeline_et_txt_body_send"><![CDATA[{email_header}
+<p>Привет.</p>
+<p>Взгляните на <a href="{ViewLink}">это сообщение</a>, оно может быть интересно для вас.</p>
+{email_footer}]]></string>
+
 	<string name="_bx_ntfs_alert_action_post_common"><![CDATA[добавить сообщение]]></string>
 </resources>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1216,6 +1216,7 @@
 	<string name="_adm_stg_cpt_option_sys_cache_memcache_port"><![CDATA[Memcached - порт сервера]]></string>
 	<string name="_adm_stg_cpt_option_sys_captcha_default"><![CDATA[Объект CAPTCHA]]></string>
 	<string name="_adm_stg_cpt_option_sys_email_confirmation"><![CDATA[Задействовать подтверждение эл. адреса]]></string>
+	<string name="_adm_stg_cpt_option_sys_email_attachable_email_templates"><![CDATA[Список присоединяемых имейл темплейтов]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Задействовать кэш БД]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_engine"><![CDATA[Кэш-движок для БД (значение, отличное от File, может потребовать дополнительной настройки сервера)]]></string>
 	<string name="_adm_stg_cpt_option_sys_default_payment"><![CDATA[Модуль оплаты]]></string>

+ 106 - 0
modules/boonex/timeline/classes/BxTimelineMenuItemShare.php

@@ -0,0 +1,106 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Timeline Timeline
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+/**
+ * 'Item' menu.
+ */
+class BxTimelineMenuItemShare extends BxTemplMenu
+{
+    protected $_oModule;
+
+	protected $_iEvent;
+	protected $_aEvent;
+
+    public function __construct($aObject, $oTemplate = false)
+    {
+        parent::__construct($aObject, $oTemplate);
+
+        $this->_oModule = BxDolModule::getInstance('bx_timeline');
+
+        if(bx_get('content_id') !== false)
+        	$this->setEventId((int)bx_get('content_id'));
+    }
+
+    public function setEventId($iEventId)
+    {
+    	$this->_iEvent = $iEventId;
+    	$this->_aEvent = $this->_oModule->_oDb->getEvents(array('browse' => 'id', 'value' => $this->_iEvent));
+        $bEvent = !empty($this->_aEvent) && is_array($this->_aEvent);
+    	
+    	//--- Repost item
+    	$sRepostOnclick = '';
+    	if($bEvent) {
+        	$iOwnerId = $this->_oModule->getUserId(); //--- in whose timeline the content will be reposted
+            $sType = $this->_aEvent['type'];
+            $sAction = $this->_aEvent['action'];
+            $iObjectId = $this->_oModule->_oConfig->isSystem($sType, $sAction) ? $this->_aEvent['object_id'] : $this->_aEvent['id'];
+
+            $sRepostOnclick = $this->_oModule->serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
+    	}
+
+    	//--- Send item
+    	$sEtSend = '';
+    	if($bEvent) {
+    	    $aEt = array(
+    	        'name' => 'bx_timeline_send',
+    	        'params' => array(
+    	            'ViewLink' => $this->_oModule->_oConfig->getItemViewUrl($this->_aEvent)
+    	        )
+    	    );
+
+    	    $sAetSend = urlencode(base64_encode(serialize($aEt))); 
+    	}
+
+    	$this->addMarkers(array(
+        	'js_object_view' => $this->_oModule->_oConfig->getJsObject('view'),
+
+        	'content_id' => $this->_iEvent,
+
+    	    'js_onclick_repost' => $sRepostOnclick,
+    		'et_send' => $sAetSend
+    	));
+    }
+
+    /**
+     * Check if menu items is visible.
+     * @param $a menu item array
+     * @return boolean
+     */
+    protected function _isVisible ($a)
+    {
+        if(!parent::_isVisible($a))
+            return false;
+
+		if(empty($this->_aEvent) || !is_array($this->_aEvent))
+			return false;
+
+        $sCheckFuncName = '';
+        $aCheckFuncParams = array();
+        switch ($a['name']) {
+        	case 'item-repost':
+                $sCheckFuncName = 'isAllowedRepost';
+				$aCheckFuncParams = array($this->_aEvent);
+                break;
+
+			case 'item-send':
+                $sCheckFuncName = 'isAllowedSend';
+				$aCheckFuncParams = array($this->_aEvent);
+                break;
+        }
+
+        if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))
+            return true;
+
+        return call_user_func_array(array($this->_oModule, $sCheckFuncName), $aCheckFuncParams) === true;
+    }
+}
+
+/** @} */

+ 41 - 0
modules/boonex/timeline/install/installer.php

@@ -17,6 +17,47 @@ class BxTimelineInstaller extends BxBaseModNotificationsInstaller
     {
         parent::__construct($aConfig);
     }
+
+    public function enable($aParams)
+    {
+        $aResult = parent::enable($aParams);
+        if($aResult['result'])
+            $this->updateParamAET(true);
+
+        return $aResult;
+    }
+
+    public function disable($aParams)
+    {
+        $aResult = parent::disable($aParams);
+        if($aResult['result'])
+            $this->updateParamAET(false);
+        
+        return $aResult;
+    }
+
+    protected function updateParamAET($bAdd)
+    {
+        $sAetDivider = ',';
+        $sAetName = 'bx_timeline_send';
+
+        $sAetParam = 'sys_email_attachable_email_templates';
+        $sAetParamValue = getParam($sAetParam);
+
+        if($bAdd)
+            $sAetParamValue = trim($sAetParamValue . $sAetDivider . $sAetName, $sAetDivider);
+        else {
+            $aAet = explode($sAetDivider, $sAetParamValue);
+
+            $mixedKey = array_search($sAetName, $aAet);
+            if($mixedKey !== false) {
+                unset($aAet[$mixedKey]);
+                $sAetParamValue = implode($sAetDivider, $aAet);
+            }
+        }
+
+        return setParam($sAetParam, $sAetParamValue);
+    }
 }
 
 /** @} */

+ 7 - 0
modules/boonex/timeline/install/langs/en.xml

@@ -153,5 +153,12 @@
 	<string name="_bx_timeline_txt_err_already_reposted"><![CDATA[You already reposted the item.]]></string>
 	<string name="_bx_timeline_txt_msg_success_repost"><![CDATA[The item was successfully reposted.]]></string>
 
+    <!-- EMAIL TEMPLATES -->
+    <string name="_bx_timeline_et_txt_name_send"><![CDATA[Send to Friend.]]></string>
+    <string name="_bx_timeline_et_txt_subject_send"><![CDATA[It may be interesting for you.]]></string>
+    <string name="_bx_timeline_et_txt_body_send"><![CDATA[
+<p>Hello.</p>
+<p>Take a look at <a href="{ViewLink}">this post</a>, it may be interesting for you.</p>]]></string>
+
 	<string name="_bx_ntfs_alert_action_post_common"><![CDATA[add post]]></string>
 </resources>

+ 4 - 0
modules/boonex/timeline/install/sql/disable.sql

@@ -54,3 +54,7 @@ DELETE FROM `sys_objects_search` WHERE `ObjectName` IN ('bx_timeline', 'bx_timel
 
 -- METATAGS
 DELETE FROM `sys_objects_metatags` WHERE `object` = 'bx_timeline';
+
+
+-- EMAIL TEMPLATES
+DELETE FROM `sys_email_templates` WHERE `Module` = 'bx_timeline';

+ 6 - 1
modules/boonex/timeline/install/sql/enable.sql

@@ -47,7 +47,7 @@ INSERT INTO `sys_menu_sets`(`set_name`, `module`, `title`, `deletable`) VALUES
 
 INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
 ('bx_timeline_menu_item_share', 'bx_timeline', 'item-repost', '_bx_timeline_menu_item_title_system_item_repost', '_bx_timeline_menu_item_title_item_repost', 'javascript:void(0)', 'javascript:{js_onclick_repost}', '_self', 'repeat', '', 2147483647, 1, 0, 1),
-('bx_timeline_menu_item_share', 'bx_timeline', 'item-send', '_bx_timeline_menu_item_title_system_item_send', '_bx_timeline_menu_item_title_item_send', 'javascript:void(0)', 'javascript:{js_onclick_send}', '_self', 'envelope', '', 2147483647, 1, 0, 2);
+('bx_timeline_menu_item_share', 'bx_timeline', 'item-send', '_bx_timeline_menu_item_title_system_item_send', '_bx_timeline_menu_item_title_item_send', 'page.php?i=start-convo&et={et_send}', '', '_self', 'envelope', '', 2147483647, 1, 0, 2);
 
 -- MENU: Item Manage (Pin, Delete, etc)
 INSERT INTO `sys_objects_menu`(`object`, `title`, `set_name`, `module`, `template_id`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES 
@@ -234,3 +234,8 @@ INSERT INTO `sys_objects_search` (`ObjectName`, `Title`, `Order`, `ClassName`, `
 -- METATAGS
 INSERT INTO `sys_objects_metatags` (`object`, `table_keywords`, `table_locations`, `table_mentions`, `override_class_name`, `override_class_file`) VALUES
 ('bx_timeline', 'bx_timeline_meta_keywords', 'bx_timeline_meta_locations', '', '', '');
+
+
+-- EMAIL TEMPLATES
+INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `Body`) VALUES 
+('bx_timeline', '_bx_timeline_et_txt_name_send', 'bx_timeline_send', '_bx_timeline_et_txt_subject_send', '_bx_timeline_et_txt_body_send');