Elgg, how to get all actions? - elgg

i need to register to the events of the actions in elgg framework
( like making a post or adding a friend)
Is there a way of doing so ?

In the bundled Developer Tools plugin you can inspect all registered actions, events, and plugin hooks and what handler functions are bound to them. You can use functions like elgg_register_event_handler and elgg_register_plugin_hook_handler to register callbacks on events/hooks that occur.

Actions like posting a blog or making a comment can be registered into the Elgg actions system through this API (eventually saved in $CONFIG->actions as an array):
elgg_register_action($action, $filename = "", ...)
After you have registered an action, you can perform it by the URL http://elggsite.org/action/action_name/ either through form post or ajax.
The action_name url segment correspond to the first parameter passed in the elgg_register_action() API.
Furthermore, you can dump all actions registered into Elgg by
var_dump($CONFIG->actions);
after Elgg finishes booting.

Related

Prestashop : Decorate a module's service from another module

I want to use the module ps_facebook to send a catalog to Facebook but I need to change the name of the product sent.
I already sought and I found that's the module ps_eventbus that manages to load and decorate datas.
Unfortunately there is no hook. My only possibility is to rewrite a part of this service.
This service is loaded by the module ps_eventbus in the file decorate.yml and I want to change the call of this service by our specific service in our module.
So I wonder if it's possible to override properly the service PrestaShop\Module\PsEventbus\Decorator\ProductDecorator and how to do that ?
I suggest you check the Symfony documentation, here
https://symfony.com/doc/3.4/service_container/service_decoration.html
As it is not directly related to the PrestaShop itself. If this service is public, you can probably decorate it, as shown in the docs.

Add IBAN check to widget validation

For an employee questionnaire I would like to add an IBAN check to a textbox widget. Is it possible to add a library like https://github.com/arhs/iban.js as an external resource in App Maker? How do I have to implement a validation method once the library has been added.
You can easily add any external library. If library is available via CDN (Content Delivery Network) you can just add URL in Application Settings -> External Resources -> JavaScript URLs
otherwise you can upload the js file as app resource (Settings -> Resources) and use resource's URL instead.
The library will help you to validate input on client:
// onValidate event of input widget:
if (!IBAN.isValid(newValue)) {
return 'Please, provide valid account number';
}
But it will not help you with server side validation... So, end user can in theory compromise your system through dev console. You can try to copy/paste library's code to server script and make extra validation in onBeforeCreate and onBeforeSave model's events but most likely it will require some additional tweaks.
You may also consider using Regex to validate the IBAN - you won't need to worry about pulling in external JS then. This answer may be useful. With this regex, you can validate the string server side, which is more secure. This link has more information on validating RegEx in Javascript.

Programmatically register routes at runtime

I want to be able to annotate some of my controllers with #SomethingProvider so that they automatically serve POST /{original-resource-url}/something URL and tie this URL to a generic handler.
Using a controller with wildcard mapping would not work because not all the resources will have that "something" collection available. Ex:
POST /user/something
POST /product/something
etc.
but not
POST /anything/something
My idea is to scan my controllers at runtime and look for that #SomethingProvider annotation so I can programmatically register the additional "something" endpoints.
I know it has to do with RequestMappingHandlerMapping but I can't figure out how to tap into it to add mappings.
Thanks geniuses

where sfGuard checks out perms and credentials in order to implement Google's Oauth 2

I want to integrate Google's Oauth2 in my symfony-1.4 CRM. I have successfully implemented this, I have extended sfGuardAuth in my own module, and now mysfGuardAuth is being used for siging and signout. Is there where I handle Google's Oauth2 with 2 extra actions:
executeCkeckGoogleAccess();
executeOauth();
The problem is to checkout if Google's token is still a valid one, I have to redirect in each action of everymodule to the action checkGoogleAccess in mysfGuardAuth module.
What I want is to check this in an implicit way in the same place where symfony, or sfGuard or whatever checks for the right perms or credentials before executing or not executing the requested action.
I only want to write the code once.
Thank you.
After some research this is how sfGuard checks everything.
When you make a request to a module action, before the action is executed, a new sfContext is dispached.
The sfContext gets the user that extends sfGuardUser and has some methods that are executed. There is where perms, session status and everithing else is checked
The user must be configured in apps/yourApp/lib
By default is apps/yourApp/lib/myUser which extends sfGuardUser. The most apropiate way to achieve this is to create a new user class like: apps/yourApp/lib/yourAppUser which extends aswell sfGuardUser, and there extend the methods initialize and/or shutdown with the functionality you want.
By this way I have achieved to get Google's Oauth2 working in my app.
I hope this is usefull for more people.
UPDATE
All described above is true, but if you want to check something always before an action execution you must use filters instead of whats described before.
Filters are executed before each action, so there you can checkout whatever you need having access to the current context, and set up new attributes for the user. In my case I wanna check if the requested action needs a google token, if true, then Another filter will check if the user has alraedy a valid token, in that case, nothing happens, otherwise, the user is redirected to the module/action which handles google token requests.
Comunication between diferent filters, actions and requests are handled via user attributes.
the user is an object of the clas myOwnUser which extends sfGuardSecurityUser, there the function signOut is extended in order to delete all attributes saved in "myOwnNamespace"

Orbeon - Multi-language template HTTP Service request

On a multi-language template I use a HTTP service to load a list of countries from a web service. The loading itself is done by an action that reacts to the Form Load event.
Since the names of the countries are different in each language, I would like to pass a parameter to the web service that specifies the language of the user.
Another option would be to select the correct label after the list has been loaded.
Unfortunately I don't have any clue on how to achieve this. Any ideas ?
I managed to pass the language to the web service by editing the source code manually. I added the language as web service request parameter with the following xml (added to the action).
<xforms:action context="instance('fr-service-request-instance')">
<xforms:action class="fr-set-service-value-action">
<xxforms:variable name="control-name" select="'requestor_country'" as="xs:string"/>
<xxforms:variable name="path" select="//*:language" as="xs:string"/>
<xforms:setvalue ref="$path" value="xxforms:instance('fr-language-instance')"/>
</xforms:action>
</xforms:action>
I still have one problem though, when the user switches language, the values are not loaded and the list is empty.
Currently the country list is loaded on the xforms-ready event. Which one should be used when switching language ?

Resources