pnForum : optimisation du cache  Début

  • Voila par défaut, le cache est mis à "false" pour toutes les pages de pnForum, ce qui fait que vous ne bénificiez pas pleinement des options de cache des smarty. J'ai recodé une partie des fonctions pour mettre en place une gestion de cache de base fonctionnelle.

    Cette étude donne une idée sur une nouvelle notion de la gestion de cache pas seulement basé sur le temps de raffraichissement mais aussi sur des actions volontaires liée à certaines modifications de la part de l'utilisateur.

    Je suis actuellement en train de tester le fonctionnement de ces modifs.

    L'intéret de ces manipulations ne peut se voir que si vous avez un cache pnrender important (3600 secondes, vois plus, pour tout dire je crois qu'on peut monter à 24 h, voir méme un cache illimité suivant l'espace disponible sur votre serveur)

    But
    - fournir un tutorial au personne qui veulent utiliser pleinement les options de cache de leur postnuke
    - augmenter les temps d'affichage des forums en utilisant un systéme de cache (l'affichage des pages devient quasiment instané si elle est déja en cache)

    Explication

    Les pages les plus chargés sur un forum sont la page principale (main), la page d'affichage des topics d'un forum (viewforum) et la page de visualisation d'un sujet (viewtopic). Le but est donc de mettre en cache uniquement ces trois pages pour l'instant.

    Pour que cette gestion puisse être pleinement fonctionnelle, il faut que le cache soit raffraichi quand :
    - on poste un sujet
    - on répond à un sujet
    - on édite un sujet
    - on éffectue des opérations d'administrations sur les sujets

    Implémentation

    ouvrir module/pnforum/pnuser.php


    partie 1 : mise en cache des pages principales du forum
    la fonction main est mise en cache avec un id correspondant à l'identifiant utilisateur
    en effet, suivant votre statut (ou id) vous ne verrez pas la page principale de la méme maniére
    , en particulier si vous etes admin , vous verrez vos forums privés alors que de utilisateurs standard ne le verront pas.

    Code

    function pnForum_user_main($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            $viewcat = (int)pnVarCleanFromInput('viewcat');

            $favorites = (bool)pnVarCleanFromInput('favorites');

        }

        $viewcat = (!empty($viewcat)) ? $viewcat : -1;



        list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');



     $pnr =& new pnRender('pnForum');

       // edit mumu

       // $pnr->caching = false;

        $uid = pnUserGetVar('uid');

        $pnr->cache_id = $uid ;

        if ($pnr->is_cached('pnforum_user_main.html')) {

           return $pnr->fetch('pnforum_user_main.html');

        }



        $loggedIn = pnUserLoggedIn();

        if(pnModGetVar('pnForum', 'favorites_enabled')=='yes') {

            if($loggedIn && empty($favorites)) {

                $favorites = pnModAPIFunc('pnForum', 'user', 'get_favorite_status');

            }

        }

        if ($loggedIn && $favorites) {

            $tree = pnModAPIFunc('pnForum', 'user', 'getFavorites', array('user_id' => (int)pnUserGetVar('uid'),

                                                                          'last_visit' => $last_visit ));

        } else {

            $tree = pnModAPIFunc('pnForum', 'user', 'readcategorytree', array('last_visit' => $last_visit ));



            if(pnModGetVar('pnForum', 'slimforum') == 'yes') {

                // this needs to be in here because we want to display the favorites

                // not go to it if there is only one

                // check if we have one category and one forum only

                if(count($tree)==1) {

                    foreach($tree as $catname=>$forumarray) {

                        if(count($forumarray['forums'])==1) {

                            return pnRedirect(pnModURL('pnForum', 'user', 'viewforum', array('forum'=>$forumarray['forums'][0]['forum_id'])));

                        }

                    }

                }

            }

        }



         // edit mumu

       // $pnr->caching = false;



        $pnr->add_core_data();

        $pnr->assign( 'favorites', $favorites);

        $pnr->assign( 'tree', $tree);

        $pnr->assign( 'view_category', $viewcat);

        $pnr->assign( 'last_visit', $last_visit);

        $pnr->assign( 'last_visit_unix', $last_visit_unix);

        $pnr->assign( 'numposts', pnModAPIFunc('pnForum', 'user', 'boardstats',

                                                array('id'   => '0',

                                                      'type' => 'all' )));

        return $pnr->fetch('pnforum_user_main.html');

    }



    la fonction viewforum utilise aussi une gestion d'id basé sur l'id utilisateur, mais comme il y a plusieurs forums il faut générer un id qui soit une combinaison de l'id utilisateur et du numéro de forum (forum_id).

    Code

    function pnForum_user_viewforum($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            $forum_id = (int)pnVarCleanFromInput('forum');

            $start    = (int)pnVarCleanFromInput('start');

        }



        list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');

        $pnr =& new pnRender('pnForum');

       // edit mumu

       // $pnr->caching = false;

        $uid = pnUserGetVar('uid');

        $pnr->cache_id = $forum_id.$uid.$start ;

        if ($pnr->is_cached('pnforum_user_viewforum.html')) {

           return $pnr->fetch('pnforum_user_viewforum.html');

        }

        $forum = pnModAPIFunc('pnForum', 'user', 'readforum',

                              array('forum_id'        => $forum_id,

                                    'start'           => $start,

                                    'last_visit'      => $last_visit,

                                    'last_visit_unix' => $last_visit_unix));









        $pnr->add_core_data();

        $pnr->assign( 'forum', $forum);

        $pnr->assign( 'hot_threshold', pnModGetVar('pnForum', 'hot_threshold'));

        $pnr->assign( 'loggedin',$logged );

        $pnr->assign( 'last_visit', $last_visit);

        $pnr->assign( 'last_visit_unix', $last_visit_unix);

        return $pnr->fetch('pnforum_user_viewforum.html');

    }


    la fonction viewtopic utiilse la méme particularité que la fonction viewforum en utilisant un fait le numéro de sujet au lieu du numéro de forum. au passage, (je l'ai pas dit dans les parties précédentes pour pas surcharger), on fait un test pour voir si la page est en cache au début et si c'est le cas on l'affiche, sinon ca sert à rien de faire les modifs ;).

    Code

    function pnForum_user_viewtopic($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            $topic_id = (int)pnVarCleanFromInput('topic');

            $start    = (int)pnVarCleanFromInput('start');

            $view     = strtolower(pnVarCleanFromInput('view'));

        }





        list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');

          $pnr =& new pnRender('pnForum');

         $uid = pnUserGetVar('uid');

        $pnr->cache_id = $topic_id.$uid.$start;



       if ($pnr->is_cached('pnforum_user_viewtopic.html')) {

           return $pnr->fetch('pnforum_user_viewtopic.html');

        }

        if(!empty($view) && ($view=="next" || $view=="previous")) {

            $topic_id = pnModAPIFunc('pnForum', 'user', 'get_previous_or_next_topic_id',

                                     array('topic_id' => $topic_id,

                                           'view'     => $view));

            return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic',

                                array('topic' => $topic_id)));

        }

        $topic = pnModAPIFunc('pnForum', 'user', 'readtopic',

                              array('topic_id'   => $topic_id,

                                    'start'      => $start,

                                    'last_visit' => $last_visit));

        // keywords :





        // edit mumu

        //$pnr->caching = false;





        $pnr->add_core_data();

        $pnr->assign( 'topic', $topic);

        $pnr->assign( 'post_count', count($topic['posts']));

        $pnr->assign( 'hot_threshold', pnModGetVar('pnForum', 'hot_threshold'));

        $pnr->assign( 'last_visit', $last_visit);

        $pnr->assign( 'last_visit_unix', $last_visit_unix);

        return $pnr->fetch('pnforum_user_viewtopic.html');



    }


    version imprimable, pour la version imprimable, on ne met que l'identifiant du topic
    remarquez que la fonction is_cached ne fonctionnera que si vous avez précisé l'id du cache avant.

    Code

    /**

     * print

     * prepare print view of the selected posting or topic

     *

     */

    function pnForum_user_print($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            $post_id  = (int)pnVarCleanFromInput('post');

            $topic_id = (int)pnVarCleanFromInput('topic');

        }



        if(useragent_is_bot() == true) {

            if($post_id <> 0 ) {

                $topic_id =pnModAPIFunc('pnForum', 'user', 'get_topicid_by_postid',

                                        array('post_id' => $post_id));

            }

            if(($topic_id <> 0) && ($topic_id<>false)) {

                return pnForum_user_viewtopic(array('topic' => $topic_id,

                                                    'start'   => 0));

            } else {

                return pnRedirect(pnModURL('pnForum', 'user', 'main'));

            }

        } else {

            $pnr =& new pnRender('pnForum');

              $pnr->cache_id = $topic_id; // idem pour post id

            //$pnr->caching = false;

           /* if($post_id<>0) {





                $post = pnModAPIFunc('pnForum', 'user', 'readpost',

                                     array('post_id' => $post_id));

                $pnr->assign('post', $post);

                $output = $pnr->fetch('pnforum_user_printpost.html');

            } else

             je ne gére pas l'impréssion d'un post dans un sujet, pour moi ca ne

             sert à rien

             */

            if($topic_id<>0) {

                if ($pnr->is_cached('pnforum_user_printtopic.html')) {

                   return $pnr->fetch('pnforum_user_printtopic.html');

                }

                $topic = pnModAPIFunc('pnForum', 'user', 'readtopic',

                                     array('topic_id'  => $topic_id,

                                           'complete' => true ));

                $pnr->assign('topic', $topic);

                $output = $pnr->fetch('pnforum_user_printtopic.html');

            } else {

                return pnRedirect(pnModURL('pnForum', 'user', 'main'));

            }

            echo "<html>\n";

            echo "<head>\n";

        echo "\r\n";

            echo "\n";



            global $additional_header;

            if (is_array($additional_header))

            {

              foreach ($additional_header as $header)

                echo "$header\n";

            }

            echo "</head>\n";

            echo "<body >\n";

            echo $output;

            echo "</body>\n";

            echo "</html>\n";

            exit;

        }

    }



    ... je vais rédiger la partie 2 sur un autres posts, merci de patienter











    modifié par : mumuri, 29 Jan 2006 - 21:31



    Membre du PSR Project (Pagesetter replacement)
  • partie 2 : raffraichissement du cache avec clear_cache

    c'est bien joli de mettre en page des caches, mais l'intéret c'est de forcer leur raffraichissement, indépendamment du compteur de cache. c'est ce que nous allons faire

    si nous repondons à un sujet et que nous validons la réponse, alors on éfface TOUT le cache (en effet pour l'instant on peut pas faire autrement car smarty ne le permet pas , enfin je crois)

    Code

    function pnForum_user_reply($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            list($topic_id,

                 $post_id,

                 $message,

                 $attach_signature,

                 $subscribe_topic,

                 $preview,

                $submit,

                 $cancel ) = pnVarCleanFromInput('topic',

                                                'post',

                                                'message',

                                                'attach_signature',

                                                'subscribe_topic',

                                                'preview',

                                                'submit',

                                                'cancel');

        }



        $post_id = (int)$post_id;

        $topic_id = (int)$topic_id;

        $attach_signature = (int)$attach_signature;

        $subscribe_topic = (int)$subscribe_topic;



        /**

         * if cancel is submitted move to forum-view

         */

        if(!empty($cancel)) {

            return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic'=> $topic_id)));

        }



        $preview = (empty($preview)) ? false : true;



        if (empty($submit)) {

            $submit = false;

            $subject="";

            $message="";

        } else {

            $submit = true;

        }



        if ($submit==true && $preview==false) {

            // Confirm authorisation code

            if (!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }



            // sync the users, so that new pn users get into the pnForum

            // database

            pnModAPIFunc('pnForum', 'user', 'usersync');



              list($start,$post_id ,$forum_id) = pnModAPIFunc('pnForum', 'user', 'storereply',



                                                 array( 'topic_id'         => $topic_id,

                                                        'message'          => $message,

                                                            'attach_signature' => $attach_signature,



                                                             'subscribe_topic'  => $subscribe_topic));

                  // edit mumu

                  $pnr =& new pnRender('pnForum');

                  $pnr->clear_cache(null);



                  return pnRedirect(pnModURL('pnForum', 'user', 'viewforum',

                                        array('forum' => $forum_id)));

        } else {

            list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');

            $reply = pnModAPIFunc('pnForum', 'user', 'preparereply',

                                  array('topic_id'   => $topic_id,

                                        'post_id'    => $post_id,

                                        'last_visit' => $last_visit,

                                        'reply_start'=> empty($message),

                                        'attach_signature' => $attach_signature,

                                        'subscribe_topic'  => $subscribe_topic));

            if($preview==true) {

                $reply['message'] = pnfVarPrepHTMLDisplay($message);

            }



            $pnr =& new pnRender('pnForum');

            // edit mumu



            $pnr->caching = false;

            $pnr->add_core_data();

            $pnr->assign( 'reply', $reply);

            $pnr->assign( 'preview', $preview);

            $pnr->assign( 'last_visit', $last_visit);

            $pnr->assign( 'last_visit_unix', $last_visit_unix);

            return $pnr->fetch('pnforum_user_reply.html');

        }

    }


    on fait pareil à la création de nouveau sujet

    Code

    function pnForum_user_newtopic($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            list($forum_id,

                 $message,

                 $subject,

                 $cancel,

                 $submit,

                 $attach_signature,

                 $subscribe_topic,

                 $preview) = pnVarCleanFromInput('forum',

                                                 'message',

                                                 'subject',

                                                 'cancel',

                                                 'submit',

                                                 'attach_signature',

                                                 'subscribe_topic',

                                                 'preview');

        }



        $preview = (empty($preview)) ? false : true;

        $cancel  = (empty($cancel))  ? false : true;

        $submit  = (empty($submit))  ? false : true;



        //  if cancel is submitted move to forum-view

        if($cancel==true) {

            return pnRedirect(pnModURL('pnForum','user', 'viewforum', array('forum'=>$forum_id)));

        }



        if($submit==false) {

            $subject = '';

            $message = '';

        }



        list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');



        $newtopic = pnModAPIFunc('pnForum', 'user', 'preparenewtopic',

                                 array('forum_id'   => $forum_id,

                                       'subject'    => $subject,

                                       'message'    => $message,

                                       'topic_start'=> (empty($subject) && empty($message)),

                                       'attach_signature' => $attach_signature,

                                       'subscribe_topic'  => $subscribe_topic));

        if($submit==true && $preview==false) {

            // sync the users, so that new pn users get into the pnForum

            // database

            pnModAPIFunc('pnForum', 'user', 'usersync');



            // it's a submitted page

            // Confirm authorisation code

            if (!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }



            //store the new topic

            $topic_id = pnModAPIFunc('pnForum', 'user', 'storenewtopic',

                                     array('forum_id'         => $forum_id,

                                           'subject'          => $subject,

                                           'message'          => $message,

                                           'attach_signature' => $attach_signature,

                                           'subscribe_topic'  => $subscribe_topic));

            $pnr =& new pnRender('pnForum');



             $pnr->clear_cache(null);

            return pnRedirect(pnModURL('pnForum', 'user', 'viewforum',

                                array('forum' => pnVarPrepForStore($forum_id))));

        } else {

            // new topic

            $pnr =& new pnRender('pnForum');



            $pnr->caching = false;

            $pnr->add_core_data();

            $pnr->assign( 'preview', $preview);

            $pnr->assign( 'newtopic', $newtopic);

            $pnr->assign( 'last_visit', $last_visit);

            $pnr->assign( 'last_visit_unix', $last_visit_unix);

            return $pnr->fetch('pnforum_user_newtopic.html');

        }

    }


    à l'édition de post, on éfface tout aussi.

    Code

    /**

     * editpost

     *

     */

    function pnForum_user_editpost($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            list($post_id,

                 $topic_id,

                 $message,

                 $subject,

                 $submit,

                 $delete,

                 $cancel,

                 $preview) =  pnVarCleanFromInput('post',

                                                  'topic',

                                                  'message',

                                                  'subject',

                                                  'submit',

                                                  'delete',

                                                  'cancel',

                                                  'preview');

        }



        $preview = (empty($preview)) ? false : true;



        //  if cancel is submitted move to forum-view

        if(!empty($cancel)) {

            return pnRedirect(pnModURL('pnForum','user', 'viewtopic', array('topic'=>$topic_id)));

        }



        if (empty($submit)) {

            $subject="";

            $message="";

        }



        list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');



        if($submit && !$preview) {

            /**

             * Confirm authorisation code

             */

            if (!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }

            //store the new topic

            $redirect = pnModAPIFunc('pnForum', 'user', 'updatepost',

                                     array('post_id'  => $post_id,

                                           'delete'   => $delete,

                                           'subject'  => $subject,

                                           'message'  => $message));

             // edit mumu

             $pnr =& new pnRender('pnForum');

             $pnr->clear_cache(null);

            return pnRedirect($redirect);



        } else {

            $post = pnModAPIFunc('pnForum', 'user', 'readpost',

                                 array('post_id'    => $post_id));

            if(!empty($subject)) {

                $post['topic_subject'] = $subject;

            }



            // if the current user is the original poster we allow to

            // edit the subject

            $firstpost = pnModAPIFunc('pnForum', 'user', 'get_firstlast_post_in_topic',

                                      array('topic_id' => $post['topic_id'],

                                            'first'    => true));

            if($post['poster_data']['pn_uid'] = $firstpost['poster_data']['pn_uid']) {

                $post['edit_subject'] = true;

            }



            if(!empty($message)) {

                $post['post_text'] = $message;

                list($post['post_textdisplay']) = pnModCallHooks('item', 'transform', '', array($message));

            }

            $pnr =& new pnRender('pnForum');

            $pnr->caching = false;

            $pnr->add_core_data();

            $pnr->assign( 'preview', $preview);

            $pnr->assign( 'post', $post);

            $pnr->assign( 'last_visit', $last_visit);

            $pnr->assign( 'last_visit_unix', $last_visit_unix);

            return $pnr->fetch('pnforum_user_editpost.html');

        }

    }


    ... passons à la partie admin ...

    chaque fois qu'on modére un sujet il faut aussi raffraichir le cache (genre si vous déplacer un sujet, ou si vous le découper en deux sous sujet etc ...)


    Code

    /**

     * topicadmin

     *

     */

    function pnForum_user_topicadmin($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            $topic_id = (int)pnVarCleanFromInput('topic');

            $post_id  = (int)pnVarCleanFromInput('post');

            $forum_id = (int)pnVarCleanFromInput('forum');  // for move

            $mode     = pnVarCleanFromInput('mode');

            $submit   = pnVarCleanFromInput('submit');

            $shadow   = pnVarCleanFromInput('createshadowtopic');

        }

        $shadow = (empty($shadow)) ? false : true;



        if(empty($topic_id) && !empty($post_id)) {

            $topic_id = pnModAPIFunc('pnForum', 'user', 'get_topicid_by_postid',

                                     array('post_id' => $post_id));

        }

        $topic = pnModAPIFunc('pnForum', 'user', 'readtopic',

                              array('topic_id' => $topic_id));

        if($topic['access_moderate']<>true) {

            return showforumerror(_PNFORUM_NOAUTH_TOMODERATE, __FILE__, __LINE__);

        }



        $pnr =& new pnRender('pnForum');

         $pnr->caching = false;

        $pnr->add_core_data();

        $pnr->assign('mode', $mode);

        $pnr->assign('topic_id', $topic_id);

        $pnr->assign('last_visit', $last_visit);

        $pnr->assign('last_visit_unix', $last_visit_unix);



        if(empty($submit)) {

            switch($mode) {

                case "del":

                case "delete":

                    $templatename = "pnforum_user_deletetopic.html";

                    break;

                case "move":

                case "join":

                    $pnr->assign('forums', pnModAPIFunc('pnForum', 'user', 'readuserforums'));

                    $templatename = "pnforum_user_movetopic.html";

                    break;

                case "lock":

                case "unlock":

                    $templatename = "pnforum_user_locktopic.html";

                    break;

                case "sticky":

                case "unsticky":

                    $templatename = "pnforum_user_stickytopic.html";

                    break;

                case "viewip":

                    $pnr->assign('viewip', pnModAPIFunc('pnForum', 'user', 'get_viewip_data', array('post_id' => $post_id)));

                    $templatename = "pnforum_user_viewip.html";

                    break;

                default:

                    return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic'=>$topic_id)));

            }

            return $pnr->fetch($templatename);



        } else { // submit is set

          $pnr->clear_cache(null); // edit : modération éffectuée on efface le cache

     

            if (!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }

            switch($mode) {

                case "del":

                case "delete":

                    $forum_id = pnModAPIFunc('pnForum', 'user', 'deletetopic', array('topic_id'=>$topic_id));

                    return pnRedirect(pnModURL('pnForum', 'user', 'viewforum', array('forum'=>$forum_id)));

                    break;

                case "move":

                    pnModAPIFunc('pnForum', 'user', 'movetopic', array('topic_id' => $topic_id,

                                                                       'forum_id' => $forum_id,

                                                                       'shadow'   => $shadow ));

                    break;

                case "lock":

                case "unlock":

                    pnModAPIFunc('pnForum', 'user', 'lockunlocktopic', array('topic_id'=> $topic_id, 'mode'=>$mode));

                    break;

                case "sticky":

                case "unsticky":

                    pnModAPIFunc('pnForum', 'user', 'stickyunstickytopic', array('topic_id'=> $topic_id, 'mode'=>$mode));

                    break;

                case "join":

                    $to_topic_id = pnVarCleanFromInput('to_topic_id');

                    pnModAPIFunc('pnForum', 'user', 'jointopics', array('from_topic_id' => $topic_id,

                                                                        'to_topic_id'   => $to_topic_id));

                    return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic' => $to_topic_id)));

                    break;

                default:

            }

            return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic'=>$topic_id)));

        }

    }



    Code

    /**

     * splittopic

     *

     */

    function pnForum_user_splittopic($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            list($post_id,

                 $submit,

                 $newsubject) = pnVarCleanFromInput('post',

                                                    'submit',

                                                    'newsubject');

        }



        $post = pnModAPIFunc('pnForum', 'user', 'readpost',

                             array('post_id' => $post_id));



        if(!allowedtomoderatecategoryandforum($post['cat_id'], $post['forum_id'])) {

            // user is not allowed to moderate this forum

            return showforumerror(getforumerror('auth_mod',$post['forum_id'], 'forum', _PNFORUM_NOAUTH_TOMODERATE), __FILE__, __LINE__);

        }



        $pnr =& new pnRender('pnForum');



        if(!empty($submit)) {

            // Confirm authorisation code

            if (!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }

            // submit is set, we split the topic now

            $post['topic_subject'] = $newsubject;

            $newtopic_id = pnModAPIFunc('pnForum', 'user', 'splittopic',

                                       array('post' => $post));

            $pnr->clear_cache(null);  // sujet découpé , on enléve le cache

            return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic',

                                       array('topic' => $newtopic_id)));



        } else {

             $pnr->caching = false;

            $pnr->add_core_data();

            $pnr->assign('post', $post);

            return $pnr->fetch('pnforum_user_splittopic.html');

        }

    }


    Code

    /**
     * movepost
     * Move a single post to another thread
     * added by by el_cuervo -- dev-postnuke.com
     *
     */

    function pnForum_user_movepost($args=array())
    {
        // get the input
        if(count($args)>0) {
            extract($args);
            unset($args);
        } else {
            list($post_id,
                 $submit,
                 $to_topic) = pnVarCleanFromInput('post',
                                                   'submit',
                                                   'to_topic');
        }
        $post = pnModAPIFunc('pnForum', 'user', 'readpost', array('post_id' => $post_id));

        if(!allowedtomoderatecategoryandforum($post['cat_id'], $post['forum_id'])) {
            // user is not allowed to moderate this forum
            return showforumerror(getforumerror('auth_mod', $post['forum_id'], 'forum', _PNFORUM_NOAUTH_TOMODERATE), __file__, __line__);
        }
            $pnr =& new pnRender('pnForum');

        if(!empty($submit)) {
            if (!pnSecConfirmAuthKey()) {
                return showforumerror(_BADAUTHKEY, __file__, __line__);
            }
            $pnr->clear_cache(null);
            // submit is set, we move the posting now
            // Existe el Topic ? --- Exists new Topic ?
            $topic = pnModAPIFunc('pnForum', 'user', 'readtopic', array('topic_id' => $to_topic,
                                                                        'complete' => false));
            $post['new_topic'] = $to_topic;
            $post['old_topic'] = $topic['topic_id'];
            $start = pnModAPIFunc('pnForum', 'user', 'movepost', array('post'     => $post,
                                                                       'to_topic' => $to_topic));
            return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic',
                                       array('topic' => $to_topic,
                                             'start' => $start)) . "#pid" . $post['post_id']);
        } else {

            $pnr->caching = false;
            $pnr->add_core_data();
            $pnr->assign('post', $post);
            return $pnr->fetch('pnforum_user_movepost.html');
        }
    }


    ca c'est une modification du au changement des préférences dans un sujet par un utilisateur, à la limite c'est presque un truc qu'on devrait laisser raffraichir avec la limite naturelle de raffraichissement des templates

    Code

    /**

     * prefs

     *

     */

    function pnForum_user_prefs($args=array())

    {

        $loggedin = pnUserLoggedIn();

        if(!$loggedin) {

            return pnRedirect(pnModURL('pnForum', 'user', 'main'));

        }



        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            list($act,

                 $return_to,

                 $topic_id,

                 $forum_id ) = pnVarCleanFromInput('act',

                                                   'return_to',

                                                   'topic',

                                                   'forum');

        }



        switch($act) {

            case 'subscribe_topic':

                $return_to = (!empty($return_to))? $return_to : "viewtopic";

                pnModAPIFunc('pnForum', 'user', 'subscribe_topic',

                             array('topic_id' => $topic_id ));

                $params = array('topic'=>$topic_id);

                break;

            case 'unsubscribe_topic':

                $return_to = (!empty($return_to))? $return_to : "viewtopic";

                pnModAPIFunc('pnForum', 'user', 'unsubscribe_topic',

                             array('topic_id' => $topic_id ));

                $params = array('topic'=>$topic_id);

                break;

            case 'subscribe_forum':

                $return_to = (!empty($return_to))? $return_to : "viewforum";

                pnModAPIFunc('pnForum', 'user', 'subscribe_forum',

                             array('forum_id' => $forum_id ));

                $params = array('forum'=>$forum_id);

                break;

            case 'unsubscribe_forum':

                $return_to = (!empty($return_to))? $return_to : "viewforum";

                pnModAPIFunc('pnForum', 'user', 'unsubscribe_forum',

                             array('forum_id' => $forum_id ));

                $params = array('forum'=>$forum_id);

                break;

            case 'add_favorite_forum':

                if(pnModGetVar('pnForum', 'favorites_enabled')=='yes') {

                    $return_to = (!empty($return_to))? $return_to : "viewforum";

                    pnModAPIFunc('pnForum', 'user', 'add_favorite_forum',

                                 array('forum_id' => $forum_id ));

                    $params = array('forum'=>$forum_id);

                }

                break;

            case 'remove_favorite_forum':

                if(pnModGetVar('pnForum', 'favorites_enabled')=='yes') {

                    $return_to = (!empty($return_to))? $return_to : "viewforum";

                    pnModAPIFunc('pnForum', 'user', 'remove_favorite_forum',

                                 array('forum_id' => $forum_id ));

                    $params = array('forum'=>$forum_id);

                }

                break;

            case 'change_post_order':

                $return_to = (!empty($return_to))? $return_to : "viewtopic";

                pnModAPIFunc('pnForum', 'user', 'change_user_post_order');

                $params = array('topic'=>$topic_id);

                break;

            case 'showallforums':

            case 'showfavorites':

                if(pnModGetVar('pnForum', 'favorites_enabled')=='yes') {

                    $return_to = (!empty($return_to))? $return_to : "main";

                    $favorites = pnModAPIFunc('pnForum', 'user', 'change_favorite_status');

                    $params = array();

                }

                break;

            default:

                list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');

                $pnr =& new pnRender('pnForum');

                 $pnr->clear_cache(null);

                $pnr->caching = false;

                $pnr->add_core_data();

                $pnr->assign( 'last_visit', $last_visit);

                $pnr->assign( 'favorites_enabled', pnModGetVar('pnForum', 'favorites_enabled'));

                $pnr->assign( 'loggedin', $loggedin);

                $pnr->assign( 'last_visit_unix', $last_visit_unix);

                $pnr->assign('tree', pnModAPIFunc('pnForum', 'user', 'readcategorytree', array('last_visit' => $last_visit )));

                return $pnr->fetch('pnforum_user_prefs.html');

        }

        return pnRedirect(pnModURL('pnForum', 'user', $return_to, $params));

    }





    Membre du PSR Project (Pagesetter replacement)
  • Code

    /**

     * jointopics

     * Join a topic with another toipic                                                                                                  ?>

     * by el_cuervo -- dev-postnuke.com

     *

     */

    function pnForum_user_jointopics($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            list($post_id,

                 $submit,

                 $to_topic_id,

                 $from_topic_id) = pnVarCleanFromInput('post_id',

                                                       'submit',

                                                       'to_topic_id',

                                                       'from_topic_id');

        }



        $post = pnModAPIFunc('pnForum', 'user', 'readpost', array('post_id' => $post_id));



        if(!allowedtomoderatecategoryandforum($post['cat_id'], $post['forum_id'])) {

            // user is not allowed to moderate this forum

            return showforumerror(getforumerror('auth_mod',$post['forum_id'], 'forum', _PNFORUM_NOAUTH_TOMODERATE), __FILE__, __LINE__);

        }

           $pnr =& new pnRender('pnForum');



        if(!$submit) {



            $pnr->caching = false;

            $pnr->add_core_data();

            $pnr->assign('post', $post);

            return $pnr->fetch('pnforum_user_jointopics.html');

        } else {

            if (!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }

            $pnr->clear_cache(null);

            // check if from_topic exists. this function will return an error if not

            $from_topic = pnModAPIFunc('pnForum', 'user', 'readtopic', array('topic_id' => $from_topic_id, 'complete' => false));

            // check if to_topic exists. this function will return an error if not

            $to_topic = pnModAPIFunc('pnForum', 'user', 'readtopic', array('topic_id' => $to_topic_id, 'complete' => false));

            // submit is set, we split the topic now

            //$post['new_topic'] = $totopic;

            //$post['old_topic'] = $old_topic;

            $res = pnModAPIFunc('pnForum', 'user', 'jointopics', array('from_topic' => $from_topic,

                                                                       'to_topic'   => $to_topic));

            return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic' => $res)));

        }

    }



    Code

    /**

     * moderateforum

     * simple moderation of multiple topics

     *

     *@params to be documented  <img src="http://communaute.zikula.fr/modules/bbsmile/pnimages/smilies/icon_smile.gif" alt="icon_smile" />

     *

     */

    function pnForum_user_moderateforum($args=array())

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            $forum_id = (int)pnVarCleanFromInput('forum');

            $start    = (int)pnVarCleanFromInput('start');

            $mode     = pnVarCleanFromInput('mode');

            $submit   = pnVarCleanFromInput('submit');

            $topic_ids= pnVarCleanFromInput('topic_id');

            $shadow   = pnVarCleanFromInput('createshadowtopic');

            $moveto   = pnVarCleanFromInput('moveto');

            $jointo   = pnVarCleanFromInput('jointo');

        }

        $shadow = (empty($shadow)) ? false : true;



        list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies');



        // Get the Forum for Display and Permission-Check

        $forum = pnModAPIFunc('pnForum', 'user', 'readforum',

                              array('forum_id'        => $forum_id,

                                    'start'           => $start,

                                    'last_visit'      => $last_visit,

                                    'last_visit_unix' => $last_visit_unix));



        if(!allowedtomoderatecategoryandforum($forum['cat_id'], $forum['forum_id'])) {

            // user is not allowed to moderate this forum

            return showforumerror(getforumerror('auth_mod',$post['forum_id'], 'forum', _PNFORUM_NOAUTH_TOMODERATE), __FILE__, __LINE__);

        }



          $pnr =& new pnRender('pnForum');



        // Submit isn't set'

        if(empty($submit)) {



            $pnr->caching = false;

            $pnr->assign('forum_id', $forum_id);

            $pnr->assign('mode',$mode);

            $pnr->assign('topic_ids', $topic_ids);

            $pnr->assign('last_visit', $last_visit);

            $pnr->assign('last_visit_unix', $last_visit_unix);

            $pnr->assign('forum',$forum);

            // For Movetopic

            $pnr->assign('forums', pnModAPIFunc('pnForum', 'user', 'readuserforums'));

            return $pnr->fetch("pnforum_user_moderateforum.html");



        } else {

            // submit is set

            if (!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }

             $pnr->clear_cache(null);

            if(count($topic_ids)<>0) {

                switch($mode) {

                    case "del":

                    case "delete":

                        foreach($topic_ids as $topic_id) {

                            $forum_id = pnModAPIFunc('pnForum', 'user', 'deletetopic', array('topic_id'=>$topic_id));

                        }

                        break;

                    case "move":

                        if(empty($moveto)) {

                            return showforumerror(_PNFORUM_NOMOVETO, __FILE__, __LINE__);

                        }

                        foreach ($topic_ids as $topic_id) {

                            pnModAPIFunc('pnForum', 'user', 'movetopic', array('topic_id' => $topic_id,

                                                                               'forum_id' => $moveto,

                                                                               'shadow'   => $shadow ));

                        }

                        break;

                    case "lock":

                    case "unlock":

                        foreach($topic_ids as $topic_id) {

                            pnModAPIFunc('pnForum', 'user', 'lockunlocktopic', array('topic_id'=> $topic_id, 'mode'=>$mode));

                        }

                        break;

                    case "sticky":

                    case "unsticky":

                        foreach($topic_ids as $topic_id) {

                            pnModAPIFunc('pnForum', 'user', 'stickyunstickytopic', array('topic_id'=> $topic_id, 'mode'=>$mode));

                        }

                        break;

                    case "join":

                        if(empty($jointo)) {

                            return showforumerror(_PNFORUM_NOJOINTO, __FILE__, __LINE__);

                        }

                        if(in_array($jointo, $topic_ids)) {

                            // jointo, the target topic, is part of the topics to join

                            // we remove this to avoid a loop

                            $fliparray = array_flip($topic_ids);

                            unset($fliparray[$jointo]);

                            $topic_ids = array_flip($fliparray);

                        }

                        foreach($topic_ids as $to_topic_id) {

                            pnModAPIFunc('pnForum', 'user', 'jointopics', array('from_topic_id' => $topic_id,

                                                                                'to_topic_id'   => $jointo));

                        }

                        break;

                    default:

                }

                // Refresh Forum Info

                $forum = pnModAPIFunc('pnForum', 'user', 'readforum',

                                  array('forum_id'        => $forum_id,

                                        'start'           => $start,

                                        'last_visit'      => $last_visit,

                                        'last_visit_unix' => $last_visit_unix));

            }

        }

        return pnRedirect(pnModURL('pnForum', 'user', 'moderateforum', array('forum' => $forum_id)));

    }



    raffraichissement de l'icone de souscription au topic.

    Code

    /**

     * topicsubscriptions

     * manage the users topic subscription

     *

     *@params

     *

     */

    function pnForum_user_topicsubscriptions($args)

    {

        // get the input

        if(count($args)>0) {

            extract($args);

            unset($args);

        } else {

            list($topic_id,

                 $submit) = pnVarCleanFromInput('topic_id',

                                                'submit');

        }



        $subscriptions = pnModAPIFunc('pnForum', 'user', 'get_topic_subscriptions');



        $pnr =& new pnRender('pnForum');



        if(!$submit) {



            $pnr->caching = false;

            $pnr->add_core_data();

            $pnr->assign('subscriptions', $subscriptions);

            return $pnr->fetch('pnforum_user_topicsubscriptions.html');

        } else {  // submit is set



            if(!pnSecConfirmAuthKey()) {

                return showforumerror(_BADAUTHKEY, __FILE__, __LINE__);

            }

            $pnr->clear_cache(null);

            if(is_array($topic_id)) {

                foreach($subscriptions as $subscription) {

                    if(!array_key_exists($subscription['topic_id'], $topic_id)) {

                        pnModAPIFunc('pnForum', 'user', 'unsubscribe_topic',

                                     array('topic_id' => $subscription['topic_id'],

                                           'silent'   => true));

                    }

                }

            }

            return pnRedirect(pnModURL('pnForum', 'user', 'topicsubscriptions'));

        }

    }

    PS : ca serai agréable de pouvoir faire des aperçus pour les éditions, ne serait ce que pour rajouter les highlight, ca serait cool que le tag highlight, marche pour plusieurs lignes aussi.






    modifié par : mumuri, 29 Jan 2006 - 11:48



    Membre du PSR Project (Pagesetter replacement)
  • Perspectives

    Pour l'instant, on éfface tout le cache du module, ce n'est pas trés propre .

    En effet,
    si on édite un sujet , on devrait éffacer le cache du template viewtopic
    si on répond a un sujet ou qu'on crée un sujet, on devrait éffacer le cache de template viewforum du forum considéré et le cache de la page principale

    hors pour l'instant, la combinaison smarty - pnrender ne le permet pas , en effet si vous faites un clear_cache("template.html") et que ce template à un cache_id prédéfinit, alors ca ne l'éffacera pas. Il faudrait donc modifier le fonctionnement de la fonction de 'clear_cache' pour que ce soit possible. Par exemmple, un clear_cache("pnforum_user_viewforum.html",9) éffacerait le cache toutes les pages liés à ce template.

    par exemple, les deux fichiers suivants serait éffacé

    Quote


    pnForum^9^pnForum^forums^fra^%%69^69F^69F3A644%%pnforum_user_viewforum.html
    pnForum^92^pnForum^forums^fra^%%69^69F^69F3A644%%pnforum_user_viewforum.html

    9 correspond à l'id du forum
    dans 92 correspond à une combinaison de l'id du forum avec l'identifiant utilisateur

    le probléme c'est que les fichiers n'ont pas la bonne structure (imaginez que vous ayez créer 92 forum,vous ne pourriez pas faire la différence ).
    Par exemple

    Quote


    pnForum^9^pnForum^forums^fra^%%69^69F^69F3A644%%pnforum_user_viewforum.html
    pnForum^9-uid2^pnForum^forums^fra^%%69^69F^69F3A644%%pnforum_user_viewforum.html


    C'est possible car smarty a prédéfini une fonction de callback "$this->cache_handler_func" (ligne 949 dans smarty.class.php) pour la fonction clear_cache. Postnuke pour l'instant utilise la fonction définit par défaut "smarty_core_rm_auto". Un hack de pnrender permettrait qui consisterait à définir cette fonction permettrait donc de faire ce traitement, tout en restant compatible avec les modules n'utilisant pas cette option.


    Je précise aussi que ce hack est en cours de test



    Membre du PSR Project (Pagesetter replacement)
  • Debug

    Ce que j'ai testé

    la compilation du fichier PHP marche, pas de bugs de codage donc
    la création d'un nouveau sujet éfface bien le cache.
    la réponse à un post éfface bien le cache




    modifié par : mumuri, 29 Jan 2006 - 12:25



    Membre du PSR Project (Pagesetter replacement)
  • mumuri

    ...ca serait cool que le tag highlight, marche pour plusieurs lignes aussi.


    [notag]

    Code

    blablabla
    [/notag] "highlightera" la ligne 2 et les lignes 4 à 7...

    Voir : http://www.postnuke-france.org/index.php?module=Forum&func=viewtopic&topic=706




    Chestnut !
    Administrateur
    Aucun Support par message privé...
    Même en cas de pensée suicidaire !
    Règles à suivre
  • ca je le sais, ce que j'aurai voulu c'est que
    [highlight] marche pour plusieurs lignes, ca m'aurai évité de prévisualiser a chaque fois pour voir les numéros de ligne

    merci quand méme



    Membre du PSR Project (Pagesetter replacement)
  • mumuri

    ca je le sais, ce que j'aurai voulu c'est que
    [highlight] marche pour plusieurs lignes, ca m'aurai évité de prévisualiser a chaque fois pour voir les numéros de ligne

    merci quand méme


    Tu peux éviter la prévisualisation en utilisant tout simplement le tag highlight à l'intérieur de ton code... Inutile de savoir le numéro de ligne.
    Je te renvoie donc encore au lien http://www.postnuke-france.org/module-Forum-viewtopic-topic-706.html

    [notag]

    Code

    Code X

    [highlight]Code Y[/highlight]

    [/notag]

    Résultat :

    Code

    Code X

    [highlight]Code Y[/highlight]





    Chestnut !
    Administrateur
    Aucun Support par message privé...
    Même en cas de pensée suicidaire !
    Règles à suivre
  • Je parlais de çà

    Code X

    [highlight]Code Y
    Code Z[/highlight]


    Code

    Code X

    [highlight]Code Y
    Code Z[/highlight]


    je voulais mettre plusieurs ligne en highlight d'un coup ;)

    ---------------
    pour la mise en cache, j'ai trouvé un bug, c'est que je ne gére pas les numéros de pages pour le viewforum et viewtopic, je vais arranger çà.

    EDIT : voila c'est bon , j'ai rajouté le $start au cache_id de viewforum et viewtopic



    modifié par : mumuri, 29 Jan 2006 - 21:33



    Membre du PSR Project (Pagesetter replacement)
  • mumuri


    je voulais mettre plusieurs ligne en highlight d'un coup ;)


    Comme quoi on peut pas toujours tout avoir...
    icon_wink




    Chestnut !
    Administrateur
    Aucun Support par message privé...
    Même en cas de pensée suicidaire !
    Règles à suivre
  • mumuri

    Perspectives

    Pour l'instant, on éfface tout le cache du module, ce n'est pas trés propre .

    En effet,
    si on édite un sujet , on devrait éffacer le cache du template viewtopic
    si on répond a un sujet ou qu'on crée un sujet, on devrait éffacer le cache de template viewforum du forum considéré et le cache de la page principale

    hors pour l'instant, la combinaison smarty - pnrender ne le permet pas , en effet si vous faites un clear_cache("template.html") et que ce template à un cache_id prédéfinit, alors ca ne l'éffacera pas. Il faudrait donc modifier le fonctionnement de la fonction de 'clear_cache' pour que ce soit possible. Par exemmple, un clear_cache("pnforum_user_viewforum.html",9) éffacerait le cache toutes les pages liés à ce template.

    par exemple, les deux fichiers suivants serait éffacé
    ...


    je reviens sur çà, qui était à l'époque plus une méconnaissance du système que un réel manque de smarty

    Quote



    http://www.smarty.net/manual/fr/caching.groups.php

    autrement dit on peut définir une architecture de gestion de cache assez puissante basé sur un mélange d'id dynamique (idforum, idtopic, iduser ...) et de structures fonctionnelles ("pnforum|viewtopic", "pnforum|viewforum" ....).




    modifié par : mumuri, 10 Mai 2008 - 13:29



    Membre du PSR Project (Pagesetter replacement)
  • 5 visiteurs

Données pour les 20 dernières minutes