<?xml version="1.0" encoding="UTF-8"?>
<ajxp_plugin name="share" label="CONF_MESSAGE[Sharing Features]" description="CONF_MESSAGE[Share Center actions and hooks]"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
    <server_settings>
        <global_param name="DISABLE_ALL_SHARING" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Disable all sharing on files or folders]" label="CONF_MESSAGE[Disable all sharing]" type="boolean" default="false" expose="false"/>
        <global_param name="DISABLE_RESHARING" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Disallow all sharing for shared workspaces]" label="CONF_MESSAGE[Disable resharing]" type="boolean" default="true" expose="false"/>
        <global_param name="ENABLE_FILE_PUBLIC_LINK" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Allow users to generate public links on files]" label="CONF_MESSAGE[Files: enable public links]" type="boolean" default="true" expose="true"/>
        <global_param name="ENABLE_FILE_INTERNAL_SHARING" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Enable internal file sharing (sharing with users existing or temporary users)]" label="CONF_MESSAGE[Files: enable internal sharing]" type="boolean" mandatory="true" default="true" expose="true"/>
        <global_param name="ENABLE_FOLDER_PUBLIC_LINK" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Allow users to generate public links on folders]" label="CONF_MESSAGE[Folders: enable public links]" type="boolean" default="true" expose="true"/>
        <global_param name="ENABLE_FOLDER_INTERNAL_SHARING" group="CONF_MESSAGE[Authorizations]" description="CONF_MESSAGE[Enable internal folder sharing (sharing with users existing or temporary users)]" label="CONF_MESSAGE[Folders: enable internal sharing]" type="boolean" mandatory="true" default="true" expose="true"/>
        <global_param name="HASH_MIN_LENGTH" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Minimum length of the generated hash]" label="CONF_MESSAGE[Hash minimum length]" type="integer" default="6"/>
        <global_param name="HASH_USER_EDITABLE" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Allow users to manually choose a hash for the generated links]" label="CONF_MESSAGE[Hash user-editable]" type="boolean" default="true" expose="true"/>
        <global_param name="FILE_MAX_EXPIRATION" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Maximum share expiration limit for file, 0 = unlimited]" label="CONF_MESSAGE[Maximum file expiration limit]" type="integer" default="0" expose="true"/>
        <global_param name="FILE_MAX_DOWNLOAD" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Maximum download limit for file, 0 = unlimited]" label="CONF_MESSAGE[Maximum file download limit]" type="integer" default="0" expose="true"/>
        <global_param name="SHARE_FORCE_PASSWORD" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Do not allow users to create public links, only private links (password-protected)]" label="CONF_MESSAGE[Set password mandatory]" type="boolean" default="false" expose="true"/>
        <global_param name="EMAIL_PERSONAL_LINK_SEND_CLEAR" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[For personal invitations (link is customized), let users choose whether to append clear email address or hashed string to link.]" label="CONF_MESSAGE[Choose personalized invitation format]" type="boolean" default="false" expose="true"/>
        <global_param name="EMAIL_INVITE_EXTERNAL" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Use external mailer for invitations]" label="CONF_MESSAGE[Force External Mailer]" type="boolean" default="false" expose="true"/>
        <global_param name="CREATE_QRCODE" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Create and display QRCode for shared link]" label="CONF_MESSAGE[Create QRCode]" type="boolean" default="false" expose="true"/>
        <global_param name="SHARED_FOLDER_SHOW_SEARCH" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Display a search form in the shared folder minisites. This can impact global performances as it will create indexes for all shares.]" label="CONF_MESSAGE[Allow search in minisite]" type="boolean" default="false" expose="true"/>
        <global_param name="INFOPANEL_DISPLAY_HTML_EMBED" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Display pasteable HTML snippet in right-hand information panel]" label="CONF_MESSAGE[Display HTML Embed code]" type="boolean" default="false" expose="true"/>
        <global_param name="INFOPANEL_DISPLAY_DIRECT_DOWNLOAD" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Display pasteable download link in right-hand information panel]" label="CONF_MESSAGE[Display Direct Download Link]" type="boolean" default="false" expose="true"/>
        <global_param name="AVOID_SHARED_FOLDER_SAME_LABEL" group="CONF_MESSAGE[Internal Sharing]" description="CONF_MESSAGE[Disallow users to create shared folders if a workspace already exists with the same label]" label="CONF_MESSAGE[Avoid labels duplication]" type="boolean" default="false"/>
        <global_param name="SHARED_USERS_TMP_PREFIX" group="CONF_MESSAGE[Internal Sharing]" description="CONF_MESSAGE[Mandatory prefix for users created temporary users login]" label="CONF_MESSAGE[Tmp users prefix]" type="string" expose="true"/>
        <global_param name="FORK_EVENT_FORWARDING" group="CONF_MESSAGE[Internal Sharing]" type="boolean" label="CONF_MESSAGE[Fork Events Forwarding]" description="CONF_MESSAGE[If you detect performances issues while modifiyng files under deep trees, try activating that one. Please be sure of what you do, this may trigger a whole lot of php processes on the server.]" default="false"/>
        <global_param name="WATCHER_SHARES_AUTO_OWNER" group="CONF_MESSAGE[Notifications]" type="boolean" label="CONF_MESSAGE[Shares Owner]" description="CONF_MESSAGE[When sharing with some internal users, choose whether the owner will be notified by default of any event happening on this share]" default="false" expose="true"/>
        <global_param name="WATCHER_SHARES_AUTO_USERS" group="CONF_MESSAGE[Notifications]" type="boolean" label="CONF_MESSAGE[Shares Target users]" description="CONF_MESSAGE[When sharing with some internal users, choose whether these users will be notified by default of any event happening on this share]" default="false" expose="true"/>
    </server_settings>
    <client_settings>
        <resources>
            <i18n namespace="share_center" path="plugins/action.share/res/i18n"/>
            <css file="plugins/action.share/res/react-share-form.css" autoload="true"/>
            <js file="plugins/action.share/res/build/model/ShareModel.js" className="ReactModelShare"/>
            <js file="plugins/action.share/res/build/model/ShareActions.js" className="ShareActions"/>
            <js file="plugins/action.share/res/build/ShareTemplates.js" className="ShareTemplates" depends="React,PydioComponents,PydioWorkspaces"/>
            <js file="plugins/action.share/res/build/ShareInfoPanel.js" className="ShareInfoPanel" depends="React,ReactModelShare"/>
            <js file="plugins/action.share/res/build/ShareDialog.js" className="ShareDialog" depends="React,ReactModelShare,PydioForm,PydioComponents"/>
            <js file="plugins/action.share/res/build/UserShares.js" className="UserShares" depends="React,PydioComponents"/>
        </resources>
    </client_settings>
    <registry_contributions>
        <actions>
            <action name="share_react">
                <gui text="292" title="292" iconClass="mdi mdi-share-variant" hasAccessKey="false">
                    <context selection="true" dir="true" recycle="hidden" actionBar="true" actionBarGroup="0_get,info_panel_share" contextMenu="true"/>
                    <selectionContext dir="true" file="true" recycle="false" unique="true" evalMetadata="!metadata.get('ajxp_shared')"/>
                </gui>
                <rightsContext noUser="true" userLogged="only" read="true" write="false" adminOnly=""/>
                <processing>
                    <clientCallback module="ShareActions.Callbacks.share"/>
                </processing>
            </action>
            <action name="share-edit-shared">
                <gui iconClass="mdi mdi-share-variant" text="share_center.125" title="share_center.126">
                    <context dir="true" recycle="hidden" selection="true" actionBar="true" contextMenu="true" actionBarGroup="0_get,info_panel_share" behaviour="hidden"/>
                    <selectionContext dir="true" file="true" evalMetadata="metadata.get('ajxp_shared')" recycle="false" unique="true" behaviour="hidden"/>
                </gui>
                <processing>
                    <clientCallback module="ShareActions.Callbacks.editShare"/>
                </processing>
            </action>
            <action name="share">
                <rightsContext noUser="true" userLogged="only" read="true" write="false" adminOnly=""/>
                <processing>
                    <serverCallback methodName="switchAction" restParams="/simple_share_type/file+" developerComment="Main action for sharing a file or a folder">
                        <input_param description="Path of the resource to share" name="nodes" type="AJXP_NODE[]" mandatory="true"/>
                        <input_param description="Simple type for sharing via the REST api, always links, public or private" name="simple_share_type" type="public|private" mandatory="false"/>
                        <input_param description="Specific type of sharing" name="sub_action" type="delegate_repo|create_minisite|public_link" mandatory="true"/>
                        <input_param description="For editing the data of an existing workspace/minisite" name="repository_id" type="string" mandatory="false"/>
                        <input_param description="For a workspace, directly set a watch on this for the current user" name="self_watch_folder" type="boolean"/>
                        <input_param description="For a minisite, will determine whether it will be public (true) or private (false), creating a temporary user in the first case." name="create_guest_user" type="boolean"/>
                        <input_param description="For a workspace/private minisite, define zero or more ACL for users" name="user_[n]" type="string"/>
                        <input_param description="For a workspace/private minisite, read right for user N" name="right_read_[n]" type="boolean"/>
                        <input_param description="For a workspace/private minisite, write right for user N" name="right_write_[n]" type="boolean"/>
                        <input_param description="For a workspace/private minisite, watch status for user N" name="right_watch_[n]" type="boolean"/>
                        <input_param description="For a public link, set a maximum number of downloads authorized" name="downloadlimit" type="integer"/>
                        <input_param description="For a public link, set a maximum number of authorized days" name="expiration" type="integer"/>
                        <input_param description="For a public link, set a password" name="password" type="string"/>
                        <input_param description="For a minisite on file or folder, force a custom link handle" name="custom_handle" type="string"/>
                        <input_param description="Additional plugins data that can be stored in the shared resource" name="PLUGINS_DATA" type="FORM_DATA"/>
                    </serverCallback>
                    </processing>
            </action>
            <action name="migrate_legacy_shares">
                <rightsContext adminOnly="true" noUser="false" read="true" userLogged="true" write="true"/>
                <processing>
                    <serverCallback methodName="migrateLegacyShares" restParams="/dry_run"/>
                </processing>
            </action>
            <action name="load_shared_element_data">
                <processing>
                    <serverCallback methodName="switchAction" restParams="/file+" developerComment="Loads all current sharing data for a given resource. Workspace must support metadata management (metastore).">
                        <input_param description="Path of the resource to share" name="file" type="path" mandatory="true"/>
                        <input_param description="Type of element to load (file or folder)" name="element_type" type="file|repository" mandatory="true"/>
                        <output type="application/json"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="unshare">
                <processing>
                    <serverCallback methodName="switchAction" restParams="/file+" developerComment="Stop sharing a folder, or remove a public link from a file.">
                        <input_param description="Path of the resource to unshare" name="file" type="path" mandatory="true"/>
                        <input_param description="Type of element to load (file or folder)" name="element_type" type="file|repository" mandatory="true"/>
                        <input_param description="If the resource is a file, send also the element_id, as many links can be generated for one file" name="element_id" type="string"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="toggle_link_watch">
                <processing>
                    <serverCallback methodName="switchAction" restParams="/file+" developerComment="Toggle a shared element status for being watched or not.">
                        <input_param description="Path of the resource to unshare" name="file" type="path" mandatory="true"/>
                        <input_param description="Type of element to load (file or folder)" name="element_type" type="file|repository" mandatory="true"/>
                        <input_param description="If the resource is a file, send also the element_id, as many links can be generated for one file" name="element_id" type="string"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="reset_counter">
                <processing>
                    <serverCallback methodName="switchAction" restParams="/file+" developerComment="Reset download counter for a given link generated on a file.">
                        <input_param description="Path of the resource to unshare" name="file" type="path" mandatory="true"/>
                        <input_param description="Send also the element_id, as many links can be generated for one file" name="element_id" type="string"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="share_link_update_target_users">
                <processing>
                    <serverCallback methodName="switchAction" restParams="/hash" developerComment="Store target users for a given link.">
                        <input_param description="Hash of the link" name="hash" type="path" mandatory="true"/>
                        <input_param description="Json encoded list of users, an associative array of unique keys and users label (e.g. email or label)." name="json_users" type="string"/>
                        <input_param description="Restrict link access to these users" name="restrict" type="boolean"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="forward_change_event">
                <processing>
                    <serverCallback methodName="forwardEventToSharesAction"/>
                </processing>
            </action>
            <action name="sharelist-edit">
                <gui src="share.png" iconClass="mdi mdi-share-variant" text="share_center.125" title="share_center.126">
                    <context dir="true" recycle="false" selection="true" actionBar="true" actionBarGroup="share_list_toolbar-selection" behaviour="hidden"/>
                    <selectionContext dir="true" file="true" evalMetadata="metadata.get('ajxp_shared')" recycle="false" unique="true" behaviour="hidden"/>
                </gui>
                <processing>
                    <clientCallback module="ShareActions.Callbacks.editFromList"/>
                </processing>
            </action>
            <action name="sharelist-load">
                <gui src="share.png" iconClass="icon-refresh" text="149" title="149">
                    <context dir="true" recycle="false" selection="false" actionBar="true" actionBarGroup="share_list_toolbar" behaviour="hidden"/>
                </gui>
                <processing>
                    <clientCallback module="ShareActions.Callbacks.loadList"/>
                </processing>
                <processing>
                    <serverCallback restParams="/" methodName="switchAction" sdkMethodName="loadShareList">
                        <input_param description="Parent repository ID" name="parent_repository_id" type="string" mandatory="false"/>
                        <input_param name="user_context" type="string" description="Either global (all users, requires admin right) or current (current user)" default="current"/>
                    </serverCallback>
                </processing>
            </action>
            <action name="sharelist-clearExpired">
                <gui text="user_dash.25" title="user_dash.26" iconClass="icon-time" accessKey="" hasAccessKey="false">
                    <context dir="true" selection="false" recycle="false" 
                             actionBar="true" contextMenu="false" infoPanel="false"
                             actionBarGroup="share_list_toolbar" inZip="false"/>
                </gui>
                <rightsContext noUser="true" userLogged="only" read="true" write="true" adminOnly=""/>
                <processing>
                    <clientCallback module="ShareActions.Callbacks.clearExpired"/>
                    <serverCallback methodName="switchAction" developerComment="Clear expired links" restParams="/"/>
                </processing>
            </action>
            <action name="sharelist-migrate">
                <processing>
                    <serverCallback methodName="switchAction" developerComment="Migrate Internal repositories to store" restParams="/"/>
                </processing>
            </action>
            <action name="share_current_page">
                <gui src="" iconClass="mdi mdi-share-variant" text="share_center.110" title="share_center.110">
                    <context dir="true" recycle="false" selection="false" actionBarGroup="minisite-share-actions" actionBar="true"/>
                </gui>
                <processing>
                    <clientCallback dialogOpenForm="share_current_url" dialogSkipButtons="true">
                        <dialogOnOpen><![CDATA[
                            modal.getForm().down("#crt-page-url").setValue(document.location.href);
                            if(pydioBootstrap.parameters.get('PRESET_LOGIN') === 'ajxp_preloged_user' && !ajaxplorer.getContextHolder().isEmpty() && pydio.getController().getActionByName("download")){
                                var tpl = new Template('<div style="font-size: 16px; padding-top:15px; text-align:left;">#{title} <a href="#{link}" target="_blank" class="icon-link" style="font-size: 0.8em;"></a></div><input type="text" value="#{link}" style="width: 98%;">');
                                var node = ajaxplorer.getContextHolder().getUniqueNode();
                                var editors = pydio.Registry.findEditorsForMime(node.getAjxpMime(), true);
                                if(editors.length && Class.getByName(editors[0].editorClass)){
                                    var staticClass = Class.getByName(editors[0].editorClass).prototype;
                                    if(staticClass.getRESTPreviewLinks){
                                        var links = staticClass.getRESTPreviewLinks(node);
                                        $H(links).each(function(pair){
                                            modal.getForm().down("#additional_links").insert(tpl.evaluate({title:pair.key,link:document.location.href.split('?').shift() + "/dl"+node.getPath()+"?ct=true"+pair.value}));
                                        });
                                    }
                                }
                                var dlLink = document.location.href.split('?').shift() + "/dl" + node.getPath();
                                modal.getForm().down("#additional_links").insert(tpl.evaluate({title:MessageHash['share_center.60'],link:dlLink}));
                            }
                        ]]></dialogOnOpen>
                        <dialogOnComplete><![CDATA[
                            hideLightBox();
                        ]]></dialogOnComplete>
                        <dialogOnCancel><![CDATA[]]></dialogOnCancel>
                    </clientCallback>
                    <clientForm id="share_current_url"><![CDATA[
                        <div id="share_current_url" box_width="300" style="text-align:center;">
                            <input type="text" id="crt-page-url" onclick="$(this).select();" value="" style="width: 387px;text-align: center;font-size: 19px;margin: 10px 0;padding: 5px;">
                            <div class="non_macos">AJXP_MESSAGE[share_center.143]</div>
                            <div class="macos_only" style="display:none;">AJXP_MESSAGE[share_center.144]</div>
                            <br>
                            <div id="additional_links" style="padding-bottom:10px;"></div>
                        </div>
                    ]]></clientForm>
                </processing>
            </action>
            <action name="download">
                <pre_processing>
                    <serverCallback methodName="preProcessDownload" applyCondition="$apply=\Pydio\Core\Services\SessionService::has(\Pydio\Core\Services\SessionService::CTX_MINISITE_HASH);"/>
                </pre_processing>
            </action>
            <action name="open_user_shares">
                <gui text="share_center.98" title="share_center.98" iconClass="mdi mdi-share-variant" accessKey="folder_access_key">
                    <context selection="false" dir="" recycle="false" actionBar="true" actionBarGroup="user" contextMenu="false" infoPanel="false"/>
                </gui>
                <rightsContext noUser="false" userLogged="only" read="false" write="false" adminOnly="false"/>
                <processing>
                    <clientCallback module="ShareActions.Callbacks.openUserShareView"/>
                </processing>
            </action>
        </actions>
        <client_configs>
            <template name="minisite_std_list" element="ajxp_shared_folder" position="top" label="share_center.153"
                      namespace="ShareTemplates" component="FolderMinisite" props='{"containerId":"ajxp_shared_folder","imageBackgroundFromConfigs":"gui.ajax/CUSTOM_SHAREPAGE_BACKGROUND_"}'/>

            <template name="minisite_film_strip" element="ajxp_film_strip" position="top" label="share_center.154"
                      namespace="ShareTemplates" component="FilmStripMinisite" props='{"containerId":"ajxp_film_strip","imageBackgroundFromConfigs":"gui.ajax/CUSTOM_SHAREPAGE_BACKGROUND_"}'/>

            <template name="unique_preview_file" element="ajxp_unique_strip" position="top" label="Unique File Preview"
                      namespace="ShareTemplates" component="FileMinisite" props='{"containerId":"ajxp_unique_strip","imageBackgroundFromConfigs":"gui.ajax/CUSTOM_SHAREPAGE_BACKGROUND_"}'/>

            <template name="unique_preview_download" element="ajxp_unique_dl" position="top" label="Big download button"
                      namespace="ShareTemplates" component="DLTemplate" props='{"containerId":"ajxp_unique_dl","imageBackgroundFromConfigs":"gui.ajax/CUSTOM_SHAREPAGE_BACKGROUND_"}'/>

            <template name="minisite_embed_list" element="ajxp_embed_template" position="top" label="share_center.155"
                      namespace="ShareTemplates" component="FolderMinisite" props='{"containerId":"ajxp_embed_template","minisiteMode":"embed","imageBackgroundFromConfigs":"gui.ajax/CUSTOM_SHAREPAGE_BACKGROUND_"}'/>

            <template name="minisite_dropbox" element="ajxp_dropbox_template" position="top" label="share_center.163"
                      namespace="ShareTemplates" component="DropZoneMinisite" props='{"containerId":"ajxp_dropbox_template","minisiteMode":"embed","imageBackgroundFromConfigs":"gui.ajax/CUSTOM_SHAREPAGE_BACKGROUND_"}'/>

            <component_config component="InfoPanel">
                <infoPanel mime="meta:ajxp_shared" reactComponent="ShareInfoPanel.InfoPanel" weight="-20"/>
            </component_config>
        </client_configs>
        <hooks>
            <serverCallback hookName="node.info.nocache" methodName="nodeSharedMetadata"/>
            <serverCallback hookName="node.change" methodName="updateNodeSharedData"/>
            <serverCallback hookName="user.after_delete" methodName="cleanUserShares" defer="true"/>
            <serverCallback hookName="workspace.after_delete" methodName="cleanWorkspaceShares" defer="true"/>
            <serverCallback methodName="forwardEventToShares" hookName="node.change" defer="true"/>
        </hooks>
    </registry_contributions>
    <class_definition filename="plugins/action.share/src/ShareCenter.php" classname="Pydio\Share\ShareCenter"/>
    <dependencies>
        <!--<activePlugin pluginName="access.AJXP_STREAM_PROVIDER|access.ajxp_user|access.ajxp_conf|access.ajxp_admin"/>-->
    </dependencies>
</ajxp_plugin>
