Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

php problem Undefined variable: smilies (#8) in /functions/text.php on line 761

Options
  • 24-06-2014 9:16pm
    #1
    Closed Accounts Posts: 431 ✭✭


    here is the code:
    # Uncomment and run this block of code to generate new regex if any smilies have been altered in get_smilies method.
    			$smilies_keys = array_map ( 'preg_quote', array_keys ( $smilies ) );
    			$regex = "#(?<!\w)(". implode ( '|', $smilies_keys ) .")(?!\w)#se";
    			throw new error ($regex);
    		
    		
    		// Smilies list ([hook: smilies list])
    		$regex = '#(?<!\w|&\#8222;)(\:\)|\:\(\(|\:\(|\:DD|\:D|\:o|0_0|o_o|O_O|\:P|\:confused\:|B\)|\:shy\:|&gt;\:\(|o_O|O_o|\:angry\:|\:mad\:|&gt;_&gt;|-_-|8D|\:\||&gt;_&lt;|8\)|\:-\(|x\(|\:-\)|&lt;_&lt;|\:/|\:wacko\:|\^_\^|;\)|\:\\\\)(?!\w|&\#8220;)#se';
    		$txt = preg_replace ( $regex, '$this -> parse_smilies ( "\1", true )', $txt );
    		
    		return $txt;
    	}
    

    what exactly is gone wrong here what variables are undefined? also how do you insert code on boards


Comments

  • Registered Users Posts: 6,487 ✭✭✭daymobrew


    also how do you insert code on boards
    Put [ CODE ] this is my code block [ / CODE ] (without the spaces) around your code.

    You can also copy your code to http://pastebin.com/ and link to it in your post.


  • Registered Users Posts: 1,311 ✭✭✭Procasinator


    We can see $smilies is undefined from what you have posted, but I would guess this is only a fragment of the function.

    You will probably need to post more code.


  • Closed Accounts Posts: 431 ✭✭whats newxt


    ok so how would i define it then, i know nothing about php just trying to install an old cms


  • Registered Users Posts: 6,487 ✭✭✭daymobrew


    ok so how would i define it then, i know nothing about php just trying to install an old cms
    Post the entire function or file.


  • Registered Users Posts: 1,311 ✭✭✭Procasinator


    Some quick googling shows that the function you are calling is parse_smilies from text.php of a project called Diferior.

    Have you modified this function?

    Example:
    https://code.google.com/p/freetorrent/source/browse/trunk/trunk/Diferior_v8.03/functions/text.php?r=164


  • Advertisement
  • Closed Accounts Posts: 431 ✭✭whats newxt


    Some quick googling shows that the function you are calling is parse_smilies from text.php of a project called Diferior.

    Have you modified this function?

    Yes thats what i'm trying to install locally on LAMP and no i did not change anything. How do i get past this error?


  • Registered Users Posts: 1,311 ✭✭✭Procasinator


    You haven't given enough information for us to help you.


  • Registered Users Posts: 4,080 ✭✭✭sheesh


    looking at the code that procrastinator posted the function get_smilies (), is not in that file and needs to be included


    I would say using this very limited info that it is $smilies is not defined as it seems to defined inside an if statement.


  • Registered Users Posts: 1,311 ✭✭✭Procasinator


    sheesh wrote: »
    looking at the code that procrastinator posted the function get_smilies (), is not in that file and needs to be included

    It is there alright, just below the parse_smilies method.

    Looking at the OP code, it appears he may have uncommented the bit that has that note (only a fragment, but I see no closing comment sign so there is a good chance). If he did do that, smilies would be undefined.

    OP: The comment saying you can uncomment that block is misleading, cause even if it $smilies was defined, the throwing of the exception implies it's not meant to be run as-is.

    You could probably change the function to something like:

    [PHP]
    public function parse_smilies ( $txt, $callback = false )
    {
    $smilies = $this -> get_smilies ();

    if ( $callback )
    {
    $dir = 'http://'. URL .'/tpl_resources/'. $_SESSION [ 'template_dir' ] .'/images/smilies/';
    return '<img src="'. $dir . $smilies [ $txt ] .'.gif" alt="'. $txt .'" name="smilie_img" class="smilie" />';
    }

    // We need to build regex as we modified the smiliies list.
    $smilies_keys = array_map ( 'preg_quote', array_keys ( $smilies ) );
    $regex = "#(?<!\w)(". implode ( '|', $smilies_keys ) .")(?!\w)#se";

    // Smilies list ([hook: smilies list])
    // As the smilies have been modified from the out of the box settings, we can no longer use a hardcoded regex pattern.
    //$regex = '#(?<!\w|&\#8222;)(\:\)|\:\(\(|\:\(|\:DD|\:D|\:o|0_0|o_o|O_O|\:P|\:confused\:|B\)|\:shy\:|>\:\(|o_O|O_o|\:angry\:|\:mad\:|>_>|-_-|8D|\:\||>_<|8\)|\:-\(|x\(|\:-\)|<_<|\:/|\:wacko\:|\^_\^|;\)|\:\\\\)(?!\w|&\#8220;)#se';

    $txt = preg_replace ( $regex, '$this -> parse_smilies ( "\1", true )', $txt );

    return $txt;
    }
    [/PHP]

    The reason the code is like this, is because the author used a poor man's caching of the regex pattern. The out of the box smilies will always have the same regex, so instead of running the code to make the regex on each request, he has hard-coded it. As soon as you modify the list, the regex is out of date.


Advertisement