AntonLV 6 년 전
부모
커밋
131127b598

+ 44 - 5
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -1555,15 +1555,15 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         if(!$iItemId)
             return array();
 
-        $aParams = array(
+        $aParams = $this->_prepareParams(array(
             'view' => BX_TIMELINE_VIEW_ITEM, 
             'type' => BX_TIMELINE_TYPE_ITEM
-        );
-        $aParams = $this->_prepareParams($aParams);
+        ));
 
-        return $this->_oTemplate->getItemBlock($iItemId, $aParams);
+        $aItemData = $this->getItemData($iItemId, $aParams);
+        return $this->_oTemplate->getItemBlock($aItemData, $aParams);
     }
-
+    
     public function serviceGetBlockItemContent()
     {
         $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
@@ -2473,6 +2473,45 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     /*
      * COMMON METHODS
      */
+    public function getItemData($iId, $aParams = array())
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(empty($aParams))
+            $aParams = $this->_prepareParams(array(
+                'view' => BX_TIMELINE_VIEW_ITEM, 
+                'type' => BX_TIMELINE_TYPE_ITEM
+            ));
+
+        $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
+        if(empty($aEvent))
+            return array('code' => 1, 'content' => _t('_Empty'));
+
+        $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
+        if(!empty($iProfile)) {
+            $oProfile = BxDolProfile::getInstance($iProfile);
+            if(!$oProfile)
+                return array('code' => 1, 'content' => _t('_Empty'));
+
+            $mixedResult = $oProfile->checkAllowedProfileView();
+            if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
+                return array('code' => 2, 'content' => $mixedResult);
+        }
+
+        $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
+        if(empty($sContent))
+            return array('code' => 2, 'content' => _t('_Access denied'));
+
+        $sKey = 'allowed_view';
+        if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED) 
+            return array('code' => 2, 'content' => $aEvent[$sKey]);
+
+        if($this->isAllowedView($aEvent) !== true)
+            return array('code' => 2, 'content' => _t('_Access denied'));
+
+        return array('code' => 0, 'content' => $sContent, 'event' => $aEvent);
+    }
+
     public function deleteEvent($aEvent)
     {
     	if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))

+ 51 - 0
modules/boonex/timeline/classes/BxTimelinePageViewItem.php

@@ -0,0 +1,51 @@
+<?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
+ *
+ * @{
+ */
+
+class BxTimelinePageViewItem extends BxBaseModTextPageAuthor
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    protected $_iItemId;
+
+    public function __construct($aObject, $oTemplate = false)
+    {
+        $this->_sModule = 'bx_timeline';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+
+        parent::__construct($aObject, $this->_oModule->_oTemplate);
+
+        $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
+        if(!$iItemId) 
+            return;
+
+        $this->_iItemId = $iItemId;
+    }
+    
+    public function getCode()
+    {
+        $aItemData = $this->_oModule->getItemData($this->_iItemId);
+
+        if(empty($aItemData) || !is_array($aItemData)) {
+            $this->_oTemplate->displayPageNotFound();
+            exit;
+        }
+
+        if($aItemData['code'] != 0) {
+            $this->_oTemplate->displayMsg($aItemData['content']);
+            exit;
+        }
+
+        return parent::getCode();
+    }
+}
+
+/** @} */

+ 19 - 23
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -12,6 +12,7 @@
 class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 {
     protected static $_aMemoryCacheItems;
+    protected static $_aMemoryCacheItemsData;
     protected static $_sMemoryCacheItemsKeyMask;
 
     protected static $_sTmplContentItemItem;
@@ -35,6 +36,7 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         parent::init();
 
         self::$_aMemoryCacheItems = array();
+        self::$_aMemoryCacheItemsData = array();
         self::$_sMemoryCacheItemsKeyMask = "%s_%d";
     }
 
@@ -239,34 +241,22 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         ));
     }
 
-    public function getItemBlock($iId, $aBrowseParams = array())
+    public function getItemBlock($mixedId, $aBrowseParams = array())
     {
         $CNF = $this->_oConfig->CNF;
+        $oModule = $this->getModule();
 
-        $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
-        if(empty($aEvent))
-            return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
-
-        $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
-        if(!empty($iProfile)) {
-            $oProfile = BxDolProfile::getInstance($iProfile);
-            if(!$oProfile)
-                return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
-
-            $mixedResult = $oProfile->checkAllowedProfileView();
-            if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
-                return array('content' => MsgBox($mixedResult), 'designbox_id' => 13);
-        }
+        if(is_numeric($mixedId))
+            $mixedId = $oModule->getItemData($mixedId);
 
-        $sContent = $this->getPost($aEvent, $aBrowseParams);
+        if(empty($mixedId) || !is_array($mixedId))
+            return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
 
-        $sKey = 'allowed_view';
-        if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED) 
-            return array('content' => MsgBox($aEvent[$sKey]), 'designbox_id' => 13);
+        if($mixedId['code'] != 0)
+            return array('content' => MsgBox($mixedId['content']), 'designbox_id' => 13);
 
-        $oModule = $this->getModule();
-        if($oModule->isAllowedView($aEvent) !== true)
-            return array('content' => MsgBox(_t('_Access denied')), 'designbox_id' => 13);
+        $aEvent = $mixedId['event'];
+        $sContent = $mixedId['content'];
 
         if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
             $mixedViews = $oModule->getViewsData($aEvent['views']);
@@ -408,13 +398,18 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
 
         $sMemoryCacheItemsKey = sprintf(self::$_sMemoryCacheItemsKeyMask, $aBrowseParams['view'], $iEventId);
-        if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItems))
+        if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItems)) {
+            if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItemsData))
+                $aEvent = self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey];
+
             return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
+        }
 
         /**
          * Add all items in memory cache even if they are empty.
          */
         self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = '';
+        self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = array();
 
         $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
         if($oPrivacy) {
@@ -465,6 +460,7 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
         $sType = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
         self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = $this->_getPost($sType, $aEvent, $aBrowseParams);
+        self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = $aEvent;
 
         return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
     }

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

@@ -4,8 +4,8 @@ INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `lay
 ('bx_timeline_view_home', '_bx_timeline_page_title_sys_view_home', '_bx_timeline_page_title_view_home', 'bx_timeline', 5, 2147483647, 1, 'timeline-view-home', 'page.php?i=timeline-view-home', '', '', '', 0, 1, 0, '', ''),
 ('bx_timeline_view_hot', '_bx_timeline_page_title_sys_view_hot', '_bx_timeline_page_title_view_hot', 'bx_timeline', 5, 2147483647, 1, 'timeline-view-hot', 'page.php?i=timeline-view-hot', '', '', '', 0, 1, 0, '', ''),
 
-('bx_timeline_item', '_bx_timeline_page_title_sys_item', '_bx_timeline_page_title_item', 'bx_timeline', 2, 2147483647, 1, 'item', 'page.php?i=item', '', '', '', 0, 1, 0, '', ''),
-('bx_timeline_item_brief', '_bx_timeline_page_title_sys_item_brief', '_bx_timeline_page_title_item_brief', 'bx_timeline', 2, 2147483647, 1, 'item-quick', 'page.php?i=item-quick', '', '', '', 0, 1, 0, '', '');
+('bx_timeline_item', '_bx_timeline_page_title_sys_item', '_bx_timeline_page_title_item', 'bx_timeline', 2, 2147483647, 1, 'item', 'page.php?i=item', '', '', '', 0, 1, 0, 'BxTimelinePageViewItem', 'modules/boonex/timeline/classes/BxTimelinePageViewItem.php'),
+('bx_timeline_item_brief', '_bx_timeline_page_title_sys_item_brief', '_bx_timeline_page_title_item_brief', 'bx_timeline', 2, 2147483647, 1, 'item-quick', 'page.php?i=item-quick', '', '', '', 0, 1, 0, 'BxTimelinePageViewItem', 'modules/boonex/timeline/classes/BxTimelinePageViewItem.php');
 
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
 ('bx_timeline_view', 1, 'bx_timeline', '_bx_timeline_page_block_title_system_post_profile', '_bx_timeline_page_block_title_post_profile', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:14:"get_block_post";}', 0, 0, 1, 1),