Skip to content

Commit

Permalink
🚀 first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdyar committed Aug 26, 2021
0 parents commit 104d21e
Show file tree
Hide file tree
Showing 36 changed files with 2,509 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Telelog

Keep track of everything happening on your WordPress in Telegram.

## Set up

1. Create a new Telegram bot. ([Learn more](https://core.telegram.org/bots#3-how-do-i-create-a-bot))
2. Go to TeleLog admin page from your wordpress dashboard.
3. Copy your bot token from botfather and paste it in the "API Key" field.
4. If you want TeleLog to send the logs to your personal account, you can use your userid and put it in the "Chat ID" field ([Find your userid](https://t.me/userinfobot)), the other option is to create a channel and make your bot an admin with "Post Messages" access and enter the channel username as "Chat ID", with an atsign(@) before it, e.g: `@username`.
Empty file added assets/scripts.js
Empty file.
Empty file added assets/styles.css
Empty file.
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "mahdyar/telelog",
"description": "Keep track of everything happening on your WordPress in Telegram",
"keywords": [
"telegram",
"logging",
"wordpress",
"wp",
"log",
"wordpress log"
],
"type": "project",
"license": "GPL",
"autoload": {
"psr-4": {
"Telelog\\Inc\\": "inc/"
}
},
"homepage": "https://github.com/mahdyar/telelog",
"authors": [
{
"name": "Mahdyar Hasanpour",
"email": "hasanpour@mahdyar.me",
"homepage": "https://mahdyar.me"
}
],
"minimum-stability": "dev",
"require": {}
}
18 changes: 18 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions inc/Base/Activate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Base;

class Activate
{
public static function activate()
{
flush_rewrite_rules();

if (get_option('telelog_on_post_publish') === false)
update_option('telelog_on_post_publish', '1');
if (get_option('telelog_on_post_update') === false)
update_option('telelog_on_post_update', '1');
}
}
20 changes: 20 additions & 0 deletions inc/Base/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Base;

class BaseController
{
public $plugin_path;
public $plugin_url;
public $plugin;
public function __construct()
{
$this->plugin_path = plugin_dir_path(dirname(__FILE__, 2));
$this->plugin_url = plugin_dir_url(dirname(__FILE__, 2));
$this->plugin = plugin_basename(dirname(__FILE__, 3)) . '/telelog.php';
}
}
20 changes: 20 additions & 0 deletions inc/Base/Deactivate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Base;

class Deactivate
{
public static function deactivate()
{
flush_rewrite_rules();

delete_option('telelog_api_key');
delete_option('telelog_chat_id');
delete_option('telelog_on_post_update');
delete_option('telelog_on_post_publish');
}
}
25 changes: 25 additions & 0 deletions inc/Base/Enqueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Base;

use \Telelog\Inc\Base\BaseController;

class Enqueue extends BaseController
{
/**
* Enqueue the scripts and stylesheets
* @return void
*/
public function register()
{
// add_action('admin_enqueue_scripts', array($this, 'enqueue'));
}
function enqueue()
{
// wp_enqueue_script('telelog_scripts', $this->plugin_url . 'assets/scripts.js', __FILE__);
}
}
23 changes: 23 additions & 0 deletions inc/Base/SettingsLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Base;

use \Telelog\Inc\Base\BaseController;

class SettingsLinks extends BaseController
{
public function register()
{
add_filter("plugin_action_links_$this->plugin", array($this, 'add_settings_link'));
}
public function add_settings_link($links)
{
$settings_link = '<a href="admin.php?page=telelog">' . __('Settings', 'telelog') . '</a>';
array_unshift($links, $settings_link);
return $links;
}
}
17 changes: 17 additions & 0 deletions inc/Base/Translation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Base;

use Telelog\Inc\Base\BaseController;

class Translation extends BaseController
{
public function register()
{
load_plugin_textdomain('telelog', false, str_replace('/telelog.php', '/languages/', $this->plugin));
}
}
51 changes: 51 additions & 0 deletions inc/Init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc;


final class Init
{
/**
* Store all the classes inside an array
* @return array list of classes
*/
public static function get_services()
{
return [
Base\Translation::class,
Pages\Admin::class,
Base\Enqueue::class,
Base\SettingsLinks::class,
Telegram\PostTransition::class,
];
}

/**
* Loop through the classes, initialize them,
* and call the register() function if it exists
* @return void
*/
public static function register_services()
{
foreach (self::get_services() as $class) {
$service = self::instantiate($class);
if (method_exists($service, 'register')) {
$service->register();
}
}
}

/**
* Initialize the class
* @param class $class class from the services array
* @return object new instance of the class
*/
private static function instantiate($class)
{
return new $class();
}
}
57 changes: 57 additions & 0 deletions inc/Pages/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Pages;

use Telelog\Inc\Pages\Callbacks\AdminCallbacks;

class Admin
{
public $callbacks;

public $settings = array();

public $sections = array();

public $fields = array();

/**
* Add TeleLog to the admin menu
* @return void
*/
public function register()
{
$this->callbacks = new AdminCallbacks();
add_action('admin_menu', array($this, 'add_admin_pages'));
add_action('admin_init', array($this, 'register_custom_fields'));
}

/**
* Add the admin pages
* @return void
*/
public function add_admin_pages()
{
add_menu_page(__('TeleLog', 'telelog'), __('TeleLog', 'telelog'), 'manage_options', 'telelog', array($this->callbacks, 'admin_index'), 'dashicons-megaphone', 110);
}

public function register_custom_fields()
{
register_setting('telelog_options', 'telelog_api_key', array($this->callbacks, 'sanitize_api_key'));
register_setting('telelog_options', 'telelog_chat_id', array($this->callbacks, 'sanitize_chat_id'));
register_setting('telelog_options', 'telelog_on_post_publish', array($this->callbacks, 'sanitize_on_post_publish'));
register_setting('telelog_options', 'telelog_on_post_update', array($this->callbacks, 'sanitize_on_post_update'));

add_settings_section('api_settings', __('Settings', 'telelog'), array($this->callbacks, 'api_settings_text'), 'telelog');
add_settings_section('hooks_settings', __('Hooks', 'telelog'), array($this->callbacks, 'hooks_settings_text'), 'telelog');

add_settings_field('telelog_api_key', __('API Key', 'telelog'), array($this->callbacks, 'telelog_api_key'), 'telelog', 'api_settings');
add_settings_field('telelog_chat_id', __('Chat ID', 'telelog'), array($this->callbacks, 'telelog_chat_id'), 'telelog', 'api_settings');

add_settings_field('telelog_on_post_publish', __('Post Publish', 'telelog'), array($this->callbacks, 'telelog_on_post_publish'), 'telelog', 'hooks_settings');
add_settings_field('telelog_on_post_update', __('Post Update', 'telelog'), array($this->callbacks, 'telelog_on_post_update'), 'telelog', 'hooks_settings');
}
}
Loading

0 comments on commit 104d21e

Please sign in to comment.