├── .gitignore ├── README ├── gtfs └── ADD GTFS FILES HERE ├── index.php ├── source ├── css │ └── main.css ├── gfx │ ├── false.png │ └── true.png ├── pages │ ├── checkForm.php │ ├── createTables.php │ ├── fillTables.php │ └── makeconfig.php └── sql │ ├── createSQL.php │ └── makeTables.php └── sql-connect.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | PHP GTFS MySQL IMPORT WITH GUI 2 | Author: Steffen Martinsen (steffen@steffenmedia.no - @kverdagshelt) 3 | 4 | This is a PHP "app" that reads files from a provided GTFS feed and puts the data into a MySQL table via a GUI (Graphical User Interface) that totally looks like the Wordpress setup (and should be just as easy to operate). 5 | This was originally written to fetch GTFS data for Kolumbus (www.kolumbus.no) GTFS feed, and might require some modification to work properly with other GTFS sets although it should detect most of it. 6 | 7 | USAGE: 8 | 1. Download/clone 9 | 2. Unzip GTFS zip and add all .txt files into the "gtfs" folder at the root of this repo. 10 | 3. Upload it, or run it locally with PHP and follow the on-screen guide. 11 | 12 | 13 | FILES (And stuff they do): 14 | 15 | - index.php 16 | contains some HTML and links to CSS to make the GUI looks slick and smooth. It also performs a check to see if the config file is created. If not, it includes a script that will help you create one. 17 | 18 | - sql-connect.php 19 | connects to your mysql database provided in the config file. If the config file does not exist, launch index.php to create it. 20 | 21 | - gtfs/ 22 | the gtfs folder contains the raw gtfs .txt files. by default it contains an empty file called ADD GTFS FILES HERE which is what one would except. Add the .txt files here! 23 | 24 | - source/gfx/ 25 | doesn't contain anything really. I thought i should provide some graphics but it wasn't necessary really :) 26 | 27 | - source/css/ 28 | contains one stylesheet to provide a somewhat simple graphical user interface. 29 | 30 | - source/pages/makeconfig.php 31 | is the file index php includes if no config file is provided. basically it helps you create a config file. 32 | 33 | - source/pages/checkForm.php 34 | checks if the provided data to the config file is correct. this only applies if you created the config file through makeconfig.php 35 | 36 | - source/pages/createTables.php 37 | displays a list to the user with the tables that are being created. 38 | 39 | - source/pages/fillTables.php 40 | displays a list of default gtfs files, and which of those is found. files that is found appears in green, while files thats missing appears in red. missing files are ignored while importing to mysql table. 41 | 42 | -source/sql/makeTables.php 43 | creates the sql skeleton of tables automatically to the desired/provided database. 44 | 45 | -source/sql/createSQL.php 46 | reads the files in the gtfs folder, and puts them into the mysql database. this might take some time. default allocated memory is 512M and it shouldn't timeout. might screw things up if you have large files and running php in safe_mode. 47 | 48 | // Steffen Martinsen Tuesday 07.02.2012 -------------------------------------------------------------------------------- /gtfs/ADD GTFS FILES HERE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steffenz/php-gtfs-mysql/7b489443de7ff3901b161bce3418aa5bff08db88/gtfs/ADD GTFS FILES HERE -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Install - php-gtfs-mysql 6 | 7 | 8 |


9 |

10 | 19 | 20 |
21 | 22 | -------------------------------------------------------------------------------- /source/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #f9f9f9; 3 | margin:0; 4 | padding:0; 5 | font-family: Helvetica; 6 | } 7 | 8 | #kontainer { 9 | width:700px; 10 | margin:0 auto; 11 | background: #fff; 12 | border:1px solid #f4f4f4; 13 | } 14 | 15 | h1 { 16 | font-size:22px; 17 | } 18 | 19 | p { 20 | font-size:12px; 21 | padding-left:30px; 22 | padding-right:30px; 23 | padding-top:5px; 24 | padding-bottom:20px; 25 | } 26 | 27 | #kontainer input { 28 | width:200px; 29 | border:1px solid #f3f3f3; 30 | text-align: center; 31 | padding:5px; 32 | outline:none; 33 | } 34 | 35 | #mysqlnfo { 36 | font-size: 12px; 37 | margin-left:100px; 38 | } 39 | 40 | 41 | /* wpstyle buttons http://blog.sachinkraj.com/how-to-design-buttons-like-wordpress/ */ 42 | .button { 43 | display: inline-block; 44 | outline: none; 45 | cursor: pointer; 46 | text-align: center; 47 | text-decoration: none; 48 | font: 12px/100% Arial, Helvetica, sans-serif; 49 | padding: .4em 1.2em .4em; 50 | text-shadow: 0 1px 1px rgba(255,255,255,.5); 51 | -webkit-border-radius: 1.4em; 52 | -moz-border-radius: 1.4em; 53 | border-radius: 1.4em; 54 | 55 | color:#222222; 56 | border: solid 1px #dddddd; 57 | background: #eeeeee; 58 | background: -webkit-gradient(linear, left top, left bottombottom, from(#ffffff), to(#cccccc)); 59 | background: -moz-linear-gradient(top, #cccccc, #ffffff); 60 | 61 | } 62 | 63 | .button:hover { 64 | text-decoration: none; 65 | color:#111111; 66 | border: solid 1px #aaaaaa; 67 | } 68 | 69 | .button:active { 70 | color:#222222; 71 | border: solid 1px #aaaaaa; 72 | background: #eeeeee; 73 | background: -webkit-gradient(linear, left top, left bottombottom, from(#ccccccc), to(#ffffff)); 74 | background: -moz-linear-gradient(top, #ffffff, #cccccc); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /source/gfx/false.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steffenz/php-gtfs-mysql/7b489443de7ff3901b161bce3418aa5bff08db88/source/gfx/false.png -------------------------------------------------------------------------------- /source/gfx/true.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steffenz/php-gtfs-mysql/7b489443de7ff3901b161bce3418aa5bff08db88/source/gfx/true.png -------------------------------------------------------------------------------- /source/pages/checkForm.php: -------------------------------------------------------------------------------- 1 | '; 27 | fwrite($fh, $stringData); 28 | header("Location: ../../index.php"); 29 | } 30 | 31 | ?> -------------------------------------------------------------------------------- /source/pages/createTables.php: -------------------------------------------------------------------------------- 1 | 9 |

Lets create the tables.

10 | 11 |

Everything seems to be going our way. Now we need to create the table skeleton for our MySQL schema/tables Hit the "Create tables" button to continue.

12 |
13 | 14 | 26 | Create MySQL tables.. 27 | 28 | 29 | -------------------------------------------------------------------------------- /source/pages/fillTables.php: -------------------------------------------------------------------------------- 1 |

All set! Lets fill in your data!

2 | 3 |

All the SQL tables have been created in your database. Now we need to fill them with your provided GTFS data. This might take some time to execute.

Here is a list of files in your GTFS folder. Green labels means that the file is found, and red means its not

4 | Warning: Some files may not exist because they isn't required/implemented. If you are absolutely sure that this is the package as you've downloaded it, you can safely ignore the red files. I'll figure out whats missing, and won't waste any of your time with it.

5 | 6 | 7 | Warning: PHP is in safe mode! The script might exhaust the PHP memory, or time out during query. Please switch off safe mode, or manually adjust the timeout and max memory usage in php.ini

"; 14 | } 15 | ?> 16 | 17 | 117 | Add data to MySQL.. 118 | 119 | 120 | -------------------------------------------------------------------------------- /source/pages/makeconfig.php: -------------------------------------------------------------------------------- 1 | 7 | 8 |

Create a new configuration file.

9 | 10 |

What this is: In order for this script to work I need to have some information about your MySQL database to store in a config.php file. This file will be created automatically, so no worries. Also, I kind of need to modify your PHP settings, but we will deal with that later. 11 |
15 | Error: Connection to MySQL could not be established. Are you sure you entered them correctly? 16 | "; 17 | } 18 | 19 | if($_GET['error'] == "nodbname") { 20 | echo " 21 |

22 | Error: Please provide a name for the database. If it does not exists, it will be created. 23 | "; 24 | } 25 | ?> 26 |

27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
Database name:Either a new or an existing DB.
Username:Your MySQL username.
Password:Your MySQL password.
Host:Typically localhost.
56 | Check settings and continue 57 |
58 | -------------------------------------------------------------------------------- /source/sql/createSQL.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /source/sql/makeTables.php: -------------------------------------------------------------------------------- 1 | 125 | 126 | -------------------------------------------------------------------------------- /sql-connect.php: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------