Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #59 from NeoRazorX/beta
Browse files Browse the repository at this point in the history
Refactorizada la API y corregido el actualizador
  • Loading branch information
NeoRazorX committed Jan 3, 2019
2 parents d515fd3 + b189fcd commit 323fbd2
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 30 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2017.911
2017.912
31 changes: 5 additions & 26 deletions api.php
Expand Up @@ -27,37 +27,16 @@

require_once 'base/fs_extended_model.php';
require_once 'base/fs_log_manager.php';
require_once 'base/fs_api.php';
require_all_models();

$db->connect();

if (!$db->connected()) {
echo 'ERROR al conectar a la base de datos';
} else if (!fs_filter_input_req('v')) {
echo 'Version de la API de FacturaScripts ausente. Actualiza el cliente.';
} else if (fs_filter_input_req('v') != '2') {
echo 'Version de la API de FacturaScripts incorrecta. Actualiza el cliente.';
} else if (fs_filter_input_req('f')) {
$ejecutada = FALSE;
$fsext = new fs_extension();
foreach ($fsext->all_4_type('api') as $ext) {
if ($ext->text == fs_filter_input_req('f')) {
try {
call_user_func(fs_filter_input_req('f'));
} catch (Exception $exception) {
echo 'ERROR: ' . $exception->getMessage();
}

$ejecutada = TRUE;
break;
}
}

if (!$ejecutada) {
echo 'Ninguna funcion API ejecutada.';
}
if ($db->connected()) {
$api = new fs_api();
echo $api->run();
} else {
echo 'Ninguna funcion ejecutada.';
echo 'ERROR al conectar a la base de datos';
}

/// guardamos los errores en el log
Expand Down
96 changes: 96 additions & 0 deletions base/fs_api.php
@@ -0,0 +1,96 @@
<?php
/**
* This file is part of FacturaScripts
* Copyright (C) 2013-2018 Carlos Garcia Gomez <neorazorx@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Description of fs_api
*
* @author Carlos García Gómez <neorazorx@gmail.com>
*/
class fs_api
{

/**
*
* @return string
*/
public function run()
{
$function_name = fs_filter_input_req('f');
$version = fs_filter_input_req('v');

if (!$version) {
return 'Version de la API de FacturaScripts ausente. Actualiza el cliente.';
} else if ($version != '2') {
return 'Version de la API de FacturaScripts incorrecta. Actualiza el cliente.';
} else if (!$function_name) {
return 'Ninguna funcion ejecutada.';
}

return $this->execute($function_name);
}

/**
*
* @return string
*/
private function get_last_activity()
{
$last_activity = 0;

$user_model = new fs_user();
foreach ($user_model->all() as $user) {
$time = empty($user->last_login) ? 0 : strtotime($user->last_login . ' ' . $user->last_login_time);
if ($time > $last_activity) {
$last_activity = $time;
}
}

return date('Y-m-d H:i:s', $last_activity);
}

/**
*
* @param string $function_name
*
* @return string
*/
private function execute($function_name)
{
$fsext = new fs_extension();
foreach ($fsext->all_4_type('api') as $ext) {
if ($ext->text != $function_name) {
continue;
}

try {
call_user_func($function_name);
} catch (Exception $exception) {
echo 'ERROR: ' . $exception->getMessage();
}

return '';
}

if ($function_name == 'lastactivity') {
return $this->get_last_activity();
}

return 'Ninguna funcion API ejecutada.';
}
}
6 changes: 3 additions & 3 deletions base/fs_updater.php
Expand Up @@ -272,12 +272,12 @@ public function check_for_plugin_updates()
} else if ($plugin['idplugin']) {
/// plugin de pago/oculto
foreach ($this->plugin_manager->downloads() as $ditem) {
if ($ditem->id != $plugin['idplugin']) {
if ($ditem['id'] != $plugin['idplugin']) {
continue;
}

if (intval($ditem->version) > $plugin['version']) {
$plugin['new_version'] = intval($ditem->version);
if (intval($ditem['version']) > $plugin['version']) {
$plugin['new_version'] = intval($ditem['version']);
$plugin['depago'] = TRUE;
$plugin['private_key'] = '';

Expand Down

0 comments on commit 323fbd2

Please sign in to comment.