pnForum : optimisation du cache
Auteur Sujet

Post 
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


[size=large]partie 1 : mise en cache des pages principales du forum[/size]
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.

  1. function pnForum_user_main($args=array()) 
  2.     // get the input 
  3.     if(count($args)>0) { 
  4.         extract($args); 
  5.         unset($args); 
  6.     } else { 
  7.         $viewcat = (int)pnVarCleanFromInput('viewcat'); 
  8.         $favorites = (bool)pnVarCleanFromInput('favorites'); 
  9.     } 
  10.     $viewcat = (!empty($viewcat)) ? $viewcat : -1; 
  11.  
  12.     list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies'); 
  13.  
  14.  $pnr =& new pnRender('pnForum'); 
  15.    // edit mumu 
  16.    // $pnr->caching = false; 
  17.     $uid = pnUserGetVar('uid'); 
  18.     $pnr->cache_id = $uid ; 
  19.     if ($pnr->is_cached('pnforum_user_main.html')) { 
  20.        return $pnr->fetch('pnforum_user_main.html'); 
  21.     } 
  22.  
  23.     $loggedIn = pnUserLoggedIn(); 
  24.     if(pnModGetVar('pnForum', 'favorites_enabled')=='yes') { 
  25.         if($loggedIn && empty($favorites)) { 
  26.             $favorites = pnModAPIFunc('pnForum', 'user', 'get_favorite_status'); 
  27.         } 
  28.     } 
  29.     if ($loggedIn && $favorites) { 
  30.         $tree = pnModAPIFunc('pnForum', 'user', 'getFavorites', array('user_id' => (int)pnUserGetVar('uid'), 
  31.                                                                       'last_visit' => $last_visit )); 
  32.     } else { 
  33.         $tree = pnModAPIFunc('pnForum', 'user', 'readcategorytree', array('last_visit' => $last_visit )); 
  34.  
  35.         if(pnModGetVar('pnForum', 'slimforum') == 'yes') { 
  36.             // this needs to be in here because we want to display the favorites 
  37.             // not go to it if there is only one 
  38.             // check if we have one category and one forum only 
  39.             if(count($tree)==1) { 
  40.                 foreach($tree as $catname=>$forumarray) { 
  41.                     if(count($forumarray['forums'])==1) { 
  42.                         return pnRedirect(pnModURL('pnForum', 'user', 'viewforum', array('forum'=>$forumarray['forums'][0]['forum_id']))); 
  43.                     } 
  44.                 } 
  45.             } 
  46.         } 
  47.     } 
  48.  
  49.      // edit mumu 
  50.    // $pnr->caching = false; 
  51.  
  52.     $pnr->add_core_data(); 
  53.     $pnr->assign( 'favorites', $favorites); 
  54.     $pnr->assign( 'tree', $tree); 
  55.     $pnr->assign( 'view_category', $viewcat); 
  56.     $pnr->assign( 'last_visit', $last_visit); 
  57.     $pnr->assign( 'last_visit_unix', $last_visit_unix); 
  58.     $pnr->assign( 'numposts', pnModAPIFunc('pnForum', 'user', 'boardstats', 
  59.                                             array('id'   => '0', 
  60.                                                   'type' => 'all' ))); 
  61.     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).

  1. function pnForum_user_viewforum($args=array()) 
  2.     // get the input 
  3.     if(count($args)>0) { 
  4.         extract($args); 
  5.         unset($args); 
  6.     } else { 
  7.         $forum_id = (int)pnVarCleanFromInput('forum'); 
  8.         $start    = (int)pnVarCleanFromInput('start'); 
  9.     } 
  10.  
  11.     list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies'); 
  12.     $pnr =& new pnRender('pnForum'); 
  13.    // edit mumu 
  14.    // $pnr->caching = false; 
  15.     $uid = pnUserGetVar('uid'); 
  16.     $pnr->cache_id = $forum_id.$uid.$start ; 
  17.     if ($pnr->is_cached('pnforum_user_viewforum.html')) { 
  18.        return $pnr->fetch('pnforum_user_viewforum.html'); 
  19.     } 
  20.     $forum = pnModAPIFunc('pnForum', 'user', 'readforum', 
  21.                           array('forum_id'        => $forum_id, 
  22.                                 'start'           => $start, 
  23.                                 'last_visit'      => $last_visit, 
  24.                                 'last_visit_unix' => $last_visit_unix)); 
  25.  
  26.  
  27.  
  28.  
  29.     $pnr->add_core_data(); 
  30.     $pnr->assign( 'forum', $forum); 
  31.     $pnr->assign( 'hot_threshold', pnModGetVar('pnForum', 'hot_threshold')); 
  32.     $pnr->assign( 'loggedin',$logged ); 
  33.     $pnr->assign( 'last_visit', $last_visit); 
  34.     $pnr->assign( 'last_visit_unix', $last_visit_unix); 
  35.     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 ;).

  1. function pnForum_user_viewtopic($args=array()) 
  2.     // get the input 
  3.     if(count($args)>0) { 
  4.         extract($args); 
  5.         unset($args); 
  6.     } else { 
  7.         $topic_id = (int)pnVarCleanFromInput('topic'); 
  8.         $start    = (int)pnVarCleanFromInput('start'); 
  9.         $view     = strtolower(pnVarCleanFromInput('view')); 
  10.     } 
  11.  
  12.  
  13.     list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies'); 
  14.       $pnr =& new pnRender('pnForum'); 
  15.      $uid = pnUserGetVar('uid'); 
  16.     $pnr->cache_id = $topic_id.$uid.$start; 
  17.  
  18.    if ($pnr->is_cached('pnforum_user_viewtopic.html')) { 
  19.        return $pnr->fetch('pnforum_user_viewtopic.html'); 
  20.     } 
  21.     if(!empty($view) && ($view=="next" || $view=="previous")) { 
  22.         $topic_id = pnModAPIFunc('pnForum', 'user', 'get_previous_or_next_topic_id', 
  23.                                  array('topic_id' => $topic_id, 
  24.                                        'view'     => $view)); 
  25.         return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', 
  26.                             array('topic' => $topic_id))); 
  27.     } 
  28.     $topic = pnModAPIFunc('pnForum', 'user', 'readtopic', 
  29.                           array('topic_id'   => $topic_id, 
  30.                                 'start'      => $start, 
  31.                                 'last_visit' => $last_visit)); 
  32.     // keywords : 
  33.  
  34.  
  35.     // edit mumu 
  36.     //$pnr->caching = false; 
  37.  
  38.  
  39.     $pnr->add_core_data(); 
  40.     $pnr->assign( 'topic', $topic); 
  41.     $pnr->assign( 'post_count', count($topic['posts'])); 
  42.     $pnr->assign( 'hot_threshold', pnModGetVar('pnForum', 'hot_threshold')); 
  43.     $pnr->assign( 'last_visit', $last_visit); 
  44.     $pnr->assign( 'last_visit_unix', $last_visit_unix); 
  45.     return $pnr->fetch('pnforum_user_viewtopic.html'); 
  46.  


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.
  1. /** 
  2.  * print 
  3.  * prepare print view of the selected posting or topic 
  4.  * 
  5.  */ 
  6. function pnForum_user_print($args=array()) 
  7.     // get the input 
  8.     if(count($args)>0) { 
  9.         extract($args); 
  10.         unset($args); 
  11.     } else { 
  12.         $post_id  = (int)pnVarCleanFromInput('post'); 
  13.         $topic_id = (int)pnVarCleanFromInput('topic'); 
  14.     } 
  15.  
  16.     if(useragent_is_bot() == true) { 
  17.         if($post_id <> 0 ) { 
  18.             $topic_id =pnModAPIFunc('pnForum', 'user', 'get_topicid_by_postid', 
  19.                                     array('post_id' => $post_id)); 
  20.         } 
  21.         if(($topic_id <> 0) && ($topic_id<>false)) { 
  22.             return pnForum_user_viewtopic(array('topic' => $topic_id, 
  23.                                                 'start'   => 0)); 
  24.         } else { 
  25.             return pnRedirect(pnModURL('pnForum', 'user', 'main')); 
  26.         } 
  27.     } else { 
  28.         $pnr =& new pnRender('pnForum'); 
  29.           $pnr->cache_id = $topic_id; // idem pour post id 
  30.         //$pnr->caching = false; 
  31.        /* if($post_id<>0) { 
  32.  
  33.  
  34.             $post = pnModAPIFunc('pnForum', 'user', 'readpost', 
  35.                                  array('post_id' => $post_id)); 
  36.             $pnr->assign('post', $post); 
  37.             $output = $pnr->fetch('pnforum_user_printpost.html'); 
  38.         } else 
  39.          je ne gére pas l'impréssion d'un post dans un sujet, pour moi ca ne 
  40.          sert à rien 
  41.          */ 
  42.         if($topic_id<>0) { 
  43.             if ($pnr->is_cached('pnforum_user_printtopic.html')) { 
  44.                return $pnr->fetch('pnforum_user_printtopic.html'); 
  45.             } 
  46.             $topic = pnModAPIFunc('pnForum', 'user', 'readtopic', 
  47.                                  array('topic_id'  => $topic_id, 
  48.                                        'complete' => true )); 
  49.             $pnr->assign('topic', $topic); 
  50.             $output = $pnr->fetch('pnforum_user_printtopic.html'); 
  51.         } else { 
  52.             return pnRedirect(pnModURL('pnForum', 'user', 'main')); 
  53.         } 
  54.         echo "<html>\n"; 
  55.         echo "<head>\n"; 
  56.     echo "\r\n"; 
  57.         echo "\n"; 
  58.  
  59.         global $additional_header; 
  60.         if (is_array($additional_header)) 
  61.         { 
  62.           foreach ($additional_header as $header) 
  63.             echo "$header\n"; 
  64.         } 
  65.         echo "</head>\n"; 
  66.         echo "<body >\n"; 
  67.         echo $output; 
  68.         echo "</body>\n"; 
  69.         echo "</html>\n"; 
  70.         exit; 
  71.     } 



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









modifié par : mumuri, 29 Jan 2006 - 21:31
Données personnelles Accueil

Post 
[size=large]partie 2 : raffraichissement du cache avec clear_cache[/size]

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)

  1. function pnForum_user_reply($args=array()) 
  2.     // get the input 
  3.     if(count($args)>0) { 
  4.         extract($args); 
  5.         unset($args); 
  6.     } else { 
  7.         list($topic_id, 
  8.              $post_id, 
  9.              $message, 
  10.              $attach_signature, 
  11.              $subscribe_topic, 
  12.              $preview, 
  13.             $submit, 
  14.              $cancel ) = pnVarCleanFromInput('topic', 
  15.                                             'post', 
  16.                                             'message', 
  17.                                             'attach_signature', 
  18.                                             'subscribe_topic', 
  19.                                             'preview', 
  20.                                             'submit', 
  21.                                             'cancel'); 
  22.     } 
  23.  
  24.     $post_id = (int)$post_id; 
  25.     $topic_id = (int)$topic_id; 
  26.     $attach_signature = (int)$attach_signature; 
  27.     $subscribe_topic = (int)$subscribe_topic; 
  28.  
  29.     /** 
  30.      * if cancel is submitted move to forum-view 
  31.      */ 
  32.     if(!empty($cancel)) { 
  33.         return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic'=> $topic_id))); 
  34.     } 
  35.  
  36.     $preview = (empty($preview)) ? false : true; 
  37.  
  38.     if (empty($submit)) { 
  39.         $submit = false; 
  40.         $subject=""; 
  41.         $message=""; 
  42.     } else { 
  43.         $submit = true; 
  44.     } 
  45.  
  46.     if ($submit==true && $preview==false) { 
  47.         // Confirm authorisation code 
  48.         if (!pnSecConfirmAuthKey()) { 
  49.             return showforumerror(_BADAUTHKEY, __FILE__, __LINE__); 
  50.         } 
  51.  
  52.         // sync the users, so that new pn users get into the pnForum 
  53.         // database 
  54.         pnModAPIFunc('pnForum', 'user', 'usersync'); 
  55.  
  56.           list($start,$post_id ,$forum_id) = pnModAPIFunc('pnForum', 'user', 'storereply', 
  57.  
  58.                                              array( 'topic_id'         => $topic_id, 
  59.                                                     'message'          => $message, 
  60.                                                         'attach_signature' => $attach_signature, 
  61.  
  62.                                                          'subscribe_topic'  => $subscribe_topic)); 
  63.               // edit mumu 
  64.               $pnr =& new pnRender('pnForum'); 
  65.               $pnr->clear_cache(null); 
  66.  
  67.               return pnRedirect(pnModURL('pnForum', 'user', 'viewforum', 
  68.                                     array('forum' => $forum_id)));  
  69.     } else { 
  70.         list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies'); 
  71.         $reply = pnModAPIFunc('pnForum', 'user', 'preparereply', 
  72.                               array('topic_id'   => $topic_id, 
  73.                                     'post_id'    => $post_id, 
  74.                                     'last_visit' => $last_visit, 
  75.                                     'reply_start'=> empty($message), 
  76.                                     'attach_signature' => $attach_signature, 
  77.                                     'subscribe_topic'  => $subscribe_topic)); 
  78.         if($preview==true) { 
  79.             $reply['message'] = pnfVarPrepHTMLDisplay($message); 
  80.         } 
  81.  
  82.         $pnr =& new pnRender('pnForum'); 
  83.         // edit mumu 
  84.  
  85.         $pnr->caching = false; 
  86.         $pnr->add_core_data(); 
  87.         $pnr->assign( 'reply', $reply); 
  88.         $pnr->assign( 'preview', $preview); 
  89.         $pnr->assign( 'last_visit', $last_visit); 
  90.         $pnr->assign( 'last_visit_unix', $last_visit_unix); 
  91.         return $pnr->fetch('pnforum_user_reply.html'); 
  92.     } 


on fait pareil à la création de nouveau sujet
  1. function pnForum_user_newtopic($args=array()) 
  2.     // get the input 
  3.     if(count($args)>0) { 
  4.         extract($args); 
  5.         unset($args); 
  6.     } else { 
  7.         list($forum_id, 
  8.              $message, 
  9.              $subject, 
  10.              $cancel, 
  11.              $submit, 
  12.              $attach_signature, 
  13.              $subscribe_topic, 
  14.              $preview) = pnVarCleanFromInput('forum', 
  15.                                              'message', 
  16.                                              'subject', 
  17.                                              'cancel', 
  18.                                              'submit', 
  19.                                              'attach_signature', 
  20.                                              'subscribe_topic', 
  21.                                              'preview'); 
  22.     } 
  23.  
  24.     $preview = (empty($preview)) ? false : true; 
  25.     $cancel  = (empty($cancel))  ? false : true; 
  26.     $submit  = (empty($submit))  ? false : true; 
  27.  
  28.     //  if cancel is submitted move to forum-view 
  29.     if($cancel==true) { 
  30.         return pnRedirect(pnModURL('pnForum','user', 'viewforum', array('forum'=>$forum_id))); 
  31.     } 
  32.  
  33.     if($submit==false) { 
  34.         $subject = ''; 
  35.         $message = ''; 
  36.     } 
  37.  
  38.     list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies'); 
  39.  
  40.     $newtopic = pnModAPIFunc('pnForum', 'user', 'preparenewtopic', 
  41.                              array('forum_id'   => $forum_id, 
  42.                                    'subject'    => $subject, 
  43.                                    'message'    => $message, 
  44.                                    'topic_start'=> (empty($subject) && empty($message)), 
  45.                                    'attach_signature' => $attach_signature, 
  46.                                    'subscribe_topic'  => $subscribe_topic)); 
  47.     if($submit==true && $preview==false) { 
  48.         // sync the users, so that new pn users get into the pnForum 
  49.         // database 
  50.         pnModAPIFunc('pnForum', 'user', 'usersync'); 
  51.  
  52.         // it's a submitted page 
  53.         // Confirm authorisation code 
  54.         if (!pnSecConfirmAuthKey()) { 
  55.             return showforumerror(_BADAUTHKEY, __FILE__, __LINE__); 
  56.         } 
  57.  
  58.         //store the new topic 
  59.         $topic_id = pnModAPIFunc('pnForum', 'user', 'storenewtopic', 
  60.                                  array('forum_id'         => $forum_id, 
  61.                                        'subject'          => $subject, 
  62.                                        'message'          => $message, 
  63.                                        'attach_signature' => $attach_signature, 
  64.                                        'subscribe_topic'  => $subscribe_topic)); 
  65.         $pnr =& new pnRender('pnForum'); 
  66.  
  67.          $pnr->clear_cache(null); 
  68.         return pnRedirect(pnModURL('pnForum', 'user', 'viewforum', 
  69.                             array('forum' => pnVarPrepForStore($forum_id)))); 
  70.     } else { 
  71.         // new topic 
  72.         $pnr =& new pnRender('pnForum'); 
  73.  
  74.         $pnr->caching = false; 
  75.         $pnr->add_core_data(); 
  76.         $pnr->assign( 'preview', $preview); 
  77.         $pnr->assign( 'newtopic', $newtopic); 
  78.         $pnr->assign( 'last_visit', $last_visit); 
  79.         $pnr->assign( 'last_visit_unix', $last_visit_unix); 
  80.         return $pnr->fetch('pnforum_user_newtopic.html'); 
  81.     } 


à l'édition de post, on éfface tout aussi.
  1. /** 
  2.  * editpost 
  3.  * 
  4.  */ 
  5. function pnForum_user_editpost($args=array()) 
  6.     // get the input 
  7.     if(count($args)>0) { 
  8.         extract($args); 
  9.         unset($args); 
  10.     } else { 
  11.         list($post_id, 
  12.              $topic_id, 
  13.              $message, 
  14.              $subject, 
  15.              $submit, 
  16.              $delete, 
  17.              $cancel, 
  18.              $preview) =  pnVarCleanFromInput('post', 
  19.                                               'topic', 
  20.                                               'message', 
  21.                                               'subject', 
  22.                                               'submit', 
  23.                                               'delete', 
  24.                                               'cancel', 
  25.                                               'preview'); 
  26.     } 
  27.  
  28.     $preview = (empty($preview)) ? false : true; 
  29.  
  30.     //  if cancel is submitted move to forum-view 
  31.     if(!empty($cancel)) { 
  32.         return pnRedirect(pnModURL('pnForum','user', 'viewtopic', array('topic'=>$topic_id))); 
  33.     } 
  34.  
  35.     if (empty($submit)) { 
  36.         $subject=""; 
  37.         $message=""; 
  38.     } 
  39.  
  40.     list($last_visit, $last_visit_unix) = pnModAPIFunc('pnForum', 'user', 'setcookies'); 
  41.  
  42.     if($submit && !$preview) { 
  43.         /** 
  44.          * Confirm authorisation code 
  45.          */ 
  46.         if (!pnSecConfirmAuthKey()) { 
  47.             return showforumerror(_BADAUTHKEY, __FILE__, __LINE__); 
  48.         } 
  49.         //store the new topic 
  50.         $redirect = pnModAPIFunc('pnForum', 'user', 'updatepost', 
  51.                                  array('post_id'  => $post_id, 
  52.                                        'delete'   => $delete, 
  53.                                        'subject'  => $subject, 
  54.                                        'message'  => $message)); 
  55.          // edit mumu 
  56.          $pnr =& new pnRender('pnForum'); 
  57.          $pnr->clear_cache(null); 
  58.         return pnRedirect($redirect); 
  59.  
  60.     } else { 
  61.         $post = pnModAPIFunc('pnForum', 'user', 'readpost', 
  62.                              array('post_id'    => $post_id)); 
  63.         if(!empty($subject)) { 
  64.             $post['topic_subject'] = $subject; 
  65.         } 
  66.  
  67.         // if the current user is the original poster we allow to 
  68.         // edit the subject 
  69.         $firstpost = pnModAPIFunc('pnForum', 'user', 'get_firstlast_post_in_topic', 
  70.                                   array('topic_id' => $post['topic_id'], 
  71.                                         'first'    => true)); 
  72.         if($post['poster_data']['pn_uid'] = $firstpost['poster_data']['pn_uid']) { 
  73.             $post['edit_subject'] = true; 
  74.         } 
  75.  
  76.         if(!empty($message)) { 
  77.             $post['post_text'] = $message; 
  78.             list($post['post_textdisplay']) = pnModCallHooks('item', 'transform', '', array($message)); 
  79.         } 
  80.         $pnr =& new pnRender('pnForum'); 
  81.         $pnr->caching = false; 
  82.         $pnr->add_core_data(); 
  83.         $pnr->assign( 'preview', $preview); 
  84.         $pnr->assign( 'post', $post); 
  85.         $pnr->assign( 'last_visit', $last_visit); 
  86.         $pnr->assign( 'last_visit_unix', $last_visit_unix); 
  87.         return $pnr->fetch('pnforum_user_editpost.html'); 
  88.     } 


... 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 ...)


  1. /** 
  2.  * topicadmin 
  3.  * 
  4.  */ 
  5. function pnForum_user_topicadmin($args=array()) 
  6.     // get the input 
  7.     if(count($args)>0) { 
  8.         extract($args); 
  9.         unset($args); 
  10.     } else { 
  11.         $topic_id = (int)pnVarCleanFromInput('topic'); 
  12.         $post_id  = (int)pnVarCleanFromInput('post'); 
  13.         $forum_id = (int)pnVarCleanFromInput('forum');  // for move 
  14.         $mode     = pnVarCleanFromInput('mode'); 
  15.         $submit   = pnVarCleanFromInput('submit'); 
  16.         $shadow   = pnVarCleanFromInput('createshadowtopic'); 
  17.     } 
  18.     $shadow = (empty($shadow)) ? false : true; 
  19.  
  20.     if(empty($topic_id) && !empty($post_id)) { 
  21.         $topic_id = pnModAPIFunc('pnForum', 'user', 'get_topicid_by_postid', 
  22.                                  array('post_id' => $post_id)); 
  23.     } 
  24.     $topic = pnModAPIFunc('pnForum', 'user', 'readtopic', 
  25.                           array('topic_id' => $topic_id)); 
  26.     if($topic['access_moderate']<>true) { 
  27.         return showforumerror(_PNFORUM_NOAUTH_TOMODERATE, __FILE__, __LINE__); 
  28.     } 
  29.  
  30.     $pnr =& new pnRender('pnForum'); 
  31.      $pnr->caching = false; 
  32.     $pnr->add_core_data(); 
  33.     $pnr->assign('mode', $mode); 
  34.     $pnr->assign('topic_id', $topic_id); 
  35.     $pnr->assign('last_visit', $last_visit); 
  36.     $pnr->assign('last_visit_unix', $last_visit_unix); 
  37.  
  38.     if(empty($submit)) { 
  39.         switch($mode) { 
  40.             case "del": 
  41.             case "delete": 
  42.                 $templatename = "pnforum_user_deletetopic.html"; 
  43.                 break; 
  44.             case "move": 
  45.             case "join": 
  46.                 $pnr->assign('forums', pnModAPIFunc('pnForum', 'user', 'readuserforums')); 
  47.                 $templatename = "pnforum_user_movetopic.html"; 
  48.                 break; 
  49.             case "lock": 
  50.             case "unlock": 
  51.                 $templatename = "pnforum_user_locktopic.html"; 
  52.                 break; 
  53.             case "sticky": 
  54.             case "unsticky": 
  55.                 $templatename = "pnforum_user_stickytopic.html"; 
  56.                 break; 
  57.             case "viewip": 
  58.                 $pnr->assign('viewip', pnModAPIFunc('pnForum', 'user', 'get_viewip_data', array('post_id' => $post_id))); 
  59.                 $templatename = "pnforum_user_viewip.html"; 
  60.                 break; 
  61.             default: 
  62.                 return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic'=>$topic_id))); 
  63.         } 
  64.         return $pnr->fetch($templatename); 
  65.  
  66.     } else { // submit is set 
  67.       $pnr->clear_cache(null); // edit : modération éffectuée on efface le cache 
  68.    
  69.         if (!pnSecConfirmAuthKey()) { 
  70.             return showforumerror(_BADAUTHKEY, __FILE__, __LINE__); 
  71.         } 
  72.         switch($mode) { 
  73.             case "del": 
  74.             case "delete": 
  75.                 $forum_id = pnModAPIFunc('pnForum', 'user', 'deletetopic', array('topic_id'=>$topic_id)); 
  76.                 return pnRedirect(pnModURL('pnForum', 'user', 'viewforum', array('forum'=>$forum_id))); 
  77.                 break; 
  78.             case "move": 
  79.                 pnModAPIFunc('pnForum', 'user', 'movetopic', array('topic_id' => $topic_id, 
  80.                                                                    'forum_id' => $forum_id, 
  81.                                                                    'shadow'   => $shadow )); 
  82.                 break; 
  83.             case "lock": 
  84.             case "unlock": 
  85.                 pnModAPIFunc('pnForum', 'user', 'lockunlocktopic', array('topic_id'=> $topic_id, 'mode'=>$mode)); 
  86.                 break; 
  87.             case "sticky": 
  88.             case "unsticky": 
  89.                 pnModAPIFunc('pnForum', 'user', 'stickyunstickytopic', array('topic_id'=> $topic_id, 'mode'=>$mode)); 
  90.                 break; 
  91.             case "join": 
  92.                 $to_topic_id = pnVarCleanFromInput('to_topic_id'); 
  93.                 pnModAPIFunc('pnForum', 'user', 'jointopics', array('from_topic_id' => $topic_id, 
  94.                                                                     'to_topic_id'   => $to_topic_id)); 
  95.                 return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic' => $to_topic_id))); 
  96.                 break; 
  97.             default: 
  98.         } 
  99.         return pnRedirect(pnModURL('pnForum', 'user', 'viewtopic', array('topic'=>$topic_id))); 
  100.     } 



  1. /** 
  2.  * splittopic 
  3.  * 
  4.  */ 
  5. function pnForum_user_splittopic($args=array()) 
  6.     // get the input 
  7.     if(count($args)>0) { 
  8.         extract($args); 
  9.         unset($args); 
  10.     } else { 
  11.         list($post_id, 
  12.              $submit, 
  13.              $newsubject) = pnVarCleanFromInput('post', 
  14.                                                 'submit', 
  15.                                                 'newsubject'); 
  16.     } 
  17.