Changeset 1751877
- Timestamp:
- 10/24/2017 01:27:34 PM (8 years ago)
- Location:
- bbq/tags/1.1
- Files:
-
- 6 edited
-
admin/class-bbq-admin.php (modified) (1 diff)
-
includes/BbqHelper.php (modified) (1 diff)
-
includes/BbqOption.php (modified) (1 diff)
-
includes/BbqSynchronizer.php (modified) (2 diffs)
-
public/class-bbq-public.php (modified) (3 diffs)
-
public/js/bbq-code-init.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
bbq/tags/1.1/admin/class-bbq-admin.php
r1751712 r1751877 74 74 $synchronizer = new BbqSynchronizer(); 75 75 $synchronizer->getDataFromServer(); 76 $synchronizer->sendCategories(); 76 77 } 77 78 -
bbq/tags/1.1/includes/BbqHelper.php
r1751712 r1751877 124 124 return $openTagsCounter !== $closingTagsCounter; 125 125 } 126 127 public static function getCurrentCategoriesIds() 128 { 129 $ids = []; 130 $categories = get_the_category(); 131 foreach ($categories as $category) { 132 $ids[] = $category->term_id; 133 } 134 135 return $ids; 136 } 126 137 } -
bbq/tags/1.1/includes/BbqOption.php
r1751712 r1751877 14 14 * @property array $fixedBlocksIds 15 15 * @property string $excludedAdvertisementContainerTags; 16 * @property array $syncedCategories 16 17 */ 17 18 class BbqOption -
bbq/tags/1.1/includes/BbqSynchronizer.php
r1751712 r1751877 3 3 class BbqSynchronizer 4 4 { 5 protected $token; 6 protected $domain; 7 8 public function __construct() 9 { 10 $this->token = Bbq::$option->token; 11 $this->domain = Bbq::$option->domain; 12 if(!$this->token || !$this->domain) { 13 BbqHelper::alert('warning', 'Укажите домен и токен.'); 14 } 15 } 16 5 17 public function getDataFromServer() 6 18 { 7 $token = Bbq::$option->token;8 $domain = Bbq::$option->domain;9 if(!$token || !$domain) {10 BbqHelper::alert('warning', 'Укажите домен и токен.');11 12 return;13 }14 15 19 try { 16 $data = file_get_contents(rtrim($ domain, '/') . '/site/synchronize-all?token=' . $token . '&domain=' . BbqHelper::parseHost(get_site_url()));20 $data = file_get_contents(rtrim($this->domain, '/') . '/site/synchronize-all?token=' . $this->token . '&domain=' . BbqHelper::parseHost(get_site_url())); 17 21 $data = json_decode($data); 18 22 if($data && isset($data->ads) && isset($data->code) && isset($data->blocks) && isset($data->saitCodeUrl)) { … … 59 63 return true; 60 64 } 65 66 public function sendCategories() 67 { 68 $sendData = []; 69 $categories = get_categories(['hide_empty' => 0]); 70 foreach ($categories as $category) { 71 $sendData[] = ['id' => $category->term_id, 'name' => $category->name]; 72 } 73 74 //если мы уже отправляли эти категории и получили ответ "ok", то больше не надо ничего отправлять 75 $syncedCategories = Bbq::$option->syncedCategories; 76 if($syncedCategories === $sendData) { 77 return true; 78 } 79 80 try { 81 $url = rtrim($this->domain, '/') . '/site/synchronize-categories?token=' . $this->token . '&domain=' . BbqHelper::parseHost(get_site_url()); 82 $ch = curl_init(); 83 curl_setopt($ch, CURLOPT_URL, $url); 84 curl_setopt($ch, CURLOPT_POST, 1); 85 curl_setopt($ch, CURLOPT_POSTFIELDS, ['categories' => $sendData]); 86 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 87 curl_setopt($ch, CURLOPT_TIMEOUT, 3); 88 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 89 $response = curl_exec($ch); 90 curl_close($ch); 91 92 if($response !== 'ok') { 93 BbqHelper::alert('warning', 'Ошибка при синхронизации категорий'); 94 } else { 95 Bbq::$option->syncedCategories = $sendData; 96 } 97 } catch (Exception $e) { 98 BbqHelper::alert('warning', 'Ошибка при синхронизации категорий. Ошибка - "' . $e->getMessage() . '"'); 99 } 100 101 return true; 102 } 61 103 } -
bbq/tags/1.1/public/class-bbq-public.php
r1751712 r1751877 51 51 public function __construct($plugin_name, $version) 52 52 { 53 54 53 $this->plugin_name = $plugin_name; 55 54 $this->version = $version; … … 58 57 $synchronizer = new BbqSynchronizer(); 59 58 $synchronizer->getDataFromServer(); 59 $synchronizer->sendCategories(); 60 60 } 61 61 } … … 126 126 'marginTop' => (int)Bbq::$option->marginTop, 127 127 'marginBottom' => (int)Bbq::$option->marginBottom, 128 'currentSaitDomain' => BbqHelper::parseHost(get_site_url()) 128 'currentSaitDomain' => BbqHelper::parseHost(get_site_url()), 129 'categoriesIds' => implode(',', BbqHelper::getCurrentCategoriesIds()) 129 130 ] 130 131 ); -
bbq/tags/1.1/public/js/bbq-code-init.js
r1751712 r1751877 3 3 t = d.getElementsByTagName("script")[0]; 4 4 s = d.createElement("script"); 5 s.src = bbq.saitCodeUrl + "?saitDomain=" + escape(bbq.currentSaitDomain) + "&referrer=" + escape(document.referrer); 5 s.src = bbq.saitCodeUrl + "?saitDomain=" + escape(bbq.currentSaitDomain) 6 + "&referrer=" + escape(document.referrer) 7 + '&categories=' + bbq.categoriesIds; 6 8 s.type = "text/javascript"; 7 9 s.async = true;
Note: See TracChangeset
for help on using the changeset viewer.