PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/sites/all/themes/freethemes4you_polit_01_1/common_methods.php

https://gitlab.com/endomorphosis/superchooseday
PHP | 483 lines | 386 code | 62 blank | 35 comment | 102 complexity | 4b57e556b446377d9e2e82af84da34f0 MD5 | raw file
  1. <?php
  2. /* Common Drupal methods definitons using in FreeThemes4You theme export */
  3. /**
  4. * Generate the HTML representing a given menu with FreeThemes4You style.
  5. *
  6. */
  7. function art_menu_worker($content = NULL, $show_sub_menus, $menu_class) {
  8. if (!$content) {
  9. return '';
  10. }
  11. $output = $content;
  12. // used to support Menutrails module
  13. $output = str_replace("active-trail", "active-trail active", $output);
  14. $empty_str = '';
  15. $menu_str = ' class="menu"';
  16. if(strpos($output, $menu_str) !== FALSE) {
  17. $pattern = '/class="menu"/i';
  18. $replacement = 'class="'. $menu_class .'"';
  19. $output = preg_replace($pattern, $replacement, $output, 1);
  20. $output = str_replace($menu_str, $empty_str, $output);
  21. }
  22. if (class_exists('DOMDocument')) {
  23. $output = art_menu_xml_parcer($output, $show_sub_menus, $menu_class);
  24. /* Support Block Edit Link module */
  25. $output = str_replace('<!DOCTYPE root>', $empty_str, $output);
  26. }
  27. else {
  28. $output = preg_replace('~(<a [^>]*>)([^<]*)(</a>)~', '$1<span class="l"></span><span class="r"></span><span class="t">$2</span>$3', $output);
  29. }
  30. return $output;
  31. }
  32. function art_menu_xml_parcer($content, $show_sub_menus, $menu_class) {
  33. $parent_id = $menu_class . '-id';
  34. try {
  35. $doc = art_xml_loader($content, $parent_id);
  36. }
  37. catch(Exception $e) {
  38. return $content;
  39. }
  40. $parent = $doc->documentElement;
  41. $elements = $parent->childNodes;
  42. $ul_children = NULL;
  43. foreach($elements as $element) {
  44. if (!isset($element) || !(isset($element->tagName)) || $element->tagName != "ul") continue;
  45. $ul_children = $element->childNodes;
  46. break;
  47. }
  48. if ($ul_children == NULL) return $content;
  49. $ul_children = art_menu_style_parcer($doc, $ul_children, $show_sub_menus);
  50. return $doc->saveHTML();
  51. }
  52. function art_xml_loader($content, $parent_id) {
  53. $old_error_handler = set_error_handler('art_handle_xml_error');
  54. $dom = new DOMDocument();
  55. /* Support Block Edit Link module */
  56. $doc_content = <<< XML
  57. <?xml version="1.0" encoding="utf-8"?>
  58. <!DOCTYPE root [
  59. <!ENTITY nbsp "&#160;">
  60. ]>
  61. <div id="$parent_id">$content</div>
  62. XML;
  63. $dom->loadXml($doc_content);
  64. restore_error_handler();
  65. return $dom;
  66. }
  67. function art_handle_xml_error($errno, $errstr, $errfile, $errline) {
  68. if ($errno==E_WARNING && (substr_count($errstr,"DOMDocument::loadXML()")>0))
  69. throw new DOMException($errstr);
  70. else
  71. return false;
  72. }
  73. function art_menu_style_parcer($doc, $elements, $show_sub_menus) {
  74. $parentNodes_to_delete = array();
  75. $childNodes_to_delete = array();
  76. foreach ($elements as $element) {
  77. if (is_a($element, "DOMElement") && ($element->tagName == "li")) {
  78. $children = $element->childNodes;
  79. $parent_class = $element->getAttribute("class");
  80. $is_parent_class_active = strpos($parent_class, "active") !== FALSE;
  81. foreach ($children as $child) {
  82. if (is_a($child, "DOMElement") && ($child->tagName == "a")) {
  83. $caption = $child->nodeValue;
  84. if (empty($caption) || $caption=='test') {
  85. $childNodes_to_delete[] = $child;
  86. $parentNodes_to_delete[] = $element;
  87. break;
  88. }
  89. $child->nodeValue = "";
  90. if ($is_parent_class_active) {
  91. $child->setAttribute("class", $child->getAttribute("class").' active');
  92. }
  93. $spanL = $doc->createElement("span");
  94. $spanL->setAttribute("class", "l");
  95. $spanL->nodeValue = "&nbsp;";
  96. $child->appendChild($spanL);
  97. $spanR = $doc->createElement("span");
  98. $spanR->setAttribute("class", "r");
  99. $spanR->nodeValue = "&nbsp;";
  100. $child->appendChild($spanR);
  101. $spanT = $doc->createElement("span");
  102. $spanT->setAttribute("class", "t");
  103. $spanT->nodeValue = check_plain($caption);
  104. $child->appendChild($spanT);
  105. }
  106. else if (!$show_sub_menus) {
  107. $childNodes_to_delete[] = $child;
  108. }
  109. }
  110. }
  111. }
  112. art_remove_elements($childNodes_to_delete);
  113. art_remove_elements($parentNodes_to_delete);
  114. return $elements;
  115. }
  116. function art_remove_elements($elements_to_delete) {
  117. if (!isset($elements_to_delete)) return;
  118. foreach($elements_to_delete as $element) {
  119. if ($element != null) {
  120. $element->parentNode->removeChild($element);
  121. }
  122. }
  123. }
  124. function art_node_worker($node) {
  125. $links_output = art_links_woker($node->links);
  126. $terms_output = art_terms_worker($node->taxonomy);
  127. $output = $links_output;
  128. if (!empty($links_output) && !empty($terms_output)) {
  129. $output .= '&nbsp;|&nbsp;';
  130. }
  131. $output .= $terms_output;
  132. return $output;
  133. }
  134. /*
  135. * Split out taxonomy terms by vocabulary.
  136. *
  137. * @param $terms
  138. * An object providing all relevant information for displaying terms:
  139. *
  140. * @ingroup themeable
  141. */
  142. function art_terms_worker($terms) {
  143. $output = '';
  144. if (!empty($terms)) {
  145. $links = array();
  146. ob_start();?>
  147. <img class="art-metadata-icon" src="<?php echo get_full_path_to_theme(); ?>/images/posttagicon.png" width="18" height="18" alt="" /> <?php
  148. $output .= ob_get_clean();
  149. $output .= t('Tags: ');
  150. foreach ($terms as $term) {
  151. $links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
  152. }
  153. $output .= implode(', ', $links);
  154. }
  155. return $output;
  156. }
  157. /**
  158. * Return a themed set of links.
  159. *
  160. * @param $links
  161. * A keyed array of links to be themed.
  162. * @param $attributes
  163. * A keyed array of attributes
  164. * @return
  165. * A string containing an unordered list of links.
  166. */
  167. function art_links_woker($links, $attributes = array('class' => 'links')) {
  168. $output = '';
  169. if (!empty($links)) {
  170. $output = '';
  171. $num_links = count($links);
  172. $index = 0;
  173. foreach ($links as $key => $link) {
  174. $class = $key;
  175. if (strpos ($class, "read_more") !== FALSE) {
  176. continue;
  177. }
  178. // Automatically add a class to each link and also to each LI
  179. if (isset($link['attributes']) && isset($link['attributes']['class'])) {
  180. $link['attributes']['class'] .= ' ' . $key;
  181. }
  182. else {
  183. $link['attributes']['class'] = $key;
  184. }
  185. // Add first and last classes to the list of links to help out themers.
  186. $extra_class = '';
  187. if ($index == 1) {
  188. $extra_class .= 'first ';
  189. }
  190. if ($index == $num_links) {
  191. $extra_class .= 'last ';
  192. }
  193. if (!empty($class)) {
  194. if (strpos ($class, "comment") !== FALSE) {
  195. if ($index > 0) {
  196. $output .= '&nbsp;|&nbsp;';
  197. }
  198. ob_start();?>
  199. <img class="art-metadata-icon" src="<?php echo get_full_path_to_theme(); ?>/images/postcommentsicon.png" width="18" height="18" alt="" /> <?php
  200. $output .= ob_get_clean();
  201. $output .= get_html_link_output($link);
  202. $index++;
  203. continue;
  204. }
  205. if ($index > 0) {
  206. $output .= '&nbsp|&nbsp';
  207. }
  208. ob_start();?>
  209. <img class="art-metadata-icon" src="<?php echo get_full_path_to_theme(); ?>/images/postcategoryicon.png" width="18" height="18" alt="" /> <?php
  210. $output .= ob_get_clean();
  211. $output .= get_html_link_output($link);
  212. $index++;
  213. }
  214. else {
  215. $output .= '&nbsp;|&nbsp;' . get_html_link_output($link);
  216. $index++;
  217. }
  218. }
  219. }
  220. return $output;
  221. }
  222. function get_html_link_output($link) {
  223. $output = '';
  224. // Is the title HTML?
  225. $html = isset($link['html']) ? $link['html'] : NULL;
  226. // Initialize fragment and query variables.
  227. $link['query'] = isset($link['query']) ? $link['query'] : NULL;
  228. $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;
  229. if (isset($link['href'])) {
  230. if (get_drupal_version() == 5) {
  231. $output = l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
  232. }
  233. else {
  234. $output = l($link['title'], $link['href'], array('language' => $link['language'], 'attributes'=>$link['attributes'], 'query'=>$link['query'], 'fragment'=>$link['fragment'], 'absolute'=>FALSE, 'html'=>$html));
  235. }
  236. }
  237. else if ($link['title']) {
  238. if (!$html) {
  239. $link['title'] = check_plain($link['title']);
  240. }
  241. $output = $link['title'];
  242. }
  243. return $output;
  244. }
  245. function art_content_replace($content) {
  246. $first_time_str = '<div id="first-time"';
  247. $article_str = ' class="art-article"';
  248. $post_type = $vars['node']->type;
  249. $pos = strpos($content, $first_time_str);
  250. if($pos !== FALSE)
  251. {
  252. $output = str_replace($first_time_str, $first_time_str . $article_str, $content);
  253. $output = <<< EOT
  254. <div id="post-$post_type">
  255. <div class="art-post">
  256. <div class="art-post-body">
  257. <div class="art-post-inner">
  258. <div class="art-postcontent">
  259. $output
  260. </div>
  261. <div class="cleared"></div>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. EOT;
  267. }
  268. else
  269. {
  270. $output = $content;
  271. }
  272. return $output;
  273. }
  274. function art_placeholders_output($var1, $var2, $var3) {
  275. $output = '';
  276. if (!empty($var1) && !empty($var2) && !empty($var3)) {
  277. $output .= <<< EOT
  278. <table class="position" cellpadding="0" cellspacing="0" border="0">
  279. <tr valign="top">
  280. <td class="third-width">$var1</td>
  281. <td class="third-width">$var2</td>
  282. <td>$var3</td>
  283. </tr>
  284. </table>
  285. EOT;
  286. }
  287. else if (!empty($var1) && !empty($var2)) {
  288. $output .= <<< EOT
  289. <table class="position" cellpadding="0" cellspacing="0" border="0">
  290. <tr valign="top">
  291. <td class="third-width">$var1</td>
  292. <td>$var2</td>
  293. </tr>
  294. </table>
  295. EOT;
  296. }
  297. else if (!empty($var2) && !empty($var3)) {
  298. $output .= <<< EOT
  299. <table class="position" cellpadding="0" cellspacing="0" border="0">
  300. <tr valign="top">
  301. <td class="two-thirds-width">$var2</td>
  302. <td>$var3</td>
  303. </tr>
  304. </table>
  305. EOT;
  306. }
  307. else if (!empty($var1) && !empty($var3)) {
  308. $output .= <<< EOT
  309. <table class="position" cellpadding="0" cellspacing="0" border="0">
  310. <tr valign="top">
  311. <td class="half-width">$var1</td>
  312. <td>$var3</td>
  313. </tr>
  314. </table>
  315. EOT;
  316. }
  317. else {
  318. if (!empty($var1)) {
  319. $output .= <<< EOT
  320. <div id="var1">$var1</div>
  321. EOT;
  322. }
  323. if (!empty($var2)) {
  324. $output .= <<< EOT
  325. <div id="var1">$var2</div>
  326. EOT;
  327. }
  328. if (!empty($var3)) {
  329. $output .= <<< EOT
  330. <div id="var1">$var3</div>
  331. EOT;
  332. }
  333. }
  334. return $output;
  335. }
  336. function art_sidebar($s, $sidebar) {
  337. if (!empty($s)) return $s;
  338. if (!empty($sidebar)) return $sidebar;
  339. return NULL;
  340. }
  341. function art_get_sidebar_style($sidebar, $vnavigation, $class) {
  342. $output = 'art-layout-cell ';
  343. if (empty($sidebar) && empty($vnavigation)) {
  344. $output .= 'art-content';
  345. }
  346. else {
  347. $output .= $class;
  348. }
  349. return $output;
  350. }
  351. function art_get_content_cell_style($left, $vnav_left, $right, $vnav_right, $content) {
  352. if (empty($left) && empty($vnav_left) && empty($right) && empty($vnav_right))
  353. return 'art-layout-cell art-content-wide';
  354. if (empty($left) && empty($vnav_left))
  355. return 'art-layout-cell art-content-sidebar1';
  356. if (empty($right) && empty($vnav_right))
  357. return 'art-layout-cell art-content-sidebar2';
  358. return 'art-layout-cell art-content';
  359. }
  360. function art_submitted_worker($date, $author) {
  361. $output = '';
  362. if ($date != '') {
  363. ob_start();?>
  364. <img class="art-metadata-icon" src="<?php echo get_full_path_to_theme(); ?>/images/postdateicon.png" width="18" height="18" alt="" /> <?php
  365. $output .= ob_get_clean();
  366. $output .= $date;
  367. }
  368. if ($author != '') {
  369. ob_start();?>
  370. <img class="art-metadata-icon" src="<?php echo get_full_path_to_theme(); ?>/images/postauthoricon.png" width="18" height="18" alt="" /> <?php if ($output != '') {
  371. $output .= '&nbsp;|&nbsp;';
  372. }
  373. $output .= ob_get_clean();
  374. $output .= $author;
  375. }
  376. return $output;
  377. }
  378. function is_art_links_set($links) {
  379. $size = sizeof($links);
  380. if ($size == 0) {
  381. return FALSE;
  382. }
  383. //check if there's "Read more" in node links only
  384. $read_more_link = $links['node_read_more'];
  385. if ($read_more_link != NULL && $size == 1) {
  386. return FALSE;
  387. }
  388. return TRUE;
  389. }
  390. /**
  391. * Method to define node title output.
  392. *
  393. */
  394. function art_node_title_output($title, $node_url, $page) {
  395. $output = '';
  396. if ($page == 0)
  397. $output = '<a href="' . $node_url . '" title="' . $title . '">' . $title . '</a>';
  398. else
  399. $output = $title;
  400. return $output;
  401. }
  402. function art_vmenu_output($subject, $content) {
  403. if (empty($content))
  404. return;
  405. $bvm = "<div class=\"art-vmenublock\">\r\n <div class=\"art-vmenublock-body\">\r\n";
  406. $bvmt = "<div class=\"art-vmenublockheader\">\r\n <h3 class=\"t subject\">";
  407. $evmt = "</h3>\r\n</div>\r\n";
  408. $bvmc = "<div class=\"art-vmenublockcontent\">\r\n <div class=\"art-vmenublockcontent-body\">\r\n";
  409. $evmc = "\r\n\r\n </div>\r\n</div>\r\n";
  410. $evm = "\r\n </div>\r\n</div>\r\n";
  411. echo $bvm;
  412. if ('' != $bvmt && '' != $evmt && !empty($subject)) {
  413. echo $bvmt;
  414. echo $subject;
  415. echo $evmt;
  416. }
  417. echo $bvmc;
  418. echo art_menu_worker($content, true, 'art-vmenu');
  419. echo $evmc;
  420. echo $evm;
  421. }