Not logged in. · Lost password · Register
Forum: General Help and Support General Stuff RSS
Calling a function from another PHP script?
Avatar
anegru #1
Member for 3 months · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: Calling a function from another PHP script?
So I am trying to make a script that will automatically add an Acl for a user based on information taken from a bureaucracy form. I'm trying to use remote.php since it has addAcl and delAcl functions in it. I tried using include 'remote.php' and require 'remote.php' but with either one I will get an error in Dokuwiki that says 

'Call to undefined function _getMethods() in C:\Users\...\dokuwiki\Main1\conf\plugin\bureaucracy\getpage.php on line 24'

I was wondering if there is a way to make my script recognize a function inside of another script and use it without having to import that function directly into the script. The site I am working on is internal so XML-RPC wouldn't make sense in this case... If someone knows an answer or even has suggestions to try please do!
Avatar
schplurtz (Moderator) #2
Member since Nov 2009 · 474 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
Use plugin_load( 'remote', 'acl' );
A quick example. I dont have time to check more. I'm not sure it will run if the user filling the form is not an admin, because only admins can add ACL... :-/
 
file conf/plugin/bureaucracy/truc.php contains this :
<?php
use dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface;
 
class helper_plugin_bureaucracy_handler_truc implements bureaucracy_handler_interface {
 
    /**
     * Just do some nonsense. ignore all input fields.
     */
    public function handleData($fields, $thanks)
    {
        global $ID;
 
        $acl=plugin_load( 'remote', 'acl' );
        $result=$acl->addAcl( 'somenamespace:*', 'someuser', AUTH_EDIT );
        $thanks .= '<hr>';
        $thanks .= 'add acl result : ';
        $thanks .= $result === true ? "OK" : "Not OK";
        $thanks .= '<div><p>'.html_wikilink( $ID, 'back to form' ).'</p></div>';
        // add some debug stuff.
        $thanks .= '<hr>';
        $foo='<pre>'.hsc(print_r($fields,true)).'</pre>';
        $thanks .= $foo;

        return $thanks;
    }
}

on a page, a bureaucracy form like this one :
<form>
action script truc.php
textbox "Type something"
submit "go"
</form>
Avatar
anegru #3
Member for 3 months · 5 posts
Group memberships: Members
Show profile · Link to this post
This worked completely! Thank you. Now its time to figure out a way in which only users in a particular group can call the script (In case anyone decides to call the script from another form). I've been looking into using the $INFO array but I seem to be having difficulties displaying it. If this is a separate issue and needs to be in a different post I will gladly do that as well. Let me know if you have any questions or need clarification!
Avatar
schplurtz (Moderator) #4
Member since Nov 2009 · 474 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
I've been looking into using the $INFO array but I seem to be having difficulties displaying it.
Try this :
global $INFO;
msg('<pre>'.hsc(print_r($INFO,true)).'</pre>');
Avatar
anegru #5
Member for 3 months · 5 posts
Group memberships: Members
Show profile · Link to this post
That helped a lot. Thanks again for your quick response! My site is coming together quite nicely now. So I have a page creation and page transition form set up on an admin page that can be accessed from another page where regular users can request access to projects that they are currently not a part of and cannot see.

The form will have a drop down menu with all the device names listed and another drop down menu with the reason why the user wants access. The request form is then sent by email action to the admin group. I'm currently trying to make the device drop down menu be dynamically filled from the devices namespaces that currently exist in the project_list namespace. That way, when a new device is added, the menu will include that device in the list.

I've been looking at the data plugin as it is included in the site I am working on but I am not sure how to proceed. Should I use a script action and modify a page field alias to include the device name after the user creates a new page? Let me know what you think and again, thank you so much for your continued help!
Avatar
schplurtz (Moderator) #6
Member since Nov 2009 · 474 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
Your question is becoming too complicated for me, as I'm not a developer.

But, well, I guess you could, as you suggest, create an action plugin that catches the IO_WIKIPAGE_WRITE event. You must get the event  BEFORE the page is actually saved, otherwise, it will be almost impossible to distinguish between page creation, edit and suppression. In the event handler, you could modify the data plugin database, add and remove components in a field alias. Possibly invalidate DW cache. This should not be too difficult.

Now, modifying another plugin database is probably not the best thing to do. Is there another solution ? I just don't know. Although a bit hackish, this should work.

The "See also" section on page IO_WIKIPAGE_WRITE, will lead you to PHP code of all the plugins that use this event (including the data plugin itself).
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-10-16, 19:59:12 (UTC +02:00)