diff --git a/filters_dp.info b/filters_dp.info new file mode 100644 index 0000000000000000000000000000000000000000..59e334029447f9786221193d864b067ab6e02083 --- /dev/null +++ b/filters_dp.info @@ -0,0 +1,7 @@ +name = Filters for Dutch+ +description = Filters for displaying content in Dutch+ +core = 7.x +package = Others +configure = admin/settings/filters_dp +stylesheets[all][] = style/filters_dp.css +scripts[] = js/filters_dp.js diff --git a/filters_dp.install b/filters_dp.install new file mode 100644 index 0000000000000000000000000000000000000000..3b64267500c2eaacb6c6967917d67c7636044660 --- /dev/null +++ b/filters_dp.install @@ -0,0 +1,110 @@ +<?php + +/* + * @file + * Install file of filters_dp + * + */ + +/** + * Implements hook_schema(). + */ +function filters_dp_schema() { + $schema = array(); + + $schema['filters_dp_content'] = array( + 'description' => t('Links the content with the filters'), + 'fields' => array( + 'id' => array( + 'type' => 'serial', // incremental + 'unsigned' => TRUE, // no negative integers + 'size' => 'normal', // tiny, small, medium, normal, big + 'not null' => TRUE, // default FALSE + 'description' => t('The primary identifier.'), + ), + 'nid' => array( + 'type' => 'int', + 'size' => 'normal', + 'not null' => TRUE, + 'description' => t('Node id') + ), + 'fid' => array( + 'type' => 'int', + 'size' => 'normal', + 'not null' => TRUE, + 'description' => t('Filter id') + ), + ), + 'primary key' => array('id'), + ); + + $schema['filters_dp_list'] = array( + 'description' => t('Filters list'), + 'fields' => array( + 'id' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'size' => 'normal', + 'not null' => TRUE, + 'description' => t('The primary identifier for a possibility.'), + ), + 'title' => array( + 'type' => 'text', + 'size' => 'normal', + 'description' => t('Title of the filter'), + ), + 'main_page' => array( + 'type' => 'int', + 'size' => 'normal', + 'description' => t('The node of the main page of the filter'), + ), + ), + 'primary key' => array('id'), + ); + + return $schema; +} + +/** + * Implements hook_install(). + */ +function filters_dp_install() { + _filters_dp_install_db(); +} + +/** + * Introduces the example filters + */ +function _filters_dp_install_db() { + $filter = array(); + $filter[1] = array( + 'title' => 'Beginners' + ); + $filter[2] = array( + 'title' => 'Docenten' + ); + $filter[3] = array( + 'title' => 'English' + ); + + foreach ($filter as $value) { + db_insert('filters_dp_list') + ->fields(array('title')) + ->values($value) + ->execute(); + } +} + +/** + * Adds main page field for each filter + */ + +function filters_dp_update_7100() { + $spec = array( + 'type' => 'int', + 'size' => 'normal', + 'description' => t('The node of the main page of the filter'), + ); + + db_add_field('filters_dp_list', 'main_page', $spec); +} diff --git a/filters_dp.module b/filters_dp.module new file mode 100644 index 0000000000000000000000000000000000000000..b30754f4fa88c1b7db8169ea1560d366052ae674 --- /dev/null +++ b/filters_dp.module @@ -0,0 +1,140 @@ +<?php + +/* + * @file + * Module file of filters_dp + */ + +module_load_include('inc', 'filters_dp', 'forms'); +module_load_include('inc', 'filters_dp', 'functions'); +module_load_include('inc', 'filters_dp', 'views'); + +/** + * Implements hook_menu(). + * + * Here we set up the URLs (menu entries) for the + * form examples. Note that most of the menu items + * have page callbacks and page arguments set, with + * page arguments set to be functions in external files. + */ +function filters_dp_menu() { + + // Admin menus + + $items['admin/settings/filters_dp'] = array( + 'title' => 'Filters Dutch+ Configuration', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('filters_dp_settings_form'), + 'access arguments' => array('administer filters_dp'), + 'type' => MENU_NORMAL_ITEM + ); + + $items['admin/settings/filters_dp/list'] = array( + 'title' => 'Filters Dutch+ Configuration', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('filters_dp_admin_settings_form'), + 'access arguments' => array('administer filters_dp'), + 'type' => MENU_NORMAL_ITEM + ); + + $items['set-filter/%'] = array( + 'title' => 'Filter Callback', + 'page callback' => '_filters_dp_activate_filter', + 'page arguments' => array(1), + 'type' => MENU_CALLBACK, + 'access callback' => TRUE, + ); + + return $items; +} + +/** + * Implements hook_permission(). + * + * Since the access to our new custom pages will be granted based on + * special permissions, we need to define what those permissions are here. + * This ensures that they are available to enable on the user role + * administration pages. + */ +function filters_dp_permission() { + $permissions = array( + 'administer filters_dp' => array( + 'title' => t('Administer Filters Dutch+'), + 'description' => t('Associate nodes with filters'), + 'restrict access' => TRUE, + ), + ); + + return $permissions; +} + +function filters_dp_form_alter(&$form, &$form_state, $form_id) { + if ($form_id == 'filters_dp_settings_form') { + $form['#submit'][] = '_filters_dp_admin_submit_handler'; + } +} + +/** +* Implements hook_block_info(). +*/ +function filters_dp_block_info() { + $blocks = array(); + + $blocks['filters'] = array( + 'info' => t('Filters'), + ); + + return $blocks; +} + +/** +* Implements hook_block_view(). +*/ +function filters_dp_block_view($delta = '') { + $block = array(); + + switch ($delta) { + case 'filters': + $block['subject'] = ''; + $block['content'] = _filters_dp_block_content(); + break; + } + + return $block; +} + +/** + * Implements hook_library(); + */ + +function filters_dp_library() { + $libraries['filters_dp_js'] = array( + 'title' => 'filters_dp', + 'version' => '1', + 'js' => array( + drupal_get_path('module', 'filters_dp') . '/js/filters_dp.js' => array(), + ), + ); + return $libraries; + + $libraries['filters_dp'] = array( + 'title' => 'filters_dp', + 'version' => '1', + 'js' => array( + array( + 'type' => 'setting', + 'data' => array('fid' => 1), + ), + ), + ); + return $libraries; +} + +/** + * Implements hook_page_alter(&$page); + */ +function filters_dp_page_alter(&$page) { + if (isset($_SESSION['filters_dp'])) { + drupal_add_js(array('filters_dp' => $_SESSION['filters_dp']), 'setting'); + } +} diff --git a/forms.inc b/forms.inc new file mode 100644 index 0000000000000000000000000000000000000000..0262bea239e9ffca5d749a15cec767de9d76413b --- /dev/null +++ b/forms.inc @@ -0,0 +1,84 @@ +<?php + +/** + * @file - All forms go in this file + */ + + +function filters_dp_settings_form($form, &$form_state) { + $form = array(); + + $form['list'] = array( + '#markup' => _filters_dp_get_nodes(), + ); + + $filters = _filters_dp_get_filters(); + $options = array(); + foreach ($filters as $filter) { + $options[$filter->id] = $filter->title; + } + + $form['filter'] = array( + '#type' => 'select', + '#title' => t('Select filter'), + '#options' => $options, + ); + + $form['node'] = array( + '#type' => 'textfield', + '#title' => t('Nid'), + '#required' => TRUE, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Add'), + ); + + return $form; +} + +function filters_dp_settings_form_submit($form, &$form_state) { + $nid = $form_state['values']['node']; + $fid = $form_state['values']['filter']; + + _filters_dp_insert_record($nid, $fid); + + drupal_set_message(t('Node added to filter')); +} + +function filters_dp_admin_settings_form($form, &$form_state) { + $form = array(); + + $form['list'] = array( + '#markup' => _filters_dp_list_filters(), + ); + + $form['title'] = array( + '#type' => 'textfield', + '#title' => t('Title'), + '#required' => TRUE, + ); + + $form['main_page'] = array( + '#type' => 'textfield', + '#title' => t('Nid of the main page'), + '#required' => TRUE, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return $form; +} + +function filters_dp_admin_settings_form_submit($form, &$form_state) { + $title = $form_state['values']['title']; + $main_page = $form_state['values']['main_page']; + + _filters_dp_list_insert_record($title, $main_page); + + drupal_set_message(t('Node added')); +} diff --git a/functions.inc b/functions.inc new file mode 100644 index 0000000000000000000000000000000000000000..9fa858bb7dfcb5430c8379492d147ad0b05bdfe5 --- /dev/null +++ b/functions.inc @@ -0,0 +1,172 @@ +<?php + +/** + * @file - Diverse functions + */ + +function _filters_dp_insert_record($nid, $fid) { + $value = new stdClass(); + $value->nid = $nid; + $value->fid = $fid; + + $key = _filters_dp_find_record($nid, $fid); + + drupal_write_record('filters_dp_content', $value, $key); +} + +function _filters_dp_find_record($nid, $fid) { + + $key = array(); + + $query = db_select('filters_dp_content', 'c') + ->fields('c', array('id')) + ->condition('nid', $nid) + ->condition('fid', $fid) + ->execute(); + + $id = $query->fetchAssoc(); + + if (!empty($id)) { + $key = array('id'); + } + + return $key; +} + +function _filters_dp_get_filters() { + $query = db_select('filters_dp_list', 'l') + ->fields('l') + ->execute(); + + $filters = $query->fetchAll(); + + return $filters; +} + +function _filters_dp_get_nodes() { + + $header = array( + 'Node ID', + 'Title', + 'Filter', + ); + + $rows = array(); + + $results = db_select('filters_dp_content', 'c') + ->fields('c') + ->execute(); + + foreach ($results as $value) { + if ($value->nid != 0) { + $node = node_load($value->nid); + $filter = _filters_dp_load_filter($value->fid); + $rows[] = array( + $value->nid, + $node->title, + $filter->title, + ); + } + } + + return theme('table', array('header' => $header, 'rows' => $rows)); +} + +function _filters_dp_load_filter($fid) { + $query = db_select('filters_dp_list', 'l') + ->fields('l') + ->condition('id', $fid) + ->execute(); + + return $query->fetch(); +} + +function _filters_dp_admin_submit_handler(&$form, &$form_state) { + $form_state['redirect'] = 'admin/settings/filters_dp'; +} + +function _filters_dp_activate_filter($fid) { + + if ($fid != 0) { + $_SESSION['filters_dp']['nodes'] = _filters_dp_get_nodeID_by_fid($fid); + if ((isset($_SESSION['filters_dp']['fid']) && $_SESSION['filters_dp']['fid'] != $fid) || !isset($_SESSION['filters_dp']['fid'])) { + $_SESSION['filters_dp']['fid'] = $fid; + $nid = get_filter_main_page($fid); + drupal_goto("node/" . $nid); + } + else { + _filters_dp_remove_filter(); + drupal_goto('<front>'); + } + } + else { + _filters_dp_remove_filter(); + drupal_goto('<front>'); + } +} + +function _filters_dp_get_nodeID_by_fid($fid) { + + $query = db_select('filters_dp_content', 'c') + ->fields('c') + ->condition('fid', $fid) + ->execute(); + + $nids = array(); + + foreach ($query as $result) { + $nids[] = $result->nid; + } + + return $nids; +} + +function _filters_dp_remove_filter() { + unset($_SESSION['filters_dp']['nodes']); + $_SESSION['filters_dp']['fid'] = 1; +} + +function get_filter_main_page($fid) { + $query = db_select('filters_dp_list', 'c') + ->fields('c', array('main_page')) + ->condition('id', $fid) + ->execute(); + + $nid = $query->fetchField(); + + return $nid; +} + +function _filters_dp_list_insert_record($title, $main_page) { + $value = new stdClass(); + $value->title = $title; + $value->main_page = $main_page; + + drupal_write_record('filters_dp_list', $value, array()); +} + +function _filters_dp_list_filters() { + + $header = array( + 'Filter ID', + 'Title', + 'Main Page', + ); + + $rows = array(); + + $results = db_select('filters_dp_list', 'c') + ->fields('c') + ->execute(); + + foreach ($results as $value) { + $node = node_load($value->main_page); + $rows[] = array( + $value->id, + $value->title, + $node->title, + ); + } + + return theme('table', array('header' => $header, 'rows' => $rows)); +} diff --git a/images/beginners_off.jpg b/images/beginners_off.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e4a5f34e76b25fcf3afb3304e8ce3d0a9490aa97 Binary files /dev/null and b/images/beginners_off.jpg differ diff --git a/images/beginners_on.jpg b/images/beginners_on.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c144624891ddd8ef0460afca632a84ddb58e98f8 Binary files /dev/null and b/images/beginners_on.jpg differ diff --git a/images/docenten_off.jpg b/images/docenten_off.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0941f6d86f8b3a7be775a460bdb93b7b1ae35392 Binary files /dev/null and b/images/docenten_off.jpg differ diff --git a/images/docenten_on.jpg b/images/docenten_on.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e90d47c9a18ce2e252eea940890cb4f96df1f20e Binary files /dev/null and b/images/docenten_on.jpg differ diff --git a/images/engels_off.jpg b/images/engels_off.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0d84a56550fade3171afdf4cefc22e2cf32eb95f Binary files /dev/null and b/images/engels_off.jpg differ diff --git a/images/engels_on.jpg b/images/engels_on.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d1c39ce7a1a806aa6164ad68a98461ad7fe357c8 Binary files /dev/null and b/images/engels_on.jpg differ diff --git a/js/filters_dp.js b/js/filters_dp.js new file mode 100644 index 0000000000000000000000000000000000000000..f991afe15209cb8e20c9806ffcd945e159094a33 --- /dev/null +++ b/js/filters_dp.js @@ -0,0 +1,68 @@ +(function($) { + Drupal.behaviors.filters_dp = { + attach: function(context, settings) { + if (Drupal.settings.filters_dp && Drupal.settings.filters_dp.fid) { + switch(Drupal.settings.filters_dp.fid) { + case "1": + break; + case "2": + var color = "#f6f4b7"; + var hoverColor = '#faf9d7'; + break; + case "3": + var color = "#c9e1ea"; + var hoverColor = '#e2edf1'; + break; + case "4": + var color = "#b5cb88"; + var hoverColor = '#cddeab'; + break; + } + + if (color) { + var menu = $("#main-menu ul.menu li"); + menu.each(function( index ) { + var link = $(this).find("a").attr("href"); + link = link.replace("/node/",""); + if ($.inArray(link, Drupal.settings.filters_dp.nodes) > -1) { + $(this).css({"backgroundColor": color}); + // Add hover color too + $(this).hover( + function() { + $(this).css({"backgroundColor": hoverColor}); + }, + function() { + $(this).css({"backgroundColor": color}); + } + ); + + // Color also the parent menus + $(this).parents("li").css({"backgroundColor": color}); + $(this).parents("li").hover( + function() { + $(this).css({"backgroundColor": hoverColor}); + }, + function() { + $(this).css({"backgroundColor": color}); + } + ); + } + }); + } + + // Starting page + var pathname = window.location.pathname; + var node = pathname.replace("/node/", ""); + var pages = ["33", "34", "179"]; + if ($.inArray(node, pages) > -1) { + url = "https://dutchplusplus.ned.univie.ac.at/sites/all/modules/custom/filters_dp/js/img" + pages[$.inArray(node, pages)] + ".png"; + $("h1.title").css({"background": "url(" + url + ") no-repeat"}); + $("h1.title").css({"height": "60px"}); + $("h1.title").css({"text-align": "center"}); + $("h1.title").css({"padding-top": "20px"}); + $("h1.title").css({"margin-left": "50px"}); + } + } + } + } +})(jQuery); diff --git a/js/img179.png b/js/img179.png new file mode 100644 index 0000000000000000000000000000000000000000..704db8fbf09a6ffdd779e2f8b77f95f1b60b0715 Binary files /dev/null and b/js/img179.png differ diff --git a/js/img33.png b/js/img33.png new file mode 100644 index 0000000000000000000000000000000000000000..c590548c42fe0e4aa2a16e14e39c2b87f90a5831 Binary files /dev/null and b/js/img33.png differ diff --git a/js/img34.png b/js/img34.png new file mode 100644 index 0000000000000000000000000000000000000000..d6c90b4de79fe5bba0d860ac19984234bd1aa0b6 Binary files /dev/null and b/js/img34.png differ diff --git a/style/filters_dp.css b/style/filters_dp.css new file mode 100644 index 0000000000000000000000000000000000000000..65905beeebfbbbeb3f9c8bf18221e22c651b4b80 --- /dev/null +++ b/style/filters_dp.css @@ -0,0 +1,98 @@ +/** + * Filter block + */ +#filters { + margin: 70px auto; + font-family: "PT Sans", sans-serif; + width: 300px; +} + +.filter-box { + width: 84px; + height: 137px; + display: inline-block; + margin-left: 15px; +} + +.filter-box p { + margin: auto; + font-size: 11px; + font-family: "Open Sans", sans-serif; +} + +.filter-box img { +} + +.filter-box h1 { + font-size: 18px; + font-weight: bold; + margin: auto; + text-align: center; + background-color: #fff; + height: 40px; + padding-top: 10px; +} + +.filter-box h2 { + font-size: 18px; + font-weight: bold; + color: #89898b; + margin: 5px; + margin-left: 29px; +} + +.filter-box a { + color: #fff; + font-weight: bold; + text-decoration: none; + font-size: 15px; +} + +.filter-box .button-on { + color: #fff; + padding: 5px; + width: 25px; + margin: 0px auto; + float: left; +} + +#beginners { + background-color: #f6f4b7; + color: #e9eb3b; +} + +#docenten { + background-color: #c9e1ea; + color: #005b7f; +} + +#engels { + background-color: #b5cb88; + color: #309515; +} + +.button-off { + padding: 5px; + background-color: #89898b; + width: 25px; + float: left; +} + +.filter-box p.button-on { + margin-left: 23px; + float: left; +} + +.button-engels { + background-color: #309515; +} + +.button-beginners { + background-color: #e9eb3b; +} + + +.button-docenten { + background-color: #005b7f; +} + diff --git a/style/images/beginners.png b/style/images/beginners.png new file mode 100644 index 0000000000000000000000000000000000000000..88c9f7ce2b13e7e7799898096378e6dbbb004c69 Binary files /dev/null and b/style/images/beginners.png differ diff --git a/style/images/docenten.png b/style/images/docenten.png new file mode 100644 index 0000000000000000000000000000000000000000..b4683893a2d86bf285a330cbd9d31aba91a553ee Binary files /dev/null and b/style/images/docenten.png differ diff --git a/style/images/engels.png b/style/images/engels.png new file mode 100644 index 0000000000000000000000000000000000000000..cb45315cbd7a9c311410109c7e097fa3a1b51ee2 Binary files /dev/null and b/style/images/engels.png differ diff --git a/style/images/standaard.png b/style/images/standaard.png new file mode 100644 index 0000000000000000000000000000000000000000..94921cd406d806ae911ae2572b54c594239b62cf Binary files /dev/null and b/style/images/standaard.png differ diff --git a/style/style.css b/style/style.css new file mode 100644 index 0000000000000000000000000000000000000000..502ff18b2f47afdcc491fb95cb764de639b020f8 --- /dev/null +++ b/style/style.css @@ -0,0 +1,48 @@ +#filters { + margin: 50px auto; +} + +.filter-box { + width: 84pt; + height: 137pt; + border: 2px solid #8e8e8f; + display: inline-block; + margin-left: 15px; +} + +.filter-box p { + margin: auto; +} + +.filter-box img { + width: 84pt; +} + +.filter-box h1 { + font-size: 18px; + margin: auto; + text-align: center; + background-color: #fff; + height: 50px; + padding-top: 10px; +} + +#standaard { + background-color: #dbe9ee; + margin-left: 150px; + color: #1e4250; +} + +#beginners { + background-color: #fefee2; + color: #c5bf2e; +} + +#docenten { + background-color: #fbe6f1; + color: #b70862; +} + +#engels { + background-color: #e6f3cb; +} diff --git a/views.inc b/views.inc new file mode 100644 index 0000000000000000000000000000000000000000..2f3520a718ea86d8629a388d94f477fa3c61eae8 --- /dev/null +++ b/views.inc @@ -0,0 +1,29 @@ +<?php + +/** + * All functions that return HTML as output + */ + +function _filters_dp_block_content() { + + global $base_url; + + $html = '<div id="filters">'; + + $filters = _filters_dp_get_filters(); + + foreach ($filters as $filter) { + $image = $base_url . '/' . drupal_get_path('module', 'filters_dp'). '/images/' . strtolower($filter->title) . '_off.jpg'; + if (isset($_SESSION['filters_dp']) && $_SESSION['filters_dp']['fid'] == $filter->id) { + $image = $base_url . '/' . drupal_get_path('module', 'filters_dp'). '/images/' . strtolower($filter->title) . '_on.jpg'; + } + + $html .= '<div id="' . strtolower($filter->title) .'" class="filter-box">'; + $html .= '<a href="' . $base_url . '/set-filter/' . $filter->id . '"><img src="' . $image . '" /></a>'; + $html .= '</div>'; + } + + $html .= '</div>'; + + return $html; +}