Пример #1
0
/**
 * Almacenamos la categoría en la base de datos
 */
function saveCatego($edit = 0)
{
    global $xoopsSecurity, $db;
    if (!$xoopsSecurity->check()) {
        redirectMsg('categories.php', __('Sorry, session token expired!', 'mywords'), 1);
        die;
    }
    $query = '';
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
        if ($k == 'op' || $k == 'XOOPS_TOKEN_REQUEST') {
            continue;
        }
        $query .= $query == '' ? "{$k}=" . urlencode($v) : '&' . $k . '=' . urlencode($v);
    }
    $query = $edit ? '&op=edit' : '';
    if ($edit) {
        if ($id <= 0) {
            redirectMsg('categories.php', __('You must specify a valid category', 'mywords'), 1);
            die;
        }
        $catego = new MWCategory($id);
        if ($catego->isNew()) {
            redirectMsg('categories.php', __('Specified category not exists!', 'mywords'), 1);
            die;
        }
    } else {
        $catego = new MWCategory();
    }
    if ($name == '') {
        redirectMsg('categories.php?' . $query, __('Please specify a name for this category!', 'mywords'), 1);
        die;
    }
    $shortname = $shortname == '' ? TextCleaner::sweetstring($name) : $shortname;
    # Verificamos que no exista la categoría
    $result = $db->query("SELECT COUNT(*) FROM " . $db->prefix("mw_categories") . " WHERE parent='{$parent}'" . ($edit ? " AND id_cat<>{$id}" : '') . " AND (name='{$name}' OR shortname='{$shortname}')");
    list($num) = $db->fetchRow($result);
    if ($num > 0) {
        redirectMsg('categories.php?' . $query, __('There is already a category with the same name!', 'mywords'), 1);
        die;
    }
    # Si todo esta bien guardamos la categoría
    $catego->setVar('name', $name);
    $catego->setVar('shortname', $shortname);
    $catego->setVar('description', $desc);
    $catego->setVar('parent', $parent);
    if (!$edit) {
        $catego->setVar('posts', 0);
    }
    $result = $catego->save();
    if ($result) {
        redirectMsg('categories.php', __('Category created succesfully!', 'mywords'), 0);
    } else {
        redirectMsg('categories.php?' . $query, __('There was an error!', 'mywords') . "<br />" . $catego->errors(), 1);
    }
}
Пример #2
0
global $xoopsLogger;
$xoopsLogger->renderingEnabled = false;
error_reporting(0);
$xoopsLogger->activated = false;
extract($_POST);
if (!$xoopsSecurity->check() || !$xoopsSecurity->checkReferer()) {
    $ret = array('error' => __('You are not allowed to do this operation!', 'mywords'));
    echo json_encode($ret);
    die;
}
if (!isset($name) || $name == '') {
    $ret = array('error' => __('A name is neccesary to create a new category!', 'mywords'), 'token' => $xoopsSecurity->createToken());
    echo json_encode($ret);
    die;
}
$catego = new MWCategory();
$catego->setVar('name', $name);
$catego->setVar('shortname', TextCleaner::sweetstring($name));
$catego->setVar('parent', $parent);
if (MWFunctions::category_exists($catego)) {
    $ret = array('error' => __('There is already a category with same name!', 'mywords'), 'token' => $xoopsSecurity->createToken());
    echo json_encode($ret);
    die;
}
if (!$catego->save()) {
    $ret = array('error' => __('Category could not inserted!', 'mywords') . "\n" . $catego->errors(), 'token' => $xoopsSecurity->createToken());
    echo json_encode($ret);
    die;
}
$ret = array('message' => __('Category created successfully!', 'mywords'), 'token' => $xoopsSecurity->createToken(), 'id' => $catego->id());
echo json_encode($ret);
Пример #3
0
 /**
  * Imports a single category from publisher to MyWords
  */
 public function category()
 {
     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(__('Category ID %u is not valid!', 'mywords'), $id), 0, 1, ['result' => 'error']);
     }
     $sql = "SELECT * FROM " . $xoopsDB->prefix("publisher_categories") . " WHERE categoryid = {$id}";
     $result = $xoopsDB->query($sql);
     if ($xoopsDB->getRowsNum($result)) {
         if ($id <= 0) {
             $this->ajax_response(sprintf(__('Category with ID %u was not found!', 'mywords'), $id), 0, 1, ['result' => 'error']);
         }
     }
     $row = $xoopsDB->fetchArray($result);
     $cache = $this->loadCache();
     $category = new MWCategory();
     $category->setVar('name', $row['name']);
     $category->setVar('description', $row['description']);
     $category->setVar('shortname', TextCleaner::getInstance()->sweetstring($row['name']));
     // Search for parent
     if (isset($cache['categories'][$row['parentid']])) {
         $category->setVar('parent', $cache['categories'][$row['parentid']]);
     }
     unset($row);
     if ($functions->category_exists($category)) {
         $this->ajax_response(sprintf(__('Category %s already exists', 'mywords'), $category->name), 0, 1, ['result' => 'success']);
     }
     if (!$category->save()) {
         $this->ajax_response(sprintf(__('Category %s could not be saved!', 'mywords'), $category->name), 0, 1, ['result' => 'error']);
     }
     $cache['categories'][$id] = $category->id();
     $this->writeCache($cache);
     $this->ajax_response(sprintf(__('Category %s imported successfully!', 'mywords'), '<strong>' . $category->name . '</strong>'), 0, 1, ['result' => 'success']);
 }