Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
data_source_xml_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/data_source/data_source/data_source_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
56  function paintFeed(&$asset, &$o, $prefix)
57  {
58  $url = html_entity_decode($asset->attr('url'));
59  $wa = $asset->writeAccess('attributes');
60  if ($wa) {
61  text_box($prefix.'feed_url', $url, 30);
62  return TRUE;
63  } else {
64  echo $url;
65  }
66  return FALSE;
67 
68  }//end paintFeed()
69 
70 
81  function processFeed(&$asset, &$o, $prefix)
82  {
83  $url = htmlentities($asset->attr('url'));
84  if (isset($_POST[$prefix.'feed_url'])) {
85  $link = htmlentities(trim($_POST[$prefix.'feed_url']));
86  if (strcasecmp($url, $link) != 0) {
87  $asset->setAttrValue('url', $link);
88  return TRUE;
89  }
90  }
91  return FALSE;
92 
93  }//end processFeed()
94 
95 
106  function paintTags(&$asset, &$o, $prefix)
107  {
108  $tags = unserialize(html_entity_decode($asset->attr('tags')));
109  $wa = $asset->writeAccess('attributes');
110  if ($wa) {
111  text_area($prefix.'tag_names', !empty($tags) ? implode(',', $tags) : '', 40);
112  return TRUE;
113  } else {
114  echo !empty($tags) ? implode(',', $tags) : '';
115  }
116  return FALSE;
117 
118  }//end paintTags()
119 
120 
131  function processTags(&$asset, &$o, $prefix)
132  {
133  $current_tags = htmlentities($asset->attr('tags'));
134  if (isset($_POST[$prefix.'tag_names'])) {
135  $posted_tags = htmlentities($_POST[$prefix.'tag_names']);
136  if (strcasecmp($current_tags, $posted_tags) != 0) {
137  $exploded = explode(',', $posted_tags);
138  // trim excess whitespace for accuracy
139  array_walk($exploded, Array(&$this, '_trimValue'));
140  $asset->setAttrValue('tags', serialize($exploded));
141  return TRUE;
142  }
143  }
144  return FALSE;
145 
146  }//end processTags()
147 
148 
159  function paintTagAttributes(&$asset, &$o, $prefix)
160  {
161  $tags = unserialize(html_entity_decode($asset->attr('tags')));
162  $tag_attributes = unserialize(html_entity_decode($asset->attr('tag_attributes')));
163  $wa = $asset->writeAccess('attributes');
164  ?>
165  <table class="sq-backend-table">
166  <tr>
167  <th><?php echo translate('tag');?></th>
168  <th><?php echo translate('attributes');?></th>
169  </tr>
170  <?php
171  for ($i=0; $i<count($tags); $i++) {
172  ?>
173  <tr>
174  <td><?php echo $tags[$i];?> </td>
175  <?php if ($wa) { ?>
176  <td><?php text_box($prefix.'tagattr_'.$i, isset($tag_attributes[$tags[$i]]) ? implode(',', $tag_attributes[$tags[$i]]) : '', 30); ?> </td>
177  <?php } else { ?>
178  <td><?php echo isset($tag_attributes[$tags[$i]]) ? implode(',', $tag_attributes[$tags[$i]]) : ''; ?> </td>
179  <?php } ?>
180  </tr>
181  <?php
182  }
183  ?>
184  </table>
185  <?php
186 
187  return $wa;
188 
189  }//end paintTagAttributes()
190 
191 
202  function processTagAttributes(&$asset, &$o, $prefix)
203  {
204  $i = 0;
205  $tags = unserialize(html_entity_decode($asset->attr('tags')));
206  $results = Array();
207  foreach ($_POST as $tag => $attributes) {
208  if ($tag === $prefix.'tagattr_'.$i) {
209  $exploded = explode(',', htmlentities($attributes));
210  // trim excess whitespace for accuracy
211  array_walk($exploded, Array(&$this, '_trimValue'));
212  if (isset($tags[$i])) $results[$tags[$i]] = $exploded;
213  $i++;
214  }
215  }
216  if (!empty($results)) {
217  $asset->setAttrValue('tag_attributes', serialize($results));
218  return TRUE;
219  } else {
220  return FALSE;
221  }
222 
223  }//end processTagAttributes()
224 
225 
234  function _trimValue(&$value)
235  {
236  $value = trim($value);
237 
238  }//end _trimValue()
239 
240 
251  function paintCDATATags(&$asset, &$o, $prefix)
252  {
253  $tags = unserialize(html_entity_decode($asset->attr('cdata_tags')));
254  $wa = $asset->writeAccess('attributes');
255  if ($wa) {
256  text_area($prefix.'cdata_tag_names', !empty($tags) ? implode(',', $tags) : '', 40);
257  return TRUE;
258  } else {
259  echo !empty($tags) ? implode(',', $tags) : '';
260  }
261  return FALSE;
262 
263  }//end paintTags()
264 
265 
276  function processCDATATags(&$asset, &$o, $prefix)
277  {
278  $current_tags = htmlentities($asset->attr('cdata_tags'));
279  if (isset($_POST[$prefix.'cdata_tag_names'])) {
280  $posted_tags = htmlentities($_POST[$prefix.'cdata_tag_names']);
281 
282  if (strcasecmp($current_tags, $posted_tags) != 0) {
283  $exploded = explode(',', $posted_tags);
284  // trim excess whitespace for accuracy
285  array_walk($exploded, Array(&$this, '_trimValue'));
286  $asset->setAttrValue('cdata_tags', serialize($exploded));
287  // overwrite the cache with this new XML feed url
288  $asset->setResultSet(Array(), $asset->attr('url'));
289  $asset->getResultSet($asset->attr('url'));
290  return TRUE;
291  }
292  }
293  return FALSE;
294 
295  }//end processTags()
296 
297 
298 }//end class
299 
300 ?>