@@ -79,29 +79,29 @@ |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
| 82 | - public function insert_prelim_data() { |
|
| 83 | - |
|
| 84 | - $model = new InsightModel(); |
|
| 85 | - |
|
| 86 | - if ($model->count() === 0) { |
|
| 87 | - |
|
| 88 | - $init_insight = array( |
|
| 89 | - __('Score','cgss'), |
|
| 90 | - __('Snippet','cgss'), |
|
| 91 | - __('Text','cgss'), |
|
| 92 | - __('Links','cgss'), |
|
| 93 | - __('Keywords','cgss'), |
|
| 94 | - __('Images','cgss'), |
|
| 95 | - __('Responsive','cgss'), |
|
| 96 | - __('Speed','cgss'), |
|
| 97 | - __('Social','cgss') |
|
| 98 | - ); |
|
| 99 | - $no_data = __( 'No scan reports are available yet', 'cgss' ); |
|
| 100 | - foreach ($init_insight as $key => $value) { |
|
| 101 | - $model->insert($value, $no_data, $key + 1); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 82 | + public function insert_prelim_data() { |
|
| 83 | + |
|
| 84 | + $model = new InsightModel(); |
|
| 85 | + |
|
| 86 | + if ($model->count() === 0) { |
|
| 87 | + |
|
| 88 | + $init_insight = array( |
|
| 89 | + __('Score','cgss'), |
|
| 90 | + __('Snippet','cgss'), |
|
| 91 | + __('Text','cgss'), |
|
| 92 | + __('Links','cgss'), |
|
| 93 | + __('Keywords','cgss'), |
|
| 94 | + __('Images','cgss'), |
|
| 95 | + __('Responsive','cgss'), |
|
| 96 | + __('Speed','cgss'), |
|
| 97 | + __('Social','cgss') |
|
| 98 | + ); |
|
| 99 | + $no_data = __( 'No scan reports are available yet', 'cgss' ); |
|
| 100 | + foreach ($init_insight as $key => $value) { |
|
| 101 | + $model->insert($value, $no_data, $key + 1); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | //Include scripts |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | //fetch the data using custom named method function |
| 34 | - public static function get_insight() { |
|
| 34 | + public static function get_insight() { |
|
| 35 | 35 | |
| 36 | - $model = new InsightModel(); |
|
| 36 | + $model = new InsightModel(); |
|
| 37 | 37 | |
| 38 | - return $model->all(); |
|
| 39 | - } |
|
| 38 | + return $model->all(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | //How many rows are present there |
| 52 | - public static function record_count() { |
|
| 52 | + public static function record_count() { |
|
| 53 | 53 | |
| 54 | - $model = new InsightModel(); |
|
| 54 | + $model = new InsightModel(); |
|
| 55 | 55 | |
| 56 | - return $model->count(); |
|
| 57 | - } |
|
| 56 | + return $model->count(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | //Display the score |
| 32 | - public function score_html(): string { |
|
| 32 | + public function score_html(): string { |
|
| 33 | 33 | |
| 34 | 34 | $score = $this->result['score']; |
| 35 | 35 | $social = $this->result['social']; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | // Display the snippets |
| 47 | - public function snippet_display(): string { |
|
| 47 | + public function snippet_display(): string { |
|
| 48 | 48 | |
| 49 | 49 | $snippet = $this->result['snip']; |
| 50 | 50 | $title = $snippet['title']; |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | |
| 79 | 79 | // Display text and link data |
| 80 | - public function text_display(): string { |
|
| 80 | + public function text_display(): string { |
|
| 81 | 81 | |
| 82 | 82 | $text = $this->result['text']; |
| 83 | 83 | $keys = (!empty($text['keys']) ? implode(', ', array_keys($text['keys'])) : ''); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | // Display design data |
| 109 | - public function design_display(): string { |
|
| 109 | + public function design_display(): string { |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | $design = $this->result['design']; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | |
| 140 | 140 | // Display crawl data |
| 141 | - public function crawl_display(): string { |
|
| 141 | + public function crawl_display(): string { |
|
| 142 | 142 | |
| 143 | 143 | $crawl = $this->result['crawl']; |
| 144 | 144 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | |
| 172 | 172 | // Display speed data |
| 173 | - public function speed_display(): string { |
|
| 173 | + public function speed_display(): string { |
|
| 174 | 174 | |
| 175 | 175 | $speed = $this->result['speed']; |
| 176 | 176 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | |
| 200 | 200 | // Render the HTML |
| 201 | - public function render(): void { |
|
| 201 | + public function render(): void { |
|
| 202 | 202 | |
| 203 | 203 | $this->score_html = $this->score_html(); |
| 204 | 204 | $this->snippets_html = $this->snippet_display(); |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
| 219 | - public function box($title, $icon, $desc): void { |
|
| 219 | + public function box($title, $icon, $desc): void { |
|
| 220 | 220 | |
| 221 | 221 | echo |
| 222 | 222 | '<div class="postbox"> |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
| 233 | - public function dashicon($icon): string { |
|
| 233 | + public function dashicon($icon): string { |
|
| 234 | 234 | |
| 235 | 235 | return '<span class="dashicons dashicons-'.$icon.'"></span>'; |
| 236 | 236 | } |
@@ -25,25 +25,25 @@ |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | //DB insert function |
| 28 | - public function save() { |
|
| 29 | - |
|
| 30 | - $model = new InsightModel(); |
|
| 31 | - |
|
| 32 | - $result = array( |
|
| 33 | - $this->score, |
|
| 34 | - $this->snippet, |
|
| 35 | - $this->text, |
|
| 36 | - $this->links, |
|
| 37 | - $this->keywords, |
|
| 38 | - $this->images, |
|
| 39 | - $this->responsive, |
|
| 40 | - $this->speed, |
|
| 41 | - $this->social, |
|
| 42 | - ); |
|
| 43 | - foreach ($result as $key => $value) { |
|
| 44 | - $model->updateRemark($key + 1, $value); |
|
| 45 | - } |
|
| 46 | - } |
|
| 28 | + public function save() { |
|
| 29 | + |
|
| 30 | + $model = new InsightModel(); |
|
| 31 | + |
|
| 32 | + $result = array( |
|
| 33 | + $this->score, |
|
| 34 | + $this->snippet, |
|
| 35 | + $this->text, |
|
| 36 | + $this->links, |
|
| 37 | + $this->keywords, |
|
| 38 | + $this->images, |
|
| 39 | + $this->responsive, |
|
| 40 | + $this->speed, |
|
| 41 | + $this->social, |
|
| 42 | + ); |
|
| 43 | + foreach ($result as $key => $value) { |
|
| 44 | + $model->updateRemark($key + 1, $value); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | //Compile the result |
@@ -8,61 +8,61 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Insight |
| 10 | 10 | { |
| 11 | - /** @var wpdb */ |
|
| 12 | - protected $db; |
|
| 11 | + /** @var wpdb */ |
|
| 12 | + protected $db; |
|
| 13 | 13 | |
| 14 | - /** @var string */ |
|
| 15 | - protected $table; |
|
| 14 | + /** @var string */ |
|
| 15 | + protected $table; |
|
| 16 | 16 | |
| 17 | - public function __construct(?wpdb $db = null) |
|
| 18 | - { |
|
| 19 | - global $wpdb; |
|
| 20 | - $this->db = $db ?: $wpdb; |
|
| 21 | - $this->table = $this->db->prefix . 'cgss_insight'; |
|
| 22 | - } |
|
| 17 | + public function __construct(?wpdb $db = null) |
|
| 18 | + { |
|
| 19 | + global $wpdb; |
|
| 20 | + $this->db = $db ?: $wpdb; |
|
| 21 | + $this->table = $this->db->prefix . 'cgss_insight'; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Get all rows from the insight table. |
|
| 26 | - */ |
|
| 27 | - public function all(): array |
|
| 28 | - { |
|
| 29 | - $sql = "SELECT * FROM {$this->table}"; |
|
| 30 | - return $this->db->get_results($sql, ARRAY_A); |
|
| 31 | - } |
|
| 24 | + /** |
|
| 25 | + * Get all rows from the insight table. |
|
| 26 | + */ |
|
| 27 | + public function all(): array |
|
| 28 | + { |
|
| 29 | + $sql = "SELECT * FROM {$this->table}"; |
|
| 30 | + return $this->db->get_results($sql, ARRAY_A); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Count rows in the insight table. |
|
| 35 | - */ |
|
| 36 | - public function count(): int |
|
| 37 | - { |
|
| 38 | - $sql = "SELECT COUNT(*) FROM {$this->table}"; |
|
| 39 | - return (int) $this->db->get_var($sql); |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * Count rows in the insight table. |
|
| 35 | + */ |
|
| 36 | + public function count(): int |
|
| 37 | + { |
|
| 38 | + $sql = "SELECT COUNT(*) FROM {$this->table}"; |
|
| 39 | + return (int) $this->db->get_var($sql); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Insert an insight row. |
|
| 44 | - */ |
|
| 45 | - public function insert(string $item, string $remark, int $id): bool |
|
| 46 | - { |
|
| 47 | - $result = $this->db->insert( |
|
| 48 | - $this->table, |
|
| 49 | - ['ID' => $id, 'item' => $item, 'remark' => $remark], |
|
| 50 | - ['%d', '%s', '%s'] |
|
| 51 | - ); |
|
| 52 | - return $result !== false; |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * Insert an insight row. |
|
| 44 | + */ |
|
| 45 | + public function insert(string $item, string $remark, int $id): bool |
|
| 46 | + { |
|
| 47 | + $result = $this->db->insert( |
|
| 48 | + $this->table, |
|
| 49 | + ['ID' => $id, 'item' => $item, 'remark' => $remark], |
|
| 50 | + ['%d', '%s', '%s'] |
|
| 51 | + ); |
|
| 52 | + return $result !== false; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Update remark value by row id. |
|
| 57 | - */ |
|
| 58 | - public function updateRemark(int $id, string $remark): int |
|
| 59 | - { |
|
| 60 | - return $this->db->update( |
|
| 61 | - $this->table, |
|
| 62 | - ['remark' => $remark], |
|
| 63 | - ['ID' => $id], |
|
| 64 | - ['%s'], |
|
| 65 | - ['%d'] |
|
| 66 | - ); |
|
| 67 | - } |
|
| 55 | + /** |
|
| 56 | + * Update remark value by row id. |
|
| 57 | + */ |
|
| 58 | + public function updateRemark(int $id, string $remark): int |
|
| 59 | + { |
|
| 60 | + return $this->db->update( |
|
| 61 | + $this->table, |
|
| 62 | + ['remark' => $remark], |
|
| 63 | + ['ID' => $id], |
|
| 64 | + ['%s'], |
|
| 65 | + ['%d'] |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | 68 | } |