@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | License: GPLv3 |
12 | 12 | License URI: http://www.gnu.org/licenses/gpl-3.0.html |
13 | 13 | */ |
14 | -if (!defined('ABSPATH')) exit; |
|
14 | +if ( ! defined('ABSPATH')) exit; |
|
15 | 15 | |
16 | 16 | |
17 | 17 | //Define basic names |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | defined('CGSS_PATH') or define('CGSS_PATH', plugin_dir_path(__FILE__)); |
22 | 22 | defined('CGSS_FILE') or define('CGSS_FILE', plugin_basename(__FILE__)); |
23 | 23 | |
24 | -defined('CGSS_EXECUTE') or define('CGSS_EXECUTE', plugin_dir_path(__FILE__).'src/'); |
|
25 | -defined('CGSS_HELPER') or define('CGSS_HELPER', plugin_dir_path(__FILE__).'helper/'); |
|
26 | -defined('CGSS_TRANSLATE') or define('CGSS_TRANSLATE', plugin_basename( plugin_dir_path(__FILE__).'asset/ln/')); |
|
24 | +defined('CGSS_EXECUTE') or define('CGSS_EXECUTE', plugin_dir_path(__FILE__) . 'src/'); |
|
25 | +defined('CGSS_HELPER') or define('CGSS_HELPER', plugin_dir_path(__FILE__) . 'helper/'); |
|
26 | +defined('CGSS_TRANSLATE') or define('CGSS_TRANSLATE', plugin_basename(plugin_dir_path(__FILE__) . 'asset/ln/')); |
|
27 | 27 | |
28 | 28 | //change /wp-plugin-framework/ with your /plugin-name/ |
29 | -defined('CGSS_JS') or define('CGSS_JS', plugins_url().'/complete-google-seo-scan/asset/js/'); |
|
30 | -defined('CGSS_CSS') or define('CGSS_CSS', plugins_url().'/complete-google-seo-scan/asset/css/'); |
|
31 | -defined('CGSS_IMAGE') or define('CGSS_IMAGE', plugins_url().'/complete-google-seo-scan/asset/img/'); |
|
29 | +defined('CGSS_JS') or define('CGSS_JS', plugins_url() . '/complete-google-seo-scan/asset/js/'); |
|
30 | +defined('CGSS_CSS') or define('CGSS_CSS', plugins_url() . '/complete-google-seo-scan/asset/css/'); |
|
31 | +defined('CGSS_IMAGE') or define('CGSS_IMAGE', plugins_url() . '/complete-google-seo-scan/asset/img/'); |
|
32 | 32 | |
33 | 33 | |
34 | 34 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * The Plugin |
39 | 39 | */ |
40 | 40 | function cgss_build() { |
41 | - if ( class_exists( 'NirjharLo\\Cgss\\Loader' ) ) { |
|
41 | + if (class_exists('NirjharLo\\Cgss\\Loader')) { |
|
42 | 42 | return NirjharLo\Cgss\Loader::instance(); |
43 | 43 | } |
44 | 44 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace NirjharLo\Cgss\Lib; |
3 | 3 | |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined('ABSPATH')) exit; |
|
5 | 5 | |
6 | 6 | |
7 | 7 | use \WP_List_Table; |
@@ -14,24 +14,24 @@ discard block |
||
14 | 14 | * $Table->display(); |
15 | 15 | * |
16 | 16 | */ |
17 | -if ( ! class_exists( 'CGSS_TABLE' ) ) { |
|
17 | +if ( ! class_exists('CGSS_TABLE')) { |
|
18 | 18 | |
19 | 19 | final class Table extends WP_List_Table { |
20 | 20 | |
21 | 21 | |
22 | 22 | public function __construct() { |
23 | 23 | |
24 | - parent::__construct( [ |
|
25 | - 'singular' => __( 'Post', 'cgss' ), |
|
26 | - 'plural' => __( 'Posts', 'cgss' ), |
|
24 | + parent::__construct([ |
|
25 | + 'singular' => __('Post', 'cgss'), |
|
26 | + 'plural' => __('Posts', 'cgss'), |
|
27 | 27 | 'ajax' => false, |
28 | - ] ); |
|
28 | + ]); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | 33 | //fetch the data using custom named method function |
34 | - public static function get_posts( $per_page = 10, $page_number = 1 ) { |
|
34 | + public static function get_posts($per_page = 10, $page_number = 1) { |
|
35 | 35 | |
36 | 36 | global $wpdb; |
37 | 37 | |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | $sql .= " QUERIES WHERE post_status='publish' AND post_type='$page'"; |
43 | 43 | |
44 | 44 | //Set filters in the query using $_REQUEST |
45 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
46 | - $sql .= ' ORDER BY ' . esc_sql( $_REQUEST['orderby'] ); |
|
47 | - $sql .= ! empty( $_REQUEST['order'] ) ? ' ' . esc_sql( $_REQUEST['order'] ) : ' ASC'; |
|
45 | + if ( ! empty($_REQUEST['orderby'])) { |
|
46 | + $sql .= ' ORDER BY ' . esc_sql($_REQUEST['orderby']); |
|
47 | + $sql .= ! empty($_REQUEST['order']) ? ' ' . esc_sql($_REQUEST['order']) : ' ASC'; |
|
48 | 48 | } |
49 | 49 | $sql .= " LIMIT $per_page"; |
50 | - $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page; |
|
50 | + $sql .= ' OFFSET ' . ($page_number - 1) * $per_page; |
|
51 | 51 | |
52 | 52 | //get the data from database |
53 | - $result = $wpdb->get_results( $sql, 'ARRAY_A' ); |
|
53 | + $result = $wpdb->get_results($sql, 'ARRAY_A'); |
|
54 | 54 | |
55 | 55 | // FETCH POST META DATA AND MERGE IT WITH RESULTS |
56 | 56 | $result = SELF::get_post_meta_data($result); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | //If there is no data to show |
64 | 64 | public function no_items() { |
65 | 65 | |
66 | - _e( 'No Published Posts are available.', 'cgss' ); |
|
66 | + _e('No Published Posts are available.', 'cgss'); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -80,45 +80,45 @@ discard block |
||
80 | 80 | $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}posts"; |
81 | 81 | $sql .= " QUERIES WHERE post_status='publish' AND post_type='$page'"; |
82 | 82 | |
83 | - return $wpdb->get_var( $sql ); |
|
83 | + return $wpdb->get_var($sql); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
87 | 87 | |
88 | 88 | //Display columns content |
89 | - public function column_name( $item ) { |
|
89 | + public function column_name($item) { |
|
90 | 90 | |
91 | - $title = sprintf( '<strong>%s</strong>', $item['post_title'] ); |
|
91 | + $title = sprintf('<strong>%s</strong>', $item['post_title']); |
|
92 | 92 | |
93 | 93 | //Change the page instruction where you want to show it |
94 | 94 | $actions = array( |
95 | - 'scan' => sprintf( '<a href="?page='.$_GET['page'].'&scan='.$item['ID'].'" target="_blank">%s</a>', __( 'Scan', 'cgss' ) ), |
|
96 | - 'view' => sprintf( '<a href="'.get_permalink($item['ID']).'" target="_blank">%s</a>', __( 'View', 'cgss' ) ) |
|
95 | + 'scan' => sprintf('<a href="?page=' . $_GET['page'] . '&scan=' . $item['ID'] . '" target="_blank">%s</a>', __('Scan', 'cgss')), |
|
96 | + 'view' => sprintf('<a href="' . get_permalink($item['ID']) . '" target="_blank">%s</a>', __('View', 'cgss')) |
|
97 | 97 | ); |
98 | - return $title . $this->row_actions( $actions ); |
|
98 | + return $title . $this->row_actions($actions); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | |
102 | 102 | |
103 | 103 | //set coulmns name |
104 | - public function column_default( $item, $column_name ) { |
|
104 | + public function column_default($item, $column_name) { |
|
105 | 105 | |
106 | - switch ( $column_name ) { |
|
106 | + switch ($column_name) { |
|
107 | 107 | |
108 | 108 | case 'post_title': |
109 | 109 | //This is the first column |
110 | - return $this->column_name( $item ); |
|
110 | + return $this->column_name($item); |
|
111 | 111 | case 'focus': |
112 | 112 | case 'word': |
113 | 113 | case 'link': |
114 | 114 | case 'image': |
115 | 115 | case 'share': |
116 | - return $item[ $column_name ]; |
|
116 | + return $item[$column_name]; |
|
117 | 117 | case 'time': |
118 | - return $item[ $column_name ]; |
|
118 | + return $item[$column_name]; |
|
119 | 119 | default: |
120 | 120 | //Show the whole array for troubleshooting purposes |
121 | - return print_r( $item, true ); |
|
121 | + return print_r($item, true); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | public function get_columns() { |
129 | 129 | |
130 | 130 | $columns = array( |
131 | - 'post_title' => __( 'Post', 'cgss' ), |
|
132 | - 'focus' => __( 'Focus', 'cgss' ), |
|
133 | - 'word' => __( 'Words', 'cgss' ), |
|
134 | - 'link' => __( 'Links', 'cgss' ), |
|
135 | - 'image' => __( 'Images', 'cgss' ), |
|
136 | - 'share' => __( 'Shares', 'cgss' ), |
|
137 | - 'time' => __( 'Time(s)', 'cgss' ), |
|
131 | + 'post_title' => __('Post', 'cgss'), |
|
132 | + 'focus' => __('Focus', 'cgss'), |
|
133 | + 'word' => __('Words', 'cgss'), |
|
134 | + 'link' => __('Links', 'cgss'), |
|
135 | + 'image' => __('Images', 'cgss'), |
|
136 | + 'share' => __('Shares', 'cgss'), |
|
137 | + 'time' => __('Time(s)', 'cgss'), |
|
138 | 138 | |
139 | 139 | ); |
140 | 140 | return $columns; |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | public function get_sortable_columns() { |
147 | 147 | |
148 | 148 | $sortable_columns = array( |
149 | - 'post_title' => array( 'post_title', true ), |
|
149 | + 'post_title' => array('post_title', true), |
|
150 | 150 | ); |
151 | 151 | return $sortable_columns; |
152 | 152 | } |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | $this->_column_headers = $this->get_column_info(); |
160 | 160 | |
161 | 161 | /** Process bulk action */ |
162 | - $per_page = $this->get_items_per_page( 'post_per_page', 5 ); |
|
162 | + $per_page = $this->get_items_per_page('post_per_page', 5); |
|
163 | 163 | $current_page = $this->get_pagenum(); |
164 | 164 | $total_items = self::record_count(); |
165 | - $this->set_pagination_args( array( |
|
165 | + $this->set_pagination_args(array( |
|
166 | 166 | 'total_items' => $total_items, |
167 | 167 | 'per_page' => $per_page, |
168 | - ) ); |
|
168 | + )); |
|
169 | 169 | |
170 | - $this->items = self::get_posts( $per_page, $current_page ); |
|
170 | + $this->items = self::get_posts($per_page, $current_page); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | |
@@ -181,18 +181,18 @@ discard block |
||
181 | 181 | 'text' => array( |
182 | 182 | 'count' => '--', |
183 | 183 | 'top_key' => '--', |
184 | - 'links' => array( 'count' => '--' ), |
|
184 | + 'links' => array('count' => '--'), |
|
185 | 185 | ), |
186 | 186 | 'design' => array( |
187 | - 'image' => array( 'count' => '--' ) |
|
187 | + 'image' => array('count' => '--') |
|
188 | 188 | ), |
189 | 189 | 'social' => '--', |
190 | - 'speed' => array( 'down_time' => '--' ), |
|
190 | + 'speed' => array('down_time' => '--'), |
|
191 | 191 | ); |
192 | 192 | |
193 | 193 | $metas = array(); |
194 | 194 | foreach ($IDs as $post_id) { |
195 | - $meta = get_post_meta( $post_id, 'cgss_scan_result', true ); |
|
195 | + $meta = get_post_meta($post_id, 'cgss_scan_result', true); |
|
196 | 196 | $metas[] = is_array($meta) ? $meta : $empty_metas; |
197 | 197 | } |
198 | 198 | $text = array_column($metas, 'text'); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | /** |
5 | 5 | * Add scripts to the plugin. CSS and JS. |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
7 | +if ( ! defined('ABSPATH')) exit; |
|
8 | 8 | |
9 | 9 | |
10 | 10 | final class Script { |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | public function __construct() { |
14 | 14 | |
15 | - add_action( 'admin_head', array( $this, 'data_table_css' ) ); |
|
15 | + add_action('admin_head', array($this, 'data_table_css')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace NirjharLo\Cgss\Lib\Analysis\Lib; |
3 | 3 | |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined('ABSPATH')) exit; |
|
5 | 5 | |
6 | 6 | |
7 | 7 | /** |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | $compress_num = 0; |
28 | 28 | $compress_size = 0; |
29 | 29 | |
30 | - if ( $this->js_url ) { |
|
30 | + if ($this->js_url) { |
|
31 | 31 | |
32 | 32 | $num = count($this->js_url); |
33 | 33 | |
34 | 34 | //get files and check their bodies |
35 | - foreach ( $this->js_url as $val ) { |
|
36 | - $body = @file_get_contents( $val, FILE_USE_INCLUDE_PATH ); |
|
35 | + foreach ($this->js_url as $val) { |
|
36 | + $body = @file_get_contents($val, FILE_USE_INCLUDE_PATH); |
|
37 | 37 | if ($body) { |
38 | - $pre_size = mb_strlen( $body, '8bit' ); |
|
39 | - $size += round( ( $pre_size / 1024 ), 0 ); |
|
40 | - $pure_body = filter_var( $body, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW ); |
|
41 | - $pure_size = mb_strlen( $pure_body, '8bit' ); |
|
42 | - $percent_comp = 1 - ( $pure_size / $pre_size ); |
|
43 | - if ( $percent_comp > 0.05 ) { |
|
38 | + $pre_size = mb_strlen($body, '8bit'); |
|
39 | + $size += round(($pre_size / 1024), 0); |
|
40 | + $pure_body = filter_var($body, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
41 | + $pure_size = mb_strlen($pure_body, '8bit'); |
|
42 | + $percent_comp = 1 - ($pure_size / $pre_size); |
|
43 | + if ($percent_comp > 0.05) { |
|
44 | 44 | $compress_num += 1; |
45 | - $compress_size += round( ( ( $pre_size - $pure_size ) / 1024 ), 0 ); |
|
45 | + $compress_size += round((($pre_size - $pure_size) / 1024), 0); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | } |
@@ -66,26 +66,26 @@ discard block |
||
66 | 66 | $compress_num = 0; |
67 | 67 | $compress_size = 0; |
68 | 68 | |
69 | - if ( $this->css_url ) { |
|
69 | + if ($this->css_url) { |
|
70 | 70 | |
71 | 71 | $num = count($this->css_url); |
72 | 72 | |
73 | 73 | //get files and check their bodies |
74 | - foreach ( $this->css_url as $val ) { |
|
75 | - $body = @file_get_contents( $val, FILE_USE_INCLUDE_PATH ); |
|
74 | + foreach ($this->css_url as $val) { |
|
75 | + $body = @file_get_contents($val, FILE_USE_INCLUDE_PATH); |
|
76 | 76 | if ($body) { |
77 | - $pre_size = mb_strlen( $body, '8bit' ); |
|
78 | - $size += round( ( $pre_size / 1024 ), 0 ); |
|
79 | - if ( strpos( $val, '.css' ) !== false ) { |
|
80 | - $import += substr_count( $body, '@import' ); |
|
81 | - $media += substr_count( $body, '@media' ); |
|
77 | + $pre_size = mb_strlen($body, '8bit'); |
|
78 | + $size += round(($pre_size / 1024), 0); |
|
79 | + if (strpos($val, '.css') !== false) { |
|
80 | + $import += substr_count($body, '@import'); |
|
81 | + $media += substr_count($body, '@media'); |
|
82 | 82 | } |
83 | - $pure_body = filter_var( $body, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW ); |
|
84 | - $pure_size = mb_strlen( $pure_body, '8bit' ); |
|
85 | - $percent_comp = 1 - ( $pure_size / $pre_size ); |
|
86 | - if ( $percent_comp > 0.05 ) { |
|
83 | + $pure_body = filter_var($body, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
84 | + $pure_size = mb_strlen($pure_body, '8bit'); |
|
85 | + $percent_comp = 1 - ($pure_size / $pre_size); |
|
86 | + if ($percent_comp > 0.05) { |
|
87 | 87 | $compress_num += 1; |
88 | - $compress_size += round( ( ( $pre_size - $pure_size ) / 1024 ), 0 ); |
|
88 | + $compress_size += round((($pre_size - $pure_size) / 1024), 0); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace NirjharLo\Cgss\Lib\Analysis\Lib; |
4 | 4 | |
5 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
5 | +if ( ! defined('ABSPATH')) exit; |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * An object to extract most used pharases in an array of phrases, containing one or more words. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $four = $this->fetch(4); |
29 | 29 | $five = $this->fetch(5); |
30 | 30 | $six = $this->fetch(6); |
31 | - $keys = array_merge( $six, $five, $four, $three, $two, $one ); |
|
31 | + $keys = array_merge($six, $five, $four, $three, $two, $one); |
|
32 | 32 | return $keys; |
33 | 33 | } |
34 | 34 | |
@@ -38,45 +38,45 @@ discard block |
||
38 | 38 | $one_arr = $this->fetch(1); |
39 | 39 | $stop = $this->stop(); |
40 | 40 | $output = array(); |
41 | - foreach ( $one_arr as $val => $key ) { |
|
42 | - if ( strlen( $val ) > 3 and ! in_array( $val, $stop ) ) { |
|
41 | + foreach ($one_arr as $val => $key) { |
|
42 | + if (strlen($val) > 3 and ! in_array($val, $stop)) { |
|
43 | 43 | $output[$val] = $key; |
44 | 44 | } |
45 | 45 | } |
46 | - return array_slice( $output, 0, 10 ); |
|
46 | + return array_slice($output, 0, 10); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | //generate individual words from text content |
50 | - public function fetch( $n ) { |
|
50 | + public function fetch($n) { |
|
51 | 51 | |
52 | 52 | //compare text and words to find keyword |
53 | 53 | $keys = array(); |
54 | - $phrs = $this->prepare( $n ); |
|
54 | + $phrs = $this->prepare($n); |
|
55 | 55 | $phrs_count = count($phrs); |
56 | - foreach( $phrs as $val ) { |
|
57 | - $key_num = substr_count( $this->text, $val ); |
|
58 | - $key_per = round( ( ( ( $key_num * $n ) / $phrs_count ) * 100 ), 3 ); |
|
59 | - if ( $key_num > 1 and $key_per > 0.2 and ! isset( $keys[$val] ) ) { |
|
56 | + foreach ($phrs as $val) { |
|
57 | + $key_num = substr_count($this->text, $val); |
|
58 | + $key_per = round(((($key_num * $n) / $phrs_count) * 100), 3); |
|
59 | + if ($key_num > 1 and $key_per > 0.2 and ! isset($keys[$val])) { |
|
60 | 60 | $keys[$val] = $key_per; |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | //arrange them to select top final 3 keyword |
65 | - if ( is_array( $keys ) ) { |
|
66 | - arsort( $keys ); |
|
67 | - if ( $n != 1 ) { |
|
65 | + if (is_array($keys)) { |
|
66 | + arsort($keys); |
|
67 | + if ($n != 1) { |
|
68 | 68 | |
69 | 69 | //remove keys without much significance |
70 | 70 | $del_keys = array(); |
71 | - foreach ( $keys as $val => $key ) { |
|
72 | - $key_size = strlen( implode( '', explode( ' ', $val ) ) ) / 2; |
|
73 | - if ( $key_size <= $n ) { |
|
71 | + foreach ($keys as $val => $key) { |
|
72 | + $key_size = strlen(implode('', explode(' ', $val))) / 2; |
|
73 | + if ($key_size <= $n) { |
|
74 | 74 | $del_keys[] = $val; |
75 | 75 | } |
76 | 76 | } |
77 | - $new_keys = array_diff( $keys, $del_keys ); |
|
77 | + $new_keys = array_diff($keys, $del_keys); |
|
78 | 78 | |
79 | - $key_top = array_slice( $new_keys, 0, 3 ); |
|
79 | + $key_top = array_slice($new_keys, 0, 3); |
|
80 | 80 | } else { |
81 | 81 | $key_top = $keys; |
82 | 82 | } |
@@ -85,26 +85,26 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | //generate individual words from text content |
88 | - public function prepare( $n ) { |
|
88 | + public function prepare($n) { |
|
89 | 89 | $i = 0; |
90 | 90 | $part = array(); |
91 | 91 | $w_input = $this->words; |
92 | - for( $i = 0; $i < $n; $i++ ) { |
|
92 | + for ($i = 0; $i < $n; $i++) { |
|
93 | 93 | |
94 | 94 | //create an array of words of pharses as sub-arrays |
95 | - $pieces = array_chunk( $w_input, $n ); |
|
96 | - $last_one = array_pop( $pieces ); |
|
97 | - if ( is_array( $last_one ) and count( $last_one ) != $i ) { |
|
95 | + $pieces = array_chunk($w_input, $n); |
|
96 | + $last_one = array_pop($pieces); |
|
97 | + if (is_array($last_one) and count($last_one) != $i) { |
|
98 | 98 | unset($pieces[count($pieces) - 1]); |
99 | 99 | } |
100 | 100 | |
101 | 101 | //create phrase out of those sub array |
102 | - foreach( $pieces as $val ) { |
|
103 | - $part[] = implode( ' ', $val ); |
|
102 | + foreach ($pieces as $val) { |
|
103 | + $part[] = implode(' ', $val); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | //Offset input words first value to create more unique words |
107 | - $del_w_input = array_diff( $w_input, array( $w_input[0] ) ); |
|
107 | + $del_w_input = array_diff($w_input, array($w_input[0])); |
|
108 | 108 | $w_input = array_values($del_w_input); |
109 | 109 | } |
110 | 110 | return $part; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | //array of stop words |
114 | 114 | public function stop() { |
115 | - return array( 'from', 'that', 'this', 'what', 'when', 'where', 'have', 'they', 'just', 'your', 'most', 'their', 'some', 'then', 'there', 'them', 'make', 'ever', 'never', 'enough', 'should', 'would', 'could', 'also', 'such', 'shall', 'will', 'with' ); |
|
115 | + return array('from', 'that', 'this', 'what', 'when', 'where', 'have', 'they', 'just', 'your', 'most', 'their', 'some', 'then', 'there', 'them', 'make', 'ever', 'never', 'enough', 'should', 'would', 'could', 'also', 'such', 'shall', 'will', 'with'); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | ?> |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace NirjharLo\Cgss\Lib\Analysis\Lib; |
3 | 3 | |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined('ABSPATH')) exit; |
|
5 | 5 | |
6 | 6 | |
7 | 7 | /** |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | public function cache() { |
22 | 22 | |
23 | 23 | $cache = 0; |
24 | - if ( is_array( $this->header ) ) { |
|
25 | - if ( array_key_exists( "Cache-Control", $this->header ) ) { |
|
24 | + if (is_array($this->header)) { |
|
25 | + if (array_key_exists("Cache-Control", $this->header)) { |
|
26 | 26 | $cache_val = $this->header["Cache-Control"]; |
27 | - if ( $cache_val ) { |
|
27 | + if ($cache_val) { |
|
28 | 28 | $cache = 1; |
29 | 29 | } |
30 | 30 | } |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | public function if_mod() { |
38 | 38 | |
39 | 39 | $if_mod = 0; |
40 | - if ( is_array( $this->header ) ) { |
|
41 | - if ( array_key_exists( "Last-Modified", $this->header ) ) { |
|
40 | + if (is_array($this->header)) { |
|
41 | + if (array_key_exists("Last-Modified", $this->header)) { |
|
42 | 42 | $if_mod = 1; |
43 | 43 | } |
44 | 44 | } |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | public function alive() { |
51 | 51 | |
52 | 52 | $alive = 0; |
53 | - if ( is_array( $this->header ) ) { |
|
54 | - if ( array_key_exists( "Connection", $this->header ) ) { |
|
53 | + if (is_array($this->header)) { |
|
54 | + if (array_key_exists("Connection", $this->header)) { |
|
55 | 55 | $connection = $this->header["Connection"]; |
56 | - if ( $connection == "Keep-Alive" ) { |
|
56 | + if ($connection == "Keep-Alive") { |
|
57 | 57 | $alive = 1; |
58 | 58 | } |
59 | 59 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | $gzip = 0; |
69 | 69 | $encode = $_SERVER['HTTP_ACCEPT_ENCODING']; |
70 | - if ( substr( $encode, 0, 4 ) == 'gzip' ) { |
|
70 | + if (substr($encode, 0, 4) == 'gzip') { |
|
71 | 71 | $gzip = 1; |
72 | 72 | } |
73 | 73 | return $gzip; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | //Get the IP address |
78 | 78 | public function IP() { |
79 | 79 | |
80 | - $IP = gethostbyname( $this->domain ); |
|
80 | + $IP = gethostbyname($this->domain); |
|
81 | 81 | return $IP; |
82 | 82 | } |
83 | 83 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace NirjharLo\Cgss\Lib\Analysis\Lib; |
3 | 3 | |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined('ABSPATH')) exit; |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * |
@@ -36,37 +36,37 @@ discard block |
||
36 | 36 | //Fetch and scan tag values and return details as an array. |
37 | 37 | public function tag() { |
38 | 38 | |
39 | - $tag_obj = $this->dom->getElementsByTagName( $this->tag ); |
|
39 | + $tag_obj = $this->dom->getElementsByTagName($this->tag); |
|
40 | 40 | $num = 0; |
41 | 41 | $val = array(); |
42 | 42 | $specify = $this->specify; |
43 | - foreach ( $tag_obj as $obj ) { |
|
44 | - if ( $specify ) { |
|
45 | - if ( $specify["att"] && $specify["val"] ) { |
|
43 | + foreach ($tag_obj as $obj) { |
|
44 | + if ($specify) { |
|
45 | + if ($specify["att"] && $specify["val"]) { |
|
46 | 46 | |
47 | 47 | //individual_object->function_for_attribute |
48 | - $get_att = $this->get_att( $obj, $specify["att"] ); |
|
49 | - $get_val = $this->get_att( $obj, $specify["get_att"] ); |
|
50 | - if ( strtolower( $get_att ) == $specify["val"] and $get_val ) { |
|
48 | + $get_att = $this->get_att($obj, $specify["att"]); |
|
49 | + $get_val = $this->get_att($obj, $specify["get_att"]); |
|
50 | + if (strtolower($get_att) == $specify["val"] and $get_val) { |
|
51 | 51 | $val[] = $get_val; |
52 | 52 | } |
53 | 53 | } else { |
54 | - $get_val = $this->get_att( $obj, $specify["get_att"] ); |
|
55 | - if ( $get_val ) { |
|
54 | + $get_val = $this->get_att($obj, $specify["get_att"]); |
|
55 | + if ($get_val) { |
|
56 | 56 | $val[] = $get_val; |
57 | 57 | } |
58 | 58 | } |
59 | 59 | } else { |
60 | 60 | |
61 | 61 | //whole_object->individual_object |
62 | - $tag_val = $tag_obj->item( $num ); |
|
62 | + $tag_val = $tag_obj->item($num); |
|
63 | 63 | $val[] = $tag_val->nodeValue; |
64 | 64 | } |
65 | 65 | $num = $num + 1; |
66 | 66 | } |
67 | 67 | |
68 | 68 | //Format output result for easy usage |
69 | - if ( count( $val ) != 0 ) { |
|
69 | + if (count($val) != 0) { |
|
70 | 70 | return $val; |
71 | 71 | } else { |
72 | 72 | return false; |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | |
78 | 78 | // Fetch multiple attributes. |
79 | 79 | public function atts() { |
80 | - if ( $this->atts ) { |
|
81 | - $tag_obj = $this->dom->getElementsByTagName( $this->tag ); |
|
80 | + if ($this->atts) { |
|
81 | + $tag_obj = $this->dom->getElementsByTagName($this->tag); |
|
82 | 82 | $val = array(); |
83 | - foreach( $this->atts as $key ) { |
|
83 | + foreach ($this->atts as $key) { |
|
84 | 84 | $fetch = array(); |
85 | - foreach( $tag_obj as $obj ) { |
|
86 | - $fetch[] = $this->get_att( $obj, $key ); |
|
85 | + foreach ($tag_obj as $obj) { |
|
86 | + $fetch[] = $this->get_att($obj, $key); |
|
87 | 87 | } |
88 | 88 | $val[$key] = $fetch; |
89 | 89 | } |
@@ -96,15 +96,15 @@ discard block |
||
96 | 96 | |
97 | 97 | |
98 | 98 | // Fetch single attributes. |
99 | - public function get_att( $obj, $val ) { |
|
99 | + public function get_att($obj, $val) { |
|
100 | 100 | |
101 | 101 | $data = false; |
102 | - $data = $obj->getAttribute( strtolower( $val ) ); |
|
103 | - if ( ! $data ) { |
|
104 | - $data = $obj->getAttribute( ucfirst( $val ) ); |
|
102 | + $data = $obj->getAttribute(strtolower($val)); |
|
103 | + if ( ! $data) { |
|
104 | + $data = $obj->getAttribute(ucfirst($val)); |
|
105 | 105 | } |
106 | - if ( ! $data ) { |
|
107 | - $data = $obj->getAttribute( strtoupper( $val ) ); |
|
106 | + if ( ! $data) { |
|
107 | + $data = $obj->getAttribute(strtoupper($val)); |
|
108 | 108 | } |
109 | 109 | return $data; |
110 | 110 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace NirjharLo\Cgss\Lib\Analysis\Lib; |
3 | 3 | |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined('ABSPATH')) exit; |
|
5 | 5 | |
6 | 6 | |
7 | 7 | use \DomXPath; |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | public function words() { |
34 | 34 | |
35 | 35 | //get word counts from text string. Here I use 2 loops to check for voids and characters. |
36 | - $text = str_replace( array( '.', ',', ':', '\'', '"', ')', '(', ']', '[', '}', '{', ';', '+', '-', '_', '*', '&', '^', '%', '$', '#', '@', '!', '~', '?', '>', '<', '/', '\\', '|' ), ' ' , $this->text ); |
|
37 | - $pure_text = filter_var( $text, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW ); |
|
36 | + $text = str_replace(array('.', ',', ':', '\'', '"', ')', '(', ']', '[', '}', '{', ';', '+', '-', '_', '*', '&', '^', '%', '$', '#', '@', '!', '~', '?', '>', '<', '/', '\\', '|'), ' ', $this->text); |
|
37 | + $pure_text = filter_var($text, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
38 | 38 | |
39 | 39 | //after formating text, explode the string into words and remove empty elements. |
40 | - $text_string = explode( ' ', $pure_text ); |
|
40 | + $text_string = explode(' ', $pure_text); |
|
41 | 41 | $words = array(); |
42 | - foreach ( $text_string as $key ) { |
|
43 | - if ( $key ) { |
|
44 | - $words[] = trim( $key ); |
|
42 | + foreach ($text_string as $key) { |
|
43 | + if ($key) { |
|
44 | + $words[] = trim($key); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | return $words; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function text() { |
59 | 59 | |
60 | 60 | $xpath = $this->xpath; |
61 | - return preg_replace( '/[ \n]+/', ' ', preg_replace( '/[ \t]+/', ' ', preg_replace( '/\s*$^\s*/m', ' ', $xpath['content'] ) ) ); |
|
61 | + return preg_replace('/[ \n]+/', ' ', preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', ' ', $xpath['content']))); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | //get total text content from xpath |
@@ -71,38 +71,38 @@ discard block |
||
71 | 71 | public function xpath() { |
72 | 72 | |
73 | 73 | //generate whole html |
74 | - $xpath = new DomXPath( $this->dom ); |
|
74 | + $xpath = new DomXPath($this->dom); |
|
75 | 75 | |
76 | 76 | //Get html size |
77 | 77 | $html_size = $this->body_size; |
78 | 78 | |
79 | 79 | //make it ready to get body xpath for text. |
80 | - foreach ( $xpath->query( '//script' ) as $key ) { |
|
81 | - $key->parentNode->removeChild( $key ); |
|
80 | + foreach ($xpath->query('//script') as $key) { |
|
81 | + $key->parentNode->removeChild($key); |
|
82 | 82 | } |
83 | - foreach ( $xpath->query( '//style' ) as $key ) { |
|
84 | - $key->parentNode->removeChild( $key ); |
|
83 | + foreach ($xpath->query('//style') as $key) { |
|
84 | + $key->parentNode->removeChild($key); |
|
85 | 85 | } |
86 | - $all_text = $xpath->query( '//body[text()]' ); |
|
86 | + $all_text = $xpath->query('//body[text()]'); |
|
87 | 87 | |
88 | 88 | //generate whole text |
89 | 89 | $all_text_target = $all_text->item(0); |
90 | - if ( $all_text_target ) { |
|
91 | - $only_text = strtolower( trim( $all_text_target->nodeValue ) ); |
|
90 | + if ($all_text_target) { |
|
91 | + $only_text = strtolower(trim($all_text_target->nodeValue)); |
|
92 | 92 | } else { |
93 | 93 | $only_text = ''; |
94 | 94 | } |
95 | 95 | |
96 | 96 | //get text size |
97 | - $text_size = mb_strlen( $only_text, '8bit' ); |
|
97 | + $text_size = mb_strlen($only_text, '8bit'); |
|
98 | 98 | |
99 | 99 | //get html to text ratio |
100 | - $ht_ratio = round( ( $text_size / $html_size ) * 100, 1 ); |
|
100 | + $ht_ratio = round(($text_size / $html_size) * 100, 1); |
|
101 | 101 | |
102 | 102 | return array( |
103 | 103 | 'content' => $only_text, |
104 | 104 | 'ratio' => $ht_ratio, |
105 | - 'size' => round( ( $text_size / 1024 ), 1 ), |
|
105 | + 'size' => round(($text_size / 1024), 1), |
|
106 | 106 | ); |
107 | 107 | } |
108 | 108 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace NirjharLo\Cgss\Lib\Analysis\Lib; |
3 | 3 | |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined('ABSPATH')) exit; |
|
5 | 5 | |
6 | 6 | |
7 | 7 | /** |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | public function fb() { |
21 | 21 | |
22 | 22 | $share = false; |
23 | - $fb_data = @file_get_contents( 'http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=' . $this->url ); |
|
24 | - if ( ! empty( $fb_data ) ) { |
|
25 | - $fb_shares = json_decode( $fb_data, true ); |
|
26 | - if ( array_key_exists ( 0, $fb_shares ) ) { |
|
23 | + $fb_data = @file_get_contents('http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=' . $this->url); |
|
24 | + if ( ! empty($fb_data)) { |
|
25 | + $fb_shares = json_decode($fb_data, true); |
|
26 | + if (array_key_exists(0, $fb_shares)) { |
|
27 | 27 | $fb_shares_act = $fb_shares[0]; |
28 | - if ( is_array( $fb_shares_act ) and array_key_exists ( 'share_count', $fb_shares_act ) and array_key_exists ( 'like_count', $fb_shares_act ) ) { |
|
28 | + if (is_array($fb_shares_act) and array_key_exists('share_count', $fb_shares_act) and array_key_exists('like_count', $fb_shares_act)) { |
|
29 | 29 | $share = array( |
30 | 30 | 'share' => $fb_shares_act['share_count'], |
31 | 31 | 'like' => $fb_shares_act['like_count'], |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
36 | - if (!$share) { |
|
36 | + if ( ! $share) { |
|
37 | 37 | $share = 0; |
38 | 38 | } |
39 | 39 | return $share; |