Plugin Directory

Changeset 3232762


Ignore:
Timestamp:
01/31/2025 03:39:11 PM (13 months ago)
Author:
bikkel
Message:

tagging version 2.3.1

Location:
news-parser
Files:
641 added
6 edited

Legend:

Unmodified
Added
Removed
  • news-parser/trunk/inc/Parser/Abstracts/AbstractParseContent.php

    r3049937 r3232762  
    3535    protected $options;
    3636   
     37    protected $userAgens=[
     38        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${version} Safari/537.36 Edge/12.246',
     39        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${version} Safari/537.36',
     40        'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${version} Safari/537.36',
     41        'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${version} Safari/537.36',
     42    ];
    3743    protected $url;
    3844    /**
     
    8692    protected function download($url)
    8793    {
    88         $request_args=array('user-agent'=>'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36');
     94        $rendom_chrome_version=rand(70, 150).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255);
     95        $random_user_agent=str_replace('${version}',$rendom_chrome_version, $this->userAgens[array_rand($this->userAgens)]);
     96        $request_args=array(
     97            'user-agent'=>$random_user_agent,
     98            'accept-encoding'=>'gzip, deflate, br, zstd',
     99            'accept'=>'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
     100        );
    89101        $data = $this->wpRemoteGet($url, $request_args);
    90102        if (is_wp_error($data)) {
  • news-parser/trunk/inc/Parser/HTMLPatternParser.php

    r3231549 r3232762  
    7575            switch ($el_tag) {
    7676                case 'img':
    77                     if (!$this->isImageFitToContext($el)) {
    78                         break;
    79                     }
    8077                    $image_srcset = $this->parseSourceImageTag($el);
    8178                    // If the element is an image, the content will be of type array.
     
    105102                    }
    106103                    break;
     104                case 'ol':
     105                        // If the element is a list, the content will be of type array.
     106                        $el_data['content'] = array();
     107                        foreach ($el->find('li') as $li) {
     108                            $el_data['content'][] = $this->removeTags($li->innertext);
     109                        }
     110                        break;
    107111                case 'video':
    108112                    // Find the YouTube video ID.
  • news-parser/trunk/inc/Parser/Modifiers/AdapterModifiers/Before/GeneratePostBodyWithAI.php

    r3231549 r3232762  
    5252    private function preparePostBody($body, $savePostStructure)
    5353    {
    54         return $savePostStructure ? $this->encodeBodyWithStructure($body) : $this->encodeBody($body);
     54        $filtered_body = array_filter($body, function ($el) {
     55            return $el['content'] !== '';
     56        });
     57        return $savePostStructure ? $this->encodeBodyWithStructure($filtered_body) : $this->encodeBody($filtered_body);
    5558    }
    5659
     
    8891    protected function processBodyArray($ai_request_options, $prompt, $body, $title)
    8992    {
    90         $result = [];
     93       $result=[];
    9194        foreach ($body as $block) {
    9295            if ($block['ai']) {
    93                 $ai_request_options['messages'][0]['content'] = $this->preparePrompt($prompt, $block['content'], $title);
    94                 $result[] =  [
    95                     'ai' => true,
    96                     'content'=>$this->aiServeceProvider->chat($ai_request_options)
    97                 ];
    98             } else {
    99                 $result[] = $block;
    100             }
     96                if($block['element']['content']==='') continue;
     97                if (is_array($block['element']['content'])) {
     98                    $block['element']['content'] = array_map(function($content) use ($ai_request_options, $prompt, $title) {
     99                        $ai_request_options['messages'][0]['content'] = $this->preparePrompt($prompt, $content, $title);
     100                        return  $this->aiServeceProvider->chat($ai_request_options);
     101                    }, $block['element']['content']);
     102                   
     103                }  else {
     104                    $ai_request_options['messages'][0]['content'] = $this->preparePrompt($prompt, $block['element']['content'], $title);
     105                    $block['element']['content'] =  $this->aiServeceProvider->chat($ai_request_options);
     106                }
     107            }
     108            $result[]=$block;
    101109        }
    102110
     
    126134       
    127135        foreach ($body as $el){
    128             if (is_array($el)){
     136            if ($el['tagName'] !== 'p') {
    129137                $result[]=$el;
    130138                continue;
    131139            }
    132             $el_array = explode(PHP_EOL, $el);
     140            $el_array = explode(PHP_EOL, $el['content']);
    133141            $sub_result_array = [];
    134142            foreach ($el_array as $el_part) {
     
    156164    protected function unwrapBody($body){
    157165       return array_map(function ($el) {
    158             return $el['content'];
     166            return $el['element'];
    159167        }, $body);
    160168    }
     
    168176            } else if ($element['tagName'] === 'h1' || $element['tagName'] === 'h2' || $element['tagName'] === 'h3' || $element['tagName'] === 'h4') {
    169177                $contentBlock.=PHP_EOL.self::HEADER_SYMBOL.$element['content'].self::HEADER_SYMBOL.PHP_EOL;
     178            } else if ($element['tagName'] === 'li') {
     179                $contentBlock.=PHP_EOL.'- '.$element['content'];
     180            } else if ($element['tagName'] === 'ol') {
     181                $contentBlock.=PHP_EOL.'- '.$element['content'];
    170182            } else {
    171183                if ($contentBlock!=='') {
    172184                    $mergedBody[] =[
    173185                        'ai'=>true,
    174                         'content'=>$contentBlock
     186                        'element'=>[
     187                            'tagName'=>'p',
     188                            'content'=>$contentBlock
     189                        ]
    175190                    ];
     191                    $contentBlock='';
    176192                }
    177193                $mergedBody[] =['ai'=>false,
    178                     'content'=>$element
     194                    'element'=>$element
    179195                ];
    180196            }
     
    183199            $mergedBody[] =[
    184200                'ai'=>true,
    185                 'content'=>$contentBlock
     201                'element'=>[
     202                    'tagName'=>'p',
     203                    'content'=>$contentBlock
     204                ]
    186205            ];
    187206        }
     
    193212        $contentBlock='';
    194213        foreach ($body as $element) {
    195             if ($element['tagName'] === 'p'||$element['tagName'] === 'span') {
    196                 $contentBlock=$element['content'];
     214            if ($element['tagName'] === 'p'||$element['tagName'] === 'span'||$element['tagName'] === 'div') {
     215                $mergedBody[] =[
     216                    'ai'=>true,
     217                    'element'=>$element,
     218                ];
    197219            } else if ($element['tagName'] === 'h1' || $element['tagName'] === 'h2' || $element['tagName'] === 'h3' || $element['tagName'] === 'h4') {
    198                 $contentBlock=self::HEADER_SYMBOL.$element['content'].self::HEADER_SYMBOL.PHP_EOL;
    199             } else {
    200                 $mergedBody[] =['ai'=>false,
    201                     'content'=>$element
    202                 ];
    203                 continue;
    204             }
    205             $mergedBody[] =['ai'=>true,
    206                 'content'=>$contentBlock
    207             ];
     220                $mergedBody[] =[
     221                    'ai'=>true,
     222                    'element'=>$element
     223                ];
     224            } else if($element['tagName'] === 'li'||$element['tagName'] === 'ol') {
     225                $mergedBody[] =[
     226                    'ai'=>true,
     227                    'element'=>$element,
     228                ];
     229            }else if($element['tagName'] === 'ul') {
     230                $mergedBody[] =[
     231                    'ai'=>true,
     232                    'element'=>$element,
     233                ];
     234
     235            }   else {
     236                $mergedBody[] =[
     237                    'ai'=>false,
     238                    'element'=>$element
     239                ];
     240               
     241            }
     242           
    208243        }
    209244        return $mergedBody;
  • news-parser/trunk/inc/Utils/AdapterGuttenberg.php

    r3231549 r3232762  
    4949                    break;
    5050                case 'ul':
     51                case 'ol':   
    5152                    $post_content.=$this->listBlock($el);
    5253                    break;
     
    161162    protected function listBlock($el)
    162163    {
    163         $list_begin='<!-- wp:list --><ul>';
     164        $el_tag=$el['tagName'];
     165        $list_begin="<!-- wp:list --><$el_tag>";
    164166        $list='';
    165         $list_end='</ul><!-- /wp:list -->';
     167        $list_end="</$el_tag><!-- /wp:list -->";
    166168        $li_elements=$el['content'];
    167169        foreach ($li_elements as $li) {
  • news-parser/trunk/news-parser.php

    r3231549 r3232762  
    44Plugin URI: https://www.news-parser.com
    55Description: Parse full text news from RSS Feed
    6 Version: 2.3.0
     6Version: 2.3.1
    77Author: Evgeny S.Zalevskiy <2600@ukr.net>
    88Author URI: https://github.com/zalevsk1y/
     
    1515
    1616
    17 define('NEWS_PARSER_PLUGIN_VERSION', '2.3.0');
     17define ('NEWS_PARSER_PLUGIN_VERSION', '2.3.1');
    1818define ("NEWS_PARSER_PLUGIN_MODE","production");
    1919
  • news-parser/trunk/readme.txt

    r3231549 r3232762  
    77Requires at least: 5.2.0
    88Tested up to: 6.7.1
    9 Stable tag: 2.3.0
     9Stable tag: 2.3.1
    1010License: MIT
    1111License URI: https://opensource.org/licenses/MIT
     
    171171== Changelog ==
    172172
    173 = 2.3.0 - 09-12-24 =
     173= 2.3.1 - 31-01-25 =
     174
     175* Added: Visual Constructor shows saved template data.
     176* Fix: some bugs.
     177
     178= 2.3.0 - 29-01-25 =
    174179
    175180* Added: Visual Constructor shows saved template data.
Note: See TracChangeset for help on using the changeset viewer.