• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

XenWord Development in April 2016

Status
Not open for further replies.

LPH

Flight Director
Flight Instructor
The first day of April started off with attempting to tackle one of the most challenging areas of the XenWord plugin, the Comments System.

In particular, the counts.php page has been rewritten with PHP comments so that the coding can be followed better. The file is incomplete due to one of the four possibilities returning the thread count instead of the count of an array_merge.

Scenario One
A WordPress post is created prior to XenWord activation and has one WordPress comment

Scenario Two
A WordPress post is created prior to XenWord activation and numerous comments are made. Later this thread is tied to a XenForo discussion thread and more replies and comments are done.

Scenario Three
A WordPress post is created after XenWord activation and members add WordPress comments and XenForo replies.

Scenario Four
A WordPress post is created after XenWord activation and no comments or XenForo replies are published.

Scenario one will return a count of 1. Scenario Three and Four will return the thread reply_count which has the correct count.

Scenario Two does not return the correct comment count because it is returning the reply_count for the thread.

After hours of rewriting the count.php file, I'm exhausted and ready for bed. Have a great evening.
 

LPH

Flight Director
Flight Instructor
DRY is a concept that I've wanted to embrace for several years. This is why some of the code is refactored and files are renamed, etc. The past few days was spent on the Comments System and trying to figure out the best way to do loops.

The majority of my time was spent learning more about the Post Ratings add-on for XenForo. Here is a short video.

 

LPH

Flight Director
Flight Instructor
PhpStorm 2016 was installed, leading to trouble with BitBucket and the loss of connection. It took a few hours of reading and trying different things before finally using Git in the terminal to re-establish a connection.

A PHP Inspection plugin was installed in PhpStorm. This identified a few areas in the code that should be changed for optimization as well as pointed out some errors. A few bugs were identified and corrected.

Here is the changelog up to this point:

( 108 ) Alpha Release 3.0.4.01 - April 8, 2016
Bug Fix: Line 80 Counts.php
Bug Fix: Changed code for redirects for logout on WP Toolbar
Bug Fix: Access modifiers in class-xenword-redirects.php
PHP Inspection: xenword.php, change to __DIR__
PHP Inspection: class-xenword-activator.php change != to !== and remove two returns
PHP Inspection: class-xenword-deactivator.php remove return, use single quote
PHP Inspection: class-xenword-action-links.php use __DIR__
PHP Inspection: class-xenword-admin-notices.php use single quote, conditional ===
PHP Inspection: /XenForo/Index.php static::getXenForo();
PHP Inspection: class-xenword-avatars.php Use strpos instead of strstr
PHP Inspection: class-xenword-footer.php Use Yoda statement
PHP Inspection: class-xenword-includes.php static:: instead of $this
PHP Inspection: class-xenword-metabox-forumid.php hardening == to === line 69v
 

LPH

Flight Director
Flight Instructor
Fascinating coding today. I mainly worked on links today, and made sure the code uses XenForo_Link.

I installed the IDE Atom several months ago but never liked it. After doing an upgrade today and adding several WordPress plugins for the IDE, I decided to open the XenWord project. The style of the IDE provided a different enough view that some minor changes were made to the code.

( 109 ) Alpha Release 3.0.4.02 - April 10, 2016
Tested with WordPress 4.5-RC2, XenForo 1.5.7.
Bug Fix: Master On/Off Switch for comments stops loading of all comment files
Bug Fix: Discussion Link, reply count option (adding a CSS comment bubble)
Author_Link class now uses $thread array to build link
Changed Comment Author URL code in Display.php to use array to build link
Changed Latest member link in dashboard widget to canonical
Changed Online Members and Staff Members Widgets to canonical
Changed Board Totals Widget to canonical
Moved all comment files into the Comments folder; adjusted Autoloader.php
Renamed switch display_comments_in_wp to display_comments

These files are now live on tuxreports.com :)
 

LPH

Flight Director
Flight Instructor
Exhausting several days (20+ hours of getting no where fast). The comment counts were still incorrect and since the Comments.php file and Display.php files were torn apart, it took some time to reassemble in order to figure out the issue. The Counts.php file was too complicated so the majority of the code was stripped out and simplified to a few lines. Basically, the file looks for a thread, if present then returns the reply_count. This is probably the easiest way to handle things.

In terms of XenForo posts being written to WordPress, the good news is that it "sort of" works. The post is written, however, the newly created WordPress comment then writes back to XenForo. Conditionals for checking on a commentmeta origin value doesn't seem to stop the behavior. Sleep might help ;)
 

LPH

Flight Director
Flight Instructor
WordPress comments and XenForo replies are finally tied together. It was a simple change that escaped me until today. After weeks of trying different ways, someone explained wp_new_comment was triggering the preprocess_comment and comment_post hook. This meant the wp_new_comment was replaced with wp_insert_comment and the feature works.

The following video shows setting up XenWord from the start of a new WordPress installation to demonstrating a live update feature by activating the WordPress plugin wpDiscuz which enhances the default WordPress comment system.

 

LPH

Flight Director
Flight Instructor
Not convinced this is a worthy option, but while looking at the comment system, it seemed odd not to have the signature lines from the members posting on the WordPress side. The dashed separator line isn't proper but the "This is my signature" on the test environment is written from XenForo into the WordPress database.

Screen Shot 2016-04-23 at 9.17.15 AM.png

Found a huge bug in the quoting of comments. The comment_parent is coming from the WordPress database and does not match the proper post_id in XenForo. I don't have a solution yet but am working through some ideas.
 

LPH

Flight Director
Flight Instructor
Shifted my attention for the past few days on the login system. A WordPress cookie is not set and this means most caching plugins will not work properly. I stripped out the class-xenword-login-xfusers.php file and inserted in the following. Login works and a cookie is set. Logout requires a double click, which isn't acceptable. I'll keep fussing with it.

PHP:
add_action( 'after_setup_theme', 'xenword_login' );

function xenword_login( ) {
   
   $visitor = XenWord::getVisitor();
   XenWord_XF_Users::check_options();
   $user_id = $visitor::getUserId();

   if ( $user_id > 0 ) {

      $user = get_user_by( 'id', $user_id );

      if ( is_a( $user, 'WP_User' ) ) {
         wp_set_current_user( $user_id, $user->user_login );

         if ( !is_admin()) {
            wp_set_auth_cookie( $user_id );
         }

         do_action( 'wp_login', $user->user_login );
      }

   } else {
      wp_clear_auth_cookie();
      return true;
   }

   return false;
}
 

LPH

Flight Director
Flight Instructor
As posted earlier today, my attention shifted for a few days to the Login system. Using WordPress pluggable functions harms future upgradability of the plugin. This has happened a few times over the last few years. This is why I wanted to get wp_login or wp_signon working properly. The WordPress Logged in cookie now sets but caching plugins still aren't working correctly. :(

I'm stopping for a little while and have finished the following:

Code:
Code change: Authentication now uses do_action( 'wp_login', $user->user_login );
Removed signature code in Posts.php 
Bug Fix: if ( is_single( $post ) ) in Display.php
Bug Fix: XenWord_XF_Users::add_user $user_check is a string
Bug Fix: $post_ids = array(); in Posts.php

The change in authentication will take the plugin to 3.0.6.01 since it is a rather massive change. The last beta should be out after running this on this server.
 
Status
Not open for further replies.
Top