Changeset 1572350
- Timestamp:
- 01/11/2017 09:32:52 AM (9 years ago)
- Location:
- exposify/tags/1.2.0
- Files:
-
- 1 added
- 4 edited
- 1 copied
-
. (copied) (copied from exposify/trunk)
-
README.txt (modified) (2 diffs)
-
admin.php (modified) (6 diffs)
-
exposify.php (modified) (2 diffs)
-
handler.php (added)
-
public.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
exposify/tags/1.2.0/README.txt
r1532313 r1572350 4 4 Requires at least: 4.5.0 5 5 Tested up to: 4.6.1 6 Stable tag: 1. 1.06 Stable tag: 1.2.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 48 48 == Changelog == 49 49 50 = 1.2 = 51 * Code refactor. Pull HTML templates from Exposify instead from the own site. 50 52 = 1.0 = 51 53 * Inital version. -
exposify/tags/1.2.0/admin.php
r1532313 r1572350 22 22 null, 23 23 'exposify_settings' 24 );25 26 add_settings_field(27 'exposify_api_url',28 __('Deine Team-URL von Exposify*', 'exposify'),29 'exposify_api_url_render',30 'exposify_settings',31 'exposify_general_section'32 24 ); 33 25 … … 71 63 'exposify_visual_section' 72 64 ); 73 74 add_settings_field(75 'exposify_extra_styles',76 __('Zusätzlich einzubindende Style Dateien', 'exposify'),77 'exposify_extra_styles_render',78 'exposify_settings',79 'exposify_visual_section'80 );81 82 add_settings_field(83 'exposify_extra_scripts',84 __('Zusätzlich einzubindende Javascript Dateien', 'exposify'),85 'exposify_extra_scripts_render',86 'exposify_settings',87 'exposify_visual_section'88 );89 90 add_settings_field(91 'exposify_template_overview',92 __('HTML Template für die Immobilien Übersicht', 'exposify'),93 'exposify_template_overview_render',94 'exposify_settings',95 'exposify_visual_section'96 );97 98 add_settings_field(99 'exposify_template_single',100 __('HTML Template für eine einzelne Immobilie', 'exposify'),101 'exposify_template_single_render',102 'exposify_settings',103 'exposify_visual_section'104 );105 106 add_settings_field(107 'exposify_css',108 __('CSS Template', 'exposify'),109 'exposify_css_render',110 'exposify_settings',111 'exposify_visual_section'112 );113 65 } 114 66 … … 120 72 function exposify_sanitize_settings($option) 121 73 { 122 $option['exposify_api_url'] = sanitize_text_field($option['exposify_api_url']);123 74 $option['exposify_api_key'] = sanitize_text_field($option['exposify_api_key']); 124 75 $option['exposify_site_title'] = sanitize_text_field($option['exposify_site_title']); … … 127 78 128 79 return $option; 129 }130 131 /**132 * Display the field.133 */134 function exposify_api_url_render()135 {136 $options = get_option('exposify_settings');137 ?>138 <input class="regular-text" type="text" name="exposify_settings[exposify_api_url]" value="<?php echo $options['exposify_api_url']; ?>" placeholder="z.B. https://app.exposify.de/api/beta/foo-bar-team">139 <?php140 80 } 141 81 … … 176 116 * Display the field. 177 117 */ 178 function exposify_template_overview_render()179 {180 $options = get_option('exposify_settings');181 ?>182 <p>183 <?php echo __('Das HTML Template für die Übersicht aller Immobilien. Über das Array <code>$properties</code> kann auf alle Immobilien zugegriffen werden. Über die Variable <code>$search_query</code> kann auf den aktuellen Such-String zugegriffen werden.', 'exposify'); ?>184 </p>185 <textarea class="large-text" type="text" name="exposify_settings[exposify_template_overview]" rows="15"><?php echo $options['exposify_template_overview']; ?></textarea>186 <?php187 }188 189 /**190 * Display the field.191 */192 function exposify_extra_styles_render() {193 $options = get_option('exposify_settings');194 ?>195 <textarea class="large-text" type="text" name="exposify_settings[exposify_extra_styles]" rows="3" placeholder="<?php echo __('Name; URI;', 'exposify'); ?>"><?php echo $options['exposify_extra_styles']; ?></textarea>196 <?php197 }198 199 /**200 * Display the field.201 */202 function exposify_extra_scripts_render() {203 $options = get_option('exposify_settings');204 ?>205 <textarea class="large-text" type="text" name="exposify_settings[exposify_extra_scripts]" rows="3" placeholder="<?php echo __('Name; URI; Boolean, soll Skript erst im Footer eingebunden werden?;', 'exposify'); ?>"><?php echo $options['exposify_extra_scripts']; ?></textarea>206 <?php207 }208 209 /**210 * Display the field.211 */212 118 function exposify_theme_template_render() 213 119 { … … 222 128 ?> 223 129 </select> 224 <?php225 }226 227 /**228 * Display the field.229 */230 function exposify_template_single_render()231 {232 $options = get_option('exposify_settings');233 ?>234 <p>235 <?php echo __('Das HTML Template für eine einzelne Immobilie. Über die Variable <code>$property</code> kann auf die Immobilie zugegriffen werden.', 'exposify'); ?>236 </p>237 <textarea class="large-text" type="text" name="exposify_settings[exposify_template_single]" rows="15"><?php echo $options['exposify_template_single']; ?></textarea>238 <?php239 }240 241 /**242 * Display the field.243 */244 function exposify_css_render()245 {246 $options = get_option('exposify_settings');247 ?>248 <textarea class="large-text" type="text" name="exposify_settings[exposify_css]" rows="15"><?php echo $options['exposify_css']; ?></textarea>249 130 <?php 250 131 } -
exposify/tags/1.2.0/exposify.php
r1532313 r1572350 5 5 Plugin URI: https://exposify.de 6 6 Description: Zeigt alle eigenen Immobilienangebote von Exposify. 7 Version: 1. 1.07 Version: 1.2.0 8 8 Author: Exposify 9 9 Author URI: https://exposify.de … … 77 77 if (is_admin()) { 78 78 require(__DIR__ . '/admin.php'); 79 } else { 80 require(__DIR__ . '/handler.php'); 81 require(__DIR__ . '/public.php'); 79 82 } 80 81 require(__DIR__ . '/public.php'); -
exposify/tags/1.2.0/public.php
r1532313 r1572350 1 1 <?php 2 2 3 /** 4 * Evaluate the HTML Template from the database for a single property and display it. 5 * @param String $api_url 6 * @param String $api_key 7 * @param String $slug 8 */ 9 function exposify_show_single_property($api_url, $api_key, $slug) 10 { 11 $curl = curl_init(); 12 curl_setopt_array($curl, [ 13 CURLOPT_RETURNTRANSFER => 1, 14 CURLOPT_URL => $api_url . '/' . $slug . '?api_token=' . $api_key, 15 CURLOPT_TIMEOUT => 5 16 ]); 17 $result = curl_exec($curl); 18 curl_close($curl); 3 class ExposifyViewer { 19 4 20 if (!$result) { 21 echo __('Die Immobilie kann im Moment leider nicht geladen werden. Versuchen Sie es bitte später erneut oder kontaktieren Sie uns!', 'exposify'); 22 return null; 5 /** 6 * An instance of the Exposify handler. 7 * @var Exposify 8 */ 9 public $exposify; 10 11 /** 12 * Construct the class. 13 * @param String $apiKey 14 * @param String $baseUrl 15 */ 16 public function __construct($apiKey, $baseUrl = 'https://app.exposify.de') 17 { 18 $this->exposify = new Exposify($apiKey, $baseUrl); 19 20 add_filter('the_content', [$this, 'changePageContent']); 21 add_filter('page_template', [$this, 'changePageTemplate']); 22 add_action('wp_enqueue_scripts', [$this, 'insertLinks']); 23 23 } 24 24 25 $property = json_decode($result, true); 26 27 // evaluate the single Template 28 $visual_settings = get_option('exposify_settings'); 29 eval(' ?>' . $visual_settings['exposify_template_single'] . '<?php '); 30 } 31 32 /** 33 * Evaluate the HTML Template from the database for the properties overview and display it. 34 * @param String $api_url 35 * @param String $api_key 36 * @param String $search_query 37 */ 38 function exposify_show_properties_overview($api_url, $api_key, $search_query='') 39 { 40 $curl = curl_init(); 41 curl_setopt_array($curl, [ 42 CURLOPT_RETURNTRANSFER => 1, 43 CURLOPT_URL => $api_url . '?api_token=' . $api_key . '&query=' . $search_query, 44 CURLOPT_TIMEOUT => 5 45 ]); 46 $result = curl_exec($curl); 47 curl_close($curl); 48 49 if (!$result) { 50 echo __('Die Immobilien können im Moment leider nicht geladen werden. Versuchen Sie es bitte später erneut oder kontaktieren Sie uns!', 'exposify'); 51 return null; 25 /** 26 * Request the property/properties, if there isn't a result yet. 27 * @return Void 28 */ 29 public function attemptRequest() 30 { 31 if (empty($this->exposify->html->getResult())) { 32 if (get_query_var('slug')) { 33 $this->exposify->html->requestSingleProperty(get_query_var('slug')); 34 } else { 35 $this->exposify->html->requestAllProperties(get_query_var('search', '')); 36 } 37 } 52 38 } 53 39 54 $api_array = json_decode($result, true); 55 $properties = $api_array['properties']; 56 57 // evaluate the overview Template 58 $visual_settings = get_option('exposify_settings'); 59 eval(' ?>' . $visual_settings['exposify_template_overview'] . '<?php '); 60 } 61 62 /** 63 * Alter the content of the properties page and replace it with the templates. 64 * @param String $content 65 * @return String $content 66 */ 67 function exposify_change_properties_page_content($content) 68 { 69 if (get_the_ID() == get_option('exposify_properties_page_id')) { 70 // get the credentials 71 $credentials = get_option('exposify_settings'); 72 $immoapiurl = $credentials['exposify_api_url']; 73 $immoapikey = $credentials['exposify_api_key']; 74 75 if (filter_var($immoapiurl, FILTER_VALIDATE_URL) === false || !$immoapikey) { 76 return __('Die Immobilienübersicht ist noch nicht fertig eingerichtet.', 'exposify'); 40 /** 41 * Change the page template to the specified one. 42 * @param String $oldTemplate 43 * @return String 44 */ 45 public function changePageTemplate($oldTemplate) 46 { 47 if (get_the_ID() != get_option('exposify_properties_page_id')) { 48 return $oldTemplate; 77 49 } 78 50 79 if (get_query_var('slug')) { 80 exposify_show_single_property($immoapiurl, $immoapikey, get_query_var('slug')); 81 } else { 82 exposify_show_properties_overview($immoapiurl, $immoapikey, get_query_var('search')); 51 $new_template = get_option('exposify_settings')['exposify_theme_template']; 52 if (locate_template($new_template) != '' && $new_template != 'default') { 53 return get_template_directory() . '/' . $new_template; 83 54 } 55 56 return $oldTemplate; 84 57 } 85 return $content;86 }87 58 88 /** 89 * Alter the title of the properties page. 90 * @param String $content 91 * @return String $content 92 */ 93 function exposify_change_properties_page_title($title, $id) 94 { 95 if ($id == get_option('exposify_properties_page_id')) { 96 if (get_query_var('slug') && in_the_loop()) { 97 $credentials = get_option('exposify_settings'); 98 $immoapiurl = $credentials['exposify_api_url']; 99 $immoapikey = $credentials['exposify_api_key']; 59 /** 60 * Insert the properties into the page. 61 * @param String $oldContent 62 * @return String 63 */ 64 public function changePageContent($oldContent) 65 { 66 if (get_the_ID() != get_option('exposify_properties_page_id')) { 67 return $oldContent; 68 } 69 $this->attemptRequest(); 100 70 101 $curl = curl_init(); 102 curl_setopt_array($curl, [ 103 CURLOPT_RETURNTRANSFER => 1, 104 CURLOPT_URL => $immoapiurl . '/' . get_query_var('slug') . '?api_token=' . $immoapikey, 105 CURLOPT_TIMEOUT => 5 106 ]); 107 $result = curl_exec($curl); 108 curl_close($curl); 71 return $this->exposify->html->getContent(); 72 } 109 73 110 if (!$result) { 111 return $title; 74 /** 75 * Change the page title to the property name. 76 * @param String $oldTitle 77 * @return String 78 */ 79 public function changePageTitle($oldTitle) 80 { 81 if ( 82 get_the_ID() != get_option('exposify_properties_page_id') || 83 !in_the_loop() 84 ) { 85 return $oldTitle; 86 } 87 88 $this->attemptRequest(); 89 90 return $this->exposify->html->getTitle(); 91 } 92 93 /** 94 * Insert all external CSS and JS files in the page. 95 * @return Void 96 */ 97 public function insertLinks() 98 { 99 if (get_the_ID() != get_option('exposify_properties_page_id')) { 100 return; 101 } 102 103 $this->attemptRequest(); 104 105 if (isset($this->exposify->html->getError()['css'])) { 106 $css = $this->exposify->html->getError()['js']; 107 } 108 if (isset($this->exposify->html->getResult()['css'])) { 109 $css = $this->exposify->html->getResult()['css']; 110 } 111 if (isset($css) && is_array($css)) { 112 foreach ($css as $css_src) { 113 wp_enqueue_style('exposify', $css_src); 112 114 } 115 } 113 116 114 $property = json_decode($result, true);115 return $property['name'];117 if (isset($this->exposify->html->getError()['js'])) { 118 $js = $this->exposify->html->getError()['js']; 116 119 } 117 } 118 return $title; 119 } 120 121 /** 122 * Display the custom css. Use wp_enqueue_style later. 123 */ 124 function exposify_get_css() 125 { 126 if (get_the_ID() == get_option('exposify_properties_page_id')) { 127 $data = get_option('exposify_settings'); 128 $css = "<style id='exposify-css'>" . $data['exposify_css'] . "</style>\r"; 129 echo $css; 120 if (isset($this->exposify->html->getResult()['js'])) { 121 $js = $this->exposify->html->getResult()['js']; 122 } 123 if (isset($js) && is_array($js)) { 124 foreach ($js as $js_src) { 125 wp_enqueue_script('exposify', $js_src); 126 } 127 } 130 128 } 131 129 } 132 130 133 /** 134 * Alter the template of the properties page. 135 * @param String $template 136 * @return String 137 */ 138 function exposify_change_page_template($template) 139 { 140 if (get_the_ID() == get_option('exposify_properties_page_id')) { 141 $new_template = get_option('exposify_settings')['exposify_theme_template']; 142 if (locate_template($new_template) != '' && $new_template != 'default') { 143 return get_template_directory() . '/' . $new_template; 144 } else { 145 return $template; 146 } 147 } 148 return $template; 149 } 150 151 /** 152 * Append extra CSS and JS files to the header/footer 153 */ 154 function exposify_add_additional_css() { 155 $options = get_option('exposify_settings'); 156 $styles = explode('\r\n', $options['exposify_extra_styles']); 157 $scripts = explode('\r\n', $options['exposify_extra_scripts']); 158 159 foreach ($styles as $style) { 160 $style_array = explode('; ', $style, 3); 161 wp_enqueue_style($style_array[0], $style_array[1]); 162 } 163 foreach ($scripts as $script) { 164 $script_array = explode('; ', $script, 4); 165 wp_enqueue_script($script_array[0], $script_array[1], null, null, boolval($script_array[2])); 166 } 167 } 168 169 add_filter('the_content', 'exposify_change_properties_page_content'); 170 add_filter('the_title', 'exposify_change_properties_page_title', 10, 2); 171 add_filter('page_template', 'exposify_change_page_template'); 172 add_action('wp_head', 'exposify_get_css', 99999999); 173 add_action('wp_enqueue_scripts', 'exposify_add_additional_css' ); 131 $viewer = new ExposifyViewer(get_option('exposify_settings')['exposify_api_key']);
Note: See TracChangeset
for help on using the changeset viewer.