PageRenderTime 81ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/profiles/drupal_commons/themes/fusion/fusion_core/template.php

https://gitlab.com/endomorphosis/aegir
PHP | 589 lines | 397 code | 68 blank | 124 comment | 118 complexity | d8e7e26aa1171719d7a0ae7803db3092 MD5 | raw file
  1. <?php
  2. require_once('theme-settings.php');
  3. /**
  4. * Initialize theme settings
  5. */
  6. global $theme_key;
  7. if (db_is_active()) {
  8. fusion_core_initialize_theme_settings($theme_key);
  9. }
  10. /**
  11. * Maintenance page preprocessing
  12. */
  13. function fusion_core_preprocess_maintenance_page(&$vars) {
  14. if (db_is_active()) {
  15. fusion_core_preprocess_page($vars);
  16. }
  17. }
  18. /**
  19. * Page preprocessing
  20. */
  21. function fusion_core_preprocess_page(&$vars) {
  22. global $language, $theme_key, $theme_info, $user;
  23. // Remove sidebars if disabled e.g., for Panels
  24. if (!$vars['show_blocks']) {
  25. $vars['sidebar_first'] = '';
  26. $vars['sidebar_last'] = '';
  27. }
  28. // Set grid info & row widths
  29. $grid_name = substr(theme_get_setting('theme_grid'), 0, 7);
  30. $grid_type = substr(theme_get_setting('theme_grid'), 7);
  31. $grid_width = (int)substr($grid_name, 4, 2);
  32. $vars['grid_width'] = $grid_name . $grid_width;
  33. $sidebar_first_width = ($vars['sidebar_first']) ? theme_get_setting('sidebar_first_width') : 0;
  34. $sidebar_last_width = ($vars['sidebar_last']) ? theme_get_setting('sidebar_last_width') : 0;
  35. $vars['sidebar_first_width'] = $grid_name . $sidebar_first_width;
  36. $vars['main_group_width'] = $grid_name . ($grid_width - $sidebar_first_width);
  37. // For nested elements in a fluid grid calculate % widths & add inline
  38. if ($grid_type == 'fluid') {
  39. $sidebar_last_width = round(($sidebar_last_width/($grid_width - $sidebar_first_width)) * 100, 2);
  40. $vars['content_group_width'] = '" style="width:' . (100 - $sidebar_last_width) . '%';
  41. $vars['sidebar_last_width'] = '" style="width:' . $sidebar_last_width . '%';
  42. }
  43. else {
  44. $vars['content_group_width'] = $grid_name . ($grid_width - ($sidebar_first_width + $sidebar_last_width));
  45. $vars['sidebar_last_width'] = $grid_name . $sidebar_last_width;
  46. }
  47. // Add to array of helpful body classes
  48. $body_classes = explode(' ', $vars['body_classes']); // Default classes
  49. if (isset($vars['node'])) {
  50. $body_classes[] = ($vars['node']) ? 'full-node' : ''; // Full node
  51. $body_classes[] = (($vars['node']->type == 'forum') || (arg(0) == 'forum')) ? 'forum' : ''; // Forum page
  52. }
  53. else {
  54. $body_classes[] = (arg(0) == 'forum') ? 'forum' : ''; // Forum page
  55. }
  56. if (module_exists('panels') && function_exists('panels_get_current_page_display')) { // Panels page
  57. $body_classes[] = (panels_get_current_page_display()) ? 'panels' : '';
  58. }
  59. $body_classes[] = 'layout-'. (($vars['sidebar_first']) ? 'first-main' : 'main') . (($vars['sidebar_last']) ? '-last' : ''); // Sidebars active
  60. $body_classes[] = theme_get_setting('sidebar_layout'); // Sidebar layout
  61. $body_classes[] = (theme_get_setting('theme_font') != 'none') ? theme_get_setting('theme_font') : ''; // Font family
  62. $body_classes[] = theme_get_setting('theme_font_size'); // Font size
  63. $body_classes[] = (user_access('administer blocks', $user) && theme_get_setting('grid_mask')) ? 'grid-mask-enabled' : ''; // Grid mask overlay
  64. $body_classes[] = 'grid-type-' . $grid_type; // Fixed width or fluid
  65. $body_classes[] = 'grid-width-' . sprintf("%02d", $grid_width); // Grid width in units
  66. $body_classes[] = ($grid_type == 'fluid') ? theme_get_setting('fluid_grid_width') : ''; // Fluid grid width in %
  67. $body_classes = array_filter($body_classes); // Remove empty elements
  68. $vars['body_classes'] = implode(' ', $body_classes); // Create class list separated by spaces
  69. // Add a unique css id for the body tag by converting / or + or _ in the current page alias into a dash (-).
  70. $vars['body_id'] = 'pid-' . strtolower(fusion_core_clean_css_identifier(drupal_get_path_alias($_GET['q'])));
  71. // Generate links tree & add Superfish class if dropdown enabled, else make standard primary links
  72. $vars['primary_links_tree'] = '';
  73. if ($vars['primary_links']) {
  74. if (theme_get_setting('primary_menu_dropdown') == 1) {
  75. // Check for menu internationalization
  76. if (module_exists('i18nmenu')) {
  77. $vars['primary_links_tree'] = i18nmenu_translated_tree(variable_get('menu_primary_links_source', 'primary-links'));
  78. }
  79. else {
  80. $vars['primary_links_tree'] = menu_tree(variable_get('menu_primary_links_source', 'primary-links'));
  81. }
  82. $vars['primary_links_tree'] = preg_replace('/<ul class="menu/i', '<ul class="menu sf-menu', $vars['primary_links_tree'], 1);
  83. }
  84. else {
  85. $vars['primary_links_tree'] = theme('links', $vars['primary_links'], array('class' => 'menu'));
  86. }
  87. }
  88. // Remove breadcrumbs if disabled
  89. if (theme_get_setting('breadcrumb_display') == 0) {
  90. $vars['breadcrumb'] = '';
  91. }
  92. // Add grid, color, ie6, ie7, ie8 & local stylesheets, including inherited & rtl versions
  93. $grid_style = '/css/' . theme_get_setting('theme_grid');
  94. $themes = fusion_core_theme_paths($theme_key);
  95. $vars['setting_styles'] = $vars['ie6_styles'] = $vars['ie7_styles'] = $vars['ie8_styles'] = $vars['local_styles'] = '';
  96. $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
  97. foreach ($themes as $name => $path) {
  98. $link = '<link type="text/css" rel="stylesheet" media="all" href="' . base_path() . $path;
  99. $vars['setting_styles'] .= (file_exists($path . $grid_style . '.css')) ? $link . $grid_style . '.css' . $query_string . '"/>' . "\n" : '';
  100. $vars['ie6_styles'] .= (file_exists($path . '/css/ie6-fixes.css')) ? $link . '/css/ie6-fixes.css' . $query_string . '"/>' . "\n" : '';
  101. $vars['ie7_styles'] .= (file_exists($path . '/css/ie7-fixes.css')) ? $link . '/css/ie7-fixes.css' . $query_string . '" />' . "\n" : '';
  102. $vars['ie8_styles'] .= (file_exists($path . '/css/ie8-fixes.css')) ? $link . '/css/ie8-fixes.css' . $query_string . '" />' . "\n" : '';
  103. $vars['local_styles'] .= (file_exists($path . '/css/local.css')) ? $link . '/css/local.css' . $query_string . '" />' . "\n" : '';
  104. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  105. $vars['setting_styles'] .= (file_exists($path . $grid_style . '-rtl.css')) ? $link . $grid_style . '-rtl.css" />' . "\n" : '';
  106. $vars['ie6_styles'] .= (file_exists($path . '/css/ie6-fixes-rtl.css')) ? $link . '/css/ie6-fixes-rtl.css' . $query_string . '" />' . "\n" : '';
  107. $vars['ie7_styles'] .= (file_exists($path . '/css/ie7-fixes-rtl.css')) ? $link . '/css/ie7-fixes-rtl.css' . $query_string . '" />' . "\n" : '';
  108. $vars['ie8_styles'] .= (file_exists($path . '/css/ie8-fixes-rtl.css')) ? $link . '/css/ie8-fixes-rtl.css' . $query_string . '" />' . "\n" : '';
  109. $vars['local_styles'] .= (file_exists($path . '/css/local-rtl.css')) ? $link . '/css/local-rtl.css' . $query_string . '" />' . "\n" : '';
  110. }
  111. }
  112. // Use grouped import setting to avoid 30 stylesheet limit in IE
  113. if (theme_get_setting('fix_css_limit') && !variable_get('preprocess_css', FALSE)) {
  114. $css = drupal_add_css();
  115. $style_count = substr_count($vars['setting_styles'] . $vars['ie6_styles'] . $vars['ie7_styles'] . $vars['ie8_styles'] . $vars['local_styles'], '<link');
  116. if (fusion_core_css_count($css) > (30 - $style_count)) {
  117. $styles = '';
  118. $suffix = "\n".'</style>'."\n";
  119. foreach ($css as $media => $types) {
  120. $prefix = '<style type="text/css" media="'. $media .'">'."\n";
  121. $imports = array();
  122. foreach ($types as $files) {
  123. foreach ($files as $file => $preprocess) {
  124. $imports[] = '@import "'. base_path() . $file .'";';
  125. if (count($imports) == 30) {
  126. $styles .= $prefix . implode("\n", $imports) . $suffix;
  127. $imports = array();
  128. }
  129. }
  130. }
  131. $styles .= (count($imports) > 0) ? ($prefix . implode("\n", $imports) . $suffix) : '';
  132. }
  133. $vars['styles'] = $styles;
  134. }
  135. }
  136. // Replace page title as Drupal core does, but strip tags from site slogan.
  137. // Site name and slogan do not need to be sanitized because the permission
  138. // 'administer site configuration' is required to be set and should be given to
  139. // trusted users only.
  140. // No sanitization will be applied when using the page title module.
  141. if (!module_exists('page_title')) {
  142. if (drupal_get_title()) {
  143. $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
  144. }
  145. else {
  146. $head_title = array(variable_get('site_name', 'Drupal'));
  147. if (variable_get('site_slogan', '')) {
  148. $head_title[] = strip_tags(variable_get('site_slogan', ''));
  149. }
  150. }
  151. if (is_array($head_title)) $head_title = implode(' | ', $head_title);
  152. $vars['head_title'] = $head_title;
  153. }
  154. }
  155. /**
  156. * Node preprocessing
  157. */
  158. function fusion_core_preprocess_node(&$vars) {
  159. // Build array of handy node classes
  160. $node_classes = array();
  161. $node_classes[] = $vars['zebra']; // Node is odd or even
  162. $node_classes[] = (!$vars['node']->status) ? 'node-unpublished' : ''; // Node is unpublished
  163. $node_classes[] = ($vars['sticky']) ? 'sticky' : ''; // Node is sticky
  164. $node_classes[] = $vars['teaser'] ? 'teaser' : 'full-node'; // Node is teaser or full-node
  165. $node_classes[] = 'node-type-'. $vars['node']->type; // Node is type-x, e.g., node-type-page
  166. $node_classes[] = (isset($vars['skinr'])) ? $vars['skinr'] : ''; // Add Skinr classes if present
  167. $node_classes = array_filter($node_classes); // Remove empty elements
  168. $vars['node_classes'] = implode(' ', $node_classes); // Implode class list with spaces
  169. // Add node_top and node_bottom region content
  170. $vars['node_top'] = theme('blocks', 'node_top');
  171. $vars['node_bottom'] = theme('blocks', 'node_bottom');
  172. // Render Ubercart fields into separate variables for node-product.tpl.php
  173. if (module_exists('uc_product') && uc_product_is_product($vars) && $vars['template_files'][0] == 'node-product') {
  174. $node = node_build_content(node_load($vars['nid']), $vars['teaser'], $vars['page']);
  175. $vars['fusion_uc_image'] = drupal_render($node->content['image']);
  176. $vars['fusion_uc_body'] = drupal_render($node->content['body']);
  177. $vars['fusion_uc_display_price'] = drupal_render($node->content['display_price']);
  178. $vars['fusion_uc_add_to_cart'] = drupal_render($node->content['add_to_cart']);
  179. $vars['fusion_uc_sell_price'] = drupal_render($node->content['sell_price']);
  180. $vars['fusion_uc_cost'] = drupal_render($node->content['cost']);
  181. $vars['fusion_uc_weight'] = (!empty($node->weight)) ? drupal_render($node->content['weight']) : ''; // Hide weight if empty
  182. if ($vars['fusion_uc_weight'] == '') {
  183. unset($node->content['weight']);
  184. }
  185. $dimensions = !empty($node->height) && !empty($node->width) && !empty($node->length); // Hide dimensions if empty
  186. $vars['fusion_uc_dimensions'] = ($dimensions) ? drupal_render($node->content['dimensions']) : '';
  187. if ($vars['fusion_uc_dimensions'] == '') {
  188. unset($node->content['dimensions']);
  189. }
  190. $list_price = !empty($node->list_price) && $node->list_price > 0; // Hide list price if empty or zero
  191. $vars['fusion_uc_list_price'] = ($list_price) ? drupal_render($node->content['list_price']) : '';
  192. if ($vars['fusion_uc_list_price'] == '') {
  193. unset($node->content['list_price']);
  194. }
  195. $vars['fusion_uc_additional'] = drupal_render($node->content); // Render remaining fields
  196. }
  197. }
  198. /**
  199. * Comment preprocessing
  200. */
  201. function fusion_core_preprocess_comment(&$vars) {
  202. global $user;
  203. static $comment_odd = TRUE; // Comment is odd or even
  204. // Build array of handy comment classes
  205. $comment_classes = array();
  206. $comment_classes[] = $comment_odd ? 'odd' : 'even';
  207. $comment_odd = !$comment_odd;
  208. $comment_classes[] = ($vars['comment']->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : ''; // Comment is unpublished
  209. $comment_classes[] = ($vars['comment']->new) ? 'comment-new' : ''; // Comment is new
  210. $comment_classes[] = ($vars['comment']->uid == 0) ? 'comment-by-anon' : ''; // Comment is by anonymous user
  211. $comment_classes[] = ($user->uid && $vars['comment']->uid == $user->uid) ? 'comment-mine' : ''; // Comment is by current user
  212. $vars['author_comment'] = ($vars['comment']->uid == $vars['node']->uid) ? TRUE : FALSE; // Comment is by node author
  213. $comment_classes[] = ($vars['author_comment']) ? 'comment-by-author' : '';
  214. $comment_classes = array_filter($comment_classes); // Remove empty elements
  215. $vars['comment_classes'] = implode(' ', $comment_classes); // Create class list separated by spaces
  216. }
  217. /**
  218. * Comment wrapper preprocessing
  219. * Defaults for comments display
  220. */
  221. function fusion_core_preprocess_comment_wrapper(&$vars) {
  222. $vars['display_mode'] = COMMENT_MODE_FLAT_EXPANDED;
  223. $vars['display_order'] = COMMENT_ORDER_OLDEST_FIRST;
  224. $vars['comment_controls_state'] = COMMENT_CONTROLS_HIDDEN;
  225. }
  226. /**
  227. * Returns a list of blocks.
  228. * Uses Drupal block interface and appends any blocks assigned by the Context module.
  229. */
  230. function fusion_core_block_list($region) {
  231. $drupal_list = block_list($region);
  232. if (module_exists('context') && $context = context_get_plugin('reaction', 'block')) {
  233. $context_list = $context->block_list($region);
  234. $drupal_list = array_merge($context_list, $drupal_list);
  235. }
  236. return $drupal_list;
  237. }
  238. /**
  239. * Block preprocessing
  240. */
  241. function fusion_core_preprocess_block(&$vars) {
  242. global $theme_info, $user;
  243. static $regions, $sidebar_first_width, $sidebar_last_width, $grid_name, $grid_width, $grid_fixed;
  244. // Initialize position to avoid notice if function returns.
  245. $vars['position'] = '';
  246. // Do not process blocks outside defined regions
  247. if (!in_array($vars['block']->region, array_keys($theme_info->info['regions']))) {
  248. return;
  249. }
  250. // Initialize block region grid info once per page
  251. if (!isset($regions)) {
  252. $grid_name = substr(theme_get_setting('theme_grid'), 0, 7);
  253. $grid_width = (int)substr($grid_name, 4, 2);
  254. $grid_fixed = (substr(theme_get_setting('theme_grid'), 7) != 'fluid') ? 1 : 0;
  255. $sidebar_first_width = (fusion_core_block_list('sidebar_first')) ? theme_get_setting('sidebar_first_width') : 0;
  256. $sidebar_last_width = (fusion_core_block_list('sidebar_last')) ? theme_get_setting('sidebar_last_width') : 0;
  257. $regions = fusion_core_set_regions($grid_width, $sidebar_first_width, $sidebar_last_width);
  258. }
  259. // Increment block count for current block's region, add first/last position class
  260. $regions[$vars['block']->region]['count']++;
  261. $region_count = $regions[$vars['block']->region]['count'];
  262. $total_blocks = $regions[$vars['block']->region]['total'];
  263. $vars['position'] = ($region_count == 1) ? 'first' : '';
  264. $vars['position'] .= ($region_count == $total_blocks) ? ' last' : '';
  265. // Set a default block width if not already set by Skinr
  266. if (!isset($vars['skinr']) || (strpos($vars['skinr'], $grid_name) === false)) {
  267. // Stack blocks vertically in sidebars by setting to full sidebar width
  268. if ($vars['block']->region == 'sidebar_first') {
  269. $width = ($grid_fixed) ? $sidebar_first_width : $grid_width; // Sidebar width or 100% (if fluid)
  270. }
  271. elseif ($vars['block']->region == 'sidebar_last') {
  272. $width = ($grid_fixed) ? $sidebar_last_width : $grid_width; // Sidebar width or 100% (if fluid)
  273. }
  274. else {
  275. // Default block width = region width divided by total blocks, adding any extra width to last block
  276. $region_width = ($grid_fixed) ? $regions[$vars['block']->region]['width'] : $grid_width; // fluid grid regions = 100%
  277. $width_adjust = (($region_count == $total_blocks) && ($region_width % $total_blocks)) ? $region_width % $total_blocks : 0;
  278. $width = ($total_blocks) ? floor($region_width / $total_blocks) + $width_adjust : 0;
  279. }
  280. $vars['skinr'] = (isset($vars['skinr'])) ? $vars['skinr'] . ' ' . $grid_name . $width : $grid_name . $width;
  281. }
  282. if (isset($vars['skinr']) && (strpos($vars['skinr'], 'superfish') !== false) &&
  283. ($vars['block']->module == 'menu' || ($vars['block']->module == 'user' && $vars['block']->delta == 1))) {
  284. $superfish = ' sf-menu';
  285. $superfish .= (strpos($vars['skinr'], 'superfish-vertical')) ? ' sf-vertical' : '';
  286. $vars['block']->content = preg_replace('/<ul class="menu/i', '<ul class="menu' . $superfish, $vars['block']->content, 1);
  287. }
  288. // Add block edit links for admins
  289. if (user_access('administer blocks', $user) && theme_get_setting('block_config_link')) {
  290. $vars['edit_links'] = '<div class="fusion-edit">'. implode(' ', fusion_core_edit_links($vars['block'])) .'</div>';
  291. }
  292. }
  293. /**
  294. * Views preprocessing
  295. * Add view type class (e.g., node, teaser, list, table)
  296. */
  297. function fusion_core_preprocess_views_view(&$vars) {
  298. $vars['css_name'] = $vars['css_name'] .' view-style-'. views_css_safe(strtolower($vars['view']->type));
  299. }
  300. /**
  301. * Search result preprocessing
  302. */
  303. function fusion_core_preprocess_search_result(&$vars) {
  304. static $search_zebra = 'even';
  305. $search_zebra = ($search_zebra == 'even') ? 'odd' : 'even';
  306. $vars['search_zebra'] = $search_zebra;
  307. $result = $vars['result'];
  308. $vars['url'] = check_url($result['link']);
  309. $vars['title'] = check_plain($result['title']);
  310. // Check for snippet existence. User search does not include snippets.
  311. $vars['snippet'] = '';
  312. if (isset($result['snippet']) && theme_get_setting('search_snippet')) {
  313. $vars['snippet'] = $result['snippet'];
  314. }
  315. $info = array();
  316. if (!empty($result['type']) && theme_get_setting('search_info_type')) {
  317. $info['type'] = check_plain($result['type']);
  318. }
  319. if (!empty($result['user']) && theme_get_setting('search_info_user')) {
  320. $info['user'] = $result['user'];
  321. }
  322. if (!empty($result['date']) && theme_get_setting('search_info_date')) {
  323. $info['date'] = format_date($result['date'], 'small');
  324. }
  325. if (isset($result['extra']) && is_array($result['extra'])) {
  326. // $info = array_merge($info, $result['extra']); Drupal bug? [extra] array not keyed with 'comment' & 'upload'
  327. if (!empty($result['extra'][0]) && theme_get_setting('search_info_comment')) {
  328. $info['comment'] = $result['extra'][0];
  329. }
  330. if (!empty($result['extra'][1]) && theme_get_setting('search_info_upload')) {
  331. $info['upload'] = $result['extra'][1];
  332. }
  333. }
  334. // Provide separated and grouped meta information.
  335. $vars['info_split'] = $info;
  336. $vars['info'] = implode(' - ', $info);
  337. // Provide alternate search result template.
  338. $vars['template_files'][] = 'search-result-'. $vars['type'];
  339. }
  340. /**
  341. * Username override
  342. * Hides or shows username '(not verified)' text
  343. */
  344. function fusion_core_username($object) {
  345. if ((!$object->uid) && $object->name) {
  346. $output = (!empty($object->homepage)) ? l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow'))) : check_plain($object->name);
  347. $output .= (theme_get_setting('user_notverified_display') == 1) ? t(' (not verified)') : '';
  348. }
  349. else {
  350. $output = theme_username($object);
  351. }
  352. return $output;
  353. }
  354. /**
  355. * File element override
  356. * Sets form file input max width
  357. */
  358. function fusion_core_file($variables) {
  359. $variables['element']['#size'] = (!isset($variables['element']['#size']) || $variables['element']['#size'] > 40) ? 40 : $variables['element']['#size'];
  360. return theme_file($variables);
  361. }
  362. /**
  363. * Custom theme functions
  364. */
  365. function fusion_core_theme() {
  366. return array(
  367. 'grid_row' => array(
  368. 'arguments' => array('element' => NULL, 'name' => NULL, 'class' => NULL, 'width' => NULL),
  369. ),
  370. 'grid_block' => array(
  371. 'arguments' => array('element' => NULL, 'name' => NULL),
  372. ),
  373. );
  374. }
  375. /**
  376. * Row & block theme functions
  377. * Adds divs to elements in page.tpl.php
  378. */
  379. function fusion_core_grid_row($element, $name, $class='', $width='', $extra='') {
  380. $output = '';
  381. $extra = ($extra) ? ' ' . $extra : '';
  382. if ($element) {
  383. if ($class == 'full-width') {
  384. $output .= '<div id="' . $name . '-wrapper" class="' . $name . '-wrapper full-width">' . "\n";
  385. $output .= '<div id="' . $name . '" class="' . $name . ' row ' . $width . $extra . '">' . "\n";
  386. }
  387. else {
  388. $output .= '<div id="' . $name . '" class="' . $name . ' row ' . $class . ' ' . $width . $extra . '">' . "\n";
  389. }
  390. $output .= '<div id="' . $name . '-inner" class="' . $name . '-inner inner clearfix">' . "\n";
  391. $output .= $element;
  392. $output .= '</div><!-- /' . $name . '-inner -->' . "\n";
  393. $output .= '</div><!-- /' . $name . ' -->' . "\n";
  394. $output .= ($class == 'full-width') ? '</div><!-- /' . $name . '-wrapper -->' . "\n" : '';
  395. }
  396. return $output;
  397. }
  398. function fusion_core_grid_block($element, $name) {
  399. $output = '';
  400. if ($element) {
  401. $output .= '<div id="' . $name . '" class="' . $name . ' block">' . "\n";
  402. $output .= '<div id="' . $name . '-inner" class="' . $name . '-inner inner clearfix">' . "\n";
  403. $output .= $element;
  404. $output .= '</div><!-- /' . $name . '-inner -->' . "\n";
  405. $output .= '</div><!-- /' . $name . ' -->' . "\n";
  406. }
  407. return $output;
  408. }
  409. /**
  410. * Block region grid info function
  411. * Defaults match grid_row widths set in preprocess_page()
  412. */
  413. function fusion_core_set_regions($grid_width, $sidebar_first_width, $sidebar_last_width) {
  414. $sidebar_total = $sidebar_first_width + $sidebar_last_width;
  415. $regions = array(
  416. 'header_top' => array('width' => $grid_width, 'total' => count(fusion_core_block_list('header_top')), 'count' => 0),
  417. 'header' => array('width' => $grid_width, 'total' => count(fusion_core_block_list('header')), 'count' => 0),
  418. 'preface_top' => array('width' => $grid_width, 'total' => count(fusion_core_block_list('preface_top')), 'count' => 0),
  419. 'preface_bottom' => array('width' => $grid_width - $sidebar_first_width, 'total' => count(fusion_core_block_list('preface_bottom')), 'count' => 0),
  420. 'sidebar_first' => array('width' => $sidebar_first_width, 'total' => count(fusion_core_block_list('sidebar_first')), 'count' => 0),
  421. 'content_top' => array('width' => $grid_width - $sidebar_total, 'total' => count(fusion_core_block_list('content_top')), 'count' => 0),
  422. 'content' => array('width' => $grid_width - $sidebar_total, 'total' => count(fusion_core_block_list('content')), 'count' => 0),
  423. 'node_top' => array('width' => $grid_width - $sidebar_total, 'total' => count(fusion_core_block_list('node_top')), 'count' => 0),
  424. 'node_bottom' => array('width' => $grid_width - $sidebar_total, 'total' => count(fusion_core_block_list('node_bottom')), 'count' => 0),
  425. 'content_bottom' => array('width' => $grid_width - $sidebar_total, 'total' => count(fusion_core_block_list('content_bottom')), 'count' => 0),
  426. 'sidebar_last' => array('width' => $sidebar_last_width, 'total' => count(fusion_core_block_list('sidebar_last')), 'count' => 0),
  427. 'postscript_top' => array('width' => $grid_width - $sidebar_first_width, 'total' => count(fusion_core_block_list('postscript_top')), 'count' => 0),
  428. 'postscript_bottom' => array('width' => $grid_width, 'total' => count(fusion_core_block_list('postscript_bottom')), 'count' => 0),
  429. 'footer' => array('width' => $grid_width, 'total' => count(fusion_core_block_list('footer')), 'count' => 0)
  430. );
  431. return $regions;
  432. }
  433. /**
  434. * Block edit links function
  435. * Create block edit links for admins
  436. */
  437. function fusion_core_edit_links($block) {
  438. $path = 'admin/build/block/configure/' . $block->module . '/' . $block->delta;
  439. $return = drupal_get_destination();
  440. // Use 'edit' for custom blocks, 'configure' for others
  441. if ($block->module == 'block') {
  442. $text = t('edit block');
  443. $block_info = array('@region' => str_replace('_', ' ', $block->region));
  444. $attributes = array('title' => t('edit the content of this Custom block (in @region)', $block_info), 'class' => 'fusion-block-edit');
  445. }
  446. else {
  447. $text = t('configure block');
  448. $block_info = array('@type' => ucwords($block->module), '@region' => str_replace('_', ' ', $block->region));
  449. $attributes = array('title' => t('configure this @type block (in @region)', $block_info), 'class' => 'fusion-block-config');
  450. }
  451. $edit_links[] = l($text, $path, array('attributes' => $attributes, 'query' => $return));
  452. // Add extra 'edit menu' for menu blocks
  453. if (user_access('administer menu') && ($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1))) {
  454. $text = t('edit menu');
  455. $path = 'admin/build/menu-customize/' . (($block->module == 'user') ? 'navigation' : $block->delta);
  456. $attributes = array('title' => t('edit the menu of this @type block (in @region)', $block_info), 'class' => 'fusion-edit-menu');
  457. $edit_links[] = l($text, $path, array('attributes' => $attributes, 'query' => $return));
  458. }
  459. return $edit_links;
  460. }
  461. /**
  462. * CSS count function
  463. * Counts the total number of CSS files in $vars['css']
  464. */
  465. function fusion_core_css_count($array) {
  466. $count = 0;
  467. foreach ($array as $item) {
  468. $count = (is_array($item)) ? $count + fusion_core_css_count($item) : $count + 1;
  469. }
  470. return $count;
  471. }
  472. /**
  473. * Theme paths function
  474. * Retrieves current theme path and its parent
  475. * theme paths, in parent-to-child order.
  476. */
  477. function fusion_core_theme_paths($theme) {
  478. $all_parents = array();
  479. $themes = list_themes();
  480. $all_parents[$theme] = drupal_get_path('theme', $theme);
  481. $base_theme = $themes[$theme]->info['base theme'];
  482. while ($base_theme) {
  483. $all_parents[$base_theme] = drupal_get_path('theme', $base_theme);
  484. $base_theme = (isset($themes[$base_theme]->info['base theme'])) ? $themes[$base_theme]->info['base theme'] : '';
  485. }
  486. return array_reverse($all_parents);
  487. }
  488. /**
  489. * Theme settings link function
  490. * Creates link with prefix and suffix text
  491. * ($options info: http://api.drupal.org/api/function/l)
  492. */
  493. function fusion_core_themesettings_link($prefix, $suffix, $text, $path, $options) {
  494. return $prefix . (($text) ? l($text, $path, $options) : '') . $suffix;
  495. }
  496. /**
  497. * @function fusion_core_clean_css_identifier()
  498. * backport of drupal_clean_css_identifier() from Drupal 7.x
  499. *
  500. * @param $identifier
  501. * the identifier to clean
  502. * @param $filter
  503. * an array of string replacements to use on the identifier
  504. *
  505. * @return
  506. * A string safe for use as a CSS class or ID
  507. **/
  508. function fusion_core_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')) {
  509. // By default, we filter using Drupal's coding standards.
  510. $identifier = strtr($identifier, $filter);
  511. // Valid characters in a CSS identifier are:
  512. // - the hyphen (U+002D)
  513. // - a-z (U+0030 - U+0039)
  514. // - A-Z (U+0041 - U+005A)
  515. // - the underscore (U+005F)
  516. // - 0-9 (U+0061 - U+007A)
  517. // - ISO 10646 characters U+00A1 and higher
  518. // We strip out any character not in the above list.
  519. $identifier = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier);
  520. return $identifier;
  521. }