template.php 15 KB

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