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

Ticket #4999 - Avatar for account profile.

AntonLV пре 1 година
родитељ
комит
8525bce646

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
install/sql/system.sql


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

@@ -2728,6 +2728,8 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_form_account_input_receive_updates"><![CDATA[Receive Site Updates]]></string>
 	<string name="_sys_form_account_input_submit"><![CDATA[Submit]]></string>
         <string name="_sys_form_account_input_publish"><![CDATA[Create new account]]></string>
+        <string name="_sys_form_account_input_caption_system_picture"><![CDATA[Account Picture]]></string>
+        <string name="_sys_form_account_input_picture"><![CDATA[Upload an account picture]]></string>
         <string name="_sys_form_agents_comment"><![CDATA[Agents: Message]]></string>
         <string name="_sys_form_display_agents_comment_post"><![CDATA[Agents: Message Send]]></string>
         <string name="_sys_form_agents_comment_input_caption_system_action"><![CDATA[Action]]></string>

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

@@ -2706,6 +2706,8 @@
 	<string name="_sys_form_account_input_receive_updates"><![CDATA[Получать обновления сайта]]></string>
 	<string name="_sys_form_account_input_submit"><![CDATA[Отправить]]></string>
         <string name="_sys_form_account_input_publish"><![CDATA[Создать новую учетную запись]]></string>
+        <string name="_sys_form_account_input_caption_system_picture"><![CDATA[Изображение аккаунта]]></string>
+        <string name="_sys_form_account_input_picture"><![CDATA[Загрузить изображение аккаунта]]></string>
         <string name="_sys_form_agents_comment"><![CDATA[Агенты: Сообщение]]></string>
         <string name="_sys_form_display_agents_comment_post"><![CDATA[Агенты: Отправить сообщение]]></string>
         <string name="_sys_form_agents_comment_input_caption_system_action"><![CDATA[Действие]]></string>

+ 6 - 0
template/scripts/BxBaseAccountForms.php

@@ -130,6 +130,9 @@ class BxBaseAccountForms extends BxDolProfileForms
 
         $iProfileId = $this->onAccountCreated($iAccountId, $oForm->isSetPendingApproval());
 
+        if(($sField = 'picture') && isset($oForm->aInputs[$sField]))
+            $oForm->processFiles($sField, $iAccountId, true);
+
         // perform action
         BxDolAccount::isAllowedCreate ($iProfileId, true);
 
@@ -348,6 +351,9 @@ class BxBaseAccountForms extends BxDolProfileForms
                 return $sLKey = '_sys_txt_error_account_update' && $bIsApi ? _t($sLKey) : MsgBox(_t($sLKey));
         }
 
+        if(($sField = 'picture') && isset($oForm->aInputs[$sField]))
+            $oForm->processFiles($sField, $iAccountId, false);
+
         // check if email was changed
         if (!empty($aTrackTextFieldsChanges['changed_fields']) && in_array('email', $aTrackTextFieldsChanges['changed_fields'])){
             $oAccount = BxDolAccount::getInstance($iAccountId, true); // refresh account to clear cache 

+ 89 - 0
template/scripts/BxBaseFormAccount.php

@@ -126,10 +126,33 @@ class BxBaseFormAccount extends BxTemplFormView
 
     protected $_bSetPendingApproval = false;
 
+    protected $_sGhostTemplate = 'account_form_ghost_template.html';
+
     public function __construct($aInfo, $oTemplate)
     {
         parent::__construct($aInfo, $oTemplate);
+        
         $this->_bSetPendingApproval = !(bool)getParam('sys_account_autoapproval');
+
+        if(($sField = 'picture') && isset($this->aInputs[$sField])) {
+            /**
+             * Note. For now Account Picture is available in edit form only. 
+             * To make it available on create form Uploader should correctly support 
+             * uploading by visitor.
+             */
+            if($this->aParams['display'] == 'sys_account_settings_info')
+                $this->aInputs[$sField] = array_merge($this->aInputs[$sField], [
+                    'storage_object' => 'sys_accounts_pictures',
+                    'uploaders' => !empty($this->aInputs[$sField]['value']) ? unserialize($this->aInputs[$sField]['value']) : ['sys_crop'],
+                    'images_transcoder' => 'sys_accounts_thumb',
+                    'storage_private' => 0,
+                    'multiple' => false,
+                    'content_id' => 0,
+                    'ghost_template' => ''
+                ]);
+            else
+                unset($this->aInputs[$sField]);
+        }
     }
 
     function isValid ()
@@ -175,6 +198,20 @@ class BxBaseFormAccount extends BxTemplFormView
         return ($this->_bSetPendingApproval = $b);
     }
 
+    public function initChecker ($aValues = [], $aSpecificValues = [])
+    {
+        $bValues = $aValues && !empty($aValues['id']);
+
+        if(($sField = 'picture') && isset($this->aInputs[$sField])) {
+            if($bValues)
+                $this->aInputs[$sField]['content_id'] = $aValues['id'];
+
+            $this->aInputs[$sField]['ghost_template'] = $this->oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getGhostTmplVars($sField));
+        }
+
+        parent::initChecker($aValues, $aSpecificValues);
+    }
+
     public function insert ($aValsToAdd = array(), $isIgnore = false)
     {
         $iNow = time();
@@ -255,6 +292,41 @@ class BxBaseFormAccount extends BxTemplFormView
         return $bResult;
     }
 
+    public function processFiles($sFieldFile, $iAccountId = 0, $isAssociateWithContent = false)
+    {
+        if (!isset($this->aInputs[$sFieldFile]))
+            return true;
+
+        $mixedFileIds = $this->getCleanValue($sFieldFile);
+        if(!$mixedFileIds)
+            return true;
+
+        $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
+        if (!$oStorage)
+            return false;
+
+        $iProfileId = 0;
+        if($iAccountId && ($aAccountInfo = BxDolAccountQuery::getInstance()->getInfoById($iAccountId)))
+            $iProfileId = $aAccountInfo['profile_id'];
+        else
+            $iProfileId = bx_get_logged_profile_id();
+
+        $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iAccountId, true, $this->_isAdmin());
+        if(!empty($aGhostFiles) && is_array($aGhostFiles))
+            foreach($aGhostFiles as $aFile) {
+                if(is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
+                    continue;
+
+                if($aFile['private'])
+                    $oStorage->setFilePrivate ($aFile['id'], 1);
+
+                if($iAccountId)
+                    $oStorage->updateGhostsContentId ($aFile['id'], $iProfileId, $iAccountId, $this->_isAdmin());
+            }
+
+        return true;
+    }
+
     protected function genCustomInputAgreement ($aInput)
     {
     	$oPermalink = BxDolPermalinks::getInstance();
@@ -265,6 +337,23 @@ class BxBaseFormAccount extends BxTemplFormView
     {
         $this->aInputs['do_submit']['error'] = $s;
     }
+
+    protected function _isAdmin()
+    {
+        return BxDolAcl::getInstance()->isMemberLevelInSet([MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR]);
+    }
+
+    protected function _getGhostTmplVars($sField)
+    {
+    	return [
+            'name' => $this->aInputs[$sField]['name'],
+            'content_id' => $this->aInputs[$sField]['content_id'],
+            'bx_if:set_thumb' => [
+                'condition' => false,
+                'content' => [],
+            ]
+        ];
+    }
 }
 
 /** @} */

Неке датотеке нису приказане због велике количине промена