/** * 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; }
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; }
/** * Muestra una lista de las categorías existentes */ function showCategos() { global $tpl, $xoopsSecurity, $xoopsModule, $xoopsSecurity; $row = array(); MWFunctions::categos_list($row); $categories = array(); foreach ($row as $k) { $catego = new MWCategory(); $catego->assignVars($k); $catego->loadPosts(); $categories[] = array('id_cat' => $catego->id(), 'description' => $catego->getVar('description', 'n'), 'posts' => $catego->getVar('posts', 'n'), 'name' => $catego->getVar('name', 'n'), 'indent' => $k['indent'], 'shortname' => $catego->getVar('shortname', 'n')); } // Categories pagination // Paginamos $limit = 15; if (count($categories) > $limit) { $page = rmc_server_var($_GET, 'page', 1); $page = $page < 1 ? 1 : $page; $limit_c = $page * ($limit - 1); $limit_c = $limit_c > count($categories) - 1 ? count($categories) - 1 : $limit_c; $tpages = ceil(count($categories) / 3); if ($page > $tpages) { $page = $tpages; } $nav = new RMPageNav(count($categories), $limit, $page, 5); $nav->target_url('?page={PAGE_NUM}'); $i = ($page - 1) * $limit; while ($i <= $limit_c) { $pcategories[] = $categories[$i]; $i++; } $categories = $pcategories; } MWFunctions::include_required_files(); RMTemplate::get()->add_head('<script type="text/javascript"> function cat_del_confirm(cat, id){ var string = "' . __('Do you really want to delete \\"%s\\"', 'mywords') . '"; string = string.replace("%s", cat); var ret = confirm(string); if (ret){ $("#tblCats input[type=checkbox]").removeAttr("checked"); $("#cat-"+id).attr("checked","checked"); $("#cat-op").val("delete"); $("#tblCats").submit(); } } </script>'); RMTemplate::get()->set_help('http://redmexico.com.mx/docs/mywords/descripcion-del-modulo#categorias'); xoops_cp_location('<a href="./">' . $xoopsModule->name() . '</a> » ' . __('Categories', 'mywords')); xoops_cp_header(); $desc = ''; $posts = ''; $parent = ''; $selcat = ''; $new = ''; $name = ''; $shortcut = ''; extract($_GET); include RMTemplate::get()->get_template('admin/mywords_categories.php', 'module', 'mywords'); RMTemplate::get()->assign('xoops_pagetitle', __('Categories Management', 'mywords')); RMTemplate::get()->add_script(RMCURL . '/include/js/jquery.checkboxes.js'); RMTemplate::get()->add_script('../include/js/categories.js'); xoops_cp_footer(); }
$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 ‘%s’ 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;