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

#53 code clean-up: some TODOs around the code

Alex Trofimov 12 лет назад
Родитель
Сommit
a8b6858e00

+ 10 - 3
inc/classes/BxDolAccount.php

@@ -116,9 +116,7 @@ class BxDolAccount extends BxDol {
      * Send "confirmation" email
      */
     public function sendConfirmationEmail($iAccountId = false) {
-        $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
-        $aAccountInfo = $this->getInfo($iAccountId);
-        $sEmail = $aAccountInfo['email'];
+        $sEmail = $this->getEmail($iAccountId);
 
         bx_import('BxDolKey');
         $oKey = BxDolKey::getInstance();
@@ -188,6 +186,15 @@ class BxDolAccount extends BxDol {
         return BxDolTemplate::getInstance()->getImageUrl('account-icon.png');
     }
 
+    /**
+     * Get account email
+     */
+    public function getEmail($iAccountId = false) {
+        $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
+        $aAccountInfo = $this->getInfo($iAccountId);
+        return $aAccountInfo['email'];
+    }
+
     /**
      * Validate account. 
      * @param $s - account identifier (id or email) 

+ 7 - 3
inc/classes/BxDolAcl.php

@@ -502,8 +502,8 @@ class BxDolAcl extends BxDol implements iBxDolSingleton {
     		if ($aMembershipCurrent['id'] == MEMBERSHIP_ID_STANDARD) 
                 return true;
 
-    		// delete any present and future memberships
-    		return $this->oDb->deleteLevelByProfileId($iProfileId, true);
+    		// delete present and future memberships
+    		return $this->oDb->deleteLevelByProfileId($iProfileId);
     	}
 
     	if ($iDays < 0) 
@@ -518,7 +518,7 @@ class BxDolAcl extends BxDol implements iBxDolSingleton {
                 return false;
     	}
     	else
-    	    $this->oDb->deleteLevelByProfileId($iProfileId); ///< Delete previous profile's membership level
+    	    $this->oDb->deleteLevelByProfileId($iProfileId, true); ///< Delete any profile's membership level
 
         // set lifetime membership if 0 days is used.
         $iDateExpires = $iDays != 0 ? (int)$iDateStarts + $iDays * $iSecInDay : 'NULL';
@@ -673,6 +673,10 @@ class BxDolAcl extends BxDol implements iBxDolSingleton {
 
         return $aMembershipLast;
     }
+
+    public function onProfileDelete ($iProfileId) {
+        return $this->oDb->deleteLevelByProfileId($iProfileId, true);
+    }
 }
 
 function checkAction($iProfileId, $iActionId, $bPerformAction = false) {

+ 1 - 1
inc/classes/BxDolAclQuery.php

@@ -251,7 +251,7 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton {
     }
 
     function deleteLevelByProfileId($iProfileId, $bAll = false) {
-        $sQuery = $this->prepare("DELETE FROM `sys_acl_levels_members` WHERE `IDMember`=?" . ($bAll ? " AND (`DateExpires` IS NULL OR `DateExpires`>NOW())" : ""), $iProfileId);
+        $sQuery = $this->prepare("DELETE FROM `sys_acl_levels_members` WHERE `IDMember` = ? " . ($bAll ? "" : " AND (`DateExpires` IS NULL OR `DateExpires` > NOW())"), $iProfileId);
         return (int)$this->query($sQuery) > 0;
     }
 

+ 2 - 0
inc/classes/BxDolCacheUtilities.php

@@ -7,6 +7,8 @@
  * @{
  */
 
+// TODO: check if it is used or maybe usefull for future use, also it needs some refactoring
+
 class BxDolCacheUtilities extends BxDol
 {
     protected $oMemberMenu;

+ 5 - 0
inc/classes/BxDolEmailTemplates.php

@@ -167,6 +167,11 @@ class BxDolEmailTemplates extends BxDol implements iBxDolSingleton {
             $oProfile = BxDolProfile::getInstance($iProfileId);
             if ($oProfile && ($aProfileInfo = $oProfile->getInfo())) {
                 $aResultKeys = array_merge($aResultKeys, array(
+                    'profile_name' => $oProfile->getDisplayName(),
+                    'profile_url' => $oProfile->getUrl(),
+                    'profile_thumb' => $oProfile->getThumb(),
+                    'profile_icon' => $oProfile->getIcon(),
+
                     'profile_id' => $aProfileInfo['id'],
                     'profile_status' => $aProfileInfo['status'],
                     'profile_type' => $aProfileInfo['type'],

+ 3 - 6
inc/classes/BxDolImageTranscoder.php

@@ -291,7 +291,6 @@ class BxDolImageTranscoder extends BxDol implements iBxDolFactoryObject
             return $this->_oStorage->getFileUrlById($iFileId);
         }
 
-        // TODO: reconsider adding timestamp in the url
         return BX_DOL_URL_ROOT . 'image_transcoder.php?o=' . $this->_aObject['object'] . '&h=' . $mixedHandler . '&dpx=' . $this->getDevicePixelRatio() . '&t=' . time();
     }
 
@@ -532,11 +531,9 @@ class BxDolImageTranscoder extends BxDol implements iBxDolFactoryObject
     }
 
     protected function getTmpFilename ($sOverrideName = false) {
-        if ($sOverrideName) {
-            // TODO: generate uniq folder for current dolphin instance and image object
-            return realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . rand(10000, 99999) . $sOverrideName;
-        }
-        return tempnam(realpath(sys_get_temp_dir()), 'bxdol');
+        if ($sOverrideName)
+            return BX_DIRECTORY_PATH_TMP . rand(10000, 99999) . $sOverrideName;
+        return tempnam(BX_DIRECTORY_PATH_TMP, $this->_aObject['object']);
     }
 
     protected function applyFilter_Grayscale ($sFile, $aParams) { 

+ 36 - 20
inc/classes/BxDolProfile.php

@@ -115,6 +115,14 @@ class BxDolProfile extends BxDol implements iBxDolProfile {
         return $aInfo['account_id'];
     }
 
+    /**
+     * Get account object associated with the profile
+     */
+    public function getAccountObject() {
+        bx_import('BxDolAccount');
+        return BxDolAccount::getInstance($this->getAccountId());
+    }
+
     /**
      * Get content id associated with the profile
      */
@@ -258,9 +266,9 @@ class BxDolProfile extends BxDol implements iBxDolProfile {
         $oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
         $oConn->onDeleteInitiatorAndContent($ID);
 
-        // delete associated content 
-        // TODO: remake deletion of associated content
-        $this->_oQuery->res("DELETE FROM `sys_acl_levels_members` WHERE `IDMember` = {$ID}");
+        // delete profile's acl levels
+        bx_import('BxDolAcl');
+        BxDolAcl::getInstance()->onProfileDelete($ID);
 
         // delete profile
         if (!$this->_oQuery->delete($ID))
@@ -297,38 +305,46 @@ class BxDolProfile extends BxDol implements iBxDolProfile {
      * Change profile status from 'Pending' to the next level - 'Active'
      */
     public function approve($iAction, $iProfileId = 0) {
-        if (!$iProfileId)
-            $iProfileId = $this->_iProfileID;
-        if (!$this->_oQuery->changeStatus($iProfileId, BX_PROFILE_STATUS_ACTIVE))
-            return false;
-        bx_alert('profile', 'approve', $iProfileId, false, array('action' => $iAction));
-        // TODO: send email that profile is approved
-        return true;
+        return $this->changeStatus(BX_PROFILE_STATUS_ACTIVE, 'approve', $iAction, $iProfileId);
     }
 
     /**
      * Change profile status to 'Pending' 
      */
     public function disapprove($iAction, $iProfileId = 0) {
-        if (!$this->_oQuery->changeStatus((int)$iProfileId ? $iProfileId : $this->_iProfileID, BX_PROFILE_STATUS_PENDING))
-            return false;
-        bx_alert('profile', 'disapprove', $iProfileId ? $iProfileId : $this->_iProfileID, false, array('action' => $iAction));
-        // TODO: send email that profile is disapproved ?
-        return true;
+        return $this->changeStatus(BX_PROFILE_STATUS_PENDING, 'disapprove', $iAction, $iProfileId);
     }
 
     /**
      * Change profile status to 'Suspended' 
      */
     public function suspend($iAction, $iProfileId = 0) {
-        if (!$this->_oQuery->changeStatus((int)$iProfileId ? $iProfileId : $this->_iProfileID, BX_PROFILE_STATUS_SUSPENDED))
-            return false;
-        bx_alert('profile', 'suspend', $iProfileId, false, array('action' => $iAction));
-        // TODO: send email that profile is suspended
-        return true;
+        return $this->changeStatus(BX_PROFILE_STATUS_SUSPENDED, 'suspend', $iAction, $iProfileId);
     }
 
+    protected function changeStatus($sStatus, $sAlertActionName, $iAction, $iProfileId = 0) {
+        if (!$iProfileId)
+            $iProfileId = $this->_iProfileID;
+
+        // get account and profile objects
+        $oProfile = BxDolProfile::getInstance($iProfileId);
+        $oAccount = $oProfile->getAccountObject();
+        if (!$oProfile || !$oAccount)
+            return false;
+
+        // change status
+        if (!$this->_oQuery->changeStatus($iProfileId, $sStatus))
+            return false;
+
+        // alert about status changing
+        bx_alert('profile', $sAlertActionName, $iProfileId, false, array('action' => $iAction));
+
+        // send email to member about status change
+        sendMailTemplate('t_ChangeStatus' . ucfirst($sStatus), $oAccount->id(), $iProfileId, array('status' => $sStatus), BX_EMAIL_SYSTEM);
 
+        return true;
+    }
+    
     /**
      * Display informer message if it is possible to switch to this profile
      */

+ 6 - 4
inc/classes/BxDolStorage.php

@@ -410,7 +410,7 @@ abstract class BxDolStorage extends BxDol implements iBxDolFactoryObject {
 
         // create tmp file        
         
-        $sTmpFile = tempnam(realpath(sys_get_temp_dir()), 'bxdol');
+        $sTmpFile = tempnam(BX_DIRECTORY_PATH_TMP, $this->_aObject['object']);
         if (!$oHelper->save($sTmpFile)) {
             $this->setErrorCode(BX_DOL_STORAGE_INVALID_FILE);
             return false;
@@ -660,9 +660,11 @@ abstract class BxDolStorage extends BxDol implements iBxDolFactoryObject {
         return $this->_oDb->getFiles($iProfileId);
     }    
 
-    public function tmpDebugGetFilesList() { // TODO: remove this function, since it is for debugging purposes only
-        $sQuery = "SELECT * FROM `" . $this->_aObject['table_files'] . "`";
-        return $this->_oDb->getAll($sQuery);
+    /**
+     * Get all files in the storage
+     */
+    public function getFilesAll($iStart = 0, $iPerPage = 1000) {
+        return $this->_oDb->getFilesAll($iStart, $iPerPage);
     }
 
     /**

+ 5 - 0
inc/classes/BxDolStorageQuery.php

@@ -231,6 +231,11 @@ class BxDolStorageQuery extends BxDolDb {
         return $this->getAll($sQuery);
     }
 
+    public function getFilesAll($iStart, $iPerPage) {
+        $sQuery = $this->prepare("SELECT * FROM `" . $this->_sTableFiles . "` LIMIT ?, ?", (int)$iStart, (int)$iPerPage);
+        return $this->getAll($sQuery);
+    }
+
     public function prune() {
         $iTime = time();
         $sQuery = $this->prepare("DELETE FROM `sys_storage_tokens` WHERE `object` = ? AND `created` < ?", $this->_aObject['object'], $iTime - $this->_aObject['token_life']);

+ 22 - 0
inc/utils.inc.php

@@ -241,7 +241,29 @@ function htmlspecialchars_adv( $string ) {
     return htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
 }
 
+/**
+ * Send mail to user by parsing email template
+ */
+function sendMailTemplate($sTemplateName, $iAccountId = 0, $iProfileId = 0, $aReplaceVars = array(), $iEmailType = BX_EMAIL_NOTIFY) {
+
+    bx_import('BxDolAccount');
+    $oAccount = BxDolAccount::getInstance($iAccountId);
+
+    bx_import('BxDolProfile');
+    $oProfile = BxDolProfile::getInstance($iProfileId);
+
+    bx_import('BxDolEmailTemplates');
+    $oEmailTemplates = BxDolEmailTemplates::getInstance();
 
+    if (!$oAccount || !$oProfile || !$oEmailTemplates)
+        return false;
+
+    $aTemplate = $oEmailTemplates->parseTemplate($sTemplateName, $aReplaceVars, $iAccountId, $iProfileId);
+    if (!$aTemplate)
+        return false;
+
+    return sendMail($oAccount->getEmail(), $aTemplate['Subject'], $aTemplate['Body'], 0, array(), $iEmailType);
+}
 
 /**
  * Send email function

+ 4 - 6
install/sql/system.sql

@@ -128,10 +128,6 @@ CREATE TABLE `sys_objects_cmts` (
 
 -- --------------------------------------------------------
 
---
--- Table structure for table `sys_email_templates`
---
-
 CREATE TABLE IF NOT EXISTS `sys_email_templates` (
   `ID` int(11) unsigned NOT NULL auto_increment,
   `Module` varchar(32) NOT NULL,
@@ -143,7 +139,6 @@ CREATE TABLE IF NOT EXISTS `sys_email_templates` (
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
 
 INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `Body`) VALUES
-('system', '_sys_et_txt_name_system_activation', 't_Activation', '_sys_et_txt_subject_activation', '_sys_et_txt_body_activation'),
 ('system', '_sys_et_txt_name_system_admin_email', 't_AdminEmail', '_sys_et_txt_subject_admin_email', '_sys_et_txt_body_admin_email'),
 ('system', '_sys_et_txt_name_system_confirmation', 't_Confirmation', '_sys_et_txt_subject_confirmation', '_sys_et_txt_body_confirmation'),
 ('system', '_sys_et_txt_name_system_forgot', 't_Forgot', '_sys_et_txt_subject_forgot', '_sys_et_txt_body_forgot'),
@@ -152,7 +147,10 @@ INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `B
 ('system', '_sys_et_txt_name_system_mem_changed', 't_MemChanged', '_sys_et_txt_subject_mem_changed', '_sys_et_txt_body_mem_changed'),
 ('system', '_sys_et_txt_name_system_comment_replied', 't_CommentReplied', '_sys_et_txt_subject_comment_replied', '_sys_et_txt_body_comment_replied'),
 ('system', '_sys_et_txt_name_system_delayed_module_uninstall', 't_DelayedModuleUninstall', '_sys_et_txt_subject_delayed_module_uninstall', '_sys_et_txt_body_delayed_module_uninstall'),
-('system', '_sys_et_txt_name_system_pruning', 't_Pruning', '_sys_et_txt_subject_pruning', '_sys_et_txt_body_pruning');
+('system', '_sys_et_txt_name_system_pruning', 't_Pruning', '_sys_et_txt_subject_pruning', '_sys_et_txt_body_pruning'),
+('system', '_sys_et_txt_name_profile_change_status_active', 't_ChangeStatusActive', '_sys_et_txt_subject_profile_change_status_active', '_sys_et_txt_body_profile_change_status_active'),
+('system', '_sys_et_txt_name_profile_change_status_suspended', 't_ChangeStatusSuspended', '_sys_et_txt_subject_profile_change_status_suspended', '_sys_et_txt_body_profile_change_status_suspended'),
+('system', '_sys_et_txt_name_profile_change_status_pending', 't_ChangeStatusPending', '_sys_et_txt_subject_profile_change_status_pending', '_sys_et_txt_body_profile_change_status_pending');
 
 -- --------------------------------------------------------
 

+ 23 - 10
modules/boonex/english/data/langs/system.xml

@@ -1408,14 +1408,6 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_designbox_2"><![CDATA[Empty box]]></string>
 	<string name="_sys_designbox_3"><![CDATA[Content + background]]></string>
 	<string name="_sys_et_txt_about_us"><![CDATA[About us]]></string>
-	<string name="_sys_et_txt_body_activation"><![CDATA[<bx_include_auto:_email_header.html />
-<p>Hello,</p>
-<p>Your profile was reviewed and activated!</p>
-<p>Simply follow the link below to enjoy our services:<br />
-<a href="{site_url}member.php">{site_url}member.php</a></p>
-<p>Your e-mail used for registration: <span style="color:#FF6633">{email}</span></p>
-<p><b>Thank you for using our services!</b></p>
-<bx_include_auto:_email_footer.html />]]></string>
 	<string name="_sys_et_txt_body_admin_email"><![CDATA[<bx_include_auto:_email_header.html />
 <p>Hello,</p>
 <p>Administration of the <a href="{site_url}">{site_name}</a> is glad to inform you that</p>
@@ -1460,11 +1452,27 @@ If it is not enabled then please consider implement this optimization, since it
 <p>Hello!</p>
 <p>Your new password is:</p>
 <p><b>{password}</b></p>
+<bx_include_auto:_email_footer.html />]]></string>
+	<string name="_sys_et_txt_body_profile_change_status_active"><![CDATA[<bx_include_auto:_email_header.html />
+<p>Hello {profile_name},</p>
+<p>Your profile was reviewed and activated!</p>
+<p>Simply follow the link below to enjoy our services:<br />
+<a href="{site_url}member.php">{site_url}member.php</a></p>
+<p>Your e-mail used for registration: <span style="color:#FF6633">{account_email}</span></p>
+<p><b>Thank you for using our services!</b></p>
+<bx_include_auto:_email_footer.html />]]></string>
+	<string name="_sys_et_txt_body_profile_change_status_pending"><![CDATA[<bx_include_auto:_email_header.html />
+<p>Hello {profile_name},</p>
+<p>Your profile is waiting for review, as soon as it is reviewed you will receive notification by email.</p>
+<p><b>Thank you for using our services.</b></p>
+<bx_include_auto:_email_footer.html />]]></string>
+	<string name="_sys_et_txt_body_profile_change_status_suspended"><![CDATA[<bx_include_auto:_email_header.html />
+<p>Hello {profile_name},</p>
+<p>Your profile was suspended.</p>
 <bx_include_auto:_email_footer.html />]]></string>
 	<string name="_sys_et_txt_body_pruning"><![CDATA[<bx_include_auto:_email_header.html />
 <p>{pruning_output}</p>
 <bx_include_auto:_email_footer.html />]]></string>
-	<string name="_sys_et_txt_name_system_activation"><![CDATA[Profile activation message]]></string>
 	<string name="_sys_et_txt_name_system_admin_email"><![CDATA[Message sending from the Admin Panel]]></string>
 	<string name="_sys_et_txt_name_system_comment_replied"><![CDATA[The letter is sent to members whose comment was replied]]></string>
 	<string name="_sys_et_txt_name_system_confirmation"><![CDATA[Profile e-mail confirmation message]]></string>
@@ -1473,8 +1481,10 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_et_txt_name_system_mem_changed"><![CDATA[The letter is sent to members whose membership level was changed]]></string>
 	<string name="_sys_et_txt_name_system_mem_expiration"><![CDATA[Membership expiration letter sent to members whose membership level expires]]></string>
 	<string name="_sys_et_txt_name_system_password_reset"><![CDATA[New password message]]></string>
+	<string name="_sys_et_txt_name_profile_change_status_active"><![CDATA[Profile status changed to active]]></string>
+	<string name="_sys_et_txt_name_profile_change_status_pending"><![CDATA[Profile status changed to pending]]></string>
+	<string name="_sys_et_txt_name_profile_change_status_suspended"><![CDATA[Profile status changed to suspended]]></string>
 	<string name="_sys_et_txt_name_system_pruning"><![CDATA[Pruning result]]></string>
-	<string name="_sys_et_txt_subject_activation"><![CDATA[Profile status was changed to Active]]></string>
 	<string name="_sys_et_txt_subject_admin_email"><![CDATA[Message from <SiteName> Admin: <MessageSubject>]]></string>
 	<string name="_sys_et_txt_subject_comment_replied"><![CDATA[Your comment was replied]]></string>
 	<string name="_sys_et_txt_subject_confirmation"><![CDATA[Confirm Your Email (ACTION REQUIRED)]]></string>
@@ -1483,6 +1493,9 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_et_txt_subject_mem_changed"><![CDATA[Your membership level was changed]]></string>
 	<string name="_sys_et_txt_subject_mem_expiration"><![CDATA[Your membership is about to expire]]></string>
 	<string name="_sys_et_txt_subject_password_reset"><![CDATA[New Password]]></string>
+	<string name="_sys_et_txt_subject_profile_change_status_active"><![CDATA[Profile Activated]]></string>
+	<string name="_sys_et_txt_subject_profile_change_status_pending"><![CDATA[Profile Pending Review]]></string>
+	<string name="_sys_et_txt_subject_profile_change_status_suspended"><![CDATA[Profile was Suspended]]></string>
 	<string name="_sys_et_txt_subject_pruning"><![CDATA[{site_title} pruning result]]></string>
 	<string name="_sys_et_txt_unsubscribe"><![CDATA[Unsubscribe]]></string>
 	<string name="_sys_form_account"><![CDATA[Account]]></string>

+ 1 - 1
samples/transcoder.php

@@ -101,7 +101,7 @@ $(document).ready(function () {
         }
     }
 
-    $a = $oStorage->tmpDebugGetFilesList();
+    $a = $oStorage->getFilesAll();
     echo "<hr /> <h2>Files List:</h2>";
     echo '<form method="POST">';
     foreach ($a as $r)