Beispiel #1
0
/**
 * Preprocessor for page.tpl.php template file.
 */
function dewey_preprocess_page(&$vars, $hook)
{
    global $user;
    $space = spaces_get_space();
    $context = context_get();
    $vars['space'] = $space;
    $vars['context'] = $context;
    // Replace screen/all stylesheets with print
    // We want a minimal print representation here for full control.
    if (isset($_GET['print'])) {
        $css = drupal_add_css();
        unset($css['all']);
        unset($css['screen']);
        $css['all'] = $css['print'];
        $vars['styles'] = drupal_get_css($css);
        // Add print header
        $vars['print_header'] = theme('print_header');
        // Replace all body classes
        $attr['class'] = 'print';
        // Use print template
        $vars['template_file'] = 'print-page';
        // Suppress devel output
        $GLOBALS['devel_shutdown'] = FALSE;
    }
    // If user is not a member of the group, add an "Join group" button.
    if (!empty($space) && $space->controllers->variable->space_type == "og" && !in_array($space->id, array_keys($user->og_groups))) {
        $add_group = array('add-group' => array('title' => t('Join group'), 'href' => 'og/subscribe/' . $space->id));
        $vars['context_links'] = theme('links', $add_group);
    }
    // If we're on on a user page or a group page, add an add group link.
    if (empty($vars['context_links']) && !in_array($space->controllers->variable->space_type, array('og', 'user')) && $user->uid != 0) {
        $add_group = array('add-group' => array('title' => t('Add Group'), 'href' => 'node/add/group'));
        $vars['context_links'] = theme('links', $add_group);
    }
    // If we're in the discussion context, add an add discussion link.
    if (empty($vars['context_links']) && isset($context['context']['spaces-feature-discussion'])) {
        $add_discussion = array('add-discussion' => array('title' => t('Add Discussion'), 'href' => 'node/add/story'));
        $vars['context_links'] = theme('links', $add_discussion);
    }
    // Path to theme
    $vars['path'] = base_path() . path_to_theme() . '/';
    // Create login or account page.
    list($user_picture, $user_picture_preset) = dewey_comment_user_picture($user->picture, $user->uid);
    $user_picture = "<div class='picture grid-1'>" . $user_picture . "</div>";
    $vars['user_picture'] = $user_picture;
    if ($user->uid) {
        $vars['user_account'] = $user_picture . " " . l($user->name, 'user') . "   " . l('logout', 'logout');
    } else {
        $vars['user_account'] = l('Login', 'user', array('attributes' => array('class' => 'user-account')));
    }
    $vars['user_account'] = "<span class='user-links'>" . $vars['user_account'] . "</span>";
    // Set title
    if ($space) {
        if (!empty($space->group->title)) {
            $vars['space_title'] = l(strtoupper($space->group->title), '<front>');
        }
    } else {
        $vars['space_title'] = $vars['title'];
    }
    // Create the menu item for the group settings tab for group admins.
    if (!empty($space) && $space->type == 'og') {
        $result = db_result(db_query("SELECT uid\n                        FROM {og_uid}\n                        WHERE is_admin = 1\n                        AND nid = %d\n                        AND uid = %d", $space->id, $user->uid));
        if ($result || $user->uid == 1) {
            $vars['space_settings'] = theme('group_settings_dropdown', $space);
        }
    }
    // Add custom breadcrumb.
    $active_menu = "";
    if (!empty($context['context'])) {
        $contexts = array_keys($context['context']);
        foreach ($contexts as $item) {
            if (preg_match('/spaces-feature.*/', $item, $matches)) {
                $active_menu = $context['context'][$item]->reactions['menu'];
            }
        }
    }
    $breadcrumb .= "<div id='breadcrumb'";
    $breadcrumb .= l("Home", base_path(), array('external' => true)) . " > ";
    if (isset($space->id)) {
        $breadcrumb .= l($space->group->title, "");
        if (!empty($active_menu)) {
            $breadcrumb .= " > " . l(capitalizeWords($active_menu), $active_menu);
        }
    } else {
        $breadcrumb = trim($breadcrumb, " >");
    }
    $breadcrumb .= "</div>";
    $vars['breadcrumb'] = $breadcrumb;
    $vars['meta'] = '';
    // SEO optimization, add in the node's teaser, or if on the homepage, the mission statement
    // as a description of the page that appears in search engines
    if ($vars['is_front'] && $vars['mission'] != '') {
        $vars['meta'] .= '<meta name="description" content="' . dewey_trim_text($vars['mission']) . '" />' . "\n";
    } else {
        if (isset($vars['node']->teaser) && $vars['node']->teaser != '') {
            $vars['meta'] .= '<meta name="description" content="' . dewey_trim_text($vars['node']->teaser) . '" />' . "\n";
        } else {
            if (isset($vars['node']->body) && $vars['node']->body != '') {
                $vars['meta'] .= '<meta name="description" content="' . dewey_trim_text($vars['node']->body) . '" />' . "\n";
            }
        }
    }
    // SEO optimization, if the node has tags, use these as keywords for the page
    if (isset($vars['node']->taxonomy)) {
        $keywords = array();
        foreach ($vars['node']->taxonomy as $term) {
            $keywords[] = $term->name;
        }
        $vars['meta'] .= '<meta name="keywords" content="' . implode(',', $keywords) . '" />' . "\n";
    }
    // SEO optimization, avoid duplicate titles in search indexes for pager pages
    if (isset($_GET['page']) || isset($_GET['sort'])) {
        $vars['meta'] .= '<meta name="robots" content="noindex,follow" />' . "\n";
    }
}
Beispiel #2
0
<?php

function capitalizeWords($line)
{
    $result = '';
    $words = explode(' ', $line);
    foreach ($words as $word) {
        if (strlen($result) > 0) {
            $result .= ' ';
        }
        $result .= ucfirst($word);
    }
    return $result;
}
//On parcours le fichiers en ignorant les lignes vides
$lines = file($argv[1], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
    $line = trim($line);
    print_r(capitalizeWords($line));
    print_r("\n");
}