Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

eznews.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: eznews.php 6224 2001-07-20 11:21:41Z jakobn $
5 //
6 // Definition of eZNews class
7 //
8 // Created on: <13-Nov-2000 12:51:40 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
58 // include_once( "classes/ezdb.php" );
59 // include_once( "classes/ezdatetime.php" );
60 // include_once( "ezuser/classes/ezuser.php" );
61
62 class eZNews
63 {
70 function __construct( $id="" )
71 {
72 $this->IsPublished = 0;
73
74 if ( $id != "" )
75 {
76 $this->ID = $id;
77 $this->get( $this->ID );
78 }
79 }
80
86 function store()
87 {
88 $db =& eZDB::globalDatabase();
89 $db->begin();
90
91 $timeStamp = (new eZDateTime())->timeStamp( true );
92
93 $name = $db->escapeString( $this->Name );
94 $intro = $db->escapeString( $this->Intro );
95 $url = $db->escapeString( $this->URL );
96 $keywords = $db->escapeString( $this->KeyWords );
97 $origin = $db->escapeString( $this->Origin );
98
99 if ( !isset( $this->ID ) )
100 {
101 // check if the news is already stored.
102 $db->array_query( $ret, "SELECT ID FROM eZNewsFeed_News WHERE
103 Name='$name' AND
104 Intro='$intro' AND
105 URL='$url'
106 " );
107
108 if ( count( $ret ) == 0 )
109 {
110
111 $db->lock( "eZNewsFeed_News" );
112 $nextID = $db->nextID( "eZNewsFeed_News", "ID" );
113
114 $ret[] = $db->query( "INSERT INTO eZNewsFeed_News
115 ( ID,
116 Name,
117 Intro,
118 IsPublished,
119 PublishingDate,
120 OriginalPublishingDate,
121 KeyWords,
122 Origin,
123 URL )
124 VALUES
125 ( '$nextID',
126 '$name',
127 '$intro',
128 '$this->IsPublished',
129 '$timeStamp',
130 '$this->OriginalPublishingDate',
131 '$keywords',
132 '$this->Origin',
133 '$url' )" );
134
135 $this->ID = $nextID;
136
137 }
138 else
139 {
140 $ret[] = false;
141 }
142 }
143 else
144 {
145 $db->array_query( $res, "SELECT ID FROM eZNewsFeed_News WHERE IsPublished='0' AND ID='$this->ID'" );
146 if ( ( count( $res ) > 0 ) && ( $this->IsPublished == "1" ) )
147 {
148 $db->query( "UPDATE eZNewsFeed_News SET
149 Name='$name',
150 Intro='$intro',
151 IsPublished='1',
152 PublishingDate='$timeStamp',
153 OriginalPublishingDate='$this->OriginalPublishingDate',
154 KeyWords='$keywords',
155 Origin='$origin',
156 URL='$url'
157 WHERE ID='$this->ID'
158 " );
159 }
160 else
161 {
162 $db->query( "UPDATE eZNewsFeed_News SET
163 Name='$name',
164 Intro='$intro',
165 IsPublished='$this->IsPublished',
166 PublishingDate=PublishingDate,
167 OriginalPublishingDate='$this->OriginalPublishingDate',
168 KeyWords='$keywords',
169 Origin='$origin',
170 URL='$url'
171 WHERE ID='$this->ID'
172 " );
173 }
174
175 $ret[] = true;
176 }
177
178 eZDB::finish( $ret, $db );
179
180 return !in_array( false, $ret );
181 }
182
186 function get( $id="" )
187 {
188 $db =& eZDB::globalDatabase();
189 $ret = false;
190
191 if ( $id != "" )
192 {
193 $db->array_query( $news_array, "SELECT * FROM eZNewsFeed_News WHERE ID='$id'" );
194 if ( count( $news_array ) > 1 )
195 {
196 die( "Error: News's with the same ID was found in the database. This shouldent happen." );
197 }
198 else if( count( $news_array ) == 1 )
199 {
200 $this->ID =& $news_array[0][$db->fieldName("ID")];
201 $this->Name =& $news_array[0][$db->fieldName("Name")];
202 $this->Intro =& $news_array[0][$db->fieldName("Intro")];
203 $this->IsPublished =& $news_array[0][$db->fieldName("IsPublished")];
204 $this->PublishingDate =& $news_array[0][$db->fieldName("PublishingDate")];
205 $this->OriginalPublishingDate =& $news_array[0][$db->fieldName("OriginalPublishingDate")];
206 $this->Origin =& $news_array[0][$db->fieldName("Origin")];
207 $this->KeyWords =& $news_array[0][$db->fieldName("KeyWords")];
208 $this->URL =& $news_array[0][$db->fieldName("URL")];
209
210 $ret = true;
211 }
212 }
213 return $ret;
214 }
215
219 function delete()
220 {
221 $db =& eZDB::globalDatabase();
222
223 if ( isset( $this->ID ) )
224 {
225 $db->begin();
226
227 $res[] = $db->query( "DELETE FROM eZNewsFeed_NewsCategoryLink WHERE NewsID='$this->ID'" );
228
229 $res[] = $db->query( "DELETE FROM eZNewsFeed_News WHERE ID='$this->ID'" );
230
231 if ( in_array( false, $res ) )
232 $db->rollback( );
233 else
234 $db->commit();
235 }
236
237 return in_array( false, $res );
238 }
239
243 function id()
244 {
245 return $this->ID;
246 }
247
251 function &name()
252 {
253 return htmlspecialchars( $this->Name );
254 }
255
259 function &intro()
260 {
261 return $this->Intro;
262 }
263
267 function &url()
268 {
269 return $this->URL;
270 }
271
277 function &publishingDate()
278 {
279 $dateTime = new eZDateTime();
280 $dateTime->setTimeStamp( $this->PublishingDate );
281
282 return $dateTime;
283 }
284
290 function &originalPublishingDate()
291 {
292 $dateTime = new eZDateTime();
293 $dateTime->setTimeStamp( $this->OriginalPublishingDate );
294
295 return $dateTime;
296 }
297
301 function origin( )
302 {
303 return $this->Origin;
304 }
305
309 function keywords( )
310 {
311 return $this->KeyWords;
312 }
313
317 function isPublished()
318 {
319 $ret = false;
320 if ( $this->IsPublished == 1 )
321 {
322 $ret = true;
323 }
324 return $ret;
325 }
326
327
331 function setName( $value )
332 {
333 $this->Name = $value;
334 }
335
339 function setIntro( $value )
340 {
341 $this->Intro = $value;
342 }
343
347 function setURL( $value )
348 {
349 $this->URL = $value;
350 }
351
355 function setOrigin( $value )
356 {
357 $this->Origin = $value;
358 }
359
360
364 function setKeyWords( $value )
365 {
366 $this->KeyWords = $value;
367 }
368
374 function setOriginalPublishingDate( $time)
375 {
376 if ( is_a( $time, "eZDateTime" ) )
377 {
378 $this->OriginalPublishingDate = $time->timeStamp();
379
380 }
381 }
382
386 function setIsPublished( $value )
387 {
388 if ( $value == true )
389 {
390 $this->IsPublished = 1;
391 }
392 else
393 {
394 $this->IsPublished = 0;
395 }
396 }
397
398
404 function categories()
405 {
406 $db =& eZDB::globalDatabase();
407
408 $ret = array();
409 $db->array_query( $category_array, "SELECT * FROM eZNewsFeed_NewsCategoryLink WHERE NewsID='$this->ID'" );
410
411 foreach ( $category_array as $category )
412 {
413 $ret[] = new eZNewsCategory( $category[$db->fieldName("CategoryID")] );
414 }
415
416 return $ret;
417 }
418
422 function removeFromCategories()
423 {
424 $db =& eZDB::globalDatabase();
425
426 $db->begin();
427 $ret[] = $db->query( "DELETE FROM eZNewsFeed_NewsCategoryLink WHERE NewsID='$this->ID'" );
428 eZDB::finish( $ret, $db );
429
430 }
431
432
437 function existsInCategory( $category )
438 {
439 $ret = false;
440 if ( is_a( $category, "eZNewsCategory" ) )
441 {
442 $db =& eZDB::globalDatabase();
443 $catID = $category->id();
444
445 $db->array_query( $ret_array, "SELECT ID FROM eZNewsFeed_NewsCategoryLink
446 WHERE NewsID='$this->ID' AND CategoryID='$catID'" );
447
448 if ( count( $ret_array ) == 1 )
449 {
450 $ret = true;
451 }
452 }
453 return $ret;
454 }
455
460 function &search( $queryText, $fetchNonPublished=false, $offset=0, $limit=20 )
461 {
462 $db =& eZDB::globalDatabase();
463
464 if ( $fetchNonPublished == true )
465 {
466 $fetchText = "eZNewsFeed_News.IsPublished = '1' AND";
467 }
468 else
469 {
470 $fetchText = "";
471 }
472
473 $return_array = array();
474 $news_array = array();
475
476 $db->array_query( $news_array,
477 "SELECT eZNewsFeed_News.ID AS NewsID, eZNewsFeed_News.Name
478 FROM eZNewsFeed_News
479 WHERE
480 (
481 eZNewsFeed_News.Name LIKE '%$queryText%' OR
482 eZNewsFeed_News.Intro LIKE '%$queryText%'
483 )
484 ORDER BY PublishingDate", array( "Limit" => $limit, "Offset" => $offset ) );
485
486 for ( $i=0; $i<count($news_array); $i++ )
487 {
488 $return_array[$i] = new eZNews( $news_array[$i][$db->fieldName("NewsID")], false );
489 }
490
491 return $return_array;
492 }
493
497 function &searchCount( $queryText, $fetchNonPublished=false )
498 {
499 $db =& eZDB::globalDatabase();
500
501 if ( $fetchNonPublished == true )
502 {
503 $fetchText = "eZNewsFeed_News.IsPublished = '1' AND";
504 }
505 else
506 {
507 $fetchText = "";
508 }
509
510 $return_array = array();
511 $news_array = array();
512
513 $db->array_query( $news_array,
514 "SELECT count( eZNewsFeed_News.ID ) AS Count
515 FROM eZNewsFeed_News
516 WHERE
517 (
518 eZNewsFeed_News.Name LIKE '%$queryText%' OR
519 eZNewsFeed_News.Intro LIKE '%$queryText%'
520 )
521 " );
522
523
524 return $news_array[0][$db->fieldName("Count")];
525 }
526
530 function newsList( $sortMode=time,
531 $fetchNonPublished=false,
532 $offset=0,
533 $limit=25 )
534 {
535 $db =& eZDB::globalDatabase();
536
537 $OrderBy = "eZNewsFeed_News.PublishingDate DESC";
538 switch( $sortMode )
539 {
540 case "alpha" :
541 {
542 $OrderBy = "eZNewsFeed_News.Name DESC";
543 }
544 break;
545 }
546
547
548 $return_array = array();
549 $news_array = array();
550
551 if ( $fetchNonPublished == true )
552 {
553 $db->array_query( $news_array, "
554 SELECT eZNewsFeed_News.ID AS NewsID, eZNewsFeed_News.Name
555 FROM eZNewsFeed_News
556 GROUP BY eZNewsFeed_News.ID ORDER BY $OrderBy", array( "Limit" => $limit, "Offset" => $offset ) );
557 }
558 else
559 {
560 $db->array_query( $news_array, "
561 SELECT eZNewsFeed_News.ID AS NewsID, eZNewsFeed_News.Name
562 FROM eZNewsFeed_News
563 WHERE
564 eZNewsFeed_NewsCategoryLink.NewsID = eZNewsFeed_News.ID
565 AND
566 eZNewsFeed_News.IsPublished = '1'
567 GROUP BY eZNewsFeed_News.ID ORDER BY $OrderBy
568 ", array( "Limit" => $limit, "Offset" => $offset ) );
569 }
570
571 for ( $i=0; $i<count($news_array); $i++ )
572 {
573 $return_array[$i] = new eZNews( $news_array[$i][$db->fieldName("NewsID")], false );
574 }
575
576 return $return_array;
577
578
579
580 }
581
582 var $ID;
583 var $Name;
584 var $Intro;
585 var $PublishingDate;
586 var $OriginalPublishingDate;
587 var $IsPublished;
588 var $KeyWords;
589 var $Origin;
590 var $URL;
591 }
592
593 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
$dateTime
$dateTime
Definition: authorview.php:77
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZNewsCategory
Definition: eznewscategory.php:42
eZNews
Definition: eznews.php:63
eZNews\originalPublishingDate
& originalPublishingDate()
Definition: eznews.php:290
eZNews\setKeyWords
setKeyWords( $value)
Definition: eznews.php:364
eZNews\$Origin
$Origin
Definition: eznews.php:589
eZNews\setIntro
setIntro( $value)
Definition: eznews.php:339
eZNews\setOrigin
setOrigin( $value)
Definition: eznews.php:355
eZNews\$KeyWords
$KeyWords
Definition: eznews.php:588
eZNews\$Name
$Name
Definition: eznews.php:583
eZNews\setOriginalPublishingDate
setOriginalPublishingDate( $time)
Definition: eznews.php:374
eZNews\setName
setName( $value)
Definition: eznews.php:331
eZNews\$PublishingDate
$PublishingDate
Definition: eznews.php:585
eZNews\newsList
newsList( $sortMode=time, $fetchNonPublished=false, $offset=0, $limit=25)
Definition: eznews.php:530
eZNews\setURL
setURL( $value)
Definition: eznews.php:347
eZNews\setIsPublished
setIsPublished( $value)
Definition: eznews.php:386
eZNews\id
id()
Definition: eznews.php:243
eZNews\origin
origin()
Definition: eznews.php:301
eZNews\searchCount
& searchCount( $queryText, $fetchNonPublished=false)
Definition: eznews.php:497
eZNews\store
store()
Definition: eznews.php:86
eZNews\search
& search( $queryText, $fetchNonPublished=false, $offset=0, $limit=20)
Definition: eznews.php:460
eZNews\existsInCategory
existsInCategory( $category)
Definition: eznews.php:437
eZNews\$IsPublished
$IsPublished
Definition: eznews.php:587
eZNews\$OriginalPublishingDate
$OriginalPublishingDate
Definition: eznews.php:586
eZNews\categories
categories()
Definition: eznews.php:404
eZNews\$ID
$ID
Definition: eznews.php:582
eZNews\isPublished
isPublished()
Definition: eznews.php:317
eZNews\$Intro
$Intro
Definition: eznews.php:584
eZNews\$URL
$URL
Definition: eznews.php:590
eZNews\name
& name()
Definition: eznews.php:251
eZNews\url
& url()
Definition: eznews.php:267
eZNews\__construct
__construct( $id="")
Definition: eznews.php:70
eZNews\keywords
keywords()
Definition: eznews.php:309
eZNews\publishingDate
& publishingDate()
Definition: eznews.php:277
eZNews\intro
& intro()
Definition: eznews.php:259
eZNews\removeFromCategories
removeFromCategories()
Definition: eznews.php:422
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$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
$time
$time
Definition: homepage.php:327
$url
$url
Definition: messagereviewlist.php:153
$OrderBy
$OrderBy
Definition: reciverpopup.php:21
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+.