Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezlink.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezlink.php 9782 2003-02-26 09:03:33Z br $
5 //
6 // Definition of eZLink class
7 //
8 // Created on: <15-Sep-2000 14:40:06 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
60 // include_once( "classes/ezquery.php" );
61 // include_once( "classes/ezdatetime.php" );
62 // include_once( "classes/ezdb.php" );
63
64 class eZLink
65 {
69 function __construct( $id = -1 )
70 {
71 $this->ImageID = 0;
72 if ( $id != -1 )
73 {
74 $this->ID = $id;
75 $this->get( $this->ID );
76 }
77 }
78
82 function store()
83 {
84 $db =& eZDB::globalDatabase();
85
86 $db->begin();
87
88 $description = $db->escapeString( $this->Description );
89 $name = $db->escapeString( $this->Name );
90 $url = $db->escapeString( $this->Url );
91 $keywords = $db->escapeString( $this->KeyWords );
92 $timeStamp = new eZDateTime();
93 $timeStamp = $timeStamp->timeStamp( true );
94
95 if ( !isset( $this->ID) )
96 {
97 $db->lock( "eZLink_Link" );
98 $nextID = $db->nextID( "eZLink_Link", "ID" );
99
100 $res = $db->query( "INSERT INTO eZLink_Link
101 ( ID,
102 Name,
103 Description,
104 KeyWords,
105 Created,
106 Modified,
107 Url,
108 ImageID,
109 Accepted )
110 VALUES
111 ( '$nextID',
112 '$name',
113 '$description',
114 '$keywords',
115 '$timeStamp',
116 '$timeStamp',
117 '$url',
118 '$this->ImageID',
119 '$this->Accepted' )" );
120
121 $this->ID = $nextID;
122
123 $db->unlock();
124 }
125 else
126 {
127 $res = $db->query( "UPDATE eZLink_Link SET
128 Name='$name',
129 Description='$description',
130 KeyWords='$keywords',
131 Modified='$timeStamp',
132 Url='$url',
133 ImageID='$this->ImageID',
134 Accepted='$this->Accepted'
135 WHERE ID='$this->ID'" );
136 }
137
138 if ( $res == false )
139 {
140 $db->rollback();
141 }
142 else
143 {
144 $db->commit();
145 }
146 }
147
151 function setType( $type )
152 {
153 if ( is_a( $type, "eZLinkType" ) )
154 {
155 $db =& eZDB::globalDatabase();
156
157 $db->begin();
158
159 $typeID = $type->id();
160
161 $res[] = $db->query( "DELETE FROM eZLink_AttributeValue
162 WHERE LinkID='$this->ID'" );
163 $res[] = $db->query( "DELETE FROM eZLink_TypeLink
164 WHERE LinkID='$this->ID'" );
165
166 $db->lock( "eZLink_TypeLink" );
167
168 $nextID = $db->nextID( "eZLink_TypeLink", "ID" );
169
170 $query = "INSERT INTO eZLink_TypeLink
171 (ID, TypeID, LinkID)
172 VALUES
173 ('$nextID',
174 '$typeID',
175 '$this->ID')";
176
177 $res[] = $db->query( $query );
178
179 $db->unlock();
180
181 if ( in_array( false, $res ) )
182 $db->rollback();
183 else
184 $db->commit();
185
186 }
187 }
188
192 function type()
193 {
194 $db =& eZDB::globalDatabase();
195
196 $db->array_query( $res, "SELECT TypeID FROM
197 eZLink_TypeLink WHERE LinkID='$this->ID'" );
198
199 $type = false;
200
201 if ( count( $res ) == 1 )
202 {
203 $type = new eZLinkType( $res[0][$db->fieldName("TypeID")] );
204 }
205
206 return $type;
207 }
208
212 function removeType()
213 {
214 $db =& eZDB::globalDatabase();
215
216 // delete values
217 $db->query( "DELETE FROM eZLink_AttributeValue WHERE LinkID='$this->ID'" );
218
219 $db->query( "DELETE FROM eZLink_TypeLink WHERE LinkID='$this->ID'" );
220
221 }
222
226 function update()
227 {
228 $db =& eZDB::globalDatabase();
229
230 $db->begin( );
231
232 $description = $db->escapeString( $this->Description );
233 $name = $db->escapeString( $this->Name );
234 $url = $db->escapeString( $this->Url );
235 $keywords = $db->escapeString( $this->KeyWords );
236
237 $timeStamp = new eZDateTime();
238 $timeStamp = $timeStamp->timeStamp( true );
239
240
241 $res = $db->query( "UPDATE eZLink_Link SET
242 Name='$name',
243 Description='$description',
244 KeyWords='$keywords',
245 Modified='$timeStamp',
246 Url='$url',
247 ImageID='$this->ImageID',
248 Accepted='$this->Accepted'
249 WHERE ID='$this->ID'" );
250
251
252 if ( $res == false )
253 $db->rollback( );
254 else
255 $db->commit();
256
257 }
258
262 function delete()
263 {
264 $db =& eZDB::globalDatabase();
265
266 $db->begin();
267
268 $res[] = $db->query( "DELETE FROM eZLink_Hit WHERE Link='$this->ID'" );
269 $res[] = $db->query( "DELETE FROM eZLink_Link WHERE ID='$this->ID'" );
270 $res[] = $db->query( "DELETE FROM eZLink_TypeLink WHERE LinkID='$this->ID'" );
271 $res[] = $db->query( "DELETE FROM eZLink_AttributeValue WHERE LinkID='$this->ID'" );
272 $res[] = $db->query( "DELETE FROM eZLink_LinkCategoryDefinition WHERE LinkID='$this->ID'" );
273 $res[] = $db->query( "DELETE FROM eZLink_LinkCategoryLink WHERE LinkID='$this->ID'" );
274
275 if ( in_array( false, $res ) )
276 $db->rollback();
277 else
278 $db->commit();
279 }
280
284 function get( $id )
285 {
286 $db =& eZDB::globalDatabase();
287
288 if ( $id != "" )
289 {
290 $link_array = array();
291 $db->array_query( $link_array, "SELECT * FROM eZLink_Link WHERE ID='$id'" );
292 if ( count( $link_array ) > 1 )
293 {
294 die( "Error: more than one link with the same ID found" );
295 }
296 else if ( count( $link_array ) == 1 )
297 {
298 $this->ID =& $link_array[0][$db->fieldName("ID")];
299 $this->Name =& $link_array[0][$db->fieldName("Name")];
300 $this->Description =& $link_array[0][$db->fieldName("Description")];
301 $this->KeyWords =& $link_array[0][$db->fieldName("KeyWords")];
302 $this->Created =& $link_array[0][$db->fieldName("Created")];
303 $this->Modified =& $link_array[0][$db->fieldName("Modified")];
304 $this->Accepted =& $link_array[0][$db->fieldName("Accepted")];
305 $this->Url =& $link_array[0][$db->fieldName("Url")];
306 $this->ImageID =& $link_array[0][$db->fieldName("ImageID")];
307 }
308 }
309
310 }
311
315 function &getByCategory( $id )
316 {
317 $db =& eZDB::globalDatabase();
318
319 $link_array = array();
320 $return_array = array();
321
322 $db->array_query( $link_array, "SELECT eZLink_Link.ID FROM eZLink_Link, eZLink_LinkCategoryLink
323 WHERE CategoryID='$id' AND eZLink_Link.ID=LinkID AND Accepted='1' ORDER BY Name" );
324
325 for( $i=0; $i < count( $link_array ); $i++ )
326 {
327 $return_array[] = new eZLink( $link_array[$i][$db->fieldName( "ID" )] );
328 }
329
330 return $return_array;
331 }
332
338 function &getNotAccepted( $offset = 0, $limit = 30 )
339 {
340 $db =& eZDB::globalDatabase();
341
342 $link_array = array();
343 $return_array = array();
344
345 $db->array_query( $link_array, "SELECT ID, Name FROM eZLink_Link
346 WHERE Accepted='0' ORDER BY Name",
347 array( "Limit" => $limit, "Offset" => $offset ) );
348
349 for ( $i = 0; $i < count( $link_array ); $i++ )
350 {
351 $return_array[] = new eZLink( $link_array[$i][$db->fieldName( "ID" )] );
352 }
353
354 return $return_array;
355 }
356
360 function unAcceptedCount()
361 {
362 $db =& eZDB::globalDatabase();
363
364 $query = "SELECT count( ID ) AS Count
365 FROM eZLink_Link WHERE Accepted='0'";
366
367 $db->array_query( $linkArray, $query );
368
369 return $linkArray[0][$db->fieldName( "Count" )];
370 }
371
372
376 function &getLastTenDate( $limit, $offset )
377 {
378 $db =& eZDB::globalDatabase();
379
380 $link_array = array();
381 $return_array = array();
382
383 $db->array_query( $link_array,
384 "SELECT * FROM eZLink_Link WHERE Accepted='1' ORDER BY Created DESC",
385 array( "Limit" => $limit, "Offset" => $offset ) );
386
387 for( $i=0; $i < count( $link_array ); $i++ )
388 {
389 $return_array[] = new eZLink( $link_array[$i][$db->fieldName( "ID" )] );
390 }
391 return $return_array;
392 }
393
397 function &getLastTen( $limit, $offset )
398 {
399 $db =& eZDB::globalDatabase();
400 $link_array = 0;
401
402 $db->array_query( $link_array,
403 "SELECT * FROM eZLink_Link WHERE Accepted='1' ORDER BY Name DESC",
404 array( "Limit" => $limit, "Offset" => $offset ) );
405
406 return $link_array;
407 }
408
414 function &getQuery( $query, $limit, $offset )
415 {
416 $db =& eZDB::globalDatabase();
417 $link_array = array();
418 $return_array = array();
419
420 $query = new eZQuery( array( "KeyWords", "Name", "Description" ), $query );
421 $query->setPartialCompare( true );
422 $query_str = "SELECT ID FROM eZLink_Link WHERE (" .
423 $query->buildQuery() .
424 ") AND Accepted='1' GROUP BY Name, ID ORDER BY Name";
425
426 $db->array_query( $link_array, $query_str,
427 array( "Limit" => $limit, "Offset" => $offset ) );
428
429 $ret = array();
430
431 foreach( $link_array as $linkItem )
432 {
433 $ret[] = new eZLink( $linkItem[$db->fieldName( "ID" )] );
434 }
435 return $ret;
436 }
437
438
442 function &getQueryCount( $query )
443 {
444 $db =& eZDB::globalDatabase();
445 $link_array = 0;
446
447 $query = new eZQuery( array( "KeyWords", "Name", "Description" ), $query );
448
449 $query_str = "SELECT count(ID) AS Count, Name FROM eZLink_Link WHERE (" .
450 $query->buildQuery() .
451 ") AND Accepted='1' GROUP BY Name ORDER BY Name";
452
453 $db->array_query( $link_array, $query_str );
454
455 $ret = 0;
456 if ( count( $link_array ) == 1 )
457 $ret = $link_array[0][$db->fieldName("Count")];
458
459 return $ret;
460 }
461
462
466 function &getAll()
467 {
468 $db =& eZDB::globalDatabase();
469 $category_array = 0;
470
471 $db->array_query( $category_array, "SELECT * FROM eZLink_Link ORDER BY Name" );
472
473 return $category_array;
474 }
475
479 function &checkUrl( $url )
480 {
481 $db =& eZDB::globalDatabase();
482
483 $db->array_query( $url_array, "SELECT url FROM eZLink_Link WHERE url='$url'" );
484
485 return count( $url_array );
486 }
487
492 function setCategoryDefinition( $value )
493 {
494 if ( is_a( $value, "eZLinkCategory" ) )
495 $categoryID = $value->id();
496 else if ( is_numeric( $value ) )
497 $categoryID = $value;
498 else
499 return false;
500
501 $db =& eZDB::globalDatabase();
502 $db->begin();
503
504 $res[] = $db->query( "DELETE FROM eZLink_LinkCategoryDefinition
505 WHERE LinkID='$this->ID'" );
506 $db->lock( "eZLink_LinkCategoryDefinition" );
507 $nextID = $db->nextID( "eZLink_LinkCategoryDefinition", "ID" );
508 $res[] = $db->query( "INSERT INTO eZLink_LinkCategoryDefinition
509 (ID, LinkID, CategoryID) VALUES
510 ('$nextID','$this->ID','$categoryID')" );
511 $db->unlock();
512 eZDB::finish( $res, $db );
513 }
514
515
519 function categoryDefinition( $as_object = true )
520 {
521 $db =& eZDB::globalDatabase();
522
523 $db->array_query( $res, "SELECT CategoryID FROM
524 eZLink_LinkCategoryDefinition
525 WHERE LinkID='$this->ID'" );
526
527 $category = false;
528 if ( count( $res ) == 1 )
529 {
530 if ( $as_object )
531 $category = new eZLinkCategory( $res[0][$db->fieldName( "CategoryID" )] );
532 else
533 $category = $res[0][$db->fieldName( "CategoryID" )];
534 }
535 else
536 {
537 print ( "<br><b>Failed to get link category definition for ID $this->ID</b>" );
538 }
539
540 return $category;
541 }
542
547 function categories( $as_object = true )
548 {
549 $db =& eZDB::globalDatabase();
550
551 $ret = array();
552 $category_array = array();
553 $db->array_query( $category_array, "SELECT * FROM eZLink_LinkCategoryLink
554 WHERE LinkID='$this->ID'" );
555 if ( $as_object )
556 {
557 foreach ( $category_array as $category )
558 {
559 $ret[] = new eZLinkCategory( $category[$db->fieldName( "CategoryID" )] );
560 }
561 }
562 else
563 {
564 foreach ( $category_array as $category )
565 {
566 $ret[] = $category[$db->fieldName( "CategoryID" )];
567 }
568 }
569 return $ret;
570 }
571
575 function setName( &$value )
576 {
577 $this->Name = $value;
578 }
579
583 function setDescription( &$value )
584 {
585 $this->Description = $value;
586 }
587
588
592 function setKeyWords( &$value )
593 {
594 $this->KeyWords = ( $value );
595 }
596
600 function setAccepted( $value )
601 {
602 if ( $value == true )
603 $this->Accepted = "1";
604 else
605 $this->Accepted = "0";
606 }
607
611 function setUrl( &$value )
612 {
613 $this->Url = ( $value );
614 }
615
619 function &name()
620 {
621 $this->Name = stripslashes( $this->Name );
622 return htmlspecialchars( $this->Name );
623 }
624
625
629 function &description()
630 {
631 $this->Description = stripslashes( $this->Description );
632 $this->Description = htmlspecialchars( $this->Description );
633 return nl2br( $this->Description );
634 }
635
639 function &keyWords()
640 {
641 if( !is_null( $this->KeyWords ) )
642 {
643 $this->KeyWords = stripslashes($this->KeyWords);
644 return htmlspecialchars( $this->KeyWords );
645 }
646
647 return $this->KeyWords;
648 }
649
653 function &created()
654 {
655 return $this->Created;
656 }
657
661 function &modified()
662 {
663 return $this->Modified;
664 }
665
669 function accepted()
670 {
671 if ( $this->Accepted == 1 )
672 return true;
673 else
674 return false;
675 }
676
680 function &url()
681 {
682 return $this->Url;
683 }
684
688 function id()
689 {
690 return $this->ID;
691 }
692
696 function setImage( &$value )
697 {
698 if ( is_a( $value, "eZImage" ) )
699 {
700 $this->ImageID = $value->id();
701 }
702 elseif ( is_numeric( $value ) )
703 {
704 $this->ImageID = $value;
705 }
706 }
707
713 function &image( )
714 {
715 $ret = false;
716 if ( $this->ImageID != 0 )
717 {
718 $ret = new eZImage( $this->ImageID );
719 }
720
721 return $ret;
722 }
723
727 function deleteImage()
728 {
729 $db =& eZDB::globalDatabase();
730
731 $db->array_query( $result, "SELECT ImageID FROM eZLink_Link WHERE ID='$this->ID'" );
732
733 $db->query( "UPDATE eZLink_Link set ImageID='0' WHERE ID='$this->ID'" );
734 }
735
736 var $ID;
737 var $Name;
738 var $Description;
739 var $KeyWords;
740 var $Created;
741 var $Modified;
742 var $Accepted;
743 var $ImageID;
744 var $Url;
745 var $url_array;
746
747 }
748
749 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZImage
Definition: ezimage.php:95
eZLinkCategory
Definition: ezlinkcategory.php:37
eZLinkType
Definition: ezlinktype.php:33
eZLink
Definition: ezlink.php:65
eZLink\image
& image()
Definition: ezlink.php:713
eZLink\unAcceptedCount
unAcceptedCount()
Definition: ezlink.php:360
eZLink\$Url
$Url
Definition: ezlink.php:744
eZLink\setAccepted
setAccepted( $value)
Definition: ezlink.php:600
eZLink\$url_array
$url_array
Definition: ezlink.php:745
eZLink\removeType
removeType()
Definition: ezlink.php:212
eZLink\categoryDefinition
categoryDefinition( $as_object=true)
Definition: ezlink.php:519
eZLink\$Modified
$Modified
Definition: ezlink.php:741
eZLink\getAll
& getAll()
Definition: ezlink.php:466
eZLink\name
& name()
Definition: ezlink.php:619
eZLink\created
& created()
Definition: ezlink.php:653
eZLink\getLastTen
& getLastTen( $limit, $offset)
Definition: ezlink.php:397
eZLink\url
& url()
Definition: ezlink.php:680
eZLink\$Created
$Created
Definition: ezlink.php:740
eZLink\getLastTenDate
& getLastTenDate( $limit, $offset)
Definition: ezlink.php:376
eZLink\getQuery
& getQuery( $query, $limit, $offset)
Definition: ezlink.php:414
eZLink\getByCategory
& getByCategory( $id)
Definition: ezlink.php:315
eZLink\store
store()
Definition: ezlink.php:82
eZLink\setDescription
setDescription(&$value)
Definition: ezlink.php:583
eZLink\modified
& modified()
Definition: ezlink.php:661
eZLink\id
id()
Definition: ezlink.php:688
eZLink\setImage
setImage(&$value)
Definition: ezlink.php:696
eZLink\update
update()
Definition: ezlink.php:226
eZLink\getNotAccepted
& getNotAccepted( $offset=0, $limit=30)
Definition: ezlink.php:338
eZLink\accepted
accepted()
Definition: ezlink.php:669
eZLink\categories
categories( $as_object=true)
Definition: ezlink.php:547
eZLink\setName
setName(&$value)
Definition: ezlink.php:575
eZLink\$Description
$Description
Definition: ezlink.php:738
eZLink\setType
setType( $type)
Definition: ezlink.php:151
eZLink\setCategoryDefinition
setCategoryDefinition( $value)
Definition: ezlink.php:492
eZLink\description
& description()
Definition: ezlink.php:629
eZLink\type
type()
Definition: ezlink.php:192
eZLink\setUrl
setUrl(&$value)
Definition: ezlink.php:611
eZLink\checkUrl
& checkUrl( $url)
Definition: ezlink.php:479
eZLink\$Accepted
$Accepted
Definition: ezlink.php:742
eZLink\getQueryCount
& getQueryCount( $query)
Definition: ezlink.php:442
eZLink\$ID
$ID
Definition: ezlink.php:736
eZLink\setKeyWords
setKeyWords(&$value)
Definition: ezlink.php:592
eZLink\$KeyWords
$KeyWords
Definition: ezlink.php:739
eZLink\deleteImage
deleteImage()
Definition: ezlink.php:727
eZLink\$ImageID
$ImageID
Definition: ezlink.php:743
eZLink\$Name
$Name
Definition: ezlink.php:737
eZLink\__construct
__construct( $id=-1)
Definition: ezlink.php:69
eZLink\keyWords
& keyWords()
Definition: ezlink.php:639
eZQuery
Definition: ezquery.php:54
$type
$type
Definition: classes/admin/linkselect.php:220
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$link_array
$link_array
Definition: latest.php:52
$url
$url
Definition: messagereviewlist.php:153
$categoryID
else $categoryID
Definition: productview.php:66
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$category_array
$category_array
Definition: todoedit.php:604
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.