PluginProbe
SheetDB – get your Google Spreadsheet data / trunk
SheetDB – get your Google Spreadsheet data vtrunk
trunk 1.3.7
sheetdb / sheetdb.php

sheetdb.php in SheetDB – get your Google Spreadsheet data trunk, at sheetdb.php

132 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package SheetDB
5 */
6 /*
7 Plugin name: SheetDB
8 Description: The SheetDB wordpress plugin allows you to easily add content from Google Spreadsheet to your wordpress site.
9 Version: 1.3.7
10 Author: SheetDB
11 Author URI: https://sheetdb.io/
12 Plugin URI: https://wordpress.org/plugins/sheetdb/
13 License: GPLv2 or later
14 Text domain: sheetdb
15 */
16
17 /*
18 This program is free software: you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation, either version 3 of the License, or
21 (at your option) any later version.
22
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
32 defined('ABSPATH') or die();
33
34 // Main Plugin Class
35 if (!class_exists('WordpressSheetDB')) {
36 class WordpressSheetDB
37 {
38 public function __construct()
39 {
40 add_shortcode('sheetdb', [$this, 'sheetdb_shortcode']);
41 add_shortcode('sheetdb-slot', [$this, 'sheetdb_slot_shortcode']);
42
43 add_action('wp_footer', array($this, 'enqueueAssets'));
44 }
45
46 public function enqueueAssets()
47 {
48 wp_enqueue_script('sheetdb-js', plugins_url('assets/js/sheetdb-handlebars-1.2.6.js', __FILE__));
49 }
50
51 public function sheetdb_shortcode($atts, $content)
52 {
53 isset($atts['url']) ? $url = $atts['url'] : $url = null;
54 isset($atts['element']) ? $element = tag_escape($atts['element']) : $element = "div";
55 if (!$element) {
56 $element = 'div';
57 }
58
59 isset($atts['save']) ? $save = $atts['save'] : $save = null;
60 isset($atts['sheet']) ? $sheet = $atts['sheet'] : $sheet = null;
61 isset($atts['limit']) ? $limit = $atts['limit'] : $limit = null;
62 isset($atts['offset']) ? $offset = $atts['offset'] : $offset = null;
63 isset($atts['search']) ? $search = $atts['search'] : $search = null;
64 isset($atts['search-mode']) ? $searchMode = $atts['search-mode'] : $searchMode = null;
65 isset($atts['sort-by']) ? $sortBy = $atts['sort-by'] : $sortBy = null;
66 isset($atts['sort-order']) ? $sortOrder = $atts['sort-order'] : $sortOrder = null;
67 isset($atts['sort-method']) ? $sortMethod = $atts['sort-method'] : $sortMethod = null;
68 isset($atts['sort-date-format']) ? $sortDateFormat = $atts['sort-date-format'] : $sortDateFormat = null;
69 isset($atts['lazy-loading']) ? $lazy = true : $lazy = false;
70
71 if (!$url) return 'Use URL attribute with the SheetDB shortcode.';
72
73 $additionalCode = $this->makeAdditionalCode($sheet, $limit, $offset, $search, $searchMode, $sortBy, $sortOrder, $sortMethod, $sortDateFormat, $save, $lazy);
74
75 return "<{$element} data-sheetdb-url=\"" . esc_url($url) . "\"{$additionalCode}>" . wp_kses_post($content) . "</{$element}>";
76 }
77
78 public function sheetdb_slot_shortcode($atts, $content)
79 {
80 isset($atts['slot']) ? $slot = $atts['slot'] : $slot = null;
81 isset($atts['element']) ? $element = tag_escape($atts['element']) : $element = "div";
82 if (!$element) {
83 $element = 'div';
84 }
85
86 return "<{$element} data-sheetdb-slot=\"" . esc_attr($slot) . "\">" . wp_kses_post($content) . "</{$element}>";
87 }
88
89 private function makeAdditionalCode($sheet, $limit, $offset, $search, $searchMode, $sortBy, $sortOrder, $sortMethod, $sortDateFormat, $save, $lazy)
90 {
91 $additionalCode = '';
92 if ($sheet) {
93 $additionalCode .= ' data-sheetdb-sheet="' . esc_attr($sheet) . '"';
94 }
95 if ($limit) {
96 $additionalCode .= ' data-sheetdb-limit="' . esc_attr($limit) . '"';
97 }
98 if ($offset) {
99 $additionalCode .= ' data-sheetdb-offset="' . esc_attr($offset) . '"';
100 }
101 if ($search) {
102 $additionalCode .= ' data-sheetdb-search="' . esc_attr($search) . '"';
103 }
104 if ($searchMode) {
105 $additionalCode .= ' data-sheetdb-search-mode="' . esc_attr($searchMode) . '"';
106 }
107 if ($sortBy) {
108 $additionalCode .= ' data-sheetdb-sort-by="' . esc_attr($sortBy) . '"';
109 }
110 if ($sortOrder) {
111 $additionalCode .= ' data-sheetdb-sort-order="' . esc_attr($sortOrder) . '"';
112 }
113 if ($sortMethod) {
114 $additionalCode .= ' data-sheetdb-sort-method="' . esc_attr($sortMethod) . '"';
115 }
116 if ($sortDateFormat) {
117 $additionalCode .= ' data-sheetdb-sort-date-format="' . esc_attr($sortDateFormat) . '"';
118 }
119 if ($save) {
120 $additionalCode .= ' data-sheetdb-save="' . esc_attr($save) . '"';
121 }
122 if ($lazy) {
123 $additionalCode .= ' lazy-loading="true"';
124 }
125
126 return $additionalCode;
127 }
128 }
129 }
130
131 $wordpressSheetDB = new WordpressSheetDB;
132