├── .gitattributes ├── .gitignore ├── README.md ├── addchat_installer ├── database │ ├── addchat_db.sql │ └── index.html ├── includes │ ├── Core.php │ ├── Database.php │ └── index.html ├── index.html ├── index.php └── src │ ├── assets │ ├── addchat │ │ ├── css │ │ │ ├── addchat.css │ │ │ ├── addchat.min.css │ │ │ └── index.html │ │ ├── img │ │ │ ├── addchat-logo-white.png │ │ │ ├── addchat-shadow.png │ │ │ ├── addchat.png │ │ │ ├── avatar.png │ │ │ └── index.html │ │ ├── index.html │ │ ├── js │ │ │ ├── addchat-legacy.min.js │ │ │ ├── addchat.min.js │ │ │ └── index.html │ │ ├── sound │ │ │ ├── index.html │ │ │ ├── notification.mp3 │ │ │ └── notification.ogg │ │ └── webfonts │ │ │ ├── fa-brands-400.eot │ │ │ ├── fa-brands-400.svg │ │ │ ├── fa-brands-400.ttf │ │ │ ├── fa-brands-400.woff │ │ │ ├── fa-brands-400.woff2 │ │ │ ├── fa-regular-400.eot │ │ │ ├── fa-regular-400.svg │ │ │ ├── fa-regular-400.ttf │ │ │ ├── fa-regular-400.woff │ │ │ ├── fa-regular-400.woff2 │ │ │ ├── fa-solid-900.eot │ │ │ ├── fa-solid-900.svg │ │ │ ├── fa-solid-900.ttf │ │ │ ├── fa-solid-900.woff │ │ │ ├── fa-solid-900.woff2 │ │ │ └── index.html │ └── index.html │ ├── config │ ├── addchat.php │ └── index.html │ ├── controllers │ ├── Addchat_api.php │ └── index.html │ ├── index.html │ ├── language │ ├── addchat_lang.php │ └── index.html │ └── libraries │ ├── Addchat_db_lib.php │ ├── Addchat_lib.php │ └── index.html └── license /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX Specific files 2 | .DS_Store 3 | /__MACOXS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AddChat Codeigniter Lite 2 | 3 | Welcome to AddChat Codeigniter Lite. 4 | 5 | ### All-in-one multi-purpose Chat Widget Codeigniter Pacakge 6 | 7 | AddChat is a new chatting friend of Codeigniter. It's a standalone Chat widget that uses the website's existing `users` base, and let website users chat with each other. 8 | 9 |
10 | 11 | You get full source-code, hence AddChat lives and runs on your server/hosting including database. And therefore, you get complete privacy over your data. Either you're a big corporate sector or a small business. AddChat is for everyone. 12 | 13 | --- 14 | 15 | #### Read the documentation live - [AddChat Codeigniter Lite Docs](https://addchat-docs.classiebit.com) 16 | 17 | #### Live Preview - [AddChat Codeigniter Lite](https://addchat-codeigniter.classiebit.com) 18 | 19 | --- 20 | 21 | ![AddChat Lite - Codeigniter Chat Widget](https://addchat-docs.classiebit.com/images/addchat-docs-banner-1.jpg "AddChat Lite - Codeigniter Chat Widget") 22 | 23 | --- 24 | 25 | > **Here's a complete video tutorial guide for getting started quickly [AddChat Codeigniter Academy](https://classiebit.com/academy/addchat-codeigniter/getting-started) ✌️** 26 | 27 | --- 28 | 29 | ## Overview 30 | 31 | **Addchat Lite** is a chat widget that you can integrate into an existing or a fresh Codeigniter website. AddChat works like a standalone widget and fulfills all your business-related needs like - 32 | 33 | 1. User-to-user chatting 34 | 2. Live real-time chatting (without page refresh) 35 | 3. **Internal** notification system (saves **Pusher** monthly subscription fees) 36 | 4. Customer support ( Pro) 37 | 5. Multi-user groups ( Pro) 38 | 39 | and a lot more features available in in **AddChat Codeigniter Pro** ⚡️ 40 | 41 | 42 | ## Why AddChat ? 43 | 44 | Some of the key highlights, why you would like to go with AddChat! 45 | 46 | - Save monthly subscription bills (pay once use forever) 47 | - No Confidential Data leak 48 | - Complete Privacy 49 | - Easy to install & update 50 | - Use existing users database 51 | - Multi-purpose, use it as Helpdesk, Customer support, User-to-user chatting and much more... 52 | 53 | --- 54 | 55 | > **AddChat never modifies your existing database tables or records. And it never breaks down any of your website functionality.** 56 | 57 | --- 58 | 59 | > **AddChat is fully tested and ready to be used in production websites.** 60 | 61 | --- 62 | 63 | 64 | ## Technical Specification 65 | 66 | AddChat is very light, high performance, scalable and secure. 67 | 68 | 1. AddChat front-end built with **VueJs**, which is purely API based web-app. 69 | 70 | 2. AddChat back-end (API) built with **Codeigniter** 71 | 72 | - **AddChat Codeigniter** version comes with an installer, which auto-install AddChat in an existing or a fresh Codeigniter website 73 | 74 | 75 | 76 | ## User Interface & Design 77 | 78 | AddChat is designed in **CSS Flexbox** and **Sass**. Let's see what's so special about **CSS Flexbox** and why we used it. 79 | 80 | 1. AddChat is a CSS Framework Independent. Means, no matter in which CSS Framework your website is in, it neither affects the website CSS nor gets affected by it. 81 | 82 | - [Bootstrap](https://getbootstrap.com/) 83 | - [Bulma](https://bulma.io/) 84 | - [Materializecss](https://materializecss.com/) 85 | - [Semantic UI](https://semantic-ui.com/) 86 | - [UIKit](https://getuikit.com/) 87 | - [Zurb Foundation](https://foundation.zurb.com/) 88 | 89 | or any other... 90 | 91 | 2. AddChat CSS is completely encapsulated (wrapped in AddChat wrapper with `#addchat-bot .c-` prefix). 92 | - Hence, it never override your website CSS nor inherits from it. 93 | 94 | - AddChat UI is extra-responsive. Optimized for **extra-small** devices to large **4K desktops** - 95 | 96 | * Small phones 97 | * Android Phones 98 | * iPhones 99 | * iPad & iPad Pro0 100 | * Small-Medium Size Laptops 101 | * Large Desktops 102 | 103 | 3. We've used the popular **NPM** package `auto-prefixer` to make the AddChat UI design same across all types of browsers e.g `Chrome, Firefox, Safari, Edge` etc 104 | 105 | 106 | 107 | ## Multi-regional 108 | 109 | AddChat is compatible with all languages and timezones. AddChat auto adapts and adjust website's default timezone and language. Please refer to the Language section for more info about **adding a new language** in [AddChat Codeigniter](https://addchat-docs.classiebit.com/docs/1.0/admin/multi-language-codeigniter) 110 | 111 | --- 112 | 113 | > **AddChat never breaks any of your website functionality, even if something went wrong with AddChat, there are `fallback modes` for every worst-case scenario.** 114 | 115 | --- 116 | 117 | 118 | ## Lite Version 119 | 120 | --- 121 | 122 | > **This is AddChat Lite version documentation** 123 | 124 | --- 125 | 126 | 127 | **AddChat Lite** is open-source, free to use. Lite version has got limited features & functionality. 128 | 129 | - **AddChat Codeigniter Lite** 130 | 131 | + [Live](https://addchat-codeigniter.classiebit.com) - Visit live. 132 | + [Github](https://github.com/classiebit/addchat-codeigniter) - Give us a Star. 133 | + [Download](https://classiebit.com/addchat-codeigniter) - Visit here to download 134 | 135 | 136 | ## Pro Version 137 | 138 | **AddChat Pro Version** comes with **Commercial** license. Pro version is fully loaded with a lot of useful and exciting features. 139 | 140 | - **AddChat CodeIgniter Pro** 141 | 142 | + [Live](https://addchat-codeigniter-pro.classiebit.com) - Live preview available now. 143 | + [Purchase](https://classiebit.com/addchat-codeigniter-pro) - Available for purchase now - Flat 50% Off (limited time offer) 144 | 145 | --- 146 | 147 | # Codeigniter Installation 148 | 149 | AddChat CodeIgniter comes with an installer that makes the installation process fully automated and smooth 🍻 150 | 151 | --- 152 | 153 | ![AddChat CodeIgniter Installer](https://addchat-docs.classiebit.com/images/addchat-codeigniter-lite-installer.jpg "AddChat CodeIgniter Installer") 154 | 155 | --- 156 | 157 | > **Here's a complete video tutorial guide for getting started quickly [AddChat CodeIgniter Academy](https://classiebit.com/academy/addchat-codeigniter/getting-started) ✌️** 158 | 159 | --- 160 | 161 | ### Server Requirements 162 | 163 | * PHP version **5.6** or newer is recommended. 164 | * Make sure **.htaccess** is enabled. 165 | * CodeIgniter website with an **Authentication** (user-login) system. 166 | 167 | 168 | ### Remember 169 | 170 | * The website directory must have proper **write** permissions e.g `sudo chown -R :www-data yourwebsite` 171 | * Change CSRF regenerate to `FALSE` in `application/config/config.php` `$config['csrf_regenerate'] = false` 172 | 173 | 174 | ### Install 175 | 176 | 1. Download & Unzip the package. 177 | 2. Copy the **addchat_installer** folder and paste it into your website root directory. 178 | 3. After doing so, your website directory will look like this. 179 | 180 | ```bash 181 | 182 | yoursite.com 183 | │ 184 | ├── addchat_installer 185 | ├── application 186 | ├── system 187 | │ 188 | ├── .. 189 | ├── .. 190 | ├── .. 191 | │ 192 | ├── .htaccess 193 | └── index.php 194 | 195 | ``` 196 | 197 | 4. Visit `yoursite.com/addchat_installer` to run the installer. 198 | 199 | 200 | --- 201 | 202 | > **Make sure **.htaccess** files exist and not hidden.** 203 | 204 | --- 205 | 206 | > **Do not forget to delete the **addchat_installer** folder after successful installation.** 207 | 208 | --- 209 | 210 | ## Installer Instructions 211 | 212 | 213 | #### Database 214 | 215 | - Enter your website's existing database credentials. 216 | 217 |
218 | 219 | #### Assets 220 | 221 | - Enter your website assets folder path. 222 | 223 |
224 | 225 | #### Config 226 | 227 | - Enter your website config folder path. e.g `application/config` 228 | - Enter **LOGGED-IN USER-ID SESSION KEY NAME** e.g user_id 229 | 230 | --- 231 | 232 | > **The $_SESSION variable key name in which your application stores the logged-in user id e.g $_SESSION['user_id'] then the key is *user_id*** 233 | 234 | --- 235 | 236 |
237 | 238 | #### Application 239 | 240 | - Enter **Controllers** Folder Path e.g `application/controllers` 241 | - Enter **Libraries** Folder Path e.g `application/libraries` 242 | - Enter **English Language** Folder Path e.g `application/language/english` 243 | 244 | --- 245 | 246 | > **And finally click install to start the installation process.** 247 | 248 | --- 249 | 250 | 251 | ### After successful installation, you need to do one simple step manually. 252 | 253 | 1. Open the common layout file, mostly the common layout file is the file which contains the HTML & BODY tags. 254 | 255 | - Copy AddChat CSS code and paste it right before closing **</head>** tag 256 | 257 | ```php 258 | 259 | 260 | ``` 261 | 262 | - Copy AddChat Widget code and paste it right after opening **<body>** tag 263 | 264 | ```php 265 | 266 |
271 | ``` 272 | 273 | - Copy AddChat JS code and paste it right before closing **</body>** tag 274 | 275 | ```php 276 | 277 | 278 | 279 | 280 | 281 | ``` 282 | 283 |
284 | 285 | #### The final layout will look something like this 286 | 287 | ```php 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | ``` 319 | 320 | --- 321 | 322 | > **Replace the `assets` by your website's assets path.** 323 | 324 | --- 325 | 326 | > **`addchat.min.js` for modern browsers & `addchat-legacy.min.js` for older browsers. These will be used switched by the browsers automatically on the basis on `type="module"` & `nomodule`, you need to nothing.** 327 | 328 | --- 329 | 330 | > **Setup finishes here, now heads-up straight to [Settings](https://addchat-docs.classiebit.com/docs/1.0/admin/settings) docs** 331 | 332 | --- 333 | 334 | #### Must read the documentation for getting started - [AddChat Codeigniter Lite Docs](https://addchat-docs.classiebit.com) 335 | 336 | --- -------------------------------------------------------------------------------- /addchat_installer/database/addchat_db.sql: -------------------------------------------------------------------------------- 1 | 2 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 3 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 4 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 5 | /*!40101 SET NAMES utf8 */; 6 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 7 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 8 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 9 | 10 | 11 | # Dump of table ac_messages 12 | # ------------------------------------------------------------ 13 | 14 | DROP TABLE IF EXISTS `ac_messages`; 15 | 16 | CREATE TABLE `ac_messages` ( 17 | `id` int(11) NOT NULL AUTO_INCREMENT, 18 | `m_from` int(11) NOT NULL DEFAULT '0', 19 | `m_to` int(11) NOT NULL, 20 | `message` text COLLATE utf8mb4_unicode_ci NOT NULL, 21 | `is_read` tinyint(1) NOT NULL DEFAULT '0', 22 | `m_from_delete` tinyint(1) NOT NULL DEFAULT '0', 23 | `m_to_delete` tinyint(1) NOT NULL DEFAULT '0', 24 | `dt_updated` datetime DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 27 | 28 | 29 | 30 | # Dump of table ac_profiles 31 | # ------------------------------------------------------------ 32 | 33 | DROP TABLE IF EXISTS `ac_profiles`; 34 | 35 | CREATE TABLE `ac_profiles` ( 36 | `id` int(11) NOT NULL AUTO_INCREMENT, 37 | `user_id` int(11) DEFAULT NULL, 38 | `fullname` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 39 | `avatar` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 40 | `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:offline;1:online;2:away;3:busy', 41 | `dt_updated` datetime DEFAULT NULL, 42 | PRIMARY KEY (`id`) 43 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 44 | 45 | 46 | 47 | # Dump of table ac_settings 48 | # ------------------------------------------------------------ 49 | 50 | DROP TABLE IF EXISTS `ac_settings`; 51 | 52 | CREATE TABLE `ac_settings` ( 53 | `id` int(11) NOT NULL AUTO_INCREMENT, 54 | `s_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 55 | `s_value` text COLLATE utf8mb4_unicode_ci, 56 | `dt_updated` datetime DEFAULT NULL, 57 | PRIMARY KEY (`id`) 58 | ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 59 | 60 | LOCK TABLES `ac_settings` WRITE; 61 | /*!40000 ALTER TABLE `ac_settings` DISABLE KEYS */; 62 | 63 | INSERT INTO `ac_settings` (`id`, `s_name`, `s_value`, `dt_updated`) 64 | VALUES 65 | (1,'admin_user_id','1','2019-10-18 12:53:26'), 66 | (2,'pagination_limit','5','2019-10-18 12:53:26'), 67 | (3,'img_upload_path','upload','2019-03-06 00:00:00'), 68 | (4,'assets_path','assets','2019-10-18 12:53:26'), 69 | (5,'users_table','users','2019-10-18 12:53:26'), 70 | (6,'users_col_id','id','2019-10-18 12:53:26'), 71 | (7,'users_col_email','email','2019-10-18 12:53:26'), 72 | (8,'site_name','AddChat','2019-10-18 12:53:26'), 73 | (9,'site_logo',NULL,'2019-09-06 08:25:52'), 74 | (10,'chat_icon',NULL,'2019-09-06 08:24:20'), 75 | (11,'notification_type','0','2019-10-18 12:53:26'), 76 | (12,'footer_text','AddChat | by Classiebit','2019-10-18 12:53:26'), 77 | (13,'footer_url','https://classiebit.com/addchat-codeigniter-pro','2019-10-18 12:53:26'); 78 | 79 | /*!40000 ALTER TABLE `ac_settings` ENABLE KEYS */; 80 | UNLOCK TABLES; 81 | 82 | 83 | # Dump of table ac_users_messages 84 | # ------------------------------------------------------------ 85 | 86 | DROP TABLE IF EXISTS `ac_users_messages`; 87 | 88 | CREATE TABLE `ac_users_messages` ( 89 | `id` int(11) NOT NULL AUTO_INCREMENT, 90 | `users_id` int(11) NOT NULL, 91 | `buddy_id` int(11) NOT NULL, 92 | `messages_count` int(11) NOT NULL DEFAULT '1', 93 | PRIMARY KEY (`id`), 94 | UNIQUE KEY `users_id` (`users_id`,`buddy_id`) 95 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 96 | 97 | 98 | 99 | 100 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 101 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 102 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 103 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 104 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 105 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 106 | -------------------------------------------------------------------------------- /addchat_installer/database/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/includes/Core.php: -------------------------------------------------------------------------------- 1 | xcopy($trans); 89 | 90 | // now check if files are transferred or not 91 | if(! file_exists($trans['destination'].$trans['file_check'])) 92 | { 93 | $response = array('response'=>false, 'error'=>"Invalid ".$trans['path']); 94 | 95 | return false; 96 | } 97 | } 98 | 99 | return TRUE; 100 | } 101 | 102 | /** 103 | * Copy a file, or recursively copy a folder and its contents 104 | * @author Aidan Lister 105 | * @version 1.0.1 106 | * @link http://aidanlister.com/2004/04/recursively-copying-directories-in-php/ 107 | * @param string $source Source path 108 | * @param string $dest Destination path 109 | * @param int $permissions New folder creation permissions 110 | * @return bool Returns true on success, false on failure 111 | */ 112 | function xcopy($trans = array()) 113 | { 114 | // Simple copy for a file 115 | if (is_file($trans['source'])) { 116 | return copy($trans['source'], $trans['destination']); 117 | } 118 | 119 | // Make destination directory 120 | if (!is_dir($trans['destination'])) 121 | { 122 | if($trans['make_dir']) 123 | { 124 | mkdir($trans['destination'], 0777, true); 125 | } 126 | else 127 | { 128 | return false; 129 | } 130 | } 131 | 132 | // Loop through the folder 133 | $dir = dir($trans['source']); 134 | while (false !== $entry = $dir->read()) { 135 | // Skip pointers 136 | if ($entry == '.' || $entry == '..') { 137 | continue; 138 | } 139 | 140 | // Deep copy directories 141 | $this->xcopy(array('source'=>"".$trans['source']."/".$entry."", 'destination'=>"".$trans['destination']."/".$entry."", 'make_dir'=>$trans['make_dir'])); 142 | } 143 | 144 | // Clean up 145 | $dir->close(); 146 | return true; 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /addchat_installer/includes/Database.php: -------------------------------------------------------------------------------- 1 | close(); 17 | 18 | return true; 19 | } 20 | 21 | // Function to create the tables and fill them with the default data 22 | function create_tables($data) 23 | { 24 | // Connect to the database 25 | $mysqli = new mysqli($data['hostname'],$data['username'],$data['password'],$data['database']); 26 | 27 | // Check for errors 28 | if(mysqli_connect_errno()) 29 | return false; 30 | 31 | // Open the default SQL file 32 | // install addchat tables 33 | $query = file_get_contents('database/addchat_db.sql'); 34 | 35 | // Execute a multi query 36 | $mysqli->multi_query($query); 37 | 38 | // Close the connection 39 | $mysqli->close(); 40 | 41 | return TRUE; 42 | } 43 | } -------------------------------------------------------------------------------- /addchat_installer/includes/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

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

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/index.php: -------------------------------------------------------------------------------- 1 | validate_post($_POST) == true) 33 | { 34 | // First create the database, then create tables, then write config file 35 | /** 36 | * 1. Verify connection to DB 37 | * 2. Write config and transfer to application 38 | * 3. Transfer controller, libraries & assets data 39 | * 4. Create AddChat db tables 40 | */ 41 | 42 | if($database->connect_database($_POST) == false) 43 | { 44 | $message = $core->show_message('error',"Could not connect to Database, please verify your settings."); 45 | } 46 | else if ($core->write_config($_POST) == false) 47 | { 48 | $message = $core->show_message('error',"AddChat config file could not be transferred, please make sure you have set correct write permissions to project directory."); 49 | } 50 | else if($core->transfer_files($_POST) == false) 51 | { 52 | $message = $core->show_message('error', "AddChat files could not be transferred, please make sure you have set correct write permissions to project directory."); 53 | } 54 | else if ($database->create_tables($_POST) == false) 55 | { 56 | $message = $core->show_message('error',"The database tables could not be created, please verify your settings."); 57 | } 58 | 59 | // If no errors, redirect to registration page 60 | if(!isset($message)) 61 | { 62 | $install_success = 1; 63 | } 64 | } 65 | else 66 | { 67 | $message = $core->show_message('error','Please fill in   (required) fields'); 68 | } 69 | } 70 | 71 | ?> 72 | 73 | 74 | 75 | AddChat CodeIgniter Lite | Installer 76 | 77 | 78 | 79 | 80 | 81 | 82 | 144 | 145 | 146 | 147 |
148 |
149 |
150 |
151 | 152 | 153 | 159 | 160 | 163 | 164 |
    165 |
  • 166 | 1. Copy AddChat CSS code and paste it right before closing </head> tag 167 | 168 |

    169 |
    170 |     
    171 |         
    172 |         <!-- 1. AddChat css -->
    173 |         <link href="<?php echo base_url('/addchat/css/addchat.min.css') ?>" rel="stylesheet">
    174 |               
    175 |     </head>
    176 |     
    177 |     
    178 | 179 |
  • 180 |
  • 181 | 2. Copy AddChat Widget code and paste it right after opening <body> tag 182 | 183 |

    184 |
    185 |     
    186 |     <body>
    187 |         
    188 |         <!-- 2. AddChat widget -->
    189 |         <div id="addchat_app" 
    190 |             data-baseurl="<?php echo base_url() ?>"
    191 |             data-csrfname="<?php echo $this->security->get_csrf_token_name() ?>"
    192 |             data-csrftoken="<?php echo $this->security->get_csrf_hash() ?>"
    193 |         ></div>
    194 |         
    195 |     
    196 |     
    197 | 198 |
  • 199 |
  • 200 | 3. Copy AddChat JS code and paste it right before closing </body> tag 201 | 202 |

    203 |
    204 |     
    205 |         
    206 |         <!-- 3. AddChat JS -->
    207 |         <!-- Modern browsers -->
    208 |         <script  type="module" src="<?php echo base_url('/addchat/js/addchat.min.js') ?>"></script>
    209 |         <!-- Fallback support for Older browsers -->
    210 |         <script nomodule src="<?php echo base_url('/addchat/js/addchat-legacy.min.js') ?>"></script>
    211 |         
    212 | 
    213 |     </body>
    214 |     
    215 |     
    216 |
  • 217 |
218 | 219 | 222 | 223 |
    224 |
  • 225 | 226 |
    227 |     
    228 | 
    229 |     <head>
    230 | 
    231 |         <!-- Your site other content -->
    232 | 
    233 |         
    234 |         <!-- 1. AddChat css -->
    235 |         <link href="<?php echo base_url('/addchat/css/addchat.min.css') ?>" rel="stylesheet">
    236 |         
    237 |                                 
    238 |     </head>
    239 | 
    240 |     <body>
    241 | 
    242 |         
    243 |         <!-- 2. AddChat widget -->
    244 |         <div id="addchat_app" 
    245 |             data-baseurl="<?php echo base_url() ?>"
    246 |             data-csrfname="<?php echo $this->security->get_csrf_token_name() ?>"
    247 |             data-csrftoken="<?php echo $this->security->get_csrf_hash() ?>"
    248 |         ></div>
    249 |         
    250 | 
    251 |         <!-- Your site other content -->
    252 | 
    253 |         
    254 |         <!-- 3. AddChat JS -->
    255 |         <!-- Modern browsers -->
    256 |         <script  type="module" src="<?php echo base_url('/addchat/js/addchat.min.js') ?>"></script>
    257 |         <!-- Fallback support for Older browsers -->
    258 |         <script nomodule src="<?php echo base_url('/addchat/js/addchat-legacy.min.js') ?>"></script>
    259 |         
    260 | 
    261 |     </body>
    262 | 
    263 |     
    264 |     
    265 | 266 |
  • 267 |
268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 |
276 |
277 |

V1.0 AddChat CodeIgniter Lite | Installer

278 |

IMPORTANT! Please read the installation guide in AddChat docs

279 | 280 |
281 | 286 |
287 |
288 |
289 |
290 | 291 | 292 | '.$message.'
';} ?> 293 | 294 | IN DEMO MODE
';} ?> 295 | 296 | 384 | 385 |



386 | 387 | 388 |
389 |
390 |
391 | 392 |
393 |
394 | 395 | 396 | 397 | 398 | 399 | -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/css/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/img/addchat-logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/img/addchat-logo-white.png -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/img/addchat-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/img/addchat-shadow.png -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/img/addchat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/img/addchat.png -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/img/avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/img/avatar.png -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/img/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

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

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/sound/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/sound/notification.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/sound/notification.mp3 -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/sound/notification.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/sound/notification.ogg -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-brands-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-brands-400.eot -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-brands-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-brands-400.woff -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-regular-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-regular-400.eot -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-regular-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-regular-400.woff -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-solid-900.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-solid-900.eot -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-solid-900.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-solid-900.woff -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/classiebit/addchat-codeigniter/2453defba8c4f5724cdc4e98a6b94a295a208ab9/addchat_installer/src/assets/addchat/webfonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /addchat_installer/src/assets/addchat/webfonts/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

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

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/config/addchat.php: -------------------------------------------------------------------------------- 1 | "%LOGGED_USER_ID%", 24 | 25 | ]; -------------------------------------------------------------------------------- /addchat_installer/src/config/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/controllers/Addchat_api.php: -------------------------------------------------------------------------------- 1 | load->helper(array('form', 'url')); 27 | $this->load->library(array('form_validation')); 28 | 29 | // AddChat Lib 30 | $this->load->library('addchat_lib'); 31 | } 32 | 33 | public function get_lang() 34 | { 35 | $this->addchat_lib->get_lang(); 36 | } 37 | 38 | public function get_config() 39 | { 40 | $this->addchat_lib->get_config(); 41 | } 42 | 43 | public function get_profile() 44 | { 45 | $this->addchat_lib->get_profile(); 46 | } 47 | 48 | public function get_buddy() 49 | { 50 | $this->addchat_lib->get_buddy(); 51 | } 52 | 53 | public function get_users($offset = 0) 54 | { 55 | $this->addchat_lib->get_users($offset); 56 | } 57 | 58 | public function get_messages($buddy_id = null,$offset = 0) 59 | { 60 | $this->addchat_lib->get_messages($buddy_id,$offset); 61 | } 62 | 63 | public function send_message() 64 | { 65 | $this->addchat_lib->send_message(); 66 | } 67 | 68 | public function delete_chat($user_id = null) 69 | { 70 | $this->addchat_lib->delete_chat($user_id); 71 | } 72 | 73 | public function profile_update() 74 | { 75 | $this->addchat_lib->profile_update(); 76 | } 77 | 78 | public function get_updates() 79 | { 80 | $this->addchat_lib->get_updates(); 81 | } 82 | 83 | 84 | public function get_latest_message($buddy_id = null) 85 | { 86 | $this->addchat_lib->get_latest_message($buddy_id); 87 | } 88 | 89 | public function message_delete($message_id = null) 90 | { 91 | $this->addchat_lib->message_delete($message_id); 92 | } 93 | 94 | 95 | /* ------- Admin methods start------- */ 96 | 97 | public function check_admin() 98 | { 99 | $this->addchat_lib->check_admin(); 100 | } 101 | 102 | public function save_settings() 103 | { 104 | $this->addchat_lib->save_settings(); 105 | } 106 | 107 | public function a_chat_between($offset = 0) 108 | { 109 | $this->addchat_lib->a_chat_between($offset); 110 | } 111 | 112 | public function a_get_conversations($m_from = null, $m_to = null, $offset = 0) 113 | { 114 | $this->addchat_lib->a_get_conversations($m_from, $m_to, $offset); 115 | } 116 | 117 | 118 | 119 | /* ------- Admin methods end------- */ 120 | 121 | } 122 | 123 | /* Addchat_api controller ends */ -------------------------------------------------------------------------------- /addchat_installer/src/controllers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

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

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/language/addchat_lang.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /addchat_installer/src/libraries/Addchat_db_lib.php: -------------------------------------------------------------------------------- 1 | AC_LIB =& get_instance(); 20 | $this->AC_LIB->load->database(); 21 | $this->AC_LIB->load->library(array('session')); 22 | 23 | // Addchat tables 24 | $this->profiles_tb = 'ac_profiles'; 25 | $this->ac_messages_tb = 'ac_messages'; 26 | $this->ac_users_messages_tb = 'ac_users_messages'; 27 | $this->ac_settings_tb = 'ac_settings'; 28 | 29 | // fetch settings 30 | if(empty($this->AC_LIB->session->userdata('ac_session'))) 31 | { 32 | $settings = $this->get_settings(); 33 | 34 | $tmp = new stdClass(); 35 | foreach ($settings as $setting) 36 | { 37 | $tmp->{$setting->s_name} = $setting->s_value; 38 | } 39 | 40 | $this->AC_LIB->session->set_userdata('ac_session',$tmp); 41 | $this->AC_SETTINGS = $this->AC_LIB->session->userdata('ac_session'); 42 | } 43 | else 44 | { 45 | $this->AC_SETTINGS = $this->AC_LIB->session->userdata('ac_session'); 46 | } 47 | 48 | 49 | // External tables 50 | // users table 51 | $this->users_tb = $this->AC_SETTINGS->users_table; 52 | $this->users_tb_id = $this->AC_SETTINGS->users_col_id; 53 | $this->users_tb_email = $this->AC_SETTINGS->users_col_email; 54 | } 55 | 56 | /* ------- Users ------- */ 57 | 58 | // get specific user by id 59 | public function get_user($user_id = 0, $logged_in_user = 0) 60 | { 61 | $select = array( 62 | "$this->users_tb.$this->users_tb_id", 63 | "$this->users_tb.$this->users_tb_email", 64 | 65 | "$this->profiles_tb.fullname", 66 | "$this->profiles_tb.avatar", 67 | "$this->profiles_tb.status online", 68 | ); 69 | 70 | return $this->AC_LIB->db 71 | ->select($select) 72 | ->join($this->profiles_tb, "$this->profiles_tb.user_id = $this->users_tb.$this->users_tb_id", "left") 73 | ->where("$this->users_tb.$this->users_tb_id", $user_id) 74 | ->get($this->users_tb) 75 | ->row(); 76 | } 77 | 78 | // get_users list 79 | public function get_users($login_user_id = 0, $filters = array(), $is_admin = null) 80 | { 81 | $this->AC_LIB->db 82 | ->select(array( 83 | "$this->users_tb.$this->users_tb_id", 84 | "$this->users_tb.$this->users_tb_email", 85 | "$this->profiles_tb.avatar", 86 | "$this->profiles_tb.fullname username", 87 | "$this->profiles_tb.status online", 88 | "(SELECT IF(COUNT(ACM.id) > 0, COUNT(ACM.id), null) FROM $this->ac_messages_tb ACM WHERE ACM.m_to = '$login_user_id' AND ACM.m_from = '$this->users_tb.$this->users_tb_id' AND ACM.is_read = '0') unread", 89 | )); 90 | 91 | // exclude logged in user 92 | $this->AC_LIB->db 93 | ->join($this->profiles_tb, "$this->profiles_tb.user_id = $this->users_tb.$this->users_tb_id", "left") 94 | ->where(array("$this->users_tb.$this->users_tb_id !=" =>$login_user_id)); 95 | 96 | // in case of search, search amongst all users 97 | if(!empty($filters['search']) ) 98 | { 99 | // admin can seach all users 100 | // and if have is_groups off then user can search all users 101 | $this->AC_LIB->db 102 | ->group_start() 103 | ->or_like("$this->profiles_tb.fullname", $filters['search'], 'both') 104 | ->or_like("$this->users_tb.$this->users_tb_email", $filters['search'], 'both') 105 | ->group_end(); 106 | } 107 | 108 | return $this->AC_LIB->db 109 | ->limit($filters['limit']) 110 | ->offset($filters['offset']) 111 | ->get($this->users_tb) 112 | ->result(); 113 | } 114 | 115 | // Update users update_user 116 | public function update_user($user_id = 0, $data = array()) 117 | { 118 | $result = $this->AC_LIB->db 119 | ->select() 120 | ->where('user_id', $user_id) 121 | ->get("$this->profiles_tb") 122 | ->row(); 123 | 124 | // insert data in profile table if user have not exist 125 | if(empty($result)) 126 | { 127 | $this->AC_LIB->db->insert("$this->profiles_tb", $data); 128 | } 129 | else 130 | { 131 | // if user exist then update user data 132 | $this->AC_LIB->db 133 | ->where("user_id", $user_id) 134 | ->update("$this->profiles_tb", $data); 135 | } 136 | 137 | return true; 138 | } 139 | 140 | 141 | /* ------- Messages ------- */ 142 | 143 | // Delete chat delete_chat 144 | public function delete_chat($user_id = 0, $sub_user_id = 0) 145 | { 146 | $this->AC_LIB->db 147 | ->where(array("$this->ac_messages_tb.m_from"=>$user_id, "$this->ac_messages_tb.m_to"=>$sub_user_id)) 148 | ->update($this->ac_messages_tb, array("m_from_delete"=>1)); 149 | 150 | $this->AC_LIB->db 151 | ->where(array("$this->ac_messages_tb.m_to"=>$user_id, "$this->ac_messages_tb.m_from"=>$sub_user_id)) 152 | ->update($this->ac_messages_tb, array("m_to_delete"=>1)); 153 | 154 | return TRUE; 155 | } 156 | 157 | // delete message 158 | public function message_delete($message_id = null, $login_user_id = null) 159 | { 160 | $message = $this->AC_LIB->db 161 | ->select('*') 162 | ->where("id", $message_id) 163 | ->get($this->ac_messages_tb) 164 | ->row(); 165 | 166 | if(empty($message)) 167 | return false; 168 | 169 | $this->AC_LIB->db 170 | ->where(array("id" => $message_id)); 171 | 172 | if($message->m_from == $login_user_id) 173 | $this->AC_LIB->db->update($this->ac_messages_tb, array("m_from_delete" => '1')); 174 | 175 | if($message->m_to == $login_user_id) 176 | $this->AC_LIB->db->update($this->ac_messages_tb, array("m_to_delete" => '1')); 177 | 178 | return true; 179 | } 180 | 181 | // send message 182 | public function send_message($data = array()) 183 | { 184 | $this->AC_LIB->db->insert($this->ac_messages_tb, $data); 185 | return $this->AC_LIB->db->insert_id(); 186 | } 187 | 188 | public function get_messages($user_id = 0, $chat_user = 0, $filters = array(), $count = false) 189 | { 190 | $this->AC_LIB->db 191 | ->select(array( 192 | "$this->ac_messages_tb.id ", 193 | "$this->ac_messages_tb.m_from ", 194 | "$this->ac_messages_tb.m_to ", 195 | "$this->ac_messages_tb.message ", 196 | "$this->ac_messages_tb.is_read ", 197 | "$this->ac_messages_tb.dt_updated ", 198 | )); 199 | 200 | // group query for removing deleted messages 201 | $this->AC_LIB->db 202 | ->where("( (`$this->ac_messages_tb`.`m_from` = '$user_id' AND `$this->ac_messages_tb`.`m_to` = '$chat_user')", null, FALSE) 203 | ->or_where("(`$this->ac_messages_tb`.`m_from` = '$chat_user' AND `$this->ac_messages_tb`.`m_to` = '$user_id') )", null, FALSE) 204 | ->where("( (IF(`$this->ac_messages_tb`.`m_from` = '$user_id', `$this->ac_messages_tb`.`m_from_delete`, `$this->ac_messages_tb`.`m_to_delete`) = 0) AND (IF(`$this->ac_messages_tb`.`m_to` = '$user_id', `$this->ac_messages_tb`.`m_to_delete`, `$this->ac_messages_tb`.`m_from_delete`) = 0) )", null, FALSE); 205 | 206 | if(!$count) 207 | return $this->AC_LIB->db->count_all_results($this->ac_messages_tb); 208 | 209 | $messages = $this->AC_LIB->db 210 | ->order_by("$this->ac_messages_tb.id") 211 | ->limit($filters['limit']) 212 | ->offset($filters['offset']) 213 | ->get($this->ac_messages_tb); 214 | 215 | $this->AC_LIB->db 216 | ->where("$this->ac_messages_tb.m_to", $user_id) 217 | ->where("$this->ac_messages_tb.m_from", $chat_user) 218 | ->update($this->ac_messages_tb, array("$this->ac_messages_tb.is_read"=>'1')); 219 | 220 | return $messages->result(); 221 | } 222 | 223 | 224 | /* ------- Notifications ------- */ 225 | 226 | // add notification 227 | public function set_notification($notification = array()) 228 | { 229 | $result = $this->AC_LIB->db 230 | ->select() 231 | ->where($notification) 232 | ->get($this->ac_users_messages_tb) 233 | ->row(); 234 | 235 | // insert 236 | if(empty($result)) 237 | { 238 | $this->AC_LIB->db->insert($this->ac_users_messages_tb, $notification); 239 | } 240 | else // update 241 | { 242 | $this->AC_LIB->db 243 | ->where($notification) 244 | ->set('messages_count', 'messages_count+1', FALSE) 245 | ->update($this->ac_users_messages_tb); 246 | } 247 | 248 | return true; 249 | 250 | } 251 | 252 | // Remove notification 253 | public function remove_notification($notification = array()) 254 | { 255 | return $this->AC_LIB->db 256 | ->where($notification) 257 | ->delete($this->ac_users_messages_tb); 258 | 259 | } 260 | 261 | // get notification 262 | public function get_updates($login_user_id = null) 263 | { 264 | $this->AC_LIB->db 265 | ->select(array( 266 | "$this->ac_users_messages_tb.users_id", 267 | "$this->ac_users_messages_tb.buddy_id", 268 | "$this->ac_users_messages_tb.messages_count", 269 | )) 270 | ->where("buddy_id", $login_user_id); 271 | 272 | return $this->AC_LIB->db 273 | ->get($this->ac_users_messages_tb) 274 | ->result_array(); 275 | } 276 | 277 | // get latest message 278 | public function get_latest_message($login_user_id = null, $buddy_id = null) 279 | { 280 | $result = $this->AC_LIB->db 281 | ->select(array( 282 | "$this->ac_messages_tb.id ", 283 | "$this->ac_messages_tb.m_from ", 284 | "$this->ac_messages_tb.m_to ", 285 | "$this->ac_messages_tb.message ", 286 | "$this->ac_messages_tb.is_read ", 287 | "$this->ac_messages_tb.dt_updated ", 288 | )) 289 | ->where(array("$this->ac_messages_tb.m_from" => $buddy_id, "$this->ac_messages_tb.m_to" => $login_user_id, "$this->ac_messages_tb.is_read" => '0')) 290 | 291 | //group query for removing unsend messages 292 | ->where(["$this->ac_messages_tb.m_from_delete" => "0", "$this->ac_messages_tb.m_to_delete" => "0"]) 293 | ->order_by("$this->ac_messages_tb.id") 294 | ->get($this->ac_messages_tb); 295 | 296 | // delete notification 297 | $this->AC_LIB->db 298 | ->where("$this->ac_messages_tb.m_to", $login_user_id) 299 | ->where("$this->ac_messages_tb.m_from", $buddy_id) 300 | ->update($this->ac_messages_tb, array("$this->ac_messages_tb.is_read"=>'1')); 301 | 302 | return $result->result(); 303 | } 304 | 305 | 306 | /* -------- Admin Panel --------- */ 307 | 308 | /** 309 | * save settings 310 | */ 311 | public function save_settings($data = array()) 312 | { 313 | if (!empty($data)) 314 | { 315 | $saved = FALSE; 316 | 317 | foreach ($data as $key => $value) 318 | { 319 | $sql = " 320 | UPDATE {$this->ac_settings_tb} 321 | SET s_value = '" . $value . "', 322 | dt_updated = '" . date('Y-m-d H:i:s') . "' 323 | WHERE s_name = '" . $key . "' 324 | "; 325 | 326 | $this->AC_LIB->db->query($sql); 327 | 328 | if ($this->AC_LIB->db->affected_rows() > 0) 329 | { 330 | $saved = TRUE; 331 | } 332 | } 333 | 334 | if ($saved) 335 | { 336 | return TRUE; 337 | } 338 | } 339 | 340 | return FALSE; 341 | } 342 | 343 | /* 344 | * get settings 345 | */ 346 | public function get_settings() 347 | { 348 | return $this->AC_LIB->db 349 | ->select(array( 350 | "$this->ac_settings_tb.s_name", 351 | "$this->ac_settings_tb.s_value", 352 | )) 353 | ->get($this->ac_settings_tb) 354 | ->result(); 355 | } 356 | 357 | /** 358 | * get chat users who chat with each other means between users 359 | */ 360 | public function a_chat_between($filters = array(), $logged_in_user = null) 361 | { 362 | $query = "SELECT `id` FROM $this->ac_messages_tb WHERE `m_from` = $logged_in_user GROUP BY `m_from`"; 363 | 364 | if( $this->AC_LIB->db->simple_query($query) ) 365 | { 366 | // safe mode is off 367 | $select = array( 368 | "$this->ac_messages_tb.id", 369 | "$this->ac_messages_tb.m_to", 370 | "$this->ac_messages_tb.m_from", 371 | "$this->ac_messages_tb.dt_updated", 372 | "$this->ac_messages_tb.message", 373 | "(SELECT PR.fullname FROM $this->profiles_tb PR WHERE PR.id = $this->ac_messages_tb.m_from) m_from_username", 374 | "(SELECT PR2.fullname FROM $this->profiles_tb PR2 WHERE PR2.id = $this->ac_messages_tb.m_to) m_to_username", 375 | "(SELECT UR.$this->users_tb_email FROM $this->users_tb UR WHERE UR.$this->users_tb_id = $this->ac_messages_tb.m_from) m_from_email", 376 | "(SELECT UR2.$this->users_tb_email FROM $this->users_tb UR2 WHERE UR2.$this->users_tb_id = $this->ac_messages_tb.m_to) m_to_email", 377 | ); 378 | } 379 | else 380 | { 381 | // safe mode is on 382 | $select = array( 383 | "ANY_VALUE($this->ac_messages_tb.id) id", 384 | "ANY_VALUE($this->ac_messages_tb.m_to) m_to", 385 | "$this->ac_messages_tb.m_from", 386 | "ANY_VALUE($this->ac_messages_tb.dt_updated) dt_updated", 387 | "ANY_VALUE($this->ac_messages_tb.message) message", 388 | "ANY_VALUE((SELECT PR.fullname FROM $this->profiles_tb PR WHERE PR.id = $this->ac_messages_tb.m_from)) m_from_username", 389 | "ANY_VALUE((SELECT PR2.fullname FROM $this->profiles_tb PR2 WHERE PR2.id = $this->ac_messages_tb.m_to)) m_to_username", 390 | "ANY_VALUE((SELECT UR.$this->users_tb_email FROM $this->users_tb UR WHERE UR.$this->users_tb_id = $this->ac_messages_tb.m_from)) m_from_email", 391 | "ANY_VALUE((SELECT UR2.$this->users_tb_email FROM $this->users_tb UR2 WHERE UR2.$this->users_tb_id = $this->ac_messages_tb.m_to)) m_to_email", 392 | ); 393 | } 394 | 395 | return $this->AC_LIB->db 396 | ->select($select) 397 | ->where(['m_to !=' => '0', 'm_from !=' => '0']) 398 | ->group_by(array("$this->ac_messages_tb.m_from", "m_to")) 399 | ->order_by("id", 'DESC') 400 | ->limit($filters['limit']) 401 | ->offset($filters['offset']) 402 | ->get($this->ac_messages_tb) 403 | ->result(); 404 | 405 | } 406 | 407 | /** 408 | * get conversations between two users 409 | * 410 | */ 411 | public function a_get_conversations($m_from = null, $m_to = null, $filters = array(), $count = false) 412 | { 413 | $this->AC_LIB->db 414 | ->select(array( 415 | "$this->ac_messages_tb.id ", 416 | "$this->ac_messages_tb.m_from ", 417 | "$this->ac_messages_tb.m_to ", 418 | "$this->ac_messages_tb.message ", 419 | "$this->ac_messages_tb.is_read ", 420 | "$this->ac_messages_tb.dt_updated ", 421 | "$this->ac_messages_tb.m_to_delete ", 422 | "$this->ac_messages_tb.m_from_delete ", 423 | "(SELECT PR.avatar FROM $this->profiles_tb PR WHERE PR.id = $this->ac_messages_tb.m_from) m_from_image", 424 | "(SELECT PR2.avatar FROM $this->profiles_tb PR2 WHERE PR2.id = $this->ac_messages_tb.m_to) m_to_image", 425 | )); 426 | // //group query for removing deleted messages 427 | $this->AC_LIB->db 428 | ->where("( (`$this->ac_messages_tb`.`m_from` = '$m_from' AND `$this->ac_messages_tb`.`m_to` = '$m_to')", null, FALSE) 429 | ->or_where("(`$this->ac_messages_tb`.`m_from` = '$m_to' AND `$this->ac_messages_tb`.`m_to` = '$m_from') )", null, FALSE); 430 | 431 | 432 | 433 | if($count) 434 | return $this->AC_LIB->db->count_all_results($this->ac_messages_tb); 435 | 436 | return $this->AC_LIB->db 437 | ->order_by("$this->ac_messages_tb.id") 438 | ->limit($filters['limit']) 439 | ->offset($filters['offset']) 440 | ->get($this->ac_messages_tb) 441 | ->result(); 442 | 443 | } 444 | 445 | 446 | 447 | } 448 | 449 | /* End Addchat_db_lib class */ -------------------------------------------------------------------------------- /addchat_installer/src/libraries/Addchat_lib.php: -------------------------------------------------------------------------------- 1 | AC_LIB =& get_instance(); 24 | $this->AC_LIB->load->helper(array('form', 'url', 'email')); 25 | $this->AC_LIB->load->library(array('addchat_db_lib', 'form_validation', 'session')); 26 | 27 | // get application default language + sync with AddChat lang 28 | // get default lang if in session 29 | if(!empty($this->AC_LIB->session->language)) 30 | $this->AC_LIB->config->set_item('language', $this->AC_LIB->session->language); 31 | 32 | $language = $this->AC_LIB->config->item('language'); 33 | $this->AC_LIB->lang->load('addchat', $language); 34 | 35 | // get addchat settings 36 | $this->AC_SETTINGS = $this->AC_LIB->session->userdata('ac_session'); 37 | 38 | // get addchat config 39 | $this->AC_LIB->config->load('addchat', TRUE); 40 | $this->AC_CONFIG = $this->AC_LIB->config->item('addchat', 'addchat'); 41 | 42 | // get the logged in user 43 | $this->AC_SETTINGS->logged_user_id = isset($_SESSION[$this->AC_CONFIG->session_user_id]) ? (int) $_SESSION[$this->AC_CONFIG->session_user_id] : NULL; 44 | 45 | // get the admin user 46 | $this->AC_SETTINGS->admin_user_id = (int) $this->AC_SETTINGS->admin_user_id; 47 | $this->AC_SETTINGS->is_admin = $this->AC_SETTINGS->admin_user_id === $this->AC_SETTINGS->logged_user_id ? 1 : 0; 48 | } 49 | 50 | 51 | /* 52 | * Get-set lang 53 | */ 54 | public function get_lang() 55 | { 56 | // get lang variables 57 | $lang_variables = $this->AC_LIB->lang->language; 58 | 59 | // send to app 60 | $this->format_json(['lang' => $lang_variables]); 61 | } 62 | 63 | /* 64 | * Get configurations 65 | */ 66 | public function get_config() 67 | { 68 | $data['config'] = array(); 69 | $data['config']['site_name'] = $this->AC_SETTINGS->site_name; 70 | $data['config']['site_logo'] = $this->AC_SETTINGS->site_logo; 71 | $data['config']['chat_icon'] = $this->AC_SETTINGS->chat_icon; 72 | $data['config']['logged_user_id'] = $this->AC_SETTINGS->logged_user_id; 73 | $data['config']['img_upld_pth'] = $this->AC_SETTINGS->img_upload_path; 74 | $data['config']['assets_path'] = $this->AC_SETTINGS->assets_path; 75 | $data['config']['is_admin'] = $this->AC_SETTINGS->is_admin; 76 | $data['config']['admin_user_id'] = $this->AC_SETTINGS->admin_user_id; 77 | $data['config']['pagination_limit'] = $this->AC_SETTINGS->pagination_limit; 78 | $data['config']['users_table'] = $this->AC_SETTINGS->users_table; 79 | $data['config']['users_col_id'] = $this->AC_SETTINGS->users_col_id; 80 | $data['config']['users_col_email'] = $this->AC_SETTINGS->users_col_email; 81 | $data['config']['notification_type'] = $this->AC_SETTINGS->notification_type; 82 | $data['config']['footer_text'] = $this->AC_SETTINGS->footer_text; 83 | $data['config']['footer_url'] = $this->AC_SETTINGS->footer_url; 84 | 85 | $this->format_json($data); 86 | } 87 | 88 | /* 89 | * Get user's profile 90 | */ 91 | public function get_profile($is_return = false) 92 | { 93 | // check is logged-in 94 | $this->check_auth(); 95 | 96 | $data = array(); 97 | $data['status'] = true; 98 | $data['profile'] = $this->AC_LIB->addchat_db_lib->get_user($this->AC_SETTINGS->logged_user_id); 99 | 100 | if($is_return) 101 | return $data; 102 | 103 | $this->format_json($data); 104 | } 105 | 106 | /** 107 | * Get buddy 108 | */ 109 | public function get_buddy() 110 | { 111 | // check is logged-in 112 | $this->check_auth(); 113 | 114 | /* Validate form input */ 115 | $this->AC_LIB->form_validation 116 | ->set_rules('user', lang('user'), 'trim|is_natural_no_zero'); 117 | 118 | if($this->AC_LIB->form_validation->run() === FALSE) 119 | { 120 | $this->format_json(array('status' => false, 'response'=> validation_errors())); 121 | } 122 | 123 | $data = array(); 124 | $buddy = (int) $this->AC_LIB->input->post('user'); 125 | $chatbuddy = $this->AC_LIB->addchat_db_lib->get_user($buddy, $this->AC_SETTINGS->logged_user_id); 126 | 127 | $c_buddy = array( 128 | 'name' => ucwords($chatbuddy->fullname), 129 | 'status' => $chatbuddy->online, 130 | 'avatar' => $chatbuddy->avatar, 131 | 'id' => $chatbuddy->id, 132 | 'email' => $chatbuddy->email, 133 | ); 134 | 135 | $data['buddy'] = $c_buddy; 136 | $data['status'] = true; 137 | 138 | $this->format_json($data); 139 | } 140 | 141 | /* 142 | * Get users list get_users 143 | */ 144 | public function get_users($offset = 0) 145 | { 146 | // check is logged-in 147 | $this->check_auth(); 148 | 149 | // filters 150 | $filters = array(); 151 | $filters['limit'] = $this->AC_SETTINGS->pagination_limit; 152 | $filters['offset'] = (int) $offset; 153 | $filters['search'] = (string) $this->AC_LIB->input->post('search'); 154 | 155 | $users = $this->AC_LIB->addchat_db_lib->get_users( 156 | $this->AC_SETTINGS->logged_user_id, 157 | $filters, 158 | $this->AC_SETTINGS->is_admin 159 | ); 160 | 161 | if(empty($users)) 162 | { 163 | $data = array( 164 | 'users' => array(), 165 | 'offset' => 0, 166 | 'more' => 0, // to stop load more process 167 | 'status' => true, 168 | ); 169 | $this->format_json($data); 170 | } 171 | 172 | $data = array(); 173 | $data['users'] = $users; 174 | $data['offset'] = $filters['offset'] == 0 ? $filters['limit'] : $filters['limit']+$filters['offset']; 175 | $data['more'] = 1; // to continue load more process 176 | $data['status'] = true; 177 | 178 | $this->format_json($data); 179 | } 180 | 181 | 182 | /* 183 | * Get messages get_messages 184 | */ 185 | public function get_messages($buddy_id = null, $offset = 0) 186 | { 187 | // check is logged-in 188 | $this->check_auth(); 189 | 190 | $buddy_id = (int) $buddy_id; 191 | 192 | // filters 193 | $filters = array(); 194 | $filters['limit'] = $this->AC_SETTINGS->pagination_limit; 195 | $filters['offset'] = (int) $offset; 196 | 197 | $total_messages = $this->AC_LIB->addchat_db_lib->get_messages($this->AC_SETTINGS->logged_user_id, $buddy_id, $filters); 198 | 199 | // 1st case 200 | if($filters['offset'] == 0) 201 | $filters['offset'] = $total_messages > $filters['limit'] ? $total_messages - $filters['limit'] : 0; 202 | else 203 | $filters['offset'] = $filters['offset'] - $filters['limit']; 204 | 205 | // last case 206 | $more = 1; 207 | if($filters['offset'] < 0 || $filters['offset']==0) 208 | { 209 | $filters['limit'] = $filters['limit'] - $filters['offset']; 210 | $filters['offset'] = 0; 211 | $more = 0; 212 | } 213 | 214 | $messages = $this->AC_LIB->addchat_db_lib->get_messages($this->AC_SETTINGS->logged_user_id, $buddy_id, $filters, true); 215 | 216 | if(empty($messages)) 217 | { 218 | $data = array( 219 | 'messages' => array(), 220 | 'offset' => 0, 221 | 'more' => 0, // to stop load more process 222 | 'status' => true, 223 | ); 224 | $this->format_json($data); 225 | } 226 | 227 | // remove notification 228 | $this->AC_LIB->addchat_db_lib->remove_notification(array('buddy_id'=>$this->AC_SETTINGS->logged_user_id, 'users_id'=>$buddy_id)); 229 | 230 | $data = array(); 231 | $data['messages'] = array(); 232 | foreach ($messages as $key => $message) 233 | { 234 | $data['messages'][$key]['message_id'] = $message->id; 235 | $data['messages'][$key]['sender'] = $message->m_from; 236 | $data['messages'][$key]['recipient'] = $message->m_to; 237 | $data['messages'][$key]['message'] = $message->message; 238 | $data['messages'][$key]['is_read'] = $message->is_read; 239 | $data['messages'][$key]['dt_updated'] = $message->dt_updated; 240 | 241 | } 242 | 243 | $data['offset'] = $filters['offset']; 244 | $data['more'] = $more; // to continue load more process 245 | $data['status'] = true; 246 | 247 | $this->format_json($data); 248 | } 249 | 250 | /* 251 | * Send message send_message 252 | */ 253 | public function send_message() 254 | { 255 | // check is logged-in 256 | $this->check_auth(); 257 | 258 | /* Validate form input */ 259 | $this->AC_LIB->form_validation 260 | ->set_rules('user', lang('user'), 'required|trim|is_natural_no_zero') 261 | ->set_rules('message', lang('message'), 'trim|required|max_length[2000]'); 262 | 263 | if($this->AC_LIB->form_validation->run() === FALSE) 264 | { 265 | $data = array('status' => false, 'response'=> validation_errors()); 266 | $this->format_json($data); 267 | } 268 | 269 | $buddy = (int) $this->AC_LIB->input->post('user'); 270 | $message = nl2br($this->AC_LIB->input->post('message')); 271 | 272 | // return null if buddy or message is empty 273 | if(!$message || !$buddy) 274 | $this->format_json(['status' => false,'response' => 'N/A']); 275 | 276 | $msg = array( 277 | "m_from" => $this->AC_SETTINGS->logged_user_id, 278 | "m_to" => $buddy, 279 | "message" => $message, 280 | "dt_updated" => date('Y-m-d H:i:s'), 281 | ); 282 | 283 | $msg_id = $this->AC_LIB->addchat_db_lib->send_message($msg); 284 | 285 | // 2. set_notification 286 | $this->AC_LIB->addchat_db_lib->set_notification(array('users_id' => $this->AC_SETTINGS->logged_user_id, 'buddy_id' => $buddy)); 287 | 288 | $chat = array( 289 | 'message_id' => $msg_id, 290 | 'sender' => $msg['m_from'], 291 | 'recipient' => $msg['m_to'], 292 | 'message' => $msg['message'], 293 | 'dt_updated' => $msg['dt_updated'], 294 | 'is_read' => 0, 295 | ); 296 | 297 | $data = array( 298 | 'status' => true, 299 | 'message' => $chat 300 | ); 301 | 302 | $this->format_json($data); 303 | } 304 | 305 | /* 306 | * Delete chat history delete_chat 307 | */ 308 | public function delete_chat($user_id = null) 309 | { 310 | // check is logged-in 311 | $this->check_auth(); 312 | 313 | $user_id = (int) $user_id; 314 | if(empty($user_id)) 315 | { 316 | $data = array('status' => false, 'response'=> lang('delete').' '.lang('fail')); 317 | $this->format_json($data); 318 | } 319 | 320 | $data = array(); 321 | $data['status'] = $this->AC_LIB->addchat_db_lib->delete_chat($this->AC_SETTINGS->logged_user_id, $user_id); 322 | 323 | $this->format_json($data); 324 | } 325 | 326 | /* 327 | * Update profile profile_update 328 | */ 329 | public function profile_update() 330 | { 331 | // check is logged-in 332 | $this->check_auth(); 333 | 334 | $this->AC_LIB->form_validation 335 | ->set_rules('status', lang('status'), 'required|trim') 336 | ->set_rules('fullname', lang('fullname'), 'required|trim') 337 | ->set_rules('user_id', lang('user'), 'required|trim|is_natural_no_zero'); 338 | 339 | if($this->AC_LIB->form_validation->run() === FALSE) 340 | { 341 | $data = array('status' => false, 'response'=> validation_errors()); 342 | $this->format_json($data); 343 | } 344 | 345 | // upload profile image 346 | $filename = null; 347 | if(! empty($_FILES['image']['name'])) // if image 348 | { 349 | $file = array('folder'=>$this->AC_SETTINGS->img_upload_path, 'input_file'=>'image'); 350 | $filename = $this->upload_file($file); 351 | // through image upload error 352 | if(!empty($filename['error'])) 353 | { 354 | $data = array('status' => false, 'response'=> lang('image_upload').' (png | jpg | jpeg)' ); 355 | $this->format_json($data); 356 | } 357 | } 358 | 359 | $data = array(); 360 | $data['status'] = $this->AC_LIB->input->post('status'); 361 | $data['fullname'] = $this->AC_LIB->input->post('fullname'); 362 | $data['user_id'] = $this->AC_LIB->input->post('user_id'); 363 | $data['dt_updated'] = date("Y-m-d H:i:s"); 364 | 365 | if(!empty($filename)) 366 | $data['avatar'] = $filename; 367 | 368 | // update user status 369 | $status = $this->AC_LIB->addchat_db_lib->update_user($this->AC_SETTINGS->logged_user_id, $data); 370 | if($status) 371 | $this->format_json($this->get_profile(true)); 372 | 373 | } 374 | 375 | 376 | /* 377 | * Get realtime updates of messages get_updates 378 | */ 379 | public function get_updates() 380 | { 381 | // check is logged-in 382 | $this->check_auth(); 383 | 384 | $notification = $this->AC_LIB->addchat_db_lib->get_updates($this->AC_SETTINGS->logged_user_id); 385 | 386 | // stop sending notification if in case of same notification 387 | $is_same = false; 388 | if(!empty($_POST['notification'])) 389 | if($_POST['notification'] == json_encode($notification)) 390 | $is_same = true; 391 | 392 | // if no messages then do nothing 393 | if(empty($notification) || $is_same) 394 | $this->format_json(array('status' => false, 'response'=> 'N/A')); 395 | 396 | $this->format_json(array('status' => true, 'notification' => $notification)); 397 | } 398 | 399 | /* 400 | * Get latest message of active buddy 401 | */ 402 | public function get_latest_message($buddy_id = null) 403 | { 404 | // check is logged-in 405 | $this->check_auth(); 406 | 407 | $buddy_id = (int) $buddy_id; 408 | $messages = array(); 409 | if($buddy_id) 410 | { 411 | $messages = $this->AC_LIB->addchat_db_lib->get_latest_message($this->AC_SETTINGS->logged_user_id, $buddy_id); 412 | 413 | // if any new message then remove the specific notification 414 | // remove notification 415 | $this->AC_LIB->addchat_db_lib->remove_notification(array('buddy_id'=>$this->AC_SETTINGS->logged_user_id, 'users_id'=>$buddy_id)); 416 | 417 | } 418 | 419 | // if no messages then do nothing 420 | if(empty($messages)) 421 | $this->format_json(array('status' => false, 'response'=> 'N/A')); 422 | 423 | $this->format_json(array('status' => true, 'messages' => $messages)); 424 | } 425 | 426 | 427 | /** 428 | * message delete 429 | */ 430 | public function message_delete($message_id = null) 431 | { 432 | // check is logged-in 433 | $this->check_auth(); 434 | 435 | $message_id = (int) $message_id; 436 | if(empty($message_id)) 437 | $this->format_json(array('status' => false)); 438 | 439 | $status = $this->AC_LIB->addchat_db_lib->message_delete($message_id, $this->AC_SETTINGS->logged_user_id); 440 | 441 | if($status) 442 | $this->format_json(array('status' => true, 'message' => lang('message').' '.lang('deleted'))); 443 | 444 | $this->format_json(array('status' => false, 'message'=> lang('delete').' '.lang('fail'))); 445 | } 446 | 447 | /* ========== ADMIN PANEL APIs start ==========*/ 448 | 449 | /** 450 | * Check admin auth 451 | */ 452 | public function check_admin($is_return = false) 453 | { 454 | // check if logged-in user is admin 455 | if($this->AC_SETTINGS->is_admin !== $this->AC_SETTINGS->logged_user_id) 456 | $this->format_json(array('status' => false)); 457 | 458 | if(!$is_return) 459 | $this->format_json(array('status' => true)); 460 | 461 | return true; 462 | } 463 | 464 | /** 465 | * Save settings 466 | */ 467 | public function save_settings() 468 | { 469 | //check admin authentication 470 | $this->check_admin(true); 471 | 472 | // do not respond empty request 473 | if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') 474 | { 475 | header('Access-Control-Allow-Origin: *'); 476 | header('Access-Control-Allow-Headers: X-Requested-With'); 477 | header("HTTP/1.1 200 OK"); 478 | die(); 479 | } 480 | 481 | if($this->demo_mode()) 482 | { 483 | $data = array('status' => false, 'response'=> 'DEMO MODE'); 484 | $this->format_json($data); 485 | } 486 | 487 | /* Validate form input */ 488 | $this->AC_LIB->form_validation 489 | ->set_rules('site_name', lang('site_name'), 'required|trim') 490 | ->set_rules('footer_text', lang('footer_text'), 'trim') 491 | ->set_rules('footer_url', lang('footer_text').' '.lang('URL'), 'trim') 492 | ->set_rules('admin_user_id', lang('admin').' '.lang('user').' '.lang('id'), 'required|trim|is_natural_no_zero') 493 | ->set_rules('pagination_limit', lang('pagination_limit'), 'required|trim|is_natural_no_zero') 494 | ->set_rules('img_upload_path', lang('img_upload_path'), 'required|trim') 495 | ->set_rules('assets_path', lang('assets_path'), 'required|trim') 496 | ->set_rules('users_table', lang('users_table').' '.lang('name'), 'required|trim') 497 | ->set_rules('users_id', lang('users_id'), 'required|trim') 498 | ->set_rules('users_email', lang('users_email'), 'required|trim') 499 | ->set_rules('notification_type', lang('notification_type'), 'numeric'); 500 | 501 | if($this->AC_LIB->form_validation->run() === FALSE) 502 | { 503 | $data = array('status' => false, 'response'=> validation_errors()); 504 | $this->format_json($data); 505 | } 506 | 507 | $data = array(); 508 | 509 | // upload site logo 510 | $filename = null; 511 | if(! empty($_FILES['image']['name'])) // if image 512 | { 513 | $file = array('folder'=>$this->AC_SETTINGS->img_upload_path, 'input_file'=>'image'); 514 | $filename = $this->upload_file($file); 515 | // through image upload error 516 | if(!empty($filename['error'])) 517 | { 518 | $data = array('status' => false, 'response'=> lang('image_upload').' (png | jpg | jpeg)' ); 519 | $this->format_json($data); 520 | } 521 | } 522 | 523 | // upload chat icon 524 | $chat_icon = null; 525 | if(! empty($_FILES['chat_icon']['name'])) // if image 526 | { 527 | $chat_icon_file = array('folder'=>$this->AC_SETTINGS->img_upload_path, 'input_file'=>'chat_icon'); 528 | $chat_icon = $this->upload_file($chat_icon_file); 529 | 530 | // through image upload error 531 | if(!empty($chat_icon['error'])) 532 | { 533 | $data = array('status' => false, 'response'=> lang('image_upload').' (png | jpg | jpeg)' ); 534 | $this->format_json($data); 535 | } 536 | } 537 | 538 | // site logo 539 | if(!empty($filename)) 540 | $data['site_logo'] = $filename; 541 | 542 | // chat icon 543 | if(!empty($chat_icon)) 544 | $data['chat_icon'] = $chat_icon; 545 | 546 | $data['site_name'] = $this->AC_LIB->input->post('site_name'); 547 | $data['footer_text'] = $this->AC_LIB->input->post('footer_text'); 548 | $data['footer_url'] = $this->AC_LIB->input->post('footer_url'); 549 | $data['admin_user_id'] = $this->AC_LIB->input->post('admin_user_id'); 550 | $data['pagination_limit'] = $this->AC_LIB->input->post('pagination_limit'); 551 | $data['img_upload_path'] = $this->AC_LIB->input->post('img_upload_path'); 552 | $data['assets_path'] = $this->AC_LIB->input->post('assets_path'); 553 | $data['users_table'] = $this->AC_LIB->input->post('users_table'); 554 | $data['users_col_id'] = $this->AC_LIB->input->post('users_id'); 555 | $data['users_col_email'] = $this->AC_LIB->input->post('users_email'); 556 | $data['notification_type'] = $this->AC_LIB->input->post('notification_type'); 557 | 558 | $status = $this->AC_LIB->addchat_db_lib->save_settings($data); 559 | 560 | 561 | $this->format_json(array('status' => $status)); 562 | } 563 | 564 | /** 565 | * get chat users who chat with each other means between users 566 | * 567 | */ 568 | public function a_chat_between($offset = 0) 569 | { 570 | //check admin authentication 571 | $this->check_admin(true); 572 | 573 | // filters 574 | $filters = array(); 575 | $filters['limit'] = $this->AC_SETTINGS->pagination_limit; 576 | $filters['offset'] = (int) $offset; 577 | 578 | $chat_betweens = $this->AC_LIB->addchat_db_lib->a_chat_between($filters, $this->AC_SETTINGS->logged_user_id); 579 | if(empty($chat_betweens)) 580 | { 581 | $data = array( 582 | 'chat_betweens' => array(), 583 | 'offset' => 0, 584 | 'more' => 0, // to stop load more process 585 | 'status' => true, 586 | ); 587 | $this->format_json($data); 588 | } 589 | 590 | $data = array( 591 | 'status' => true, 592 | 'offset' => $filters['offset'] == 0 ? $filters['limit'] : $filters['limit']+$filters['offset'], 593 | 'more' => 1, // to stop load more process 594 | 'chat_betweens' => $chat_betweens, 595 | ); 596 | 597 | $this->format_json($data); 598 | } 599 | 600 | /** 601 | * get conversation of between to users 602 | */ 603 | public function a_get_conversations($m_from = null, $m_to = null, $offset = 0) 604 | { 605 | //check admin authentication 606 | $this->check_admin(true); 607 | 608 | $m_from = (int) $m_from; 609 | $m_to = (int) $m_to; 610 | 611 | // filters 612 | $filters = array(); 613 | $filters['limit'] = $this->AC_SETTINGS->pagination_limit; 614 | $filters['offset'] = (int) $offset; 615 | 616 | $total_messages = $this->AC_LIB->addchat_db_lib->a_get_conversations($m_from, $m_to, $filters, true); 617 | 618 | // 1st case 619 | if($filters['offset'] == 0) 620 | $filters['offset'] = $total_messages > $filters['limit'] ? $total_messages - $filters['limit'] : 0; 621 | 622 | 623 | else 624 | $filters['offset'] = $filters['offset'] - $filters['limit']; 625 | 626 | // last case 627 | $more = 1; 628 | if($filters['offset'] < 0 || $filters['offset']==0) 629 | { 630 | $filters['limit'] = $filters['limit'] - $filters['offset']; 631 | $filters['offset'] = 0; 632 | $more = 0; 633 | } 634 | 635 | $conversations = $this->AC_LIB->addchat_db_lib->a_get_conversations($m_from, $m_to, $filters); 636 | 637 | if(empty($conversations)) 638 | { 639 | $data = array( 640 | 'conversations' => array(), 641 | 'offset' => 0, 642 | 'more' => 0, // to stop load more process 643 | 'status' => true, 644 | ); 645 | $this->format_json($data); 646 | } 647 | 648 | $data = array( 649 | 'conversations' => $conversations, 650 | 'status' => true, 651 | 'more' => $more, // to continue load more process 652 | 'offset' => $filters['offset'], 653 | ); 654 | $this->format_json($data); 655 | } 656 | 657 | /* ========== ADMIN PANEL APIs end==========*/ 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | /* ========== PRIVATE HELPER FUNCTIONS ==========*/ 667 | /** 668 | * Upload File 669 | */ 670 | private function upload_file($data = array()) 671 | { 672 | $this->AC_LIB->load->library(array('upload', 'image_lib')); 673 | 674 | $config = array(); 675 | $config['allowed_types'] = 'jpg|JPG|jpeg|JPEG|png|PNG'; 676 | $config['size'] = '8388608'; 677 | $config['file_ext_tolower'] = TRUE; 678 | $config['overwrite'] = TRUE; 679 | $config['remove_spaces'] = TRUE; 680 | $config['upload_path'] = './'.$data['folder'].'/'; 681 | 682 | if (!is_dir($config['upload_path'])) 683 | mkdir($config['upload_path'], 0777, TRUE); 684 | 685 | $filename = time().rand(1,988); 686 | $extension = strtolower(pathinfo($_FILES[$data['input_file']]['name'], PATHINFO_EXTENSION)); 687 | 688 | // original file for resizing 689 | $config['file_name'] = $filename.'_large'.'.'.$extension; 690 | 691 | // file name for further use 692 | $filename = $filename.'.'.$extension; 693 | 694 | $this->AC_LIB->upload->initialize($config); 695 | 696 | if (! $this->AC_LIB->upload->do_upload($data['input_file'])) 697 | { 698 | // remove all uploaded files in case of error 699 | $this->reset_file($config['upload_path'], $filename); 700 | return array('error' => $this->AC_LIB->upload->display_errors()); 701 | } 702 | 703 | // cropped thumbnail 704 | $thumb = array(); 705 | $thumb['image_library'] = 'gd2'; 706 | $thumb['source_image'] = $config['upload_path'].$config['file_name']; 707 | $thumb['new_image'] = $config['upload_path'].$filename; 708 | $thumb['maintain_ratio'] = TRUE; 709 | $thumb['width'] = 800; 710 | $thumb['height'] = 600; 711 | $thumn['quality'] = 50; 712 | $thumb['file_permissions'] = 0644; 713 | 714 | $this->AC_LIB->image_lib->initialize($thumb); 715 | 716 | if (! $this->AC_LIB->image_lib->resize()) 717 | { 718 | $this->reset_file($config['upload_path'], $filename); 719 | return array('error' => $this->AC_LIB->image_lib->display_errors()); 720 | } 721 | 722 | $this->AC_LIB->image_lib->clear(); 723 | 724 | // remove the original image 725 | unlink($config['upload_path'].$config['file_name']); 726 | 727 | return $filename; 728 | 729 | } 730 | 731 | /** 732 | * Reset File 733 | */ 734 | private function reset_file($path = '', $data = '') 735 | { 736 | if(file_exists($path.$data)) 737 | @unlink($path.$data); 738 | 739 | return 1; 740 | } 741 | 742 | /** 743 | * Validate email 744 | */ 745 | private function isValidEmail($email) 746 | { 747 | return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; 748 | } 749 | 750 | /** 751 | * Check if user logged in 752 | */ 753 | private function check_auth() 754 | { 755 | if(!$this->AC_SETTINGS->logged_user_id) 756 | $this->format_json(array('status' => false, 'response'=> lang('access_denied'))); 757 | 758 | return true; 759 | } 760 | 761 | /** 762 | * Echo json 763 | */ 764 | private function format_json($data = array()) 765 | { 766 | header('Content-Type: application/json'); 767 | echo json_encode($data); 768 | exit; 769 | } 770 | 771 | /** 772 | * Detect demo mode 773 | */ 774 | private function demo_mode() 775 | { 776 | $domain = strtolower($_SERVER['SERVER_NAME']); 777 | if (strpos($domain, 'classiebit.com') !== FALSE || strpos($domain, 'addchat-codeigniter.test') !== FALSE) 778 | return true; 779 | 780 | return FALSE; 781 | } 782 | 783 | 784 | } 785 | /*End Addchat_lib Class*/ -------------------------------------------------------------------------------- /addchat_installer/src/libraries/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 403 Forbidden 5 | 6 | 7 | 8 |

Directory access is forbidden.

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 - 2019, British Columbia Institute of Technology 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 13 | all 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 21 | THE SOFTWARE. --------------------------------------------------------------------------------