vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Unexpected T_STRING in custom plugin ? (https://vborg.vbsupport.ru/showthread.php?t=282443)

Altari 05-04-2012 07:57 PM

Unexpected T_STRING in custom plugin ?
 
Hello

(Sorry for my bad english)
I wrote a custom plugin and i have a error when trying to display an array using vb:each (unexpected T_STRING in class_core.php). If i don't register the array, there is no error, if i don't try to display the array there is no error, and my code perfectly run outside of VB.

So in my plugin i create an array, needed to create the second array :
PHP Code:

        $rescue = array();
        while (
$donnees $db->fetch_array($req_rescue)){
            
$rescue_id intval($donnees['id']);
            if(
$donnees['cherchable'] = 1){$rescue[$rescue_id] = $donnees['nom'];}
            else{
$rescue[$rescue_id] = 0;} 
            unset(
$rescue_id);
        }
        unset(
$donnees);
        
$db->free_result($req_rescue);
        
        
$tableau_lieux = array();
        while (
$donnees $db->fetch_array($req_liste)){
            
$id_lieu $donnees['a13'];
            if(
$donnees['a13'] != 0){
                if(!
array_key_exists($id_lieu$tableau_lieux)){
                    
$tableau_lieux[$id_lieu] = $rescue[$id_lieu];
                }
            }
            unset(
$id_lieu);
        }
        unset(
$donnees);
        
$db->free_result($req_liste); 

Prepare the array and registering it, to be used in the template recherche_adop_fd which will be displayed in 'forumdisplay' :

PHP Code:

        //On enl?ve les valeurs valant 0 (non cherchable) et on tri
        
unset($tableau_lieux[array_search(0$tableau_lieux)]);
        
asort($tableau_lieux);
        
$newTemplate vB_Template::create('recherche_adop_fd'); 
        
$newTemplate->register('tableau_lieux'$tableau_lieux);
        
$recherche_adop_fd$newTemplate->render();   

        
$placer_recherche '<!--recherche_adop-->'

        
$vbulletin->templatecache['FORUMDISPLAY'] = str_replace($placer_recherche,$placer_recherche.$recherche_adop_fd$vbulletin->templatecache['FORUMDISPLAY']); 

And my vb:each from recherche_adop_fd :
PHP Code:

            <vb:each from="tableau_lieux" key="id" value="valeur">
            <
option value="{vb:var id}">{vb:var valeur}</option>
            </
vb:each

If that can help you, here is the tableau_lieu array output using a print_r :
Code:

Array
(
    [372] => 01 - Ain
    [373] => 02 - Aisne
    [374] => 03 - Allier
    [375] => 04 - Alpes-de-Haute-Provence
    [376] => 05 - Hautes-Alpes
    [377] => 06 - Alpes-Maritimes
    [378] => 07 - Ard?che
    [379] => 08 - Ardennes
    [380] => 09 - Ari?ge
    [381] => 10 - Aube
    [382] => 11 - Aude
    [383] => 12 - Aveyron
    [384] => 13 - Bouches-du-Rh?ne
    [385] => 14 - Calvados
    [386] => 15 - Cantal
    [387] => 16 - Charente
    [388] => 17 - Charente-Maritime
    [389] => 18 - Cher
    [391] => 20 - Corse
    [392] => 21 - C?te-d'Or
    [393] => 22 - C?tes-d'Armor
    [395] => 24 - Dordogne
    [396] => 25 - Doubs
    [397] => 26 - Dr?me
    [398] => 27 - Eure
    [399] => 28 - Eure-et-Loir
    [400] => 29 - Finist?re
    [401] => 30 - Gard
    [402] => 31 - Haute-Garonne
    [403] => 32 - Gers
    [404] => 33 - Gironde
    [405] => 34 - H?rault
    [406] => 35 - Ille-et-Vilaine
    [407] => 36 - Indre
    [408] => 37 - Indre-et-Loire
    [409] => 38 - Is?re
    [410] => 39 - Jura
    [411] => 40 - Landes
    [412] => 41 - Loir-et-Cher
    [413] => 42 - Loire
    [414] => 43 - Haute-Loire
    [415] => 44 - Loire-Atlantique
    [416] => 45 - Loiret
    [417] => 46 - Lot
    [418] => 47 - Lot-et-Garonne
    [420] => 49 - Maine-et-Loire
    [421] => 50 - Manche
    [422] => 51 - Marne
    [423] => 52 - Haute-Marne
    [425] => 54 - Meurthe-et-Moselle
    [426] => 55 - Meuse
    [427] => 56 - Morbihan
    [428] => 57 - Moselle
    [429] => 58 - Ni?vre
    [430] => 59 - Nord
    [431] => 60 - Oise
    [432] => 61 - Orne
    [433] => 62 - Pas-de-Calais
    [434] => 63 - Puy-de-D?me
    [435] => 64 - Pyr?n?es-Atlantiques
    [436] => 65 - Hautes-Pyr?n?es
    [437] => 66 - Pyr?n?es-Orientales
    [438] => 67 - Bas-Rhin
    [439] => 68 - Haut-Rhin
    [440] => 69 - Rh?ne
    [441] => 70 - Haute-Sa?ne
    [442] => 71 - Sa?ne-et-Loire
    [443] => 72 - Sarthe
    [444] => 73 - Savoie
    [445] => 74 - Haute-Savoie
    [446] => 75 - Paris
    [447] => 76 - Seine-Maritime
    [448] => 77 - Seine-et-Marne
    [449] => 78 - Yvelines
    [450] => 79 - Deux-S?vres
    [451] => 80 - Somme
    [452] => 81 - Tarn
    [453] => 82 - Tarn-et-Garonne
    [454] => 83 - Var
    [455] => 84 - Vaucluse
    [456] => 85 - Vend?e
    [457] => 86 - Vienne
    [459] => 88 - Vosges
    [460] => 89 - Yonne
    [461] => 90 - Territoire de Belfort
    [462] => 91 - Essonne
    [463] => 92 - Hauts-de-Seine
    [464] => 93 - Seine-Saint-Denis
    [465] => 94 - Val-de-Marne
    [466] => 95 - Val-d'Oise
    [468] => Belgique
    [470] => Canada
    [472] => Non renseign?
    [467] => Outre-mer
)

Thank you a lot.

kh99 05-04-2012 10:58 PM

The problem is that $vbulletin->templatecache[] does not just contain the template html, it contains php code that produces the html when run through eval(). If you execute the query

Code:

SELECT template FROM template WHERE title='FORUMDISPLAY'
you will see the value of $vbulletin->templatecache['FORUMDISPLAY']. I believe what is causing your error is that some of your place names have the single quote ' character in them, so it is causing mismatched quotes in the template php code. You might be able to fix this by adding the following code to your plugin:

Code:

$recherche_adop_fd = str_replace("'", "\'", $recherche_adop_fd);

just after the $newTemplate->render() line.


All times are GMT. The time now is 10:26 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01143 seconds
  • Memory Usage 1,750KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete