template.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <?php
  2. /**
  3. * Implements hook_css_alter().
  4. * @TODO: Once http://drupal.org/node/901062 is resolved, determine whether
  5. * this can be implemented in the .info file instead.
  6. *
  7. * Omitted:
  8. * - color.css
  9. * - contextual.css
  10. * - dashboard.css
  11. * - field_ui.css
  12. * - image.css
  13. * - locale.css
  14. * - shortcut.css
  15. * - simpletest.css
  16. * - toolbar.css
  17. */
  18. function tao_css_alter(&$css) {
  19. $exclude = array(
  20. 'misc/vertical-tabs.css' => FALSE,
  21. 'modules/aggregator/aggregator.css' => FALSE,
  22. 'modules/block/block.css' => FALSE,
  23. 'modules/book/book.css' => FALSE,
  24. 'modules/comment/comment.css' => FALSE,
  25. 'modules/dblog/dblog.css' => FALSE,
  26. 'modules/file/file.css' => FALSE,
  27. 'modules/filter/filter.css' => FALSE,
  28. 'modules/forum/forum.css' => FALSE,
  29. 'modules/help/help.css' => FALSE,
  30. 'modules/menu/menu.css' => FALSE,
  31. 'modules/node/node.css' => FALSE,
  32. 'modules/openid/openid.css' => FALSE,
  33. 'modules/poll/poll.css' => FALSE,
  34. 'modules/profile/profile.css' => FALSE,
  35. 'modules/search/search.css' => FALSE,
  36. 'modules/statistics/statistics.css' => FALSE,
  37. 'modules/syslog/syslog.css' => FALSE,
  38. 'modules/system/admin.css' => FALSE,
  39. 'modules/system/maintenance.css' => FALSE,
  40. 'modules/system/system.css' => FALSE,
  41. 'modules/system/system.admin.css' => FALSE,
  42. 'modules/system/system.base.css' => FALSE,
  43. 'modules/system/system.maintenance.css' => FALSE,
  44. 'modules/system/system.menus.css' => FALSE,
  45. 'modules/system/system.theme.css' => FALSE,
  46. 'modules/taxonomy/taxonomy.css' => FALSE,
  47. 'modules/tracker/tracker.css' => FALSE,
  48. 'modules/update/update.css' => FALSE,
  49. 'modules/user/user.css' => FALSE,
  50. );
  51. $css = array_diff_key($css, $exclude);
  52. }
  53. /**
  54. * Implementation of hook_theme().
  55. */
  56. function tao_theme() {
  57. $items = array();
  58. // Consolidate a variety of theme functions under a single template type.
  59. $items['block'] = array(
  60. 'arguments' => array('block' => NULL),
  61. 'template' => 'object',
  62. 'path' => drupal_get_path('theme', 'tao') .'/templates',
  63. );
  64. $items['comment'] = array(
  65. 'arguments' => array('comment' => NULL, 'node' => NULL, 'links' => array()),
  66. 'template' => 'object',
  67. 'path' => drupal_get_path('theme', 'tao') .'/templates',
  68. );
  69. $items['node'] = array(
  70. 'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
  71. 'template' => 'node',
  72. 'path' => drupal_get_path('theme', 'tao') .'/templates',
  73. );
  74. $items['fieldset'] = array(
  75. 'arguments' => array('element' => array()),
  76. 'template' => 'fieldset',
  77. 'path' => drupal_get_path('theme', 'tao') .'/templates',
  78. );
  79. // Split out pager list into separate theme function.
  80. $items['pager_list'] = array('arguments' => array(
  81. 'tags' => array(),
  82. 'limit' => 10,
  83. 'element' => 0,
  84. 'parameters' => array(),
  85. 'quantity' => 9,
  86. ));
  87. return $items;
  88. }
  89. /**
  90. * Preprocess functions ===============================================
  91. */
  92. function tao_preprocess_html(&$vars) {
  93. $vars['classes_array'][] = 'tao';
  94. // Add IE from theme file.
  95. $tao_path = drupal_get_path('theme', 'tao');
  96. $info = drupal_parse_info_file($tao_path.'/tao.info');
  97. $ie = $info['stylesheets']['ie'];
  98. foreach ($ie as $key => $value) {
  99. drupal_add_css(
  100. $tao_path.'/'.$value,
  101. array(
  102. 'browsers' => array(
  103. 'IE' => $key,
  104. '!IE' => FALSE
  105. )
  106. )
  107. );
  108. }
  109. }
  110. /**
  111. * Implementation of preprocess_page().
  112. */
  113. function tao_preprocess_page(&$vars) {
  114. // Split primary and secondary local tasks
  115. $vars['primary_local_tasks'] = menu_primary_local_tasks();
  116. $vars['secondary_local_tasks'] = menu_secondary_local_tasks();
  117. // Link site name to frontpage
  118. $vars['site_name'] = l($vars['site_name'], '<front>');
  119. }
  120. /**
  121. * Implementation of preprocess_block().
  122. */
  123. function tao_preprocess_block(&$vars) {
  124. $vars['hook'] = 'block';
  125. $vars['attributes_array']['id'] = $vars['block_html_id'];
  126. $vars['attributes_array']['class'] = $vars['classes_array'];
  127. $vars['title_attributes_array']['class'][] = $vars['hook'] . '-title';
  128. $vars['title_attributes_array']['class'][] = 'clearfix';
  129. $vars['content_attributes_array']['class'][] = $vars['hook'] . '-content';
  130. $vars['content_attributes_array']['class'][] = 'clearfix';
  131. if ($vars['block']->module == 'block') {
  132. $vars['content_attributes_array']['class'][] = 'prose';
  133. }
  134. $vars['title'] = !empty($vars['block']->subject) ? $vars['block']->subject : '';
  135. // In D7 the page content may be served as a block. Replace the generic
  136. // 'block' class from the page content with a more specific class that can
  137. // be used to distinguish this block from others.
  138. // Subthemes can easily override this behavior in an implementation of
  139. // preprocess_block().
  140. if ($vars['block']->module === 'system' && $vars['block']->delta === 'main') {
  141. $vars['classes_array'] = array_diff($vars['classes_array'], array('block'));
  142. $vars['classes_array'][] = 'block-page-content';
  143. }
  144. }
  145. /**
  146. * Implementation of preprocess_node().
  147. */
  148. function tao_preprocess_node(&$vars) {
  149. $vars['hook'] = 'node';
  150. $vars['classes_array'][] = 'clearfix';
  151. $vars['attributes_array']['id'] = "node-{$vars['node']->nid}";
  152. $vars['title_attributes_array']['class'][] = $vars['hook'] . '-title';
  153. $vars['title_attributes_array']['class'][] = 'clearfix';
  154. $vars['content_attributes_array']['class'][] = $vars['hook'] . '-content';
  155. $vars['content_attributes_array']['class'][] = 'clearfix';
  156. $vars['content_attributes_array']['class'][] = 'prose';
  157. if (isset($vars['content']['links'])) {
  158. $vars['links'] = $vars['content']['links'];
  159. unset($vars['content']['links']);
  160. }
  161. if (isset($vars['content']['comments'])) {
  162. $vars['post_object']['comments'] = $vars['content']['comments'];
  163. unset($vars['content']['comments']);
  164. }
  165. if ($vars['display_submitted']) {
  166. $vars['submitted'] = t('Submitted by !username on !datetime', array(
  167. '!username' => $vars['name'],
  168. '!datetime' => $vars['date'],
  169. ));
  170. }
  171. }
  172. /**
  173. * Implementation of preprocess_comment().
  174. */
  175. function tao_preprocess_comment(&$vars) {
  176. $vars['hook'] = 'comment';
  177. $vars['classes_array'][] = 'clearfix';
  178. $vars['title_attributes_array']['class'][] = $vars['hook'] . '-title';
  179. $vars['title_attributes_array']['class'][] = 'clearfix';
  180. $vars['content_attributes_array']['class'][] = $vars['hook'] . '-content';
  181. $vars['content_attributes_array']['class'][] = 'clearfix';
  182. $vars['submitted'] = t('Submitted by !username on !datetime', array(
  183. '!username' => $vars['author'],
  184. '!datetime' => $vars['created'],
  185. ));
  186. if (isset($vars['content']['links'])) {
  187. $vars['links'] = $vars['content']['links'];
  188. unset($vars['content']['links']);
  189. }
  190. }
  191. /**
  192. * Implementation of preprocess_fieldset().
  193. */
  194. function tao_preprocess_fieldset(&$vars) {
  195. $element = $vars['element'];
  196. _form_set_class($element, array('form-wrapper'));
  197. $vars['attributes'] = isset($element['#attributes']) ? $element['#attributes'] : array();
  198. $vars['attributes']['class'][] = 'fieldset';
  199. if (!empty($element['#title'])) {
  200. $vars['attributes']['class'][] = 'titled';
  201. }
  202. if (!empty($element['#id'])) {
  203. if (!empty($element["#attributes"]["id"])) {
  204. $vars['attributes']['id'] = $element["#attributes"]["id"];
  205. } else {
  206. $vars['attributes']['id'] = $element['#id'];
  207. }
  208. }
  209. $description = !empty($element['#description']) ? "<div class='description'>{$element['#description']}</div>" : '';
  210. $children = !empty($element['#children']) ? $element['#children'] : '';
  211. $value = !empty($element['#value']) ? $element['#value'] : '';
  212. $vars['content'] = $description . $children . $value;
  213. $vars['title'] = !empty($element['#title']) ? $element['#title'] : '';
  214. $vars['hook'] = 'fieldset';
  215. }
  216. /**
  217. * Implementation of preprocess_field().
  218. */
  219. function tao_preprocess_field(&$vars) {
  220. // Add prose class to long text fields.
  221. if ($vars['element']['#field_type'] === 'text_with_summary') {
  222. $vars['classes_array'][] = 'prose';
  223. }
  224. }
  225. /**
  226. * Function overrides =================================================
  227. */
  228. /**
  229. * Override of theme('textarea').
  230. * Deprecate misc/textarea.js in favor of using the 'resize' CSS3 property.
  231. */
  232. function tao_textarea($vars) {
  233. $element = $vars['element'];
  234. $element['#attributes']['name'] = $element['#name'];
  235. $element['#attributes']['id'] = $element['#id'];
  236. $element['#attributes']['cols'] = $element['#cols'];
  237. $element['#attributes']['rows'] = $element['#rows'];
  238. _form_set_class($element, array('form-textarea'));
  239. $wrapper_attributes = array(
  240. 'class' => array('form-textarea-wrapper'),
  241. );
  242. // Add resizable behavior.
  243. if (!empty($element['#resizable'])) {
  244. $wrapper_attributes['class'][] = 'resizable';
  245. }
  246. $output = '<div' . drupal_attributes($wrapper_attributes) . '>';
  247. $output .= '<textarea' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>';
  248. $output .= '</div>';
  249. return $output;
  250. }
  251. /**
  252. * Override of theme_pager().
  253. * Easily one of the most obnoxious theming jobs in Drupal core.
  254. * Goals: consolidate functionality into less than 5 functions and
  255. * ensure the markup will not conflict with major other styles
  256. * (theme_item_list() in particular).
  257. */
  258. function tao_pager($vars) {
  259. $tags = $vars['tags'];
  260. $element = $vars['element'];
  261. $parameters = $vars['parameters'];
  262. $quantity = $vars['quantity'];
  263. $pager_list = theme('pager_list', $vars);
  264. $links = array();
  265. $links['pager-first'] = theme('pager_first', array(
  266. 'text' => (isset($tags[0]) ? $tags[0] : t('First')),
  267. 'element' => $element,
  268. 'parameters' => $parameters
  269. ));
  270. $links['pager-previous'] = theme('pager_previous', array(
  271. 'text' => (isset($tags[1]) ? $tags[1] : t('Prev')),
  272. 'element' => $element,
  273. 'interval' => 1,
  274. 'parameters' => $parameters
  275. ));
  276. $links['pager-next'] = theme('pager_next', array(
  277. 'text' => (isset($tags[3]) ? $tags[3] : t('Next')),
  278. 'element' => $element,
  279. 'interval' => 1,
  280. 'parameters' => $parameters
  281. ));
  282. $links['pager-last'] = theme('pager_last', array(
  283. 'text' => (isset($tags[4]) ? $tags[4] : t('Last')),
  284. 'element' => $element,
  285. 'parameters' => $parameters
  286. ));
  287. $links = array_filter($links);
  288. $pager_links = theme('links', array(
  289. 'links' => $links,
  290. 'attributes' => array('class' => 'links pager pager-links')
  291. ));
  292. if ($pager_list) {
  293. return '<div class="pager clearfix">' . $pager_list . ' ' . $pager_links . '</div>';
  294. }
  295. }
  296. /**
  297. * Split out page list generation into its own function.
  298. */
  299. function tao_pager_list($vars) {
  300. $tags = $vars['tags'];
  301. $element = $vars['element'];
  302. $parameters = $vars['parameters'];
  303. $quantity = $vars['quantity'];
  304. global $pager_page_array, $pager_total;
  305. if ($pager_total[$element] > 1) {
  306. // Calculate various markers within this pager piece:
  307. // Middle is used to "center" pages around the current page.
  308. $pager_middle = ceil($quantity / 2);
  309. // current is the page we are currently paged to
  310. $pager_current = $pager_page_array[$element] + 1;
  311. // first is the first page listed by this pager piece (re quantity)
  312. $pager_first = $pager_current - $pager_middle + 1;
  313. // last is the last page listed by this pager piece (re quantity)
  314. $pager_last = $pager_current + $quantity - $pager_middle;
  315. // max is the maximum page number
  316. $pager_max = $pager_total[$element];
  317. // End of marker calculations.
  318. // Prepare for generation loop.
  319. $i = $pager_first;
  320. if ($pager_last > $pager_max) {
  321. // Adjust "center" if at end of query.
  322. $i = $i + ($pager_max - $pager_last);
  323. $pager_last = $pager_max;
  324. }
  325. if ($i <= 0) {
  326. // Adjust "center" if at start of query.
  327. $pager_last = $pager_last + (1 - $i);
  328. $i = 1;
  329. }
  330. // End of generation loop preparation.
  331. $links = array();
  332. // When there is more than one page, create the pager list.
  333. if ($i != $pager_max) {
  334. // Now generate the actual pager piece.
  335. for ($i; $i <= $pager_last && $i <= $pager_max; $i++) {
  336. if ($i < $pager_current) {
  337. $links["$i pager-item"] = theme('pager_previous', array(
  338. 'text' => $i,
  339. 'element' => $element,
  340. 'interval' => ($pager_current - $i),
  341. 'parameters' => $parameters
  342. ));
  343. }
  344. if ($i == $pager_current) {
  345. $links["$i pager-current"] = array('title' => $i);
  346. }
  347. if ($i > $pager_current) {
  348. $links["$i pager-item"] = theme('pager_next', array(
  349. 'text' => $i,
  350. 'element' => $element,
  351. 'interval' => ($i - $pager_current),
  352. 'parameters' => $parameters
  353. ));
  354. }
  355. }
  356. return theme('links', array(
  357. 'links' => $links,
  358. 'attributes' => array('class' => 'links pager pager-list')
  359. ));
  360. }
  361. }
  362. return '';
  363. }
  364. /**
  365. * Return an array suitable for theme_links() rather than marked up HTML link.
  366. */
  367. function tao_pager_link($vars) {
  368. $text = $vars['text'];
  369. $page_new = $vars['page_new'];
  370. $element = $vars['element'];
  371. $parameters = $vars['parameters'];
  372. $attributes = $vars['attributes'];
  373. $page = isset($_GET['page']) ? $_GET['page'] : '';
  374. if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
  375. $parameters['page'] = $new_page;
  376. }
  377. $query = array();
  378. if (count($parameters)) {
  379. $query = drupal_get_query_parameters($parameters, array());
  380. }
  381. if ($query_pager = pager_get_query_parameters()) {
  382. $query = array_merge($query, $query_pager);
  383. }
  384. // Set each pager link title
  385. if (!isset($attributes['title'])) {
  386. static $titles = NULL;
  387. if (!isset($titles)) {
  388. $titles = array(
  389. t('« first') => t('Go to first page'),
  390. t('‹ previous') => t('Go to previous page'),
  391. t('next ›') => t('Go to next page'),
  392. t('last »') => t('Go to last page'),
  393. );
  394. }
  395. if (isset($titles[$text])) {
  396. $attributes['title'] = $titles[$text];
  397. }
  398. else if (is_numeric($text)) {
  399. $attributes['title'] = t('Go to page @number', array('@number' => $text));
  400. }
  401. }
  402. return array(
  403. 'title' => $text,
  404. 'href' => $_GET['q'],
  405. 'attributes' => $attributes,
  406. 'query' => count($query) ? $query : NULL,
  407. );
  408. }
  409. /**
  410. * Override of theme_views_mini_pager().
  411. */
  412. function tao_views_mini_pager($vars) {
  413. $tags = $vars['tags'];
  414. $quantity = $vars['quantity'];
  415. $element = $vars['element'];
  416. $parameters = $vars['parameters'];
  417. global $pager_page_array, $pager_total;
  418. // Calculate various markers within this pager piece:
  419. // Middle is used to "center" pages around the current page.
  420. $pager_middle = ceil($quantity / 2);
  421. // current is the page we are currently paged to
  422. $pager_current = $pager_page_array[$element] + 1;
  423. // max is the maximum page number
  424. $pager_max = $pager_total[$element];
  425. // End of marker calculations.
  426. $links = array();
  427. if ($pager_total[$element] > 1) {
  428. $links['pager-previous'] = theme('pager_previous', array(
  429. 'text' => (isset($tags[1]) ? $tags[1] : t('Prev')),
  430. 'element' => $element,
  431. 'interval' => 1,
  432. 'parameters' => $parameters
  433. ));
  434. $links['pager-current'] = array(
  435. 'title' => t('@current of @max', array(
  436. '@current' => $pager_current,
  437. '@max' => $pager_max)
  438. )
  439. );
  440. $links['pager-next'] = theme('pager_next', array(
  441. 'text' => (isset($tags[3]) ? $tags[3] : t('Next')),
  442. 'element' => $element,
  443. 'interval' => 1,
  444. 'parameters' => $parameters
  445. ));
  446. return theme('links', array('links' => $links, 'attributes' => array('class' => array('links', 'pager', 'views-mini-pager'))));
  447. }
  448. }