social_media_links.module 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. <?php
  2. /**
  3. * @file
  4. * Functions for the Social Media Links module.
  5. */
  6. /**
  7. * Implements hook_theme().
  8. */
  9. function social_media_links_theme($existing, $type, $theme, $path) {
  10. return array(
  11. 'social_media_links_platforms_table' => array(
  12. 'render element' => 'form',
  13. ),
  14. 'social_media_links_platforms' => array(
  15. 'variables' => array(
  16. 'platform_values' => array(),
  17. 'icon_style' => array(),
  18. 'appearance' => array(),
  19. 'link_attributes' => array(),
  20. 'attributes' => array(),
  21. ),
  22. ),
  23. 'social_media_links_platform' => array(
  24. 'variables' => array(
  25. 'info' => array(),
  26. 'name' => NULL,
  27. 'value' => NULL,
  28. 'icon_style' => array(),
  29. 'appearance' => array(),
  30. 'attributes' => array(),
  31. ),
  32. ),
  33. );
  34. }
  35. /**
  36. * Implements hook_ctools_plugin_directory().
  37. */
  38. function social_media_links_ctools_plugin_directory($module, $plugin) {
  39. if ($module == 'ctools' && $plugin == 'content_types') {
  40. return 'plugins/' . $plugin;
  41. }
  42. return FALSE;
  43. }
  44. /**
  45. * Implements hook_block_info().
  46. */
  47. function social_media_links_block_info() {
  48. $blocks['social-media-links'] = array(
  49. 'info' => t('Social Media Links'),
  50. // We cache per role, so that the edit/configure links display only if the
  51. // user has access.
  52. 'cache' => DRUPAL_CACHE_PER_ROLE,
  53. );
  54. return $blocks;
  55. }
  56. /**
  57. * Implements hook_block_configure().
  58. */
  59. function social_media_links_block_configure($delta = '') {
  60. if ($delta === 'social-media-links') {
  61. $values = array(
  62. 'platforms' => variable_get('social_media_links_platforms', array()),
  63. 'appearance' => variable_get('social_media_links_appearance', array()),
  64. 'icon_style' => variable_get('social_media_links_icon_style', ''),
  65. 'link_attributes' => variable_get('social_media_links_link_attributes', array()),
  66. );
  67. $form = social_media_links_form($values);
  68. return $form;
  69. }
  70. }
  71. function social_media_links_form($values) {
  72. $form = array();
  73. // Platforms.
  74. $form['platforms'] = array(
  75. '#type' => 'fieldset',
  76. '#title' => t('Platforms'),
  77. '#collapsible' => TRUE,
  78. '#collapsed' => FALSE,
  79. '#tree' => TRUE,
  80. '#theme' => 'social_media_links_platforms_table',
  81. );
  82. $platform_values = isset($values['platforms']) ? $values['platforms'] : array();
  83. $platforms = social_media_links_platforms();
  84. if (!empty($platform_values)) {
  85. // Combine the platforms with the weight value for sorting.
  86. foreach ($platforms as $key => $value) {
  87. if (isset($platform_values[$key]['weight'])) {
  88. $platforms[$key]['weight'] = $platform_values[$key]['weight'];
  89. }
  90. }
  91. uasort($platforms, 'drupal_sort_weight');
  92. }
  93. $i = -10;
  94. foreach ($platforms as $key => $value) {
  95. $form['platforms'][$key] = array(
  96. 'platform_value' => array(
  97. '#type' => 'textfield',
  98. '#title' => $value['title'],
  99. '#title_display' => 'invisible',
  100. '#size' => 40,
  101. '#field_prefix' => $value['base url'],
  102. '#default_value' => isset($platform_values[$key]['platform_value']) ? $platform_values[$key]['platform_value'] : '',
  103. ),
  104. 'weight' => array(
  105. '#type' => 'weight',
  106. '#title' => t('Weight'),
  107. '#title_display' => 'invisible',
  108. '#delta' => 10,
  109. '#default_value' => isset($platform_values[$key]['weight']) ? $platform_values[$key]['weight'] : $i + 1,
  110. '#attributes' => array('class' => array('weight')),
  111. ),
  112. );
  113. $i++;
  114. }
  115. // Appearance.
  116. $form['appearance'] = array(
  117. '#type' => 'fieldset',
  118. '#title' => t('Appearance'),
  119. '#collapsible' => TRUE,
  120. '#collapsed' => TRUE,
  121. '#tree' => TRUE,
  122. );
  123. $appearance_values = isset($values['appearance']) ? $values['appearance'] : array();
  124. $form['appearance']['orientation'] = array(
  125. '#type' => 'select',
  126. '#title' => t('Orientation'),
  127. '#default_value' => isset($appearance_values['orientation']) ? $appearance_values['orientation'] : 'h',
  128. '#options' => array(
  129. 'v' => t('vertical'),
  130. 'h' => t('horizontal'),
  131. ),
  132. );
  133. $form['appearance']['show_name'] = array(
  134. '#type' => 'checkbox',
  135. '#title' => t('Show name'),
  136. '#description' => t('Show the platform name next to the icon.'),
  137. '#default_value' => isset($appearance_values['show_name']) ? $appearance_values['show_name'] : 0,
  138. );
  139. // Link Attributes.
  140. $form['link_attributes'] = array(
  141. '#type' => 'fieldset',
  142. '#title' => t('Link attributes'),
  143. '#collapsible' => TRUE,
  144. '#collapsed' => TRUE,
  145. '#tree' => TRUE,
  146. );
  147. $link_values = isset($values['link_attributes']) ? $values['link_attributes'] : array();
  148. $form['link_attributes']['target'] = array(
  149. '#type' => 'select',
  150. '#title' => t('Default target'),
  151. '#default_value' => isset($link_values['target']) ? $link_values['target'] : '<none>',
  152. '#options' => array(
  153. '<none>' => t('Remove target attribute'),
  154. '_blank' => t('Open in a new browser window or tab (_blank)'),
  155. '_self' => t('Open in the current window (_self)'),
  156. '_parent' => t('Open in the frame that is superior to the frame the link is in (_parent)'),
  157. '_top' => t('Cancel all frames and open in full browser window (_top)'),
  158. ),
  159. );
  160. $form['link_attributes']['rel'] = array(
  161. '#type' => 'select',
  162. '#title' => t('Default rel'),
  163. '#default_value' => isset($link_values['rel']) ? $link_values['rel'] : '<none>',
  164. '#options' => array(
  165. '<none>' => t('Remove rel attribute'),
  166. 'nofollow' => t('Set nofollow'),
  167. ),
  168. );
  169. // Icon Sets.
  170. $form['icons'] = array(
  171. '#type' => 'fieldset',
  172. '#title' => t('Icon Sets'),
  173. '#collapsible' => TRUE,
  174. '#collapsed' => FALSE,
  175. );
  176. $options = social_media_links_iconsets_options();
  177. $form['icons']['icon_style'] = array(
  178. '#type' => 'select',
  179. '#title' => t('Icon Style'),
  180. '#default_value' => $values['icon_style'],
  181. '#options' => $options,
  182. );
  183. // Generate the icon set table.
  184. $header = array(
  185. array(
  186. 'data' => t('Name'),
  187. 'style' => 'width: 150px;',
  188. ),
  189. t('Sizes'),
  190. t('Icon examples and download instructions'),
  191. );
  192. $rows = array();
  193. $icons = social_media_links_iconsets();
  194. foreach ($icons as $iconset_name => $iconset) {
  195. if (isset($iconset['download url'])) {
  196. $name = '<strong>' . l($iconset['name'], $iconset['download url'], array('attributes' => array('target' => '_blank'))) . '</strong>';
  197. }
  198. else {
  199. $name = '<strong>' . $iconset['name'] . '</strong>';
  200. }
  201. if (isset($iconset['publisher'])) {
  202. $name .= '<br />' . t('by') . ' ';
  203. if (isset($iconset['publisher url'])) {
  204. $name .= l($iconset['publisher'], $iconset['publisher url'], array('attributes' => array('target' => '_blank')));
  205. }
  206. else {
  207. $name .= $iconset['publisher'];
  208. }
  209. }
  210. $row = array(
  211. $name,
  212. implode('<br />', $iconset['styles']),
  213. );
  214. if (!empty($iconset['path'])) {
  215. $row[] = _social_media_links_generate_example_table($platforms, $iconset);
  216. }
  217. else {
  218. $searchdirs = social_media_links_searchdirs($iconset_name);
  219. $str = '<strong>' . t('Not installed.') . '</strong><br />';
  220. $str .= t('To install: !download and install it into',
  221. array(
  222. '!download' => l(t('Download'), $iconset['download url'], array('attributes' => array('target' => '_blank'))),
  223. )
  224. );
  225. $str .= ' <code> DRUPAL_ROOT/' . preg_replace('/,([^,]+) ?$/', " " . t('or') . " $1", implode(', ', $searchdirs), 1) . '</code>.';
  226. if (isset($iconset['additional instructions'])) {
  227. $str .= ' ' . $iconset['additional instructions'];
  228. }
  229. $row[] = $str;
  230. }
  231. $rows[] = $row;
  232. $vars = array(
  233. 'header' => $header,
  234. 'rows' => $rows,
  235. 'attributes' => array(
  236. 'id' => 'social-media-links-iconsets',
  237. ),
  238. );
  239. $form['icons']['installed'] = array(
  240. '#markup' => theme('table', $vars),
  241. );
  242. }
  243. return $form;
  244. }
  245. /**
  246. * Implements hook_block_save().
  247. */
  248. function social_media_links_block_save($delta = '', $edit = array()) {
  249. if ($delta === 'social-media-links') {
  250. variable_set('social_media_links_platforms', $edit['platforms']);
  251. variable_set('social_media_links_appearance', $edit['appearance']);
  252. variable_set('social_media_links_link_attributes', $edit['link_attributes']);
  253. variable_set('social_media_links_icon_style', $edit['icon_style']);
  254. }
  255. }
  256. /**
  257. * Implements hook_block_view().
  258. */
  259. function social_media_links_block_view($delta = '') {
  260. $block = array();
  261. switch ($delta) {
  262. case 'social-media-links':
  263. $platforms = variable_get('social_media_links_platforms', array());
  264. $platforms = _social_media_links_cleanup_platforms($platforms);
  265. if (count($platforms) > 0) {
  266. $block['subject'] = t('Follow Us');
  267. $block['content'] = array(
  268. '#theme' => 'social_media_links_platforms',
  269. '#platform_values' => $platforms,
  270. '#icon_style' => variable_get('social_media_links_icon_style'),
  271. '#appearance' => variable_get('social_media_links_appearance'),
  272. '#link_attributes' => variable_get('social_media_links_link_attributes'),
  273. '#attributes' => array(
  274. 'class' => array('social-media-links', 'platforms'),
  275. ),
  276. );
  277. // Add css to the block.
  278. $block['content']['#attached']['css'][] = drupal_get_path('module', 'social_media_links') . '/social_media_links.css';
  279. }
  280. break;
  281. }
  282. return $block;
  283. }
  284. /**
  285. * Preprocesses variables for social media links platforms.
  286. *
  287. * @see theme_social_media_links_platforms()
  288. */
  289. function template_preprocess_social_media_links_platforms(&$variables) {
  290. $platform_infos = social_media_links_platforms();
  291. $icon_style = explode(':', $variables['icon_style']);
  292. // Apply the link settings to the render array.
  293. foreach ($variables['link_attributes'] as $key => $value) {
  294. if ($value == '<none>') {
  295. unset($variables['link_attributes'][$key]);
  296. }
  297. }
  298. // Sort and loop over the platforms.
  299. uasort($variables['platform_values'], 'drupal_sort_weight');
  300. foreach ($variables['platform_values'] as $platform_name => $platform_value) {
  301. // Build the platform data array.
  302. $variables['platforms'][$platform_name] = array(
  303. '#theme' => 'social_media_links_platform',
  304. '#name' => $platform_name,
  305. '#info' => $platform_infos[$platform_name],
  306. '#value' => $platform_value['platform_value'],
  307. '#icon_style' => $icon_style,
  308. '#appearance' => $variables['appearance'],
  309. '#attributes' => $variables['link_attributes'],
  310. );
  311. }
  312. if ($variables['appearance']['orientation'] == 'h') {
  313. $variables['attributes']['class'][] = 'inline horizontal';
  314. }
  315. else {
  316. $variables['attributes']['class'][] = 'vertical';
  317. }
  318. }
  319. /**
  320. * Processes variables for social-media-links-platform.tpl.php.
  321. *
  322. * @see theme_social_media_links_platform()
  323. */
  324. function template_preprocess_social_media_links_platform(&$variables) {
  325. $info = $variables['info'];
  326. $name = $variables['name'];
  327. $value = $variables['value'];
  328. $icon_style = $variables['icon_style'];
  329. // Call the url callback of the platform to create the link url.
  330. $variables['link'] = $info['base url'] . $value;
  331. if (isset($info['url callback'])) {
  332. $platform_url_changed = call_user_func($info['url callback'], $info['base url'], $value);
  333. if ($platform_url_changed) {
  334. $variables['link'] = $platform_url_changed;
  335. }
  336. }
  337. $variables['attributes']['title'] = check_plain($info['title']);
  338. $variables['icon_path'] = social_media_links_icon($icon_style[0], $name, $icon_style[1]);
  339. $variables['icon_alt'] = isset($info['image alt']) ? $info['image alt'] : $info['title'] . ' ' . t('icon');
  340. }
  341. /**
  342. * Get the available platforms.
  343. *
  344. * @return array
  345. * Returns a list of platforms.
  346. */
  347. function social_media_links_platforms() {
  348. $platforms = &drupal_static(__FUNCTION__);
  349. // Grab from cache or build the array.
  350. if (isset($platforms)) {
  351. return $platforms;
  352. }
  353. include_once 'social_media_links.platforms.inc';
  354. $platforms = array();
  355. $platforms = module_invoke_all('social_media_links_platform_info');
  356. drupal_alter('social_media_links_platform_info', $platforms);
  357. return $platforms;
  358. }
  359. /**
  360. * Get all registered icon sets.
  361. *
  362. * @return array
  363. * Return a list of all registered platforms.
  364. */
  365. function social_media_links_iconsets() {
  366. $sets = &drupal_static(__FUNCTION__);
  367. // Grab from cache or build the array.
  368. if (isset($sets)) {
  369. return $sets;
  370. }
  371. include_once 'social_media_links.iconsets.inc';
  372. $sets = array();
  373. $sets = module_invoke_all('social_media_links_iconset_info');
  374. foreach ($sets as $key => $set) {
  375. if ($path = social_media_links_iconset_path($key)) {
  376. $sets[$key]['path'] = $path;
  377. }
  378. }
  379. drupal_alter('social_media_links_iconset_info', $sets);
  380. return $sets;
  381. }
  382. /**
  383. * Get informations about a specific icon set.
  384. *
  385. * @param string $iconset
  386. * Name of the icon set.
  387. *
  388. * @return array
  389. * Informations about the icon set.
  390. */
  391. function social_media_links_iconset($iconset) {
  392. $sets = social_media_links_iconsets();
  393. return isset($sets[$iconset]) ? $sets[$iconset] : FALSE;
  394. }
  395. /**
  396. * Get the path of a platform icon.
  397. *
  398. * @param string $iconset
  399. * Name of the icon set.
  400. * @param string $platform
  401. * Name of the platform.
  402. * @param string $style
  403. * Icon size.
  404. *
  405. * @return string
  406. * Path to the icon image.
  407. */
  408. function social_media_links_icon($iconset, $platform, $style) {
  409. $iconset = social_media_links_iconset($iconset);
  410. return call_user_func($iconset['path callback'], $platform, $style);
  411. }
  412. /**
  413. * Returns an array with the possible locations of the installed iconsets.
  414. *
  415. * @param string $iconset
  416. * Optional: Name of the iconset.
  417. *
  418. * @return array
  419. * Possible path locations of the iconsets.
  420. */
  421. function social_media_links_searchdirs($iconset = '') {
  422. $searchdirs = array();
  423. $profile = drupal_get_path('profile', drupal_get_profile());
  424. $config = conf_path();
  425. // Similar to 'modules' and 'themes' directories in the root directory,
  426. // certain distributions may want to place libraries into a 'libraries'
  427. // directory in Drupal's root directory.
  428. $searchdirs[] = 'libraries';
  429. // Similar to 'modules' and 'themes' directories inside an installation
  430. // profile, installation profiles may want to place libraries into a
  431. // 'libraries' directory. But exclude/ignore the standard drupal profiles.
  432. if (!in_array($profile, array('minimal', 'standard', 'testing'))) {
  433. $searchdirs[] = "$profile/libraries";
  434. }
  435. // Always search sites/all/libraries.
  436. $searchdirs[] = 'sites/all/libraries';
  437. // Also search sites/<domain>/libraries.
  438. $searchdirs[] = "$config/libraries";
  439. if (!empty($iconset)) {
  440. foreach ($searchdirs as $key => $dir) {
  441. $searchdirs[$key] = $dir . '/' . $iconset;
  442. }
  443. }
  444. return $searchdirs;
  445. }
  446. /**
  447. * Return an array of library directories.
  448. *
  449. * @return array
  450. * A list of library directories.
  451. */
  452. function social_media_links_libraries() {
  453. $directories = &drupal_static(__FUNCTION__);
  454. // Grab from cache or build the array.
  455. if (isset($directories)) {
  456. return $directories;
  457. }
  458. $searchdirs = social_media_links_searchdirs();
  459. // Add the social_media_links module directory.
  460. $searchdirs[] = drupal_get_path('module', 'social_media_links') . '/libraries';
  461. $directories = array();
  462. $nomask = array('CVS');
  463. foreach ($searchdirs as $dir) {
  464. if (is_dir($dir) && $handle = opendir($dir)) {
  465. while (FALSE !== ($file = readdir($handle))) {
  466. if (!in_array($file, $nomask) && $file[0] != '.') {
  467. if (is_dir("$dir/$file")) {
  468. $directories[$file] = "$dir/$file";
  469. }
  470. }
  471. }
  472. closedir($handle);
  473. }
  474. }
  475. return $directories;
  476. }
  477. /**
  478. * Return the library path of an icon set.
  479. *
  480. * @param string $iconset
  481. * Name of the icon set.
  482. *
  483. * @return string
  484. * Path of the icon set.
  485. */
  486. function social_media_links_iconset_path($iconset) {
  487. $path = FALSE;
  488. $libraries = social_media_links_libraries();
  489. if (array_key_exists($iconset, $libraries)) {
  490. $path = $libraries[$iconset];
  491. }
  492. return $path;
  493. }
  494. /**
  495. * Get the list options for the icon set style select.
  496. *
  497. * @return array
  498. * Array with the select options.
  499. */
  500. function social_media_links_iconsets_options() {
  501. $iconsets = social_media_links_iconsets();
  502. $options = array();
  503. foreach ($iconsets as $iconset_name => $iconset) {
  504. if (!empty($iconset['path'])) {
  505. foreach ($iconset['styles'] as $sid => $style) {
  506. $options[$iconset['name']][$iconset_name . ':' . $sid] = $style;
  507. }
  508. }
  509. }
  510. return $options;
  511. }
  512. /**
  513. * Theme function for the platforms.
  514. */
  515. function theme_social_media_links_platforms(&$variables) {
  516. $output = '';
  517. $platforms = $variables['platforms'];
  518. $attributes = $variables['attributes'];
  519. // Open the ul element.
  520. $output .= '<ul' . drupal_attributes($attributes) . '>';
  521. $num_platforms = count($platforms);
  522. $i = 1;
  523. foreach ($platforms as $name => $platform) {
  524. $class = array($name);
  525. // Add first and last classes to the list of platforms to help out themers.
  526. if ($i == 1) {
  527. $class[] = 'first';
  528. }
  529. if ($i == $num_platforms) {
  530. $class[] = 'last';
  531. }
  532. $output .= '<li ' . drupal_attributes(array('class' => $class)) . '>';
  533. // Render the platform item.
  534. $output .= drupal_render($platform);
  535. $output .= '</li>';
  536. $i++;
  537. }
  538. // Close the ul element.
  539. $output .= '</ul>';
  540. return $output;
  541. }
  542. /**
  543. * Theme function for a single platform element.
  544. */
  545. function theme_social_media_links_platform(&$variables) {
  546. $output = '';
  547. $icon = theme_image(array(
  548. 'path' => $variables['icon_path'],
  549. 'alt' => $variables['icon_alt'],
  550. 'attributes' => array(),
  551. ));
  552. $options = array();
  553. $options['attributes'] = $variables['attributes'];
  554. $options['html'] = TRUE;
  555. $output .= l($icon, $variables['link'], $options);
  556. if (!empty($variables['appearance']['show_name'])) {
  557. if ($variables['appearance']['orientation'] == 'h') {
  558. $output .= '<br />';
  559. }
  560. $title = check_plain($variables['attributes']['title']);
  561. $output .= '<span>' . l($title, $variables['link'], $options) . '</span>';
  562. }
  563. return $output;
  564. }
  565. /**
  566. * Returns HTML for the platform table with tabledrag.
  567. */
  568. function theme_social_media_links_platforms_table(&$variables) {
  569. $form = $variables['form'];
  570. $rows = array();
  571. foreach (element_children($form) as $platform) {
  572. $form[$platform]['weight']['#attributes']['class'] = array('platforms-order-weight');
  573. $rows[] = array(
  574. 'data' => array(
  575. '<strong>' . $form[$platform]['platform_value']['#title'] . '<strong>',
  576. array('class' => array('platform-cross'), 'data' => drupal_render($form[$platform]['platform_value'])),
  577. array('class' => array('tabledrag-hide'), 'data' => drupal_render($form[$platform]['weight'])),
  578. ),
  579. 'class' => array('draggable'),
  580. );
  581. }
  582. $header = array(
  583. t('Platform'),
  584. '',
  585. array(
  586. 'class' => array('tabledrag-hide'),
  587. 'data' => t('Weight'),
  588. ),
  589. );
  590. $output = theme('table', array(
  591. 'header' => $header,
  592. 'rows' => $rows,
  593. 'attributes' => array('id' => 'platforms-order'),
  594. ));
  595. drupal_add_tabledrag('platforms-order', 'order', 'silbing', 'platforms-order-weight');
  596. return $output;
  597. }
  598. /**
  599. * Helper function to clean up the platforms array from the empty
  600. * values.
  601. *
  602. * @param array $platforms
  603. * The array with the platforms.
  604. *
  605. * @return array
  606. * The cleaned platforms array.
  607. */
  608. function _social_media_links_cleanup_platforms($platforms) {
  609. foreach ((array) $platforms as $key => $platform) {
  610. if (empty($platform['platform_value'])) {
  611. unset($platforms[$key]);
  612. }
  613. }
  614. return $platforms;
  615. }
  616. /**
  617. * Helper function to generate the icon set example table.
  618. *
  619. * @param array $platforms
  620. * Keyed array with all available platforms.
  621. * @param array $iconset
  622. * Array with the information about the icon set.
  623. *
  624. * @return string
  625. * The generated table markup.
  626. */
  627. function _social_media_links_generate_example_table($platforms, $iconset) {
  628. if (!is_array($platforms) && count($platforms) == 0) {
  629. return '';
  630. }
  631. $groups = array_chunk($platforms, 10, TRUE);
  632. $output = '';
  633. // Use the first iconset style for the sample table.
  634. $style = key($iconset['styles']);
  635. foreach ($groups as $group) {
  636. $header = array();
  637. $row = array();
  638. foreach ($group as $platform_name => $platform) {
  639. $header[] = array(
  640. 'data' => $platform['title'],
  641. 'style' => 'text-align: center; ',
  642. );
  643. $vars = array('path' => call_user_func($iconset['path callback'], $platform_name, $style));
  644. if (file_exists($vars['path'])) {
  645. $row[] = array(
  646. 'data' => theme('image', $vars) . ' ',
  647. 'style' => 'text-align: center;',
  648. );
  649. }
  650. else {
  651. $row[] = array(
  652. 'data' => '–',
  653. 'style' => 'text-align: center;',
  654. );
  655. }
  656. }
  657. $vars = array(
  658. 'header' => $header,
  659. 'rows' => array('data' => $row),
  660. );
  661. $output .= theme('table', $vars);
  662. $output .= '<br />';
  663. }
  664. return $output;
  665. }