def get_posts(pageno, keyword=None): c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `status`=1 " %(util.tab('content')) where_c = '`status`=1' if keyword is not None: c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `status`=1 and `title` like '%%%s%%'" %(util.tab('content'), keyword) where_c = "`status`=1 and `title` like '%%%s%%'" % (keyword) results = db.query(c_sql) count = results[0].cid pageDict = util.get_page_dict(pageno, count) return (db.select(util.tab('content'),where=where_c, order='`id` DESC', limit=pageDict['pagesize'], offset=pageDict['start']), pageDict )
def get_admin_posts(pageno, keyword=None): c_sql = "SELECT COUNT(`id`) AS cid FROM `%s`" %(util.tab('content')) where_c = '1=1' if keyword is not None and keyword <> '': c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `title` like '%%%s%%' or `createtime` like '%%%s%%' or `modifytime` like '%%%s%%'"\ %(util.tab('content'), keyword, keyword, keyword) where_c = "`title` like '%%%s%%' or `createtime` like '%%%s%%' or `modifytime` like '%%%s%%'" % (keyword, keyword, keyword) results = db.query(c_sql) count = results[0].cid pageDict = util.get_page_dict(pageno, count, conf.page_admin_size) return (db.select(util.tab('content'),where=where_c, order='`id` DESC', limit=pageDict['pagesize'], offset=pageDict['start']), pageDict )
def get_posts_by_tag(tagid, pageno): myvars = dict(tid=tagid) tags = db.select(util.tab('metas'), myvars, where="`id`=$tid") tag = None if tags is not None and len(tags) > 0: tag = tags[0] results = db.query("SELECT COUNT(`cid`) AS countc FROM `%s` where `mid`='%d'" %(util.tab('rel'), tag.id)) if results is not None and len(results) > 0: countc = results[0].countc pageDict = util.get_page_dict(pageno, countc) rels = db.select(util.tab('rel'),myvars, where="`mid`=$tid", order='`cid` DESC', limit=pageDict['pagesize'], offset=pageDict['start']) cids = [] for rel in rels: cids.append(str(rel.cid)) cids = ",".join(cids) return (db.select(util.tab('content'), where="`status`=1 and `id` in (%s)" %(cids), order='`id` DESC', limit=pageDict['pagesize'], offset=pageDict['start']),pageDict,tag ) return ([], None, tag) count = results[0].cid pageDict = util.get_page_dict(pageno, count) return (db.select(util.tab('content'), where="`status`=1", order='`id` DESC', limit=pageDict['pagesize'], offset=pageDict['start']),pageDict, tag )
def get_posts_by_createtime(pageno, date=None, month=None, year=None, arch=None): c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `status`=1" %(util.tab('content')) where_c = '`status`=1' if date is not None: c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `status`=1 and DATE_FORMAT(createtime, '%%d')='%s'" %(util.tab('content'), date) where_c = "`status`=1 and DATE_FORMAT(createtime, '%%d')='%s' " % (date) elif month is not None: c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `status`=1 and DATE_FORMAT(createtime, '%%m')='%s'" %(util.tab('content'), month) where_c = "`status`=1 and DATE_FORMAT(createtime, '%%m')='%s' " % (month) elif year is not None: c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `status`=1 and DATE_FORMAT(createtime, '%%Y')='%s'" %(util.tab('content'), year) where_c = "`status`=1 and DATE_FORMAT(createtime, '%%Y')='%s' " % (year) elif arch is not None: c_sql = "SELECT COUNT(`id`) AS cid FROM `%s` where `status`=1 and DATE_FORMAT(createtime, '%%Y-%%m')='%s'" %(util.tab('content'), arch) where_c = "`status`=1 and DATE_FORMAT(createtime, '%%Y-%%m')='%s' " % (arch) results = db.query(c_sql) count = results[0].cid pageDict = util.get_page_dict(pageno, count) return (db.select(util.tab('content'),where=where_c, order='`id` DESC', limit=pageDict['pagesize'], offset=pageDict['start']), pageDict )