Changeset 2100357
- Timestamp:
- 06/04/2019 11:09:16 AM (7 years ago)
- Location:
- saperu-integration/trunk
- Files:
-
- 3 edited
-
readme.txt (modified) (3 diffs)
-
sape/sape.php (modified) (11 diffs)
-
saperu-integration.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
saperu-integration/trunk/readme.txt
r2097717 r2100357 7 7 Tags: sape, seo, link, site, teaser, rtb 8 8 Requires at least: 4.2 9 Tested up to: 4.79 Tested up to: 5.2.1 10 10 Stable tag: trunk 11 Version: 0.0 611 Version: 0.07 12 12 Author: Sape.ru 13 13 Author URI: https://www.sape.ru/ … … 106 106 SapeArticles: Work without URL-template and .htaccess config 107 107 108 ### v 0.07 109 Added backward compartibility for articles placement old common mode 110 108 111 ## Changelog 109 112 ### v 0.01 … … 124 127 ### v 0.06 125 128 SapeArticles: Work without URL-template and .htaccess config 129 130 ### v 0.07 131 Added backward compartibility for articles placement old common mode -
saperu-integration/trunk/sape/sape.php
r2097717 r2100357 21 21 class SAPE_base 22 22 { 23 protected $_version = '1.4. 5';23 protected $_version = '1.4.6'; 24 24 25 25 protected $_verbose = false; … … 1856 1856 class SAPE_articles extends SAPE_base 1857 1857 { 1858 const INTEGRATION_TYPE_WORDPRESS = 2; 1859 1858 1860 protected $_request_mode; 1859 1861 … … 1986 1988 1987 1989 /** 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) { 1991 1998 // Инициализация файла работы с WordPress 1992 1999 $this->_wp_init(); 1993 2000 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( 2036 2026 'id' => (int)$articleId, 2037 'wp_post_id' => $this->_data['wp'][$articleId]['wp_post_id'],2038 2027 'title' => $this->_data['article']['title'], 2039 2028 'keywords' => $this->_data['article']['keywords'], … … 2042 2031 ); 2043 2032 } 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 */ 2063 2078 public function wp_get_post_ids() { 2064 2079 $wpPostIds = array(); … … 2077 2092 } 2078 2093 2094 /** 2095 * Сохранение информации о постах движка Wordpress, 2096 * которые были созданы в режиме интеграции 2097 * 2098 * @param $posts 2099 * @param string $mode 2100 */ 2079 2101 public function wp_save_local_db($posts, $mode = 'add') { 2080 2102 if (isset($posts) && is_array($posts)) { … … 2095 2117 } 2096 2118 2119 /** 2120 * Передача диспенсеру УРЛов размещенных статей, 2121 * созданных в режиме интеграции 2122 * 2123 * @param $posts 2124 * @param $upload_base_url 2125 */ 2097 2126 public function wp_push_posts($posts, $upload_base_url) { 2098 2127 $this->_set_request_mode('article'); … … 2122 2151 } 2123 2152 2153 /** 2154 * Инициализация режима интеграции с CMS Wordpress 2155 */ 2124 2156 protected function _wp_init() 2125 2157 { … … 2186 2218 } 2187 2219 2220 /** 2221 * Загрузка статьи в режиме интеграции CMS Wordpress 2222 * 2223 * @param $article_meta 2224 */ 2188 2225 protected function _load_wp_article($article_meta) 2189 2226 { … … 2223 2260 } 2224 2261 2262 /** 2263 * Создание папки для хранения изображений статьи 2264 * в режиме интеграции с CMS Wordpress 2265 * 2266 * @param $article_id 2267 * @param $upload_base_dir 2268 * 2269 * @return bool 2270 */ 2225 2271 protected function _prepare_wp_path_to_images($article_id, $upload_base_dir) 2226 2272 { … … 2283 2329 } 2284 2330 2331 /** 2332 * Загрузка изображения статьи в режиме 2333 * интеграции с CMS Wordpress 2334 * 2335 * @param $image_uri 2336 * @param $article_id 2337 * @param $upload_base_dir 2338 */ 2285 2339 protected function _load_wp_image($image_uri, $article_id, $upload_base_dir) 2286 2340 { … … 2574 2628 return $this->_raise_error('Нет файла ' . $this->_db_file . '. Создать не удалось. Выставите права 777 на папку.'); 2575 2629 } 2576 $this->_write($this->_db_file, 'a:0:{}');2630 $this->_write($this->_db_file, serialize(array())); 2577 2631 } 2578 2632 -
saperu-integration/trunk/saperu-integration.php
r2097717 r2100357 4 4 Plugin URI: https://github.com/sape-ru/client-code-wordpress/releases 5 5 Description: Plugin for Sape.ru webmaster services integration 6 Version: 0.0 66 Version: 0.07 7 7 Author: Sape.ru 8 8 Author URI: http://www.sape.ru/ … … 69 69 70 70 // 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); 72 75 73 76 // _SAPE_USER … … 129 132 130 133 add_action( 'wp_footer', array( &$this, 'render_remained_article' ), 1 ); 134 135 // Выводим контент постов без внутреннего преобразования Wordpress 136 add_filter( 'the_content', array(&$this, 'disable_transform_content') ); 131 137 } 132 138 } … … 153 159 }, 2 ); 154 160 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 } 165 169 } 166 170 … … 205 209 // deny edit and delete sape article posts 206 210 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 } 207 222 } 208 223 … … 220 235 } 221 236 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 222 252 public static function activation_hook() { 223 253 // init options … … 324 354 } 325 355 326 public function _sape_wp_pro sess() {356 public function _sape_wp_process() { 327 357 $newArticles = array(); 328 358 $updateArticles = array(); … … 331 361 $uploadDirInfo = wp_upload_dir(); 332 362 333 $this->_getSapeArticles()->wp_pro sess($newArticles, $updateArticles, $deleteArticles, $uploadDirInfo['basedir']);363 $this->_getSapeArticles()->wp_process($newArticles, $updateArticles, $deleteArticles, $uploadDirInfo['basedir']); 334 364 335 365 // Блок обработки новых статей … … 446 476 447 477 // Запускаем обработку размещения статей 448 $this->_sape_wp_pro sess();478 $this->_sape_wp_process(); 449 479 450 480 return ! empty( $text ) ? $text : $content; … … 515 545 register_setting( 'sape_base', 'sape_part_is_client', 'boolval' ); 516 546 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')) ); 518 548 519 549 register_setting( 'sape_base', 'sape_part_is_articles_post_author', array('type'=>'intval')); … … 697 727 $SID = get_option('sape_user'); 698 728 699 if ($SID) {729 if ($SID) { 700 730 $file_name = $this->_getTizerImageOptions($args); 701 731 if(isset($file_name) && !is_array($file_name) && $file_name <> '') { … … 704 734 file_put_contents($_SERVER['DOCUMENT_ROOT'].'/'.$file_name, $data); 705 735 } 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); 706 747 } 707 748 return $args;
Note: See TracChangeset
for help on using the changeset viewer.