Changeset 1853982
- Timestamp:
- 04/06/2018 09:37:51 AM (8 years ago)
- Location:
- fv-community-news/trunk
- Files:
-
- 5 added
- 2 deleted
- 30 edited
-
. (modified) (1 prop)
-
composer.json (modified) (2 diffs)
-
config/default.config.php (modified) (2 diffs)
-
fv-community-news.php (modified) (9 diffs)
-
fvcn-theme/fvcn/content-single-post.php (modified) (1 diff)
-
fvcn-theme/fvcn/css/fvcn-theme.css (modified) (2 diffs)
-
fvcn-theme/fvcn/css/fvcn-theme.min.css (modified) (1 diff)
-
fvcn-theme/fvcn/form-post.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
src/Admin/Admin.php (modified) (5 diffs)
-
src/Admin/Dashboard/Widget/RecentPosts.php (modified) (5 diffs)
-
src/Admin/Post/Edit.php (modified) (3 diffs)
-
src/Admin/Post/Moderation.php (modified) (5 diffs)
-
src/Akismet/Handler.php (modified) (2 diffs)
-
src/Autoloader.php (modified) (4 diffs)
-
src/Container/Container.php (modified) (2 diffs)
-
src/Factory/Post/Controller.php (modified) (1 diff)
-
src/Hook/Collection.php (modified) (1 diff)
-
src/Hook/Controller.php (modified) (1 diff)
-
src/Hook/Init.php (modified) (4 diffs)
-
src/Hook/Mail.php (added)
-
src/Hook/Syncer.php (modified) (1 diff)
-
src/Installer.php (modified) (2 diffs)
-
src/Post/Controller.php (modified) (9 diffs)
-
src/Post/Mapper.php (modified) (9 diffs)
-
src/Post/PostType.php (deleted)
-
src/Post/Status.php (added)
-
src/Post/Type.php (added)
-
src/Post/TypeRegistrar.php (added)
-
src/Syncer/Api/Api.php (modified) (2 diffs)
-
src/Syncer/Syncer.php (modified) (5 diffs)
-
src/Template (deleted)
-
src/Version.php (modified) (1 diff)
-
src/View/AjaxForm.php (modified) (3 diffs)
-
src/Widget/Form.php (modified) (1 diff)
-
src/Widget/ListPosts.php (modified) (2 diffs)
-
src/template-functions.php (added)
Legend:
- Unmodified
- Added
- Removed
-
fv-community-news/trunk
- Property svn:ignore
-
old new 2 2 .gitignore 3 3 .idea 4 phpunit.xml 5 phpunit.xml.dist 6 test 7 vendor 8 composer.lock
-
- Property svn:ignore
-
fv-community-news/trunk/composer.json
r1806332 r1853982 3 3 "description": "FV Community News", 4 4 "type": "project", 5 "keywords": [ 6 "Frank", 7 "Verhoeven", 8 "Community", 9 "News" 5 "keywords": ["Frank", "Verhoeven", "Community", "News"], 6 "homepage": "https://frankverhoeven.me/wordpress-plugin-fv-community-news/", 7 "authors": [ 8 { 9 "name": "Frank Verhoeven", 10 "email": "[email protected]" 11 } 10 12 ], 11 "homepage": "https://frankverhoeven.me/wordpress-plugin-fv-community-news/",12 13 "minimum-stability": "dev", 13 14 "prefer-stable": true, … … 15 16 "php": "^7.0" 16 17 }, 18 "require-dev": { 19 "phpunit/phpunit": "^6.5" 20 }, 17 21 "autoload": { 18 22 "psr-4": { 19 23 "FvCommunityNews\\": "src/" 20 24 } 25 }, 26 "autoload-dev": { 27 "psr-4": { 28 "FvCommunityNews\\Test\\": "test/" 29 } 21 30 } 22 31 } -
fv-community-news/trunk/config/default.config.php
r1843050 r1853982 1 1 <?php 2 3 use FvCommunityNews\Version; 2 4 3 5 return [ … … 5 7 * @var int Current plugin version 6 8 */ 7 '_fvcn_version' => FvCommunityNews::VERSION,9 '_fvcn_version' => Version::getCurrentVersion(), 8 10 9 11 /** -
fv-community-news/trunk/fv-community-news.php
r1843050 r1853982 5 5 * Plugin URI: https://frankverhoeven.me/wordpress-plugin-fv-community-news/ 6 6 * Description: Allow visitors of your site to submit articles. 7 * Version: 3. 2.27 * Version: 3.3 8 8 * Author: Frank Verhoeven 9 9 * Author URI: https://frankverhoeven.me/ … … 15 15 use FvCommunityNews\Hook\Collection as HookCollection; 16 16 17 if (! defined('ABSPATH')) exit;17 if (!\defined('ABSPATH')) exit; 18 18 19 19 /** … … 24 24 final class FvCommunityNews 25 25 { 26 /**27 * @var string28 */29 const VERSION = '3.2.1';30 /**31 * @var string32 */33 const DIR = __DIR__;34 /**35 * @var string36 */37 const FILE = __FILE__;38 26 /** 39 27 * @var Container … … 47 35 public function __construct() 48 36 { 49 register_activation_hook(__FILE__, [static::class, 'activation']);50 register_deactivation_hook(__FILE__, [static::class, 'deactivation']);37 \register_activation_hook(__FILE__, [static::class, 'activation']); 38 \register_deactivation_hook(__FILE__, [static::class, 'deactivation']); 51 39 } 52 40 … … 80 68 $autoloader->register(); 81 69 82 $files = [ 83 '/src/Template/fvcn-core-theme.php', 84 '/src/Template/common-functions.php', 85 '/src/Template/options-functions.php', 86 '/src/Template/post-functions.php', 87 '/src/Template/tag-functions.php', 88 '/src/Template/user-functions.php', 89 ]; 90 91 foreach ($files as $file) { 92 $autoloader->loadFile(__DIR__ . $file); 93 } 70 $autoloader->loadFile(__DIR__ . '/src/template-functions.php'); 94 71 } 95 72 … … 101 78 public static function activation() 102 79 { 103 do_action('fvcn_activation');104 register_uninstall_hook(__FILE__, [static::class, 'uninstall']);80 \do_action('fvcn_activation'); 81 \register_uninstall_hook(__FILE__, [static::class, 'uninstall']); 105 82 } 106 83 … … 112 89 public static function deactivation() 113 90 { 114 do_action('fvcn_deactivation');91 \do_action('fvcn_deactivation'); 115 92 } 116 93 … … 122 99 public static function uninstall() 123 100 { 124 do_action('fvcn_uninstall');101 \do_action('fvcn_uninstall'); 125 102 } 126 103 } … … 135 112 $fvcn->start(); 136 113 } catch (Exception $e) { 137 if ( defined('WP_DEBUG') && true === WP_DEBUG) {114 if (\defined('WP_DEBUG') && true === WP_DEBUG) { 138 115 echo '<h3>' . $e->getMessage() . '</h3><pre>' . $e->getTraceAsString() . '</pre>'; 139 116 } 140 117 141 error_log('fvcn: ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString());118 \error_log('fvcn: ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString()); 142 119 } 143 120 -
fv-community-news/trunk/fvcn-theme/fvcn/content-single-post.php
r1806332 r1853982 29 29 </div><!-- .entry-content --> 30 30 31 <div class=" fvcn-post-meta">31 <div class="entry-meta fvcn-post-meta"> 32 32 <span class="fvcn-post-tags"> 33 <?php fvcn_post_tag_list(0, ['before'=>__('Tags: ', 'fvcn'), 'after'=>' ']); ?>33 <?php fvcn_post_tag_list(0, ['before'=>__('Tags: ', 'fvcn'), 'after'=>' | ']); ?> 34 34 </span> 35 | 36 <span class="fvcn-post-rating"> 37 <?php if (fvcn_is_post_rated_by_current_user()) : ?> 38 <?php _e('Rating:', 'fvcn'); ?> 39 <strong><?php fvcn_post_rating(); ?></strong> 40 <?php else : ?> 41 <?php _e('Rate this post:', 'fvcn'); ?> 42 <a href="<?php fvcn_post_rating_decrement_link(); ?>" rel="nofollow">-</a> 43 <strong><?php fvcn_post_rating(); ?></strong> 44 <a href="<?php fvcn_post_rating_increment_link(); ?>" rel="nofollow">+</a> 45 <?php endif; ?> 35 <span class="fvcn-post-likes"> 36 <?php fvcn_is_post_liked_by_current_user() ? fvcn_post_unlike_button() : fvcn_post_like_button(); ?> 46 37 </span> 47 38 </div><!-- .entry-meta --> -
fv-community-news/trunk/fvcn-theme/fvcn/css/fvcn-theme.css
r1806332 r1853982 4 4 * @author Frank Verhoeven <[email protected]> 5 5 */ 6 7 .fvcn-post-form-new-post label { 8 display: block; 9 margin: 5px 0 3px; 10 } 6 11 7 12 .fvcn-post-thumbnail { … … 32 37 33 38 .fvcn-post-link {} 39 40 .fvcn-like-form { 41 display: inline-block; 42 } 43 44 .fvcn-like-button, 45 .fvcn-unlike-button { 46 border: none; 47 background: transparent !important; 48 cursor: pointer; 49 padding: 0; 50 color: #000; 51 } 52 53 .fvcn-like-button svg { 54 color: #000; 55 } 56 57 .fvcn-unlike-button svg, 58 .fvcn-like-button:hover svg { 59 color: #c55; 60 } 34 61 35 62 -
fv-community-news/trunk/fvcn-theme/fvcn/css/fvcn-theme.min.css
r1806332 r1853982 1 .fvcn-post- thumbnail{float:left;padding:0;margin:.3em 10px 0 0;display:block}.fvcn-post-content,.fvcn-post-meta{margin:0!important;width:100%!important}.fvcn-list-posts-widget .fvcn-post-thumbnail{margin:.4em 5px 0 0}.fvcn-list-posts-widget .fvcn-post-content:after{clear:both;content:" ";display:table}.fvcn-view-all{text-align:right}.fvcn-template-notice{padding:.1em .4em!important;margin:5px 0!important;border-radius:4px;background-color:#ffffe0;border:1px solid #e6db55;color:#000;clear:both;box-shadow:0 1px 1px #fff inset}.fvcn-template-notice.error{background-color:#ffebe8;border-color:#e39387}.fvcn-template-notice li{list-style:none!important;color:#000!important;font-size:.8em!important;padding:0!important;margin:0!important;border:none!important}.fvcn_form_widget .fvcn-post-form input[type="text"],.fvcn_form_widget .fvcn-post-form input[type="file"],.fvcn_form_widget .fvcn-post-form textarea{width:100%}.fvcn-post-form-loader{margin-top:1.5em;margin-left:.5em;display:none}.fvcn-post-form-loader-img{width:1em;height:1em;overflow:hidden;-webkit-animation:spin 1.5s linear infinite;-moz-animation:spin 1.5s linear infinite;animation:spin 1.5s linear infinite}@-moz-keyframes spin{100%{-moz-transform:rotate(360deg)}}@-webkit-keyframes spin{100%{-webkit-transform:rotate(360deg)}}@keyframes spin{100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}1 .fvcn-post-form-new-post label{display:block;margin:5px 0 3px}.fvcn-post-thumbnail{float:left;padding:0;margin:0.3em 10px 0 0;display:block}.fvcn-post-content,.fvcn-post-meta{margin:0 !important;width:100% !important}.fvcn-list-posts-widget .fvcn-post-thumbnail{margin:0.4em 5px 0 0}.fvcn-list-posts-widget .fvcn-post-content:after{clear:both;content:" ";display:table}.fvcn-view-all{text-align:right}.fvcn-like-form{display:inline-block}.fvcn-like-button,.fvcn-unlike-button{border:none;background:transparent !important;cursor:pointer;padding:0;color:#000}.fvcn-like-button svg{color:#000}.fvcn-unlike-button svg,.fvcn-like-button:hover svg{color:#c55}.fvcn-template-notice{padding:.1em .4em !important;margin:5px 0 !important;border-radius:4px;background-color:#ffffe0;border:1px solid #e6db55;color:#000;clear:both;-webkit-box-shadow:0 1px 1px #fff inset;box-shadow:0 1px 1px #fff inset}.fvcn-template-notice.error{background-color:#ffebe8;border-color:#e39387}.fvcn-template-notice li{list-style:none !important;color:#000 !important;font-size:.8em !important;padding:0 !important;margin:0 !important;border:none !important}.fvcn_form_widget .fvcn-post-form input[type="text"],.fvcn_form_widget .fvcn-post-form input[type="file"],.fvcn_form_widget .fvcn-post-form textarea{width:100%}.fvcn-post-form-loader{margin-top:1.5em;margin-left:.5em;display:none}.fvcn-post-form-loader-img{width:1em;height:1em;overflow:hidden;-webkit-animation:spin 1.5s linear infinite;animation:spin 1.5s linear infinite}@-webkit-keyframes spin{100%{-webkit-transform:rotate(360deg)}}@keyframes spin{100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}} -
fv-community-news/trunk/fvcn-theme/fvcn/form-post.php
r1810381 r1853982 143 143 <?php fvcn_post_form_fields(); ?> 144 144 145 146 147 145 <?php do_action('fvcn_post_form_extras_bottom'); ?> 148 146 </form> -
fv-community-news/trunk/readme.txt
r1843050 r1853982 6 6 Requires at least: 4.8 7 7 Tested up to: 4.9 8 Stable tag: 3. 2.28 Stable tag: 3.3 9 9 10 10 Give the visitors of your site the ability to submit their news to you, and list it in a nice news feed. … … 134 134 135 135 136 = 3.3 = 137 138 * New: Posts now have a like button so visitors can like your community news. 139 * Change: The old rating system was removed and replaced by a like system. 140 * Improvement: Various bugfixes & improvements. 141 142 136 143 = 3.2.2 = 137 144 -
fv-community-news/trunk/src/Admin/Admin.php
r1810381 r1853982 9 9 use FvCommunityNews\Admin\Settings\Settings; 10 10 use FvCommunityNews\Container\Container; 11 use FvCommunityNews\Post\ PostType;11 use FvCommunityNews\Post\Type as PostType; 12 12 13 13 /** … … 70 70 } 71 71 72 $postType = PostType:: POST_TYPE_KEY;72 $postType = PostType::post(); 73 73 74 74 switch ($pageId) { … … 124 124 $menuIconUrl = $registry['pluginUrl'] . 'public/images/menu.png'; 125 125 $menuIconUrl2x = $registry['pluginUrl'] . 'public/images/[email protected]'; 126 $postClass = sanitize_html_class(PostType:: POST_TYPE_KEY);126 $postClass = sanitize_html_class(PostType::post()); 127 127 128 128 ?> … … 184 184 { 185 185 $adminFormPage = add_submenu_page( 186 'edit.php?post_type=' . PostType:: POST_TYPE_KEY,186 'edit.php?post_type=' . PostType::post(), 187 187 __('FV Community News Form', 'fvcn'), 188 188 __('Form', 'fvcn'), … … 194 194 195 195 add_submenu_page( 196 'edit.php?post_type=' . PostType:: POST_TYPE_KEY,196 'edit.php?post_type=' . PostType::post(), 197 197 __('FV Community News Settings', 'fvcn'), 198 198 __('Settings', 'fvcn'), -
fv-community-news/trunk/src/Admin/Dashboard/Widget/RecentPosts.php
r1810381 r1853982 5 5 use FvCommunityNews\Config\AbstractConfig as Config; 6 6 use FvCommunityNews\Post\Mapper as PostMapper; 7 use FvCommunityNews\Post\PostType; 7 use FvCommunityNews\Post\Status; 8 use FvCommunityNews\Post\Type as PostType; 8 9 9 10 /** … … 256 257 $options = [ 257 258 'posts_per_page' => $this->config['_fvcn_dashboard_rp_num'], 258 'post_status' => PostType::STATUS_PUBLISH . ',' . PostType::STATUS_PENDING259 'post_status' => Status::publish() . ',' . Status::pending() 259 260 ]; 260 261 … … 268 269 $class = 'fvcn-post '; 269 270 270 if ( PostType::STATUS_PENDING== fvcn_get_post_status()) {271 if (Status::pending() == fvcn_get_post_status()) { 271 272 $class .= 'pending '; 272 273 } else { … … 320 321 'post' => fvcn_get_post_id(), 321 322 'action' => 'trash' 322 ], 'post.php'), 'trash-' . PostType:: POST_TYPE_KEY. '_' . fvcn_get_post_id()));323 ], 'post.php'), 'trash-' . PostType::post() . '_' . fvcn_get_post_id())); 323 324 ?> 324 325 <span class="publish"><a href="<?= $publish_uri; ?>"><?php _e('Publish', 'fvcn'); ?></a></span> … … 337 338 338 339 <p id="fvcn-dashboard-view-links"> 339 <a href="edit.php?post_type=<?= PostType:: POST_TYPE_KEY?>"><?php _e('View All', 'fvcn'); ?></a>340 <a href="edit.php?post_type=<?= PostType::post() ?>"><?php _e('View All', 'fvcn'); ?></a> 340 341 </p> 341 342 -
fv-community-news/trunk/src/Admin/Post/Edit.php
r1806332 r1853982 3 3 namespace FvCommunityNews\Admin\Post; 4 4 5 use FvCommunityNews\Post\ PostType;5 use FvCommunityNews\Post\Type as PostType; 6 6 7 7 /** … … 23 23 public function __construct() 24 24 { 25 $this->postType = PostType:: POST_TYPE_KEY;25 $this->postType = PostType::post(); 26 26 27 27 add_action('add_meta_boxes', [$this, 'registerMetaboxPostInfo']); … … 117 117 --> 118 118 <p> 119 <label for="fvcn_post_ rating"><?php _e('Rating', 'fvcn'); ?></label>120 <input type="text" name="fvcn_post_ rating" id="fvcn_post_rating" value="<?= get_post_meta($id, '_fvcn_post_rating', true); ?>" style="width: 100%;" disabled>119 <label for="fvcn_post_likes"><?php _e('Likes', 'fvcn'); ?></label> 120 <input type="text" name="fvcn_post_likes" id="fvcn_post_likes" value="<?= get_post_meta($id, '_fvcn_post_likes', true); ?>" style="width: 100%;" disabled> 121 121 </p> 122 122 -
fv-community-news/trunk/src/Admin/Post/Moderation.php
r1810381 r1853982 4 4 5 5 use FvCommunityNews\Post\Mapper as PostMapper; 6 use FvCommunityNews\Post\PostType; 6 use FvCommunityNews\Post\Status; 7 use FvCommunityNews\Post\Type as PostType; 7 8 8 9 /** … … 28 29 { 29 30 $this->postMapper = $postMapper; 30 $this->postType = PostType:: POST_TYPE_KEY;31 $this->postType = PostType::post(); 31 32 32 33 $this->setupActions() … … 78 79 'ps' => [ 79 80 'all' => 'all', 80 'public' => PostType::STATUS_PUBLISH,81 'pending' => PostType::STATUS_PENDING,82 'spam' => PostType::STATUS_SPAM,83 'trash' => PostType::STATUS_TRASH81 'public' => Status::publish(), 82 'pending' => Status::pending(), 83 'spam' => Status::spam(), 84 'trash' => Status::trash(), 84 85 ], 85 86 'locale'=> [ … … 114 115 check_admin_referer('fvcn-bulk-action', '_fvcn_bulk_action'); 115 116 116 if (fvcn_has_posts(['post_status' =>PostType::STATUS_SPAM, 'posts_per_page'=>-1])) {117 if (fvcn_has_posts(['post_status' => Status::spam(), 'posts_per_page' => -1])) { 117 118 while (fvcn_posts()) { 118 119 fvcn_the_post(); … … 351 352 wp_nonce_field('fvcn-bulk-action', '_fvcn_bulk_action'); 352 353 353 if (isset($_GET['post_status']) && PostType::STATUS_SPAM== $_GET['post_status']) {354 if (isset($_GET['post_status']) && Status::spam() == $_GET['post_status']) { 354 355 submit_button(__('Remove All Spam', 'fvcn'), 'button-secondary apply', 'fvcn-remove-all-spam-submit', false); 355 356 } -
fv-community-news/trunk/src/Akismet/Handler.php
r1806332 r1853982 4 4 5 5 use FvCommunityNews\Post\Mapper; 6 use FvCommunityNews\Post\ PostType;6 use FvCommunityNews\Post\Status; 7 7 8 8 /** … … 103 103 $method = 'submitSpam'; 104 104 } elseif ('fvcn_publish_post' == $filter) { 105 if ( PostType::STATUS_SPAM!= fvcn_get_post_status($postId)) {105 if (Status::spam() != fvcn_get_post_status($postId)) { 106 106 return $this; 107 107 } -
fv-community-news/trunk/src/Autoloader.php
r1760963 r1853982 44 44 public function register($prepend = false) 45 45 { 46 spl_autoload_register([$this, 'autoload'], true, $prepend);46 \spl_autoload_register([$this, 'autoload'], true, $prepend); 47 47 } 48 48 … … 52 52 public function unregister() 53 53 { 54 spl_autoload_unregister([$this, 'autoload']);54 \spl_autoload_unregister([$this, 'autoload']); 55 55 } 56 56 … … 63 63 { 64 64 foreach ($this->prefixes as $prefix => $path) { 65 $len = strlen($prefix);65 $len = \strlen($prefix); 66 66 67 if (0 === strncmp($prefix, $class, $len)) {68 $relativeClass = substr($class, $len);69 $file = $path . str_replace('\\', '/', $relativeClass) . '.php';67 if (0 === \strncmp($prefix, $class, $len)) { 68 $relativeClass = \substr($class, $len); 69 $file = $path . \str_replace('\\', '/', $relativeClass) . '.php'; 70 70 71 71 $this->loadFile($file); … … 83 83 // Prevent access to $this/self 84 84 (function() use ($file) { 85 if ( file_exists($file)) {85 if (\file_exists($file)) { 86 86 require $file; 87 87 } -
fv-community-news/trunk/src/Container/Container.php
r1825546 r1853982 22 22 23 23 /** 24 * __construct()25 *26 24 * @param array $factories 27 25 */ … … 38 36 * @return mixed Entry. 39 37 */ 40 public function get( $id)38 public function get(string $id) 41 39 { 42 40 if (!$this->has($id)) { -
fv-community-news/trunk/src/Factory/Post/Controller.php
r1810381 r1853982 26 26 { 27 27 return new PostController( 28 $container->get('Config'), 28 29 $container->get(Mapper::class), 29 30 $container->get(Form::class) -
fv-community-news/trunk/src/Hook/Collection.php
r1843050 r1853982 136 136 137 137 'template_include' => [ 138 ['function' => 'fvcn_template_include'],139 ],140 'fvcn_template_include' => [141 138 [ 142 139 'function' => 'fvcn_theme_compat_template_include', -
fv-community-news/trunk/src/Hook/Controller.php
r1825546 r1853982 36 36 $this->postController->createPost(); 37 37 } 38 } 39 40 if (isset($_REQUEST['fvcn_post_rating_action'], $_REQUEST['post_id']) && 41 in_array($_REQUEST['fvcn_post_rating_action'], ['increase', 'decrease'])) 42 { 43 $this->postController->adjustPostRating(); 38 if (isset($_POST['fvcn-post-like-action'], $_POST['fvcn-post-id'])) { 39 $this->postController->likeUnlikePost(); 40 } 44 41 } 45 42 } -
fv-community-news/trunk/src/Hook/Init.php
r1825546 r1853982 7 7 use FvCommunityNews\Container\Container; 8 8 use FvCommunityNews\Installer; 9 use FvCommunityNews\Post\ PostType;9 use FvCommunityNews\Post\TypeRegistrar as PostTypeRegistrar; 10 10 use FvCommunityNews\Shortcode\PostForm as PostFormShortcode; 11 11 use FvCommunityNews\Shortcode\RecentPosts as RecentPostsShortcode; … … 69 69 protected function setupVariables() 70 70 { 71 $pluginDir = plugin_dir_path(FvCommunityNews::FILE); 72 $pluginUrl = plugin_dir_url(FvCommunityNews::FILE); 71 $reflection = new \ReflectionClass(FvCommunityNews::class); 72 73 $pluginDir = plugin_dir_path($reflection->getFileName()); 74 $pluginUrl = plugin_dir_url($reflection->getFileName()); 73 75 $baseSlug = $this->config['_fvcn_base_slug']; 74 76 … … 118 120 $mofile = sprintf('fvcn-%s.mo', $locale); 119 121 120 $mofile_local = FvCommunityNews::DIR . '/languages/' . $mofile; 122 $reflection = new \ReflectionClass(FvCommunityNews::class); 123 124 $mofile_local = \dirname($reflection->getFileName()) . '/languages/' . $mofile; 121 125 $mofile_global = WP_LANG_DIR . '/fv-community-news/' . $mofile; 122 126 … … 140 144 protected function registerPostType() 141 145 { 142 $postType = new PostType(); 143 $postType->registerPostType( 146 PostTypeRegistrar::registerPostType( 144 147 $this->config['_fvcn_base_slug'] . '/' . $this->config['_fvcn_post_slug'], 145 148 $this->config['_fvcn_base_slug'] . '/' . $this->config['_fvcn_post_archive_slug'] 146 149 ); 147 $postType->registerPostStatuses(); 148 $postType->registerTaxonomy($this->config['_fvcn_base_slug'] . '/' . $this->config['_fvcn_post_tag_slug']); 150 PostTypeRegistrar::registerPostStatuses(); 151 PostTypeRegistrar::registerTaxonomy( 152 $this->config['_fvcn_base_slug'] . '/' . $this->config['_fvcn_post_tag_slug'] 153 ); 149 154 150 155 do_action('fvcn_register_post_type'); -
fv-community-news/trunk/src/Hook/Syncer.php
r1843050 r1853982 36 36 add_action('fvcn_insert_post', [$syncer, 'submitPost'], 999 ); 37 37 add_action('fvcn_publish_post', [$syncer, 'submitPost'], 999); 38 add_action('fvcn_like_post', [$syncer, 'likePost'], 999); 39 add_action('fvcn_unlike_post', [$syncer, 'unlikePost'], 999); 38 40 add_action('fvcn_increase_post_view_count', [$syncer, 'increasePostView'], 999); 39 add_action('fvcn_increase_post_rating', [$syncer, 'increasePostRating'], 999);40 add_action('fvcn_decrease_post_rating', [$syncer, 'decreasePostRating'], 999);41 41 } 42 42 } -
fv-community-news/trunk/src/Installer.php
r1806332 r1853982 44 44 public function isUpdate() 45 45 { 46 return (1 == version_compare(Version::getCurrentVersion(), $this->config['_fvcn_version']));46 return (1 == \version_compare(Version::getCurrentVersion(), $this->config['_fvcn_version'])); 47 47 } 48 48 … … 94 94 { 95 95 $lastCheck = $this->config->get('_fvcn_previous_has_update', false); 96 if (!$lastCheck || ( time() - $lastCheck) > 86400) { // Only check once every 24 hours96 if (!$lastCheck || (\time() - $lastCheck) > 86400) { // Only check once every 24 hours 97 97 $latest = Version::getLatestVersion(); 98 $this->config->set('_fvcn_previous_has_update', time());98 $this->config->set('_fvcn_previous_has_update', \time()); 99 99 100 100 if (null !== $latest) { 101 return (1 == version_compare($latest, $this->config['_fvcn_version']));101 return (1 == \version_compare($latest, $this->config['_fvcn_version'])); 102 102 } 103 103 } -
fv-community-news/trunk/src/Post/Controller.php
r1825546 r1853982 2 2 3 3 namespace FvCommunityNews\Post; 4 5 use FvCommunityNews\Config\AbstractConfig as Config; 4 6 5 7 /** … … 10 12 class Controller 11 13 { 14 /** 15 * @var Config 16 */ 17 private $config; 12 18 /** 13 19 * @var Mapper … … 20 26 21 27 /** 28 * @param Config $config 22 29 * @param Mapper $postMapper 23 30 * @param Form $postForm 24 31 */ 25 public function __construct( Mapper $postMapper, Form $postForm)32 public function __construct(Config $config, Mapper $postMapper, Form $postForm) 26 33 { 34 $this->config = $config; 27 35 $this->postMapper = $postMapper; 28 36 $this->postForm = $postForm; … … 42 50 return null; 43 51 } 44 if (fvcn_is_anonymous() && ! fvcn_is_anonymous_allowed()) {52 if (fvcn_is_anonymous() && !$this->config['_fvcn_is_anonymous_allowed']) { 45 53 return null; 46 54 } … … 56 64 $data = $this->postForm->getData(); 57 65 58 $status = PostType::STATUS_PENDING;59 if (! fvcn_admin_moderation()) {60 if ( fvcn_user_moderation()) {66 $status = Status::pending(); 67 if (!$this->config['_fvcn_admin_moderation']) { 68 if ($this->config['_fvcn_user_moderation']) { 61 69 if (fvcn_has_user_posts()) { 62 $status = PostType::STATUS_PUBLISH;70 $status = Status::publish(); 63 71 } 64 72 } else { 65 $status = PostType::STATUS_PUBLISH;73 $status = Status::publish(); 66 74 } 67 75 } … … 71 79 $data['fvcn_post_form_tags'] = explode(',', $data['fvcn_post_form_tags']); 72 80 } 73 $data['fvcn_post_form_tags'] = [ fvcn_get_post_tag_id() => $data['fvcn_post_form_tags']];81 $data['fvcn_post_form_tags'] = [Type::tag()->getType() => $data['fvcn_post_form_tags']]; 74 82 } 75 83 … … 80 88 'tax_input' => $data['fvcn_post_form_tags'], 81 89 'post_status' => $status, 82 'post_type' => PostType::POST_TYPE_KEY90 'post_type' => Type::post() 83 91 ]); 84 92 $postMeta = apply_filters('fvcn_new_post_meta_pre_insert', [ … … 96 104 97 105 if ('template_redirect' == current_filter()) { 98 if ( PostType::STATUS_PUBLISH== fvcn_get_post_status($postId)) {106 if (Status::publish() == fvcn_get_post_status($postId)) { 99 107 wp_redirect(add_query_arg(['fvcn_added' => $postId], fvcn_get_post_permalink($postId))); 100 108 } else { … … 114 122 * @return void 115 123 */ 116 public function adjustPostRating()124 public function likeUnlikePost() 117 125 { 118 126 $actions = [ 119 ' increase',120 ' decrease'127 'like', 128 'unlike' 121 129 ]; 122 130 123 if (!isset($_REQUEST['fvcn _post_rating_action'], $_REQUEST['post_id']) || !in_array($_REQUEST['fvcn_post_rating_action'], $actions)) {131 if (!isset($_REQUEST['fvcn-post-like-action'], $_REQUEST['fvcn-post-id']) || !in_array($_REQUEST['fvcn-post-like-action'], $actions)) { 124 132 return; 125 133 } 126 if (0 === ($id = fvcn_get_post_id($_REQUEST['post_id']))) { 127 return; 128 } 129 if (fvcn_is_post_rated_by_current_user($id)) { 134 if (0 === ($id = fvcn_get_post_id($_REQUEST['fvcn-post-id']))) { 130 135 return; 131 136 } 132 137 133 check_admin_referer('fvcn-post- rating');138 check_admin_referer('fvcn-post-like'); 134 139 135 if ('increase' == $_REQUEST['fvcn_post_rating_action']) { 136 $this->postMapper->increasePostRating($id); 140 if ('like' == $_REQUEST['fvcn-post-like-action']) { 141 if (\fvcn_is_post_liked_by_current_user($id)) { 142 return; 143 } 144 $this->postMapper->likePost($id); 145 setcookie('fvcn_post_liked_' . $id . '_' . COOKIEHASH, 'true', time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 137 146 } else { 138 $this->postMapper->decreasePostRating($id); 147 if (!\fvcn_is_post_liked_by_current_user($id)) { 148 return; 149 } 150 $this->postMapper->unlikePost($id); 151 setcookie('fvcn_post_liked_' . $id . '_' . COOKIEHASH, 'true', time() - 30000000, COOKIEPATH, COOKIE_DOMAIN); 139 152 } 140 141 setcookie('fvcn_post_rated_' . $id . '_' . COOKIEHASH, 'true', time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);142 153 143 154 wp_redirect(fvcn_get_post_permalink($id)); -
fv-community-news/trunk/src/Post/Mapper.php
r1810381 r1853982 23 23 'post_title' => '', 24 24 'post_content' => '', 25 'post_status' => PostType::STATUS_PENDING,26 'post_type' => PostType::POST_TYPE_KEY,25 'post_status' => Status::pending(), 26 'post_type' => Type::post(), 27 27 'post_password' => '', 28 28 'tax_input' => '' … … 33 33 34 34 // Anonymous tags fix 35 if (!empty($data['tax_input']) && is_array($data['tax_input']) && !empty($data['tax_input'][PostType::TAG_TYPE_KEY])) { 36 wp_set_post_terms($postId, $data['tax_input'][PostType::TAG_TYPE_KEY], PostType::TAG_TYPE_KEY); 35 $tagType = Type::tag()->getType(); 36 if (!empty($data['tax_input']) && is_array($data['tax_input']) 37 && !empty($data['tax_input'][$tagType])) 38 { 39 wp_set_post_terms($postId, $data['tax_input'][$tagType], $tagType); 37 40 } 38 41 … … 41 44 '_fvcn_anonymous_author_email' => '', 42 45 '_fvcn_post_url' => '', 43 '_fvcn_post_ rating' => 0,46 '_fvcn_post_likes' => 0, 44 47 '_fvcn_author_ip' => fvcn_get_current_author_ip(), 45 48 '_fvcn_author_au' => fvcn_get_current_author_ua() … … 47 50 $meta = wp_parse_args($meta, $defaultMeta); 48 51 49 foreach ($meta as $meta_key =>$meta_value) {52 foreach ($meta as $meta_key => $meta_value) { 50 53 update_post_meta($postId, $meta_key, $meta_value); 51 54 } … … 80 83 * @return int 81 84 */ 82 public function publishPost(int $postId) 85 public function publishPost(int $postId): int 83 86 { 84 87 do_action('fvcn_publish_post', $postId); 85 return $this->changePostStatus($postId, PostType::STATUS_PUBLISH);88 return $this->changePostStatus($postId, Status::publish()); 86 89 } 87 90 … … 92 95 * @return int 93 96 */ 94 public function unpublishPost(int $postId) 97 public function unpublishPost(int $postId): int 95 98 { 96 99 do_action('fvcn_unpublish_post', $postId); 97 return $this->changePostStatus($postId, PostType::STATUS_PENDING);100 return $this->changePostStatus($postId, Status::pending()); 98 101 } 99 102 … … 104 107 * @return int 105 108 */ 106 public function spamPost(int $postId) 109 public function spamPost(int $postId): int 107 110 { 108 111 do_action('fvcn_spam_post', $postId); 109 return $this->changePostStatus($postId, PostType::STATUS_SPAM);112 return $this->changePostStatus($postId, Status::spam()); 110 113 } 111 114 … … 114 117 * 115 118 * @param int $postId 116 * @param string$status119 * @param Status $status 117 120 * @return int 118 121 */ 119 protected function changePostStatus(int $postId, string $status)122 protected function changePostStatus(int $postId, Status $status): int 120 123 { 121 $post = []; 122 $post['ID'] = $postId; 123 $post['post_status'] = $status; 124 $post = [ 125 'ID' => $postId, 126 'post_status' => $status->getStatus(), 127 ]; 124 128 125 129 return wp_update_post($post); … … 127 131 128 132 /** 129 * increasePostRating()133 * likePost() 130 134 * 131 135 * @param int $postId 132 136 */ 133 public function increasePostRating(int $postId)137 public function likePost(int $postId) 134 138 { 135 do_action('fvcn_ increase_post_rating', $postId);136 update_post_meta($postId, '_fvcn_post_ rating', fvcn_get_post_rating($postId) + 1);139 do_action('fvcn_like_post', $postId); 140 update_post_meta($postId, '_fvcn_post_likes', fvcn_get_post_likes($postId) + 1); 137 141 } 138 142 139 143 /** 140 * decreasePostRating()144 * unlikePost() 141 145 * 142 146 * @param int $postId 143 147 */ 144 public function decreasePostRating(int $postId)148 public function unlikePost(int $postId) 145 149 { 146 do_action('fvcn_ decrease_post_rating', $postId);147 update_post_meta($postId, '_fvcn_post_ rating', fvcn_get_post_rating($postId) - 1);150 do_action('fvcn_unlike_post', $postId); 151 update_post_meta($postId, '_fvcn_post_likes', max(0, fvcn_get_post_likes($postId) - 1)); 148 152 } 149 153 -
fv-community-news/trunk/src/Syncer/Api/Api.php
r1843050 r1853982 65 65 public static function latestVersion(): Api 66 66 { 67 return new static(static::API_VERSIONS . '/ current', 'GET');67 return new static(static::API_VERSIONS . '/latest', 'GET'); 68 68 } 69 69 … … 101 101 102 102 /** 103 * Make an API request to add a starto a post.103 * Make an API request to add a like to a post. 104 104 * 105 * @param int $id ID of the post to star.105 * @param int $id ID of the post to like. 106 106 * @return Api 107 107 */ 108 public static function starPost(int $id): Api108 public static function likePost(int $id): Api 109 109 { 110 return new static(static::API_POSTS . '/' . $id . '/ stars', 'POST');110 return new static(static::API_POSTS . '/' . $id . '/likes', 'POST'); 111 111 } 112 112 113 113 /** 114 * Make an API request to remove a starfrom a post.114 * Make an API request to remove a like from a post. 115 115 * 116 * @param int $id ID of the post to un star.116 * @param int $id ID of the post to unlike. 117 117 * @return Api 118 118 */ 119 public static function un starPost(int $id): Api119 public static function unlikePost(int $id): Api 120 120 { 121 return new static(static::API_POSTS . '/' . $id . '/ stars', 'DELETE');121 return new static(static::API_POSTS . '/' . $id . '/likes', 'DELETE'); 122 122 } 123 123 } -
fv-community-news/trunk/src/Syncer/Syncer.php
r1843050 r1853982 36 36 'url' => \fvcn_get_post_link($postId), 37 37 'tags' => \explode(';', \strip_tags(\fvcn_get_post_tag_list($postId, ['before'=>'', 'sep'=>';', 'after'=>'']))), 38 ' rating' => \fvcn_get_post_rating($postId),38 'likes' => \fvcn_get_post_likes($postId), 39 39 'views' => \fvcn_get_post_views($postId), 40 40 'thumbnail' => $thumbnail, … … 52 52 if (!empty($response)) { 53 53 \update_post_meta($postId, '_fvcn_post_synced', $response['post']['id']); 54 return \absint($response['post']['id']);54 return $response['post']['id']; 55 55 } 56 56 … … 79 79 80 80 /** 81 * Submit a star increase to the API.81 * Submit a like to the API. 82 82 * 83 83 * @param int $postId 84 84 * @return void 85 85 */ 86 public function increasePostRating(int $postId)86 public function likePost(int $postId) 87 87 { 88 88 $apiId = $this->submitPost($postId); … … 92 92 } 93 93 94 $this->executeRequest(Api:: starPost($apiId), [], ['blocking' => false]);94 $this->executeRequest(Api::likePost($apiId), [], ['blocking' => false]); 95 95 } 96 96 97 97 /** 98 * Submit a star decrease to the API.98 * Submit an unlike to the API. 99 99 * 100 100 * @param int $postId 101 101 * @return void 102 102 */ 103 public function decreasePostRating(int $postId)103 public function unlikePost(int $postId) 104 104 { 105 105 $apiId = $this->submitPost($postId); … … 109 109 } 110 110 111 $this->executeRequest(Api::un starPost($apiId), [], ['blocking' => false]);111 $this->executeRequest(Api::unlikePost($apiId), [], ['blocking' => false]); 112 112 } 113 113 -
fv-community-news/trunk/src/Version.php
r1843050 r1853982 27 27 public static function getCurrentVersion() 28 28 { 29 return FvCommunityNews::VERSION; 29 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 30 $reflection = new \ReflectionClass(FvCommunityNews::class); 31 $data = \get_plugin_data($reflection->getFileName()); 32 return $data['Version']; 30 33 } 31 34 -
fv-community-news/trunk/src/View/AjaxForm.php
r1810381 r1853982 4 4 5 5 use FvCommunityNews\Post\Controller; 6 use FvCommunityNews\Post\ PostType;6 use FvCommunityNews\Post\Status; 7 7 use WP_Error; 8 8 … … 73 73 $postId = $this->postController->createPost(); 74 74 75 if ( fvcn_has_errors()) {75 if (!empty($this->error->get_error_codes())) { 76 76 $errors = []; 77 77 foreach ($this->error->get_error_codes() as $code) { … … 84 84 ]; 85 85 } else { 86 if ( PostType::STATUS_PUBLISH== fvcn_get_post_status($postId)) {86 if (Status::publish() == fvcn_get_post_status($postId)) { 87 87 $permalink = fvcn_get_post_permalink($postId); 88 88 $message = ''; -
fv-community-news/trunk/src/Widget/Form.php
r1806332 r1853982 52 52 ?> 53 53 54 <?php if (fvcn_ is_anonymous_allowed()|| !fvcn_is_anonymous()) : ?>54 <?php if (fvcn_container_get('Config')['_fvcn_is_anonymous_allowed'] || !fvcn_is_anonymous()) : ?> 55 55 56 56 <?php fvcn_get_template_part('fvcn/form', 'post'); ?> -
fv-community-news/trunk/src/Widget/ListPosts.php
r1810381 r1853982 78 78 { 79 79 $instance = $old_instance; 80 $instance['title'] = strip_tags($new_instance['title']);81 $instance['thumbnail'] = strip_tags($new_instance['thumbnail']);82 $instance['view_all'] = strip_tags($new_instance['view_all']);80 $instance['title'] = \strip_tags($new_instance['title']); 81 $instance['thumbnail'] = \strip_tags($new_instance['thumbnail']); 82 $instance['view_all'] = \strip_tags($new_instance['view_all']); 83 83 $instance['num_posts'] = $new_instance['num_posts']; 84 84 … … 100 100 public function form($instance) 101 101 { 102 $title = !empty($instance['title']) ? esc_attr($instance['title']): 'FV Community News';103 $num_posts = !empty($instance['num_posts']) ? esc_attr($instance['num_posts']) : '5';104 $thumbnail = !empty($instance['thumbnail']) ? esc_attr($instance['thumbnail']): '';105 $view_all = !empty($instance['view_all']) ? esc_attr($instance['view_all']): '';102 $title = !empty($instance['title']) ? esc_attr($instance['title']) : 'FV Community News'; 103 $num_posts = !empty($instance['num_posts']) ? esc_attr($instance['num_posts']) : 5; 104 $thumbnail = !empty($instance['thumbnail']) ? esc_attr($instance['thumbnail']) : ''; 105 $view_all = !empty($instance['view_all']) ? esc_attr($instance['view_all']) : ''; 106 106 ?> 107 107
Note: See TracChangeset
for help on using the changeset viewer.