Skip to content
Browse files

Latest version of recalls website including license and readme files

  • Loading branch information...
1 parent 7d1c5b8 commit 220206bd2a37f5814691a9dbdaa5352502457877 Consumer Focus Labs committed Jul 14, 2009
View
25 LICENSE
@@ -0,0 +1,25 @@
+CodeIgniter License Agreement
+
+Copyright (c) 2008, EllisLab, Inc.
+All rights reserved.
+
+This license is a legal agreement between you and EllisLab Inc. for the use of CodeIgniter Software (the "Software"). By obtaining the Software you agree to comply with the terms and conditions of this license.
+
+Permitted Use
+You are permitted to use, copy, modify, and distribute the Software and its documentation, with or without modification, for any purpose, provided that the following conditions are met:
+
+- A copy of this license agreement must be included with the distribution.
+- Redistributions of source code must retain the above copyright notice in all source code files.
+- Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
+- Any files that have been modified must carry notices stating the nature of the change and the names of those who changed them.
+- Products derived from the Software must include an acknowledgment that they are derived from CodeIgniter in their documentation and/or other materials provided with the distribution.
+- Products derived from the Software may not be called "CodeIgniter", nor may "CodeIgniter" appear in their name, without prior written permission from EllisLab, Inc.
+
+Indemnity
+You agree to indemnify and hold harmless the authors of the Software and any contributors for any direct, indirect, incidental, or consequential third-party claims, actions or suits, as well as any related expenses, liabilities, damages, settlements or fees arising from your use or misuse of the Software, or a violation of any terms of this license.
+
+Disclaimer of Warranty
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF QUALITY, PERFORMANCE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
+
+Limitations of Liability
+YOU ASSUME ALL RISK ASSOCIATED WITH THE INSTALLATION AND USE OF THE SOFTWARE. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS OF THE SOFTWARE BE LIABLE FOR CLAIMS, DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE. LICENSE HOLDERS ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USE AND ASSUME ALL RISKS ASSOCIATED WITH ITS USE, INCLUDING BUT NOT LIMITED TO THE RISKS OF PROGRAM ERRORS, DAMAGE TO EQUIPMENT, LOSS OF DATA OR SOFTWARE PROGRAMS, OR UNAVAILABILITY OR INTERRUPTION OF OPERATIONS.
View
30 README
@@ -0,0 +1,30 @@
+== Product Recalls
+
+The product recalls project is a website based upon the Code Igniter (1.7.1) PHP
+framework. It scrapes details of product recalls from the European Commission
+website and makes them available in a searchable database with categories, email
+subscription and RSS feeds.
+
+For more information, see http://www.consumerfocuslabs.org
+
+== What's new in this release?
+
+This is the initial release of this project. Future updates will be
+detailed in a CHANGELOG file.
+
+== Installation/Usage
+* Run the sql scripts in the schema directory to create the database
+* Copy all files to your public html directory
+* Rename config/config.example to config/config
+* Update this file with your database and website settings
+* set up a cronjob to run run_scraper.php on a regular basis (this scrapes the EC website)
+* set up a cronjob to run run_emailer.php on a regular basis (this sends the emails)
+
+
+== The distribution
+
+This website runs on the CodeIgniter PHP framework (http://www.codeigniter.com).
+If you need exmples on how to get this running, please see the user guide.
+
+== Dependencies
+* PHP & MySql
View
0 config/config → config/config.example
File renamed without changes.
View
1 system/application/config/routes.php
@@ -43,6 +43,7 @@
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";
+$route['browse'] = "categories/index";
$route['category/(:any)/page/(:num)'] = "categories/category_lookup_page/$1/$2";
$route['category/(:any)'] = "categories/category_lookup/$1";
$route['search/(:any)/(:any)/page/(:num)'] = "search/lookup_page/$1/$2/$3";
View
53 system/application/controllers/about.php
@@ -1,49 +1,84 @@
<?php
-
+/**
+ * Categories Class
+ *
+ * @package Product Recalls
+ * @subpackage Controllers
+ * @category About
+ * @author Dafydd Vaughan, Consumer Focus Labs
+ * @link http://www.consumerfocuslabs.org
+ */
class About extends Controller {
+ /**
+ * Constructor
+ *
+ * @access public
+ */
function Welcome()
{
- parent::Controller();
+ //load parent
+ parent::Controller();
+
+ //load in some helpers
+ //TO DO: autoload please!
+ $this->load->model('Recall_model','',TRUE);
+ $this->load->helper('url_helper');
}
+ /**
+ * Displays "about us" information page
+ *
+ * @access public
+ */
function index()
{
- $this->load->model('Recall_model','',TRUE);
- $this->load->helper('url_helper');
+ //load page data
$page_data['page_title'] = "About ".SITE_NAME;
$page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
$page_data['feeds']= array();
$page_data['menu'] = 'about';
+ //load views
$this->load->view('header',$page_data);
$this->load->view('about');
$this->load->view('footer');
}
+ /**
+ * Displays an example email view
+ *
+ * @access public
+ */
function example() {
- $this->load->model('Recall_model','',TRUE);
- $this->load->helper('url_helper');
+
+ //load page data
$page_data['page_title']= "Example Email Alert | ".SITE_NAME;
$page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
$page_data['feeds'] = array();
$page_data['menu'] = 'about';
+ //load views
$this->load->view('header',$page_data);
$this->load->view('example_email');
$this->load->view('footer');
}
+ /**
+ * Displays feedback request page
+ *
+ * @access public
+ */
function feedback() {
- $this->load->model('Recall_model','',TRUE);
- $this->load->helper('url_helper');
+ //load page data
$page_data['page_title']= "Send Us Your Feedback | ".SITE_NAME;
$page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
$page_data['feeds'] = array();
$page_data['menu'] = 'feedback';
+ //load views
$this->load->view('header',$page_data);
$this->load->view('feedback');
$this->load->view('footer');
}
}
-/* End of file welcome.php */
+/* End of file about.php */
/* Location: ./system/application/controllers/about.php */
View
2 system/application/controllers/categories.php
@@ -39,7 +39,7 @@ function Categories() {
function index() {
//set up page data
- $page_data['page_title'] = "Recall Categories | ".SITE_NAME;
+ $page_data['page_title'] = "Browse product recalls by category | ".SITE_NAME;
$page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
$page_data['feeds']= array();
$page_data['menu'] = 'categories';
View
5 system/application/controllers/feed.php
@@ -5,7 +5,7 @@
* @package Product Recalls
* @subpackage Controllers
* @category Feeds
- * @author Dafydd Vaughan, Consumer Focus Labs
+ * @author Consumer Focus Labs
* @link http://www.consumerfocuslabs.org
*/
class Feed extends Controller {
@@ -192,4 +192,5 @@ function category($category="") {
}
}
-?>
+/* End of file feed.php */
+/* Location: ./system/application/controllers/feed.php */
View
269 system/application/controllers/import.php
@@ -1,269 +0,0 @@
-<?php
-
-class Import extends Controller {
-
- private $log = array();
- private $imported_counter = 0;
- private $recalls_counter = 0;
-
- function index() {
-
- //if this is being run through the main website
- //disallow and throw a 404 error
- if(substr_count($_SERVER['SCRIPT_FILENAME'],'run_scraper.php') < 1) {
- $this->load->helper('url_helper');
- show_404(current_url());
- exit;
- }
-
- //load helper and model
- $this->load->helper('scraping_helper');
- $this->load->model('Recall_model','',TRUE);
-
-
- //scrape the content
- $this->scrape_ts();
-
- //send log email
- $this->log_mail();
-
- //delete recent recalls cache if cache is active
- if (WWW_CACHE_ACTIVE) {
- $this->mp_cache->delete('recent-recalls');
- }
-
- //load the view
- $this->load->view('import');
- }
-
- private function log($message,$log_type='debug') {
-
- //print the message to the screen
- print $message."\n";
- //push it to the log
- array_push($this->log,$message);
- log_message($log_type,SCRAPER_EMAIL_LOG_PREFIX." ".$message);
-
-
- }
-
- private function log_mail($complete = TRUE) {
-
- //load the email helper
- //$this->load->helper('email_helper');
- $this->load->library('email');
-
-
- //set up the email
- $this->email->from(EMAILER_ADDRESS,SITE_NAME);
- $this->email->to(SCRAPER_EMAIL_LOG);
- if ($complete) {
- $this->email->subject(SCRAPER_EMAIL_LOG_PREFIX." Scraped ".$this->imported_counter."/".$this->recalls_counter);
- } else {
- $this->email->subject(SCRAPER_EMAIL_LOG_PREFIX." ERROR");
- }
- $this->email->message(implode("\n",$this->log));
-
- //send the email
- $this->email->send();
-
- }
-
- private function scrape_ts() {
-
- //url info
- $url_prefix = "http://www.tradingstandards.gov.uk/navless/recall/";
- $url_page = "listing.asp";
-
- $link_regex = "/<a href=\"(.*?)\">.*?<\/a>/s";
-
- $this->log("starting scraping ({$url_prefix}{$url_page})");
-
- //get content of product list page
- try {
- $ts_html = scrape_content($url_prefix.$url_page);
- } catch (Exception $e) {
- $this->log("fatal error: ". $e->getMessage(),'error');
- $this->log_mail(FALSE);
- exit;
-
- }
-
- //grab all the links on the page
- preg_match_all($link_regex,$ts_html,$matches,PREG_PATTERN_ORDER);
-
- $this->log("found ".count($matches[1])." recalls to scrape");
-
- if (count($matches[1]) < 1) {
- $this->log("fatal error: no links to scrape",'error');
- $this->log_mail(FALSE);
- exit;
- }
-
- //for each URL on the page, scrape its content
- foreach($matches[1] as $recallitem) {
-
- $this->recalls_counter++;
-
- $this->log("-- getting scrape for ({$url_prefix}{$recallitem})");
-
- //try and scrape the content, if an error occurs
- //log it and move to next item
- try {
- //scrape
- $result = $this->scrape_ts_info($url_prefix.$recallitem);
-
- //does the record already exist?
- $exists = $this->Recall_model->id_exist($result["id"],1);
-
-
- if (!$exists) {
- $this->log("-- importing data for product (".$result["title"].")");
-
- //produce the unique url
- $internal_url = $this->produce_slug($result["title"],$result["id"]);
- //store in database
- $data = array(
- 'product_name' => $result["title"],
- 'description' => $result["content"],
- 'external_url' => $url_prefix.$recallitem,
- 'internal_url' => $internal_url,
- 'source_id' => $result["id"],
- 'source' => 1
- );
- $this->db->insert('recalls',$data);
- $this->imported_counter++;
- } else {
- $this->log("-- product already recorded");
- }
-
- } catch (Exception $e) {
- $this->log("error: ". $e->getMessage(),'error');
- }
- sleep(SCRAPER_SLEEP);
- //exit;
-
- }
-
- $this->log("import complete (".$this->imported_counter."/".$this->recalls_counter.")");
- $this->log("end");
-
- }
-
- private function scrape_ts_info($url) {
-
- $return = array();
-
- //get id of item
-
- $id_regex = "/id=([0-9]*)/";
-
- preg_match_all($id_regex,$url,$id_matches,PREG_PATTERN_ORDER);
-
- if (count($id_matches[1]) == 1) {
-
- $return["id"] = 0+$id_matches[1][0];
-
- }
-
-
-
- //scrape content
- try {
- $html = scrape_content($url);
- } catch (Exception $e) {
- throw $e;
- exit;
- }
-
- //get title from recall
-
- $title_regex = "/<h2 class=\"iframe_content_news_heading\">(.*?)<\/h2>/s";
-
- preg_match_all($title_regex,$html,$title_matches,PREG_PATTERN_ORDER);
-
- foreach($title_matches[1] as $title) {
- $title = str_replace("- recall","",$title);
- $return["title"] = trim($title);
- }
-
- //get content from recall
-
- $content_regex = "/<p>(.*?)<\/p>/s";
-
- preg_match_all($content_regex,$html,$content_matches,PREG_PATTERN_ORDER);
-
- $return["content"] = "";
- foreach($content_matches[1] as $content) {
-
- //strip out tags from html
- $content = strip_tags($content);
- $content = html_entity_decode($content);
-
- //add line breaks
- $content = trim($content)."\n";
-
- //add to result
- $return["content"] .= $content;
-
- }
-
- return $return;
-
- }
-
- private function produce_slug($title,$id) {
- $this->load->helper('slug_helper');
- $internal_base_url = produce_slug($title,"-");
- $internal_url = $internal_base_url;
- $internal_url_attempts = 0;
-
- //do while url already exists
-
- while ($this->Recall_model->internal_url_exist($internal_url)) {
- if ($internal_url_attempts < 10) {
- $internal_url = $internal_base_url."-".($internal_url_attempts+1);
- $internal_url_attempts++;
- } else {
- $internal_url = $internal_base_url."-".$id;
- break;
-
- }
- }
-
- return $internal_url;
- }
-
- function checker() {
-
- //if this is being run through the main website
- //disallow and throw a 404 error
- if(substr_count($_SERVER['SCRIPT_FILENAME'],'run_scraper_checker.php') < 1) {
- $this->load->helper('url_helper');
- show_404(current_url());
- exit;
- }
-
- $this->load->model('Recall_model','',TRUE);
- $this->load->library('email');
- $this->load->helper('date');
-
- if ($this->Recall_model->are_there_recent_updates() < 1) {
- //there have been no updates for 2 days, send a warning email
-
- //set up the email
- $this->email->from(EMAILER_ADDRESS,SITE_NAME);
- $this->email->to(SCRAPER_EMAIL_LOG);
-
- $this->email->subject(SCRAPER_EMAIL_LOG_PREFIX." No Recent Updates");
- $this->email->message("There have been no updates for 2 days. Please check.");
-
- //send the email
- $this->email->send();
-
- }
-
- }
-
-}
-?>
View
329 system/application/controllers/recall.php
@@ -1,173 +1,192 @@
<?php
+/**
+ * Recall Class
+ *
+ * @package Product Recalls
+ * @subpackage Controllers
+ * @category Recall
+ * @author Consumer Focus Labs
+ * @link http://www.consumerfocuslabs.org
+ */
class Recall extends Controller {
- function Recall() {
- parent::Controller();
-
- }
-
+ /**
+ * Constructor
+ *
+ * @access public
+ */
+ function Recall() {
+ //load parent
+ parent::Controller();
+ //load in some helpers
+ $this->load->helper('typography_helper');
+ //TO DO: autoload please!
+ $this->load->model('Recall_model', '', TRUE);
+ $this->load->model('Category_model', '', TRUE);
+ $this->load->helper('url_helper');
+ $this->load->helper('date_helper');
+ $this->load->helper('text_helper');
+ }
- function index()
- {
- /*$this->load->helper('url_helper');
- $this->load->model('Recall_model','',TRUE);
- $data['recalls'] = $this->Recall_model->get_recent_entries(SITE_ENTRIES_PER_PAGE,0);
-
- //var_dump($data);// exit;
- $this->load->view('header');
- $this->load->view('recallview', $data);
- $this->load->view('footer');*/
- $this->page(0);
- }
-
-
- function view($url) {
+ /**
+ * Lists all recalls held in the database
+ *
+ * @access public
+ */
+ function index()
+ {
+ //this is the first page of results
+ //so call first page
+ $this->page(0);
+ }
-
+ /**
+ * Show the details of a particular recall
+ *
+ * @access public
+ * @param string $url the unique slug of the recall to display
+ */
+ function view($url) {
- $this->load->helper('url_helper');
- $this->load->helper('typography_helper');
- $this->load->helper('date_helper');
- $this->load->model('Recall_model','',TRUE);
- $data['recalls'] = $this->Recall_model->get_recall($url);
-
-
- if (count($data['recalls']) < 1) {
- show_404(current_url());
- } else {
- $page_data['page_title'] = " | ".SITE_NAME;
- if ($data['recalls'][0]['status'] == "removed") { $page_data['page_title'] = " (Removed)".$page_data['page_title']; }
- if ($data['recalls'][0]['status'] == "updated") { $page_data['page_title'] = " (Updated)".$page_data['page_title']; }
- $page_data['page_title'] = $data['recalls'][0]['product_name'].$page_data['page_title'];
- if ($data['recalls'][0]['brand'] != "") { $page_data['page_title'] = $data['recalls'][0]['brand']." ".$page_data['page_title']; }
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $page_data['feeds']= array();
- $page_data['menu'] = 'default';
+ //load the recall
+ $data['recalls'] = $this->Recall_model->get_recall($url);
+
+ //if the recall doesn't exist, display a 404 error
+ if (count($data['recalls']) < 1) {
+ show_404(current_url());
+ } else {
+
+ //load page data
+ $page_data['page_title'] = " | ".SITE_NAME;
+ if ($data['recalls'][0]['status'] == "removed") { $page_data['page_title'] = " (Removed)".$page_data['page_title']; }
+ if ($data['recalls'][0]['status'] == "updated") { $page_data['page_title'] = " (Updated)".$page_data['page_title']; }
+ $page_data['page_title'] = $data['recalls'][0]['product_name'].$page_data['page_title'];
+ if ($data['recalls'][0]['brand'] != "") { $page_data['page_title'] = $data['recalls'][0]['brand']." ".$page_data['page_title']; }
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+ $page_data['feeds']= array();
+ $page_data['menu'] = 'default';
- $this->load->view('header', $page_data);
- $this->load->view('view_recall_item', $data);
- $this->load->view('footer');
- }
-
- }
-
-/* function since($timestamp=0) {
- $this->load->helper('url_helper');
- $this->load->helper('typography_helper');
- $this->load->helper('text_helper');
- $this->load->model('Recall_model','',TRUE);
- $data['recalls'] = $this->Recall_model->get_entries_since($timestamp);
- $page_data['page_title'] = "Recalls List | ".SITE_NAME;
- $this->load->view('header',$page_data);
- $data['links'] = "";
- $this->load->view('recallview', $data);
- $this->load->view('footer');
-
-
- }*/
-
- function page($row=0) {
-
-
-
- $this->load->helper('url_helper');
- $this->load->helper('typography_helper');
- $this->load->helper('text_helper');
- $this->load->model('Recall_model','',TRUE);
+ //load views
+ $this->load->view('header', $page_data);
+ $this->load->view('view_recall_item', $data);
+ $this->load->view('footer');
+ }
+ }
- $this->load->library('pagination');
+ /**
+ * List a particular page of recalls
+ * from the database
+ *
+ * @access public
+ * @param integer $row the row from which to start the display
+ */
+ function page($row=0) {
+
+ //load pagination library
+ $this->load->library('pagination');
- $data['recalls'] = $this->Recall_model->get_recent_entries(SITE_ENTRIES_PER_PAGE,$row);
+ //load recalls from the database
+ $data['recalls'] = $this->Recall_model->get_recent_entries(SITE_ENTRIES_PER_PAGE,$row);
- if (count($data['recalls']) < 1) {
- show_404(current_url());
- } else {
-
- if ($row === 0) {
- $data['pagenum'] = "";
+ //if there are no recalls to display, show a 404 error
+ if (count($data['recalls']) < 1) {
+ show_404(current_url());
} else {
- $pagenum = ($row / SITE_ENTRIES_PER_PAGE)+1;
- $data['pagenum'] = "Page ".$pagenum;
- }
-
- $page_data['page_title'] = "Latest UK Product Recalls ";
- if ( $row > 0 ) { $page_data['page_title'] .= "(Page ".$pagenum.") "; }
- $page_data['page_title'] .= "| ".SITE_NAME;
- $page_data['feeds']= array();
- $page_data['menu'] = 'default';
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $this->load->view('header',$page_data);
- $config['base_url'] = site_url("recall/page/");
- $config['total_rows'] = $this->Recall_model->records();
- $config['per_page'] = SITE_ENTRIES_PER_PAGE;
- $config['num_links'] = 8;
- $this->pagination->initialize($config);
- $data['links'] = $this->pagination->create_links();
- $this->load->view('recallview', $data);
- $this->load->view('footer');
- }
- }
+ //if this is the first page, don't display "Page" on screen'
+ if ($row === 0) {
+ $data['pagenum'] = "";
+ } else {
+ $pagenum = ($row / SITE_ENTRIES_PER_PAGE)+1;
+ $data['pagenum'] = "Page ".$pagenum;
+ }
+
+ //load page data
+ $page_data['page_title'] = "Latest UK Product Recalls ";
+ if ( $row > 0 ) { $page_data['page_title'] .= "(Page ".$pagenum.") "; }
+ $page_data['page_title'] .= "| ".SITE_NAME;
+ $page_data['feeds']= array();
+ $page_data['menu'] = 'default';
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+
+ //load header view
+ $this->load->view('header',$page_data);
+
+ //setup pagination
+ $config['base_url'] = site_url("recall/page/");
+ $config['total_rows'] = $this->Recall_model->records();
+ $config['per_page'] = SITE_ENTRIES_PER_PAGE;
+ $config['num_links'] = 8;
+ $this->pagination->initialize($config);
+ $data['links'] = $this->pagination->create_links();
+
+ //load main view
+ $this->load->view('recallview', $data);
+
+ //load footer view
+ $this->load->view('footer');
+ }
+ }
- /**
- * Searches for a term within the recalls database
- * shows the results on the page
- *
- * @access public
- * @param string $search_string the string to search for
- * @deprecated 0.3 - 9 Jul 2009
- */
- function search($search_string="") {
- $this->load->helper('url_helper');
+ /**
+ * Searches for a term within the recalls database
+ * shows the results on the page
+ *
+ * @access public
+ * @param string $search_string the string to search for
+ * @deprecated 0.3 - 9 Jul 2009
+ */
+ function search($search_string="") {
- redirect(site_url(array('search','all',$search_string)),'location','301');
- exit;
-
- //this code has been depreciated as of 20090709
- //search now handled in search controller
- /*
- $this->load->library('form_validation');
- $this->load->helper('form');
-
- $this->load->helper('typography_helper');
- $this->load->helper('text_helper');
- $this->load->model('Recall_model','',TRUE);
-
- $valid = FALSE;
+ redirect(site_url(array('search','all',$search_string)),'location','301');
+ exit;
- $this->form_validation->set_rules('txtSearch','search','trim|required|xss_clean');
+ //this code has been depreciated as of 20090709
+ //search now handled in search controller
+ /*
+ $this->load->library('form_validation');
+ $this->load->helper('form');
- if ($search_string == "") {
- $search_string = $this->input->post('txtSearch',TRUE);
- $valid = $this->form_validation->run();
- } else {
- $valid = TRUE;
- }
+ $this->load->helper('typography_helper');
+ $this->load->helper('text_helper');
+ $this->load->model('Recall_model','',TRUE);
+
+ $valid = FALSE;
+
+ $this->form_validation->set_rules('txtSearch','search','trim|required|xss_clean');
+
+ if ($search_string == "") {
+ $search_string = $this->input->post('txtSearch',TRUE);
+ $valid = $this->form_validation->run();
+ } else {
+ $valid = TRUE;
+ }
+
+ if (!$valid) {
+ $page_data['page_title'] = "Not a valid search | ".SITE_NAME;
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+ $page_data['feeds'] = array();
+ $page_data['menu'] = 'default';
+ $this->load->view('header',$page_data);
+ $this->load->view('view_recall_search_empty');
+ $this->load->view('footer');
+ } else {
- if (!$valid) {
- $page_data['page_title'] = "Not a valid search | ".SITE_NAME;
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $page_data['feeds'] = array();
- $page_data['menu'] = 'default';
- $this->load->view('header',$page_data);
- $this->load->view('view_recall_search_empty');
- $this->load->view('footer');
- } else {
-
- $data['recalls'] = $this->Recall_model->search_recalls($search_string);
- $data['links'] = "";
- $data['search_string'] = $search_string;
- $data['result_count'] = count($data['recalls']);
-
- $page_data['page_title'] = $data['result_count']." results for search '".$search_string."' | ".SITE_NAME;
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $page_data['feeds'][0]['feed_name']= 'Search results feed for '.$search_string;
- $page_data['feeds'][0]['feed_url']= site_url(array('feed','search',$search_string));
- $page_data['menu'] = 'default';
- $this->load->view('header',$page_data);
- $this->load->view('view_recall_search', $data);
- $this->load->view('footer');
- }*/
- }
+ $data['recalls'] = $this->Recall_model->search_recalls($search_string);
+ $data['links'] = "";
+ $data['search_string'] = $search_string;
+ $data['result_count'] = count($data['recalls']);
+
+ $page_data['page_title'] = $data['result_count']." results for search '".$search_string."' | ".SITE_NAME;
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+ $page_data['feeds'][0]['feed_name']= 'Search results feed for '.$search_string;
+ $page_data['feeds'][0]['feed_url']= site_url(array('feed','search',$search_string));
+ $page_data['menu'] = 'default';
+ $this->load->view('header',$page_data);
+ $this->load->view('view_recall_search', $data);
+ $this->load->view('footer');
+ }*/
+ }
}
-?>
+/* End of file recall.php */
+/* Location: ./system/application/controllers/recall.php */
View
189 system/application/controllers/signup.php
@@ -1,34 +1,65 @@
<?php
+/**
+ * Signup Class
+ *
+ * @package Product Recalls
+ * @subpackage Controllers
+ * @category Signup
+ * @author Consumer Focus Labs
+ * @link http://www.consumerfocuslabs.org
+ */
class Signup extends Controller {
- function Signup() {
- parent::Controller();
- $this->load->model('User_model', '', TRUE);
- $this->load->model('Recall_model', '', TRUE);
-
- }
-
- function index()
- {
+ /**
+ * Constructor
+ *
+ * @access public
+ */
+ function Signup() {
+ //load parent
+ parent::Controller();
+
+ //load in some helpers
+ $this->load->model('User_model', '', TRUE);
$this->load->helper('form');
- $this->load->helper('url');
$this->load->library('form_validation');
$this->load->library('email');
-
- // validate form
+ //TO DO: autoload please!
+ $this->load->helper('url_helper');
+ $this->load->helper('typography_helper');
+ $this->load->helper('date_helper');
+ $this->load->helper('text_helper');
+ $this->load->model('Recall_model','',TRUE);
+ $this->load->model('Category_model','',TRUE);
+ }
+
+ /**
+ * Attempts to process the registration
+ *
+ * @access public
+ */
+ function index() {
+
+ //validate form
$this->form_validation->set_rules('txtEmail','email address','trim|required|valid_email|xss_clean');
$this->form_validation->set_rules('ddlFrequency','frequency','trim|required|alpha|exact_length[1]|xss_clean');
$this->form_validation->set_rules('ddlCat','category','trim|required|numeric|is_natural|xss_clean');
if ($this->form_validation->run() == FALSE) {
//form validation has failed. show the signup form again
+ //set page data
$page_data['page_title'] = "Sign Up | ".SITE_NAME;
$page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
$page_data['feeds']= array();
$page_data['menu'] = 'default';
+
+ //load a list of categories for use in the signup form (name/id)
+ $data['categories'] = $this->Category_model->category_list_dropdown();
+
+ //load views
$this->load->view('header',$page_data);
- $this->load->view('signup/signup.php');
+ $this->load->view('signup/signup.php',$data);
$this->load->view('footer');
}
@@ -38,6 +69,7 @@ function index()
//which interval to use?
$email_frequency = 0;
switch ($this->input->post('ddlFrequency',TRUE)) {
+ //daily is no longer an option
//case "d" :
// $email_frequency=1;
// break;
@@ -77,68 +109,82 @@ function index()
}
- }
-
- function confirm($key) {
-
- $this->load->helper('url');
-
- //validate confirmation key
- $valid = $this->User_model->validate_user($key);
- //if valid
- if ($valid) {
- //activate user
- $this->User_model->activate_user($key);
- //show message
- $page_data['page_title'] = "Your alert has been activated | ".SITE_NAME;
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $page_data['feeds']= array();
- $page_data['menu'] = 'default';
- $this->load->view('header',$page_data);
- $this->load->view('signup/signup_complete.php');
- $this->load->view('footer');
- } else {
- //show invalid key error
- $page_data['page_title'] = "Sign Up - Key not recognised | ".SITE_NAME;
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $page_data['feeds']= array();
- $page_data['menu'] = 'default';
- $this->load->view('header',$page_data);
- $this->load->view('signup/problem.php');
- $this->load->view('footer');
}
+
+ /**
+ * Attempts to confirm the registration attempt
+ *
+ * @access public
+ * @param string $key the unique hashed key for the user
+ */
+ function confirm($key) {
+
+ //validate confirmation key
+ $valid = $this->User_model->validate_user($key);
+
+ //if valid
+ if ($valid) {
+ //activate user
+ $this->User_model->activate_user($key);
+ //show message
+ $page_data['page_title'] = "Your alert has been activated | ".SITE_NAME;
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+ $page_data['feeds']= array();
+ $page_data['menu'] = 'default';
+ $this->load->view('header',$page_data);
+ $this->load->view('signup/signup_complete.php');
+ $this->load->view('footer');
+ } else {
+ //show invalid key error
+ $page_data['page_title'] = "Sign Up - Key not recognised | ".SITE_NAME;
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+ $page_data['feeds']= array();
+ $page_data['menu'] = 'default';
+ $this->load->view('header',$page_data);
+ $this->load->view('signup/problem.php');
+ $this->load->view('footer');
+ }
- }
+ }
- function unsubscribe($key) {
- $this->load->helper('url');
- //validate unsubscribe key
- $valid = $this->User_model->validate_user($key);
+ /**
+ * Attempts to unsubscribe the user from the site
+ *
+ * @access public
+ * @param string $key the unique hashed key for the user
+ */
+ function unsubscribe($key) {
+
+ //validate unsubscribe key
+ $valid = $this->User_model->validate_user($key);
- if ($valid) {
- //if valid, unsubscribe user
- $this->User_model->unsubscribe_user($key);
- //show message
- $page_data['page_title'] = "Your alert has been removed | ".SITE_NAME;
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $page_data['feeds']= array();
- $page_data['menu'] = 'default';
- $this->load->view('header',$page_data);
- $this->load->view('signup/unsubscribe_complete.php');
- $this->load->view('footer');
- } else {
- //show invalid key message
- $page_data['page_title'] = "Unsubscribe - Key not recognised | ".SITE_NAME;
- $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
- $page_data['feeds']= array();
- $page_data['menu'] = 'default';
- $this->load->view('header',$page_data);
- $this->load->view('signup/problem.php');
- $this->load->view('footer');
- }
+ if ($valid) {
+ //if valid, unsubscribe user
+ $this->User_model->unsubscribe_user($key);
+ //show message
+ $page_data['page_title'] = "Your alert has been removed | ".SITE_NAME;
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+ $page_data['feeds']= array();
+ $page_data['menu'] = 'default';
+ $this->load->view('header',$page_data);
+ $this->load->view('signup/unsubscribe_complete.php');
+ $this->load->view('footer');
+ } else {
+ //show invalid key message
+ $page_data['page_title'] = "Unsubscribe - Key not recognised | ".SITE_NAME;
+ $page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
+ $page_data['feeds']= array();
+ $page_data['menu'] = 'default';
+ $this->load->view('header',$page_data);
+ $this->load->view('signup/problem.php');
+ $this->load->view('footer');
+ }
- }
+ }
+ /*
+ A FUNCTION FOR CHECKING TO SEE IF AN EMAIL ADDRESS IS ALREADY REGISTERED IN THE DATABASE
+ AT PRESENT, IT IS NOT REQUIRED
function email_check($str) {
if ($this->User_model->user_active($str) == true) {
$this->form_validation->set_message('email_check','The %s you entered is already registered');
@@ -147,10 +193,11 @@ function email_check($str) {
else {
return TRUE;
}
- }
+ }*/
}
-?>
+/* End of file signup.php */
+/* Location: ./system/application/controllers/signup.php */
View
3 system/application/controllers/user.php
@@ -13,4 +13,5 @@ function index()
}
}
-?>
+/* End of file user.php */
+/* Location: ./system/application/controllers/user.php */
View
47 system/application/controllers/welcome.php
@@ -1,31 +1,60 @@
<?php
-
+/**
+ * Welcome Class
+ *
+ * @package Product Recalls
+ * @subpackage Controllers
+ * @category Welcome
+ * @author Consumer Focus Labs
+ * @link http://www.consumerfocuslabs.org
+ */
class Welcome extends Controller {
+ /**
+ * Constructor
+ *
+ * @access public
+ */
function Welcome()
{
- parent::Controller();
+ //load parent
+ parent::Controller();
+
+ //load in some helpers
+ $this->load->helper('form_helper');
+ //TO DO: autoload please!
+ $this->load->helper('url_helper');
+ $this->load->helper('typography_helper');
+ $this->load->helper('date_helper');
+ $this->load->helper('text_helper');
+ $this->load->model('Recall_model','',TRUE);
+ $this->load->model('Category_model','',TRUE);
}
+ /**
+ * Show the homepage
+ *
+ * @access public
+ */
function index()
{
+ //if the cache is turned on, then cache the homepage
if ( WWW_CACHE_ACTIVE ) {
$this->output->cache(WWW_CACHE);
}
- $this->load->helper('url_helper');
- $this->load->helper('text_helper');
- $this->load->helper('form_helper');
- $this->load->helper('typography_helper');
- $this->load->model('Recall_model','',TRUE);
- $this->load->model('Category_model','',TRUE);
+
+ //load the most recent recalls from the database
$data['recalls'] = $this->Recall_model->get_recent_entries(5);
+ //load a list of categories for use in the signup form (name/id)
$data['categories'] = $this->Category_model->category_list_dropdown();
+ //load a list of categories for use in the search form (name/slug)
$data['categories_slug'] = $this->Category_model->category_list_dropdown_slug();
-
+ //load page data
$page_data['recent_recalls'] = $this->Recall_model->num_recent_recalls();
$page_data['page_title'] = "Welcome to ".SITE_NAME." (BETA) - ".SITE_TAGLINE;
$page_data['feeds']= array();
$page_data['menu'] = 'default';
+ //display views
$this->load->view('header',$page_data);
$this->load->view('welcome_message',$data);
$this->load->view('footer');
View
4 system/application/helpers/slug_helper.php
@@ -43,5 +43,5 @@ function produce_slug($text,$split_character) {
}
-/* End of file scraping_helper.php */
-/* Location: ./system/helpers/scraping_helper.php */
+/* End of file slug_helper.php */
+/* Location: ./system/helpers/slug_helper.php */
View
84 system/application/models/user_model.php
@@ -1,20 +1,47 @@
<?php
-
+/**
+ * User Model
+ *
+ * @package Product Recalls
+ * @subpackage Models
+ * @category User
+ * @author Consumer Focus Labs
+ * @link http://www.consumerfocuslabs.org
+ */
class User_model extends Model {
-
+ /**
+ * Constructor
+ *
+ * @access public
+ */
function User_model()
{
+ //load parent
parent::Model();
}
+ /**
+ * Gets a list of users which need to be sent an updated
+ * list of recalls
+ *
+ * @access public
+ * @return array of users
+ */
function get_email_list()
{
$query = $this->db->query('(SELECT users.*, confirmations.user_key FROM users INNER JOIN confirmations on users.id=confirmations.parent_id WHERE confirmations.parent_table="users" AND users.live=1 AND users.frequency=2 AND date_last_sent<DATE_SUB(now(),INTERVAL 1 WEEK)) UNION (SELECT users.*, confirmations.user_key FROM users INNER JOIN confirmations on users.id=confirmations.parent_id WHERE confirmations.parent_table="users" AND users.live=1 AND users.frequency=3 AND date_last_sent<DATE_SUB(now(),INTERVAL 1 MONTH))');
return $query->result_array();
}
+ /**
+ * Returns whether a user is active or inactive
+ *
+ * @access public
+ * @param string $email the email address of the user to check
+ * @return boolean true if active, false if inactive
+ */
function user_active($email) {
$this->db->select('users.id');
@@ -30,8 +57,18 @@ function user_active($email) {
}
+ /**
+ * Creates a new user in the database
+ *
+ * @access public
+ * @param string $email the email of the user to create
+ * @param integer $frequency the frequency with which to send emails (1=daily,2=weekly,3=monthly)
+ * @param integer $category the id of the category of recalls to send (0=all)
+ * @return string a unique text key to idenfity the user
+ */
function create_user($email,$frequency,$category) {
+ //create data array & add to database
$data = array(
'email' => $email,
'frequency' => $frequency,
@@ -41,21 +78,30 @@ function create_user($email,$frequency,$category) {
);
$this->db->insert('users',$data);
+ //get id of user
$user_id = $this->db->insert_id();
+ //create unique hash for this user
$user_key = hash('md5',$email.date("YmdHis"));
+ //create activation record in database
$data = array(
'parent_table' => 'users',
'parent_id' => $user_id,
'user_key' => $user_key
);
$this->db->insert('confirmations',$data);
-
+ //return key
return $user_key;
-
-
+
}
+ /**
+ * Confirms whether a unique key corresponds to a valid user
+ *
+ * @access public
+ * @param string $key the unique key to validate
+ * @return boolean whether key is valid or not
+ */
function validate_user($key) {
$this->db->select('users.id');
@@ -67,20 +113,29 @@ function validate_user($key) {
}
+ /**
+ * Attempts to activate a user to begin sending them messages
+ *
+ * @access public
+ * @param string $key the unique key of the user to activate
+ */
function activate_user($key) {
-
+ //set live to true
$data = array(
'live' => TRUE
);
$where = "users.id=(SELECT confirmations.parent_id FROM confirmations WHERE confirmations.parent_table='users' AND confirmations.user_key='".$key."')";
$this->db->where($where);
$this->db->update('users',$data);
- //UPDATE users
- //SET users.live=1
- //WHERE users.id = (SELECT confirmations.parent_id FROM confirmations WHERE confirmations.parent_table='users' AND confirmations.user_key='46c9b7a3c5f3e998b280c10d0a69ebe1')
-
+
}
+ /**
+ * Attempts to unsubscribe a user to stop sending them messages
+ *
+ * @access public
+ * @param string $key the unique key of the user to unsubscribe
+ */
function unsubscribe_user($key) {
$data = array(
@@ -92,6 +147,12 @@ function unsubscribe_user($key) {
}
+ /**
+ * Updates the last sent date of a user
+ *
+ * @access public
+ * @param integer $user the id number of the user to update
+ */
function update_user_sent_date($user) {
$data = array('date_last_sent'=>date('Y-m-d H:i:s'));
@@ -102,4 +163,5 @@ function update_user_sent_date($user) {
}
-?>
+/* End of file recall_model.php */
+/* Location: ./system/application/models/recall_model.php */
View
2 system/application/views/categories/categories_list.php
@@ -1,6 +1,6 @@
<div id="divContent">
<div class="divContainer">
- <h3>Recall Categories</h3>
+ <h3>Browse product recalls by category</h3>
<table width="100%" cellspacing="0" border="0">
<thead>
View
2 system/application/views/header.php
@@ -23,7 +23,7 @@
<li class="recentUpdates"><?php echo $recent_recalls; ?> updates this month</li>
<li <?php if ($menu == 'feedback') :?>class="active"<?php endif; ?>><a href="<?php echo site_url("about/feedback");?>" title="Send us your feedback">Feedback</a></li>
<li <?php if ($menu == 'about') :?>class="active"<?php endif; ?>><a href="<?php echo site_url("about");?>" title="About <?php echo SITE_NAME ?>">About</a></li>
- <li <?php if ($menu == 'categories') :?>class="active"<?php endif; ?>><a href="<?php echo site_url("categories");?>" title="View recall categories">Categories</a></li>
+ <li <?php if ($menu == 'categories') :?>class="active"<?php endif; ?>><a href="<?php echo site_url("browse");?>" title="View recall categories">Browse</a></li>
<li <?php if ($menu == 'default') :?>class="active"<?php endif; ?>><a href="<?php echo site_url("");?>" title="Signup for email alerts and search the database">Signup &amp; Search</a></li>
</ul>
<br class="clear" />
View
6 system/application/views/signup/signup.php
@@ -10,6 +10,12 @@
<input id="txtEmail" name="txtEmail" type="text" class="textbox" value="<?php echo set_value('txtEmail'); ?>" /><br class="clear" />
</li>
<li>
+ <label for="ddlCat">Which category?</label>
+ <? $catdropdown = 'class="large"';?>
+ <?php echo form_dropdown('ddlCat',$categories,array(),$catdropdown); ?>
+ <br class="clear" />
+ </li>
+ <li>
<label for="ddlFrequency">How often?</label>
<select id="ddlFrequency" name="ddlFrequency" class="small">
<option value="w" <?php echo set_select('ddlFrequency', 'w', TRUE); ?> >Weekly</option>
View
14 system/application/views/view_recall_item.php
@@ -23,17 +23,9 @@
</div>
<?php endif; ?>
-<!-- AddThis Button BEGIN -->
-<div class="addthis_toolbox addthis_default_style" style="width:200px;float:right;padding-top:30px;">
-<a href="http://www.addthis.com/bookmark.php?v=250&pub=xa-4a5370fb4218dcc3" class="addthis_button_compact">Share</a>
-<span class="addthis_separator">|</span>
-<a class="addthis_button_facebook"></a>
-<a class="addthis_button_myspace"></a>
-<a class="addthis_button_google"></a>
-<a class="addthis_button_twitter"></a>
-</div>
-<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a5370fb4218dcc3"></script>
-<!-- AddThis Button END -->
+<!-- ShareThis Button BEGIN -->
+<div style="width:150px; float: right; padding-top: 30px;"><script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#publisher=c1c9b7ca-2eef-40d3-beac-bab0387dec1a&amp;type=website&amp;buttonText=Share%20This%20Recall"></script></div>
+<!-- ShareThis Button END -->
<p><strong>Source:</strong> <a href="<?php echo $recall['external_url']; ?>" title="View original source for <?php echo $recall['product_name'];?> recall"><?php echo $recall['source_name']; ?> (<?php echo $recall['source_id']; ?>)</a>

0 comments on commit 220206b

Please sign in to comment.
Something went wrong with that request. Please try again.