readme.md 3.68 KB
Newer Older
hxgf's avatar
hxgf committed
1
![headphones icon](https://stereotk.com/images/stereo-headphones-black-small.png)
hxgf's avatar
hxgf committed
2

hxgf's avatar
hxgf committed
3 4
# STEREO Internet Tool Kit
### v1.3.0
hxgf's avatar
hxgf committed
5

hxgf's avatar
hxgf committed
6
---
hxgf's avatar
hxgf committed
7

hxgf's avatar
v1 rc2  
hxgf committed
8

hxgf's avatar
hxgf committed
9
## FEATURES
hxgf's avatar
hxgf committed
10 11
- Easy and flexible routing system with pretty urls 😍
- Powerful [Handlebars](http://handlebarsjs.com/) templates
hxgf's avatar
v1 rc2  
hxgf committed
12
- Convenient MYSQL CRUD functionality
hxgf's avatar
hxgf committed
13 14 15
- Helpful utility functions *(for working with cookies, http requests, email, etc)*
- Sensible *(and minimal)* front-end boilerplate ✨
- Straightforward application structure
hxgf's avatar
v1 rc2  
hxgf committed
16 17 18 19 20
- Works with most shared web hosting providers  




hxgf's avatar
hxgf committed
21
## INSTALLATION
hxgf's avatar
hxgf committed
22 23 24
STEREO is designed to function with most LAMP stacks, and will support very old systems. Minimum requirements: PHP: 5.3, MYSQL: 3.0, Apache: 2.4.

*\* NGINX is also supported, see docs for configuration*
hxgf's avatar
v1 rc2  
hxgf committed
25

hxgf's avatar
hxgf committed
26
_Easiest installation: [download the latest release](https://gitlab.com/hxgf/stereo/-/archive/1.3.0/stereo-1.3.0.zip)_ and put the files on your server or dev environment 👍
hxgf's avatar
hxgf committed
27 28

Next-easiest installation: clone the latest version of the master branch with git:
hxgf's avatar
v1 rc2  
hxgf committed
29
```
hxgf's avatar
hxgf committed
30 31 32
git clone https://gitlab.com/hxgf/stereo.git .
```
...just remember to remove this repo from your actual project:
hxgf's avatar
v1 rc2  
hxgf committed
33
```
hxgf's avatar
hxgf committed
34 35 36
rm -Rf .git
```

hxgf's avatar
v1 rc2  
hxgf committed
37 38


hxgf's avatar
hxgf committed
39
## GETTING STARTED
hxgf's avatar
hxgf committed
40 41 42 43
1. Edit your global settings (site title, DB connection): ./settings.php
2. Set up some routes: ./controllers/_routes.php
3. Make some templates: ./pages/index.hbs
4. Build something cool!
hxgf's avatar
v1 rc2  
hxgf committed
44

hxgf's avatar
hxgf committed
45
### Routing + template example
hxgf's avatar
hxgf committed
46

hxgf's avatar
hxgf committed
47 48 49
Let's render a handlebars template with a global base template with data from PHP arrays!

First, in ./controllers/_routes.php:
hxgf's avatar
v1 rc2  
hxgf committed
50
```
hxgf's avatar
hxgf committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
$app->get('/favorite-planets', function(){

  $planets[] = array(
    'title' => 'Mercury',
    'nickname' => 'Swift Planet'
  );

  $planets[] = array(
    'title' => 'Venus',
    'nickname' => 'The Morning Star'
  );

  $planets[] = array(
    'title' => 'Earth',
    'nickname' => 'Big Blue'
  );

  $planets[] = array(
    'title' => 'Nibiru',
    'nickname' => 'Planet X'
  );

hxgf's avatar
v1 rc2  
hxgf committed
73 74 75 76
  $GLOBALS['app']->render_template(array(
    'template' => 'planets',
    'title' => 'Cool Planets',
    'data' => array(
hxgf's avatar
hxgf committed
77 78
      'reader_name' => 'Chad',
      'planets' => $planets
hxgf's avatar
v1 rc2  
hxgf committed
79 80
    )
  ));
hxgf's avatar
hxgf committed
81

hxgf's avatar
v1 rc2  
hxgf committed
82 83 84
});
```

hxgf's avatar
hxgf committed
85
and then in ./pages/planets.hbs:
hxgf's avatar
hxgf committed
86 87 88 89 90 91 92 93 94 95 96 97
```
<div class="mw8 center pa5">
  Greetings, {{reader_name}}! Allow me to provide you with a list of my favorite planets:
  <ul>
    {{#each planets}}
    <li>{{title}} ({{nickname}})</li>
    {{/each}}
  </ul>
</div>
```

Can you guess what will be rendered? 
hxgf's avatar
hxgf committed
98

hxgf's avatar
hxgf committed
99 100
Go here to find out: [https://stereotk.com/favorite-planets](https://stereotk.com/favorite-planets)

hxgf's avatar
v1 rc2  
hxgf committed
101

hxgf's avatar
hxgf committed
102

hxgf's avatar
hxgf committed
103
### Other responses you can make:
hxgf's avatar
v1 rc2  
hxgf committed
104

hxgf's avatar
hxgf committed
105
Render a single PHP / HTML document:
hxgf's avatar
v1 rc2  
hxgf committed
106 107 108 109 110 111
```
$app->get('/normal-page', function(){
  require __DIR__ . '/pages/whatever.html';
});
```

hxgf's avatar
hxgf committed
112
Render a PHP array as a JSON response:
hxgf's avatar
v1 rc2  
hxgf committed
113 114
```
$app->post('/json-response', function(){
hxgf's avatar
hxgf committed
115 116 117

  // do something magic here...crunch some data? web scraping? make some API calls? idk, math??

hxgf's avatar
v1 rc2  
hxgf committed
118
  $GLOBALS['app']->render_json(array(
hxgf's avatar
hxgf committed
119 120 121 122
    'righteous_content' => 'for sure',
    'planets' => array(
      'Mercury', 'Venus', 'Earth', 'Nibiru'
    )
hxgf's avatar
v1 rc2  
hxgf committed
123 124 125 126
  ));
});
```

hxgf's avatar
hxgf committed
127
Set headers / do redirects:
hxgf's avatar
v1 rc2  
hxgf committed
128
```
hxgf's avatar
hxgf committed
129
$app->get('/party', function(){
hxgf's avatar
v1 rc2  
hxgf committed
130 131 132 133
  header("Location: http://partyphysics.com/");
});
```

hxgf's avatar
hxgf committed
134 135 136 137 138
...and that's just the beginning! 

STEREO has abstraction tools to help you build all kinds of functionality!

Check out the full documentation to see everything you can do: [https://docs.stereotk.com](https://docs.stereotk.com)
hxgf's avatar
v1 rc2  
hxgf committed
139 140 141



hxgf's avatar
hxgf committed
142
## CONTRIBUTING
hxgf's avatar
hxgf committed
143
Contributions, issues, and feature requests are welcomed and appreciated (although a timely response is not guaranteed). Check the [issues page](https://gitlab.com/hxgf/stereo/issues) if you're interested in helping out 🙌 🙏
hxgf's avatar
v1 rc2  
hxgf committed
144 145 146



hxgf's avatar
hxgf committed
147
## LICENSE
hxgf's avatar
hxgf committed
148 149
Copyright © 2019 [HXGF](https://hxgf.io).
This project is [MIT](https://gitlab.com/hxgf/stereo/blob/master/stereo/license.md) licensed.
hxgf's avatar
v1 rc2  
hxgf committed
150