/** * Get training object * @param int $index optional * @return \TrainingObject */ public final function object($index = 0) { if ($index > 0) { \Runalyze\Error::getInstance()->addDebug('ParserAbstractSingle has only one training, asked for index = ' . $index); } return $this->TrainingObject; }
/** * Can the strategy handle the data? * * To test this, we try to fetch a gtopo30-value. * This costs only 0.1 credit per call. * * We assume that Geonames will find elevation data for all points. * * @see http://www.geonames.org/export/webservice-exception.html */ public function canHandleData() { $url = 'http://api.geonames.org/gtopo30JSON?lat=47.01&lng=10.2&username='******'gtopo30'])) { return true; } if (isset($response['status']) && isset($response['status']['value'])) { switch ((int) $response['status']['value']) { case 10: \Runalyze\Error::getInstance()->addWarning('Geonames user account is not valid.'); break; case 18: \Runalyze\Error::getInstance()->addDebug('Geonames-request failed: daily limit of credits exceeded'); break; case 19: \Runalyze\Error::getInstance()->addDebug('Geonames-request failed: hourly limit of credits exceeded'); break; case 20: \Runalyze\Error::getInstance()->addDebug('Geonames-request failed: weekly limit of credits exceeded'); break; default: if (isset($response['status']['message'])) { \Runalyze\Error::getInstance()->addDebug('Geonames response: ' . $response['status']['message']); } } } return false; }
/** * Get training object * @param int $index optional index * @return TrainingObject */ public final function object($index = 0) { if (!isset($this->TrainingObjects[$index])) { Error::getInstance()->addDebug('Parser has only ' . $this->numberOfTrainings() . ' trainings, but asked for index = ' . $index); return end($this->TrainingObjects); } return $this->TrainingObjects[$index]; }
/** * Initialize this plugin * @see PluginPanel::initPlugin() */ protected function initPlugin() { $this->fileNameStart = SessionAccountHandler::getId() . '-runalyze-backup'; if (isset($_GET['json'])) { if (move_uploaded_file($_FILES['qqfile']['tmp_name'], realpath('') . '/../data/DbBackup/import/' . $_FILES['qqfile']['name'])) { Error::getInstance()->footer_sent = true; echo '{"success":true}'; } else { echo '{"error":"Moving file did not work. Set chmod 777 for /data/DbBackup/import/"}'; } exit; } }
/** * Send an email via smtp * @param string $to * @param string $subject * @param string $message * @return boolean */ public static function sendMail($to, $subject, $message) { $sender = MAIL_SENDER == '' ? '*****@*****.**' : MAIL_SENDER; try { $message = Swift_Message::newInstance()->setSubject($subject)->setBody($message, 'text/html')->setFrom(array($sender => MAIL_NAME))->setTo($to); $transport = Swift_SmtpTransport::newInstance(SMTP_HOST, SMTP_PORT, SMTP_SECURITY)->setUsername(SMTP_USERNAME)->setPassword(SMTP_PASSWORD); $mailer = Swift_Mailer::newInstance($transport); return $mailer->send($message); } catch (Exception $e) { Error::getInstance()->addError('Mail could not be sent: ' . $e->getMessage()); return false; } }
/** * Can the strategy handle the data? * * We assume that GoogleMaps will find elevation data for all points. * * @see https://developers.google.com/maps/documentation/elevation/?hl=de&csw=1 */ public function canHandleData() { $url = 'http://maps.googleapis.com/maps/api/elevation/json?locations=49.4,7.7&sensor=false'; $response = json_decode(\Filesystem::getExternUrlContent($url), true); if (is_null($response)) { return false; } if (is_array($response) && isset($response['results'])) { return true; } if (isset($response['status'])) { \Runalyze\Error::getInstance()->addDebug('GoogleMaps response: ' . $response['status']); } return false; }
/** * Load file */ protected function loadFile() { if (!file_exists($this->schemeFile)) { Error::getInstance()->addError('Cannot find database scheme: ' . $this->schemeFile); return; } else { include $this->schemeFile; if (!isset($TABLENAME) || !isset($FIELDS) || !isset($FIELDSETS)) { Error::getInstance()->addError('$TABLENAME, $FIELDS and $FIELDSETS must be defined in scheme file: ' . $this->schemeFile); } else { $this->tableName = PREFIX . $TABLENAME; $this->fields = array_merge($this->fields, $FIELDS); $this->fieldsets = array_merge($this->fieldsets, $FIELDSETS); $this->hiddenKeys = array_merge($this->hiddenKeys, $HIDDEN_KEYS); } } }
/** * Get training objects * @param int $index optional index * @return TrainingObject training object */ public final function object($index = 0) { if (is_null($this->Parser)) { Error::getInstance()->addError('Parser of Importer is empty. Returned default TrainingObject.'); return new TrainingObject(DataObject::$DEFAULT_ID); } return $this->Parser->object($index); }
/** * Own function to handle the errors using class::Error. * @param string $type type of error (E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE) * @param string $message error message * @param string $file filename * @param int $line line number * @return bool returning true to not execute PHP internal error handler */ function error_handler($type, $message, $file, $line) { switch ($type) { case E_ERROR: $type = 'ERROR'; break; case E_WARNING: $type = 'WARNING'; break; case E_NOTICE: $type = 'NOTICE'; break; default: $type = 'Unknown error type'; break; } Error::getInstance()->add($type, $message, $file, $line); return true; }
/** * Parse one trackpoint * @param SimpleXMLElement $TP */ protected function parseTrackpoint(&$TP) { if ($this->distancesAreEmpty) { $TP->addChild('DistanceMeters', 1000 * $this->distanceToTrackpoint($TP)); } //else if ((float)$TP->DistanceMeters < $this->gps['km']) // $TP->DistanceMeters = 1000*$this->distanceToTrackpoint($TP); $ThisBreakInMeter = (double) $TP->DistanceMeters - $this->lastDistance; $ThisBreakInSeconds = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - end($this->gps['time_in_s']) - $this->PauseInSeconds; if (Configuration::ActivityForm()->detectPauses()) { $NoMove = $this->lastDistance == (double) $TP->DistanceMeters && !$this->isWithoutDistance; $TooSlow = !$this->lastPointWasEmpty && $ThisBreakInMeter > 0 && $ThisBreakInSeconds / $ThisBreakInMeter > 6; } else { $NoMove = $TooSlow = false; } if (empty($TP->DistanceMeters) && !$this->isWithoutDistance || $NoMove || $TooSlow) { $Ignored = false; if (count($TP->children()) == 1 || $NoMove || $TooSlow) { if ($NoMove && $ThisBreakInSeconds <= self::$IGNORE_NO_MOVE_UNTIL) { $Ignored = true; } else { $this->PauseInSeconds += $ThisBreakInSeconds; $this->wasPause = true; $this->pauseDuration += $ThisBreakInSeconds; } if (self::$DEBUG_SPLITS) { Error::getInstance()->addDebug('PAUSE at ' . (string) $TP->Time . ' of ' . $ThisBreakInSeconds . ', empty point: ' . ($NoMove ? 'no move' . ($Ignored ? ' ignored' : '') : 'empty trackpoint') . ($TooSlow ? ' (too slow, ' . $ThisBreakInMeter . 'm in ' . $ThisBreakInSeconds . 's)' : '')); } } if (!$Ignored) { return; } } if (empty($TP->DistanceMeters) && !empty($this->gps['km'])) { $TP->DistanceMeters = end($this->gps['km']) * 1000; } if ($this->TrainingObject->getTimestamp() == 0) { $this->TrainingObject->setTimestamp(strtotime((string) $TP->Time)); } if ($this->lastPointWasEmpty) { $OldPauseInSeconds = $this->PauseInSeconds; $this->PauseInSeconds = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - end($this->gps['time_in_s']); $this->pauseDuration += $this->PauseInSeconds - $OldPauseInSeconds; $this->wasPause = true; if (self::$DEBUG_SPLITS) { Error::getInstance()->addDebug('PAUSE at ' . (string) $TP->Time . ' of ' . ($this->PauseInSeconds - $OldPauseInSeconds) . ', last point was empty'); } } if ($this->wasPause) { $this->TrainingObject->Pauses()->add(new \Runalyze\Model\Trackdata\Pause(end($this->gps['time_in_s']), $this->pauseDuration, end($this->gps['heartrate']), !empty($TP->HeartRateBpm) ? round($TP->HeartRateBpm->Value) : 0)); $this->wasPause = false; $this->pauseDuration = 0; } $this->lastPointWasEmpty = false; $this->lastPoint = (int) $TP->DistanceMeters; $this->lastDistance = (double) $TP->DistanceMeters; $this->gps['time_in_s'][] = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - $this->PauseInSeconds; $this->gps['km'][] = round((double) $TP->DistanceMeters / 1000, ParserAbstract::DISTANCE_PRECISION); $this->gps['altitude'][] = (int) $TP->AltitudeMeters; $this->gps['heartrate'][] = !empty($TP->HeartRateBpm) ? round($TP->HeartRateBpm->Value) : 0; if (!empty($TP->Position)) { $this->gps['latitude'][] = (double) $TP->Position->LatitudeDegrees; $this->gps['longitude'][] = (double) $TP->Position->LongitudeDegrees; } elseif (!empty($this->gps['latitude'])) { $this->gps['latitude'][] = end($this->gps['latitude']); $this->gps['longitude'][] = end($this->gps['longitude']); } else { $this->gps['latitude'][] = 0; $this->gps['longitude'][] = 0; } $this->parseExtensionValues($TP); }
/** * Write a file * @param string $fileName relative to FRONTEND_PATH * @param string $fileContent */ public static function writeFile($fileName, $fileContent) { $file = fopen(FRONTEND_PATH . $fileName, "w"); if ($file !== false) { fwrite($file, $fileContent); fclose($file); } else { \Runalyze\Error::getInstance()->addError('Die Datei "' . $fileName . '" konnte zum Schreiben nicht erstellt/geöffnet werden.'); } }
/** * Update database */ protected function updateDatabase() { $columns = array_keys($this->data); $values = array_values($this->data); DB::getInstance()->update($this->tableName(), $this->id, $columns, $values); if (self::$DEBUG_QUERIES) { Error::getInstance()->addDebug('Updated #' . $this->id . ' ' . $this->tableName() . ': ' . print_r($this->data, true)); } }
<div class="panel clear"> <div class="panel-heading"><h1><?php _e('Debug console'); ?> </h1></div> <div class="panel-content"><?php echo \Runalyze\Error::getInstance()->display(); ?> </div> </div>
/** * Install this plugin * @return bool */ public final function install() { if ($this->id() != PluginInstaller::ID) { Error::getInstance()->addError('Plugin can not be installed, id is set wrong.'); return false; } $this->id = DB::getInstance()->insert('plugin', array('key', 'type', 'active', 'order'), array($this->key(), $this->typeString(), '1', '99')); return true; }
/** * Throw error for unknown extension * @param string $filename * @param string $extension */ private function throwUnknownExtension($filename, $extension) { Error::getInstance()->addError('Can\'t import ' . $filename . ', there is no importer for *.' . $extension); }
/** * Get timestamp of first training * @return int Timestamp */ private static function calculateStartTime() { $data = DB::getInstance()->query('SELECT MIN(`time`) as `time` FROM `' . PREFIX . 'training` WHERE accountid = ' . SessionAccountHandler::getId())->fetch(); if (isset($data['time']) && $data['time'] == 0) { $data = DB::getInstance()->query('SELECT MIN(`time`) as `time` FROM `' . PREFIX . 'training` WHERE `time` != 0 AND accountid = ' . SessionAccountHandler::getId())->fetch(); Error::getInstance()->addWarning('Du hast ein Training ohne Zeitstempel, also mit dem Datum 01.01.1970.'); } if ($data === false || $data['time'] == null) { return 0; } return $data['time']; }
/** * Display the HTML-Footer */ public function displayFooter() { if (RUNALYZE_DEBUG && Error::getInstance()->hasErrors()) { Error::getInstance()->display(); } if (!Request::isAjax() && !isset($_GET['hideHtmlHeader'])) { include 'tpl/tpl.Frontend.footer.php'; } Error::getInstance()->footer_sent = true; }
/** * Set some special configuration values * @param int $accountId */ private static function setSpecialConfigValuesFor($accountId) { if (is_null($accountId) || $accountId < 0) { Error::getInstance()->addError('AccountID for special config-values not set.'); return; } $DB = DB::getInstance(); $columns = array('category', 'key', 'value', 'accountid'); $DB->exec('UPDATE `' . PREFIX . 'type` SET `sportid`="' . self::$SPECIAL_KEYS['RUNNING_SPORT_ID'] . '" WHERE `accountid`="' . $accountId . '"'); $DB->insert('conf', $columns, array('general', 'MAINSPORT', self::$SPECIAL_KEYS['MAIN_SPORT_ID'], $accountId)); $DB->insert('conf', $columns, array('general', 'RUNNINGSPORT', self::$SPECIAL_KEYS['RUNNING_SPORT_ID'], $accountId)); $DB->insert('conf', $columns, array('general', 'TYPE_ID_RACE', self::$SPECIAL_KEYS['TYPE_ID_RACE'], $accountId)); //Connect equipment type and sport $DB->insert('equipment_sport', array('sportid', 'equipment_typeid'), array(self::$SPECIAL_KEYS['RUNNING_SPORT_ID'], self::$SPECIAL_KEYS['EQUIPMENT_SHOES_ID'])); $DB->insert('equipment_sport', array('sportid', 'equipment_typeid'), array(self::$SPECIAL_KEYS['RUNNING_SPORT_ID'], self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'])); // Use shoes as main equipment for running $DB->exec('UPDATE `' . PREFIX . 'sport` SET `main_equipmenttypeid`="' . self::$SPECIAL_KEYS['EQUIPMENT_SHOES_ID'] . '" WHERE `id`="' . self::$SPECIAL_KEYS['RUNNING_SPORT_ID'] . '"'); // Add standard clothes equipment $eqColumns = array('name', 'notes', 'typeid', 'accountid'); $DB->insert('equipment', $eqColumns, array(__('long sleeve'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); $DB->insert('equipment', $eqColumns, array(__('T-shirt'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); $DB->insert('equipment', $eqColumns, array(__('singlet'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); $DB->insert('equipment', $eqColumns, array(__('jacket'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); $DB->insert('equipment', $eqColumns, array(__('long pants'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); $DB->insert('equipment', $eqColumns, array(__('shorts'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); $DB->insert('equipment', $eqColumns, array(__('gloves'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); $DB->insert('equipment', $eqColumns, array(__('hat'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId)); }
/** * Check for JSON-return * @return boolean */ private function returnJSON() { $Uploader = new ImporterUpload(); if ($Uploader->thereWasAFile()) { echo $Uploader->getResponse(); Error::getInstance()->debug_displayed = true; return true; } return false; }
/** * End benchmark * * This will produce a debug message with execution time. */ public static function end() { if (!is_null(self::$StartTime)) { Error::getInstance()->addDebug('Benchmark time: ' . (microtime(true) - self::$StartTime)); } }