/** * * @param string $debug */ public function __construct($debug = false) { if ($debug === true) { $this->debug = true; } $conf = OcConfig::instance(); $dsnarr = array('host' => $conf->getDbHost(), 'dbname' => $conf->getDbName(), 'charset' => 'utf8'); $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => true); /* * Older PHP versions do not support the 'charset' DSN option. * This should be removed in future */ if ($dsnarr['charset'] and version_compare(PHP_VERSION, '5.3.6', '<')) { $options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $dsnarr['charset']; } $dsnpairs = array(); foreach ($dsnarr as $k => $v) { if ($v === null) { continue; } $dsnpairs[] = $k . "=" . $v; } $dsn = 'mysql:' . implode(';', $dsnpairs); try { parent::__construct($dsn, $conf->getDbUser(), $conf->getDbPass(), $options); } catch (PDOException $e) { $message = "OcPdo object creation failed!"; $this->error($message, $e, true); //fatal error! return null; } }
/** * * @param array $params require: * 'prizedTime' => (datetime) date time when user were awarded with this medal * 'type' => medal type */ public function __construct($params) { $this->medalId = $params['medalId']; $details = \lib\Controllers\MedalsController::getMedalConfigByMedalId($this->medalId); $this->conditions = $details['conditions']; $this->name = $details['name']; $this->description = $details['description']; $this->dateIntroduced = $details['dateIntroduced']; if (isset($params['prizedTime'])) { $this->prizedTime = $params['prizedTime']; $this->level = (int) $params['level']; $this->setImage(); } $this->config = \lib\Objects\OcConfig\OcConfig::instance(); }
public static function GenerateShowMapsWhenMore() { $result = ''; foreach (OcConfig::mapsConfig() as $key => $val) { if (self::ShouldSkip($val)) { continue; } if (!isset($val['showOnlyIfMore'])) { continue; } if ($result !== '') { $result .= ",\n"; } $result .= "\t{$key}:" . ($val['showOnlyIfMore'] ? 'true' : 'false'); } return "{\n" . $result . "\n}"; }
/** * @param $username //because we always write to somebody with oc nick * @param bool $automatically //if you don't want to add 'mail_auto_generated' text into footer - set it to false */ public function addFooterAndHeader($username, $automatically = true) { $footer = new EmailFormatter(__DIR__ . "/../../tpl/stdstyle/email/ocFooter.email.html"); $header = new EmailFormatter(__DIR__ . "/../../tpl/stdstyle/email/ocHeader.email.html"); $footer->setVariable("octeamEmailsSignature", OcConfig::getOcteamEmailsSignature()); if ($automatically) { $footer->setVariable("mail_auto_generated", tr("mail_auto_generated")); } else { $footer->setVariable("mail_auto_generated", ""); } $header->setVariable("server", OcConfig::getAbsolute_server_URI()); $header->setVariable("oc_logo", OcConfig::getHeaderLogo()); $header->setVariable("sitename", OcConfig::getSiteName()); $header->setVariable("short_sitename", OcConfig::getShortSiteName()); $header->setVariable("welcome", tr("welcome")); $header->setVariable("user", $username); $this->emailContent = $header->getEmailContent() . $this->emailContent . $footer->getEmailContent(); }
private function userMedals() { /* lang test */ /* get locale from browser */ $userPrefferedLanguages = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']); $mostPrefferedLanguage = explode(',', $userPrefferedLanguages[0]); $locale = str_replace('-', '_', $mostPrefferedLanguage[0]); if (isset($_REQUEST['locale'])) { /* get locale from $_REQUEST*/ $locale = $_REQUEST['locale']; } $putenv = putenv("LANG={$locale}"); $setlocale = setlocale(LC_ALL, $locale); // d($locale, $putenv, $setlocale); bindtextdomain("medals", __DIR__ . '/../languages'); bind_textdomain_codeset('medals', 'UTF-8'); textdomain("medals"); // print gettext('level'); // print '<BR>'; /* end lang test*/ $ocConfig = \lib\Objects\OcConfig\OcConfig::instance(); $smarty = new \Smarty(); $smarty->setCompileDir($ocConfig->getDynamicFilesPath() . 'tmp/templates_c'); $smarty->debugging = false; $smarty->caching = false; $smarty->setTemplateDir(__DIR__ . '/../../tpl/smarty'); $smarty->setCacheDir($ocConfig->getDynamicFilesPath() . 'tmp/smarty_cache'); $user = new \lib\Objects\User\User(array('userId' => $this->request['userId'])); $user->loadMedalsFromDb(); // d($user, $user->getMedals()); /* @var $medal \lib\Objects\Medals\Medal */ foreach ($user->getMedals() as $medal) { $medal->checkConditionsForUser($user); $smartyMedals['medals'][] = array('imgSrc' => $medal->getImage(), 'name' => $medal->getName(), 'profile' => $medal->getMedalProfile(), 'level' => $medal->getLevel(), 'levelName' => $medal->getLevelName(), 'currentLevelInfo' => $medal->getLevelInfo(), 'nextLevelInfo' => $medal->getLevelInfo($medal->getLevel() + 1)); } $smartyMedals['tr'] = array('level' => _('level'), 'user' => _('user'), 'medals' => _('medals'), 'nextLevelRequirements' => _('Next level Requirements'), 'currentLevelRequirements' => _('Level achievements'), 'medalInfo' => _('Medal Profile'), 'cacheTypes' => _('Geocache types')); $smarty->assign('geocacheIcons', \cache::getCacheIconsSet()); $smarty->assign('user', $user->getUserInformation()); $smarty->assign("smartyMedals", $smartyMedals); $smarty->assign("bgImage", $this->shuffleBackgroundImage()); $smarty->display('medals.tpl'); }
public function removeLog(GeoCacheLog $log, $request = null) { $result = false; if ($log === false) { $this->errors[] = 'No such log'; return false; } if ($log->getNode() != OcConfig::instance()->getOcNodeId()) { $this->errors[] = 'Wrong Node'; return false; } $loggedUser = \lib\Objects\ApplicationContainer::Instance()->getLoggedUser(); if ($loggedUser === false) { $this->errors[] = 'User is not looged-in'; return false; } if ($log->getUser()->getUserId() === $loggedUser->getUserId() || $log->getGeoCache()->getOwner()->getUserId() == $loggedUser->getUserId() || $loggedUser->getIsAdmin()) { if ($log->getUser()->getUserId() !== $loggedUser->getUserId()) { EmailSender::sendRemoveLogNotification(__DIR__ . '/../../tpl/stdstyle/email/removed_log.email.html', $log, $loggedUser); } $updateQuery = "UPDATE `cache_logs` SET deleted = 1, `del_by_user_id` = :1 , `last_modified`=NOW(), `last_deleted`=NOW() WHERE `cache_logs`.`id`=:2 LIMIT 1"; $db = OcDb::instance(); $db->multiVariableQuery($updateQuery, $loggedUser->getUserId(), $log->getId()); $log->getUser()->recalculateAndUpdateStats(); if ($log->getType() == GeoCacheLog::LOGTYPE_MOVED) { $this->handleMobileGeocachesAfterLogDelete($log); } if ($log->getType() == GeoCacheLog::LOGTYPE_FOUNDIT || $log->getType() == GeoCacheLog::LOGTYPE_ATTENDED) { $this->cacheScoreHandlingAfterRemoveLog($log); } //call eventhandler require_once __DIR__ . '/../eventhandler.inc.php'; event_remove_log($log->getGeoCache()->getCacheId(), $loggedUser->getUserId()); $this->updateGeocacheAfterLogRemove($log, $db); $result = true; } else { $this->errors[] = 'User has no privileages to delete this log'; } return $result; }
function buildGeocacheHtml(lib\Objects\GeoCache\GeoCache $geocache, $html) { $ocConfig = \lib\Objects\OcConfig\OcConfig::instance(); $html = mb_ereg_replace('{cacheimage}', '<img src="' . $geocache->getCacheIcon() . '" width="16" />', $html); $html = mb_ereg_replace('{cachestatus}', htmlspecialchars(tr($geocache->getStatusTranslationIdentifier()), ENT_COMPAT, 'UTF-8'), $html); $html = mb_ereg_replace('{cacheid}', htmlspecialchars(urlencode($geocache->getCacheId()), ENT_COMPAT, 'UTF-8'), $html); if ($geocache->getDateActivate() === null) { $html = mb_ereg_replace('{date}', tr('no_time_indicated'), $html); } else { $html = mb_ereg_replace('{date}', $geocache->getDateActivate()->format($ocConfig->getDateFormat()), $html); } $html = mb_ereg_replace('{cachename}', htmlspecialchars($geocache->getCacheName(), ENT_COMPAT, 'UTF-8'), $html); $html = mb_ereg_replace('{wpname}', htmlspecialchars($geocache->getWaypointId(), ENT_COMPAT, 'UTF-8'), $html); return $html; }
public function __construct() { $this->config = \lib\Objects\OcConfig\OcConfig::Instance(); }
public static function sendRemoveLogNotification($emailTemplateFile, GeoCacheLog $log, User $loggedUser) { $formattedMessage = new EmailFormatter($emailTemplateFile); $formattedMessage->setVariable("log_owner", $log->getUser()->getUserName()); $formattedMessage->setVariable("waypointId", $log->getGeoCache()->getWaypointId()); $formattedMessage->setVariable("serviceUrl", OcConfig::getAbsolute_server_URI()); $formattedMessage->setVariable("logRemover", $loggedUser->getUserName()); $formattedMessage->setVariable("logRemoverId", $loggedUser->getUserId()); $formattedMessage->setVariable("cache_name", $log->getGeoCache()->getCacheName()); $formattedMessage->setVariable("log_entry", $log->getText()); $formattedMessage->setVariable("removedLog_01", tr('removedLog_01')); $formattedMessage->setVariable("removedLog_02", tr('removedLog_02')); $formattedMessage->addFooterAndHeader($log->getUser()->getUserName()); $email = new Email(); $email->addToAddr($log->getUser()->getEmail()); $email->setReplyToAddr(OcConfig::getNoreplyEmailAddress()); $email->setFromAddr(OcConfig::getNoreplyEmailAddress()); $email->setSubject(tr('removed_log_title')); $email->setBody($formattedMessage->getEmailContent(), true); $email->send(); }
/** * Call OKAPI, parse response and display the results * @param array $params - params of the cache to search and display */ private function htmlFormat(array $params) { $ocConfig = \lib\Objects\OcConfig\OcConfig::instance(); //call OKAPI $okapi_resp = \okapi\Facade::service_call('services/caches/shortcuts/search_and_retrieve', $this->user_id, $params); if (!is_a($okapi_resp, "ArrayObject")) { // strange OKAPI return !? error_log(__METHOD__ . ": ERROR: strange OKAPI response - not an ArrayObject"); exit(0); } \okapi\OkapiErrorHandler::disable(); if ($okapi_resp->count() == 0) { // no caches found exit(0); } // get the first object from the list $arrayCopy = $okapi_resp->getArrayCopy(); $geoCache = new \lib\Objects\GeoCache\GeoCache(array('okapiRow' => array_pop($arrayCopy))); //generate the results if ($this->screenWidth < 400) { tpl_set_tplname('map/map_cacheinfo_small'); } else { tpl_set_tplname('map/map_cacheinfo'); } tpl_set_var('cache_lat', $geoCache->getCoordinates()->getLatitude()); tpl_set_var('cache_lon', $geoCache->getCoordinates()->getLongitude()); tpl_set_var('cache_name', $geoCache->getCacheName()); tpl_set_var('cache_icon', $geoCache->getCacheIcon()); $is_event = $geoCache->getCacheType() == $geoCache::TYPE_EVENT ? '1' : '0'; // be aware: booleans not working here tpl_set_var('is_event', $is_event, false); $is_scored = $geoCache->getRatingId() != 0 && $geoCache->getRatingVotes() > 2 ? '1' : '0'; tpl_set_var('is_scored', $is_scored, false); tpl_set_var('rating_desc', tr($geoCache->getRatingDesc())); $is_recommended = $geoCache->getRecommendations() > 0 ? '1' : '0'; tpl_set_var('is_recommended', $is_recommended, false); tpl_set_var('cache_recommendations', $geoCache->getRecommendations(), false); tpl_set_var('cache_code', $geoCache->getWaypointId()); tpl_set_var('cache_founds', $geoCache->getFounds()); tpl_set_var('cache_not_founds', $geoCache->getNotFounds()); tpl_set_var('cache_rating_votes', $geoCache->getRatingVotes()); tpl_set_var('cache_willattends', $geoCache->getWillattends()); tpl_set_var('cache_url', $geoCache->getCacheUrl()); tpl_set_var('user_name', $geoCache->getOwner()->getUserName()); tpl_set_var('user_profile', $geoCache->getOwner()->getProfileUrl()); tpl_set_var('start_date', $geoCache->getDatePlaced()->format($ocConfig->getDateFormat())); tpl_set_var('cache_size_desc', tr($geoCache->getSizeDesc())); $is_powertrail_part = $geoCache->isPowerTrailPart() ? '1' : '0'; tpl_set_var('is_powertrail_part', $is_powertrail_part, false); if ($geoCache->isPowerTrailPart()) { tpl_set_var('pt_name', $geoCache->getPowerTrail()->getName()); tpl_set_var('pt_image', $geoCache->getPowerTrail()->getImage()); tpl_set_var('pt_icon', $geoCache->getPowerTrail()->getFootIcon()); tpl_set_var('pt_url', $geoCache->getPowerTrail()->getPowerTrailUrl()); } $is_titled = $geoCache->isTitled() ? 'true' : 'false'; tpl_set_var('is_titled', $is_titled, false); //tpl_set_var('is_titled', $geoCache->isTitled(), false); // make the template and send it out tpl_BuildTemplate(false, false, true); }
private function __construct() { $this->ocConfig = OcConfig::instance(); $this->db = OcDb::instance(); }
/** * Function to check if current cache is part of any PowerTrail. * On success PowerTrail object is created. * * @return boolean true if this cache belongs to any PowerTrail; */ public function isPowerTrailPart() { if (!OcConfig::instance()->getPowerTrailModuleSwitchOn()) { return false; } if (is_null($this->isPowerTrailPart)) { $ptArr = PowerTrail::CheckForPowerTrailByCache($this->id); if (count($ptArr) > 0) { // TODO: ASSUMPTION: cache belongs to ONLY one PT $this->isPowerTrailPart = true; $this->powerTrail = new PowerTrail(array('dbRow' => $ptArr[0])); } else { $this->isPowerTrailPart = false; } } return $this->isPowerTrailPart; }
/** * powerTrail.php * ------------------------------------------------------------------------------------------------ * Power Trails in opencaching * this is display file. for API check dir powerTrail * ------------------------------------------------------------------------------------------------ * @author: Andrzej 'Łza' Woźniak [wloczynutka[on]gmail.com] * * * */ // variables required by opencaching.pl global $lang, $rootpath, $usr, $absolute_server_URI, $cookie; //prepare the templates and include all neccessary require_once 'lib/common.inc.php'; $ocConfig = \lib\Objects\OcConfig\OcConfig::instance(); $appContainer = lib\Objects\ApplicationContainer::Instance(); require_once 'lib/cache.php'; require_once __DIR__ . '/lib/cachemap3lib.inc.php'; $_SESSION['powerTrail']['userFounds'] = $usr['userFounds']; if ($ocConfig->getPowerTrailModuleSwitchOn() === false) { header("location: {$absolute_server_URI}"); } $firePtMenu = true; //Preprocessing if ($error == false) { if (isset($_REQUEST['sortBy']) || isset($_REQUEST['filter']) || isset($_REQUEST['sortDir'])) { saveCookie($cookie); } else { if ($cookie->is_set("ptSrBy")) { $_REQUEST['sortBy'] = $cookie->get("ptSrBy");
$desclangs = mb_split(',', $geocache->getDescLanguagesList()); // use cache desc in lang of interface by default $desclang = mb_strtoupper($lang); // check if there is a desc in current lang if (array_search($desclang, $desclangs) === false) { $desclang = $desclangs[0]; $enable_google_translation = true; //no desc in current lang - enable translation } // check if user requests other lang of cache desc... if (isset($_REQUEST['desclang']) && array_search($_REQUEST['desclang'], $desclangs)) { $desclang = $_REQUEST['desclang']; $enable_google_translation = false; //user wants this lang - disable translations } if (!OcConfig::instance()->isGoogleTranslationEnabled()) { $enable_google_translation = false; //TODO: Translation is not available - needs implementation... } //build langs list $langlist = ''; foreach ($desclangs as $desclanguage) { if ($langlist != '') { $langlist .= ', '; } $langlist .= '<a href="viewcache.php?cacheid=' . urlencode($cache_id) . '&desclang=' . urlencode($desclanguage) . $linkargs . '">'; if ($desclanguage == $desclang) { $langlist .= '<i>' . htmlspecialchars($desclanguage, ENT_COMPAT, 'UTF-8') . '</i>'; } else { $langlist .= htmlspecialchars($desclanguage, ENT_COMPAT, 'UTF-8'); }