Ignore:
Timestamp:
Mar 8, 2011, 1:19:06 PM (13 years ago)
Author:
mistic100
Message:

[extensions] ContestResults 1.3

  • Add error and success messages on admin page
  • Add Spain (es_ES) thanks to jpr928
  • Contest status is automatic and shows remaining days
  • More flexibility for description fields
  • Compatibility with Piwigo 2.2.0
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/ContestResults/include/cutstring.class.php

    r6782 r9572  
    66
    77class HtmlCutString{
    8   function __construct($string, $limit){
    9     // create dom element using the html string
    10     $this->tempDiv = new DomDocument;
    11     $this->tempDiv->loadXML('<div>'.$string.'</div>');
    12     // keep the characters count till now
    13     $this->charCount = 0;
    14     $this->encoding = 'UTF-8';
    15     // character limit need to check
    16     $this->limit = $limit;
    17   }
    18   function cut(){
    19     // create empty document to store new html
    20     $this->newDiv = new DomDocument;
    21     // cut the string by parsing through each element
    22     $this->searchEnd($this->tempDiv->documentElement,$this->newDiv);
    23     $newhtml = $this->newDiv->saveHTML();
    24     return $newhtml;
    25   }
    26 
    27   function deleteChildren($node) {
    28     while (isset($node->firstChild)) {
    29       $this->deleteChildren($node->firstChild);
    30       $node->removeChild($node->firstChild);
    31     }
    32   }
    33   function searchEnd($parseDiv, $newParent){
    34     foreach($parseDiv->childNodes as $ele){
    35         // not text node
    36         if($ele->nodeType != 3){
    37           $newEle = $this->newDiv->importNode($ele,true);
    38           if(count($ele->childNodes) === 0){
    39             $newParent->appendChild($newEle);
    40             continue;
    41           }
    42           $this->deleteChildren($newEle);
    43           $newParent->appendChild($newEle);
    44             $res = $this->searchEnd($ele,$newEle);
    45             if($res)
    46                         return $res;
    47             else
    48                         continue;
     8        function __construct($string, $limit){
     9                // create dom element using the html string
     10                $this->tempDiv = new DomDocument;
     11                $this->tempDiv->loadXML('<div>'.$string.'</div>');
     12                // keep the characters count till now
     13                $this->charCount = 0;
     14                $this->encoding = 'UTF-8';
     15                // character limit need to check
     16                $this->limit = $limit;
    4917        }
    50 
    51         // the limit of the char count reached
    52         if(mb_strlen($ele->nodeValue,$this->encoding) + $this->charCount >= $this->limit){
    53           $newEle = $this->newDiv->importNode($ele);
    54             $newEle->nodeValue = substr($newEle->nodeValue,0, $this->limit - $this->charCount);
    55             $newParent->appendChild($newEle);
    56             return true;
     18        function cut(){
     19                // create empty document to store new html
     20                $this->newDiv = new DomDocument;
     21                // cut the string by parsing through each element
     22                $this->searchEnd($this->tempDiv->documentElement,$this->newDiv);
     23                $newhtml = $this->newDiv->saveHTML();
     24                return $newhtml;
    5725        }
    58         $newEle = $this->newDiv->importNode($ele);
    59         $newParent->appendChild($newEle);
    60         $this->charCount += mb_strlen($newEle->nodeValue,$this->encoding);
    61     }
    62     return false;
    63   }
     26        function deleteChildren($node) {
     27                while (isset($node->firstChild)) {
     28                        $this->deleteChildren($node->firstChild);
     29                        $node->removeChild($node->firstChild);
     30                }
     31        }
     32        function searchEnd($parseDiv, $newParent){
     33                foreach($parseDiv->childNodes as $ele){
     34                        // not text node
     35                        if($ele->nodeType != 3){
     36                                $newEle = $this->newDiv->importNode($ele,true);
     37                                if(count($ele->childNodes) === 0){
     38                                        $newParent->appendChild($newEle);
     39                                        continue;
     40                                }
     41                                $this->deleteChildren($newEle);
     42                                $newParent->appendChild($newEle);
     43                                $res = $this->searchEnd($ele,$newEle);
     44                                if($res)
     45                                        return $res;
     46                                else
     47                                        continue;
     48                        }
     49                        // the limit of the char count reached
     50                        if(mb_strlen($ele->nodeValue,$this->encoding) + $this->charCount >= $this->limit){
     51                                $newEle = $this->newDiv->importNode($ele);
     52                                $newEle->nodeValue = substr($newEle->nodeValue,0, $this->limit - $this->charCount);
     53                                $newParent->appendChild($newEle);
     54                                return true;
     55                        }
     56                        $newEle = $this->newDiv->importNode($ele);
     57                        $newParent->appendChild($newEle);
     58                        $this->charCount += mb_strlen($newEle->nodeValue,$this->encoding);
     59                }
     60                return false;
     61        }
    6462}
    6563?>
Note: See TracChangeset for help on using the changeset viewer.