Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

suggestlink.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: suggestlink.php 9517 2002-05-08 11:07:34Z vl $
5 //
6 // Created on: <26-Oct-2000 14:58:57 ce>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/ezhttptool.php" );
29 // include_once( "ezuser/classes/ezpermission.php" );
30 // include_once( "classes/eztexttool.php" );
31
32 $ini =& eZINI::instance( 'site.ini' );
33
34 $Language = $ini->variable( "eZLinkMain", "Language" );
35 $error = new eZINI( "kernel/ezlink/user/intl/" . $Language . "/suggestlink.php.ini", false );
36
37 // include_once( "classes/eztemplate.php" );
38 // include( "ezlink/classes/ezlinkcategory.php" );
39 // include( "ezlink/classes/ezlink.php" );
40 // include( "ezlink/classes/ezhit.php" );
41 // include_once( "ezlink/classes/ezlinktype.php" );
42 // include_once( "ezlink/classes/ezlinkattribute.php" );
43 // include_once( "ezlink/classes/ezmeta.php" );
44
45 //require( "kernel/ezuser/admin/admincheck.php" );
46
47 if ( isset( $DeleteLinks ) )
48 {
49 $Action = "DeleteLinks";
50 }
51
52 if ( isset( $Delete ) )
53 {
54 $Action = "delete";
55 }
56
57 if ( isset( $Back ) )
58 {
59 if ( $LinkID != "" )
60 {
61 $link = new eZLink();
62 $link->get( $LinkID );
63 $catDef = $link->categoryDefinition();
64 $LinkCategoryID = $catDef->id();
65
66 eZHTTPTool::header( "Location: /link/category/$LinkCategoryID/" );
67 exit();
68 }
69 else
70 {
71 eZHTTPTool::header( "Location: " . $_SERVER['HTTP_REFERER'] );
72 exit();
73 }
74 }
75
76 $Accepted = $ini->variable( "eZLinkMain", "AcceptSuggestedLinks" );
77
78 // Get images from the image browse function.
79 if ( ( isset( $AddImages ) ) and ( is_numeric( $LinkID ) ) and ( is_numeric( $LinkID ) ) )
80 {
81 $image = new eZImage( $ImageID );
82 $link = new eZLink( $LinkID );
83 $link->setImage( $image );
84 $link->update();
85 $Action = "edit";
86 }
87
88 if ( isset( $GetSite ) && $GetSite )
89 {
90 if ( $Url )
91 {
92 if ( !preg_match( "%^([a-z]+://)%", $Url ) )
93 $real_url = "https://" . $Url;
94 else
95 $real_url = $Url;
96
97
98 include( "kernel/ezlink/classes/ezmeta.php" );
99 $metaList = fetchURLInfo( $real_url );
100
101 if ( $metaList == false )
102 {
103 $error_msg = $error->variable( "strings", "error_nosite" );
104 }
105 else if ( count( $metaList ) == 0 )
106 {
107 $error_msg = $error->variable( "strings", "error_nometa" );
108 }
109
110 if ( isset( $metaList["description"] ) && $metaList["description"] )
111 $tdescription = $metaList["description"];
112 else
113 $tdescription = $description;
114
115 if ( isset( $metaList["keywords"] ) && $metaList["keywords"] )
116 $tkeywords = $metaList["keywords"];
117 else
118 $tkeywords = $Keywords;
119
120 if ( isset( $metaList["title"] ) &&$metaList["title"] )
121 $tname = $metaList["title"];
122 else if ( $metaList["abstract"] )
123 $tname = $metaList["abstract"];
124 else
125 $tname = $Name;
126
127 // $tdescription = $metaList["description"];
128 // $tkeywords = $metaList["keywords"];
129 // $tname = $Name;
130
131 $turl = eZTextTool::htmlspecialchars( $Url );
132 }
133
134 $action_value = "insert";
135 $Action = "new";
136
137 }
138
139 // Update a link.
140 if ( isset( $Action ) && $Action == "update" )
141 {
142 if ( $Name != "" && $LinkCategoryID != "" && $Url != "" )
143 {
144 $link = new eZLink();
145 $link->get( $LinkID );
146
147 $link->setName( $Name );
148 $link->setDescription( $Description );
149 $link->setKeyWords( $Keywords );
150 $link->setUrl( $Url );
151
152 $link->setCategoryDefinition( $LinkCategoryID );
153
154 // Calculate new and unused categories
155
156 $old_maincategory = $link->categoryDefinition();
157 $old_categories =& array_unique( array_merge( $old_maincategory->id(),
158 $link->categories( false ) ) );
159
160 $new_categories = array_unique( array_merge( $CategoryID, $CategoryArray ) );
161
162 $remove_categories = array_diff( $old_categories, $new_categories );
163 $add_categories = array_diff( $new_categories, $old_categories );
164
165 $categoryIDArray = array();
166
167 foreach ( $categoryArray as $cat )
168 {
169 $categoryIDArray[] = $cat->id();
170 }
171
172 foreach ( $remove_categories as $categoryItem )
173 {
174 eZLinkCategory::removeLink( $link, $categoryItem );
175 }
176
177 // add to categories
178 $category = new eZLinkCategory( $LinkCategoryID );
179 $link->setCategoryDefinition( $category );
180 $category->addLink( $link );
181
182 foreach ( $add_categories as $categoryItem )
183 {
184 eZLinkCategory::addLink( $link, $categoryItem );
185 }
186
187 if ( $Accepted == "1" && eZPermission::checkPermission( $user, "eZLink", "LinkModify" ) )
188 $link->setAccepted( true );
189 else
190 $link->setAccepted( false );
191
192 $link->setUrl( $Url );
193
194 $file = new eZPBImageFile();
195 if ( $file->getUploadedFile( "ImageFile" ) )
196 {
197 $image = new eZImage( );
198 $image->setName( "LinkImage" );
199 $image->setImage( $file );
200
201 $image->store();
202
203 $link->setImage( $image );
204 }
205
206 if ( $TypeID == -1 )
207 {
208 $link->removeType();
209 }
210 else
211 {
212 $link->removeType();
213
214 $link->setType( new eZLinkType( $TypeID ) );
215
216 $i = 0;
217 if ( count( $AttributeValue ) > 0 )
218 {
219 foreach ( $AttributeValue as $attribute )
220 {
221 $att = new eZLinkAttribute( $AttributeID[$i] );
222
223 $att->setValue( $link, $attribute );
224
225 $i++;
226 }
227 }
228 }
229
230 $link->update();
231
232 if ( $DeleteImage )
233 {
234 $link->deleteImage();
235 }
236
237 eZHTTPTool::header( "Location: /link/category/$LinkCategoryID" );
238 exit();
239 }
240 else
241 {
242 $error_msg = $error->variable( "strings", "error_missingdata" );
243 }
244 }
245 //else
246 //{
247 // eZHTTPTool::header( "Location: /link/norights" );
248 // exit();
249 //}
250
251
252 // Insert a link.
253 if ( isset( $Action ) && $Action == "insert" )
254 {
255 if ( $Name != "" && $LinkCategoryID != "" && $Url != "" )
256 {
257 $link = new eZLink();
258
259 $link->setName( $Name );
260 $link->setDescription( $Description );
261 $link->setKeyWords( $Keywords );
262 if ( $Accepted == "1" && eZPermission::checkPermission( $user, "eZLink", "LinkAdd" ) )
263 $link->setAccepted( true );
264 else
265 $link->setAccepted( false );
266
267 $link->setUrl( $Url );
268
269 $tname = $Name;
270 $turl = $Url;
271 if ( !$GetSite )
272 {
273 $tkeywords = $Keywords;
274 $tdescription = $Description;
275 }
276
277 $file = new eZPBImageFile();
278 if ( $file->getUploadedFile( "ImageFile" ) )
279 {
280 $image = new eZImage( );
281 $image->setName( "LinkImage" );
282 $image->setImage( $file );
283
284 $image->store();
285
286 $link->setImage( $image );
287 }
288
289 $link->store();
290
291 if ( $TypeID == -1 )
292 {
293 $link->removeType();
294 }
295 else
296 {
297 $link->setType( new eZLinkType( $TypeID ) );
298
299 $i = 0;
300 if ( count( $AttributeValue ) > 0 )
301 {
302 foreach ( $AttributeValue as $attribute )
303 {
304 $att = new eZLinkAttribute( $AttributeID[$i] );
305 $att->setValue( $link, $attribute );
306 $i++;
307 }
308 }
309 }
310
311 // Add to categories.
312 $cat = new eZLinkCategory( $LinkCategoryID );
313 $cat->addLink( $link );
314 $link->setCategoryDefinition( $cat );
315 if ( isset( $CategoryArray ) && count( $CategoryArray ) > 0 )
316 {
317 foreach ( $CategoryArray as $categoryItem )
318 {
319 if ( $categoryItem != $cat->id() )
320 eZLinkCategory::addLink( $link, $categoryItem );
321 }
322 }
323
324 $linkID = $link->id();
325
326 eZHTTPTool::header( "Location: /link/category/$LinkCategoryID" );
327 exit();
328 }
329 else if ( !isset( $Update ) )
330 {
331 $error_msg = $error->variable( "strings", "error_missingdata" );
332 }
333 }
334 else
335 {
336 // eZHTTPTool::header( "Location: /link/norights" );
337 // $LinkID = false;
338 // $error_msg = false;
339 // $tdescription = false;
340 // $tkeywords = false;
341 // $turl = false;
342 // $tname = false;
343 $linkType = false;
344 }
345
346 // set the template files.
347
348 $t = new eZTemplate( "kernel/ezlink/user/" . $ini->variable( "eZLinkMain", "TemplateDir" ),
349 "kernel/ezlink/user/" . "/intl", $Language, "suggestlink.php" );
350 $t->setAllStrings();
351
352 $t->set_file( "link_edit", "suggestlink.tpl" );
353
354 $t->set_block( "link_edit", "link_category_tpl", "link_category" );
355
356 $t->set_block( "link_edit", "accept_link_tpl", "accept_link" );
357 $t->set_block( "link_edit", "image_item_tpl", "image_item" );
358 $t->set_block( "link_edit", "multiple_category_tpl", "multiple_category" );
359
360 $t->set_block( "link_edit", "type_tpl", "type" );
361
362 $t->set_block( "link_edit", "attribute_list_tpl", "attribute_list" );
363 $t->set_block( "attribute_list_tpl", "attribute_tpl", "attribute" );
364
365
366 $languageIni = new eZINI( "kernel/ezlink/user/intl/" . $Language . "/suggestlink.php.ini", false );
367 $headline = $languageIni->variable( "strings", "headline_insert" );
368
369 $linkselect = new eZLinkCategory();
370
371 $linkCategoryList =& $linkselect->getTree();
372
373 // Template variables.
374 $action_value = "update";
375
376 //if ( !eZPermission::checkPermission( $user, "eZLink", "LinkAdd" ) )
377 //{
378 // eZHTTPTool::header( "Location: /link/norights" );
379 //}
380
381 $action_value = "insert";
382
383 $t->set_var( "image_item", "" );
384 // set accepted link as default.
385 $yes_selected = "selected";
386 $no_selected = "";
387
388 if ( $_SERVER['HTTP_REFERER'] != "" )
389 {
390 $t->set_var( "referer_url", $_SERVER['HTTP_REFERER'] );
391 }
392 else
393 {
394 $refererURL = $_SERVER['HTTP_REFERER'];
395 if ( $refererURL != "" )
396 {
397 $t->set_var( "referer_url", $refererURL );
398 }
399 else
400 {
401 $t->set_var( "referer_url", "/" );
402 }
403 }
404
405
406 if ( isset( $Action ) && $Action == "AttributeList" )
407 {
408 $tname = $Name;
409 $tkeywords = $Keywords;
410 $tdescription = $Description;
411 $turl = $Url;
412
413 $action_value = "update";
414
415 $t->set_var( "image_item", "" );
416
417
418 if ( $Accepted )
419 {
420 $yes_selected = "selected";
421 $no_selected = "";
422 }
423 else
424 {
425 $yes_selected = "";
426 $no_selected = "selected";
427 }
428
429 $action_value = $url_array[3];
430 }
431
432 // Selector
433 $link_select_dict = "";
434 $catCount = count( $linkCategoryList );
435 $t->set_var( "num_select_categories", min( $catCount, 10 ) );
436 $i = 0;
437 foreach ( $linkCategoryList as $linkCategoryItem )
438 {
439 $t->set_var( "link_category_id", $linkCategoryItem[0]->id() );
440 $t->set_var( "link_category_name", $linkCategoryItem[0]->name() );
441
442 if ( $LinkCategoryID == $linkCategoryItem[0]->id() )
443 {
444 $t->set_var( "is_selected", "selected" );
445 }
446 else
447 {
448 $t->set_var( "is_selected", "" );
449 }
450
451 if ( $linkCategoryItem[1] > 0 )
452 $t->set_var( "option_level", str_repeat( "&nbsp;", $linkCategoryItem[1] ) );
453 else
454 $t->set_var( "option_level", "" );
455
456 $link_select_dict[$linkCategoryItem[0]->id()] = $i;
457
458 if ( isset( $LinkCategoryIDArray ) && is_array( $LinkCategoryIDArray ) and in_array( $linkCategoryItem[0]->id(), $LinkCategoryIDArray )
459 and ( $LinkCategoryID != $linkCategoryItem[0]->id() ) )
460 {
461 $t->set_var( "multiple_selected", "selected" );
462 $i++;
463 }
464 else
465 {
466 $t->set_var( "multiple_selected", "" );
467 }
468
469 $t->parse( "link_category", "link_category_tpl", true );
470 $t->parse( "multiple_category", "multiple_category_tpl", true );
471 }
472
473 $t->set_var( "type", "" );
474 $type = new eZLinkType();
475 $types = $type->getAll();
476
477 if ( isset( $TypeID ) )
478 $linkType = new eZLinkType( $TypeID );
479
480 foreach ( $types as $typeItem )
481 {
482 if ( is_a( $linkType, "eZLinkType" ) )
483 {
484 if ( $linkType->id() == $typeItem->id() )
485 {
486 $t->set_var( "selected", "selected" );
487 }
488 else
489 {
490 $t->set_var( "selected", "" );
491 }
492 }
493 else
494 {
495 $t->set_var( "selected", "" );
496 }
497
498 $t->set_var( "type_id", $typeItem->id( ) );
499 $t->set_var( "type_name", $typeItem->name( ) );
500
501 $t->parse( "type", "type_tpl", true );
502 }
503
504
505 if ( is_a( $linkType, "eZLinkType" ) )
506 {
507 $attributes = $linkType->attributes();
508
509 foreach ( $attributes as $attribute )
510 {
511 $t->set_var( "attribute_id", $attribute->id( ) );
512 $t->set_var( "attribute_name", $attribute->name( ) );
513
514 $t->set_var( "attribute_value", $attribute->value( $editLink ) );
515
516 $t->parse( "attribute", "attribute_tpl", true );
517 }
518 }
519
520 if ( isset( $attributes ) && count( $attributes ) > 0 || !isset( $type ) )
521 {
522 $t->parse( "attribute_list", "attribute_list_tpl" );
523 }
524 else
525 {
526 $t->set_var( "attribute_list", "" );
527 }
528
529 $t->set_var( "yes_selected", $yes_selected );
530 $t->set_var( "no_selected", $no_selected );
531
532 $t->set_var( "action_value", $action_value );
533
534 $t->set_var( "name", isset( $tname ) ? $tname : false );
535 $t->set_var( "url", isset( $turl ) ? $turl : false );
536 $t->set_var( "keywords", isset( $tkeywords ) ? $tkeywords : false );
537 $t->set_var( "description", isset( $tdescription ) ? $tdescription : false );
538
539 // $t->set_var( "accepted", $taccepted );
540
541 $t->set_var( "headline", isset( $headline ) ? $headline : false );
542 $t->set_var( "error_msg", isset( $error_msg ) ? $error_msg : false );
543 $t->set_var( "link_id", isset( $LinkID ) ? $LinkID : false );
544
545 $t->pparse( "output", "link_edit" );
546
547 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$categoryArray
$categoryArray
Definition: adedit.php:379
$CategoryID
$CategoryID
Definition: admin/articleedit.php:53
$Description
$Description
Definition: articlelistrss.php:38
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZINI
Reads and writes .ini style configuration files.
eZImage
Definition: ezimage.php:95
eZLinkAttribute
Definition: ezlinkattribute.php:33
eZLinkCategory
Definition: ezlinkcategory.php:37
eZLinkCategory\addLink
static addLink( $value, $categoryid=false)
Definition: ezlinkcategory.php:139
eZLinkCategory\removeLink
static removeLink( $value, $categoryid=false)
Definition: ezlinkcategory.php:117
eZLinkType
Definition: ezlinktype.php:33
eZLink
Definition: ezlink.php:65
eZPBImageFile
Definition: ezpbimagefile.php:71
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZTemplate
Definition: eztemplate.php:107
eZTextTool\htmlspecialchars
static htmlspecialchars( $string)
Definition: eztexttool.php:144
$Action
$Action
Definition: companysearch.php:80
$ImageID
$ImageID
Definition: companytypelist.php:201
$url_array
$url_array
Definition: ezaddress/admin/datasupplier.php:34
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$cat
if(isset( $DeleteCategories)) $cat
Definition: ezforum/admin/categoryedit.php:49
$link
$link
Definition: ezlink/admin/attributeedit.php:49
$error_msg
$error_msg
Definition: ezlink/admin/categoryedit.php:33
fetchURLInfo
& fetchURLInfo( $url)
Definition: ezmeta.php:27
exit
exit
Definition: folder.php:81
$LinkCategoryIDArray
else $LinkCategoryIDArray
Definition: linkedit.php:100
$Name
$Name
Definition: polledit.php:250
$Accepted
if(isset( $DeleteLinks)) if(isset( $Delete)) if(isset( $Back)) $Accepted
Definition: suggestlink.php:76
$languageIni
$languageIni
Definition: suggestlink.php:366
$t
$t
Definition: suggestlink.php:348
$yes_selected
$yes_selected
Definition: suggestlink.php:385
$headline
$headline
Definition: suggestlink.php:367
$linkselect
$linkselect
Definition: suggestlink.php:369
$i
$i
Definition: suggestlink.php:436
$Language
$Language
Definition: suggestlink.php:34
$ini
$ini
Definition: suggestlink.php:32
$catCount
$catCount
Definition: suggestlink.php:434
$types
$types
Definition: suggestlink.php:475
$type
$type
Definition: suggestlink.php:474
$linkCategoryList
$linkCategoryList
Definition: suggestlink.php:371
$link_select_dict
if(isset( $Action) && $Action=="AttributeList") $link_select_dict
Definition: suggestlink.php:433
$action_value
$action_value
Definition: suggestlink.php:374
$error
$error
Definition: suggestlink.php:35
$no_selected
$no_selected
Definition: suggestlink.php:386
$user
$user
Definition: user/adlist.php:39
$image
$image
Definition: user/articlelist.php:242
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.