ソースを参照

Ticket #285 - Core changes.

AntonLV 10 年 前
親
コミット
5f1476d72f

+ 17 - 9
inc/classes/BxDolAcl.php

@@ -63,6 +63,15 @@ define('CHECK_ACTION_RESULT_LIMIT_REACHED', 3);
 define('CHECK_ACTION_RESULT_NOT_ALLOWED_BEFORE', 4);
 define('CHECK_ACTION_RESULT_NOT_ALLOWED_AFTER', 5);
 
+/**
+ * Standard period units
+ */
+define('MEMBERSHIP_PERIOD_UNIT_DAY', 'day');
+define('MEMBERSHIP_PERIOD_UNIT_WEEK', 'week');
+define('MEMBERSHIP_PERIOD_UNIT_MONTH', 'month');
+define('MEMBERSHIP_PERIOD_UNIT_YEAR', 'year');
+
+
 class BxDolAcl extends BxDol implements iBxDolSingleton
 {
     protected $oDb;
@@ -420,19 +429,16 @@ class BxDolAcl extends BxDol implements iBxDolSingleton
      * @param  int     $iLevelId   membership that is going to be assigned to the profile
      *                             if $iLevelId == MEMBERSHIP_ID_STANDARD then $days and $bStartsNow parameters are not used,
      *                             so Standard membership is always set immediately and `forever`
-     * @param  int     $iDays      number of days to set membership for if 0, then the membership is set forever
+     * @param  mixed   $mixedPeriod  number of Days to set membership for or an array with 'period'-'period unit' pair. If number or 'period' in pair equal 0, then the membership is set forever
      * @param  boolean $bStartsNow if true, the membership will start immediately if false, the membership will start after the current membership expires
      * @return boolean true in case of success, false in case of failure
      */
-    function setMembership($iProfileId, $iLevelId, $iDays = 0, $bStartsNow = false, $sTransactionId = '')
+    function setMembership($iProfileId, $iLevelId, $mixedPeriod = 0, $bStartsNow = false, $sTransactionId = '')
     {
         $iProfileId = (int)$iProfileId;
         $iLevelId = (int)$iLevelId;
-        $iDays = (int)$iDays;
         $bStartsNow = $bStartsNow ? true : false;
 
-        $iSecInDay = 86400;
-
         if (!$iProfileId)
             $iProfileId = -1;
 
@@ -464,7 +470,7 @@ class BxDolAcl extends BxDol implements iBxDolSingleton
             return $this->oDb->deleteLevelByProfileId($iProfileId);
         }
 
-        if ($iDays < 0)
+        if ((is_numeric($mixedPeriod) && (int)$mixedPeriod < 0) || (is_array($mixedPeriod) && (!isset($mixedPeriod['period']) || $mixedPeriod['period'] < 0)))
             return false;
 
         $iDateStarts = time();
@@ -482,12 +488,14 @@ class BxDolAcl extends BxDol implements iBxDolSingleton
         }
 
         // set lifetime membership if 0 days is used.
-        $iDateExpires = $iDays != 0 ? (int)$iDateStarts + $iDays * $iSecInDay : null;
-        if(!$this->oDb->insertLevelByProfileId($iProfileId, $iLevelId, $iDateStarts, $iDateExpires, $sTransactionId))
+        if(is_numeric($mixedPeriod))
+        	$mixedPeriod = array('period' => (int)$mixedPeriod, 'period_unit' => MEMBERSHIP_PERIOD_UNIT_DAY);
+
+        if(!$this->oDb->insertLevelByProfileId($iProfileId, $iLevelId, $iDateStarts, $mixedPeriod, $sTransactionId))
            return false;
 
         // raise membership alert
-        $oZ = new BxDolAlerts('profile', 'set_membership', '', $iProfileId, array('mlevel'=> $iLevelId, 'days' => $iDays, 'starts_now' => $bStartsNow, 'txn_id' => $sTransactionId));
+        $oZ = new BxDolAlerts('profile', 'set_membership', '', $iProfileId, array('mlevel'=> $iLevelId, 'period' => $mixedPeriod['period'], 'period_unit' => $mixedPeriod['period_unit'], 'starts_now' => $bStartsNow, 'txn_id' => $sTransactionId));
         $oZ->alert();
 
         // Send notification

+ 33 - 3
inc/classes/BxDolAclQuery.php

@@ -292,10 +292,40 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
         return (int)$this->query($sQuery, $aBindings) > 0;
     }
 
-    function insertLevelByProfileId($iProfileId, $iMembershipId, $iDateStarts, $iDateExpires, $sTransactionId)
+    function insertLevelByProfileId($iProfileId, $iMembershipId, $iDateStarts, $aPeriod, $sTransactionId)
     {
-        $sQuery = $this->prepare("INSERT `sys_acl_levels_members` (`IDMember`, `IDLevel`, `DateStarts`, `DateExpires`, `TransactionID`) VALUES (?, ?, FROM_UNIXTIME(?), FROM_UNIXTIME(?), ?)", $iProfileId, $iMembershipId, $iDateStarts, $iDateExpires, $sTransactionId);
-        return (int)$this->query($sQuery) > 0;
+    	$aBindings = array(
+			'member_id' => $iProfileId,
+			'level_id' => $iMembershipId,
+			'transaction_id' => $sTransactionId,
+			'date_starts' => $iDateStarts
+		);
+
+    	$sSetClause = '';
+    	if((int)$aPeriod['period'] != 0) {
+    		$aBindings['period'] = (int)$aPeriod['period'];
+
+	    	switch($aPeriod['period_unit']) {
+	    		case MEMBERSHIP_PERIOD_UNIT_DAY:
+	    		case MEMBERSHIP_PERIOD_UNIT_WEEK:
+	    			if($aPeriod['period_unit'] == MEMBERSHIP_PERIOD_UNIT_WEEK)
+	    				$aBindings['period'] *= 7;
+
+	    			$sSetClause = ", `DateExpires`=DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period DAY)";
+	    			break;
+
+	    		case MEMBERSHIP_PERIOD_UNIT_MONTH:
+	    			$sSetClause = ", `DateExpires`=DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period MONTH)";
+	    			break;
+
+	    		case MEMBERSHIP_PERIOD_UNIT_YEAR:
+	    			$sSetClause = ", `DateExpires`=DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period YEAR)";
+	    			break;
+	    	}
+    	}
+
+        $sQuery = $this->prepare("INSERT `sys_acl_levels_members` SET `IDMember`=:member_id, `IDLevel`=:level_id, `DateStarts`=FROM_UNIXTIME(:date_starts), `TransactionID`=:transaction_id" . $sSetClause);
+        return (int)$this->query($sQuery, $aBindings) > 0;
     }
 
     function deleteLevelByProfileId($iProfileId, $bAll = false)

+ 59 - 0
inc/classes/BxDolCronAcl.php

@@ -0,0 +1,59 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+class BxDolCronAcl extends BxDolCron
+{
+    public function processing()
+    {
+    	/*
+        $iExpireNotificationDays = (int)getParam("sys_acl_expire_notification_days");
+        $bExpireNotifyOnce = getParam("sys_acl_expire_notify_once") == 'on';
+
+        $iExpireLetters = 0;
+
+        $oDb = BxDolDb::getInstance();
+        $oAcl = BxDolAcl::getInstance();
+
+        $aRow = $oDb->getFirstRow( "SELECT `ID` FROM `Profiles`");
+        while(!empty($aRow)) {
+            $aCurrentMem = getMemberMembershipInfo( $aRow['ID'] );
+            // If expire_notification_days is -1 then notify after expiration
+            if ( $aCurrentMem['ID'] == MEMBERSHIP_ID_STANDARD && $iExpireNotificationDays == -1 ) {
+                // Calculate last UNIX Timestamp
+                $iLastTimestamp = time() - 24 * 3600;
+                $aLastMem = getMemberMembershipInfo( $aRow['ID'], $iLastTimestamp );
+                if($aCurrentMem['ID'] != $aLastMem['ID']) {
+                    $bMailResult = $oAcl->getExpirationLetter($aRow['ID'], $aLastMem['Name'], -1);
+                    if($bMailResult)
+                        $iExpireLetters++;
+                }
+            }
+            // If memberhip is not standard then check if it will change
+            else if($aCurrentMem['ID'] != MEMBERSHIP_ID_STANDARD) {
+                // Calculate further UNIX Timestamp
+                $iFurtherTimestamp = time() + $iExpireNotificationDays * 24 * 3600;
+                $aFurtherMem = getMemberMembershipInfo( $aRow['ID'], $iFurtherTimestamp );
+                if($aCurrentMem['ID'] != $aFurtherMem['ID'] && $aFurtherMem['ID'] == MEMBERSHIP_ID_STANDARD) {
+                    if(!$bExpireNotifyOnce || abs($iFurtherTimestamp - $aCurrentMem['DateExpires']) < 24 * 3600) {
+                        $bMailResult = $oAcl->getExpirationLetter( $aRow['ID'], $aCurrentMem['Name'], (int)(($aCurrentMem['DateExpires'] - time())/(24 * 3600)));
+                        if($bMailResult)
+                            $iExpireLetters++;
+                    }
+                }
+            }
+
+            $aRow = $oDb->getNextRow();
+        }
+
+        echo "Send membership expire letters: $iExpireLetters letters\n";
+        */
+    }
+}
+
+/** @} */

+ 12 - 0
install/sql/system.sql

@@ -389,6 +389,17 @@ SET @iCategoryId = LAST_INSERT_ID();
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 (@iCategoryId, 'sys_account_autoapproval', '_adm_stg_cpt_option_sys_account_autoapproval', 'on', 'checkbox', '', '', '', 10);
 
+
+--
+-- CATEGORY: ACL
+--
+INSERT INTO `sys_options_categories`(`type_id`, `name`, `caption`, `hidden`, `order`) VALUES (@iTypeId, 'acl', '_adm_stg_cpt_category_acl', 0, 15);
+SET @iCategoryId = LAST_INSERT_ID();
+
+INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
+(@iCategoryId, 'sys_acl_expire_notification_days', '_adm_stg_cpt_option_sys_acl_expire_notification_days', '1', 'digit', '', '', '', 1),
+(@iCategoryId, 'sys_acl_expire_notify_once', '_adm_stg_cpt_option_sys_acl_expire_notify_once', 'on', 'checkbox', '', '', '', 2);
+
 --
 -- Table structure for table `sys_options_mixes`
 --
@@ -1138,6 +1149,7 @@ CREATE TABLE `sys_cron_jobs` (
 
 INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES
 ('pruning', '0 0 * * *', 'BxDolCronPruning', 'inc/classes/BxDolCronPruning.php', ''),
+('sys_acl', '0 0 * * *', 'BxDolCronAcl', 'inc/classes/BxDolCronAcl.php', ''),
 ('sys_upgrade', '0 3 * * *', 'BxDolCronUpgradeCheck', 'inc/classes/BxDolCronUpgradeCheck.php', ''),
 ('sys_upgrade_modules', '30 2 * * *', 'BxDolCronUpgradeModulesCheck', 'inc/classes/BxDolCronUpgradeModulesCheck.php', ''),
 ('sys_storage', '* * * * *', 'BxDolCronStorage', 'inc/classes/BxDolCronStorage.php', ''),

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

@@ -1121,6 +1121,7 @@
 	<string name="_adm_prm_txt_visibility_items_nobody"><![CDATA[Nobody]]></string>
 	<string name="_adm_scs_operation_done"><![CDATA[]]></string>
 	<string name="_adm_stg_cpt_category_account"><![CDATA[Account]]></string>
+	<string name="_adm_stg_cpt_category_acl"><![CDATA[ACL]]></string>
 	<string name="_adm_stg_cpt_category_cache"><![CDATA[Cache]]></string>
 	<string name="_adm_stg_cpt_category_general"><![CDATA[General]]></string>
 	<string name="_adm_stg_cpt_category_languages"><![CDATA[Languages]]></string>
@@ -1145,6 +1146,8 @@
 	<string name="_adm_stg_cpt_option_site_email_notify"><![CDATA[Email to send site messages from]]></string>
 	<string name="_adm_stg_cpt_option_site_title"><![CDATA[Site title]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_autoapproval"><![CDATA[Automatic account activation after creation]]></string>
+	<string name="_adm_stg_cpt_option_sys_acl_expire_notification_days"><![CDATA[Number of days before membership expiration to notify members (-1 = after expiration)]]></string>
+	<string name="_adm_stg_cpt_option_sys_acl_expire_notify_once"><![CDATA[Notify members about membership expiration only once (every day otherwise)]]></string>
 	<string name="_adm_stg_cpt_option_sys_add_nofollow"><![CDATA[Add "nofollow" attribute for external links]]></string>
 	<string name="_adm_stg_cpt_option_sys_autoupdate_force_modified_files"><![CDATA[Force site and module auto-update, even if some files were modified]]></string>
 	<string name="_adm_stg_cpt_option_sys_autoupdate_modules"><![CDATA[Apps auto-update]]></string>

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

@@ -1121,6 +1121,7 @@
 	<string name="_adm_prm_txt_visibility_items_nobody"><![CDATA[Никого]]></string>
 	<string name="_adm_scs_operation_done"><![CDATA[]]></string>
 	<string name="_adm_stg_cpt_category_account"><![CDATA[Аккаунт]]></string>
+	<string name="_adm_stg_cpt_category_acl"><![CDATA[Уровни доступа]]></string>
 	<string name="_adm_stg_cpt_category_cache"><![CDATA[Кэш]]></string>
 	<string name="_adm_stg_cpt_category_general"><![CDATA[Общие]]></string>
 	<string name="_adm_stg_cpt_category_languages"><![CDATA[Языки]]></string>
@@ -1145,6 +1146,8 @@
 	<string name="_adm_stg_cpt_option_site_email_notify"><![CDATA[Имейл, с которого будут посылаться сообщения от сайта]]></string>
 	<string name="_adm_stg_cpt_option_site_title"><![CDATA[Название сайта]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_autoapproval"><![CDATA[Автоматическая активация аккаунта после создания]]></string>
+	<string name="_adm_stg_cpt_option_sys_acl_expire_notification_days"><![CDATA[За сколько дней до окончания членства оповестить пользователя об окончании (-1 = после окончания)]]></string>
+	<string name="_adm_stg_cpt_option_sys_acl_expire_notify_once"><![CDATA[Оповещать пользователей об окончании членства только одинажды (каждый день в противном случае)]]></string>
 	<string name="_adm_stg_cpt_option_sys_add_nofollow"><![CDATA[Добавить атрибут "nofollow" для внешних ссылок]]></string>
 	<string name="_adm_stg_cpt_option_sys_autoupdate_force_modified_files"><![CDATA[Инициировать автообновление для сайта и модулей, даже если какие-то файлы были модифицированы]]></string>
 	<string name="_adm_stg_cpt_option_sys_autoupdate_modules"><![CDATA[Автообновление Расширений]]></string>