sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected static function _update_settings( $values ) { update_option( 'menu-icons', wp_parse_args( kucrut_validate( $values ), self::$settings ) ); set_transient( self::TRANSIENT_KEY, 'updated', 30 ); $redirect_url = remove_query_arg( array( 'menu-icons-reset' ), wp_get_referer() ); return $redirect_url; }
Update settings @since 0.7.0 @access protected @param array $values Settings values. @return string Redirect URL.
entailment
protected static function _reset_settings() { delete_option( 'menu-icons' ); set_transient( self::TRANSIENT_KEY, 'reset', 30 ); $redirect_url = remove_query_arg( array( self::RESET_KEY, 'menu-icons-updated' ), wp_get_referer() ); return $redirect_url; }
Reset settings @since 0.7.0 @access protected @return string Redirect URL.
entailment
public static function _ajax_menu_icons_update_settings() { check_ajax_referer( self::UPDATE_KEY, self::UPDATE_KEY ); if ( empty( $_POST['menu-icons']['settings'] ) ) { wp_send_json_error(); } $redirect_url = self::_update_settings( $_POST['menu-icons']['settings'] ); // Input var okay. wp_send_json_success( array( 'redirectUrl' => $redirect_url ) ); }
Update settings via ajax @since 0.7.0 @wp_hook action wp_ajax_menu_icons_update_settings
entailment
public static function _admin_notices() { $messages = array( 'updated' => __( '<strong>Menu Icons Settings</strong> have been successfully updated.', 'menu-icons' ), 'reset' => __( '<strong>Menu Icons Settings</strong> have been successfully reset.', 'menu-icons' ), ); $message_type = get_transient( self::TRANSIENT_KEY ); if ( ! empty( $message_type ) && ! empty( $messages[ $message_type ] ) ) { printf( '<div class="updated notice is-dismissible"><p>%s</p></div>', wp_kses( $messages[ $message_type ], array( 'strong' => true ) ) ); } delete_transient( self::TRANSIENT_KEY ); }
Print admin notices @since 0.3.0 @wp_hook action admin_notices
entailment
public static function _meta_box() { ?> <div class="taxonomydiv"> <ul id="menu-icons-settings-tabs" class="taxonomy-tabs add-menu-item-tabs hide-if-no-js"> <?php foreach ( self::get_fields() as $section ) : ?> <?php printf( '<li><a href="#" title="%s" class="mi-settings-nav-tab" data-type="menu-icons-settings-%s">%s</a></li>', esc_attr( $section['description'] ), esc_attr( $section['id'] ), esc_html( $section['title'] ) ); ?> <?php endforeach; ?> <?php printf( '<li><a href="#" class="mi-settings-nav-tab" data-type="menu-icons-settings-extensions">%s</a></li>', esc_html__( 'Extensions', 'menu-icons' ) ); ?> </ul> <?php foreach ( self::_get_fields() as $section_index => $section ) : ?> <div id="menu-icons-settings-<?php echo esc_attr( $section['id'] ) ?>" class="tabs-panel _<?php echo esc_attr( $section_index ) ?>"> <h4 class="hide-if-js"><?php echo esc_html( $section['title'] ) ?></h4> <?php foreach ( $section['fields'] as $field ) : ?> <div class="_field"> <?php printf( '<label for="%s" class="_main">%s</label>', esc_attr( $field->id ), esc_html( $field->label ) ); ?> <?php $field->render() ?> </div> <?php endforeach; ?> </div> <?php endforeach; ?> <div id="menu-icons-settings-extensions" class="tabs-panel _extensions"> <h4 class="hide-if-js"><?php echo esc_html__( 'Extensions', 'menu-icons' ) ?></h4> <ul> <li><a target="_blank" href="http://wordpress.org/plugins/menu-icons-icomoon/">IcoMoon</a></li> </ul> </div> </div> <p class="submitbox button-controls"> <?php wp_nonce_field( self::UPDATE_KEY, self::UPDATE_KEY ) ?> <span class="list-controls"> <?php printf( '<a href="%s" title="%s" class="select-all submitdelete">%s</a>', esc_url( wp_nonce_url( admin_url( '/nav-menus.php' ), self::RESET_KEY, self::RESET_KEY ) ), esc_attr__( 'Discard all changes and reset to default state', 'menu-icons' ), esc_html__( 'Reset', 'menu-icons' ) ); ?> </span> <span class="add-to-menu"> <span class="spinner"></span> <?php submit_button( __( 'Save Settings', 'menu-icons' ), 'secondary', 'menu-icons-settings-save', false ); ?> </span> </p> <?php }
Settings meta box @since 0.3.0
entailment
public static function get_fields() { $menu_id = self::get_current_menu_id(); $icon_types = wp_list_pluck( Menu_Icons::get( 'types' ), 'name' ); asort( $icon_types ); $sections = array( 'global' => array( 'id' => 'global', 'title' => __( 'Global', 'menu-icons' ), 'description' => __( 'Global settings', 'menu-icons' ), 'fields' => array( array( 'id' => 'icon_types', 'type' => 'checkbox', 'label' => __( 'Icon Types', 'menu-icons' ), 'choices' => $icon_types, 'value' => self::get( 'global', 'icon_types' ), ), ), 'args' => array(), ), ); if ( ! empty( $menu_id ) ) { $menu_term = get_term( $menu_id, 'nav_menu' ); $menu_key = sprintf( 'menu_%d', $menu_id ); $menu_settings = self::get_menu_settings( $menu_id ); $sections['menu'] = array( 'id' => $menu_key, 'title' => __( 'Current Menu', 'menu-icons' ), 'description' => sprintf( __( '"%s" menu settings', 'menu-icons' ), apply_filters( 'single_term_title', $menu_term->name ) ), 'fields' => self::get_settings_fields( $menu_settings ), 'args' => array( 'inline_description' => true ), ); } return apply_filters( 'menu_icons_settings_sections', $sections, $menu_id ); }
Get settings sections @since 0.3.0 @uses apply_filters() Calls 'menu_icons_settings_sections'. @return array
entailment
public static function get_settings_fields( array $values = array() ) { $fields = array( 'hide_label' => array( 'id' => 'hide_label', 'type' => 'select', 'label' => __( 'Hide Label', 'menu-icons' ), 'default' => '', 'choices' => array( array( 'value' => '', 'label' => __( 'No', 'menu-icons' ), ), array( 'value' => '1', 'label' => __( 'Yes', 'menu-icons' ), ), ), ), 'position' => array( 'id' => 'position', 'type' => 'select', 'label' => __( 'Position', 'menu-icons' ), 'default' => 'before', 'choices' => array( array( 'value' => 'before', 'label' => __( 'Before', 'menu-icons' ), ), array( 'value' => 'after', 'label' => __( 'After', 'menu-icons' ), ), ), ), 'vertical_align' => array( 'id' => 'vertical_align', 'type' => 'select', 'label' => __( 'Vertical Align', 'menu-icons' ), 'default' => 'middle', 'choices' => array( array( 'value' => 'super', 'label' => __( 'Super', 'menu-icons' ), ), array( 'value' => 'top', 'label' => __( 'Top', 'menu-icons' ), ), array( 'value' => 'text-top', 'label' => __( 'Text Top', 'menu-icons' ), ), array( 'value' => 'middle', 'label' => __( 'Middle', 'menu-icons' ), ), array( 'value' => 'baseline', 'label' => __( 'Baseline', 'menu-icons' ), ), array( 'value' => 'text-bottom', 'label' => __( 'Text Bottom', 'menu-icons' ), ), array( 'value' => 'bottom', 'label' => __( 'Bottom', 'menu-icons' ), ), array( 'value' => 'sub', 'label' => __( 'Sub', 'menu-icons' ), ), ), ), 'font_size' => array( 'id' => 'font_size', 'type' => 'number', 'label' => __( 'Font Size', 'menu-icons' ), 'default' => '1.2', 'description' => 'em', 'attributes' => array( 'min' => '0.1', 'step' => '0.1', ), ), 'svg_width' => array( 'id' => 'svg_width', 'type' => 'number', 'label' => __( 'SVG Width', 'menu-icons' ), 'default' => '1', 'description' => 'em', 'attributes' => array( 'min' => '.5', 'step' => '.1', ), ), 'image_size' => array( 'id' => 'image_size', 'type' => 'select', 'label' => __( 'Image Size', 'menu-icons' ), 'default' => 'thumbnail', 'choices' => kucrut_get_image_sizes(), ), ); $fields = apply_filters( 'menu_icons_settings_fields', $fields ); foreach ( $fields as &$field ) { if ( isset( $values[ $field['id'] ] ) ) { $field['value'] = $values[ $field['id'] ]; } if ( ! isset( $field['value'] ) && isset( $field['default'] ) ) { $field['value'] = $field['default']; } } unset( $field ); return $fields; }
Get settings fields @since 0.4.0 @param array $values Values to be applied to each field. @uses apply_filters() Calls 'menu_icons_settings_fields'. @return array
entailment
private static function _get_fields() { if ( ! class_exists( 'Kucrut_Form_Field' ) ) { require_once Menu_Icons::get( 'dir' ) . 'includes/library/form-fields.php'; } $keys = array( 'menu-icons', 'settings' ); $sections = self::get_fields(); foreach ( $sections as &$section ) { $_keys = array_merge( $keys, array( $section['id'] ) ); $_args = array_merge( array( 'keys' => $_keys ), $section['args'] ); foreach ( $section['fields'] as &$field ) { $field = Kucrut_Form_Field::create( $field, $_args ); } unset( $field ); } unset( $section ); return $sections; }
Get processed settings fields @since 0.3.0 @access private @return array
entailment
public static function _enqueue_assets() { $url = Menu_Icons::get( 'url' ); $suffix = kucrut_get_script_suffix(); if ( defined( 'MENU_ICONS_SCRIPT_DEBUG' ) && MENU_ICONS_SCRIPT_DEBUG ) { $script_url = '//localhost:8081/'; } else { $script_url = $url; } wp_enqueue_style( 'menu-icons', "{$url}css/admin{$suffix}.css", false, Menu_Icons::VERSION ); wp_enqueue_script( 'menu-icons', "{$script_url}js/admin{$suffix}.js", self::$script_deps, Menu_Icons::VERSION, true ); $customizer_url = add_query_arg( array( 'autofocus[section]' => 'custom_css', 'return' => admin_url( 'nav-menus.php' ), ), admin_url( 'customize.php' ) ); /** * Allow plugins/themes to filter the settings' JS data * * @since 0.9.0 * * @param array $js_data JS Data. */ $menu_current_theme = ''; $theme = wp_get_theme(); if ( ! empty( $theme ) ) { if ( is_child_theme() ) { $menu_current_theme = $theme->parent()->get( 'Name' ); } else { $menu_current_theme = $theme->get( 'Name' ); } } $box_data = '<div id="menu-icons-sidebar">'; if ( ( $menu_current_theme != 'Hestia' ) && ( $menu_current_theme != 'Hestia Pro' ) ) { $menu_upgrade_hestia_box_text = 'Check-out our latest FREE multi-purpose theme: <strong>Hestia</strong>'; if ( $menu_current_theme == 'Zerif Lite' ) { $menu_upgrade_hestia_box_text = 'Check-out our latest FREE multi-purpose theme: <strong>Hestia</strong>, your Zerif Lite content will be imported automatically! '; } $menu_upgrade_hestia_url = add_query_arg( array( 'theme' => 'hestia', ), admin_url( 'theme-install.php' ) ); $box_data .= '<div class="menu-icons-upgrade-hestia postbox new-card">'; $box_data .= '<p>' . wp_kses_post( $menu_upgrade_hestia_box_text ) . '</p>'; $box_data .= '<a class="button" href="' . $menu_upgrade_hestia_url . '" target="_blank">Preview Hestia</a>'; $box_data .= '</div>'; } if ( ! empty( $_POST['menu_icons_mail'] ) ) { require( plugin_dir_path( __DIR__ ) . 'mailin.php' ); $user_info = get_userdata( 1 ); $mailin = new Mailin( 'https://api.sendinblue.com/v2.0', 'cHW5sxZnzE7mhaYb' ); $data = array( 'email' => $_POST['menu_icons_mail'], 'attributes' => array( 'NAME' => $user_info->first_name, 'SURNAME' => $user_info->last_name, ), 'blacklisted' => 0, 'listid' => array( 145 ), 'blacklisted_sms' => 0, ); $status = $mailin->create_update_user( $data ); if ( $status['code'] == 'success' ) { update_option( 'menu_icons_subscribe', true ); } } $email_output = '<div class="menu-icons-subscribe postbox new-card">'; $email_output .= '<h3 class="title">' . esc_html__( 'Get Our Free Email Course', 'menu-icons' ) . '</h3>'; $email_output .= '<div id="formdata"><p>' . esc_html__( 'Ready to learn how to reduce your website loading times by half? Come and join the 1st lesson here!', 'menu-icons' ) . ' </p><form class="menu-icons-submit-mail" method="post"><input name="menu_icons_mail" type="email" value="' . get_option( 'admin_email' ) . '" /><input id="ebutton" class="button" type="submit" value="Submit"></form></div>'; $email_output .= '<p id="success">' . esc_html__( 'Thank you for subscribing! You have been added to the mailing list and will receive the next email information in the coming weeks. If you ever wish to unsubscribe, simply use the "Unsubscribe" link included in each newsletter.', 'menu-icons' ) . '</p>'; $email_output .= '<p id="failiure">' . esc_html__( 'Unable to Subscribe.', 'menu-icons' ) . '</p>'; $email_output .= '</div>'; $email_output .= '</div>'; $email_output .= '<script>'; $email_output .= '$( \'#failiure\' ).hide();'; $email_output .= '$( \'#success\' ).hide();'; $email_output .= '$( \'form.menu-icons-submit-mail\' ).submit(function(event) {'; $email_output .= 'event.preventDefault();'; $email_output .= '$.ajax({'; $email_output .= 'type: \'POST\','; $email_output .= 'data: $( \'form.menu-icons-submit-mail\' ).serialize(),'; $email_output .= 'success: function(result) {'; $email_output .= '$( \'#formdata\' ).hide();'; $email_output .= '$( \'#success\' ).show();'; $email_output .= '},'; $email_output .= 'error: function(result) { $( \'#failiure\' ).show(); }'; $email_output .= '}); });'; $email_output .= '</script>'; $shown = (bool) get_option( 'menu_icons_subscribe', false ); if ( $shown === true ) { $email_output = ''; } $box_data .= $email_output; $js_data = apply_filters( 'menu_icons_settings_js_data', array( 'text' => array( 'title' => __( 'Select Icon', 'menu-icons' ), 'select' => __( 'Select', 'menu-icons' ), 'remove' => __( 'Remove', 'menu-icons' ), 'change' => __( 'Change', 'menu-icons' ), 'all' => __( 'All', 'menu-icons' ), 'preview' => __( 'Preview', 'menu-icons' ), 'settingsInfo' => sprintf( '<div> %1$s <p>' . esc_html__( 'Please note that the actual look of the icons on the front-end will also be affected by the style of your active theme. You can add your own CSS using %2$s or a plugin such as %3$s if you need to override it.', 'menu-icons' ) . '</p></div>', $box_data, sprintf( '<a href="%s">%s</a>', esc_url( $customizer_url ), esc_html__( 'the customizer', 'menu-icons' ) ), '<a target="_blank" href="https://wordpress.org/plugins/advanced-css-editor/">Advanced CSS Editor</a>' ), ), 'settingsFields' => self::get_settings_fields(), 'activeTypes' => self::get( 'global', 'icon_types' ), 'ajaxUrls' => array( 'update' => add_query_arg( 'action', 'menu_icons_update_settings', admin_url( '/admin-ajax.php' ) ), ), 'menuSettings' => self::get_menu_settings( self::get_current_menu_id() ), ) ); wp_localize_script( 'menu-icons', 'menuIcons', $js_data ); }
Enqueue scripts & styles for Appearance > Menus page @since 0.3.0 @wp_hook action admin_enqueue_scripts
entailment
public static function get( $name = null ) { if ( is_null( $name ) ) { return self::$data; } if ( isset( self::$data[ $name ] ) ) { return self::$data[ $name ]; } return null; }
Get plugin data @since 0.1.0 @since 0.9.0 Return NULL if $name is not set in $data. @param string $name @return mixed
entailment
public static function _load() { load_plugin_textdomain( 'menu-icons', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); self::$data = array( 'dir' => plugin_dir_path( __FILE__ ), 'url' => plugin_dir_url( __FILE__ ), 'types' => array(), ); $vendor_file = dirname(__FILE__) . '/vendor/autoload.php'; if ( is_readable( $vendor_file ) ) { require_once $vendor_file; } // Load Icon Picker. if ( ! class_exists( 'Icon_Picker' ) ) { $ip_file = self::$data['dir'] . 'includes/library/icon-picker/icon-picker.php'; if ( file_exists( $ip_file ) ) { require_once $ip_file; } else { add_action( 'admin_notices', array( __CLASS__, '_notice_missing_icon_picker' ) ); return; } } Icon_Picker::instance(); require_once self::$data['dir'] . 'includes/library/compat.php'; require_once self::$data['dir'] . 'includes/library/functions.php'; require_once self::$data['dir'] . 'includes/meta.php'; Menu_Icons_Meta::init(); add_action( 'icon_picker_init', array( __CLASS__, '_init' ), 9 ); }
Load plugin 1. Load translation 2. Set plugin data (directory and URL paths) 3. Attach plugin initialization at icon_picker_init hook @since 0.1.0 @wp_hook action plugins_loaded @link http://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded
entailment
public static function _init() { /** * Allow themes/plugins to add/remove icon types * * @since 0.1.0 * @param array $types Icon types */ self::$data['types'] = apply_filters( 'menu_icons_types', Icon_Picker_Types_Registry::instance()->types ); // Nothing to do if there are no icon types registered. if ( empty( self::$data['types'] ) ) { if ( WP_DEBUG ) { trigger_error( esc_html__( 'Menu Icons: No registered icon types found.', 'menu-icons' ) ); } return; } // Load settings. require_once self::$data['dir'] . 'includes/settings.php'; Menu_Icons_Settings::init(); // Load front-end functionalities. if ( ! is_admin() ) { require_once self::$data['dir'] . '/includes/front.php'; Menu_Icons_Front_End::init(); } do_action( 'menu_icons_loaded' ); }
Initialize 1. Get registered types from Icon Picker 2. Load settings 3. Load front-end functionalities @since 0.1.0 @since 0.9.0 Hook into `icon_picker_init`. @wp_hook action icon_picker_init @link http://codex.wordpress.org/Plugin_API/Action_Reference
entailment
public static function get( $id, $defaults = array() ) { $defaults = wp_parse_args( $defaults, self::$defaults ); $value = get_post_meta( $id, self::KEY, true ); $value = wp_parse_args( (array) $value, $defaults ); // Backward-compatibility. if ( empty( $value['icon'] ) && ! empty( $value['type'] ) && ! empty( $value[ "{$value['type']}-icon" ] ) ) { $value['icon'] = $value[ "{$value['type']}-icon" ]; } if ( ! empty( $value['width'] ) ) { $value['svg_width'] = $value['width']; } unset( $value['width'] ); if ( isset( $value['position'] ) && ! in_array( $value['position'], array( 'before', 'after' ), true ) ) { $value['position'] = $defaults['position']; } if ( isset( $value['size'] ) && ! isset( $value['font_size'] ) ) { $value['font_size'] = $value['size']; unset( $value['size'] ); } // The values below will NOT be saved if ( ! empty( $value['icon'] ) && in_array( $value['type'], array( 'image', 'svg' ), true ) ) { $value['url'] = wp_get_attachment_image_url( $value['icon'], 'thumbnail', false ); } return $value; }
Get menu item meta value @since 0.3.0 @since 0.9.0 Add $defaults parameter. @param int $id Menu item ID. @param array $defaults Optional. Default value. @return array
entailment
public static function update( $id, $value ) { /** * Allow plugins/themes to filter the values * * Deprecated. * * @since 0.1.0 * @param array $value Metadata value. * @param int $id Menu item ID. */ $_value = apply_filters( 'menu_icons_values', $value, $id ); if ( $_value !== $value && WP_DEBUG ) { _deprecated_function( 'menu_icons_values', '0.8.0', 'menu_icons_item_meta_values' ); } /** * Allow plugins/themes to filter the values * * @since 0.8.0 * @param array $value Metadata value. * @param int $id Menu item ID. */ $value = apply_filters( 'menu_icons_item_meta_values', $_value, $id ); // Don't bother saving if `type` or `icon` is not set. if ( empty( $value['type'] ) || empty( $value['icon'] ) ) { $value = false; } // Update if ( ! empty( $value ) ) { update_post_meta( $id, self::KEY, $value ); } else { delete_post_meta( $id, self::KEY ); } }
Update menu item metadata @since 0.9.0 @param int $id Menu item ID. @param mixed $value Metadata value. @return void
entailment
public static function init() { $active_types = Menu_Icons_Settings::get( 'global', 'icon_types' ); if ( empty( $active_types ) ) { return; } foreach ( Menu_Icons::get( 'types' ) as $type ) { if ( in_array( $type->id, $active_types, true ) ) { self::$icon_types[ $type->id ] = $type; } } /** * Allow themes/plugins to override the hidden label class * * @since 0.8.0 * @param string $hidden_label_class Hidden label class. * @return string */ self::$hidden_label_class = apply_filters( 'menu_icons_hidden_label_class', self::$hidden_label_class ); /** * Allow themes/plugins to override default inline style * * @since 0.9.0 * @param array $default_style Default inline style. * @return array */ self::$default_style = apply_filters( 'menu_icons_default_style', self::$default_style ); add_action( 'wp_enqueue_scripts', array( __CLASS__, '_enqueue_styles' ), 7 ); add_filter( 'wp_nav_menu_args', array( __CLASS__, '_add_menu_item_title_filter' ) ); add_filter( 'wp_nav_menu', array( __CLASS__, '_remove_menu_item_title_filter' ) ); }
Add hooks for front-end functionalities @since 0.9.0
entailment
public static function get_nav_menu_id( $args ) { $args = (object) $args; $menu = wp_get_nav_menu_object( $args->menu ); // Get the nav menu based on the theme_location if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) { $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] ); } // get the first menu that has items if we still can't find a menu if ( ! $menu && ! $args->theme_location ) { $menus = wp_get_nav_menus(); foreach ( $menus as $menu_maybe ) { if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { $menu = $menu_maybe; break; } } } if ( is_object( $menu ) && ! is_wp_error( $menu ) ) { return $menu->term_id; } else { return false; } }
Get nav menu ID based on arguments passed to wp_nav_menu() @since 0.3.0 @param array $args wp_nav_menu() Arguments @return mixed Nav menu ID or FALSE on failure
entailment
public static function _enqueue_styles() { foreach ( self::$icon_types as $type ) { if ( wp_style_is( $type->stylesheet_id, 'registered' ) ) { wp_enqueue_style( $type->stylesheet_id ); } } /** * Allow plugins/themes to override the extra stylesheet location * * @since 0.9.0 * @param string $extra_stylesheet_uri Extra stylesheet URI. */ $extra_stylesheet_uri = apply_filters( 'menu_icons_extra_stylesheet_uri', sprintf( '%scss/extra%s.css', Menu_Icons::get( 'url' ), kucrut_get_script_suffix() ) ); wp_enqueue_style( 'menu-icons-extra', $extra_stylesheet_uri, false, Menu_Icons::VERSION ); }
Enqueue stylesheets @since 0.1.0 @wp_hook action wp_enqueue_scripts @link http://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts
entailment
public static function _add_icon( $title, $id ) { $meta = Menu_Icons_Meta::get( $id ); $icon = self::get_icon( $meta ); if ( empty( $icon ) ) { return $title; } $title_class = ! empty( $meta['hide_label'] ) ? self::$hidden_label_class : ''; $title_wrapped = sprintf( '<span%s>%s</span>', ( ! empty( $title_class ) ) ? sprintf( ' class="%s"', esc_attr( $title_class ) ) : '', $title ); if ( 'after' === $meta['position'] ) { $title_with_icon = "{$title_wrapped}{$icon}"; } else { $title_with_icon = "{$icon}{$title_wrapped}"; } /** * Allow plugins/themes to override menu item markup * * @since 0.8.0 * * @param string $title_with_icon Menu item markup after the icon is added. * @param integer $id Menu item ID. * @param array $meta Menu item metadata values. * @param string $title Original menu item title. * * @return string */ $title_with_icon = apply_filters( 'menu_icons_item_title', $title_with_icon, $id, $meta, $title ); return $title_with_icon; }
Add icon to menu item title @since 0.1.0 @since 0.9.0 Renamed the method to `add_icon()`. @wp_hook filter the_title @param string $title Menu item title. @param int $id Menu item ID. @return string
entailment
public static function get_icon( $meta ) { $icon = ''; // Icon type is not set. if ( empty( $meta['type'] ) ) { return $icon; } // Icon is not set. if ( empty( $meta['icon'] ) ) { return $icon; } // Icon type is not registered/enabled. if ( ! isset( self::$icon_types[ $meta['type'] ] ) ) { return $icon; } $type = self::$icon_types[ $meta['type'] ]; $callbacks = array( array( $type, 'get_icon' ), array( __CLASS__, "get_{$type->id}_icon" ), array( __CLASS__, "get_{$type->template_id}_icon" ), ); foreach ( $callbacks as $callback ) { if ( is_callable( $callback ) ) { $icon = call_user_func( $callback, $meta ); break; } } return $icon; }
Get icon @since 0.9.0 @param array $meta Menu item meta value. @return string
entailment
public static function get_icon_style( $meta, $keys, $as_attribute = true ) { $style_a = array(); $style_s = ''; foreach ( $keys as $key ) { if ( ! isset( self::$default_style[ $key ] ) ) { continue; } $rule = self::$default_style[ $key ]; if ( ! isset( $meta[ $key ] ) || $meta[ $key ] === $rule['value'] ) { continue; } $value = $meta[ $key ]; if ( ! empty( $rule['unit'] ) ) { $value .= $rule['unit']; } $style_a[ $rule['property'] ] = $value; } if ( empty( $style_a ) ) { return $style_s; } foreach ( $style_a as $key => $value ) { $style_s .= "{$key}:{$value};"; } $style_s = esc_attr( $style_s ); if ( $as_attribute ) { $style_s = sprintf( ' style="%s"', $style_s ); } return $style_s; }
Get icon style @since 0.9.0 @param array $meta Menu item meta value. @param array $keys Style properties. @param bool $as_attribute Optional. Whether to output the style as HTML attribute or value only. Defaults to TRUE. @return string
entailment
public static function get_icon_classes( $meta, $output = 'string' ) { $classes = array( '_mi' ); if ( empty( $meta['hide_label'] ) ) { $classes[] = "_{$meta['position']}"; } if ( 'string' === $output ) { $classes = implode( ' ', $classes ); } return $classes; }
Get icon classes @since 0.9.0 @param array $meta Menu item meta value. @param string $output Whether to output the classes as string or array. Defaults to string. @return string|array
entailment
public static function get_font_icon( $meta ) { $classes = sprintf( '%s %s %s', self::get_icon_classes( $meta ), $meta['type'], $meta['icon'] ); $style = self::get_icon_style( $meta, array( 'font_size', 'vertical_align' ) ); return sprintf( '<i class="%s" aria-hidden="true"%s></i>', esc_attr( $classes ), $style ); }
Get font icon @since 0.9.0 @param array $meta Menu item meta value. @return string
entailment
public static function get_image_icon( $meta ) { $args = array( 'class' => sprintf( '%s _image', self::get_icon_classes( $meta ) ), 'aria-hidden' => 'true', ); $style = self::get_icon_style( $meta, array( 'vertical_align' ), false ); if ( ! empty( $style ) ) { $args['style'] = $style; } return wp_get_attachment_image( $meta['icon'], $meta['image_size'], false, $args ); }
Get image icon @since 0.9.0 @param array $meta Menu item meta value. @return string
entailment
public static function get_svg_icon( $meta ) { $classes = sprintf( '%s _svg', self::get_icon_classes( $meta ) ); $style = self::get_icon_style( $meta, array( 'svg_width', 'vertical_align' ) ); return sprintf( '<img src="%s" class="%s" aria-hidden="true"%s />', esc_url( wp_get_attachment_url( $meta['icon'] ) ), esc_attr( $classes ), $style ); }
Get SVG icon @since 0.9.0 @param array $meta Menu item meta value. @return string
entailment
private function do_request( $resource, $method, $input ) { $called_url = $this->base_url . '/' . $resource; $ch = curl_init( $called_url ); $auth_header = 'api-key:' . $this->api_key; $content_header = 'Content-Type:application/json'; if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) { // Windows only over-ride curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); } curl_setopt( $ch, CURLOPT_HTTPHEADER, array($auth_header, $content_header) ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $input ); $data = curl_exec( $ch ); if ( curl_errno( $ch ) ) { echo 'Curl error: ' . curl_error( $ch ) . '\n'; } curl_close( $ch ); return json_decode( $data, true ); }
Do CURL request with authorization
entailment
public function update_campaign( $data ) { $id = $data['id']; unset( $data['id'] ); return $this->put( 'campaign/' . $id, json_encode( $data ) ); }
/* Update your campaign. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of campaign to be modified [Mandatory] @options data {String} category: Tag name of the campaign [Optional] @options data {String} from_name: Sender name from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists] @options data {String} name: Name of the campaign [Optional] @options data {String} bat: Email address for test mail [Optional] @options data {String} html_content: Body of the content. The HTML content field must have more than 10 characters [Optional] @options data {String} html_url: Url which content is the body of content [Optional] @options data {Array} listid These are the lists to which the campaign has been sent [Mandatory: if scheduled_date is not empty] @options data {String} scheduled_date: The day on which the campaign is supposed to run[Optional] @options data {String} subject: Subject of the campaign. @options data {String} from_email: Sender email from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists] @options data {String} reply_to: The reply to email in the campaign emails [Optional] @options data {String} to_field: This is to personalize the «To» Field. If you want to include the first name and last name of your recipient, add [PRENOM] [NOM]. To use the contact attributes here, these should already exist in SendinBlue account [Optional] @options data {Array} exclude_list: These are the lists which must be excluded from the campaign [Optional] @options data {String} attachment_url: Provide the absolute url of the attachment [Optional] @options data {Integer} inline_image: Status of inline image. Possible values = 0 (default) & 1. inline_image = 0 means image can’t be embedded, & inline_image = 1 means image can be embedded, in the email [Optional] @options data {Integer} mirror_active: Status of mirror links in campaign. Possible values = 0 & 1 (default). mirror_active = 0 means mirror links are deactivated, & mirror_active = 1 means mirror links are activated, in the campaign [Optional] @options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
entailment
public function campaign_report_email( $data ) { $id = $data['id']; unset( $data['id'] ); return $this->post( 'campaign/' . $id . '/report', json_encode( $data ) ); }
/* Send report of Sent and Archived campaign. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of campaign to send its report [Mandatory] @options data {String} lang: Language of email content. Possible values – fr (default), en, es, it & pt [Optional] @options data {String} email_subject: Message subject [Mandatory] @options data {Array} email_to: Email address of the recipient(s). Example: "[email protected]". You can use commas to separate multiple recipients [Mandatory] @options data {String} email_content_type: Body of the message in text/HTML version. Possible values – text & html [Mandatory] @options data {Array} email_bcc: Same as email_to but for Bcc [Optional] @options data {Array} email_cc: Same as email_to but for Cc [Optional] @options data {String} email_body: Body of the message [Mandatory]
entailment
public function update_trigger_campaign( $data ) { $id = $data['id']; unset( $data['id'] ); return $this->put( 'campaign/' . $id, json_encode( $data ) ); }
/* Update and schedule your Trigger campaigns. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of Trigger campaign to be modified [Mandatory] @options data {String} category: Tag name of the campaign [Optional] @options data {String} from_name: Sender name from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists] @options data {String} trigger_name: Name of the campaign [Mandatory] @options data {String} bat Email address for test mail [Optional] @options data {String} html_content: Body of the content. The HTML content field must have more than 10 characters [Mandatory: if html_url is empty] @options data {String} html_url: Url which content is the body of content [Mandatory: if html_content is empty] @options data {Array} listid: These are the lists to which the campaign has been sent [Mandatory: if scheduled_date is not empty] @options data {String} scheduled_date: The day on which the campaign is supposed to run[Optional] @options data {String} subject: Subject of the campaign [Mandatory] @options data {String} from_email: Sender email from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists] @options data {String} reply_to: The reply to email in the campaign emails [Optional] @options data {String} to_field: This is to personalize the «To» Field. If you want to include the first name and last name of your recipient, add [PRENOM] [NOM]. To use the contact attributes here, these should already exist in SendinBlue account [Optional] @options data {Array} exclude_list: These are the lists which must be excluded from the campaign [Optional] @options data {Integer} recurring: Type of trigger campaign. Possible values = 0 (default) & 1. recurring = 0 means contact can receive the same Trigger campaign only once, & recurring = 1 means contact can receive the same Trigger campaign several times [Optional] @options data {String} attachment_url: Provide the absolute url of the attachment [Optional] @options data {Integer} inline_image: Status of inline image. Possible values = 0 (default) & 1. inline_image = 0 means image can’t be embedded, & inline_image = 1 means image can be embedded, in the email [Optional] @options data {Integer} mirror_active: Status of mirror links in campaign. Possible values = 0 & 1 (default). mirror_active = 0 means mirror links are deactivated, & mirror_active = 1 means mirror links are activated, in the campaign [Optional] @options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
entailment
public function update_list( $data ) { $id = $data['id']; unset( $data['id'] ); return $this->put( 'list/' . $id, json_encode( $data ) ); }
/* Update a list. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of list to be modified [Mandatory] @options data {String} list_name: Desired name of the list to be modified [Optional] @options data {Integer} list_parent: Folder ID [Mandatory]
entailment
public function delete_attribute( $type, $data ) { $type = $data['type']; unset( $data['type'] ); return $this->post( 'attribute/' . $type, json_encode( $data ) ); }
/* Delete a specific type of attribute information. @param {Array} data contains php array with key value pair. @options data {Integer} type: Type of attribute to be deleted [Mandatory]
entailment
public function update_sender( $data ) { $id = $data['id']; unset( $data['id'] ); return $this->put( 'advanced/' . $id, json_encode( $data ) ); }
/* Update your Senders. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of sender to be modified [Mandatory] @options data {String} name: Name of the sender [Mandatory] @options data {Array} ip_domain: Pass pipe ( | ) separated Dedicated IP and its associated Domain. Example: "1.2.3.4|mydomain.com". You can use commas to separate multiple ip_domain’s [Mandatory: Only for Dedicated IP clients, for Shared IP clients, it should be kept blank]
entailment
public function update_template( $data ) { $id = $data['id']; unset( $data['id'] ); return $this->put( 'template/' . $id, json_encode( $data ) ); }
/* Update a Template. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of Template to be modified [Mandatory] @options data {String} from_name: Sender name from which the campaign emails are sent [Mandatory: for Dedicated IP clients & for Shared IP clients, if sender exists] @options data {String} template_name: Name of the Template [Mandatory] @options data {String} bat: Email address for test mail [Optional] @options data {String} html_content: Body of the content. The HTML content field must have more than 10 characters [Mandatory: if html_url is empty] @options data {String} html_url: Url which content is the body of content [Mandatory: if html_content is empty] @options data {String} subject: Subject of the campaign [Mandatory] @options data {String} from_email: Sender email from which the campaign emails are sent [Mandatory: for Dedicated IP clients & for Shared IP clients, if sender exists] @options data {String} reply_to: The reply to email in the campaign emails [Optional] @options data {String} to_field: This is to personalize the «To» Field. If you want to include the first name and last name of your recipient, add [PRENOM] [NOM]. To use the contact attributes here, these should already exist in SendinBlue account [Optional] @options data {Integer} status: Status of template. Possible values = 0 (default) & 1. status = 0 means template is inactive, & status = 1 means template is active [Optional] @options data {Integer} attachment: Status of attachment. Possible values = 0 (default) & 1. attach = 0 means an attachment can’t be sent, & attach = 1 means an attachment can be sent, in the email [Optional]
entailment
final public static function load( $url_path = null ) { // Set URL path for assets if ( ! is_null( $url_path ) ) { self::$url_path = $url_path; } else { self::$url_path = plugin_dir_url( __FILE__ ); } // Supported field types self::$types = apply_filters( 'form_field_types', self::$types ); }
Loader @param string URL path to this directory
entailment
final public static function create( array $field, $args = array() ) { $field = wp_parse_args( $field, self::$defaults['field'] ); if ( ! isset( self::$types[ $field['type'] ] ) || ! is_subclass_of( self::$types[ $field['type'] ], __CLASS__ ) ) { trigger_error( sprintf( esc_html__( '%1$s: Type %2$s is not supported, reverting to text.', 'menu-icons' ), __CLASS__, esc_html( $field['type'] ) ), E_USER_WARNING ); $field['type'] = 'text'; } if ( is_null( $field['value'] ) && ! is_null( $field['default'] ) ) { $field['value'] = $field['default']; } foreach ( self::$forbidden_attributes as $key ) { unset( $field['attributes'][ $key ] ); } $args = (object) wp_parse_args( $args, self::$defaults['args'] ); $class = self::$types[ $field['type'] ]; return new $class( $field, $args ); }
Create field @param array $field Field array @param array $args Extra field arguments
entailment
protected function create_name() { $format = '%s'; $format .= str_repeat( '[%s]', ( count( $this->args->keys ) - 1 ) ); return $this->create_id_name( $format ); }
Create name attribute @since 0.1.0 @access protected @return string
entailment
protected function build_attributes( $excludes = array() ) { $excludes = array_filter( (array) $excludes ); $attributes = ''; foreach ( $this->attributes as $key => $value ) { if ( in_array( $key, $excludes, true ) ) { continue; } if ( 'class' === $key ) { $value = implode( ' ', (array) $value ); } $attributes .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( $value ) ); } return $attributes; }
Build field attributes @since 0.1.0 @param array $excludes Attributes to be excluded @return string
entailment
public function description() { if ( ! empty( $this->field['description'] ) ) { $tag = ( ! empty( $this->args->inline_description ) ) ? 'span' : 'p'; printf( // WPCS: XSS ok. '<%1$s class="description">%2$s</%1$s>', $tag, wp_kses( $this->field['description'], $this->allowed_html ) ); } }
Print field description @since 0.1.0
entailment
public function getThumbnail($video_path,$storage_path,$thumnail_name,$tts=10) { try { if(config('thumbnail.binaries.enabled')) { $ffmpeg = FFMpeg::create( array( 'ffmpeg.binaries' => config('thumbnail.binaries.path.ffmpeg'), 'ffprobe.binaries' => config('thumbnail.binaries.path.ffprobe'), 'timeout' => config('thumbnail.binaries.path.timeout'), 'ffmpeg.threads' => config('thumbnail.binaries.path.threads'), ) ); } else { $ffmpeg = FFMpeg::create(); } $video = $ffmpeg->open($video_path); $result_image = $storage_path.'/'.$thumnail_name; $video ->filters() ->resize(new Coordinate\Dimension(config('thumbnail.dimensions.height'), config('thumbnail.dimensions.width'))) ->synchronize();//320, 240 $video ->frame(Coordinate\TimeCode::fromSeconds($tts)) ->save($result_image); if($video) { if(config('thumbnail.watermark.image.enabled')) { $src = imagecreatefrompng(config('thumbnail.watermark.image.path')); $got_image = imagecreatefromjpeg($result_image); // Get dimensions of image screen shot $width = imagesx($got_image); $height = imagesy($got_image); // final output image dimensions $newwidth = config('thumbnail.dimensions.width'); $newheight = config('thumbnail.dimensions.height'); $tmp = imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$got_image,0,0,0,0,$newwidth,$newheight,$width,$height); // Set the brush imagesetbrush($tmp, $src); // Draw a couple of brushes, each overlaying each imageline($tmp, imagesx($tmp) / 2, imagesy($tmp) / 2, imagesx($tmp) / 2, imagesy($tmp) / 2, IMG_COLOR_BRUSHED); imagejpeg($tmp,$result_image,100); } return true; } else { return false; } } catch(Exception $thumbnailException) { // error processing request throw new Exception($thumbnailException->getMessage()); } }
Create Thumbnail Image Create a new image from video source based on the specified parameters. This method will allows video to convert to image. This method will add watermark to image @access public @param video_path Video resource source path @param storage_path Image resource destination path @param thumbnail_name Image name for output @param tts Time to take screenshot [optional] @return boolean @since Method available since Release 1.0.0 @version 1.4.4 @author lakshmajim <[email protected]>
entailment
public function clipWebM($src, $dest, $from, $to) { $ffmpeg = FFMpeg::create(); $video = $ffmpeg->open($src); if($from >= $to) throw new Exception("The start clipping time must be less than end clipping time"); $video ->filters() ->clip(Coordinate\TimeCode::fromSeconds($from), Coordinate\TimeCode::fromSeconds($to)); $video ->save(new Video\WebM(), $dest); if($video) return true; else return false; }
Clips the given video Create a new clipped video of type WebM from the given video @access public @param src Video resource source path @param dest Video resource destination path @param from Clipping start time @param to Clipping end time @return boolean @since Method available since Release 1.4.4 @version 1.4.4 @author lakshmajim <[email protected]>
entailment
public function watermarkVideo($src, $dest) { $ffmpeg = FFMpeg::create(); $video = $ffmpeg->open($src); if(!config('thumbnail.watermark.video.enabled')) throw new Exception("Configure watermark path in env file"); // $video->filters()->resize($dimension, $mode, $useStandards); $video ->filters() ->watermark(config('thumbnail.watermark.video.path'), array( 'position' => 'relative', 'bottom' => 50, 'right' => 50, )); $video ->save(new Video\WebM(), $dest); if($video) return true; else return false; }
Insert watermark on the given video @access public @param src Video resource source path @param dest Video resource destination path @return boolean @since Method available since Release 1.4.4 @version 1.4.4 @author lakshmajim <[email protected]>
entailment
public function register() { if (method_exists(\Illuminate\Foundation\Application::class, 'singleton')) { $this->app->singleton('thumbnail', function($app) { return new Thumbnail; }); } else { $this->app['thumbnail'] = $this->app->share(function($app) { return new Thumbnail; }); } }
Register the application services. @return void @author lakshmaji <[email protected]> @package Thumbnail @version 1.4.4 @since Method available since Release 1.0.0
entailment
public function getToken($request = null) { $request = $request ?: $this->makeRequest(); list($token) = sscanf($request->header($this->getAuthHeaderKey()), 'Bearer %s'); if( ! $token) { $name = $this->getInputName(); $token = $request->input($name); } return $token; }
Get the JWT token from the request We'll check the Authorization header first, and if that's not set then check the input to see if its provided there instead. @param Request|null $request @return string|null
entailment
public function jwtToken($request = null) { $token = $this->getToken($request); if( ! $token) throw new NoTokenException('JWT token is required.'); $driver = $this->makeDriver(); $jwt = new JwtToken($driver); $jwt->setToken($token); return $jwt; }
Create a new JWT token object from the token in the request @param Request|null $request @return JwtToken @throws NoTokenException
entailment
public function jwtPayload($path = null, $request = null) { $jwt = $this->jwtToken($request); return $jwt->payload($path); }
Get payload from JWT token @param string|null $path to query payload @param Request|null $request @return array
entailment
public function validateToken($token, $secret, $algorithm = 'HS256') { try { JWT::decode($token, $secret, [$algorithm]); } catch(\Exception $e) { return false; } return true; }
Validate that the provided token @param string $token @param string $secret @param string $algorithm @return bool
entailment
public function decodeToken($token, $secret, $algorithm = 'HS256') { $decoded = JWT::decode($token, $secret, [$algorithm]); return $this->convertObjectToArray($decoded); }
Decode the provided token into an array @param string $token @param string $secret @param string $algorithm @return array
entailment
private function convertObjectToArray($data) { $converted = []; foreach($data as $key => $value) { if(is_object($value)) { $converted[$key] = $this->convertObjectToArray($value); } else { $converted[$key] = $value; } } return $converted; }
Recursively convert the provided object to an array @param mixed $data @return array
entailment
public function handle($request, Closure $next) { $token = $this->getTokenFromRequest($request); $this->jwt->setToken($token)->validateOrFail(); return $next($request); }
Validate JWT token before passing on to the next middleware @param \Illuminate\Http\Request $request @param Closure $next
entailment
public function handleJwtException(JwtException $e) { if($e instanceof InvalidTokenException) { return $this->handleJwtInvalidToken($e); } elseif ($e instanceof NoTokenException) { return $this->handleJwtNoToken($e); } elseif ($e instanceof NoSecretException) { return $this->handleJwtNoSecret($e); } else { $message = getenv('JWT_MESSAGE_ERROR') ?: 'There was an error while validating the authorization token.'; return response()->json([ 'error' => $message ], 500); } }
Render JWT exception @param JwtException $e @return \Illuminate\Http\Response
entailment
public function validate($secret = null, $algo = null) { $token = $this->token(); $secret = $secret ?: $this->secret(); $algo = $algo ?: $this->algorithm(); return $this->jwt->validateToken($token, $secret, $algo); }
Validate a token @param string|null $secret @param string|null $algo @return bool
entailment
public function validateOrFail($secret = null, $algo = null) { if( ! $this->validate($secret, $algo)) { throw new InvalidTokenException('Token is not valid.'); } return true; }
Validate the token or throw an exception @param string|null $secret @param string|null $algo @return bool @throws InvalidTokenException
entailment
public function payload($path = null, $secret = null, $algo = null) { $token = $this->token(); $secret = $secret ?: $this->secret(); $algo = $algo ?: $this->algorithm(); $payload = $this->jwt->decodeToken($token, $secret, $algo); return $this->queryPayload($payload, $path); }
Get the payload from the current token @param string|null $path dot syntax to query for specific data @param string|null $secret @param string|null $algo @return array
entailment
private function queryPayload($payload, $path = null) { if(is_null($path)) return $payload; if(array_key_exists($path, $payload)) { return $payload[$path]; } $dotData = Arr::dot($payload); if(array_key_exists($path, $dotData)) { return $dotData[$path]; } return null; }
Query the payload using dot syntax to find specific data @param array $payload @param string|null $path @return mixed
entailment
public function createToken($payload, $secret = null, $algo = null) { $algo = $algo ?: $this->algorithm(); $secret = $secret ?: $this->secret(); if($payload instanceof JwtPayloadInterface) { $payload = $payload->getPayload(); } $newToken = $this->jwt->createToken($payload, $secret, $algo); $token = clone $this; $token->setToken($newToken); return $token; }
Create a new token with the provided payload The default algorithm used is HS256. To set a custom one, set the env variable JWT_ALGO. @todo Support for enforcing required claims in payload as well as defaults @param JwtPayloadInterface|array $payload @param string|null $secret @param string|null $algo @return JwtToken
entailment
public function dispatchFrom($command, ArrayAccess $source, array $extras = []) { return $this->dispatch($this->marshal($command, $source, $extras)); }
Marshal a command and dispatch it to its appropriate handler. @param mixed $command @param \ArrayAccess $source @param array $extras @return mixed
entailment
protected function marshal($command, ArrayAccess $source, array $extras = []) { $injected = []; $reflection = new ReflectionClass($command); if ($constructor = $reflection->getConstructor()) { $injected = array_map(function ($parameter) use ($command, $source, $extras) { return $this->getParameterValueForCommand($command, $source, $parameter, $extras); }, $constructor->getParameters()); } return $reflection->newInstanceArgs($injected); }
Marshal a command from the given array accessible object. @param string $command @param \ArrayAccess $source @param array $extras @return mixed
entailment
public function dispatchNow($command, Closure $afterResolving = null) { return $this->pipeline->send($command)->through($this->pipes)->then(function ($command) use ($afterResolving) { if ($command instanceof SelfHandling) { return $this->container->call([$command, 'handle']); } $handler = $this->resolveHandler($command); if ($afterResolving) { call_user_func($afterResolving, $handler); } return call_user_func( [$handler, $this->getHandlerMethod($command)], $command ); }); }
Dispatch a command to its appropriate handler in the current process. @param mixed $command @param \Closure|null $afterResolving @return mixed
entailment
protected function commandShouldBeQueued($command) { if ($command instanceof ShouldQueue) { return true; } return (new ReflectionClass($this->getHandlerClass($command)))->implementsInterface( 'Illuminate\Contracts\Queue\ShouldQueue' ); }
Determine if the given command should be queued. @param mixed $command @return bool
entailment
public function resolveHandler($command) { if ($command instanceof SelfHandling) { return $command; } return $this->container->make($this->getHandlerClass($command)); }
Get the handler instance for the given command. @param mixed $command @return mixed
entailment
protected function inflectSegment($command, $segment) { $className = get_class($command); if (isset($this->mappings[$className])) { return $this->getMappingSegment($className, $segment); } elseif ($this->mapper) { return $this->getMapperSegment($command, $segment); } throw new InvalidArgumentException("No handler registered for command [{$className}]"); }
Get the given handler segment for the given command. @param mixed $command @param int $segment @return string
entailment
public function register() { $this->app->singleton('Collective\Bus\Dispatcher', function ($app) { return new Dispatcher($app, function () use ($app) { return $app['Illuminate\Contracts\Queue\Queue']; }); }); $this->app->alias( 'Collective\Bus\Dispatcher', 'Illuminate\Contracts\Bus\Dispatcher' ); $this->app->alias( 'Collective\Bus\Dispatcher', 'Illuminate\Contracts\Bus\QueueingDispatcher' ); }
Register the service provider. @return void
entailment
public function authenticatedRequest(Google_HttpRequest $request) { $request = Google_Client::$auth->sign($request); return $this->makeRequest($request); }
Perform an authenticated / signed apiHttpRequest. This function takes the apiHttpRequest, calls apiAuth->sign on it (which can modify the request in what ever way fits the auth mechanism) and then calls apiCurlIO::makeRequest on the signed request @param Google_HttpRequest $request @return Google_HttpRequest The resulting HTTP response including the responseHttpCode, responseHeaders and responseBody.
entailment
public function setOptions($optCurlParams) { foreach ($optCurlParams as $key => $val) { $this->curlParams[$key] = $val; } }
Set options that update cURL's default behavior. The list of accepted options are: {@link http://php.net/manual/en/function.curl-setopt.php] @param array $optCurlParams Multiple options used by a cURL session.
entailment
public function getHtmlOutput() { try { $profileId = $this->getFirstProfileId(); if (isset($profileId)) { $results = $this->queryCoreReportingApi($profileId); return $this->getFormattedResults($results); } } catch (Google_ServiceException $e) { // Error from the API. $this->error = $e->getMessage(); } catch (demoException $e) { // Error running this demo. $this->error = $e->getMessage(); } return ''; }
Tries to the get users first profile ID then uses that profile id to query the core reporting API. The results from the API are formatted and returned. If any error occurs, $this->error gets set. @return string The formatted API response.
entailment
private function getFormattedResults($results) { $profileName = $results->getProfileInfo()->getProfileName(); $output = '<h3>Results for profile: ' . htmlspecialchars($profileName, ENT_NOQUOTES) . '</h3>'; if (count($results->getRows()) > 0) { $table = '<table>'; // Print headers. $table .= '<tr>'; foreach ($results->getColumnHeaders() as $header) { $table .= '<th>' . $header->getName() . '</th>'; } $table .= '</tr>'; // Print table rows. foreach ($results->getRows() as $row) { $table .= '<tr>'; foreach ($row as $cell) { $table .= '<td>' . htmlspecialchars($cell, ENT_NOQUOTES) . '</td>'; } $table .= '</tr>'; } $table .= '</table>'; } else { $table = '<p>No results found.</p>'; } return $output . $table; }
Formats the results from the Core Reporting API into some nice HTML. The profile name is printed as a header. The results of the query is printed as a table. Note, all the results from the API are html escaped to prevent malicious code from running on the page. @param GaData $results The Results from the Core Reporting API. @return string The nicely formatted results.
entailment
public function reset($achievementId, $optParams = array()) { $params = array('achievementId' => $achievementId); $params = array_merge($params, $optParams); $data = $this->__call('reset', array($params)); if ($this->useObjects()) { return new Google_AchievementResetResponse($data); } else { return $data; } }
Resets the achievement with the given ID. This method is only accessible to whitelisted tester accounts for your application. (achievements.reset) @param string $achievementId The ID of the achievement used by this method. @param array $optParams Optional parameters. @return Google_AchievementResetResponse
entailment
public function resetAll($optParams = array()) { $params = array(); $params = array_merge($params, $optParams); $data = $this->__call('resetAll', array($params)); if ($this->useObjects()) { return new Google_AchievementResetAllResponse($data); } else { return $data; } }
Resets all achievements for the currently authenticated player for your application. This method is only accessible to whitelisted tester accounts for your application. (achievements.resetAll) @param array $optParams Optional parameters. @return Google_AchievementResetAllResponse
entailment
public function listHidden($applicationId, $optParams = array()) { $params = array('applicationId' => $applicationId); $params = array_merge($params, $optParams); $data = $this->__call('listHidden', array($params)); if ($this->useObjects()) { return new Google_HiddenPlayerList($data); } else { return $data; } }
Get the list of players hidden from the given application. This method is only available to user accounts for your developer console. (applications.listHidden) @param string $applicationId The application being requested. @param array $optParams Optional parameters. @opt_param int maxResults The maximum number of player resources to return in the response, used for paging. For any response, the actual number of player resources returned may be less than the specified maxResults. @opt_param string pageToken The token returned by the previous request. @return Google_HiddenPlayerList
entailment
public function hide($applicationId, $playerId, $optParams = array()) { $params = array('applicationId' => $applicationId, 'playerId' => $playerId); $params = array_merge($params, $optParams); $data = $this->__call('hide', array($params)); return $data; }
Hide the given player's leaderboard scores from the given application. This method is only available to user accounts for your developer console. (players.hide) @param string $applicationId The application being requested. @param string $playerId A player ID. A value of me may be used in place of the authenticated player's ID. @param array $optParams Optional parameters.
entailment
public function reset($optParams = array()) { $params = array(); $params = array_merge($params, $optParams); $data = $this->__call('reset', array($params)); return $data; }
Reset all rooms for the currently authenticated player for your application. This method is only accessible to whitelisted tester accounts for your application. (rooms.reset) @param array $optParams Optional parameters.
entailment
public function reset($leaderboardId, $optParams = array()) { $params = array('leaderboardId' => $leaderboardId); $params = array_merge($params, $optParams); $data = $this->__call('reset', array($params)); if ($this->useObjects()) { return new Google_PlayerScoreResetResponse($data); } else { return $data; } }
Reset scores for the specified leaderboard, resetting the leaderboard to empty. This method is only accessible to whitelisted tester accounts for your application. (scores.reset) @param string $leaderboardId The ID of the leaderboard. @param array $optParams Optional parameters. @return Google_PlayerScoreResetResponse
entailment
public function getBaseUrl() { if ($pos = strpos($this->url, '?')) { return substr($this->url, 0, $pos); } return $this->url; }
Misc function that returns the base url component of the $url used by the OAuth signing class to calculate the base string @return string The base url component of the $url. @see http://oauth.net/core/1.0a/#anchor13
entailment
public function getQueryParams() { if ($pos = strpos($this->url, '?')) { $queryStr = substr($this->url, $pos + 1); $params = array(); parse_str($queryStr, $params); return $params; } return array(); }
Misc function that returns an array of the query parameters of the current url used by the OAuth signing class to calculate the signature @return array Query parameters in the query string.
entailment
public function setTokenFromStorage() { $accessToken = $this->storage->get(); if (isset($accessToken)) { $this->client->setAccessToken($accessToken); } }
Retrieves an access token from the storage object and sets it into the client object.
entailment
public function authenticate() { try { $accessToken = $this->client->authenticate(); $this->storage->set($accessToken); // Keep things pretty. Removes the auth code from the URL. if ($_GET['code']) { header("Location: $this->controllerUrl"); } } catch (Google_AuthException $e) { $this->errorMsg = $e->getMessage(); } }
Goes through the client authorization routine. This routine both redirects a user to the Google Accounts authorization screen as well as handle the response from the authorization service to retrieve the authorization code then exchange it for an access token. This method also removes the authorization code from the URL to keep things pretty. Details on how the apiClient implements authorization can be found here: http://code.google.com/p/google-api-php-client/source/browse/trunk/src/auth/apiOAuth2.php#84 If an authorization error occurs, the exception is caught and the error message is saved in $error.
entailment
public function revokeToken() { $accessToken = $this->storage->get(); if ($accessToken) { $tokenObj = json_decode($accessToken); try { $this->client->revokeToken($tokenObj->refresh_token); $this->storage->delete(); } catch (Google_AuthException $e) { $this->errorMsg = $e->getMessage(); } } // Keep things pretty. Removes the auth code from the URL. header("Location: $this->controllerUrl"); }
Revokes an authorization token. This both revokes the token by making a Google Accounts API request to revoke the token as well as deleting the token from the storage mechanism. If any errors occur, the authorization exception is caught and the message is stored in error.
entailment
public function get($customerId, $deviceId, $optParams = array()) { $params = array('customerId' => $customerId, 'deviceId' => $deviceId); $params = array_merge($params, $optParams); $data = $this->__call('get', array($params)); if ($this->useObjects()) { return new Google_ChromeOsDevice($data); } else { return $data; } }
Retrieve Chrome OS Device (chromeosdevices.get) @param string $customerId Immutable id of the Google Apps account @param string $deviceId Immutable id of Chrome OS Device @param array $optParams Optional parameters. @opt_param string projection Restrict information returned to a set of selected fields. @return Google_ChromeOsDevice
entailment
public function listChromeosdevices($customerId, $optParams = array()) { $params = array('customerId' => $customerId); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_ChromeOsDevices($data); } else { return $data; } }
Retrieve all Chrome OS Devices of a customer (paginated) (chromeosdevices.list) @param string $customerId Immutable id of the Google Apps account @param array $optParams Optional parameters. @opt_param int maxResults Maximum number of results to return. Default is 100 @opt_param string orderBy Column to use for sorting results @opt_param string pageToken Token to specify next page in the list @opt_param string projection Restrict information returned to a set of selected fields. @opt_param string query Search string in the format given at http://support.google.com/chromeos/a/bin/answer.py?hl=en=1698333 @opt_param string sortOrder Whether to return results in ascending or descending order. Only of use when orderBy is also used @return Google_ChromeOsDevices
entailment
public function patch($customerId, $deviceId, Google_ChromeOsDevice $postBody, $optParams = array()) { $params = array('customerId' => $customerId, 'deviceId' => $deviceId, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('patch', array($params)); if ($this->useObjects()) { return new Google_ChromeOsDevice($data); } else { return $data; } }
Update Chrome OS Device. This method supports patch semantics. (chromeosdevices.patch) @param string $customerId Immutable id of the Google Apps account @param string $deviceId Immutable id of Chrome OS Device @param Google_ChromeOsDevice $postBody @param array $optParams Optional parameters. @opt_param string projection Restrict information returned to a set of selected fields. @return Google_ChromeOsDevice
entailment
public function get($groupKey, $optParams = array()) { $params = array('groupKey' => $groupKey); $params = array_merge($params, $optParams); $data = $this->__call('get', array($params)); if ($this->useObjects()) { return new Google_Group($data); } else { return $data; } }
Retrieve Group (groups.get) @param string $groupKey Email or immutable Id of the group @param array $optParams Optional parameters. @return Google_Group
entailment
public function listGroups($optParams = array()) { $params = array(); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_Groups($data); } else { return $data; } }
Retrieve all groups in a domain (paginated) (groups.list) @param array $optParams Optional parameters. @opt_param string customer Immutable id of the Google Apps account. In case of multi-domain, to fetch all groups for a customer, fill this field instead of domain. @opt_param string domain Name of the domain. Fill this field to get groups from only this domain. To return all groups in a multi-domain fill customer field instead. @opt_param int maxResults Maximum number of results to return. Default is 200 @opt_param string pageToken Token to specify next page in the list @opt_param string userKey Email or immutable Id of the user if only those groups are to be listed, the given user is a member of. If Id, it should match with id of user object @return Google_Groups
entailment
public function patch($groupKey, Google_Group $postBody, $optParams = array()) { $params = array('groupKey' => $groupKey, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('patch', array($params)); if ($this->useObjects()) { return new Google_Group($data); } else { return $data; } }
Update Group. This method supports patch semantics. (groups.patch) @param string $groupKey Email or immutable Id of the group. If Id, it should match with id of group object @param Google_Group $postBody @param array $optParams Optional parameters. @return Google_Group
entailment
public function listGroupsAliases($groupKey, $optParams = array()) { $params = array('groupKey' => $groupKey); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_Aliases($data); } else { return $data; } }
List all aliases for a group (aliases.list) @param string $groupKey Email or immutable Id of the group @param array $optParams Optional parameters. @return Google_Aliases
entailment
public function get($groupKey, $memberKey, $optParams = array()) { $params = array('groupKey' => $groupKey, 'memberKey' => $memberKey); $params = array_merge($params, $optParams); $data = $this->__call('get', array($params)); if ($this->useObjects()) { return new Google_Member($data); } else { return $data; } }
Retrieve Group Member (members.get) @param string $groupKey Email or immutable Id of the group @param string $memberKey Email or immutable Id of the member @param array $optParams Optional parameters. @return Google_Member
entailment
public function listMembers($groupKey, $optParams = array()) { $params = array('groupKey' => $groupKey); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_Members($data); } else { return $data; } }
Retrieve all members in a group (paginated) (members.list) @param string $groupKey Email or immutable Id of the group @param array $optParams Optional parameters. @opt_param int maxResults Maximum number of results to return. Default is 200 @opt_param string pageToken Token to specify next page in the list @opt_param string roles Comma separated role values to filter list results on. @return Google_Members
entailment
public function patch($groupKey, $memberKey, Google_Member $postBody, $optParams = array()) { $params = array('groupKey' => $groupKey, 'memberKey' => $memberKey, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('patch', array($params)); if ($this->useObjects()) { return new Google_Member($data); } else { return $data; } }
Update membership of a user in the specified group. This method supports patch semantics. (members.patch) @param string $groupKey Email or immutable Id of the group. If Id, it should match with id of group object @param string $memberKey Email or immutable Id of the user. If Id, it should match with id of member object @param Google_Member $postBody @param array $optParams Optional parameters. @return Google_Member
entailment
public function action($customerId, $resourceId, Google_MobileDeviceAction $postBody, $optParams = array()) { $params = array('customerId' => $customerId, 'resourceId' => $resourceId, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('action', array($params)); return $data; }
Take action on Mobile Device (mobiledevices.action) @param string $customerId Immutable id of the Google Apps account @param string $resourceId Immutable id of Mobile Device @param Google_MobileDeviceAction $postBody @param array $optParams Optional parameters.
entailment
public function delete($customerId, $resourceId, $optParams = array()) { $params = array('customerId' => $customerId, 'resourceId' => $resourceId); $params = array_merge($params, $optParams); $data = $this->__call('delete', array($params)); return $data; }
Delete Mobile Device (mobiledevices.delete) @param string $customerId Immutable id of the Google Apps account @param string $resourceId Immutable id of Mobile Device @param array $optParams Optional parameters.
entailment
public function get($customerId, $resourceId, $optParams = array()) { $params = array('customerId' => $customerId, 'resourceId' => $resourceId); $params = array_merge($params, $optParams); $data = $this->__call('get', array($params)); if ($this->useObjects()) { return new Google_MobileDevice($data); } else { return $data; } }
Retrieve Mobile Device (mobiledevices.get) @param string $customerId Immutable id of the Google Apps account @param string $resourceId Immutable id of Mobile Device @param array $optParams Optional parameters. @opt_param string projection Restrict information returned to a set of selected fields. @return Google_MobileDevice
entailment
public function listMobiledevices($customerId, $optParams = array()) { $params = array('customerId' => $customerId); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_MobileDevices($data); } else { return $data; } }
Retrieve all Mobile Devices of a customer (paginated) (mobiledevices.list) @param string $customerId Immutable id of the Google Apps account @param array $optParams Optional parameters. @opt_param int maxResults Maximum number of results to return. Default is 100 @opt_param string orderBy Column to use for sorting results @opt_param string pageToken Token to specify next page in the list @opt_param string projection Restrict information returned to a set of selected fields. @opt_param string query Search string in the format given at http://support.google.com/a/bin/answer.py?hl=en=1408863#search @opt_param string sortOrder Whether to return results in ascending or descending order. Only of use when orderBy is also used @return Google_MobileDevices
entailment
public function get($customerId, $orgUnitPath, $optParams = array()) { $params = array('customerId' => $customerId, 'orgUnitPath' => $orgUnitPath); $params = array_merge($params, $optParams); $data = $this->__call('get', array($params)); if ($this->useObjects()) { return new Google_OrgUnit($data); } else { return $data; } }
Retrieve Organization Unit (orgunits.get) @param string $customerId Immutable id of the Google Apps account @param string $orgUnitPath Full path of the organization unit @param array $optParams Optional parameters. @return Google_OrgUnit
entailment
public function listOrgunits($customerId, $optParams = array()) { $params = array('customerId' => $customerId); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_OrgUnits($data); } else { return $data; } }
Retrieve all Organization Units (orgunits.list) @param string $customerId Immutable id of the Google Apps account @param array $optParams Optional parameters. @opt_param string orgUnitPath the URL-encoded organization unit @opt_param string type Whether to return all sub-organizations or just immediate children @return Google_OrgUnits
entailment
public function update($customerId, $orgUnitPath, Google_OrgUnit $postBody, $optParams = array()) { $params = array('customerId' => $customerId, 'orgUnitPath' => $orgUnitPath, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('update', array($params)); if ($this->useObjects()) { return new Google_OrgUnit($data); } else { return $data; } }
Update Organization Unit (orgunits.update) @param string $customerId Immutable id of the Google Apps account @param string $orgUnitPath Full path of the organization unit @param Google_OrgUnit $postBody @param array $optParams Optional parameters. @return Google_OrgUnit
entailment
public function delete($userKey, $optParams = array()) { $params = array('userKey' => $userKey); $params = array_merge($params, $optParams); $data = $this->__call('delete', array($params)); return $data; }
Delete user (users.delete) @param string $userKey Email or immutable Id of the user @param array $optParams Optional parameters.
entailment
public function listUsers($optParams = array()) { $params = array(); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_Users($data); } else { return $data; } }
Retrieve either deleted users or all users in a domain (paginated) (users.list) @param array $optParams Optional parameters. @opt_param string customer Immutable id of the Google Apps account. In case of multi-domain, to fetch all users for a customer, fill this field instead of domain. @opt_param string domain Name of the domain. Fill this field to get users from only this domain. To return all users in a multi-domain fill customer field instead. @opt_param int maxResults Maximum number of results to return. Default is 100. Max allowed is 500 @opt_param string orderBy Column to use for sorting results @opt_param string pageToken Token to specify next page in the list @opt_param string query Query string for prefix matching searches. Should be of the form "key:value*" where key can be "email", "givenName" or "familyName". The asterisk is required, for example: "givenName:Ann*" is a valid query. @opt_param string showDeleted If set to true retrieves the list of deleted users. Default is false @opt_param string sortOrder Whether to return results in ascending or descending order. @return Google_Users
entailment
public function makeAdmin($userKey, Google_UserMakeAdmin $postBody, $optParams = array()) { $params = array('userKey' => $userKey, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('makeAdmin', array($params)); return $data; }
change admin status of a user (users.makeAdmin) @param string $userKey Email or immutable Id of the user as admin @param Google_UserMakeAdmin $postBody @param array $optParams Optional parameters.
entailment
public function undelete($userKey, Google_UserUndelete $postBody, $optParams = array()) { $params = array('userKey' => $userKey, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('undelete', array($params)); return $data; }
Undelete a deleted user (users.undelete) @param string $userKey The immutable id of the user @param Google_UserUndelete $postBody @param array $optParams Optional parameters.
entailment
public function update($userKey, Google_User $postBody, $optParams = array()) { $params = array('userKey' => $userKey, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('update', array($params)); if ($this->useObjects()) { return new Google_User($data); } else { return $data; } }
update user (users.update) @param string $userKey Email or immutable Id of the user. If Id, it should match with id of user object @param Google_User $postBody @param array $optParams Optional parameters. @return Google_User
entailment
public function insert($userKey, Google_Alias $postBody, $optParams = array()) { $params = array('userKey' => $userKey, 'postBody' => $postBody); $params = array_merge($params, $optParams); $data = $this->__call('insert', array($params)); if ($this->useObjects()) { return new Google_Alias($data); } else { return $data; } }
Add a alias for the user (aliases.insert) @param string $userKey Email or immutable Id of the user @param Google_Alias $postBody @param array $optParams Optional parameters. @return Google_Alias
entailment
public function listUsersAliases($userKey, $optParams = array()) { $params = array('userKey' => $userKey); $params = array_merge($params, $optParams); $data = $this->__call('list', array($params)); if ($this->useObjects()) { return new Google_Aliases($data); } else { return $data; } }
List all aliases for a user (aliases.list) @param string $userKey Email or immutable Id of the user @param array $optParams Optional parameters. @return Google_Aliases
entailment