Initial check-in of the works.

This commit is contained in:
Harald Milz 2019-03-22 20:48:56 +01:00
parent 929a0cc1b9
commit d82a54afdd
4 changed files with 309 additions and 0 deletions

19
Makefile Normal file
View file

@ -0,0 +1,19 @@
NAME = kal3000-gcal-import
INSTALLDIR = /usr/share/wordpress/wp-content/plugins/$(NAME)
VERSION = 0.1.0
release:
cd ..
zip -9 -r $(NAME)-$(VERSION).zip $(NAME)/*.php $(NAME)/*.txt
install:
mkdir -p $(INSTALLDIR)
cp -va *.txt *.php $(INSTALLDIR)
chown -R www-data:www-data $(INSTALLDIR)

64
gcal-import-worker.php Normal file
View file

@ -0,0 +1,64 @@
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
// we may need a http proxy for the fetch. Should be set from the admin page.
// define ('http_proxy', 'http://example.org:8080');
// we'll set this as category => proxy, link => link, active => 0;
// in the admin page, all entries will be displayed with a checkbox for activating, deactivating, deleting.
// TODO: housekeeping function. use WP scheduler.
// This is where the real work is done, i.e. retrieve, parse the GCAL, and insert the posts.
// Posting: simulate a real HTTPS POST
//
/**
* The worker gets called by the WP scheduler hourly.
* POST: simulates or performs a real POST.
*
* @since 0.1.0
*
*/
function gcal_import_worker()
{
error_log ("gcal_import_worker started", 0);
/*
* retrieve the proxy from the db, and if it exists, construct a context.
* TODO: USER:PASS in DB.
*
* http://www.pirob.com/2013/06/php-using-getheaders-and-filegetcontents-functions-behind-proxy.html
* http://ubuntu1804/site/wp-admin/post.php?post=128&action=edit
* vi +809 ./wp-admin/includes/post.php function wp_write_post()
*/
global $wpdb;
$table = $wpdb->prefix.GCAL_TABLE;
$structure = "SELECT gcal_category from $table ;";
$categories = $wpdb->query($structure);
foreach ( $categories as $category) {
error_log ("found category $category");
gcal_import_process_category($category);
}
error_log ("gcal_import_worker finished", 0);
}
function gcal_import_process_category($category) {
global $wpdb;
$table = $wpdb->prefix.GCAL_TABLE;
$structure = "SELECT gcal_link from $table WHERE gcal_category = '$category' AND gcal_active = '1' ;";
$link = $wpdb->query($structure);
}

156
gcal-import.php Normal file
View file

@ -0,0 +1,156 @@
<?php
/**
* Plugin Name: Kal3000 Google Calender Importer
* Plugin URI: https://github.com/hmilz/kal3000-gcal-import
* Description: Imports and Merges an Arbitrary Number of Public Google Calendars into Kal3000
* Version: 0.1
* Author: Harald Milz <hm@seneca.muc.de>
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0
* Domain Path: /languages
*
* {Plugin Name} is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* {Plugin Name} is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with {Plugin Name}. If not, see {License URI}.
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
define ('GCAL_TABLE', 'gcal_import');
// we may need a http proxy for the fetch. Should be set from the admin page.
// define ('http_proxy', 'http://example.org:8080');
/*
* gcal-import-install
* create DB table with:
* - gcal_category - name of the calendar, for later per-unit display
* - gcal_link - the public or private .ics link
* - gcal_veranstalter - ?
* - gcal_active - flag if a calendar is active or not. Default active.
*
*/
/**
* Initializes the plugin and creates a table
*
* @since 0.1.0
*
* - gcal_category - name of the calendar, for later per-unit display
* - gcal_link - the public or private .ics link
* - gcal_veranstalter - ?
* - gcal_active - flag if a calendar is active or not. Default active.
*/
function gcal_import_activate()
{
error_log ("gcal_import_activate started");
global $wpdb;
// CREATE will produce an error if the table exists already.
$table = $wpdb->prefix.GCAL_TABLE;
$structure = "CREATE TABLE IF NOT EXISTS $table (
id INT(9) NOT NULL AUTO_INCREMENT,
gcal_category VARCHAR(32) NOT NULL,
gcal_link VARCHAR(256) NOT NULL,
gcal_active INT(9) DEFAULT 1,
UNIQUE KEY id (id)
);";
$wpdb->query($structure);
/*
if () {
// Populate table
// this will later be set by the admin page
$wpdb->query("INSERT INTO $table(gcal_category, gcal_link, gcal_active)
VALUES('kv-freising', 'https://calendar.google.com/calendar/ical/gruene.freising%40gmail.com/public/basic.ics', '1')");
}
*/
if ( ! wp_next_scheduled( 'gcal_import_worker_hook' ) ) {
wp_schedule_event( time(), 'hourly', 'gcal_import_worker_hook' );
}
error_log ("gcal_import_activate finished");
}
register_activation_hook( __FILE__, 'gcal_import_activate' );
/**
* Deactivate unregisters the housekeeping function.
*
* @since 0.1.0
*
*/
function gcal_import_deactivate()
{
error_log ("gcal_import_deactivate started");
wp_clear_scheduled_hook('gcal_import_cron_hook' );
error_log ("gcal_import_deactivate finished");
}
register_deactivation_hook( __FILE__, 'gcal_import_deactivate' );
/**
* Uninstall drops our DB table
*
* @since 0.1.0
*
*/
function gcal_import_uninstall()
{
error_log ("gcal_import_uninstall started");
// can we uninstall without deactivating first?
// gcal_import_deactivate;
global $wpdb;
$table = $wpdb->prefix.GCAL_TABLE;
$structure = "DROP TABLE $table ;";
$wpdb->query($structure);
error_log ("gcal_import_uninstall finished");
}
register_uninstall_hook( __FILE__, 'gcal_import_uninstall' );
/**
* Display the admin table
* may go to a separate file eventually
*
* @since 0.1.0
*
*/
function gcal_import_admin()
{
global $wpdb;
$table = $wpdb->prefix.GCAL_TABLE;
// we MUST protect queries,
// see https://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks
// $sql = $wpdb->prepare( 'INSERT INTO $table ... ' , value_parameter[, value_parameter ... ] );
}
// The real work goes here.
require_once dirname( __FILE__ ) . "/gcal-import-worker.php";
add_action( 'gcal_import_worker_hook', 'gcal_import_worker' );

70
readme.txt Normal file
View file

@ -0,0 +1,70 @@
=== Test Plugin ===
Contributors: user, user, user
Tags: tag, tag, tag
Donate link: http://example.com/
Requires at least: 4.0
Tested up to: 4.8
Requires PHP: 5.6
Stable tag: 1.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Short description of this great plugin. No more than 150 characters, no markup.
== Description ==
Long description of this great plugin. No characters limit, and you can use markdown.
For backwards compatibility, if this section is missing, the full length of the short description will be used, and
markdown parsed.
Ordered list:
1. Some feature
1. Another feature
1. Something else about the plugin
Unordered list:
* something
* something else
* third thing
Link to [WordPress](http://wordpress.org/ "Your favorite software") and one to [Markdown's Syntax Documentation][markdown syntax].
Titles are optional, naturally.
Asterisks for *emphasis*.
Double it up for **strong**.
== Installation ==
1. Upload "test-plugin.php" to the "/wp-content/plugins/" directory.
1. Activate the plugin through the "Plugins" menu in WordPress.
1. Place "do_action( 'plugin_name_hook' );" in your templates.
== Frequently Asked Questions ==
= A question that someone might have =
An answer to that question.
= What about foo bar? =
Answer to foo bar dilemma.
== Screenshots ==
1. The screenshot description corresponds to screenshot-1.(png|jpg|jpeg|gif).
2. The screenshot description corresponds to screenshot-2.(png|jpg|jpeg|gif).
3. The screenshot description corresponds to screenshot-3.(png|jpg|jpeg|gif).
== Changelog ==
= 0.2 =
* A change since the previous version.
* Another change.
= 0.1 =
* Initial release.
== Upgrade Notice ==
= 0.2 =
Upgrade notices describe the reason a user should upgrade
= 0.1 =
This version fixes a security related bug. Upgrade immediately.