Просмотр исходного кода

Ticket #4602 - Add domain validation in Link Auto Attachment feature: in Timeline.

AntonLV 2 лет назад
Родитель
Сommit
233723d374

+ 1 - 1
inc/classes/BxDolStorage.php

@@ -1462,7 +1462,7 @@ class BxDolStorageHelperUrl extends BxDolStorageHelperPath
                 file_put_contents($aParams['path'], $s);
             } 
             else {
-                $hRead = fopen($aParams['url'], "rb");
+                $hRead = @fopen($aParams['url'], "rb");
                 $hWrite = fopen($aParams['path'], "wb");
                 if (false !== $hRead && false !== $hWrite) {
                     while (!feof($hRead)) {

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

@@ -303,18 +303,18 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
     public function deleteUnusedLinks($iUserId, $iLinkId = 0)
     {
-    	$aBindings = array(
-    		'profile_id' => $iUserId
-    	);
+    	$aBindings = [
+            'profile_id' => $iUserId
+    	];
 
         $sWhereAddon = '';
         if(!empty($iLinkId)) {
-        	$aBindings['id'] = $iLinkId;
+            $aBindings['id'] = $iLinkId;
 
-            $sWhereAddon = " AND `id`=:id";
+            $sWhereAddon = " AND `tl`.`id`=:id";
         }
 
-        return $this->query("DELETE FROM `" . $this->_sPrefix . "links` WHERE `profile_id`=:profile_id" . $sWhereAddon, $aBindings);
+        return $this->query("DELETE FROM `tl`, `tle` USING `" . $this->_sPrefix . "links` AS `tl` LEFT JOIN `" . $this->_sPrefix . "links2events` AS `tle` ON `tl`.`id`=`tle`.`link_id` WHERE `tl`.`profile_id`=:profile_id AND ISNULL(`tle`.`event_id`)" . $sWhereAddon, $aBindings);
     }
 
     public function saveLink($iEventId, $iLinkId)

+ 7 - 3
modules/boonex/timeline/classes/BxTimelineFormPost.php

@@ -83,9 +83,6 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
             $this->aInputs['attachments']['content'] = $oMenu->getCode() . $this->_oModule->_oTemplate->parseHtmlByName('uploader_progress.html', []);;
         }
 
-        if(isset($this->aInputs[$CNF['FIELD_LINK']]))
-            $this->aInputs[$CNF['FIELD_LINK']]['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId, $iValueId);
-
         foreach(['FIELD_VIDEO', 'FIELD_FILE'] as $sSetting){
             if(!isset($CNF[$sSetting]) || !isset($this->aInputs[$CNF[$sSetting]])) 
                 continue;
@@ -107,6 +104,13 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
             $this->aInputs[$CNF['FIELD_ANONYMOUS']]['checked'] = $aValues[$CNF['FIELD_OBJECT_ID']] < 0;
 
         parent::initChecker ($aValues, $aSpecificValues);
+
+        if(isset($this->aInputs[$CNF['FIELD_LINK']])) {
+            if(!$bValueId && !$this->isSubmitted())
+                $this->_oModule->deleteLinksUnused($iUserId);
+
+            $this->aInputs[$CNF['FIELD_LINK']]['content'] = $this->_oModule->_oTemplate->getAttachLinkField($iUserId, $iValueId);
+        }
     }
 
     public function insert($aValsToAdd = array(), $isIgnore = false)

+ 16 - 2
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -5181,6 +5181,20 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         return $bResult;
     }
 
+    public function deleteLinksUnused($iProfileId)
+    {
+        $aLinks = $this->_oDb->getUnusedLinks($iProfileId);
+        if(empty($aLinks) || !is_array($aLinks))
+            return;
+
+        $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
+        foreach($aLinks as $aLink)
+            if(!empty($aLink['media_id']))
+                $oStorage->deleteFile($aLink['media_id']);
+
+        $this->_oDb->deleteUnusedLinks($iProfileId);
+    }
+
     public function deleteCacheItem($iEventId)
     {
         //--- Delete own item cache.
@@ -5496,8 +5510,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
         ));
 
-        $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
-        $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
+        $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : $sHost;
+        $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : '';
 
         $sMediaUrl = '';
         if(!empty($aSiteInfo['thumbnailUrl']))

+ 5 - 6
modules/boonex/timeline/js/post.js

@@ -36,12 +36,7 @@ function BxTimelinePost(oOptions) {
             oPost = $($this.sIdPostForm);
 
     	oPost.each(function() {
-            var sId = $(this).attr('id');
-            $this.initFormPost(sId);
-
-            $this.initTrackerInsertSpace(sId);
-            if($this._bAutoAttach) 
-                $this.initTrackerInsertImage(sId);
+            $this.initFormPost($(this).attr('id'));
     	});
     });
 }
@@ -64,6 +59,10 @@ BxTimelinePost.prototype.initFormPost = function(sFormId)
             window[$this._sObjName].afterFormPostSubmit(oForm, oData);
         }
     });
+    
+    $this.initTrackerInsertSpace(sFormId);
+    if($this._bAutoAttach) 
+        $this.initTrackerInsertImage(sFormId);
 };
 
 BxTimelinePost.prototype.onFormPostSubmit = function(oForm)

+ 1 - 1
modules/boonex/timeline/template/css/post.css

@@ -59,7 +59,7 @@ div.bx-tl-ali-thumbnail img {
 }
 div.bx-tl-ali-embed {
     max-height: 250px;
-    overflow-y: scroll;
+    overflow-y: auto;
 }
 div.bx-tl-ali-actions .bx-btn {
     display: inline-block;