[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: datahandler.php 5297 2010-12-28 22:01:14Z Tomm $ 10 */ 11 12 /** 13 * Base data handler class. 14 * 15 */ 16 class DataHandler 17 { 18 /** 19 * The data being managed by the data handler 20 * 21 * @var array Data being handled by the data handler. 22 */ 23 public $data = array(); 24 25 /** 26 * Whether or not the data has been validated. Note: "validated" != "valid". 27 * 28 * @var boolean True when validated, false when not validated. 29 */ 30 public $is_validated = false; 31 32 /** 33 * The errors that occurred when handling data. 34 * 35 * @var array 36 */ 37 public $errors = array(); 38 39 /** 40 * The status of administrator override powers. 41 * 42 * @var boolean 43 */ 44 public $admin_override = false; 45 46 /** 47 * Defines if we're performing an update or an insert. 48 * 49 * @var string 50 */ 51 public $method; 52 53 /** 54 * The prefix for the language variables used in the data handler. 55 * 56 * @var string 57 */ 58 public $language_prefix = ''; 59 60 61 /** 62 * Constructor for the data handler. 63 * 64 * @param string The method we're performing with this object. 65 */ 66 function __construct($method="insert") 67 { 68 if($method != "update" && $method != "insert") 69 { 70 die("A valid method was not supplied to the data handler."); 71 } 72 $this->method = $method; 73 } 74 75 /** 76 * Sets the data to be used for the data handler 77 * 78 * @param array The data. 79 */ 80 function set_data($data) 81 { 82 if(!is_array($data)) 83 { 84 return false; 85 } 86 $this->data = $data; 87 return true; 88 } 89 90 /** 91 * Add an error to the error array. 92 * 93 * @param string The error name. 94 */ 95 function set_error($error, $data='') 96 { 97 $this->errors[$error] = array( 98 "error_code" => $error, 99 "data" => $data 100 ); 101 } 102 103 /** 104 * Returns the error(s) that occurred when handling data. 105 * 106 * @return string|array An array of errors. 107 */ 108 function get_errors() 109 { 110 return $this->errors; 111 } 112 113 /** 114 * Returns the error(s) that occurred when handling data 115 * in a format that MyBB can handle. 116 * 117 * @return An array of errors in a MyBB format. 118 */ 119 function get_friendly_errors() 120 { 121 global $lang; 122 123 // Load the language pack we need 124 if($this->language_file) 125 { 126 $lang->load($this->language_file, true); 127 } 128 // Prefix all the error codes with the language prefix. 129 foreach($this->errors as $error) 130 { 131 $lang_string = $this->language_prefix.'_'.$error['error_code']; 132 if(!$lang->$lang_string) 133 { 134 $errors[] = $error['error_code']; 135 continue; 136 } 137 138 if(!empty($error['data']) && !is_array($error['data'])) 139 { 140 $error['data'] = array($error['data']); 141 } 142 143 if(is_array($error['data'])) 144 { 145 array_unshift($error['data'], $lang->$lang_string); 146 $errors[] = call_user_func_array(array($lang, "sprintf"), $error['data']); 147 } 148 else 149 { 150 $errors[] = $lang->$lang_string; 151 } 152 } 153 return $errors; 154 } 155 156 /** 157 * Sets whether or not we are done validating. 158 * 159 * @param boolean True when done, false when not done. 160 */ 161 function set_validated($validated = true) 162 { 163 $this->is_validated = $validated; 164 } 165 166 /** 167 * Returns whether or not we are done validating. 168 * 169 * @return boolean True when done, false when not done. 170 */ 171 function get_validated() 172 { 173 if($this->is_validated == true) 174 { 175 return true; 176 } 177 else 178 { 179 return false; 180 } 181 } 182 183 /** 184 * Verifies if yes/no options haven't been modified. 185 * 186 * @param array The user options array. 187 * @param string The specific option to check. 188 * @param string Optionally specify if the default should be used. 189 */ 190 function verify_yesno_option(&$options, $option, $default=1) 191 { 192 if($this->method == "insert" || array_key_exists($option, $options)) 193 { 194 if($options[$option] != $default && $options[$option] != "") 195 { 196 if($default == 1) 197 { 198 $options[$option] = 0; 199 } 200 else 201 { 202 $options[$option] = 1; 203 } 204 } 205 else if(@array_key_exists($option, $options) && $options[$option] == '') 206 { 207 $options[$option] = 0; 208 } 209 else 210 { 211 $options[$option] = $default; 212 } 213 } 214 } 215 } 216 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |