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
Location:
extensions/ContestResults/include
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/ContestResults/include/cr_comment_picture.php

    r9200 r9572  
    11<?php
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     3
     4// +-----------------------------------------------------------------------+
     5//              Affichage du commentaire sur la page d'une image participante
     6// +-----------------------------------------------------------------------+
    37
    48// Requète simple pour savoir si l'image a participé à des concours
     
    610
    711if(pwg_db_num_rows($participation)){
     12        // requète complète
    813        $results = pwg_query("SELECT
    914                        i.rank,
     
    4651        </style>';
    4752
     53        // +-----------------------------------------------------------------------+
     54        //                              Template
     55        // +-----------------------------------------------------------------------+
    4856        $template->assign('COMMENT_IMG', $template->get_template_vars('COMMENT_IMG') . $comment);
    49         $template->assign('PLUGIN_PICTURE_BEFORE', $template->get_template_vars('PLUGIN_PICTURE_BEFORE') . $css);
     57        $template->append('footer_elements', $css);
    5058}
    5159?>
  • extensions/ContestResults/include/cr_main.php

    r9200 r9572  
    1111                date_begin,
    1212                date_end,
    13                 status,
    1413                logo,
    1514                summary
     
    1918while ($contest = pwg_db_fetch_assoc($contests)) {
    2019        if ($contest['visible'] OR is_admin()) {
     20                $contest['finished'] = is_date_passed($contest['date_end']);
     21               
    2122                // infos sur le concours
    2223                $item =  array(
     
    2425                        'NAME' => trigger_event('render_CR_content', $contest['name']),
    2526                        'VISIBLE' => $contest['visible'],
    26                         'STATUS' => $contest['status'],
     27                        'FINISHED' => $contest['finished'],
    2728                        'DATE_END' => format_date($contest['date_end']),
    2829                        'DATE_BEGIN' => format_date($contest['date_begin']),
     
    3031                        'SUMMARY' => CR_cut_string(trigger_event('render_CR_content', $contest['summary']), 350),
    3132                        'URL' => CR_PUBLIC . $contest['id'] . '-' . str2url(trigger_event('render_CR_content', $contest['name'])),
     33                        'DAYS' => DateDiff($contest['date_end'], date('Y-m-d')),
    3234                );
    3335               
    3436                // podium si terminé
    35                 if ($contest['status'] == 'finished') {
     37                if ($contest['finished'] == true) {
    3638                        $results = pwg_query("SELECT
    3739                                        i.id,
     
    6769//                              Template
    6870// +-----------------------------------------------------------------------+
     71if (is_admin()) {
     72        $template->assign('U_EDIT', CR_ADMIN);
     73}
    6974$template->assign('CR_PATH', CR_PATH);
    7075$template->assign('SEPARATOR', $conf['level_separator']);
  • extensions/ContestResults/include/cr_menubar.php

    r9200 r9572  
    3737                                name,
    3838                                visible,
    39                                 status,
    4039                                date_begin,
    4140                                date_end
     
    4342                        ORDER BY date_begin DESC;");
    4443
    45                 $m = 0; // copteur pour limiter le nombre de concours affichés
     44                $m = 0; // compteur pour limiter le nombre de concours affichés
    4645                while($contest = pwg_db_fetch_assoc($contests)){
    4746                        if (($contest['visible'] OR is_admin()) AND $m < $config['menubar_block']['number']) {
     
    5049                                        'LABEL' => trigger_event('render_CR_content', $contest['name']),
    5150                                        'DATE' => format_date($contest['date_begin']) . ' - ' . format_date($contest['date_end']),
    52                                         'STATUS' => $contest['status'],
    53                                         'VISIBLE' => $contest['visible']
     51                                        'VISIBLE' => $contest['visible'],
     52                                        'FINISHED' => is_date_passed($contest['date_end']),
     53                                        'DAYS' => DateDiff($contest['date_end'],date('Y-m-d')),
    5454                                ));
    5555                        }
  • extensions/ContestResults/include/cr_page.php

    r9200 r9572  
    1515if (pwg_db_num_rows($contest)) {
    1616        $contest = pwg_db_fetch_assoc($contest);
     17        $contest['finished'] = is_date_passed($contest['date_end']);
    1718       
    1819        // Concours non-publique
     
    2526                'ID' => $contest['id'],
    2627                'NAME' => trigger_event('render_CR_content', $contest['name']),
    27                 'STATUS' => $contest['status'],
    2828                'VISIBLE' => $contest['visible'],
     29                'FINISHED' => $contest['finished'],
    2930                'DATE_BEGIN' => format_date($contest['date_begin']),
    3031                'DATE_END' => format_date($contest['date_end']),
     
    3233                'BANNER' => $contest['banner'],
    3334                'URL' => CR_PUBLIC . $contest['id'] . '-' . str2url(trigger_event('render_CR_content', $contest['name'])),
     35                'DAYS' => DateDiff($contest['date_end'], date('Y-m-d')),
    3436        ));
    3537       
    3638        // Les quatre zones texte
    37         foreach (array('presentation','rules','prices','final') AS $key) {
    38                 $template->assign(strtoupper($key), trigger_event('render_CR_content', $contest[$key]));
     39        if (!empty($contest['description'])) {
     40                $contest['description'] = unserialize(base64_decode($contest['description']));
     41                foreach ($contest['description'] as $desc) {
     42                        $template->append('description', array(
     43                                'NAME' => trigger_event('render_CR_content', stripslashes($desc['name'])),
     44                                'CONTENT' => trigger_event('render_CR_content', stripslashes($desc['content'])),
     45                        ));
     46                }
    3947        }
    4048       
    4149        // Affichage des résultats
    42         if ($contest['status'] == 'finished') {
     50        if ($contest['finished'] == true) {
    4351                // Infos des résultats
    4452                $results = pwg_query("SELECT * FROM " . CR_TABLE_2 . " WHERE contest_id=" . $contest['id'] . " ORDER BY rank ASC;");
  • 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?>
  • extensions/ContestResults/include/functions.php

    r9200 r9572  
    2323        }
    2424}
     25
     26// Nombre de jours entre deux dates
     27function DateDiff($date2, $date1) {
     28        return ceil((strtotime($date2)-strtotime($date1))/(3600*24));
     29}
     30
     31// Date passée
     32function is_date_passed($date) {
     33        if (time() > strtotime($date)) {
     34                return true;
     35        } else {
     36                return false;
     37        }
     38}
    2539?>
Note: See TracChangeset for help on using the changeset viewer.