Plugin Directory

Changeset 1853982


Ignore:
Timestamp:
04/06/2018 09:37:51 AM (8 years ago)
Author:
frankverhoeven
Message:

Push 3.3

Location:
fv-community-news/trunk
Files:
5 added
2 deleted
30 edited

Legend:

Unmodified
Added
Removed
  • fv-community-news/trunk

    • Property svn:ignore
      •  

        old new  
        22.gitignore
        33.idea
         4phpunit.xml
         5phpunit.xml.dist
         6test
         7vendor
         8composer.lock
  • fv-community-news/trunk/composer.json

    r1806332 r1853982  
    33  "description": "FV Community News",
    44  "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    }
    1012  ],
    11   "homepage": "https://frankverhoeven.me/wordpress-plugin-fv-community-news/",
    1213  "minimum-stability": "dev",
    1314  "prefer-stable": true,
     
    1516    "php": "^7.0"
    1617  },
     18  "require-dev": {
     19    "phpunit/phpunit": "^6.5"
     20  },
    1721  "autoload": {
    1822    "psr-4": {
    1923      "FvCommunityNews\\": "src/"
    2024    }
     25  },
     26  "autoload-dev": {
     27    "psr-4": {
     28      "FvCommunityNews\\Test\\": "test/"
     29    }
    2130  }
    2231}
  • fv-community-news/trunk/config/default.config.php

    r1843050 r1853982  
    11<?php
     2
     3use FvCommunityNews\Version;
    24
    35return [
     
    57     * @var int Current plugin version
    68     */
    7     '_fvcn_version' => FvCommunityNews::VERSION,
     9    '_fvcn_version' => Version::getCurrentVersion(),
    810
    911    /**
  • fv-community-news/trunk/fv-community-news.php

    r1843050 r1853982  
    55 * Plugin URI:  https://frankverhoeven.me/wordpress-plugin-fv-community-news/
    66 * Description: Allow visitors of your site to submit articles.
    7  * Version:     3.2.2
     7 * Version:     3.3
    88 * Author:      Frank Verhoeven
    99 * Author URI:  https://frankverhoeven.me/
     
    1515use FvCommunityNews\Hook\Collection as HookCollection;
    1616
    17 if (!defined('ABSPATH')) exit;
     17if (!\defined('ABSPATH')) exit;
    1818
    1919/**
     
    2424final class FvCommunityNews
    2525{
    26     /**
    27      * @var string
    28      */
    29     const VERSION = '3.2.1';
    30     /**
    31      * @var string
    32      */
    33     const DIR = __DIR__;
    34     /**
    35      * @var string
    36      */
    37     const FILE = __FILE__;
    3826    /**
    3927     * @var Container
     
    4735    public function __construct()
    4836    {
    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']);
    5139    }
    5240
     
    8068        $autoloader->register();
    8169
    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');
    9471    }
    9572
     
    10178    public static function activation()
    10279    {
    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']);
    10582    }
    10683
     
    11289    public static function deactivation()
    11390    {
    114         do_action('fvcn_deactivation');
     91        \do_action('fvcn_deactivation');
    11592    }
    11693
     
    12299    public static function uninstall()
    123100    {
    124         do_action('fvcn_uninstall');
     101        \do_action('fvcn_uninstall');
    125102    }
    126103}
     
    135112    $fvcn->start();
    136113} catch (Exception $e) {
    137     if (defined('WP_DEBUG') && true === WP_DEBUG) {
     114    if (\defined('WP_DEBUG') && true === WP_DEBUG) {
    138115        echo '<h3>' . $e->getMessage() . '</h3><pre>' . $e->getTraceAsString() . '</pre>';
    139116    }
    140117
    141     error_log('fvcn: ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString());
     118    \error_log('fvcn: ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString());
    142119}
    143120
  • fv-community-news/trunk/fvcn-theme/fvcn/content-single-post.php

    r1806332 r1853982  
    2929</div><!-- .entry-content -->
    3030
    31 <div class="fvcn-post-meta">
     31<div class="entry-meta fvcn-post-meta">
    3232    <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'=>' | ']); ?>
    3434    </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(); ?>
    4637    </span>
    4738</div><!-- .entry-meta -->
  • fv-community-news/trunk/fvcn-theme/fvcn/css/fvcn-theme.css

    r1806332 r1853982  
    44 * @author Frank Verhoeven <[email protected]>
    55 */
     6
     7.fvcn-post-form-new-post label {
     8    display: block;
     9    margin: 5px 0 3px;
     10}
    611
    712.fvcn-post-thumbnail {
     
    3237
    3338.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}
    3461
    3562
  • 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  
    143143        <?php fvcn_post_form_fields(); ?>
    144144
    145 
    146 
    147145        <?php do_action('fvcn_post_form_extras_bottom'); ?>
    148146    </form>
  • fv-community-news/trunk/readme.txt

    r1843050 r1853982  
    66Requires at least:  4.8
    77Tested up to:       4.9
    8 Stable tag:         3.2.2
     8Stable tag:         3.3
    99
    1010Give the visitors of your site the ability to submit their news to you, and list it in a nice news feed.
     
    134134
    135135
     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
    136143= 3.2.2 =
    137144
  • fv-community-news/trunk/src/Admin/Admin.php

    r1810381 r1853982  
    99use FvCommunityNews\Admin\Settings\Settings;
    1010use FvCommunityNews\Container\Container;
    11 use FvCommunityNews\Post\PostType;
     11use FvCommunityNews\Post\Type as PostType;
    1212
    1313/**
     
    7070        }
    7171
    72         $postType = PostType::POST_TYPE_KEY;
     72        $postType = PostType::post();
    7373
    7474        switch ($pageId) {
     
    124124        $menuIconUrl = $registry['pluginUrl'] . 'public/images/menu.png';
    125125        $menuIconUrl2x = $registry['pluginUrl'] . 'public/images/[email protected]';
    126         $postClass = sanitize_html_class(PostType::POST_TYPE_KEY);
     126        $postClass = sanitize_html_class(PostType::post());
    127127
    128128        ?>
     
    184184    {
    185185        $adminFormPage = add_submenu_page(
    186             'edit.php?post_type=' . PostType::POST_TYPE_KEY,
     186            'edit.php?post_type=' . PostType::post(),
    187187            __('FV Community News Form', 'fvcn'),
    188188            __('Form', 'fvcn'),
     
    194194
    195195        add_submenu_page(
    196             'edit.php?post_type=' . PostType::POST_TYPE_KEY,
     196            'edit.php?post_type=' . PostType::post(),
    197197            __('FV Community News Settings', 'fvcn'),
    198198            __('Settings', 'fvcn'),
  • fv-community-news/trunk/src/Admin/Dashboard/Widget/RecentPosts.php

    r1810381 r1853982  
    55use FvCommunityNews\Config\AbstractConfig as Config;
    66use FvCommunityNews\Post\Mapper as PostMapper;
    7 use FvCommunityNews\Post\PostType;
     7use FvCommunityNews\Post\Status;
     8use FvCommunityNews\Post\Type as PostType;
    89
    910/**
     
    256257        $options = [
    257258            'posts_per_page' => $this->config['_fvcn_dashboard_rp_num'],
    258             'post_status' => PostType::STATUS_PUBLISH . ',' . PostType::STATUS_PENDING
     259            'post_status' => Status::publish() . ',' . Status::pending()
    259260        ];
    260261
     
    268269                    $class = 'fvcn-post ';
    269270
    270                     if (PostType::STATUS_PENDING == fvcn_get_post_status()) {
     271                    if (Status::pending() == fvcn_get_post_status()) {
    271272                        $class .= 'pending ';
    272273                    } else {
     
    320321                                    'post' => fvcn_get_post_id(),
    321322                                    'action' => 'trash'
    322                                 ], 'post.php'), 'trash-' . PostType::POST_TYPE_KEY . '_' . fvcn_get_post_id()));
     323                                ], 'post.php'), 'trash-' . PostType::post() . '_' . fvcn_get_post_id()));
    323324                                ?>
    324325                                <span class="publish"><a href="<?= $publish_uri; ?>"><?php _e('Publish', 'fvcn'); ?></a></span>
     
    337338
    338339            <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>
    340341            </p>
    341342
  • fv-community-news/trunk/src/Admin/Post/Edit.php

    r1806332 r1853982  
    33namespace FvCommunityNews\Admin\Post;
    44
    5 use FvCommunityNews\Post\PostType;
     5use FvCommunityNews\Post\Type as PostType;
    66
    77/**
     
    2323    public function __construct()
    2424    {
    25         $this->postType = PostType::POST_TYPE_KEY;
     25        $this->postType = PostType::post();
    2626
    2727        add_action('add_meta_boxes', [$this, 'registerMetaboxPostInfo']);
     
    117117        -->
    118118        <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>
    121121        </p>
    122122
  • fv-community-news/trunk/src/Admin/Post/Moderation.php

    r1810381 r1853982  
    44
    55use FvCommunityNews\Post\Mapper as PostMapper;
    6 use FvCommunityNews\Post\PostType;
     6use FvCommunityNews\Post\Status;
     7use FvCommunityNews\Post\Type as PostType;
    78
    89/**
     
    2829    {
    2930        $this->postMapper = $postMapper;
    30         $this->postType = PostType::POST_TYPE_KEY;
     31        $this->postType = PostType::post();
    3132
    3233        $this->setupActions()
     
    7879                'ps' => [
    7980                    'all' => 'all',
    80                     'public'  => PostType::STATUS_PUBLISH,
    81                     'pending' => PostType::STATUS_PENDING,
    82                     'spam'    => PostType::STATUS_SPAM,
    83                     'trash'   => PostType::STATUS_TRASH
     81                    'public'  => Status::publish(),
     82                    'pending' => Status::pending(),
     83                    'spam'    => Status::spam(),
     84                    'trash'   => Status::trash(),
    8485                ],
    8586                'locale'=> [
     
    114115            check_admin_referer('fvcn-bulk-action', '_fvcn_bulk_action');
    115116
    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])) {
    117118                while (fvcn_posts()) {
    118119                    fvcn_the_post();
     
    351352        wp_nonce_field('fvcn-bulk-action', '_fvcn_bulk_action');
    352353
    353         if (isset($_GET['post_status']) && PostType::STATUS_SPAM == $_GET['post_status']) {
     354        if (isset($_GET['post_status']) && Status::spam() == $_GET['post_status']) {
    354355            submit_button(__('Remove All Spam', 'fvcn'), 'button-secondary apply', 'fvcn-remove-all-spam-submit', false);
    355356        }
  • fv-community-news/trunk/src/Akismet/Handler.php

    r1806332 r1853982  
    44
    55use FvCommunityNews\Post\Mapper;
    6 use FvCommunityNews\Post\PostType;
     6use FvCommunityNews\Post\Status;
    77
    88/**
     
    103103            $method = 'submitSpam';
    104104        } elseif ('fvcn_publish_post' == $filter) {
    105             if (PostType::STATUS_SPAM != fvcn_get_post_status($postId)) {
     105            if (Status::spam() != fvcn_get_post_status($postId)) {
    106106                return $this;
    107107            }
  • fv-community-news/trunk/src/Autoloader.php

    r1760963 r1853982  
    4444    public function register($prepend = false)
    4545    {
    46         spl_autoload_register([$this, 'autoload'], true, $prepend);
     46        \spl_autoload_register([$this, 'autoload'], true, $prepend);
    4747    }
    4848
     
    5252    public function unregister()
    5353    {
    54         spl_autoload_unregister([$this, 'autoload']);
     54        \spl_autoload_unregister([$this, 'autoload']);
    5555    }
    5656
     
    6363    {
    6464        foreach ($this->prefixes as $prefix => $path) {
    65             $len = strlen($prefix);
     65            $len = \strlen($prefix);
    6666
    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';
    7070
    7171                $this->loadFile($file);
     
    8383        // Prevent access to $this/self
    8484        (function() use ($file) {
    85             if (file_exists($file)) {
     85            if (\file_exists($file)) {
    8686                require $file;
    8787            }
  • fv-community-news/trunk/src/Container/Container.php

    r1825546 r1853982  
    2222
    2323    /**
    24      * __construct()
    25      *
    2624     * @param array $factories
    2725     */
     
    3836     * @return mixed Entry.
    3937     */
    40     public function get($id)
     38    public function get(string $id)
    4139    {
    4240        if (!$this->has($id)) {
  • fv-community-news/trunk/src/Factory/Post/Controller.php

    r1810381 r1853982  
    2626    {
    2727        return new PostController(
     28            $container->get('Config'),
    2829            $container->get(Mapper::class),
    2930            $container->get(Form::class)
  • fv-community-news/trunk/src/Hook/Collection.php

    r1843050 r1853982  
    136136
    137137        'template_include' => [
    138             ['function' => 'fvcn_template_include'],
    139         ],
    140         'fvcn_template_include' => [
    141138            [
    142139                'function' => 'fvcn_theme_compat_template_include',
  • fv-community-news/trunk/src/Hook/Controller.php

    r1825546 r1853982  
    3636                $this->postController->createPost();
    3737            }
    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            }
    4441        }
    4542    }
  • fv-community-news/trunk/src/Hook/Init.php

    r1825546 r1853982  
    77use FvCommunityNews\Container\Container;
    88use FvCommunityNews\Installer;
    9 use FvCommunityNews\Post\PostType;
     9use FvCommunityNews\Post\TypeRegistrar as PostTypeRegistrar;
    1010use FvCommunityNews\Shortcode\PostForm as PostFormShortcode;
    1111use FvCommunityNews\Shortcode\RecentPosts as RecentPostsShortcode;
     
    6969    protected function setupVariables()
    7070    {
    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());
    7375        $baseSlug = $this->config['_fvcn_base_slug'];
    7476
     
    118120        $mofile = sprintf('fvcn-%s.mo', $locale);
    119121
    120         $mofile_local = FvCommunityNews::DIR . '/languages/' . $mofile;
     122        $reflection = new \ReflectionClass(FvCommunityNews::class);
     123
     124        $mofile_local = \dirname($reflection->getFileName()) . '/languages/' . $mofile;
    121125        $mofile_global = WP_LANG_DIR . '/fv-community-news/' . $mofile;
    122126
     
    140144    protected function registerPostType()
    141145    {
    142         $postType = new PostType();
    143         $postType->registerPostType(
     146        PostTypeRegistrar::registerPostType(
    144147            $this->config['_fvcn_base_slug'] . '/' . $this->config['_fvcn_post_slug'],
    145148            $this->config['_fvcn_base_slug'] . '/' . $this->config['_fvcn_post_archive_slug']
    146149        );
    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        );
    149154
    150155        do_action('fvcn_register_post_type');
  • fv-community-news/trunk/src/Hook/Syncer.php

    r1843050 r1853982  
    3636            add_action('fvcn_insert_post', [$syncer, 'submitPost'], 999 );
    3737            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);
    3840            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);
    4141        }
    4242    }
  • fv-community-news/trunk/src/Installer.php

    r1806332 r1853982  
    4444    public function isUpdate()
    4545    {
    46         return (1 == version_compare(Version::getCurrentVersion(), $this->config['_fvcn_version']));
     46        return (1 == \version_compare(Version::getCurrentVersion(), $this->config['_fvcn_version']));
    4747    }
    4848
     
    9494    {
    9595        $lastCheck = $this->config->get('_fvcn_previous_has_update', false);
    96         if (!$lastCheck || (time() - $lastCheck) > 86400) { // Only check once every 24 hours
     96        if (!$lastCheck || (\time() - $lastCheck) > 86400) { // Only check once every 24 hours
    9797            $latest = Version::getLatestVersion();
    98             $this->config->set('_fvcn_previous_has_update', time());
     98            $this->config->set('_fvcn_previous_has_update', \time());
    9999
    100100            if (null !== $latest) {
    101                 return (1 == version_compare($latest, $this->config['_fvcn_version']));
     101                return (1 == \version_compare($latest, $this->config['_fvcn_version']));
    102102            }
    103103        }
  • fv-community-news/trunk/src/Post/Controller.php

    r1825546 r1853982  
    22
    33namespace FvCommunityNews\Post;
     4
     5use FvCommunityNews\Config\AbstractConfig as Config;
    46
    57/**
     
    1012class Controller
    1113{
     14    /**
     15     * @var Config
     16     */
     17    private $config;
    1218    /**
    1319     * @var Mapper
     
    2026
    2127    /**
     28     * @param Config $config
    2229     * @param Mapper $postMapper
    2330     * @param Form $postForm
    2431     */
    25     public function __construct(Mapper $postMapper, Form $postForm)
     32    public function __construct(Config $config, Mapper $postMapper, Form $postForm)
    2633    {
     34        $this->config = $config;
    2735        $this->postMapper = $postMapper;
    2836        $this->postForm = $postForm;
     
    4250            return null;
    4351        }
    44         if (fvcn_is_anonymous() && !fvcn_is_anonymous_allowed()) {
     52        if (fvcn_is_anonymous() && !$this->config['_fvcn_is_anonymous_allowed']) {
    4553            return null;
    4654        }
     
    5664            $data = $this->postForm->getData();
    5765
    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']) {
    6169                    if (fvcn_has_user_posts()) {
    62                         $status = PostType::STATUS_PUBLISH;
     70                        $status = Status::publish();
    6371                    }
    6472                } else {
    65                     $status = PostType::STATUS_PUBLISH;
     73                    $status = Status::publish();
    6674                }
    6775            }
     
    7179                    $data['fvcn_post_form_tags'] = explode(',', $data['fvcn_post_form_tags']);
    7280                }
    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']];
    7482            }
    7583
     
    8088                'tax_input' => $data['fvcn_post_form_tags'],
    8189                'post_status' => $status,
    82                 'post_type' => PostType::POST_TYPE_KEY
     90                'post_type' => Type::post()
    8391            ]);
    8492            $postMeta = apply_filters('fvcn_new_post_meta_pre_insert', [
     
    96104
    97105            if ('template_redirect' == current_filter()) {
    98                 if (PostType::STATUS_PUBLISH == fvcn_get_post_status($postId)) {
     106                if (Status::publish() == fvcn_get_post_status($postId)) {
    99107                    wp_redirect(add_query_arg(['fvcn_added' => $postId], fvcn_get_post_permalink($postId)));
    100108                } else {
     
    114122     * @return void
    115123     */
    116     public function adjustPostRating()
     124    public function likeUnlikePost()
    117125    {
    118126        $actions = [
    119             'increase',
    120             'decrease'
     127            'like',
     128            'unlike'
    121129        ];
    122130
    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)) {
    124132            return;
    125133        }
    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']))) {
    130135            return;
    131136        }
    132137
    133         check_admin_referer('fvcn-post-rating');
     138        check_admin_referer('fvcn-post-like');
    134139
    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);
    137146        } 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);
    139152        }
    140 
    141         setcookie('fvcn_post_rated_' . $id . '_' . COOKIEHASH, 'true', time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    142153
    143154        wp_redirect(fvcn_get_post_permalink($id));
  • fv-community-news/trunk/src/Post/Mapper.php

    r1810381 r1853982  
    2323            'post_title' => '',
    2424            '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(),
    2727            'post_password' => '',
    2828            'tax_input' => ''
     
    3333
    3434        // 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);
    3740        }
    3841
     
    4144            '_fvcn_anonymous_author_email' => '',
    4245            '_fvcn_post_url' => '',
    43             '_fvcn_post_rating' => 0,
     46            '_fvcn_post_likes' => 0,
    4447            '_fvcn_author_ip' => fvcn_get_current_author_ip(),
    4548            '_fvcn_author_au' => fvcn_get_current_author_ua()
     
    4750        $meta = wp_parse_args($meta, $defaultMeta);
    4851
    49         foreach ($meta as $meta_key=>$meta_value) {
     52        foreach ($meta as $meta_key => $meta_value) {
    5053            update_post_meta($postId, $meta_key, $meta_value);
    5154        }
     
    8083     * @return int
    8184     */
    82     public function publishPost(int $postId)
     85    public function publishPost(int $postId): int
    8386    {
    8487        do_action('fvcn_publish_post', $postId);
    85         return $this->changePostStatus($postId, PostType::STATUS_PUBLISH);
     88        return $this->changePostStatus($postId, Status::publish());
    8689    }
    8790
     
    9295     * @return int
    9396     */
    94     public function unpublishPost(int $postId)
     97    public function unpublishPost(int $postId): int
    9598    {
    9699        do_action('fvcn_unpublish_post', $postId);
    97         return $this->changePostStatus($postId, PostType::STATUS_PENDING);
     100        return $this->changePostStatus($postId, Status::pending());
    98101    }
    99102
     
    104107     * @return int
    105108     */
    106     public function spamPost(int $postId)
     109    public function spamPost(int $postId): int
    107110    {
    108111        do_action('fvcn_spam_post', $postId);
    109         return $this->changePostStatus($postId, PostType::STATUS_SPAM);
     112        return $this->changePostStatus($postId, Status::spam());
    110113    }
    111114
     
    114117     *
    115118     * @param int $postId
    116      * @param string $status
     119     * @param Status $status
    117120     * @return int
    118121     */
    119     protected function changePostStatus(int $postId, string $status)
     122    protected function changePostStatus(int $postId, Status $status): int
    120123    {
    121         $post = [];
    122         $post['ID'] = $postId;
    123         $post['post_status'] = $status;
     124        $post = [
     125            'ID' => $postId,
     126            'post_status' => $status->getStatus(),
     127        ];
    124128
    125129        return wp_update_post($post);
     
    127131
    128132    /**
    129      * increasePostRating()
     133     * likePost()
    130134     *
    131135     * @param int $postId
    132136     */
    133     public function increasePostRating(int $postId)
     137    public function likePost(int $postId)
    134138    {
    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);
    137141    }
    138142
    139143    /**
    140      * decreasePostRating()
     144     * unlikePost()
    141145     *
    142146     * @param int $postId
    143147     */
    144     public function decreasePostRating(int $postId)
     148    public function unlikePost(int $postId)
    145149    {
    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));
    148152    }
    149153
  • fv-community-news/trunk/src/Syncer/Api/Api.php

    r1843050 r1853982  
    6565    public static function latestVersion(): Api
    6666    {
    67         return new static(static::API_VERSIONS . '/current', 'GET');
     67        return new static(static::API_VERSIONS . '/latest', 'GET');
    6868    }
    6969
     
    101101
    102102    /**
    103      * Make an API request to add a star to a post.
     103     * Make an API request to add a like to a post.
    104104     *
    105      * @param int $id ID of the post to star.
     105     * @param int $id ID of the post to like.
    106106     * @return Api
    107107     */
    108     public static function starPost(int $id): Api
     108    public static function likePost(int $id): Api
    109109    {
    110         return new static(static::API_POSTS . '/' . $id . '/stars', 'POST');
     110        return new static(static::API_POSTS . '/' . $id . '/likes', 'POST');
    111111    }
    112112
    113113    /**
    114      * Make an API request to remove a star from a post.
     114     * Make an API request to remove a like from a post.
    115115     *
    116      * @param int $id ID of the post to unstar.
     116     * @param int $id ID of the post to unlike.
    117117     * @return Api
    118118     */
    119     public static function unstarPost(int $id): Api
     119    public static function unlikePost(int $id): Api
    120120    {
    121         return new static(static::API_POSTS . '/' . $id . '/stars', 'DELETE');
     121        return new static(static::API_POSTS . '/' . $id . '/likes', 'DELETE');
    122122    }
    123123}
  • fv-community-news/trunk/src/Syncer/Syncer.php

    r1843050 r1853982  
    3636                'url' => \fvcn_get_post_link($postId),
    3737                '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),
    3939                'views' => \fvcn_get_post_views($postId),
    4040                'thumbnail' => $thumbnail,
     
    5252            if (!empty($response)) {
    5353                \update_post_meta($postId, '_fvcn_post_synced', $response['post']['id']);
    54                 return \absint($response['post']['id']);
     54                return $response['post']['id'];
    5555            }
    5656
     
    7979
    8080    /**
    81      * Submit a star increase to the API.
     81     * Submit a like to the API.
    8282     *
    8383     * @param int $postId
    8484     * @return void
    8585     */
    86     public function increasePostRating(int $postId)
     86    public function likePost(int $postId)
    8787    {
    8888        $apiId = $this->submitPost($postId);
     
    9292        }
    9393
    94         $this->executeRequest(Api::starPost($apiId), [], ['blocking' => false]);
     94        $this->executeRequest(Api::likePost($apiId), [], ['blocking' => false]);
    9595    }
    9696
    9797    /**
    98      * Submit a star decrease to the API.
     98     * Submit an unlike to the API.
    9999     *
    100100     * @param int $postId
    101101     * @return void
    102102     */
    103     public function decreasePostRating(int $postId)
     103    public function unlikePost(int $postId)
    104104    {
    105105        $apiId = $this->submitPost($postId);
     
    109109        }
    110110
    111         $this->executeRequest(Api::unstarPost($apiId), [], ['blocking' => false]);
     111        $this->executeRequest(Api::unlikePost($apiId), [], ['blocking' => false]);
    112112    }
    113113
  • fv-community-news/trunk/src/Version.php

    r1843050 r1853982  
    2727    public static function getCurrentVersion()
    2828    {
    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'];
    3033    }
    3134
  • fv-community-news/trunk/src/View/AjaxForm.php

    r1810381 r1853982  
    44
    55use FvCommunityNews\Post\Controller;
    6 use FvCommunityNews\Post\PostType;
     6use FvCommunityNews\Post\Status;
    77use WP_Error;
    88
     
    7373        $postId = $this->postController->createPost();
    7474
    75         if (fvcn_has_errors()) {
     75        if (!empty($this->error->get_error_codes())) {
    7676            $errors = [];
    7777            foreach ($this->error->get_error_codes() as $code) {
     
    8484            ];
    8585        } else {
    86             if (PostType::STATUS_PUBLISH == fvcn_get_post_status($postId)) {
     86            if (Status::publish() == fvcn_get_post_status($postId)) {
    8787                $permalink = fvcn_get_post_permalink($postId);
    8888                $message = '';
  • fv-community-news/trunk/src/Widget/Form.php

    r1806332 r1853982  
    5252        ?>
    5353
    54         <?php if (fvcn_is_anonymous_allowed() || !fvcn_is_anonymous()) : ?>
     54        <?php if (fvcn_container_get('Config')['_fvcn_is_anonymous_allowed'] || !fvcn_is_anonymous()) : ?>
    5555
    5656            <?php fvcn_get_template_part('fvcn/form', 'post'); ?>
  • fv-community-news/trunk/src/Widget/ListPosts.php

    r1810381 r1853982  
    7878    {
    7979        $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']);
    8383        $instance['num_posts'] = $new_instance['num_posts'];
    8484
     
    100100    public function form($instance)
    101101    {
    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']) : '';
    106106        ?>
    107107
Note: See TracChangeset for help on using the changeset viewer.