summaryrefslogtreecommitdiff
path: root/common_methods.php
blob: 4e868356f69eb7c5ee8bf5d4560d56bc9b0d98fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<?php

/* Common Drupal methods definitons using in Artisteer theme export */

/**
 * Generate the HTML representing a given menu with Artisteer style.
 *
*/
function nuvemdario_menu_worker($content = NULL, $show_sub_menus, $menu_class) {
  if (!$content) {
    return '';
  }

  $output = $content;
  // used to support Menutrails module
  $output = str_replace("active-trail", "active-trail active", $output);
  
  $empty_str = '';
  $menu_str = ' class="menu"';
  if(strpos($output, $menu_str) !== FALSE) {
    $pattern = '/class="menu"/i';
    $replacement = 'class="'. $menu_class .'"';
    $output = preg_replace($pattern, $replacement, $output, 1);
    $output = str_replace($menu_str, $empty_str, $output);
  }

  if (class_exists('DOMDocument')) {
    $output = nuvemdario_menu_xml_parcer($output, $show_sub_menus, $menu_class);
    /* Support Block Edit Link module */
	  $output = str_replace('<!DOCTYPE root>', $empty_str, $output);
  }
  else {
    $output = preg_replace('~(<a [^>]*>)([^<]*)(</a>)~', '$1<span class="l"></span><span class="r"></span><span class="t">$2</span>$3', $output);
  }
  
  return $output;
}

function nuvemdario_menu_xml_parcer($content, $show_sub_menus, $menu_class) {
  $parent_id = $menu_class . '-id';

  $doc = nuvemdario_xml_document_creator($content, $parent_id);
  if ($doc === FALSE) {
	  return $content; // An error occurred while reading XML content
  }

  $parent = $doc->documentElement;
  $elements = $parent->childNodes;
  $ul_elements = $doc->getElementsByTagName("ul");
  $ul_element = NULL;
  foreach($ul_elements as $ul_element) {
		// First ul element with css-class b2-hmenu or b2-vmenu
    if (($ul_element->getAttribute('class') == "b2-vmenu") || ($ul_element->getAttribute('class') == "b2-hmenu"))
		  break;
    continue;
  }

  if ($ul_element == NULL) return $content;
  $ul_children = nuvemdario_menu_style_parcer($doc, $ul_element->childNodes, $show_sub_menus);

  $parent->appendChild($ul_element);
  while ($ul_element->previousSibling)
    $parent->removeChild($ul_element->previousSibling);

  return html_entity_decode($doc->saveHTML(), ENT_NOQUOTES, "UTF-8");
}

function nuvemdario_xml_document_creator($content, $parent_id) {
  $old_error_handler = set_error_handler('nuvemdario_handle_xml_error');
  $dom = new DOMDocument();
  /* Support Block Edit Link module */
  $doc_content = <<< XML
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
<!ENTITY nbsp "&#160;">
]>
<div id="$parent_id">$content</div>
XML;
 
  $dom->loadXml($doc_content);   
  restore_error_handler();
  return $dom;
}

function nuvemdario_handle_xml_error($errno, $errstr, $errfile, $errline) {
  if ($errno==E_WARNING && (substr_count($errstr,"DOMDocument::loadXML()")>0))
   return false; // An error occurred while reading XML content
  else 
    return true; // Successful
}

function nuvemdario_menu_style_parcer($doc, $elements, $show_sub_menus) {
  $parentNodes_to_delete = array();
  $childNodes_to_delete = array();
  foreach ($elements as $element) {
    if (is_a($element, "DOMElement") && ($element->tagName == "li")) {
      $children = $element->childNodes;
      $parent_class = $element->getAttribute("class");
      $is_parent_class_active = strpos($parent_class, "active") !== FALSE;

      foreach ($children as $child) {
        if (is_a($child, "DOMElement") && ($child->tagName == "a")) {
          $caption = $child->nodeValue;
          if (empty($caption) || $caption=='test') {
            $childNodes_to_delete[] = $child;
            $parentNodes_to_delete[] = $element;
            break;
          }

          $child->nodeValue = "";
          if ($is_parent_class_active) {
            $child->setAttribute("class", $child->getAttribute("class").' active');
          }

          $spanL = $doc->createElement("span");
          $spanL->setAttribute("class", "l");
          //$spanL->nodeValue = "&nbsp;";
          $child->appendChild($spanL);

          $spanR = $doc->createElement("span");
          $spanR->setAttribute("class", "r");
          //$spanR->nodeValue = "&nbsp;";
          $child->appendChild($spanR);

          $spanT = $doc->createElement("span");
          $spanT->setAttribute("class", "t");
          $spanT->nodeValue = check_plain($caption);
          $child->appendChild($spanT);
        }
        else if (!$show_sub_menus) {
          $childNodes_to_delete[] = $child;
        }
      }
    }
  }

  nuvemdario_remove_elements($childNodes_to_delete);
  nuvemdario_remove_elements($parentNodes_to_delete);
  return $elements;
}

function nuvemdario_remove_elements($elements_to_delete) {
  if (!isset($elements_to_delete)) return;
  foreach($elements_to_delete as $element) {
    if ($element != null) {
      $element->parentNode->removeChild($element);
    }
  }
}

function nuvemdario_node_worker($node) {
  $links_output = nuvemdario_links_woker($node->links);
  $terms_output = nuvemdario_terms_worker($node->taxonomy);

  $output = $links_output;
  if (!empty($links_output) && !empty($terms_output)) {
    $output .= '&nbsp;|&nbsp;';
  }
  $output .= $terms_output;
  return $output;
}

/*
 * Split out taxonomy terms by vocabulary.
 *
 * @param $terms
 *   An object providing all relevant information for displaying terms:
 *
 * @ingroup themeable
 */
function nuvemdario_terms_worker($terms) {
  $result = '';
$terms = nuvemdario_get_terms_D7($content);
  if (!empty($terms)) {
  ob_start();?>
  <img class="b2-metadata-icon" src="<?php echo nuvemdario_get_full_path_to_theme(); ?>/images/posttagicon.png" width="16" height="16" alt="" /> <?php
  $result .= ($result == '') ? ob_get_clean() : '&nbsp;|&nbsp;' . ob_get_clean();
  $result .= '<div class="b2-tags">' . render($terms) . '</div>';
  }
  
  return $result;
}

/**
 * Return a themed set of links.
 *
 * @param $links
 *   A keyed array of links to be themed.
 * @param $attributes
 *   A keyed array of attributes
 * @return
 *   A string containing an unordered list of links.
 */
function nuvemdario_links_woker($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (!empty($links)) {
    $output = '';

    $num_links = count($links);
    $index = 0;

    foreach ($links as $key => $link) {
      $class = $key;
      if (strpos ($class, "read_more") !== FALSE) {
        continue;
      }

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
      }
      else {
        $link['attributes']['class'] = $key;
      }

      // Add first and last classes to the list of links to help out themers.
      $extra_class = '';
      if ($index == 1) {
        $extra_class .= 'first ';
      }
      if ($index == $num_links) {
        $extra_class .= 'last ';
      }

      $link_output = nuvemdario_get_html_link_output($link);
      if (!empty($class)) {
if (strpos ($key, "comment") !== FALSE) {
        
          if ($index > 0 && !empty($link_output) && !empty($output)) {
          $output .= '&nbsp;|&nbsp;';
        }
        ob_start();?>
        <img class="b2-metadata-icon" src="<?php echo nuvemdario_get_full_path_to_theme(); ?>/images/postcommentsicon.png" width="16" height="16" alt="" /> <?php
        $output .= ob_get_clean();
        $output .= $link_output;
        $index++;
        continue;
        }
        
if ($index > 0 && !empty($link_output) && !empty($output)) {
          $output .= '&nbsp|&nbsp';
        }
        ob_start();?>
        <img class="b2-metadata-icon" src="<?php echo nuvemdario_get_full_path_to_theme(); ?>/images/postcategoryicon.png" width="16" height="16" alt="" /> <?php
        $output .= ob_get_clean();
        $output .= $link_output;
        $index++;
        
      }
      else {
        $output .= '&nbsp;|&nbsp;' . $link_output;
        $index++;
      }
    }
  }

  return $output;
}

function nuvemdario_get_html_link_output($link) {
  $output = '';
  // Is the title HTML?
  $html = isset($link['html']) ? $link['html'] : NULL;

  // Initialize fragment and query variables.
  $link['query'] = isset($link['query']) ? $link['query'] : NULL;
  $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

  if (isset($link['href'])) {
    if (get_drupal_version() == 5) {
      $output = l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
    }
    else {
      $output = l($link['title'], $link['href'], array('language' => $link['language'], 'attributes'=>$link['attributes'], 'query'=>$link['query'], 'fragment'=>$link['fragment'], 'absolute'=>FALSE, 'html'=>$html));
    }
  }
  else if ($link['title']) {
    if (!$html) {
      $link['title'] = check_plain($link['title']);
    }
    $output = $link['title'];
  }

  return $output;
}

function nuvemdario_content_replace($content) {
  $first_time_str = '<div id="first-time"';
  $article_str = ' class="b2-article"';
  $pos = strpos($content, $first_time_str);
  if($pos !== FALSE)
  {
    $output = str_replace($first_time_str, $first_time_str . $article_str, $content);
    $output = <<< EOT
<div class="b2-post">
        <div class="b2-post-body">
    <div class="b2-post-inner b2-article">
    
<div class="b2-postcontent">
    
      $output

    </div>
    <div class="cleared"></div>
    

    </div>
    
    		<div class="cleared"></div>
        </div>
    </div>
    
EOT;
  }
  else 
  {
    $output = $content;
  }
  return $output;
}

function nuvemdario_placeholders_output($var1, $var2, $var3) {
  $output = '';
  if (!empty($var1) && !empty($var2) && !empty($var3)) {
    $output .= <<< EOT
      <table class="position" cellpadding="0" cellspacing="0" border="0">
        <tr valign="top">
          <td class="third-width">$var1</td>
          <td class="third-width">$var2</td>
          <td>$var3</td>
        </tr>
      </table>
EOT;
  }
  else if (!empty($var1) && !empty($var2)) {
    $output .= <<< EOT
      <table class="position" cellpadding="0" cellspacing="0" border="0">
        <tr valign="top">
          <td class="third-width">$var1</td>
          <td>$var2</td>
        </tr>
      </table>
EOT;
  }
  else if (!empty($var2) && !empty($var3)) {
    $output .= <<< EOT
      <table class="position" cellpadding="0" cellspacing="0" border="0">
        <tr valign="top">
          <td class="two-thirds-width">$var2</td>
          <td>$var3</td>
        </tr>
      </table>
EOT;
  }
  else if (!empty($var1) && !empty($var3)) {
    $output .= <<< EOT
      <table class="position" cellpadding="0" cellspacing="0" border="0">
        <tr valign="top">
          <td class="half-width">$var1</td>
          <td>$var3</td>
        </tr>
      </table>
EOT;
  }
  else {
    if (!empty($var1)) {
      $output .= <<< EOT
        <div id="var1">$var1</div>
EOT;
    }
    if (!empty($var2)) {
      $output .= <<< EOT
        <div id="var1">$var2</div>
EOT;
    }
    if (!empty($var3)) {
      $output .= <<< EOT
        <div id="var1">$var3</div>
EOT;
    }
  }

  return $output;
}

function nuvemdario_get_sidebar($sidebar, $vnavigation, $class) {
  $result = 'b2-layout-cell ';
  if (empty($sidebar) && empty($vnavigation)) {
    $result .= 'b2-content';
  }
  else {
    $result .= $class;
  }

  $output = '<div class="'.$result.'">'.render($vnavigation) . render($sidebar).'</div>'; 
  return $output;
}

function nuvemdario_get_content_cell_style($left, $vnav_left, $right, $vnav_right, $content) {
  return 'b2-layout-cell b2-content'; 
}

function nuvemdario_submitted_worker($date, $author) {
  $output = '';
  if ($date != '') {
ob_start();?>
    <img class="b2-metadata-icon" src="<?php echo nuvemdario_get_full_path_to_theme(); ?>/images/postdateicon.png" width="16" height="16" alt="" /> <?php
    $output .= ob_get_clean();
    $output .= $date;
    
  }
  if ($author != '') {
ob_start();?>
    <img class="b2-metadata-icon" src="<?php echo nuvemdario_get_full_path_to_theme(); ?>/images/postauthoricon.png" width="16" height="16" alt="" /> <?php if ($output != '') {
      $output .= '&nbsp;|&nbsp;';
    }
    $output .= ob_get_clean();
    $output .= $author;
    
  }
  return $output;
}

function is_nuvemdario_links_set($links) {
  $size = sizeof($links);
  if ($size == 0) {
    return FALSE;
  }

  //check if there's "Read more" in node links only  
  $read_more_link = $links['node_read_more'];
  if ($read_more_link != NULL && $size == 1) {
    return FALSE;
  }

  return TRUE;
}

/**
 * Method to define node title output.
 *
*/
function nuvemdario_node_title_output($title, $node_url, $page) {
  $output = '';
  if (!$page)
    $output = '<a href="' . $node_url . '" title="' . $title . '">' . $title . '</a>';
  else
    $output = $title;
  return $output;
}

function nuvemdario_vmenu_output($subject, $content) {
  if (empty($content))
    return;

  $output =	nuvemdario_menu_worker($content, true, 'b2-vmenu');
  $bvm = "<div class=\"b2-vmenublock\">\r\n    <div class=\"b2-vmenublock-body\">\r\n";
  $bvmt = "<div class=\"b2-vmenublockheader\">\r\n    <div class=\"l\"></div>\r\n    <div class=\"r\"></div>\r\n    <h3 class=\"t subject\">";
  $evmt = "</h3>\r\n</div>\r\n";
  $bvmc = "<div class=\"b2-vmenublockcontent\">\r\n    <div class=\"b2-vmenublockcontent-body\">\r\n<div class=\"content\">\r\n";
  $evmc = "\r\n</div>\r\n		<div class=\"cleared\"></div>\r\n    </div>\r\n</div>\r\n";
  $evm = "\r\n		<div class=\"cleared\"></div>\r\n    </div>\r\n</div>\r\n";
  echo $bvm;
  if ('' != $bvmt && '' != $evmt && !empty($subject)) {
    echo $bvmt;
    echo $subject;
    echo $evmt;
  }
  echo $bvmc;
  echo $output;
  echo $evmc;
  echo $evm;
}