View source
<?php
function custompage_view_tile($name, $title = '', $display_id = 'block_1') {
$args = func_get_args();
array_shift($args);
if (count($args)) {
array_shift($args);
}
if (count($args)) {
array_shift($args);
}
$view = views_get_view($name);
if (empty($view)) {
return;
}
if ($title !== FALSE) {
if (empty($title)) {
$display_title = $view->display[$display_id]->display_options['title'];
$title = $display_title;
if (empty($display_title)) {
$title = $view->display['default']->display_options['title'];
if (empty($title)) {
$title = $view->display[$display_id]->display_title;
}
}
}
}
if (!isset($view->override_path)) {
$view->override_path = $_GET['q'];
}
$content = $view
->preview($display_id, $args);
if (!empty($title)) {
$content = "<div><h2>{$title}</h2>{$content}</div>";
}
$editlink = custompage_edit_link('admin/structure/views/edit/' . $name);
$tile = custompage_tile_wrap($content, $editlink);
return $tile;
}
function custompage_node_tile($key, $type = '', $teaser_only = FALSE, $show_title = TRUE) {
global $language;
$langcode = $language->language;
$default = language_default();
$default_langcode = $default->language;
if (is_numeric($key)) {
$node = node_load($key);
}
else {
if (is_string($key) && !empty($type) && is_string($type)) {
$entities = entity_load('node', FALSE, $conditions = array(
'title' => $key,
'type' => $type,
));
$node = $entities[1];
}
}
if (!is_object($node)) {
return ' ';
}
$sql = db_select('node', 'n');
$sql
->fields('n', array(
'nid',
));
$and = db_and()
->condition('tnid', $node->nid)
->condition('language', $langcode);
$sql
->condition($and);
$i18n_nid = $sql
->execute()
->fetchField();
if (is_numeric($i18n_nid) && $i18n_nid > 0) {
$node = node_load($i18n_nid);
}
if (!$show_title) {
unset($node->title);
}
if ($teaser_only == FALSE) {
$view_mode = 'full';
}
else {
$view_mode = 'teaser';
}
$node_view = node_view($node, $view_mode, $langcode);
$content = drupal_render($node_view);
$editlink = custompage_edit_link('node/' . $node->nid . '/edit/');
$tile = custompage_tile_wrap($content, $editlink);
return $tile;
}
function custompage_region_tile($region) {
$tile = theme('blocks', $region);
if (empty($tile)) {
return '';
}
$editlink = custompage_edit_link('admin/structure/block/list', FALSE);
$tile = custompage_tile_wrap($tile, $editlink);
return $tile;
}
function custompage_menu_tile($menu_name) {
$out = "<ul class=\"menu-{$menu_name}\">";
$menu = menu_navigation_links($menu_name);
foreach ($menu as $item) {
$item = _custompage_translate_path($item);
$out .= "<li>" . theme_menu_item_link($item) . "</li>";
}
$out .= "</ul>";
$editlink = custompage_edit_link('admin/structure/menu-customize/' . $menu_name);
$tile = custompage_tile_wrap($out, $editlink);
return $tile;
}
function custompage_edit_link($url, $return = TRUE) {
if ($return) {
$dest = substr($_SERVER['REQUEST_URI'], 1);
if (strpos('?', $url) === FALSE) {
$url .= '?';
}
$url .= "destination={$dest}";
}
$editlink = l(t('Edit'), $url);
$editlink = urldecode($editlink);
return $editlink;
}
function custompage_tile_wrap($content, $editlink) {
if (empty($content)) {
return '';
}
$out = $content;
$extraclass = '';
if (user_access('edit custompage tiles') && variable_get('custompage_inline_edit', FALSE)) {
$out = '<div class="edit">' . $editlink . '</div>' . $out;
$extraclass = 'cp_showborder';
}
return '<div class="cp_tile ' . $extraclass . '">' . $out . '</div>';
}
function _custompage_translate_path($link) {
global $language;
if ($language && module_exists('translation')) {
$new_paths = translation_path_get_translations($link['href']);
if ($new_paths[$language->language]) {
$link['href'] = $new_paths[$language->language];
}
$link['title'] = t($link['title']);
if ($link['attributes']['title']) {
$link['attributes']['title'] = t($link['attributes']['title']);
}
}
return $link;
}