ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilExternalFeedBlock.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Block/classes/class.ilCustomBlock.php");
5
13{
17 protected $db;
18
22 protected $log;
23
24
25 protected $feed_url;
26
32 public function __construct($a_id = 0)
33 {
34 global $DIC;
35
36 $this->db = $DIC->database();
37 $this->log = $DIC["ilLog"];
38 if ($a_id > 0) {
39 $this->setId($a_id);
40 $this->read();
41 }
42 }
43
49 public function setFeedUrl($a_feed_url)
50 {
51 $this->feed_url = $a_feed_url;
52 }
53
59 public function isFeedUrlLocal($url)
60 {
61 $host = strtolower(parse_url($url, PHP_URL_HOST));
62 if (is_int(strpos($url, ".localhost")) || trim($host) == "localhost") {
63 return true;
64 }
65 $ip = gethostbyname($host);
66
67 $res = filter_var(
68 $ip,
69 FILTER_VALIDATE_IP,
70 FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
71 );
72 if (in_array($res, [false, ""])) {
73 return true;
74 }
75 return false;
76 }
77
83 public function getFeedUrl()
84 {
85 return $this->feed_url;
86 }
87
92 public function create()
93 {
96
97 parent::create();
98
99 $query = "INSERT INTO il_external_feed_block (" .
100 " id" .
101 ", feed_url" .
102 " ) VALUES (" .
103 $ilDB->quote($this->getId(), "integer")
104 . "," . $ilDB->quote($this->getFeedUrl(), "text") . ")";
105 $ilDB->manipulate($query);
106 }
107
112 public function read()
113 {
115
116 parent::read();
117
118 $query = "SELECT * FROM il_external_feed_block WHERE id = " .
119 $ilDB->quote($this->getId(), "integer");
120 $set = $ilDB->query($query);
121 $rec = $ilDB->fetchAssoc($set);
122
123 $this->setFeedUrl($rec["feed_url"]);
124 }
125
130 public function update()
131 {
133
135
136 $query = "UPDATE il_external_feed_block SET " .
137 " feed_url = " . $ilDB->quote($this->getFeedUrl(), "text") .
138 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
139
140 $ilDB->manipulate($query);
141 }
142
147 public function delete()
148 {
150
151 parent::delete();
152
153 $query = "DELETE FROM il_external_feed_block" .
154 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
155
156 $ilDB->manipulate($query);
157 }
158}
An exception for terminatinating execution or to throw for unit testing.
This is the super class of all custom blocks.
setId($a_id)
Set Id.
Custom block for external feeds.
__construct($a_id=0)
Constructor.
isFeedUrlLocal($url)
Check if feed url is local.
update()
Update item in database.
setFeedUrl($a_feed_url)
Set FeedUrl.
read()
Read item from database.
update($pash, $contents, Config $config)
$query
$url
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB