PHP Classes

Crow Simple PHP Blog Github: Use Github as a content manager for blog posts

Recommend this page to a friend!
  Info   View files Example   Videos Videos   View files View files (49)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 113 This week: 1All time: 9,554 This week: 108Up
Version License PHP version Categories
crow-web-client 1.0.0GNU General Publi...5.5PHP 5, Content management, Web services
Description 

Author

This package can use Github as a content manager for blog posts.

It provides a Web interface to create blog posts with data that is stored in a Git repository in GitHub.

The blog is published in a domain provided by GitHub as a sub-domain of github.io.

Innovation Award
PHP Programming Innovation award winner
December 2018
Winner


Prize: One big elePHPant Plush Mascott
Github is a well-known site for publishing projects based on files that are changed. Each file revision can be stored using Git version control software.

Since it can manage the revisions of any types of files, it can also manage the posts of a blog.

This package can manage a blog using a Git repository hosted on GitHub.

Manuel Lemos
Picture of naveen
  Performance   Level  
Name: naveen <contact>
Classes: 5 packages by
Country: India India
Innovation award
Innovation award
Nominee: 2x

Winner: 2x

Example

<?php
session_start
();
require
'template_handler.php';
require
'lib/api.github.php';
require
'headers.php';
require
'lib/commonFunctions.php';

if (empty(
$_SESSION['authorized_email'])) {
   
header("location: login.php");
    exit();
}

if (isset(
$_GET['show_message'])) {
    if (!empty(
$_GET['show_message'])) {
       
$show_message = $_GET['show_message'];
       
$show_message = str_replace("+", " ", $show_message);
       
$alertLoader = new Loader();
       
$alertLoader->set_template_file("success_message");
       
$alertLoader->assign("MESSAGE_INFO", $show_message);
       
$alertLoader->output();
    }
}

if (isset(
$_POST)) {
    if (!empty(
$_POST['cr_post_title']) && !empty($_POST['cr_post_description'])) {

       
$post_action = $_POST['form_action'];
       
       
//either be create, update, delete
       
if ($post_action == "edit_post" && !empty($_POST['cr_post_id'])) {
           
$post_id = $_POST['cr_post_id'];
           
$post_title = $_POST['cr_post_title'];
           
$post_description = $_POST['cr_post_description'];
           
$post_description = html_entity_decode($post_description);
           
$propertyName = array("title", "description");
           
$propertyValue = array($post_title, $post_description);
           
$arr = updateArrayByProperty ("id", $post_id,$propertyName, $propertyValue, $_SESSION['posts']);

           
$_SESSION['posts'] = updateArrayByProperty ("id", $post_id,$propertyName, $propertyValue, $_SESSION['posts']);
           
           
pushUpdatedFile ("cr_posts.json", $_SESSION['posts_file_sha'], $_SESSION['posts'], $_SESSION['access_token'], $_SESSION['owner'], $_SESSION['repo_name'], $_SESSION['user_email']);
           
           
//get the changed sha and store
           
$pathToFile = "cr_posts.json";
           
$file_info = getFileUrl($_SESSION['access_token'], $_SESSION['owner'], $_SESSION['repo_name'], $pathToFile);
           
$_SESSION['posts_file_sha'] = $file_info['sha'];
           
$message = "Edits are Saved";
           
$message = urlencode($message);
           
header("location: index.php?show_message=$message");
            exit();
           
        }
        else if (
$post_action == "create_post") {
           
$random_id = md5(str_shuffle(time()));
           
           
$post_title = $_POST['cr_post_title'];
           
$post_description = $_POST['cr_post_description'];
           
$post_description = html_entity_decode($post_description);
           
$propertyName = array("id","title","description","date_created", "author", "author_url");
           
$date_created = date("Y-m-d", time());
           
$author_url = "https://github.com/".$_SESSION['owner'];
           
$propertyValue = array($random_id, $post_title, $post_description, $date_created, $_SESSION['owner'], $author_url);
           
$_SESSION['posts'] = addArrayToExistingArray($propertyName, $propertyValue, $_SESSION['posts']);

           
pushUpdatedFile ("cr_posts.json", $_SESSION['posts_file_sha'], $_SESSION['posts'], $_SESSION['access_token'], $_SESSION['owner'], $_SESSION['repo_name'], $_SESSION['user_email']);
           

           
$pathToFile = "cr_posts.json";
           
$file_info = getFileUrl($_SESSION['access_token'], $_SESSION['owner'], $_SESSION['repo_name'], $pathToFile);
           
$_SESSION['posts_file_sha'] = $file_info['sha'];
           
$message = "Post was successfully created";
           
$message = urlencode($message);
           
header("location: index.php?show_message=$message");
            exit();
           
        }
    }
}


$loader = new loader();
$loader->set_template_file("index");




$access_token = $_SESSION['access_token'];

//TEST CASES
//1.the repo might not be present (Dont proceed)
//2.The repo is present (fetch json files to sessions);
//3.AccessToken may turn invalid

if (!isset($_SESSION['posts'])) {

   
$owner_array = getOwnerInfo($access_token);
   
$username = $owner_array['login'];
   
$_SESSION['user_email'] = $owner_array['email'];

   
$repo_name = $username.".github.io";

   
$_SESSION['owner'] = $username;

   
$_SESSION['repo_name'] = $repo_name;

   
$pathToFile = "cr_posts.json";

   
$file_info = getFileUrl($access_token, $username, $repo_name, $pathToFile);

   
$file_url = $file_info['download_url'];

   
$_SESSION['posts'] = getContentsFile($file_url);

   
$_SESSION['posts_file_sha'] = $file_info['sha'];

   
$POSTS = "";
    foreach (
$_SESSION['posts'] as $key) {
       
$navigation_posts = new loader();
       
$navigation_posts->set_template_file("display_posts_navigation");
       
$navigation_posts->assign("TITLE", $key['title']);
       
$navigation_posts->assign("ID", $key['id']);
       
$navigation_posts->assign("BLOG_URL", $_SESSION['repo_name']);
       
$POSTS = $POSTS.$navigation_posts->returnHtml();
   
    }

   
//obtain site settings
   
$pathToFile = "cr_info.json";

   
$file_info = getFileUrl($access_token, $username, $repo_name, $pathToFile);

   
$file_url = $file_info['download_url'];

   
$_SESSION['site_settings'] = getContentsFile($file_url);

   
$_SESSION['site_settings_sha'] = $file_info['sha'];


   
$loader->assign("TITLE", "write a post - Crow");
   
$loader->assign("CR_POSTS", $POSTS);
   
$loader->assign("POST_ACTION", "create_post");
   
$loader->assign("POST_TITLE", "");
   
$loader->assign("POST_DESCRIPTION", "");
   
$loader->assign("ACTION_TEXT", "create post");
   
$loader->output();
}
else if (!empty(
$_GET['id']) && !empty($_GET['mode'])) {

   
$mode = $_GET['mode'];

   
$id = $_GET['id'];

   
$TITLE = " ";

   
$DESCRIPTION = " ";

   
$POSTS = "";
   
    foreach (
$_SESSION['posts'] as $key) {
       
$navigation_posts = new loader();
       
$navigation_posts->set_template_file("display_posts_navigation");
       
$navigation_posts->assign("TITLE", $key['title']);
       
$navigation_posts->assign("ID", $key['id']);
       
$navigation_posts->assign("BLOG_URL", $_SESSION['repo_name']);
       
$POSTS = $POSTS.$navigation_posts->returnHtml();
        if (
$key['id'] == $id) {
           
$TITLE = $key['title'];
           
$DESCRIPTION = $key['description'];
        }
    }

    if (
$mode == "edit") {
           
$loader->assign("TITLE", "Edit this post - ".$TITLE);
           
$loader->assign("CR_POSTS", $POSTS);
           
$loader->assign("POST_TITLE", $TITLE);
           
$loader->assign("POST_DESCRIPTION", $DESCRIPTION);
           
$loader->assign("ACTION_TEXT", "Update Post");
           
$loader->assign("POST_ACTION", "edit_post");
           
$loader->assign("CR_POST_ID", $id);
           
$loader->output();
    }
    else if (
$mode == "delete") {
       
$navigationBarLoader = new Loader();
       
$navigationBarLoader->set_template_file("navigation_bar");
       
$navigationBarLoader->assign("TITLE", $TITLE);
       
$navigationBarLoader->output();
       
$confirmDeleteLoader = new loader();
       
$confirmDeleteLoader->set_template_file("confirm_delete");
       
$confirmDeleteLoader->assign("POST_TITLE", $TITLE);
       
$confirmDeleteLoader->assign("POST_DESCRIPTION", substr($DESCRIPTION, 0, 500));
       
$confirmDeleteLoader->assign("ID", $id);
       
$confirmDeleteLoader->output();
       
$footerLoader = new Loader();
       
$footerLoader->set_template_file("footer");
       
$footerLoader->assign("h", "");
       
$footerLoader->output();
    }
    else if (
$mode == "confirm_delete") {
       
$navigationBarLoader = new Loader();
       
$navigationBarLoader->set_template_file("navigation_bar");
       
$navigationBarLoader->assign("TITLE", $TITLE);
       
$navigationBarLoader->output();
       
//remove the key from the session array
       
$keyRemovedArray = removeKeyFromJSONArrayByProperty("id", $id, $_SESSION['posts']);
       
//update the content to host
       
$_SESSION['posts'] = array_values($keyRemovedArray);

       
pushUpdatedFile ("cr_posts.json", $_SESSION['posts_file_sha'], $_SESSION['posts'], $_SESSION['access_token'], $_SESSION['owner'], $_SESSION['repo_name'], $_SESSION['user_email']);

       
$pathToFile = "cr_posts.json";
       
$file_info = getFileUrl($_SESSION['access_token'], $_SESSION['owner'], $_SESSION['repo_name'], $pathToFile);
       
$_SESSION['posts_file_sha'] = $file_info['sha'];
       
header("location: index.php");
        exit();

    }
}

else {
   
$POSTS = "";
    foreach (
$_SESSION['posts'] as $key) {
       
$navigation_posts = new loader();
       
$navigation_posts->set_template_file("display_posts_navigation");
       
$navigation_posts->assign("TITLE", $key['title']);
       
$navigation_posts->assign("ID", $key['id']);
       
$navigation_posts->assign("BLOG_URL", $_SESSION['repo_name']);
       
$POSTS = $POSTS.$navigation_posts->returnHtml();
    }
   
$loader->assign("TITLE", "Write a post");
   
$loader->assign("CR_POSTS", $POSTS);
   
$loader->assign("POST_TITLE", "");
   
$loader->assign("POST_DESCRIPTION", "");
   
$loader->assign("ACTION_TEXT", "Create Post");
   
$loader->assign("POST_ACTION", "create_post");
   
$loader->output();
}


?>














<!-- library to support formatting in text area -->
<script src="js/medium-editor.js"></script>
<link rel="stylesheet" href="css/medium-editor.css">
<link rel="stylesheet" href="css/themes/tim.css">

<script>
var editor = new MediumEditor('.editable', {toolbar: {
                    buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'h2', 'h3', 'h1', 'h4', 'h5']
                       
                    },
                    placeholder: {
                      text: 'Enter your post description',
                    hideOnClick: true
                }
            });
</script>


Details

crow web client is a client for github blog cms crow.If you want to host a blog on github for free then crow can help you to do it.

1.To setup your free blog, fork this repo (https://github.com/naveen17797/crow) and rename it as yourgithubusername.github.io

2.Now place this crow web client package in your localhost (complete installation instructions available here (https://youtu.be/GKGUDhaStE0)

3.Start publishing posts from your localhost


  Files folder image Files  
File Role Description
Files folder imagecss (5 files, 1 directory)
Files folder imageimages (2 files)
Files folder imagejs (3 files)
Files folder imagelib (3 files)
Files folder imagetemplates (12 files)
Image file crow.png Data Auxiliary data
Plain text file headers.php Aux. Auxiliary script
Plain text file index.php Example Example script
Plain text file LICENSE Lic. License text
Plain text file login.php Example Example script
Plain text file README.md Doc. Documentation
Plain text file register.php Example Example script
Plain text file setup.php Example Example script
Plain text file site_settings.php Example Example script
Plain text file template_handler.php Class Class source

  Files folder image Files  /  css  
File Role Description
Files folder imagethemes (14 files)
  Plain text file bootstrap.min.css Data Auxiliary data
  Plain text file fontawesome.min.css Data Auxiliary data
  Plain text file medium-editor.css Data Auxiliary data
  Plain text file medium-editor.min.css Data Auxiliary data
  Plain text file style_default.css Data Auxiliary data

  Files folder image Files  /  css  /  themes  
File Role Description
  Plain text file beagle.css Data Auxiliary data
  Plain text file beagle.min.css Data Auxiliary data
  Plain text file bootstrap.css Data Auxiliary data
  Plain text file bootstrap.min.css Data Auxiliary data
  Plain text file default.css Data Auxiliary data
  Plain text file default.min.css Data Auxiliary data
  Plain text file flat.css Data Auxiliary data
  Plain text file flat.min.css Data Auxiliary data
  Plain text file mani.css Data Auxiliary data
  Plain text file mani.min.css Data Auxiliary data
  Plain text file roman.css Data Auxiliary data
  Plain text file roman.min.css Data Auxiliary data
  Plain text file tim.css Data Auxiliary data
  Plain text file tim.min.css Data Auxiliary data

  Files folder image Files  /  images  
File Role Description
  Image file icons8-github-filled-100.png Icon Icon image
  Image file icons8-gitlab-96.png Icon Icon image

  Files folder image Files  /  js  
File Role Description
  Plain text file angular.min.js Data Auxiliary data
  Plain text file medium-editor.js Data Auxiliary data
  Plain text file medium-editor.min.js Data Auxiliary data

  Files folder image Files  /  lib  
File Role Description
  Plain text file api.github.php Aux. Auxiliary script
  Plain text file class.json_handler.php Class Class source
  Plain text file commonFunctions.php Aux. Auxiliary script

  Files folder image Files  /  templates  
File Role Description
  HTML file confirm_delete.html Doc. Documentation
  HTML file display_posts_navigation.html Doc. Documentation
  HTML file error_alert.html Doc. Documentation
  HTML file footer.html Doc. Documentation
  HTML file index.html Doc. Documentation
  HTML file login.html Doc. Documentation
  HTML file navigation_bar.html Doc. Documentation
  HTML file register.html Doc. Documentation
  HTML file setup.html Doc. Documentation
  HTML file site_settings.html Doc. Documentation
  HTML file site_setting_item.html Doc. Documentation
  HTML file success_message.html Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:113
This week:1
All time:9,554
This week:108Up