Created
July 8, 2015 05:18
-
-
Save LaocheXe/320b2d6f4504f6a568dc to your computer and use it in GitHub Desktop.
Shortcode for Plugin SWTORSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class swtorss_shortcodes extends e_shortcode | |
{ | |
public function __construct() | |
{ | |
// Nothing Here | |
} | |
function sc_swtorss_code_exe() | |
{ | |
$pref = e107::getConfig(); | |
$tp = e107::getParser(); | |
$plugin_pref = array(); | |
$plugin_pref['server'] = $_POST['server']; | |
$plugin_pref['url'] = $_POST['url']; | |
$plugin_pref['cache_file_name'] = $_POST['cache_file_name']; | |
$plugin_pref['cache_time_life'] = $_POST['cache_time_life']; | |
$serverName = $plugin_pref['server']; | |
$url = $plugin_pref['url']; | |
$cache_file_name = $plugin_pref['cache_file_name']; | |
$cache_time_life = $plugin_pref['cache_time_life']; | |
$cache_file_path = "cache"; | |
$cache_file = ''.$cache_file_path.''.$cache_file_name.''; | |
include_once('simple_html_dom.php'); | |
$data = new simple_html_dom(); | |
if(!(file_exists($cache_file)) || time() - filemtime($cache_file) >= $cache_time_life ) | |
{ | |
$data->load_file($url); | |
$data->save($cache_file); | |
} | |
else | |
{ | |
$data->load_file($cache_file); | |
} | |
$serverElm = $data->find("div[data-name=$serverName]", 0); | |
$server["name"] = $serverElm->find("div.name",0)->innertext; | |
$server["status"] = $serverElm->getAttribute('data-status'); | |
$server["type"] = $serverElm->getAttribute('data-type'); | |
$server["timezone"] = $serverElm->getAttribute('data-timezone'); | |
switch($serverElm->getAttribute('data-population')) | |
{ | |
case '1': | |
$server["population"] = 'Light'; | |
break; | |
case '2': | |
$server["population"] = 'Standard'; | |
break; | |
case '3': | |
$server["population"] = 'Heavy'; | |
break; | |
case '4': | |
$server["population"] = 'Very Heavy'; | |
break; | |
case '5': | |
$server["population"] = 'Full'; | |
break; | |
} | |
$text .= ' | |
<div id="swtor-serverStatus-widget"> | |
<div class="container"> | |
<div class="name">'.$server["name"].' '.$server["type"].', '.$server["timezone"].'</div> | |
<div class="status '.$server["status"].'"><strong>Status:</strong> '.$server["status"].'</div> | |
<div class="population"><strong>Population:</strong> '.$server["population"].'</div> | |
</div> | |
</div> | |
'; | |
return $text; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment