Annotation of /trunk/lib/editmon.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: editmon.class.php | | ||
| 19 : | | | | ||
| 20 : | ----------------------------------------------------------------------- | ||
| 21 : | * @version $Id:editmon.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 : | * EditMon class; the zOOm Edit Monitor, which keeps track of user actions like | ||
| 30 : | * commenting / rating of a medium, sending eCards and creating lightboxes. | ||
| 31 : | * | ||
| 32 : | * @access public | ||
| 33 : | */ | ||
| 34 : | class editmon extends zoom { | ||
| 35 : | /** | ||
| 36 : | * @var int | ||
| 37 : | * @access private | ||
| 38 : | */ | ||
| 39 : | var $_lifetime = null; | ||
| 40 : | /** | ||
| 41 : | * @var string | ||
| 42 : | * @access private | ||
| 43 : | */ | ||
| 44 : | var $_session_id = null; | ||
| 45 : | /** | ||
| 46 : | * Editmon object contructor. | ||
| 47 : | * | ||
| 48 : | * @return editmon | ||
| 49 : | * @access public | ||
| 50 : | */ | ||
| 51 : | function editmon() { | ||
| 52 : | global $mosConfig_lifetime, $mainframe, $_SESSION, $session; | ||
| 53 : | $this->_lifetime = $mosConfig_lifetime; | ||
| 54 : | if(is_callable(array('mosMainframe', 'sessionCookieName'))) { | ||
| 55 : | // Session Cookie `name` | ||
| 56 : | $sessionCookieName = mosMainFrame::sessionCookieName(); | ||
| 57 : | // Get Session Cookie `value` | ||
| 58 : | $sessioncookie = mosGetParam( $_COOKIE, $sessionCookieName, null ); | ||
| 59 : | // Session ID / `value` | ||
| 60 : | $sessionValueCheck = mosMainFrame::sessionCookieValue( $sessioncookie ); | ||
| 61 : | $this->_session_id = $sessionValueCheck; | ||
| 62 : | } else { | ||
| 63 : | if (isset($mainframe) && is_object($session)) { | ||
| 64 : | $this->_session_id = $session->session_id; | ||
| 65 : | } else if (isset($_COOKIE['sessioncookie'])) { | ||
| 66 : | $sessioncookie = $_COOKIE['sessioncookie']; | ||
| 67 : | $this->_session_id = md5($sessioncookie.$_SERVER['REMOTE_ADDR']); | ||
| 68 : | } | ||
| 69 : | } | ||
| 70 : | } | ||
| 71 : | /** | ||
| 72 : | * Register that a user has performed an action which may not be repeated | ||
| 73 : | * (specified by the admin). | ||
| 74 : | * | ||
| 75 : | * @param int $id | ||
| 76 : | * @param string $which | ||
| 77 : | * @param string $filename | ||
| 78 : | * @return boolean | ||
| 79 : | * @access public | ||
| 80 : | */ | ||
| 81 : | function setEditMon($id, $which, $filename='') { | ||
| 82 : | global $database; | ||
| 83 : | $today = time() + intval($this->_lifetime); | ||
| 84 : | $sid = md5($this->_session_id); | ||
| 85 : | if (!$this->isEdited($id, $which, $filename)) { | ||
| 86 : | switch ($which){ | ||
| 87 : | case 'comment': | ||
| 88 : | $database->setQuery("INSERT INTO #__zoom_editmon (user_session,comment_time,object_id) VALUES ('$sid','$today','".$this->escapeString($id)."')"); | ||
| 89 : | break; | ||
| 90 : | case 'vote': | ||
| 91 : | $database->setQuery("INSERT INTO #__zoom_editmon (user_session,vote_time,object_id) VALUES ('$sid','$today','".$this->escapeString($id)."')"); | ||
| 92 : | break; | ||
| 93 : | case 'pass': | ||
| 94 : | $database->setQuery("INSERT INTO #__zoom_editmon (user_session,pass_time,object_id) VALUES ('$sid','$today','".$this->escapeString($id)."')"); | ||
| 95 : | break; | ||
| 96 : | case 'lightbox': | ||
| 97 : | $database->setQuery("INSERT INTO #__zoom_editmon (user_session,lightbox_time,lightbox_file) VALUES ('$sid','$today','".$this->escapeString($filename)."')"); | ||
| 98 : | break; | ||
| 99 : | } | ||
| 100 : | if (@$database->query()) { | ||
| 101 : | return true; | ||
| 102 : | } else { | ||
| 103 : | return false; | ||
| 104 : | } | ||
| 105 : | } | ||
| 106 : | } | ||
| 107 : | /** | ||
| 108 : | * Delete rows of the 'mos_zoom_editmon' table which are out-of-date. | ||
| 109 : | * | ||
| 110 : | * @return void | ||
| 111 : | * @access public | ||
| 112 : | */ | ||
| 113 : | function updateEditMon() { | ||
| 114 : | global $database; | ||
| 115 : | $now = time(); | ||
| 116 : | // first, delete rows containing vote, commment and gallery-pass times... | ||
| 117 : | $database->setQuery("DELETE FROM #__zoom_editmon WHERE vote_time < '$now' OR comment_time < '$now' OR pass_time < '$now'"); | ||
| 118 : | @$database->query(); | ||
| 119 : | // second, delete lightbox rows and files... | ||
| 120 : | $database->setQuery("SELECT lightbox_file FROM #__zoom_editmon WHERE lightbox_time < '$now'"); | ||
| 121 : | $this->_result = $database->query(); | ||
| 122 : | if (mysql_num_rows($this->_result) > 0) { | ||
| 123 : | while ($lightbox = mysql_fetch_object($this->_result)) { | ||
| 124 : | @unlink($lightbox->lightbox_file); | ||
| 125 : | $database->setQuery("DELETE FROM #__zoom_editmon WHERE lightbox_time < '$now'"); | ||
| 126 : | $database->query(); | ||
| 127 : | } | ||
| 128 : | } | ||
| 129 : | } | ||
| 130 : | /** | ||
| 131 : | * When an image or comment has been deleted, its EditMon record should be deleted. | ||
| 132 : | * | ||
| 133 : | * @param int $imgid | ||
| 134 : | * @return void | ||
| 135 : | * @access public | ||
| 136 : | */ | ||
| 137 : | function purgeComments($imgid, $limit_session = true) { | ||
| 138 : | global $database; | ||
| 139 : | $sid = md5($this->_session_id); | ||
| 140 : | $database->setQuery("DELETE FROM #__zoom_editmon WHERE ".($limit_session ? "user_session = '$sid' AND " : "")."object_id = $imgid"); | ||
| 141 : | @$database->query(); | ||
| 142 : | } | ||
| 143 : | /** | ||
| 144 : | * Checks if a user has the right to edit a medium, or if he/ she already | ||
| 145 : | * edited the medium before. | ||
| 146 : | * | ||
| 147 : | * @param int $id | ||
| 148 : | * @param string $which | ||
| 149 : | * @param string $filename | ||
| 150 : | * @return boolean | ||
| 151 : | * @access public | ||
| 152 : | */ | ||
| 153 : | function isEdited($id, $which, $filename='') { | ||
| 154 : | global $database; | ||
| 155 : | $now = time(); | ||
| 156 : | $sid = md5($this->_session_id); | ||
| 157 : | switch ($which) { | ||
| 158 : | case 'comment': | ||
| 159 : | $database->setQuery("SELECT edtid FROM #__zoom_editmon WHERE user_session='$sid' AND comment_time>'$now' AND object_id=".$this->escapeString($id)); | ||
| 160 : | break; | ||
| 161 : | case 'vote'; | ||
| 162 : | $database->setQuery("SELECT edtid FROM #__zoom_editmon WHERE user_session='$sid' AND vote_time>'$now' AND object_id=".$this->escapeString($id)); | ||
| 163 : | break; | ||
| 164 : | case 'pass': | ||
| 165 : | $database->setQuery("SELECT edtid FROM #__zoom_editmon WHERE user_session='$sid' AND pass_time>'$now' AND object_id=".$this->escapeString($id)); | ||
| 166 : | break; | ||
| 167 : | case 'lightbox': | ||
| 168 : | $database->setQuery("SELECT edtid FROM #__zoom_editmon WHERE user_session='$sid' AND lightbox_time>'$now' AND lightbox_file='".$this->escapeString($filename)."'"); | ||
| 169 : | break; | ||
| 170 : | } | ||
| 171 : | $this->_result = $database->query(); | ||
| 172 : | if (mysql_num_rows($this->_result) > 0) { | ||
| 173 : | return true; | ||
| 174 : | } else { | ||
| 175 : | return false; | ||
| 176 : | } | ||
| 177 : | } | ||
| 178 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

