Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezurltranslator.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezurltranslator.php 9232 2002-02-15 18:51:33Z master $
5 //
6 // Definition of eZURLTranslator class
7 //
8 // Created on: <22-Apr-2001 18:38:38 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
35 // include_once( "classes/ezdb.php" );
36
37 class eZURLTranslator
38 {
42 function __construct( $id=-1 )
43 {
44 if ( $id != -1 )
45 {
46 $this->ID = $id;
47 $this->get( $this->ID );
48 }
49 }
50
54 static public function translate( $url )
55 {
56 $ret = false;
57 $url_array = array();
58 $db =& eZDB::globalDatabase();
59
60 // Hack to delete a trailing slash
61 $url = preg_replace("'/$'", "", $url);
62
63 $db->array_query( $url_array,
64 "SELECT Dest FROM eZURLTranslator_URL
65 WHERE Source='$url'" );
66
67 // $url = preg_replace("'/$'", "", $url);
68
69 if ( count( $url_array ) > 0 )
70 {
71 $ret = $url_array[0][$db->fieldName("Dest")];
72 }
73 return $ret;
74 }
75
79 function store()
80 {
81 $db =& eZDB::globalDatabase();
82
83 $db->begin( );
84
85 if ( !isset( $this->ID ) )
86 {
87 $db->lock( "eZURLTranslator_URL" );
88
89 $nextID = $db->nextID( "eZURLTranslator_URL", "ID" );
90 $timeStamp =& (new eZDateTime())->timeStamp( true );
91
92 $res = $db->query( "INSERT INTO eZURLTranslator_URL
93 ( ID, Source, Dest, Created ) VALUES
94 ( '$nextID',
95 '$this->Source',
96 '$this->Dest',
97 '$timeStamp' )
98 " );
99
100 $this->ID = $nextID;
101 }
102 else
103 {
104 $res = $db->query( "UPDATE eZURLTranslator_URL SET
105 Source='$this->Source',
106 Dest='$this->Dest'
107 WHERE ID='$this->ID'" );
108 }
109
110 $db->unlock();
111
112 if ( $res == false )
113 $db->rollback( );
114 else
115 $db->commit();
116
117 return true;
118 }
119
123 function get( $id=-1 )
124 {
125 $db =& eZDB::globalDatabase();
126
127 if ( $id != -1 )
128 {
129 $db->array_query( $url_array, "SELECT * FROM eZURLTranslator_URL WHERE ID='$id'" );
130
131 if ( count( $url_array ) > 1 )
132 {
133 // $db->array_query( $url_array, "DELETE FROM eZURLTranslator_URL WHERE ID='$id'" );
134 die( "Error: Url translations's with the same ID was found in the database. This shouldn't happen." );
135 }
136 else if ( count( $url_array ) == 1 )
137 {
138 $this->ID =& $url_array[0][$db->fieldName("ID")];
139 $this->Source =& $url_array[0][$db->fieldName("Source")];
140 $this->Dest =& $url_array[0][$db->fieldName("Dest")];
141 }
142 }
143 }
144
145 // EP --------------------------------------------------------------------------
149 function getbydest( $dest = '' )
150 {
151 $db =& eZDB::globalDatabase();
152
153 if ( $dest != '' )
154 {
155 $db->array_query( $url_array, "SELECT * FROM eZURLTranslator_URL WHERE Dest='$dest'" );
156
157 $this->ID =& $url_array[0][$db->fieldName( "ID" )];
158 $this->Source =& $url_array[0][$db->fieldName( "Source" )];
159 $this->Dest =& $url_array[0][$db->fieldName( "Dest" )];
160 }
161 }
162
166 function &getAll()
167 {
168 $db =& eZDB::globalDatabase();
169
170 $return_array = array();
171 $url_array = array();
172
173 $db->array_query( $url_array, "SELECT ID, Created FROM eZURLTranslator_URL ORDER BY Created" );
174
175 for ( $i=0; $i<count($url_array); $i++ )
176 {
177 $return_array[$i] = new eZURLTranslator( $url_array[$i][$db->fieldName("ID")], 0 );
178 }
179
180 return $return_array;
181 }
182
186 function delete()
187 {
188 $db =& eZDB::globalDatabase();
189
190 $db->begin( );
191
192 $res = $db->query( "DELETE FROM eZURLTranslator_URL WHERE ID='$this->ID'" );
193
194 if ( $res == false )
195 $db->rollback( );
196 else
197 $db->commit();
198 }
199
203 function id()
204 {
205 return $this->ID;
206 }
207
211 function source()
212 {
213 return $this->Source;
214 }
215
219 function dest()
220 {
221 return $this->Dest;
222 }
223
224
228 function setSource( $value )
229 {
230 $this->Source = $value;
231 }
232
236 function setDest( $value )
237 {
238 $this->Dest = $value;
239 }
240
241 var $ID;
242 var $Source;
243 var $Dest;
244
245 }
246
247 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZURLTranslator
Definition: ezurltranslator.php:38
eZURLTranslator\store
store()
Definition: ezurltranslator.php:79
eZURLTranslator\setSource
setSource( $value)
Definition: ezurltranslator.php:228
eZURLTranslator\dest
dest()
Definition: ezurltranslator.php:219
eZURLTranslator\getbydest
getbydest( $dest='')
Definition: ezurltranslator.php:149
eZURLTranslator\$Dest
$Dest
Definition: ezurltranslator.php:243
eZURLTranslator\setDest
setDest( $value)
Definition: ezurltranslator.php:236
eZURLTranslator\__construct
__construct( $id=-1)
Definition: ezurltranslator.php:42
eZURLTranslator\translate
static translate( $url)
Definition: ezurltranslator.php:54
eZURLTranslator\$Source
$Source
Definition: ezurltranslator.php:242
eZURLTranslator\source
source()
Definition: ezurltranslator.php:211
eZURLTranslator\getAll
& getAll()
Definition: ezurltranslator.php:166
eZURLTranslator\id
id()
Definition: ezurltranslator.php:203
eZURLTranslator\$ID
$ID
Definition: ezurltranslator.php:241
$id
$id
Definition: companytypelist.php:193
$url_array
$url_array
Definition: ezaddress/admin/datasupplier.php:34
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$url
$url
Definition: messagereviewlist.php:153
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.