Community Support for OpenDocMan (Deprecated)
Plug-ins patch (edit & add) - Printable Version

+- Community Support for OpenDocMan (Deprecated) (https://forum.opendocman.com)
+-- Forum: OpenDocMan Community Discussion (https://forum.opendocman.com/forum-5.html)
+--- Forum: OpenDocMan Patches (https://forum.opendocman.com/forum-10.html)
+--- Thread: Plug-ins patch (edit & add) (/thread-415.html)



Plug-ins patch (edit & add) - sokac - 05-29-2011

This patch is allowing developers to get file id from own plugin.

[attachment=0]

Here are changes in methods Plugin_class.php (not included in patch)
Code:
/*
     * This function is run after a new file is added
     */
    function onAfterAdd($fileId) {}

    /*
     * This function is run before the edit file form is finished being rendered
     */
    function onBeforeEditFile($fileId) {}

    /*
     * This function is run after the user saves and change to a file
     */
    function onAfterEditFile($fileId) {}



Re: Plug-ins patch (edit & add) - Stephen - 05-29-2011

I think I need to edit add.php and edit.php as well.

Something like this:
add.php
Code:
callPluginMethod('onAfterAdd',$fileId);

This will ensure the current $fileid is passed to the onAfterAdd method automatically.

Does that make sense?


Re: Plug-ins patch (edit & add) - sokac - 05-29-2011

Affected files are (see in patch):
add.php
edit.php
functions.php

As you can see, callPluginMethod('onAfterAdd'); was changed to callPluginMethod('onAfterAdd', $fileId); (and for onBeforeEdit and onAfterEdit).

Changes in Plugin_class.php are optional (for documentation)

Patch.diff:
Code:
diff -urB opendocman-unstable-daily-orig/add.php opendocman-unstable-daily/add.php
--- opendocman-unstable-daily-orig/add.php    2011-05-27 08:01:13.000000000 +0200
+++ opendocman-unstable-daily/add.php    2011-05-27 22:00:59.949135276 +0200
@@ -634,7 +634,7 @@
         $message = urlencode(msg('message_document_added'));

         // Call the plugin API
-        callPluginMethod('onAfterAdd');
+        callPluginMethod('onAfterAdd', $fileId);
        
         header('Location: out.php?last_message=' . $message);
     }
diff -urB opendocman-unstable-daily-orig/edit.php opendocman-unstable-daily/edit.php
--- opendocman-unstable-daily-orig/edit.php    2011-05-27 08:01:13.000000000 +0200
+++ opendocman-unstable-daily/edit.php    2011-05-27 22:18:05.584915775 +0200
@@ -474,7 +474,7 @@
         </td>
<?php
     // Call Plugin API
-    callPluginMethod('onBeforeEditFile');
+    callPluginMethod('onBeforeEditFile', $data_id);
?>
    </tr>
    </table>
@@ -576,7 +576,7 @@
    $message = urlencode('Document successfully updated');

         // Call the plugin API
-        callPluginMethod('onAfterEditFile');
+        callPluginMethod('onAfterEditFile', $_REQUEST['id']);

         header('Location: out.php?last_message=' . $message);
}
diff -urB opendocman-unstable-daily-orig/functions.php opendocman-unstable-daily/functions.php
--- opendocman-unstable-daily-orig/functions.php    2011-05-27 08:01:13.000000000 +0200
+++ opendocman-unstable-daily/functions.php    2011-05-27 22:00:40.918758424 +0200
@@ -788,7 +788,7 @@
      * @param string $method The name of the plugin method being envoked.
      * @return null
      */
-    function callPluginMethod($method)
+    function callPluginMethod($method, $data=null)
     {
         foreach ($GLOBALS['plugin']->pluginslist as $value)
         {
@@ -797,6 +797,6 @@
                 echo 'Sorry, your plugin ' . $value . ' is not setup properly';
             }
             $plugin_obj = new $value;
-            $plugin_obj->$method();
+            $plugin_obj->$method($data);
         }
     }



Re: Plug-ins patch (edit & add) - Stephen - 05-29-2011

Great, the changes I am committing are basically the same changes that you have here but with some minor differences in variable naming.


Re: Plug-ins patch (edit & add) - Stephen - 05-29-2011

I just committed the changes to the SVN trunk. Please let me know if everything works for you.


Re: Plug-ins patch (edit & add) - sokac - 05-29-2011

Great, it works Wink


Re: Plug-ins patch (edit & add) - mohsinj677 - 12-14-2013

Sounds like you have a typo. Try grabbing v1.2.6.4, it contains a more permanent attempt at solving the mime issue.