Plugin Directory

Changeset 1706971


Ignore:
Timestamp:
08/02/2017 01:09:25 PM (9 years ago)
Author:
vashkatsi
Message:

1.0.7

Location:
bbq
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • bbq/tags/1.0.7/README.txt

    r1706725 r1706971  
    44Requires at least: 4.0.0
    55Tested up to: 4.7.2
    6 Stable tag: 1.0.6
     6Stable tag: 1.0.7
    77
    88Плагин интеграции с сервисом bbq.money.
     
    3333== Changelog ==
    3434
     35= 1.0.7 =
     36* Добавлена возможность указывать теги (например цитаты и таблицы), в которые запрещено будет помещать рекламное объявление.
     37
    3538= 1.0.5 =
    3639* Изменена логика вставки блоков в текст. Теперь минимальное расстояние между блоками - 1500 символов.
  • bbq/tags/1.0.7/admin/class-bbq-admin.php

    r1706725 r1706971  
    175175        register_setting($this->plugin_name, self::$option_name . '_marginTop');
    176176        register_setting($this->plugin_name, self::$option_name . '_marginBottom');
     177        register_setting($this->plugin_name, self::$option_name . '_excludedAdvertisementContainerTags');
    177178        register_setting($this->plugin_name, self::$option_name . '_token');
    178179        register_setting($this->plugin_name, self::$option_name . '_domain', 'esc_url');
     
    224225        echo '<span class="description">px</span>';
    225226        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>';
    226235    }
    227236}
  • bbq/tags/1.0.7/bbq.php

    r1706725 r1706971  
    1717 * Plugin URI:        https://bbq.money/
    1818 * Description:       Плагин интеграции с сервисом BBQ.MONEY
    19  * Version:           1.0.6
     19 * Version:           1.0.7
    2020 * Author:            Archil
    2121 * Author URI:        http://archil.net/
  • bbq/tags/1.0.7/includes/BbqHelper.php

    r1706725 r1706971  
    8181    }
    8282
    83     public static function insertAfterParagraph($insertion, $paragraphId, $content)
     83    public static function insertAfterTag($insertion, $paragraphId, $content, $tag = 'p')
    8484    {
    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
    8791        foreach ($paragraphs as $index => $paragraph) {
    8892            if(trim($paragraph)) {
    89                 $paragraphs[$index] .= $closing_p;
     93                $paragraphs[$index] .= $closingTag;
    9094            }
     95            $tempString .= $paragraphs[$index];
     96
    9197            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                        }
    100105                    }
    101106                }
     107
     108                $paragraphs[$index] .= $insertion;
    102109            }
     110
    103111        }
    104112
    105113        return implode('', $paragraphs);
    106114    }
     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    }
    107126}
  • bbq/tags/1.0.7/includes/BbqOption.php

    r1706725 r1706971  
    1313 * @property integer $marginBottom
    1414 * @property array $fixedBlocksIds
     15 * @property string $excludedAdvertisementContainerTags;
    1516 */
    1617class BbqOption
     
    2627    }
    2728
     29    public function getExcludedAdvertisementContainerTags()
     30    {
     31        return get_option($this->option_prefix . 'excludedAdvertisementContainerTags', 'table,blockquote');
     32    }
     33
    2834    public function getBlocks()
    2935    {
     
    3339            $blocks[$i]->positionNumber = BbqBlockPosition::getPositionNumber($blocks[$i]->blockPosition);
    3440        }
    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);
    4241
    4342        return $blocks;
  • bbq/tags/1.0.7/public/class-bbq-public.php

    r1706725 r1706971  
    169169            $paragraphsCounter = count(explode('</p>', $content));
    170170            $beforePost = '';
     171            //Вставка рекламы перед и после статьи
     172            usort($blocks, function ($a, $b) { return $a->blockPositionPriority < $b->blockPositionPriority; });
    171173            foreach ($blocks as $block) {
    172 
    173174                //checking if current page type allowed
    174175                if(isset($block->blockPageTypes)) {
     
    191192                    $content .= $block->blockDiv;
    192193                }
     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                }
    193213
    194214                if($block->blockPosition === BbqBlockPosition::FIRST_IN_POST && $allowedBlocksCounter !== 0) {
    195                     $content = BbqHelper::insertAfterParagraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 1)), $content);
     215                    $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 1)), $content);
    196216                    $allowedBlocksCounter--;
    197217                }
    198218                if($block->blockPosition === BbqBlockPosition::SECOND_IN_POST && $allowedBlocksCounter !== 0) {
    199                     $content = BbqHelper::insertAfterParagraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 2)), $content);
     219                    $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 2)), $content);
    200220                    $allowedBlocksCounter--;
    201221                }
    202222                if($block->blockPosition === BbqBlockPosition::THIRD_IN_POST && $allowedBlocksCounter !== 0) {
    203                     $content = BbqHelper::insertAfterParagraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 3)), $content);
     223                    $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 3)), $content);
    204224                    $allowedBlocksCounter--;
    205225                }
    206226                if($block->blockPosition === BbqBlockPosition::FOURTH_IN_POST && $allowedBlocksCounter !== 0) {
    207                     $content = BbqHelper::insertAfterParagraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 4)), $content);
     227                    $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 4)), $content);
    208228                    $allowedBlocksCounter--;
    209229                }
    210230                if($block->blockPosition === BbqBlockPosition::FIFTH_IN_POST && $allowedBlocksCounter !== 0) {
    211                     $content = BbqHelper::insertAfterParagraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 5)), $content);
     231                    $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 5)), $content);
    212232                    $allowedBlocksCounter--;
    213233                }
    214234                if($block->blockPosition === BbqBlockPosition::SIXTH_IN_POST && $allowedBlocksCounter !== 0) {
    215                     $content = BbqHelper::insertAfterParagraph($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 6)), $content);
     235                    $content = BbqHelper::insertAfterTag($block->blockDiv, (int)floor($paragraphsCounter / (($maxInTextBlocksNumber + 1) / 6)), $content);
    216236                    $allowedBlocksCounter--;
    217237                }
    218238                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            }
    224243        }
    225244
  • bbq/trunk/README.txt

    r1705768 r1706971  
    44Requires at least: 4.0.0
    55Tested up to: 4.7.2
    6 Stable tag: 1.0.6
     6Stable tag: 1.0.7
    77
    88Плагин интеграции с сервисом bbq.money.
     
    3333== Changelog ==
    3434
     35= 1.0.7 =
     36* Добавлена возможность указывать теги (например цитаты и таблицы), в которые запрещено будет помещать рекламное объявление.
     37
    3538= 1.0.5 =
    3639* Изменена логика вставки блоков в текст. Теперь минимальное расстояние между блоками - 1500 символов.
Note: See TracChangeset for help on using the changeset viewer.