Plugin Directory

Changeset 2100357


Ignore:
Timestamp:
06/04/2019 11:09:16 AM (7 years ago)
Author:
sapeofficial
Message:

version 0.07

Location:
saperu-integration/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • saperu-integration/trunk/readme.txt

    r2097717 r2100357  
    77Tags:  sape, seo, link, site, teaser, rtb
    88Requires at least: 4.2
    9 Tested up to: 4.7
     9Tested up to: 5.2.1
    1010Stable tag: trunk
    11 Version: 0.06
     11Version: 0.07
    1212Author: Sape.ru
    1313Author URI: https://www.sape.ru/
     
    106106SapeArticles: Work without URL-template and .htaccess config
    107107
     108### v 0.07
     109Added backward compartibility for articles placement old common mode
     110
    108111## Changelog
    109112### v 0.01
     
    124127### v 0.06
    125128SapeArticles: Work without URL-template and .htaccess config
     129
     130### v 0.07
     131Added backward compartibility for articles placement old common mode
  • saperu-integration/trunk/sape/sape.php

    r2097717 r2100357  
    2121class SAPE_base
    2222{
    23     protected $_version = '1.4.5';
     23    protected $_version = '1.4.6';
    2424
    2525    protected $_verbose = false;
     
    18561856class SAPE_articles extends SAPE_base
    18571857{
     1858    const INTEGRATION_TYPE_WORDPRESS = 2;
     1859
    18581860    protected $_request_mode;
    18591861
     
    19861988
    19871989    /**
    1988      * @param $command
    1989      */
    1990     public function wp_prosess(&$newArticles, &$updateArticles, &$deletedArticles, $upload_base_dir) {
     1990     * Основной метод при работе в режиме интеграции с CMS Wordpress
     1991     *
     1992     * @param $newArticles
     1993     * @param $updateArticles
     1994     * @param $deletedArticles
     1995     * @param $upload_base_dir
     1996     */
     1997    public function wp_process(&$newArticles, &$updateArticles, &$deletedArticles, $upload_base_dir) {
    19911998        // Инициализация файла работы с WordPress
    19921999        $this->_wp_init();
    19932000
    1994         // Список статей на диспенсере
    1995         $dispenserArticles = array();
    1996         if (isset($this->_data['index']['articles'])) {
    1997             foreach ($this->_data['index']['articles'] as $article) {
    1998                 $dispenserArticles[(int)$article['id']] = array(
    1999                     'id'           => (int)$article['id'],
    2000                     'date_updated' => (int)$article['date_updated']
    2001                 );
    2002             }
    2003         }
    2004 
    2005         // Список статей из WordPress-а
    2006         $wpArticles = $this->_data['wp'];
    2007 
    2008         $dispenserArticleIds = array_keys($dispenserArticles);
    2009         $wpArticleIds        = array_keys($wpArticles);
    2010         $unionArticlesIds    = array_merge($dispenserArticleIds, $wpArticleIds);
    2011 
    2012         foreach ($unionArticlesIds as $articleId) {
    2013             // Новые статьи
    2014             if (in_array($articleId, $dispenserArticleIds) && !in_array($articleId, $wpArticleIds)) {
    2015                 $this->_load_wp_article($dispenserArticles[$articleId]);
    2016 
    2017                 $newArticles[$articleId] = array(
    2018                     'id'          => (int)$articleId,
    2019                     'title'       => $this->_data['article']['title'],
    2020                     'keywords'    => $this->_data['article']['keywords'],
    2021                     'description' => $this->_data['article']['description'],
    2022                     'body'        => $this->_data['article']['body'],
    2023                 );
    2024             }
    2025 
    2026             // Существующие статьи
    2027             if (in_array($articleId, $dispenserArticleIds) && in_array($articleId, $wpArticleIds)) {
    2028                 $this->_load_wp_article($dispenserArticles[$articleId]);
    2029 
    2030                 if (
    2031                     $this->_data['article']['title'] != $this->_data['wp'][$articleId]['wp_post_title']
    2032                     ||
    2033                     $this->_data['article']['body'] != $this->_data['wp'][$articleId]['wp_post_content']
    2034                 ) {
    2035                     $updateArticles[$articleId] = array(
     2001        if ((int)$this->_data['index']['integration_type'] == self::INTEGRATION_TYPE_WORDPRESS) {
     2002            // Список статей на диспенсере
     2003            $dispenserArticles = array();
     2004            if (isset($this->_data['index']['articles'])) {
     2005                foreach ($this->_data['index']['articles'] as $article) {
     2006                    $dispenserArticles[(int)$article['id']] = array(
     2007                        'id'           => (int)$article['id'],
     2008                        'date_updated' => (int)$article['date_updated']
     2009                    );
     2010                }
     2011            }
     2012
     2013            // Список статей из WordPress-а
     2014            $wpArticles = $this->_data['wp'];
     2015
     2016            $dispenserArticleIds = array_keys($dispenserArticles);
     2017            $wpArticleIds        = array_keys($wpArticles);
     2018            $unionArticlesIds    = array_merge($dispenserArticleIds, $wpArticleIds);
     2019
     2020            foreach ($unionArticlesIds as $articleId) {
     2021                // Новые статьи
     2022                if (in_array($articleId, $dispenserArticleIds) && !in_array($articleId, $wpArticleIds)) {
     2023                    $this->_load_wp_article($dispenserArticles[$articleId]);
     2024
     2025                    $newArticles[$articleId] = array(
    20362026                        'id'          => (int)$articleId,
    2037                         'wp_post_id'  => $this->_data['wp'][$articleId]['wp_post_id'],
    20382027                        'title'       => $this->_data['article']['title'],
    20392028                        'keywords'    => $this->_data['article']['keywords'],
     
    20422031                    );
    20432032                }
    2044             }
    2045 
    2046             // Снятые статьи
    2047             if (!in_array($articleId, $dispenserArticleIds) && in_array($articleId, $wpArticleIds)) {
    2048                 $deletedArticles[$articleId] = array(
    2049                     'id'         => (int)$articleId,
    2050                     'wp_post_id' => (int)$wpArticles[$articleId]['wp_post_id']
    2051                 );
    2052             }
    2053         }
    2054 
    2055         // Работа с изображениями
    2056         if (isset($this->_data['index']['images'])) {
    2057             foreach ($this->_data['index']['images'] as $image_uri => $image_meta) {
    2058                 $this->_load_wp_image($image_uri, $image_meta['article_id'], $upload_base_dir);
    2059             }
    2060         }
    2061     }
    2062 
     2033
     2034                // Существующие статьи
     2035                if (in_array($articleId, $dispenserArticleIds) && in_array($articleId, $wpArticleIds)) {
     2036                    $this->_load_wp_article($dispenserArticles[$articleId]);
     2037
     2038                    if (
     2039                        $this->_data['article']['title'] != $this->_data['wp'][$articleId]['wp_post_title']
     2040                        ||
     2041                        $this->_data['article']['body'] != $this->_data['wp'][$articleId]['wp_post_content']
     2042                    ) {
     2043                        $updateArticles[$articleId] = array(
     2044                            'id'          => (int)$articleId,
     2045                            'wp_post_id'  => $this->_data['wp'][$articleId]['wp_post_id'],
     2046                            'title'       => $this->_data['article']['title'],
     2047                            'keywords'    => $this->_data['article']['keywords'],
     2048                            'description' => $this->_data['article']['description'],
     2049                            'body'        => $this->_data['article']['body'],
     2050                        );
     2051                    }
     2052                }
     2053
     2054                // Снятые статьи
     2055                if (!in_array($articleId, $dispenserArticleIds) && in_array($articleId, $wpArticleIds)) {
     2056                    $deletedArticles[$articleId] = array(
     2057                        'id'         => (int)$articleId,
     2058                        'wp_post_id' => (int)$wpArticles[$articleId]['wp_post_id']
     2059                    );
     2060                }
     2061            }
     2062
     2063            // Работа с изображениями
     2064            if (isset($this->_data['index']['images'])) {
     2065                foreach ($this->_data['index']['images'] as $image_uri => $image_meta) {
     2066                    $this->_load_wp_image($image_uri, $image_meta['article_id'], $upload_base_dir);
     2067                }
     2068            }
     2069        }
     2070    }
     2071
     2072    /**
     2073     * Массив идентификаторов постов движка Wordpress,
     2074     * которые были созданы в режиме интеграции
     2075     *
     2076     * @return array
     2077     */
    20632078    public function wp_get_post_ids() {
    20642079        $wpPostIds = array();
     
    20772092    }
    20782093
     2094    /**
     2095     * Сохранение информации о постах движка Wordpress,
     2096     * которые были созданы в режиме интеграции
     2097     *
     2098     * @param        $posts
     2099     * @param string $mode
     2100     */
    20792101    public function wp_save_local_db($posts, $mode = 'add') {
    20802102        if (isset($posts) && is_array($posts)) {
     
    20952117    }
    20962118
     2119    /**
     2120     * Передача диспенсеру УРЛов размещенных статей,
     2121     * созданных в режиме интеграции
     2122     *
     2123     * @param $posts
     2124     * @param $upload_base_url
     2125     */
    20972126    public function wp_push_posts($posts, $upload_base_url) {
    20982127        $this->_set_request_mode('article');
     
    21222151    }
    21232152
     2153    /**
     2154     * Инициализация режима интеграции с CMS Wordpress
     2155     */
    21242156    protected function _wp_init()
    21252157    {
     
    21862218    }
    21872219
     2220    /**
     2221     * Загрузка статьи в режиме интеграции CMS Wordpress
     2222     *
     2223     * @param $article_meta
     2224     */
    21882225    protected function _load_wp_article($article_meta)
    21892226    {
     
    22232260    }
    22242261
     2262    /**
     2263     * Создание папки для хранения изображений статьи
     2264     * в режиме интеграции с CMS Wordpress
     2265     *
     2266     * @param $article_id
     2267     * @param $upload_base_dir
     2268     *
     2269     * @return bool
     2270     */
    22252271    protected function _prepare_wp_path_to_images($article_id, $upload_base_dir)
    22262272    {
     
    22832329    }
    22842330
     2331    /**
     2332     * Загрузка изображения статьи в режиме
     2333     * интеграции с CMS Wordpress
     2334     *
     2335     * @param $image_uri
     2336     * @param $article_id
     2337     * @param $upload_base_dir
     2338     */
    22852339    protected function _load_wp_image($image_uri, $article_id, $upload_base_dir)
    22862340    {
     
    25742628                return $this->_raise_error('Нет файла ' . $this->_db_file . '. Создать не удалось. Выставите права 777 на папку.');
    25752629            }
    2576             $this->_write($this->_db_file, 'a:0:{}');
     2630            $this->_write($this->_db_file,  serialize(array()));
    25772631        }
    25782632
  • saperu-integration/trunk/saperu-integration.php

    r2097717 r2100357  
    44Plugin URI: https://github.com/sape-ru/client-code-wordpress/releases
    55Description: Plugin for Sape.ru webmaster services integration
    6 Version: 0.06
     6Version: 0.07
    77Author: Sape.ru
    88Author URI: http://www.sape.ru/
     
    6969
    7070        // init
    71         add_action( 'init', array( &$this, 'init' ) );
     71        add_action('init', array(&$this, 'init'));
     72
     73        // updrage
     74        add_action('upgrader_process_complete', array(&$this, 'upgrade'), 10, 2);
    7275
    7376        // _SAPE_USER
     
    129132
    130133            add_action( 'wp_footer', array( &$this, 'render_remained_article' ), 1 );
     134
     135            // Выводим контент постов без внутреннего преобразования Wordpress
     136            add_filter( 'the_content', array(&$this, 'disable_transform_content') );
    131137        }
    132138    }
     
    153159            }, 2 );
    154160
    155             if ( _SAPE_USER !== '' ) {
    156                 add_shortcode('sape_tizer', array(&$this, 'shortcode_sape_tizer'));
    157                 add_filter('no_texturize_shortcodes', function ($list) {
    158                     $list[] = 'sape_tizer';
    159 
    160                     return $list;
    161                 });
    162             }
    163         }
    164 
     161            add_shortcode('sape_tizer', array(&$this, 'shortcode_sape_tizer'));
     162
     163            add_filter('no_texturize_shortcodes', function ($list) {
     164                $list[] = 'sape_tizer';
     165
     166                return $list;
     167            });
     168        }
    165169    }
    166170
     
    205209        // deny edit and delete sape article posts
    206210        add_action('user_has_cap', array( &$this, 'deny_edit_and_delete_posts' ), 10, 3);
     211    }
     212
     213    public function upgrade($upgrader_object, $options) {
     214        $current_plugin_path_name = plugin_basename( __FILE__ );
     215        if ($options['action'] == 'update' && $options['type'] == 'plugin' ) {
     216            foreach($options['plugins'] as $each_plugin){
     217                if ($each_plugin == $current_plugin_path_name) {
     218                    self::activation_hook();
     219                }
     220            }
     221        }
    207222    }
    208223
     
    220235    }
    221236
     237    function disable_transform_content($content) {
     238        try {
     239            $postId = $GLOBALS['post']->ID;
     240            if ((int)$postId > 0) {
     241                $sape_articles_post_ids = $this->_getSapeArticles()->wp_get_post_ids();
     242                if (in_array($postId, $sape_articles_post_ids)) {
     243                    remove_filter('the_content', 'wpautop');
     244                    remove_filter('the_content', 'wptexturize');
     245                }
     246            }
     247        } catch (Exception $e) {}
     248
     249        return $content;
     250    }
     251
    222252    public static function activation_hook() {
    223253        // init options
     
    324354    }
    325355
    326     public function _sape_wp_prosess() {
     356    public function _sape_wp_process() {
    327357        $newArticles     = array();
    328358        $updateArticles  = array();
     
    331361        $uploadDirInfo = wp_upload_dir();
    332362
    333         $this->_getSapeArticles()->wp_prosess($newArticles, $updateArticles, $deleteArticles, $uploadDirInfo['basedir']);
     363        $this->_getSapeArticles()->wp_process($newArticles, $updateArticles, $deleteArticles, $uploadDirInfo['basedir']);
    334364
    335365        // Блок обработки новых статей
     
    446476
    447477        // Запускаем обработку размещения статей
    448         $this->_sape_wp_prosess();
     478        $this->_sape_wp_process();
    449479
    450480        return ! empty( $text ) ? $text : $content;
     
    515545        register_setting( 'sape_base', 'sape_part_is_client', 'boolval' );
    516546        register_setting( 'sape_base', 'sape_part_is_context', 'boolval' );
    517         register_setting( 'sape_base', 'sape_part_is_articles', 'boolval' );
     547        register_setting( 'sape_base', 'sape_part_is_articles', array('type'=>'boolval' , 'sanitize_callback' => array( &$this, 'change_field_article')) );
    518548
    519549        register_setting( 'sape_base', 'sape_part_is_articles_post_author', array('type'=>'intval'));
     
    697727        $SID = get_option('sape_user');
    698728
    699         if($SID) {
     729        if ($SID) {
    700730            $file_name = $this->_getTizerImageOptions($args);
    701731            if(isset($file_name) && !is_array($file_name) && $file_name <> '') {
     
    704734                file_put_contents($_SERVER['DOCUMENT_ROOT'].'/'.$file_name, $data);
    705735            }
     736        }
     737        return $args;
     738    }
     739
     740    function change_field_article($args)
     741    {
     742        $SID = get_option('sape_user');
     743        if ($SID) {
     744            $dir = self::_getSapePath() . DIRECTORY_SEPARATOR . 'sape.php';
     745            $data = sprintf('<?php define(\'_SAPE_USER\', \'%s\');require_once(\'%s\');$sape = new SAPE_articles();echo $sape->process_request();', $SID, $dir);
     746            file_put_contents($_SERVER['DOCUMENT_ROOT'].'/'.$SID.'.php', $data);
    706747        }
    707748        return $args;
Note: See TracChangeset for help on using the changeset viewer.