예제 #1
0
function activate_position($status)
{
    global $xoopsSecurity, $xoopsDB;
    if (!$xoopsSecurity->check()) {
        RMUris::redirect_with_message(__('Session token is not valid!', 'rmcommon'), 'blocks.php', RMMSG_ERROR);
    }
    $ids = RMHttpRequest::post('ids', 'array', array());
    if (!is_array($ids) || empty($ids)) {
        RMUris::redirect_with_message(__('No position id has been provided', 'rmcommon'), 'blocks.php', RMMSG_WARN);
    }
    $sql = "UPDATE " . $xoopsDB->prefix("mod_rmcommon_blocks_positions") . " SET active = " . ($status == 'active' ? 1 : 0) . "\n            WHERE id_position IN (" . implode(',', $ids) . ")";
    if ($xoopsDB->queryF($sql)) {
        RMUris::redirect_with_message(__('Database updated successully!', 'rmcommon'), 'blocks.php', RMMSG_SUCCESS);
    } else {
        RMUris::redirect_with_message(__('Errors ocurrs while trying to update data:', 'rmcommon') . $xoopsDB->error(), 'blocks.php', RMMSG_ERROR);
    }
}
예제 #2
0
/**
* @desc Eliminina categorías
**/
function deleteCatego()
{
    global $xoopsModule, $xoopsSecurity;
    $ids = RMHttpRequest::post('ids', 'array', array());
    //Verificamos si se ha proporcionado una categoría
    if (empty($ids)) {
        RMUris::redirect_with_message(__('You must select at least one category', 'bxpress'), './categories.php', RMMSG_WARN);
        die;
    }
    if (!$xoopsSecurity->check()) {
        RMUris::redirect_with_message(__('Session token expired!', 'bxpress'), 'categories.php', RMMSG_ERROR);
        die;
    }
    $errors = '';
    foreach ($ids as $k) {
        //Verificamos que la categoría sea válida
        if ($k <= 0) {
            $errors .= sprintf(__('Category ID %s is not valid!', 'bxpress'), '<strong>' . $k . '</strong>') . '<br />';
            continue;
        }
        //Verificamos que categoría exista
        $cat = new bXCategory($k);
        if ($cat->isNew()) {
            $errors .= sprintf(__('Category with id %s does not exists!', 'bxpress'), '<strong>' . $k . '</strong>') . '<br />';
            continue;
        }
        if (!$cat->delete()) {
            $errors .= sprintf(__('Category %s could not be deleted!', 'bxpress'), '<strong>' . $k . '</strong>') . '<br />';
        }
    }
    if ($errors != '') {
        RMUris::redirect_with_message(__('There was errors during this operation', 'bxpress') . '<br />' . $errors, './categories.php', RMMSG_ERROR);
        die;
    } else {
        RMUris::redirect_with_message(__('Categories deleted successfully!', 'bxpress'), './categories.php', RMMSG_SUCCESS);
        die;
    }
}
예제 #3
0
function delete_group_data()
{
    global $xoopsSecurity, $xoopsDB;
    $ajax = new Rmcommon_Ajax();
    $ajax->prepare_ajax_response();
    if (!$xoopsSecurity->validateToken(false, true, 'CUTOKEN')) {
        $ajax->ajax_response(__('Session token expired!', 'rmcommon'), 1, 0, array('action' => 'reload'));
    }
    $ids = RMHttpRequest::post('ids', 'array', array());
    if (empty($ids)) {
        $ajax->ajax_response(__('You must select at least one group. Please, try again.', 'rmcommon'), 1, 1);
    }
    $to_delete = array_search(XOOPS_GROUP_ADMIN, $ids);
    if (FALSE !== $to_delete) {
        unset($ids[$to_delete]);
    }
    $to_delete = array_search(XOOPS_GROUP_USERS, $ids);
    if (FALSE !== $to_delete) {
        unset($ids[$to_delete]);
    }
    $to_delete = array_search(XOOPS_GROUP_ANONYMOUS, $ids);
    if (FALSE !== $to_delete) {
        unset($ids[$to_delete]);
    }
    if (empty($ids)) {
        $ajax->ajax_response(__('No valid groups has been selected. Note that system groups could not be deleted.', 'rmcommon'), 1, 1);
    }
    $errors = '';
    // Eliminar permisos del grupo
    $sql = "DELETE FROM " . $xoopsDB->prefix("group_permission") . " WHERE gperm_groupid IN (" . implode(",", $ids) . ")";
    if (!$xoopsDB->queryF($sql)) {
        $errors .= $xoopsDB->error();
    }
    // Eliminar permisos específicos
    $sql = "DELETE FROM " . $xoopsDB->prefix("mod_rmcommon_permissions") . " WHERE `group` IN (" . implode(",", $ids) . ")";
    if (!$xoopsDB->queryF($sql)) {
        $errors .= '<br>' . $xoopsDB->error();
    }
    // Eliminar relaciones con usuarios
    $sql = "DELETE FROM " . $xoopsDB->prefix("groups_users_link") . " WHERE `groupid` IN (" . implode(",", $ids) . ")";
    if (!$xoopsDB->queryF($sql)) {
        $errors .= '<br>' . $xoopsDB->error();
    }
    // Eliminar datos del grupo
    $sql = "DELETE FROM " . $xoopsDB->prefix("groups") . " WHERE `groupid` IN (" . implode(",", $ids) . ")";
    if (!$xoopsDB->queryF($sql)) {
        $errors .= '<br>' . $xoopsDB->error();
    }
    if ('' == $errors) {
        showMessage(__('Selected groups has been deleted.', 'rmcommon'), RMMSG_SUCCESS, 'fa fa-remove-circle');
        $ajax->ajax_response('', 0, 1, array('reload' => true));
    } else {
        $ajax->ajax_response(__('Errors ocurred while trying to delete selected groups.', 'rmcommon') . "\n" . $errors, 1, 1);
    }
}
예제 #4
0
 /**
  * Process subscription to an event by getting url parameters
  */
 public function subscribe()
 {
     global $cuSettings, $xoopsUser;
     $this->prepare_ajax_response();
     $event = RMHttpRequest::post('event', 'string', '');
     $status = RMHttpRequest::post('status', 'integer', 1);
     if (!$xoopsUser) {
         $this->add_error(__('No user has been specified', 'rmcommon'));
         return false;
     }
     if ('' == $event) {
         $this->add_error(__('No event name has been specified', 'rmcommon'));
         return false;
     }
     include_once RMCPATH . '/class/crypt.php';
     $crypt = new Crypt(null, $cuSettings->secretkey);
     $event = $crypt->decrypt($event);
     $event = json_decode($event);
     $event->uid = $xoopsUser->uid();
     // Include controller file
     if ('plugin' == $event->type) {
         $file = XOOPS_ROOT_PATH . '/modules/rmcommon/plugins/' . $event->element . '/class/' . strtolower($event->element) . '.notifications.class.php';
     } elseif ('theme' == $event->type) {
         $file = XOOPS_ROOT_PATH . '/themes/' . $event->element . '/class/' . strtolower($event->element) . '.notifications.class.php';
     } else {
         $file = XOOPS_ROOT_PATH . '/modules/' . $event->element . '/class/' . strtolower($event->element) . '.notifications.class.php';
     }
     include_once $file;
     $class = ucfirst($event->element) . '_Notifications';
     if (!class_exists(ucfirst($event->element) . '_Notifications')) {
         $this->add_error(__('There are not a notifications controller for this element', 'rmcommon'));
         return false;
     }
     // Verify if event is a valid and existing event in module
     $notification = $class::get();
     if (!$notification->is_valid($event->event)) {
         $this->add_error(__('Specified event is not valid for this element', 'rmcommon'));
         return false;
     }
     $subscribed = $this->is_subscribed($event->event, $event->element, $event->type, $event->params);
     $event->status = $status ? 'subscribed' : 'removed';
     if ($status && $subscribed) {
         return $event;
     }
     if (!$status && $subscribed) {
         if ($this->unsubscribe($event)) {
             return $event;
         } else {
             return false;
         }
     }
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     $sql = "INSERT INTO " . $db->prefix("mod_rmcommon_notifications") . " (`event`,`element`,`params`,`uid`,`type`,`date`)\n                VALUES ('{$event->event}', '{$event->element}', '{$event->params}', '" . $xoopsUser->uid() . "',\n                '{$event->type}', now())";
     if ($db->queryF($sql)) {
         return $event;
     } else {
         $this->add_error($db->error());
     }
     return false;
 }
예제 #5
0
/**
* This function allows to insert a new block in database
*/
function insert_block()
{
    global $xoopsSecurity;
    $mod = RMHttpRequest::post('module', 'string', '');
    $id = RMHttpRequest::post('block', 'string', '');
    $token = RMHttpRequest::post('XOOPS_TOKEN_REQUEST', 'string', '');
    $canvas = RMHttpRequest::post('canvas', 'integer', 0);
    if (!$xoopsSecurity->check()) {
        response(__('Sorry, you are not allowed to view this page', 'rmcommon'), array(), 1, 0);
    }
    if ($mod == '' || $id == '') {
        response(__('The block specified seems to be invalid. Please try again.', 'rmcommon'), array(), 1, 0);
    }
    $module = RMModules::load_module($mod);
    if (!$module) {
        response(__('The specified module does not exists!', 'rmcommon'), array(), 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(__('The specified block does not exists, please verify your selection.', 'rmcommon'), array(), 1, 1);
    }
    $block = new RMInternalBlock();
    if ($canvas <= 0) {
        $db = XoopsDatabaseFactory::getDatabaseConnection();
        // Get a default side
        $sql = "SELECT id_position FROM " . $db->prefix("mod_rmcommon_blocks_positions") . " ORDER BY id_position LIMIT 0, 1";
        $result = $db->query($sql);
        if ($result) {
            list($canvas) = $db->fetchRow($result);
        } else {
            $canvas = '';
        }
    }
    $block->setReadGroups(array(0));
    $block->setVar('name', $bk['name']);
    $block->setVar('element', $mod);
    $block->setVar('element_type', $bk['type'] == '' ? 'module' : ($bk['type'] == 'theme' || $bk['type'] == 'plugin' ? $bk['type'] : 'module'));
    $block->setVar('canvas', $canvas);
    $block->setVar('visible', 0);
    $block->setVar('type', $bk['type']);
    $block->setVar('isactive', 1);
    $block->setVar('dirname', isset($bk['dirname']) ? $bk['dirname'] : $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(__('Block could not be created. Please try again!', 'rmcommon'), array('error' => $block->errors()), 1, 1);
    }
    RMEvents::get()->run_event('rmcommon.block.added', $block);
    $pos = RMBlocksFunctions::block_positions();
    $ret = array('id' => $block->id(), 'title' => $block->getVar('name'), 'module' => $block->getVar('element'), 'description' => $block->getVar('description'), 'canvas' => $pos[$canvas], 'weight' => $block->getVar('weight'), 'visible' => $block->getVar('visible'));
    response(sprintf(__('Block "%s" was added successfully! Please configure it.', 'rmcommon'), $block->getVar('name')), array('block' => $ret), 0, 1);
    die;
}
예제 #6
0
 /**
  * Save current model data with a new registry
  */
 public function save()
 {
     $attributes = $this->attributes;
     $fields = array();
     /**
      * Name to get post/get/put vars
      */
     $vars_container = get_class($this);
     /**
      * Determinamos si se trata de un objeto existente
      * o un objeto nuevo en base a la clave principal.
      * Si el contenedor de la variables cuenta con un
      * índice nombrado igual que la clave principal entonces
      * es un objeto existente, si no, se trata de un objeto
      * nuevo.
      * Importante: el valor del índice nombrado como la clave
      * principal siempre debe ser numérico.
      */
     if (isset($vars_container[$this->db->primary_key])) {
         $action_type = 'update';
     } else {
         $action_type = 'new';
     }
     $this->data = RMHttpRequest::post($vars_container, 'array', array());
     foreach ($this->columns as $column => $data) {
         /**
          * Si se trata de un objeto nuevo evitamos la verificación
          * de la clave principal.
          */
         if ($column == $this->db->primary_key && $action_type == 'new') {
             continue;
         }
         /**
          * Verificamos la integridad de los datos proporcionados.
          */
         if (!$this->verify_http_data($column)) {
             return false;
         }
         $fields[$column] = isset($rules[$column]) ? $rules[$column]($attributes) : (isset($attributes[$column]) ? $attributes[$column] : null);
     }
     return $this->db->database->queryF($this->db->getInsert($fields));
 }
예제 #7
0
/**
* @desc Activa o desactiva un foro
*/
function bx_activate_forums($status = 1)
{
    global $xoopsDB, $xoopsSecurity;
    if (!$xoopsSecurity->check()) {
        RMUris::redirect_with_message(__('Session token expired! Try again.', 'bxpress'), 'forums.php', RMMSG_ERROR);
    }
    $forums = RMHttpRequest::post('ids', 'array', null);
    if (!is_array($forums) || empty($forums)) {
        RMUris::redirect_with_message(__('No forum has been selected.', 'bxpress'), 'forums.php', RMMSG_ERROR);
    }
    $sql = "UPDATE " . $xoopsDB->prefix("mod_bxpress_forums") . " SET active='{$status}' WHERE ";
    $sql1 = '';
    foreach ($forums as $k => $v) {
        $sql1 .= $sql1 == '' ? "id_forum='{$v}' " : "OR id_forum='{$v}' ";
    }
    $xoopsDB->queryF($sql . $sql1);
    RMUris::redirect_with_message(__('Database updated successfully!', 'bxpress'), 'forums.php', RMMSG_INFO);
}
예제 #8
0
 /**
  * RSS Management
  */
 public function eventCoreIncludeCommonEnd()
 {
     global $xoopsOption;
     if (defined('RMC_CHECK_UPDATES') && $xoopsOption['pagetype'] == 'admin') {
         global $xoopsSecurity, $rmTpl;
         $rmTpl->add_head_script('var xoToken = "' . $xoopsSecurity->createToken() . '";');
     }
     // Process notifications
     $current = explode("?", RMUris::relative_url(RMUris::current_url()));
     if ($current[0] == '/notifications.php') {
         $page = RMHttpRequest::post('page', 'string', '');
         if ('cu-notification-subscribe' == $page) {
             include RMCPATH . '/include/notifications.php';
         }
         $page = RMHttpRequest::get('page', 'string', '');
         if ('cu-notification-list' == $page) {
             include RMCPATH . '/include/notifications.php';
         }
     }
     RMEvents::get()->run_event('rmcommon.xoops.common.end');
 }
예제 #9
0
     die;
 }
 // Object type
 $type = rmc_server_var($_POST, 'type', '');
 if (trim($type) == '') {
     redirect_header($uri, 2, __('Object type missing!', 'rmcommon'));
     die;
 }
 // Object name
 $object = strtolower(rmc_server_var($_POST, 'object', ''));
 if (trim($object) == '') {
     redirect_header($uri, 2, __('Object name missing!', 'rmcommon'));
     die;
 }
 // Text
 $text = RMHttpRequest::post('comment_text', 'string', '');
 if (trim($text) == '') {
     redirect_header($uri, 2, __('You must write a message!', 'rmcommon'));
     die;
 }
 $kses = new RMKses();
 $text = $kses->filter($text, 'reduced');
 RMEvents::get()->run_event('rmcommon.comment.postdata', $uri);
 // Save comment user
 $db = XoopsDatabaseFactory::getDatabaseConnection();
 if ($xoopsUser) {
     $sql = "SELECT id_user FROM " . $db->prefix("mod_rmcommon_comments_assignations") . " WHERE xuid=" . $xoopsUser->uid();
 } else {
     $sql = "SELECT id_user FROM " . $db->prefix("mod_rmcommon_comments_assignations") . " WHERE email='{$email}'";
 }
 $result = $db->query($sql);
예제 #10
0
function update_locally()
{
    global $xoopsSecurity, $xoopsLogger, $xoopsConfig;
    $xoopsLogger->activated = false;
    if (!$xoopsSecurity->check()) {
        jsonReturn(__('Wrong action!', 'rmcommon'), 1, array(), 0);
    }
    $dir = RMHttpRequest::post('module', 'string', '');
    $type = RMHttpRequest::post('type', 'string', '');
    if ('' == $dir || '' == $type) {
        jsonReturn(__('Data not valid!', 'rmcommon'));
    }
    if ('module' == $type) {
        if (!is_dir(XOOPS_ROOT_PATH . '/modules/' . $dir)) {
            jsonReturn(__('Module does not exists!', 'rmcommon'));
        }
        xoops_loadLanguage('admin', 'system');
        $file = XOOPS_ROOT_PATH . '/modules/system/language/' . $xoopsConfig['language'] . '/admin/modulesadmin.php';
        if (file_exists($file)) {
            include_once $file;
        } else {
            include_once str_replace($xoopsConfig['language'], 'english', $file);
        }
        include_once XOOPS_ROOT_PATH . '/modules/system/admin/modulesadmin/modulesadmin.php';
        $log = xoops_module_update($dir);
        jsonReturn(__('Module updated locally', 'rmcommon'), 0, array('log' => $log));
    } elseif ('plugin' == $type) {
        if (!is_dir(XOOPS_ROOT_PATH . '/modules/rmcommon/plugins/' . $dir)) {
            jsonReturn(__('Plugin does not exists!', 'rmcommon'));
        }
        $plugin = new RMPlugin($dir);
        if ($plugin->isNew()) {
            jsonReturn(__('Plugin does not exists!', 'rmcommon'));
        }
        if (!$plugin->on_update()) {
            jsonReturn(sprintf(__('Plugins manager could not update the plugin: %s', 'rmcommon'), $plugin->errors()));
        }
        jsonReturn(__('Plugin updated locally', 'rmcommon'), 0);
    }
}
예제 #11
0
    }
    $image = new RMImage($id);
    if ($image->isNew()) {
        images_send_json(array('message' => __('Specified image does not exists', 'rmcommon'), 'error' => 1, 'token' => $xoopsSecurity->createToken()));
    }
    $author = new RMUser($image->uid);
    $original = pathinfo($image->get_files_path() . '/' . $image->file);
    $dimensions = getimagesize($image->get_files_path() . '/' . $image->file);
    $mimes = (include XOOPS_ROOT_PATH . '/include/mimetypes.inc.php');
    $category_sizes = $cat->getVar('sizes');
    $sizes = array();
    foreach ($category_sizes as $i => $size) {
        if ($size['width'] <= 0) {
            continue;
        }
        $tfile = $image->get_files_path() . '/sizes/' . $original['filename'] . '-' . $size['name'] . '.' . $original['extension'];
        if (!is_file($tfile)) {
            continue;
        }
        $t_dim = getimagesize($tfile);
        $sizes[] = array('width' => $t_dim[0], 'height' => $t_dim[1], 'url' => $image->get_files_url() . '/sizes/' . $original['filename'] . '-' . $size['name'] . '.' . $original['extension'], 'name' => $size['name']);
    }
    $sizes[] = array('width' => $dimensions[0], 'height' => $dimensions[1], 'url' => $image->getOriginal(), 'name' => __('Original', 'rmcommon'));
    $links = array('none' => array('caption' => __('None', 'rmcommon'), 'value' => ''), 'file' => array('caption' => __('File URL', 'rmcommon'), 'value' => XOOPS_UPLOAD_URL . '/' . date('Y', $image->getVar('date')) . '/' . date('m', $image->getVar('date')) . '/' . $image->getVar('file')));
    $links = RMEvents::get()->run_event('rmcommon.image.insert.links', $links, $image, RMHttpRequest::post('url', 'string', ''));
    // Image data
    $data = array('id' => $image->id(), 'title' => $image->title, 'date' => formatTimestamp($image->date, 'l'), 'description' => $image->getVar('desc', 'n'), 'author' => array('uname' => $author->uname, 'uid' => $author->uid, 'avatar' => RMEvents::get()->run_event('rmcommon.get.avatar', $author->email, 40), 'url' => XOOPS_URL . '/userinfo.php?uid=' . $author->email), 'medium' => $image->get_by_size(300), 'url' => $image->get_files_url(), 'original' => array('file' => $original['basename'], 'url' => $image->getOriginal(), 'size' => RMFormat::bytes_format(filesize($image->get_files_path() . '/' . $image->file)), 'width' => $dimensions[0], 'height' => $dimensions[1]), 'mime' => isset($mimes[$original['extension']]) ? $mimes[$original['extension']] : 'application/octet-stream', 'sizes' => $sizes, 'links' => $links);
    $data = RMEvents::get()->run_event('rmcommon.loading.image.details', $data, $image, RMHttpRequest::request('url', 'string', ''));
    $data['token'] = $xoopsSecurity->createToken();
    images_send_json($data);
}
예제 #12
0
 /**
  * Imports a single article from Publisher
  */
 public function article()
 {
     global $xoopsSecurity, $xoopsDB;
     $this->prepare_ajax_response();
     $functions = MWFunctions::get();
     if (!$xoopsSecurity->check(true, false, 'CUTOKEN')) {
         $this->ajax_response(__('Session token not valid!', 'mywords'), 1, 0);
     }
     $id = RMHttpRequest::post('id', 'integer', 0);
     if ($id <= 0) {
         $this->ajax_response(sprintf(__('Article ID %u is not valid!', 'mywords'), $id), 0, 1, ['result' => 'error']);
     }
     $sql = "SELECT * FROM " . $xoopsDB->prefix("publisher_items") . " WHERE itemid = {$id}";
     $result = $xoopsDB->query($sql);
     if ($xoopsDB->getRowsNum($result)) {
         if ($id <= 0) {
             $this->ajax_response(sprintf(__('Article with ID %u was not found!', 'mywords'), $id), 0, 1, ['result' => 'error']);
         }
     }
     $row = $xoopsDB->fetchArray($result);
     $cache = $this->loadCache();
     $post = new MWPost();
     $post->setVar('title', $row['title']);
     $post->setVar('shortname', TextCleaner::getInstance()->sweetstring($row['title']));
     $post->setVar('content', $row['body']);
     switch ($row['status']) {
         case 1:
         case 4:
             $status = 'pending';
             break;
         case 2:
             $status = 'publish';
             break;
         case 3:
             $status = 'draft';
             break;
     }
     $post->setVar('status', $status);
     $post->setVar('visibility', 'public');
     $post->setVar('author', $row['uid']);
     $post->setVar('comstatus', 1);
     $post->setVar('pubdate', $row['datesub']);
     $post->setVar('created', $row['datesub']);
     $post->setVar('reads', $row['counter']);
     $post->setVar('description', $row['summary']);
     $post->setVar('keywords', $row['meta_keywords']);
     $post->setVar('format', 'post');
     if (isset($cache['categories'][$row['categoryid']])) {
         $post->add_categories($cache['categories'][$row['categoryid']]);
     }
     unset($row);
     if (!$post->save()) {
         $this->ajax_response(sprintf(__('Article %s could not be saved!', 'mywords'), $post->title), 0, 1, ['result' => 'error']);
     }
     $this->ajax_response(sprintf(__('Article %s imported successfully!', 'mywords'), '<strong>' . $post->title . '</strong>'), 0, 1, ['result' => 'success']);
 }
예제 #13
0
파일: likes.php 프로젝트: petitours/bxpress
 */
require '../../mainfile.php';
$xoopsLogger->activated = false;
function response_json($error = 0, $message = '', $data = array(), $token = true)
{
    global $xoopsSecurity;
    echo json_encode(array('message' => $message, 'data' => $data, 'error' => $error, 'token' => $token ? $xoopsSecurity->createToken(0, 'BXTOKEN') : ''));
    exit;
}
if (!$xoopsUser) {
    exit;
}
/*
 * Get parameters
 */
$id = RMHttpRequest::post('id', 'integer', 0);
if (!$xoopsSecurity->check(true, false, 'BXTOKEN')) {
    response_json(1, __('Please refresh the page in order to register your likes.', 'bxpress'), array(), false);
}
$post = new bXPost($id);
if ($post->isNew()) {
    response_json(1, __('The specified post does not exists! Verify it!', 'bxpress'), array(), true);
}
$sql = "SELECT COUNT(*) FROM " . $xoopsDB->prefix("mod_bxpress_likes") . " WHERE uid=" . $xoopsUser->uid() . " AND post=" . $post->id();
list($exists) = $xoopsDB->fetchRow($xoopsDB->query($sql));
if ($exists > 0) {
    $action = 'unlike';
} else {
    $action = 'like';
}
if ('like' == $action) {
예제 #14
0
function module_uninstall_now()
{
    global $xoopsSecurity, $xoopsConfig, $rmTpl, $xoopsDB;
    $dir = RMHttpRequest::post('module', 'string', '');
    if (!$xoopsSecurity->check()) {
        redirectMsg('modules.php', __('Sorry, this operation could not be completed!', 'rmcommon'), 1);
        die;
    }
    $module_handler = xoops_gethandler('module');
    if (!($mod = $module_handler->getByDirname($dir))) {
        redirectMsg('modules.php', sprintf(__('Module %s is not installed yet!', 'rmcommon'), $mod), 1);
        die;
    }
    $file = XOOPS_ROOT_PATH . '/modules/system/language/' . $xoopsConfig['language'] . '/admin/modulesadmin.php';
    if (file_exists($file)) {
        include_once $file;
    } else {
        include_once str_replace($xoopsConfig['language'], 'english', $file);
    }
    include_once XOOPS_ROOT_PATH . '/modules/system/admin/modulesadmin/modulesadmin.php';
    RMEvents::get()->run_event('rmcommon.uninstalling.module', $mod);
    $module_log = xoops_module_uninstall($dir);
    // Remove comments
    $sql = "DELETE FROM " . $xoopsDB->prefix("mod_rmcommon_comments") . " WHERE id_obj='{$dir}'";
    if ($xoopsDB->queryF($sql)) {
        $module_log .= '<br><span class="text-success"><span class="fa fa-check"></span> Comments deleted successfully!</span>';
    } else {
        $module_log .= '<br><span class="text-danger"><span class="fa fa-exclamation-triangle"></span> Comments could not be deleted: ' . $xoopsDB->error() . '</span>';
    }
    // Remove notifications
    $sql = "DELETE FROM " . $xoopsDB->prefix("mod_rmcommon_notifications") . " WHERE element='{$dir}' AND `type`='module'";
    if ($xoopsDB->queryF($sql)) {
        $module_log .= '<br><span class="text-success"><span class="fa fa-check"></span> Notifications deleted successfully!</span>';
    } else {
        $module_log .= '<br><span class="text-danger"><span class="fa fa-exclamation-triangle"></span> Notifications could not be deleted: ' . $xoopsDB->error() . '</span>';
    }
    $module_log = RMEvents::get()->run_event('rmcommon.module.uninstalled', $module_log, $mod);
    //RMFunctions::create_toolbar();
    RMTemplate::get()->add_style('modules.min.css', 'rmcommon');
    RMBreadCrumb::get()->add_crumb(__('Modules Management', 'rmcommon'), 'modules.php');
    RMBreadCrumb::get()->add_crumb(sprintf(__('%s install log', 'rmcommon'), $mod->getVar('name')));
    $rmTpl->assign('xoops_pagetitle', sprintf(__('%s install log', 'rmcommon'), $mod->getVar('name')));
    xoops_cp_header();
    $module = new XoopsModule();
    $module->loadInfo($mod, false);
    $log_title = sprintf(__('Uninstall log for %s', 'rmcommon'), $module ? $module->getInfo('name') : $mod);
    $action = rmc_server_var($_POST, 'action', '');
    include RMTemplate::get()->get_template('rmc-modules-log.php', 'module', 'rmcommon');
    xoops_cp_footer();
}
예제 #15
0
/**
 * Save module settings
 */
function save_module_settings()
{
    global $xoopsSecurity, $xoopsDB;
    $mod = RMHttpRequest::post('mod', 'string', '');
    $via_ajax = RMHttpRequest::post('via_ajax', 'integer', 0);
    if ($via_ajax) {
        $ajax = new AjaxResponse();
        $ajax->prepare_ajax_response();
    }
    if ($mod == '') {
        RMUris::redirect_with_message(__('A module has not been specified!', 'rmcommon'), 'settings.php', RMMSG_ERROR);
    }
    //echo RMHttpRequest::request('CUTOKEN_REQUEST', 'string', '') . ' ' . print_r($_SESSION['CUTOKEN_SESSION'], true); die();
    if (!$xoopsSecurity->check(true, false, $via_ajax ? 'CUTOKEN' : 'XOOPS_TOKEN')) {
        if ($via_ajax) {
            $ajax->ajax_response(__('Session token expired. Please try again.', 'rmcommon'), 1, 0);
        } else {
            RMUris::redirect_with_message(__('Session token expired. Please try again.', 'rmcommon'), 'settings.php', RMMSG_WARN);
        }
    }
    $module = RMModules::load_module($mod);
    if (!$module) {
        if ($via_ajax) {
            $ajax->ajax_response(__('The specified module does not exists.', 'rmcommon'), 1, 1);
        } else {
            RMUris::redirect_with_message(__('The specified module does not exists.', 'rmcommon'), 'settings.php', RMMSG_ERROR);
        }
    }
    $current_settings = (array) RMSettings::module_settings($module->getVar('dirname'));
    $new_settings = RMHttpRequest::post(ucfirst($module->getVar('dirname')), 'array', array());
    $configs = $module->getInfo('config');
    $fields = array();
    // Container for all fields and values
    foreach ($configs as $option) {
        $id = $option['name'];
        $field = new stdClass();
        $field->id = $id;
        $field->value = isset($values->{$id}) ? $values->{$id} : $option['default'];
        $field->caption = defined($option['title']) ? constant($option['title']) : $option['title'];
        $field->description = defined($option['description']) ? constant($option['description']) : $option['description'];
        $field->field = $option['formtype'];
        $field->type = $option['valuetype'];
        $field->options = isset($option['options']) ? $option['options'] : null;
        $category = isset($option['category']) ? $option['category'] : 'all';
        $fields[$id] = $field;
    }
    /**
     * This keys already exists in database
     */
    $to_save = array_intersect_key($new_settings, $current_settings);
    /**
     * This settings will be added to database beacause don't exists in table
     */
    $to_add = array_diff_key($new_settings, $current_settings);
    /**
     * This keys has been removed from xoops_version.php file and then
     * must be removed from table
     */
    $to_delete = array_diff_key($current_settings, $new_settings);
    $errors = '';
    // Errors ocurred while saving
    /**
     * First for all, remove unused items
     */
    $keys = array_keys($to_delete);
    if (!empty($keys)) {
        $sql = "DELETE FROM " . $xoopsDB->prefix("config") . " WHERE conf_modid = " . $module->mid() . " AND (conf_name = '" . implode("' OR conf_name='", $keys) . "')";
        if (!$xoopsDB->queryF($sql)) {
            $errors .= $xoopsDB->error() . '<br>';
        }
    }
    /**
     * Save existing items
     */
    if (!empty($to_save)) {
        foreach ($to_save as $name => $value) {
            $item = new Rmcommon_Config_Item($name, $module->mid());
            if (isset($fields[$name])) {
                $item->setVar('conf_valuetype', $fields[$name]->type);
                $item->setVar('conf_title', $fields[$name]->caption);
                $item->setVar('conf_desc', $fields[$name]->description);
                $item->setVar('conf_formtype', $fields[$name]->field);
            }
            $item->set_value($value, $item->getVar('conf_valuetype'));
            $item->save();
        }
    }
    /**
     * Add new items
     */
    if (!empty($to_add)) {
        foreach ($to_add as $name => $value) {
            $item = new Rmcommon_Config_Item($name, $module->mid());
            if (isset($fields[$name])) {
                $item->setVar('conf_modid', $module->mid());
                $item->setVar('conf_name', $name);
                $item->setVar('conf_valuetype', $fields[$name]->type);
                $item->setVar('conf_title', $fields[$name]->caption);
                $item->setVar('conf_desc', $fields[$name]->description);
                $item->setVar('conf_formtype', $fields[$name]->field);
            }
            $item->set_value($value, $item->getVar('conf_valuetype'));
            $item->save();
        }
    }
    /**
     * Notify to system events
     */
    RMEvents::get()->trigger('rmcommon.saved.settings', $module->dirname(), $to_save, $to_add, $to_delete);
    if ($module->getInfo('hasAdmin')) {
        $goto = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . $module->getInfo('adminindex');
    } else {
        $goto = 'settings.php';
    }
    if ($via_ajax) {
        $ajax->ajax_response(__('Settings saved successfully!', 'rmcommon'), 0, 1, array('closeWindow' => '#cu-settings-form', 'notify' => array('icon' => 'svg-rmcommon-ok-circle', 'type' => 'alert-success')));
    } else {
        RMUris::redirect_with_message(__('Settings saved successfully!', 'rmcommon'), $goto, RMMSG_SUCCESS, 'fa fa-check');
    }
}