예제 #1
0
 /**
  * Obtiene la ruta completa de la categor?a basada en nombres
  */
 function path()
 {
     if ($this->getVar('parent') == 0) {
         return $this->getVar('shortname', 'n') . '/';
     }
     $parent = new MWCategory($this->getVar('parent', 'n'));
     return $parent->path() . $this->getVar('shortname') . '/';
 }
예제 #2
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;
 }
예제 #3
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;
}
예제 #4
0
파일: rss.php 프로젝트: JustineBABY/mywords
}
load_mod_locale("mywords");
$show = rmc_server_var($_GET, 'show', 'all');
$xoopsModule = RMFunctions::load_module('mywords');
$config = RMSettings::module_settings('mywords');
include_once XOOPS_ROOT_PATH . '/modules/mywords/class/mwfunctions.php';
$rss_channel = array();
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();
예제 #5
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);
예제 #6
0
/**
 * Elimina una categoría de la base de datos.
 * Las subcategorías pertenecientes a esta categoría no son eliminadas,
 * sino que son asignadas a la categoría superior.
 */
function deleteCatego()
{
    global $xoopsSecurity, $xoopsModule;
    $cats = rmc_server_var($_POST, 'cats', array());
    if (empty($cats)) {
        redirectMsg('categories.php', __('You must select one category at least!', 'mywords'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('categories.php', __("Session token expired!", 'mw_categories'), 1);
        die;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $sql = "SELECT * FROM " . $db->prefix("mw_categories") . " WHERE id_cat IN (" . implode(",", $cats) . ")";
    $result = $db->query($sql);
    while ($row = $db->fetchArray($result)) {
        $cat = new MWCategory();
        $cat->assignVars($row);
        if (!$cat->delete()) {
            showMessage(__('Category "%s" could not be deleted', 'mywords'), 1);
        }
    }
    redirectMsg('categories.php', __('Database updated!', 'mw_categories'), 0);
}
예제 #7
0
 /**
  * Devuelve los nombres de las categorías a las que pertenece
  * el post actual
  * @param bool $asList Detemina si se muestra en forma de lista o de array
  * @param string $delimiter Delimitador para la lista
  * @param bool Get names with links. Only works when $asList equal true
  * @param string Section for link. It can be front or admin. Only works when $asList equal true
  * @return string or array
  */
 public function get_categories_names($asList = true, $delimiter = ',', $links = true, $section = 'front')
 {
     if (empty($this->lcats)) {
         $this->get_categos('data');
     }
     $rtn = $asList ? '' : array();
     $url = MWFunctions::get_url();
     foreach ($this->lcats as $cat) {
         if ($asList) {
             if ($links) {
                 $category = new MWCategory();
                 $category->assignVars($cat);
                 $rtn .= $rtn == '' ? '' : "{$delimiter}";
                 $rtn .= '<a href="' . ($section == 'front' ? $category->permalink() : 'posts.php?cat=' . $cat['id_cat']) . '">' . $cat['name'] . '</a>';
             } else {
                 $rtn .= $rtn == '' ? $cat['name'] : "{$delimiter} {$cat['name']}";
             }
         } else {
             $rtn[] = $row['nombre'];
         }
     }
     return $rtn;
 }
예제 #8
0
/**
* @desc Genera la información para mostrar la Sindicación
* @param int Limite de resultados
* @return Array
*/
function &mywords_rssshow($limit)
{
    global $util, $mc;
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    include_once XOOPS_ROOT_PATH . '/modules/mywords/class/mwcategory.class.php';
    include_once XOOPS_ROOT_PATH . '/modules/mywords/class/mwpost.class.php';
    foreach ($_GET as $k => $v) {
        ${$k} = $v;
    }
    $feed = array();
    // Información General
    $ret = array();
    $mc =& $util->moduleConfig('mywords');
    if ($show == 'all') {
        $feed['title'] = htmlspecialchars(_MI_MW_RSSNAME);
        $feed['link'] = XOOPS_URL . '/modules/mywords';
        $feed['description'] = htmlspecialchars($util->filterTags($mc['rssdesc']));
        $sql = "SELECT * FROM " . $db->prefix("mw_posts") . " WHERE aprovado='1' AND estado>'0' ORDER BY modificado DESC LIMIT 0,{$limit}";
    } else {
        if ($id == '') {
            return;
        }
        $cat = new MWCategory($id);
        if ($cat->isNew()) {
            return;
        }
        $feed['title'] = sprintf(_MI_MW_RSSNAMECAT, $cat->getName());
        $feed['link'] = $cat->getLink();
        $feed['description'] = $cat->getDescription();
        $sql = "SELECT b.* FROM " . $db->prefix("mw_catpost") . " a," . $db->prefix("mw_posts") . " b WHERE a.cat='" . $cat->getID() . "' AND b.id_post=a.post AND b.aprovado='1' AND b.estado>'0' ORDER BY b.modificado DESC LIMIT 0,{$limit}";
    }
    // Generamos los elementos
    $result = $db->query($sql);
    $posts = array();
    while ($row = $db->fetchArray($result)) {
        $post = new MWPost();
        $post->assignVars($row);
        $rtn = array();
        $rtn['title'] = $post->getTitle();
        $rtn['link'] = $post->getPermaLink();
        $rtn['description'] = xoops_utf8_encode(htmlspecialchars($post->getHomeText(), ENT_QUOTES));
        $rtn['pubDate'] = formatTimestamp($post->getDate());
        $posts[] = $rtn;
    }
    $ret = array('feed' => $feed, 'items' => $posts);
    return $ret;
}
예제 #9
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']);
 }
예제 #10
0
        $idp = 0;
        # ID de la categoria padre
        foreach ($path as $k) {
            if ($k == '') {
                continue;
            }
            $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
 */