| [ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 #CMS - CMS Made Simple 3 #(c)2004 by Ted Kulp (tedkulp@users.sf.net) 4 #This project's homepage is: http://cmsmadesimple.org 5 # 6 #This program is free software; you can redistribute it and/or modify 7 #it under the terms of the GNU General Public License as published by 8 #the Free Software Foundation; either version 2 of the License, or 9 #(at your option) any later version. 10 # 11 #This program is distributed in the hope that it will be useful, 12 #BUT withOUT ANY WARRANTY; without even the implied warranty of 13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 #GNU General Public License for more details. 15 #You should have received a copy of the GNU General Public License 16 #along with this program; if not, write to the Free Software 17 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 # 19 #$Id: class.recentpage.inc.php 3414 2006-09-01 00:05:09Z dittmann $ 20 21 /** 22 * Recent Page class for admin 23 * 24 * @package CMS 25 */ 26 class RecentPage 27 { 28 /** 29 * ID 30 */ 31 var $id; 32 33 /** 34 * User(owner) ID 35 */ 36 var $user_id; 37 38 /** 39 * Title 40 */ 41 var $title; 42 43 /** 44 * Url 45 */ 46 var $url; 47 48 /** 49 * Timestamp 50 */ 51 var $timestamp; 52 53 54 /** 55 * Generic constructor. Runs the SetInitialValues fuction. 56 */ 57 function RecentPage() 58 { 59 $this->SetInitialValues(); 60 } 61 62 /** 63 * Sets object to some sane initial values 64 * 65 */ 66 function SetInitialValues() 67 { 68 $this->id = -1; 69 $this->title = ''; 70 $this->url = ''; 71 $this->user_id = -1; 72 $this->timestamp = -1; 73 } 74 75 /** 76 * Sets object attributes in one go 77 * 78 */ 79 function SetValues($title, $url, $userid) 80 { 81 $this->title = $title; 82 $this->url = $url; 83 $this->user_id = $userid; 84 } 85 86 87 /** 88 * Saves the page to the database, creating a new record. 89 * 90 * @returns mixed If successful, true. If it fails, false. 91 */ 92 function Save() 93 { 94 return RecentPageOperations::InsertPage($this); 95 } 96 97 /** 98 * Purges oldest records from the database, preserving only the 99 * n most-recent. 100 * 101 * @returns mixed If successful, true. If it fails, false. 102 */ 103 function PurgeOldPages($userid,$count=5) 104 { 105 return RecentPageOperations::PurgeOldPages($userid,$count); 106 } 107 } 108 109 /** 110 * Class for doing recent page-related functions. 111 * 112 * @package CMS 113 */ 114 class RecentPageOperations 115 { 116 /** 117 * Gets a list of all recent pages for a given user 118 * 119 * @returns array An array of RecentPage objects 120 */ 121 function LoadRecentPages($user_id) 122 { 123 global $gCms; 124 $db = &$gCms->GetDb(); 125 126 $result = array(); 127 128 $query = "SELECT id, user_id, title, url, access_time FROM ".cms_db_prefix(). 129 "admin_recent_pages WHERE user_id = ? ORDER BY access_time DESC"; 130 $dbresult = $db->Execute($query, array($user_id)); 131 132 while ($dbresult && $row = $dbresult->FetchRow()) 133 { 134 $onepage = new RecentPage(); 135 $onepage->id = $row['id']; 136 $onepage->user_id = $row['user_id']; 137 $onepage->url = $row['url']; 138 $onepage->title = $row['title']; 139 $onepage->timestamp = $row['access_time']; 140 $result[] = $onepage; 141 } 142 143 return $result; 144 } 145 146 /** 147 * Saves a new page to the database. 148 * 149 * @param mixed $page RecentPage object to save 150 * 151 * @returns mixed The new id. If it fails, it returns -1. 152 */ 153 function InsertPage($page) 154 { 155 $result = -1; 156 157 global $gCms; 158 $db = &$gCms->GetDb(); 159 160 $new_page_id = $db->GenID(cms_db_prefix()."admin_recent_pages_seq"); 161 $time = $db->DBTimeStamp(time()); 162 $query = "INSERT INTO ".cms_db_prefix()."admin_recent_pages (id, user_id, url, title, access_time) VALUES (?,?,?,?,".$time.")"; 163 $dbresult = $db->Execute($query, array($new_page_id, $page->user_id, $page->url, 164 $page->title)); 165 if ($dbresult !== false) 166 { 167 $result = $new_page_id; 168 } 169 170 return $result; 171 } 172 173 /** 174 * Purges old recent pages from the database. 175 * 176 * @param int $count - number of pages to preserve 177 * 178 * @returns mixed If successful, true. If it fails, false. 179 */ 180 function PurgeOldPages($user_id, $count) 181 { 182 $result = false; 183 $oldPages = array(); 184 185 global $gCms; 186 $db = &$gCms->GetDb(); 187 188 $query = "SELECT id FROM ".cms_db_prefix(). 189 "admin_recent_pages WHERE user_id = ? ORDER BY access_time DESC limit 10000 offset ?"; 190 $dbresult = $db->Execute($query, array($user_id,$count)); 191 while ($dbresult && $row = $dbresult->FetchRow()) 192 { 193 $oldPages[] = array( $row['id'] ); 194 } 195 196 $query = "DELETE FROM ".cms_db_prefix()."admin_recent_pages where id=?"; 197 $db->Execute($query, $oldPages); 198 199 if ($dbresult !== false) 200 { 201 $result = true; 202 } 203 return $result; 204 } 205 } 206 207 # vim:ts=4 sw=4 noet 208 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |