Minor - Flint fixes

pull/3953/head
Angel Fernando Quiroz Campos 4 years ago
parent c146d907f8
commit 5ff706b2a5
  1. 22
      diff
  2. 3
      main/common_cartridge/cc13_export.php
  3. 2
      main/common_cartridge/export/src/CcManifest.php
  4. 4
      main/common_cartridge/export/src/base/CcConverters.php
  5. 13
      main/common_cartridge/export/src/base/CcVersion1.php
  6. 4
      main/common_cartridge/export/src/base/XMLGenericDocument.php
  7. 9
      main/common_cartridge/export/src/lib/ccdependencyparser.php
  8. 1
      main/exercise/exercise_result.php
  9. 6
      main/inc/lib/webservices/Rest.php
  10. 5
      plugin/lti_provider/LtiProviderPlugin.php
  11. 1
      plugin/lti_provider/create.php
  12. 1
      plugin/lti_provider/db/lti13_cookie.php
  13. 4
      plugin/lti_provider/src/LtiProvider.php
  14. 2
      plugin/lti_provider/tool/api/score.php
  15. 1
      plugin/lti_provider/tool/login.php
  16. 3
      plugin/lti_provider/tool/start.php
  17. 2
      plugin/onlyoffice/3rdparty/jwt/BeforeValidException.php
  18. 2
      plugin/onlyoffice/3rdparty/jwt/ExpiredException.php
  19. 213
      plugin/onlyoffice/3rdparty/jwt/JWT.php
  20. 2
      plugin/onlyoffice/3rdparty/jwt/SignatureInvalidException.php
  21. 58
      plugin/onlyoffice/callback.php
  22. 30
      plugin/onlyoffice/create.php
  23. 37
      plugin/onlyoffice/editor.php
  24. 7
      plugin/onlyoffice/install.php
  25. 3
      plugin/onlyoffice/lang/bulgarian.php
  26. 3
      plugin/onlyoffice/lang/dutch.php
  27. 3
      plugin/onlyoffice/lang/english.php
  28. 1
      plugin/onlyoffice/lang/french.php
  29. 3
      plugin/onlyoffice/lang/german.php
  30. 3
      plugin/onlyoffice/lang/greek.php
  31. 3
      plugin/onlyoffice/lang/italian.php
  32. 3
      plugin/onlyoffice/lang/polish.php
  33. 3
      plugin/onlyoffice/lang/portuguese.php
  34. 3
      plugin/onlyoffice/lang/russian.php
  35. 1
      plugin/onlyoffice/lang/spanish.php
  36. 15
      plugin/onlyoffice/lib/appConfig.php
  37. 18
      plugin/onlyoffice/lib/crypt.php
  38. 64
      plugin/onlyoffice/lib/fileUtility.php
  39. 16
      plugin/onlyoffice/lib/langManager.php
  40. 8
      plugin/onlyoffice/lib/onlyofficeActionObserver.php
  41. 10
      plugin/onlyoffice/lib/onlyofficeItemActionObserver.php
  42. 9
      plugin/onlyoffice/lib/onlyofficeItemViewObserver.php
  43. 8
      plugin/onlyoffice/lib/onlyofficePlugin.php
  44. 50
      plugin/onlyoffice/lib/onlyofficeTools.php
  45. 23
      plugin/onlyoffice/lib/templateManager.php
  46. 8
      plugin/onlyoffice/plugin.php
  47. 9
      plugin/onlyoffice/uninstall.php

22
diff

@ -1,22 +0,0 @@
diff --git a/main/inc/lib/webservices/Rest.php b/main/inc/lib/webservices/Rest.php
index 45408f9beccd6dd71d50654020d9a921cd4764a1..7fbacd658889ca10ce3393759fcdac3c13cbeb9b 100644
--- a/main/inc/lib/webservices/Rest.php
+++ b/main/inc/lib/webservices/Rest.php
@@ -885,7 +885,7 @@ class Rest extends WebService
'display_order' => 0,
'session_id' => $sessionId,
'visibility' => 1,
- ]
+ ],
],
Link::getLinkCategories($courseId, $sessionId)
);
@@ -913,7 +913,7 @@ class Rest extends WebService
'title' => Security::remove_XSS($link['title']),
'description' => Security::remove_XSS($link['description']),
'visibility' => (int) $link['visibility'],
- 'url' => $webCodePath."link/link_goto.php?$cidReq&link_id=".$link['id']
+ 'url' => $webCodePath."link/link_goto.php?$cidReq&link_id=".$link['id'],
];
},
$links

@ -3,7 +3,6 @@
require_once __DIR__.'/../inc/global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'common_cartridge/export/src/lib/ccdependencyparser.php';
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
@ -85,8 +84,6 @@ if (Security::check_token('post') && ($action === 'course_select_form')) {
} else {
echo Display::return_message(get_lang('NoResourcesToBackup'), 'warning');
}
}
Display::display_footer();

@ -274,7 +274,7 @@ class CcManifest extends XMLGenericDocument implements CcIManifest
}
/**
* TODO - implement this method - critical
* TODO - implement this method - critical.
*/
private function fillManifest()
{

@ -15,8 +15,6 @@ abstract class CcConverters
/**
* ctor.
*
* @param CcIItem $item
* @param CcIManifest $manifest
* @param string $rootpath
* @param string $path
*
@ -44,7 +42,7 @@ abstract class CcConverters
/**
* performs conversion.
*
* @param string $outdir - root directory of common cartridge
* @param string $outdir - root directory of common cartridge
* @param object $objCourse
*
* @return bool

@ -223,8 +223,6 @@ class CcVersion1 extends CcVersionBase
/**
* Create a Resource (How to).
*
* @param CcIResource $res
* @param DOMDocument $doc
* @param object $xmlnode
*
* @return DOMNode
@ -262,8 +260,6 @@ class CcVersion1 extends CcVersionBase
/**
* Create an Item Folder (How To).
*
* @param CcIOrganization $org
* @param DOMDocument $doc
* @param DOMElement $xmlnode
*/
protected function createItemFolder(CcIOrganization &$org, DOMDocument &$doc, DOMElement &$xmlnode = null)
@ -285,8 +281,6 @@ class CcVersion1 extends CcVersionBase
/**
* Create an Organization (How To).
*
* @param CcIOrganization $org
* @param DOMDocument $doc
* @param object $xmlnode
*
* @return DOMNode
@ -306,8 +300,6 @@ class CcVersion1 extends CcVersionBase
/**
* Create Metadata For Manifest (How To).
*
* @param CcIMetadataManifest $met
* @param DOMDocument $doc
* @param object $xmlnode
*
* @return DOMNode
@ -334,8 +326,6 @@ class CcVersion1 extends CcVersionBase
/**
* Create Metadata For Resource (How To).
*
* @param CcIMetadataResource $met
* @param DOMDocument $doc
* @param object $xmlnode
*
* @return DOMNode
@ -353,8 +343,6 @@ class CcVersion1 extends CcVersionBase
/**
* Create Metadata For File (How To).
*
* @param CcIMetadataFile $met
* @param DOMDocument $doc
* @param object $xmlnode
*
* @return DOMNode
@ -479,7 +467,6 @@ class CcVersion1 extends CcVersionBase
* Create Lifecycle Metadata (How To).
*
* @param object $met
* @param DOMDocument $doc
* @param object $met
* @param object $xmlnode
*

@ -236,7 +236,7 @@ class XMLGenericDocument
}
/**
* Get the nodes from a path
* Get the nodes from a path.
*
* @param string $path
* @param DOMNode $nd
@ -256,7 +256,7 @@ class XMLGenericDocument
}
/**
* Get a list of nodes from a path
* Get a list of nodes from a path.
*
* @param string $path
* @param DOMNode $node

@ -76,10 +76,11 @@ function stripUrl($path, $rootDir = '')
}
/**
* Get full path
* Get full path.
*
* @param string $path
* @param string $dirsep
*
* @return false|string
*/
function fullPath($path, $dirsep = DIRECTORY_SEPARATOR)
@ -136,12 +137,12 @@ function isUrl($url)
}
/**
* Gets the dependency files of the $fname file
* Gets the dependency files of the $fname file.
*
* @param string $manifestroot
* @param string $fname
* @param string $folder
* @param array $filenames
* @param array $filenames
*/
function getDepFiles($manifestroot, $fname, $folder, &$filenames)
{
@ -164,7 +165,7 @@ function getDepFiles($manifestroot, $fname, $folder, &$filenames)
}
/**
* Gets the dependency of .html of the $fname file
* Gets the dependency of .html of the $fname file.
*
* @param string $manifestroot
* @param string $fname

@ -387,7 +387,6 @@ function showEmbeddableFinishButton()
$.get(url);
});
</script>';
}
return $js.PHP_EOL.$html;

@ -52,7 +52,7 @@ class Rest extends WebService
const GET_COURSE_LEARNPATH = 'course_learnpath';
const GET_COURSE_LP_PROGRESS = 'course_lp_progress';
const GET_COURSE_LINKS = 'course_links';
const GET_COURSE_WORKS= 'course_works';
const GET_COURSE_WORKS = 'course_works';
const SAVE_COURSE_NOTEBOOK = 'save_course_notebook';
@ -2549,7 +2549,7 @@ class Rest extends WebService
);
return array_map(
function (array $work) use ($isAllowedToEdit, $courseInfo, $courseId, $sessionId) {
function (array $work) use ($isAllowedToEdit, $courseInfo) {
$work['type'] = 'work.png';
if (!$isAllowedToEdit) {
@ -2601,7 +2601,7 @@ class Rest extends WebService
switch ($status) {
case 1:
return makeVisible($workId, $courseInfo);
case 0;
case 0:
return makeInvisible($workId, $courseInfo);
default:
throw new Exception(get_lang('ActionNotAllowed'));

@ -56,6 +56,7 @@ class LtiProviderPlugin extends Plugin
* Get a selectbox with quizzes in courses , used for a tool provider.
*
* @param null $issuer
*
* @return string
*/
public function getQuizzesSelect($issuer = null)
@ -79,7 +80,7 @@ class LtiProviderPlugin extends Plugin
);
foreach ($exerciseList as $key => $exercise) {
$selectValue = "{$course['code']}@@quiz-{$exercise['iid']}";
$htmlcontent .= '<option value="'.$selectValue.'" '.($toolProvider == $selectValue?' selected="selected"':'').'>'.Security::remove_XSS($exercise['title']).'</option>';
$htmlcontent .= '<option value="'.$selectValue.'" '.($toolProvider == $selectValue ? ' selected="selected"' : '').'>'.Security::remove_XSS($exercise['title']).'</option>';
}
$htmlcontent .= '</optgroup>';
}
@ -87,6 +88,7 @@ class LtiProviderPlugin extends Plugin
$htmlcontent .= ' </div>
<div class="col-sm-2"></div>
</div>';
return $htmlcontent;
}
@ -130,6 +132,7 @@ class LtiProviderPlugin extends Plugin
list($courseCode, $tool) = explode('@@', $toolProvider);
list($toolName, $toolId) = explode('-', $tool);
$vars = ['courseCode' => $courseCode, 'toolName' => $toolName, 'toolId' => $toolId];
return $vars;
}

@ -6,6 +6,7 @@ $cidReset = true;
require_once __DIR__.'/../../main/inc/global.inc.php';
use Chamilo\PluginBundle\Entity\LtiProvider\Platform;
use Chamilo\PluginBundle\LtiProvider\Form\FrmAdd;
require_once __DIR__.'/LtiProviderPlugin.php';
api_protect_admin_script();

@ -7,7 +7,6 @@ class Lti13Cookie implements Lti1p3Cookie
{
public function getCookie($name)
{
if (isset($_REQUEST['state']) && $name === 'lti1p3_'.$_REQUEST['state']) {
return $_REQUEST['state'];
}

@ -56,11 +56,10 @@ class LtiProvider
}
/**
* Verify if email user is in the platform to create it and login (true) or not (false)
* Verify if email user is in the platform to create it and login (true) or not (false).
*/
public function validateUser(array $launchData, string $courseCode): bool
{
if (empty($launchData)) {
return false;
}
@ -92,6 +91,7 @@ class LtiProvider
}
$login = UserManager::loginAsUser($userId, false);
return $login;
}
}

@ -38,7 +38,6 @@ $score = Packback\Lti1p3\LtiGrade::new()
->setGradingProgress('FullyGraded')
->setUserId($launch->getLaunchData()['sub']);
$scoreLineitem = Packback\Lti1p3\LtiLineitem::new()
->setTag('score')
->setScoreMaximum($weight)
@ -47,7 +46,6 @@ $scoreLineitem = Packback\Lti1p3\LtiLineitem::new()
$grades->putGrade($score, $scoreLineitem);
$time = Packback\Lti1p3\LtiGrade::new()
->setScoreGiven($duration)
->setScoreMaximum(999)

@ -3,6 +3,5 @@
require_once __DIR__.'/../../../main/inc/global.inc.php';
require_once __DIR__.'/../src/LtiProvider.php';
use Packback\Lti1p3;
LtiProvider::create()->login($_REQUEST);

@ -5,8 +5,6 @@ require_once __DIR__.'/../../../main/inc/global.inc.php';
require_once __DIR__.'/../src/LtiProvider.php';
require_once __DIR__.'/../LtiProviderPlugin.php';
use Packback\Lti1p3;
$launch = LtiProvider::create()->launch();
if (!$launch->hasNrps()) {
throw new Exception("Don't have names and roles!");
@ -23,4 +21,3 @@ $cidReq = 'cidReq='.$toolVars['courseCode'].'&id_session=0&gidReq=0&gradebook=0'
$launchUrl = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.$cidReq.'&origin=embeddable&exerciseId='.$toolVars['toolId'].'&lti_launch_id='.$launch->getLaunchId();
header('Location: '.$launchUrl);
exit;

@ -1,7 +1,7 @@
<?php
namespace Firebase\JWT;
class BeforeValidException extends \UnexpectedValueException
{
}

@ -1,7 +1,7 @@
<?php
namespace Firebase\JWT;
class ExpiredException extends \UnexpectedValueException
{
}

@ -1,27 +1,29 @@
<?php
namespace Firebase\JWT;
use \DomainException;
use \InvalidArgumentException;
use \UnexpectedValueException;
use \DateTime;
use DateTime;
use DomainException;
use InvalidArgumentException;
use UnexpectedValueException;
/**
* JSON Web Token implementation, based on this spec:
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06.
*
* PHP version 5
*
* @category Authentication
* @package Authentication_JWT
*
* @author Neuman Vong <neuman@twilio.com>
* @author Anant Narayanan <anant@php.net>
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
* @link https://github.com/firebase/php-jwt
*
* @see https://github.com/firebase/php-jwt
*/
class JWT
{
/**
* When checking nbf, iat or expiration times,
* we want to provide some extra leeway time to
@ -37,34 +39,34 @@ class JWT
*/
public static $timestamp = null;
public static $supported_algs = array(
'HS256' => array('hash_hmac', 'SHA256'),
'HS512' => array('hash_hmac', 'SHA512'),
'HS384' => array('hash_hmac', 'SHA384'),
'RS256' => array('openssl', 'SHA256'),
);
public static $supported_algs = [
'HS256' => ['hash_hmac', 'SHA256'],
'HS512' => ['hash_hmac', 'SHA512'],
'HS384' => ['hash_hmac', 'SHA384'],
'RS256' => ['openssl', 'SHA256'],
];
/**
* Decodes a JWT string into a PHP object.
*
* @param string $jwt The JWT
* @param string|array $key The key, or map of keys.
* If the algorithm used is asymmetric, this is the public key
* @param array $allowed_algs List of supported verification algorithms
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
* @param string $jwt The JWT
* @param string|array $key The key, or map of keys.
* If the algorithm used is asymmetric, this is the public key
* @param array $allowed_algs List of supported verification algorithms
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
*
* @return object The JWT's payload as a PHP object
* @throws UnexpectedValueException Provided JWT was invalid
* @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed
* @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf'
* @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat'
* @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim
*
* @throws UnexpectedValueException Provided JWT was invalid
* @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed
* @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf'
* @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat'
* @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim
* @return object The JWT's payload as a PHP object
*
* @uses jsonDecode
* @uses urlsafeB64Decode
*/
public static function decode($jwt, $key, $allowed_algs = array())
public static function decode($jwt, $key, $allowed_algs = [])
{
$timestamp = is_null(static::$timestamp) ? time() : static::$timestamp;
@ -86,7 +88,7 @@ class JWT
throw new UnexpectedValueException('Invalid claims encoding');
}
$sig = static::urlsafeB64Decode($cryptob64);
if (empty($header->alg)) {
throw new UnexpectedValueException('Empty algorithm');
}
@ -112,18 +114,14 @@ class JWT
// Check if the nbf if it is defined. This is the time that the
// token can actually be used. If it's not yet that time, abort.
if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf)
);
throw new BeforeValidException('Cannot handle token prior to '.date(DateTime::ISO8601, $payload->nbf));
}
// Check that this token has been created before 'now'. This prevents
// using tokens that have been created for later use (and haven't
// correctly used the nbf claim).
if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
);
throw new BeforeValidException('Cannot handle token prior to '.date(DateTime::ISO8601, $payload->iat));
}
// Check if this token has expired.
@ -137,13 +135,13 @@ class JWT
/**
* Converts and signs a PHP object or array into a JWT string.
*
* @param object|array $payload PHP object or array
* @param string $key The secret key.
* If the algorithm used is asymmetric, this is the private key
* @param string $alg The signing algorithm.
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
* @param mixed $keyId
* @param array $head An array with header elements to attach
* @param object|array $payload PHP object or array
* @param string $key The secret key.
* If the algorithm used is asymmetric, this is the private key
* @param string $alg The signing algorithm.
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
* @param mixed $keyId
* @param array $head An array with header elements to attach
*
* @return string A signed JWT
*
@ -152,14 +150,14 @@ class JWT
*/
public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null)
{
$header = array('typ' => 'JWT', 'alg' => $alg);
$header = ['typ' => 'JWT', 'alg' => $alg];
if ($keyId !== null) {
$header['kid'] = $keyId;
}
if ( isset($head) && is_array($head) ) {
if (isset($head) && is_array($head)) {
$header = array_merge($head, $header);
}
$segments = array();
$segments = [];
$segments[] = static::urlsafeB64Encode(static::jsonEncode($header));
$segments[] = static::urlsafeB64Encode(static::jsonEncode($payload));
$signing_input = implode('.', $segments);
@ -173,14 +171,14 @@ class JWT
/**
* Sign a string with a given key and algorithm.
*
* @param string $msg The message to sign
* @param string|resource $key The secret key
* @param string $alg The signing algorithm.
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
*
* @return string An encrypted message
* @param string $msg The message to sign
* @param string|resource $key The secret key
* @param string $alg The signing algorithm.
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
*
* @throws DomainException Unsupported algorithm was specified
*
* @return string An encrypted message
*/
public static function sign($msg, $key, $alg = 'HS256')
{
@ -188,7 +186,7 @@ class JWT
throw new DomainException('Algorithm not supported');
}
list($function, $algorithm) = static::$supported_algs[$alg];
switch($function) {
switch ($function) {
case 'hash_hmac':
return hash_hmac($algorithm, $msg, $key, true);
case 'openssl':
@ -202,60 +200,14 @@ class JWT
}
}
/**
* Verify a signature with the message, key and method. Not all methods
* are symmetric, so we must have a separate verify and sign method.
*
* @param string $msg The original message (header and body)
* @param string $signature The original signature
* @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key
* @param string $alg The algorithm
*
* @return bool
*
* @throws DomainException Invalid Algorithm or OpenSSL failure
*/
private static function verify($msg, $signature, $key, $alg)
{
if (empty(static::$supported_algs[$alg])) {
throw new DomainException('Algorithm not supported');
}
list($function, $algorithm) = static::$supported_algs[$alg];
switch($function) {
case 'openssl':
$success = openssl_verify($msg, $signature, $key, $algorithm);
if (!$success) {
throw new DomainException("OpenSSL unable to verify data: " . openssl_error_string());
} else {
return $signature;
}
case 'hash_hmac':
default:
$hash = hash_hmac($algorithm, $msg, $key, true);
if (function_exists('hash_equals')) {
return hash_equals($signature, $hash);
}
$len = min(static::safeStrlen($signature), static::safeStrlen($hash));
$status = 0;
for ($i = 0; $i < $len; $i++) {
$status |= (ord($signature[$i]) ^ ord($hash[$i]));
}
$status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash));
return ($status === 0);
}
}
/**
* Decode a JSON string into a PHP object.
*
* @param string $input JSON string
*
* @return object Object representation of JSON string
*
* @throws DomainException Provided string was invalid JSON
*
* @return object Object representation of JSON string
*/
public static function jsonDecode($input)
{
@ -280,6 +232,7 @@ class JWT
} elseif ($obj === null && $input !== 'null') {
throw new DomainException('Null result with non-null input');
}
return $obj;
}
@ -288,9 +241,9 @@ class JWT
*
* @param object|array $input A PHP object or array
*
* @return string JSON representation of the PHP object or array
*
* @throws DomainException Provided object could not be encoded to valid JSON
*
* @return string JSON representation of the PHP object or array
*/
public static function jsonEncode($input)
{
@ -300,6 +253,7 @@ class JWT
} elseif ($json === 'null' && $input !== null) {
throw new DomainException('Null result with non-null input');
}
return $json;
}
@ -317,6 +271,7 @@ class JWT
$padlen = 4 - $remainder;
$input .= str_repeat('=', $padlen);
}
return base64_decode(strtr($input, '-_', '+/'));
}
@ -332,6 +287,53 @@ class JWT
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
/**
* Verify a signature with the message, key and method. Not all methods
* are symmetric, so we must have a separate verify and sign method.
*
* @param string $msg The original message (header and body)
* @param string $signature The original signature
* @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key
* @param string $alg The algorithm
*
* @throws DomainException Invalid Algorithm or OpenSSL failure
*
* @return bool
*/
private static function verify($msg, $signature, $key, $alg)
{
if (empty(static::$supported_algs[$alg])) {
throw new DomainException('Algorithm not supported');
}
list($function, $algorithm) = static::$supported_algs[$alg];
switch ($function) {
case 'openssl':
$success = openssl_verify($msg, $signature, $key, $algorithm);
if (!$success) {
throw new DomainException("OpenSSL unable to verify data: ".openssl_error_string());
} else {
return $signature;
}
// no break
case 'hash_hmac':
default:
$hash = hash_hmac($algorithm, $msg, $key, true);
if (function_exists('hash_equals')) {
return hash_equals($signature, $hash);
}
$len = min(static::safeStrlen($signature), static::safeStrlen($hash));
$status = 0;
for ($i = 0; $i < $len; $i++) {
$status |= (ord($signature[$i]) ^ ord($hash[$i]));
}
$status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash));
return $status === 0;
}
}
/**
* Helper method to create a JSON error.
*
@ -341,16 +343,12 @@ class JWT
*/
private static function handleJsonError($errno)
{
$messages = array(
$messages = [
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
);
throw new DomainException(
isset($messages[$errno])
? $messages[$errno]
: 'Unknown JSON error: ' . $errno
);
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
];
throw new DomainException(isset($messages[$errno]) ? $messages[$errno] : 'Unknown JSON error: '.$errno);
}
/**
@ -365,6 +363,7 @@ class JWT
if (function_exists('mb_strlen')) {
return mb_strlen($str, '8bit');
}
return strlen($str);
}
}

@ -1,7 +1,7 @@
<?php
namespace Firebase\JWT;
class SignatureInvalidException extends \UnexpectedValueException
{
}

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,15 +13,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__.'/../../main/inc/global.inc.php';
use ChamiloSession as Session;
/**
* Status of the document
* Status of the document.
*/
const TrackerStatus_Editing = 1;
const TrackerStatus_MustSave = 2;
@ -35,15 +32,15 @@ $plugin = OnlyofficePlugin::create();
if (isset($_GET["hash"]) && !empty($_GET["hash"])) {
$callbackResponseArray = [];
@header( 'Content-Type: application/json; charset==utf-8');
@header( 'X-Robots-Tag: noindex' );
@header( 'X-Content-Type-Options: nosniff' );
@header('Content-Type: application/json; charset==utf-8');
@header('X-Robots-Tag: noindex');
@header('X-Content-Type-Options: nosniff');
list ($hashData, $error) = Crypt::ReadHash($_GET["hash"]);
list($hashData, $error) = Crypt::ReadHash($_GET["hash"]);
if ($hashData === null) {
$callbackResponseArray["status"] = "error";
$callbackResponseArray["error"] = $error;
die(json_encode($callbackResponseArray));
exit(json_encode($callbackResponseArray));
}
$type = $hashData->type;
@ -60,7 +57,7 @@ if (isset($_GET["hash"]) && !empty($_GET["hash"])) {
$userInfo = api_get_user_info($userId);
} else {
$result["error"] = "User not found";
die (json_encode($result));
exit(json_encode($result));
}
if (api_is_anonymous()) {
@ -76,22 +73,22 @@ if (isset($_GET["hash"]) && !empty($_GET["hash"])) {
$userId = api_get_user_id();
}
switch($type) {
switch ($type) {
case "track":
$callbackResponseArray = track();
die (json_encode($callbackResponseArray));
exit(json_encode($callbackResponseArray));
case "download":
$callbackResponseArray = download();
die (json_encode($callbackResponseArray));
exit(json_encode($callbackResponseArray));
default:
$callbackResponseArray["status"] = "error";
$callbackResponseArray["error"] = "404 Method not found";
die(json_encode($callbackResponseArray));
exit(json_encode($callbackResponseArray));
}
}
/**
* Handle request from the document server with the document status information
* Handle request from the document server with the document status information.
*/
function track(): array
{
@ -107,6 +104,7 @@ function track(): array
if (($body_stream = file_get_contents("php://input")) === false) {
$result["error"] = "Bad Request";
return $result;
}
@ -114,27 +112,29 @@ function track(): array
if ($data === null) {
$result["error"] = "Bad Response";
return $result;
}
if (!empty($plugin->get("jwt_secret"))) {
if (!empty($data["token"])) {
try {
$payload = \Firebase\JWT\JWT::decode($data["token"], $plugin->get("jwt_secret"), array("HS256"));
$payload = \Firebase\JWT\JWT::decode($data["token"], $plugin->get("jwt_secret"), ["HS256"]);
} catch (\UnexpectedValueException $e) {
$result["status"] = "error";
$result["error"] = "403 Access denied";
return $result;
}
} else {
$token = substr($_SERVER[AppConfig::JwtHeader()], strlen("Bearer "));
try {
$decodeToken = \Firebase\JWT\JWT::decode($token, $plugin->get("jwt_secret"), array("HS256"));
$decodeToken = \Firebase\JWT\JWT::decode($token, $plugin->get("jwt_secret"), ["HS256"]);
$payload = $decodeToken->payload;
} catch (\UnexpectedValueException $e) {
$result["status"] = "error";
$result["error"] = "403 Access denied";
return $result;
}
}
@ -149,7 +149,6 @@ function track(): array
switch ($status) {
case TrackerStatus_MustSave:
case TrackerStatus_Corrupted:
$downloadUri = $data["url"];
if (!empty($docId) && !empty($courseCode)) {
@ -157,16 +156,18 @@ function track(): array
if ($docInfo === false) {
$result["error"] = "File not found";
return $result;
}
$filePath = $docInfo["absolute_path"];
} else {
$result["error"] = "Bad Request";
return $result;
}
list ($isAllowToEdit, $isMyDir, $isGroupAccess, $isReadonly) = getPermissions($docInfo, $userId, $courseCode, $groupId, $sessionId);
list($isAllowToEdit, $isMyDir, $isGroupAccess, $isReadonly) = getPermissions($docInfo, $userId, $courseCode, $groupId, $sessionId);
if ($isReadonly) {
break;
@ -201,19 +202,20 @@ function track(): array
}
}
// no break
case TrackerStatus_Editing:
case TrackerStatus_Closed:
$track_result = 0;
break;
}
$result["error"] = $track_result;
return $result;
}
/**
* Downloading file by the document service
* Downloading file by the document service.
*/
function download()
{
@ -228,11 +230,11 @@ function download()
if (!empty($plugin->get("jwt_secret"))) {
$token = substr($_SERVER[AppConfig::JwtHeader()], strlen("Bearer "));
try {
$payload = \Firebase\JWT\JWT::decode($token, $plugin->get("jwt_secret"), array("HS256"));
$payload = \Firebase\JWT\JWT::decode($token, $plugin->get("jwt_secret"), ["HS256"]);
} catch (\UnexpectedValueException $e) {
$result["status"] = "error";
$result["error"] = "403 Access denied";
return $result;
}
}
@ -242,23 +244,25 @@ function download()
if ($docInfo === false) {
$result["error"] = "File not found";
return $result;
}
$filePath = $docInfo["absolute_path"];
} else {
$result["error"] = "File not found";
return $result;
}
@header("Content-Type: application/octet-stream");
@header("Content-Disposition: attachment; filename=" . $docInfo["title"]);
@header("Content-Disposition: attachment; filename=".$docInfo["title"]);
readfile($filePath);
}
/**
* Method checks access rights to document and returns permissions
* Method checks access rights to document and returns permissions.
*/
function getPermissions(array $docInfo, int $userId, string $courseCode, int $groupId = null, int $sessionId = null): array
{

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,9 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__.'/../../main/inc/global.inc.php';
use ChamiloSession as Session;
@ -26,7 +23,7 @@ $plugin = OnlyofficePlugin::create();
$mapFileFormat = [
"text" => $plugin->get_lang("document"),
"spreadsheet" => $plugin->get_lang("spreadsheet"),
"presentation" => $plugin->get_lang("presentation")
"presentation" => $plugin->get_lang("presentation"),
];
$userId = $_GET["userId"];
@ -58,7 +55,7 @@ if (!($isAllowToEdit || $isMyDir || $groupRights)) {
$form = new FormValidator(
"doc_create",
"post",
api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/create.php"
api_get_path(WEB_PLUGIN_PATH)."onlyoffice/create.php"
);
$form->addText("fileName", $plugin->get_lang("title"), true);
@ -84,13 +81,13 @@ if ($form->validate()) {
$fileType = $values["fileFormat"];
$fileExt = FileUtility::getDocExt($fileType);
$fileTitle = $values["fileName"] . "." . $fileExt;
$fileTitle = $values["fileName"].".".$fileExt;
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo["code"];
$fileNamePrefix = DocumentManager::getDocumentSuffix($courseInfo, $sessionId, $groupId);
$fileName = $values["fileName"] . $fileNamePrefix . "." . $fileExt;
$fileName = $values["fileName"].$fileNamePrefix.".".$fileExt;
$groupInfo = GroupManager::get_group_properties($groupId);
@ -106,16 +103,16 @@ if ($form->validate()) {
$sessionId
);
$folderPath = $document_data["absolute_path"];
$fileRelatedPath = $fileRelatedPath . substr($document_data["absolute_path_from_document"], 10) . "/" . $fileName;
$fileRelatedPath = $fileRelatedPath.substr($document_data["absolute_path_from_document"], 10)."/".$fileName;
} else {
$folderPath = api_get_path(SYS_COURSE_PATH) . api_get_course_path($courseCode) . "/document";
$folderPath = api_get_path(SYS_COURSE_PATH).api_get_course_path($courseCode)."/document";
if (!empty($groupId)) {
$folderPath = $folderPath . "/" . $groupInfo["directory"];
$fileRelatedPath = $groupInfo["directory"] . "/";
$folderPath = $folderPath."/".$groupInfo["directory"];
$fileRelatedPath = $groupInfo["directory"]."/";
}
$fileRelatedPath = $fileRelatedPath . $fileName;
$fileRelatedPath = $fileRelatedPath.$fileName;
}
$filePath = $folderPath . "/" . $fileName;
$filePath = $folderPath."/".$fileName;
if (file_exists($filePath)) {
Display::addFlash(Display::return_message($plugin->get_lang("fileIsExist"), "error"));
@ -156,10 +153,9 @@ if ($form->validate()) {
$sessionId
);
header("Location: " . $goBackUrl);
header("Location: ".$goBackUrl);
exit();
}
} else {
Display::addFlash(
Display::return_message(
@ -172,7 +168,7 @@ if ($form->validate()) {
display:
$goBackUrl = $goBackUrl ?: Security::remove_XSS($_SERVER["HTTP_REFERER"]);
$actionsLeft = '<a href="'. $goBackUrl . '">' . Display::return_icon("back.png", get_lang("Back") . " " . get_lang("To") . " " . get_lang("DocumentsOverview"), "", ICON_SIZE_MEDIUM) . "</a>";
$actionsLeft = '<a href="'.$goBackUrl.'">'.Display::return_icon("back.png", get_lang("Back")." ".get_lang("To")." ".get_lang("DocumentsOverview"), "", ICON_SIZE_MEDIUM)."</a>";
Display::display_header($plugin->get_lang("createNewDocument"));
echo Display::toolbarAction("actions-documents", [$actionsLeft]);

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,9 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__.'/../../main/inc/global.inc.php';
const USER_AGENT_MOBILE = "/android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i";
@ -25,19 +22,21 @@ $plugin = OnlyofficePlugin::create();
$isEnable = $plugin->get("enable_onlyoffice_plugin") === 'true';
if (!$isEnable) {
die ("Document server isn't enabled");
exit("Document server isn't enabled");
return;
}
$documentServerUrl = $plugin->get("document_server_url");
if (empty($documentServerUrl)) {
die ("Document server isn't configured");
exit("Document server isn't configured");
return;
}
$config = [];
$docApiUrl = $documentServerUrl . "/web-apps/apps/api/documents/api.js";
$docApiUrl = $documentServerUrl."/web-apps/apps/api/documents/api.js";
$docId = $_GET["docId"];
$groupId = isset($_GET["groupId"]) && !empty($_GET["groupId"]) ? $_GET["groupId"] : null;
@ -68,26 +67,26 @@ $config = [
"fileType" => $extension,
"key" => $key,
"title" => $docInfo["title"],
"url" => $fileUrl
"url" => $fileUrl,
],
"editorConfig" => [
"lang" => $langInfo["isocode"],
"region" => $langInfo["isocode"],
"user" => [
"id" => strval($userId),
"name" => $userInfo["username"]
"name" => $userInfo["username"],
],
"customization" => [
"goback" => [
"blank" => false,
"requestClose" => false,
"text" => get_lang("Back"),
"url" => Security::remove_XSS($_SERVER["HTTP_REFERER"])
"url" => Security::remove_XSS($_SERVER["HTTP_REFERER"]),
],
"compactHeader" => true,
"toolbarNoTabs" => true
]
]
"toolbarNoTabs" => true,
],
],
];
$userAgent = $_SERVER['HTTP_USER_AGENT'];
@ -167,7 +166,7 @@ if (!empty($plugin->get("jwt_secret"))) {
}
/**
* Return callback url
* Return callback url.
*/
function getCallbackUrl(int $docId, int $userId, int $courseId, int $sessionId, int $groupId = null): string
{
@ -178,7 +177,7 @@ function getCallbackUrl(int $docId, int $userId, int $courseId, int $sessionId,
"courseId" => $courseId,
"userId" => $userId,
"docId" => $docId,
"sessionId" => $sessionId
"sessionId" => $sessionId,
];
if (!empty($groupId)) {
@ -187,7 +186,7 @@ function getCallbackUrl(int $docId, int $userId, int $courseId, int $sessionId,
$hashUrl = Crypt::GetHash($data);
return $url . api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/callback.php?hash=" . $hashUrl;
return $url.api_get_path(WEB_PLUGIN_PATH)."onlyoffice/callback.php?hash=".$hashUrl;
}
?>
@ -205,7 +204,7 @@ function getCallbackUrl(int $docId, int $userId, int $courseId, int $sessionId,
display: none;
}
</style>
<script type="text/javascript" src=<?php echo $docApiUrl?>></script>
<script type="text/javascript" src=<?php echo $docApiUrl; ?>></script>
<script type="text/javascript">
var onAppReady = function () {
innerAlert("Document editor ready");
@ -219,8 +218,8 @@ function getCallbackUrl(int $docId, int $userId, int $courseId, int $sessionId,
'</div>' +
'</div>');
var config = <?php echo json_encode($config)?>;
var isMobileAgent = <?php echo json_encode($isMobileAgent)?>;
var config = <?php echo json_encode($config); ?>;
var isMobileAgent = <?php echo json_encode($isMobileAgent); ?>;
config.events = {
"onAppReady": onAppReady

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,12 +13,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__.'/../../main/inc/global.inc.php';
/**
* @package chamilo.plugin.onlyoffice
*/
OnlyofficePlugin::create()->install();
OnlyofficePlugin::create()->install();

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "ONLYOFFICE конекторът ви позволява да преглеждате, редактирате и да си сътрудничите с текстови документи, таблици и презентациив рамките на Chamilo с помощта на ONLYOFFICE Docs.";
@ -18,4 +17,4 @@ $strings["presentation"] = "Презентация";
$strings["create"] = "Създай";
$strings["fileIsExist"] = "Файлът вече съществува";
$strings["impossibleCreateFile"] = "Не може да се създаде файл";
$strings["createNewDocument"] = "Създай нов документ";
$strings["createNewDocument"] = "Създай нов документ";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "ONLYOFFICE connector maakt het mogelijk om tekstdocumenten, spreadsheets en presentaties te bekijken, te bewerken en samen te werken binnen Chamilo met behulp van ONLYOFFICE Docs.";
@ -18,4 +17,4 @@ $strings["presentation"] = "Presentatie";
$strings["create"] = "Maak";
$strings["fileIsExist"] = "Bestand bestaat al";
$strings["impossibleCreateFile"] = "Onmogelijk om bestand te maken";
$strings["createNewDocument"] = "Nieuw document maken";
$strings["createNewDocument"] = "Nieuw document maken";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "ONLYOFFICE connector allows you to view, edit, and collaborate on text documents, spreadsheets, and presentations within Chamilo using ONLYOFFICE Docs.";
@ -18,4 +17,4 @@ $strings["presentation"] = "Presentation";
$strings["create"] = "Create";
$strings["fileIsExist"] = "File already exists";
$strings["impossibleCreateFile"] = "Impossible to create file";
$strings["createNewDocument"] = "Create new document";
$strings["createNewDocument"] = "Create new document";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "Connecteur ONLYOFFICE vous permet d’afficher, éditer et coéditer les documents texte, les feuilles de calcul et les présentations au sein de Chamilo en utilisant ONLYOFFICE Docs.";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "Mit dem ONLYOFFICE-Konnektor können Sie in Chamilo Textdokumente, Tabellenkalkulationen und Präsentationen mit ONLYOFFICE Docs öffnen und bearbeiten";
@ -18,4 +17,4 @@ $strings["presentation"] = "Präsentation";
$strings["create"] = "Erstellen";
$strings["fileIsExist"] = "Die Datei ist bereits vorhanden";
$strings["impossibleCreateFile"] = "Datei kann nicht erstellt werden";
$strings["createNewDocument"] = "Neues Dokument erstellen";
$strings["createNewDocument"] = "Neues Dokument erstellen";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "Ο συνδετήρας ONLYOFFICE σάς επιτρέπει να προβάλετε, να επεξεργαστείτε και να συνεργαστείτε σε έγγραφα κειμένου, υπολογιστικά φύλλα και παρουσιάσεις στο Chamilo χρησιμοποιώντας έγγραφα ONLYOFFICE.";
@ -17,4 +16,4 @@ $strings["presentation"] = "Παρουσίαση";
$strings["create"] = "Δημιουργία";
$strings["fileIsExist"] = "Το αρχείο υπάρχει ήδη";
$strings["impossibleCreateFile"] = "Η δημιουργία αρχείου είναι αδύνατη";
$strings["createNewDocument"] = "Δημιουργία νέου εγγράφου";
$strings["createNewDocument"] = "Δημιουργία νέου εγγράφου";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "Il connettore ONLYOFFICE ti consente di visualizzare, modificare e collaborare su documenti di testo, fogli di calcolo e presentazioni all'interno di Chamilo con ONLYOFFICE Docs.";
@ -18,4 +17,4 @@ $strings["presentation"] = "Presentazione";
$strings["create"] = "Crea";
$strings["fileIsExist"] = "Il file esiste già";
$strings["impossibleCreateFile"] = "Impossibile creare file";
$strings["createNewDocument"] = "Crea nuovo documento";
$strings["createNewDocument"] = "Crea nuovo documento";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "ONLYOFFICE connector pozwala na przeglądanie, edytowanie oraz współpracę nad dokumentami tekstowymi, arkuszami kalkulacyjnymi i prezentacjami w Chamilo za pośrednictwem ONLYOFFICE Docs.";
@ -18,4 +17,4 @@ $strings["presentation"] = "Prezentacja";
$strings["create"] = "Utwórz";
$strings["fileIsExist"] = "Plik już istnieje";
$strings["impossibleCreateFile"] = "Nie można utworzyć pliku";
$strings["createNewDocument"] = "Utwórz nowy dokument";
$strings["createNewDocument"] = "Utwórz nowy dokument";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "ONLYOFFICE connector permite que você visualize, edite e colabore em documentos de texto, planilhas e apresentações dentro do Chamilo usando o ONLYOFFICE Docs.";
@ -18,4 +17,4 @@ $strings["presentation"] = "Apresentação";
$strings["create"] = "Criar";
$strings["fileIsExist"] = "Arquivo já existe";
$strings["impossibleCreateFile"] = "Impossível criar arquivo";
$strings["createNewDocument"] = "Criar novo documento";
$strings["createNewDocument"] = "Criar novo documento";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "Коннектор ONLYOFFICE позволяет просматривать и редактировать текстовые документы, электронные таблицы и презентации и работать над ними совместно в Chamilo, используя ONLYOFFICE Docs.";
@ -18,4 +17,4 @@ $strings["presentation"] = "Презентация ";
$strings["create"] = "Создать ";
$strings["fileIsExist"] = "Файл уже существует";
$strings["impossibleCreateFile"] = "Невозможно создать файл";
$strings["createNewDocument"] = "Создать новый документ";
$strings["createNewDocument"] = "Создать новый документ";

@ -1,7 +1,6 @@
<?php
/**
* @author ASENSIO SYSTEM SIA
*
*/
$strings["plugin_title"] = "ONLYOFFICE";
$strings['plugin_comment'] = "El conector de ONLYOFFICE le permite ver, editar y colaborar en documentos de texto, hojas de cálculo y presentaciones dentro de Chamilo utilizando ONLYOFFICE Docs.";

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,22 +13,20 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__."/../../../main/inc/global.inc.php";
require_once __DIR__ . "/../../../main/inc/global.inc.php";
class AppConfig {
class AppConfig
{
/**
* The config key for the jwt header
* The config key for the jwt header.
*
* @var string
*/
private const jwtHeader = "onlyoffice_jwt_header";
/**
* Get the jwt header setting
* Get the jwt header setting.
*
* @return string
*/

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,15 +13,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__."/../../../main/inc/global.inc.php";
require_once __DIR__ . "/../../../main/inc/global.inc.php";
class Crypt {
class Crypt
{
/**
* Generate token for the object
* Generate token for the object.
*
* @param array $object - object to signature
*
@ -34,7 +31,7 @@ class Crypt {
}
/**
* Create an object from the token
* Create an object from the token.
*
* @param string $token - token
*
@ -48,10 +45,11 @@ class Crypt {
return [$result, "token is empty"];
}
try {
$result = \Firebase\JWT\JWT::decode($token, api_get_security_key(), array("HS256"));
$result = \Firebase\JWT\JWT::decode($token, api_get_security_key(), ["HS256"]);
} catch (\UnexpectedValueException $e) {
$error = $e->getMessage();
}
return [$result, $error];
}
}

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,20 +13,18 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__."/../../../main/inc/global.inc.php";
require_once __DIR__ . "/../../../main/inc/global.inc.php";
class FileUtility {
class FileUtility
{
/**
* Application name
* Application name.
*/
public const app_name = "onlyoffice";
/**
* Extensions of files that can edit
* Extensions of files that can edit.
*
* @var array
*/
@ -35,51 +32,51 @@ class FileUtility {
"docx",
"xlsx",
"pptx",
"ppsx"
"ppsx",
];
/**
* Extensions of files that can view
* Extensions of files that can view.
*
* @var array
*/
public static $can_view_types = [
"docx", "xlsx", "pptx", "ppsx",
"txt", "csv", "odt", "ods","odp",
"doc", "xls", "ppt", "pps","epub",
"rtf", "mht", "html", "htm","xps","pdf","djvu"
"txt", "csv", "odt", "ods", "odp",
"doc", "xls", "ppt", "pps", "epub",
"rtf", "mht", "html", "htm", "xps", "pdf", "djvu",
];
/**
* Extensions of text files
* Extensions of text files.
*
* @var array
*/
public static $text_doc = [
"docx", "txt", "odt", "doc", "rtf", "html",
"htm", "xps", "pdf", "djvu"
"htm", "xps", "pdf", "djvu",
];
/**
* Extensions of presentation files
* Extensions of presentation files.
*
* @var array
*/
public static $presentation_doc = [
"pptx", "ppsx", "odp", "ppt", "pps"
public static $presentation_doc = [
"pptx", "ppsx", "odp", "ppt", "pps",
];
/**
* Extensions of spreadsheet files
* Extensions of spreadsheet files.
*
* @var array
*/
public static $spreadsheet_doc = [
"xlsx", "csv", "ods", "xls"
"xlsx", "csv", "ods", "xls",
];
/**
* Return file type by extension
* Return file type by extension.
*/
public static function getDocType(string $extension): string
{
@ -97,7 +94,7 @@ class FileUtility {
}
/**
* Return file extension by file type
* Return file extension by file type.
*/
public static function getDocExt(string $type): string
{
@ -115,17 +112,16 @@ class FileUtility {
}
/**
* Return file url for download
* Return file url for download.
*/
public static function getFileUrl(int $courseId, int $userId, int $docId, int $sessionId = null, int $groupId = null): string
{
$data = [
"type" => "download",
"courseId" => $courseId,
"userId" => $userId,
"docId" => $docId,
"sessionId" => $sessionId
"sessionId" => $sessionId,
];
if (!empty($groupId)) {
@ -134,29 +130,33 @@ class FileUtility {
$hashUrl = Crypt::GetHash($data);
return api_get_path(WEB_PLUGIN_PATH) . self::app_name . "/" . "callback.php?hash=" . $hashUrl;
return api_get_path(WEB_PLUGIN_PATH).self::app_name."/"."callback.php?hash=".$hashUrl;
}
/**
* Return file key
* Return file key.
*/
public static function getKey(string $courseCode, int $docId): string
{
$docInfo = DocumentManager::get_document_data_by_id($docId, $courseCode);
$mtime = filemtime($docInfo["absolute_path"]);
$key = $mtime . $courseCode . $docId;
$key = $mtime.$courseCode.$docId;
return self::GenerateRevisionId($key);
}
/**
* Translation key to a supported form
* Translation key to a supported form.
*/
public static function GenerateRevisionId(string $expectedKey): string
{
if (strlen($expectedKey) > 20) $expectedKey = crc32( $expectedKey);
if (strlen($expectedKey) > 20) {
$expectedKey = crc32($expectedKey);
}
$key = preg_replace("[^0-9-.a-zA-Z_=]", "_", $expectedKey);
$key = substr($key, 0, min(array(strlen($key), 20)));
$key = substr($key, 0, min([strlen($key), 20]));
return $key;
}
}

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,15 +13,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__."/../../../main/inc/global.inc.php";
require_once __DIR__ . "/../../../main/inc/global.inc.php";
class LangManager {
class LangManager
{
/**
* Return lang info for current user
* Return lang info for current user.
*/
public static function getLangUser(): array
{
@ -34,11 +31,12 @@ class LangManager {
if (empty($userLang)) {
$langId = SubLanguageManager::get_platform_language_id();
$langInfo = api_get_language_info($langId);
return $langInfo;
}
$allLang = SubLanguageManager::getAllLanguages();
foreach($allLang as $langItem) {
foreach ($allLang as $langItem) {
if ($langItem["english_name"] === $userLang) {
$langInfo = $langItem;
break;

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,9 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class OnlyofficeActionObserver extends HookObserver implements HookDocumentActionObserverInterface
{
/**
@ -31,7 +28,7 @@ class OnlyofficeActionObserver extends HookObserver implements HookDocumentActio
}
/**
* Create a Onlyoffice edit tools when the Chamilo loads document tools
* Create a Onlyoffice edit tools when the Chamilo loads document tools.
*
* @param HookDocumentActionEventInterface $event - the hook event
*/
@ -41,6 +38,7 @@ class OnlyofficeActionObserver extends HookObserver implements HookDocumentActio
if ($data["type"] === HOOK_EVENT_TYPE_PRE) {
$data["actions"][] = OnlyofficeTools::getButtonCreateNew();
return $data;
}
}

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,13 +13,11 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class OnlyofficeItemActionObserver extends HookObserver implements HookDocumentItemActionObserverInterface
{
/**
* Constructor
* Constructor.
*/
public function __construct()
{
@ -31,7 +28,7 @@ class OnlyofficeItemActionObserver extends HookObserver implements HookDocumentI
}
/**
* Create a Onlyoffice edit tools when the Chamilo loads document items
* Create a Onlyoffice edit tools when the Chamilo loads document items.
*
* @param HookDocumentItemActionEventInterface $event - the hook event
*/
@ -41,6 +38,7 @@ class OnlyofficeItemActionObserver extends HookObserver implements HookDocumentI
if ($data["type"] === HOOK_EVENT_TYPE_PRE) {
$data["actions"][] = OnlyofficeTools::getButtonEdit($data);
return $data;
}
}

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,13 +13,11 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class OnlyofficeItemViewObserver extends HookObserver implements HookDocumentItemViewObserverInterface
{
/**
* Constructor
* Constructor.
*/
public function __construct()
{
@ -31,7 +28,7 @@ class OnlyofficeItemViewObserver extends HookObserver implements HookDocumentIte
}
/**
* Create a Onlyoffice view tools when the Chamilo loads document items
* Create a Onlyoffice view tools when the Chamilo loads document items.
*
* @param HookDocumentItemViewEventInterface $event - the hook event
*/

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
@ -35,13 +33,13 @@ class OnlyofficePlugin extends Plugin implements HookPluginInterface
[
"enable_onlyoffice_plugin" => "boolean",
"document_server_url" => "text",
"jwt_secret" => "text"
"jwt_secret" => "text",
]
);
}
/**
* Create OnlyofficePlugin object
* Create OnlyofficePlugin object.
*/
public static function create(): OnlyofficePlugin
{

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,17 +13,14 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class OnlyofficeTools {
class OnlyofficeTools
{
/**
* Return button-link to onlyoffice editor for file
* Return button-link to onlyoffice editor for file.
*/
public static function getButtonEdit(array $document_data): string
{
$plugin = OnlyofficePlugin::create();
$isEnable = $plugin->get("enable_onlyoffice_plugin") === "true";
@ -32,7 +28,7 @@ class OnlyofficeTools {
return '';
}
$urlToEdit = api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/editor.php";
$urlToEdit = api_get_path(WEB_PLUGIN_PATH)."onlyoffice/editor.php";
$extension = strtolower(pathinfo($document_data["title"], PATHINFO_EXTENSION));
@ -41,13 +37,13 @@ class OnlyofficeTools {
$groupId = api_get_group_id();
if (!empty($groupId)) {
$urlToEdit = $urlToEdit . "?groupId=" . $groupId . "&";
$urlToEdit = $urlToEdit."?groupId=".$groupId."&";
} else {
$urlToEdit = $urlToEdit . "?";
$urlToEdit = $urlToEdit."?";
}
$documentId = $document_data["id"];
$urlToEdit = $urlToEdit . "docId=" . $documentId;
$urlToEdit = $urlToEdit."docId=".$documentId;
if ($canEdit || $canView) {
return Display::url(
@ -63,11 +59,10 @@ class OnlyofficeTools {
}
/**
* Return button-link to onlyoffice editor for view file
* Return button-link to onlyoffice editor for view file.
*/
public static function getButtonView (array $document_data): string
public static function getButtonView(array $document_data): string
{
$plugin = OnlyofficePlugin::create();
$isEnable = $plugin->get("enable_onlyoffice_plugin") === "true";
@ -75,7 +70,7 @@ class OnlyofficeTools {
return '';
}
$urlToEdit = api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/editor.php";
$urlToEdit = api_get_path(WEB_PLUGIN_PATH)."onlyoffice/editor.php";
$sessionId = api_get_session_id();
$courseInfo = api_get_course_info();
@ -94,9 +89,9 @@ class OnlyofficeTools {
$docInfoGroup = api_get_item_property_info(api_get_course_int_id(), 'document', $documentId, $sessionId);
$isGroupAccess = GroupManager::allowUploadEditDocument($userId, $courseInfo["code"], $groupProperties, $docInfoGroup);
$urlToEdit = $urlToEdit . "?groupId=" . $groupId . "&";
$urlToEdit = $urlToEdit."?groupId=".$groupId."&";
} else {
$urlToEdit = $urlToEdit . "?";
$urlToEdit = $urlToEdit."?";
}
$isAllowToEdit = api_is_allowed_to_edit(true, true);
@ -104,7 +99,7 @@ class OnlyofficeTools {
$accessRights = $isAllowToEdit || $isMyDir || $isGroupAccess;
$urlToEdit = $urlToEdit . "docId=" . $documentId;
$urlToEdit = $urlToEdit."docId=".$documentId;
if ($canView && !$accessRights) {
return Display::url(Display::return_icon('../../plugin/onlyoffice/resources/onlyoffice_view.png', $plugin->get_lang('openByOnlyoffice')), $urlToEdit, ["style" => "float:right; margin-right:8px"]);
@ -114,11 +109,10 @@ class OnlyofficeTools {
}
/**
* Return button-link to onlyoffice create new
* Return button-link to onlyoffice create new.
*/
public static function getButtonCreateNew (): string
public static function getButtonCreateNew(): string
{
$plugin = OnlyofficePlugin::create();
$isEnable = $plugin->get("enable_onlyoffice_plugin") === "true";
@ -131,12 +125,12 @@ class OnlyofficeTools {
$groupId = api_get_group_id();
$userId = api_get_user_id();
$urlToCreate = api_get_path(WEB_PLUGIN_PATH) . "onlyoffice/create.php"
."?folderId=" . (empty($_GET["id"])?'0':(int)$_GET["id"])
. "&courseId=" . $courseId
. "&groupId=" . $groupId
. "&sessionId=" . $sessionId
. "&userId=" . $userId;
$urlToCreate = api_get_path(WEB_PLUGIN_PATH)."onlyoffice/create.php"
."?folderId=".(empty($_GET["id"]) ? '0' : (int) $_GET["id"])
."&courseId=".$courseId
."&groupId=".$groupId
."&sessionId=".$sessionId
."&userId=".$userId;
return Display::url(
Display::return_icon(

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,17 +13,15 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__."/../../../main/inc/global.inc.php";
require_once __DIR__ . "/../../../main/inc/global.inc.php";
class TemplateManager {
class TemplateManager
{
/**
* Mapping local path to templates
* Mapping local path to templates.
*
* @var Array
* @var array
*/
private static $localPath = [
"bg" => "bg-BG",
@ -47,11 +44,11 @@ class TemplateManager {
"sv" => "sv-SE",
"uk" => "uk-UA",
"vi" => "vi-VN",
"zh" => "zh-CN"
"zh" => "zh-CN",
];
/**
* Return path to template new file
* Return path to template new file.
*/
public static function getEmptyTemplate($fileExtension): string
{
@ -60,8 +57,8 @@ class TemplateManager {
if (!array_key_exists($lang, self::$localPath)) {
$lang = "en";
}
$templateFolder = api_get_path(SYS_PLUGIN_PATH) . "onlyoffice/assets/" . self::$localPath[$lang];
$templateFolder = api_get_path(SYS_PLUGIN_PATH)."onlyoffice/assets/".self::$localPath[$lang];
return $templateFolder . "/" . ltrim($fileExtension, ".") . ".zip";
return $templateFolder."/".ltrim($fileExtension, ".").".zip";
}
}

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,13 +13,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__.'/../../main/inc/global.inc.php';
/**
* @author Asensio System SIA
*/
$plugin_info = OnlyofficePlugin::create()->get_info();
$plugin_info = OnlyofficePlugin::create()->get_info();

@ -1,7 +1,6 @@
<?php
/**
*
* (c) Copyright Ascensio System SIA 2021
* (c) Copyright Ascensio System SIA 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,12 +13,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require_once __DIR__.'/../../main/inc/global.inc.php';
/**
* uninstall the plugin
* uninstall the plugin.
*/
OnlyofficePlugin::create()->uninstall();
OnlyofficePlugin::create()->uninstall();

Loading…
Cancel
Save