/** * Show info about stations * * @param string $station_name * @param object $obj * @param string $tdclass */ private function station_info($station_name, $obj, $tdclass) { $station_ls_from_star = $obj->ls_from_star == 0 ? "n/a" : number_format($obj->ls_from_star); $station_max_landing_pad_size = $obj->max_landing_pad_size; $station_max_landing_pad_size = $station_max_landing_pad_size == "L" ? "Large" : "Medium"; $station_is_planetary = $obj->is_planetary; $station_type = $obj->type; $icon = get_station_icon($station_type, $station_is_planetary); $station_id = $obj->station_id; $station_faction = $obj->station_faction == "" ? "" : "<strong>Faction:</strong> " . $obj->station_faction . "<br />"; $station_government = $obj->station_government == "" ? "" : "<strong>Government:</strong> " . $obj->station_government . "<br />"; $station_allegiance = $obj->station_allegiance == "" ? "" : "<strong>Allegiance:</strong> " . $obj->station_allegiance . "<br />"; $station_state = $obj->station_state == "" ? "" : "<strong>State:</strong> " . $obj->station_state . "<br />"; $station_type_d = $obj->type == "" ? "" : "<strong>Type:</strong> " . $obj->type . "<br />"; $station_economies = $obj->station_economies == "" ? "" : "<strong>Economies:</strong> " . $obj->station_economies . "<br />"; $station_import_commodities = $obj->import_commodities == "" ? "" : "<br /><strong>Import commodities:</strong> " . $obj->import_commodities . "<br />"; $station_export_commodities = $obj->export_commodities == "" ? "" : "<strong>Export commodities:</strong> " . $obj->export_commodities . "<br />"; $station_prohibited_commodities = $obj->prohibited_commodities == "" ? "" : "<strong>Prohibited commodities:</strong> " . $obj->prohibited_commodities . "<br />"; $station_selling_ships = $obj->selling_ships == "" ? "" : "<br /><strong>Selling ships:</strong> " . str_replace("'", "", $obj->selling_ships) . "<br />"; $station_shipyard = $obj->shipyard; $station_outfitting = $obj->outfitting; $station_commodities_market = $obj->commodities_market; $station_black_market = $obj->black_market; $station_refuel = $obj->refuel; $station_repair = $obj->repair; $station_rearm = $obj->rearm; $station_includes = array("shipyard" => $station_shipyard, "outfitting" => $station_outfitting, "commodities market" => $station_commodities_market, "black market" => $station_black_market, "refuel" => $station_refuel, "repair" => $station_repair, "restock" => $station_rearm); $i = 0; $station_services = ""; foreach ($station_includes as $name => $included) { if ($included == 1) { if ($i != 0) { $station_services .= ", "; } else { $station_services .= "<strong>Facilities:</strong> "; } $station_services .= $name; $i++; } } $station_services .= "<br />"; $outfitting_updated_at = $obj->outfitting_updated_at == "0" ? "" : "<br /><strong>Outfitting last updated:</strong> " . get_timeago($obj->outfitting_updated_at, true, true) . "<br />"; $shipyard_updated_at = $obj->shipyard_updated_at == "0" ? "" : "<strong>Shipyard last updated:</strong> " . get_timeago($obj->shipyard_updated_at, true, true) . "<br />"; $info = $station_type_d . $station_faction . $station_government . $station_allegiance . $station_state . $station_economies . $station_services; $info .= $station_import_commodities . $station_export_commodities . $station_prohibited_commodities . $outfitting_updated_at . $shipyard_updated_at . $station_selling_ships; $info = str_replace("['", "", $info); $info = str_replace("']", "", $info); $info = str_replace("', '", ", ", $info); /** * get allegiance icon */ $station_allegiance_icon = get_allegiance_icon($obj->station_allegiance); $station_allegiance_icon = '<img src="/style/img/' . $station_allegiance_icon . '" alt="' . $obj->station_allegiance . '" style="width:19px;height:19px;margin-right:5px" />'; /** * notify user if data is old */ $station_disp_name = $station_name; if (!empty($group_id) || !empty($ship_name)) { if (data_is_old($obj->outfitting_updated_at) || data_is_old($obj->shipyard_updated_at)) { $station_disp_name = '<span class="old_data">' . $station_name . '</span>'; } } ?> <td class="<?php echo $tdclass; ?> "> <?php echo $station_allegiance_icon . $icon; ?> <a href="javascript:void(0)" id="minfo<?php echo $station_id; ?> " title="Additional information"> <?php echo $station_disp_name; ?> </a> </td> <td class="<?php echo $tdclass; ?> "> <?php echo $station_ls_from_star; ?> </td> <td class="<?php echo $tdclass; ?> "> <?php echo $station_max_landing_pad_size; ?> </td> <script> $(document).mouseup(function (e) { var containers = []; containers.push($("#si_statinfo")); $.each(containers, function (key, value) { if (!$(value).is(e.target) && $(value).has(e.target).length === 0) { $(value).fadeOut("fast"); } }); }); $("#minfo<?php echo $station_id; ?> ").click(function (e) { var statinfo_div = $("#si_statinfo"); if (statinfo_div.is(":hidden")) { statinfo_div.fadeToggle("fast"); statinfo_div.css( { left: e.pageX - 330, top: e.pageY - 40 }); statinfo_div.html("<?php echo addslashes($info); ?> "); } }); </script> <?php }
/** * Get time elapsed in string * http://stackoverflow.com/questions/27330650/how-to-display-time-in-x-days-ago-in-php * * @param int $ptime unix timestamp * @param bool $diff * @param bool $format * @return string $ret * @author Arun Kumar */ function get_timeago($ptime, $diff = true, $format = false) { global $system_time; $ptime_og = $ptime; if ($diff === true) { $ptime = $ptime - $system_time * 60 * 60; } $etime = time() - $ptime; if ($etime < 1) { return 'less than ' . $etime . ' second ago'; } $a = array(12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second'); foreach ($a as $secs => $str) { $d = $etime / $secs; if ($d >= 1) { $r = round($d); if ($format !== true) { return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago'; } else { if (data_is_old($ptime_og)) { return '<span class="old_data">' . $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago</span>'; } else { return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago'; } } } } }
$station_services .= "<br />"; $outfitting_updated_at = $arr["outfitting_updated_at"] == "0" ? "" : "<br /><strong>Outfitting last updated:</strong> " . get_timeago($arr["outfitting_updated_at"], true, true) . "<br />"; $shipyard_updated_at = $arr["shipyard_updated_at"] == "0" ? "" : "<strong>Shipyard last updated:</strong> " . get_timeago($arr["shipyard_updated_at"], true, true) . "<br />"; $info = $station_type_d . $station_faction . $station_government . $station_allegiance . $station_state . $station_economies . $station_services . $station_import_commodities . $station_export_commodities . $station_prohibited_commodities . $outfitting_updated_at . $shipyard_updated_at . $station_selling_ships; $info = str_replace("['", "", $info); $info = str_replace("']", "", $info); $info = str_replace("', '", ", ", $info); // get allegiance icon $station_allegiance_icon = get_allegiance_icon($arr["station_allegiance"]); $station_allegiance_icon = '<img src="/style/img/' . $station_allegiance_icon . '" alt="' . $arr["station_allegiance"] . '" style="width:19px;height:19px;margin-right:5px" />'; /* * notify user if data is old */ $station_disp_name = $station_name; if (!empty($group_id) || !empty($ship_name)) { if (data_is_old($arr["outfitting_updated_at"]) || data_is_old($arr["shipyard_updated_at"])) { $station_disp_name = '<span class="old_data">' . $station_name . '</span>'; } } echo '<td class="transparent">' . $station_allegiance_icon . $icon . '<a href="javascript:void(0)" onclick="$(\'#si_statinfo_' . $station_id . '\').fadeToggle(\'fast\')" title="Additional information">' . $station_disp_name . '<div class="stationinfo_ns" id="si_statinfo_' . $station_id . '">' . $info . '</div></td>'; echo '<td class="transparent">' . $station_ls_from_star . '</td>'; echo '<td class="transparent">' . $station_max_landing_pad_size . '</td>'; } echo '</tr>'; $last_system = $system; } } else { echo '<tr><td>None found!</td></tr>'; } ?> </table>