You are here

function om_node_preprocess_html in OM Tools 7.2

Same name and namespace in other branches
  1. 8.2 tools/node/node.inc \om_node_preprocess_html()
  2. 8 tools/node/node.inc \om_node_preprocess_html()
  3. 7 tools/node/node.inc \om_node_preprocess_html()

Override or insert om variables into the templates.

File

tools/node/node.inc, line 64
Node Tools

Code

function om_node_preprocess_html(&$vars) {
  $node_tools = $vars['om_node_tools_values'];
  if (isset($node_tools['node_body_classes_switch']) && $node_tools['node_body_classes_switch'] == 1 || isset($node_tools['node_terms_classes_switch']) && $node_tools['node_terms_classes_switch'] == 1 || isset($node_tools['node_type_titles_switch']) && $node_tools['node_type_titles_switch'] == 1) {
    $classes = $vars['classes_array'];
    if (!$vars['is_front']) {

      // Add unique class for each page.
      $path = drupal_get_path_alias($_GET['q']);

      // path title
      $classes[] = om_tools_class_safe('page-' . $path);

      // default section
      list($section) = explode('/', $path, 2);
      $arg = arg();

      // get all arguments
      // the page must be a node
      if ($arg[0] == 'node') {

        // a better way of getting node types for D7
        $node = menu_get_object();
        $node_type = is_object($node) ? $node->type : '';
        if (isset($node_tools['node_body_classes']) && $node_tools['node_body_classes'] == 1) {
          if ($arg[1] == 'add' && isset($arg[2])) {

            // add node
            $section = 'node-add';
            $page_type = $arg[2];
            $page_type_op = $page_type . '-add';
          }
          elseif ($arg[1] == 'add' && !isset($arg[2])) {

            // add any node
            $section = 'node-add';
            $page_type = 'any';
            $page_type_op = $page_type . '-add';
          }
          elseif (is_numeric($arg[1]) && !isset($arg[2]) && empty($node_type)) {

            // not found
            $section = 'page-not-found';
            $page_type = 'any';
            $page_type_op = $page_type . '-view';
          }
          elseif (is_numeric($arg[1]) && !isset($arg[2])) {

            // view node
            // default $section
            $page_type = $node_type;
            $page_type_op = $page_type . '-view';
          }
          elseif (is_numeric($arg[1]) && isset($arg[2])) {

            // has arg 2, like delete, edit, etc.
            $section = 'node-' . $arg[2];
            $page_type = !empty($node_type) ? $node_type : 'any';
            $page_type_op = $page_type . '-' . $arg[2];
          }
          $classes[] = om_tools_class_safe($node_tools['node_body_classes_prefix'] . $page_type);
          $classes[] = om_tools_class_safe($node_tools['node_body_classes_prefix'] . $page_type_op);
        }
        if (isset($node_tools['node_terms_classes_switch']) && $node_tools['node_terms_classes_switch'] == 1) {

          // Term classes

          //$terms = (is_numeric($arg[1])) ? om_tools_taxonomy_node_get_terms(node_load($arg[1]), 'tid'): '';
          $terms = $node ? om_tools_taxonomy_node_get_terms($node, 'tid') : '';
          if (!empty($terms) && $node_tools['node_terms_classes']) {
            foreach ($terms as $term) {
              $classes[] = om_tools_class_safe($node_tools['node_terms_classes_prefix'] . $term->name);
            }
          }
        }

        //dsm($node_tools);

        // node titles
        if (isset($node_tools['node_type_titles_switch']) && $node_tools['node_type_titles_switch'] == 1) {
          if (!empty($node_type) && !empty($node_tools['node_' . $node_type . '_titles'])) {
            $classes[] = 'om-tools-no-title';
          }
        }

        //dsm($terms);
      }

      // if ($arg[0] == 'node') closing
      $classes[] = om_tools_class_safe('section-' . $section);
      $classes[] = 'om-tools-active';
    }
    $vars['classes_array'] = $classes;
    $vars['classes'] = implode(' ', $classes);

    // Concatenate with spaces.

    //dsm($vars);
  }
}