Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable Substitution #30

Open
ConX opened this issue Feb 5, 2022 · 0 comments
Open

Variable Substitution #30

ConX opened this issue Feb 5, 2022 · 0 comments
Assignees

Comments

@ConX
Copy link
Owner

ConX commented Feb 5, 2022

Reported on dokuwiki.org by

It would be great to be able to insert other data as well, eg dates, username etc

eg I have a button that inserts

<todo startdate:yyyy-mm-dd @user>//my text here//</todo>

I'd like to be able to have custom button fill in information such as the date, time and username (or any other info calculated from that eg:

<todo startdate:@Date@ due:@date@+10 @@user@>Update AVG boot disk</todo>
would show as

<todo startdate:2015-02-25 due:2105-03-07 @Chris>Update AVG boot disk</todo>
To achieve the above date substitutions edit your action.php file in the plugin folder to include these additional lines:

    protected function loadCBData() {
        $json = new JSON(JSON_LOOSE_TYPE);
        $file = @[file_get_contents](http://www.php.net/file_get_contents)(DOKU_PLUGIN . "custombuttons/config.json");
        if(!$file) return false;
 
/** Start of new lines */
        $file = [str_replace](http://www.php.net/str_replace)('@@TODAY@@',[date](http://www.php.net/date)("Y-m-d"),$file);
        $file = [str_replace](http://www.php.net/str_replace)('@@USER@@',$client,$file);
        $file = [str_replace](http://www.php.net/str_replace)('@@ONEWEEK@@',[date](http://www.php.net/date)("Y-m-d",[strtotime](http://www.php.net/strtotime)('+7 days')),$file);
        $file = [str_replace](http://www.php.net/str_replace)('@@TWOWEEKS@@',[date](http://www.php.net/date)("Y-m-d",[strtotime](http://www.php.net/strtotime)('+14 days')),$file);
        $file = [str_replace](http://www.php.net/str_replace)('@@THREEWEEKS@@',[date](http://www.php.net/date)("Y-m-d",[strtotime](http://www.php.net/strtotime)('+21 days')),$file);
        $file = [str_replace](http://www.php.net/str_replace)('@@FOURWEEKS@@' ,[date](http://www.php.net/date)("Y-m-d",[strtotime](http://www.php.net/strtotime)('+28 days')),$file);
        $file = [str_replace](http://www.php.net/str_replace)('@@ONEMONTH@@',[date](http://www.php.net/date)("Y-m-d",[strtotime](http://www.php.net/strtotime)('+30 days')),$file);
/** End of new lines */
 
        return $json->decode($file);
    }

I'm still working on getting the username substituted in… If I'd known it was this simple I'd have done it ages ago. The placeholders to put in your button text are @@today@@, @@oneweek@@ etc. Hopefully, it's obvious enough to make your own tweaks.

@ConX ConX self-assigned this Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant