Changeset 1706971
- Timestamp:
- 08/02/2017 01:09:25 PM (9 years ago)
- Location:
- bbq
- Files:
-
- 7 edited
-
tags/1.0.7/README.txt (modified) (2 diffs)
-
tags/1.0.7/admin/class-bbq-admin.php (modified) (2 diffs)
-
tags/1.0.7/bbq.php (modified) (1 diff)
-
tags/1.0.7/includes/BbqHelper.php (modified) (1 diff)
-
tags/1.0.7/includes/BbqOption.php (modified) (3 diffs)
-
tags/1.0.7/public/class-bbq-public.php (modified) (2 diffs)
-
trunk/README.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bbq/tags/1.0.7/README.txt
r1706725 r1706971 4 4 Requires at least: 4.0.0 5 5 Tested up to: 4.7.2 6 Stable tag: 1.0. 66 Stable tag: 1.0.7 7 7 8 8 Плагин интеграции с сервисом bbq.money. … … 33 33 == Changelog == 34 34 35 = 1.0.7 = 36 * Добавлена возможность указывать теги (например цитаты и таблицы), в которые запрещено будет помещать рекламное объявление. 37 35 38 = 1.0.5 = 36 39 * Изменена логика вставки блоков в текст. Теперь минимальное расстояние между блоками - 1500 символов. -
bbq/tags/1.0.7/admin/class-bbq-admin.php
r1706725 r1706971 175 175 register_setting($this->plugin_name, self::$option_name . '_marginTop'); 176 176 register_setting($this->plugin_name, self::$option_name . '_marginBottom'); 177 register_setting($this->plugin_name, self::$option_name . '_excludedAdvertisementContainerTags'); 177 178 register_setting($this->plugin_name, self::$option_name . '_token'); 178 179 register_setting($this->plugin_name, self::$option_name . '_domain', 'esc_url'); … … 224 225 echo '<span class="description">px</span>'; 225 226 echo '</p>'; 227 228 $excludedAdvertisementContainerTags = Bbq::$option->excludedAdvertisementContainerTags; 229 echo '<p>'; 230 echo '<label for="' . self::$option_name . '_excludedAdvertisementContainerTags' . '">Исключенные теги контейнеров рекламных объявлений:'; 231 echo '</label>'; 232 echo '<input style="width:210px;" type="text" name="' . self::$option_name . '_excludedAdvertisementContainerTags' . '" id="' . self::$option_name . '_excludedAdvertisementContainerTags' . '" value="' . $excludedAdvertisementContainerTags . '">'; 233 echo '<span class="description">Каждый тег через запятую, по умолчанию: "table,blockquote".</span>'; 234 echo '</p>'; 226 235 } 227 236 } -
bbq/tags/1.0.7/bbq.php
r1706725 r1706971 17 17 * Plugin URI: https://bbq.money/ 18 18 * Description: Плагин интеграции с сервисом BBQ.MONEY 19 * Version: 1.0. 619 * Version: 1.0.7 20 20 * Author: Archil 21 21 * Author URI: http://archil.net/ -
bbq/tags/1.0.7/includes/BbqHelper.php
r1706725 r1706971 81 81 } 82 82 83 public static function insertAfter Paragraph($insertion, $paragraphId, $content)83 public static function insertAfterTag($insertion, $paragraphId, $content, $tag = 'p') 84 84 { 85 $closing_p = '</p>'; 86 $paragraphs = explode($closing_p, $content); 85 $closingTag = '</' . $tag . '>'; 86 $paragraphs = explode($closingTag, $content); 87 $tempString = ''; //сюда пишем постепепенно все параграфы 88 $excludedAdvertisementContainerTags = Bbq::$option->excludedAdvertisementContainerTags; 89 $excludedAdvertisementContainerTags = $excludedAdvertisementContainerTags ? explode(',', $excludedAdvertisementContainerTags) : []; 90 87 91 foreach ($paragraphs as $index => $paragraph) { 88 92 if(trim($paragraph)) { 89 $paragraphs[$index] .= $closing _p;93 $paragraphs[$index] .= $closingTag; 90 94 } 95 $tempString .= $paragraphs[$index]; 96 91 97 if($paragraphId === $index + 1) { 92 if(strpos($paragraphs[$index], '<blockquote') === false) { 93 $paragraphs[$index] .= $insertion; 94 } else { 95 $blockQuoteEndPosition = strpos($paragraphs[$index + 1], '</blockquote>'); 96 if($blockQuoteEndPosition === false) { 97 return self::insertAfterParagraph($insertion, $paragraphId + 1, $content); 98 } else { 99 $paragraphs[$index + 1] = substr_replace($paragraphs[$index + 1], $insertion, $blockQuoteEndPosition + strlen('</blockquote>')); 98 if($excludedAdvertisementContainerTags) { 99 foreach ($excludedAdvertisementContainerTags as $excludedAdvertisementContainerTag) { 100 if(self::tagIsOpened($tempString, $excludedAdvertisementContainerTag)) { 101 $tagNumber = substr_count($tempString, '<' . $excludedAdvertisementContainerTag); 102 103 return self::insertAfterTag($insertion, $tagNumber, $content, $excludedAdvertisementContainerTag); 104 } 100 105 } 101 106 } 107 108 $paragraphs[$index] .= $insertion; 102 109 } 110 103 111 } 104 112 105 113 return implode('', $paragraphs); 106 114 } 115 116 protected static function tagIsOpened($string, $tag) 117 { 118 if(strpos($string, '<' . $tag) === false) { 119 return false; 120 } 121 $openTagsCounter = substr_count($string, '<' . $tag); 122 $closingTagsCounter = substr_count($string, '</' . $tag); 123 124 return $openTagsCounter !== $closingTagsCounter; 125 } 107 126 } -
bbq/tags/1.0.7/includes/BbqOption.php
r1706725 r1706971 13 13 * @property integer $marginBottom 14 14 * @property array $fixedBlocksIds 15 * @property string $excludedAdvertisementContainerTags; 15 16 */ 16 17 class BbqOption … … 26 27 } 27 28 29 public function getExcludedAdvertisementContainerTags() 30 { 31 return get_option($this->option_prefix . 'excludedAdvertisementContainerTags', 'table,blockquote'); 32 } 33 28 34 public function getBlocks() 29 35 { … … 33 39 $blocks[$i]->positionNumber = BbqBlockPosition::getPositionNumber($blocks[$i]->blockPosition); 34 40 } 35 $positionNumber = [];36 $blockPositionPriority = [];37 foreach ($blocks as $key => $row) {38 $positionNumber[$key] = (int)$row->positionNumber;39 $blockPositionPriority[$key] = (int)$row->blockPositionPriority;40 }41 array_multisort($positionNumber, SORT_DESC, $blockPositionPriority, SORT_DESC, $blocks);42 41 43 42 return $blocks; -
bbq/tags/1.0.7/public/class-bbq-public.php
r1706725 r1706971 169 169 $paragraphsCounter = count(explode('</p>', $content)); 170 170 $beforePost = ''; 171 //Вставка рекламы перед и после статьи 172 usort($blocks, function ($a, $b) { return $a->blockPositionPriority < $b->blockPositionPriority; }); 171 173 foreach ($blocks as $block) { 172 173 174 //checking if current page type allowed 174 175 if(isset($block->blockPageTypes)) { … … 191 192 $content .= $block->blockDiv; 192 193 } 194 } 195 $content = $beforePost . $content; 196 197 //Вставка рекламы внутри статьи 198 usort($blocks, function ($a, $b) { return $a->positionNumber > $b->positionNumber; }); 199 foreach ($blocks as $block) { 200 //checking if current page type allowed 201 if(isset($block->blockPageTypes)) { 202 $flag = false; 203 $allowedPageTypes = json_decode($block->blockPageTypes); 204 foreach ($allowedPageTypes as $allowedPageType => $isAllowed) { 205 if($isAllowed && $flag = $allowedPageType()) { 206 break; 207 } 208 } 209 if(!$flag) { 210 continue; 211 } 212 } 193 213 194 214 if($block->blockPosition === BbqBlockPosition::FIRST_IN_POST && $allowedBlocksCounter !== 0) { 195 $content = BbqHelper::insertAfter Paragraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 1)), $content);215 $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 1)), $content); 196 216 $allowedBlocksCounter--; 197 217 } 198 218 if($block->blockPosition === BbqBlockPosition::SECOND_IN_POST && $allowedBlocksCounter !== 0) { 199 $content = BbqHelper::insertAfter Paragraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 2)), $content);219 $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 2)), $content); 200 220 $allowedBlocksCounter--; 201 221 } 202 222 if($block->blockPosition === BbqBlockPosition::THIRD_IN_POST && $allowedBlocksCounter !== 0) { 203 $content = BbqHelper::insertAfter Paragraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 3)), $content);223 $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 3)), $content); 204 224 $allowedBlocksCounter--; 205 225 } 206 226 if($block->blockPosition === BbqBlockPosition::FOURTH_IN_POST && $allowedBlocksCounter !== 0) { 207 $content = BbqHelper::insertAfter Paragraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 4)), $content);227 $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 4)), $content); 208 228 $allowedBlocksCounter--; 209 229 } 210 230 if($block->blockPosition === BbqBlockPosition::FIFTH_IN_POST && $allowedBlocksCounter !== 0) { 211 $content = BbqHelper::insertAfter Paragraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 5)), $content);231 $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 5)), $content); 212 232 $allowedBlocksCounter--; 213 233 } 214 234 if($block->blockPosition === BbqBlockPosition::SIXTH_IN_POST && $allowedBlocksCounter !== 0) { 215 $content = BbqHelper::insertAfter Paragraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 6)), $content);235 $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 6)), $content); 216 236 $allowedBlocksCounter--; 217 237 } 218 238 if($block->blockPosition === BbqBlockPosition::SEVENTH_IN_POST && $allowedBlocksCounter !== 0) { 219 $content = BbqHelper::insertAfterParagraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 7)), $content); 220 $allowedBlocksCounter--; 221 } 222 } 223 $content = $beforePost . $content; 239 $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 7)), $content); 240 $allowedBlocksCounter--; 241 } 242 } 224 243 } 225 244 -
bbq/trunk/README.txt
r1705768 r1706971 4 4 Requires at least: 4.0.0 5 5 Tested up to: 4.7.2 6 Stable tag: 1.0. 66 Stable tag: 1.0.7 7 7 8 8 Плагин интеграции с сервисом bbq.money. … … 33 33 == Changelog == 34 34 35 = 1.0.7 = 36 * Добавлена возможность указывать теги (например цитаты и таблицы), в которые запрещено будет помещать рекламное объявление. 37 35 38 = 1.0.5 = 36 39 * Изменена логика вставки блоков в текст. Теперь минимальное расстояние между блоками - 1500 символов.
Note: See TracChangeset
for help on using the changeset viewer.