Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
url.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_attribute.inc';
19 require_once SQ_FUDGE_PATH.'/general/general.inc';
20 
33 {
34 
35 
43  function Asset_Attribute_Url($attributeid=0, $value=null)
44  {
45  $this->Asset_Attribute($attributeid, $value);
46 
47  // set default edit parameters
48  $this->_edit_params['width'] = 0;
49  $this->_edit_params['protocols'] = Array('http');
50 
51  }//end constructor
52 
53 
62  function paintEditParams($prefix, $write_access=false)
63  {
64  echo '<b>URL Attribute " '.ucwords(str_replace('_', ' ', $this->name)).' " ('.$this->name.')</b><br />';
65  ?>
66  <table class="sq-backend-table">
67  <tr>
68  <td class="sq-backend-section-heading" style="width: 100px;"><?php echo translate('width'); ?></td>
69  <td class="sq-backend-table-cell">
70  <?php
71  if ($write_access) {
72  text_box($prefix.'_'.$this->name.'_width', $this->_edit_params['width']);
73  } else {
74  echo $this->_edit_params['width'];
75  }
76  ?>
77  </td>
78  </tr>
79  <tr>
80  <td class="sq-backend-section-heading" style="width: 100px;"><?php echo translate('protocols'); ?></td>
81  <td class="sq-backend-table-cell">
82  <?php
83  if ($write_access) {
84  text_box($prefix.'_'.$this->name.'_height', implode(',', $this->_edit_params['protocols']));
85  } else {
86  echo $this->_edit_params['protocols'];
87  }
88  ?>
89  </td>
90  </tr>
91  </table>
92  <?php
93 
94  }//end paintEditParams()
95 
96 
105  function processEditParams($prefix)
106  {
107  // reading submitted vars
108  if (!empty($_POST[$prefix.'_'.$this->name.'_width'])) {
109  $this->_edit_params['width'] = $_POST[$prefix.'_'.$this->name.'_width'];
110  }
111 
112  if (!empty($_POST[$prefix.'_'.$this->name.'_protocols'])) {
113  $protocols = str_replace(' ', '', $_POST[$prefix.'_'.$this->name.'_protocols']);
114  $this->_edit_params['protocols'] = explode(',', $protocols);
115  }
116 
117  $values = Array();
118  $values['width'] = $this->_edit_params['width'];
119  $values['protocols'] = $this->_edit_params['protocols'];
120 
121  return $values;
122 
123  }//end processEditParams()
124 
125 
135  function setEditParams(&$node)
136  {
137  if (!parent::setEditParams($node)) return false;
138 
139  if (isset($node->attributes()->width)) {
140  $this->_edit_params['width'] = (int) $node->attributes()->width;
141  }
142  if (isset($node->attributes()->protocols)) {
143  $protocols = str_replace(' ', '', (string)$node->attributes()->protocols);
144  $this->_edit_params['protocols'] = explode(',', $protocols);
145  }
146 
147  return true;
148 
149  }//end setEditParams()
150 
151 
161  function paint($prefix, $read_only=false)
162  {
163  if ($read_only) {
164  echo htmlspecialchars(nl2br($this->value));
165  return;
166  }
167 
168  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
169 
170  url_tester($prefix, $this->value, $this->_edit_params['protocols'], $this->_edit_params['width']);
171 
172  return true;
173 
174  }//end paint()
175 
176 
185  function process($prefix)
186  {
187  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
188 
189  if (!isset($_REQUEST[$prefix.'_url'])) return false;
190  if (!isset($_REQUEST[$prefix.'_protocol'])) return false;
191 
192  $value = get_url_tester_url($prefix);
193  if ($this->value != $value && $this->setValue($value)) {
194  $this->processed = true;
195  } else {
196  $this->processed = false;
197  }
198 
199  }//end process()
200 
201 
210  function validateValue(&$value)
211  {
212  $new_value = (string) $value;
213  if ($new_value != $value) return false;
214  $value = $new_value;
215  return true;
216 
217  }//end validateValue()
218 
219 
220 }//end class
221 
222 ?>