View source
<?php
function single_page_site_help($path, $arg) {
switch ($path) {
case 'admin/help#single_page_site':
$output = file_get_contents(drupal_get_path('module', 'single_page_site') . '/README.txt');
return module_exists('markdown') ? module_invoke('markdown', 'filter', 'process', 0, -1, $output) : '<pre>' . $output . '</pre>';
}
}
function single_page_site_permission() {
return array(
'administer single page site' => array(
'title' => t('Administer single page site'),
'description' => t('Configure Single Page Site settings.'),
),
'view single page site' => array(
'title' => t('View single page site'),
'description' => t('Decide who can view Single Page Site.'),
),
);
}
function single_page_site_menu() {
$items = array();
$items['single-page-site'] = array(
'title' => 'Single Page Website',
'page callback' => 'single_page_site_callback',
'access arguments' => array(
'view single page site',
),
'file' => 'includes/single_page_site.callback.inc',
);
$items['admin/config/system/single-page-site'] = array(
'title' => 'Single Page Site Settings',
'description' => 'Configure menu\'s and classes etc.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'single_page_site_settings_form',
),
'access arguments' => array(
'administer single page site',
),
'file' => 'includes/single_page_site.admin.inc',
);
return $items;
}
function single_page_site_theme() {
return array(
'single_page_site' => array(
'template' => 'single-page-site',
'variables' => array(
'items' => array(),
'wrapper' => 'single-page-overall-wrapper',
),
),
);
}
function single_page_site_page_build(&$page) {
global $language;
$settings = variable_get('single_page_site_settings', array());
if (!empty($settings)) {
$path = drupal_get_path('module', 'single_page_site');
$page['page_bottom']['single_page_site'] = array(
'#attached' => array(),
);
$attached =& $page['page_bottom']['single_page_site']['#attached'];
$options = array(
'every_page' => TRUE,
);
$attached['js'][$path . '/js/single-page-site-menu.js'] = $options;
$settings_js = array(
'className' => !empty($settings['class']) ? $settings['class'] : 'li',
'menuClass' => $settings['menuclass'],
'isFrontpage' => $settings['homepage'],
);
if (!$settings['homepage']) {
$settings_js['singlePage']['urlAlias'] = drupal_get_path_alias('single-page-site', $language->language);
}
$attached['js'][] = array(
'data' => array(
'singlePage' => $settings_js,
),
'type' => 'setting',
);
}
}
function single_page_site_html_head_alter(&$elements) {
if (current_path() == 'single-page-site') {
foreach ($elements as $key => $element) {
if (isset($element['#tag']) && $element['#tag'] == 'link' && (!isset($element['#theme']) || strpos($element['#theme'], 'metatag') === FALSE)) {
if (isset($element['#attributes']['rel']) && ($element['#attributes']['rel'] == 'canonical' || $element['#attributes']['rel'] == 'shortlink')) {
unset($elements[$key]);
}
}
}
}
}
function _single_page_site_generate_anchor($link) {
$temp_link = str_replace(array(
'/',
'?q=',
), array(
'',
'',
), $link);
return preg_replace('/[^A-Za-z0-9]/', '', $temp_link);
}
function _single_page_site_get_title($item) {
return isset($item['#localized_options']['attributes']['name']) ? check_plain($item['#localized_options']['attributes']['name']) : check_plain($item['#title']);
}
function single_page_site_form_menu_edit_item_alter(&$form, &$form_state) {
$settings = variable_get('single_page_site_settings', array());
if ($settings && $settings['menu'] == $form['original_item']['#value']['menu_name']) {
$form['#validate'][] = '_single_page_site_validate_menu_item';
}
}
function _single_page_site_validate_menu_item($form, &$form_state) {
if ($form_state['values']['link_path'] == 'single-page-site') {
form_set_error('link_path', t("You can't add this page to this menu, because it is used as a single page menu."));
}
elseif ($form_state['values']['link_path'] == '<front>') {
form_set_error('link_path', t("You can't add the frontpage in this menu, because it is your 'single page' page"));
}
}