Permalink
Browse files

Remove post_processor on multi shortener (use hook instead).

Delete shorten.bitly plugin
  • Loading branch information...
1 parent 2a27c1a commit ab08fe0e7a134858b245d60251935d3100304492 @cdujeu cdujeu committed May 9, 2016
@@ -1416,6 +1416,15 @@ public function createSharedMinisite($httpVars, &$update)
$this->getPublicAccessManager()->initFolder();
$hash = $shareObject->save();
$url = $this->getPublicAccessManager()->buildPublicLink($hash);
+ $existingShortForm = $shareObject->getShortFormUrl();
+ if(empty($existingShortForm)){
+ $shortForm = "";
+ Controller::applyHook("url.shorten", array($url, &$shortForm));
+ if(!empty($shortForm)){
+ $shareObject->setShortFormUrl($shortForm);
+ $shareObject->save();
+ }
+ }
// LOG AND PUBLISH EVENT
$update = isSet($httpVars["repository_id"]);
@@ -1,104 +0,0 @@
-<?php
-/*
- * Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
- * This file is part of Pydio.
- *
- * Pydio is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Pydio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
- *
- * The latest code can be found at <http://pyd.io/>.
- */
-
-use Pydio\Access\Core\AJXP_Node;
-use Pydio\Access\Core\UserSelection;
-use Pydio\Core\Services\ConfService;
-use Pydio\Core\Utils\Utils;
-use Pydio\Core\PluginFramework\Plugin;
-
-defined('AJXP_EXEC') or die( 'Access not allowed');
-
-/**
- * Use a developer Bit.ly account to shorten publiclet links.
- * @package AjaXplorer_Plugins
- * @subpackage Shorten
- */
-class BitlyShortener extends Plugin
-{
- public function postProcess($action, $httpVars, $params)
- {
- $jsonData = json_decode($params["ob_output"], true);
- if ($jsonData != false) {
- $url = $jsonData["publiclet_link"] ;
- $elementId = $jsonData["element_id"];
- } else {
- $url = $params["ob_output"];
- $elementId = -1;
- }
-
- $BITLY_USER = $this->getFilteredOption("BITLY_USER");
- $BITLY_APIKEY = $this->getFilteredOption("BITLY_APIKEY");
-
- if (empty($BITLY_USER) || empty($BITLY_APIKEY)) {
- print($url);
- $this->logError("Config", "Bitly Shortener : you must drop the conf.shorten.bitly.inc file inside conf.php and set the login/api key!");
- return;
- }
- $bitly_login = $BITLY_USER;
- $bitly_api = $BITLY_APIKEY;
- $format = 'json';
- $version = '2.0.1';
- $bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$bitly_login.'&apiKey='.$bitly_api.'&format='.$format;
- $response = Utils::getRemoteContent($bitly);
- $json = json_decode($response, true);
- if (isSet($json['results'][$url]['shortUrl'])) {
- print($json['results'][$url]['shortUrl']);
- $this->updateMetaShort($httpVars["file"], $elementId, $json['results'][$url]['shortUrl']);
- } else {
- print($url);
- }
- }
-
- protected function updateMetaShort($file, $elementId, $shortUrl)
- {
- $context = new UserSelection(ConfService::getRepository());
- $baseUrl = $context->currentBaseUrl();
- $node = new AJXP_Node($baseUrl.$file);
- if ($node->hasMetaStore()) {
- $metadata = $node->retrieveMetadata(
- "ajxp_shared",
- true,
- AJXP_METADATA_SCOPE_REPOSITORY
- );
- if ($elementId != -1) {
- if (!is_array($metadata["element"][$elementId])) {
- $metadata["element"][$elementId] = array();
- }
- $metadata["element"][$elementId]["short_form_url"] = $shortUrl;
- } else {
- if(isSet($metadata["shares"])){
- $key = array_pop(array_keys($metadata["shares"]));
- $metadata["shares"][$key]["short_form_url"] = $shortUrl;
- }else{
- $metadata['short_form_url'] = $shortUrl;
- }
- }
- $node->setMetadata(
- "ajxp_shared",
- $metadata,
- true,
- AJXP_METADATA_SCOPE_REPOSITORY
- );
- }
- }
-
-}
@@ -1,28 +0,0 @@
-<?php
-/*
-* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
-* This file is part of Pydio.
-*
-* Pydio is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* Pydio is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
-*
-* The latest code can be found at <http://pyd.io/>.
-*/
-$mess=array(
-"Bit.ly URL Shortener" => "Bit.ly URL-Kürzungsdienst",
-"Shorten Download Links before sending them back to the user. Requires a Bit.ly account." => "Links zum Herunterladen von Dateien vor dem Versand an Benutzer kürzen. Erfordert einen Bit.ly Zugang.",
-"User Name" => "Benutzername",
-"Bit.ly account user name" => "Benutzername bei Bit.ly",
-"API Key" => "API Key",
-"Bit.ly account API Key" => "Bit.ly API-Key",
-);
@@ -1,28 +0,0 @@
-<?php
-/*
-* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
-* This file is part of Pydio.
-*
-* Pydio is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* Pydio is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
-*
-* The latest code can be found at <http://pyd.io/>.
-*/
-$mess=array(
-"Bit.ly URL Shortener" => "Bit.ly URL Shortener",
-"Shorten Download Links before sending them back to the user. Requires a Bit.ly account." => "Shorten Download Links before sending them back to the user. Requires a Bit.ly account.",
-"User Name" => "User Name",
-"Bit.ly account user name" => "Bit.ly account user name",
-"API Key" => "API Key",
-"Bit.ly account API Key" => "Bit.ly account API Key",
-);
@@ -1,28 +0,0 @@
-<?php
-/*
-* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
-* This file is part of Pydio.
-*
-* Pydio is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* Pydio is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
-*
-* The latest code can be found at <http://pyd.io/>.
-*/
-$mess=array(
-"Bit.ly URL Shortener" => "Raccourcisseur d'URL Bit.ly",
-"Shorten Download Links before sending them back to the user. Requires a Bit.ly account." => "Raccourcir les liens de téléchargement avant de les renvoyer à l'utilisateur. Nécessite un compte Bit.ly.",
-"User Name" => "Nom d'utilisateur",
-"Bit.ly account user name" => "Nom d'utilisateur Bit.ly",
-"API Key" => "Clef API",
-"Bit.ly account API Key" => "Clef d'API Bit.ly",
-);
@@ -1,28 +0,0 @@
-<?php
-/*
-* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
-* This file is part of Pydio.
-*
-* Pydio is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* Pydio is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
-*
-* The latest code can be found at <http://pyd.io/>.
-*/
-$mess=array(
-"Bit.ly URL Shortener" => "Abbreviatore URL Bit.ly",
-"Shorten Download Links before sending them back to the user. Requires a Bit.ly account." => "Abbrevia i link di download prima di mostrarli all'utente. Richiede un account su 'Bit.ly'.",
-"User Name" => "Nome Utente",
-"Bit.ly account user name" => "Nome utente per Bit.ly",
-"API Key" => "Chiave API",
-"Bit.ly account API Key" => "Chiave API per Bit.ly",
-);
@@ -1,29 +0,0 @@
-<?php
-/*
-* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
-* This file is part of Pydio.
-*
-* Pydio is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* Pydio is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
-*
-* The latest code can be found at <http://pyd.io/>.
-*/
-$mess=array(
-"Bit.ly URL Shortener" => "Redutor de URLs Bit.ly",
-"Shorten Download URLs before sending them back to the user. Requires a Bit.ly account." => "Diminui o tamanho dos URLs de transferência antes de os dar ao utilizador. Requer uma conta Bit.ly.",
-"User Name" => "Nome de Utilizador",
-"Bit.ly account user name" => "Nome de utilizador Bit.ly",
-"API Key" => "Chave API",
-"Bit.ly account API Key" => "Chave API da conta Bit.ly",
-"Shorten Download Links before sending them back to the user. Requires a Bit.ly account." => "Shorten Download Links before sending them back to the user. Requires a Bit.ly account.",
-);
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ajxp_plugin id="shorten.bitly" enabled="false" label="CONF_MESSAGE[Bit.ly URL Shortener]" description="CONF_MESSAGE[Shorten Download Links before sending them back to the user. Requires a Bit.ly account.]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
- <plugin_info>
- <core_relation packaged="false" tested_version="6.2"/>
- </plugin_info>
- <client_settings>
- <resources>
- <i18n namespace="bitly_shortener" path="plugins/shorten.bitly/i18n" />
- </resources>
- </client_settings>
- <server_settings>
- <global_param name="BITLY_USER" type="string" label="CONF_MESSAGE[User Name]" description="CONF_MESSAGE[Bit.ly account user name]" mandatory="true"/>
- <global_param name="BITLY_APIKEY" type="string" label="CONF_MESSAGE[API Key]" description="CONF_MESSAGE[Bit.ly account API Key]" mandatory="true"/>
- </server_settings>
- <registry_contributions>
- <actions>
- <!-- Override a simple action -->
- <action name="share">
- <post_processing>
- <serverCallback methodName="postProcess" capture="true" applyCondition="$apply=(!isSet($httpVars['sub_action']) || $httpVars['sub_action'] == 'create_minisite');"/>
- </post_processing>
- </action>
- </actions>
- </registry_contributions>
- <class_definition filename="plugins/shorten.bitly/class.BitlyShortener.php" classname="BitlyShortener"/>
- <dependencies>
- <activePlugin pluginName="action.share"/>
- </dependencies>
-</ajxp_plugin>
@@ -1 +0,0 @@
-<p>Uses the Bit.ly webservice to automatically shorten the links generated for public files.</p>
@@ -28,33 +28,6 @@ public function processShortenHook($url, &$shorten){
$shorten = $this->generateLink($url);
}
- /**
- * @param $action
- * @param $httpVars
- * @param $params
- */
- public function postProcess($action, $httpVars, $params)
- {
- $type = $this->getFilteredOption("SHORTEN_TYPE");
- if(empty($type)) return;
- $jsonData = json_decode($params["ob_output"], true);
- $elementId = -1;
- if ($jsonData != false) {
- $url = $jsonData["publiclet_link"] ;
- $elementId = $jsonData["element_id"];
- } else {
- $url = $params["ob_output"];
- }
-
- $res = $this->generateLink($url);
- if(!empty($res)){
- $this->updateMetaShort($httpVars["file"], $elementId, $res);
- print($res);
- }else{
- print($url);
- }
- }
-
protected function generateLink($url){
$type = $this->getFilteredOption("SHORTEN_TYPE");
@@ -173,38 +146,5 @@ protected function generateLink($url){
return null;
}
-
- protected function updateMetaShort($file, $elementId, $shortUrl)
- {
- $context = new UserSelection(ConfService::getRepository());
- $baseUrl = $context->currentBaseUrl();
- $node = new AJXP_Node($baseUrl.$file);
- if ($node->hasMetaStore()) {
- $metadata = $node->retrieveMetadata(
- "ajxp_shared",
- true,
- AJXP_METADATA_SCOPE_REPOSITORY
- );
- if ($elementId != -1) {
- if (!is_array($metadata["element"][$elementId])) {
- $metadata["element"][$elementId] = array();
- }
- $metadata["element"][$elementId]["short_form_url"] = $shortUrl;
- } else {
- if(isSet($metadata["shares"])){
- $key = array_pop(array_keys($metadata["shares"]));
- $metadata["shares"][$key]["short_form_url"] = $shortUrl;
- }else{
- $metadata['short_form_url'] = $shortUrl;
- }
- }
- $node->setMetadata(
- "ajxp_shared",
- $metadata,
- true,
- AJXP_METADATA_SCOPE_REPOSITORY
- );
- }
- }
-
+
}
@@ -29,14 +29,6 @@
<global_param group_switch_name="shorten_type" group_switch_label="yourls" group_switch_value="yourls" name="YOURLS_USEIDN" type="boolean" label="CONF_MESSAGE[Use IDN]" description="CONF_MESSAGE[Use IDN]" mandatory="false" default="false"/>
</server_settings>
<registry_contributions>
- <actions>
- <!-- Override share action output / Backward compat -->
- <action name="share">
- <post_processing>
- <serverCallback methodName="postProcess" capture="true" applyCondition="$apply=(!isSet($httpVars['sub_action']) || $httpVars['sub_action'] == 'create_minisite');"/>
- </post_processing>
- </action>
- </actions>
<hooks>
<serverCallback methodName="processShortenHook" hookName="url.shorten"/>
</hooks>

0 comments on commit ab08fe0

Please sign in to comment.