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

+ 9 - 1
inc/classes/BxDolPrivacy.php

@@ -70,7 +70,8 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         $this->_aObject = $aObject;
         $this->_sObject = $aObject['object'];
 
-        $this->_oDb = new BxDolPrivacyQuery($this->_aObject);
+        $this->_oDb = new BxDolPrivacyQuery();
+        $this->_oDb->init($this->_aObject);
     }
 
     /**
@@ -280,6 +281,13 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return BxDolConnection::getObjectInstance('sys_profiles_friends')->isConnected($iOwnerId, $iViewerId, true);
     }
 
+    public function setTableFieldAuthor($sValue)
+    {
+        $this->_aObject['table_field_author'] = $sValue;
+
+        $this->_oDb->init($this->_aObject);
+    }
+
 	protected function getPrivacyGroupsForContentPublic($iProfileIdOwner = 0, $aCustomGroups = array())
     {
     	$aGroups = array(BX_DOL_PG_ALL);

+ 14 - 8
inc/classes/BxDolPrivacyQuery.php

@@ -24,16 +24,10 @@ class BxDolPrivacyQuery extends BxDolDb
 
     protected $_sCacheTestedObject;
 
-    public function __construct($aObject = array())
+    public function __construct()
     {
         parent::__construct();
-        $this->_aObject = $aObject;
-
-        if(!empty($this->_aObject)) {
-            $this->_sTable = $this->_aObject['table'];
-            $this->_sFieldId = $this->_aObject['table_field_id'];
-            $this->_sFieldOwnerId = $this->_aObject['table_field_author'];
-        }
+        $this->_aObject = array();
 
         $this->_sCachePrivacyObject = 'sys_privacy_object_';
         $this->_sCachePrivacyObjectDefault = 'sys_privacy_object_default_';
@@ -58,6 +52,18 @@ class BxDolPrivacyQuery extends BxDolDb
         return $aObject;
     }
 
+    public function init($aObject = array())
+    {
+        if(empty($aObject) || !is_array($aObject)) 
+            return;
+
+        $this->_aObject = $aObject;
+
+        $this->_sTable = $this->_aObject['table'];
+        $this->_sFieldId = $this->_aObject['table_field_id'];
+        $this->_sFieldOwnerId = $this->_aObject['table_field_author'];
+    }
+
     function getObjectInfo($sAction, $iObjectId)
     {
         if(empty($this->_sTable) || empty($this->_sFieldId) || empty($this->_sFieldOwnerId))

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

@@ -16,11 +16,14 @@
 
 	<string name="_bx_timeline_form_post"><![CDATA[Сообщение]]></string>
 	<string name="_bx_timeline_form_post_display_add"><![CDATA[Написать сообщение]]></string>
+	<string name="_bx_timeline_form_post_display_add_public"><![CDATA[Написать публичное сообщение]]></string>
 	<string name="_bx_timeline_form_post_input_sys_owner_id"><![CDATA[ID владельца]]></string>
 	<string name="_bx_timeline_form_post_input_sys_action"><![CDATA[Действие]]></string>
 	<string name="_bx_timeline_form_post_input_sys_type"><![CDATA[Тип]]></string>
 	<string name="_bx_timeline_form_post_input_sys_text"><![CDATA[Содержимое]]></string>
 	<string name="_bx_timeline_form_post_input_text"><![CDATA[]]></string>
+    <string name="_bx_timeline_form_post_input_sys_object_privacy_view"><![CDATA[Видимость]]></string>
+    <string name="_bx_timeline_form_post_input_object_privacy_view"><![CDATA[Видимость]]></string>
 	<string name="_bx_timeline_form_post_input_sys_link"><![CDATA[Ссылка]]></string>
 	<string name="_bx_timeline_form_post_input_link_alt"><![CDATA[Добавить ссылку]]></string>
 	<string name="_bx_timeline_form_post_input_link_err_delete"><![CDATA[Невозможно удалить ссылку. Пожалуйста, оповестите нас о проблеме.]]></string>

+ 1 - 0
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -98,6 +98,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         	'form_post' => $this->_sName . '_post',
         	'form_attach_link' => $this->_sName . '_attach_link',
         	'form_display_post_add' => $this->_sName . '_post_add',
+        	'form_display_post_add_public' => $this->_sName . '_post_add_public',
         	'form_display_attach_link_add' => $this->_sName . '_attach_link_add'
         ));
 

+ 6 - 5
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -370,13 +370,14 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 		if($sWhereModuleFilter != '')
 			$sWhereClause .= $sWhereModuleFilter;
 
-		//--- Apply privacy filter
-		$oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
-		$aQueryParts = $oPrivacy->getContentByGroupAsSQLPart(BX_DOL_PG_ALL);
-		$sWhereClause .= $aQueryParts['where'] . " ";
-
 		//--- Check type
 		switch($aParams['type']) {
+		    case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
+		        //--- Apply privacy filter
+        		$aQueryParts = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'))->getContentByGroupAsSQLPart(BX_DOL_PG_ALL);
+        		$sWhereClause .= $aQueryParts['where'] . " ";
+		        break;
+
 			case BX_BASE_MOD_NTFS_TYPE_OWNER:
 				if(empty($aParams['owner_id']))
 					break;

+ 15 - 0
modules/boonex/timeline/classes/BxTimelineFormPost.php

@@ -14,6 +14,8 @@
  */
 class BxTimelineFormPost extends BxBaseModGeneralFormEntry
 {
+    protected $_bPublicMode;
+
     public function __construct($aInfo, $oTemplate = false)
     {
         $this->MODULE = 'bx_timeline';
@@ -23,9 +25,22 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
         $iUserId = $this->_oModule->getUserId();
         $iOwnerId = $this->_oModule->getOwnerId();
 
+        $this->_bPublicMode = isset($this->aParams['display']) && $this->aParams['display'] == $this->_oModule->_oConfig->getObject('form_display_post_add_public');
+
 		$this->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'post/';
         $this->aInputs['owner_id']['value'] = $iOwnerId;
 
+        if(isset($this->aInputs['object_privacy_view'])) {
+            $this->aInputs['object_privacy_view'] = array_merge($this->aInputs['object_privacy_view'], BxDolPrivacy::getGroupChooser($this->_oModule->_oConfig->getObject('privacy_view'), 0, array(
+                'title' => _t('_bx_timeline_form_post_input_object_privacy_view')
+            )));
+
+            if($this->_bPublicMode)
+                foreach($this->aInputs['object_privacy_view']['values'] as $iKey => $aValue)
+                    if($aValue['key'] !== BX_DOL_PG_ALL)
+                        unset($this->aInputs['object_privacy_view']['values'][$iKey]);
+        }
+
         if(isset($this->aInputs['link']))
             $this->aInputs['link']['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId);
 

+ 15 - 6
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -419,7 +419,9 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     public function serviceGetBlockPostHome()
     {
         $iProfileId = 0;
-        return $this->_getBlockPost($iProfileId);
+        return $this->_getBlockPost($iProfileId, array(
+            'form_display' => 'form_display_post_add_public'
+        ));
     }
 
     public function serviceGetBlockPostAccount()
@@ -719,11 +721,13 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
     }
 
-    public function getFormPost()
+    public function getFormPost($aParams = array())
     {
         $iUserId = $this->getUserId();
 
-        $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_add'), $this->_oTemplate);
+        $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
+        $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
+        $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
 
         $oForm->initChecker();
         if($oForm->isSubmittedAndValid()) {
@@ -744,6 +748,11 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             if($bText)
             	$aContent['text'] = $sText;
 
+            //--- Process Privacy ---//
+            $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
+            if(empty($iObjectPrivacyView))
+                $iObjectPrivacyView = $this->_oConfig->getPrivacyViewDefault('object');
+
             //--- Process Link ---//
             $aLinkIds = $oForm->getCleanValue('link');
             $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
@@ -764,7 +773,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
             $iId = $oForm->insert(array(
                 'object_id' => $iUserId,
-                'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
+                'object_privacy_view' => $iObjectPrivacyView,
                 'content' => serialize($aContent),
                 'title' => $sTitle,
                 'description' => $sDescription,
@@ -1301,14 +1310,14 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         return array('content' => $sContent);
     }
 
-    protected function _getBlockPost($iProfileId)
+    protected function _getBlockPost($iProfileId, $aParams = array())
     {
         $this->_iOwnerId = $iProfileId;
 
         if($this->isAllowedPost() !== true)
             return array();
 
-		$sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
+		$sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
         return array('content' => $sContent);
     }
 

+ 9 - 2
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -43,9 +43,9 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         ));
     }
 
-    public function getPostBlock($iOwnerId)
+    public function getPostBlock($iOwnerId, $aParams = array())
     {
-        $aForm = $this->getModule()->getFormPost();
+        $aForm = $this->getModule()->getFormPost($aParams);
 
         return $this->parseHtmlByName('block_post.html', array (
             'style_prefix' => $this->_oConfig->getPrefix('style'),
@@ -160,6 +160,13 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
     public function getPost(&$aEvent, $aBrowseParams = array())
     {
+        $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
+        if($oPrivacy) {
+            $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
+            if(!$oPrivacy->check($aEvent['id']))
+                return '';
+        }
+
         $aResult = $this->getData($aEvent);
         if($aResult === false)
             return '';

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

@@ -16,11 +16,14 @@
 
 	<string name="_bx_timeline_form_post"><![CDATA[Post]]></string>
 	<string name="_bx_timeline_form_post_display_add"><![CDATA[Write Post]]></string>
+	<string name="_bx_timeline_form_post_display_add_public"><![CDATA[Write Public Post]]></string>
 	<string name="_bx_timeline_form_post_input_sys_owner_id"><![CDATA[Owner ID]]></string>
 	<string name="_bx_timeline_form_post_input_sys_action"><![CDATA[Action]]></string>
 	<string name="_bx_timeline_form_post_input_sys_type"><![CDATA[Type]]></string>
 	<string name="_bx_timeline_form_post_input_sys_text"><![CDATA[Content]]></string>
 	<string name="_bx_timeline_form_post_input_text"><![CDATA[]]></string>
+	<string name="_bx_timeline_form_post_input_sys_object_privacy_view"><![CDATA[Visibility]]></string>
+    <string name="_bx_timeline_form_post_input_object_privacy_view"><![CDATA[Visibility]]></string>
 	<string name="_bx_timeline_form_post_input_sys_link"><![CDATA[Link]]></string>
 	<string name="_bx_timeline_form_post_input_link_alt"><![CDATA[Add Link]]></string>
 	<string name="_bx_timeline_form_post_input_link_err_delete"><![CDATA[Cannot remove the link. Please report.]]></string>

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

@@ -127,7 +127,7 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 
 -- PRIVACY 
 INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
-('bx_timeline_privacy_view', 'bx_timeline', 'view', '_bx_timeline_privacy_view', '3', 'bx_timeline_events', 'id', 'owner_id', 'BxTimelinePrivacy', 'modules/boonex/timeline/classes/BxTimelinePrivacy.php');
+('bx_timeline_privacy_view', 'bx_timeline', 'view', '_bx_timeline_privacy_view', '3', 'bx_timeline_events', 'id', '', 'BxTimelinePrivacy', 'modules/boonex/timeline/classes/BxTimelinePrivacy.php');
 
 
 -- ACL

+ 22 - 7
modules/boonex/timeline/install/sql/install.sql

@@ -277,13 +277,15 @@ INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_att
 ('bx_timeline_post', @sName, '_bx_timeline_form_post', '', '', 'do_submit', 'bx_timeline_events', 'id', '', '', '', 0, 1, 'BxTimelineFormPost', 'modules/boonex/timeline/classes/BxTimelineFormPost.php');
 
 INSERT INTO `sys_form_displays` (`display_name`, `module`, `object`, `title`, `view_mode`) VALUES
-('bx_timeline_post_add', @sName, 'bx_timeline_post', '_bx_timeline_form_post_display_add', 0);
+('bx_timeline_post_add', @sName, 'bx_timeline_post', '_bx_timeline_form_post_display_add', 0),
+('bx_timeline_post_add_public', @sName, 'bx_timeline_post', '_bx_timeline_form_post_display_add_public', 0);
 
 INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES
 ('bx_timeline_post', @sName, 'type', 'post', '', 0, 'hidden', '_bx_timeline_form_post_input_sys_type', '', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
 ('bx_timeline_post', @sName, 'action', '', '', 0, 'hidden', '_bx_timeline_form_post_input_sys_action', '', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
 ('bx_timeline_post', @sName, 'owner_id', '0', '', 0, 'hidden', '_bx_timeline_form_post_input_sys_owner_id', '', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 0, 0),
 ('bx_timeline_post', @sName, 'text', '', '', 0, 'textarea', '_bx_timeline_form_post_input_sys_text', '_bx_timeline_form_post_input_text', '', 0, 0, 0, 'a:1:{s:12:"autocomplete";s:3:"off";}', '', '', '', '', '', 'Xss', '', 1, 0),
+('bx_timeline_post', @sName, 'object_privacy_view', '', '', 0, 'custom', '_bx_timeline_form_post_input_sys_object_privacy_view', '_bx_timeline_form_post_input_object_privacy_view', '', 1, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_timeline_post', @sName, 'location', '', '', 0, 'location', '_sys_form_input_sys_location', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_timeline_post', @sName, 'link', '', '', 0, 'custom', '_bx_timeline_form_post_input_sys_link', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_timeline_post', @sName, 'photo', 'a:1:{i:0;s:24:"bx_timeline_simple_photo";}', 'a:1:{s:24:"bx_timeline_simple_photo";s:26:"_sys_uploader_simple_title";}', 0, 'files', '_bx_timeline_form_post_input_sys_photo', '_bx_timeline_form_post_input_photo', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
@@ -296,12 +298,25 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('bx_timeline_post_add', 'action', 2147483647, 1, 2),
 ('bx_timeline_post_add', 'owner_id', 2147483647, 1, 3),
 ('bx_timeline_post_add', 'text', 2147483647, 1, 4),
-('bx_timeline_post_add', 'location', 2147483647, 1, 5),
-('bx_timeline_post_add', 'link', 2147483647, 1, 6),
-('bx_timeline_post_add', 'photo', 2147483647, 1, 7),
-('bx_timeline_post_add', 'video', 2147483647, 1, 8),
-('bx_timeline_post_add', 'attachments', 2147483647, 1, 9),
-('bx_timeline_post_add', 'do_submit', 2147483647, 1, 10);
+('bx_timeline_post_add', 'object_privacy_view', 2147483647, 1, 5),
+('bx_timeline_post_add', 'location', 2147483647, 1, 6),
+('bx_timeline_post_add', 'link', 2147483647, 1, 7),
+('bx_timeline_post_add', 'photo', 2147483647, 1, 8),
+('bx_timeline_post_add', 'video', 2147483647, 1, 9),
+('bx_timeline_post_add', 'attachments', 2147483647, 1, 10),
+('bx_timeline_post_add', 'do_submit', 2147483647, 1, 11),
+
+('bx_timeline_post_add_public', 'type', 2147483647, 1, 1),
+('bx_timeline_post_add_public', 'action', 2147483647, 1, 2),
+('bx_timeline_post_add_public', 'owner_id', 2147483647, 1, 3),
+('bx_timeline_post_add_public', 'text', 2147483647, 1, 4),
+('bx_timeline_post_add_public', 'object_privacy_view', 2147483647, 1, 5),
+('bx_timeline_post_add_public', 'location', 2147483647, 1, 6),
+('bx_timeline_post_add_public', 'link', 2147483647, 1, 7),
+('bx_timeline_post_add_public', 'photo', 2147483647, 1, 8),
+('bx_timeline_post_add_public', 'video', 2147483647, 1, 9),
+('bx_timeline_post_add_public', 'attachments', 2147483647, 1, 10),
+('bx_timeline_post_add_public', 'do_submit', 2147483647, 1, 11);
 
 -- Forms -> Attach link
 INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_attrs`, `submit_name`, `table`, `key`, `uri`, `uri_title`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES