Page 1 of 6 123 ... LastLast
Results 1 to 10 of 55

Thread: PHP help

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default PHP help

    Thanks to BRATS-SplatterGuts, he pointed out a glitch that I haven't come across and now I'm trying to fix. It seems to only affect the custom xcode tags, but I'm running into some trouble.
    Just to highlight the issue...

    For example, if you search the forum for "targetname" (without quotes), you will get results. One of the first results you should get is the thread "Teleport help for Dude" when you click the thread and look at the first post with the [xcode] tags, you will notice this


    local.trig targetname port1



    display as

    local.trig <span class="highlight">targetname</span> port1



    This is because the word we searched for in the forums matches the word in the xcode tags so it highlights it, and the embedded code to highlight is
    Code:
    <span class="highlight">some text</span>

    furthermore, if you look at the class in the css you will see

    .highlight {
    color: #417394;
    background: #FFEB90 none repeat-x ;
    }



    Any way... The "simple", but annoying fix is, when you do a search for that keyword, it appends "?highlight=keyword" to the URL of the thread.


    In our case
    http://www.x-null.net/forums/showthr...ght=targetname


    So it tries to highlight the word wherever it is displayed in that thread.




    What I'm trying to do is fix this glitch.
    What we know is the thread results are displayed in "showthread.php", so after some searching I have come across this function



    // *********************************************************************************
    // words to highlight from the search engine
    if (!empty($vbulletin->GPC['highlight']))
    {
    $highlight = preg_replace('#\*+#s', '*', $vbulletin->GPC['highlight']);

    if ($highlight != '*')
    {
    $regexfind = array('\*', '\<', '\>');
    $regexreplace = array('[\w.:@*/?=]*?', '<', '>');
    $highlight = preg_quote(strtolower($highlight), '#');
    $highlight = explode(' ', $highlight);
    $highlight = str_replace($regexfind, $regexreplace, $highlight);

    foreach ($highlight AS $val)
    {
    if ($val = trim($val))
    {
    $replacewords[] = htmlspecialchars_uni($val);
    }
    }
    }
    }



    This line:

    $replacewords[] = htmlspecialchars_uni($val);

    ...is what does the highlighting of the keyword, so I need to put in a line somewhere within the foreach() (I'm assuming).


    My issue is I'm not sure how to do this. I tried this
    Code:
    //preg_match_all('/[[\s]*xcode=[\s]*' . '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^]"]*)"?' . '[\s]*[\/]?[\s]*>/si', $contents, $match);
    preg_match('/[xcode=*', $val, $match );
    if(isset(tag_list['option']["$tagname"]['xcode']))
    if(isset(tag_list['option']["$pre_tag"]))

    The results are it either highlights keywords, or I break something and it doesn't highlight anything at all.
    Any suggestions?

  2. #2
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    ummm i'm not sure if it'd help , but

    why don't u just enable highlighting from the xcode ?

  3. #3
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    I don't understand what you're saying?

    The xcode is a third party plugin, that's seperate from vbulletin. Vbulletin does all contextual searches within it's own source, and xcode does it's own thing. It probably wouldn't be very safe to hook several things within a 3rd party plugin just to grab the search results. I'm not sure.

    The thing that bothers me, is the logic is simple enough, I just don't know how to do it within php. lol.

    Another thing I can do is check classes, because xcode uses this

    Code:
    <td class="code">
    of this
    <div id="highlighter_600321" class="syntaxhighlighter  php">
    However, once again, I'm not sure how to check if $val is part of that code block or class.

  4. #4
    Client Beta Testers Appelpitje's Avatar
    Join Date
    Jan 2012
    Location
    Belgium
    Posts
    571

    Default

    Not sure if this is your question but if you want to see whats in $val you could use this:

    PHP Code:
    <script type="text/javascript">
    console.log("<?php var_dump($val); ?>");
    </script>
    And check the browser console.

  5. #5
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    all I actually needed to do is
    Code:
    var_dump($val);
    which outputs
    string(10) "targetname"

  6. #6

    Default

    I didn't mean to start anything....REALLY!
    http://aodmohaaclan.clanservers.com/public_html/Xnull Sig.jpg

  7. #7
    Banned
    Join Date
    May 2010
    Location
    fuck off?
    Posts
    1,145

    Default

    ???
    This is not a PHP problem, nore is it a website problem
    Its a mac and XCODE problem. The problem being, its copying formatted text.
    The solution? use a good OS, use a good IDE which does code and doesnt copy formatted text? (ridiculous just like eclipsecrap) or find the option in XCode to use ascii and try that.

    not a php problem ....


    the other options is to manage the copy paste from code blocks and strip html, not worth it though.

  8. #8
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Elgan, I don't understand how i's a mac formatting issue? I'm on a macbook pro currently, but I'm able to recreate this on a Windows computer too.

    And the xcode plugin is coded in JS/php... I actually modified it in EditPlus which is a very simple stand alone text editor so nothing fancy about it.

  9. #9

    Default

    So, I'm not sure how this all works, but most likely, your only option is to use jQuery to remove the highlight markup from the xcode sections using a classname or id clientside. You could try selecting by classname and then removing the classname as a simple option...

    That, or you need to tell PHP to ignore inserting highlighting in certain sections of HTML or strip it out later somehow...

    Assuming xcode markup is always like it was in your example, this will work...

    Code:
    jQuery(document).ready(function() {
    	$(".syntaxhighlighter").each(function(e){
    		$(this).find("code").each(function(e){
    			var text = $(this).text();
    			if(text == '"highlight"'){
    				prevCodeDiv = $(this).prev();
    				nextCodeDiv = $(this).next();
    				closeSpanCodeDiv = $(this).next().next().next();
    				if(prevCodeDiv.length && nextCodeDiv.length && closeSpanCodeDiv.length){
    					// Delete this one from the DOM
    					$(this).remove();
    					
    					// Replace the highlight span start
    					$(prevCodeDiv).text(function () {
    						return $(prevCodeDiv).text().replace("<span class=", ""); 
    					});
    					
    					// Remove the close >
    					$(nextCodeDiv).remove();
    					
    					// Replace and remove the closing span tag
    					$(closeSpanCodeDiv).text(function () {
    						return $(closeSpanCodeDiv).text().replace("</span>", ""); 
    					});
    					
    				}
    			}
    		});
    	});
    });
    Browse MOHAA Servers Post GameSpy Era

    VISIT MOHREBORN.COM FOR LATEST INFORMATION



    Medal of Honor: Game Server Browser Fixer - Patches your MOHAA, MOHSH, and MOHBT game binaries to allow you to retrieve a list of game servers within the multi-player menu in-game even after GameSpy ceases operation!

    Medal of Honor: Query Launcher - Find, browse, organize, join, get your ping, and get more information regarding all Medal of Honor (AA, SH, & BT) servers from your PC at any time!
    Medal of Honor: Web Server Master List - Find and browse all Medal of Honor servers online using your browser!
    Add your Medal of Honor Server to the Master List
    YouTube Video for Medal of Honor: Query Launcher and MOHAASERVERS.TK!



    MOHAA Mods and Utilities
    OwN-3m-All's Mods
    Make Me Stock - A program that allows you to easily move-in and move-out non-stock mods and other files at the click of a button. Automates adding / removing mods without having to copy / move files manually.



    Quality Game Servers

    Rent dedicated Dallas Texas, Kansas City, Las Vegas Nevada, Chicago, Pennsylvania, and Sofia Bulgaria MOHAA and other game servers from We Be HostiN starting at $10 a month.


  10. #10

    Default

    Or do something like this on the php end wherever it needs to go:

    Code:
    $pattern = "/\[xcode\](.*)\[\/xcode\]/s"
    $xcodeMarkup = preg_match($pattern, $htmlMarkupForWholePage, $matches);
    foreach ($matches as &$match) {
    	$cleanReplacement = strip_tags($match);
    	$htmlMarkupForWholePage = str_replace($match, $cleanReplacement, $htmlMarkupForWholePage);
    }
    Don't know. That is a crappy problem to have. haha, luckily, it won't kill us.
    Browse MOHAA Servers Post GameSpy Era

    VISIT MOHREBORN.COM FOR LATEST INFORMATION



    Medal of Honor: Game Server Browser Fixer - Patches your MOHAA, MOHSH, and MOHBT game binaries to allow you to retrieve a list of game servers within the multi-player menu in-game even after GameSpy ceases operation!

    Medal of Honor: Query Launcher - Find, browse, organize, join, get your ping, and get more information regarding all Medal of Honor (AA, SH, & BT) servers from your PC at any time!
    Medal of Honor: Web Server Master List - Find and browse all Medal of Honor servers online using your browser!
    Add your Medal of Honor Server to the Master List
    YouTube Video for Medal of Honor: Query Launcher and MOHAASERVERS.TK!



    MOHAA Mods and Utilities
    OwN-3m-All's Mods
    Make Me Stock - A program that allows you to easily move-in and move-out non-stock mods and other files at the click of a button. Automates adding / removing mods without having to copy / move files manually.



    Quality Game Servers

    Rent dedicated Dallas Texas, Kansas City, Las Vegas Nevada, Chicago, Pennsylvania, and Sofia Bulgaria MOHAA and other game servers from We Be HostiN starting at $10 a month.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •