diff --git a/libra/LibraDatabase.php b/libra/LibraDatabase.php new file mode 100644 index 000000000..9017ebfc4 --- /dev/null +++ b/libra/LibraDatabase.php @@ -0,0 +1,60 @@ + + */ + +use LiteDatabase, + LibraDatabaseTraits; + +class LibraDatabase +{ + use LibraDatabaseTraits; + + protected $database; + + function __construct($litefile) + { + if (!$litefile) { + return false; + } + + $this->database = new LiteDatabase($litefile); + } + + /** + * Get this + * + * @return $this; + */ + public function get() + { + return $this; + } + + /** + * Get the tables from the libra database + * + * @return Array - tables + */ + public function tables() + { + $tables = $this->database->sql("SELECT name FROM sqlite_master WHERE type = 'table'"); + $tables = $this->sortDataByColumn($tables, 'name'); + return $tables; + } + + /** + * Run SQL on the libra database + * + * @param $string - the sql string to run + * @return Array - array of data + */ + public function sql($sql) + { + return $this->database->sql($sql); + } +} \ No newline at end of file diff --git a/libra/LibraDatabaseTraits.php b/libra/LibraDatabaseTraits.php new file mode 100644 index 000000000..ca3cd277f --- /dev/null +++ b/libra/LibraDatabaseTraits.php @@ -0,0 +1,50 @@ + + */ + +trait LibraDatabaseTraits +{ + /** + * Sorts an array by a column within the array, + * main use is databases results + * + * @param $data - the data to resort + * @param $column - the column to use for sorting + * @return Array - the new array! + */ + protected function sortDataByColumn($data, $column) + { + $newData = []; + foreach($data as $k => $v) + { + $newKey = $v[$column]; + $newData[$newKey] = $this->removeNumericIndexes($v); + } + + ksort($newData); + return $newData; + } + + /** + * Removes numeric indexes, for some reason sqlite + * returns both table column names and an index list, + * so this helps strip index's and reduce data duplication + * + * @param $data - the array to remove from + * @return Array - the new array, without numeric indexes! + */ + protected function removeNumericIndexes($data) + { + foreach($data as $k => $v) + if (is_numeric($k)) + unset($data[$k]); + + return $data; + } +} \ No newline at end of file diff --git a/libra/LiteDatabase.php b/libra/LiteDatabase.php new file mode 100644 index 000000000..3f4c959b4 --- /dev/null +++ b/libra/LiteDatabase.php @@ -0,0 +1,45 @@ + + */ + +use \PDO; + +class LiteDatabase +{ + protected $connection; + + function __construct($sqlite) + { + if (!file_exists($sqlite)) { + return false; + } + + // create connection + $this->connection = new PDO('sqlite:'. $sqlite); + if (!$this->connection) { + return false; + } + } + + private function track($type) + { + global $tracking; + $tracking->update($type); + } + + public function sql($sql) + { + if (!$this->connection) { + return false; + } + + $query = $this->connection->prepare($sql); + $query->execute(); + return $query->fetchAll(); + } +} \ No newline at end of file diff --git a/libra/README.md b/libra/README.md new file mode 100644 index 000000000..8c88bb5a6 --- /dev/null +++ b/libra/README.md @@ -0,0 +1,15 @@ +# FFXIV Libra +Libra is SE's official mobile application, it can be found here: http://eu.finalfantasyxiv.com/pr/special/libraeorzea/ + +# Downloading the App +The easiest way to download the app is through the android store. https://play.google.com/store/apps/details?id=com.square_enix.libra_eorzeaE + +You can Google this easily "Download APK" etc. Or you can get browser extensions to do it if you have an Android phone. + +Note that even if you download the APK when SE "update it", it may not have the latest database version, the application itself when downloaded from the store only contains the last SQLite database from when the application was fully updated. If SE update the SQLite database but not the actual applications code, then it does not get updated on the store. + +So in order to always have the most up to date SQLite file, you need a rooted android where you can view the installation of Libra and you can get the SQLite file from there. + +# Viewing the data + +You can use a tool such as SQLLiteBrowser to view the data, but it will not output the SQLite file correctly. I've included some PHP code which can be used to connect to the SQLite file and you can then do normal SQL queries on the file. \ No newline at end of file