PluginProbe ʕ •ᴥ•ʔ
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) / 3.5.0
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) v3.5.0
3.5.1 3.5.0 3.4.2 trunk 1.0.1 1.0.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.3.9.1 3.4.0 3.4.1
cookie-law-info / legacy / admin / modules / cli-policy-generator / cli-policy-generator.php
cookie-law-info / legacy / admin / modules / cli-policy-generator Last commit date
assets 2 weeks ago classes 2 weeks ago data 2 weeks ago views 2 weeks ago cli-policy-generator.php 2 weeks ago
cli-policy-generator.php
179 lines
1 <?php
2 /**
3 * Policy generator
4 *
5 * @link http://cookielawinfo.com/
6 * @since 1.7.4
7 */
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11 require plugin_dir_path( __FILE__ ) . 'classes/class-policy-generator-ajax.php';
12 require plugin_dir_path( __FILE__ ) . 'classes/class-preview-page.php';
13 class Cookie_Law_Info_Cli_Policy_Generator {
14
15 public $plugin_name;
16
17 public static $policy_pageid = 'cli_pg_policy_page_id';
18 public function __construct() {
19 add_action( 'admin_menu', array( $this, 'add_admin_pages' ) );
20 add_filter( 'display_post_states', array( $this, 'add_display_post_states' ), 10, 2 );
21 }
22
23 /**
24 * Add a post display state for Cookie Policy page in the page list table.
25 *
26 * @since 1.7.4
27 **/
28 public function add_display_post_states( $post_states, $post ) {
29 if ( $post->ID == $this->get_cookie_policy_pageid() ) {
30 $post_states['page_for_cookie_policy'] = 'Cookie Policy Page';
31 }
32 return $post_states;
33 }
34
35 private static function gen_page_html( $content_data_arr = array(), $render_shortcode = 1 ) {
36 $html = '';
37 foreach ( $content_data_arr as $key => $value ) {
38 $html .= '<h3>' . $value['hd'] . '</h3>';
39 $post_content = ( isset( $value['content'] ) ? sanitize_textarea_field( $value['content'] ) : '' );
40 $html .= '<div>' . ( $render_shortcode == 1 ? do_shortcode( stripslashes( $post_content ) ) : stripslashes( $post_content ) ) . '</div>';
41 }
42 return $html;
43 }
44
45 public static function get_page_content() {
46 $content_val = get_option( 'cli_pg_content_data' );
47 $html = isset( $content_val ) ? $content_val : '';
48 return $html;
49 }
50
51 /**
52 * Generating content for page from session/post
53 *
54 * @since 1.7.4
55 * @return string
56 */
57 public static function generate_page_content( $powered_by, $content_data_post_arr = array(), $render_shortcode = 1 ) {
58 $html = '<div class="cli_pg_page_container">';
59 $html .= self::gen_page_html( $content_data_post_arr, $render_shortcode );
60 $html .= ( $powered_by == 1 ? '[webtoffee_powered_by]' : '' ) . '</div>';
61 return $html;
62 }
63
64 /**
65 * Get policy page id from option table
66 *
67 * @since 1.7.4
68 * @return int
69 */
70 public static function get_cookie_policy_pageid() {
71 $pageid = get_option( self::$policy_pageid );
72 if ( $pageid === false ) {
73 return 0;
74 } else {
75 return $pageid;
76 }
77 }
78
79 /**
80 * Update policy page id
81 *
82 * @since 1.7.4
83 */
84 public static function set_cookie_policy_pageid( $pageid ) {
85 update_option( self::$policy_pageid, $pageid );
86 }
87
88
89 /**
90 * Add administration menus
91 *
92 * @since 1.7.4
93 **/
94 public function add_admin_pages() {
95 add_submenu_page(
96 'edit.php?post_type=' . CLI_POST_TYPE,
97 __( 'Policy generator', 'cookie-law-info' ),
98 __( 'Policy generator', 'cookie-law-info' ),
99 'manage_options',
100 'cookie-law-info-policy-generator',
101 array( $this, 'policy_generator_page' )
102 );
103 }
104
105 /*
106 *
107 * Policy generator page (Admin page)
108 *
109 * @since 1.7.4
110 **/
111 public function policy_generator_page() {
112 add_editor_style( plugin_dir_url( __FILE__ ) . 'assets/css/editor-style.css' );
113 wp_enqueue_script( 'cli_policy_generator', plugin_dir_url( __FILE__ ) . 'assets/js/cli-policy-generator-admin.js', array( 'jquery' ), CLI_VERSION, false );
114 wp_enqueue_script( $this->plugin_name );
115 $params = array(
116 'nonces' => array(
117 'cli_policy_generator' => wp_create_nonce( 'cli_policy_generator' ),
118 ),
119 'ajax_url' => admin_url( 'admin-ajax.php' ),
120 'page_id' => '',
121 'labels' => array(
122 'error' => __( 'Error', 'cookie-law-info' ),
123 'success' => __( 'Success', 'cookie-law-info' ),
124 ),
125 );
126 wp_localize_script( 'cli_policy_generator', 'cli_policy_generator', $params );
127 $default_data = $this->process_default_data();
128 $preview_url = home_url() . '/cli-policy-preview/';
129 include plugin_dir_path( __FILE__ ) . 'views/policy-generator.php';
130 }
131
132 /*
133 *
134 * Process default data, read template file
135 * @since 1.7.4
136 **/
137 private function process_default_data() {
138 $data_path = plugin_dir_path( __FILE__ ) . 'data/';
139 include $data_path . 'data.policy-generator.php';
140 $out = array();
141 if ( $cli_pg_default_data ) {
142 foreach ( $cli_pg_default_data as $data ) {
143 $temp = $data;
144 // reading template file
145 if ( $data['body'] == '' && $data['body_file'] != '' && file_exists( $data_path . $data['body_file'] ) ) {
146 ob_start();
147 include $data_path . $data['body_file'];
148 $temp['body'] = $this->process_data( ob_get_clean() );
149 }
150 $out[] = $temp;
151 }
152 }
153 return $out;
154 }
155
156 /*
157 *
158 * Process default data, read template file
159 * @since 1.7.4
160 **/
161 private function process_data( $txt ) {
162 $home_url = home_url();
163 $home_domain = parse_url( $home_url, PHP_URL_HOST ); // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
164 $txt = str_replace(
165 array(
166 '{{site_url}}',
167 ),
168 array(
169 '<a href="' . $home_url . '">' . $home_domain . '</a>',
170 ),
171 $txt
172 );
173 // $txt=do_shortcode($txt);
174 return $txt;
175 }
176 }
177 $cli_pg = new Cookie_Law_Info_Cli_Policy_Generator();
178 $cli_pg->plugin_name = $this->plugin_name;
179