├── .gitignore ├── .htaccess ├── application ├── .htaccess ├── cache │ ├── .htaccess │ └── index.html ├── config │ ├── autoload.php │ ├── config.php │ ├── constants.php │ ├── database.php │ ├── doctypes.php │ ├── foreign_chars.php │ ├── hooks.php │ ├── index.html │ ├── memcached.php │ ├── migration.php │ ├── mimes.php │ ├── oauth2.php │ ├── profiler.php │ ├── routes.php │ ├── smileys.php │ └── user_agents.php ├── controllers │ ├── Errors.php │ ├── Welcome.php │ └── index.html ├── core │ ├── MY_Controller.php │ ├── MY_Loader.php │ ├── MY_Router.php │ └── index.html ├── helpers │ └── index.html ├── hooks │ └── index.html ├── index.html ├── language │ ├── english │ │ └── index.html │ └── index.html ├── libraries │ ├── Authenticate.php │ ├── Middleware.php │ ├── MyAPI.php │ ├── MyOAuth2.php │ ├── RESTful.php │ ├── Request.php │ ├── Response.php │ └── index.html ├── logs │ └── index.html ├── models │ ├── index.html │ └── welcome_model.php ├── modules │ ├── oauth2 │ │ ├── config │ │ │ └── routes.php │ │ └── controllers │ │ │ ├── OAuth2_api_controller.php │ │ │ └── index.html │ └── user │ │ ├── config │ │ └── routes.php │ │ ├── controllers │ │ ├── User_api_controller.php │ │ ├── User_controller.php │ │ └── index.html │ │ ├── models │ │ └── User_model.php │ │ └── views │ │ └── User_view.php ├── third_party │ ├── MX │ │ ├── Base.php │ │ ├── Ci.php │ │ ├── Config.php │ │ ├── Controller.php │ │ ├── Lang.php │ │ ├── Loader.php │ │ ├── Modules.php │ │ └── Router.php │ └── index.html └── views │ ├── errors │ ├── cli │ │ ├── error_404.php │ │ ├── error_db.php │ │ ├── error_exception.php │ │ ├── error_general.php │ │ ├── error_php.php │ │ └── index.html │ ├── html │ │ ├── error_404.php │ │ ├── error_db.php │ │ ├── error_exception.php │ │ ├── error_general.php │ │ ├── error_php.php │ │ └── index.html │ └── index.html │ ├── index.html │ └── welcome_message.php ├── composer.json ├── index.php ├── license.md ├── orm ├── classes │ ├── Base │ │ ├── User.php │ │ └── UserQuery.php │ ├── Map │ │ └── UserTableMap.php │ ├── User.php │ └── UserQuery.php ├── config.php └── schema.xml ├── propel ├── propel.yml ├── readme.md ├── sql ├── development.sql ├── oauth.sql └── sqldb.map ├── test └── api_test.php └── vendor └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | application/cache/* 4 | !application/cache/index.html 5 | !application/cache/.htaccess 6 | 7 | application/logs/* 8 | !application/logs/index.html 9 | !application/logs/.htaccess 10 | 11 | user_guide_src/build/* 12 | user_guide_src/cilexer/build/* 13 | user_guide_src/cilexer/dist/* 14 | user_guide_src/cilexer/pycilexer.egg-info/* 15 | vendor/* 16 | !vendor/.gitkeep 17 | **/.DS_STORE 18 | **/.DS_Store 19 | composer.lock 20 | 21 | # IDE Files 22 | #------------------------- 23 | /nbproject/ 24 | .idea/* 25 | 26 | ## Sublime Text cache files 27 | *.tmlanguage.cache 28 | *.tmPreferences.cache 29 | *.stTheme.cache 30 | *.sublime-workspace 31 | *.sublime-project 32 | -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | # Apache configuration file 2 | # httpd.apache.org/docs/2.2/mod/quickreference.html 3 | 4 | # Note .htaccess files are an overhead, this logic should be in your Apache 5 | # config if possible: httpd.apache.org/docs/2.2/howto/htaccess.html 6 | 7 | # Techniques in here adapted from all over, including: 8 | # Kroc Camen: camendesign.com/.htaccess 9 | # perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/ 10 | # Sample .htaccess file of CMS MODx: modxcms.com 11 | 12 | 13 | # ---------------------------------------------------------------------- 14 | # Better website experience for IE users 15 | # ---------------------------------------------------------------------- 16 | 17 | # Force the latest IE version, in various cases when it may fall back to IE7 mode 18 | # github.com/rails/rails/commit/123eb25#commitcomment-118920 19 | # Use ChromeFrame if it's installed for a better experience for the poor IE folk 20 | 21 | 22 | Header set X-UA-Compatible "IE=Edge,chrome=1" 23 | # mod_headers can't match by content-type, but we don't want to send this header on *everything*... 24 | 25 | Header unset X-UA-Compatible 26 | 27 | 28 | 29 | 30 | # ---------------------------------------------------------------------- 31 | # Cross-domain AJAX requests 32 | # ---------------------------------------------------------------------- 33 | 34 | # Serve cross-domain Ajax requests, disabled by default. 35 | # enable-cors.org 36 | # code.google.com/p/html5security/wiki/CrossOriginRequestSecurity 37 | 38 | # 39 | # Header set Access-Control-Allow-Origin "*" 40 | # 41 | 42 | 43 | # ---------------------------------------------------------------------- 44 | # CORS-enabled images (@crossorigin) 45 | # ---------------------------------------------------------------------- 46 | 47 | # Send CORS headers if browsers request them; enabled by default for images. 48 | # developer.mozilla.org/en/CORS_Enabled_Image 49 | # blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html 50 | # hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/ 51 | # wiki.mozilla.org/Security/Reviews/crossoriginAttribute 52 | 53 | 54 | 55 | # mod_headers, y u no match by Content-Type?! 56 | 57 | SetEnvIf Origin ":" IS_CORS 58 | Header set Access-Control-Allow-Origin "*" env=IS_CORS 59 | 60 | 61 | 62 | 63 | 64 | # ---------------------------------------------------------------------- 65 | # Webfont access 66 | # ---------------------------------------------------------------------- 67 | 68 | # Allow access from all domains for webfonts. 69 | # Alternatively you could only whitelist your 70 | # subdomains like "subdomain.example.com". 71 | 72 | 73 | 74 | Header set Access-Control-Allow-Origin "*" 75 | 76 | 77 | 78 | 79 | # ---------------------------------------------------------------------- 80 | # Proper MIME type for all files 81 | # ---------------------------------------------------------------------- 82 | 83 | # JavaScript 84 | # Normalize to standard type (it's sniffed in IE anyways) 85 | # tools.ietf.org/html/rfc4329#section-7.2 86 | AddType application/javascript js jsonp 87 | AddType application/json json 88 | 89 | # Audio 90 | AddType audio/ogg oga ogg 91 | AddType audio/mp4 m4a f4a f4b 92 | AddType audio/mpeg mp3 93 | 94 | # Video 95 | AddType video/ogg ogv 96 | AddType video/mp4 mp4 m4v f4v f4p 97 | AddType video/webm webm 98 | AddType video/x-flv flv 99 | 100 | # SVG 101 | # Required for svg webfonts on iPad 102 | # twitter.com/FontSquirrel/status/14855840545 103 | AddType image/svg+xml svg svgz 104 | AddEncoding gzip svgz 105 | 106 | # Webfonts 107 | AddType application/vnd.ms-fontobject eot 108 | AddType application/x-font-ttf ttf ttc 109 | AddType font/opentype otf 110 | AddType application/x-font-woff woff 111 | 112 | # Assorted types 113 | AddType image/x-icon ico 114 | AddType image/webp webp 115 | AddType text/cache-manifest appcache manifest 116 | AddType text/x-component htc 117 | AddType application/xml rss atom xml rdf 118 | AddType application/x-chrome-extension crx 119 | AddType application/x-opera-extension oex 120 | AddType application/x-xpinstall xpi 121 | AddType application/octet-stream safariextz 122 | AddType application/x-web-app-manifest+json webapp 123 | AddType text/x-vcard vcf 124 | AddType application/x-shockwave-flash swf 125 | AddType text/vtt vtt 126 | 127 | 128 | # ---------------------------------------------------------------------- 129 | # Allow concatenation from within specific js and css files 130 | # ---------------------------------------------------------------------- 131 | 132 | # e.g. Inside of script.combined.js you could have 133 | # 134 | # 135 | # and they would be included into this single file. 136 | 137 | # This is not in use in the boilerplate as it stands. You may 138 | # choose to use this technique if you do not have a build process. 139 | 140 | # 141 | # Options +Includes 142 | # AddOutputFilterByType INCLUDES application/javascript application/json 143 | # SetOutputFilter INCLUDES 144 | # 145 | 146 | # 147 | # Options +Includes 148 | # AddOutputFilterByType INCLUDES text/css 149 | # SetOutputFilter INCLUDES 150 | # 151 | 152 | 153 | # ---------------------------------------------------------------------- 154 | # Gzip compression 155 | # ---------------------------------------------------------------------- 156 | 157 | 158 | 159 | # Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ 160 | 161 | 162 | SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding 163 | RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding 164 | 165 | 166 | 167 | # Compress all output labeled with one of the following MIME-types 168 | 169 | AddOutputFilterByType DEFLATE application/atom+xml \ 170 | application/javascript \ 171 | application/json \ 172 | application/rss+xml \ 173 | application/vnd.ms-fontobject \ 174 | application/x-font-ttf \ 175 | application/xhtml+xml \ 176 | application/xml \ 177 | font/opentype \ 178 | image/svg+xml \ 179 | image/x-icon \ 180 | text/css \ 181 | text/html \ 182 | text/plain \ 183 | text/x-component \ 184 | text/xml 185 | 186 | 187 | 188 | 189 | 190 | # ---------------------------------------------------------------------- 191 | # Expires headers (for better cache control) 192 | # ---------------------------------------------------------------------- 193 | 194 | # These are pretty far-future expires headers. 195 | # They assume you control versioning with filename-based cache busting 196 | # Additionally, consider that outdated proxies may miscache 197 | # www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ 198 | 199 | # If you don't use filenames to version, lower the CSS and JS to something like 200 | # "access plus 1 week". 201 | 202 | 203 | ExpiresActive on 204 | 205 | # Perhaps better to whitelist expires rules? Perhaps. 206 | ExpiresDefault "access plus 1 month" 207 | 208 | # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5) 209 | ExpiresByType text/cache-manifest "access plus 0 seconds" 210 | 211 | # Your document html 212 | ExpiresByType text/html "access plus 0 seconds" 213 | 214 | # Data 215 | ExpiresByType text/xml "access plus 0 seconds" 216 | ExpiresByType application/xml "access plus 0 seconds" 217 | ExpiresByType application/json "access plus 0 seconds" 218 | 219 | # Feed 220 | ExpiresByType application/rss+xml "access plus 1 hour" 221 | ExpiresByType application/atom+xml "access plus 1 hour" 222 | 223 | # Favicon (cannot be renamed) 224 | ExpiresByType image/x-icon "access plus 1 week" 225 | 226 | # Media: images, video, audio 227 | ExpiresByType image/gif "access plus 1 month" 228 | ExpiresByType image/png "access plus 1 month" 229 | ExpiresByType image/jpeg "access plus 1 month" 230 | ExpiresByType video/ogg "access plus 1 month" 231 | ExpiresByType audio/ogg "access plus 1 month" 232 | ExpiresByType video/mp4 "access plus 1 month" 233 | ExpiresByType video/webm "access plus 1 month" 234 | 235 | # HTC files (css3pie) 236 | ExpiresByType text/x-component "access plus 1 month" 237 | 238 | # Webfonts 239 | ExpiresByType application/x-font-ttf "access plus 1 month" 240 | ExpiresByType font/opentype "access plus 1 month" 241 | ExpiresByType application/x-font-woff "access plus 1 month" 242 | ExpiresByType image/svg+xml "access plus 1 month" 243 | ExpiresByType application/vnd.ms-fontobject "access plus 1 month" 244 | 245 | # CSS and JavaScript 246 | ExpiresByType text/css "access plus 1 year" 247 | ExpiresByType application/javascript "access plus 1 year" 248 | 249 | 250 | 251 | # ------------------------------------------------------------------------------ 252 | # | File access | 253 | # ------------------------------------------------------------------------------ 254 | 255 | # Block access to directories without a default document. 256 | # Usually you should leave this uncommented because you shouldn't allow anyone 257 | # to surf through every directory on your server (which may includes rather 258 | # private places like the CMS's directories). 259 | 260 | 261 | Options -Indexes 262 | 263 | 264 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 265 | 266 | # Block access to hidden files and directories. 267 | # This includes directories used by version control systems such as Git and SVN. 268 | 269 | 270 | RewriteCond %{SCRIPT_FILENAME} -d [OR] 271 | RewriteCond %{SCRIPT_FILENAME} -f 272 | RewriteRule "(^|/)\." - [F] 273 | 274 | 275 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 276 | 277 | # Block access to backup and source files. 278 | # These files may be left by some text editors and can pose a great security 279 | # danger when anyone has access to them. 280 | 281 | 282 | 283 | # Apache < 2.3 284 | 285 | Order allow,deny 286 | Deny from all 287 | Satisfy All 288 | 289 | 290 | # Apache ≥ 2.3 291 | 292 | Require all denied 293 | 294 | 295 | 296 | 297 | 298 | # ---------------------------------------------------------------------- 299 | # Prevent mobile network providers from modifying your site 300 | # ---------------------------------------------------------------------- 301 | 302 | # The following header prevents modification of your code over 3G on some 303 | # European providers. 304 | # This is the official 'bypass' suggested by O2 in the UK. 305 | 306 | # 307 | # Header set Cache-Control "no-transform" 308 | # 309 | 310 | 311 | # ---------------------------------------------------------------------- 312 | # ETag removal 313 | # ---------------------------------------------------------------------- 314 | 315 | # FileETag None is not enough for every server. 316 | 317 | Header unset ETag 318 | 319 | 320 | # Since we're sending far-future expires, we don't need ETags for 321 | # static content. 322 | # developer.yahoo.com/performance/rules.html#etags 323 | FileETag None 324 | 325 | 326 | 327 | RewriteEngine On 328 | RewriteCond %{REQUEST_FILENAME} !-f 329 | RewriteCond %{REQUEST_FILENAME} !-d 330 | RewriteRule ^(.*)$ index.php/$1 [L] 331 | 332 | -------------------------------------------------------------------------------- /application/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Require all denied 3 | 4 | 5 | Deny from all 6 | -------------------------------------------------------------------------------- /application/cache/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Require all denied 3 | 4 | 5 | Deny from all 6 | -------------------------------------------------------------------------------- /application/cache/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/config/autoload.php: -------------------------------------------------------------------------------- 1 | 'ua'); 61 | */ 62 | $autoload['libraries'] = array( 63 | 'parser' 64 | ); 65 | 66 | /* 67 | | ------------------------------------------------------------------- 68 | | Auto-load Drivers 69 | | ------------------------------------------------------------------- 70 | | These classes are located in system/libraries/ or in your 71 | | application/libraries/ directory, but are also placed inside their 72 | | own subdirectory and they extend the CI_Driver_Library class. They 73 | | offer multiple interchangeable driver options. 74 | | 75 | | Prototype: 76 | | 77 | | $autoload['drivers'] = array('cache'); 78 | */ 79 | $autoload['drivers'] = array(); 80 | 81 | /* 82 | | ------------------------------------------------------------------- 83 | | Auto-load Helper Files 84 | | ------------------------------------------------------------------- 85 | | Prototype: 86 | | 87 | | $autoload['helper'] = array('url', 'file'); 88 | */ 89 | $autoload['helper'] = array( 90 | 'url', 91 | 'file' 92 | ); 93 | 94 | /* 95 | | ------------------------------------------------------------------- 96 | | Auto-load Config files 97 | | ------------------------------------------------------------------- 98 | | Prototype: 99 | | 100 | | $autoload['config'] = array('config1', 'config2'); 101 | | 102 | | NOTE: This item is intended for use ONLY if you have created custom 103 | | config files. Otherwise, leave it blank. 104 | | 105 | */ 106 | $autoload['config'] = array(); 107 | 108 | /* 109 | | ------------------------------------------------------------------- 110 | | Auto-load Language files 111 | | ------------------------------------------------------------------- 112 | | Prototype: 113 | | 114 | | $autoload['language'] = array('lang1', 'lang2'); 115 | | 116 | | NOTE: Do not include the "_lang" part of your file. For example 117 | | "codeigniter_lang.php" would be referenced as array('codeigniter'); 118 | | 119 | */ 120 | $autoload['language'] = array(); 121 | 122 | /* 123 | | ------------------------------------------------------------------- 124 | | Auto-load Models 125 | | ------------------------------------------------------------------- 126 | | Prototype: 127 | | 128 | | $autoload['model'] = array('first_model', 'second_model'); 129 | | 130 | | You can also supply an alternative model name to be assigned 131 | | in the controller: 132 | | 133 | | $autoload['model'] = array('first_model' => 'first'); 134 | */ 135 | $autoload['model'] = array(); 136 | -------------------------------------------------------------------------------- /application/config/config.php: -------------------------------------------------------------------------------- 1 | ]+$/i 157 | | 158 | | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! 159 | | 160 | */ 161 | $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; 162 | 163 | /* 164 | |-------------------------------------------------------------------------- 165 | | Enable Query Strings 166 | |-------------------------------------------------------------------------- 167 | | 168 | | By default CodeIgniter uses search-engine friendly segment based URLs: 169 | | example.com/who/what/where/ 170 | | 171 | | By default CodeIgniter enables access to the $_GET array. If for some 172 | | reason you would like to disable it, set 'allow_get_array' to FALSE. 173 | | 174 | | You can optionally enable standard query string based URLs: 175 | | example.com?who=me&what=something&where=here 176 | | 177 | | Options are: TRUE or FALSE (boolean) 178 | | 179 | | The other items let you set the query string 'words' that will 180 | | invoke your controllers and its functions: 181 | | example.com/index.php?c=controller&m=function 182 | | 183 | | Please note that some of the helpers won't work as expected when 184 | | this feature is enabled, since CodeIgniter is designed primarily to 185 | | use segment based URLs. 186 | | 187 | */ 188 | $config['allow_get_array'] = TRUE; 189 | $config['enable_query_strings'] = FALSE; 190 | $config['controller_trigger'] = 'c'; 191 | $config['function_trigger'] = 'm'; 192 | $config['directory_trigger'] = 'd'; 193 | 194 | /* 195 | |-------------------------------------------------------------------------- 196 | | Error Logging Threshold 197 | |-------------------------------------------------------------------------- 198 | | 199 | | You can enable error logging by setting a threshold over zero. The 200 | | threshold determines what gets logged. Threshold options are: 201 | | 202 | | 0 = Disables logging, Error logging TURNED OFF 203 | | 1 = Error Messages (including PHP errors) 204 | | 2 = Debug Messages 205 | | 3 = Informational Messages 206 | | 4 = All Messages 207 | | 208 | | You can also pass an array with threshold levels to show individual error types 209 | | 210 | | array(2) = Debug Messages, without Error Messages 211 | | 212 | | For a live site you'll usually only enable Errors (1) to be logged otherwise 213 | | your log files will fill up very fast. 214 | | 215 | */ 216 | $config['log_threshold'] = 0; 217 | 218 | /* 219 | |-------------------------------------------------------------------------- 220 | | Error Logging Directory Path 221 | |-------------------------------------------------------------------------- 222 | | 223 | | Leave this BLANK unless you would like to set something other than the default 224 | | application/logs/ directory. Use a full server path with trailing slash. 225 | | 226 | */ 227 | $config['log_path'] = ''; 228 | 229 | /* 230 | |-------------------------------------------------------------------------- 231 | | Log File Extension 232 | |-------------------------------------------------------------------------- 233 | | 234 | | The default filename extension for log files. The default 'php' allows for 235 | | protecting the log files via basic scripting, when they are to be stored 236 | | under a publicly accessible directory. 237 | | 238 | | Note: Leaving it blank will default to 'php'. 239 | | 240 | */ 241 | $config['log_file_extension'] = ''; 242 | 243 | /* 244 | |-------------------------------------------------------------------------- 245 | | Log File Permissions 246 | |-------------------------------------------------------------------------- 247 | | 248 | | The file system permissions to be applied on newly created log files. 249 | | 250 | | IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal 251 | | integer notation (i.e. 0700, 0644, etc.) 252 | */ 253 | $config['log_file_permissions'] = 0644; 254 | 255 | /* 256 | |-------------------------------------------------------------------------- 257 | | Date Format for Logs 258 | |-------------------------------------------------------------------------- 259 | | 260 | | Each item that is logged has an associated date. You can use PHP date 261 | | codes to set your own date formatting 262 | | 263 | */ 264 | $config['log_date_format'] = 'Y-m-d H:i:s'; 265 | 266 | /* 267 | |-------------------------------------------------------------------------- 268 | | Error Views Directory Path 269 | |-------------------------------------------------------------------------- 270 | | 271 | | Leave this BLANK unless you would like to set something other than the default 272 | | application/views/errors/ directory. Use a full server path with trailing slash. 273 | | 274 | */ 275 | $config['error_views_path'] = ''; 276 | 277 | /* 278 | |-------------------------------------------------------------------------- 279 | | Cache Directory Path 280 | |-------------------------------------------------------------------------- 281 | | 282 | | Leave this BLANK unless you would like to set something other than the default 283 | | application/cache/ directory. Use a full server path with trailing slash. 284 | | 285 | */ 286 | $config['cache_path'] = ''; 287 | 288 | /* 289 | |-------------------------------------------------------------------------- 290 | | Cache Include Query String 291 | |-------------------------------------------------------------------------- 292 | | 293 | | Whether to take the URL query string into consideration when generating 294 | | output cache files. Valid options are: 295 | | 296 | | FALSE = Disabled 297 | | TRUE = Enabled, take all query parameters into account. 298 | | Please be aware that this may result in numerous cache 299 | | files generated for the same page over and over again. 300 | | array('q') = Enabled, but only take into account the specified list 301 | | of query parameters. 302 | | 303 | */ 304 | $config['cache_query_string'] = FALSE; 305 | 306 | /* 307 | |-------------------------------------------------------------------------- 308 | | Encryption Key 309 | |-------------------------------------------------------------------------- 310 | | 311 | | If you use the Encryption class, you must set an encryption key. 312 | | See the user guide for more info. 313 | | 314 | | http://codeigniter.com/user_guide/libraries/encryption.html 315 | | 316 | */ 317 | $config['encryption_key'] = ''; 318 | 319 | /* 320 | |-------------------------------------------------------------------------- 321 | | Session Variables 322 | |-------------------------------------------------------------------------- 323 | | 324 | | 'sess_driver' 325 | | 326 | | The storage driver to use: files, database, redis, memcached 327 | | 328 | | 'sess_cookie_name' 329 | | 330 | | The session cookie name, must contain only [0-9a-z_-] characters 331 | | 332 | | 'sess_expiration' 333 | | 334 | | The number of SECONDS you want the session to last. 335 | | Setting to 0 (zero) means expire when the browser is closed. 336 | | 337 | | 'sess_save_path' 338 | | 339 | | The location to save sessions to, driver dependent. 340 | | 341 | | For the 'files' driver, it's a path to a writable directory. 342 | | WARNING: Only absolute paths are supported! 343 | | 344 | | For the 'database' driver, it's a table name. 345 | | Please read up the manual for the format with other session drivers. 346 | | 347 | | IMPORTANT: You are REQUIRED to set a valid save path! 348 | | 349 | | 'sess_match_ip' 350 | | 351 | | Whether to match the user's IP address when reading the session data. 352 | | 353 | | 'sess_time_to_update' 354 | | 355 | | How many seconds between CI regenerating the session ID. 356 | | 357 | | 'sess_regenerate_destroy' 358 | | 359 | | Whether to destroy session data associated with the old session ID 360 | | when auto-regenerating the session ID. When set to FALSE, the data 361 | | will be later deleted by the garbage collector. 362 | | 363 | | Other session cookie settings are shared with the rest of the application, 364 | | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here. 365 | | 366 | */ 367 | $config['sess_driver'] = 'files'; 368 | $config['sess_cookie_name'] = 'ci_session'; 369 | $config['sess_expiration'] = 7200; 370 | $config['sess_save_path'] = sys_get_temp_dir(); 371 | $config['sess_match_ip'] = FALSE; 372 | $config['sess_time_to_update'] = 300; 373 | $config['sess_regenerate_destroy'] = FALSE; 374 | 375 | /* 376 | |-------------------------------------------------------------------------- 377 | | Cookie Related Variables 378 | |-------------------------------------------------------------------------- 379 | | 380 | | 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions 381 | | 'cookie_domain' = Set to .your-domain.com for site-wide cookies 382 | | 'cookie_path' = Typically will be a forward slash 383 | | 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists. 384 | | 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) 385 | | 386 | | Note: These settings (with the exception of 'cookie_prefix' and 387 | | 'cookie_httponly') will also affect sessions. 388 | | 389 | */ 390 | $config['cookie_prefix'] = ''; 391 | $config['cookie_domain'] = ''; 392 | $config['cookie_path'] = '/'; 393 | $config['cookie_secure'] = FALSE; 394 | $config['cookie_httponly'] = FALSE; 395 | 396 | /* 397 | |-------------------------------------------------------------------------- 398 | | Standardize newlines 399 | |-------------------------------------------------------------------------- 400 | | 401 | | Determines whether to standardize newline characters in input data, 402 | | meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value. 403 | | 404 | | This is particularly useful for portability between UNIX-based OSes, 405 | | (usually \n) and Windows (\r\n). 406 | | 407 | */ 408 | $config['standardize_newlines'] = FALSE; 409 | 410 | /* 411 | |-------------------------------------------------------------------------- 412 | | Global XSS Filtering 413 | |-------------------------------------------------------------------------- 414 | | 415 | | Determines whether the XSS filter is always active when GET, POST or 416 | | COOKIE data is encountered 417 | | 418 | | WARNING: This feature is DEPRECATED and currently available only 419 | | for backwards compatibility purposes! 420 | | 421 | */ 422 | $config['global_xss_filtering'] = FALSE; 423 | 424 | /* 425 | |-------------------------------------------------------------------------- 426 | | Cross Site Request Forgery 427 | |-------------------------------------------------------------------------- 428 | | Enables a CSRF cookie token to be set. When set to TRUE, token will be 429 | | checked on a submitted form. If you are accepting user data, it is strongly 430 | | recommended CSRF protection be enabled. 431 | | 432 | | 'csrf_token_name' = The token name 433 | | 'csrf_cookie_name' = The cookie name 434 | | 'csrf_expire' = The number in seconds the token should expire. 435 | | 'csrf_regenerate' = Regenerate token on every submission 436 | | 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks 437 | */ 438 | $config['csrf_protection'] = FALSE; 439 | $config['csrf_token_name'] = 'csrf_test_name'; 440 | $config['csrf_cookie_name'] = 'csrf_cookie_name'; 441 | $config['csrf_expire'] = 7200; 442 | $config['csrf_regenerate'] = TRUE; 443 | $config['csrf_exclude_uris'] = array(); 444 | 445 | /* 446 | |-------------------------------------------------------------------------- 447 | | Output Compression 448 | |-------------------------------------------------------------------------- 449 | | 450 | | Enables Gzip output compression for faster page loads. When enabled, 451 | | the output class will test whether your server supports Gzip. 452 | | Even if it does, however, not all browsers support compression 453 | | so enable only if you are reasonably sure your visitors can handle it. 454 | | 455 | | Only used if zlib.output_compression is turned off in your php.ini. 456 | | Please do not use it together with httpd-level output compression. 457 | | 458 | | VERY IMPORTANT: If you are getting a blank page when compression is enabled it 459 | | means you are prematurely outputting something to your browser. It could 460 | | even be a line of whitespace at the end of one of your scripts. For 461 | | compression to work, nothing can be sent before the output buffer is called 462 | | by the output class. Do not 'echo' any values with compression enabled. 463 | | 464 | */ 465 | $config['compress_output'] = FALSE; 466 | 467 | /* 468 | |-------------------------------------------------------------------------- 469 | | Master Time Reference 470 | |-------------------------------------------------------------------------- 471 | | 472 | | Options are 'local' or any PHP supported timezone. This preference tells 473 | | the system whether to use your server's local time as the master 'now' 474 | | reference, or convert it to the configured one timezone. See the 'date 475 | | helper' page of the user guide for information regarding date handling. 476 | | 477 | */ 478 | $config['time_reference'] = 'local'; 479 | 480 | /* 481 | |-------------------------------------------------------------------------- 482 | | Rewrite PHP Short Tags 483 | |-------------------------------------------------------------------------- 484 | | 485 | | If your PHP installation does not have short tag support enabled CI 486 | | can rewrite the tags on-the-fly, enabling you to utilize that syntax 487 | | in your view files. Options are TRUE or FALSE (boolean) 488 | | 489 | | Note: You need to have eval() enabled for this to work. 490 | | 491 | */ 492 | $config['rewrite_short_tags'] = FALSE; 493 | 494 | /* 495 | |-------------------------------------------------------------------------- 496 | | Reverse Proxy IPs 497 | |-------------------------------------------------------------------------- 498 | | 499 | | If your server is behind a reverse proxy, you must whitelist the proxy 500 | | IP addresses from which CodeIgniter should trust headers such as 501 | | HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify 502 | | the visitor's IP address. 503 | | 504 | | You can use both an array or a comma-separated list of proxy addresses, 505 | | as well as specifying whole subnets. Here are a few examples: 506 | | 507 | | Comma-separated: '10.0.1.200,192.168.5.0/24' 508 | | Array: array('10.0.1.200', '192.168.5.0/24') 509 | */ 510 | $config['proxy_ips'] = ''; 511 | -------------------------------------------------------------------------------- /application/config/constants.php: -------------------------------------------------------------------------------- 1 | db->last_query() and profiling of DB queries. 63 | | When you run a query, with this setting set to TRUE (default), 64 | | CodeIgniter will store the SQL statement for debugging purposes. 65 | | However, this may cause high memory usage, especially if you run 66 | | a lot of SQL queries ... disable this to avoid that problem. 67 | | 68 | | The $active_group variable lets you choose which connection group to 69 | | make active. By default there is only one group (the 'default' group). 70 | | 71 | | The $query_builder variables lets you determine whether or not to load 72 | | the query builder class. 73 | */ 74 | $active_group = (ENVIRONMENT !== 'production') ? 'default' : 'production'; 75 | $query_builder = TRUE; 76 | 77 | $db['default'] = array( 78 | 'dsn' => '', 79 | 'hostname' => 'localhost', 80 | 'username' => 'root', 81 | 'password' => 'root', 82 | 'database' => 'dbcodeigniter', 83 | 'dbdriver' => 'mysqli', 84 | 'dbprefix' => '', 85 | 'pconnect' => FALSE, 86 | 'db_debug' => (ENVIRONMENT !== 'production'), 87 | 'cache_on' => FALSE, 88 | 'cachedir' => '', 89 | 'char_set' => 'utf8', 90 | 'dbcollat' => 'utf8_general_ci', 91 | 'swap_pre' => '', 92 | 'encrypt' => FALSE, 93 | 'compress' => FALSE, 94 | 'stricton' => FALSE, 95 | 'failover' => array(), 96 | 'save_queries' => TRUE 97 | ); 98 | 99 | $db['production'] = array( 100 | 'dsn' => '', 101 | 'hostname' => 'localhost', 102 | 'username' => 'root', 103 | 'password' => 'root', 104 | 'database' => 'dbcodeigniter', 105 | 'dbdriver' => 'mysqli', 106 | 'dbprefix' => '', 107 | 'pconnect' => FALSE, 108 | 'db_debug' => (ENVIRONMENT !== 'production'), 109 | 'cache_on' => FALSE, 110 | 'cachedir' => '', 111 | 'char_set' => 'utf8', 112 | 'dbcollat' => 'utf8_general_ci', 113 | 'swap_pre' => '', 114 | 'encrypt' => FALSE, 115 | 'compress' => FALSE, 116 | 'stricton' => FALSE, 117 | 'failover' => array(), 118 | 'save_queries' => TRUE 119 | ); 120 | 121 | // OAuth2 122 | $db['oauth'] = array( 123 | 'dsn' => 'mysql:dbname=dbcodeigniter;host=localhost', 124 | 'username' => 'root', 125 | 'password' => 'root' 126 | ); 127 | -------------------------------------------------------------------------------- /application/config/doctypes.php: -------------------------------------------------------------------------------- 1 | '', 7 | 'xhtml1-strict' => '', 8 | 'xhtml1-trans' => '', 9 | 'xhtml1-frame' => '', 10 | 'xhtml-basic11' => '', 11 | 'html5' => '', 12 | 'html4-strict' => '', 13 | 'html4-trans' => '', 14 | 'html4-frame' => '', 15 | 'mathml1' => '', 16 | 'mathml2' => '', 17 | 'svg10' => '', 18 | 'svg11' => '', 19 | 'svg11-basic' => '', 20 | 'svg11-tiny' => '', 21 | 'xhtml-math-svg-xh' => '', 22 | 'xhtml-math-svg-sh' => '', 23 | 'xhtml-rdfa-1' => '', 24 | 'xhtml-rdfa-2' => '' 25 | ); 26 | -------------------------------------------------------------------------------- /application/config/foreign_chars.php: -------------------------------------------------------------------------------- 1 | 'ae', 14 | '/ö|œ/' => 'oe', 15 | '/ü/' => 'ue', 16 | '/Ä/' => 'Ae', 17 | '/Ü/' => 'Ue', 18 | '/Ö/' => 'Oe', 19 | '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A', 20 | '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a', 21 | '/Б/' => 'B', 22 | '/б/' => 'b', 23 | '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', 24 | '/ç|ć|ĉ|ċ|č/' => 'c', 25 | '/Д/' => 'D', 26 | '/д/' => 'd', 27 | '/Ð|Ď|Đ|Δ/' => 'Dj', 28 | '/ð|ď|đ|δ/' => 'dj', 29 | '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E', 30 | '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e', 31 | '/Ф/' => 'F', 32 | '/ф/' => 'f', 33 | '/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G', 34 | '/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g', 35 | '/Ĥ|Ħ/' => 'H', 36 | '/ĥ|ħ/' => 'h', 37 | '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I', 38 | '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i', 39 | '/Ĵ/' => 'J', 40 | '/ĵ/' => 'j', 41 | '/Ķ|Κ|К/' => 'K', 42 | '/ķ|κ|к/' => 'k', 43 | '/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L', 44 | '/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l', 45 | '/М/' => 'M', 46 | '/м/' => 'm', 47 | '/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N', 48 | '/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n', 49 | '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O', 50 | '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o', 51 | '/П/' => 'P', 52 | '/п/' => 'p', 53 | '/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R', 54 | '/ŕ|ŗ|ř|ρ|р/' => 'r', 55 | '/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S', 56 | '/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's', 57 | '/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T', 58 | '/ț|ţ|ť|ŧ|т/' => 't', 59 | '/Þ|þ/' => 'th', 60 | '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U', 61 | '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u', 62 | '/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y', 63 | '/ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y', 64 | '/В/' => 'V', 65 | '/в/' => 'v', 66 | '/Ŵ/' => 'W', 67 | '/ŵ/' => 'w', 68 | '/Ź|Ż|Ž|Ζ|З/' => 'Z', 69 | '/ź|ż|ž|ζ|з/' => 'z', 70 | '/Æ|Ǽ/' => 'AE', 71 | '/ß/' => 'ss', 72 | '/IJ/' => 'IJ', 73 | '/ij/' => 'ij', 74 | '/Œ/' => 'OE', 75 | '/ƒ/' => 'f', 76 | '/ξ/' => 'ks', 77 | '/π/' => 'p', 78 | '/β/' => 'v', 79 | '/μ/' => 'm', 80 | '/ψ/' => 'ps', 81 | '/Ё/' => 'Yo', 82 | '/ё/' => 'yo', 83 | '/Є/' => 'Ye', 84 | '/є/' => 'ye', 85 | '/Ї/' => 'Yi', 86 | '/Ж/' => 'Zh', 87 | '/ж/' => 'zh', 88 | '/Х/' => 'Kh', 89 | '/х/' => 'kh', 90 | '/Ц/' => 'Ts', 91 | '/ц/' => 'ts', 92 | '/Ч/' => 'Ch', 93 | '/ч/' => 'ch', 94 | '/Ш/' => 'Sh', 95 | '/ш/' => 'sh', 96 | '/Щ/' => 'Shch', 97 | '/щ/' => 'shch', 98 | '/Ъ|ъ|Ь|ь/' => '', 99 | '/Ю/' => 'Yu', 100 | '/ю/' => 'yu', 101 | '/Я/' => 'Ya', 102 | '/я/' => 'ya' 103 | ); 104 | -------------------------------------------------------------------------------- /application/config/hooks.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/config/memcached.php: -------------------------------------------------------------------------------- 1 | array( 15 | 'hostname' => '127.0.0.1', 16 | 'port' => '11211', 17 | 'weight' => '1', 18 | ), 19 | ); 20 | -------------------------------------------------------------------------------- /application/config/migration.php: -------------------------------------------------------------------------------- 1 | migration->current() this is the version that schema will 69 | | be upgraded / downgraded to. 70 | | 71 | */ 72 | $config['migration_version'] = 0; 73 | 74 | /* 75 | |-------------------------------------------------------------------------- 76 | | Migrations Path 77 | |-------------------------------------------------------------------------- 78 | | 79 | | Path to your migrations folder. 80 | | Typically, it will be within your application path. 81 | | Also, writing permission is required within the migrations path. 82 | | 83 | */ 84 | $config['migration_path'] = APPPATH.'migrations/'; 85 | -------------------------------------------------------------------------------- /application/config/mimes.php: -------------------------------------------------------------------------------- 1 | array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'), 14 | 'cpt' => 'application/mac-compactpro', 15 | 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'), 16 | 'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'), 17 | 'dms' => 'application/octet-stream', 18 | 'lha' => 'application/octet-stream', 19 | 'lzh' => 'application/octet-stream', 20 | 'exe' => array('application/octet-stream', 'application/x-msdownload'), 21 | 'class' => 'application/octet-stream', 22 | 'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'), 23 | 'so' => 'application/octet-stream', 24 | 'sea' => 'application/octet-stream', 25 | 'dll' => 'application/octet-stream', 26 | 'oda' => 'application/oda', 27 | 'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'), 28 | 'ai' => array('application/pdf', 'application/postscript'), 29 | 'eps' => 'application/postscript', 30 | 'ps' => 'application/postscript', 31 | 'smi' => 'application/smil', 32 | 'smil' => 'application/smil', 33 | 'mif' => 'application/vnd.mif', 34 | 'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'), 35 | 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'), 36 | 'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'), 37 | 'wbxml' => 'application/wbxml', 38 | 'wmlc' => 'application/wmlc', 39 | 'dcr' => 'application/x-director', 40 | 'dir' => 'application/x-director', 41 | 'dxr' => 'application/x-director', 42 | 'dvi' => 'application/x-dvi', 43 | 'gtar' => 'application/x-gtar', 44 | 'gz' => 'application/x-gzip', 45 | 'gzip' => 'application/x-gzip', 46 | 'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'), 47 | 'php4' => 'application/x-httpd-php', 48 | 'php3' => 'application/x-httpd-php', 49 | 'phtml' => 'application/x-httpd-php', 50 | 'phps' => 'application/x-httpd-php-source', 51 | 'js' => array('application/x-javascript', 'text/plain'), 52 | 'swf' => 'application/x-shockwave-flash', 53 | 'sit' => 'application/x-stuffit', 54 | 'tar' => 'application/x-tar', 55 | 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), 56 | 'z' => 'application/x-compress', 57 | 'xhtml' => 'application/xhtml+xml', 58 | 'xht' => 'application/xhtml+xml', 59 | 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'), 60 | 'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'), 61 | 'mid' => 'audio/midi', 62 | 'midi' => 'audio/midi', 63 | 'mpga' => 'audio/mpeg', 64 | 'mp2' => 'audio/mpeg', 65 | 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), 66 | 'aif' => array('audio/x-aiff', 'audio/aiff'), 67 | 'aiff' => array('audio/x-aiff', 'audio/aiff'), 68 | 'aifc' => 'audio/x-aiff', 69 | 'ram' => 'audio/x-pn-realaudio', 70 | 'rm' => 'audio/x-pn-realaudio', 71 | 'rpm' => 'audio/x-pn-realaudio-plugin', 72 | 'ra' => 'audio/x-realaudio', 73 | 'rv' => 'video/vnd.rn-realvideo', 74 | 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'), 75 | 'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'), 76 | 'gif' => 'image/gif', 77 | 'jpeg' => array('image/jpeg', 'image/pjpeg'), 78 | 'jpg' => array('image/jpeg', 'image/pjpeg'), 79 | 'jpe' => array('image/jpeg', 'image/pjpeg'), 80 | 'png' => array('image/png', 'image/x-png'), 81 | 'tiff' => 'image/tiff', 82 | 'tif' => 'image/tiff', 83 | 'css' => array('text/css', 'text/plain'), 84 | 'html' => array('text/html', 'text/plain'), 85 | 'htm' => array('text/html', 'text/plain'), 86 | 'shtml' => array('text/html', 'text/plain'), 87 | 'txt' => 'text/plain', 88 | 'text' => 'text/plain', 89 | 'log' => array('text/plain', 'text/x-log'), 90 | 'rtx' => 'text/richtext', 91 | 'rtf' => 'text/rtf', 92 | 'xml' => array('application/xml', 'text/xml', 'text/plain'), 93 | 'xsl' => array('application/xml', 'text/xsl', 'text/xml'), 94 | 'mpeg' => 'video/mpeg', 95 | 'mpg' => 'video/mpeg', 96 | 'mpe' => 'video/mpeg', 97 | 'qt' => 'video/quicktime', 98 | 'mov' => 'video/quicktime', 99 | 'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'), 100 | 'movie' => 'video/x-sgi-movie', 101 | 'doc' => array('application/msword', 'application/vnd.ms-office'), 102 | 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'), 103 | 'dot' => array('application/msword', 'application/vnd.ms-office'), 104 | 'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'), 105 | 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'), 106 | 'word' => array('application/msword', 'application/octet-stream'), 107 | 'xl' => 'application/excel', 108 | 'eml' => 'message/rfc822', 109 | 'json' => array('application/json', 'text/json'), 110 | 'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'), 111 | 'p10' => array('application/x-pkcs10', 'application/pkcs10'), 112 | 'p12' => 'application/x-pkcs12', 113 | 'p7a' => 'application/x-pkcs7-signature', 114 | 'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'), 115 | 'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'), 116 | 'p7r' => 'application/x-pkcs7-certreqresp', 117 | 'p7s' => 'application/pkcs7-signature', 118 | 'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'), 119 | 'crl' => array('application/pkix-crl', 'application/pkcs-crl'), 120 | 'der' => 'application/x-x509-ca-cert', 121 | 'kdb' => 'application/octet-stream', 122 | 'pgp' => 'application/pgp', 123 | 'gpg' => 'application/gpg-keys', 124 | 'sst' => 'application/octet-stream', 125 | 'csr' => 'application/octet-stream', 126 | 'rsa' => 'application/x-pkcs7', 127 | 'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'), 128 | '3g2' => 'video/3gpp2', 129 | '3gp' => array('video/3gp', 'video/3gpp'), 130 | 'mp4' => 'video/mp4', 131 | 'm4a' => 'audio/x-m4a', 132 | 'f4v' => 'video/mp4', 133 | 'webm' => 'video/webm', 134 | 'aac' => 'audio/x-acc', 135 | 'm4u' => 'application/vnd.mpegurl', 136 | 'm3u' => 'text/plain', 137 | 'xspf' => 'application/xspf+xml', 138 | 'vlc' => 'application/videolan', 139 | 'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'), 140 | 'au' => 'audio/x-au', 141 | 'ac3' => 'audio/ac3', 142 | 'flac' => 'audio/x-flac', 143 | 'ogg' => 'audio/ogg', 144 | 'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'), 145 | 'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'), 146 | 'ics' => 'text/calendar', 147 | 'ical' => 'text/calendar', 148 | 'zsh' => 'text/x-scriptzsh', 149 | '7zip' => array('application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'), 150 | 'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'), 151 | 'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'), 152 | 'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'), 153 | 'svg' => array('image/svg+xml', 'application/xml', 'text/xml'), 154 | 'vcf' => 'text/x-vcard', 155 | 'srt' => array('text/srt', 'text/plain'), 156 | 'vtt' => array('text/vtt', 'text/plain'), 157 | 'ico' => array('image/x-icon', 'image/x-ico', 'image/vnd.microsoft.icon') 158 | ); 159 | -------------------------------------------------------------------------------- /application/config/oauth2.php: -------------------------------------------------------------------------------- 1 | 'mysql:dbname=dboauth;host=localhost', 17 | 'username' => 'root', 18 | 'password' => 'root' 19 | ); 20 | 21 | /** 22 | * Ignore OAuth2 authorization request. 23 | * 24 | * Example: 25 | * Class_api_controller/method_post 26 | */ 27 | $config['ignore'] = array( 28 | 'OAuth2_api_controller/client_credential_post' 29 | ); 30 | -------------------------------------------------------------------------------- /application/config/profiler.php: -------------------------------------------------------------------------------- 1 | my_controller/index 51 | | my-controller/my-method -> my_controller/my_method 52 | */ 53 | 54 | $route['default_controller'] = 'welcome'; 55 | $route['404_override'] = 'errors'; 56 | $route['translate_uri_dashes'] = FALSE; 57 | 58 | /* 59 | * API 60 | */ 61 | 62 | // OAuth 2 Module 63 | // -- Client Credentials 64 | $route['v1/login/oauth/access_token'] = 'oauth2/login/access_token'; 65 | 66 | // User Module 67 | $route['v1/user'] = 'user'; 68 | $route['v1/user/([0-9]+)'] = 'user/$1'; 69 | -------------------------------------------------------------------------------- /application/config/smileys.php: -------------------------------------------------------------------------------- 1 | array('grin.gif', '19', '19', 'grin'), 21 | ':lol:' => array('lol.gif', '19', '19', 'LOL'), 22 | ':cheese:' => array('cheese.gif', '19', '19', 'cheese'), 23 | ':)' => array('smile.gif', '19', '19', 'smile'), 24 | ';-)' => array('wink.gif', '19', '19', 'wink'), 25 | ';)' => array('wink.gif', '19', '19', 'wink'), 26 | ':smirk:' => array('smirk.gif', '19', '19', 'smirk'), 27 | ':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'), 28 | ':-S' => array('confused.gif', '19', '19', 'confused'), 29 | ':wow:' => array('surprise.gif', '19', '19', 'surprised'), 30 | ':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'), 31 | ':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'), 32 | '%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'), 33 | ';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'), 34 | ':P' => array('raspberry.gif', '19', '19', 'raspberry'), 35 | ':blank:' => array('blank.gif', '19', '19', 'blank stare'), 36 | ':long:' => array('longface.gif', '19', '19', 'long face'), 37 | ':ohh:' => array('ohh.gif', '19', '19', 'ohh'), 38 | ':grrr:' => array('grrr.gif', '19', '19', 'grrr'), 39 | ':gulp:' => array('gulp.gif', '19', '19', 'gulp'), 40 | '8-/' => array('ohoh.gif', '19', '19', 'oh oh'), 41 | ':down:' => array('downer.gif', '19', '19', 'downer'), 42 | ':red:' => array('embarrassed.gif', '19', '19', 'red face'), 43 | ':sick:' => array('sick.gif', '19', '19', 'sick'), 44 | ':shut:' => array('shuteye.gif', '19', '19', 'shut eye'), 45 | ':-/' => array('hmm.gif', '19', '19', 'hmmm'), 46 | '>:(' => array('mad.gif', '19', '19', 'mad'), 47 | ':mad:' => array('mad.gif', '19', '19', 'mad'), 48 | '>:-(' => array('angry.gif', '19', '19', 'angry'), 49 | ':angry:' => array('angry.gif', '19', '19', 'angry'), 50 | ':zip:' => array('zip.gif', '19', '19', 'zipper'), 51 | ':kiss:' => array('kiss.gif', '19', '19', 'kiss'), 52 | ':ahhh:' => array('shock.gif', '19', '19', 'shock'), 53 | ':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'), 54 | ':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'), 55 | ':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'), 56 | ':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'), 57 | ':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'), 58 | ':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'), 59 | ':vampire:' => array('vampire.gif', '19', '19', 'vampire'), 60 | ':snake:' => array('snake.gif', '19', '19', 'snake'), 61 | ':exclaim:' => array('exclaim.gif', '19', '19', 'exclaim'), 62 | ':question:' => array('question.gif', '19', '19', 'question') 63 | 64 | ); 65 | -------------------------------------------------------------------------------- /application/config/user_agents.php: -------------------------------------------------------------------------------- 1 | 'Windows 10', 15 | 'windows nt 6.3' => 'Windows 8.1', 16 | 'windows nt 6.2' => 'Windows 8', 17 | 'windows nt 6.1' => 'Windows 7', 18 | 'windows nt 6.0' => 'Windows Vista', 19 | 'windows nt 5.2' => 'Windows 2003', 20 | 'windows nt 5.1' => 'Windows XP', 21 | 'windows nt 5.0' => 'Windows 2000', 22 | 'windows nt 4.0' => 'Windows NT 4.0', 23 | 'winnt4.0' => 'Windows NT 4.0', 24 | 'winnt 4.0' => 'Windows NT', 25 | 'winnt' => 'Windows NT', 26 | 'windows 98' => 'Windows 98', 27 | 'win98' => 'Windows 98', 28 | 'windows 95' => 'Windows 95', 29 | 'win95' => 'Windows 95', 30 | 'windows phone' => 'Windows Phone', 31 | 'windows' => 'Unknown Windows OS', 32 | 'android' => 'Android', 33 | 'blackberry' => 'BlackBerry', 34 | 'iphone' => 'iOS', 35 | 'ipad' => 'iOS', 36 | 'ipod' => 'iOS', 37 | 'os x' => 'Mac OS X', 38 | 'ppc mac' => 'Power PC Mac', 39 | 'freebsd' => 'FreeBSD', 40 | 'ppc' => 'Macintosh', 41 | 'linux' => 'Linux', 42 | 'debian' => 'Debian', 43 | 'sunos' => 'Sun Solaris', 44 | 'beos' => 'BeOS', 45 | 'apachebench' => 'ApacheBench', 46 | 'aix' => 'AIX', 47 | 'irix' => 'Irix', 48 | 'osf' => 'DEC OSF', 49 | 'hp-ux' => 'HP-UX', 50 | 'netbsd' => 'NetBSD', 51 | 'bsdi' => 'BSDi', 52 | 'openbsd' => 'OpenBSD', 53 | 'gnu' => 'GNU/Linux', 54 | 'unix' => 'Unknown Unix OS', 55 | 'symbian' => 'Symbian OS' 56 | ); 57 | 58 | 59 | // The order of this array should NOT be changed. Many browsers return 60 | // multiple browser types so we want to identify the sub-type first. 61 | $browsers = array( 62 | 'OPR' => 'Opera', 63 | 'Flock' => 'Flock', 64 | 'Edge' => 'Spartan', 65 | 'Chrome' => 'Chrome', 66 | // Opera 10+ always reports Opera/9.80 and appends Version/ to the user agent string 67 | 'Opera.*?Version' => 'Opera', 68 | 'Opera' => 'Opera', 69 | 'MSIE' => 'Internet Explorer', 70 | 'Internet Explorer' => 'Internet Explorer', 71 | 'Trident.* rv' => 'Internet Explorer', 72 | 'Shiira' => 'Shiira', 73 | 'Firefox' => 'Firefox', 74 | 'Chimera' => 'Chimera', 75 | 'Phoenix' => 'Phoenix', 76 | 'Firebird' => 'Firebird', 77 | 'Camino' => 'Camino', 78 | 'Netscape' => 'Netscape', 79 | 'OmniWeb' => 'OmniWeb', 80 | 'Safari' => 'Safari', 81 | 'Mozilla' => 'Mozilla', 82 | 'Konqueror' => 'Konqueror', 83 | 'icab' => 'iCab', 84 | 'Lynx' => 'Lynx', 85 | 'Links' => 'Links', 86 | 'hotjava' => 'HotJava', 87 | 'amaya' => 'Amaya', 88 | 'IBrowse' => 'IBrowse', 89 | 'Maxthon' => 'Maxthon', 90 | 'Ubuntu' => 'Ubuntu Web Browser' 91 | ); 92 | 93 | $mobiles = array( 94 | // legacy array, old values commented out 95 | 'mobileexplorer' => 'Mobile Explorer', 96 | // 'openwave' => 'Open Wave', 97 | // 'opera mini' => 'Opera Mini', 98 | // 'operamini' => 'Opera Mini', 99 | // 'elaine' => 'Palm', 100 | 'palmsource' => 'Palm', 101 | // 'digital paths' => 'Palm', 102 | // 'avantgo' => 'Avantgo', 103 | // 'xiino' => 'Xiino', 104 | 'palmscape' => 'Palmscape', 105 | // 'nokia' => 'Nokia', 106 | // 'ericsson' => 'Ericsson', 107 | // 'blackberry' => 'BlackBerry', 108 | // 'motorola' => 'Motorola' 109 | 110 | // Phones and Manufacturers 111 | 'motorola' => 'Motorola', 112 | 'nokia' => 'Nokia', 113 | 'palm' => 'Palm', 114 | 'iphone' => 'Apple iPhone', 115 | 'ipad' => 'iPad', 116 | 'ipod' => 'Apple iPod Touch', 117 | 'sony' => 'Sony Ericsson', 118 | 'ericsson' => 'Sony Ericsson', 119 | 'blackberry' => 'BlackBerry', 120 | 'cocoon' => 'O2 Cocoon', 121 | 'blazer' => 'Treo', 122 | 'lg' => 'LG', 123 | 'amoi' => 'Amoi', 124 | 'xda' => 'XDA', 125 | 'mda' => 'MDA', 126 | 'vario' => 'Vario', 127 | 'htc' => 'HTC', 128 | 'samsung' => 'Samsung', 129 | 'sharp' => 'Sharp', 130 | 'sie-' => 'Siemens', 131 | 'alcatel' => 'Alcatel', 132 | 'benq' => 'BenQ', 133 | 'ipaq' => 'HP iPaq', 134 | 'mot-' => 'Motorola', 135 | 'playstation portable' => 'PlayStation Portable', 136 | 'playstation 3' => 'PlayStation 3', 137 | 'playstation vita' => 'PlayStation Vita', 138 | 'hiptop' => 'Danger Hiptop', 139 | 'nec-' => 'NEC', 140 | 'panasonic' => 'Panasonic', 141 | 'philips' => 'Philips', 142 | 'sagem' => 'Sagem', 143 | 'sanyo' => 'Sanyo', 144 | 'spv' => 'SPV', 145 | 'zte' => 'ZTE', 146 | 'sendo' => 'Sendo', 147 | 'nintendo dsi' => 'Nintendo DSi', 148 | 'nintendo ds' => 'Nintendo DS', 149 | 'nintendo 3ds' => 'Nintendo 3DS', 150 | 'wii' => 'Nintendo Wii', 151 | 'open web' => 'Open Web', 152 | 'openweb' => 'OpenWeb', 153 | 154 | // Operating Systems 155 | 'android' => 'Android', 156 | 'symbian' => 'Symbian', 157 | 'SymbianOS' => 'SymbianOS', 158 | 'elaine' => 'Palm', 159 | 'series60' => 'Symbian S60', 160 | 'windows ce' => 'Windows CE', 161 | 162 | // Browsers 163 | 'obigo' => 'Obigo', 164 | 'netfront' => 'Netfront Browser', 165 | 'openwave' => 'Openwave Browser', 166 | 'mobilexplorer' => 'Mobile Explorer', 167 | 'operamini' => 'Opera Mini', 168 | 'opera mini' => 'Opera Mini', 169 | 'opera mobi' => 'Opera Mobile', 170 | 'fennec' => 'Firefox Mobile', 171 | 172 | // Other 173 | 'digital paths' => 'Digital Paths', 174 | 'avantgo' => 'AvantGo', 175 | 'xiino' => 'Xiino', 176 | 'novarra' => 'Novarra Transcoder', 177 | 'vodafone' => 'Vodafone', 178 | 'docomo' => 'NTT DoCoMo', 179 | 'o2' => 'O2', 180 | 181 | // Fallback 182 | 'mobile' => 'Generic Mobile', 183 | 'wireless' => 'Generic Mobile', 184 | 'j2me' => 'Generic Mobile', 185 | 'midp' => 'Generic Mobile', 186 | 'cldc' => 'Generic Mobile', 187 | 'up.link' => 'Generic Mobile', 188 | 'up.browser' => 'Generic Mobile', 189 | 'smartphone' => 'Generic Mobile', 190 | 'cellphone' => 'Generic Mobile' 191 | ); 192 | 193 | // There are hundreds of bots but these are the most common. 194 | $robots = array( 195 | 'googlebot' => 'Googlebot', 196 | 'msnbot' => 'MSNBot', 197 | 'baiduspider' => 'Baiduspider', 198 | 'bingbot' => 'Bing', 199 | 'slurp' => 'Inktomi Slurp', 200 | 'yahoo' => 'Yahoo', 201 | 'ask jeeves' => 'Ask Jeeves', 202 | 'fastcrawler' => 'FastCrawler', 203 | 'infoseek' => 'InfoSeek Robot 1.0', 204 | 'lycos' => 'Lycos', 205 | 'yandex' => 'YandexBot', 206 | 'mediapartners-google' => 'MediaPartners Google', 207 | 'CRAZYWEBCRAWLER' => 'Crazy Webcrawler', 208 | 'adsbot-google' => 'AdsBot Google', 209 | 'feedfetcher-google' => 'Feedfetcher Google', 210 | 'curious george' => 'Curious George' 211 | ); 212 | -------------------------------------------------------------------------------- /application/controllers/Errors.php: -------------------------------------------------------------------------------- 1 | 20 | * @see http://codeigniter.com/user_guide/general/urls.html 21 | */ 22 | function index() { 23 | $this->response->not_found(); 24 | $this->response->send(array( 25 | 'message' => 'Request not found.' 26 | )); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /application/controllers/Welcome.php: -------------------------------------------------------------------------------- 1 | 20 | * @see http://codeigniter.com/user_guide/general/urls.html 21 | */ 22 | function index() { 23 | $this->load->view('welcome_message'); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /application/controllers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/core/MY_Controller.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | class MY_Controller extends CI_Controller { 16 | 17 | public $request; 18 | public $response; 19 | public $restful; 20 | public $oauth; 21 | 22 | public function __construct() { 23 | parent::__construct(); 24 | 25 | $load = $this->load; 26 | $input = $this->input; 27 | 28 | $this->load->library('Response', $load); 29 | $this->load->library('Request', array( 30 | 'load' => $load, 31 | 'input' => $input 32 | )); 33 | 34 | $request = $this->request; 35 | $response = $this->response; 36 | 37 | $this->load->library('Middleware', array( 38 | 'load' => $load, 39 | 'request' => $request, 40 | 'response' => $response 41 | )); 42 | 43 | $this->load->library('RESTful', array( 44 | 'load' => $load, 45 | 'input' => $input, 46 | 'request' => $request, 47 | 'response' => $response, 48 | 'router' => $this->router 49 | ), 'restful'); 50 | 51 | $this->oauth = $this->restful->get_oauth(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /application/core/MY_Loader.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/helpers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/hooks/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/language/english/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/language/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/libraries/Authenticate.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class Authenticate { 13 | 14 | protected $request; 15 | protected $response; 16 | 17 | function __construct($request, $response) { 18 | $this->request = $request; 19 | $this->response = $response; 20 | } 21 | 22 | function guard() { 23 | // Authentication stuff goes here 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /application/libraries/Middleware.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | class Middleware { 14 | 15 | protected $load; 16 | 17 | function __construct($params) { 18 | $this->load = $params['load']; 19 | $this->request = $params['request']; 20 | $this->response = $params['response']; 21 | 22 | // Authentication stuff 23 | // $this->authentication(); 24 | } 25 | 26 | function authentication() { 27 | $this->load->library('Authenticate'); 28 | 29 | $authenticate = new Authenticate($this->request, $this->response); 30 | $authenticate->guard(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /application/libraries/MyAPI.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class MyAPI { 12 | 13 | private static $_instance = NULL; 14 | private static $_supported_formats = array( 15 | 'json' => 'application/json', 16 | 'xml' => 'application/xml' 17 | ); 18 | private static $_options = array( 19 | 'base_url' => '', 20 | 'api_key' => '', 21 | 'data_type' => 'json', 22 | 'header' => array() 23 | ); 24 | private static $_CURL_OPTS = array( 25 | CURLOPT_CONNECTTIMEOUT => 10, 26 | CURLOPT_RETURNTRANSFER => TRUE, 27 | CURLOPT_TIMEOUT => 60, 28 | CURLOPT_USERAGENT => 'myapi-php-1.0', 29 | ); 30 | 31 | /** 32 | * Create API handler 33 | * @param array $options 34 | * 35 | * Supported values: 36 | * 37 | * array( 38 | * 'base_url' => '', 39 | * 'api_key' => '', 40 | * 'data_type' => 'json', 41 | * 'header' => array() 42 | * ) 43 | * 44 | * @return MyAPI MyAPI instance 45 | */ 46 | static function create($options = array()) { 47 | $opts = array_merge(self::$_options, $options); 48 | 49 | $header = $opts['header']; 50 | $header['api-key'] = $opts['api_key']; 51 | 52 | $headers = array(); 53 | 54 | foreach ($header as $key => $value) { 55 | $headers[] = "$key: $value"; 56 | } 57 | 58 | $opts['header'] = $headers; 59 | 60 | self::$_options = $opts; 61 | 62 | if (static::$_instance === NULL) { 63 | static::$_instance = new static(); 64 | } 65 | 66 | return static::$_instance; 67 | } 68 | 69 | /** 70 | * Makes an HTTP request. This method can be overridden by subclasses if 71 | * developers want to do fancier things or use something other than curl to 72 | * make the request. 73 | * 74 | * @param string $url The URL to make the request to 75 | * @param array $params The parameters to use for the POST body 76 | * @param string $method Request method: GET, POST, PUT, DELETE, etc 77 | * @param CurlHandler $ch Initialized curl handle 78 | * 79 | * @return string The response text 80 | */ 81 | static function create_request($url, $params, $method = 'GET', $ch = NULL) { 82 | if (!$ch) { 83 | $ch = curl_init(); 84 | } 85 | 86 | $opts = self::$_CURL_OPTS; 87 | $header = self::$_options['header']; 88 | $base_url = self::$_options['base_url']; 89 | $data_type = self::$_options['data_type']; 90 | $accept_types = self::$_supported_formats; 91 | $url = $base_url . $url; 92 | 93 | $header[] = 'Accept: ' . $accept_types[$data_type]; 94 | 95 | $opts[CURLOPT_HTTPHEADER] = $header; 96 | $opts[CURLOPT_CUSTOMREQUEST] = strtoupper($method); 97 | 98 | if ($method === 'GET') { 99 | $url .= (empty($params) ? '' : '?' . http_build_query($params)); 100 | } else { 101 | $opts[CURLOPT_POSTFIELDS] = $params; 102 | } 103 | 104 | $opts[CURLOPT_URL] = $url; 105 | 106 | curl_setopt_array($ch, $opts); 107 | 108 | $result = curl_exec($ch); 109 | 110 | if ($result === FALSE && empty($opts[CURLOPT_IPRESOLVE])) { 111 | $matches = array(); 112 | $regex = '/Failed to connect to ([^:].*): Network is unreachable/'; 113 | 114 | if (preg_match($regex, curl_error($ch), $matches)) { 115 | if (strlen(@inet_pton($matches[1])) === 16) { 116 | custom_error_log('Invalid IPv6 configuration on server, ' . 117 | 'Please disable or get native IPv6 on your server.'); 118 | self::$_CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; 119 | curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 120 | $result = curl_exec($ch); 121 | } 122 | } 123 | } 124 | 125 | if ($result === FALSE) { 126 | $err = new \Exception(implode("\n", array( 127 | 'error_code' => curl_errno($ch), 128 | 'message' => curl_error($ch) 129 | ))); 130 | 131 | curl_close($ch); 132 | 133 | throw $err; 134 | } 135 | 136 | curl_close($ch); 137 | 138 | if ($data_type === 'json') { 139 | $result = json_decode($result, TRUE); 140 | } 141 | 142 | if ($data_type === 'xml') { 143 | $result = json_decode(json_encode(simplexml_load_string($result)), TRUE); 144 | } 145 | 146 | return $result; 147 | } 148 | 149 | /** 150 | * Log data 151 | * @param mixed $msg 152 | */ 153 | function custom_error_log($msg) { 154 | if (php_sapi_name() != 'cli') { 155 | error_log($msg); 156 | } 157 | } 158 | 159 | /** 160 | * GET request 161 | * @param string $url 162 | * @param array $params 163 | * @return mixed Response data 164 | */ 165 | public static function get($url, $params = array(), $cn = NULL) { 166 | return self::create_request($url, $params, 'GET', $cn); 167 | } 168 | 169 | /** 170 | * POST request 171 | * @param string $url 172 | * @param array $params 173 | * @return mixed Response data 174 | */ 175 | public static function post($url, $params = array(), $cn = NULL) { 176 | return self::create_request($url, $params, 'POST', $cn); 177 | } 178 | 179 | /** 180 | * PUT request 181 | * @param string $url 182 | * @param array $params 183 | * @return mixed Response data 184 | */ 185 | public static function put($url, $params = array(), $cn = NULL) { 186 | return self::create_request($url, $params, 'PUT', $cn); 187 | } 188 | 189 | /** 190 | * DELETE request 191 | * @param string $url 192 | * @param array $params 193 | * @return mixed Response data 194 | */ 195 | public static function delete($url, $params = array(), $cn = NULL) { 196 | return self::create_request($url, $params, 'DELETE', $cn); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /application/libraries/MyOAuth2.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | class MyOAuth2 { 16 | 17 | /** 18 | * Create authentication server 19 | * @param array $config 20 | */ 21 | function __construct($config) { 22 | if (!class_exists('OAuth2\Autoloader')) { 23 | require_once APP_VENDOR . DS . 'bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php'; 24 | OAuth2\Autoloader::register(); 25 | } 26 | 27 | if (empty($config)) { 28 | die('OAuth2 Storage settings is not defined'); 29 | } 30 | 31 | $this->storage = new OAuth2\Storage\Pdo(array( 32 | 'dsn' => $config['dsn'], 33 | 'username' => $config['username'], 34 | 'password' => $config['password'] 35 | )); 36 | $this->server = new OAuth2\Server($this->storage, array('allow_implicit' => TRUE)); 37 | $this->request = OAuth2\Request::createFromGlobals(); 38 | $this->response = new OAuth2\Response(); 39 | } 40 | 41 | /** 42 | * Return OAuth2\Server 43 | * @return OAuth2\Server 44 | */ 45 | function server() { 46 | return $this->server; 47 | } 48 | 49 | /** 50 | * Get access_token data by access_token 51 | * @param string $access_token 52 | * @return array 53 | */ 54 | function get_access_token($access_token) { 55 | return $this->storage->getAccessToken($access_token); 56 | } 57 | 58 | /** 59 | * Get client details by client_id 60 | * @param string $client_id 61 | * @return array 62 | */ 63 | function get_client_details($client_id) { 64 | return $this->storage->getClientDetails($client_id); 65 | } 66 | 67 | /** 68 | * Get client details by access_token 69 | * @param string $access_token 70 | * @return array 71 | */ 72 | function get_client_details_by_access_token($access_token) { 73 | $client_data = NULL; 74 | $access_token_details = $this->get_access_token($access_token); 75 | 76 | if (!empty($access_token_details)) { 77 | $client_id = $access_token_details['client_id']; 78 | $client_data = $this->get_client_details($client_id); 79 | } 80 | 81 | return $client_data; 82 | } 83 | 84 | /** 85 | * Get Client details data by incoming request 86 | * @return array 87 | */ 88 | function get_client_details_by_request() { 89 | $headers = $this->request->headers; 90 | $access_token = NULL; 91 | $client_data = NULL; 92 | 93 | if (!empty($headers) && isset($headers['AUTHORIZATION'])) { 94 | $access_token = trim(str_replace('Bearer ', '', $headers['AUTHORIZATION'])); 95 | } else { 96 | $query = $this->request->query; 97 | 98 | if (!empty($query) && isset($query['access_token'])) { 99 | $access_token = trim($query['access_token']); 100 | } 101 | } 102 | 103 | if (!empty($access_token)) { 104 | $client_data = $this->get_client_details_by_access_token($access_token); 105 | } 106 | 107 | return $client_data; 108 | } 109 | 110 | /** 111 | * Authentication for resources 112 | * http://bshaffer.github.io/oauth2-server-php-docs/controllers/resource/ 113 | * 114 | * @param string $format Data format 115 | */ 116 | function authentication_resource($format) { 117 | if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { 118 | $response = $this->server->getResponse(); 119 | $response->setParameters(array( 120 | 'message' => 'Requires authentication' 121 | )); 122 | $response->send($format); 123 | exit; 124 | } 125 | } 126 | 127 | /** 128 | * The client uses their credentials to retrieve an access token directly, 129 | * which allows access to resources under the client’s control. 130 | * http://bshaffer.github.io/oauth2-server-php-docs/grant-types/client-credentials/ 131 | */ 132 | public function client_credentials($format) { 133 | $this->request->request['grant_type'] = 'client_credentials'; 134 | $this->server->addGrantType(new OAuth2\GrantType\ClientCredentials($this->storage, array( 135 | 'allow_credentials_in_request_body' => FALSE 136 | ))); 137 | $this->server->handleTokenRequest($this->request)->send($format); 138 | } 139 | 140 | /** 141 | * A Resource Owner’s username and password are submitted as part of 142 | * the request, and a token is issued upon successful authentication. 143 | * http://bshaffer.github.io/oauth2-server-php-docs/grant-types/user-credentials/ 144 | */ 145 | public function password_credentials() { 146 | $users = array('user' => array('password' => '1234', 'first_name' => 'John', 'last_name' => 'Doe')); 147 | $storage = new OAuth2\Storage\Memory(array('user_credentials' => $users)); 148 | $this->server->addGrantType(new OAuth2\GrantType\UserCredentials($storage)); 149 | $this->server->handleTokenRequest($this->request)->send(); 150 | } 151 | 152 | /** 153 | * The client can submit a refresh token and recieve 154 | * a new access token if the access token had expired. 155 | * http://bshaffer.github.io/oauth2-server-php-docs/grant-types/refresh-token/ 156 | */ 157 | public function refresh_token() { 158 | $this->server->addGrantType(new \OAuth2\GrantType\RefreshToken($this->storage, array( 159 | 'always_issue_new_refresh_token' => TRUE, 160 | 'unset_refresh_token_after_use' => TRUE, 161 | 'refresh_token_lifetime' => 2419200, 162 | ))); 163 | $this->server->handleTokenRequest($this->request)->send(); 164 | } 165 | 166 | /** 167 | * Limit scpoe here 168 | * @param $scope = "node file userinfo" 169 | */ 170 | public function require_scope($scope = '') { 171 | if (!$this->server->verifyResourceRequest($this->request, $this->response, $scope)) { 172 | $this->server->getResponse()->send(); 173 | exit; 174 | } 175 | } 176 | 177 | public function check_client_id() { 178 | if (!$this->server->validateAuthorizeRequest($this->request, $this->response)) { 179 | $this->response->send(); 180 | exit; 181 | } 182 | } 183 | 184 | public function authorize($is_authorized) { 185 | $this->server->addGrantType(new OAuth2\GrantType\AuthorizationCode($this->storage)); 186 | $this->server->handleAuthorizeRequest($this->request, $this->response, $is_authorized); 187 | if ($is_authorized) { 188 | $code = substr($this->response->getHttpHeader('Location'), strpos($this->response->getHttpHeader('Location'), 'code=') + 5, 40); 189 | header("Location: " . $this->response->getHttpHeader('Location')); 190 | } 191 | $this->response->send(); 192 | } 193 | 194 | public function authorization_code() { 195 | $this->server->addGrantType(new OAuth2\GrantType\AuthorizationCode($this->storage)); 196 | $this->server->handleTokenRequest($this->request)->send(); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /application/libraries/RESTful.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class RESTful { 15 | 16 | protected $request; 17 | protected $response; 18 | protected $oauth; 19 | private $_supported_formats = array( 20 | 'json' => 'application/json', 21 | 'xml' => 'application/xml' 22 | ); 23 | 24 | function __construct($params) { 25 | $this->load = $params['load']; 26 | $this->input = $params['input']; 27 | $this->router = $params['router']; 28 | $this->request = $params['request']; 29 | $this->response = $params['response']; 30 | 31 | $this->process_restful_request(); 32 | } 33 | 34 | /** 35 | * Process incoming RESTful request 36 | */ 37 | private function process_restful_request() { 38 | $method = $this->validate_restful_method(); 39 | 40 | if ($method) { 41 | $format = $this->get_content_type_format(); 42 | $uri_format = NULL; 43 | 44 | if (!$format) { 45 | $format = 'json'; 46 | $uri_format = $this->get_content_type_query_format(); 47 | } 48 | 49 | if ($uri_format) { 50 | $format = $uri_format; 51 | } 52 | 53 | $this->response->set_default_format($format); 54 | 55 | $this->process_api_request(); 56 | 57 | if ($this->request->method() !== $method) { 58 | $this->response->method_not_allowed(); 59 | $this->response->send(array( 60 | 'message' => 'Method not allowed.' 61 | )); 62 | } 63 | } 64 | } 65 | 66 | /** 67 | * Process incoming API request 68 | */ 69 | private function process_api_request() { 70 | if ($this->validate_api_class()) { 71 | if (!defined('RESTFUL_API_KEY')) { 72 | $this->response->unauthorized(); 73 | $this->response->send(array( 74 | 'message' => 'API key is not exists.' 75 | )); 76 | } 77 | 78 | if (!$this->is_valid_api_key()) { 79 | $this->response->unauthorized(); 80 | $this->response->send(array( 81 | 'message' => 'API key is not valid.' 82 | )); 83 | } 84 | 85 | $this->oauth_api_processing(); 86 | } 87 | } 88 | 89 | /** 90 | * Checks if API-KEY is valid 91 | * @return bool 92 | */ 93 | private function is_valid_api_key() { 94 | $api_key = $this->input->server('HTTP_API_KEY'); 95 | return ($api_key === RESTFUL_API_KEY); 96 | } 97 | 98 | /** 99 | * Validate if incoming function is a valid RESTful method. 100 | * @return string | NULL 101 | */ 102 | function validate_restful_method() { 103 | $match = array(); 104 | $method = $this->router->fetch_method(); 105 | $request_method = NULL; 106 | 107 | preg_match('/(.+)\_(get|post|put|delete)$/', $method, $match); 108 | 109 | if (!empty($match)) { 110 | $request_method = $match[2]; 111 | } 112 | 113 | return $request_method; 114 | } 115 | 116 | /** 117 | * Validate if incoming controller is a valid API Controller. 118 | * @return string | NULL 119 | */ 120 | function validate_api_class() { 121 | $match = array(); 122 | $class = $this->router->fetch_class(); 123 | $request_method = NULL; 124 | 125 | preg_match('/(.+)\_(api\_controller)$/', $class, $match); 126 | 127 | if (!empty($match)) { 128 | $request_method = $match[2]; 129 | } 130 | 131 | return $request_method; 132 | } 133 | 134 | /** 135 | * Get the format value in query string. 136 | * @return string | NULL 137 | */ 138 | function get_content_type_query_format() { 139 | $format = NULL; 140 | $uri_format = trim($this->request->get('format')); 141 | $query_format = filter_var($uri_format, FILTER_SANITIZE_STRING); 142 | 143 | if (!empty($query_format) && array_key_exists($query_format, $this->_supported_formats)) { 144 | $format = $query_format; 145 | } 146 | 147 | return $format; 148 | } 149 | 150 | /** 151 | * Get incoming Content-Type value in header. 152 | * @return string | NULL 153 | */ 154 | private function get_content_type_format() { 155 | $content_type = $this->input->server('HTTP_ACCEPT'); 156 | 157 | foreach ($this->_supported_formats as $key => $value) { 158 | if (strpos($content_type, ';') !== FALSE) { 159 | $content_type = current(explode(';', $content_type)); 160 | } 161 | 162 | if ($content_type === $value) { 163 | return $key; 164 | } 165 | } 166 | 167 | return NULL; 168 | } 169 | 170 | /** 171 | * OAuth2 API processing request 172 | */ 173 | private function oauth_api_processing() { 174 | require APP_LIBRARIES . DS . 'MyOAuth2.php'; 175 | 176 | $config = $this->load->config('oauth2', TRUE); 177 | $config_storage = $config['storage']; 178 | $config_ignore = $config['ignore']; 179 | 180 | $this->oauth = new MyOAuth2($config_storage); 181 | 182 | $class_name = $this->router->fetch_class(); 183 | $method_name = $this->router->fetch_method(); 184 | 185 | if (empty($config_ignore) || !in_array("$class_name/$method_name", $config_ignore)) { 186 | $format = $this->response->get_default_format(); 187 | $this->oauth->authentication_resource($format); 188 | } 189 | } 190 | 191 | /** 192 | * Return MyOAuth2 instance 193 | * @return MyOAuth2 194 | */ 195 | function get_oauth() { 196 | return $this->oauth; 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /application/libraries/Request.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Request { 11 | 12 | protected $load; 13 | protected $input; 14 | 15 | public function __construct($params) { 16 | $this->load = $params['load']; 17 | $this->input = $params['input']; 18 | } 19 | 20 | /** 21 | * Returns GET data 22 | * @param string $key 23 | * @return mixed 24 | */ 25 | function get($key = NULL) { 26 | return $this->request_data('get', $key); 27 | } 28 | 29 | /** 30 | * Returns POST data 31 | * @param string $key 32 | * @return mixed 33 | */ 34 | function post($key = NULL) { 35 | return $this->request_data('post', $key); 36 | } 37 | 38 | /** 39 | * Returns PUT data 40 | * @param string $key 41 | * @return mixed 42 | */ 43 | function put($key = NULL) { 44 | return $this->request_data('put', $key); 45 | } 46 | 47 | /** 48 | * Returns DELETE data 49 | * @param string $key 50 | * @return mixed 51 | */ 52 | function delete($key = NULL) { 53 | return $this->request_data('delete', $key); 54 | } 55 | 56 | /** 57 | * If GET request 58 | * @return bool 59 | */ 60 | function is_get() { 61 | return ($this->method() === 'get'); 62 | } 63 | 64 | /** 65 | * If POST request 66 | * @return bool 67 | */ 68 | function is_post() { 69 | return ($this->method() === 'post'); 70 | } 71 | 72 | /** 73 | * If PUT request 74 | * @return bool 75 | */ 76 | function is_put() { 77 | return ($this->method() === 'put'); 78 | } 79 | 80 | /** 81 | * If DELETE request 82 | * @return bool 83 | */ 84 | function is_delete() { 85 | return ($this->method() === 'delete'); 86 | } 87 | 88 | /** 89 | * Get HTTP data by specific methods 90 | * @param string $method GET, POST, PUT and DELETE 91 | * @param mixed $key 92 | * @return mixed 93 | */ 94 | private function request_data($method, $key = NULL) { 95 | $values = NULL; 96 | 97 | switch ($method) { 98 | case 'get': 99 | if ($this->is_get()) { 100 | $values = $this->input->get($key); 101 | } 102 | 103 | break; 104 | case 'post': 105 | if ($this->is_post()) { 106 | $values = $this->input->post($key); 107 | } 108 | 109 | break; 110 | case 'put': 111 | if ($this->is_put()) { 112 | $values = $this->raw_request_data($key); 113 | break; 114 | } 115 | 116 | break; 117 | case 'delete': 118 | if ($this->is_delete()) { 119 | $values = $this->raw_request_data($key); 120 | } 121 | 122 | break; 123 | } 124 | 125 | return $values; 126 | } 127 | 128 | /** 129 | * Get raw request data 130 | * @param mixed $key 131 | * @return mixed 132 | */ 133 | private function raw_request_data($key) { 134 | $values = $this->parse_raw_http_request(); 135 | 136 | if (!empty($key)) { 137 | $values = isset($values[$key]) ? $values[$key] : NULL; 138 | } 139 | 140 | return $values; 141 | } 142 | 143 | /** 144 | * Parse raw HTTP request data 145 | * http://www.chlab.ch/blog/archives/php/manually-parse-raw-http-data-php 146 | * 147 | * Pass in $a_data as an array. This is done by reference to avoid copying 148 | * the data around too much. 149 | * 150 | * Any files found in the request will be added by their field name to the 151 | * $data['files'] array. 152 | * 153 | * @param array Empty array to fill with data 154 | * @return array Associative array of request data 155 | */ 156 | function parse_raw_http_request() { 157 | $a_data = array(); 158 | // read incoming data 159 | $input = file_get_contents('php://input'); 160 | 161 | $matches = array(); 162 | // grab multipart boundary from content type header 163 | preg_match('/boundary=(.*)$/', $this->input->server('CONTENT_TYPE'), $matches); 164 | 165 | // content type is probably regular form-encoded 166 | if (!count($matches)) { 167 | // we expect regular puts to containt a query string containing data 168 | parse_str(urldecode($input), $a_data); 169 | return $a_data; 170 | } 171 | 172 | $boundary = $matches[1]; 173 | 174 | // split content by boundary and get rid of last -- element 175 | $a_blocks = preg_split("/-+$boundary/", $input); 176 | array_pop($a_blocks); 177 | 178 | // loop data blocks 179 | foreach ($a_blocks as $block) { 180 | if (empty($block)) { 181 | continue; 182 | } 183 | 184 | // you'll have to var_dump $block to understand this and maybe replace \n or \r with a visibile char 185 | // parse uploaded files 186 | if (strpos($block, 'application/octet-stream') !== FALSE) { 187 | // match "name", then everything after "stream" (optional) except for prepending newlines 188 | preg_match("/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s", $block, $matches); 189 | $a_data['files'][$matches[1]] = $matches[2]; 190 | } 191 | // parse all other fields 192 | else { 193 | if (strpos($block, 'filename') !== FALSE) { 194 | $mime = array(); 195 | // match "name" and optional value in between newline sequences 196 | preg_match('/name=\"([^\"]*)\"; filename=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s', $block, $matches); 197 | preg_match('/Content-Type: (.*)?/', $matches[3], $mime); 198 | 199 | // match the mime type supplied from the browser 200 | $image = preg_replace('/Content-Type: (.*)[^\n\r]/', '', $matches[3]); 201 | 202 | // get current system path and create tempory file name & path 203 | $path = sys_get_temp_dir() . '/php' . substr(sha1(rand()), 0, 6); 204 | 205 | // write temporary file to emulate $_FILES super global 206 | $err = file_put_contents($path, $image); 207 | 208 | $tmp = array(); 209 | // Did the user use the infamous <input name="array[]" for multiple file uploads? 210 | if (preg_match('/^(.*)\[\]$/i', $matches[1], $tmp)) { 211 | $a_data[$tmp[1]]['name'][] = $matches[2]; 212 | } else { 213 | $a_data[$matches[1]]['name'][] = $matches[2]; 214 | } 215 | 216 | // Create the remainder of the $_FILES super global 217 | $a_data[$tmp[1]]['type'][] = $mime[1]; 218 | $a_data[$tmp[1]]['tmp_name'][] = $path; 219 | $a_data[$tmp[1]]['error'][] = ($err === FALSE) ? $err : 0; 220 | $a_data[$tmp[1]]['size'][] = filesize($path); 221 | } else { 222 | // match "name" and optional value in between newline sequences 223 | preg_match('/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s', $block, $matches); 224 | 225 | if (preg_match('/^(.*)\[\]$/i', $matches[1], $tmp)) { 226 | $a_data[$tmp[1]][] = $matches[2]; 227 | } else { 228 | $a_data[$matches[1]] = $matches[2]; 229 | } 230 | } 231 | } 232 | } 233 | 234 | return $a_data; 235 | } 236 | 237 | /** 238 | * Get REQUEST_METHOD like GET, PUT, POST, DELETE, PATCH, etc. 239 | * @return string 240 | */ 241 | function method() { 242 | return strtolower($this->input->server('REQUEST_METHOD')); 243 | } 244 | 245 | } 246 | -------------------------------------------------------------------------------- /application/libraries/Response.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Response { 11 | 12 | private $_default_format = 'json'; 13 | 14 | /** 15 | * JSON format response 16 | * @param mixed $data 17 | */ 18 | function json($data) { 19 | $json = json_encode($data); 20 | 21 | if ($json === FALSE) { 22 | $json = json_encode(array('jsonError', json_last_error_msg())); 23 | 24 | if ($json === FALSE) { 25 | $json = '{"jsonError": "unknown"}'; 26 | } 27 | } 28 | 29 | header('Content-Type: application/json; charset=utf-8'); 30 | echo $json; 31 | } 32 | 33 | /** 34 | * XML format response 35 | * @param mixed $data 36 | */ 37 | function xml($data) { 38 | header('Content-Type: application/xml; charset=utf-8'); 39 | echo $this->to_xml($data); 40 | } 41 | 42 | function to_xml($data, $basenode = 'response', $xml = null) { 43 | // turn off compatibility mode as simple xml throws a wobbly if you don't. 44 | if (ini_get('zend.ze1_compatibility_mode') == 1) { 45 | ini_set('zend.ze1_compatibility_mode', 0); 46 | } 47 | 48 | if ($xml == null) { 49 | $xml = simplexml_load_string("<$basenode />"); 50 | } 51 | 52 | // loop through the data passed in. 53 | foreach ($data as $key => $value) { 54 | // no numeric keys in our xml please! 55 | if (is_numeric($key)) { 56 | // make string key... 57 | $key = "item_" . (string) $key; 58 | } 59 | 60 | // replace anything not alpha numeric 61 | $key = preg_replace('/[^a-z]/i', '', $key); 62 | 63 | // if there is another array found recrusively call this function 64 | if (is_array($value)) { 65 | $node = $xml->addChild($key); 66 | // recrusive call. 67 | $this->to_xml($value, $basenode, $node); 68 | } else { 69 | // add single node. 70 | $value = htmlentities($value); 71 | $xml->addChild($key, $value); 72 | } 73 | } 74 | // pass back as string. or simple xml object if you want! 75 | return $xml->asXML(); 76 | } 77 | 78 | /** 79 | * Send data by default format 80 | * @param array $data 81 | */ 82 | function send($data) { 83 | $this->{$this->_default_format}($data); 84 | exit; 85 | } 86 | 87 | /** 88 | * Set the default output format 89 | * @param string $format json, xml and html 90 | * @param string $format 91 | */ 92 | function set_default_format($format) { 93 | $this->_default_format = $format; 94 | } 95 | 96 | /** 97 | * Get the default output format 98 | * @param string $format 99 | */ 100 | function get_default_format() { 101 | return $this->_default_format; 102 | } 103 | 104 | function forbidden() { 105 | $this->status(403, 'HTTP/1.1 403 Forbidden'); 106 | } 107 | 108 | function not_found() { 109 | $this->status(404, 'HTTP/1.1 404 Not Found'); 110 | } 111 | 112 | function ok() { 113 | $this->status(200, 'HTTP/1.1 200 OK'); 114 | } 115 | 116 | function bad_request() { 117 | $this->status(400, 'HTTP/1.1 400 Bad Request'); 118 | } 119 | 120 | function method_not_allowed() { 121 | $this->status(405, 'HTTP/1.1 405 Method Not Allowed'); 122 | } 123 | 124 | function service_unavailable() { 125 | $this->status(503, 'HTTP/1.1 503 Service Unavailable'); 126 | } 127 | 128 | function internal_server_error() { 129 | $this->status(500, 'HTTP/1.1 500 Internal Server Error'); 130 | } 131 | 132 | function unauthorized() { 133 | $this->status(401, 'HTTP/1.1 401 Unauthorized'); 134 | } 135 | 136 | function request_timeout() { 137 | $this->status(408, 'HTTP/1.1 408 Request Timeout'); 138 | } 139 | 140 | private function status($code, $msg = '') { 141 | header($msg, TRUE, $code); 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /application/libraries/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/logs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/models/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/models/welcome_model.php: -------------------------------------------------------------------------------- 1 | response->get_default_format(); 19 | $this->oauth->client_credentials($format); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /application/modules/oauth2/controllers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/modules/user/config/routes.php: -------------------------------------------------------------------------------- 1 | load->model('User_model'); 16 | } 17 | 18 | /** 19 | * Get one specific user by id. 20 | * GET /v1/user/[:id] 21 | * @param int $id 22 | */ 23 | function one_get($id) { 24 | $user = $this->User_model->find_one_by_id($id); 25 | $this->response->send($user); 26 | } 27 | 28 | /** 29 | * Get all users. 30 | * GET /v1/user 31 | */ 32 | function all_get() { 33 | $users = $this->User_model->find_all(); 34 | $this->response->send($users); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /application/modules/user/controllers/User_controller.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * @see http://codeigniter.com/user_guide/general/urls.html 19 | */ 20 | function index_get() { 21 | $this->load->model('User_model'); 22 | 23 | $users = $this->User_model->find_all(); 24 | $this->response->output($users); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /application/modules/user/controllers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/modules/user/models/User_model.php: -------------------------------------------------------------------------------- 1 | find()->toArray(); 20 | } catch (PropelException $e) { 21 | return; 22 | } 23 | } 24 | 25 | /** 26 | * Find one user by primary key 27 | * @return array 28 | */ 29 | function find_one_by_id($id) { 30 | try { 31 | $data = array(); 32 | $user = UserQuery::create()->findPk($id); 33 | 34 | if ($user) { 35 | $data = $user->toArray(); 36 | } 37 | 38 | return $data; 39 | } catch (PropelException $e) { 40 | return; 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /application/modules/user/views/User_view.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | Welcome to User Module 8 | 9 | 71 | 72 | 73 | 74 |
75 | 76 |

User Module

77 | 78 | 79 |
80 |

Module directory:

81 | 82 |
 83 | application/modules
 84 | │
 85 | └── user
 86 |     ├── config
 87 |     │   └── routes.php
 88 |     ├── controllers
 89 |     │   └── User_controller.php
 90 |     ├── models
 91 |     │   └── User_model.php
 92 |     └── views
 93 |         └── User_message.php
 94 | 
95 | 96 |

User Model

97 | 98 |
 99 | // User_controller.php  
100 | $this->User_model->find_all();
101 | 
102 | Records from database: 103 | 104 |
    105 | {users} 106 |
  1. {UserFullname} ({UserEmail})
  2. 107 | {/users} 108 |
109 |
110 | 111 | 115 |
116 | 117 | 118 | -------------------------------------------------------------------------------- /application/third_party/MX/Base.php: -------------------------------------------------------------------------------- 1 | is_loaded, TRUE)) return $this->item($file); 41 | 42 | $_module OR $_module = CI::$APP->router->fetch_module(); 43 | list($path, $file) = Modules::find($file, $_module, 'config/'); 44 | 45 | if ($path === FALSE) 46 | { 47 | parent::load($file, $use_sections, $fail_gracefully); 48 | return $this->item($file); 49 | } 50 | 51 | if ($config = Modules::load_file($file, $path, 'config')) 52 | { 53 | /* reference to the config array */ 54 | $current_config =& $this->config; 55 | 56 | if ($use_sections === TRUE) 57 | { 58 | if (isset($current_config[$file])) 59 | { 60 | $current_config[$file] = array_merge($current_config[$file], $config); 61 | } 62 | else 63 | { 64 | $current_config[$file] = $config; 65 | } 66 | 67 | } 68 | else 69 | { 70 | $current_config = array_merge($current_config, $config); 71 | } 72 | 73 | $this->is_loaded[] = $file; 74 | unset($config); 75 | return $this->item($file); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /application/third_party/MX/Controller.php: -------------------------------------------------------------------------------- 1 | config->item('controller_suffix'), '', get_class($this)); 46 | log_message('debug', $class." MX_Controller Initialized"); 47 | Modules::$registry[strtolower($class)] = $this; 48 | 49 | /* copy a loader instance and initialize */ 50 | $this->load = clone load_class('Loader'); 51 | $this->load->initialize($this); 52 | 53 | /* autoload module items */ 54 | $this->load->_autoloader($this->autoload); 55 | } 56 | 57 | public function __get($class) 58 | { 59 | return CI::$APP->$class; 60 | } 61 | } -------------------------------------------------------------------------------- /application/third_party/MX/Lang.php: -------------------------------------------------------------------------------- 1 | load($_lang); 43 | return $this->language; 44 | } 45 | 46 | $deft_lang = CI::$APP->config->item('language'); 47 | $idiom = ($lang == '') ? $deft_lang : $lang; 48 | 49 | if (in_array($langfile.'_lang'.EXT, $this->is_loaded, TRUE)) 50 | return $this->language; 51 | 52 | $_module OR $_module = CI::$APP->router->fetch_module(); 53 | list($path, $_langfile) = Modules::find($langfile.'_lang', $_module, 'language/'.$idiom.'/'); 54 | 55 | if ($path === FALSE) 56 | { 57 | if ($lang = parent::load($langfile, $lang, $return, $add_suffix, $alt_path)) return $lang; 58 | 59 | } 60 | else 61 | { 62 | if($lang = Modules::load_file($_langfile, $path, 'lang')) 63 | { 64 | if ($return) return $lang; 65 | $this->language = array_merge($this->language, $lang); 66 | $this->is_loaded[] = $langfile.'_lang'.EXT; 67 | unset($lang); 68 | } 69 | } 70 | 71 | return $this->language; 72 | } 73 | } -------------------------------------------------------------------------------- /application/third_party/MX/Loader.php: -------------------------------------------------------------------------------- 1 | _module = CI::$APP->router->fetch_module(); 48 | 49 | if ($controller instanceof MX_Controller) 50 | { 51 | /* reference to the module controller */ 52 | $this->controller = $controller; 53 | 54 | /* references to ci loader variables */ 55 | foreach (get_class_vars('CI_Loader') as $var => $val) 56 | { 57 | if ($var != '_ci_ob_level') 58 | { 59 | $this->$var =& CI::$APP->load->$var; 60 | } 61 | } 62 | } 63 | else 64 | { 65 | parent::initialize(); 66 | 67 | /* autoload module items */ 68 | $this->_autoloader(array()); 69 | } 70 | 71 | /* add this module path to the loader variables */ 72 | $this->_add_module_paths($this->_module); 73 | } 74 | 75 | /** Add a module path loader variables **/ 76 | public function _add_module_paths($module = '') 77 | { 78 | if (empty($module)) return; 79 | 80 | foreach (Modules::$locations as $location => $offset) 81 | { 82 | /* only add a module path if it exists */ 83 | if (is_dir($module_path = $location.$module.'/') && ! in_array($module_path, $this->_ci_model_paths)) 84 | { 85 | array_unshift($this->_ci_model_paths, $module_path); 86 | } 87 | } 88 | } 89 | 90 | /** Load a module config file **/ 91 | public function config($file, $use_sections = FALSE, $fail_gracefully = FALSE) 92 | { 93 | return CI::$APP->config->load($file, $use_sections, $fail_gracefully, $this->_module); 94 | } 95 | 96 | /** Load the database drivers **/ 97 | public function database($params = '', $return = FALSE, $query_builder = NULL) 98 | { 99 | if ($return === FALSE && $query_builder === NULL && 100 | isset(CI::$APP->db) && is_object(CI::$APP->db) && ! empty(CI::$APP->db->conn_id)) 101 | { 102 | return FALSE; 103 | } 104 | 105 | require_once BASEPATH.'database/DB'.EXT; 106 | 107 | if ($return === TRUE) return DB($params, $query_builder); 108 | 109 | CI::$APP->db = DB($params, $query_builder); 110 | 111 | return $this; 112 | } 113 | 114 | /** Load a module helper **/ 115 | public function helper($helper = array()) 116 | { 117 | if (is_array($helper)) return $this->helpers($helper); 118 | 119 | if (isset($this->_ci_helpers[$helper])) return; 120 | 121 | list($path, $_helper) = Modules::find($helper.'_helper', $this->_module, 'helpers/'); 122 | 123 | if ($path === FALSE) return parent::helper($helper); 124 | 125 | Modules::load_file($_helper, $path); 126 | $this->_ci_helpers[$_helper] = TRUE; 127 | return $this; 128 | } 129 | 130 | /** Load an array of helpers **/ 131 | public function helpers($helpers = array()) 132 | { 133 | foreach ($helpers as $_helper) $this->helper($_helper); 134 | return $this; 135 | } 136 | 137 | /** Load a module language file **/ 138 | public function language($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') 139 | { 140 | CI::$APP->lang->load($langfile, $idiom, $return, $add_suffix, $alt_path, $this->_module); 141 | return $this; 142 | } 143 | 144 | public function languages($languages) 145 | { 146 | foreach($languages as $_language) $this->language($_language); 147 | return $this; 148 | } 149 | 150 | /** Load a module library **/ 151 | public function library($library, $params = NULL, $object_name = NULL) 152 | { 153 | if (is_array($library)) return $this->libraries($library); 154 | 155 | $class = strtolower(basename($library)); 156 | 157 | if (isset($this->_ci_classes[$class]) && $_alias = $this->_ci_classes[$class]) 158 | return $this; 159 | 160 | ($_alias = strtolower($object_name)) OR $_alias = $class; 161 | 162 | list($path, $_library) = Modules::find($library, $this->_module, 'libraries/'); 163 | 164 | /* load library config file as params */ 165 | if ($params == NULL) 166 | { 167 | list($path2, $file) = Modules::find($_alias, $this->_module, 'config/'); 168 | ($path2) && $params = Modules::load_file($file, $path2, 'config'); 169 | } 170 | 171 | if ($path === FALSE) 172 | { 173 | $this->_ci_load_library($library, $params, $object_name); 174 | } 175 | else 176 | { 177 | Modules::load_file($_library, $path); 178 | 179 | $library = ucfirst($_library); 180 | CI::$APP->$_alias = new $library($params); 181 | 182 | $this->_ci_classes[$class] = $_alias; 183 | } 184 | return $this; 185 | } 186 | 187 | /** Load an array of libraries **/ 188 | public function libraries($libraries) 189 | { 190 | foreach ($libraries as $library => $alias) 191 | { 192 | (is_int($library)) ? $this->library($alias) : $this->library($library, NULL, $alias); 193 | } 194 | return $this; 195 | } 196 | 197 | /** Load a module model **/ 198 | public function model($model, $object_name = NULL, $connect = FALSE) 199 | { 200 | if (is_array($model)) return $this->models($model); 201 | 202 | ($_alias = $object_name) OR $_alias = basename($model); 203 | 204 | if (in_array($_alias, $this->_ci_models, TRUE)) 205 | return $this; 206 | 207 | /* check module */ 208 | list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/'); 209 | 210 | if ($path == FALSE) 211 | { 212 | /* check application & packages */ 213 | parent::model($model, $object_name, $connect); 214 | } 215 | else 216 | { 217 | class_exists('CI_Model', FALSE) OR load_class('Model', 'core'); 218 | 219 | if ($connect !== FALSE && ! class_exists('CI_DB', FALSE)) 220 | { 221 | if ($connect === TRUE) $connect = ''; 222 | $this->database($connect, FALSE, TRUE); 223 | } 224 | 225 | Modules::load_file($_model, $path); 226 | 227 | $model = ucfirst($_model); 228 | CI::$APP->$_alias = new $model(); 229 | 230 | $this->_ci_models[] = $_alias; 231 | } 232 | return $this; 233 | } 234 | 235 | /** Load an array of models **/ 236 | public function models($models) 237 | { 238 | foreach ($models as $model => $alias) 239 | { 240 | (is_int($model)) ? $this->model($alias) : $this->model($model, $alias); 241 | } 242 | return $this; 243 | } 244 | 245 | /** Load a module controller **/ 246 | public function module($module, $params = NULL) 247 | { 248 | if (is_array($module)) return $this->modules($module); 249 | 250 | $_alias = strtolower(basename($module)); 251 | CI::$APP->$_alias = Modules::load(array($module => $params)); 252 | return $this; 253 | } 254 | 255 | /** Load an array of controllers **/ 256 | public function modules($modules) 257 | { 258 | foreach ($modules as $_module) $this->module($_module); 259 | return $this; 260 | } 261 | 262 | /** Load a module plugin **/ 263 | public function plugin($plugin) 264 | { 265 | if (is_array($plugin)) return $this->plugins($plugin); 266 | 267 | if (isset($this->_ci_plugins[$plugin])) 268 | return $this; 269 | 270 | list($path, $_plugin) = Modules::find($plugin.'_pi', $this->_module, 'plugins/'); 271 | 272 | if ($path === FALSE && ! is_file($_plugin = APPPATH.'plugins/'.$_plugin.EXT)) 273 | { 274 | show_error("Unable to locate the plugin file: {$_plugin}"); 275 | } 276 | 277 | Modules::load_file($_plugin, $path); 278 | $this->_ci_plugins[$plugin] = TRUE; 279 | return $this; 280 | } 281 | 282 | /** Load an array of plugins **/ 283 | public function plugins($plugins) 284 | { 285 | foreach ($plugins as $_plugin) $this->plugin($_plugin); 286 | return $this; 287 | } 288 | 289 | /** Load a module view **/ 290 | public function view($view, $vars = array(), $return = FALSE) 291 | { 292 | list($path, $_view) = Modules::find($view, $this->_module, 'views/'); 293 | 294 | if ($path != FALSE) 295 | { 296 | $this->_ci_view_paths = array($path => TRUE) + $this->_ci_view_paths; 297 | $view = $_view; 298 | } 299 | 300 | return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); 301 | } 302 | 303 | protected function &_ci_get_component($component) 304 | { 305 | return CI::$APP->$component; 306 | } 307 | 308 | public function __get($class) 309 | { 310 | return (isset($this->controller)) ? $this->controller->$class : CI::$APP->$class; 311 | } 312 | 313 | public function _ci_load($_ci_data) 314 | { 315 | extract($_ci_data); 316 | 317 | if (isset($_ci_view)) 318 | { 319 | $_ci_path = ''; 320 | 321 | /* add file extension if not provided */ 322 | $_ci_file = (pathinfo($_ci_view, PATHINFO_EXTENSION)) ? $_ci_view : $_ci_view.EXT; 323 | 324 | foreach ($this->_ci_view_paths as $path => $cascade) 325 | { 326 | if (file_exists($view = $path.$_ci_file)) 327 | { 328 | $_ci_path = $view; 329 | break; 330 | } 331 | if ( ! $cascade) break; 332 | } 333 | } 334 | elseif (isset($_ci_path)) 335 | { 336 | 337 | $_ci_file = basename($_ci_path); 338 | if( ! file_exists($_ci_path)) $_ci_path = ''; 339 | } 340 | 341 | if (empty($_ci_path)) 342 | show_error('Unable to load the requested file: '.$_ci_file); 343 | 344 | if (isset($_ci_vars)) 345 | $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, (array) $_ci_vars); 346 | 347 | extract($this->_ci_cached_vars); 348 | 349 | ob_start(); 350 | 351 | if ((bool) @ini_get('short_open_tag') === FALSE && CI::$APP->config->item('rewrite_short_tags') == TRUE) 352 | { 353 | echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' $this->_ci_ob_level + 1) 365 | { 366 | ob_end_flush(); 367 | } 368 | else 369 | { 370 | CI::$APP->output->append_output(ob_get_clean()); 371 | } 372 | } 373 | 374 | /** Autoload module items **/ 375 | public function _autoloader($autoload) 376 | { 377 | $path = FALSE; 378 | 379 | if ($this->_module) 380 | { 381 | list($path, $file) = Modules::find('constants', $this->_module, 'config/'); 382 | 383 | /* module constants file */ 384 | if ($path != FALSE) 385 | { 386 | include_once $path.$file.EXT; 387 | } 388 | 389 | list($path, $file) = Modules::find('autoload', $this->_module, 'config/'); 390 | 391 | /* module autoload file */ 392 | if ($path != FALSE) 393 | { 394 | $autoload = array_merge(Modules::load_file($file, $path, 'autoload'), $autoload); 395 | } 396 | } 397 | 398 | /* nothing to do */ 399 | if (count($autoload) == 0) return; 400 | 401 | /* autoload package paths */ 402 | if (isset($autoload['packages'])) 403 | { 404 | foreach ($autoload['packages'] as $package_path) 405 | { 406 | $this->add_package_path($package_path); 407 | } 408 | } 409 | 410 | /* autoload config */ 411 | if (isset($autoload['config'])) 412 | { 413 | foreach ($autoload['config'] as $config) 414 | { 415 | $this->config($config); 416 | } 417 | } 418 | 419 | /* autoload helpers, plugins, languages */ 420 | foreach (array('helper', 'plugin', 'language') as $type) 421 | { 422 | if (isset($autoload[$type])) 423 | { 424 | foreach ($autoload[$type] as $item) 425 | { 426 | $this->$type($item); 427 | } 428 | } 429 | } 430 | 431 | /* autoload database & libraries */ 432 | if (isset($autoload['libraries'])) 433 | { 434 | if (in_array('database', $autoload['libraries'])) 435 | { 436 | /* autoload database */ 437 | if ( ! $db = CI::$APP->config->item('database')) 438 | { 439 | $this->database(); 440 | $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); 441 | } 442 | } 443 | 444 | /* autoload libraries */ 445 | foreach ($autoload['libraries'] as $library => $alias) 446 | { 447 | (is_int($library)) ? $this->library($alias) : $this->library($library, NULL, $alias); 448 | } 449 | } 450 | 451 | /* autoload models */ 452 | if (isset($autoload['model'])) 453 | { 454 | foreach ($autoload['model'] as $model => $alias) 455 | { 456 | (is_int($model)) ? $this->model($alias) : $this->model($model, $alias); 457 | } 458 | } 459 | 460 | /* autoload module controllers */ 461 | if (isset($autoload['modules'])) 462 | { 463 | foreach ($autoload['modules'] as $controller) 464 | { 465 | ($controller != $this->_module) && $this->module($controller); 466 | } 467 | } 468 | } 469 | } 470 | 471 | /** load the CI class for Modular Separation **/ 472 | (class_exists('CI', FALSE)) OR require dirname(__FILE__).'/Ci.php'; -------------------------------------------------------------------------------- /application/third_party/MX/Modules.php: -------------------------------------------------------------------------------- 1 | item('modules_locations')) OR Modules::$locations = array( 9 | APPPATH.'modules/' => '../modules/', 10 | ); 11 | 12 | /* PHP5 spl_autoload */ 13 | spl_autoload_register('Modules::autoload'); 14 | 15 | /** 16 | * Modular Extensions - HMVC 17 | * 18 | * Adapted from the CodeIgniter Core Classes 19 | * @link http://codeigniter.com 20 | * 21 | * Description: 22 | * This library provides functions to load and instantiate controllers 23 | * and module controllers allowing use of modules and the HMVC design pattern. 24 | * 25 | * Install this file as application/third_party/MX/Modules.php 26 | * 27 | * @copyright Copyright (c) 2015 Wiredesignz 28 | * @version 5.5 29 | * 30 | * Permission is hereby granted, free of charge, to any person obtaining a copy 31 | * of this software and associated documentation files (the "Software"), to deal 32 | * in the Software without restriction, including without limitation the rights 33 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 34 | * copies of the Software, and to permit persons to whom the Software is 35 | * furnished to do so, subject to the following conditions: 36 | * 37 | * The above copyright notice and this permission notice shall be included in 38 | * all copies or substantial portions of the Software. 39 | * 40 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 41 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 42 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 43 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 44 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 45 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 46 | * THE SOFTWARE. 47 | **/ 48 | class Modules 49 | { 50 | public static $routes, $registry, $locations; 51 | 52 | /** 53 | * Run a module controller method 54 | * Output from module is buffered and returned. 55 | **/ 56 | public static function run($module) 57 | { 58 | $method = 'index'; 59 | 60 | if(($pos = strrpos($module, '/')) != FALSE) 61 | { 62 | $method = substr($module, $pos + 1); 63 | $module = substr($module, 0, $pos); 64 | } 65 | 66 | if($class = self::load($module)) 67 | { 68 | if (method_exists($class, $method)) { 69 | ob_start(); 70 | $args = func_get_args(); 71 | $output = call_user_func_array(array($class, $method), array_slice($args, 1)); 72 | $buffer = ob_get_clean(); 73 | return ($output !== NULL) ? $output : $buffer; 74 | } 75 | } 76 | 77 | log_message('error', "Module controller failed to run: {$module}/{$method}"); 78 | } 79 | 80 | /** Load a module controller **/ 81 | public static function load($module) 82 | { 83 | (is_array($module)) ? list($module, $params) = each($module) : $params = NULL; 84 | 85 | /* get the requested controller class name */ 86 | $alias = strtolower(basename($module)); 87 | 88 | /* create or return an existing controller from the registry */ 89 | if ( ! isset(self::$registry[$alias])) 90 | { 91 | /* find the controller */ 92 | list($class) = CI::$APP->router->locate(explode('/', $module)); 93 | 94 | /* controller cannot be located */ 95 | if (empty($class)) return; 96 | 97 | /* set the module directory */ 98 | $path = APPPATH.'controllers/'.CI::$APP->router->directory; 99 | 100 | /* load the controller class */ 101 | $class = $class.CI::$APP->config->item('controller_suffix'); 102 | self::load_file(ucfirst($class), $path); 103 | 104 | /* create and register the new controller */ 105 | $controller = ucfirst($class); 106 | self::$registry[$alias] = new $controller($params); 107 | } 108 | 109 | return self::$registry[$alias]; 110 | } 111 | 112 | /** Library base class autoload **/ 113 | public static function autoload($class) 114 | { 115 | /* don't autoload CI_ prefixed classes or those using the config subclass_prefix */ 116 | if (strstr($class, 'CI_') OR strstr($class, config_item('subclass_prefix'))) return; 117 | 118 | /* autoload Modular Extensions MX core classes */ 119 | if (strstr($class, 'MX_')) 120 | { 121 | if (is_file($location = dirname(__FILE__).'/'.substr($class, 3).EXT)) 122 | { 123 | include_once $location; 124 | return; 125 | } 126 | show_error('Failed to load MX core class: '.$class); 127 | } 128 | 129 | /* autoload core classes */ 130 | if(is_file($location = APPPATH.'core/'.ucfirst($class).EXT)) 131 | { 132 | include_once $location; 133 | return; 134 | } 135 | 136 | /* autoload library classes */ 137 | if(is_file($location = APPPATH.'libraries/'.ucfirst($class).EXT)) 138 | { 139 | include_once $location; 140 | return; 141 | } 142 | } 143 | 144 | /** Load a module file **/ 145 | public static function load_file($file, $path, $type = 'other', $result = TRUE) 146 | { 147 | $file = str_replace(EXT, '', $file); 148 | $location = $path.$file.EXT; 149 | 150 | if ($type === 'other') 151 | { 152 | if (class_exists($file, FALSE)) 153 | { 154 | log_message('debug', "File already loaded: {$location}"); 155 | return $result; 156 | } 157 | include_once $location; 158 | } 159 | else 160 | { 161 | /* load config or language array */ 162 | include $location; 163 | 164 | if ( ! isset($$type) OR ! is_array($$type)) 165 | show_error("{$location} does not contain a valid {$type} array"); 166 | 167 | $result = $$type; 168 | } 169 | log_message('debug', "File loaded: {$location}"); 170 | return $result; 171 | } 172 | 173 | /** 174 | * Find a file 175 | * Scans for files located within modules directories. 176 | * Also scans application directories for models, plugins and views. 177 | * Generates fatal error if file not found. 178 | **/ 179 | public static function find($file, $module, $base) 180 | { 181 | $segments = explode('/', $file); 182 | 183 | $file = array_pop($segments); 184 | $file_ext = (pathinfo($file, PATHINFO_EXTENSION)) ? $file : $file.EXT; 185 | 186 | $path = ltrim(implode('/', $segments).'/', '/'); 187 | $module ? $modules[$module] = $path : $modules = array(); 188 | 189 | if ( ! empty($segments)) 190 | { 191 | $modules[array_shift($segments)] = ltrim(implode('/', $segments).'/','/'); 192 | } 193 | 194 | foreach (Modules::$locations as $location => $offset) 195 | { 196 | foreach($modules as $module => $subpath) 197 | { 198 | $fullpath = $location.$module.'/'.$base.$subpath; 199 | 200 | if ($base == 'libraries/' OR $base == 'models/') 201 | { 202 | if(is_file($fullpath.ucfirst($file_ext))) return array($fullpath, ucfirst($file)); 203 | } 204 | else 205 | /* load non-class files */ 206 | if (is_file($fullpath.$file_ext)) return array($fullpath, $file); 207 | } 208 | } 209 | 210 | return array(FALSE, $file); 211 | } 212 | 213 | /** Parse module routes **/ 214 | public static function parse_routes($module, $uri) 215 | { 216 | /* load the route file */ 217 | if ( ! isset(self::$routes[$module])) 218 | { 219 | if (list($path) = self::find('routes', $module, 'config/')) 220 | { 221 | $path && self::$routes[$module] = self::load_file('routes', $path, 'route'); 222 | } 223 | } 224 | 225 | if ( ! isset(self::$routes[$module])) return; 226 | 227 | /* parse module routes */ 228 | foreach (self::$routes[$module] as $key => $val) 229 | { 230 | $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); 231 | 232 | if (preg_match('#^'.$key.'$#', $uri)) 233 | { 234 | if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) 235 | { 236 | $val = preg_replace('#^'.$key.'$#', $val, $uri); 237 | } 238 | return explode('/', $module.'/'.$val); 239 | } 240 | } 241 | } 242 | } -------------------------------------------------------------------------------- /application/third_party/MX/Router.php: -------------------------------------------------------------------------------- 1 | module; 46 | } 47 | 48 | protected function _set_request($segments = array()) 49 | { 50 | if ($this->translate_uri_dashes === TRUE) 51 | { 52 | foreach(range(0, 2) as $v) 53 | { 54 | isset($segments[$v]) && $segments[$v] = str_replace('-', '_', $segments[$v]); 55 | } 56 | } 57 | 58 | $segments = $this->locate($segments); 59 | 60 | if($this->located == -1) 61 | { 62 | $this->_set_404override_controller(); 63 | return; 64 | } 65 | 66 | if(empty($segments)) 67 | { 68 | $this->_set_default_controller(); 69 | return; 70 | } 71 | 72 | $this->set_class($segments[0]); 73 | 74 | if (isset($segments[1])) 75 | { 76 | $this->set_method($segments[1]); 77 | } 78 | else 79 | { 80 | $segments[1] = 'index'; 81 | } 82 | 83 | array_unshift($segments, NULL); 84 | unset($segments[0]); 85 | $this->uri->rsegments = $segments; 86 | } 87 | 88 | protected function _set_404override_controller() 89 | { 90 | $this->_set_module_path($this->routes['404_override']); 91 | } 92 | 93 | protected function _set_default_controller() 94 | { 95 | if (empty($this->directory)) 96 | { 97 | /* set the default controller module path */ 98 | $this->_set_module_path($this->default_controller); 99 | } 100 | 101 | parent::_set_default_controller(); 102 | 103 | if(empty($this->class)) 104 | { 105 | $this->_set_404override_controller(); 106 | } 107 | } 108 | 109 | /** Locate the controller **/ 110 | public function locate($segments) 111 | { 112 | $this->located = 0; 113 | $ext = $this->config->item('controller_suffix').EXT; 114 | 115 | /* use module route if available */ 116 | if (isset($segments[0]) && $routes = Modules::parse_routes($segments[0], implode('/', $segments))) 117 | { 118 | $segments = $routes; 119 | } 120 | 121 | /* get the segments array elements */ 122 | list($module, $directory, $controller) = array_pad($segments, 3, NULL); 123 | 124 | /* check modules */ 125 | foreach (Modules::$locations as $location => $offset) 126 | { 127 | /* module exists? */ 128 | if (is_dir($source = $location.$module.'/controllers/')) 129 | { 130 | $this->module = $module; 131 | $this->directory = $offset.$module.'/controllers/'; 132 | 133 | /* module sub-controller exists? */ 134 | if($directory) 135 | { 136 | /* module sub-directory exists? */ 137 | if(is_dir($source.$directory.'/')) 138 | { 139 | $source .= $directory.'/'; 140 | $this->directory .= $directory.'/'; 141 | 142 | /* module sub-directory controller exists? */ 143 | if($controller) 144 | { 145 | if(is_file($source.ucfirst($controller).$ext)) 146 | { 147 | $this->located = 3; 148 | return array_slice($segments, 2); 149 | } 150 | else $this->located = -1; 151 | } 152 | } 153 | else 154 | if(is_file($source.ucfirst($directory).$ext)) 155 | { 156 | $this->located = 2; 157 | return array_slice($segments, 1); 158 | } 159 | else $this->located = -1; 160 | } 161 | 162 | /* module controller exists? */ 163 | if(is_file($source.ucfirst($module).$ext)) 164 | { 165 | $this->located = 1; 166 | return $segments; 167 | } 168 | } 169 | } 170 | 171 | if( ! empty($this->directory)) return; 172 | 173 | /* application sub-directory controller exists? */ 174 | if($directory) 175 | { 176 | if(is_file(APPPATH.'controllers/'.$module.'/'.ucfirst($directory).$ext)) 177 | { 178 | $this->directory = $module.'/'; 179 | return array_slice($segments, 1); 180 | } 181 | 182 | /* application sub-sub-directory controller exists? */ 183 | if($controller) 184 | { 185 | if(is_file(APPPATH.'controllers/'.$module.'/'.$directory.'/'.ucfirst($controller).$ext)) 186 | { 187 | $this->directory = $module.'/'.$directory.'/'; 188 | return array_slice($segments, 2); 189 | } 190 | } 191 | } 192 | 193 | /* application controllers sub-directory exists? */ 194 | if (is_dir(APPPATH.'controllers/'.$module.'/')) 195 | { 196 | $this->directory = $module.'/'; 197 | return array_slice($segments, 1); 198 | } 199 | 200 | /* application controller exists? */ 201 | if (is_file(APPPATH.'controllers/'.ucfirst($module).$ext)) 202 | { 203 | return $segments; 204 | } 205 | 206 | $this->located = -1; 207 | } 208 | 209 | /* set module path */ 210 | protected function _set_module_path(&$_route) 211 | { 212 | if ( ! empty($_route)) 213 | { 214 | // Are module/directory/controller/method segments being specified? 215 | $sgs = sscanf($_route, '%[^/]/%[^/]/%[^/]/%s', $module, $directory, $class, $method); 216 | 217 | // set the module/controller directory location if found 218 | if ($this->locate(array($module, $directory, $class))) 219 | { 220 | //reset to class/method 221 | switch ($sgs) 222 | { 223 | case 1: $_route = $module.'/index'; 224 | break; 225 | case 2: $_route = ($this->located < 2) ? $module.'/'.$directory : $directory.'/index'; 226 | break; 227 | case 3: $_route = ($this->located == 2) ? $directory.'/'.$class : $class.'/index'; 228 | break; 229 | case 4: $_route = ($this->located == 3) ? $class.'/'.$method : $method.'/index'; 230 | break; 231 | } 232 | } 233 | } 234 | } 235 | 236 | public function set_class($class) 237 | { 238 | $suffix = $this->config->item('controller_suffix'); 239 | if (strpos($class, $suffix) === FALSE) 240 | { 241 | $class .= $suffix; 242 | } 243 | parent::set_class($class); 244 | } 245 | } -------------------------------------------------------------------------------- /application/third_party/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/views/errors/cli/error_404.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | An uncaught Exception was encountered 4 | 5 | Type: 6 | Message: 7 | Filename: getFile(), "\n"; ?> 8 | Line Number: getLine(); ?> 9 | 10 | 11 | 12 | Backtrace: 13 | getTrace() as $error): ?> 14 | 15 | File: 16 | Line: 17 | Function: 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /application/views/errors/cli/error_general.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | A PHP Error was encountered 4 | 5 | Severity: 6 | Message: 7 | Filename: 8 | Line Number: 9 | 10 | 11 | 12 | Backtrace: 13 | 14 | 15 | File: 16 | Line: 17 | Function: 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /application/views/errors/cli/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/views/errors/html/error_404.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 404 Page Not Found 8 | 57 | 58 | 59 |
60 |

61 | 62 |
63 | 64 | -------------------------------------------------------------------------------- /application/views/errors/html/error_db.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | Database Error 8 | 57 | 58 | 59 |
60 |

61 | 62 |
63 | 64 | -------------------------------------------------------------------------------- /application/views/errors/html/error_exception.php: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 | 7 |

An uncaught Exception was encountered

8 | 9 |

Type:

10 |

Message:

11 |

Filename: getFile(); ?>

12 |

Line Number: getLine(); ?>

13 | 14 | 15 | 16 |

Backtrace:

17 | getTrace() as $error): ?> 18 | 19 | 20 | 21 |

22 | File:
23 | Line:
24 | Function: 25 |

26 | 27 | 28 | 29 | 30 | 31 | 32 |
-------------------------------------------------------------------------------- /application/views/errors/html/error_general.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | Error 8 | 57 | 58 | 59 |
60 |

61 | 62 |
63 | 64 | -------------------------------------------------------------------------------- /application/views/errors/html/error_php.php: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 | 7 |

A PHP Error was encountered

8 | 9 |

Severity:

10 |

Message:

11 |

Filename:

12 |

Line Number:

13 | 14 | 15 | 16 |

Backtrace:

17 | 18 | 19 | 20 | 21 |

22 | File:
23 | Line:
24 | Function: 25 |

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
-------------------------------------------------------------------------------- /application/views/errors/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/views/errors/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /application/views/welcome_message.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | Welcome to CodeIgniter HMVC 8 | 9 | 70 | 71 | 72 | 73 |
74 |

Welcome to CodeIgniter HMVC

75 | 76 |
77 |

78 | The page you are looking at is being generated dynamically by CodeIgniter.
79 | If you would like to edit this page you'll find it located at: 80 |

81 | 82 | application/views/welcome_message.php 83 | 84 |

The corresponding controller for this page is found at:

85 | application/controllers/Welcome.php 86 | 87 |

> See HMVC Module Example

88 | 89 |

If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.

90 |
91 | 92 | 93 |
94 | 95 | 96 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "The CodeIgniter Application with Composer", 3 | "require": { 4 | "php": ">=5.5", 5 | "codeigniter/framework": "3.0.*", 6 | "propel/propel": "~2.0@dev", 7 | "bshaffer/oauth2-server-php": "^1.8" 8 | }, 9 | "autoload": { 10 | "classmap": ["orm/classes"] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | =')) { 76 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); 77 | } else { 78 | error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); 79 | } 80 | break; 81 | 82 | default: 83 | header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); 84 | echo 'The application environment is not set correctly.'; 85 | exit(1); // EXIT_ERROR 86 | } 87 | 88 | /* 89 | * --------------------------------------------------------------- 90 | * SYSTEM FOLDER NAME 91 | * --------------------------------------------------------------- 92 | * 93 | * This variable must contain the name of your "system" folder. 94 | * Include the path if the folder is not in the same directory 95 | * as this file. 96 | */ 97 | $system_path = 'vendor/codeigniter/framework/system'; 98 | 99 | /* 100 | * --------------------------------------------------------------- 101 | * APPLICATION FOLDER NAME 102 | * --------------------------------------------------------------- 103 | * 104 | * If you want this front controller to use a different "application" 105 | * folder than the default one you can set its name here. The folder 106 | * can also be renamed or relocated anywhere on your server. If 107 | * you do, use a full server path. For more info please see the user guide: 108 | * http://codeigniter.com/user_guide/general/managing_apps.html 109 | * 110 | * NO TRAILING SLASH! 111 | */ 112 | $application_folder = 'application'; 113 | 114 | /* 115 | * --------------------------------------------------------------- 116 | * VIEW FOLDER NAME 117 | * --------------------------------------------------------------- 118 | * 119 | * If you want to move the view folder out of the application 120 | * folder set the path to the folder here. The folder can be renamed 121 | * and relocated anywhere on your server. If blank, it will default 122 | * to the standard location inside your application folder. If you 123 | * do move this, use the full server path to this folder. 124 | * 125 | * NO TRAILING SLASH! 126 | */ 127 | $view_folder = ''; 128 | 129 | 130 | /* 131 | * -------------------------------------------------------------------- 132 | * DEFAULT CONTROLLER 133 | * -------------------------------------------------------------------- 134 | * 135 | * Normally you will set your default controller in the routes.php file. 136 | * You can, however, force a custom routing by hard-coding a 137 | * specific controller class/function here. For most applications, you 138 | * WILL NOT set your routing here, but it's an option for those 139 | * special instances where you might want to override the standard 140 | * routing in a specific front controller that shares a common CI installation. 141 | * 142 | * IMPORTANT: If you set the routing here, NO OTHER controller will be 143 | * callable. In essence, this preference limits your application to ONE 144 | * specific controller. Leave the function name blank if you need 145 | * to call functions dynamically via the URI. 146 | * 147 | * Un-comment the $routing array below to use this feature 148 | */ 149 | // The directory name, relative to the "controllers" folder. Leave blank 150 | // if your controller is not in a sub-folder within the "controllers" folder 151 | // $routing['directory'] = ''; 152 | // The controller class file name. Example: mycontroller 153 | // $routing['controller'] = ''; 154 | // The controller function you wish to be called. 155 | // $routing['function'] = ''; 156 | 157 | 158 | /* 159 | * ------------------------------------------------------------------- 160 | * CUSTOM CONFIG VALUES 161 | * ------------------------------------------------------------------- 162 | * 163 | * The $assign_to_config array below will be passed dynamically to the 164 | * config class when initialized. This allows you to set custom config 165 | * items or override any default config values found in the config.php file. 166 | * This can be handy as it permits you to share one application between 167 | * multiple front controller files, with each file containing different 168 | * config values. 169 | * 170 | * Un-comment the $assign_to_config array below to use this feature 171 | */ 172 | // $assign_to_config['name_of_config_item'] = 'value of config item'; 173 | // -------------------------------------------------------------------- 174 | // END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE 175 | // -------------------------------------------------------------------- 176 | 177 | /* 178 | * --------------------------------------------------------------- 179 | * Resolve the system path for increased reliability 180 | * --------------------------------------------------------------- 181 | */ 182 | 183 | // Set the current directory correctly for CLI requests 184 | if (defined('STDIN')) { 185 | chdir(dirname(__FILE__)); 186 | } 187 | 188 | if (($_temp = realpath($system_path)) !== FALSE) { 189 | $system_path = $_temp . '/'; 190 | } else { 191 | // Ensure there's a trailing slash 192 | $system_path = rtrim($system_path, '/') . '/'; 193 | } 194 | 195 | // Is the system path correct? 196 | if (!is_dir($system_path)) { 197 | header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); 198 | echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: ' . pathinfo(__FILE__, PATHINFO_BASENAME); 199 | exit(3); // EXIT_CONFIG 200 | } 201 | 202 | /* 203 | * ------------------------------------------------------------------- 204 | * Now that we know the path, set the main path constants 205 | * ------------------------------------------------------------------- 206 | */ 207 | // The name of THIS file 208 | define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); 209 | 210 | // Path to the system folder 211 | define('BASEPATH', str_replace('\\', '/', $system_path)); 212 | 213 | // Path to the front controller (this file) 214 | define('FCPATH', dirname(__FILE__) . '/'); 215 | 216 | // Name of the "system folder" 217 | define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); 218 | 219 | // The path to the "application" folder 220 | if (is_dir($application_folder)) { 221 | if (($_temp = realpath($application_folder)) !== FALSE) { 222 | $application_folder = $_temp; 223 | } 224 | 225 | define('APPPATH', $application_folder . DIRECTORY_SEPARATOR); 226 | } else { 227 | if (!is_dir(BASEPATH . $application_folder . DIRECTORY_SEPARATOR)) { 228 | header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); 229 | echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF; 230 | exit(3); // EXIT_CONFIG 231 | } 232 | 233 | define('APPPATH', BASEPATH . $application_folder . DIRECTORY_SEPARATOR); 234 | } 235 | 236 | // The path to the "views" folder 237 | if (!is_dir($view_folder)) { 238 | if (!empty($view_folder) && is_dir(APPPATH . $view_folder . DIRECTORY_SEPARATOR)) { 239 | $view_folder = APPPATH . $view_folder; 240 | } elseif (!is_dir(APPPATH . 'views' . DIRECTORY_SEPARATOR)) { 241 | header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); 242 | echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF; 243 | exit(3); // EXIT_CONFIG 244 | } else { 245 | $view_folder = APPPATH . 'views'; 246 | } 247 | } 248 | 249 | if (($_temp = realpath($view_folder)) !== FALSE) { 250 | $view_folder = $_temp . DIRECTORY_SEPARATOR; 251 | } else { 252 | $view_folder = rtrim($view_folder, '/\\') . DIRECTORY_SEPARATOR; 253 | } 254 | 255 | define('VIEWPATH', $view_folder); 256 | 257 | /* 258 | * -------------------------------------------------------------------- 259 | * LOAD THE BOOTSTRAP FILE 260 | * -------------------------------------------------------------------- 261 | * 262 | * And away we go... 263 | */ 264 | 265 | // Composer autoload 266 | require_once __DIR__ . '/vendor/autoload.php'; 267 | 268 | // Propel2 config load 269 | require_once __DIR__ . '/orm/config.php'; 270 | 271 | require_once BASEPATH . 'core/CodeIgniter.php'; 272 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 José Luis Quintana 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /orm/classes/User.php: -------------------------------------------------------------------------------- 1 | checkVersion('2.0.0-dev'); 4 | $serviceContainer->setAdapterClass('development', 'mysql'); 5 | $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle(); 6 | $manager->setConfiguration(array ( 7 | 'dsn' => 'mysql:host=localhost;dbname=dbcodeigniter', 8 | 'user' => 'root', 9 | 'password' => 'root', 10 | 'classname' => 'Propel\\Runtime\\Connection\\DebugPDO', 11 | 'attributes' => 12 | array ( 13 | 'ATTR_EMULATE_PREPARES' => false, 14 | ), 15 | 'settings' => 16 | array ( 17 | 'charset' => 'utf8', 18 | 'queries' => 19 | array ( 20 | ), 21 | ), 22 | )); 23 | $manager->setName('development'); 24 | $serviceContainer->setConnectionManager('development', $manager); 25 | $serviceContainer->setAdapterClass('production', 'mysql'); 26 | $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle(); 27 | $manager->setConfiguration(array ( 28 | 'dsn' => 'mysql:host=localhost;dbname=dbcodeigniter', 29 | 'user' => 'root', 30 | 'password' => 'root', 31 | 'classname' => 'Propel\\Runtime\\Connection\\DebugPDO', 32 | 'attributes' => 33 | array ( 34 | 'ATTR_EMULATE_PREPARES' => false, 35 | ), 36 | 'settings' => 37 | array ( 38 | 'charset' => 'utf8', 39 | 'queries' => 40 | array ( 41 | ), 42 | ), 43 | )); 44 | $manager->setName('production'); 45 | $serviceContainer->setConnectionManager('production', $manager); 46 | $serviceContainer->setDefaultDatasource('development'); -------------------------------------------------------------------------------- /orm/schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 |
-------------------------------------------------------------------------------- /propel: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | Boilerplate for creating Codeigniter 3 [HMVC](https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc) with [Propel 2 ORM](http://propelorm.org/) and [OAuth2](https://github.com/bshaffer/oauth2-server-php). 4 | 5 | ## Features 6 | - CodeIgniter 3 with HMVC Modular Extension 7 | - Composer project 8 | - HTTP verbs: `GET`, `POST`, `PUT` and `DELETE`. 9 | - [Propel 2 ORM](http://propelorm.org/) (optional) 10 | - [OAuth2](https://github.com/bshaffer/oauth2-server-php) (optional) 11 | 12 | ## Install 13 | 14 | Clone this repository and install composer dependencies. 15 | 16 | ```sh 17 | $ git clone https://github.com/joseluisq/codeigniter3-hmvc-boilerplate.git 18 | $ cd codeigniter3-hmvc-boilerplate 19 | $ composer install 20 | ``` 21 | 22 | Run development server. 23 | 24 | ```sh 25 | $ php -S localhost:8001 -t path_project_directory 26 | ``` 27 | 28 | ## Propel 2 29 | This project brings [Propel 2 ORM](http://propelorm.org/) buit-in. 30 | 31 | ### Settings 32 | [Propel configuration file](http://propelorm.org/documentation/10-configuration.html) is located at `/propel.yml`. 33 | 34 | ### Reverse Engineering 35 | Reverse-engineer the XML schema based on given database. 36 | 37 | ```sh 38 | $ ./propel database:reverse --output-dir=orm development 39 | ``` 40 | 41 | ### Build model classes 42 | Build the model classes based on Propel XML schemas. 43 | 44 | ```sh 45 | $ ./propel model:build 46 | ``` 47 | 48 | ### Build config file 49 | Transform the configuration to PHP code leveraging the ServiceContainer. 50 | 51 | ```sh 52 | $ ./propel config:conver 53 | ``` 54 | 55 | ### Build SQL 56 | Build SQL files 57 | 58 | ```sh 59 | $ ./propel sql:build 60 | ``` 61 | 62 | ## OAuth2 63 | 64 | #### Client Credentials 65 | 66 | ``` 67 | POST http://localhost:8001/v1/login/oauth/access_token 68 | ``` 69 | 70 | Header params: 71 | 72 | - `API-KEY` : (View `application/constants.php` file for change `API_KEY`) 73 | - `Authorization` : `client_id` and `client_secret` 74 | 75 | Example: 76 | 77 | ```sh 78 | $ curl \ 79 | -H "API-KEY:32563b81ec7288ef87bbe39c3b7001a7bff35395eec1eac906a580e6a12d189e" \ 80 | -u admin \ 81 | -X POST http://localhost:8001/v1/login/oauth/access_token 82 | ``` 83 | 84 | Output: 85 | 86 | ```json 87 | {"access_token":"8ea0d5aedc6c7da8f3b6603b8ba783c85c7f0ef7","expires_in":3600,"token_type":"Bearer","scope":null} 88 | ``` 89 | 90 | Use `Accept` header for choose the format of the data that you wish to receive. 91 | For example: `application/json` (default) and `application/xml` 92 | 93 | ## API (example) 94 | 95 | `User` API requires `access_token`. 96 | 97 | #### Get all Users 98 | 99 | ``` 100 | GET "http://localhost:8001/v1/user?access_token=..." 101 | ``` 102 | 103 | Example: 104 | 105 | `access_token` via query string: 106 | 107 | ```sh 108 | $ curl \ 109 | -H "API-KEY: 32563b81ec7288ef87bbe39c3b7001a7bff35395eec1eac906a580e6a12d189e" \ 110 | -X GET "http://localhost:8001/v1/user?access_token=6b3a73aaa27f3a8495d7588fee56ab15628e64d7" 111 | ``` 112 | 113 | Or `access_token` via `Authentication` header: 114 | 115 | ```sh 116 | $ curl \ 117 | -H "API-KEY: 32563b81ec7288ef87bbe39c3b7001a7bff35395eec1eac906a580e6a12d189e" \ 118 | -H "Authorization: Bearer 44cc7ead29d1855900c084d713ca21c9409a4675" \ 119 | -X GET "http://localhost:8001/v1/user" 120 | ``` 121 | 122 | #### Get specific User by Id 123 | 124 | ``` 125 | GET "http://localhost:8001/v1/user/[:Id]?access_token=..." 126 | ``` 127 | 128 | Example: 129 | 130 | ```sh 131 | $ curl \ 132 | -H "API-KEY: 32563b81ec7288ef87bbe39c3b7001a7bff35395eec1eac906a580e6a12d189e" \ 133 | -H "Authorization: Bearer 44cc7ead29d1855900c084d713ca21c9409a4675" \ 134 | -X GET "http://localhost:8001/v1/user/2" 135 | ``` 136 | 137 | **Note:** Check out `application/config.php` for change default timezone. 138 | 139 | ## License 140 | MIT license 141 | 142 | © 2016 [José Luis Quintana](http://git.io/joseluisq) 143 | -------------------------------------------------------------------------------- /sql/development.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.6.1 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: May 08, 2016 at 04:40 AM 7 | -- Server version: 10.0.23-MariaDB 8 | -- PHP Version: 5.6.21 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | -- 14 | -- Database: `dbcodeigniter` 15 | -- 16 | 17 | -- -------------------------------------------------------- 18 | 19 | -- 20 | -- Table structure for table `user` 21 | -- 22 | 23 | CREATE TABLE `user` ( 24 | `user_id` int(11) NOT NULL, 25 | `user_fullname` varchar(100) NOT NULL, 26 | `user_email` varchar(40) NOT NULL, 27 | `user_password` varchar(45) NOT NULL, 28 | `user_dni` varchar(10) NOT NULL, 29 | `user_phone` varchar(10) NOT NULL, 30 | `user_registered` datetime NOT NULL, 31 | `user_updated` datetime DEFAULT NULL, 32 | `user_state` int(1) NOT NULL 33 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 34 | 35 | -- 36 | -- Dumping data for table `user` 37 | -- 38 | 39 | INSERT INTO `user` (`user_id`, `user_fullname`, `user_email`, `user_password`, `user_dni`, `user_phone`, `user_registered`, `user_updated`, `user_state`) VALUES 40 | (1, 'Captain Anonymous', 'anonymous@enterprise.com', '202cb962ac59075b964b07152d234b70', '45450378', '45321120', '2016-03-18 21:07:08', NULL, 1), 41 | (2, 'John Doe', 'jonh.doe@enterprise.com', '202cb962ac59075b964b07152d234b70', '45210378', '45321120', '2016-03-18 21:07:08', NULL, 1), 42 | (3, 'Albert Einstein', 'albert.einstein@enterprise.com', '827ccb0eea8a706c4c34a16891f84e7b', '45210340', '45535202', '2016-03-18 16:11:56', NULL, 1), 43 | (4, 'Nikola Tesla', 'tesla@enterprise.com', 'eb62f6b9306db575c2d596b1279627a4', '47210041', '41135211', '2016-03-18 16:14:45', NULL, 1); 44 | 45 | -- 46 | -- Indexes for dumped tables 47 | -- 48 | 49 | -- 50 | -- Indexes for table `user` 51 | -- 52 | ALTER TABLE `user` 53 | ADD PRIMARY KEY (`user_id`), 54 | ADD UNIQUE KEY `user_email` (`user_email`), 55 | ADD UNIQUE KEY `user_dni` (`user_dni`); 56 | 57 | -- 58 | -- AUTO_INCREMENT for dumped tables 59 | -- 60 | 61 | -- 62 | -- AUTO_INCREMENT for table `user` 63 | -- 64 | ALTER TABLE `user` 65 | MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; -------------------------------------------------------------------------------- /sql/oauth.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.6.1 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: May 08, 2016 at 03:27 AM 7 | -- Server version: 10.0.23-MariaDB 8 | -- PHP Version: 5.6.21 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | -- 14 | -- Database: `dboauth` 15 | -- 16 | 17 | -- -------------------------------------------------------- 18 | 19 | -- 20 | -- Table structure for table `oauth_access_tokens` 21 | -- 22 | 23 | CREATE TABLE `oauth_access_tokens` ( 24 | `access_token` varchar(40) NOT NULL, 25 | `client_id` varchar(80) NOT NULL, 26 | `user_id` varchar(255) DEFAULT NULL, 27 | `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 28 | `scope` varchar(2000) DEFAULT NULL 29 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 30 | 31 | -- -------------------------------------------------------- 32 | 33 | -- 34 | -- Table structure for table `oauth_authorization_codes` 35 | -- 36 | 37 | CREATE TABLE `oauth_authorization_codes` ( 38 | `authorization_code` varchar(40) NOT NULL, 39 | `client_id` varchar(80) NOT NULL, 40 | `user_id` varchar(255) DEFAULT NULL, 41 | `redirect_uri` varchar(2000) DEFAULT NULL, 42 | `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 43 | `scope` varchar(2000) DEFAULT NULL 44 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 45 | 46 | -- -------------------------------------------------------- 47 | 48 | -- 49 | -- Table structure for table `oauth_clients` 50 | -- 51 | 52 | CREATE TABLE `oauth_clients` ( 53 | `client_id` varchar(80) NOT NULL, 54 | `client_secret` varchar(80) DEFAULT NULL, 55 | `redirect_uri` varchar(2000) NOT NULL, 56 | `grant_types` varchar(80) DEFAULT NULL, 57 | `scope` varchar(100) DEFAULT NULL, 58 | `user_id` varchar(80) DEFAULT NULL 59 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 60 | 61 | -- 62 | -- Dumping data for table `oauth_clients` 63 | -- 64 | 65 | INSERT INTO `oauth_clients` (`client_id`, `client_secret`, `redirect_uri`, `grant_types`, `scope`, `user_id`) VALUES 66 | ('admin', '123456', 'http://localhost/', NULL, NULL, NULL); 67 | 68 | -- -------------------------------------------------------- 69 | 70 | -- 71 | -- Table structure for table `oauth_jwt` 72 | -- 73 | 74 | CREATE TABLE `oauth_jwt` ( 75 | `client_id` varchar(80) NOT NULL, 76 | `subject` varchar(80) DEFAULT NULL, 77 | `public_key` varchar(2000) DEFAULT NULL 78 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 79 | 80 | -- -------------------------------------------------------- 81 | 82 | -- 83 | -- Table structure for table `oauth_refresh_tokens` 84 | -- 85 | 86 | CREATE TABLE `oauth_refresh_tokens` ( 87 | `refresh_token` varchar(40) NOT NULL, 88 | `client_id` varchar(80) NOT NULL, 89 | `user_id` varchar(255) DEFAULT NULL, 90 | `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 91 | `scope` varchar(2000) DEFAULT NULL 92 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 93 | 94 | -- -------------------------------------------------------- 95 | 96 | -- 97 | -- Table structure for table `oauth_scopes` 98 | -- 99 | 100 | CREATE TABLE `oauth_scopes` ( 101 | `scope` text, 102 | `is_default` tinyint(1) DEFAULT NULL 103 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 104 | 105 | -- -------------------------------------------------------- 106 | 107 | -- 108 | -- Table structure for table `oauth_users` 109 | -- 110 | 111 | CREATE TABLE `oauth_users` ( 112 | `username` varchar(255) NOT NULL, 113 | `password` varchar(2000) DEFAULT NULL, 114 | `first_name` varchar(255) DEFAULT NULL, 115 | `last_name` varchar(255) DEFAULT NULL 116 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 117 | 118 | -- 119 | -- Indexes for dumped tables 120 | -- 121 | 122 | -- 123 | -- Indexes for table `oauth_access_tokens` 124 | -- 125 | ALTER TABLE `oauth_access_tokens` 126 | ADD PRIMARY KEY (`access_token`); 127 | 128 | -- 129 | -- Indexes for table `oauth_authorization_codes` 130 | -- 131 | ALTER TABLE `oauth_authorization_codes` 132 | ADD PRIMARY KEY (`authorization_code`); 133 | 134 | -- 135 | -- Indexes for table `oauth_clients` 136 | -- 137 | ALTER TABLE `oauth_clients` 138 | ADD PRIMARY KEY (`client_id`); 139 | 140 | -- 141 | -- Indexes for table `oauth_jwt` 142 | -- 143 | ALTER TABLE `oauth_jwt` 144 | ADD PRIMARY KEY (`client_id`); 145 | 146 | -- 147 | -- Indexes for table `oauth_refresh_tokens` 148 | -- 149 | ALTER TABLE `oauth_refresh_tokens` 150 | ADD PRIMARY KEY (`refresh_token`); 151 | 152 | -- 153 | -- Indexes for table `oauth_users` 154 | -- 155 | ALTER TABLE `oauth_users` 156 | ADD PRIMARY KEY (`username`); 157 | -------------------------------------------------------------------------------- /sql/sqldb.map: -------------------------------------------------------------------------------- 1 | # Sqlfile -> Database map 2 | development.sql=development 3 | -------------------------------------------------------------------------------- /test/api_test.php: -------------------------------------------------------------------------------- 1 | 'http://localhost:8001', 7 | 'api_key' => '32563b81ec7288ef87bbe39c3b7001a7bff35395eec1eac906a580e6a12d189e', 8 | 'data_type' => 'json' 9 | )); 10 | 11 | $json = $api::get('/user/1'); 12 | $data = json_decode($json, TRUE); 13 | print_r($data); 14 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joseluisq/codeigniter3-hmvc-boilerplate/7941437f98041a1d40745d8c1424d3f2632fd507/vendor/.gitkeep --------------------------------------------------------------------------------