Skip to content

Commit

Permalink
v1.3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vaakash committed Jun 13, 2021
1 parent 876b959 commit 4ec15d1
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 26 deletions.
25 changes: 21 additions & 4 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,18 @@ public static function pull_posts(){
return;
}

$all_repos = Git_It_Write::all_repositories();
if( !isset( $all_repos[ $id ] ) ){
self::print_notice( 'Invalid repository ID', 'error' );
return;
}

$pull_type = $g[ 'pull' ];
if( !in_array( $pull_type, array( 'force', 'changes' ) ) ){
self::print_notice( 'Invalid pull type', 'error' );
return;
}

echo '<h2>Pulling posts [' . $g[ 'pull' ] . ']</h2>';

define( 'GIW_ON_GUI', true );
Expand Down Expand Up @@ -451,13 +463,18 @@ public static function sidebar(){
echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>';

echo '<form class="subscribe_form" action="https://aakashweb.us19.list-manage.com/subscribe/post?u=b7023581458d048107298247e&amp;id=ef5ab3c5c4" method="post" name="mc-embedded-subscribe-form" target="_blank" novalidate>
<input type="email" value="" name="EMAIL" class="required subscribe_email_box" id="mce-EMAIL" placeholder="Your email address">
<input type="email" value="' . get_option( 'admin_email' ) . '" name="EMAIL" class="required subscribe_email_box" id="mce-EMAIL" placeholder="Your email address">
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_b7023581458d048107298247e_ef5ab3c5c4" tabindex="-1" value=""></div>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button subscribe_btn">
</form>';
</form>
<div class="follow_btns">
<a href="https://twitter.com/intent/follow?screen_name=aakashweb" target="_blank" class="button twitter_btn"><span class="dashicons dashicons-twitter"></span> Follow on Twitter</a>
<a href="https://www.facebook.com/aakashweb/" target="_blank" class="button facebook_btn"><span class="dashicons dashicons-facebook-alt"></span> on Facebook</a>
<a href="https://www.aakashweb.com/wordpress-plugins/" target="_blank" class="button"><span class="dashicons dashicons-arrow-right-alt2"></span> More WordPress plugins</a>
</div>
';

echo '<a href="https://www.facebook.com/aakashweb" target="_blank" class="cta_link">Follow me on Facebook <span class="dashicons dashicons-arrow-right-alt"></span></a>';
echo '<a href="https://www.twitter.com/aakashweb" target="_blank" class="cta_link">Follow me on Twitter <span class="dashicons dashicons-arrow-right-alt"></span></a>';
echo '</div>';

echo '<div class="side_card">';
Expand Down
21 changes: 20 additions & 1 deletion admin/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ table.widefat td {
padding: 5px 10px;
}
.log_wrap > p:hover{
background: #016087;
background: #2271b1;
}

/* Toolbar */
Expand Down Expand Up @@ -134,6 +134,25 @@ table.widefat td {
margin: 7px 3px 0 0;
}

.side_card .follow_btns > a{
display: block;
text-align: center;
margin-bottom: 15px;
}
.side_card .follow_btns > a:last-child{
margin-bottom: 0;
}
.twitter_btn.button{
background: #1b95e0;
color: #fff;
border-color: transparent;
}
.facebook_btn.button{
background: #4080ff;
color: #fff;
border-color: transparent;
}

@media screen and (max-width: 950px) {
#main{
display: block;
Expand Down
8 changes: 4 additions & 4 deletions git-it-write.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
Description: Publish markdown files present in a Github repository as posts to WordPress automatically
Author: Aakash Chakravarthy
Author URI: https://www.aakashweb.com/
Version: 1.2
Version: 1.3
*/

define( 'GIW_VERSION', '1.2' );
define( 'GIW_VERSION', '1.3' );
define( 'GIW_PATH', plugin_dir_path( __FILE__ ) ); // All have trailing slash
define( 'GIW_ADMIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) . 'admin' ) );

final class Git_It_Write{

public static function init(){

self::includes();

}
Expand Down Expand Up @@ -76,7 +76,7 @@ public static function all_repositories(){
}

public static function general_settings(){

$settings = get_option( 'giw_general_settings', array() );
$default_settings = self::default_general_settings();

Expand Down
8 changes: 4 additions & 4 deletions includes/publish-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public static function publish_by_id( $repo_id ){
$repository = false;

// Cache the repository class object
if( array_key_exists( $username, self::$repo_obj_cache ) && array_key_exists( $repo_name, self::$repo_obj_cache[ $username ] ) ){
$repository = self::$repo_obj_cache[ $username ][ $repo_name ];
if( array_key_exists( $username, self::$repo_obj_cache ) && array_key_exists( $repo_name, self::$repo_obj_cache[ $username ] ) && array_key_exists( $branch, self::$repo_obj_cache[ $username ][ $repo_name ] ) ){
$repository = self::$repo_obj_cache[ $username ][ $repo_name ][ $branch ];
}else{
GIW_Utils::log( 'Creating repository object' );
$repository = new GIW_Repository( $username, $repo_name, $branch );
self::$repo_obj_cache[ $username ][ $repo_name ] = $repository;
self::$repo_obj_cache[ $username ][ $repo_name ][ $branch ] = $repository;
}

$publisher = new GIW_Publisher( $repository, $repo_config );
Expand All @@ -46,7 +46,7 @@ public static function publish_by_id( $repo_id ){

public static function publish_by_repo_full_name( $full_name ){

GIW_Utils::log( '********** Publishing posts by repository full name ' . $full_name . ' **********' );
GIW_Utils::log( '********** Publishing posts by repository full name ' . $full_name . ' **********' );

$name_split = explode( '/', $full_name );
if( count( $name_split ) != 2 ){
Expand Down
2 changes: 1 addition & 1 deletion includes/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function add_to_structure( $structure, $path_split, $item ){

public function build_repo_structure(){

GIW_Utils::log( 'Building repo structure...' );
GIW_Utils::log( 'Building repo structure ...' );

$tree_url = $this->tree_url();
$data = $this->get_json( $tree_url );
Expand Down
30 changes: 26 additions & 4 deletions includes/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class GIW_Utils{
public static function log( $message = '' ){

try{
$file = GIW_PATH . 'logs/log.log';

$file = self::log_file_path();
$line_tmpl = '%s - %s';

$message = is_array( $message ) ? json_encode( $message ) : $message;

$date = date('m/d/Y H:i');
Expand All @@ -31,7 +31,7 @@ public static function log( $message = '' ){
public static function read_log( $total_lines = 500 ){
// https://stackoverflow.com/a/2961685/306961

$log_path = GIW_PATH . 'logs/log.log';
$log_path = self::log_file_path();

if( !file_exists( $log_path ) ){
return array('Nothing logged yet !');
Expand All @@ -53,6 +53,28 @@ public static function read_log( $total_lines = 500 ){

}

public static function logs_folder_path(){

$upload_dir_info = wp_upload_dir();
$logs_folder = $upload_dir_info[ 'basedir' ] . '/git-it-write';

if( !file_exists( $logs_folder ) ){
wp_mkdir_p( $logs_folder );
file_put_contents( $logs_folder . '/.htaccess', 'deny from all', FILE_APPEND | LOCK_EX );
file_put_contents( $logs_folder . '/index.html', '', FILE_APPEND | LOCK_EX );
}

return $logs_folder;

}

public static function log_file_path(){

$logs_folder = self::logs_folder_path();
return $logs_folder . '/log.log';

}

public static function remove_extension_relative_url( $url ){
/**
* Accepts only a relative URL. Starting with . or /
Expand Down
Empty file removed logs/index.html
Empty file.
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ If a repository has files in the below structure,

Then below posts will be created like below (if permalinks are configured and the post type supports "hierarchy" i.e creating posts level by level (example: pages))

https:\\example.com\docs\guide\introduction\
https:\\example.com\docs\guide\getting-started\
https:\\example.com\help\faq\
https://example.com/docs/guide/introduction/
https://example.com/docs/guide/getting-started/
https://example.com/help/faq/

### 🎲 What is the use of this plugin ?

Expand Down
15 changes: 10 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Donate link: https://www.paypal.me/vaakash/
License: GPLv2 or later
Requires PHP: 5.3
Requires at least: 4.4
Tested up to: 5.5
Stable tag: 1.2
Tested up to: 5.8
Stable tag: 1.3

Publish markdown files present in a Github repository as posts to WordPress automatically

Expand All @@ -35,9 +35,9 @@ If a repository has files in the below structure,

Then below posts will be created like below (if permalinks are configured and the post type supports "hierarchy" i.e creating posts level by level (example: pages))

https:\\example.com\docs\guide\introduction\
https:\\example.com\docs\guide\getting-started\
https:\\example.com\help\faq\
https://example.com/docs/guide/introduction/
https://example.com/docs/guide/getting-started/
https://example.com/help/faq/

### 🎲 What is the use of this plugin ?

Expand Down Expand Up @@ -140,6 +140,11 @@ Yes, if you want to pull posts from a folder in a repository then you can specif

## Changelog

### 1.3
* New: Support for git branches (Thanks to https:/AppalachiaInteractive for the contribution)
* New: Logs directory has been changed to the uploads directory.
* Fix: Minor admin page enhancements.

### 1.2
* New: Support for custom fields
* New: New shortcode attribute in `[giw_edit_link]` to automatically wrap in `p` tag.
Expand Down

0 comments on commit 4ec15d1

Please sign in to comment.