-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin.php
78 lines (58 loc) · 2 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
Plugin Name: Edition Logger
Plugin URI: https://github.com/esuarezsantana/yourls-edition-logger
Description: Log every link edition
Version: 1.0
Author: Eduardo Suarez-Santana
Author URI: http://e.suarezsantana.com/
*/
// No direct call
if( !defined( 'YOURLS_ABSPATH' ) ) die();
require_once EDITIONLOGGER_KLOGGER_PATH . '/src/KLogger.php';
function editionlogger_environment_check() {
$required_params = array(
'EDITIONLOGGER_KLOGGER_PATH', // path to KLogger
'EDITIONLOGGER_LOGFILE', // File to log
);
foreach ( $required_params as $pname ) {
if ( !defined( $pname ) ) {
$message = 'Missing defined parameter '.$pname.' in plugin '. $thisplugname;
error_log( $message );
return false;
}
}
return true;
}
function editionlogger_insert_link ( $args ) {
editionlogger_environment_check();
$insert = $args[0];
$url = $args[1];
$keyword = $args[2];
if ( $insert ) {
$log = new KLogger ( EDITIONLOGGER_LOGFILE , KLogger::DEBUG );
$log->LogInfo("[".YOURLS_USER."] Link inserted: ( $keyword, $url )");
}
}
function editionlogger_delete_link ( $args ) {
editionlogger_environment_check();
$keyword = $args[0];
$log = new KLogger ( EDITIONLOGGER_LOGFILE , KLogger::DEBUG );
$log->LogInfo("[".YOURLS_USER."] Link deleted: ( $keyword )");
}
function editionlogger_edit_link ( $args ) {
editionlogger_environment_check();
$url = $args[0];
$keyword = $args[1];
$newkeyword = $args[2];
$new_url_already_there = $args[3];
$keyword_is_ok = $args[4];
// same check as in the source
if ( ( !$new_url_already_there || yourls_allow_duplicate_longurls() ) && $keyword_is_ok ) {
$log = new KLogger ( EDITIONLOGGER_LOGFILE , KLogger::DEBUG );
$log->LogInfo( "[".YOURLS_USER."] Link edited: $keyword -> ( $newkeyword, $url )" );
}
}
yourls_add_action( 'insert_link', 'editionlogger_insert_link' );
yourls_add_action( 'delete_link', 'editionlogger_delete_link' );
yourls_add_action( 'pre_edit_link', 'editionlogger_edit_link' );