Thread: Custom Top List Rank Widget on IPS with PHP Block Widget

Results 1 to 2 of 2
  1. #1 Custom Top List Rank Widget on IPS with PHP Block Widget 
    Registered Member
    Join Date
    Apr 2013
    Posts
    20
    Thanks given
    2
    Thanks received
    0
    Rep Power
    11
    Hey everyone, I just wanted to show off what I've accomplished today because I'm really proud of how it came together, and I hope to inspire others.

    I've added a 100% custom top list rank widget to my forums at Salvage RSPS: Top Runescape Private Server 2017.

    Here's a preview:

    Attached image

    I started by making a simple website scraper using simple html dom. I define my server name, the top list name and url (url of the page):
    Code:
    $rune_server = "Rune-Server";
    $rune_server_url = "https://www.rune-server.ee/toplist-";
    $name_of_server = "salvage";
    I then scrape, page by page for my server name in lower case:
    Code:
    $rune_server_rank = null;
    for ($i = 1; $i <= $PAGE_SEARCH_MAX; $i++) {
        $rune_server_rank = getRuneServerRank($name_of_server, file_get_html($rune_server_url . $i));
        if ($rune_server_rank != null) {
            break;
        }
    }
    The scraping is as follows:
    Code:
    function getRuneServerRank($server, $html) {
        $trs = $html->find("table tbody tr");  //the dom of the individual rows in the top list
        foreach ($trs as $tr) {
            if (strpos(strtolower($tr), $server)) {  //try to find my server name in one of the rows
                //server found (table row)
                $tds = $tr->find("td font");  //the nearest wrapper of the rank number I wish to find
                foreach ($tds as $td) {
                    //found cell with rank
                    $rank = $td->plaintext;   //get the plain text number from the tag
                    return (int) $rank;           //convert it to an int and return
                }
            }
        }
    
        return null;
    }
    I do the same for all the top lists I have my server listed on and add them to an array, then iterate through the array adding each find to a database table with the name of the top list, rank, a link, and the date it was inserted (I update if it the name and date already exist).

    On my website, I'm using Invision Power Board and I've added the TXT & PHP Widget to my add-ons. I dragged one of the php blocks onto my homepage and added a bit of code in the block to retrieve the data from the database and display it in a way I saw fit.

    Next, I added my php class that updates the database to my hosting site and set it to run as a cron job every 10 minutes.

    That's it! I left out a few parts just so this isn't a direct copy-paste, but it's very doable. The hardest part is figuring out the dom, but once you figure out and understand one site, the rest will come very easily. Leave any questions or comments you may have down below.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Actuvas's Avatar
    Join Date
    May 2013
    Age
    26
    Posts
    1,275
    Thanks given
    91
    Thanks received
    250
    Rep Power
    603
    Nice accomplishment
    Attached image


    Always Hiring Workers

    Only Discord = Act#8888 || Unique ID: 685662432131285002
    Reply With Quote  
     

  3. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Custom Top List Rank Widget on IPS with PHP Block Widget
    By Justin___ in forum Website Development
    Replies: 0
    Last Post: 01-03-2018, 04:35 AM
  2. What the hell is wrong with the top list
    By Defiled-X in forum Forum Related Help
    Replies: 10
    Last Post: 10-05-2010, 12:37 AM
  3. Added me server on top list..
    By R3aper in forum Forum Related Help
    Replies: 1
    Last Post: 08-27-2010, 03:47 PM
  4. [317]UltimatePk[317] #4 on Server Top List!
    By k y z o n i in forum Advertise
    Replies: 5
    Last Post: 07-08-2010, 11:41 PM
  5. [474]UltimatePk[474] #4 on Server Top List!
    By k y z o n i in forum Advertise
    Replies: 6
    Last Post: 07-08-2010, 10:59 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •