Ejemplo n.º 1
0
/**
 * Delete a set of selected widgets
 */
function delete_block()
{
    global $xoopsSecurity;
    if (!$xoopsSecurity->check()) {
        response(__('Session token expired!', 'rmcommon'), array(), 1, 0);
    }
    $block_id = rmc_server_var($_POST, 'id', 0);
    if ($block_id <= 0) {
        response(__('No block has been specified!', 'rmcommon'), array(), 1, 1);
    }
    $block = new RMInternalBlock($block_id);
    if ($block->isNew()) {
        response(__('Specified block does not exists!', 'rmcommon'), array(), 1, 1);
    }
    if (!$block->delete()) {
        response(sprintf(__('The block "%s" could not be deleted!', 'rmcommon'), $block->getVar('name')), array('error' => $block->errors()), 1, 1);
    } else {
        response(sprintf(__('The block "%s" was deleted successfully!', 'rmcommon'), $block->getVar('name')), array(), 0, 1);
    }
}
Ejemplo n.º 2
0
/**
* This function allos to insert a new block in database
*/
function insertBlock()
{
    global $xoopsSecurity;
    $mod = rmc_server_var($_POST, 'module', '');
    $id = rmc_server_var($_POST, 'block', '');
    $token = rmc_server_var($_POST, 'XOOPS_TOKEN_REQUEST', '');
    $canvas = rmc_server_var($_POST, 'canvas', '');
    if (!$xoopsSecurity->check()) {
        response(array('message' => __('Sorry, you are not allowed to view this page', 'rmcommon')), 1, 0);
        die;
    }
    if ($mod == '' || $id == '') {
        $data = array('message' => __('The block specified seems to be invalid. Please try again.', 'rmcommon'));
        response($data, 1, 0);
    }
    $module = RMFunctions::load_module($mod);
    if (!$module) {
        response(array('message' => __('The specified module does not exists!', 'rmcommon')), 1, 0);
    }
    $module->loadInfoAsVar($mod);
    $blocks = $module->getInfo('blocks');
    $ms = $module->name() . '<br />';
    $found = false;
    foreach ($blocks as $bk) {
        $str = isset($bk['show_func']) ? $bk['show_func'] : '';
        $str .= isset($bk['edit_func']) ? $bk['edit_func'] : '';
        $str .= isset($bk['dir']) ? $bk['dir'] : $mod;
        $idb = md5($str);
        if ($idb == $id) {
            $found = true;
            break;
        }
    }
    if (!$found) {
        response(array('message' => __('The specified block does not exists, please verify your selection.', 'rmcommon')), 1, 1);
    }
    $block = new RMInternalBlock();
    if ($canvas <= 0) {
        $db = XoopsDatabaseFactory::getDatabaseConnection();
        // Get a default side
        $sql = "SELECT id_position, name FROM " . $db->prefix("rmc_blocks_positions") . " ORDER BY id_position LIMIT 0, 1";
        $result = $db->query($sql);
        if ($result) {
            list($canvas, $canvas_name) = $db->fetchRow($result);
        }
    }
    $block->setReadGroups(array(0));
    $block->setVar('name', $bk['name']);
    $block->setVar('element', $mod);
    $block->setVar('element_type', $bk['plugin'] == 1 ? 'plugin' : 'module');
    $block->setVar('canvas', $canvas);
    $block->setVar('visible', 0);
    $block->setVar('type', $bk['type']);
    $block->setVar('isactive', 1);
    $block->setVar('dirname', isset($bk['dir']) ? $bk['dir'] : $mod);
    $block->setVar('file', $bk['file']);
    $block->setVar('show_func', $bk['show_func']);
    $block->setVar('edit_func', $bk['edit_func']);
    $block->setVar('description', $bk['description']);
    $block->setVar('widget', $id);
    $block->setVar('options', is_array($bk['options']) ? serialize($bk['options']) : serialize(explode("|", $bk['options'])));
    $block->setVar('template', $bk['template']);
    $block->sections(array(0));
    if (!$block->save()) {
        response(array('message' => sprintf(__('Block could not be created due to: %s. Please try again!', 'rmcommon'), $block->errors())), 1, 1);
    }
    RMEvents::get()->run_event('rmcommon.block.added', $block);
    $pos = RMBlocksFunctions::block_positions();
    $ret = array('id' => $block->id(), 'name' => $block->getVar('name'), 'module' => $block->getVar('element'), 'description' => $block->getVar('description'), 'canvas' => $pos[$canvas], 'weight' => $block->getVar('weight'), 'message' => __('Block added successfully! Please configure it.', 'rmcommon'));
    response($ret, 0, 1);
    die;
}