/** * Función para realizar búsquedas */ function mywords_search($qa, $andor, $limit, $offset, $userid) { global $xoopsUser; $db = XoopsDatabaseFactory::getDatabaseConnection(); include_once XOOPS_ROOT_PATH . '/modules/mywords/class/mwpost.class.php'; $util =& RMUtilities::get(); $mc =& $util->module_config('mywords'); $sql = "SELECT * FROM " . $db->prefix("mw_posts"); $adds = ''; if (is_array($qa) && ($count = count($qa))) { $adds = ''; for ($i = 0; $i < $count; $i++) { $adds .= $adds == '' ? "(title LIKE '%{$qa[$i]}%' OR content LIKE '%{$qa[$i]}%')" : " {$andor} (title LIKE '%{$qa[$i]}%' OR content LIKE '%{$qa[$i]}%')"; } } $sql .= $adds != '' ? " WHERE " . $adds : ''; if ($userid > 0) { $sql .= ($adds != '' ? " AND " : " WHERE ") . "author='{$userid}'"; } $sql .= " ORDER BY pubdate DESC"; $i = 0; $result = $db->query($sql, $limit, $offset); $ret = array(); while ($row = $db->fetchArray($result)) { $post = new MWPost(); $post->assignVars($row); $ret[$i]['image'] = "images/post.png"; $ret[$i]['link'] = $post->permalink(); $ret[$i]['title'] = $post->getVar('title'); $ret[$i]['time'] = $post->getVar('pubdate'); $ret[$i]['uid'] = $post->getVar('author'); $ret[$i]['desc'] = substr(strip_tags($post->content()), 0, 150); $i++; } return $ret; }
/** * Elimina un artículo de la base de datos */ function deletePost() { global $xoopsSecurity; $posts = rmc_server_var($_POST, 'posts', array()); if (empty($posts)) { redirectMsg('posts.php', __('Select one post at least!', 'mywords'), 1); die; } if (!$xoopsSecurity->check()) { redirectMsg('posts.php', __('Session token expired!', 'mywords'), 1); die; } $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT * FROM " . $db->prefix("mod_mywords_posts") . " WHERE id_post IN (" . implode(",", $posts) . ")"; $result = $db->query($sql); while ($row = $db->fetchArray($result)) { $post = new MWPost(); $post->assignVars($row); if (!$post->delete()) { showMessage(sprintf(__('Errors ocurred while deleting "%s"', 'mw_categories'), $post->getVar('title')), 1); } RMFunctions::delete_comments('mywords', urlencode('post=' . $post->id())); } redirectMsg('posts.php', __('Database updated!', 'mw_categories'), 0); }
public function get_filtered_posts($where = '', $start = 0, $limit = 1, $orderby = 'pubdate', $sort = 'desc', $status = 'publish') { $path = XOOPS_ROOT_PATH . '/modules/mywords'; include_once $path . '/class/mwpost.class.php'; $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT * FROM " . $db->prefix("mw_posts"); if ($where != '') { $sql .= " WHERE {$where}"; } if ($status != '') { $sql .= $where != '' ? " AND status='{$status}'" : " WHERE status='{$status}'"; } if ($orderby != '') { $sql .= " ORDER BY {$orderby}"; } if ($sort != '') { $sql .= " {$sort}"; } $sql .= " LIMIT {$start},{$limit}"; //echo $sql; $result = $db->query($sql); $ret = array(); while ($row = $db->fetchArray($result)) { $post = new MWPost(); $post->assignVars($row); $ret[] = $post; } return $ret; }
} else { $page = $path[$srh + 1]; } } else { $page = 1; } } $post->add_read(); // Navegación entre artículos if ($xoopsModuleConfig['shownav']) { $sql = "SELECT * FROM " . $db->prefix("mw_posts") . " WHERE id_post<" . $post->id() . " AND status='publish' ORDER BY id_post DESC LIMIT 0, 1"; $result = $db->query($sql); $pn = new MWPost(); // Anterior if ($db->getRowsNum($result) > 0) { $pn->assignVars($db->fetchArray($result)); $xoopsTpl->assign('prev_post', array('link' => $pn->permalink(), 'title' => $pn->getVar('title'))); } // Siguiente $sql = "SELECT * FROM " . $db->prefix("mw_posts") . " WHERE id_post>" . $post->id() . " AND status='publish' ORDER BY id_post ASC LIMIT 0, 1"; $result = $db->query($sql); if ($db->getRowsNum($result) > 0) { $pn->assignVars($db->fetchArray($result)); $xoopsTpl->assign('next_post', array('link' => $pn->permalink(), 'title' => $pn->getVar('title'))); } } $xoopsTpl->assign('shownav', $xoopsModuleConfig['shownav']); if ($xoopsUser && ($xoopsUser->isAdmin() || $editor->getVar('uid') == $xoopsUser->uid())) { $edit = '<a href="' . XOOPS_URL . '/modules/mywords/admin/posts.php?op=edit&id=' . $post->id() . '">' . __('Edit Post', 'mywords') . '</a>'; $xoopsTpl->assign('edit_link', $edit); unset($edit);
list($numtags) = $db->fetchRow($db->query("SELECT COUNT(*) FROM " . $db->prefix("mod_mywords_tags"))); /** * @desc Caragmaos los artículos recientemente enviados */ $drafts = array(); $result = $db->query("SELECT * FROM " . $db->prefix("mod_mywords_posts") . " WHERE status='draft' ORDER BY id_post DESC LIMIT 0,5"); while ($row = $db->fetchArray($result)) { $post = new MWPost(); $post->assignVars($row); $drafts[] = $post; } $pendings = array(); $result = $db->query("SELECT * FROM " . $db->prefix("mod_mywords_posts") . " WHERE status='waiting' ORDER BY id_post DESC LIMIT 0,8"); while ($row = $db->fetchArray($result)) { $post = new MWPost(); $post->assignVars($row); $pendings[] = $post; } // Editors $sql = "SELECT *, (SELECT COUNT(*) FROM " . $db->prefix("mod_mywords_posts") . " WHERE author=id_editor) as counter FROM " . $db->prefix("mod_mywords_editors") . " ORDER BY counter DESC LIMIT 0, 5"; $result = $db->query($sql); $editors = array(); while ($row = $db->fetchArray($result)) { $editor = new MWEditor(); $editor->assignVars($row); $editors[] = array('id' => $editor->id(), 'name' => $editor->getVar('name'), 'link' => $editor->permalink(), 'total' => $row['counter']); } unset($editor, $result, $sql); // URL rewriting $rule = "RewriteRule ^" . trim($xoopsModuleConfig['basepath'], '/') . "/?(.*)\$ modules/mywords/index.php [L]"; if ($xoopsModuleConfig['permalinks'] > 1) {
/** * @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; }