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

#42 - profiles modules should have 'message' button to write directly to the profile, auto-shrink input for entering recipient name

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

+ 35 - 35
inc/classes/BxDolForm.php

@@ -1311,7 +1311,7 @@ class BxDolFormCheckerHelper
 {
     // check functions - check values for limits or patterns
 
-    function checkLength ($s, $iLenMin, $iLenMax)
+    static public function checkLength ($s, $iLenMin, $iLenMax)
     {
         if (is_array($s)) {
             foreach ($s as $k => $v) {
@@ -1324,19 +1324,19 @@ class BxDolFormCheckerHelper
         $iLen = get_mb_len ($s);
         return $iLen >= $iLenMin && $iLen <= $iLenMax ? true : false;
     }
-    function checkDate ($s)
+    static public function checkDate ($s)
     {
-        return $this->checkPreg ($s, '#^\d+\-\d+\-\d+$#');
+        return self::checkPreg ($s, '#^\d+\-\d+\-\d+$#');
     }
-    function checkDateTime ($s)
+    static public function checkDateTime ($s)
     {
         // remove unnecessary opera's input value;
         $s = str_replace('T', ' ', $s);
         $s = str_replace('Z', ':00', $s);
 
-        return $this->checkPreg ($s, '#^\d+\-\d+\-\d+[\sT]{1}\d+:\d+[:\d+]$#');
+        return self::checkPreg ($s, '#^\d+\-\d+\-\d+[\sT]{1}\d+:\d+[:\d+]$#');
     }
-    function checkPreg ($s, $r)
+    static public function checkPreg ($s, $r)
     {
         if (is_array($s)) {
             foreach ($s as $k => $v)
@@ -1346,18 +1346,18 @@ class BxDolFormCheckerHelper
         }
         return preg_match($r, $s) ? true : false;
     }
-    function checkAvail ($s)
+    static public function checkAvail ($s)
     {
         if (is_array($s)) {
-            return !$this->_isEmptyArray($s);
+            return !self::_isEmptyArray($s);
         }
         return $s ? true : false;
     }
-    function checkEmail($s)
+    static public function checkEmail($s)
     {
-        return $this->checkPreg ($s, '/^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel)$/i');
+        return self::checkPreg ($s, '/^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel)$/i');
     }
-    function checkCaptcha($s)
+    static public function checkCaptcha($s)
     {
         bx_import('BxDolCaptcha');
         $oCaptcha = BxDolCaptcha::getObjectInstance();
@@ -1365,7 +1365,7 @@ class BxDolFormCheckerHelper
             return true;
         return $oCaptcha->check ();
     }
-    function checkIsSpam($val)
+    static public function checkIsSpam($val)
     {
         $bSpam = false;
         bx_alert('system', 'check_spam', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => $val, 'where' => 'form'));
@@ -1373,7 +1373,7 @@ class BxDolFormCheckerHelper
     }
 
     // pass functions, prepare values to insert to database
-    function passInt ($s)
+    static public function passInt ($s)
     {
         if (is_array($s)) {
             $a = array ();
@@ -1384,7 +1384,7 @@ class BxDolFormCheckerHelper
         }
         return (int)$s;
     }
-    function passFloat ($s)
+    static public function passFloat ($s)
     {
         if (is_array($s)) {
             $a = array ();
@@ -1395,43 +1395,43 @@ class BxDolFormCheckerHelper
         }
         return (float)$s;
     }
-    function passDate ($s)
+    static public function passDate ($s)
     {
         if (is_array($s)) {
             $a = array ();
             foreach ($s as $k => $v) {
-                $a[$k] = $this->_passDate ($v);
+                $a[$k] = self::_passDate ($v);
             }
             return $a;
         }
-        return $this->_passDate ($s);
+        return self::_passDate ($s);
     }
-    function _passDate ($s)
+    static public function _passDate ($s)
     {
         $iRet = bx_process_input ($s, BX_DATA_DATE_TS);
         if (false === $iRet)
             return 0;
         return $iRet;
     }
-    function passDateTime ($s)
+    static public function passDateTime ($s)
     {
         if (is_array($s)) {
             $a = array ();
             foreach ($s as $k => $v) {
-                $a[$k] = $this->_passDateTime ($v);
+                $a[$k] = self::_passDateTime ($v);
             }
             return $a;
         }
-        return $this->_passDateTime ($s);
+        return self::_passDateTime ($s);
     }
-    function _passDateTime ($s)
+    static public function _passDateTime ($s)
     {
         $iRet = bx_process_input ($s, BX_DATA_DATETIME_TS);
         if (false === $iRet)
             return 0;
         return $iRet;
     }
-    function passXss ($s)
+    static public function passXss ($s)
     {
         if (is_array($s)) {
             $a = array ();
@@ -1442,7 +1442,7 @@ class BxDolFormCheckerHelper
         }
         return bx_process_input ($s, BX_DATA_TEXT); // "strip tags" option was here in 7.0
     }
-    function passXssHtml ($s)
+    static public function passXssHtml ($s)
     {
         if (is_array($s)) {
             $a = array ();
@@ -1454,7 +1454,7 @@ class BxDolFormCheckerHelper
         return bx_process_input ($s, BX_DATA_HTML);
     }
 
-    function passAll ($s)
+    static public function passAll ($s)
     {
         if (is_array($s)) {
             $a = array ();
@@ -1466,25 +1466,25 @@ class BxDolFormCheckerHelper
         return bx_process_input ($s);
     }
 
-    function passPreg ($s, $r)
+    static public function passPreg ($s, $r)
     {
         if (is_array($s)) {
             $a = array ();
             foreach ($s as $k => $v) {
-                $a[$k] = $this->_passPreg ($v, $r);
+                $a[$k] = self::_passPreg ($v, $r);
             }
             return $a;
         }
-        return $this->_passPreg($s, $r);
+        return self::_passPreg($s, $r);
     }
-    function _passPreg ($s, $r)
+    static public function _passPreg ($s, $r)
     {
         if (preg_match ($r, $s, $m)) {
             return $m[1];
         }
         return '';
     }
-    function passBoolean ($s)
+    static public function passBoolean ($s)
     {
         if (is_array($s)) {
             $a = array ();
@@ -1496,7 +1496,7 @@ class BxDolFormCheckerHelper
         return $s == 'on' ? true : false;
     }
 
-    function passSet ($s)
+    static public function passSet ($s)
     {
         if (is_array($s)) {
             $i = 0;
@@ -1509,15 +1509,15 @@ class BxDolFormCheckerHelper
 
     // display functions, prepare values to output to the screen
 
-    function displayDate ($i)
+    static public function displayDate ($i)
     {
         return bx_process_output ($i, BX_DATA_DATE_TS);
     }
-    function displayDateTime ($i)
+    static public function displayDateTime ($i)
     {
         return bx_process_output ($i, BX_DATA_DATETIME_TS);
     }
-    function displaySet ($i)
+    static public function displaySet ($i)
     {
         $bit = 1;
         $a = array();
@@ -1531,7 +1531,7 @@ class BxDolFormCheckerHelper
 
     // for internal usage only
 
-    function _isEmptyArray ($a)
+    static public function _isEmptyArray ($a)
     {
         if (!is_array($a))
             return true;

+ 1 - 1
inc/classes/BxDolMenuQuery.php

@@ -49,7 +49,7 @@ class BxDolMenuQuery extends BxDolDb
             return false;
 
         if (empty($aMenuItem['order'])) {
-            $sQuery = $oDb->prepare("SELECT `order` FROM `sys_menu_items` WHERE `set_name` = ? AND `active` = 1 ORDER BY `order` DESC LIMIT 1", $aMenuItem['set_name']);
+            $sQuery = $oDb->prepare("SELECT `order` FROM `sys_menu_items` WHERE `set_name` = ? AND `active` = 1 AND `order` != 9999 ORDER BY `order` DESC LIMIT 1", $aMenuItem['set_name']);
             $iProfileMenuOrder = (int)$oDb->getOne($sQuery);
             $aMenuItem['order'] = $iProfileMenuOrder + 1;
         }

+ 2 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -31,6 +31,8 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolPro
     {
         if ('trigger_profile_view_submenu' == $sMenuTriggerName)
             return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
+        elseif ('trigger_profile_view_actions' == $sMenuTriggerName)
+            return $this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
         return '';
     }
 

+ 50 - 26
modules/boonex/convos/classes/BxCnvFormEntry.php

@@ -95,7 +95,9 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
         $sVals = '';
         if (!empty($aInput['value']) && is_array($aInput['value'])) {
             foreach ($aInput['value'] as $sVal) {
-               $sVals .= '<span class="bx-def-color-bg-hl bx-def-round-corners">' . BxDolProfile::getInstance($sVal)->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></span>';
+                if (!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
+                    continue;
+               $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $oProfile->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></b>';
             }
             $sVals = trim($sVals, ',');
         }
@@ -116,8 +118,11 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
         });
 
         $('#{$sId} input[type=text]').on('superselect', function(e, item) {
+            $(this).hide();
             if ('undefined' != typeof(item))
-                $(this).before('<span class="bx-def-color-bg-hl bx-def-round-corners">'+ item.label +'<input type="hidden" name="{$aInput['name']}[]" value="'+ item.value +'" /></span>');
+                $(this).before('<b class="bx-def-color-bg-hl bx-def-round-corners">'+ item.label +'<input type="hidden" name="{$aInput['name']}[]" value="'+ item.value +'" /></b>');
+            fAutoShrinkInput();
+            $(this).show();
             this.value = '';
 
         }).on('keydown', function(e) {
@@ -128,42 +133,54 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
 
         });
 
-        $('#{$sId}').on('click', 'span', function() {
+        $('#{$sId}').on('click', 'b', function() {
             $(this).remove();
+            fAutoShrinkInput();
         });
 
+        fAutoShrinkInput = function () {
+            var iWidthCont = $('#{$sId}.bx-form-input-autotoken').innerWidth();
+            var iWidthExisting = 0;
+            $('#{$sId}.bx-form-input-autotoken b').each(function () {
+                iWidthExisting += $(this).outerWidth(true);
+            });
+            $('#{$sId}.bx-form-input-autotoken input').width(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
+        };
+
+        fAutoShrinkInput();
     });
 </script>
 <style>
     .bx-form-input-autotoken {
-      float:left;
-      padding:0px;
-      height:auto;
+        float:left;
+        padding:0px;
+        height:auto;
     }
-    .bx-form-input-autotoken span {
-      cursor:pointer;
-      display:block;
-      float:left;
-      padding:0.5em;
-      padding-right:1.5em;
-      margin:0.1em;
+    .bx-form-input-autotoken b {
+        cursor:pointer;
+        display:block;
+        float:left;
+        padding:0.5em;
+        padding-right:1.5em;
+        margin:0.1em;
+        font-weight:normal;
     }
-    .bx-form-input-autotoken span:hover{
-      opacity:0.7;
+    .bx-form-input-autotoken b:hover {
+        opacity:0.7;
     }
-    .bx-form-input-autotoken span:after{
-     position:absolute;
-     content:"x";
-     padding:0 0.5em;
-     margin:0.2em 0 0.7em 0.5em;
-     font-size:0.7em;
-     font-weight:bold;
+    .bx-form-input-autotoken b:after {
+        position:absolute;
+        content:"x";
+        padding:0 0.5em;
+        margin:0.2em 0 0.7em 0.5em;
+        font-size:0.7em;
+        font-weight:bold;
     }
     .bx-form-input-autotoken input {
-      border:0;
-      margin:0;
-      padding:0 0 0 5px;
-      width:auto;
+        border:0;
+        margin:0;
+        padding:0 0 0 5px;
+        width:auto;
     }
 </style>
 <div id="{$sId}" class="bx-form-input-autotoken bx-def-font-inputs bx-form-input-text">
@@ -187,6 +204,13 @@ EOS;
                 $aValues = array_merge($aContentInfo, $aValues);
         }
 
+        if ($sProfilesIds = bx_get('profiles')) { // if writing directly to some recipients, pre-fill them
+            $a = explode(',', $sProfilesIds);
+            $a = array_unique(BxDolFormCheckerHelper::passInt($a));
+            if ($a)
+                $aValues['recipients'] = array_merge(empty($aValues['recipients']) ? array() : $aValues['recipients'], $a);
+            
+        }
         return parent::initChecker ($aValues, $aSpecificValues);
     }
 

+ 1 - 0
modules/boonex/convos/install/installer.php

@@ -18,6 +18,7 @@ class BxCnvInstaller extends BxBaseModTextInstaller
         parent::__construct($aConfig);
         $this->_aTranscoders = array ('bx_convos_preview');
         $this->_aStorages = array ('bx_convos_files');
+        $this->_aMenuTriggers = array ('trigger_profile_view_actions');
     }
 }
 

+ 4 - 2
modules/boonex/convos/install/langs/en.xml

@@ -54,10 +54,12 @@
     <string name="_bx_cnv_menu_title_folders_more"><![CDATA[Conversations folders]]></string>
     <string name="_bx_cnv_menu_set_title_submenu"><![CDATA[Conversations folders]]></string>
     <string name="_bx_cnv_menu_set_title_folders_more"><![CDATA[More folders]]></string>
-
-
+    <string name="_bx_cnv_menu_item_title_system_message"><![CDATA[Message]]></string>
+    <string name="_bx_cnv_menu_item_title_message"><![CDATA[Message]]></string>
     <string name="_bx_cnv_menu_item_title_system_mark_unread_entry"><![CDATA[Mark as unread]]></string>
     <string name="_bx_cnv_menu_item_title_mark_unread_entry"><![CDATA[Mark as unread]]></string>
+
+
     <string name="_bx_cnv_menu_item_title_system_delete_entry"><![CDATA[Delete conversation]]></string>
     <string name="_bx_cnv_menu_item_title_delete_entry"><![CDATA[Delete conversation]]></string>
     <string name="_bx_cnv_menu_item_title_system_folder_inbox"><![CDATA[Inbox]]></string>

+ 4 - 0
modules/boonex/convos/install/sql/enable.sql

@@ -102,6 +102,10 @@ INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `tit
 INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
 ('sys_profile_stats', 'bx_convos', 'profile-stats-unread-messages', '_bx_cnv_menu_item_title_system_unread_messages', '_bx_cnv_menu_item_title_unread_messages', 'modules/?r=convos/folder/1', '', '', 'comments col-red1', 'a:2:{s:6:"module";s:9:"bx_convos";s:6:"method";s:23:"get_unread_messages_num";}', '', 2147483646, 1, 0, 2);
 
+-- MENU: add menu item to profiles modules actions menu (trigger* menu sets are processed separately upon modules enable/disable)
+
+INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES 
+('trigger_profile_view_actions', 'bx_convos', 'convos-compose', '_bx_cnv_menu_item_title_system_message', '_bx_cnv_menu_item_title_message', 'page.php?i=start-convo&profiles={profile_id}', '', '', '', '', 2147483647, 1, 0, 0);
 
 -- GRID
 

+ 1 - 1
modules/boonex/persons/install/installer.php

@@ -22,7 +22,7 @@ class BxPersonsInstaller extends BxBaseModProfileInstaller
             'sys_profiles_friends' => array ('type' => 'profiles'),
             'sys_profiles_subscriptions' => array ('type' => 'profiles'),
         );
-        $this->_aMenuTriggers = array ('trigger_profile_view_submenu');
+        $this->_aMenuTriggers = array ('trigger_profile_view_submenu', 'trigger_profile_view_actions');
     }
 }