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/build/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(array(
'nid' => $key,
));
}
else {
if (is_string($key) && !empty($type) && is_string($type)) {
$node = node_load(array(
'title' => $key,
'type' => $type,
'language' => $default_langcode,
));
}
}
if (!is_object($node)) {
return ' ';
}
$sql = 'SELECT n.nid FROM {node} n WHERE n.tnid = %d and n.language = \'%s\' ';
$i18n_nid = db_result(db_query(db_rewrite_sql($sql), $node->nid, $langcode));
if (is_numeric($i18n_nid) && $i18n_nid > 0) {
$node = node_load($i18n_nid);
}
if (!$show_title) {
unset($node->title);
}
$content = node_view($node, $teaser_only, TRUE);
$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/build/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/build/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;
}