├── public ├── js │ └── script.js ├── images │ ├── titan.png │ └── favicon.ico ├── upload │ └── index.html └── css │ └── style.css ├── app ├── .htaccess ├── cache │ └── index.html ├── config │ ├── index.html │ ├── development │ │ ├── index.html │ │ └── db.php │ ├── language.php │ ├── autoload.php │ ├── routes.php │ ├── email.php │ ├── cache.php │ ├── db.php │ ├── hooks.php │ └── config.php ├── helpers │ └── index.html ├── logs │ └── index.html ├── models │ └── index.html ├── plugins │ └── index.html ├── controllers │ ├── index.html │ ├── backend │ │ ├── index.html │ │ └── Dashboard.php │ └── frontend │ │ ├── index.html │ │ ├── Home.php │ │ └── Theme.php ├── languages │ ├── index.html │ ├── english │ │ └── index.html │ └── turkish │ │ └── index.html ├── hooks │ └── index.html └── views │ ├── layouts │ ├── footer_view.php │ └── header_view.php │ ├── theme_view.php │ ├── home_view.php │ ├── backend │ └── dashboard_view.php │ └── errors │ ├── error_404.php │ └── error_system.php ├── system ├── .htaccess ├── core │ ├── index.html │ ├── Model.php │ ├── Controller.php │ ├── Functions.php │ ├── Loader.php │ └── App.php ├── helpers │ ├── index.html │ ├── Debug.php │ ├── User_agent.php │ ├── Url.php │ └── Form.php ├── languages │ ├── index.html │ ├── english │ │ ├── index.html │ │ ├── upload.php │ │ └── validation.php │ └── turkish │ │ ├── index.html │ │ ├── upload.php │ │ └── validation.php └── plugins │ ├── index.html │ ├── Template.php │ ├── Log.php │ ├── Benchmark.php │ ├── Hook.php │ ├── Mail │ ├── Mail.php │ └── Pop3.php │ ├── Session.php │ ├── Response.php │ ├── Upload.php │ ├── Cookie.php │ ├── Asset.php │ ├── Input.php │ ├── Cache.php │ ├── Curl.php │ ├── Pagination.php │ ├── Validation.php │ └── Database.php ├── .htaccess ├── .editorconfig ├── README.md ├── composer.json ├── example.nginx.conf ├── LICENCE ├── index.php └── CHANGELOG /public/js/script.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/.htaccess: -------------------------------------------------------------------------------- 1 | Options -Indexes 2 | -------------------------------------------------------------------------------- /system/.htaccess: -------------------------------------------------------------------------------- 1 | Options -Indexes 2 | -------------------------------------------------------------------------------- /public/images/titan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkaratug/titan-mvc/HEAD/public/images/titan.png -------------------------------------------------------------------------------- /public/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkaratug/titan-mvc/HEAD/public/images/favicon.ico -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | Options -MultiViews 2 | RewriteEngine On 3 | 4 | RewriteCond %{REQUEST_FILENAME} !-d 5 | RewriteCond %{REQUEST_FILENAME} !-f 6 | 7 | RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] -------------------------------------------------------------------------------- /app/cache/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

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

Directory access is forbidden.

9 | 10 | 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | tab_width = 4 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /app/views/layouts/footer_view.php: -------------------------------------------------------------------------------- 1 | asset->get_js('footer')) { 4 | foreach($this->asset->get_js('footer') as $js_file) { 5 | echo $js_file . "\n"; 6 | } 7 | } 8 | ?> 9 | 10 | -------------------------------------------------------------------------------- /app/config/language.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | return [ 9 | 10 | 'languages' => ['tr' => 'Turkish', 'en' => 'English'], 11 | 'default_language' => 'tr' 12 | 13 | ]; -------------------------------------------------------------------------------- /app/config/autoload.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | // Autoload helpers 9 | $autoload['helpers'] = ['url']; 10 | 11 | // Autoload plugins 12 | $autoload['plugins'] = ['input']; -------------------------------------------------------------------------------- /app/controllers/backend/Dashboard.php: -------------------------------------------------------------------------------- 1 | load->view('backend/dashboard_view'); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /app/config/routes.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | return [ 9 | 'anasayfa' => 'frontend/home/index', 10 | 'username/([a-zA-Z]+)' => 'frontend/home/username/$1', 11 | 'userid/(\d+)' => 'frontend/home/userid/$1', 12 | 'backend' => 'backend/dashboard/index', 13 | ]; -------------------------------------------------------------------------------- /app/config/email.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | return [ 9 | 10 | // SMTP Server 11 | 'server' => '', 12 | 13 | // Port 14 | 'port' => 587, 15 | 16 | // Username 17 | 'username' => '', 18 | 19 | // Password 20 | 'password' => '', 21 | 22 | // Charset 23 | 'charset' => 'UTF-8', 24 | 25 | ]; -------------------------------------------------------------------------------- /app/config/cache.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | return [ 9 | 10 | // Cache dosyalarının tutulacağı dizin 11 | 'path' => 'cache', 12 | 13 | // Cache dosyalarının uzantısı 14 | 'extension' => '.cache', 15 | 16 | // Cache dosyalarının tutulacağı varsayılan süre değeri 17 | 'default_expire_time' => 604800 18 | 19 | ]; -------------------------------------------------------------------------------- /app/controllers/frontend/Home.php: -------------------------------------------------------------------------------- 1 | load->view('home_view'); 13 | } 14 | 15 | public function username($name) 16 | { 17 | echo $name; 18 | } 19 | 20 | public function userid($id) 21 | { 22 | echo $id; 23 | } 24 | } -------------------------------------------------------------------------------- /app/config/db.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | // Database connection 9 | return [ 10 | 11 | 'db_driver' => 'mysql', 12 | 'db_host' => 'localhost', 13 | 'db_user' => '', 14 | 'db_pass' => '', 15 | 'db_name' => '', 16 | 'db_charset' => 'utf8', 17 | 'db_collation' => 'utf8_general_ci', 18 | 'db_prefix' => '' 19 | 20 | ]; -------------------------------------------------------------------------------- /app/config/development/db.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | // Database connection 9 | return [ 10 | 11 | 'db_driver' => 'mysql', 12 | 'db_host' => 'localhost', 13 | 'db_user' => '', 14 | 'db_pass' => '', 15 | 'db_name' => '', 16 | 'db_charset' => 'utf8', 17 | 'db_collation' => 'utf8_general_ci', 18 | 'db_prefix' => '' 19 | 20 | ]; -------------------------------------------------------------------------------- /app/controllers/frontend/Theme.php: -------------------------------------------------------------------------------- 1 | load->plugin('asset'); 13 | $this->asset->set_title('Welcome to TITAN'); 14 | $this->asset->set_favicon('favicon.ico'); 15 | $this->asset->set_css('style.css'); 16 | $this->load->view('theme_view'); 17 | } 18 | } 19 | 20 | ?> -------------------------------------------------------------------------------- /app/config/hooks.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | return [ 9 | // Sample Hook 10 | 'hook_name' => [ 11 | 'filename' => 'FileName', // filename that contains classes and functions 12 | 'class' => 'ClassName', // class name in the hook file 13 | 'method' => 'MethodName', // function name in the hook file 14 | 'params' => ['key' => 'value'] // parameters to pass to function 15 | ], 16 | ]; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Titan MVC 2 | Titan is a simple application framework built for people who use PHP. 3 | 4 | Visit http://kilavuz.titanphp.com/ for more information and documentation. 5 | 6 | # Requirements 7 | * PHP 5.4 or greater 8 | * MySQL 4.1.2 or greater 9 | * The mod_rewrite Apache module 10 | 11 | # Installation 12 | ```sh 13 | $ composer create-project tkaratug/titan-mvc titan 14 | ``` 15 | 16 | # Documentation 17 | Visit http://kilavuz.titanphp.com/ to see the documentation. 18 | 19 | # To Do 20 | - Authentication 21 | 22 | # Licence 23 | Titan is released under the MIT license. 24 | 25 | -------------------------------------------------------------------------------- /app/views/theme_view.php: -------------------------------------------------------------------------------- 1 | load->view('layouts/header_view'); ?> 2 | 3 | 6 |
7 |

Welcome to TITAN

8 |

This is theme page.

9 |
10 | 14 | 15 | load->view('layouts/footer_view'); ?> -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tkaratug/titan-mvc", 3 | "type": "project", 4 | "description": "Titan Mini MVC Framework", 5 | "keywords": ["titan","mini","framework"], 6 | "homepage": "https://github.com/tkaratug/titan-mvc", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Turan KARATUĞ", 11 | "email": "tkaratug@hotmail.com.tr", 12 | "homepage": "http://turankaratug.com", 13 | "role": "Developer" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.4.0", 18 | "windwalker/edge": "~3.0" 19 | } 20 | } -------------------------------------------------------------------------------- /system/core/Model.php: -------------------------------------------------------------------------------- 1 | titan = Loader::getInstance(); 12 | 13 | if(ENVIRONMENT != 'production') 14 | $this->config = $this->titan->config('db','dev'); 15 | else 16 | $this->config = $this->titan->config('db'); 17 | 18 | require_once SYSTEM_DIR . 'plugins/Database.php'; 19 | 20 | $this->db = Database::init($this->config); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /app/config/config.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | return [ 9 | 10 | // Default Controller Directory 11 | 'default_directory' => 'frontend', 12 | 13 | // Default Controller 14 | 'default_controller' => 'Home', 15 | 16 | // Default Method 17 | 'default_method' => 'index', 18 | 19 | // Session/Cookie Encryption Key 20 | 'encryption_key' => '', 21 | 22 | // Cookie Security 23 | 'cookie_security' => true, 24 | 25 | // Autoload Composer 26 | 'composer' => true 27 | 28 | ]; -------------------------------------------------------------------------------- /app/views/home_view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome to TITAN 6 | 7 | 8 | 9 | 10 | 13 |
14 |

Welcome to TITAN

15 |

This is home page.

16 |
17 | 21 | 22 | -------------------------------------------------------------------------------- /example.nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | root /path/to/titan-mvc; 4 | index index.html index.htm index.php; 5 | 6 | # don't forget to change server_name ! 7 | server_name titanmvc.dev; 8 | 9 | location / { 10 | if (!-e $request_filename) { 11 | rewrite ^/([^?]*)$ /index.php?url=$1 last; break; 12 | } 13 | } 14 | 15 | location ~ \.php$ { 16 | fastcgi_pass 127.0.0.1:9000; 17 | fastcgi_index index.php; 18 | fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; 19 | include fastcgi_params; 20 | } 21 | 22 | 23 | #deny access to .htaccess files, if Apache's document root 24 | # concurs with nginx's one 25 | # 26 | location ~ /\.ht { 27 | deny all; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/views/backend/dashboard_view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome to TITAN 6 | 7 | 8 | 9 | 10 | 13 |
14 |

Welcome to TITAN

15 |

This is backend dashboard page.

16 |
17 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /system/languages/turkish/upload.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | $lang['upload']['file_type_error'] = 'Dosya tipi uygun değil'; 9 | $lang['upload']['max_dimension_error'] = 'Max. resim boyutu %sx%t olmalıdır'; 10 | $lang['upload']['max_size_error'] = 'Dosya boyutu en fazla %s olmalıdır'; 11 | $lang['upload']['upload_path_needed_error'] = 'Dosya yükleme konumu belirtilmeli'; 12 | $lang['upload']['wrong_upload_path_error'] = 'Dosya yüklenecek konum bilgisi hatalı {%s}'; 13 | $lang['upload']['permission_error'] = 'Dosyanın yükleneceği dizin yazma iznine sahip olmalıdır'; 14 | $lang['upload']['upload_error'] = 'Dosya yüklenirken bir hata oluştu'; -------------------------------------------------------------------------------- /system/helpers/Debug.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | /** 9 | * String Debug 10 | * @param string $data 11 | * @param bool $stop 12 | * @return string 13 | */ 14 | if( ! function_exists('debug')) { 15 | function debug($data, $stop = false) 16 | { 17 | echo '
';
18 | 		print_r($data);
19 | 		echo '
'; 20 | 21 | if($stop) 22 | die(); 23 | } 24 | } 25 | 26 | /** 27 | * SQL Query Debug 28 | * @param bool $stop 29 | * @return string 30 | */ 31 | if ( ! function_exists('query_debug')) { 32 | function query_debug($stop = false) 33 | { 34 | $titan = Loader::getInstance(); 35 | $db = $titan->database(); 36 | debug($db->last_query(), $stop); 37 | } 38 | } 39 | 40 | ?> -------------------------------------------------------------------------------- /system/plugins/Template.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | use Windwalker\Edge\Cache\EdgeFileCache; 9 | use Windwalker\Edge\Edge; 10 | use Windwalker\Edge\Loader\EdgeFileLoader; 11 | 12 | class Template 13 | { 14 | public function render($file, $vars, $cache = false) 15 | { 16 | $paths = array(APP_DIR . '/views'); 17 | 18 | // .blade.php extension support 19 | $loader = new EdgeFileLoader($paths); 20 | $loader->addFileExtension('.blade.php'); 21 | 22 | if($cache === false) 23 | $this->edge = new Edge($loader); 24 | else 25 | $this->edge = new Edge($loader, null, new EdgeFileCache(APP_DIR . '/cache')); 26 | 27 | return $this->edge->render($file, $vars); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/views/layouts/header_view.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | asset->get_title()) 8 | echo $this->asset->get_title() . "\n"; 9 | 10 | // Meta Tags 11 | if($this->asset->get_meta()) { 12 | foreach($this->asset->get_meta() as $meta_tag) { 13 | echo $meta_tag . "\n"; 14 | } 15 | } 16 | 17 | // Favicon 18 | if($this->asset->get_favicon()) 19 | echo $this->asset->get_favicon() . "\n"; 20 | 21 | // Custom CSS Files 22 | if($this->asset->get_css()) { 23 | foreach($this->asset->get_css() as $css_file) { 24 | echo $css_file . "\n"; 25 | } 26 | } 27 | 28 | // Custom JS Files 29 | if($this->asset->get_js('header')) { 30 | foreach($this->asset->get_js('header') as $js_file) { 31 | echo $js_file . "\n"; 32 | } 33 | } 34 | ?> 35 | 36 | -------------------------------------------------------------------------------- /system/languages/english/upload.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | $lang['upload']['file_type_error'] = 'The filetype you are attempting to upload is not allowed'; 9 | $lang['upload']['max_dimension_error'] = 'The image you are attempting to upload doesn\'t fit into the allowed dimensions {%sx%t}'; 10 | $lang['upload']['max_size_error'] = 'The file you are attempting to upload must be max %s'; 11 | $lang['upload']['upload_path_needed_error'] = 'The upload path does not appear to be valid'; 12 | $lang['upload']['wrong_upload_path_error'] = 'The upload path does not appear to be valid {%s}'; 13 | $lang['upload']['permission_error'] = 'The upload destination folder does not appear to be writable'; 14 | $lang['upload']['upload_error'] = 'A problem was encountered while attempting to move the uploaded file to the final destination'; -------------------------------------------------------------------------------- /public/css/style.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=latin,latin-ext); 2 | body { 3 | font-family: Open Sans, sans-serif; 4 | font-size: 12px; 5 | } 6 | 7 | a { 8 | text-decoration: none; 9 | color: #bc5858; 10 | } 11 | 12 | #logo { 13 | position: relative; 14 | top: 75px; 15 | width: 60%; 16 | margin: 0 auto; 17 | text-align: center; 18 | } 19 | 20 | #container { 21 | position: relative; 22 | top: 100px; 23 | width: 60%; 24 | margin: 0 auto; 25 | border: 1px solid #ccc; 26 | border-radius: 3px; 27 | } 28 | 29 | #container h3 { 30 | margin: 0; 31 | padding: 10px; 32 | font-size: 18px; 33 | border-bottom: 1px solid #ccc; 34 | color: #666; 35 | } 36 | 37 | span.error_code { 38 | color: #bc5858; 39 | } 40 | 41 | #container p { 42 | margin: 0; 43 | padding: 10px; 44 | font-size: 12px; 45 | } 46 | 47 | #footer { 48 | position: relative; 49 | top: 120px; 50 | width: 60%; 51 | margin: 0 auto; 52 | font-size: 11px; 53 | } 54 | 55 | #footer span.copyright { 56 | float: left; 57 | } 58 | 59 | #footer span.version { 60 | float: right; 61 | } -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Turan Karatuğ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /system/plugins/Log.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Log 9 | { 10 | 11 | protected $log_levels = [ 12 | 0 => 'EMERGENCY', 13 | 1 => 'ALERT', 14 | 2 => 'CRITICAL', 15 | 3 => 'ERROR', 16 | 4 => 'WARNING', 17 | 5 => 'NOTICE', 18 | 6 => 'INFO', 19 | 7 => 'DEBUG' 20 | ]; 21 | 22 | /** 23 | * Write log 24 | * @param int $level 25 | * @param string $message 26 | * @return void 27 | */ 28 | public function write($level, $message) 29 | { 30 | $log_text = date('Y-m-d H:i:s') . ' ---> ' . $this->log_levels[$level] . ': ' . $message; 31 | $this->save_log($log_text); 32 | } 33 | 34 | /** 35 | * Saving Logs 36 | * @param string $log_text 37 | * @return void 38 | */ 39 | private function save_log($log_text) 40 | { 41 | $file_name = 'log-' . date('Y-m-d') . '.txt'; 42 | $file = fopen('app/logs/' . $file_name, "a"); 43 | 44 | if(fwrite($file, $log_text . "\n") === false) 45 | echo 'Log Error: Log dosyası oluşturulamadı. Yazma izinlerini kontrol ediniz.'; 46 | 47 | fclose($file); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /system/core/Controller.php: -------------------------------------------------------------------------------- 1 | autoload = $autoload; 13 | 14 | // Instance of Loader 15 | $this->load = $this; 16 | 17 | // Autoload Helpers and Plugins 18 | $this->autoload_helpers(); 19 | $this->autoload_plugins(); 20 | } 21 | 22 | /** 23 | * Helper autoloader 24 | * @return void 25 | */ 26 | public function autoload_helpers() 27 | { 28 | if(count($this->autoload['helpers']) > 0) { 29 | foreach($this->autoload['helpers'] as $helper) { 30 | $helper_name = ucfirst($helper); 31 | $this->load->helper($helper_name); 32 | } 33 | } 34 | } 35 | 36 | /** 37 | * Plugin autoloader 38 | * @return void 39 | */ 40 | public function autoload_plugins() 41 | { 42 | if(count($this->autoload['plugins']) > 0) { 43 | foreach($this->autoload['plugins'] as $plugin) { 44 | $plugin_name = ucfirst($plugin); 45 | $this->$plugin = $this->load->plugin($plugin_name); 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | - 8 | * @version 1.1.4 9 | * @copyright 2017 10 | * @license https://opensource.org/licenses/MIT 11 | * @link https://github.com/tkaratug/titan-mvc 12 | */ 13 | 14 | // Constants 15 | define('BASE_DIR', '/'); 16 | define('ROOT_DIR', realpath(dirname(__FILE__)) .'/'); 17 | define('SYSTEM_DIR', ROOT_DIR .'system/'); 18 | define('APP_DIR', ROOT_DIR .'app/'); 19 | define('PUBLIC_DIR', rtrim(BASE_DIR, '/') . '/public/'); 20 | define('VERSION', '1.1.4'); 21 | define('DIRECT', true); 22 | define('ENVIRONMENT', 'development'); // production | development 23 | 24 | // Error Reporting 25 | if(ENVIRONMENT == 'production') { 26 | error_reporting(0); 27 | ini_set('display_errors', 0); 28 | } else { 29 | error_reporting(E_ALL); 30 | ini_set('display_errors', 1); 31 | } 32 | 33 | // General Functions 34 | require_once SYSTEM_DIR . 'core/Functions.php'; 35 | 36 | // Loading core classes 37 | require_once SYSTEM_DIR . 'core/App.php'; 38 | require_once SYSTEM_DIR . 'core/Loader.php'; 39 | require_once SYSTEM_DIR . 'core/Controller.php'; 40 | require_once SYSTEM_DIR . 'core/Model.php'; 41 | 42 | // Starting Titan 43 | $app = new App(); 44 | -------------------------------------------------------------------------------- /system/plugins/Benchmark.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Benchmark 9 | { 10 | private $flag_time; 11 | 12 | /** 13 | * Get current microtime 14 | * @return double 15 | */ 16 | private function get_time() { 17 | $timer = explode( ' ', microtime() ); 18 | $timer = $timer[1] + $timer[0]; 19 | return $timer; 20 | } 21 | 22 | /** 23 | * Marh a flag for benchmark 24 | * @param string $name 25 | * @return void 26 | */ 27 | public function flag($name) 28 | { 29 | $this->flag_time[$name] = $this->get_time(); 30 | } 31 | 32 | /** 33 | * Get speed benchmark value 34 | * @param string $basla 35 | * @param string $bitir 36 | * @return double 37 | */ 38 | public function elapsed_time($basla, $bitir) 39 | { 40 | return round($this->flag_time[$bitir] - $this->flag_time[$basla], 6); 41 | } 42 | 43 | /** 44 | * Get memory usage as KB 45 | * @return string 46 | */ 47 | public function memory_usage() 48 | { 49 | return round(memory_get_usage()/1024,2) . ' Kb'; 50 | } 51 | 52 | /** 53 | * Get max memory usage as KB 54 | * @return string 55 | */ 56 | public function memory_max_usage() 57 | { 58 | return round(memory_get_peak_usage()/1024,2) . ' Kb'; 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /app/views/errors/error_404.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Titan Errors 6 | 7 | 61 | 62 | 63 |
64 |

Error Code: 404

65 |

Aradığınız sayfa bulunmamaktadır.

66 |
67 | 71 | 72 | -------------------------------------------------------------------------------- /app/views/errors/error_system.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Titan Errors 6 | 7 | 61 | 62 | 63 |
64 |

Error Code:

65 |

66 |
67 | 71 | 72 | -------------------------------------------------------------------------------- /system/plugins/Hook.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Hook 9 | { 10 | private $titan; 11 | private $hook; 12 | 13 | private $class = null; 14 | private $method = null; 15 | private $params = []; 16 | 17 | public function __construct() 18 | { 19 | $this->titan = Loader::getInstance(); 20 | $this->hook = $this->titan->config('hooks'); 21 | } 22 | 23 | /** 24 | * Run Hook File 25 | * @param $name 26 | * @return void 27 | */ 28 | public function run($name) 29 | { 30 | if (isset($this->hook[$name]) && is_array($this->hook[$name])) { 31 | 32 | $this->titan->hook($this->hook[$name]['filename']); 33 | 34 | if (array_key_exists('class', $this->hook[$name])) { 35 | $this->class = $this->hook[$name]['class']; 36 | } 37 | 38 | if (array_key_exists('method', $this->hook[$name])) { 39 | $this->method = $this->hook[$name]['method']; 40 | } 41 | 42 | if (array_key_exists('params', $this->hook[$name])) { 43 | foreach($this->hook[$name]['params'] as $key => $val) { 44 | $this->params[$key] = $val; 45 | } 46 | } 47 | 48 | if (!is_null($this->class) && !is_null($this->method)) { 49 | call_user_func_array([$this->class, $this->method], $this->params); 50 | } elseif (!is_null($this->method)) { 51 | call_user_func_array($this->method, $this->params); 52 | } 53 | 54 | $this->reset(); 55 | 56 | } 57 | } 58 | 59 | /** 60 | * Add Param to Hook 61 | * @param $params 62 | * @return void 63 | */ 64 | public function add_param($params = []) 65 | { 66 | foreach($params as $key => $val) { 67 | $this->params[$key] = $val; 68 | } 69 | } 70 | 71 | /** 72 | * Reset Hook 73 | * @return void 74 | */ 75 | private function reset() 76 | { 77 | $this->class = null; 78 | $this->method = null; 79 | $this->params = []; 80 | } 81 | } -------------------------------------------------------------------------------- /system/languages/english/validation.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | $lang['validation']['required_error'] = '%s field is requried'; 9 | $lang['validation']['numeric_error'] = '%s field must be numeric'; 10 | $lang['validation']['email_error'] = 'E-Mail is invalid'; 11 | $lang['validation']['min_len_error'] = '%s field\'s length must be min. %t'; 12 | $lang['validation']['max_len_error'] = '%s field\'s length must be max. %t'; 13 | $lang['validation']['exact_len_error'] = '%s field\'s length must be %t'; 14 | $lang['validation']['alpha_error'] = '%s field must be alpha format'; 15 | $lang['validation']['alpha_num_error'] = '%s field must be alphanumeric format'; 16 | $lang['validation']['alpha_dash_error'] = '%s field must be alphadash format'; 17 | $lang['validation']['alpha_space_error'] = '%s field must be alphaspace format'; 18 | $lang['validation']['integer_error'] = '%s field must be integer format'; 19 | $lang['validation']['boolean_error'] = '%s field must be boolean format'; 20 | $lang['validation']['float_error'] = '%s field must be float format'; 21 | $lang['validation']['valid_url_error'] = '%s field must be valid url format'; 22 | $lang['validation']['valid_ip_error'] = '%s field must be valid IP format'; 23 | $lang['validation']['valid_ipv4_error'] = '%s field must be valid IPv4 format'; 24 | $lang['validation']['valid_ipv6_error'] = '%s field must be valid IPv6 format'; 25 | $lang['validation']['valid_cc_error'] = '%s field must be valid credit card number'; 26 | $lang['validation']['contains_error'] = '%s field must contain "%t"'; 27 | $lang['validation']['min_numeric_error'] = '%s field must be minimum "%t"'; 28 | $lang['validation']['max_numeric_error'] = '%s field must be maximum "%t"'; 29 | $lang['validation']['matches_error'] = '%s field doesn\'t match with %t field'; -------------------------------------------------------------------------------- /system/languages/turkish/validation.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | $lang['validation']['required_error'] = '%s alanı boş bırakılamaz'; 9 | $lang['validation']['numeric_error'] = '%s alanı numeric tipinde olmalıdır'; 10 | $lang['validation']['email_error'] = 'E-posta adresi geçersiz'; 11 | $lang['validation']['min_len_error'] = '%s alanı minimum %t karakter olmalıdır'; 12 | $lang['validation']['max_len_error'] = '%s alanı maximum %t karakter olmalıdır'; 13 | $lang['validation']['exact_len_error'] = '%s alanı %t karakter olmalıdır'; 14 | $lang['validation']['alpha_error'] = '%s alanı alpha karakter olmalıdır'; 15 | $lang['validation']['alpha_num_error'] = '%s alanı alphanumeric karakter olmalıdır'; 16 | $lang['validation']['alpha_dash_error'] = '%s alanı alpha dash karakter olmalıdır'; 17 | $lang['validation']['alpha_space_error'] = '%s alanı alpha space karakter olmalıdır'; 18 | $lang['validation']['integer_error'] = '%s alanı integer tipinde olmalıdır'; 19 | $lang['validation']['boolean_error'] = '%s alanı boolean tipinde olmalıdır'; 20 | $lang['validation']['float_error'] = '%s alanı float tipinde olmalıdır'; 21 | $lang['validation']['valid_url_error'] = '%s alanı url formatında olmalıdır'; 22 | $lang['validation']['valid_ip_error'] = '%s alanı geçerli bir ip olmalıdır'; 23 | $lang['validation']['valid_ipv4_error'] = '%s alanı geçerli bir ipv4 olmalıdır'; 24 | $lang['validation']['valid_ipv6_error'] = '%s alanı geçerli bir ipv6 olmalıdır'; 25 | $lang['validation']['valid_cc_error'] = '%s alanı geçerli bir kredi kartı numarası olmalıdır'; 26 | $lang['validation']['contains_error'] = '%s alanı "%t" içermelidir'; 27 | $lang['validation']['min_numeric_error'] = '%s alanı minimum "%t" değeri alabilir'; 28 | $lang['validation']['max_numeric_error'] = '%s alanı maximum "%t" değeri alabilir'; 29 | $lang['validation']['matches_error'] = '%s alanı %t alanı ile eşleşmiyor'; -------------------------------------------------------------------------------- /system/helpers/User_agent.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | /** 9 | * Getting user agent 10 | * @return string 11 | */ 12 | if ( ! function_exists('get_user_agent')) { 13 | function get_user_agent() 14 | { 15 | return $_SERVER['HTTP_USER_AGENT']; 16 | } 17 | } 18 | 19 | /** 20 | * Getting real ip address of visitor 21 | * @return string 22 | */ 23 | if ( ! function_exists('get_ip')) { 24 | function get_ip() 25 | { 26 | if(!empty($_SERVER['HTTP_CLIENT_IP'])) { 27 | $ip = $_SERVER['HTTP_CLIENT_IP']; 28 | } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 29 | $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; 30 | } else { 31 | $ip = $_SERVER['REMOTE_ADDR']; 32 | } 33 | return $ip; 34 | } 35 | } 36 | 37 | /** 38 | * Is mobile 39 | * @return bool 40 | */ 41 | if( ! function_exists('is_mobile')) { 42 | function is_mobile() 43 | { 44 | return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]); 45 | } 46 | } 47 | 48 | /** 49 | * Is referral 50 | * @return bool 51 | */ 52 | if( ! function_exists('is_referral')) { 53 | function is_referral() 54 | { 55 | if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') 56 | return false; 57 | else 58 | return true; 59 | } 60 | } 61 | 62 | /** 63 | * Is robot 64 | * @return bool 65 | */ 66 | if( ! function_exists('is_robot')) { 67 | function is_robot() 68 | { 69 | if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) 70 | return true; 71 | else 72 | return false; 73 | } 74 | } 75 | 76 | /** 77 | * Get the referrer 78 | * @return string 79 | */ 80 | if( ! function_exists('get_referrer')) { 81 | function get_referrer() 82 | { 83 | return (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); 84 | } 85 | } 86 | 87 | /** 88 | * Get acceptable languages 89 | * @return array 90 | */ 91 | if ( ! function_exists('get_langs')) { 92 | function get_langs() 93 | { 94 | return explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])))); 95 | } 96 | } 97 | 98 | /** 99 | * Get browser language 100 | * @return string 101 | */ 102 | if( ! function_exists('get_browser_lang')) { 103 | function get_browser_lang() 104 | { 105 | return substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); 106 | } 107 | } 108 | 109 | 110 | ?> -------------------------------------------------------------------------------- /system/plugins/Mail/Mail.php: -------------------------------------------------------------------------------- 1 | 7 | */ 8 | 9 | // Including PHPMailer Class 10 | require_once 'Phpmailer.php'; 11 | require_once 'Smtp.php'; 12 | 13 | class Mail extends PHPMailer 14 | { 15 | // Titan Instance 16 | private $titan; 17 | 18 | // Mail Config 19 | private $config; 20 | 21 | function __construct() 22 | { 23 | parent::__construct(); 24 | 25 | // Getting Loader Instance 26 | $this->titan = Loader::getInstance(); 27 | 28 | // E-Mail Config 29 | $this->config = $this->titan->config('email'); 30 | 31 | // Setting SMTP Protocol 32 | $this->isSMTP(); 33 | 34 | // Default SMTP Auth 35 | $this->SMTPAuth = true; 36 | 37 | // Default HTML Format 38 | $this->isHTML(true); 39 | 40 | // SMTP Server 41 | $this->Host = $this->config['server']; 42 | 43 | // Username 44 | $this->Username = $this->config['username']; 45 | 46 | // User Password 47 | $this->Password = $this->config['password']; 48 | 49 | // Default Port 50 | $this->Port = $this->config['port']; 51 | 52 | // Default Charset 53 | $this->CharSet = $this->config['charset']; 54 | } 55 | 56 | /** 57 | * Mail Settings 58 | * @param array $config 59 | * @return void 60 | */ 61 | public function init($config) 62 | { 63 | if(array_key_exists('charset', $config)) 64 | $this->CharSet = $config['charset']; 65 | 66 | if(array_key_exists('server', $config)) 67 | $this->Host = $config['server']; 68 | 69 | if(array_key_exists('port', $config)) 70 | $this->Port = $config['port']; 71 | 72 | if(array_key_exists('username', $config)) 73 | $this->Username = $config['username']; 74 | 75 | if(array_key_exists('password', $config)) 76 | $this->Password = $config['password']; 77 | 78 | if(array_key_exists('is_html', $config)) 79 | $this->isHTML($config['is_html']); 80 | } 81 | 82 | /** 83 | * Set sender mail address 84 | * @param string $email 85 | * @param string $name 86 | * @return void 87 | */ 88 | public function from($email, $name = null) 89 | { 90 | $this->From = $email; 91 | $this->AddReplyTo($email, $name); 92 | 93 | if(!is_null($name)) 94 | $this->FromName = $name; 95 | } 96 | 97 | /** 98 | * Set receiver mail address 99 | * @param string $email 100 | * @param string $name 101 | * @return void 102 | */ 103 | public function to($email, $name = null) 104 | { 105 | $this->AddAddress($email, $name); 106 | } 107 | 108 | /** 109 | * Set mail subject 110 | * @param string $subject 111 | * @return void 112 | */ 113 | public function subject($subject) 114 | { 115 | $this->Subject = $subject; 116 | } 117 | 118 | /** 119 | * Set mail content (message) 120 | * @param string $message 121 | * @return void 122 | */ 123 | public function message($message) 124 | { 125 | $this->Body = $message; 126 | } 127 | 128 | function __destruct() 129 | { 130 | parent::__destruct(); 131 | } 132 | 133 | } 134 | 135 | ?> 136 | -------------------------------------------------------------------------------- /system/plugins/Session.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Session 9 | { 10 | 11 | // Session Config 12 | protected $config; 13 | 14 | // Loader instance 15 | private $titan; 16 | 17 | function __construct() 18 | { 19 | // Configurations for security 20 | ini_set('session.cookie_httponly', 1); 21 | ini_set('session.use_only_cookies', 1); 22 | 23 | $this->titan = Loader::getInstance(); 24 | 25 | // Getting config elements 26 | $this->config = $this->titan->config('config'); 27 | 28 | // Initialize Session 29 | $this->init(); 30 | } 31 | 32 | /** 33 | * Starting Session and Hijacking Security 34 | * @return void 35 | */ 36 | public function init() 37 | { 38 | if(!isset($_SESSION)) { 39 | session_start(); 40 | $this->set('session_hash', $this->generate_hash()); 41 | } else { 42 | if($this->get('session_hash') != $this->generate_hash()) 43 | $this->destroy(); 44 | } 45 | } 46 | 47 | /** 48 | * Setting a session 49 | * @param string $key 50 | * @param string $value 51 | * @return string 52 | */ 53 | public function set($key, $value = null) 54 | { 55 | if(is_array($key)) { 56 | foreach($key as $anahtar => $deger) { 57 | $_SESSION[$anahtar] = $deger; 58 | } 59 | } else { 60 | $_SESSION[$key] = $value; 61 | } 62 | } 63 | 64 | /** 65 | * Getting a session 66 | * @param string $key 67 | * @return string 68 | */ 69 | public function get($key = null) 70 | { 71 | if(is_null($key)) 72 | return $_SESSION; 73 | else 74 | return $_SESSION[$key]; 75 | } 76 | 77 | /** 78 | * Is session exists 79 | * @param string $key 80 | * @return bool 81 | */ 82 | public function is_exists($key) 83 | { 84 | return isset($_SESSION[$key]); 85 | } 86 | 87 | /** 88 | * Unset a session 89 | * @param string $key 90 | * @return void 91 | */ 92 | public function delete($key) 93 | { 94 | unset($_SESSION[$key]); 95 | } 96 | 97 | /** 98 | * Destroy a session 99 | * @return string 100 | */ 101 | public function destroy() 102 | { 103 | session_destroy(); 104 | } 105 | 106 | /** 107 | * Generating Hash for Hijacking Security 108 | * @return string 109 | */ 110 | private function generate_hash() 111 | { 112 | return md5(sha1(md5($_SERVER['REMOTE_ADDR'] . $this->config['encryption_key'] . $_SERVER['HTTP_USER_AGENT']))); 113 | } 114 | 115 | /** 116 | * Setting Flash Message 117 | * @param string $message 118 | * @param string $url 119 | * @return bool 120 | */ 121 | public function set_flash($message, $redirect_url = null) 122 | { 123 | $this->set('flash_message', $message); 124 | if (!is_null($redirect_url)) { 125 | header("Location: $redirect_url"); 126 | exit(); 127 | } 128 | return true; 129 | } 130 | 131 | /** 132 | * Getting Flash Message 133 | * @return string 134 | */ 135 | public function get_flash() 136 | { 137 | $message = $this->get('flash_message'); 138 | 139 | $this->delete('flash_message'); 140 | 141 | return $message; 142 | } 143 | 144 | /** 145 | * Is Flash Message Exists? 146 | * @return bool 147 | */ 148 | public function flash_exists() 149 | { 150 | return $this->is_exists('flash_message'); 151 | } 152 | } -------------------------------------------------------------------------------- /system/plugins/Response.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Response 9 | { 10 | 11 | public $status_codes = [ 12 | 100 => 'Continue', 13 | 101 => 'Switching Protocols', 14 | 200 => 'OK', 15 | 201 => 'Created', 16 | 202 => 'Accepted', 17 | 203 => 'Non-Authoritative Information', 18 | 204 => 'No Content', 19 | 205 => 'Reset Content', 20 | 206 => 'Partial Content', 21 | 300 => 'Multiple Choices', 22 | 301 => 'Moved Permanently', 23 | 302 => 'Found', 24 | 303 => 'See Other', 25 | 304 => 'Not Modified', 26 | 305 => 'Use Proxy', 27 | 306 => '(Unused)', 28 | 307 => 'Temporary Redirect', 29 | 400 => 'Bad Request', 30 | 401 => 'Unauthorized', 31 | 402 => 'Payment Required', 32 | 403 => 'Forbidden', 33 | 404 => 'Not Found', 34 | 405 => 'Method Not Allowed', 35 | 406 => 'Not Acceptable', 36 | 407 => 'Proxy Authentication Required', 37 | 408 => 'Request Timeout', 38 | 409 => 'Conflict', 39 | 410 => 'Gone', 40 | 411 => 'Length Required', 41 | 412 => 'Precondition Failed', 42 | 413 => 'Request Entity Too Large', 43 | 414 => 'Request-URI Too Long', 44 | 415 => 'Unsupported Media Type', 45 | 416 => 'Requested Range Not Satisfiable', 46 | 417 => 'Expectation Failed', 47 | 500 => 'Internal Server Error', 48 | 501 => 'Not Implemented', 49 | 502 => 'Bad Gateway', 50 | 503 => 'Service Unavailable', 51 | 504 => 'Gateway Timeout', 52 | 505 => 'HTTP Version Not Supported' 53 | ]; 54 | 55 | /** 56 | * Setting Header 57 | * @param string $key 58 | * @param string $value 59 | * @return bool 60 | */ 61 | public function set_header($key, $value) 62 | { 63 | if(headers_sent()) 64 | return false; 65 | 66 | header($key . ': ' . $value); 67 | 68 | return true; 69 | } 70 | 71 | /** 72 | * Getting Header 73 | * @param string $key 74 | * @return string 75 | */ 76 | public function get_header($key) 77 | { 78 | $default_headers = getallheaders(); 79 | $custom_headers = headers_list(); 80 | 81 | if($this->array_search_like($key, $custom_headers) !== false) { 82 | $index = $this->array_search_like($key, $custom_headers); 83 | $header = explode(':', $custom_headers[$index]); 84 | return trim($header[1]); 85 | } elseif(array_key_exists($key, $default_headers)) { 86 | return $default_headers[$key]; 87 | } else { 88 | return 'Header bilgisi bulunamadı'; 89 | } 90 | } 91 | 92 | /** 93 | * Make array like search 94 | * @param string $element 95 | * @param array $array 96 | * @return int|bool 97 | */ 98 | private function array_search_like($element, $array) 99 | { 100 | foreach($array as $key => $value) { 101 | if(strpos($value, $element) !== false) 102 | return $key; 103 | } 104 | return false; 105 | } 106 | 107 | /** 108 | * Setting Header Status 109 | * @param int $code 110 | * @return bool 111 | */ 112 | public function set_status($code) 113 | { 114 | return http_response_code($code); 115 | } 116 | 117 | /** 118 | * Getting Header Status 119 | * @return array 120 | */ 121 | public function get_status($code = null) 122 | { 123 | if(is_null($code)) 124 | $status_code = http_response_code(); 125 | else 126 | $status_code = $code; 127 | 128 | return [ 129 | 'code' => $status_code, 130 | 'text' => $this->status_codes[$status_code] 131 | ]; 132 | } 133 | 134 | } -------------------------------------------------------------------------------- /system/core/Functions.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | 9 | /** 10 | * Get current language 11 | * @return string 12 | */ 13 | if( ! function_exists('get_lang') ) { 14 | function get_lang() 15 | { 16 | $titan = Loader::getInstance(); 17 | $config = $titan->config('language'); 18 | 19 | if( ! isset($_SESSION) ) { 20 | session_start(); 21 | } 22 | 23 | if( ! isset($_SESSION[md5('lang')]) ) { 24 | return $_SESSION[md5('lang')] = $config['default_language']; 25 | } else { 26 | return $_SESSION[md5('lang')]; 27 | } 28 | } 29 | } 30 | 31 | /** 32 | * Set language 33 | * @param $lang string 34 | * @return void 35 | */ 36 | if( ! function_exists('set_lang') ) { 37 | function set_lang($lang = '') 38 | { 39 | $titan = Loader::getInstance(); 40 | $config = $titan->config('language'); 41 | 42 | if( ! is_string($lang) ) { 43 | return false; 44 | } 45 | 46 | if( empty($lang) ) { 47 | $lang = $config['default_language']; 48 | } 49 | 50 | if( ! isset($_SESSION) ) { 51 | session_start(); 52 | } 53 | 54 | $_SESSION[md5('lang')] = $lang; 55 | } 56 | } 57 | 58 | /** 59 | * Get string with current language 60 | * @param $file string 61 | * @param $key string 62 | * @param $change string 63 | * @return string 64 | */ 65 | if ( ! function_exists('lang') ) { 66 | function lang($file = '', $key = '', $change = '') 67 | { 68 | global $lang; 69 | 70 | $titan = Loader::getInstance(); 71 | $config = $titan->config('language'); 72 | 73 | if( ! is_string($file) || ! is_string($key) ) { 74 | return false; 75 | } 76 | 77 | $appLangDir = APP_DIR . 'languages/' . strtolower($config['languages'][get_lang()]) . '/' . strtolower($file) . '.php'; 78 | $sysLangDir = SYSTEM_DIR . 'languages/' . strtolower($config['languages'][get_lang()]) . '/' . strtolower($file) . '.php'; 79 | 80 | if( file_exists($appLangDir) ) { 81 | require_once $appLangDir; 82 | } elseif ( file_exists($sysLangDir) ) { 83 | require_once $sysLangDir; 84 | } 85 | 86 | $zone = strtolower($file); 87 | 88 | if( array_key_exists($key, $lang[$zone]) ) { 89 | $str = $lang[$zone][$key]; 90 | 91 | // Change special words 92 | if( ! is_array($change) ) { 93 | if( ! empty($change) ) { 94 | return str_replace('%s', $change, $str); 95 | } else { 96 | return $str; 97 | } 98 | } else { 99 | if( ! empty($change) ) { 100 | $keys = []; 101 | $vals = []; 102 | 103 | foreach($change as $key => $value) { 104 | $keys[] = $key; 105 | $vals[] = $value; 106 | } 107 | 108 | return str_replace($keys, $vals, $str); 109 | } else { 110 | return $str; 111 | } 112 | } 113 | 114 | } else { 115 | return false; 116 | } 117 | } 118 | } 119 | 120 | /** 121 | * Include View File 122 | * @param $file string 123 | * @param $vars array 124 | * @param $cache boolean 125 | * @return void 126 | */ 127 | if( ! function_exists('view') ) { 128 | function view($file, $vars = [], $cache = false) 129 | { 130 | $titan = Loader::getInstance(); 131 | $titan->plugin('template'); 132 | 133 | echo $titan->template->render($file, $vars, $cache); 134 | } 135 | } -------------------------------------------------------------------------------- /system/plugins/Upload.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Upload 9 | { 10 | 11 | // File Field 12 | private $file = []; 13 | 14 | // Allowed Mime Types 15 | private $allowed_types = []; 16 | 17 | // Image Width 18 | private $max_width = 0; 19 | 20 | // Image Height 21 | private $max_height = 0; 22 | 23 | // Max. File Size (KB) 24 | private $max_size = 0; 25 | 26 | // Upload Path 27 | private $upload_path = false; 28 | 29 | // Error 30 | private $error = false; 31 | 32 | /** 33 | * Set configurations 34 | * 35 | * @param $config array 36 | * @return void 37 | */ 38 | public function config($config = []) 39 | { 40 | if (array_key_exists('allowed_types', $config)) 41 | $this->allowed_types = $config['allowed_types']; 42 | 43 | if (array_key_exists('max_width', $config)) 44 | $this->max_width = $config['max_width']; 45 | 46 | if (array_key_exists('max_height', $config)) 47 | $this->max_height = $config['max_height']; 48 | 49 | if (array_key_exists('max_size', $config)) 50 | $this->max_size = $config['max_size']; 51 | 52 | if (array_key_exists('upload_path', $config)) 53 | $this->upload_path = $config['upload_path']; 54 | } 55 | 56 | /** 57 | * Start Upload Process 58 | * 59 | * @return boolean 60 | */ 61 | public function handle($field) 62 | { 63 | $this->file = $field; 64 | 65 | if ($this->check_allowed_types() && $this->check_max_size() && $this->check_upload_path()) { 66 | 67 | if (is_uploaded_file($this->file['tmp_name'])) { 68 | if (move_uploaded_file($this->file['tmp_name'], $this->upload_path . '/' . $this->file['name'])) 69 | $sonuc = true; 70 | else { 71 | $this->error = lang('upload', 'upload_error'); 72 | $sonuc = false; 73 | } 74 | } else { 75 | $this->error = lang('upload', 'upload_error'); 76 | $sonuc = false; 77 | } 78 | 79 | return $sonuc; 80 | 81 | } else { 82 | return false; 83 | } 84 | } 85 | 86 | /** 87 | * Check Allowed File Extensions 88 | * 89 | * @return boolean 90 | */ 91 | private function check_allowed_types() 92 | { 93 | if (count($this->allowed_types) > 0) { 94 | 95 | $filepath = pathinfo($this->file['name']); 96 | $extension = $filepath['extension']; 97 | 98 | if (!in_array($extension, $this->allowed_types)) { 99 | $this->error = lang('upload', 'file_type_error'); 100 | return false; 101 | } else { 102 | if (in_array($extension, ['jpg','png','gif'])) { 103 | if ($this->max_width > 0 || $this->max_height > 0) { 104 | list($width, $height) = getimagesize($this->file['tmp_name']); 105 | 106 | if($width > $this->max_width || $height > $this->max_height) { 107 | $this->error = lang('upload', 'max_dimension_error', ['%s' => $this->max_width, '%t' => $this->max_height]); 108 | return false; 109 | } 110 | } 111 | } 112 | } 113 | 114 | } 115 | 116 | return true; 117 | } 118 | 119 | /** 120 | * Check Max File Size 121 | * 122 | * @return boolean 123 | */ 124 | private function check_max_size() 125 | { 126 | if ($this->max_size > 0) { 127 | 128 | if ($this->file['size'] > ($this->max_size * 1024)) { 129 | echo $this->file['size']; 130 | $this->error = lang('upload', 'max_size_error', $this->max_size); 131 | return false; 132 | } 133 | 134 | } 135 | 136 | return true; 137 | } 138 | 139 | /** 140 | * Check Upload Path 141 | * 142 | * @return boolean 143 | */ 144 | private function check_upload_path() 145 | { 146 | if ($this->upload_path === false) { 147 | $this->error = lang('upload', 'upload_path_needed_error'); 148 | return false; 149 | } else { 150 | if (!file_exists($this->upload_path)) { 151 | $this->error = lang('upload', 'wrong_upload_path_error', $this->upload_path); 152 | return false; 153 | } else { 154 | if(!is_writable($this->upload_path)) { 155 | $this->error = lang('upload', 'permission_error'); 156 | return false; 157 | } 158 | } 159 | } 160 | 161 | return true; 162 | } 163 | 164 | /** 165 | * Get Error Messages 166 | * 167 | * @return string 168 | */ 169 | public function getErrors() 170 | { 171 | return $this->error; 172 | } 173 | 174 | } -------------------------------------------------------------------------------- /system/plugins/Cookie.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Cookie 9 | { 10 | // Cookie config 11 | private $config; 12 | 13 | // Security seperator 14 | private $seperator = '--'; 15 | 16 | // Cookie Path 17 | protected $path = '/'; 18 | 19 | // Cookie Domain 20 | protected $domain = ''; 21 | 22 | // Cookie Secure 23 | protected $secure = false; 24 | 25 | // HTTP Only 26 | protected $http_only = true; 27 | 28 | // Loader instance 29 | private $titan; 30 | 31 | function __construct() 32 | { 33 | $this->titan = Loader::getInstance(); 34 | 35 | // Getting config elements 36 | $this->config = $this->titan->config('config'); 37 | } 38 | 39 | /** 40 | * Set Cookie Path 41 | * @param string $path 42 | * @return bool 43 | */ 44 | public function set_path($path) 45 | { 46 | if ( ! is_string($path) ) { 47 | return false; 48 | } 49 | 50 | $this->path = $path; 51 | 52 | return $this; 53 | } 54 | 55 | /** 56 | * Set Cookie Domain 57 | * @param string $domain 58 | * @return $this|bool 59 | */ 60 | public function set_domain($domain) 61 | { 62 | if ( ! is_string($domain) ) { 63 | return false; 64 | } 65 | 66 | $this->domain = $domain; 67 | 68 | return $this; 69 | } 70 | 71 | /** 72 | * Set Cookie Secure 73 | * @param bool $secure 74 | * @return $this|bool 75 | */ 76 | public function set_secure($secure = false) 77 | { 78 | if ( ! is_bool($secure) ) { 79 | return false; 80 | } 81 | 82 | $this->secure = $secure; 83 | 84 | return $this; 85 | } 86 | 87 | /** 88 | * Set Cookie HTTP Only 89 | * @param bool $http 90 | * @return $this|bool 91 | */ 92 | public function set_http_only($http = true) 93 | { 94 | if ( ! is_bool($http) ) { 95 | return false; 96 | } 97 | 98 | $this->http_only = $http; 99 | 100 | return $this; 101 | } 102 | 103 | /** 104 | * Setting Cookie 105 | * @param string $name 106 | * @param string $value 107 | * @param int $time 108 | * @return bool 109 | */ 110 | public function set($name, $value, $time = null) 111 | { 112 | if(is_null($time)) { 113 | if($this->config['cookie_security'] == true) 114 | setcookie($name, $value . $this->seperator . md5($value . $this->config['encryption_key']), 0, $this->path, $this->domain, $this->secure, $this->http_only); 115 | else 116 | setcookie($name, $value, 0, $this->path, $this->domain, $this->secure, $this->http_only); 117 | } else { 118 | if($this->config['cookie_security'] == true) 119 | setcookie($name, $value . $this->seperator . md5($value . $this->config['encryption_key']), time() + (60*60*$time), $this->path, $this->domain, $this->secure, $this->http_only); 120 | else 121 | setcookie($name, $value, time() + (60*60*$time), $this->path, $this->domain, $this->secure, $this->http_only); 122 | } 123 | } 124 | 125 | /** 126 | * Getting Cookie 127 | * @param string $name 128 | * @return string 129 | */ 130 | public function get($name) 131 | { 132 | if($this->has($name)) { 133 | if($this->config['cookie_security'] == true) { 134 | $slices = explode($this->seperator, $_COOKIE[$name]); 135 | if(md5($slices[0] . $this->config['encryption_key']) == $slices[1]) 136 | return $slices[0]; 137 | else 138 | die('Cookie içeriği değiştirilmiş'); 139 | } else { 140 | return $_COOKIE[$name]; 141 | } 142 | } 143 | } 144 | 145 | /** 146 | * Delete Cookie 147 | * @param string $name 148 | * @return bool 149 | */ 150 | public function delete($name) 151 | { 152 | if($this->has($name)) { 153 | unset($_COOKIE[$name]); 154 | setcookie($name, '', time() - 3600, $this->path, $this->domain); 155 | } else { 156 | return false; 157 | } 158 | } 159 | 160 | /** 161 | * Is Cookie Exists 162 | * @param string $name 163 | * @return bool 164 | */ 165 | public function has($name) 166 | { 167 | if(isset($_COOKIE[$name])) 168 | return true; 169 | else 170 | return false; 171 | } 172 | 173 | } -------------------------------------------------------------------------------- /system/plugins/Asset.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Asset 9 | { 10 | // Asset Selector 11 | public $asset = []; 12 | 13 | /** 14 | * Set CSS files. 15 | * @param $css_file string (file path or url) 16 | * @param $source string (local|remote) 17 | * @return void 18 | */ 19 | public function set_css($css_file, $source = 'local') 20 | { 21 | if($source == 'remote') { 22 | $url = $css_file; 23 | $this->asset['header']['css'][] = ''; 24 | } else { 25 | $part = explode('.css', $css_file); 26 | $url = 'public/css/' . $part[0] . '.css' . $part[1]; 27 | 28 | // Check is file exists 29 | if(!file_exists(ROOT_DIR . 'public/css/' . $part[0] . '.css')) { 30 | $code = 1005; 31 | $text = "CSS Style dosyası bulunamadı: {$url}"; 32 | require_once 'app/views/errors/error_system.php'; 33 | die(); 34 | } 35 | 36 | $this->asset['header']['css'][] = ''; 37 | } 38 | } 39 | 40 | /** 41 | * Set JS files. 42 | * @param $js_file string (file path or url) 43 | * @param $location string (header|footer) 44 | * @param $source string (local|remote) 45 | * @return void 46 | */ 47 | public function set_js($js_file, $location = 'header', $source = 'local') 48 | { 49 | if($source == 'remote') { 50 | $url = $js_file; 51 | $this->asset[$location]['js'][] = ''; 52 | } else { 53 | $url = 'public/js/' . $js_file; 54 | 55 | // Check is file exists 56 | if(!file_exists(ROOT_DIR . $url)) { 57 | $code = 1006; 58 | $text = "Javascript dosyası bulunamadı: {$url}"; 59 | require_once 'app/views/errors/error_system.php'; 60 | die(); 61 | } 62 | 63 | $this->asset[$location]['js'][] = ''; 64 | } 65 | } 66 | 67 | /** 68 | * Set Meta Tags 69 | * @param $meta_name string (meta tag name) 70 | * @param $meta_content string (meta tag content) 71 | * @return void 72 | */ 73 | public function set_meta($meta_name, $meta_content) 74 | { 75 | $this->asset['header']['meta'][] = ''; 76 | } 77 | 78 | /** 79 | * Set Page Title 80 | * @param $title string 81 | * @return void 82 | */ 83 | public function set_title($title) 84 | { 85 | $this->asset['header']['title'] = '' . $title . ''; 86 | } 87 | 88 | /** 89 | * Set favicon 90 | * @param $image string 91 | * @param $type string 92 | * @return void 93 | */ 94 | public function set_favicon($image) 95 | { 96 | $image_file = explode('.', $image); 97 | $extension = end($image_file); 98 | 99 | switch($extension) { 100 | case 'png' : $icon_type = 'image/png'; break; 101 | case 'ico' : $icon_type = 'image/x-icon'; break; 102 | default : $icon_type = 'image/x-icon'; break; 103 | } 104 | 105 | $this->asset['header']['favicon'] = ''; 106 | } 107 | 108 | /** 109 | * Get CSS Files 110 | * @return array 111 | */ 112 | public function get_css() 113 | { 114 | if(array_key_exists('header', $this->asset) && array_key_exists('css', $this->asset['header'])) 115 | return $this->asset['header']['css']; 116 | else 117 | return null; 118 | } 119 | 120 | /** 121 | * Get JS Files 122 | * @param $location (header|footer) 123 | * @return array 124 | */ 125 | public function get_js($location = 'header') 126 | { 127 | if(array_key_exists($location, $this->asset) && array_key_exists('js', $this->asset[$location])) 128 | return $this->asset[$location]['js']; 129 | else 130 | return null; 131 | } 132 | 133 | /** 134 | * Get Meta Tags 135 | * @return array 136 | */ 137 | public function get_meta() 138 | { 139 | if(array_key_exists('header', $this->asset) && array_key_exists('meta', $this->asset['header'])) 140 | return $this->asset['header']['meta']; 141 | else 142 | return null; 143 | } 144 | 145 | /** 146 | * Get Page Title 147 | * @return string 148 | */ 149 | public function get_title() 150 | { 151 | if(array_key_exists('header', $this->asset) && array_key_exists('title', $this->asset['header'])) 152 | return $this->asset['header']['title']; 153 | else 154 | return null; 155 | } 156 | 157 | /** 158 | * Get favicon 159 | * @return string 160 | */ 161 | public function get_favicon() 162 | { 163 | if(array_key_exists('header', $this->asset) && array_key_exists('favicon', $this->asset['header'])) 164 | return $this->asset['header']['favicon']; 165 | else 166 | return null; 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /system/plugins/Input.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Input { 9 | 10 | /** 11 | * Clear XSS 12 | * @param string $data 13 | * @return string 14 | */ 15 | public function xss_clean($data) 16 | { 17 | // Fix &entity\n; 18 | $data = str_replace(array('&','<','>'), array('&amp;','&lt;','&gt;'), $data); 19 | $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data); 20 | $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data); 21 | $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8'); 22 | 23 | // Remove any attribute starting with "on" or xmlns 24 | $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data); 25 | 26 | // Remove javascript: and vbscript: protocols 27 | $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data); 28 | $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data); 29 | $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data); 30 | 31 | // Only works in IE: 32 | $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data); 33 | $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data); 34 | $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data); 35 | 36 | // Remove namespaced elements (we do not need them) 37 | $data = preg_replace('#]*+>#i', '', $data); 38 | 39 | do 40 | { 41 | // Remove really unwanted tags 42 | $old_data = $data; 43 | $data = preg_replace('#]*+>#i', '', $data); 44 | } 45 | while ($old_data !== $data); 46 | 47 | // we are done... 48 | return $data; 49 | } 50 | 51 | /** 52 | * Clean HTML 53 | * @param string $data 54 | * @return string 55 | */ 56 | public function html_clean($data) 57 | { 58 | return strip_tags(htmlentities(trim(stripslashes($data)), ENT_NOQUOTES, "UTF-8")); 59 | } 60 | 61 | /** 62 | * HTTP GET Request 63 | * @param string $data 64 | * @param bool $xss_clean 65 | * @return string 66 | */ 67 | public function get($data = null, $xss_clean = true) 68 | { 69 | if($data == null) { 70 | return $_GET; 71 | } else { 72 | if($xss_clean == true) { 73 | return $this->xss_clean($_GET[$data]); 74 | } else { 75 | return $_GET[$data]; 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * HTTP POST Request 82 | * @param string $data 83 | * @param bool $xss_clean 84 | * @return string 85 | */ 86 | public function post($data = null, $xss_clean = true) { 87 | if($data == null) { 88 | return $_POST; 89 | } else { 90 | if($xss_clean == true) { 91 | return $this->xss_clean($_POST[$data]); 92 | } else { 93 | return $_POST[$data]; 94 | } 95 | } 96 | } 97 | 98 | /** 99 | * HTTP PUT Request 100 | * @param string $data 101 | * @param bool $xss_clean 102 | * @return string 103 | */ 104 | public function put($data = null, $xss_clean = true) 105 | { 106 | parse_str(file_get_contents("php://input"),$post_vars); 107 | 108 | if($data == null) { 109 | return $post_vars; 110 | } else { 111 | if($xss_clean == true) { 112 | return $this->xss_clean($post_vars[$data]); 113 | } else { 114 | return $post_vars[$data]; 115 | } 116 | } 117 | } 118 | 119 | /** 120 | * HTTP DELETE Request 121 | * @param string $data 122 | * @param bool $xss_clean 123 | * @return string 124 | */ 125 | public function delete($data = null, $xss_clean = true) 126 | { 127 | parse_str(file_get_contents("php://input"),$post_vars); 128 | 129 | if($data == null) { 130 | return $post_vars; 131 | } else { 132 | if($xss_clean == true) { 133 | return $this->xss_clean($post_vars[$data]); 134 | } else { 135 | return $post_vars[$data]; 136 | } 137 | } 138 | } 139 | 140 | /** 141 | * HTTP Request Method 142 | * @return string 143 | */ 144 | public function request_method() 145 | { 146 | return $_SERVER['REQUEST_METHOD']; 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /system/core/Loader.php: -------------------------------------------------------------------------------- 1 | $model = new $model(); 43 | else 44 | $this->$custom_name = new $model(); 45 | } else { 46 | $code = 1001; 47 | $text = 'Model bulunamadı'; 48 | require_once APP_DIR . 'views/errors/error_system.php'; 49 | die(); 50 | } 51 | } 52 | 53 | /** 54 | * Loading View 55 | * @param string $view 56 | * @param array $data 57 | * @return void 58 | */ 59 | public function view($view, $data = []) 60 | { 61 | if (file_exists(APP_DIR . 'views/' . $view . '.php')) { 62 | extract($data); 63 | require_once APP_DIR . 'views/' . $view . '.php'; 64 | } else { 65 | $code = 1002; 66 | $text = 'View bulunamadı'; 67 | require_once APP_DIR . 'views/errors/error_system.php'; 68 | die(); 69 | } 70 | } 71 | 72 | /** 73 | * Loading Plugin 74 | * @param string $plugin 75 | * @return object 76 | */ 77 | public function plugin($plugin, $params = null) 78 | { 79 | if(file_exists(APP_DIR . 'plugins/' . ucfirst($plugin) . '/' . ucfirst($plugin) . '.php') || file_exists(APP_DIR . 'plugins/' . ucfirst($plugin) . '.php')) { 80 | if(file_exists(APP_DIR . 'plugins/' . ucfirst($plugin) . '/' . ucfirst($plugin) . '.php')) { 81 | require_once APP_DIR . 'plugins/' . ucfirst($plugin) . '/' . ucfirst($plugin) . '.php'; 82 | if(is_null($params)) 83 | $this->$plugin = new $plugin; 84 | else 85 | $this->$plugin = new $plugin($params); 86 | } else { 87 | if (file_exists(APP_DIR . 'plugins/' . ucfirst($plugin) . '.php')) { 88 | require_once APP_DIR . 'plugins/' . ucfirst($plugin) . '.php'; 89 | if(is_null($params)) 90 | $this->$plugin = new $plugin; 91 | else 92 | $this->$plugin = new $plugin($params); 93 | } 94 | } 95 | return $this->$plugin; 96 | } elseif(file_exists(SYSTEM_DIR . 'plugins/' . ucfirst($plugin) . '/' . ucfirst($plugin) . '.php') || file_exists(SYSTEM_DIR . 'plugins/' . ucfirst($plugin) . '.php')) { 97 | if(file_exists(SYSTEM_DIR . 'plugins/' . ucfirst($plugin) . '/' . ucfirst($plugin) . '.php')) { 98 | require_once SYSTEM_DIR . 'plugins/' . ucfirst($plugin) . '/' . ucfirst($plugin) . '.php'; 99 | if(is_null($params)) 100 | $this->$plugin = new $plugin; 101 | else 102 | $this->$plugin = new $plugin($params); 103 | } else { 104 | if (file_exists(SYSTEM_DIR . 'plugins/' . ucfirst($plugin) . '.php')) { 105 | require_once SYSTEM_DIR . 'plugins/' . ucfirst($plugin) . '.php'; 106 | if(is_null($params)) 107 | $this->$plugin = new $plugin; 108 | else 109 | $this->$plugin = new $plugin($params); 110 | } 111 | } 112 | return $this->$plugin; 113 | } else { 114 | $code = 1003; 115 | $text = 'Plugin bulunamadı'; 116 | require_once APP_DIR . 'views/errors/error_system.php'; 117 | die(); 118 | } 119 | } 120 | 121 | /** 122 | * Loading Helper 123 | * @param string $helper 124 | * @return void 125 | */ 126 | public function helper($helper) 127 | { 128 | if (file_exists(APP_DIR . 'helpers/' . ucfirst($helper) . '.php')) { 129 | require_once APP_DIR . 'helpers/' . ucfirst($helper) . '.php'; 130 | } elseif(file_exists(SYSTEM_DIR . 'helpers/' . ucfirst($helper) . '.php')) { 131 | require_once SYSTEM_DIR . 'helpers/' . ucfirst($helper) . '.php'; 132 | } else { 133 | $code = 1004; 134 | $text = 'Helper bulunamadı'; 135 | require_once APP_DIR . 'views/errors/error_system.php'; 136 | die(); 137 | } 138 | } 139 | 140 | /** 141 | * Config Loader 142 | * @param string $configFile 143 | * @param string $env ('prod' or 'dev') 144 | * @return void 145 | */ 146 | public function config($config, $env = 'prod') 147 | { 148 | if($env == 'prod') 149 | $full_path = APP_DIR . 'config/' . $config . '.php'; 150 | elseif($env == 'dev') 151 | $full_path = APP_DIR . 'config/development/' . $config . '.php'; 152 | 153 | if(file_exists($full_path)) { 154 | if(!array_key_exists($config, $this->loaded_configs)) 155 | $this->loaded_configs[$config] = require_once $full_path; 156 | return $this->loaded_configs[$config]; 157 | } else { 158 | $code = 1008; 159 | $text = 'Config dosyası bulunamadı. {' . $config . '}'; 160 | require_once APP_DIR . 'views/errors/error_system.php'; 161 | die(); 162 | } 163 | } 164 | 165 | /** 166 | * Database Plugin Loader 167 | * @return object 168 | */ 169 | public function database() 170 | { 171 | require_once SYSTEM_DIR . 'plugins/Database.php'; 172 | 173 | if(ENVIRONMENT != 'production') 174 | return Database::init($this->config('db', 'dev')); 175 | else 176 | return Database::init($this->config('db')); 177 | } 178 | 179 | /** 180 | * Hook Loader 181 | * @param string $hook 182 | * @return void 183 | */ 184 | public function hook($hook) 185 | { 186 | $hook_file = APP_DIR . 'hooks/' . ucfirst($hook) . '.php'; 187 | 188 | if(file_exists($hook_file)) { 189 | require_once $hook_file; 190 | } else { 191 | $code = 1009; 192 | $text = 'Hook dosyası bulunamadı. {' . $hook . '}'; 193 | require_once APP_DIR . 'views/errors/error_system.php'; 194 | die(); 195 | } 196 | } 197 | 198 | } 199 | 200 | ?> 201 | -------------------------------------------------------------------------------- /system/helpers/Url.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | /** 9 | * Getting Request Scheme 10 | * @return string 11 | */ 12 | if ( ! function_exists('request_scheme')) { 13 | function request_scheme() 14 | { 15 | if (isset($_SERVER['HTTPS'])) 16 | return 'https://'; 17 | else 18 | return 'http://'; 19 | } 20 | } 21 | 22 | /** 23 | * Getting Http Host 24 | * @return string 25 | */ 26 | if ( ! function_exists('http_host')) { 27 | function http_host() 28 | { 29 | return $_SERVER['HTTP_HOST']; 30 | } 31 | } 32 | 33 | /** 34 | * Getting Request URI 35 | * @return string 36 | */ 37 | if ( ! function_exists('request_uri')) { 38 | function request_uri() 39 | { 40 | return $_SERVER['REQUEST_URI']; 41 | } 42 | } 43 | 44 | /** 45 | * Getting Full Path of application 46 | * @return string 47 | */ 48 | if ( ! function_exists('full_path')) { 49 | function full_path() 50 | { 51 | return request_scheme() . http_host() . request_uri(); 52 | } 53 | } 54 | 55 | /** 56 | * Getting Current Url 57 | * @return string 58 | */ 59 | if ( ! function_exists('current_url')) { 60 | function current_url() 61 | { 62 | return request_scheme() . http_host() . request_uri(); 63 | } 64 | } 65 | 66 | /** 67 | * Getting base url of application 68 | * @return string 69 | */ 70 | if ( ! function_exists('base_url')) { 71 | function base_url($path = null) 72 | { 73 | if(is_null($path)) { 74 | if(BASE_DIR == '/') 75 | return request_scheme() . http_host(); 76 | else 77 | return request_scheme() . http_host() . BASE_DIR; 78 | } else { 79 | if(BASE_DIR == '/') 80 | return request_scheme() . http_host() . '/' . $path; 81 | else 82 | return request_scheme() . http_host() . BASE_DIR . '/' . $path; 83 | } 84 | } 85 | } 86 | 87 | /** 88 | * Getting URL segments 89 | * @param int $index 90 | * @return array | string 91 | */ 92 | if ( ! function_exists('get_segments')) { 93 | function get_segments($index = null) 94 | { 95 | $segments = explode('/', trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/')); 96 | if(is_null($index)) { 97 | return $segments; 98 | } else { 99 | if(array_key_exists($index, $segments)) 100 | return $segments[$index]; 101 | else 102 | return 0; 103 | } 104 | } 105 | } 106 | 107 | /** 108 | * Getting current segment 109 | * @return string 110 | */ 111 | if ( ! function_exists('current_segment')) { 112 | function current_segment() 113 | { 114 | return get_segments( count(get_segments()) - 1 ); 115 | } 116 | } 117 | 118 | /** 119 | * Getting image file 120 | * @param string $filepath 121 | * @return string 122 | */ 123 | if ( ! function_exists('get_image') ) { 124 | function get_image($file) 125 | { 126 | return PUBLIC_DIR . 'images/' . $file; 127 | } 128 | } 129 | 130 | /** 131 | * Getting CSS Style File 132 | * @param string $filepath 133 | * @return string 134 | */ 135 | if ( ! function_exists('get_css') ) { 136 | function get_css($file) 137 | { 138 | $filePath = PUBLIC_DIR . 'css/' . $file . '.css'; 139 | $rootPath = ROOT_DIR . 'public/css/' . $file . '.css'; 140 | 141 | if(file_exists($rootPath)) { 142 | return ''; 143 | } else { 144 | $code = 1005; 145 | $text = "CSS Style dosyası bulunamadı: {$filePath}"; 146 | require_once 'app/views/errors/error_system.php'; 147 | die(); 148 | } 149 | } 150 | } 151 | 152 | /** 153 | * Getting JS File 154 | * @param string $filepath 155 | * @return string 156 | */ 157 | if ( ! function_exists('get_js') ) { 158 | function get_js($file) 159 | { 160 | $filePath = PUBLIC_DIR . 'js/' . $file . '.js'; 161 | $rootPath = ROOT_DIR . 'public/js/' . $file . '.js'; 162 | 163 | if(file_exists($rootPath)) { 164 | return ''; 165 | } else { 166 | $code = 1006; 167 | $text = "Javascript dosyası bulunamadı: {$filePath}"; 168 | require_once 'app/views/errors/error_system.php'; 169 | die(); 170 | } 171 | } 172 | } 173 | 174 | /** 175 | * Redirection 176 | * @param string $link 177 | * @return void 178 | */ 179 | if ( ! function_exists('redirect')) { 180 | function redirect($link, $delay = 0) 181 | { 182 | if($delay > 0) 183 | header("Refresh:" . $delay . ";url=" . $link); 184 | else 185 | header("Location:" . $link); 186 | } 187 | } 188 | 189 | /** 190 | * Converting urls to clickable hyperlink in text 191 | * @param string $text 192 | * @return string 193 | */ 194 | if ( ! function_exists('make_link')) { 195 | function make_link($text) 196 | { 197 | $pattern = '/(((http[s]?:\/\/(.+(:.+)?@)?)|(www\.))[a-z0-9](([-a-z0-9]+\.)*\.[a-z]{2,})?\/?[a-z0-9.,_\/~#&=:;%+!?-]+)/is'; 198 | $text = preg_replace($pattern, ' $1', $text); 199 | $text = preg_replace('/href="www/', 'href="http://www', $text); 200 | return $text; 201 | } 202 | } 203 | 204 | /** 205 | * Converting email adressess to clickable mailto in text 206 | * @param string $text 207 | * @return string 208 | */ 209 | if ( ! function_exists('make_mailto')) { 210 | function make_mailto($text) 211 | { 212 | $regex = '/(\S+@\S+\.\S+)/'; 213 | $replace = '$1'; 214 | return preg_replace($regex, $replace, $text); 215 | } 216 | } 217 | 218 | /** 219 | * Safe mail 220 | * @param string $email 221 | * @return string 222 | */ 223 | if ( ! function_exists('safe_mail')) { 224 | function safe_mail($email) 225 | { 226 | $character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'; 227 | $key = str_shuffle($character_set); $cipher_text = ''; $id = 'e'.rand(1,999999999); 228 | 229 | for($i=0;$i"+d+""'; 236 | 237 | $script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")"; 238 | $script = ''; 239 | 240 | return '[javascript protected email address]'.$script; 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /system/plugins/Cache.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Cache 9 | { 10 | private $config; 11 | private $filename; 12 | private $path; 13 | private $extension; 14 | private $default_expire_time; 15 | private $titan; 16 | 17 | function __construct() 18 | { 19 | $this->titan = Loader::getInstance(); 20 | 21 | // Get config elements 22 | $this->config = $this->titan->config('cache'); 23 | 24 | // Set configurations 25 | $this->path = APP_DIR . $this->config['path']; 26 | $this->extension = $this->config['extension']; 27 | $this->default_expire_time = $this->config['default_expire_time']; 28 | } 29 | 30 | /** 31 | * Check cache directory exists 32 | * @return string|bool 33 | */ 34 | private function check_cache_dir() 35 | { 36 | if(!is_dir($this->get_path()) && !mkdir($this->get_path(), 0775, true)) { 37 | echo 'Cache dizini oluşturulamadı ' . $this->get_path(); 38 | } elseif(!is_readable($this->get_path()) || !is_writable($this->get_path())) { 39 | if(!chmod($this->get_path(), 0775)) { 40 | echo $this->get_path() . ' dizini okuma ve yazma izinlerine sahip olmalıdır'; 41 | } 42 | } else { 43 | return true; 44 | } 45 | } 46 | 47 | /** 48 | * Get cache directory 49 | * @return string|bool 50 | */ 51 | private function get_cache_dir($filename = null) 52 | { 53 | if($this->check_cache_dir() === true) { 54 | if(is_null($filename)) 55 | $filename = preg_replace('/[^0-9a-z\.\_\-]/i', '', strtolower($this->get_cache())); 56 | return $this->get_path() . '/' . $this->hash_file($filename) . $this->get_extension(); 57 | } else { 58 | return false; 59 | } 60 | } 61 | 62 | /** 63 | * Load cached file content 64 | * @return string|bool 65 | */ 66 | private function load_cache($filename = null) 67 | { 68 | if($this->get_cache_dir() !== false) { 69 | if(file_exists($this->get_cache_dir($filename))) { 70 | $file = file_get_contents($this->get_cache_dir($filename)); 71 | return json_decode($file, true); 72 | } else { 73 | return false; 74 | } 75 | } else { 76 | return false; 77 | } 78 | } 79 | 80 | /** 81 | * Write data into the cache file 82 | * @param string $key 83 | * @param string $data 84 | * @param int $expiration 85 | * @return void 86 | */ 87 | public function save($key, $data, $expiration = null) 88 | { 89 | if(is_null($expiration)) 90 | $expiration = $this->default_expire_time; 91 | 92 | $stored_data = [ 93 | 'time' => time(), 94 | 'expire' => $expiration, 95 | 'data' => serialize($data) 96 | ]; 97 | 98 | $cache_content = $this->load_cache(); 99 | 100 | if(is_array($cache_content) === true) { 101 | $cache_content[$key] = $stored_data; 102 | } else { 103 | $cache_content = [$key => $stored_data]; 104 | } 105 | 106 | $cache_content = json_encode($cache_content); 107 | file_put_contents($this->get_cache_dir(), $cache_content); 108 | } 109 | 110 | /** 111 | * Read data from the cache file 112 | * @param string $key 113 | * @return string 114 | */ 115 | public function read($key, $filename = null) 116 | { 117 | $cache_content = $this->load_cache($filename); 118 | if(!isset($cache_content[$key]['data'])) 119 | return null; 120 | else 121 | return unserialize($cache_content[$key]['data']); 122 | } 123 | 124 | /** 125 | * Delete an item from cache file 126 | * @param string $key 127 | * @return string|bool 128 | */ 129 | public function delete($key) 130 | { 131 | $cache_content = $this->load_cache(); 132 | 133 | if(is_array($cache_content)) { 134 | if(isset($cache_content[$key])) { 135 | unset($cache_content[$key]); 136 | $cache_content = json_encode($cache_content); 137 | file_put_contents($this->get_cache_dir(), $cache_content); 138 | } else { 139 | echo 'Hata: delete() - Key {'.$key.'} bulunamadı.'; 140 | } 141 | } 142 | } 143 | 144 | /** 145 | * Chech expired cached data 146 | * @param int $time 147 | * @param int $expiration 148 | * @return bool 149 | */ 150 | private function check_expired($time, $expiration) 151 | { 152 | if($expiration !== 0) { 153 | $time_diff = time() - $time; 154 | if($time_diff > $expiration) 155 | return true; 156 | else 157 | return false; 158 | } else { 159 | return false; 160 | } 161 | } 162 | 163 | /** 164 | * Delete expired cached data 165 | * @return int 166 | */ 167 | public function delete_expired_cache() 168 | { 169 | $counter = 0; 170 | $cache_content = $this->load_cache(); 171 | if(is_array($cache_content)) { 172 | foreach($cache_content as $key => $value) { 173 | if($this->check_expired($value['time'], $value['expire']) === true) { 174 | unset($cache_content[$key]); 175 | $counter++; 176 | } 177 | } 178 | 179 | if($counter > 0) { 180 | $cache_content = json_encode($cache_content); 181 | file_put_contents($this->get_cache_dir(), $cache_content); 182 | } 183 | } 184 | return $counter; 185 | } 186 | 187 | /** 188 | * Delete all cached datas 189 | * @return void 190 | */ 191 | public function clear() 192 | { 193 | if(file_exists($this->get_cache_dir())) { 194 | $file = fopen($this->get_cache_dir(), 'w'); 195 | fclose($file); 196 | } 197 | } 198 | 199 | /** 200 | * Check cached datas with $key if exists 201 | * @param string $key 202 | * @return bool 203 | */ 204 | public function is_cached($key) 205 | { 206 | $this->delete_expired_cache(); 207 | if($this->load_cache() != false) { 208 | $cache_content = $this->load_cache(); 209 | return isset($cache_content[$key]['data']); 210 | } 211 | } 212 | 213 | /** 214 | * Hash cache file name 215 | * @param string $filename 216 | * @return string 217 | */ 218 | private function hash_file($filename) 219 | { 220 | return md5($filename); 221 | } 222 | 223 | /** 224 | * Set the name of cache file 225 | * @param string $filename 226 | * @return void 227 | */ 228 | public function set_cache($filename) 229 | { 230 | $this->filename = $filename; 231 | } 232 | 233 | /** 234 | * Get the name of cache file 235 | * @return string 236 | */ 237 | public function get_cache() 238 | { 239 | return $this->filename; 240 | } 241 | 242 | /** 243 | * Set cache path 244 | * @param string $path 245 | * @return void 246 | */ 247 | public function set_path($path) 248 | { 249 | $this->path = APP_DIR . $path; 250 | } 251 | 252 | /** 253 | * Get cache path 254 | * @return string 255 | */ 256 | public function get_path() 257 | { 258 | return $this->path; 259 | } 260 | 261 | /** 262 | * Set cache file extension 263 | * @param string $ext 264 | * @return void 265 | */ 266 | public function set_extension($ext) 267 | { 268 | $this->extension = $ext; 269 | } 270 | 271 | /** 272 | * Get cache file extension 273 | * @return string 274 | */ 275 | public function get_extension() 276 | { 277 | return $this->extension; 278 | } 279 | 280 | } 281 | 282 | ?> 283 | -------------------------------------------------------------------------------- /system/plugins/Curl.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Curl 9 | { 10 | // Curl Handle 11 | private $ch = null; 12 | 13 | // Folloe Redirects 14 | public $followRedirects = true; 15 | 16 | // CURLOPT Options to send with request 17 | public $options = []; 18 | 19 | // Headers to send with request 20 | public $headers = []; 21 | 22 | // Referer Url 23 | public $referer = null; 24 | 25 | // Use Cookie 26 | public $useCookie = false; 27 | 28 | // Cookie File 29 | public $cookieFile = ''; 30 | 31 | // User Agent 32 | public $userAgent = ''; 33 | 34 | // Response Body 35 | public $responseBody = ''; 36 | 37 | // Response Headers 38 | public $responseHeader = []; 39 | 40 | // Error Message 41 | private $error = ''; 42 | 43 | function __construct() 44 | { 45 | if ($this->useCookie) 46 | $this->cookieFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'curl_cookie.txt'; 47 | 48 | if ($this->userAgent === '') 49 | $this->userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'TitanMVC/PHP '.PHP_VERSION.' (http://github.com/tkaratug/titan-mvc)'; 50 | } 51 | 52 | /** 53 | * Get Just Header of The Page 54 | * @param $url 55 | * @param $params 56 | * @return void 57 | */ 58 | public function head($url, $params = []) 59 | { 60 | $this->request('HEAD', $url, $params); 61 | } 62 | 63 | /** 64 | * Get Request 65 | * @param $url 66 | * @param $params 67 | * @return void 68 | */ 69 | public function get($url, $params = []) 70 | { 71 | if (!empty($params)) { 72 | $url .= (stripos($url, '?') !== false) ? '&' : '?'; 73 | $url .= (is_string($params)) ? $params : http_build_query($params, '', '&'); 74 | } 75 | $this->request('GET', $url); 76 | } 77 | 78 | /** 79 | * Post Request 80 | * @param $url 81 | * @param $params 82 | * @return void 83 | */ 84 | public function post($url, $params = []) 85 | { 86 | $this->request('POST', $url, $params); 87 | } 88 | 89 | /** 90 | * Put Request 91 | * @param $url 92 | * @param $params 93 | * @return void 94 | */ 95 | public function put($url, $params = []) 96 | { 97 | $this->request('PUT', $url, $params); 98 | } 99 | 100 | /** 101 | * Delete Request 102 | * @param $url 103 | * @param $params 104 | * @return void 105 | */ 106 | public function delete($url, $params = []) 107 | { 108 | $this->request('DELETE', $url, $params); 109 | } 110 | 111 | /** 112 | * Make Request 113 | * @param $method 114 | * @param $url 115 | * @param $params 116 | * @return void 117 | */ 118 | private function request($method, $url, $params = []) 119 | { 120 | $this->error = ''; 121 | $this->ch = curl_init(); 122 | if (is_array($params)) $params = http_build_query($params, '', '&'); 123 | 124 | $this->set_request_method($method); 125 | $this->set_request_options($url, $params); 126 | $this->set_request_headers(); 127 | 128 | $response = curl_exec($this->ch); 129 | 130 | if ($response) { 131 | $response = $this->getResponse($response); 132 | } else { 133 | $this->error = curl_errno($this->ch).' - '.curl_error($this->ch); 134 | } 135 | 136 | curl_close($this->ch); 137 | } 138 | 139 | /** 140 | * Set Request Headers 141 | */ 142 | private function set_request_headers() 143 | { 144 | $headers = []; 145 | foreach ($this->headers as $key => $value) { 146 | $headers[] = $key.': '.$value; 147 | } 148 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); 149 | } 150 | 151 | /** 152 | * Set Request Method 153 | * @param $method 154 | */ 155 | private function set_request_method($method) 156 | { 157 | switch (strtoupper($method)) { 158 | case 'HEAD': 159 | curl_setopt($this->ch, CURLOPT_NOBODY, true); 160 | break; 161 | case 'GET': 162 | curl_setopt($this->ch, CURLOPT_HTTPGET, true); 163 | break; 164 | case 'POST': 165 | curl_setopt($this->ch, CURLOPT_POST, true); 166 | break; 167 | default: 168 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method); 169 | } 170 | } 171 | 172 | /** 173 | * Set Request Options 174 | * @param $url 175 | * @param $params 176 | * @return mixed 177 | */ 178 | private function set_request_options($url, $params) 179 | { 180 | curl_setopt($this->ch, CURLOPT_URL, $url); 181 | if (!empty($params)) curl_setopt($this->ch, CURLOPT_POSTFIELDS, $params); 182 | 183 | # Set some default CURL options 184 | curl_setopt($this->ch, CURLOPT_HEADER, true); 185 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); 186 | curl_setopt($this->ch, CURLOPT_USERAGENT, $this->userAgent); 187 | if ($this->useCookie !== false) { 188 | curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookieFile); 189 | curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookieFile); 190 | } 191 | if ($this->followRedirects) curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); 192 | if ($this->referer !== null) curl_setopt($this->ch, CURLOPT_REFERER, $this->referer); 193 | 194 | # Set any custom CURL options 195 | foreach ($this->options as $option => $value) { 196 | curl_setopt($this->ch, constant('CURLOPT_'.str_replace('CURLOPT_', '', strtoupper($option))), $value); 197 | } 198 | } 199 | 200 | /** 201 | * Get Response of the Curl Request 202 | * @param $response 203 | */ 204 | private function getResponse($response) 205 | { 206 | # Headers regex 207 | $pattern = '#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims'; 208 | 209 | # Extract headers from response 210 | preg_match_all($pattern, $response, $matches); 211 | $headers_string = array_pop($matches[0]); 212 | $headers = explode("\r\n", str_replace("\r\n\r\n", '', $headers_string)); 213 | 214 | # Remove headers from the response body 215 | $this->responseBody = str_replace($headers_string, '', $response); 216 | 217 | # Extract the version and status from the first header 218 | $version_and_status = array_shift($headers); 219 | preg_match('#HTTP/(\d\.\d)\s(\d\d\d)\s(.*)#', $version_and_status, $matches); 220 | $this->responseHeader['Http-Version'] = $matches[1]; 221 | $this->responseHeader['Status-Code'] = $matches[2]; 222 | $this->responseHeader['Status'] = $matches[2].' '.$matches[3]; 223 | 224 | # Convert headers into an associative array 225 | foreach ($headers as $header) { 226 | preg_match('#(.*?)\:\s(.*)#', $header, $matches); 227 | $this->responseHeader[$matches[1]] = $matches[2]; 228 | } 229 | } 230 | 231 | /** 232 | * Get Error 233 | * @return string 234 | */ 235 | function getError() 236 | { 237 | return $this->error; 238 | } 239 | 240 | } -------------------------------------------------------------------------------- /system/core/App.php: -------------------------------------------------------------------------------- 1 | titan = Loader::getInstance(); 19 | 20 | // Getting config file 21 | $this->config = $this->titan->config('config'); 22 | 23 | // Setting default controller and method 24 | $this->controller = $this->config['default_controller']; 25 | $this->method = $this->config['default_method']; 26 | 27 | // Setting controller directory 28 | if ($this->config['default_directory']) { 29 | $this->directory = 'controllers/' . $this->config['default_directory'] . '/'; 30 | } else { 31 | $this->directory = 'controllers/'; 32 | } 33 | 34 | // Getting current URL 35 | $this->url = $this->parseURL(); 36 | 37 | // Getting routes 38 | $this->routes = $this->titan->config('routes'); 39 | 40 | if($this->run() === false) { 41 | // Getting Controller 42 | $this->set_controller($this->url); 43 | 44 | // Getting Method 45 | $this->set_action($this->url); 46 | 47 | // Getting parameters 48 | $this->set_params($this->url); 49 | } 50 | 51 | // Composer Autoload 52 | if($this->config['composer'] == true) { 53 | if(file_exists('vendor/autoload.php')) 54 | require_once('vendor/autoload.php'); 55 | else 56 | echo 'UYARI: Composer yükleyicisi bulunamadı.'; 57 | } 58 | 59 | call_user_func_array([$this->controller, $this->method], $this->params); 60 | } 61 | 62 | private function run() 63 | { 64 | $matched = 0; 65 | 66 | if(BASE_DIR == '/') 67 | $url = ltrim($_SERVER['REQUEST_URI'], '/'); 68 | else 69 | $url = ltrim(str_replace(BASE_DIR,'',$_SERVER['REQUEST_URI']), '/'); 70 | 71 | foreach($this->routes as $key => $value) { 72 | $key = '/^' . str_replace('/', '\/', $key) . '$/'; 73 | 74 | if(preg_match($key, $url)) { 75 | $matched++; 76 | preg_match_all($key, $url, $matches); 77 | array_shift($matches); 78 | $target = explode('/', $value); 79 | 80 | if (is_dir(APP_DIR . 'controllers/' . $target[0])) { 81 | if (file_exists(APP_DIR . 'controllers/' . $target[0] . '/' . ucfirst($target[1]) . '.php')) { 82 | $this->controller = $this->makeURL(ucfirst($target[1])); 83 | $this->loadFile(APP_DIR . 'controllers/' . $target[0] . '/' . $this->controller); 84 | $this->controller = new $this->controller; 85 | } else { 86 | $this->loadFile(APP_DIR . 'views/errors/error404'); 87 | die(); 88 | } 89 | 90 | $this->method = $target[2]; 91 | } else { 92 | if(file_exists(APP_DIR . 'controllers/' . ucfirst($target[0]) . '.php')) { 93 | $this->controller = $this->makeURL(ucfirst($target[0])); 94 | $this->loadFile(APP_DIR . 'controllers/' . $this->controller); 95 | $this->controller = new $this->controller; 96 | } else { 97 | $this->loadFile(APP_DIR . 'views/errors/error_404'); 98 | die(); 99 | } 100 | 101 | $this->method = $target[1]; 102 | } 103 | 104 | foreach($matches as $indis => $match) { 105 | $target[$indis] = $match[0]; 106 | } 107 | 108 | $this->params = $target ? array_values($target) : []; 109 | } 110 | } 111 | 112 | if($matched > 0) 113 | return true; 114 | else 115 | return false; 116 | } 117 | 118 | /** 119 | * Setting Controller 120 | * @param array $url 121 | * @return void 122 | */ 123 | private function set_controller($url) 124 | { 125 | if(isset($url[0])) { 126 | 127 | if (is_dir(APP_DIR . 'controllers/' . $url[0])) { 128 | $this->controller_dir = true; 129 | if (file_exists(APP_DIR . 'controllers/' . $url[0] . '/' . $this->makeURL($url[1]) . '.php')) { 130 | $this->controller = $this->makeURL($url[1]); 131 | $this->loadFile(APP_DIR . 'controllers/' . $url[0] . '/' . $this->controller); 132 | $this->controller = new $this->controller; 133 | } else { 134 | $this->loadFile(APP_DIR . 'views/errors/error_404'); 135 | die(); 136 | } 137 | $this->url = array_diff_key($url, [0,1]); 138 | } else { 139 | if (file_exists(APP_DIR . $this->directory . $this->makeURL($url[0]) . '.php')) { 140 | $this->controller = $this->makeURL($url[0]); 141 | $this->loadFile(APP_DIR . $this->directory . $this->controller); 142 | $this->controller = new $this->controller; 143 | } else { 144 | $this->loadFile(APP_DIR . 'views/errors/error_404'); 145 | die(); 146 | } 147 | $this->url = array_diff_key($url, [0]); 148 | } 149 | 150 | } else { 151 | $this->loadFile(APP_DIR . $this->directory . $this->controller); 152 | $this->controller = new $this->controller; 153 | } 154 | } 155 | 156 | /** 157 | * Setting Action 158 | * @param array $url 159 | * @return void 160 | */ 161 | private function set_action($url) 162 | { 163 | if ($this->controller_dir === true) { 164 | if (isset($url[2])) { 165 | if ($url[2] != 'index') { 166 | if (method_exists($this->controller, $url[2])) { 167 | $this->method = $url[2]; 168 | } else { 169 | $this->loadFile(APP_DIR . 'views/errors/error_404'); 170 | die(); 171 | } 172 | } 173 | unset($this->url[2]); 174 | } 175 | } else { 176 | if (isset($url[1])) { 177 | if ($url[1] != 'index') { 178 | if (method_exists($this->controller, $url[1])) { 179 | $this->method = $url[1]; 180 | } else { 181 | $this->loadFile(APP_DIR . 'views/errors/error_404'); 182 | die(); 183 | } 184 | } 185 | unset($this->url[1]); 186 | } 187 | } 188 | } 189 | 190 | /** 191 | * Setting Parameters 192 | * @param array $url 193 | * @return void 194 | */ 195 | private function set_params($url) 196 | { 197 | $this->params = $url ? array_values($url) : []; 198 | } 199 | 200 | /** 201 | * Parsing URL 202 | * @return array 203 | */ 204 | public function parseURL() 205 | { 206 | if (isset($_GET['url'])) { 207 | return $url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL)); 208 | } 209 | } 210 | 211 | /** 212 | * Making URL 213 | * @param string $queryString 214 | * @return string 215 | */ 216 | public function makeURL($queryString) 217 | { 218 | $queryString = ucwords(strtolower(str_replace(['-','_','%20'], [' ',' ',' '], $queryString))); 219 | $queryString = str_replace(' ', '_', $queryString); 220 | return $queryString; 221 | } 222 | 223 | /** 224 | * Loading file 225 | * @param string $fileName 226 | * @return void 227 | */ 228 | public function loadFile($fileName) { 229 | $fileName = $fileName . '.php'; 230 | if (file_exists($fileName)) { 231 | return require_once $fileName; 232 | } else { 233 | $code = 1007; 234 | $text = 'Böyle bir dosya bulunmamaktadır. {' . $fileName . '}'; 235 | require_once APP_DIR . 'views/errors/error_system.php'; 236 | die(); 237 | } 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | v1.1.4 2 | [Düzeltme]: Database pluginindeki update() ve delete() methodları uygulandıktan sonra sorgu cümlesi resetlendi. 3 | [Düzeltme]: Url helperda bulunan redirect() fonksiyonundaki, belirtilen süre içerisinde yönlendirme yapmama hatası giderildi. 4 | [Düzeltme]: Edge şablon motoru ile çalışan view() fonksiyonundaki parametre hatası giderildi. 5 | [Yeni]: Database pluginine, PDO nesnesinin methodlarına erişim sağlayan pdo() methodu eklendi. 6 | [Yeni]: Validation pluginine, iki form elemanına girilen verileri karşılaştıran matches() methodu eklendi. 7 | [Yeni]: Mail plugini için "/app/config" içerisine ayar dosyası eklendi ve default ayarlar buradan okunacak şekilde düzeltildi. 8 | [Yeni]: File Upload plugini eklendi. 9 | [Yeni]: Curl plugini eklendi. 10 | 11 | v1.1.3 12 | [Düzeltme]: Mevcut 'Template' plugininin ismi 'Asset' olarak değiştirildi. 13 | [Yeni]: CSS, JS ve imaj dosyalarının yer aldığı '/public' dizinine erişmek için 'PUBLIC_DIR' sabiti tanımlandı. 14 | [Yeni]: 'Edge Template Engine' eklendi. Mevcut Template plugini Edge ile çalışacak şekilde güncellendi. 15 | [Yeni]: Model dosyalarını farklı dizinler içinde gruplayabilme desteği eklendi. 16 | 17 | v1.1.2 18 | - [Düzeltme]: Config dosyalarının yüklenmesi sırasında oluşan bir hata giderildi. 19 | - [Düzeltme]: Multi-Language kullanımında oluşan bir hata giderildi. 20 | - [Düzeltme]: Form Validation kullanımında oluşan bir hata giderildi. 21 | 22 | v1.1.1 23 | - Düzeltme: Rotalama sistemindeki BASE_DIR sabitinden kaynaklanan hata giderildi. 24 | - Düzeltme: Debug helperda bulunan 'query_debug()' methodu güncellendi. 25 | - Yeni: Sayfaya dahil edilecek olan plugin ve helperlar içerisinde 'Loader' yükleyici nesnesine erişim imkanı sağlandı. Böylece oluşturulacak bu plugin ve helperlara Titan'ın kendi kütüphaneleri dahil edilebilir. 26 | - Yeni: Hook sistemi eklendi. 27 | - Yeni: CSRF Protection desteği eklendi. 28 | - Yeni: Loader yükleyici nesnesine 'database()' methodu eklendi. Böylece oluşturulan helper ve plugin dosyalarında Database plugini çalıştırılabilir. 29 | - Yeni: Loader yükleyici nesnesine 'config()' methodu eklendi. Böylece 'app/config' dizini altında oluşturualcak config dosyaları, Loader nesnesi ile sisteme dahil edilebilir. 30 | 31 | v1.1.0 32 | - Düzeltme: Url helperında bulunan request_scheme() methodundan kaynaklanan hata giderildi. 33 | - Projede birden fazla uygulama çalıştırma desteği eklendi. 34 | ('/app/controllers' dizini içerisinde backend ve frontend olmak üzere 2 örnek dizin oluşturuldu. Yönetici paneli ve site ön yüzü bu şekilde birbirinden ayrı olarak kodlanabilir.) 35 | 36 | v1.0.9 37 | - Düzeltme: Database pluginindeki reset() methodu kaynaklı hata giderildi. 38 | - Düzeltme: '/app/config' dizini içerisindeki ayar dosyaları array veri döndürecek şekilde güncellendi. 39 | 40 | v1.0.8 41 | - Düzeltme: Database plugini TitanDB ile değiştirildi. 42 | - Yeni: Form helper eklendi. 43 | - Yeni: Validation (Doğrulama) plugini eklendi. 44 | - Yeni: Çoklu dil desteği eklendi. 45 | 46 | v1.0.7 47 | - Düzeltme: Cookie pluginine set_path(), set_domain(), set_secure(), set_http_only() methodları eklendi. 48 | - Düzeltme: Template plugininde remote js ve css dosyaları dahil etmedeki hata giderildi. 49 | - Düzeltme: Routing yapısı değiştirildi. 50 | - Yeni: Routing yapısına Regex ile düzenli ifadeler desteği eklendi. 51 | 52 | v1.0.6 53 | - Düzeltme: Template plugininde css,js ve image dosyaları kontrolünde yaşanan hata giderildi. 54 | - Düzeltme: App.php 'deki set_action() methodu, geçerli action bulunamadığında, default methoda parametre verecek şekilde düzenlendi. 55 | - Düzeltme: Url helperındaki base_url() methodunda bulunan BASE_DIR sabitinin boş olması durumunda hatalı adres döndürmesi önlendi. 56 | - Düzeltme: Input plugininde bulunan clean() methodunun ismi html_clean() olarak değiştirildi. 57 | - Düzeltme: Input plugininde form verilerini çeken get, post, put ve delete methodları, gelen veriyi default olarak xss_clean() methodu ile XSS Filtresinden geçirecek şekilde düzenlendi. 58 | - Yeni: Session pluginindeki set() methoduna, array ile toplu session oluşturabilme özelliği eklendi. 59 | - Yeni: Pagination plugini eklendi. 60 | - Yeni: Mail plugini eklendi. 61 | 62 | v1.0.5 63 | - Düzeltme: Session plugininde 'get()' methodu parametre almazsa tüm sessionu verecek şekilde düzenleme yapıldı. 64 | - Düzeltme: Session pluginine güvenlik konfigürasyonları eklendi. 65 | - Düzeltme: Cookie pluginindeki 'delete()' methodundan kaynaklanan hata giderildi. 66 | - Düzeltme: Varsayılan cookie süresi 1 hafta olarak ayarlandı. 67 | - Düzeltme: Response pluginindeki 'get_status()' methodunda, verilen parametreye göre status durumunu döndüren düzenleme yapıldı. 68 | - Düzeltme: Benchmark helperı kaldırıldı. 69 | - Yeni: Cache plugini eklendi. 70 | - Yeni: Benchmark plugini eklendi. 71 | - Yeni: Debug helperı eklendi. 72 | 73 | v1.0.4 74 | - Düzeltme: '/system' Dizini oluşturuldu. '/app/core' dizini ve altındaki dosyalar buraya taşındı. 75 | - Düzeltme: '/system/helpers' Dizini oluşturuldu. '/app/helpers' dizini altındaki default helper dosyaları buraya taşındı. 76 | - Düzeltme: '/system/plugins' Dizini oluşturuldu. '/app/plugins' dizini altındaki default plugin dosyaları buraya taşındı. 77 | - Düzeltme: Yeni oluşturulacak helper dosyaları '/app/helpers' dizini altında çalışacak şekilde düzenleme yapıldı. 78 | - Düzeltme: Yeni oluşturulacak plugin dosyaları '/app/plugins' dizini altında çalışacak şekilde düzenleme yapıldı. 79 | - Düzeltme: Template Plugininde tanımlanmamış js,css,title ve meta dizilerin döndürdüğü hata giderildi. 80 | - Düzeltme: Url Helperındaki redirect() fonksiyonuna method parametresi eklendi. 81 | - Düzeltme: Url Helperında base_url() fonksiyonuna parametre eklendi. base_url('path') şeklinde kullanılabilir. 82 | - Yeni: Composer desteği eklendi. 83 | - Yeni: Benchmark helperı eklendi. 84 | - Yeni: User Agent helperı eklendi. 85 | - Yeni: Url Helperına get_segments() ve current_segment() fonksiyonları eklendi. 86 | - Yeni: Template Pluginine set_favicon() ve get_favicon() methodları eklendi. 87 | 88 | v1.0.3 89 | - Düzeltme: 'index.php' dosyasına, environment tanımına göre hata gösterimini açıp kapatan düzenleme eklendi. 90 | - Düzeltme: 'Load.php' dosyasının ismi 'Loader.php' olarak değiştirildi. 91 | - Yeni: Controller içinde model tanımlarken, custom model ismi belirleyebilme özelliği eklendi. 92 | - Yeni: Session Hijacking güvenlik katmanı eklendi. 93 | - Yeni: Session pluginine Flash Message methodu eklendi. 94 | - Yeni: Cookie plugini eklendi. 95 | - Yeni: Basit bir Log plugini eklendi. 96 | - Yeni: Layout yönetimi için Template plugini eklendi. 97 | 98 | v1.0.2 99 | - Düzeltme: 'Notice: A session had already been started - ignoring session_start()' hatası giderildi. 100 | - Düzeltme: 'BASE_DIR' sabitine full url yerine sadece uygulamanın bulunduğu dizin verilecek şekilde düzeltildi. 101 | - Yeni: Routing üzerinde geliştirme yapıldı. Artık 'ornek' => 'controller/method' şeklinde rota tanımlanabiliyor. 102 | - Yeni: Url Helper eklendi. Helper sayfaya dahil edildiğinde içerisindeki fonksiyonlar kullanılabilir. 103 | - Yeni: Response Plugin eklendi. 104 | 105 | v1.0.1 106 | - Yeni: '/config' dizini içerisinde 'autoload.php' ve 'db.php' adında iki yeni dosya oluşturuldu. 107 | - Düzeltme: '/config/config.php' dosyasında yer alan helper ve plugin autoload dizileri '/config/autoload.php' dosyasına, database dizileri '/config/db.php' dosyasına taşındı. 108 | - Düzeltme: '/app/core/App.php' dosyasında bulunan construct methodu güncellendi. Controller, method ve parametre seçim methodları eklendi. 109 | - Düzeltme: '/app/core/Controller.php' dosyasında, otomatik yüklenecek helper ve pluginler için autoload config dosyası kullanıldı. 110 | - Düzeltme: '/app/core/Model.php' dosyasında, database bağlantı ayarları için db config dosyası kullanıldı. 111 | - Düzeltme: 'index.php' dosyasnıa 'BASE_DIR' sabiti eklendi. Config dosyasını include eden kod kaldırıldı. 112 | -------------------------------------------------------------------------------- /system/plugins/Pagination.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Pagination 9 | { 10 | public $config = []; 11 | public $base_url; 12 | public $per_page; 13 | public $total_rows; 14 | public $uri_segment; 15 | public $total_pages; 16 | public $current_page; 17 | 18 | public $main_tag_open = '
    '; 19 | public $main_tag_close = '
'; 20 | public $first_link = 'İlk'; 21 | public $last_link = 'Son'; 22 | public $first_tag_open = '
  • '; 23 | public $first_tag_close = '
  • '; 24 | public $prev_link = 'Önceki'; 25 | public $prev_tag_open = '
  • '; 26 | public $prev_tag_close = '
  • '; 27 | public $next_link = 'Sonraki'; 28 | public $next_tag_open = '
  • '; 29 | public $next_tag_close = '
  • '; 30 | public $last_tag_open = '
  • '; 31 | public $last_tag_close = '
  • '; 32 | public $cur_tag_open = '
  • '; 33 | public $cur_tag_close = '
  • '; 34 | public $num_tag_open = '
  • '; 35 | public $num_tag_close = '
  • '; 36 | 37 | 38 | public function init($config) 39 | { 40 | // Config 41 | $this->config = $config; 42 | 43 | try { 44 | // Set base pagination URL 45 | if(array_key_exists('base_url', $this->config)) 46 | $this->base_url = $config['base_url']; 47 | else 48 | throw new Exception('Sayfalama yapılacak URL adresini belirtiniz. {base_url}'); 49 | 50 | // Set per page 51 | if(array_key_exists('per_page', $this->config)) 52 | $this->per_page = $this->config['per_page']; 53 | else 54 | throw new Exception('Her bir sayfada gösterilecek kayıt sayısını belirtiniz. {per_page}'); 55 | 56 | // Set total record count 57 | if(array_key_exists('total_rows', $this->config)) 58 | $this->total_rows = $this->config['total_rows']; 59 | else 60 | throw new Exception('Sayfalama yapılacak toplam kayıt sayısını belirtiniz. {total_rows}'); 61 | 62 | // Set uri segment of page number 63 | if(array_key_exists('uri_segment', $this->config)) 64 | $this->uri_segment = $this->config['uri_segment']; 65 | else 66 | throw new Exception('Sayfa numarasının bulunduğu URL segmentini belirtiniz. {uri_segment}'); 67 | 68 | if(array_key_exists('per_page', $this->config) && array_key_exists('total_rows', $this->config)) { 69 | // Toplam sayfa sayısı 70 | if($this->total_rows % $this->per_page != 0) { 71 | $this->total_pages = ceil($this->total_rows / $this->per_page); 72 | } else { 73 | $this->total_pages = $this->total_rows / $this->per_page; 74 | } 75 | } else { 76 | throw new Exception('Her bir sayfada gösterilecek kayıt sayısı ve toplam kayıt sayısını belirtiniz.'); 77 | } 78 | } catch(Exception $e) { 79 | echo $e->getMessage(); 80 | } 81 | 82 | // Pagination number main html open tags 83 | if(array_key_exists('main_tag_open', $this->config)) 84 | $this->main_tag_open = $this->config['main_tag_open']; 85 | 86 | // Pagination number main html close tag 87 | if(array_key_exists('main_tag_close', $this->config)) 88 | $this->main_tag_close = $this->config['main_tag_close']; 89 | 90 | // First page link in pagination numbers 91 | if(array_key_exists('first_link', $this->config)) 92 | $this->first_link = $this->config['first_link']; 93 | 94 | // Last page link in pagination numbers 95 | if(array_key_exists('last_link', $this->config)) 96 | $this->last_link = $this->config['last_link']; 97 | 98 | // First page link html open tag 99 | if(array_key_exists('first_tag_open', $this->config)) 100 | $this->first_tag_open = $this->config['first_tag_open']; 101 | 102 | // First page link html close tag 103 | if(array_key_exists('first_tag_close', $this->config)) 104 | $this->first_tag_close = $this->config['first_tag_close']; 105 | 106 | // String for previous page link 107 | if(array_key_exists('prev_link', $this->config)) 108 | $this->prev_link = $this->config['prev_link']; 109 | 110 | // Previous page link html open tag 111 | if(array_key_exists('prev_tag_open', $this->config)) 112 | $this->prev_tag_open = $this->config['prev_tag_open']; 113 | 114 | // Previous page link html close tag 115 | if(array_key_exists('prev_tag_close', $this->config)) 116 | $this->prev_tag_close = $this->config['prev_tag_close']; 117 | 118 | // String for next page link 119 | if(array_key_exists('next_link', $this->config)) 120 | $this->next_link = $this->config['next_link']; 121 | 122 | // Next page link html open tag 123 | if(array_key_exists('next_tag_open', $this->config)) 124 | $this->next_tag_open = $this->config['next_tag_open']; 125 | 126 | // Next page link html close tag 127 | if(array_key_exists('next_tag_close', $this->config)) 128 | $this->next_tag_close = $this->config['next_tag_close']; 129 | 130 | // Last page link html open tag 131 | if(array_key_exists('last_tag_open', $this->config)) 132 | $this->last_tag_open = $this->config['last_tag_open']; 133 | 134 | // Last page link html close tag 135 | if(array_key_exists('last_tag_close', $this->config)) 136 | $this->last_tag_close = $this->config['last_tag_close']; 137 | 138 | // Current page link html open tag 139 | if(array_key_exists('cur_tag_open', $this->config)) 140 | $this->cur_tag_open = $this->config['cur_tag_open']; 141 | 142 | // Current page link html close tag 143 | if(array_key_exists('cur_tag_close', $this->config)) 144 | $this->cur_tag_close = $this->config['cur_tag_close']; 145 | 146 | // Page links html open tag 147 | if(array_key_exists('num_tag_open', $this->config)) 148 | $this->num_tag_open = $this->config['num_tag_open']; 149 | 150 | // Page links html close tag 151 | if(array_key_exists('num_tag_close', $this->config)) 152 | $this->num_tag_close = $this->config['num_tag_close']; 153 | } 154 | 155 | public function get_links() 156 | { 157 | // Set Current Page 158 | if(is_numeric(get_segments($this->uri_segment))) 159 | $this->current_page = get_segments($this->uri_segment); 160 | else 161 | $this->current_page = 1; 162 | 163 | // Page numbers 164 | if($this->total_pages > 1) { 165 | 166 | $links = $this->main_tag_open; 167 | 168 | if($this->current_page > 1) { 169 | // First Page Link 170 | if($this->first_link !== false) 171 | $links .= $this->first_tag_open . '' . $this->first_link . '' . $this->first_tag_close; 172 | 173 | // Previous Page Link 174 | $links .= $this->prev_tag_open . '' . $this->prev_link . '' . $this->prev_tag_close; 175 | } 176 | 177 | if($this->total_pages > 4 && $this->current_page > 4) { 178 | for($i = $this->current_page - 3; $i < $this->current_page; $i++) { 179 | $links .= $this->num_tag_open . '' . $i . '' . $this->num_tag_close; 180 | } 181 | 182 | $links .= $this->cur_tag_open . $i . $this->cur_tag_close; 183 | 184 | if($this->current_page != $this->total_pages) { 185 | if($this->current_page + 4 > $this->total_pages) $last_page = $this->current_page + ($this->total_pages-$this->current_page); else $last_page = $this->current_page + 3; 186 | for($i = $this->current_page + 1; $i <= $last_page; $i++) { 187 | $links .= $this->num_tag_open . '' . $i . '' . $this->num_tag_close; 188 | } 189 | } 190 | } elseif($this->total_pages > 4 && $this->current_page < 5) { 191 | if($this->current_page + 4 > $this->total_pages) $last_page = $this->current_page + ($this->total_pages-$this->current_page); else $last_page = $this->current_page + 3; 192 | for($i = 1; $i <= $last_page; $i++) { 193 | if($i == $this->current_page) 194 | $links .= $this->cur_tag_open . $i . $this->cur_tag_close; 195 | else 196 | $links .= $this->num_tag_open . '' . $i . '' . $this->num_tag_close; 197 | } 198 | } else { 199 | for($i = 1; $i <= $this->total_pages; $i++) 200 | { 201 | if($i == $this->current_page) 202 | $links .= $this->cur_tag_open . $i . $this->cur_tag_close; 203 | else 204 | $links .= $this->num_tag_open . '' . $i . '' . $this->num_tag_close; 205 | } 206 | } 207 | 208 | if($this->current_page < $this->total_pages) { 209 | // Next Page Link 210 | $links .= $this->next_tag_open . '' . $this->next_link . '' . $this->next_tag_close; 211 | 212 | // Last Page Link 213 | if($this->last_link !== false) 214 | $links .= $this->last_tag_open . '' . $this->last_link . '' . $this->last_tag_close; 215 | } 216 | 217 | $links .= $this->main_tag_close; 218 | 219 | return $links; 220 | 221 | } 222 | } 223 | 224 | } 225 | 226 | ?> -------------------------------------------------------------------------------- /system/plugins/Validation.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | class Validation 9 | { 10 | public $errors = []; 11 | 12 | protected $rules = []; 13 | 14 | protected $data = []; 15 | 16 | /** 17 | * Set validation Rules 18 | * @param $rules 19 | */ 20 | public function set_rules($rules) 21 | { 22 | $this->rules = $rules; 23 | } 24 | 25 | /** 26 | * Set Data to Validate 27 | * @param $data 28 | */ 29 | public function set_data($data, $sanitize = false) 30 | { 31 | if($sanitize == true) 32 | $this->data = $this->sanitize($data); 33 | else 34 | $this->data = $data; 35 | } 36 | 37 | public function is_valid($data = [], $rules = []) 38 | { 39 | if( ! is_array($data) || ! is_array($rules) ) { 40 | return false; 41 | } 42 | 43 | if ( count($data) == 0 ) { 44 | $data = $this->data; 45 | } 46 | 47 | if( count($rules) == 0) { 48 | $rules = $this->rules; 49 | } 50 | 51 | foreach($rules as $key => $value) { 52 | $parts = explode('|', $value); 53 | 54 | foreach($parts as $part) { 55 | if(strpos($part, ',')) { 56 | $group = explode(',', $part); 57 | $filter = $group[0]; 58 | $params = $group[1]; 59 | 60 | if($filter == 'matches') { 61 | if($this->matches($data[$key], $data[$params]) === false) 62 | $this->errors[] = lang('validation', $filter . '_error', ['%s' => $key, '%t' => $params]); 63 | } else { 64 | if($this->$filter($data[$key], $params) === false) 65 | $this->errors[] = lang('validation', $filter . '_error', ['%s' => $key, '%t' => $params]); 66 | } 67 | } else { 68 | if ($this->$part($data[$key]) === false) 69 | $this->errors[] = lang('validation', $part . '_error', $key); 70 | } 71 | } 72 | } 73 | 74 | if(count($this->errors) > 0) 75 | return false; 76 | else 77 | return true; 78 | 79 | } 80 | 81 | /** 82 | * Sanitizing Data 83 | * @param string $data 84 | * @return string 85 | */ 86 | public function sanitize($data) 87 | { 88 | if( ! is_array($data) ) { 89 | return filter_var(trim($data), FILTER_SANITIZE_STRING); 90 | } else { 91 | foreach($data as $key => $value) { 92 | $data[$key] = filter_var($value, FILTER_SANITIZE_STRING); 93 | } 94 | return $data; 95 | } 96 | 97 | } 98 | 99 | /** 100 | * Required Field Control 101 | * @param string $data 102 | * @return bool 103 | */ 104 | protected function required($data) 105 | { 106 | if(!empty($data) && !is_null($data) && $data !== '') { 107 | return true; 108 | } else { 109 | return false; 110 | } 111 | } 112 | 113 | /** 114 | * Numeric Field Control 115 | * @param int $data 116 | * @return bool 117 | */ 118 | protected function numeric($data) 119 | { 120 | if(is_int($data) || is_numeric($data)) { 121 | return true; 122 | } else { 123 | return false; 124 | } 125 | } 126 | 127 | /** 128 | * Email Validation 129 | * @param string $email 130 | * @return bool 131 | */ 132 | protected function email($email) 133 | { 134 | if(filter_var($email, FILTER_VALIDATE_EMAIL)) { 135 | return true; 136 | } else { 137 | return false; 138 | } 139 | } 140 | 141 | /** 142 | * Minimum Character Check 143 | * @param string $data 144 | * @param int $length 145 | * @return bool 146 | */ 147 | protected function min_len($data, $length) 148 | { 149 | if(strlen(trim($data)) < $length) { 150 | return false; 151 | } else { 152 | return true; 153 | } 154 | } 155 | 156 | /** 157 | * Maximum Character Check 158 | * @param string $data 159 | * @param int $length 160 | * @return bool 161 | */ 162 | protected function max_len($data, $length) 163 | { 164 | if(strlen(trim($data)) > $length) { 165 | return false; 166 | } else { 167 | return true; 168 | } 169 | } 170 | 171 | /** 172 | * Exact Length Check 173 | * @param string $data 174 | * @param int $length 175 | * @return bool 176 | */ 177 | protected function exact_len($data, $length) 178 | { 179 | if(strlen(trim($data)) == $length) { 180 | return true; 181 | } else { 182 | return false; 183 | } 184 | } 185 | 186 | /** 187 | * Alpha Character Validation 188 | * @param string $data 189 | * @return bool 190 | */ 191 | protected function alpha($data) 192 | { 193 | if( ! is_string($data) ) { 194 | return false; 195 | } 196 | 197 | return ctype_alpha($data); 198 | } 199 | 200 | /** 201 | * Alphanumeric Character Validation 202 | * @param string $data 203 | * @return bool 204 | */ 205 | protected function alpha_num($data) 206 | { 207 | return ctype_alnum($data); 208 | } 209 | 210 | /** 211 | * Alpha-dash Character Validation 212 | * @param string $data 213 | * @return bool 214 | */ 215 | protected function alpha_dash($data) 216 | { 217 | return (!preg_match("/^([-a-z0-9_-])+$/i", $data)) ? false : true; 218 | } 219 | 220 | /** 221 | * Alpha-space Character Validation 222 | * @param string $data 223 | * @return bool 224 | */ 225 | protected function alpha_space($data) 226 | { 227 | return (!preg_match("/^([A-Za-z0-9- ])+$/i", $data)) ? false : true; 228 | } 229 | 230 | /** 231 | * Integer Validation 232 | * @param int $data 233 | * @return bool 234 | */ 235 | protected function integer($data) 236 | { 237 | if( is_int($data) ) { 238 | return true; 239 | } else { 240 | return false; 241 | } 242 | } 243 | 244 | /** 245 | * Boolean Validation 246 | * @param string $data 247 | * @return bool 248 | */ 249 | protected function boolean($data) 250 | { 251 | if($data === true || $data === false) { 252 | return true; 253 | } else { 254 | return false; 255 | } 256 | } 257 | 258 | /** 259 | * Float Validation 260 | * @param string $data 261 | * @return bool 262 | */ 263 | protected function float($data) 264 | { 265 | if( is_float($data) ) { 266 | return true; 267 | } else { 268 | return false; 269 | } 270 | } 271 | 272 | /** 273 | * URL Validation 274 | * @param string $url 275 | * @return bool 276 | */ 277 | protected function valid_url($url) 278 | { 279 | if (filter_var($url, FILTER_VALIDATE_URL)) { 280 | return true; 281 | } else { 282 | return false; 283 | } 284 | } 285 | 286 | /** 287 | * IP Validation 288 | * @param string $ip 289 | * @return bool 290 | */ 291 | protected function valid_ip($ip) 292 | { 293 | if(filter_var($ip, FILTER_VALIDATE_IP)) { 294 | return true; 295 | } else { 296 | return false; 297 | } 298 | } 299 | 300 | /** 301 | * IPv4 Validation 302 | * @param string $ip 303 | * @return bool 304 | */ 305 | protected function valid_ipv4($ip) 306 | { 307 | if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { 308 | return true; 309 | } else { 310 | return false; 311 | } 312 | } 313 | 314 | /** 315 | * IPv6 Validation 316 | * @param string $ip 317 | * @return bool 318 | */ 319 | protected function valid_ipv6($ip) 320 | { 321 | if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { 322 | return true; 323 | } else { 324 | return false; 325 | } 326 | } 327 | 328 | /** 329 | * Credit Card Validation 330 | * @param string $data 331 | * @return bool 332 | */ 333 | protected function valid_cc($data) 334 | { 335 | $number = preg_replace('/\D/', '', $data); 336 | 337 | if (function_exists('mb_strlen')) { 338 | $number_length = mb_strlen($number); 339 | } else { 340 | $number_length = strlen($number); 341 | } 342 | 343 | $parity = $number_length % 2; 344 | 345 | $total=0; 346 | 347 | for ($i=0; $i<$number_length; $i++) { 348 | $digit = $number[$i]; 349 | 350 | if ($i % 2 == $parity) { 351 | $digit *= 2; 352 | 353 | if ($digit > 9) { 354 | $digit -= 9; 355 | } 356 | } 357 | 358 | $total += $digit; 359 | } 360 | 361 | return ($total % 10 == 0) ? true : false; 362 | } 363 | 364 | /** 365 | * Field must contain something 366 | * @param string $data 367 | * @param string $part 368 | * @return bool 369 | */ 370 | protected function contains($data, $part) 371 | { 372 | if(strpos($data, $part) !== false) { 373 | return true; 374 | } else { 375 | return false; 376 | } 377 | } 378 | 379 | /** 380 | * Minimum Value Validation 381 | * @param int $data 382 | * @param int $min 383 | * @return bool 384 | */ 385 | protected function min_numeric($data, $min) 386 | { 387 | if(is_numeric($data) && is_numeric($min) && $data >= $min) { 388 | return true; 389 | } else { 390 | return false; 391 | } 392 | } 393 | 394 | /** 395 | * Maximum Value Validation 396 | * @param int $data 397 | * @param int $max 398 | * @return bool 399 | */ 400 | protected function max_numeric($data, $max) 401 | { 402 | if(is_numeric($data) && is_numeric($max) && $data <= $max) { 403 | return true; 404 | } else { 405 | return false; 406 | } 407 | } 408 | 409 | /** 410 | * Matched Fields Validation 411 | * @param string $data 412 | * @param string $field 413 | * @return bool 414 | */ 415 | protected function matches($data, $field) 416 | { 417 | if($data == $field) 418 | return true; 419 | else 420 | return false; 421 | } 422 | 423 | } -------------------------------------------------------------------------------- /system/plugins/Mail/Pop3.php: -------------------------------------------------------------------------------- 1 | 8 | * @author Jim Jagielski (jimjag) 9 | * @author Andy Prevost (codeworxtech) 10 | * @author Brent R. Matzelle (original founder) 11 | * @copyright 2012 - 2014 Marcus Bointon 12 | * @copyright 2010 - 2012 Jim Jagielski 13 | * @copyright 2004 - 2009 Andy Prevost 14 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License 15 | * @note This program is distributed in the hope that it will be useful - WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. 18 | */ 19 | 20 | /** 21 | * PHPMailer POP-Before-SMTP Authentication Class. 22 | * Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication. 23 | * Does not support APOP. 24 | * @package PHPMailer 25 | * @author Richard Davey (original author) 26 | * @author Marcus Bointon (Synchro/coolbru) 27 | * @author Jim Jagielski (jimjag) 28 | * @author Andy Prevost (codeworxtech) 29 | */ 30 | class POP3 31 | { 32 | /** 33 | * The POP3 PHPMailer Version number. 34 | * @var string 35 | * @access public 36 | */ 37 | public $Version = '5.2.14'; 38 | 39 | /** 40 | * Default POP3 port number. 41 | * @var integer 42 | * @access public 43 | */ 44 | public $POP3_PORT = 110; 45 | 46 | /** 47 | * Default timeout in seconds. 48 | * @var integer 49 | * @access public 50 | */ 51 | public $POP3_TIMEOUT = 30; 52 | 53 | /** 54 | * POP3 Carriage Return + Line Feed. 55 | * @var string 56 | * @access public 57 | * @deprecated Use the constant instead 58 | */ 59 | public $CRLF = "\r\n"; 60 | 61 | /** 62 | * Debug display level. 63 | * Options: 0 = no, 1+ = yes 64 | * @var integer 65 | * @access public 66 | */ 67 | public $do_debug = 0; 68 | 69 | /** 70 | * POP3 mail server hostname. 71 | * @var string 72 | * @access public 73 | */ 74 | public $host; 75 | 76 | /** 77 | * POP3 port number. 78 | * @var integer 79 | * @access public 80 | */ 81 | public $port; 82 | 83 | /** 84 | * POP3 Timeout Value in seconds. 85 | * @var integer 86 | * @access public 87 | */ 88 | public $tval; 89 | 90 | /** 91 | * POP3 username 92 | * @var string 93 | * @access public 94 | */ 95 | public $username; 96 | 97 | /** 98 | * POP3 password. 99 | * @var string 100 | * @access public 101 | */ 102 | public $password; 103 | 104 | /** 105 | * Resource handle for the POP3 connection socket. 106 | * @var resource 107 | * @access protected 108 | */ 109 | protected $pop_conn; 110 | 111 | /** 112 | * Are we connected? 113 | * @var boolean 114 | * @access protected 115 | */ 116 | protected $connected = false; 117 | 118 | /** 119 | * Error container. 120 | * @var array 121 | * @access protected 122 | */ 123 | protected $errors = array(); 124 | 125 | /** 126 | * Line break constant 127 | */ 128 | const CRLF = "\r\n"; 129 | 130 | /** 131 | * Simple static wrapper for all-in-one POP before SMTP 132 | * @param $host 133 | * @param integer|boolean $port The port number to connect to 134 | * @param integer|boolean $timeout The timeout value 135 | * @param string $username 136 | * @param string $password 137 | * @param integer $debug_level 138 | * @return boolean 139 | */ 140 | public static function popBeforeSmtp( 141 | $host, 142 | $port = false, 143 | $timeout = false, 144 | $username = '', 145 | $password = '', 146 | $debug_level = 0 147 | ) { 148 | $pop = new POP3; 149 | return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level); 150 | } 151 | 152 | /** 153 | * Authenticate with a POP3 server. 154 | * A connect, login, disconnect sequence 155 | * appropriate for POP-before SMTP authorisation. 156 | * @access public 157 | * @param string $host The hostname to connect to 158 | * @param integer|boolean $port The port number to connect to 159 | * @param integer|boolean $timeout The timeout value 160 | * @param string $username 161 | * @param string $password 162 | * @param integer $debug_level 163 | * @return boolean 164 | */ 165 | public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0) 166 | { 167 | $this->host = $host; 168 | // If no port value provided, use default 169 | if (false === $port) { 170 | $this->port = $this->POP3_PORT; 171 | } else { 172 | $this->port = (integer)$port; 173 | } 174 | // If no timeout value provided, use default 175 | if (false === $timeout) { 176 | $this->tval = $this->POP3_TIMEOUT; 177 | } else { 178 | $this->tval = (integer)$timeout; 179 | } 180 | $this->do_debug = $debug_level; 181 | $this->username = $username; 182 | $this->password = $password; 183 | // Reset the error log 184 | $this->errors = array(); 185 | // connect 186 | $result = $this->connect($this->host, $this->port, $this->tval); 187 | if ($result) { 188 | $login_result = $this->login($this->username, $this->password); 189 | if ($login_result) { 190 | $this->disconnect(); 191 | return true; 192 | } 193 | } 194 | // We need to disconnect regardless of whether the login succeeded 195 | $this->disconnect(); 196 | return false; 197 | } 198 | 199 | /** 200 | * Connect to a POP3 server. 201 | * @access public 202 | * @param string $host 203 | * @param integer|boolean $port 204 | * @param integer $tval 205 | * @return boolean 206 | */ 207 | public function connect($host, $port = false, $tval = 30) 208 | { 209 | // Are we already connected? 210 | if ($this->connected) { 211 | return true; 212 | } 213 | 214 | //On Windows this will raise a PHP Warning error if the hostname doesn't exist. 215 | //Rather than suppress it with @fsockopen, capture it cleanly instead 216 | set_error_handler(array($this, 'catchWarning')); 217 | 218 | if (false === $port) { 219 | $port = $this->POP3_PORT; 220 | } 221 | 222 | // connect to the POP3 server 223 | $this->pop_conn = fsockopen( 224 | $host, // POP3 Host 225 | $port, // Port # 226 | $errno, // Error Number 227 | $errstr, // Error Message 228 | $tval 229 | ); // Timeout (seconds) 230 | // Restore the error handler 231 | restore_error_handler(); 232 | 233 | // Did we connect? 234 | if (false === $this->pop_conn) { 235 | // It would appear not... 236 | $this->setError(array( 237 | 'error' => "Failed to connect to server $host on port $port", 238 | 'errno' => $errno, 239 | 'errstr' => $errstr 240 | )); 241 | return false; 242 | } 243 | 244 | // Increase the stream time-out 245 | stream_set_timeout($this->pop_conn, $tval, 0); 246 | 247 | // Get the POP3 server response 248 | $pop3_response = $this->getResponse(); 249 | // Check for the +OK 250 | if ($this->checkResponse($pop3_response)) { 251 | // The connection is established and the POP3 server is talking 252 | $this->connected = true; 253 | return true; 254 | } 255 | return false; 256 | } 257 | 258 | /** 259 | * Log in to the POP3 server. 260 | * Does not support APOP (RFC 2828, 4949). 261 | * @access public 262 | * @param string $username 263 | * @param string $password 264 | * @return boolean 265 | */ 266 | public function login($username = '', $password = '') 267 | { 268 | if (!$this->connected) { 269 | $this->setError('Not connected to POP3 server'); 270 | } 271 | if (empty($username)) { 272 | $username = $this->username; 273 | } 274 | if (empty($password)) { 275 | $password = $this->password; 276 | } 277 | 278 | // Send the Username 279 | $this->sendString("USER $username" . self::CRLF); 280 | $pop3_response = $this->getResponse(); 281 | if ($this->checkResponse($pop3_response)) { 282 | // Send the Password 283 | $this->sendString("PASS $password" . self::CRLF); 284 | $pop3_response = $this->getResponse(); 285 | if ($this->checkResponse($pop3_response)) { 286 | return true; 287 | } 288 | } 289 | return false; 290 | } 291 | 292 | /** 293 | * Disconnect from the POP3 server. 294 | * @access public 295 | */ 296 | public function disconnect() 297 | { 298 | $this->sendString('QUIT'); 299 | //The QUIT command may cause the daemon to exit, which will kill our connection 300 | //So ignore errors here 301 | try { 302 | @fclose($this->pop_conn); 303 | } catch (Exception $e) { 304 | //Do nothing 305 | }; 306 | } 307 | 308 | /** 309 | * Get a response from the POP3 server. 310 | * $size is the maximum number of bytes to retrieve 311 | * @param integer $size 312 | * @return string 313 | * @access protected 314 | */ 315 | protected function getResponse($size = 128) 316 | { 317 | $response = fgets($this->pop_conn, $size); 318 | if ($this->do_debug >= 1) { 319 | echo "Server -> Client: $response"; 320 | } 321 | return $response; 322 | } 323 | 324 | /** 325 | * Send raw data to the POP3 server. 326 | * @param string $string 327 | * @return integer 328 | * @access protected 329 | */ 330 | protected function sendString($string) 331 | { 332 | if ($this->pop_conn) { 333 | if ($this->do_debug >= 2) { //Show client messages when debug >= 2 334 | echo "Client -> Server: $string"; 335 | } 336 | return fwrite($this->pop_conn, $string, strlen($string)); 337 | } 338 | return 0; 339 | } 340 | 341 | /** 342 | * Checks the POP3 server response. 343 | * Looks for for +OK or -ERR. 344 | * @param string $string 345 | * @return boolean 346 | * @access protected 347 | */ 348 | protected function checkResponse($string) 349 | { 350 | if (substr($string, 0, 3) !== '+OK') { 351 | $this->setError(array( 352 | 'error' => "Server reported an error: $string", 353 | 'errno' => 0, 354 | 'errstr' => '' 355 | )); 356 | return false; 357 | } else { 358 | return true; 359 | } 360 | } 361 | 362 | /** 363 | * Add an error to the internal error store. 364 | * Also display debug output if it's enabled. 365 | * @param $error 366 | * @access protected 367 | */ 368 | protected function setError($error) 369 | { 370 | $this->errors[] = $error; 371 | if ($this->do_debug >= 1) { 372 | echo '
    ';
    373 |             foreach ($this->errors as $error) {
    374 |                 print_r($error);
    375 |             }
    376 |             echo '
    '; 377 | } 378 | } 379 | 380 | /** 381 | * Get an array of error messages, if any. 382 | * @return array 383 | */ 384 | public function getErrors() 385 | { 386 | return $this->errors; 387 | } 388 | 389 | /** 390 | * POP3 connection error handler. 391 | * @param integer $errno 392 | * @param string $errstr 393 | * @param string $errfile 394 | * @param integer $errline 395 | * @access protected 396 | */ 397 | protected function catchWarning($errno, $errstr, $errfile, $errline) 398 | { 399 | $this->setError(array( 400 | 'error' => "Connecting to the POP3 server raised a PHP warning: ", 401 | 'errno' => $errno, 402 | 'errstr' => $errstr, 403 | 'errfile' => $errfile, 404 | 'errline' => $errline 405 | )); 406 | } 407 | } 408 | -------------------------------------------------------------------------------- /system/helpers/Form.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | /** 9 | * Form open 10 | * @param string|array $name 11 | * @param array $attr 12 | * @return string 13 | */ 14 | if ( ! function_exists('form_open') ) { 15 | function form_open($name = '', $attr = []) 16 | { 17 | if(is_array($name)) { 18 | $form = '
    0) { 20 | foreach($name as $key => $val) 21 | $form .= $key . '="' . $val . '" '; 22 | } 23 | } else { 24 | $form = ' 0) { 27 | foreach($attr as $key => $val) { 28 | $form .= $key . '="' . $val . '" '; 29 | } 30 | } 31 | } 32 | 33 | $form = trim($form); 34 | $form .= '>'; 35 | 36 | return $form . "\n"; 37 | } 38 | } 39 | 40 | /** 41 | * Text input 42 | * @param string|array $name 43 | * @param array $attr 44 | * @return string 45 | */ 46 | if ( ! function_exists('form_input') ) { 47 | function form_input($name = '', $attr = []) 48 | { 49 | if(is_array($name)) { 50 | $element = ' 0) { 52 | foreach($name as $key => $val) { 53 | $element .= $key . '="' . $val . '" '; 54 | } 55 | } 56 | } else { 57 | $element = ' 0) { 60 | foreach($attr as $key => $val) { 61 | $element .= $key . '="' . $val . '" '; 62 | } 63 | } 64 | } 65 | 66 | $element = trim($element); 67 | $element .= '>'; 68 | 69 | return $element . "\n"; 70 | } 71 | } 72 | 73 | /** 74 | * Password input 75 | * @param string|array $name 76 | * @param array $attr 77 | * @return string 78 | */ 79 | if ( ! function_exists('form_password') ) { 80 | function form_password($name = '', $attr = []) 81 | { 82 | if(is_array($name)) { 83 | $element = ' 0) { 85 | foreach($name as $key => $val) { 86 | $element .= $key . '="' . $val . '" '; 87 | } 88 | } 89 | } else { 90 | $element = ' 0) { 93 | foreach($attr as $key => $val) { 94 | $element .= $key . '="' . $val . '" '; 95 | } 96 | } 97 | } 98 | 99 | $element = trim($element); 100 | $element .= '>'; 101 | 102 | return $element . "\n"; 103 | } 104 | } 105 | 106 | /** 107 | * Hidden input 108 | * @param string|array $name 109 | * @param string $value 110 | * @return string 111 | */ 112 | if ( ! function_exists('form_hidden') ) { 113 | function form_hidden($name = '', $value = '') 114 | { 115 | if(is_array($name)) { 116 | $element = ' 0) { 118 | foreach($name as $key => $val) { 119 | $element .= $key . '="' . $val . '" '; 120 | } 121 | } 122 | $element = trim($element); 123 | $element .= '>'; 124 | } else { 125 | $element = ''; 126 | } 127 | 128 | return $element . "\n"; 129 | } 130 | } 131 | 132 | /** 133 | * File input 134 | * @param string|array $name 135 | * @param bool $multiple 136 | * @param array $attr 137 | * @return string 138 | */ 139 | if ( ! function_exists('form_file') ) { 140 | function form_file($name = '', $multiple = false, $attr = []) 141 | { 142 | if(is_array($name)) { 143 | $element = ' 0) { 145 | foreach($name as $key => $val) { 146 | $element .= $key . '="' . $val . '" '; 147 | } 148 | } 149 | } else { 150 | if($multiple == true) 151 | $element = ' 0) { 156 | foreach($attr as $key => $val) { 157 | $element .= $key . '="' . $val . '" '; 158 | } 159 | } 160 | } 161 | 162 | $element = trim($element); 163 | $element .= '>'; 164 | 165 | return $element . "\n"; 166 | } 167 | } 168 | 169 | /** 170 | * Custom input 171 | * @param string|array $type 172 | * @param string $name 173 | * @param array $attr 174 | * @return string 175 | */ 176 | if ( ! function_exists('form_custom') ) { 177 | function form_custom($type = '', $name = '', $attr = []) 178 | { 179 | if(is_array($type)) { 180 | $element = ' 0) { 182 | foreach($type as $key => $val) { 183 | $element .= $key . '="' . $val . '" '; 184 | } 185 | } 186 | } else { 187 | $element = ' 0) { 190 | foreach($attr as $key => $val) { 191 | $element .= $key . '="' . $val . '" '; 192 | } 193 | } 194 | } 195 | 196 | $element = trim($element); 197 | $element .= '>'; 198 | 199 | return $element . "\n"; 200 | } 201 | } 202 | 203 | /** 204 | * Textarea 205 | * @param string|array $name 206 | * @param string $text 207 | * @param array $attr 208 | * @return string 209 | */ 210 | if ( ! function_exists('form_textarea') ) { 211 | function form_textarea($name = '', $text = '', $attr = []) 212 | { 213 | if(is_array($name)) { 214 | $element = ''; 232 | 233 | return $element . "\n"; 234 | } 235 | } 236 | 237 | /** 238 | * SelectBox 239 | * @param string|array $name 240 | * @param array $options 241 | * @param string $selected 242 | * @param array $attr 243 | * @return string 244 | */ 245 | if ( ! function_exists('form_select') ) { 246 | function form_select($name = '', $options = [], $selected = '', $attr = []) 247 | { 248 | if(is_array($name)) { 249 | $element = ' 0) { 259 | foreach($attr as $key => $val) { 260 | $element .= $key . '="' . $val . '" '; 261 | } 262 | } 263 | } 264 | 265 | $element = trim($element); 266 | $element .= '>'; 267 | 268 | $dropdown = ''; 269 | if(count($options) > 0) { 270 | foreach($options as $key => $val) { 271 | if($selected && $val == $selected) 272 | $dropdown .= ''; 273 | else 274 | $dropdown .= ''; 275 | } 276 | } 277 | 278 | return $element . "\n" . $dropdown . "\n" . ''; 279 | } 280 | } 281 | 282 | /** 283 | * Multiple SelectBox 284 | * @param string|array $name 285 | * @param array $options 286 | * @param string $selected 287 | * @param array $attr 288 | * @return string 289 | */ 290 | if ( ! function_exists('form_multiSelect') ) { 291 | function form_multiSelect($name = '', $options = [], $selected = '', $attr = []) 292 | { 293 | if(is_array($name)) { 294 | $element = ' 0) { 304 | foreach($attr as $key => $val) { 305 | $element .= $key . '="' . $val . '" '; 306 | } 307 | } 308 | } 309 | 310 | $element = trim($element); 311 | $element .= '>'; 312 | 313 | $dropdown = ''; 314 | if(count($options) > 0) { 315 | foreach($options as $key => $val) { 316 | if($selected && $val == $selected) 317 | $dropdown .= ''; 318 | else 319 | $dropdown .= ''; 320 | } 321 | } 322 | 323 | return $element . "\n" . $dropdown . "\n" . ''; 324 | } 325 | } 326 | 327 | /** 328 | * Checkbox 329 | * @param string|array $name 330 | * @param string $value 331 | * @param bool $checked 332 | * @param array $attr 333 | * @return string 334 | */ 335 | if ( ! function_exists('form_checkbox') ) { 336 | function form_checkbox($name = '', $checked = false, $value = '', $attr = []) 337 | { 338 | if(is_array($name)) { 339 | $element = ' 0) { 341 | foreach($name as $key => $val) { 342 | $element .= $key . '="' . $val . '" '; 343 | } 344 | } 345 | } else { 346 | $element = ' 0) { 349 | foreach($attr as $key => $val) { 350 | $element .= $key . '="' . $val . '" '; 351 | } 352 | } 353 | } 354 | 355 | if($checked == true) 356 | $element .= 'checked'; 357 | 358 | $element = trim($element); 359 | $element .= '>'; 360 | 361 | return $element . "\n"; 362 | } 363 | } 364 | 365 | /** 366 | * Radio button 367 | * @param string|array $name 368 | * @param string $value 369 | * @param bool $checked 370 | * @param array $attr 371 | * @return string 372 | */ 373 | if ( ! function_exists('form_radio') ) { 374 | function form_radio($name = '', $checked = false, $value = '', $attr = []) 375 | { 376 | if(is_array($name)) { 377 | $element = ' 0) { 379 | foreach($name as $key => $val) { 380 | $element .= $key . '="' . $val . '" '; 381 | } 382 | } 383 | } else { 384 | $element = ' 0) { 387 | foreach($attr as $key => $val) { 388 | $element .= $key . '="' . $val . '" '; 389 | } 390 | } 391 | } 392 | 393 | if($checked == true) 394 | $element .= 'checked'; 395 | 396 | $element = trim($element); 397 | $element .= '>'; 398 | 399 | return $element . "\n"; 400 | } 401 | } 402 | 403 | /** 404 | * Form submit 405 | * @param string|array $name 406 | * @param string $value 407 | * @param array $attr 408 | * @return string 409 | */ 410 | if ( ! function_exists('form_submit') ) { 411 | function form_submit($name = '', $value = '', $attr = []) 412 | { 413 | if(is_array($name)) { 414 | $element = ' 0) { 416 | foreach($name as $key => $val) { 417 | $element .= $key . '="' . $val . '" '; 418 | } 419 | } 420 | } else { 421 | $element = ' 0) { 424 | foreach($attr as $key => $val) { 425 | $element .= $key . '="' . $val . '" '; 426 | } 427 | } 428 | } 429 | 430 | $element = trim($element); 431 | $element .= '>'; 432 | 433 | return $element . "\n"; 434 | } 435 | } 436 | 437 | /** 438 | * Form button 439 | * @param string|array $name 440 | * @param string $content 441 | * @param array $attr 442 | * @return string 443 | */ 444 | if ( ! function_exists('form_button') ) { 445 | function form_button($name = '', $content = '', $attr = []) 446 | { 447 | if(is_array($name)) { 448 | $element = ''; 466 | 467 | return $element . "\n"; 468 | } 469 | } 470 | 471 | /** 472 | * Form reset button 473 | * @param string|array $name 474 | * @param string $value 475 | * @param array $attr 476 | * @return string 477 | */ 478 | if ( ! function_exists('form_reset') ) { 479 | function form_reset($name = '', $value = '', $attr = []) 480 | { 481 | if(is_array($name)) { 482 | $element = ' 0) { 484 | foreach($name as $key => $val) { 485 | $element .= $key . '="' . $val . '" '; 486 | } 487 | } 488 | } else { 489 | $element = ' 0) { 492 | foreach($attr as $key => $val) { 493 | $element .= $key . '="' . $val . '" '; 494 | } 495 | } 496 | } 497 | 498 | $element = trim($element); 499 | $element .= '>'; 500 | 501 | return $element . "\n"; 502 | } 503 | } 504 | 505 | /** 506 | * Form label 507 | * @param string $for 508 | * @param string $content 509 | * @param array $attr 510 | * @return string 511 | */ 512 | if ( ! function_exists('form_label') ) { 513 | function form_label($for = '', $content = '', $attr = []) 514 | { 515 | if(is_array($for)) { 516 | $label = '