/**
  *	This function will parse the template and will return the parsed contents.
  *
  *	You can specify the name of the template which should be in the template directory. If no name is specified,
  *	the basename of the PHP script with the extension '.tpl' will be used.
  *
  *	This function automatically adds some variables to the template, which you can use as well in the template:
  *	YD_FW_NAME, YD_FW_VERSION, YD_FW_NAMEVERS, YD_FW_HOMEPAGE, YD_SELF_SCRIPT, YD_SELF_URI, YD_ACTION_PARAM.
  *
  *	@param $file		(optional) The name of the template you want to parse and output.
  *	@param $cache_id	(optional) ID for the cache of the template (must be unique).
  *	@param $display		(optional) Whether the output should be displayed or returned.
  *
  *	@returns	This function returns the output of the parsed template.
  */
 function fetch($file = '', $cache_id = null, $display = false)
 {
     // Add some default variables
     $this->assign('YD_FW_NAME', YD_FW_NAME);
     $this->assign('YD_FW_VERSION', YD_FW_VERSION);
     $this->assign('YD_FW_NAMEVERS', YD_FW_NAMEVERS);
     $this->assign('YD_FW_HOMEPAGE', YD_FW_HOMEPAGE);
     $this->assign('YD_SELF_SCRIPT', YD_SELF_SCRIPT);
     $this->assign('YD_SELF_URI', YD_SELF_URI);
     $this->assign('YD_ACTION_PARAM', YD_ACTION_PARAM);
     $this->assign('YD_ACTION', YDRequest::getActionName());
     // Get the template name
     $tplName = $this->_getTemplateName($file);
     // Output the template
     $result = parent::fetch($tplName, $cache_id, false);
     // Save the cache if needed
     if (!empty($cache_id) && !$this->force_compile && $this->caching) {
         $cacheFile = $this->_getCachePath($cache_id);
         $fp = fopen($cacheFile, 'wb');
         fwrite($fp, $result);
         fclose($fp);
     }
     if ($display == true) {
         echo $result;
     } else {
         return $result;
     }
 }
Exemple #2
0
 public function fetch($file = null, $display = false, $build = false, $cache_id = null)
 {
     if (!$file) {
         $file = $this->getTemplateFileName();
     }
     if (method_exists($this, 'runFirst')) {
         $this->runFirst();
     }
     $this->readConfigure();
     return parent::fetch($file, $display, $build, $cache_id);
 }
 public static function ShowFleetPage()
 {
     global $USER, $PLANET, $reslist, $resource, $db, $LNG, $ExtraDM;
     $PlanetRess = new ResourceUpdate();
     $PlanetRess->CalcResource();
     $PlanetRess->SavePlanetToDB();
     $parse = $LNG;
     $FleetID = request_var('fleetid', 0);
     $GetAction = request_var('action', "");
     $template = new template();
     $template->loadscript('flotten.js');
     $template->page_header();
     $template->page_topnav();
     $template->page_leftmenu();
     $template->page_planetmenu();
     $template->page_footer();
     if (!empty($FleetID)) {
         switch ($GetAction) {
             case "sendfleetback":
                 parent::SendFleetBack($USER, $FleetID);
                 break;
             case "getakspage":
                 $template->assign_vars(parent::GetAKSPage($USER, $PLANET, $FleetID));
                 $template->assign_vars(array('fl_invite_members' => $LNG['fl_invite_members'], 'fl_members_invited' => $LNG['fl_members_invited'], 'fl_modify_sac_name' => $LNG['fl_modify_sac_name'], 'fl_sac_of_fleet' => $LNG['fl_sac_of_fleet'], 'fl_continue' => $LNG['fl_continue']));
                 $AKSPage = $template->fetch('fleetACS_table.tpl');
                 break;
         }
     }
     $MaxExpedition = $USER[$resource[124]];
     if ($MaxExpedition >= 1) {
         $ExpeditionEnCours = parent::GetCurrentFleets($USER['id'], 15);
         $EnvoiMaxExpedition = floor(sqrt($MaxExpedition));
     } else {
         $ExpeditionEnCours = 0;
         $EnvoiMaxExpedition = 0;
     }
     $MaxFlottes = parent::GetMaxFleetSlots($USER);
     $galaxy = request_var('galaxy', $PLANET['galaxy']);
     $system = request_var('system', $PLANET['system']);
     $planet = request_var('planet', $PLANET['planet']);
     $planettype = request_var('planettype', $PLANET['planet_type']);
     $target_mission = request_var('target_mission', 0);
     $CurrentFleets = $db->query("SELECT * FROM " . FLEETS . " WHERE `fleet_owner` = '" . $USER['id'] . "' AND `fleet_mission` <> 10 ORDER BY `fleet_end_time` ASC;");
     $CountCurrentFleets = $db->num_rows($CurrentFleets);
     while ($CurrentFleetsRow = $db->fetch_array($CurrentFleets)) {
         $fleet = explode(";", $CurrentFleetsRow['fleet_array']);
         foreach ($fleet as $ShipID => $ShipCount) {
             if (empty($ShipCount)) {
                 continue;
             }
             $a = explode(",", $ShipCount);
             $FleetList[$CurrentFleetsRow['fleet_id']][$LNG['tech'][$a[0]]] = pretty_number($a[1]);
         }
         $FlyingFleetList[] = array('id' => $CurrentFleetsRow['fleet_id'], 'mission' => $CurrentFleetsRow['fleet_mission'], 'missionname' => $LNG['type_mission'][$CurrentFleetsRow['fleet_mission']], 'way' => $CurrentFleetsRow['fleet_mess'], 'start_galaxy' => $CurrentFleetsRow['fleet_start_galaxy'], 'start_system' => $CurrentFleetsRow['fleet_start_system'], 'start_planet' => $CurrentFleetsRow['fleet_start_planet'], 'start_time' => date("d M Y H:i:s", $CurrentFleetsRow['fleet_start_time']), 'end_galaxy' => $CurrentFleetsRow['fleet_end_galaxy'], 'end_system' => $CurrentFleetsRow['fleet_end_system'], 'end_planet' => $CurrentFleetsRow['fleet_end_planet'], 'end_time' => date("d M Y H:i:s", $CurrentFleetsRow['fleet_end_time']), 'amount' => pretty_number($CurrentFleetsRow['fleet_amount']), 'backin' => pretty_time(floor($CurrentFleetsRow['fleet_end_time'] - TIMESTAMP)), 'FleetList' => $FleetList[$CurrentFleetsRow['fleet_id']]);
     }
     $db->free_result($CurrentFleets);
     foreach ($reslist['fleet'] as $FleetID) {
         if ($PLANET[$resource[$FleetID]] > 0) {
             $FleetsOnPlanet[] = array('id' => $FleetID, 'name' => $LNG['tech'][$FleetID], 'speed' => parent::GetFleetMaxSpeed($FleetID, $USER), 'count' => pretty_number($PLANET[$resource[$FleetID]]));
         }
     }
     $template->assign_vars(array('FleetsOnPlanet' => $FleetsOnPlanet, 'FlyingFleetList' => $FlyingFleetList, 'fl_number' => $LNG['fl_number'], 'fl_mission' => $LNG['fl_mission'], 'fl_ammount' => $LNG['fl_ammount'], 'fl_beginning' => $LNG['fl_beginning'], 'fl_departure' => $LNG['fl_departure'], 'fl_destiny' => $LNG['fl_destiny'], 'fl_objective' => $LNG['fl_objective'], 'fl_arrival' => $LNG['fl_arrival'], 'fl_order' => $LNG['fl_order'], 'fl_new_mission_title' => $LNG['fl_new_mission_title'], 'fl_ship_type' => $LNG['fl_ship_type'], 'fl_ship_available' => $LNG['fl_ship_available'], 'fl_fleets' => $LNG['fl_fleets'], 'fl_expeditions' => $LNG['fl_expeditions'], 'fl_speed_title' => $LNG['fl_speed_title'], 'fl_max' => $LNG['fl_max'], 'fl_no_more_slots' => $LNG['fl_no_more_slots'], 'fl_continue' => $LNG['fl_continue'], 'fl_no_ships' => $LNG['fl_no_ships'], 'fl_select_all_ships' => $LNG['fl_select_all_ships'], 'fl_remove_all_ships' => $LNG['fl_remove_all_ships'], 'fl_acs' => $LNG['fl_acs'], 'fl_send_back' => $LNG['fl_send_back'], 'fl_returning' => $LNG['fl_returning'], 'fl_r' => $LNG['fl_r'], 'fl_onway' => $LNG['fl_onway'], 'fl_a' => $LNG['fl_a'], 'fl_info_detail' => $LNG['fl_info_detail'], 'fl_bonus' => $LNG['fl_bonus'], 'fl_bonus_attack' => $LNG['fl_bonus_attack'], 'fl_bonus_defensive' => $LNG['fl_bonus_defensive'], 'fl_bonus_shield' => $LNG['fl_bonus_shield'], 'bonus_comp' => $LNG['tech'][115], 'bonus_impul' => $LNG['tech'][117], 'bonus_hyper' => $LNG['tech'][118], 'galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'planettype' => $planettype, 'target_mission' => $target_mission, 'envoimaxexpedition' => $EnvoiMaxExpedition, 'expeditionencours' => $ExpeditionEnCours, 'flyingfleets' => $CountCurrentFleets, 'maxfleets' => $MaxFlottes, 'target_mission' => $target_mission, 'currentexpeditions' => $ExpeditionEnCours, 'maxexpeditions' => $EnvoiMaxExpedition, 'slots_available' => $MaxFlottes <= $MaxFlyingFleets - $MaxFlyingRaks ? false : true, 'AKSPage' => $AKSPage, 'bonus_attack' => $USER[$resource[109]] * 10 + $USER[$resource[602]] * 5 + (TIMESTAMP - $USER[$resource[700]] <= 0 ? 100 * $ExtraDM[700]['add'] : 0), 'bonus_defensive' => $USER[$resource[110]] * 10 + $USER[$resource[602]] * 5 + (TIMESTAMP - $USER[$resource[701]] <= 0 ? 100 * $ExtraDM[701]['add'] : 0), 'bonus_shield' => $USER[$resource[111]] * 10 + $USER[$resource[602]] * 5, 'bonus_combustion' => $USER[$resource[115]] * 10 + (TIMESTAMP - $USER[$resource[706]] <= 0 ? 100 * $ExtraDM[706]['add'] : 0), 'bonus_impulse' => $USER[$resource[117]] * 20 + (TIMESTAMP - $USER[$resource[706]] <= 0 ? 100 * $ExtraDM[706]['add'] : 0), 'bonus_hyperspace' => $USER[$resource[118]] * 30 + (TIMESTAMP - $USER[$resource[706]] <= 0 ? 100 * $ExtraDM[706]['add'] : 0)));
     $template->show('fleet_table.tpl');
 }
	30
*/
$text = isset($truncText) ? $truncText : "Read more...";
/*
	Param: truncText

	Purpose:
	Text to be displayed in [+link+]

	Options:
	Any valid text or html
	
	Default:
	"Read more..."
*/
$trunc_tpl = isset($tplTrunc) ? template::fetch($tplTrunc) : false;
/*
	Param: tplTrunc

	Purpose:
	Template to be used for [+link+]

	Options:
	- Any valid chunk name
	- Code via @CODE:
	- File via @FILE:
	
	Placeholders:
	[+url+] - URL of the document
	[+text+] - &truncText
Exemple #5
0
    public function testFunction()
    {
        $template = new template();
        $data = ['list' => ['language' => 'php', 'version' => ['5.4', '5.5']], 'a' => '[', 'b' => ']'];
        $content = <<<EOF
{function name="func" vars="\$data" call="\$list" use="&\$a,&\$b"}
{foreach \$data as \$key=>\$val}
{if is_array(\$val)}
{~\$func(\$val)}
{else}
{if !is_numeric(\$key)}
{\$key.':'.\$val.','}
{else}
{\$a.\$val.\$b}
{/if}
{/if}
{/foreach}
{/function}
EOF;
        $template->fetch($content, $data);
        $this->expectOutputString("language:php,[5.4][5.5]");
    }
    function TargetEvent()
    {
        global $pricelist, $reslist, $resource;
        $db = Database::get();
        $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;';
        $senderUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner']));
        $targetUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_target_owner']));
        $sql = 'SELECT * FROM %%PLANETS%% WHERE id = :planetId;';
        $targetPlanet = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_end_id']));
        $sql = 'SELECT name FROM %%PLANETS%% WHERE id = :planetId;';
        $senderPlanetName = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_start_id']), 'name');
        $LNG = $this->getLanguage($senderUser['lang']);
        $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
        $targetUser['factor'] = getFactors($targetUser, 'basic', $this->_fleet['fleet_start_time']);
        $planetUpdater = new ResourceUpdate();
        list($targetUser, $targetPlanet) = $planetUpdater->CalcResource($targetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']);
        $sql = 'SELECT * FROM %%FLEETS%% WHERE fleet_end_id = :planetId AND fleet_mission = 5 AND fleet_end_stay > :time;';
        $targetStayFleets = $db->select($sql, array(':planetId' => $this->_fleet['fleet_end_id'], ':time' => $this->_fleet['fleet_start_time']));
        foreach ($targetStayFleets as $fleetRow) {
            $fleetData = FleetFunctions::unserialize($fleetRow['fleet_array']);
            foreach ($fleetData as $shipId => $shipAmount) {
                $targetPlanet[$resource[$shipId]] += $shipAmount;
            }
        }
        $fleetAmount = $this->_fleet['fleet_amount'] * (1 + $senderUser['factor']['SpyPower']);
        $senderSpyTech = max($senderUser['spy_tech'], 1);
        $targetSpyTech = max($targetUser['spy_tech'], 1);
        $techDifference = abs($senderSpyTech - $targetSpyTech);
        $MinAmount = ($senderSpyTech > $targetSpyTech ? -1 : 1) * pow($techDifference * SPY_DIFFENCE_FACTOR, 2);
        $SpyFleet = $fleetAmount >= $MinAmount;
        $SpyDef = $fleetAmount >= $MinAmount + 1 * SPY_VIEW_FACTOR;
        $SpyBuild = $fleetAmount >= $MinAmount + 3 * SPY_VIEW_FACTOR;
        $SpyTechno = $fleetAmount >= $MinAmount + 5 * SPY_VIEW_FACTOR;
        $classIDs[900] = array_merge($reslist['resstype'][1], $reslist['resstype'][2]);
        if ($SpyFleet) {
            $classIDs[200] = $reslist['fleet'];
        }
        if ($SpyDef) {
            $classIDs[400] = array_merge($reslist['defense'], $reslist['missile']);
        }
        if ($SpyBuild) {
            $classIDs[0] = $reslist['build'];
        }
        if ($SpyTechno) {
            $classIDs[100] = $reslist['tech'];
        }
        $targetChance = mt_rand(0, min($fleetAmount / 4 * ($targetSpyTech / $senderSpyTech), 100));
        $spyChance = mt_rand(0, 100);
        $spyData = array();
        foreach ($classIDs as $classID => $elementIDs) {
            foreach ($elementIDs as $elementID) {
                if (isset($targetUser[$resource[$elementID]])) {
                    $spyData[$classID][$elementID] = $targetUser[$resource[$elementID]];
                } else {
                    $spyData[$classID][$elementID] = $targetPlanet[$resource[$elementID]];
                }
            }
            if ($senderUser['spyMessagesMode'] == 1) {
                $spyData[$classID] = array_filter($spyData[$classID]);
            }
        }
        // I'm use template class here, because i want to exclude HTML in PHP.
        require_once 'includes/classes/class.template.php';
        $template = new template();
        $template->caching = true;
        $template->compile_id = $senderUser['lang'];
        $template->loadFilter('output', 'trimwhitespace');
        list($tplDir) = $template->getTemplateDir();
        $template->setTemplateDir($tplDir . 'game/');
        $template->assign_vars(array('spyData' => $spyData, 'targetPlanet' => $targetPlanet, 'targetChance' => $targetChance, 'spyChance' => $spyChance, 'isBattleSim' => ENABLE_SIMULATOR_LINK == true && isModuleAvailable(MODULE_SIMULATOR), 'title' => sprintf($LNG['sys_mess_head'], $targetPlanet['name'], $targetPlanet['galaxy'], $targetPlanet['system'], $targetPlanet['planet'], _date($LNG['php_tdformat'], $this->_fleet['fleet_end_time'], $targetUser['timezone'], $LNG))));
        $template->assign_vars(array('LNG' => $LNG), false);
        $spyReport = $template->fetch('shared.mission.spyReport.tpl');
        PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_qg'], 0, $LNG['sys_mess_spy_report'], $spyReport, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        $LNG = $this->getLanguage($targetUser['lang']);
        $targetMessage = $LNG['sys_mess_spy_ennemyfleet'] . " " . $senderPlanetName;
        if ($this->_fleet['fleet_start_type'] == 3) {
            $targetMessage .= $LNG['sys_mess_spy_report_moon'] . ' ';
        }
        $text = '<a href="game.php?page=galaxy&amp;galaxy=%1$s&amp;system=%2$s">[%1$s:%2$s:%3$s]</a> %7$s
		%8$s <a href="game.php?page=galaxy&amp;galaxy=%4$s&amp;system=%5$s">[%4$s:%5$s:%6$s]</a> %9$s';
        $targetMessage .= sprintf($text, $this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $LNG['sys_mess_spy_seen_at'], $targetPlanet['name'], $LNG['sys_mess_spy_seen_at2']);
        PlayerUtil::sendMessage($this->_fleet['fleet_target_owner'], 0, $LNG['sys_mess_spy_control'], 0, $LNG['sys_mess_spy_activity'], $targetMessage, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        if ($targetChance >= $spyChance) {
            $config = Config::get($this->_fleet['fleet_universe']);
            $whereCol = $this->_fleet['fleet_end_type'] == 3 ? "id_luna" : "id";
            $sql = 'UPDATE %%PLANETS%% SET
			der_metal	= der_metal + :metal,
			der_crystal = der_crystal + :crystal
			WHERE ' . $whereCol . ' = :planetId;';
            $db->update($sql, array(':metal' => $fleetAmount * $pricelist[210]['cost'][901] * $config->Fleet_Cdr / 100, ':crystal' => $fleetAmount * $pricelist[210]['cost'][902] * $config->Fleet_Cdr / 100, ':planetId' => $this->_fleet['fleet_end_id']));
            $this->KillFleet();
        } else {
            $this->setState(FLEET_RETURN);
            $this->SaveFleet();
        }
    }
 function TargetEvent()
 {
     global $pricelist, $reslist, $resource;
     $senderUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
     $senderPlanet = $GLOBALS['DATABASE']->getFirstRow("SELECT galaxy, system, planet, name FROM " . PLANETS . " WHERE id = " . $this->_fleet['fleet_start_id'] . ";");
     $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
     $ownSpyLvl = max($senderUser['spy_tech'], 1);
     $LNG = $this->getLanguage($senderUser['lang']);
     $targetUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_target_owner'] . ";");
     $targetPlanet = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE id = " . $this->_fleet['fleet_end_id'] . ";");
     $totale_ris = ($targetPlanet['metal'] + $targetPlanet['crystal'] + $targetPlanet['deuterium']) / 2;
     $fleet_202 = pretty_number(ceil($totale_ris / $pricelist[202]['capacity']));
     $fleet_203 = pretty_number(ceil($totale_ris / $pricelist[203]['capacity']));
     $fleet_209 = pretty_number(ceil($totale_ris / $pricelist[209]['capacity']));
     $fleet_219 = pretty_number(ceil($totale_ris / $pricelist[219]['capacity']));
     $risorsi = pretty_number($totale_ris);
     $targetSpyLvl = max($targetUser['spy_tech'], 1);
     $targetUser['factor'] = getFactors($targetUser, 'basic', $this->_fleet['fleet_start_time']);
     $PlanetRess = new ResourceUpdate();
     list($targetUser, $targetPlanet) = $PlanetRess->CalcResource($targetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']);
     $targetStayFleets = $GLOBALS['DATABASE']->query("SELECT * FROM " . FLEETS . " WHERE fleet_end_id = " . $this->_fleet['fleet_end_id'] . " AND fleet_mission = 5 AND fleet_end_stay > " . $this->_fleet['fleet_start_time'] . ";");
     while ($fleetRow = $GLOBALS['DATABASE']->fetch_array($targetStayFleets)) {
         $temp = explode(';', $fleetRow['fleet_array']);
         foreach ($temp as $temp2) {
             $temp2 = explode(',', $temp2);
             if (!isset($targetPlanet[$resource[$temp2[0]]])) {
                 $targetPlanet[$resource[$temp2[0]]] = 0;
             }
             $targetPlanet[$resource[$temp2[0]]] += $temp2[1];
         }
     }
     $GLOBALS['DATABASE']->free_result($targetStayFleets);
     $fleetAmount = $this->_fleet['fleet_amount'] * (1 + $senderUser['factor']['SpyPower']);
     $Diffence = abs($ownSpyLvl - $targetSpyLvl);
     $MinAmount = ($ownSpyLvl > $targetSpyLvl ? -1 : 1) * pow($Diffence * SPY_DIFFENCE_FACTOR, 2);
     $SpyFleet = $fleetAmount >= $MinAmount;
     $SpyDef = $fleetAmount >= $MinAmount + 1 * SPY_VIEW_FACTOR;
     $SpyBuild = $fleetAmount >= $MinAmount + 3 * SPY_VIEW_FACTOR;
     $SpyTechno = $fleetAmount >= $MinAmount + 5 * SPY_VIEW_FACTOR;
     $classIDs[900] = array_merge($reslist['resstype'][1], $reslist['resstype'][2]);
     if ($SpyFleet) {
         $classIDs[200] = $reslist['fleet'];
     }
     if ($SpyDef) {
         $classIDs[400] = $reslist['defense'];
     }
     if ($SpyBuild) {
         $classIDs[0] = $reslist['build'];
     }
     if ($SpyTechno) {
         $classIDs[100] = $reslist['tech'];
     }
     $targetChance = mt_rand(0, min($fleetAmount / 4 * ($targetSpyLvl / $ownSpyLvl), 100));
     $spyChance = mt_rand(0, 100);
     foreach ($classIDs as $classID => $elementIDs) {
         foreach ($elementIDs as $elementID) {
             if ($classID == 100) {
                 $spyData[$classID][$elementID] = $targetUser[$resource[$elementID]];
             } else {
                 $spyData[$classID][$elementID] = $targetPlanet[$resource[$elementID]];
             }
         }
         if ($senderUser['spyMessagesMode'] == 1) {
             $spyData[$classID] = array_filter($spyData[$classID]);
         }
     }
     // I'm use template class here, because i want to exclude HTML in PHP.
     require_once 'includes/classes/class.template.php';
     $template = new template();
     $template->caching = true;
     $template->compile_id = $senderUser['lang'];
     $template->loadFilter('output', 'trimwhitespace');
     list($tplDir) = $template->getTemplateDir();
     $template->setTemplateDir($tplDir . 'game/');
     $template->assign_vars(array('spyData' => $spyData, 'targetPlanet' => $targetPlanet, 'targetChance' => $targetChance, 'spyChance' => $spyChance, 'isBattleSim' => ENABLE_SIMULATOR_LINK == true && isModulAvalible(MODULE_SIMULATOR), 'title' => sprintf($LNG['sys_mess_head'], $targetPlanet['name'], $targetPlanet['galaxy'], $targetPlanet['system'], $targetPlanet['planet'], _date($LNG['php_tdformat'], $this->_fleet['fleet_end_time'], $targetUser['timezone'], $LNG)), 'tot_risorsi' => $risorsi, 'fleet_202' => "" . $LNG['tech'][202] . " " . $fleet_202 . "", 'fleet_203' => "" . $LNG['tech'][203] . " " . $fleet_203 . "", 'fleet_209' => "" . $LNG['tech'][209] . " " . $fleet_209 . "", 'fleet_219' => "" . $LNG['tech'][219] . " " . $fleet_219 . ""));
     $template->assign_vars(array('LNG' => $LNG), false);
     $spyRaport = $template->fetch('shared.mission.spyraport.tpl');
     SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_start_time'], 0, $LNG['sys_mess_qg'], $LNG['sys_mess_spy_report'], $spyRaport);
     $LNG = $this->getLanguage($targetUser['lang']);
     $targetMessage = $LNG['sys_mess_spy_ennemyfleet'] . " " . $senderPlanet['name'];
     if ($this->_fleet['fleet_start_type'] == 3) {
         $targetMessage .= $LNG['sys_mess_spy_report_moon'] . ' ';
     }
     $targetMessage .= '<a href="game.php?page=galaxy&amp;galaxy=' . $senderPlanet["galaxy"] . '&amp;system=' . $senderPlanet["system"] . '">' . '[' . $senderPlanet['galaxy'] . ':' . $senderPlanet['system'] . ':' . $senderPlanet['planet'] . ']</a> ' . $LNG['sys_mess_spy_seen_at'] . ' ' . $targetPlanet['name'] . ' [' . $targetPlanet['galaxy'] . ':' . $targetPlanet['system'] . ':' . $targetPlanet['planet'] . '] ' . $LNG['sys_mess_spy_seen_at2'] . '.';
     SendSimpleMessage($this->_fleet['fleet_target_owner'], 0, $this->_fleet['fleet_start_time'], 0, $LNG['sys_mess_spy_control'], $LNG['sys_mess_spy_activity'], $targetMessage);
     if ($targetChance >= $spyChance) {
         $CONF = Config::getAll(NULL, $this->_fleet['fleet_universe']);
         $WhereCol = $this->_fleet['fleet_end_type'] == 3 ? "id_luna" : "id";
         $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET\n\t\t\tder_metal = der_metal + " . $fleetAmount * $pricelist[210]['cost'][901] * (Config::get('Fleet_Cdr') / 100) . ", \n\t\t\tder_crystal = der_crystal + " . $fleetAmount * $pricelist[210]['cost'][902] * (Config::get('Fleet_Cdr') / 100) . " \n\t\t\tWHERE " . $WhereCol . " = " . $this->_fleet['fleet_end_id'] . ";");
         $this->KillFleet();
     } else {
         $this->setState(FLEET_RETURN);
         $this->SaveFleet();
     }
 }
	1 - string of links &tagDisplayDelimiter separated 
*/
$givenTags = !empty($tags) ? trim($tags) : false;
/*
	Param: tags

	Purpose:
 	Allow the user to provide initial tags to be filtered

	Options:
	Any valid tags separated by <tagDelimiter>
	
	Default:
	[NULL]
*/
$tplTagLinks = !empty($tplTagLinks) ? template::fetch($tplTagLinks) : false;
/*
	Param: tplTagLinks

	Purpose:
 	Define a custom template for the tagLinks placeholder

	Options:
	- Any valid chunk name
	- Code via @CODE
	- File via @FILE
	
	Default:
	(code)
	<a href="[+url+]" class="ditto_tag" rel="tag">[+tag+]</a>	
*/
 public function DefensesBuildingPage()
 {
     global $USER, $PLANET, $LNG, $resource, $dpath, $reslist;
     include_once ROOT_PATH . 'includes/functions/IsTechnologieAccessible.' . PHP_EXT;
     include_once ROOT_PATH . 'includes/functions/GetElementPrice.' . PHP_EXT;
     $template = new template();
     if ($PLANET[$resource[21]] == 0) {
         $template->message($LNG['bd_shipyard_required']);
         exit;
     }
     $fmenge = $_POST['fmenge'];
     $cancel = $_POST['auftr'];
     $action = request_var('action', '');
     $PlanetRess = new ResourceUpdate();
     $PlanetRess->CalcResource();
     $NotBuilding = true;
     if (!empty($PLANET['b_building_id'])) {
         $CurrentQueue = $PLANET['b_building_id'];
         $QueueArray = explode(";", $CurrentQueue);
         for ($i = 0; $i < count($QueueArray); $i++) {
             $ListIDArray = explode(",", $QueueArray[$i]);
             if ($ListIDArray[0] == 21 || $ListIDArray[0] == 15) {
                 $NotBuilding = false;
             }
         }
     }
     if (isset($fmenge) && $NotBuilding == true && $USER['urlaubs_modus'] == 0) {
         $ebuild = explode(";", $PLANET['b_hangar_id']);
         if (count($ebuild) - 1 >= MAX_FLEET_OR_DEFS_IN_BUILD) {
             $template->message(sprintf($LNG['bd_max_builds'], MAX_FLEET_OR_DEFS_IN_BUILD), "?page=buildings&mode=fleet", 3);
             exit;
         }
         $Missiles[502] = $PLANET[$resource[502]];
         $Missiles[503] = $PLANET[$resource[503]];
         $SiloSize = $PLANET[$resource[44]];
         $MaxMissiles = $SiloSize * 10;
         $BuildQueue = $PLANET['b_hangar_id'];
         $BuildArray = explode(";", $BuildQueue);
         for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
             $ElmentArray = explode(",", $BuildArray[$QElement]);
             $Missiles[$ElmentArray[0]] += $ElmentArray[1];
         }
         foreach ($fmenge as $Element => $Count) {
             $Element = in_array($Element, $reslist['defense']) ? $Element : NULL;
             $Count = is_numeric($Count) ? $Count : 0;
             $Count = max(min($Count, MAX_FLEET_OR_DEFS_PER_ROW), 0);
             $MaxElements = $this->GetMaxConstructibleElements($Element);
             if (empty($Element) || empty($Count) || empty($MaxElements) || !IsTechnologieAccessible($USER, $PLANET, $Element)) {
                 continue;
             }
             if ($Element == 502 || $Element == 503) {
                 $ActuMissiles = $Missiles[502] + 2 * $Missiles[503];
                 $MissilesSpace = $MaxMissiles - $ActuMissiles;
                 if ($Element == 502) {
                     $Count = min($Count, $MissilesSpace);
                 } else {
                     $Count = min($Count, floor($MissilesSpace / 2));
                 }
                 $Count = min($Count, $MaxElements);
                 $Missiles[$Element] += $Count;
             } elseif (in_array($Element, $reslist['one'])) {
                 $Count = $PLANET[$resource[$Element]] == 0 && strpos($PLANET['b_hangar_id'], $Element . ',') === false ? 1 : 0;
             } else {
                 $Count = min($Count, $MaxElements);
             }
             if ($Count < 1) {
                 continue;
             }
             $Ressource = $this->GetElementRessources($Element, $Count);
             $PLANET['metal'] -= $Ressource['metal'];
             $PLANET['crystal'] -= $Ressource['crystal'];
             $PLANET['deuterium'] -= $Ressource['deuterium'];
             $USER['darkmatter'] -= $Ressource['darkmatter'];
             $PLANET['b_hangar_id'] .= $Element . ',' . floattostring($Count) . ';';
         }
     }
     if ($action == "delete" && is_array($cancel) && $USER['urlaubs_modus'] == 0) {
         $this->CancelAuftr($cancel);
     }
     $PlanetRess->SavePlanetToDB();
     if (!empty($PLANET['b_hangar_id'])) {
         $template->loadscript('bcmath.js');
         $template->loadscript('shipyard.js');
         $template->execscript("ShipyardList();BuildlistShipyard();");
     }
     $template->page_header();
     $template->page_topnav();
     $template->page_leftmenu();
     $template->page_planetmenu();
     $template->page_footer();
     foreach ($reslist['defense'] as $Element) {
         if (!IsTechnologieAccessible($USER, $PLANET, $Element)) {
             continue;
         }
         $DefenseList[] = array('id' => $Element, 'name' => $LNG['tech'][$Element], 'descriptions' => $LNG['res']['descriptions'][$Element], 'price' => GetElementPrice($USER, $PLANET, $Element, false), 'restprice' => $this->GetRestPrice($Element), 'time' => pretty_time(GetBuildingTime($USER, $PLANET, $Element)), 'IsAvailable' => IsElementBuyable($USER, $PLANET, $Element, false), 'Available' => pretty_number($PLANET[$resource[$Element]]), 'AlreadyBuild' => in_array($Element, $reslist['one']) && (strpos($PLANET['b_hangar_id'], $Element . ",") !== false || $PLANET[$resource[$Element]] != 0) ? true : false);
     }
     if (!empty($PLANET['b_hangar_id'])) {
         $ElementQueue = explode(';', $PLANET['b_hangar_id']);
         $NbrePerType = "";
         $NamePerType = "";
         $TimePerType = "";
         foreach ($ElementQueue as $ElementLine => $Element) {
             if ($Element != '') {
                 $Element = explode(',', $Element);
                 $ElementTime = GetBuildingTime($USER, $PLANET, $Element[0]);
                 $QueueTime += $ElementTime * $Element[1];
                 $TimePerType .= $ElementTime . ',';
                 $NamePerType .= "'" . html_entity_decode($LNG['tech'][$Element[0]], ENT_NOQUOTES, "UTF-8") . "',";
                 $NbrePerType .= "'" . $Element[1] . "',";
             }
         }
         $template->assign_vars(array('a' => $NbrePerType, 'b' => $NamePerType, 'c' => $TimePerType, 'b_hangar_id_plus' => $PLANET['b_hangar'], 'pretty_time_b_hangar' => pretty_time(max($QueueTime - $PLANET['b_hangar'], 0)), 'bd_completed' => $LNG['bd_completed'], 'bd_cancel_warning' => $LNG['bd_cancel_warning'], 'bd_cancel_send' => $LNG['bd_cancel_send'], 'bd_actual_production' => $LNG['bd_actual_production'], 'bd_operating' => $LNG['bd_operating']));
         $Buildlist = $template->fetch('shipyard_buildlist.tpl');
     }
     $template->assign_vars(array('DefenseList' => $DefenseList, 'NotBuilding' => $NotBuilding, 'bd_available' => $LNG['bd_available'], 'bd_remaining' => $LNG['bd_remaining'], 'fgf_time' => $LNG['fgf_time'], 'bd_build_ships' => $LNG['bd_build_ships'], 'bd_building_shipyard' => $LNG['bd_building_shipyard'], 'bd_protection_shield_only_one' => $LNG['bd_protection_shield_only_one'], 'BuildList' => $Buildlist, 'maxlength' => strlen(MAX_FLEET_OR_DEFS_PER_ROW)));
     $template->show("shipyard_defense.tpl");
 }
Exemple #10
0
    public function testFor()
    {
        $template = new template();
        $content = <<<EOF
{for start="1" end=":strlen(1000000000)" comparison="lt" step="1" name="i" }
{\$i}
{/for}
EOF;
        $template->fetch($content);
        $this->expectOutputString('123456789');
    }
Exemple #11
0
<?php

/**
 * administrative interface for "What's hot" section on openSUSE.org frontpage
 *
 * @author Andreas Demmer <*****@*****.**>
 */
define('CONTENT_FILE', '../whats_hot.html');
require_once 'my.exception.php';
require_once 'template.class.php';
try {
    preg_match('/\\/([a-z]{2})\\/admin\\//i', $_SERVER['PHP_SELF'], $matches);
    $template = new template('../../whats_hot/template.html');
    $template->language = $matches[1];
    if (isset($_POST['save'])) {
        file_put_contents(CONTENT_FILE, $_POST['content']);
        $message = $template->addLoop('message');
        $message->text = 'File was saved successfully.';
    } else {
        $template->addLoop('wysiwyg_editor');
        $form = $template->addLoop('form');
        $form->content = file_get_contents(CONTENT_FILE);
    }
    echo $template->fetch();
} catch (myException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}
Exemple #12
0
 public function index($request, $response)
 {
     global $admin_id;
     $url = get_url('index', $admin_id);
     $result = Util::request($url);
     $task_list = array();
     if (!empty($result['tasks'])) {
         $task_list = $result['tasks'];
     }
     $tpl = new template();
     $tpl->assign('task_list', $task_list);
     $str = $tpl->fetch('index');
     $response->end($str);
     //$response->end($tpl->fetch('index'));
 }