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 there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 24-06-2014 8: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, Registered Users 2 Posts: 6,570 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 6,570 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 1,311 ✭✭✭Procasinator


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


  • Registered Users, Registered Users 2 Posts: 4,081 ✭✭✭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, Registered Users 2 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