<?php
namespace Wpupgrader\WordPress\Plugins\GdprConsentLite\Hooks\Actions;

use Wpupgrader\WordPress\Plugins\GdprConsentPlugin\GdprConsentPlugin;

class add_meta_boxes extends \Wpupgrader\Libraries\WordPress\Plugins\Core\Hooks\AbstractAction
{
    /**
     * This method is invoked by Wordpress
     */
    static public function invoke()
    {
        static::addConsentMetaboxes();
    }

    static protected function addConsentMetaboxes()
    {
        \add_meta_box('gdprc_consent_plugins_box', 'Disallowed Plugins', function($post) {
            global $wpdb;

            \wp_nonce_field('gdprc_disallowed_plugins_nonce_action', 'gdprc_disallowed_plugins_nonce');

            echo "<div class='gdprc_plugin_tip'><b>".\__('Selected plugins will only be loaded for the visitor if they have approved this consent.', 'gdprc_consent')."</b></div><hr/>";

            $disallowedPlugins = \get_post_meta($post->ID, 'gdprc_disallowed_plugins');
            $disallowedPlugins = \array_shift($disallowedPlugins);
            $availablePlugins = \array_filter(\get_plugins(), function($plugin) {
                return stripos($plugin['Name'], 'GDPR Consent') !== -1;
            });

            echo "<div class='gdprc_plugin_box'>";
            echo '<table class="form-table"><tbody>';

            if (\is_array($availablePlugins)) {
                foreach ($availablePlugins as $key => $value) {
                    $checked = "";
                    if (\get_current_screen()->action !== 'add') {
                        if (isset($disallowedPlugins) && \is_array($disallowedPlugins) && \in_array($key, $disallowedPlugins)) {
                            $checked = 'checked="checked"';
                        }
                    }

                    echo '<tr><th scope="row"><input type="checkbox" '.\esc_attr($checked).' name="gdprc_disallowed_plugins[]" value="'.\esc_attr($key).'" id="gdprc_disallowed_plugins_'.\esc_attr($key).'" /></th>';
                    echo '<td><label for=gdprc_disallowed_plugins_'.\esc_attr($key).'><b>'.\get_plugin_data(\trailingslashit(WP_CONTENT_DIR)."plugins/".$key, false)['Name']."</b>";
                    // echo "<br>".\get_plugin_data(\trailingslashit(WP_CONTENT_DIR)."plugins/".$key, false)['Description'];
                    echo "</label><br>";

                    /**
                     * Wordpress Plugin Enabled or already in a Consent?
                     */

                    /* If WPML is active, we do things differently */
                    if ($sitepress = \gdprc_wpml_plugin_install()) {
                        $used_in_query =
                            "SELECT `{$wpdb->posts}`.`ID`, `{$wpdb->posts}`.`post_title`
					    FROM `{$wpdb->posts}`, `{$wpdb->postmeta}`, `{$wpdb->prefix}icl_translations`
					    WHERE `{$wpdb->posts}`.`post_type` = 'gdprc_consent'
						    AND `{$wpdb->posts}`.`ID` = `{$wpdb->postmeta}`.`post_id`
				            AND `{$wpdb->posts}`.`ID` = `element_id`
				            AND `source_language_code` IS NULL
						    AND `{$wpdb->postmeta}`.`meta_key` = 'gdprc_disallowed_plugins'
						    AND `{$wpdb->postmeta}`.`meta_value` LIKE '%$key%'
						    AND `{$wpdb->posts}`.`ID` <> '".\sanitize_key($_GET['post'])."'
						    AND `{$wpdb->posts}`.`post_status` = 'publish'";
                    }
                    else {
                        $used_in_query =
                            "SELECT `{$wpdb->posts}`.`ID`, `{$wpdb->posts}`.`post_title`
					    FROM `{$wpdb->posts}`, `{$wpdb->postmeta}`
					    WHERE `{$wpdb->posts}`.`post_type` = 'gdprc_consent'
						    AND `{$wpdb->posts}`.`ID` = `{$wpdb->postmeta}`.`post_id`
						    AND `{$wpdb->postmeta}`.`meta_key` = 'gdprc_disallowed_plugins'
						    AND `{$wpdb->postmeta}`.`meta_value` LIKE '%$key%'
						    AND `{$wpdb->posts}`.`ID` <> '".\sanitize_key($_GET['post'])."'
						    AND `{$wpdb->posts}`.`post_status` = 'publish'";
                    }

                    $usedInOtherConsents = $wpdb->get_results($used_in_query, ARRAY_A);
                    $usedInOtherConsents = \array_combine(\array_column($usedInOtherConsents, 'ID'), \array_column($usedInOtherConsents, 'post_title'));

                    $in_consents = "";
                    foreach ($usedInOtherConsents as $id => $title) {
                        $in_consents .= "<a href='/wp-admin/post.php?action=edit&post=".$id."' target='_blank'>".$title."</a>, ";
                    }

                    if (!empty($in_consents)) {
                        echo "<span class='gdprc_plugin_status warning'><span class='gdpri gdpri-warning'></span> Also in: ".\substr_replace($in_consents, ".", -3)."</span>";
                    }
                    else if (\is_plugin_active($key)) {
                        echo "<span class='gdprc_plugin_status active'>";
                        \_e("Plugin is: Active", 'gdprc_consent');
                        echo "</span>";
                    }
                    else {
                        echo "<span class='gdprc_plugin_status inactive'>";
                        \_e("Plugin was deactivated", 'gdprc_consent');
                        echo "</span>";
                    }

                    echo '</td></tr>';
                }
            }
            if (empty($availablePlugins)) {
                \_e("There are no other plugins installed.", 'gdprc_consent');
            }

            echo '</tbody></table></div>';
        }, 'gdprc_consent', 'normal', 'high');

        if (\gdprConsentPluginIsProEdition()) {
            \add_meta_box('gdprc_consent_scripts_box', 'Allowed Scripts', function($post) {
                global $wpdb;

                $availableScripts = new \WP_Query([
                    'post_status'      => 'publish',
                    'post_type'        => 'gdprc_script',
                    'numberposts'      => -1,
                    'suppress_filters' => 0,
                ]);

                echo "<div class='gdprc_plugin_tip'><b>".\__('Selected scripts will only be loaded for the visitor if they have approved this consent.', 'gdprc_consent')."</b></div><hr/>";

                echo "<div class='gdprc_script_box'>";
                echo '<table class="form-table"><tbody>';

                while ($availableScripts->have_posts()) {
                    $availableScripts->the_post();
                    $gdprc_allowed_scripts = \get_post_meta(\sanitize_key($_GET['post']), 'gdprc_allowed_scripts');

                    $checked = "";
                    if (\get_current_screen()->action != 'add' && !empty($gdprc_allowed_scripts[0])) {
                        if (\in_array(\get_the_ID(), $gdprc_allowed_scripts[0])) {
                            $checked = 'checked="checked"';
                        }
                    }

                    $scriptId = \get_the_ID();
                    echo '<tr><th scope="row"><input type="checkbox" '.$checked.' name="gdprc_allowed_scripts[]" value="'.\esc_attr($scriptId).'" id="gdprc_gdprc_allowed_scripts_'.\esc_attr($scriptId).'" /></th>';
                    echo '<td><label for="gdprc_gdprc_allowed_scripts_'.\esc_attr($scriptId).'"><b>';
                    echo \get_the_title();
                    echo "</b></label><br>";

                    /**
                     * Script already in a Consent?
                     */

                    /* If WPML is active, we do things differently */
                    if ($sitepress = \gdprc_wpml_plugin_install()) {
                        $used_in_query =
                            "SELECT `{$wpdb->posts}`.`ID`, `{$wpdb->posts}`.`post_title`
				    FROM `{$wpdb->posts}`, `{$wpdb->postmeta}`, `{$wpdb->prefix}icl_translations`
				    WHERE `{$wpdb->posts}`.`post_type` = 'gdprc_consent'
					    AND `{$wpdb->posts}`.`ID` = `{$wpdb->postmeta}`.`post_id`
			            AND `{$wpdb->posts}`.`ID` = `element_id`
			            AND `source_language_code` IS NULL
					    AND `{$wpdb->postmeta}`.`meta_key` = 'gdprc_allowed_scripts'
					    AND `{$wpdb->postmeta}`.`meta_value` LIKE '%\"{$scriptId}\"%'
					    AND `{$wpdb->posts}`.`ID` <> '".\sanitize_key($_GET['post'])."'
					    AND `{$wpdb->posts}`.`post_status` = 'publish'";
                    }
                    else {
                        $used_in_query =
                            "SELECT `{$wpdb->posts}`.`ID`, `{$wpdb->posts}`.`post_title`
				    FROM `{$wpdb->posts}`, `{$wpdb->postmeta}`
				    WHERE `{$wpdb->posts}`.`post_type` = 'gdprc_consent'
					    AND `{$wpdb->posts}`.`ID` = `{$wpdb->postmeta}`.`post_id`
					    AND `{$wpdb->postmeta}`.`meta_key` = 'gdprc_allowed_scripts'
					    AND `{$wpdb->postmeta}`.`meta_value` LIKE '%\"{$scriptId}\"%'
					    AND `{$wpdb->posts}`.`ID` <> '".\sanitize_key($_GET['post'])."'
					    AND `{$wpdb->posts}`.`post_status` = 'publish'";
                    }

                    $usedInOtherConsents = $wpdb->get_results($used_in_query, ARRAY_A);
                    $usedInOtherConsents = \array_combine(\array_column($usedInOtherConsents, 'ID'), \array_column($usedInOtherConsents, 'post_title'));

                    $in_consents = "";
                    foreach ($usedInOtherConsents as $id => $title) {
                        $in_consents .= "<a href='/wp-admin/post.php?action=edit&post=".$id."' target='_blank'>".$title."</a>, ";
                    }

                    if (!empty($in_consents)) {
                        echo "<span class='gdprc_plugin_status warning'><span class='gdpri gdpri-check-square-o'></span> Also in: ".\substr_replace($in_consents, ".", -3)."</span>";
                    }

                    echo "</td></tr>";
                }

                \wp_reset_query();

                if (!$availableScripts->have_posts()) {
                    \_e("There are no scripts defined,", 'gdprc_consent');

                    echo " <a href='post-new.php?post_type=gdprc_script'>";
                    \_e("Create new");
                    echo "</a>.";
                }

                echo '</tbody></table></div>';
            }, 'gdprc_consent', 'normal', 'high');
        }

        \add_meta_box('gdprc_consent_options_box', 'Consent Options', function() {
            global $post;
            // Nonce field to validate form request came from current site
            \wp_nonce_field(\basename(__FILE__), 'gdprc_consent_options');

            $gdprc_consent_sortorder = \get_post_meta($post->ID, 'gdprc_consent_sortorder', true);
            echo '<label for="gdprc_consent_sortorder">';
            \_e("Sort order:", 'gdprc_consent');
            echo '</b></label>';
            echo '<input type="number" name="gdprc_consent_sortorder" id="gdprc_consent_sortorder" class="widefat" value="'.(!empty($gdprc_consent_sortorder) || $gdprc_consent_sortorder == "0" ? $gdprc_consent_sortorder : 10).'">';
            echo '<br/><b>'.\__("0 = top, higher = lower in consent list", 'gdprc_consent').'</b>';
            echo '<br /><br/>';
//    echo '<hr />';
            $gdprc_consent_is_required = \get_post_meta($post->ID, 'gdprc_consent_is_required', true);
            echo '<input type="checkbox" name="gdprc_consent_is_required" id="gdprc_consent_is_required"';
            \checked($gdprc_consent_is_required, 1);
            echo 'class="widefat"> <label for="gdprc_consent_is_required"><b>';
            \_e("Mark as mandatory consent", 'gdprc_consent');
            echo '*</b></label><div title="'.\__("Make sure you're following GDPR guidelines when checking this option, specifically the Privacy Default.", 'gdprc_consent').'"><br/><i> *'.\__
                ("Force visitors to accept this consent by default. (Disclaimer: Mandatory consents should only be used for scripts and plugins that are needed to visit your website.)", 'gdprc_consent').'</i></div>';
            echo '<br/>';
        }, 'gdprc_consent', 'side', 'high');

        \add_meta_box('gdprc_consent_icons_box', 'Icon Selector', function() {
            $icons = [
                'name'    => 'Icon',
                'id'      => 'icon',
                'type'    => 'select',
                'options' => [
                    'gdpri-adjust'               => 'adjust',
                    'gdpri-adn'                  => 'adn',
                    'gdpri-align-center'         => 'align-center',
                    'gdpri-align-justify'        => 'align-justify',
                    'gdpri-align-left'           => 'align-left',
                    'gdpri-align-right'          => 'align-right',
                    'gdpri-ambulance'            => 'ambulance',
                    'gdpri-anchor'               => 'anchor',
                    'gdpri-android'              => 'android',
                    'gdpri-angle-double-down'    => 'angle-double-down',
                    'gdpri-angle-double-left'    => 'angle-double-left',
                    'gdpri-angle-double-right'   => 'angle-double-right',
                    'gdpri-angle-double-up'      => 'angle-double-up',
                    'gdpri-angle-down'           => 'angle-down',
                    'gdpri-angle-left'           => 'angle-left',
                    'gdpri-angle-right'          => 'angle-right',
                    'gdpri-angle-up'             => 'angle-up',
                    'gdpri-apple'                => 'apple',
                    'gdpri-archive'              => 'archive',
                    'gdpri-arrow-circle-down'    => 'arrow-circle-down',
                    'gdpri-arrow-circle-left'    => 'arrow-circle-left',
                    'gdpri-arrow-circle-o-down'  => 'arrow-circle-o-down',
                    'gdpri-arrow-circle-o-left'  => 'arrow-circle-o-left',
                    'gdpri-arrow-circle-o-right' => 'arrow-circle-o-right',
                    'gdpri-arrow-circle-o-up'    => 'arrow-circle-o-up',
                    'gdpri-arrow-circle-right'   => 'arrow-circle-right',
                    'gdpri-arrow-circle-up'      => 'arrow-circle-up',
                    'gdpri-arrow-down'           => 'arrow-down',
                    'gdpri-arrow-left'           => 'arrow-left',
                    'gdpri-arrow-right'          => 'arrow-right',
                    'gdpri-arrow-up'             => 'arrow-up',
                    'gdpri-arrows'               => 'arrows',
                    'gdpri-arrows-alt'           => 'arrows-alt',
                    'gdpri-arrows-h'             => 'arrows-h',
                    'gdpri-arrows-v'             => 'arrows-v',
                    'gdpri-asterisk'             => 'asterisk',
                    'gdpri-automobile'           => 'automobile',
                    'gdpri-backward'             => 'backward',
                    'gdpri-ban'                  => 'ban',
                    'gdpri-bank'                 => 'bank',
                    'gdpri-bar-chart-o'          => 'bar-chart-o',
                    'gdpri-barcode'              => 'barcode',
                    'gdpri-bars'                 => 'bars',
                    'gdpri-beer'                 => 'beer',
                    'gdpri-behance'              => 'behance',
                    'gdpri-behance-square'       => 'behance-square',
                    'gdpri-bell'                 => 'bell',
                    'gdpri-bell-o'               => 'bell-o',
                    'gdpri-bitbucket'            => 'bitbucket',
                    'gdpri-bitbucket-square'     => 'bitbucket-square',
                    'gdpri-bitcoin'              => 'bitcoin',
                    'gdpri-bold'                 => 'bold',
                    'gdpri-bolt'                 => 'bolt',
                    'gdpri-bomb'                 => 'bomb',
                    'gdpri-book'                 => 'book',
                    'gdpri-bookmark'             => 'bookmark',
                    'gdpri-bookmark-o'           => 'bookmark-o',
                    'gdpri-briefcase'            => 'briefcase',
                    'gdpri-btc'                  => 'btc',
                    'gdpri-bug'                  => 'bug',
                    'gdpri-building'             => 'building',
                    'gdpri-building-o'           => 'building-o',
                    'gdpri-bullhorn'             => 'bullhorn',
                    'gdpri-bullseye'             => 'bullseye',
                    'gdpri-cab'                  => 'cab',
                    'gdpri-calendar'             => 'calendar',
                    'gdpri-calendar-o'           => 'calendar-o',
                    'gdpri-camera'               => 'camera',
                    'gdpri-camera-retro'         => 'camera-retro',
                    'gdpri-car'                  => 'car',
                    'gdpri-caret-down'           => 'caret-down',
                    'gdpri-caret-left'           => 'caret-left',
                    'gdpri-caret-right'          => 'caret-right',
                    'gdpri-caret-square-o-down'  => 'caret-square-o-down',
                    'gdpri-caret-square-o-left'  => 'caret-square-o-left',
                    'gdpri-caret-square-o-right' => 'caret-square-o-right',
                    'gdpri-caret-square-o-up'    => 'caret-square-o-up',
                    'gdpri-caret-up'             => 'caret-up',
                    'gdpri-certificate'          => 'certificate',
                    'gdpri-chain'                => 'chain',
                    'gdpri-chain-broken'         => 'chain-broken',
                    'gdpri-check'                => 'check',
                    'gdpri-check-circle'         => 'check-circle',
                    'gdpri-check-circle-o'       => 'check-circle-o',
                    'gdpri-check-square'         => 'check-square',
                    'gdpri-check-square-o'       => 'check-square-o',
                    'gdpri-chevron-circle-down'  => 'chevron-circle-down',
                    'gdpri-chevron-circle-left'  => 'chevron-circle-left',
                    'gdpri-chevron-circle-right' => 'chevron-circle-right',
                    'gdpri-chevron-circle-up'    => 'chevron-circle-up',
                    'gdpri-chevron-down'         => 'chevron-down',
                    'gdpri-chevron-left'         => 'chevron-left',
                    'gdpri-chevron-right'        => 'chevron-right',
                    'gdpri-chevron-up'           => 'chevron-up',
                    'gdpri-child'                => 'child',
                    'gdpri-circle'               => 'circle',
                    'gdpri-circle-o'             => 'circle-o',
                    'gdpri-circle-o-notch'       => 'circle-o-notch',
                    'gdpri-circle-thin'          => 'circle-thin',
                    'gdpri-clipboard'            => 'clipboard',
                    'gdpri-clock-o'              => 'clock-o',
                    'gdpri-cloud'                => 'cloud',
                    'gdpri-cloud-download'       => 'cloud-download',
                    'gdpri-cloud-upload'         => 'cloud-upload',
                    'gdpri-cny'                  => 'cny',
                    'gdpri-code'                 => 'code',
                    'gdpri-code-fork'            => 'code-fork',
                    'gdpri-codepen'              => 'codepen',
                    'gdpri-coffee'               => 'coffee',
                    'gdpri-cog'                  => 'cog',
                    'gdpri-cogs'                 => 'cogs',
                    'gdpri-columns'              => 'columns',
                    'gdpri-comment'              => 'comment',
                    'gdpri-comment-o'            => 'comment-o',
                    'gdpri-comments'             => 'comments',
                    'gdpri-comments-o'           => 'comments-o',
                    'gdpri-compass'              => 'compass',
                    'gdpri-compress'             => 'compress',
                    'gdpri-copy'                 => 'copy',
                    'gdpri-credit-card'          => 'credit-card',
                    'gdpri-crop'                 => 'crop',
                    'gdpri-crosshairs'           => 'crosshairs',
                    'gdpri-css3'                 => 'css3',
                    'gdpri-cube'                 => 'cube',
                    'gdpri-cubes'                => 'cubes',
                    'gdpri-cut'                  => 'cut',
                    'gdpri-cutlery'              => 'cutlery',
                    'gdpri-dashboard'            => 'dashboard',
                    'gdpri-database'             => 'database',
                    'gdpri-dedent'               => 'dedent',
                    'gdpri-delicious'            => 'delicious',
                    'gdpri-desktop'              => 'desktop',
                    'gdpri-deviantart'           => 'deviantart',
                    'gdpri-digg'                 => 'digg',
                    'gdpri-dollar'               => 'dollar',
                    'gdpri-dot-circle-o'         => 'dot-circle-o',
                    'gdpri-download'             => 'download',
                    'gdpri-dribbble'             => 'dribbble',
                    'gdpri-dropbox'              => 'dropbox',
                    'gdpri-drupal'               => 'drupal',
                    'gdpri-edit'                 => 'edit',
                    'gdpri-eject'                => 'eject',
                    'gdpri-ellipsis-h'           => 'ellipsis-h',
                    'gdpri-ellipsis-v'           => 'ellipsis-v',
                    'gdpri-empire'               => 'empire',
                    'gdpri-envelope'             => 'envelope',
                    'gdpri-envelope-o'           => 'envelope-o',
                    'gdpri-envelope-square'      => 'envelope-square',
                    'gdpri-eraser'               => 'eraser',
                    'gdpri-eur'                  => 'eur',
                    'gdpri-euro'                 => 'euro',
                    'gdpri-exchange'             => 'exchange',
                    'gdpri-exclamation'          => 'exclamation',
                    'gdpri-exclamation-circle'   => 'exclamation-circle',
                    'gdpri-exclamation-triangle' => 'exclamation-triangle',
                    'gdpri-expand'               => 'expand',
                    'gdpri-external-link'        => 'external-link',
                    'gdpri-external-link-square' => 'external-link-square',
                    'gdpri-eye'                  => 'eye',
                    'gdpri-eye-slash'            => 'eye-slash',
                    'gdpri-facebook'             => 'facebook',
                    'gdpri-facebook-square'      => 'facebook-square',
                    'gdpri-fast-backward'        => 'fast-backward',
                    'gdpri-fast-forward'         => 'fast-forward',
                    'gdpri-fax'                  => 'fax',
                    'gdpri-female'               => 'female',
                    'gdpri-fighter-jet'          => 'fighter-jet',
                    'gdpri-file'                 => 'file',
                    'gdpri-file-archive-o'       => 'file-archive-o',
                    'gdpri-file-audio-o'         => 'file-audio-o',
                    'gdpri-file-code-o'          => 'file-code-o',
                    'gdpri-file-excel-o'         => 'file-excel-o',
                    'gdpri-file-image-o'         => 'file-image-o',
                    'gdpri-file-movie-o'         => 'file-movie-o',
                    'gdpri-file-o'               => 'file-o',
                    'gdpri-file-pdf-o'           => 'file-pdf-o',
                    'gdpri-file-photo-o'         => 'file-photo-o',
                    'gdpri-file-picture-o'       => 'file-picture-o',
                    'gdpri-file-powerpoint-o'    => 'file-powerpoint-o',
                    'gdpri-file-sound-o'         => 'file-sound-o',
                    'gdpri-file-text'            => 'file-text',
                    'gdpri-file-text-o'          => 'file-text-o',
                    'gdpri-file-video-o'         => 'file-video-o',
                    'gdpri-file-word-o'          => 'file-word-o',
                    'gdpri-file-zip-o'           => 'file-zip-o',
                    'gdpri-files-o'              => 'files-o',
                    'gdpri-film'                 => 'film',
                    'gdpri-filter'               => 'filter',
                    'gdpri-fire'                 => 'fire',
                    'gdpri-fire-extinguisher'    => 'fire-extinguisher',
                    'gdpri-flag'                 => 'flag',
                    'gdpri-flag-checkered'       => 'flag-checkered',
                    'gdpri-flag-o'               => 'flag-o',
                    'gdpri-flash'                => 'flash',
                    'gdpri-flask'                => 'flask',
                    'gdpri-flickr'               => 'flickr',
                    'gdpri-floppy-o'             => 'floppy-o',
                    'gdpri-folder'               => 'folder',
                    'gdpri-folder-o'             => 'folder-o',
                    'gdpri-folder-open'          => 'folder-open',
                    'gdpri-folder-open-o'        => 'folder-open-o',
                    'gdpri-font'                 => 'font',
                    'gdpri-forward'              => 'forward',
                    'gdpri-foursquare'           => 'foursquare',
                    'gdpri-frown-o'              => 'frown-o',
                    'gdpri-gamepad'              => 'gamepad',
                    'gdpri-gavel'                => 'gavel',
                    'gdpri-gbp'                  => 'gbp',
                    'gdpri-ge'                   => 'ge',
                    'gdpri-gear'                 => 'gear',
                    'gdpri-gears'                => 'gears',
                    'gdpri-gift'                 => 'gift',
                    'gdpri-git'                  => 'git',
                    'gdpri-git-square'           => 'git-square',
                    'gdpri-github'               => 'github',
                    'gdpri-github-alt'           => 'github-alt',
                    'gdpri-github-square'        => 'github-square',
                    'gdpri-gittip'               => 'gittip',
                    'gdpri-glass'                => 'glass',
                    'gdpri-globe'                => 'globe',
                    'gdpri-google'               => 'google',
                    'gdpri-google-plus'          => 'google-plus',
                    'gdpri-google-plus-square'   => 'google-plus-square',
                    'gdpri-graduation-cap'       => 'graduation-cap',
                    'gdpri-group'                => 'group',
                    'gdpri-h-square'             => 'h-square',
                    'gdpri-hacker-news'          => 'hacker-news',
                    'gdpri-hand-o-down'          => 'hand-o-down',
                    'gdpri-hand-o-left'          => 'hand-o-left',
                    'gdpri-hand-o-right'         => 'hand-o-right',
                    'gdpri-hand-o-up'            => 'hand-o-up',
                    'gdpri-hdd-o'                => 'hdd-o',
                    'gdpri-header'               => 'header',
                    'gdpri-headphones'           => 'headphones',
                    'gdpri-heart'                => 'heart',
                    'gdpri-heart-o'              => 'heart-o',
                    'gdpri-history'              => 'history',
                    'gdpri-home'                 => 'home',
                    'gdpri-hospital-o'           => 'hospital-o',
                    'gdpri-html5'                => 'html5',
                    'gdpri-image'                => 'image',
                    'gdpri-inbox'                => 'inbox',
                    'gdpri-indent'               => 'indent',
                    'gdpri-info'                 => 'info',
                    'gdpri-info-circle'          => 'info-circle',
                    'gdpri-inr'                  => 'inr',
                    'gdpri-instagram'            => 'instagram',
                    'gdpri-institution'          => 'institution',
                    'gdpri-italic'               => 'italic',
                    'gdpri-joomla'               => 'joomla',
                    'gdpri-jpy'                  => 'jpy',
                    'gdpri-jsfiddle'             => 'jsfiddle',
                    'gdpri-key'                  => 'key',
                    'gdpri-keyboard-o'           => 'keyboard-o',
                    'gdpri-krw'                  => 'krw',
                    'gdpri-language'             => 'language',
                    'gdpri-laptop'               => 'laptop',
                    'gdpri-leaf'                 => 'leaf',
                    'gdpri-legal'                => 'legal',
                    'gdpri-lemon-o'              => 'lemon-o',
                    'gdpri-level-down'           => 'level-down',
                    'gdpri-level-up'             => 'level-up',
                    'gdpri-life-bouy'            => 'life-bouy',
                    'gdpri-life-ring'            => 'life-ring',
                    'gdpri-life-saver'           => 'life-saver',
                    'gdpri-lightbulb-o'          => 'lightbulb-o',
                    'gdpri-link'                 => 'link',
                    'gdpri-linkedin'             => 'linkedin',
                    'gdpri-linkedin-square'      => 'linkedin-square',
                    'gdpri-linux'                => 'linux',
                    'gdpri-list'                 => 'list',
                    'gdpri-list-alt'             => 'list-alt',
                    'gdpri-list-ol'              => 'list-ol',
                    'gdpri-list-ul'              => 'list-ul',
                    'gdpri-location-arrow'       => 'location-arrow',
                    'gdpri-lock'                 => 'lock',
                    'gdpri-long-arrow-down'      => 'long-arrow-down',
                    'gdpri-long-arrow-left'      => 'long-arrow-left',
                    'gdpri-long-arrow-right'     => 'long-arrow-right',
                    'gdpri-long-arrow-up'        => 'long-arrow-up',
                    'gdpri-magic'                => 'magic',
                    'gdpri-magnet'               => 'magnet',
                    'gdpri-mail-forward'         => 'mail-forward',
                    'gdpri-mail-reply'           => 'mail-reply',
                    'gdpri-mail-reply-all'       => 'mail-reply-all',
                    'gdpri-male'                 => 'male',
                    'gdpri-map-marker'           => 'map-marker',
                    'gdpri-maxcdn'               => 'maxcdn',
                    'gdpri-medkit'               => 'medkit',
                    'gdpri-meh-o'                => 'meh-o',
                    'gdpri-microphone'           => 'microphone',
                    'gdpri-microphone-slash'     => 'microphone-slash',
                    'gdpri-minus'                => 'minus',
                    'gdpri-minus-circle'         => 'minus-circle',
                    'gdpri-minus-square'         => 'minus-square',
                    'gdpri-minus-square-o'       => 'minus-square-o',
                    'gdpri-mobile'               => 'mobile',
                    'gdpri-mobile-phone'         => 'mobile-phone',
                    'gdpri-money'                => 'money',
                    'gdpri-moon-o'               => 'moon-o',
                    'gdpri-mortar-board'         => 'mortar-board',
                    'gdpri-music'                => 'music',
                    'gdpri-navicon'              => 'navicon',
                    'gdpri-openid'               => 'openid',
                    'gdpri-outdent'              => 'outdent',
                    'gdpri-pagelines'            => 'pagelines',
                    'gdpri-paper-plane'          => 'paper-plane',
                    'gdpri-paper-plane-o'        => 'paper-plane-o',
                    'gdpri-paperclip'            => 'paperclip',
                    'gdpri-paragraph'            => 'paragraph',
                    'gdpri-paste'                => 'paste',
                    'gdpri-pause'                => 'pause',
                    'gdpri-paw'                  => 'paw',
                    'gdpri-pencil'               => 'pencil',
                    'gdpri-pencil-square'        => 'pencil-square',
                    'gdpri-pencil-square-o'      => 'pencil-square-o',
                    'gdpri-phone'                => 'phone',
                    'gdpri-phone-square'         => 'phone-square',
                    'gdpri-photo'                => 'photo',
                    'gdpri-picture-o'            => 'picture-o',
                    'gdpri-pied-piper'           => 'pied-piper',
                    'gdpri-pied-piper-alt'       => 'pied-piper-alt',
                    'gdpri-pied-piper-square'    => 'pied-piper-square',
                    'gdpri-pinterest'            => 'pinterest',
                    'gdpri-pinterest-square'     => 'pinterest-square',
                    'gdpri-plane'                => 'plane',
                    'gdpri-play'                 => 'play',
                    'gdpri-play-circle'          => 'play-circle',
                    'gdpri-play-circle-o'        => 'play-circle-o',
                    'gdpri-plus'                 => 'plus',
                    'gdpri-plus-circle'          => 'plus-circle',
                    'gdpri-plus-square'          => 'plus-square',
                    'gdpri-plus-square-o'        => 'plus-square-o',
                    'gdpri-power-off'            => 'power-off',
                    'gdpri-print'                => 'print',
                    'gdpri-puzzle-piece'         => 'puzzle-piece',
                    'gdpri-qq'                   => 'qq',
                    'gdpri-qrcode'               => 'qrcode',
                    'gdpri-question'             => 'question',
                    'gdpri-question-circle'      => 'question-circle',
                    'gdpri-quote-left'           => 'quote-left',
                    'gdpri-quote-right'          => 'quote-right',
                    'gdpri-ra'                   => 'ra',
                    'gdpri-random'               => 'random',
                    'gdpri-rebel'                => 'rebel',
                    'gdpri-recycle'              => 'recycle',
                    'gdpri-reddit'               => 'reddit',
                    'gdpri-reddit-square'        => 'reddit-square',
                    'gdpri-refresh'              => 'refresh',
                    'gdpri-renren'               => 'renren',
                    'gdpri-reorder'              => 'reorder',
                    'gdpri-repeat'               => 'repeat',
                    'gdpri-reply'                => 'reply',
                    'gdpri-reply-all'            => 'reply-all',
                    'gdpri-retweet'              => 'retweet',
                    'gdpri-rmb'                  => 'rmb',
                    'gdpri-road'                 => 'road',
                    'gdpri-rocket'               => 'rocket',
                    'gdpri-rotate-left'          => 'rotate-left',
                    'gdpri-rotate-right'         => 'rotate-right',
                    'gdpri-rouble'               => 'rouble',
                    'gdpri-rss'                  => 'rss',
                    'gdpri-rss-square'           => 'rss-square',
                    'gdpri-rub'                  => 'rub',
                    'gdpri-ruble'                => 'ruble',
                    'gdpri-rupee'                => 'rupee',
                    'gdpri-save'                 => 'save',
                    'gdpri-scissors'             => 'scissors',
                    'gdpri-search'               => 'search',
                    'gdpri-search-minus'         => 'search-minus',
                    'gdpri-search-plus'          => 'search-plus',
                    'gdpri-send'                 => 'send',
                    'gdpri-send-o'               => 'send-o',
                    'gdpri-share'                => 'share',
                    'gdpri-share-alt'            => 'share-alt',
                    'gdpri-share-alt-square'     => 'share-alt-square',
                    'gdpri-share-square'         => 'share-square',
                    'gdpri-share-square-o'       => 'share-square-o',
                    'gdpri-shield'               => 'shield',
                    'gdpri-shopping-cart'        => 'shopping-cart',
                    'gdpri-sign-in'              => 'sign-in',
                    'gdpri-sign-out'             => 'sign-out',
                    'gdpri-signal'               => 'signal',
                    'gdpri-sitemap'              => 'sitemap',
                    'gdpri-skype'                => 'skype',
                    'gdpri-slack'                => 'slack',
                    'gdpri-sliders'              => 'sliders',
                    'gdpri-smile-o'              => 'smile-o',
                    'gdpri-sort'                 => 'sort',
                    'gdpri-sort-alpha-asc'       => 'sort-alpha-asc',
                    'gdpri-sort-alpha-desc'      => 'sort-alpha-desc',
                    'gdpri-sort-amount-asc'      => 'sort-amount-asc',
                    'gdpri-sort-amount-desc'     => 'sort-amount-desc',
                    'gdpri-sort-asc'             => 'sort-asc',
                    'gdpri-sort-desc'            => 'sort-desc',
                    'gdpri-sort-down'            => 'sort-down',
                    'gdpri-sort-numeric-asc'     => 'sort-numeric-asc',
                    'gdpri-sort-numeric-desc'    => 'sort-numeric-desc',
                    'gdpri-sort-up'              => 'sort-up',
                    'gdpri-soundcloud'           => 'soundcloud',
                    'gdpri-space-shuttle'        => 'space-shuttle',
                    'gdpri-spinner'              => 'spinner',
                    'gdpri-spoon'                => 'spoon',
                    'gdpri-spotify'              => 'spotify',
                    'gdpri-square'               => 'square',
                    'gdpri-square-o'             => 'square-o',
                    'gdpri-stack-exchange'       => 'stack-exchange',
                    'gdpri-stack-overflow'       => 'stack-overflow',
                    'gdpri-star'                 => 'star',
                    'gdpri-star-half'            => 'star-half',
                    'gdpri-star-half-empty'      => 'star-half-empty',
                    'gdpri-star-half-full'       => 'star-half-full',
                    'gdpri-star-half-o'          => 'star-half-o',
                    'gdpri-star-o'               => 'star-o',
                    'gdpri-steam'                => 'steam',
                    'gdpri-steam-square'         => 'steam-square',
                    'gdpri-step-backward'        => 'step-backward',
                    'gdpri-step-forward'         => 'step-forward',
                    'gdpri-stethoscope'          => 'stethoscope',
                    'gdpri-stop'                 => 'stop',
                    'gdpri-strikethrough'        => 'strikethrough',
                    'gdpri-stumbleupon'          => 'stumbleupon',
                    'gdpri-stumbleupon-circle'   => 'stumbleupon-circle',
                    'gdpri-subscript'            => 'subscript',
                    'gdpri-suitcase'             => 'suitcase',
                    'gdpri-sun-o'                => 'sun-o',
                    'gdpri-superscript'          => 'superscript',
                    'gdpri-support'              => 'support',
                    'gdpri-table'                => 'table',
                    'gdpri-tablet'               => 'tablet',
                    'gdpri-tachometer'           => 'tachometer',
                    'gdpri-tag'                  => 'tag',
                    'gdpri-tags'                 => 'tags',
                    'gdpri-tasks'                => 'tasks',
                    'gdpri-taxi'                 => 'taxi',
                    'gdpri-tencent-weibo'        => 'tencent-weibo',
                    'gdpri-terminal'             => 'terminal',
                    'gdpri-text-height'          => 'text-height',
                    'gdpri-text-width'           => 'text-width',
                    'gdpri-th'                   => 'th',
                    'gdpri-th-large'             => 'th-large',
                    'gdpri-th-list'              => 'th-list',
                    'gdpri-thumb-tack'           => 'thumb-tack',
                    'gdpri-thumbs-down'          => 'thumbs-down',
                    'gdpri-thumbs-o-down'        => 'thumbs-o-down',
                    'gdpri-thumbs-o-up'          => 'thumbs-o-up',
                    'gdpri-thumbs-up'            => 'thumbs-up',
                    'gdpri-ticket'               => 'ticket',
                    'gdpri-times'                => 'times',
                    'gdpri-times-circle'         => 'times-circle',
                    'gdpri-times-circle-o'       => 'times-circle-o',
                    'gdpri-tint'                 => 'tint',
                    'gdpri-toggle-down'          => 'toggle-down',
                    'gdpri-toggle-left'          => 'toggle-left',
                    'gdpri-toggle-right'         => 'toggle-right',
                    'gdpri-toggle-up'            => 'toggle-up',
                    'gdpri-trash-o'              => 'trash-o',
                    'gdpri-tree'                 => 'tree',
                    'gdpri-trello'               => 'trello',
                    'gdpri-trophy'               => 'trophy',
                    'gdpri-truck'                => 'truck',
                    'gdpri-try'                  => 'try',
                    'gdpri-tumblr'               => 'tumblr',
                    'gdpri-tumblr-square'        => 'tumblr-square',
                    'gdpri-turkish-lira'         => 'turkish-lira',
                    'gdpri-twitter'              => 'twitter',
                    'gdpri-twitter-square'       => 'twitter-square',
                    'gdpri-umbrella'             => 'umbrella',
                    'gdpri-underline'            => 'underline',
                    'gdpri-undo'                 => 'undo',
                    'gdpri-university'           => 'university',
                    'gdpri-unlink'               => 'unlink',
                    'gdpri-unlock'               => 'unlock',
                    'gdpri-unlock-alt'           => 'unlock-alt',
                    'gdpri-unsorted'             => 'unsorted',
                    'gdpri-upload'               => 'upload',
                    'gdpri-usd'                  => 'usd',
                    'gdpri-user'                 => 'user',
                    'gdpri-user-md'              => 'user-md',
                    'gdpri-users'                => 'users',
                    'gdpri-video-camera'         => 'video-camera',
                    'gdpri-vimeo-square'         => 'vimeo-square',
                    'gdpri-vine'                 => 'vine',
                    'gdpri-vk'                   => 'vk',
                    'gdpri-volume-down'          => 'volume-down',
                    'gdpri-volume-off'           => 'volume-off',
                    'gdpri-volume-up'            => 'volume-up',
                    'gdpri-warning'              => 'warning',
                    'gdpri-wechat'               => 'wechat',
                    'gdpri-weibo'                => 'weibo',
                    'gdpri-weixin'               => 'weixin',
                    'gdpri-wheelchair'           => 'wheelchair',
                    'gdpri-windows'              => 'windows',
                    'gdpri-won'                  => 'won',
                    'gdpri-wordpress'            => 'wordpress',
                    'gdpri-wrench'               => 'wrench',
                    'gdpri-xing'                 => 'xing',
                    'gdpri-xing-square'          => 'xing-square',
                    'gdpri-yahoo'                => 'yahoo',
                    'gdpri-yen'                  => 'yen',
                    'gdpri-youtube'              => 'youtube',
                    'gdpri-youtube-play'         => 'youtube-play',
                    'gdpri-youtube-square'       => 'youtube-square',

                ],

            ];

            $selected_icon = \get_post_meta(\sanitize_key($_GET['post']), 'gdprc_selected_icon', true);

            // Compatibility script for backward conversion of FA- to GDPRI- icons
            $selected_icon = \preg_replace('~^fa-~i', 'gdpri-', $selected_icon);

            if (empty($selected_icon)) {
                $selected_icon = "gdpri-warning";
            }
            echo '<div class="gdprc_selected_icon"><i class="gdprc_selected_icon_preview gdpricons gdpri gdpri-2x '.$selected_icon.'"></i><input id="gdprc_selected_icon" name="gdprc_selected_icon" type="text" value="'.$selected_icon.'"></div>';
            echo '<div class="gdprc_gdpricons"><ul>';

            foreach ($icons['options'] as $icon => $value) {
                echo '<li><i class="gdpricons gdpri gdpri-2x '.$icon.'" gdpri-name="'.$icon.'"></i></li>';
            }

            echo "</ul></div>";
        }, 'gdprc_consent', 'side', 'high');
    }
}
