diff --git a/.gitignore b/.gitignore index 8fa0d0b9..053e1221 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ application/config/database.php sftp-config.json +.idea \ No newline at end of file diff --git a/README.md b/README.md index 20a339d5..aa9b2a37 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,23 @@ ![PHPBack](http://www.phpback.org/images/logo_300.png) -##About -PHPBack is an open source feedback system you can use for your website. It gives your customers a way to communicate their ideas to improve your products. User feedback has proved to be really efective even if you have a community project or a commercial project. -Please, vist our website for more information: [http://www.phpback.org/](http://www.phpback.org/) +## About +PHPBack is an open source feedback system you can use for your website. It gives your customers a way to communicate their ideas to improve your products. User feedback has proved to be really effective even if you have a community project or a commercial project. +Please, visit our website for more information: [http://www.phpback.org/](http://www.phpback.org/) -##Requeriments -* PHP 5.3+ +## Requirements +* PHP 5.6+ * MySQL 4.1+ -##Installation -Upload this folder in your web server, go to `yourwebsite.com/feedback/` (or folder name) and fill the form. -If you have any questions, plase visit our [Wiki](https://github.com/ivandiazwm/phpback/wiki/). +## Installation +Upload this folder to your web server, go to `yourwebsite.com/feedback/` (or folder name) and fill the form. +If you have any questions, please visit our [Wiki](https://github.com/ivandiazwm/phpback/wiki/). -##License +Install on Cloudron, a platform to effortlessly run web apps on your own server. + +[![Install](https://cloudron.io/img/button.svg)](https://cloudron.io/button.html?app=org.phpback.cloudronapp) + +## License PHPBack is licensed under GPLv3 (see `LICENSE.TXT` file) and it was made using Codeigniter Framework (see `system/license.txt` file). `Ivan Diaz © 2014` diff --git a/application/config/config.php b/application/config/config.php index 75d88c40..29a54443 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -357,6 +357,17 @@ */ $config['proxy_ips'] = ''; +/* +|-------------------------------------------------------------------------- +| AutoUpdater +|-------------------------------------------------------------------------- +| +| Toggle the auto updater. If your system has other means to update or +| phpback is installed on a read-only filesystem, set this to FALSE. +| +*/ +$config['auto_update'] = FALSE; + /* End of file config.php */ /* Location: ./application/config/config.php */ diff --git a/application/controllers/action.php b/application/controllers/action.php index 9be61146..a7638b91 100755 --- a/application/controllers/action.php +++ b/application/controllers/action.php @@ -11,7 +11,7 @@ if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Action extends CI_Controller{ - + public function __construct(){ parent::__construct(); $this->load->helper('url'); @@ -19,11 +19,9 @@ public function __construct(){ $this->load->model('post'); } public function register(){ - require_once('public/recaptcha/recaptchalib.php'); - + require_once('public/recaptcha/autoload.php'); + $votes = $this->get->getSetting('maxvotes'); - $title = $this->get->getSetting('title'); - $mainmail = $this->get->getSetting('mainmail'); $email = $this->input->post('email', true); $pass = $this->input->post('password', true); @@ -31,21 +29,19 @@ public function register(){ $name = $this->input->post('name', true); if($this->get->getSetting('recaptchapublic') != ""){ - $resp = recaptcha_check_answer($this->get->getSetting('recaptchaprivate'), - $_SERVER["REMOTE_ADDR"], - $_POST["recaptcha_challenge_field"], - $_POST["recaptcha_response_field"]); - - if(!$resp->is_valid){ + $recaptcha = new \ReCaptcha\ReCaptcha($this->get->getSetting('recaptchaprivate')); + $resp = $recaptcha->verify($_POST["g-recaptcha-response"], $_SERVER['REMOTE_ADDR']); + + if(!$resp->isSuccess()){ header('Location: '. base_url() .'home/register/recaptcha'); return; } } - if(strlen($name) < 7){ + if(strlen($name) < 3){ header('Location: '. base_url() .'home/register/name'); return; } - if (!preg_match("/^([a-zA-Z0-9._]+)@([a-zA-Z0-9.-]+).([a-zA-Z]{2,4})$/",$email)){ + if (!preg_match("/^([a-zA-Z0-9._-]+)@([a-zA-Z0-9.-]+).([a-zA-Z]{2,4})$/",$email)){ header('Location: '. base_url() .'home/register/email'); return; } @@ -59,25 +55,17 @@ public function register(){ } if($this->post->add_user($name, $email, $pass, $votes, false)){ + $title = $this->get->getSetting('title'); $message = "Welcome to our feedback: $title\n\nYour Email: $email\nYour Password: $pass\n\n\nPlease login here:" . base_url() . "home/login\n"; - $this->load->library('email'); - - $this->email->initialize($this->get->email_config()); - $this->email->from($mainmail, 'PHPBack'); - $this->email->to($email); + $this->sendMail($message, "New account - $title", $email); - $this->email->subject("New account - $title"); - $this->email->message($message); - - $this->email->send(); - header('Location: '. base_url() .'home/login/register'); } else header('Location: '. base_url() .'home/register/exists'); - + } - + public function login(){ session_start(); @@ -99,7 +87,7 @@ public function login(){ header('Location: ' . base_url() . 'home/login/errorlogin/'); } } - + public function logout(){ session_start(); session_destroy(); @@ -120,17 +108,22 @@ public function vote($votes, $ideaid){ exit; } $idea = $this->get->getIdea($ideaid); - header("Location: " . base_url() . 'home/idea/' . $ideaid . '/' . str_replace(' ', '-', $idea->title)); + header("Location: " . $idea->url); } public function unvote($id){ session_start(); $vote = $this->get->get_row_by_id('votes', $id); - if(isset($_SESSION['phpback_userid']) && $_SESSION['phpback_userid'] == $vote->userid){ + + if ($vote && isset($_SESSION['phpback_userid']) && $_SESSION['phpback_userid'] == $vote->userid) { $idea = $this->get->getIdea($vote->ideaid); + $user = $this->get->getUser($vote->userid); + $this->post->update_by_id('ideas', 'votes', $idea->votes - $vote->number, $idea->id); + $this->post->update_by_id('users', 'votes', $user->votes + $vote->number, $user->id); $this->post->delete_row_by_id('votes', $id); } + header('Location:' . base_url() . 'home/profile/' . $vote->userid); } @@ -148,28 +141,28 @@ public function changepassword(){ if(strlen($new) > 5){ if($new == $rnew){ $user = $this->get->getUser($_SESSION['phpback_userid']); - + if($this->hashing->matches($old, $user->pass)){ $this->post->update_by_id('users', 'pass', $this->hashing->hash($new), $user->id); $message = "You have changed your password to: $new\n"; $this->load->library('email'); $this->email->initialize($this->get->email_config()); - + $mainmail = $this->get->getSetting('mainmail'); $title = $this->get->getSetting('title'); $this->email->from($mainmail, 'PHPBack'); - $this->email->to($user->email); + $this->email->to($user->email); $this->email->subject("Password changed - $title"); - $this->email->message($message); + $this->email->message($message); $this->email->send(); - + header('Location: ' . $toredirect); } else $this->redirectpost($toredirect, array('error' => 2)); - + } else $this->redirectpost($toredirect, array('error' => 1)); } @@ -196,8 +189,20 @@ public function newidea(){ $this->redirectpost(base_url() . "home/postidea/errordesc", array('title' => $title, 'desc' => $desc, 'catid' => $catid)); return; } - if(@isset($_SESSION['phpback_userid'])) + if(@isset($_SESSION['phpback_userid'])) { $this->post->add_idea($title, $desc, $_SESSION['phpback_userid'], $catid); + $admins = $this->get->get_admin_users(); + $adminMails = array_map(function (\stdClass $admin) { + return $admin->email; + }, $admins); + $adminMails = implode(', ', $adminMails); + $generalTitle = '' !== $this->get->getSetting('title') ? $this->get->getSetting('title') : 'PHPBack'; + $lastIdea = $this->get->getLastIdea(); + $message = sprintf($this->lang->language['log_new_idea_mail_content'], $generalTitle, $lastIdea->url); + $fullTitle = $this->lang->language['log_new_idea'] . ' : ' . $generalTitle; + + $this->sendMail($message, $fullTitle, $adminMails); + } header("Location: " . base_url() . "home/profile/" . $_SESSION['phpback_userid']); } @@ -205,23 +210,53 @@ public function comment($idea_id){ session_start(); $idea_id = (int) $idea_id; $content = $this->input->post('content', true); - if(isset($_SESSION['phpback_userid'])) + if(isset($_SESSION['phpback_userid'])) { $this->post->add_comment($idea_id, $content, $_SESSION['phpback_userid']); - header("Location: " . base_url() . "home/idea/" . $idea_id . '/' . $this->input->post('ideaname', true)); + $comments = $this->get->getCommentsByIdea($idea_id); + $usersMails = []; + foreach ($comments as $comment) { + $usersMails[] = $this->get->getUser($comment->userid)->email; + } + $usersMails = array_unique($usersMails); + $generalTitle = '' !== $this->get->getSetting('title') ? $this->get->getSetting('title') : 'PHPBack'; + $idea = $this->get->getIdea($idea_id); + $message = sprintf($this->lang->language['log_new_comment_mail_content'], $generalTitle, $idea->url); + $title = sprintf($this->lang->language['log_commented'], $idea_id); + + $this->sendMail($message, $title, $usersMails); + } + header("Location: " . $this->get->getIdea($idea_id)->url); } - public function flag($cid, $ideaid, $ideaname){ + private function sendMail($message, $title, $recipients) + { + if (empty($recipients)) { + return false; + } + $mainmail = $this->get->getSetting('mainmail'); + $this->load->library('email'); + + $this->email->initialize($this->get->email_config()); + $this->email->from($mainmail, 'PHPBack'); + $this->email->to($recipients); + $this->email->subject($title); + $this->email->message($message); + + return $this->email->send(); + } + + public function flag($cid, $idea_id){ session_start(); if(!isset($_SESSION['phpback_userid'])){ header("Location: " . base_url(). "home/login"); exit; } - $this->post->flag($cid, $_SESSION['phpback_userid']); - header("Location: " . base_url() . "home/idea/" . $ideaid . '/' . $ideaname); + $this->post->flag($cid, $_SESSION['phpback_userid']); + header("Location: " . $this->get->getIdea($idea_id)->url); } private function redirectpost($url, array $data){ - + echo ' +