Annotation of /trunk/lib/ecard.class.php
Parent Directory
|
Revision Log
Revision 2 - (view) (download)
| 1 : | andphe | 2 | <?php |
| 2 : | //zOOm Media Gallery// | ||
| 3 : | /** | ||
| 4 : | ----------------------------------------------------------------------- | ||
| 5 : | | zOOm Media Gallery! by Mike de Boer - a multi-gallery component | | ||
| 6 : | ----------------------------------------------------------------------- | ||
| 7 : | |||
| 8 : | ----------------------------------------------------------------------- | ||
| 9 : | | | | ||
| 10 : | | Author: Mike de Boer, <http://www.mikedeboer.nl> | | ||
| 11 : | | Copyright: copyright (C) 2007 by Mike de Boer | | ||
| 12 : | | Description: zOOm Media Gallery, a multi-gallery component for | | ||
| 13 : | | Joomla!. It's the most feature-rich gallery component | | ||
| 14 : | | for Joomla!! For documentation and a detailed list | | ||
| 15 : | | of features, check the zOOm homepage: | | ||
| 16 : | | http://www.zoomfactory.org | | ||
| 17 : | | License: GPL | | ||
| 18 : | | Filename: ecard.class.php | | ||
| 19 : | | | | ||
| 20 : | ----------------------------------------------------------------------- | ||
| 21 : | * @version $Id:ecard.class.php 106 2007-02-10 22:30:30Z kevinuru $ | ||
| 22 : | * @package zOOmGallery | ||
| 23 : | * @author Mike de Boer <mailme@mikedeboer.nl> | ||
| 24 : | **/ | ||
| 25 : | // MOS Intruder Alerts | ||
| 26 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 27 : | |||
| 28 : | /** | ||
| 29 : | * Ecard class; creates an instance of an ecard and contains functions for | ||
| 30 : | * ecard registration and sending. | ||
| 31 : | * | ||
| 32 : | * @access public | ||
| 33 : | */ | ||
| 34 : | class ecard extends image { | ||
| 35 : | /** | ||
| 36 : | * @var datetime | ||
| 37 : | * @access private | ||
| 38 : | */ | ||
| 39 : | var $_id = null; | ||
| 40 : | /** | ||
| 41 : | * @var image | ||
| 42 : | * @access private | ||
| 43 : | */ | ||
| 44 : | var $_image = null; | ||
| 45 : | /** | ||
| 46 : | * @var string | ||
| 47 : | * @access private | ||
| 48 : | */ | ||
| 49 : | var $_to_name = null; | ||
| 50 : | /** | ||
| 51 : | * @var string | ||
| 52 : | * @access private | ||
| 53 : | */ | ||
| 54 : | var $_from_name = null; | ||
| 55 : | /** | ||
| 56 : | * @var string | ||
| 57 : | * @access private | ||
| 58 : | */ | ||
| 59 : | var $_to_email = null; | ||
| 60 : | /** | ||
| 61 : | * @var string | ||
| 62 : | * @access private | ||
| 63 : | */ | ||
| 64 : | var $_from_email = null; | ||
| 65 : | /** | ||
| 66 : | * @var string | ||
| 67 : | * @access private | ||
| 68 : | */ | ||
| 69 : | var $_message = null; | ||
| 70 : | /** | ||
| 71 : | * @var datetime | ||
| 72 : | * @access private | ||
| 73 : | */ | ||
| 74 : | var $_end_date = null; | ||
| 75 : | /** | ||
| 76 : | * @var string | ||
| 77 : | * @access private | ||
| 78 : | */ | ||
| 79 : | var $_user_ip = null; | ||
| 80 : | //--------------------Default Constructor of the ecard-class------------// | ||
| 81 : | /** | ||
| 82 : | * Ecard object constructor | ||
| 83 : | * | ||
| 84 : | * @param int $id | ||
| 85 : | * @return ecard | ||
| 86 : | * @access public | ||
| 87 : | */ | ||
| 88 : | function ecard($id = 0) { | ||
| 89 : | $this->_user_ip = getenv('REMOTE_ADDR'); | ||
| 90 : | if($id === 0) { | ||
| 91 : | $this->_id = date("U").rand(100, 500); | ||
| 92 : | } else { | ||
| 93 : | $this->_id = zoom::escapeString($id); | ||
| 94 : | $this->getInfo(); | ||
| 95 : | } | ||
| 96 : | } | ||
| 97 : | /** | ||
| 98 : | * Retrieves data from the 'mos_zoom_ecards' table and assigns it to | ||
| 99 : | * the class variables... | ||
| 100 : | * | ||
| 101 : | * @return boolean | ||
| 102 : | * @access public | ||
| 103 : | */ | ||
| 104 : | function getInfo() { | ||
| 105 : | global $database; | ||
| 106 : | $database->setQuery("SELECT * FROM #__zoom_ecards WHERE ecdid = ".$this->_id." LIMIT 1"); | ||
| 107 : | $result = $database->query(); | ||
| 108 : | if (mysql_num_rows($result) > 0) { | ||
| 109 : | while($row = mysql_fetch_object($result)){ | ||
| 110 : | $this->_image = new image($row->imgid); | ||
| 111 : | $this->_to_name = $row->to_name; | ||
| 112 : | $this->_from_name = $row->from_name; | ||
| 113 : | $this->_to_email = $row->to_email; | ||
| 114 : | $this->_from_email = $row->from_email; | ||
| 115 : | $this->_message = $row->message; | ||
| 116 : | $this->_end_date = $row->end_date; | ||
| 117 : | $this->_user_ip = $row->user_ip; | ||
| 118 : | } | ||
| 119 : | return true; | ||
| 120 : | } else { | ||
| 121 : | return false; | ||
| 122 : | } | ||
| 123 : | } | ||
| 124 : | /** | ||
| 125 : | * Save a newly entered eCard into the database... | ||
| 126 : | * | ||
| 127 : | * @param int $imgid | ||
| 128 : | * @param string $to_name | ||
| 129 : | * @param string $from_name | ||
| 130 : | * @param string $to_email | ||
| 131 : | * @param string $from_email | ||
| 132 : | * @param string $message | ||
| 133 : | * @return boolean | ||
| 134 : | * @access public | ||
| 135 : | */ | ||
| 136 : | function save($imgid, $to_name, $from_name, $to_email, $from_email, $message) { | ||
| 137 : | global $database, $zoom; | ||
| 138 : | $this->_image = $imgid; | ||
| 139 : | $this->_to_name = trim($zoom->escapeString($to_name)); | ||
| 140 : | $this->_from_name = trim($zoom->escapeString($from_name)); | ||
| 141 : | $this->_to_email = trim($zoom->escapeString($to_email)); | ||
| 142 : | $this->_from_email = trim($zoom->escapeString($from_email)); | ||
| 143 : | $this->_message = trim($zoom->escapeString($message)); | ||
| 144 : | // construct the end-date for this eCard... | ||
| 145 : | $lifetime = $zoom->_CONFIG['ecards_lifetime']; | ||
| 146 : | $tempDate = date('Y-m-d'); | ||
| 147 : | $date_arr = explode("-", $tempDate); | ||
| 148 : | if ($lifetime == 7 || $lifetime == 14) { | ||
| 149 : | // 7 means seven days, or a WEEK; 14 means fourteen days, or TWO WEEKS | ||
| 150 : | list( $date_arr[2], $date_arr[1], $date_arr[0] ) = $this->addDays( $date_arr[2], $date_arr[1], $date_arr[0], $lifetime ); | ||
| 151 : | } elseif ($lifetime == 1 || $lifetime == 3) { | ||
| 152 : | // 1 means ONE MONTH; 3 means THREE MONTHS | ||
| 153 : | for($i = 1; $i <= $lifetime; $i++) { | ||
| 154 : | $date_arr[1]++; | ||
| 155 : | if(!checkdate($date_arr[1], $date_arr[2], $date_arr[0])){ | ||
| 156 : | $date_arr[0]++; //add one year | ||
| 157 : | $date_arr[1] = 1; //set no. of months to one (new year!) | ||
| 158 : | } | ||
| 159 : | } | ||
| 160 : | } else { | ||
| 161 : | return false; | ||
| 162 : | } | ||
| 163 : | for ($i = 0; $i < count($date_arr); $i++) { | ||
| 164 : | if (strlen($date_arr[$i]) == 1) { | ||
| 165 : | $date_arr[$i] = "0".$date_arr[$i]; | ||
| 166 : | } | ||
| 167 : | } | ||
| 168 : | ksort($date_arr); | ||
| 169 : | $this->_end_date = implode("-", $date_arr); | ||
| 170 : | $database->setQuery("INSERT INTO #__zoom_ecards " | ||
| 171 : | . "SET ecdid='".$this->_id."',imgid='".$this->_image."', to_name='".$this->_to_name."',from_name='".$this->_from_name."'," | ||
| 172 : | . "to_email='".$this->_to_email."',from_email='".$this->_from_email."',message='".$this->_message."'," | ||
| 173 : | . "end_date='".$this->_end_date."', user_ip='".$this->_user_ip."'"); | ||
| 174 : | if ($database->query()) { | ||
| 175 : | return true; | ||
| 176 : | } else { | ||
| 177 : | return false; | ||
| 178 : | } | ||
| 179 : | } | ||
| 180 : | /** | ||
| 181 : | * Send the ecard(-link) to the friend the user entered. | ||
| 182 : | * | ||
| 183 : | * @return boolean | ||
| 184 : | * @access public | ||
| 185 : | */ | ||
| 186 : | function send() { | ||
| 187 : | global $mosConfig_live_site, $mosConfig_host, $Itemid, $_SERVER; | ||
| 188 : | $messageUrl = sefRelToAbs($mosConfig_live_site."/index.php?option=com_zoom&Itemid=".$Itemid."&page=ecard&task=viewcard&ecdid=".$this->_id); | ||
| 189 : | $subject = _ZOOM_ECARD_SUBJ." ".$this->_from_name; | ||
| 190 : | |||
| 191 : | $msg = "$this->_to_name,\n\n"; | ||
| 192 : | $msg .= $this->_from_name." "._ZOOM_ECARD_MSG1." ".$mosConfig_live_site."\n\n"; | ||
| 193 : | $msg .= html_entity_decode(_ZOOM_ECARD_MSG2)."\n\n"; | ||
| 194 : | $msg .= "URL: $messageUrl\n\n"; | ||
| 195 : | $msg .= html_entity_decode(_ZOOM_ECARD_MSG3)."\n"; | ||
| 196 : | $msg .= "\n\n\n\n\n"; | ||
| 197 : | $msg .= "------------------------------------------------------------------------------------------------------------------\n"; | ||
| 198 : | $msg .= "| zOOm Media Gallery! - a multi-gallery component\n"; | ||
| 199 : | $msg .= "| copyright (C) 2004-2006 by Mike de Boer, http://www.zoomfactory.org\n"; | ||
| 200 : | $msg .= "------------------------------------------------------------------------------------------------------------------"; | ||
| 201 : | |||
| 202 : | $from = $mosConfig_live_site; | ||
| 203 : | if (mosMail($this->_from_email, $this->_from_name, $this->_to_email, $subject, $msg)){ | ||
| 204 : | return true; | ||
| 205 : | } else { | ||
| 206 : | return false; | ||
| 207 : | } | ||
| 208 : | } | ||
| 209 : | /** | ||
| 210 : | * Get the ecdid of an ecard. | ||
| 211 : | * | ||
| 212 : | * @return int | ||
| 213 : | * @access public | ||
| 214 : | */ | ||
| 215 : | function getId() { | ||
| 216 : | return $this->_id; | ||
| 217 : | } | ||
| 218 : | /** | ||
| 219 : | * Get the name of the sender OR receiver of an ecard. | ||
| 220 : | * | ||
| 221 : | * @param string $which | ||
| 222 : | * @return string | ||
| 223 : | * @access public | ||
| 224 : | */ | ||
| 225 : | function getName( $which = "to" ) { | ||
| 226 : | if ($which == "to") { | ||
| 227 : | return $this->_to_name; | ||
| 228 : | } elseif ($which == "from") { | ||
| 229 : | return $this->_from_name; | ||
| 230 : | } | ||
| 231 : | } | ||
| 232 : | /** | ||
| 233 : | * Get the email address of the sender OR receiver of an ecard. | ||
| 234 : | * | ||
| 235 : | * @param string $which | ||
| 236 : | * @return string | ||
| 237 : | * @access public | ||
| 238 : | */ | ||
| 239 : | function getEmail( $which = "to" ) { | ||
| 240 : | if ($which == "to") { | ||
| 241 : | return $this->_to_email; | ||
| 242 : | } elseif ($which == "from") { | ||
| 243 : | return $this->_from_email; | ||
| 244 : | } | ||
| 245 : | } | ||
| 246 : | /** | ||
| 247 : | * Get the message of an ecard. | ||
| 248 : | * | ||
| 249 : | * @return string | ||
| 250 : | * @access public | ||
| 251 : | */ | ||
| 252 : | function getMessage() { | ||
| 253 : | return $this->_message; | ||
| 254 : | } | ||
| 255 : | /** | ||
| 256 : | * Add a number of days to a distant epoch to a give date. | ||
| 257 : | * | ||
| 258 : | * @param int $day in format DD | ||
| 259 : | * @param int $month in format MM | ||
| 260 : | * @param int $year in format CCYY | ||
| 261 : | * @param string format for returned date | ||
| 262 : | */ | ||
| 263 : | function addDays ( $day, $month, $year, $n ) { | ||
| 264 : | $days = $this->toDays($day, $month, $year); | ||
| 265 : | return $this->fromDays($days + $n); | ||
| 266 : | } | ||
| 267 : | /** | ||
| 268 : | * Converts a date to number of days since a | ||
| 269 : | * distant unspecified epoch. | ||
| 270 : | * | ||
| 271 : | * !!Based on PEAR library function!! | ||
| 272 : | * @param int $day in format DD | ||
| 273 : | * @param int $month in format MM | ||
| 274 : | * @param int $year in format CCYY | ||
| 275 : | * @return integer number of days | ||
| 276 : | */ | ||
| 277 : | function toDays( $day=0, $month=0, $year=0) { | ||
| 278 : | if (!$day) { | ||
| 279 : | $day = intval( date( "d" ) ); | ||
| 280 : | } | ||
| 281 : | if (!$month) { | ||
| 282 : | $month = intval( date( "m" ) ); | ||
| 283 : | } | ||
| 284 : | if (!$year) { | ||
| 285 : | $year = intval( date( "Y" ) ); | ||
| 286 : | } | ||
| 287 : | |||
| 288 : | $century = floor( $year / 100 ); | ||
| 289 : | $year = $year % 100; | ||
| 290 : | |||
| 291 : | if($month > 2) { | ||
| 292 : | $month -= 3; | ||
| 293 : | } else { | ||
| 294 : | $month += 9; | ||
| 295 : | if ($year) { | ||
| 296 : | $year--; | ||
| 297 : | } else { | ||
| 298 : | $year = 99; | ||
| 299 : | $century --; | ||
| 300 : | } | ||
| 301 : | } | ||
| 302 : | |||
| 303 : | return ( floor( (146097 * $century) / 4 ) + | ||
| 304 : | floor( (1461 * $year) / 4 ) + | ||
| 305 : | floor( (153 * $month + 2) / 5 ) + | ||
| 306 : | $day + 1721119); | ||
| 307 : | } | ||
| 308 : | /** | ||
| 309 : | * Converts number of days to a distant unspecified epoch. | ||
| 310 : | * | ||
| 311 : | * !!Based on PEAR library function!! | ||
| 312 : | * @param int $days number of days | ||
| 313 : | * @param string format for returned date | ||
| 314 : | */ | ||
| 315 : | function fromDays( $days ) { | ||
| 316 : | $days -= 1721119; | ||
| 317 : | $century = floor( ( 4 * $days - 1) / 146097 ); | ||
| 318 : | $days = floor( 4 * $days - 1 - 146097 * $century ); | ||
| 319 : | $day = floor( $days / 4 ); | ||
| 320 : | |||
| 321 : | $year = floor( ( 4 * $day + 3) / 1461 ); | ||
| 322 : | $day = floor( 4 * $day + 3 - 1461 * $year ); | ||
| 323 : | $day = floor( ($day + 4) / 4 ); | ||
| 324 : | |||
| 325 : | $month = floor( ( 5 * $day - 3) / 153 ); | ||
| 326 : | $day = floor( 5 * $day - 3 - 153 * $month ); | ||
| 327 : | $day = floor( ($day + 5) / 5 ); | ||
| 328 : | |||
| 329 : | if ($month < 10) { | ||
| 330 : | $month +=3; | ||
| 331 : | } else { | ||
| 332 : | $month -=9; | ||
| 333 : | if ($year++ == 99) { | ||
| 334 : | $year = 0; | ||
| 335 : | $century++; | ||
| 336 : | } | ||
| 337 : | } | ||
| 338 : | return array( $day, $month, ($century*100 + $year) ); | ||
| 339 : | } | ||
| 340 : | } | ||
| 341 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

