A testimonial widget for a university department’s website. (WordPress)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
<?php /** * Adds Testimonial_Widget widget. Plugin Name: Testimonial Custom Plugin URI: socw-aaron.dev.pixotech.com Description: Create custom testimonials for the homepage. Version: 1.0 Author: Aaron McNeal Author URI: socw-aaron.dev.pixotech.com */ $is_widget = false; class Testimonial_Widget extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( 'testimonial_widget', // Base ID 'Story Widget', // Name array( 'description' => __( 'Story Widget' ) ) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { // get the category slug wanted by this widget $category_slug = isset( $instance['category'] ) ? $instance['category'] : 'Any'; // put it into an array since we're calling a shortcode handler, just to keep to the pattern $args_array = array( 'cat' => $category_slug ); echo display_story_widget( $args_array ); } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { if ( isset( $instance[ 'category' ] ) ) { $category = $instance[ 'category' ]; } else { $category = __( 'New category' ); } ?> <p> <label for="<?php echo $this->get_field_name( 'category' ); ?>"><?php _e( 'Category:' ); ?></label> <select class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>"> <option value="Any">Any</option> <?php $terms = get_terms( 'testimonial-category' ); $count = count($terms); if ( $count > 0 ) { foreach ($terms as $term) { if ( $term->slug == $category ) { $option = '<option value="'.$term->slug.'" selected>'; } else { $option = '<option value="'.$term->slug.'">'; } $option .= $term->name; $option .= ' ('.$term->count.')'; $option .= '</option>'; echo $option; } } ?> </select> </p> <?php } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { /* Start example //$instance = array(); //$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; //return $instance; // Stop example */ $instance = array(); $instance['category'] = ( ! empty( $new_instance['category'] ) ) ? strip_tags( $new_instance['category'] ) : ''; return $instance; } } // class Testimonial_Widget // register Testimonial_Widget widget function register_testimonial_widget() { register_widget( 'Testimonial_Widget' ); } add_action( 'widgets_init', 'register_testimonial_widget' ); ?> |
A custom companion plugin for Before & After to extend its functionality to custom post types. (WordPress)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
<?php /* Plugin Name: Before & After Custom Post Types Extension Description: This plugin extends Before & After to add page protection for custom post types. Author: Pixo (Aaron and Alex) Version: 1.0 */ class BeforeAndAfterCustomPostTypeExtension { private $post_types; function __construct() { $this->post_types = array('project'); add_action('before_and_after_bootstrap', array($this, 'hook_into_before_and_after')); } function hook_into_before_and_after(){ if (class_exists( 'BA_Goal_Model' ) ) { add_action('admin_menu', array($this, 'add_meta_box_to_custom_post_types')); add_action('save_post', array($this, 'save_page_protection_settings_for_custom_post_types'), 1, 2); } } function add_meta_box_to_custom_post_types() { $before_and_after = new BeforeAndAfterPlugin(); $this->clean_up_extra_actions_and_filters($before_and_after); add_meta_box( 'before_and_after_protection', 'Before & After', array($before_and_after->Goal, 'display_protection_meta_box'), $this->post_types, 'normal', 'default' ); } // This entire function is copied from the before and after plugin, from the file include/ba.goal_model.class.php // If that function is updated, this should be updated as well. function save_page_protection_settings_for_custom_post_types() { global $post; // return if b_a_protection fields are not present if ( empty($_POST['b_a_protection']) ) { return; } // make sure that the nonce matches and the user has permission to edit this page/post if ( empty($post) || !in_array($post->post_type, $this->post_types ) || !current_user_can( 'edit_post', $post->ID ) ) { return; } $settings = $_POST['b_a_protection']; $enabled = !empty($settings) && !empty($settings['enabled']) ? 1 : 0; $goal_id = !empty($settings['goal_id']) ? $settings['goal_id'] : 0; $bounce_url = !empty($settings['bounce_url']) ? $settings['bounce_url'] : ''; $new_value = compact('enabled', 'goal_id', 'bounce_url'); update_post_meta( $post->ID, '_b_a_required_goal', $new_value ); if ($enabled) { update_post_meta( $post->ID, '_b_a_protected', '1' ); } else { delete_post_meta($post->ID, '_b_a_protected'); } } function clean_up_extra_actions_and_filters($before_and_after) { $before_and_after_goal = $before_and_after->Goal; // Plugin actions remove_action( 'admin_head', array($before_and_after, 'admin_css') ); remove_action( 'init', array($before_and_after, 'catch_download_links') ); remove_action( 'admin_enqueue_scripts', array($before_and_after, 'admin_scripts'), 10, 1 ); remove_action( 'widgets_init', array($before_and_after, 'register_all_widgets') ); remove_action( 'activate_before-and-after-pro/before-and-after-pro.php', array($before_and_after, 'pro_activation_hook') ); remove_action( 'admin_init', array($before_and_after, 'add_extra_classes_to_admin_menu') ); // Plugin filters remove_filter( "plugin_action_links_before-and-after/before-and-after.php", array($before_and_after, 'add_settings_link_to_plugin_action_links') ); remove_filter( 'plugin_row_meta', array($before_and_after, 'add_custom_links_to_plugin_description'), 10, 2 ); remove_filter( 'gp_aloha_welcome_page_content_before-and-after-settings', array($before_and_after, 'get_welcome_template') ); // Goal Actions remove_action( 'admin_init', array( $before_and_after_goal, 'admin_init' ) ); remove_action( 'wp_ajax_before_and_after_complete_goal', array( $before_and_after_goal, 'ajax_complete_goal_by_id' ) ); remove_action( 'wp_ajax_nopriv_before_and_after_complete_goal', array( $before_and_after_goal, 'ajax_complete_goal_by_id' ) ); remove_action( 'wp_enqueue_scripts', array($before_and_after_goal, 'register_cookie_script') ); remove_action( 'added_user_meta', array($before_and_after_goal, 'unhide_goals_in_menu_editor'), 10, 4 ); remove_action( 'manage_b_a_goal_posts_custom_column', array($before_and_after_goal, 'output_custom_columns_content'), 10, 2 ); remove_action( 'template_redirect', array($before_and_after_goal, 'catch_goal_protected_pages') ); remove_action('manage_goal_posts_custom_column', array( $before_and_after_goal, 'manage_goal_columns' ), 10, 2); remove_action('init', array($before_and_after_goal, 'remove_unneeded_metaboxes')); remove_action( 'admin_menu', array( $before_and_after_goal, 'add_meta_boxes' ) ); remove_action( 'save_post', array( $before_and_after_goal, 'save_goal_settings' ), 1, 2 ); remove_action( 'save_post', array( $before_and_after_goal, 'save_page_protection_settings' ), 1, 2 ); // Goal Filters remove_filter( 'the_content', array($before_and_after_goal, 'single_goal_content_filter') ); remove_filter( 'manage_b_a_goal_posts_columns', array($before_and_after_goal, 'output_custom_columns_head'), 10 ); remove_filter('manage_edit-goal_columns', array( $before_and_after_goal, 'add_new_columns' )); remove_filter('manage_edit-goals_columns', array( $before_and_after_goal, 'add_new_columns' )); remove_filter('page_row_actions', array( $before_and_after_goal, 'add_page_row_actions' ), 10, 2); remove_filter('post_row_actions', array( $before_and_after_goal, 'add_page_row_actions' ), 10, 2); } } $beforeAndAfterCustomPostTypeExtension = new BeforeAndAfterCustomPostTypeExtension(); |
Custom theme functions for a university’s department multi-site to handle menu ancestry and Advanced Custom Fields taxonomy filtering (WordPress)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
function get_acf_taxonomy_filtering($tax_type, $tax_field, $post_filters) { $taxonomy_filters = $post_filters; $tax_object = array( 'taxonomy' => $tax_type, 'field' => $tax_field, ); $tax_array_args = array ( 'relation' => 'OR' ); foreach($taxonomy_filters as $tax) { $tax_array_args[] = wp_parse_args(array('terms' => $tax), $tax_object); } return $tax_array_args; } function check_for_main_menu_ancestry($post_id) { $menu_items = wp_get_nav_menu_items('main-menu'); $post_ancestors = array_slice(get_post_ancestors( $post_id ), 0, 2); if( $menu_items ) { foreach( $menu_items as $item ) { if( $post_id == $item->object_id ) { return true; } else { if( $post_ancestors ) { foreach($post_ancestors as $ancestor) { if( $ancestor == $item->object_id ) { return true; } } } } } } return false; } |
Registering a Advanced Custom Fields (ACF) textarea for introductory text via PHP in a custom plugin (WordPress multisite)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
<?php namespace WordPress\UIC\Publish\src\ACF\Fields; use WordPress\Pixo\ACF\Fields\CustomField; class IntroText extends CustomField { public function __construct() { $this->properties = [ array ( 'key' => 'field_571fb74bbe89b', 'label' => 'Subtitle', 'name' => 'intro_text_subtitle', 'type' => 'text', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', 'readonly' => 0, 'disabled' => 0, ), array ( 'key' => 'field_571fb7babe89c', 'label' => 'Body Text', 'name' => 'intro_text_body', 'type' => 'wysiwyg', 'instructions' => 'Start body text here. If you need to alternate text with headers, images, etc., add Text Block available in the Custom Content Components.', 'required' => 1, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'tabs' => 'all', 'toolbar' => 'inline', 'media_upload' => 0, ), array ( 'key' => 'field_574d05c0307c5', 'label' => 'Include Image?', 'name' => 'intro_text_include_image', 'type' => 'true_false', 'instructions' => 'Image should be horizontal. Recommended size is 820x448 pixels. Image appears below title and above subtitle and body text.', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'message' => '', 'default_value' => 0, ), array ( 'key' => 'field_571fb813be89d', 'label' => 'Image', 'name' => 'intro_text_image', 'type' => 'image', 'instructions' => '', 'required' => 1, 'conditional_logic' => array ( array ( array ( 'field' => 'field_574d05c0307c5', 'operator' => '==', 'value' => '1', ), ), ), 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'return_format' => 'array', 'preview_size' => 'medium', 'library' => 'all', 'min_width' => 820, 'min_height' => '', 'min_size' => '', 'max_width' => '', 'max_height' => 600, 'max_size' => '', 'mime_types' => '', ), array ( 'key' => 'field_574d05f4307c6', 'label' => 'Image Alt Text', 'name' => 'intro_text_image_alt_text', 'type' => 'text', 'instructions' => 'Used by screen readers. Write text that accurately represents content and function of the image in a few words. Do not write "image of ..." or "graphic of ..." ', 'required' => 1, 'conditional_logic' => array ( array ( array ( 'field' => 'field_574d05c0307c5', 'operator' => '==', 'value' => '1', ), ), ), 'wrapper' => array ( 'width' => 50, 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', 'readonly' => 0, 'disabled' => 0, ), array ( 'key' => 'field_571fb848be89e', 'label' => 'Image Caption', 'name' => 'intro_text_image_caption', 'type' => 'text', 'instructions' => '', 'required' => 0, 'conditional_logic' => array ( array ( array ( 'field' => 'field_574d05c0307c5', 'operator' => '==', 'value' => '1', ), ), ), 'wrapper' => array ( 'width' => 50, 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', 'readonly' => 0, 'disabled' => 0, ), array ( 'key' => 'field_571fb864be89f', 'label' => 'Image Attribution', 'name' => 'intro_text_image_attribution', 'type' => 'text', 'instructions' => 'Credit for person who shot the photo.', 'required' => 0, 'conditional_logic' => array ( array ( array ( 'field' => 'field_574d05c0307c5', 'operator' => '==', 'value' => '1', ), ), ), 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', 'readonly' => 0, 'disabled' => 0, ), ]; } } |
A script to validate and process data to track a project’s planned feature list (JavaScript, statically generated site)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
const WhenCompleteEnum = { Now: `now`, ComingThisYear: `this_year`, ComingNextYear: `next_year`, WithinTheNextThreeYears: `three_year` }; const StatusEnum = { Complete: `complete`, InProgress: `in_progress`, Upcoming: `upcoming` }; const DefaultStatus = StatusEnum.Upcoming; const WhenCompleteTemplate = { [WhenCompleteEnum.Now]: "Now", [WhenCompleteEnum.ComingThisYear]: "This year", [WhenCompleteEnum.ComingNextYear]: "Next year", [WhenCompleteEnum.WithinTheNextThreeYears]: "Within the next three years" }; const StatusTemplate = { [StatusEnum.Complete]: "Complete", [StatusEnum.InProgress]: "In Progress", [StatusEnum.Upcoming]: "Upcoming" }; function process(data) { validate(data); return data.features.map(datum => { return transformFeature(datum); }); } function validate(data) { validateFeaturesExist(data); data.features.forEach(validateFeature); } function transformFeature(featureDatum, parentId = null) { const { name, status = DefaultStatus, description, features = [], whenComplete } = featureDatum; const statusAfterCheck = checkIfStatusIsValid(status) ? status : DefaultStatus; const id = generateProbablyUniqueId(); return { id, parentId, name, status: statusAfterCheck, description, whenComplete, features: features.map(f => { return transformFeature(f, id); }), templateStatus: StatusTemplate[statusAfterCheck], templateWhenComplete: WhenCompleteTemplate[whenComplete] }; } function validateFeature(featureDatum) { validateFeatureProperty(featureDatum, `name`); validateFeatureProperty(featureDatum, `description`); validateFeatureProperty(featureDatum, `whenComplete`); validateWhenComplete(featureDatum); if (featureDatum.features) featureDatum.features.forEach(validateFeature); } function validateFeaturesExist(data) { if (!data.features) throw `Data does not contain features`; } function validateFeatureProperty(feature, property) { if (!feature[property]) throw `${property} missing on feature ${getFeatureMessageForError(feature)}`; } function validateWhenComplete(featureDatum) { const isValidWhenComplete = checkIfWhenCompleteIsValid(featureDatum.whenComplete); if (!isValidWhenComplete) throw `whenComplete is invalid on feature ${getFeatureMessageForError(featureDatum)}`; } function checkIfWhenCompleteIsValid(whenComplete) { return Object.keys(WhenCompleteEnum).map(key => WhenCompleteEnum[key]).indexOf(whenComplete) > -1; } function checkIfStatusIsValid(status) { return Object.keys(StatusEnum).map(key => StatusEnum[key]).indexOf(status) > -1; } function getFeatureMessageForError(feature) { const clonedFeature = Object.assign({}, feature); const subFeatureLength = feature.features.length; delete clonedFeature.features; return `${buildFeatureMessageWithoutFeatures(clonedFeature)},"features":Array(${subFeatureLength})}`; function buildFeatureMessageWithoutFeatures(feature) { const featureMessage = JSON.stringify(feature); return featureMessage.substring(0, featureMessage.length - 1); } } function generateProbablyUniqueId() { return `id-${(0 | Math.random() * 9e6).toString(36)}`; } module.exports = {process, getFeatureMessageForError}; |
Use the Views API to access a custom table’s columns in the Drupal backend.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
<?php /** * Implements hook_views_data(). */ function fng_ir_views_data() { $data = array(); $data['fng_ir']['table']['group'] = t('Incident Report'); $data['fng_ir']['table']['join'] = array( 'node' => array( 'left_field' => 'nid', 'field' => 'nid', ), ); $data['fng_ir']['nid'] = array( 'title' => t('Nid'), 'help' => t('The node ID of the node.'), // The help that appears on the UI, // Information for displaying the nid 'field' => array( 'handler' => 'views_handler_field_node', 'click sortable' => TRUE, ), // Information for accepting a nid as an argument 'argument' => array( 'handler' => 'views_handler_argument_node_nid', 'name field' => 'title', // the field to display in the summary. 'numeric' => TRUE, 'validate type' => 'nid', ), // Information for accepting a nid as a filter 'filter' => array( 'handler' => 'views_handler_filter_numeric', ), // Information for sorting on a nid. 'sort' => array( 'handler' => 'views_handler_sort', ), 'relationship' => array( 'base' => 'node', 'base field' => 'nid', 'handler' => 'views_handler_relationship', 'label' => t('Node ID'), ), ); $data['fng_ir']['id'] = array( 'title' => t('Id'), 'help' => t('The ID of the incident report.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field_numeric', 'click sortable' => TRUE, ), 'filter' => array( 'handler' => 'views_handler_filter_numeric', ), 'sort' => array( 'handler' => 'views_handler_sort', ), ); $data['fng_ir']['vid'] = array( 'title' => t('Vid'), 'help' => t('The node version ID of the incident report.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field_numeric', 'click sortable' => TRUE, ), 'filter' => array( 'handler' => 'views_handler_filter_numeric', ), 'sort' => array( 'handler' => 'views_handler_sort', ), ); $data['fng_ir']['time_of_incident'] = array( 'title' => t('Time of incident'), 'help' => t('Time that the incident occurred.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_field_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['incident_type'] = array( 'title' => t('Type of incident'), 'help' => t('Type of incident that occurred.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['incident_type_other'] = array( 'title' => t('Other type of incident'), 'help' => t('Other unlisted type of incident that occurred.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['site_id'] = array( 'title' => t('Site of incident'), 'help' => t('Time that the incident occurred.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['location'] = array( 'title' => t('Location of incident'), 'help' => t('Time that the incident occurred.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['accident'] = array( 'title' => t('Accident'), 'help' => t('Was there an accident?'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field_boolean', 'click sortable' => TRUE, ), 'filter' => array( 'handler' => 'views_handler_field_boolean_operator', 'label' => t('Accident'), 'type' => 'yes-no', 'use equal' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), ); $data['fng_ir']['officers_reporting'] = array( 'title' => t('Officers Reporting'), 'help' => t('Officers reporting the incident.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['supervisor'] = array( 'title' => t('Supervisor'), 'help' => t('Supervisor of the reporting officers.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['manager'] = array( 'title' => t('Manager'), 'help' => t('Manager of the site of the incident.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['officers_responding'] = array( 'title' => t('Officers Responding'), 'help' => t('Officers responding to the incident.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['report'] = array( 'title' => t('Report'), 'help' => t('Report of the incident.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['report_format'] = array( 'title' => t('Report Format'), 'help' => t('Format of the report.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['called'] = array( 'title' => t('Called'), 'help' => t('EMS/Fire/Police called.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field_boolean', 'click sortable' => TRUE, ), 'filter' => array( 'handler' => 'views_handler_field_boolean_operator', 'label' => t('Accident'), 'type' => 'yes-no', 'use equal' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), ); $data['fng_ir']['responders'] = array( 'title' => t('Responders'), 'help' => t('Responders to the incident.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['arrest'] = array( 'title' => t('Arrest'), 'help' => t('Was an arrest made?'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field_boolean', 'click sortable' => TRUE, ), 'filter' => array( 'handler' => 'views_handler_field_boolean_operator', 'label' => t('Accident'), 'type' => 'yes-no', 'use equal' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), ); $data['fng_ir']['estimated_value_description'] = array( 'title' => t('Description of Damages'), 'help' => t('The description of any damages.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', ), 'filter' => array( 'handler' => 'views_handler_filter_string', ), 'argument' => array( 'handler' => 'views_handler_argument_string', ), ); $data['fng_ir']['estimated_value'] = array( 'title' => t('Estimated Value of Damages'), 'help' => t('The estimated value of any damages.'), // The help that appears on the UI, 'field' => array( 'handler' => 'views_handler_field_numeric', 'click sortable' => TRUE, ), 'filter' => array( 'handler' => 'views_handler_filter_numeric', ), 'sort' => array( 'handler' => 'views_handler_sort', ), ); return $data; } function fng_ir_views_pre_render(&$view) { $sites = _fng_ir_get_sites(); $types = _fng_ir_get_incident_types(); foreach($view->result as $r => $result) { $result->fng_ir_incident_type = $types[$result->fng_ir_incident_type]; $result->fng_ir_site_id = $sites[$result->fng_ir_site_id]; $date_time_from_db = strtotime($result->fng_ir_time_of_incident); $date_time_reformatted = date('m/j H:i', $date_time_from_db); $result->fng_ir_time_of_incident = $date_time_reformatted; } } |
Function to create an expiration timestamp for a custom content type node (Drupal)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function _pharmacy_announcement_make_expiration_datetime($node) { $se_date = isset($node->four_winds['signage_expiration_date']) ? $node->four_winds['signage_expiration_date'] : null; $se_time = isset($node->four_winds['signage_expiration_time']) ? $node->four_winds['signage_expiration_time'] : null; if(empty($se_date) || empty($se_time)) { return null; } $se_date_array = preg_split("/-/", $se_date); $se_time_array = preg_split("/:/", $se_time); $se_timestamp = mktime($se_time_array[0], $se_time_array[1], 0, $se_date_array[1], $se_date_array[2], $se_date_array[0]); $se_datetime = date('Y-m-d H:i:s', $se_timestamp); return $se_datetime; } |
Pair-programmed JavaScript to add a cookie and remove a banner once a user accepts GDPR policy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
var COOKIE_KEY = "COOKIE_POLICY_ACCEPTED"; document.addEventListener('DOMContentLoaded', function() { if (doesCookieExist()) removeCookiePolicyElement(); function doesCookieExist() { return getCookieObject().hasOwnProperty(COOKIE_KEY); } function getCookieObject() { return document.cookie .split(';') .map(function(cookieString) { return cookieString.split('='); }) .reduce(function(cookieObject, nextSeparatedCookieString) { var property = nextSeparatedCookieString[0].trim(); var value = nextSeparatedCookieString[1].trim(); cookieObject[property] = value; return cookieObject; }, {}); } }); function acceptCookie() { document.cookie = COOKIE_KEY + '=true;max-age=' + 60*60*24*365; var cookiePolicies = getCookiePolicies(); for (var i=0; i<cookiePolicies.length; ++i) { cookiePolicies[i].classList.add('cookie-policy-leave'); cookiePolicies[i].addEventListener('transitionend', function() { removeCookiePolicyElement(); }); } } function removeCookiePolicyElement() { var cookiePolicies = getCookiePolicies(); for (var i=0; i<cookiePolicies.length; ++i) { cookiePolicies[i].remove(); } } function getCookiePolicies() { return document.querySelectorAll('.js-cookie-policy'); } |