ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_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  {
94  $ilDB = $this->db;
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  {
114  $ilDB = $this->db;
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  {
132  $ilDB = $this->db;
133 
134  parent::update();
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  {
149  $ilDB = $this->db;
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 }
update()
Update item in database.
global $DIC
Definition: saml.php:7
setId($a_id)
Set Id.
setFeedUrl($a_feed_url)
Set FeedUrl.
__construct($a_id=0)
Constructor.
isFeedUrlLocal($url)
Check if feed url is local.
Custom block for external feeds.
foreach($_POST as $key=> $value) $res
$query
This is the super class of all custom blocks.
read()
Read item from database.
update($pash, $contents, Config $config)
global $ilDB
$url