machine_name] = array('info' => t($content->title), 'cache' => DRUPAL_NO_CACHE, 'visibility' => BLOCK_VISIBILITY_LISTED,); } //Set block data for product documents to display in the admin $blocks['product_document_json'] = array('info' => t('Product Documents JSON for Magento'), 'cache' => DRUPAL_NO_CACHE, 'visibility' => BLOCK_VISIBILITY_LISTED,); return $blocks; } /** * Implementation of hook_views_query_alter(). */ /*function lyons_db_content_views_query_alter(&$view, &$query) { if ($view->name == 'product_document_json_output') { //var_dump($query->where[1]); $rolename = ''; foreach ($query->where as $where_index => $where) { // find the role ID clause $clause_index = array_search('users_roles.rid = %d', $where['clauses']); if ($clause_index !== FALSE) { // found it, so get the rolename $rolename = $where['args'][$clause_index]; break; } } // if the rolename argument was found if (!empty($rolename)) { // get the role ID $user_roles = user_roles(); $rid = array_search($rolename, $user_roles); // if the role exists, then replace the argument if ($rid !== FALSE) { $query->where[$where_index]['args'][$clause_index] = $rid; } } } } */ /** * Implementation of hook_block_view(). function lyons_db_content_block_view($delta) { $block = array(); if($delta == 'product_document_json') { $all_node_data = array(); //Get all "sticky" nodes for martin_product_document type $sticky_nodes = db_query('SELECT nid FROM {node} WHERE type = :type AND status = 1 AND sticky = 1', array(':type' => 'martin_product_document')); //STICKY nodes... foreach($sticky_nodes as $node) { $loaded_node = node_load($node->nid); if(isset($_REQUEST['product_sku']) && ($_REQUEST['product_sku'] == $loaded_node->field_product_sku['und'][0]['value'] || $_REQUEST['product_sku'] == 'alldocs')) { foreach($loaded_node->field_downloadable_file_category['und'] as $cat) { $term = taxonomy_term_load($cat['tid']); $term_name = strtolower(str_replace(" ", "_", $term->name)); $all_node_data[$term_name][($loaded_node->field_product_sku['und'][0]['value'])][] = _lyons_db_content_get_node_data($loaded_node); } } unset($loaded_node); } //Get all "non-sticky" nodes for martin_product_document type. We order by 'title' as a way to fake being able //to "weight" documents for display because 'title' is only displayed in the backend, not on the Mage PDP page. $reg_nodes = db_query('SELECT nid FROM {node} WHERE type = :type AND status = 1 AND sticky = 0 ORDER BY title ASC', array(':type' => 'martin_product_document')); foreach($reg_nodes as $node) { $loaded_node = node_load($node->nid); if(isset($_REQUEST['product_sku']) && ($_REQUEST['product_sku'] == $loaded_node->field_product_sku['und'][0]['value'] || $_REQUEST['product_sku'] == 'alldocs')) { foreach($loaded_node->field_downloadable_file_category['und'] as $cat) { $term = taxonomy_term_load($cat['tid']); $term_name = strtolower(str_replace(" ", "_", $term->name)); $all_node_data[$term_name][($loaded_node->field_product_sku['und'][0]['value'])][] = _lyons_db_content_get_node_data($loaded_node); } } unset($loaded_node); } $block['content'] = (!empty($all_node_data)) ? json_encode($all_node_data) : ''; } else { //Get block content from database to populate the block when viewed if($content = db_query('SELECT content FROM {lyons_db_content} WHERE machine_name = :delta', array(':delta' => $delta))->fetchField()) { $block['content'] = _lyons_db_content_replace($content); } } return $block; } /** * Implementation of hook_block_configure(). function lyons_db_content_block_configure($delta) { $params = explode('|', $delta); if(isset($params[0]) && $params[0] == 'product_document_json') { $all_node_data = array(); $all_terms = array(); //Get all "sticky" nodes for martin_product_document type $sticky_nodes = db_query('SELECT nid FROM {node} WHERE type = :type AND status = 1 AND sticky = 1', array(':type' => 'martin_product_document')); //STICKY nodes... foreach($sticky_nodes as $node) { $loaded_node = node_load($node->nid); if(isset($params[1]) && ($params[1] == $loaded_node->field_product_sku['und'][0]['value'] || $params[1] == 'alldocs')) { foreach($loaded_node->field_downloadable_file_category['und'] as $cat) { $term = taxonomy_term_load($cat['tid']); $term_name = strtolower(str_replace(" ", "_", $term->name)); if(!in_array($term_name, $all_terms)) { $all_terms[] = $term_name; } //These nodes are "sticky", so we'll go ahead and add them to the $all_node_data array first $all_node_data[$term_name][($loaded_node->field_product_sku['und'][0]['value'])][] = _lyons_db_content_get_node_data($loaded_node); } } unset($loaded_node); } //Get all "non-sticky" nodes for martin_product_document type. We order by 'title' as a way to fake being able //to "weight" documents for display because 'title' is only displayed in the backend, not on the Mage PDP page. $reg_nodes = db_query('SELECT nid FROM {node} WHERE type = :type AND status = 1 AND sticky = 0 ORDER BY title ASC', array(':type' => 'martin_product_document')); foreach($reg_nodes as $node) { $loaded_node = node_load($node->nid); if(isset($params[1]) && ($params[1] == $loaded_node->field_product_sku['und'][0]['value'] || $params[1] == 'alldocs')) { foreach($loaded_node->field_downloadable_file_category['und'] as $cat) { $term = taxonomy_term_load($cat['tid']); $term_name = strtolower(str_replace(" ", "_", $term->name)); if(!in_array($term_name, $all_terms)) { $all_terms[] = $term_name; } $all_node_data[$term_name][($loaded_node->field_product_sku['und'][0]['value'])][] = _lyons_db_content_get_node_data($loaded_node); } } unset($loaded_node); } if(!empty($all_node_data)) { $form['product_document_json'] = array('#type' => 'textarea', '#title' => t('JSON output of this block'), '#default_value' => json_encode($all_node_data), '#rows' => 20, '#resizable' => TRUE,); return $form; } else { return array(); } } else { //get block content from database, for admin block config form $contents = db_query('SELECT * FROM {lyons_db_content} WHERE machine_name = :delta', array(':delta' => $delta)); foreach($contents as $content) { $form['lyons_db_content'] = array('#type' => 'textarea', '#title' => t('HTML code for this block'), '#default_value' => $content->content, '#rows' => 10, '#resizable' => TRUE, '#description' => t('The following token values can be used: [lcg_show:site_search], [lcg_show:mega_menu], [lcg_show:find_a_rep], [lcg_show:site_logo]'),); return $form; } } } /** * Accepts a node object and creates an array of data that will be used on the Magento PDP page. function _lyons_db_content_get_node_data($node) { if(is_object($node) && !empty($node)) { $desc = (isset($node->field_downloadable_file_desc['und'][0]['value'])) ? $node->field_downloadable_file_desc['und'][0]['value'] : ''; $title = (isset($node->field_downloadable_files['und'][0]['description'])) ? $node->field_downloadable_files['und'][0]['description'] : ''; $url = (isset($node->field_downloadable_files['und'][0]['uri'])) ? file_create_url($node->field_downloadable_files['und'][0]['uri']) : ''; $mime = (isset($node->field_downloadable_files['und'][0]['filemime'])) ? $node->field_downloadable_files['und'][0]['filemime'] : ''; return array('description' => $desc, 'title' => $title, 'url' => $url, 'filemime' => $mime,); } return array(); } /** * Implementation of hook_block_save(). function lyons_db_content_block_save($delta, $edit = array()) { //Save changes made through the admin config form if($delta != 'product_document_json') { $cid = db_query('SELECT cid FROM {lyons_db_content} WHERE machine_name = :delta', array(':delta' => $delta))->fetchField(); if($cid) { db_update('lyons_db_content')->fields(array('content' => $edit['lyons_db_content'],))->condition('cid', $cid)->execute(); } } } /** * Implementation of hook_menu(). For setting Magento-specific variables. * at http://[drupalsite]/admin/config/lyons/lyons_db_content function lyons_db_content_menu() { $items = array(); $items['admin/config/lyons'] = array('title' => 'Lyons Module Configuration', 'description' => 'Various configuration settings for modules built by Lyons Consulting.', 'position' => 'left', 'weight' => -100, 'page callback' => 'system_admin_menu_block_page', 'access arguments' => array('administer site configuration'), 'file' => 'system.admin.inc', 'file path' => drupal_get_path('module', 'system'),); $items['admin/config/lyons/lyons_db_content'] = array('title' => 'Lyons DB Content', 'description' => 'Configuration settings for Magento Content.', 'page callback' => 'drupal_get_form', 'page arguments' => array('_lyons_db_content_form'), 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM,); //Don't set the variables to '' if they already contain some data! if(variable_get('lyons_db_content_magento_base_url', '') == '') { variable_set('lyons_db_content_magento_base_url', ''); } return $items; } /** * Lyons Magento Content admin config form. For setting Magento-specific variables. * at http://[drupalsite]/admin/config/lyons/lyons_db_content function _lyons_db_content_form($form, &$form_submit) { global $form_state; $form['lyons_db_content_magento_base_url'] = array('#type' => 'textfield', '#title' => t('Base URL for Magento'), '#description' => t('The URL where your Magento installation exists. For example: http://www.yoursite.com or http://www.yoursite.com/magento (DO NOT include trailing slash!)'), '#default_value' => variable_get('lyons_db_content_magento_base_url', ''), '#size' => 60, '#maxlength' => 128, '#required' => FALSE, '#attributes' => array('class' => array('magento-url')),); return system_settings_form($form); }*/ function lyons_db_content_block_view_alter(&$data, $block){ if($block->delta == 20){ _lyons_db_content_replace($data['content']); } } function _lyons_db_content_replace(&$content = '') { //replace token tags used in the admin config form with actual data to be displayed $content = str_ireplace('[lcg_show:mega_menu]', _lyons_db_content_get_mega_menu(), $content); $content = str_ireplace('[lcg_show:find_a_rep]', _lyons_db_content_get_find_a_rep(), $content); $content = str_ireplace('[lcg_show:site_logo]', _lyons_db_content_get_site_logo(), $content); $content = str_ireplace('[lcg_show:site_search]', _lyons_db_content_get_site_search(), $content); } /** * Implements hook_form_FORM_ID_alter(). function lyons_db_content_form_search_block_form_alter(&$form, &$form_state, $form_id) { $form['#action'] = '/search/node/'; } /** * All functions below are custom for each client */ function _lyons_db_content_get_site_search() { if(arg(0) == 'magento_services' && arg(1) == 'content_feed') { $this_form = "\n\n"; $this_form .= '

Search form

'; $this_form .= "\n\n"; return $this_form; } else { $form = drupal_get_form('search_block_form'); return "\n\n" . drupal_render($form) . "\n\n"; } } function _lyons_db_content_get_site_logo() { global $base_url; return '
'; } /** * Function returns the html necessary to display the find-a-rep dropdown in the header. */ function _lyons_db_content_get_find_a_rep() { $return_val = '
FIND A REPRESENTATIVE!
Inside the USA
Enter your ZIP code:
International
Select a country:
'; return $return_val; } /** * Function returns the html necessary to display the mega menu main navigation. */ function _lyons_db_content_get_mega_menu($microsite = 'base') { global $base_url; //Strings/html $martin_main_menu = $martin_mega_menu = ''; //Custom Menu Array $my_menu = array(); //Drupal menu array if ($microsite == 'vibesite') { $items = menu_load_links('menu-vibe-site-main-menu'); } else { $items = menu_load_links('main-menu'); } //var_dump($items); //A little preparation before we can build the menu: foreach($items as $item) { //For some reason, unpublished nodes are not "hidden". So, we must check the node status and manually make them hidden. if($item['router_path'] == 'node/%' && _lyons_db_content_node_is_unpublished($item['link_path'])){ $item['hidden'] = 1; } //Organize menus by plid (parent link id) $my_menu[($item['plid'])][] = $item; } $left = 157; //default starting place in pixels for css placement of mega menu divs $parent_count = 0; //Loop through each parent foreach($my_menu[0] as $parent) { if($parent['hidden']) { continue; } //gracefully move on if this item isn't supposed to be displayed $parent_count++; $div_id = $parent['mlid']; $child_count = 0; if(!isset($my_menu[($parent['mlid'])])) { //No children: link the main menu item directly with it's link_path $martin_main_menu .= '
  • ' . $parent['link_title'] . '
  • '; } else { //Has children: link the main menu item with javascript for opening it's mega menu //$martin_main_menu .= '
  • '.$parent['link_title'].'
  • '; //By client request, main menu links (except for Cougar) should not have a href. $main_link = ($parent['link_title'] == 'cougar') ? _lyons_db_content_get_menu_link($parent['link_path']) : '#'; $martin_main_menu .= '
  • ' . $parent['link_title'] . '
  • '; $total_child_count = count($my_menu[($parent['mlid'])]); //determine $left starting x coordinate for this parent's child menu $nonhidden_child_count = 0; foreach($my_menu[($parent['mlid'])] as $child) { //determine non-hidden child count! if($child['hidden']) { continue; } $nonhidden_child_count++; } $left = _lyons_db_content_get_menu_x_coord($parent_count, $nonhidden_child_count); if($nonhidden_child_count > 0) { $martin_mega_menu .= '