Umfragen
label.class.php
Go to the documentation of this file.
1 <?php
2 
3 require_once(INCLUDE_DIR."/htmlpurifier-4.4.0/HTMLPurifier.standalone.php");
4 
5 class label extends container implements iWidget, output_widget{
6 
7  public $typ = "label";
8  public $direct_result = true;
9 
10  public $child_widgets_whitelist = array("label");
11  public $child_options_whitelist = array();
12 
13  function set_value($value){
14  if($value != ""){
15  $config = HTMLPurifier_Config::createDefault();
16  //$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
17  // allow iframe from youtube
18  $config->set('HTML.SafeIframe',true);
19  $config->set('URI.SafeIframeRegexp','%^http://www.youtube.com/embed/%');
20  // allowed HTML tags
21  $config->set('HTML.Allowed', 'abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, dl, dt,
22  em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup,
23  u, ul, var,h1 ,h2, h3, h4, h5, h6, span, div,br,
24  a[href|target],
25  img[src|alt|height|width],
26  video[preload|src|height|width|controls|autoplay|loop|poster],
27  iframe[src|width|height],
28  table[border|frame|cellpadding|cellspacing|rules],
29  tr[valign|align],
30  td[valign|align|scope],
31  th[valign|align|scope],
32  *[style],
33  *[title]' );
34  // allowed HTML attributes
35  //$config->set('HTML', 'AllowedAttributes', '*.style,*.title,a.href');
36  // allow CSS properties
37  $config->set('CSS.AllowedProperties',array(
38  'text-decoration','text-align','font-family','font-size',
39  'padding-left','padding-right','padding-top','padding-bottom','padding',
40  'margin-left','margin-right','margin-top','margin-bottom','margin',
41  'border-left','border-right','border-top','border-bottom','border','border-collapse','border-color','border-style',
42  'color','background-color','border','border-radius','box-shadow',
43  'float','position','width','height','left','top','right','bottom'
44  ));
45  // enable CSS position attribute
46  $config->set('CSS.Trusted',true);
47  // enable target="_blank"
48  $config->set('Attr.AllowedFrameTargets', array('_blank'));
49 
50  // add custom definition for html5 video tag
51  $config->set('HTML.DefinitionID', 'video-custom.html');
52  $config->set('HTML.DefinitionRev', 1);
53  //$config->set('Cache.DefinitionImpl', null); // remove this later!
54 
55  // if cached version exists .. see http://htmlpurifier.org/docs/enduser-customize.html#optimized
56  if ($def = $config->maybeGetRawHTMLDefinition() ){
57  $videotag = $def->addElement(
58  'video', // name
59  'Block', // content set
60  'Flow', // allowed children
61  'Common', // attribute collection
62  array( // attributes
63  'autoplay' => 'Bool',
64  'controls' => 'Bool',
65  'loop' => 'Bool',
66  'muted' => 'Bool',
67  'preload' => 'Enum#auto,metadata,none',
68  'height' => 'Pixels',
69  'width' => 'Pixels',
70  'poster' => 'URI',
71  'src' => 'URI'
72  )
73  );
74  // prevent video tag in video tag .. useful?
75  $videotag->excludes = array('video' => true);
76 
77  }
78 
79  // finally clean and save
80  $purifier = new HTMLPurifier($config);
81  $clean_html = $purifier->purify($value);
82  $this->value = $clean_html;
83  return true;
84  }
85  return false;
86  }
87 
88  public function set_default_values($db){
89  $this->set_dispName("namenloser Text");
90  }
91 
92 
93  public function display_label_edit(){
94  echo '<script language="javascript" type="text/javascript" src="'.APP_ROOT.'/JS/tiny_mce/tiny_mce.js"></script>';
95  echo '<script language="javascript" type="text/javascript">';
96  echo 'tinyMCE.init({
97  theme : "advanced",
98  plugins : "media,layer,table,contextmenu",
99  content_css: "'.APP_ROOT.'/CSS/tinyMCE.css",
100  language: "de",
101  mode: "exact",
102  theme_advanced_resizing : true,
103  elements : "label_text",
104  theme_advanced_toolbar_location : "top",
105  theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
106  + "justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,"
107  + "bullist,numlist,outdent,indent,"
108  + "|,forecolor,backcolor",
109  theme_advanced_buttons2 : "link,unlink,anchor,image,media,separator,"
110  +"undo,redo,cleanup,code,separator,sub,sup,charmap,|,insertlayer,moveforward,movebackward,absolute,",
111  theme_advanced_buttons3 : "tablecontrols",
112  height:"400px",
113  width:"100%",
114  relative_urls : false,
115  remove_script_host : false
116  });';
117  echo '</script>';
118  echo "<textarea rows='20' cols='100' name='label_text' id='label_text'>{$this->value}</textarea>";
119  }
120 
121  public function display_widget_list_edit(){
122  if( sizeof($this->widget_list) != 0 ){
123  echo "<table class='table_1'>";
124  echo "<tr><th>ID</th> <th>Name</th> <th>Link zum einbauen</th> <th>Bearbeiten</th></tr>";
125  foreach($this->widget_list as $widget){
126  echo "<tr>";
127  echo "<td>{$widget->ID}</td>";
128  echo "<td>{$widget->dispName}</td>";
129  echo "<td><a href='../text.php?pollID={$this->pollID}&widget={$widget->ID}' target='_blank'>text.php?pollID={$this->pollID}&widget={$widget->ID}</td>";
130  echo "<td>
131  <input type='submit' name='editq_option_ID{$widget->ID}' title='Option Bearbeiten' value='' tabindex='-1' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/preferences-system.png );background-repeat:no-repeat;width:26px;height:26px;' />
132  <input type='submit' name='addq_option_ID{$widget->ID}' title='Option Einfügen' value='' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/list-add.png );background-repeat:no-repeat;width:26px;height:26px;' />
133  <input type='submit' name='rmq_option_ID{$widget->ID}' title='Option Löschen' value='' tabindex='-1' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/edit-delete.png );background-repeat:no-repeat;width:26px;height:26px;' />
134  </td>";
135  echo "</tr>";
136  }
137  echo "</table>";
138  }else{
139  echo "<input type='submit' name='addq_option_ID{$this->ID}' title='Option Einfügen' value='' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/list-add.png );background-repeat:no-repeat;width:26px;height:26px;' />";
140  }
141  }
142 
143  public function handle_label_edit(){
144  if( isset($_POST["label_text"]) ){
145  if( !$this->set_value($_POST["label_text"]) ){
146  return "Keinen Text eingetragen.";
147  }
148  }else{
149  return "Keinen Text eingetragen.";
150  }
151  return true;
152  }
153 
154  public function save_label($db){
155  return $db->update_widget_field($this,"value",$this->value);
156  }
157 
158 
159  function display_edit(){
160  $lasted="";
161  if( (isset($_SESSION["last_widget_edit"])) AND ($_SESSION["last_widget_edit"] == $this->ID) ){
162  echo "<script type='text/javascript'>
163  $(document).ready(function(){
164  window.scrollBy(0,-150);
165  });
166  </script>";
167 
168  $lasted = " widget_last_edit";
169  unset( $_SESSION["last_widget_edit"] );
170  }
171 
172  echo "<div class='widget_container$lasted' style='position:relative;z-index:100;background-color:rgba(255,255,255,0.5)' id='widget_container_{$this->ID}' >";
173  echo "<div class='widget_edit_toolbar'>";
174  echo "<a href='edit.php?pollID={$this->pollID}&amp;widgetID={$this->ID}' title='Bearbeiten' ><img src='".APP_ROOT."/icons/22/preferences-system.png' alt='edit'/></a>";
175  echo "<a href='action.widget.php?pollID={$this->pollID}&amp;widgetID={$this->ID}&amp;action=duplicate_widget' title='Kopieren'><img src='".APP_ROOT."/icons/22/edit-copy.png' alt='remove'/></a>";
176  echo "<a href='action.widget.php?pollID={$this->pollID}&amp;widgetID={$this->ID}&amp;action=rmwid' style='margin-left:0px' title='Löschen' ><img src='".APP_ROOT."/icons/22/edit-delete.png' alt='remove'/></a>";
177  echo "<span style='margin-left:7px'>&nbsp;</span>";
178  echo "<a href='action.widget.php?pollID={$this->pollID}&amp;widgetID={$this->ID}&amp;action=mvup' title='weiter nach Oben schieben'><img src='".APP_ROOT."/icons/22/go-up.png' alt='mv up'/></a>";
179  echo "<a href='action.widget.php?pollID={$this->pollID}&amp;widgetID={$this->ID}&amp;action=mvdwn' title='weiter nach Unten schieben'><img src='".APP_ROOT."/icons/22/go-down.png' alt='mv down'/></a>";
180  echo "</div>";
181  echo "<a href='edit.php?pollID={$this->pollID}&amp;widgetID={$this->ID}' class='widget_edit_link' id='widget{$this->ID}'>&nbsp;</a>";
182 
183  echo "<div style='margin:0px;pading:0px;position:relative;'>{$this->value}</div>";
184  echo "</div>";
185  }
186 
187 
188  function display(){
189  echo "<div class='label_widget' style='margin:0px;pading:0px;position:relative;'>{$this->value}</div>";
190  }
191 
192 
193  function handle_inpt(){
194  return true;
195  }
196 
197 }
198 // ! no ending newLine
199 ?>