Esempio n. 1
0
 /**
  * Format a timestamp according the time format in the translations.
  *
  * @param integer $time        The timestamp to format
  * @param boolean $withSeconds Whether to add seconds to the formatted time or not
  *
  * @return string
  */
 public static function time($time, $withSeconds = false)
 {
     $translator = \SmartWork\Translator::getInstance();
     if ($withSeconds) {
         return date($translator->gt('timeFormat'), $time);
     } else {
         return date($translator->gt('timeFormatShort'), $time);
     }
 }
Esempio n. 2
0
 /**
  * Transform the hit points array into a string of the following format:
  * {diceCount}{diceType}+/-{additional}
  * Also adds the stamina damage flag.
  *
  * Examples:
  * 2W6+2
  * 1W20+0
  * 1W6+1 (A)
  *
  * @param array $hitPointsArray
  *
  * @return string
  */
 public static function getHitPointsString($hitPointsArray)
 {
     $translator = \SmartWork\Translator::getInstance();
     $hitPointsString = $hitPointsArray['hitPointsDice'];
     $hitPointsString .= $translator->gt($hitPointsArray['hitPointsDiceType']);
     $hitPointsString .= sprintf('%+d', $hitPointsArray['hitPoints']);
     if ($hitPointsArray['damageType'] == 'stamina') {
         $hitPointsString .= ' ' . $translator->gt('(S)');
     }
     return $hitPointsString;
 }
Esempio n. 3
0
 /**
  * Send an email
  *
  * @param array  $recipient The recipient to send the mail to
  *                          Format:
  *                          array(
  *                              '*****@*****.**',
  *                              'test',
  *                          )
  * @param string $subject   The mail subjet
  * @param string $message   The mail message, may be html
  *
  * @return boolean
  */
 public static function send($recipient, $subject, $message)
 {
     $translator = \SmartWork\Translator::getInstance();
     $mailer = new \PHPMailer(true);
     $mailer->set('CharSet', $this->globalConfig->getConfig('charset'));
     $mailer->setFrom($this->globalConfig->getGlobal(array('mail' => 'sender')), $translator->gt('title'));
     $mailer->addAddress($recipient[0], $recipient[1]);
     $mailer->set('Subject', $subject);
     $mailer->set('AltBody', strip_tags($message));
     $mailer->msgHTML($message);
     $mailer->isHTML(true);
     return $mailer->send();
 }
Esempio n. 4
0
 /**
  * Login process with check for the form salt, existing users and a password check.
  *
  * @param string $username
  * @param string $password
  * @param string $salt
  *
  * @return void
  */
 protected function logIn($username, $password, $salt)
 {
     if (!$salt || $salt != $_SESSION['formSalts']['login']) {
         return;
     }
     if (!$username && !$password) {
         $this->template->assign('error', 'emptyLogin');
         return;
     }
     $user = \SmartWork\User::getUser($username, $password);
     if ($user) {
         $_SESSION['userId'] = $user->getUserId();
         $translator = \SmartWork\Translator::getInstance();
         $translator->setCurrentLanguage($user->getLanguageId());
         redirect('index.php?page=Index');
     } else {
         $this->template->assign('error', 'invalidLogin');
     }
 }
Esempio n. 5
0
    /**
     * Add javascripts, handle the removing of blueprints and show the blueprints list.
     *
     * @return void
     */
    public function process()
    {
        $this->getTemplate()->loadJs('addBlueprint');
        $this->getTemplate()->loadJs('jquery.materialSelect');
        $this->getTemplate()->loadJs('jquery.techniqueSelect');
        $this->getTemplate()->loadJs('jquery.blueprint');
        $this->getTemplate()->loadJs('showBlueprint');
        $this->getTemplate()->loadJsReadyScript('
			$(document).tooltip({
				content: function () {
					$(this).addClass("tooltip");
					return $(this).attr("title").replace(/(?:\\r\\n|\\r|\\n)/g, "<br />");
				}
			});
			$(".addTalentPoints").addTalentPoints();
		');
        $blueprintListing = \Listing\Blueprints::loadList();
        $itemListing = \Listing\Items::loadList();
        $itemTypeListing = \Listing\ItemTypes::loadList();
        $materialListing = \Listing\Materials::loadList();
        $techniqueListing = \Listing\Techniques::loadList();
        $moneyHelper = new \Helper\Money();
        if ($_GET['remove']) {
            $this->removeBlueprint($blueprintListing->getById($_GET['remove']));
        }
        $translator = \SmartWork\Translator::getInstance();
        $this->getTemplate()->assign('blueprintListing', $blueprintListing);
        $this->getTemplate()->assign('itemListing', $itemListing);
        $this->getTemplate()->assign('itemTypeListing', $itemTypeListing);
        $this->getTemplate()->assign('materialListing', $materialListing);
        $this->getTemplate()->assign('materialList', json_encode($materialListing->getAsArray()));
        $this->getTemplate()->assign('techniqueListing', $techniqueListing);
        $this->getTemplate()->assign('techniqueList', json_encode($techniqueListing->getAsArray()));
        $this->getTemplate()->assign('currencyList', $moneyHelper->getCurrencyList());
        $talentList = array('bowMaking' => $translator->gt('bowMaking'), 'precisionMechanics' => $translator->gt('precisionMechanics'), 'blacksmith' => $translator->gt('blacksmith'), 'woodworking' => $translator->gt('woodworking'), 'leatherworking' => $translator->gt('leatherworking'), 'tailoring' => $translator->gt('tailoring'));
        asort($talentList, SORT_NATURAL);
        $this->getTemplate()->assign('talentList', json_encode($talentList));
        $this->assign('columsPerItemType', array('meleeWeapon' => array('blueprint', 'item', 'itemType', 'damageType', 'materials', 'techniques', 'upgradeHitPoints', 'upgradeBreakFactor', 'upgradeInitiative', 'upgradeWeaponModificator'), 'rangedWeapon' => array('blueprint', 'item', 'itemType', 'damageType', 'materials', 'bonusRangedFightValue', 'reducePhysicalStrengthRequirement')));
    }
Esempio n. 6
0
 /**
  * Get the item and blueprint notes.
  *
  * @return string
  */
 protected function getNotes()
 {
     $notes = $this->item->getNotes();
     $translator = \SmartWork\Translator::getInstance();
     if ($this->bonusRangedFightValue) {
         if (!empty($notes)) {
             $notes .= ' ';
         }
         $notes .= $translator->gt('bonusRangedFightValueNote') . '(' . $this->bonusRangedFightValue . ')';
     }
     if ($this->reducePhysicalStrengthRequirement) {
         if (!empty($notes)) {
             $notes .= ' ';
         }
         $notes .= $translator->gt('reducePhysicalStrengthRequirementNote');
     }
     return $notes;
 }
Esempio n. 7
0
 /**
  * Get the notes for the item. May consist of any or all of the following:
  * - 'i' for improvisational
  * - 'z' for two handed
  * - 'p' for privileged
  *
  * @return string
  */
 public function getNotes()
 {
     $notes = '';
     $translator = \SmartWork\Translator::getInstance();
     if ($this->improvisational) {
         $notes .= $translator->gt('improvisationalNote') . ' ';
     }
     if ($this->twoHanded) {
         $notes .= $translator->gt('twoHandedNote') . ' ';
     }
     if ($this->privileged) {
         $notes .= $translator->gt('privilegedNote');
     }
     return trim($notes);
 }
Esempio n. 8
0
 /**
  * Get the talents used in this crafting. As default only unfinished parts will be returned.
  *
  * @param boolean $getAll Whether to get all talents or not, defaults to false
  *
  * @return array
  */
 public function getTalents($getAll = false)
 {
     $translator = \SmartWork\Translator::getInstance();
     $calculatedTalentPoints = $this->calculateTalentPoints();
     $talents = array();
     foreach ($this->gainedTalentPoints as $talent => $talentPoints) {
         if ($calculatedTalentPoints[$talent] <= $talentPoints && !$getAll) {
             continue;
         }
         $talents[$talent] = $translator->gt($talent);
     }
     return $talents;
 }