Esempio n. 1
0
/**
 * Action handler function
 *
 * @param	&vivvo_lite_site	$sm
 * @param	string				$action
 * @param	string				$command
 * @return	bool
 */
function schedule_service(&$sm, $action, $command)
{
    if ($action != 'schedule') {
        return false;
    }
    require_once VIVVO_FS_ROOT . 'lib/vivvo/service/Schedules.service.php';
    $service = new SchedulesService($sm);
    $dm = $sm->get_dump_manager();
    $um = $sm->get_url_manager();
    $lang = $sm->get_lang();
    switch ($command) {
        case 'add':
            $schedule_params = $um->get_param_regexp('/^schedule_/');
            if ($service->add_schedule($schedule_params)) {
                $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_SCHEDULE_ADD_SUCCESS'));
                header('X-Vivvo-Action-Status: 1');
                vivvo_hooks_manager::call('schedule_add_postaction');
                return true;
            }
            break;
        case 'edit':
            $schedule_params = $um->get_param_regexp('/^schedule_/');
            if ($service->edit_schedule($schedule_params)) {
                $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_SCHEDULE_EDIT_SUCCESS'));
                header('X-Vivvo-Action-Status: 1');
                vivvo_hooks_manager::call('schedule_edit_postaction');
                return true;
            }
            break;
        case 'delete':
            if ($service->delete_schedule($um->get_param('schedule_id'))) {
                $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_SCHEDULE_DELETE_SUCCESS'));
                header('X-Vivvo-Action-Status: 1');
                vivvo_hooks_manager::call('schedule_delete_postaction');
                return true;
            }
            break;
        case 'save_changes':
            $article_id = $um->get_param('article_id');
            foreach ($um->get_param('schedule') as $id => $mask) {
                if (!$service->edit_schedule(array('id' => $id, 'article_id' => $article_id, 'time_mask' => $mask))) {
                    break 2;
                }
            }
            foreach ($um->get_param('new_schedule') as $mask) {
                if (!$service->add_schedule(array('article_id' => $article_id, 'time_mask' => $mask))) {
                    break 2;
                }
            }
            header('X-Vivvo-Action-Status: 1');
            return true;
        default:
    }
    header('X-Vivvo-Action-Status: 0');
    header('X-Vivvo-Action-Error: ' . json_encode($service->get_error_info()));
    return false;
}
Esempio n. 2
0
/**
 * Action handler function
 *
 * @param	&vivvo_lite_site	$sm
 * @param	string				$action
 * @param	string				$command
 * @return	bool
 */
function feed_service($sm, $action, $command)
{
    if ($action != 'feed') {
        return false;
    }
    require_once dirname(__FILE__) . '/feed.service.php';
    $service = new feed_service($sm);
    $um = $sm->get_url_manager();
    $dm = $sm->get_dump_manager();
    $lang = vivvo_lang::get_instance();
    if ($command == 'edit') {
        $feed_id = $um->get_param('PLUGIN_FEED_id');
        $in_feed = $um->get_param_regexp('/^PLUGIN_FEED_/');
        if ($service->edit_feed($feed_id, $in_feed)) {
            $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_PLUGIN_FEED_EDIT_SUCCESS'));
            header('X-Vivvo-Action-Status: 1');
            vivvo_hooks_manager::call('feed_edit_postaction');
            return true;
        }
    } elseif ($command == 'preferences') {
        if (is_array($um->list) and !empty($um->list)) {
            foreach ($um->list as $key => $value) {
                if (preg_match('/^(VIVVO_PLUGIN_FEED_IMPORTER_)/', $key)) {
                    if (!($response = $service->preferences_feed($key, $um->list[$key]))) {
                        break;
                    }
                }
            }
        }
        if (!empty($response)) {
            $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_PLUGIN_FEED_PREFERENCES_SUCCESS'));
            header('X-Vivvo-Action-Status: 1');
            vivvo_hooks_manager::call('feed_preferences_postaction');
            return true;
        }
    }
    header('X-Vivvo-Action-Status: 0');
    header('X-Vivvo-Action-Error: ' . json_encode($service->get_error_info()));
    return false;
}