HomeHelpTrac

Changeset 15759 for trunk/templates


Ignore:
Timestamp:
12/14/11 01:11:37 (6 months ago)
Author:
Alexander Trofimov
Message:

getStringWithLimitedLength

Location:
trunk/templates
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/templates/base/css/common.css

    r15752 r15759  
    311311} 
    312312 
    313  
    314  
     313/* --------------- button at the end of cut string */ 
     314 
     315.bx-str-limit { 
     316    height:10px; 
     317    width:14px;     
     318    margin-left:3px; 
     319 
     320    border-radius:3px; 
     321    -moz-border-radius:3px; 
     322    -webkit-border-radius:3px;   
     323 
     324    -moz-box-shadow:0px 0px 1px rgba(92, 92, 92, 0.8); 
     325    -webkit-box-shadow:0px 0px 1px rgba(92, 92, 92, 0.8); 
     326    box-shadow:0px 0px 1px rgba(92, 92, 92, 0.8); 
     327 
     328    cursor:pointer; 
     329} 
     330 
     331/* --------------- */ 
  • trunk/templates/base/scripts/BxBaseFunctions.php

    r15750 r15759  
    77defined('BX_DOL') or die('hack attempt'); 
    88 
     9bx_import('BxDolTemplate'); 
     10 
    911class BxBaseFunctions extends BxDol { 
    1012 
    11     var $aSpecialKeys; 
    12  
    13     function BxBaseFunctions() { 
     13    protected $_aSpecialKeys; 
     14    protected $_oTemplate; 
     15 
     16    function BxBaseFunctions($oTemplate) { 
    1417 
    1518        if (isset($GLOBALS['bxDolClasses'][get_class($this)])) 
    1619            trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR); 
    1720 
    18         parent::BxDol(); 
    19         $this -> aSpecialKeys = array('rate' => '', 'rate_cnt' => ''); 
     21        parent::BxDol();         
     22 
     23        if ($oTemplate) 
     24            $this->_oTemplate = $oTemplate; 
     25        else 
     26            $this->_oTemplate = BxDolTemplate::getInstance(); 
     27 
     28        $this->_aSpecialKeys = array('rate' => '', 'rate_cnt' => ''); 
    2029    } 
    2130 
     
    8291        $sKeyValue = trim($sKeyValue, '{}'); 
    8392 
    84         if ( array_key_exists($sKeyValue, $this -> aSpecialKeys) ) { 
     93        if ( array_key_exists($sKeyValue, $this->_aSpecialKeys) ) { 
    8594            return $aRow['Eval']; 
    8695        } else { 
     
    105114                    'extended_action'    => $sScriptAction, 
    106115                ); 
    107  
    108                 bx_import('BxDolTemplate'); 
    109                 $sOutputHtml .= BxDolTemplate::getInstance() -> parseHtmlByName( $aUsedTemplate['action'], $aTemplateKeys ); 
     116                 
     117                $sOutputHtml .= $this->_oTemplate->parseHtmlByName( $aUsedTemplate['action'], $aTemplateKeys ); 
    110118            } 
    111119        } 
     
    128136            // replace all founded markers ; 
    129137            foreach( $aMatches[3] as $iMarker => $sMarkerValue ) { 
    130                 if ( is_array($aMemberSettings) and array_key_exists($sMarkerValue, $aMemberSettings) and !array_key_exists($sMarkerValue, $this -> aSpecialKeys) ){ 
     138                if ( is_array($aMemberSettings) and array_key_exists($sMarkerValue, $aMemberSettings) and !array_key_exists($sMarkerValue, $this->_aSpecialKeys) ){ 
    131139                    $sTransformText = str_replace( '{' . $sMarkerValue . '}', $aMemberSettings[$sMarkerValue],  $sTransformText); 
    132140                } else if ( $sMarkerValue == 'evalResult' and $sExecuteCode ) { 
     
    136144                } else { 
    137145                    //  if isset into special keys ; 
    138                     if ( array_key_exists($sMarkerValue, $this -> aSpecialKeys) ) { 
     146                    if ( array_key_exists($sMarkerValue, $this->_aSpecialKeys) ) { 
    139147                        return $aMemberSettings[$sMarkerValue]; 
    140148                    } else { 
     
    159167        $iId = mktime() . mt_rand(1, 1000); 
    160168 
    161         bx_import('BxDolTemplate'); 
    162         return BxDolTemplate::getInstance()->parseHtmlByName('messageBox.html', array( 
     169        return $this->_oTemplate->parseHtmlByName('messageBox.html', array( 
    163170            'id' => $iId, 
    164171            'msgText' => $sText, 
     
    175182 
    176183    function loadingBox($sName) { 
    177         bx_import('BxDolTemplate'); 
    178         return BxDolTemplate::getInstance()->parseHtmlByName('loading.html', array( 
     184        return $this->_oTemplate->parseHtmlByName('loading.html', array( 
    179185            'name' => $sName, 
    180186        )); 
     
    219225            ); 
    220226 
    221         bx_import('BxDolTemplate'); 
    222         return BxDolTemplate::getInstance()->parseHtmlByName('popup_box.html', array( 
     227        return $this->_oTemplate->parseHtmlByName('popup_box.html', array( 
    223228            'id' => $iId, 
    224229            'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '', 
     
    230235 
    231236    function transBox($content, $isPlaceInCenter = false) { 
    232         bx_import('BxDolTemplate'); 
    233237        return 
    234238            ($isPlaceInCenter ? '<div class="login_ajax_wrap">' : '') . 
    235                 BxDolTemplate::getInstance()->parseHtmlByName('popup_trans.html', array('content' => $content)) . 
     239                $this->_oTemplate->parseHtmlByName('popup_trans.html', array('content' => $content)) . 
    236240            ($isPlaceInCenter ? '</div>' : ''); 
    237241    } 
     
    349353        } 
    350354 
    351         bx_import('BxDolTemplate'); 
    352         return BxDolTemplate::getInstance()->parseHtmlByName($bCouple ? "thumbnail_couple.html" : "thumbnail_single.html", $aVariables); 
     355        return $this->_oTemplate->parseHtmlByName($bCouple ? "thumbnail_couple.html" : "thumbnail_single.html", $aVariables); 
    353356    } 
    354357 
     
    367370    } 
    368371 
    369     function getTemplateIcon($sName) { 
    370         bx_import('BxDolTemplate'); 
    371         $oSysTemplate = BxDolTemplate::getInstance(); 
    372              
    373         $sUrl = $oSysTemplate->getIconUrl($sName); 
    374         return !empty($sUrl) ? $sUrl : $oSysTemplate->getIconUrl('spacer.gif'); 
     372    function getTemplateIcon($sName) {             
     373        $sUrl = $this->_oTemplate->getIconUrl($sName); 
     374        return !empty($sUrl) ? $sUrl : $this->_oTemplate->getIconUrl('spacer.gif'); 
    375375    } 
    376376 
    377377    function getTemplateImage($sName) { 
    378         bx_import('BxDolTemplate'); 
    379         $oSysTemplate = BxDolTemplate::getInstance(); 
    380  
    381         $sUrl = $oSysTemplate->getImageUrl($sName); 
    382         return !empty($sUrl) ? $sUrl : $oSysTemplate->getImageUrl('spacer.gif'); 
     378        $sUrl = $this->_oTemplate->getImageUrl($sName); 
     379        return !empty($sUrl) ? $sUrl : $this->_oTemplate->getImageUrl('spacer.gif'); 
    383380    } 
    384381 
     
    391388    */ 
    392389    function genObjectsActions( &$aKeys,  $sActionsType, $bSubMenuMode = false ) { 
    393         bx_import('BxDolTemplate'); 
    394         $oSysTemplate = BxDolTemplate::getInstance(); 
    395390             
    396391        // ** init some needed variables ; 
     
    491486            // is there any value to having this template even if the ID is empty? 
    492487            if ( !empty($aKeys['ID']) ) { 
    493                 $sResponceBlock = $oSysTemplate -> parseHtmlByName( $aUsedTemplate['ajaxy_popup'], array('object_id' => $aKeys['ID']) ); 
     488                $sResponceBlock = $this->_oTemplate->parseHtmlByName( $aUsedTemplate['ajaxy_popup'], array('object_id' => $aKeys['ID']) ); 
    494489            } 
    495490 
     
    499494            ); 
    500495 
    501             $sActionsList = $oSysTemplate -> parseHtmlByName( $aUsedTemplate['actions'], $aTemplateKeys ); 
     496            $sActionsList = $this->_oTemplate->parseHtmlByName( $aUsedTemplate['actions'], $aTemplateKeys ); 
    502497        } 
    503498 
     
    577572        ); 
    578573 
    579         bx_import('BxDolTemplate'); 
    580         $sOutputHtml = BxDolTemplate::getInstance() -> parseHtmlByName( 'menu_bottom.html', $aTemplateKeys ); 
     574        $sOutputHtml = $this->_oTemplate->parseHtmlByName( 'menu_bottom.html', $aTemplateKeys ); 
    581575 
    582576        if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endMenu('Bottom Menu'); 
     
    613607     * @param $iRssNum - numbr of rss items to disolay 
    614608     * @param $iMemberId - optional member id 
    615      * @param $oTemplate - optional template object, BxDolTemplate singleton is used by default 
    616609     */ 
    617     function getRssHolder ($mixedRssId, $iRssNum, $iMemberId = 0, $oTemplate = false) { 
    618  
    619         if (!$oTemplate) 
    620             $oTemplate = BxDolTemplate::getInstance(); 
     610    function getRssHolder ($mixedRssId, $iRssNum, $iMemberId = 0) { 
     611 
    621612 
    622613        if (!isset($GLOBALS['gbBxSysIsRssInitialized']) || !$GLOBALS['gbBxSysIsRssInitialized']) { 
    623614 
    624             $oTemplate->addCss(array( 
     615            $this->_oTemplate->addCss(array( 
    625616                'rss.css', 
    626617            )); 
    627618 
    628             $oTemplate->addJs(array( 
     619            $this->_oTemplate->addJs(array( 
    629620                'jquery.dolRSSFeed.js', 
    630621                'jquery.jfeed.js' 
    631622            )); 
    632623 
    633             $oTemplate->addInjection ('injection_head', 'text', ' 
     624            $this->_oTemplate->addInjection ('injection_head', 'text', ' 
    634625                <script type="text/javascript" language="javascript"> 
    635626                    $(document).ready( function() { 
     
    641632        } 
    642633 
    643         return $oTemplate->parseHtmlByName('rss_holder.html', array ( 
     634        return $this->_oTemplate->parseHtmlByName('rss_holder.html', array ( 
    644635            'rss_id' => $mixedRssId, 
    645636            'rss_num' => $iRssNum, 
     
    659650            return ''; 
    660651 
    661         bx_import('BxDolTemplate'); 
    662         $oTemplate = BxDolTemplate::getInstance(); 
    663  
    664652        $sOutputCode = ''; 
    665653        foreach( $aLangs as $sName => $sLang ) { 
    666             $sFlag = $oTemplate->getIconUrl('sys_fl_' . $sName . '.gif'); 
     654            $sFlag = $this->_oTemplate->getIconUrl('sys_fl_' . $sName . '.gif'); 
    667655            $aTemplateKeys = array ( 
    668656                'bx_if:item_img' => array ( 
     
    681669            ); 
    682670 
    683             $sOutputCode .= $oTemplate->parseHtmlByName( 'member_menu_sub_item.html', $aTemplateKeys ); 
     671            $sOutputCode .= $this->_oTemplate->parseHtmlByName( 'member_menu_sub_item.html', $aTemplateKeys ); 
    684672        } 
    685673     
    686674        return $sOutputCode; 
    687675    } 
     676 
     677    /** 
     678     * functions for limiting maximal string length  
     679     */ 
     680    function getStringWithLimitedLength($sString, $iWidth = 45, $isPopupOnOverflow =  false) { 
     681        if (empty($sString) || mb_strlen($sString, 'UTF-8') <= $iWidth) 
     682            return $sString; 
     683 
     684        $sResult = ''; 
     685        $aWords = mb_split("[\s\r\n]", $sString); 
     686        $iPosition = 0; 
     687        $iWidthReal = $iWidth - 3; 
     688        $iWidthMin = $iWidth - 15; 
     689        foreach($aWords as $sWord) { 
     690            $sWord = trim($sWord); 
     691            $iWord = mb_strlen($sWord, 'UTF-8'); 
     692            if ($iPosition + $iWord <= $iWidthReal) { 
     693                // add word and continue 
     694                $sResult .= ' ' . $sWord; 
     695                $iPosition += 1 + $iWord; 
     696                continue;             
     697            } 
     698 
     699            // stop adding words 
     700 
     701            if (!$iPosition || $iPosition < $iWidthMin) { 
     702                // last word is too long, cut it   
     703                $sResult .= ' ' . mb_substr($sWord, 0, $iWidthReal - $iPosition - $iWord, 'UTF-8'); 
     704            }  
     705         
     706            if (!$isPopupOnOverflow) { 
     707                // add tripple dot 
     708                $sResult .= '...'; 
     709            } else { 
     710 
     711                // add button width popup             
     712                $sId = 'bx-str-limit-' . rand(1, PHP_INT_MAX ); 
     713                $sResult .= '<img class="bx-str-limit" onclick="$(\'#' . $sId . '\').dolPopup({pointer:{el:$(this)}})" src="' . $this->getTemplateImage('str-limit.png') . '"/>'; 
     714                $sResult .= '<div id="' . $sId . '" style="display:none;">' . BxTemplFunctions::getInstance()->transBox('<div class="bx-def-padding bx-def-color-bg-block">'.$sString.'</div>') . '</div>'; 
     715            } 
     716 
     717            break; 
     718        } 
     719 
     720        return trim($sResult); 
     721    } 
    688722} 
  • trunk/templates/base/scripts/BxBaseGrid.php

    r15744 r15759  
    2020    protected $_aPopupOptions = false; 
    2121    protected $_aQueryAppend = false; 
     22    protected $_isDisplayPopupOnTextOverflow = true; 
    2223 
    2324    public function __construct ($aOptions, $oTemplate) { 
     
    357358 
    358359        $mixedValue = $this->_getCellData($sKey, $aField, $aRow); 
     360        $mixedValue = $this->_limitMaxLength($mixedValue, $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow); 
    359361        return $this->$sMethod($mixedValue, $sKey, $aField, $aRow); 
    360362    } 
     
    479481    } 
    480482 
     483    protected function _limitMaxLength ($mixedValue, $sKey, $aField, $aRow, $isDisplayPopupOnTextOverflow) { 
     484        if ($aField['chars_limit'] > 0) { 
     485            bx_import('BxTemplFunctions'); 
     486            $mixedValue = BxTemplFunctions::getInstance()->getStringWithLimitedLength($mixedValue, $aField['chars_limit'], $isDisplayPopupOnTextOverflow); 
     487        } 
     488        return $mixedValue; 
     489    } 
     490 
    481491    protected function _convertAttrs ($aField, $sAttrName, $sClasses = false, $sStyles = false) { 
    482492        return bx_convert_array2attrs( 
  • trunk/templates/tmpl_uni/scripts/BxTemplFunctions.php

    r15211 r15759  
    1313     * class constructor 
    1414     */ 
    15     function BxTemplFunctions() { 
    16         parent::BxBaseFunctions(); 
     15    function __construct($oTemplate = null) { 
     16        parent::__construct($oTemplate); 
    1717    } 
    1818} 
Note: See TracChangeset for help on using the changeset viewer.