Ver código fonte

Ticket #367 - Related changes in core files.

AntonLV 10 anos atrás
pai
commit
dc45009327

+ 13 - 4
inc/classes/BxDolCmts.php

@@ -137,9 +137,6 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
     protected $_sFormDisplayPost;
     protected $_sFormDisplayEdit;
 
-    protected $_sTableImages;
-    protected $_sTableImages2Entries;
-
     protected $_sConnObjFriends;
     protected $_sConnObjSubscriptions;
 
@@ -434,6 +431,18 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
 		return 'cmts-notification-' . $this->_sSystem . '-' . $this->_iId;
 	}
 
+	public function setTableNameFiles($sTable)
+    {
+    	$this->_aSystem['table_images'] = $sTable;
+    	$this->_oQuery->setTableNameFiles($sTable);
+    }
+
+	public function setTableNameFiles2Entries($sTable)
+    {
+    	$this->_aSystem['table_images2entries'] = $sTable;
+    	$this->_oQuery->setTableNameFiles2Entries($sTable);
+    }
+
     public function isNl2br ()
     {
         return $this->_aSystem['nl2br'];
@@ -799,7 +808,7 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
 
             $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
 
-            $aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']);
+            $aImages = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
             foreach($aImages as $aImage)
                 $oStorage->deleteFile($aImage['image_id']);
 

+ 37 - 19
inc/classes/BxDolCmtsQuery.php

@@ -21,8 +21,8 @@ class BxDolCmtsQuery extends BxDolDb
     protected $_sTriggerFieldTitle;
     protected $_sTriggerFieldComments;
 
-    protected $_sTableImages;
-    protected $_sTableImages2Entries;
+    protected $_sTableFiles;
+    protected $_sTableFiles2Entries;
 
     protected $_sTableIds;
 
@@ -38,8 +38,8 @@ class BxDolCmtsQuery extends BxDolDb
         $this->_sTriggerFieldTitle = $aSystem['trigger_field_title'];
         $this->_sTriggerFieldComments = $aSystem['trigger_field_comments'];
 
-        $this->_sTableImages = $aSystem['table_images'];
-        $this->_sTableImages2Entries = $aSystem['table_images2entries'];
+        $this->_sTableFiles = $aSystem['table_images'];
+        $this->_sTableFiles2Entries = $aSystem['table_images2entries'];
 
         $this->_sTableIds = $aSystem['table_ids'];
 
@@ -50,7 +50,17 @@ class BxDolCmtsQuery extends BxDolDb
     {
         return $this->_sTable;
     }
-    
+
+    function setTableNameFiles($sTable)
+    {
+    	$this->_sTableFiles = $sTable;
+    }
+
+	function setTableNameFiles2Entries($sTable)
+    {
+    	$this->_sTableFiles2Entries = $sTable;
+    }
+
     function getCommentsCountAll ($iId)
     {
         $sQuery = $this->prepare("SELECT `{$this->_sTriggerFieldComments}` FROM `{$this->_sTriggerTable}` WHERE `{$this->_sTriggerFieldId}` = ?", $iId);
@@ -249,33 +259,41 @@ class BxDolCmtsQuery extends BxDolDb
 
     function saveImages($iSystemId, $iCmtId, $iImageId)
     {
-        $sQuery = $this->prepare("INSERT IGNORE INTO `{$this->_sTableImages2Entries}` SET `system_id`=?, `cmt_id`=?, `image_id`=?", $iSystemId, $iCmtId, $iImageId);
+        $sQuery = $this->prepare("INSERT IGNORE INTO `{$this->_sTableFiles2Entries}` SET `system_id`=?, `cmt_id`=?, `image_id`=?", $iSystemId, $iCmtId, $iImageId);
         return (int)$this->query($sQuery) > 0;
     }
 
-    function getImages($iSystemId, $iCmtId, $iId = false)
+    function getFiles($iSystemId, $iCmtId, $iId = false)
     {
     	$aBindings = array(
     		'system_id' => $iSystemId
     	);
 
         $sJoin = "";
-        $sWhere = " AND `i`.`system_id` = :system_id ";
+        $sWhere = " AND `tf2e`.`system_id` = :system_id ";
 
-        if (false !== $iCmtId) {
+        if($iCmtId !== false) {
         	$aBindings['cmt_id'] = $iCmtId;
 
-            $sWhere .= " AND `i`.`cmt_id` = :cmt_id ";
+            $sWhere .= " AND `tf2e`.`cmt_id` = :cmt_id ";
         }
 
-        if (false !== $iId) {
+        if($iId !== false) {
         	$aBindings['cmt_object_id'] = $iId;
 
-            $sWhere .= " AND `c`.`cmt_object_id` = :cmt_object_id";
-            $sJoin .= " INNER JOIN `{$this->_sTable}` AS `c` ON (`i`.`cmt_id` = `c`.`cmt_id`) ";
+            $sWhere .= " AND `te`.`cmt_object_id` = :cmt_object_id";
+            $sJoin .= " INNER JOIN `{$this->_sTable}` AS `te` ON (`tf2e`.`cmt_id` = `te`.`cmt_id`) ";
         }
 
-        return $this->getAll("SELECT * FROM `{$this->_sTableImages2Entries}` AS `i` " . $sJoin . " WHERE 1 " . $sWhere, $aBindings);
+        $sQuery = "SELECT 
+        		`tf2e`.*,
+        		`tf`.`file_name` AS `file_name`,
+        		`tf`.`mime_type` AS `mime_type` 
+        	FROM `{$this->_sTableFiles2Entries}` AS `tf2e` 
+        	LEFT JOIN `{$this->_sTableFiles}` AS `tf` ON (`tf2e`.`image_id` = `tf`.`id`) " . $sJoin . " 
+        	WHERE 1 " . $sWhere;
+
+        return $this->getAll($sQuery, $aBindings);
     }
 
     function deleteImages($iSystemId, $iCmtId)
@@ -291,7 +309,7 @@ class BxDolCmtsQuery extends BxDolDb
             $sWhereAddon = " AND `cmt_id` = :cmt_id ";
         }
 
-        return $this->query("DELETE FROM `{$this->_sTableImages2Entries}` WHERE `system_id` = :system_id" . $sWhereAddon, $aBindings);
+        return $this->query("DELETE FROM `{$this->_sTableFiles2Entries}` WHERE `system_id` = :system_id" . $sWhereAddon, $aBindings);
     }
 
     function updateRepliesCount($iCmtId, $iCount)
@@ -314,7 +332,7 @@ class BxDolCmtsQuery extends BxDolDb
             $sQuery = $this->prepare("UPDATE {$this->_sTable} SET `cmt_replies` = `cmt_replies` - 1 WHERE `cmt_id` = ?", $r['cmt_parent_id']);
             $this->query ($sQuery);
 
-            $aFilesMore = $this->convertImagesArray($this->getImages($aSystem['system_id'], $r['cmt_id']));
+            $aFilesMore = $this->convertImagesArray($this->getFiles($aSystem['system_id'], $r['cmt_id']));
             $this->deleteImages($aSystem['system_id'], $r['cmt_id']);
             if ($aFilesMore && null !== $aFiles)
                 $aFiles = array_merge($aFiles, $aFilesMore);
@@ -333,10 +351,10 @@ class BxDolCmtsQuery extends BxDolDb
     function deleteObjectComments ($iObjectId, &$aFilesReturn = null, &$aCmtIds = null)
     {
         $aSystem = $this->_oMain->getSystemInfo();
-        $aFiles = $this->convertImagesArray($this->getImages($aSystem['system_id'], false, $iObjectId));
+        $aFiles = $this->convertImagesArray($this->getFiles($aSystem['system_id'], false, $iObjectId));
 
         if ($aFiles) {
-            $sQuery = $this->prepare("DELETE FROM {$this->_sTableImages2Entries} WHERE `system_id` = ? AND `image_id` IN(" . $this->implode_escape($aFiles) . ")", $aSystem['system_id']);
+            $sQuery = $this->prepare("DELETE FROM {$this->_sTableFiles2Entries} WHERE `system_id` = ? AND `image_id` IN(" . $this->implode_escape($aFiles) . ")", $aSystem['system_id']);
             $this->query($sQuery);
         }
 
@@ -357,7 +375,7 @@ class BxDolCmtsQuery extends BxDolDb
     {
         // get files
         if (null !== $aFiles)
-            $aFiles = $this->convertImagesArray($this->getImages($iSystemId, false));
+            $aFiles = $this->convertImagesArray($this->getFiles($iSystemId, false));
 
         // delete files
         $this->deleteImages($iSystemId, false);

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

@@ -1402,6 +1402,7 @@
 	<string name="_cmt_msg_login_required"><![CDATA[<a href="{0}">Login</a> or <a href="{1}">Join</a> to comment.]]></string>
 	<string name="_cmt_page_view_header"><![CDATA[Comment to {0}]]></string>
 	<string name="_cmt_page_view_title"><![CDATA[Comment to <a href="{0}">{1}</a>]]></string>
+	<string name="_cmt_download_attached_file"><![CDATA[Download file]]></string>
 	<string name="_cmt_view_attached_image"><![CDATA[View image]]></string>
 	<string name="_cmt_load_more_comments_head"><![CDATA[See newer comments...]]></string>
 	<string name="_cmt_load_more_comments_tail"><![CDATA[See older comments...]]></string>

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

@@ -1400,6 +1400,7 @@
 	<string name="_cmt_msg_login_required"><![CDATA[Чтобы оставить комментарий, вам необходимо <a href="{0}">войти</a> или <a href="{1}">зарегистрироваться</a>.]]></string>
 	<string name="_cmt_page_view_header"><![CDATA[Комментировать {0}]]></string>
 	<string name="_cmt_page_view_title"><![CDATA[Комментировать <a href="{0}">{1}</a>]]></string>
+	<string name="_cmt_download_attached_file"><![CDATA[Скачать файл]]></string>
 	<string name="_cmt_view_attached_image"><![CDATA[Просмотреть изображение]]></string>
 	<string name="_cmt_load_more_comments_head"><![CDATA[Увидеть новые комментарии...]]></string>
 	<string name="_cmt_load_more_comments_tail"><![CDATA[Увидеть старые комментарии...]]></string>

+ 10 - 3
template/comment.html

@@ -39,9 +39,16 @@
 						<div class="__style_prefix__-attached bx-def-margin-thd-leftright-neg bx-clearfix">
 							<bx_repeat:attached>
 								<div class="__style_prefix__-attached-preview bx-def-round-corners bx-def-margin-thd">
-									<a href="javascript:void(0)" onclick="__js_object__.showImage(this, '__image_orig__'); return false;" title="<bx_text_attribute:_cmt_view_attached_image />">
-										<img src="<bx_image_url:spacer.gif />" style="background-image:url(__image__)" />
-									</a>
+									<bx_if:show_image>
+										<a href="javascript:void(0)" onclick="__js_object__.showImage(this, '__file__'); return false;" title="<bx_text_attribute:_cmt_view_attached_image />">
+											<img src="<bx_image_url:spacer.gif />" style="background-image:url(__preview__)" />
+										</a>
+									</bx_if:show_image>
+									<bx_if:show_file>
+										<a href="__file__" title="<bx_text_attribute:_cmt_download_attached_file />">
+											<img src="<bx_image_url:spacer.gif />" style="background-image:url(__preview__)" />
+										</a>
+									</bx_if:show_file>
 								</div>
 							</bx_repeat:attached>
 						</div>

+ 31 - 7
template/scripts/BxBaseCmts.php

@@ -216,19 +216,43 @@ class BxBaseCmts extends BxDolCmts
 
         $aTmplImages = array();
         if($this->isAttachImageEnabled()) {
-            $aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']);
-            if(!empty($aImages) && is_array($aImages)) {
+            $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
+            if(!empty($aFiles) && is_array($aFiles)) {
         		$oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
-
                 $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
 
-                foreach($aImages as $aImage)
+                foreach($aFiles as $aFile) {
+                	$bImage = strncmp($aFile['mime_type'], 'image/', 6) == 0;
+                	$bVideo = strncmp($aFile['mime_type'], 'video/', 6) == 0;
+
+                	$sPreview = '';
+                	if($oTranscoder && ($bImage || $bVideo))
+                		$sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
+
+            		if(!$sPreview)
+                		$sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
+
+					$sFile = $oStorage->getFileUrlById($aFile['image_id']);
+
                     $aTmplImages[] = array(
                         'style_prefix' => $this->_sStylePrefix,
-                        'js_object' => $this->_sJsObjName,
-                        'image' => $oTranscoder->getFileUrl($aImage['image_id']),
-                    	'image_orig' => $oStorage->getFileUrlById($aImage['image_id'])
+                    	'bx_if:show_image' => array(
+                    		'condition' => $bImage,
+                    		'content' => array(
+								'js_object' => $this->_sJsObjName,
+								'preview' => $sPreview,
+								'file' => $sFile
+                    		)
+                    	),
+                        'bx_if:show_file' => array(
+                    		'condition' => !$bImage,
+                    		'content' => array(
+								'preview' => $sPreview,
+								'file' => $sFile
+                    		)
+                    	),
                     );
+                }
             }
         }
 

+ 5 - 14
template/scripts/BxBaseCmtsForm.php

@@ -9,18 +9,9 @@
 
 class BxBaseCmtsForm extends BxTemplFormView
 {
-	protected $_sStorageObject;
-    protected $_sTranscoderPreview;
-    protected $_aImageUploaders;
-
     public function __construct($aInfo, $oTemplate)
     {
         parent::__construct($aInfo, $oTemplate);
-//TODO: Continue from HERE
-        $this->_sStorageObject = 'sys_cmts_images';
-        $this->_sTranscoderPreview = 'sys_cmts_images_preview';
-
-        $this->_aImageUploaders = array('sys_cmts_simple');
 
     	if(isset($this->aInputs['cmt_image'])) {
             $aFormNested = array(
@@ -32,9 +23,9 @@ class BxBaseCmtsForm extends BxTemplFormView
 
             $oFormNested = new BxDolFormNested('cmt_image', $aFormNested, 'cmt_submit');
 
-            $this->aInputs['cmt_image']['storage_object'] = $this->_sStorageObject;
-            $this->aInputs['cmt_image']['images_transcoder'] = $this->_sTranscoderPreview;
-            $this->aInputs['cmt_image']['uploaders'] = !empty($this->aInputs['cmt_image']['value']) ? unserialize($this->aInputs['cmt_image']['value']) : $this->_aImageUploaders;
+            $this->aInputs['cmt_image']['storage_object'] = 'sys_cmts_images';
+            $this->aInputs['cmt_image']['images_transcoder'] = 'sys_cmts_images_preview';
+            $this->aInputs['cmt_image']['uploaders'] = !empty($this->aInputs['cmt_image']['value']) ? unserialize($this->aInputs['cmt_image']['value']) : array('sys_cmts_simple');
             $this->aInputs['cmt_image']['upload_buttons_titles'] = array('Simple' => 'camera');
             $this->aInputs['cmt_image']['multiple'] = true;
             $this->aInputs['cmt_image']['ghost_template'] = $oFormNested;
@@ -43,12 +34,12 @@ class BxBaseCmtsForm extends BxTemplFormView
 
 	public function getStorageObjectName()
     {
-        return $this->_sStorageObject;
+        return isset($this->aInputs['cmt_image']['storage_object']) ? $this->aInputs['cmt_image']['storage_object'] : '';
     }
 
     public function getTranscoderPreviewName()
     {
-    	return $this->_sTranscoderPreview;
+    	return isset($this->aInputs['cmt_image']['images_transcoder']) ? $this->aInputs['cmt_image']['images_transcoder'] : '';
     }
 }