Esempio n. 1
0
 /**
  * Check if a category exists already
  * @param object MWCategory object
  * @return bool
  */
 public function category_exists(MWCategory $cat)
 {
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     $sql = "SELECT COUNT(*) FROM " . $db->prefix("mw_categories") . " WHERE name='" . $cat->getVar('name', 'n') . "' OR\n\t\t\t\tshortname='" . $cat->getVar('shortname', 'n') . "'";
     if (!$cat->isNew()) {
         $sql .= " AND id_cat<>" . $cat->id();
     }
     list($num) = $db->fetchRow($db->query($sql));
     if ($num > 0) {
         return true;
     }
     return false;
 }
Esempio n. 2
0
function mywordsBlockCats($options)
{
    global $xoopsModuleConfig, $xoopsModule;
    $categos = array();
    MWFunctions::categos_list($categos, 0, 0, $options[0]);
    $block = array();
    $mc = $xoopsModule && $xoopsModule->getVar('dirname') == 'mywords' ? $xoopsModuleConfig : RMSettings::module_settings('mywords');
    foreach ($categos as $k) {
        $ret = array();
        $cat = new MWCategory();
        $cat->assignVars($k);
        $cat->loadPosts();
        $ret['id'] = $cat->id();
        $ret['name'] = $cat->getVar('name');
        if (isset($options[1]) && $options[1]) {
            $ret['posts'] = $cat->getVar('posts');
        }
        $ret['indent'] = $k['indent'] * 2;
        $ret['link'] = $cat->permalink();
        $block['categos'][] = $ret;
    }
    RMTemplate::get()->add_style('mwblocks.css', 'mywords');
    return $block;
}
Esempio n. 3
0
switch ($show) {
    case 'cat':
        include_once XOOPS_ROOT_PATH . '/modules/mywords/class/mwcategory.class.php';
        $id = rmc_server_var($_GET, 'cat', 0);
        if ($id <= 0) {
            redirect_header('backend.php', 1, __('Sorry, specified category was not foud!', 'mywords'));
            die;
        }
        $cat = new MWCategory($id);
        if ($cat->isNew()) {
            redirect_header('backend.php', 1, __('Sorry, specified category was not foud!', 'mywords'));
            die;
        }
        $rss_channel['title'] = sprintf(__('Posts in %s - %s', 'mywords'), $cat->name, $xoopsConfig['sitename']);
        $rss_channel['link'] = $cat->permalink();
        $rss_channel['description'] = htmlspecialchars($cat->getVar('description'), ENT_QUOTES);
        $rss_channel['lastbuild'] = formatTimestamp(time(), 'rss');
        $rss_channel['webmaster'] = checkEmail($xoopsConfig['adminmail'], true);
        $rss_channel['editor'] = checkEmail($xoopsConfig['adminmail'], true);
        $rss_channel['category'] = $cat->getVar('name');
        $rss_channel['generator'] = 'Common Utilities';
        $rss_channel['language'] = RMCLANG;
        $posts = MWFunctions::get_posts_by_cat($id, 0, 10);
        $rss_items = array();
        foreach ($posts as $post) {
            $item = array();
            $item['title'] = $post->getVar('title');
            $item['link'] = $post->permalink();
            $img = new RMImage();
            $img->load_from_params($post->getVar('image', 'e'));
            if (!$img->isNew()) {
Esempio n. 4
0
/**
 * Presenta un formulario para la creación de una nueva
 * categoría para los artículos
 */
function newForm()
{
    global $xoopsModule;
    $id = isset($_GET['id']) ? $_GET['id'] : 0;
    if ($id <= 0) {
        redirectMsg('categories.php', __('You must specify a valid category', 'mywords'), 1);
        die;
    }
    // Cargamos la categoría
    $catego = new MWCategory($id);
    // Si no existe entonces devolvemos un error
    if ($catego->isNew()) {
        redirectMsg('cats.php', __('Specified category not exists!', 'mywords'), 1);
        die;
    }
    MWFunctions::include_required_files();
    xoops_cp_location('<a href="./">' . $xoopsModule->name() . '</a> &raquo; ' . __('New Category', 'mywords'));
    xoops_cp_header();
    $cats = array();
    MWFunctions::categos_list($cats, 0, 0, true, $id);
    $form = new RMForm($edit ? __('Edit Category', 'mywords') : __('Edit Category', 'mywords'), 'frmNew', 'categories.php');
    $form->styles('width: 30%;', 'odd');
    $form->addElement(new RMFormText(__('Category name', 'mywords'), 'name', 50, 150, $catego->getVar('name')), true);
    $form->addElement(new RMFormText(__('Category slug', 'mywords'), 'shortname', '', '150', $catego->getVar('shortname', 'n')));
    $form->addElement(new RMFormTextArea(__('Category description', 'mywords'), 'desc', 5, 45, $catego->getVar('description', 'e')));
    $ele = new RMFormSelect(__('Category Parent', 'mywords'), 'parent');
    $ele->addOption(0, _SELECT, $catego->getVar('parent') == 0 ? 1 : 0);
    foreach ($cats as $k) {
        $ele->addOption($k['id_cat'], str_repeat("-", $k['indent']) . ' ' . $k['name'], $catego->getVar('parent') == $k['id_cat'] ? 1 : 0);
    }
    $form->addElement($ele);
    $form->addElement(new RMFormHidden('op', 'saveedit'));
    $form->addElement(new RMFormHidden('id', $id));
    $ele = new RMFormButtonGroup('', ' ');
    $ele->addButton('sbt', __('Update Category', 'mywords'), 'submit');
    $ele->addButton('cancel', __('Cancel', 'mywords'), 'button');
    $ele->setExtra('cancel', "onclick='history.go(-1);'");
    $form->addElement($ele);
    $form->display();
    xoops_cp_footer();
}
Esempio n. 5
0
            $sql = "SELECT id_cat FROM {$tbl1} WHERE shortname='{$k}' AND parent='{$idp}'";
            $result = $db->query($sql);
            if ($db->getRowsNum($result) > 0) {
                list($idp) = $db->fetchRow($result);
            }
        }
        $category = $idp;
    }
}
$catego = new MWCategory($category);
if ($catego->isNew()) {
    redirect_header(MWFunctions::get_url(), 2, __('Specified category could not be found', 'mywords'));
    die;
}
// Datos de la Categoría
$xoopsTpl->assign('category', array('id' => $catego->id(), 'name' => $catego->getVar('name')));
$xoopsTpl->assign('lang_postsincat', sprintf(__('Posts in &#8216;%s&#8217; Category', 'mywords'), $catego->getVar('name')));
$request = substr($request, 0, strpos($request, 'page') > 0 ? strpos($request, 'page') - 1 : strlen($request));
//$request =
// Select all posts from relations table
//$sql = "SELECT post FROM ".$db->prefix("mw_catpost")." WHERE cat='$category'";
//$result = $db->query($sql);
/**
 * Paginacion de Resultados
 */
$limit = $mc['posts_limit'];
list($num) = $db->fetchRow($db->query("SELECT COUNT({$tbl2}.post) FROM {$tbl2}, {$tbl3} WHERE {$tbl2}.cat='{$category}' \n\t\tAND {$tbl3}.id_post={$tbl2}.post AND {$tbl3}.status='publish' AND \n\t\t(({$tbl3}.visibility='public' OR {$tbl3}.visibility='password') OR ({$tbl3}.visibility='private' AND \n\t\t{$tbl3}.author=" . ($xoopsUser ? $xoopsUser->uid() : -1) . "))"));
$page = isset($page) && $page > 0 ? $page : 1;
$limit = $xoopsModuleConfig['posts_limit'];
$tpages = ceil($num / $limit);
$page = $page > $tpages ? $tpages : $page;