ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilHtmlImageMapFileInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Form/classes/class.ilFileInputGUI.php';
5require_once 'Modules/TestQuestionPool/classes/class.assAnswerImagemap.php';
6
11{
15 protected $shapes = array();
16
20 public function checkInput()
21 {
25 global $DIC;
26 $lng = $DIC['lng'];
27
28 if (!parent::checkInput()) {
29 return false;
30 }
31
32 $tmp_file_name = $_FILES[$this->getPostVar()]['tmp_name'];
33 if (strlen($tmp_file_name) == 0) {
34 return true;
35 }
36
37 if (!is_readable($tmp_file_name)) {
38 $this->setAlert($lng->txt('ass_imap_map_file_not_readable'));
39 return false;
40 }
41
42 $contents = file_get_contents($tmp_file_name);
43 $matches = null;
44 if (
45 !preg_match_all('/<area(.+)>/siU', $contents, $matches) ||
46 !is_array($matches) ||
47 !isset($matches[1]) ||
48 count($matches[1]) == 0
49 ) {
50 $this->setAlert($lng->txt('ass_imap_no_map_found'));
51 return false;
52 }
53
54 for ($i = 0; $i < count($matches[1]); $i++) {
55 preg_match("/alt\s*=\s*\"(.*)\"\s*/siU", $matches[1][$i], $alt);
56 preg_match("/coords\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $coords);
57 preg_match("/shape\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $shape);
58
59 if (!$this->verifyArea($coords, $shape)) {
60 $this->setAlert($lng->txt('ass_imap_no_map_found'));
61 return false;
62 }
63
64 $this->shapes[] = new ASS_AnswerImagemap($alt[1], 0.0, $i, $coords[1], $shape[1]);
65 }
66
67 return true;
68 }
69
70 protected function verifyArea($coords, $shape)
71 {
72 if (!in_array(strtolower($shape[1]), assImagemapQuestion::AVAILABLE_SHAPES)) {
73 return false;
74 }
75
76 $coords_array = explode(',', $coords[1]);
77 foreach ($coords_array as $coord) {
78 if (!is_numeric($coord)) {
79 return false;
80 }
81 }
82
83 return true;
84 }
85
89 public function getShapes()
90 {
91 return $this->shapes;
92 }
93}
Class for true/false or yes/no answers.
An exception for terminatinating execution or to throw for unit testing.
This class represents a file property in a property form.
checkInput()
Check input, strip slashes etc.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
Class ilHtmlImageMapFileInputGUI.
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24