示例#1
0
def updateBlogXML(ident):
    from plugin import GENERIC_POST_LINK
    rss_file = "blog_%s.xml" % converters.makeLinkAble(ident)
    rss_items = []

    page_obj = CMSModel.Pages.getPageById(amiweb.session().get(
        'current_page_id', 1))

    def filterContent(text):
        return getFormatManager().htmlFormat(text, False, True, page_obj)

    for item in BlogModel.getAllPosts(ident, 10):
        if item.isPublished():
            item_content = filterContent(item.content)
            link = "%s/%s" % (getConfig().BASE_URL,
                              GENERIC_POST_LINK % item.id)
            rss_items.append(
                PyRSS2Gen.RSSItem(title=item.title,
                                  link=link,
                                  guid=link,
                                  description="%s" % item_content,
                                  pubDate=item.posted))

    host_page = CMSModel.Pages.getPageById(
        BlogModel.getBlogByIdent(ident).host_page)
    link = "%s/%s" % (getConfig().BASE_URL, host_page.getFullLink())

    rss_obj = PyRSS2Gen.RSS2(title=ident,
                             link=link,
                             description="",
                             lastBuildDate=datetime.datetime.now(),
                             items=rss_items)

    getRSSManager().publish(rss_file, rss_obj)
示例#2
0
    def _genMySqlLogin(self):
        if getConfig().DB_PASSWORD != "":
            password = "******" % getConfig().DB_PASSWORD
        else:
            password = ""

        return "-h %s -u %s %s %s" %\
            (getConfig().DB_HOST, getConfig().DB_USER, password, getConfig().DB_DATABASE)
示例#3
0
    def addComment(self, author, email, website, content, post_id):
        #Check captcha
        m = md5.new()
        m.update(content)
        hash_val = m.hexdigest()
        if hash_val != session().get('captcha_ok_for'):
            raise Exception('Wrong captcha check')
        else:
            del session()['captcha_ok_for']

        if website != '' and website.find("http://") != 0:
            website = "http://%s" % (website)

        #Strip scripts, style and meta
        content = re.sub('<(script|meta|style)(.|\s)*?>(.|\s)*?</(script|meta|style)>', '', content)

        #Check for same URL's posted
        try:
            self.checkURLSpam(author, content)
        except SpamComment:
            return '<p><b style="background-color: #ffffcc; color: red">Your comment was marked as spam.</b>, but will be readded if it isn\'t.</p>'

        self._expireCache(post_id)
        id = BlogCommentModel.add(author, email, website, content, post_id)
        email_data = {
            'title': 'An comment has been posted',
            'author': author,
            'email': email,
            'website': website,
            'content': content,
            'delete_link': self._getDeleteURL(id),
            'post_id': self._getCommentURL(post_id, id)
        }

        #Send a notification email
        if hasattr(getConfig(), 'DEFAULT_EMAIL'):
            text = """%(title)s

Author: %(author)s
Email: %(email)s
Website: %(website)s
Post link: %(post_id)s

Content:
%(content)s



Delete link: %(delete_link)s
""" % email_data
            mail = getConfig().DEFAULT_EMAIL
            getMailManager().sendEmail(mail, [mail], '[Skeletonz] %s' % email_data['title'], text)

        if id:
            return renderComment(BlogCommentModel.getById(id), True, False)
        else:
            return '<p><b style="background-color: #ffffcc; color: red">Your comment was marked as spam.</b>, but will be readded if it isn\'t.</p>'
示例#4
0
    def restoreDatabase(self, filename):
        #Be sure that it's the same prefix!
        fp = open(self._getFile(filename), "r")
        prefix = fp.readline().replace(prefix_comment, '').strip()

        if prefix != getConfig().TABLE_PREFIX:
            raise Exception('Backup prefix does not match current. Current prefix: "%s". Backup prefix: "%s"' % \
                (getConfig().TABLE_PREFIX, prefix))

        self._dropDBManual()
        self._runSQLFile(filename)
示例#5
0
    def __init__(self, prefix):
        self.prefix = prefix
        #print "[header] Truncator: getConfig().BASE_URL"
        self.rel_template = '%s/static/' % getConfig().CURRENT_TEMPLATE.NAME
        self.path_template = "%s/templates/%s/static/" % (
            os.getcwd(), getConfig().CURRENT_TEMPLATE.NAME)
        self.path_static_core = "%s/skeletonz/static/" % os.getcwd()
        self.path_static_template = "%s/%s/static/" % (
            os.getcwd(), getConfig().CURRENT_TEMPLATE.NAME)

        self.memo_css = {}
        self.memo_js = {}
示例#6
0
    def buildList(self, l, static_l, type):
        """
        Looks through the list to see if the static files have been updated/created
        If they have, we build a new cache
        If not, we return the cached version
        """
        is_updated = True
        new_memo = {}

        for url in l:
            new_memo[url] = date.today()
            """
            last_modif = os.stat(self.getRelative(url)).st_mtime
            if type == "css":
                v = self.memo_css.pop(url, None)
            elif type == "js":
                v = self.memo_js.pop(url, None)
            #print "%s == %s" % (last_modif, v)
            if v == None or v < last_modif:
                is_updated = False

            #Update new_memo
            new_memo[url] = last_modif
	    """

        if type == "css":
            file = "%s/%s/%s_styles.css" % (os.getcwd(), generated_dir,
                                            self.prefix)
            self.memo_css = new_memo
        elif type == "js":
            file = "%s/%s/%s_scripts.js" % (os.getcwd(), generated_dir,
                                            self.prefix)
            self.memo_js = new_memo

        if not is_updated:
            r_list = self.getRelativeList(l)
            truncator.minify(r_list, static_l, file)

        if type == "css":
            return [
                "%s/generated/%s_styles.css" %
                (getConfig().BASE_URL, self.prefix)
            ]
        elif type == "js":
            return [
                "%s/generated/%s_scripts.js" %
                (getConfig().BASE_URL, self.prefix)
            ]
示例#7
0
 def __call__(self, environ, start_response):
     path = environ['PATH_INFO']
     if path.find("/admin/") == 0:
         session = environ['beaker.session']
         if session.get('admin_logged_in', False) == False:
             raise httpexceptions.HTTPFound("%s/login/" % (getConfig().BASE_URL))
     return self.wsgi_app(environ, start_response)
示例#8
0
    def uploadFile(self, file, ident, ftype, id=0, linkonly=0):
        bdata = ""

        for l in file.file.readlines():
            bdata += l

        filename = file.filename.split("\\")
        filename = filename[-1:][0]

        ns = {
            'site': self,
            'BASE_URL': getConfig().BASE_URL,
            'ident': ident,
            'id': id,
            'filename': filename,
            'ident_id': makeLinkAble(ident),
            'linkonly': linkonly,
            'ftype': ftype
        }

        ns['data'] = bdata

        if model.Files.countFilesWithFilename(filename):
            ns['new_filename'] = model.Files.newFilename(filename)
            amiweb.session()['upload_ns'] = ns
            return render(
                "skeletonz/plugins/upload/view/upload_already_found.tmpl", ns)

        return self.uploadComplete(ns)
示例#9
0
    def _appendGlobalStyle(self):
        self.header.appendScript(
            '%s/static_core/scripts/general/indicator.js' %
            getConfig().BASE_URL)

        self.header.appendStaticCoreStyle("/styles/action_links.css")
        self.header.appendStaticCoreStyle("/admin/styles/gui.css")
        self.header.appendStaticCoreStyle("/admin/styles/content.css")
示例#10
0
    def appendFilter(self, edit_mode, **kv):
        #Extra arguments can be sent and they will be visible from the templates
        ident = self.args[self.type]
        #Link
        link = self.args.get("link", None)
        #Hidden
        hidden = self.args.get("hidden", None)

        ident_id = makeLinkAble(ident)

        cur_page_id = self.current_page
        if self.args.has_key('global'):
            cur_page_id = None

        obj = self.get_obj(ident, self.f_type, cur_page_id)

        #Set template namespace
        ns = {'BASE_URL': getConfig().BASE_URL,
              'ident_id': ident_id,
              'ident': ident}

        try: ns['obj'] = obj
        except: pass

        #Append extra
        for k in kv.keys():
            ns[k] = kv[k]

        if link:
            ns['LINK_START'] = '<a href="%s">' % (link)
            ns['LINK_END'] = '</a>'
        else:
            ns['LINK_START'] = ''
            ns['LINK_END'] = ''

        if self.args.has_key('align'):
            ns['LINK_START'] = '<div style="float: %s">%s' % (self.args['align'], ns['LINK_START'])
            ns['LINK_END'] = '%s</div>' % (ns['LINK_END'])

        if edit_mode == True:
            if obj == None:
                replacer = render(self.tmpl_upload_new, ns, True)
            else:
                replacer = render(self.tmpl_upload_edit, ns, True)
        else:
            if obj == None:
                replacer = render(self.tmpl_view_not_created, ns, True)
            else:
                if link:
                    if link == "linkonly":
                        replacer = render('$obj.getFilename()', ns, True)
                    else:
                        replacer = render(self.tmpl_view, ns, True)
                elif hidden:
                    replacer = ""
                else:
                    replacer = render(self.tmpl_view, ns, True)
        return "%s" % replacer
示例#11
0
def getPageLinkHTML(ident, edit_mode, section, only_form):
    from skeletonz.model import CMSModel as Model
    from skeletonz.Site import Users
    import skeletonz.model.visit as visit

    page_link = Model.PageLinks.getPageLinkByIdent(ident)
    #If it is None, then it's not created yet!
    if page_link == None:
        page_link = Model.PageLinks.createPageLink(ident)

    url = getConfig().BASE_URL
    if edit_mode:
        url = '%s/siteedit' % getConfig().BASE_URL

    js_update = "EC_Pagelink.update"

    if edit_mode:
        site_map = visit.getSitemap()
        form = visit.createOptions(page_link.getPage(), site_map, page_link.id,
                                   js_update)
        if only_form:
            return r'%s' % visit.createOptions(page_link.getPage(), site_map,
                                               page_link.id, js_update)
        else:
            if page_link.getPage() == None:
                return r'<span class="page_link_action"><a href="#">$normal_view</a></span> $edit_view %s' %\
                        (form)
            else:
                p_url = page_link.getPage().getFullLink()
                if section != None:
                    p_url = "%s#%s" % (p_url, section)

                return r'<span class="page_link_action"><a href="%s/%s">$normal_view</a></span> $edit_view %s' %\
                    (url, p_url, visit.createOptions(page_link.getPage(), site_map, page_link.id, js_update))
    else:
        if page_link.getPage() == None:
            #The page still does not have a reference
            return r'<span class="CMS_NotCreated">$normal_view</span>'
        else:
            page_link = page_link.getPage().getFullLink()
            if section is None:
                return r'<a href="%s/%s">$normal_view</a>' % (url, page_link)
            else:
                return r'<a href="%s/%s#%s">$normal_view</a>' % (
                    url, page_link, section)
示例#12
0
    def dumpTable(self, table_name):
        result = []
        mysqldump = getattr(getConfig(), "MYSQL_DUMP", None) or "mysqldump"
        dumpcmd = "%s -c %s %s" % \
          (mysqldump, self._genMySqlLogin(), table_name)

        data = os.popen(dumpcmd, "rb").read()
        data = re.sub('DEFAULT CHARSET.*?;', "CHARACTER SET utf8;", data)
        return data
示例#13
0
 def getRelative(self, url):
     url = url.replace(getConfig().BASE_URL, "")
     if url.find("/static_core/") == 0:
         url = "%s%s" % (self.path_static_core,
                         url.replace("/static_core/", ""))
     if url.find(self.rel_template) == 0:
         url = "%s%s" % (self.path_template,
                         url.replace(self.rel_template, ""))
     #No it should be realive
     return url
示例#14
0
    def __init__(self):
        self.name = NAME

        #Set header
        self.header = modules.header.SiteHeader()
        self.header.appendStyle("%s/%s/static/styles/gui.css" %
                                (getConfig().BASE_URL, self.name))
        self.header.appendStyle("%s/%s/static/styles/content.css" %
                                (getConfig().BASE_URL, self.name))

        #Set content
        self.content = modules.content.Content()

        #Set menu
        self.menu = modules.menu.ListMenu()
        modules.sections.mapSection("cms_list_menu", self.menu.renderText)

        #Set footer
        self.footer = modules.footer.Footer()
示例#15
0
def initDatabaseIfNeeded():
    try:
        mi_control.upgradeToLatest()
    except:
        debug_info.print_info()
        raise

    if Model.Menus.getMenuByName("Standard") == None:
        menu_obj = Model.Menus.add("Standard", primary=True)
        item = Model.MenuItems.add(getConfig().START_PAGE, 1, menu_obj.id)
        amiweb.db().update("page", id=item.getPage().id, hidden=0)
示例#16
0
    def updateCache(self, page_id, new_value):
        page_id = str(page_id)
        if not getConfig().USE_CACHING:
            return new_value
        try:
            del self.pages_cached[page_id]
        except:
            pass

        self.pages_cached[page_id] = (False, new_value)
        return new_value
示例#17
0
    def __init__(self):
        super(SiteHeader, self).__init__('SiteHeader')
        self.bodyclass = ''
        self.page_obj = None
        try:
            self.title_prefix = getConfig().TITLE_PREFIX
        except:
            self.title_prefix = ''

        try:
            self.title_suffix = getConfig().TITLE_SUFFIX
        except:
            self.title_suffix = ''

        self.edit_mode = False

        self.appendStaticCoreStyle("/styles/general.css")

        #Append init and greybox styles
        self.appendStaticCoreStyle("/greybox/gb_styles.css")
        self.appendStaticCoreScript('/scripts/general/init_normal.js')
示例#18
0
    def dumpDatabase(self, filename):
        sql_dump = self.dumpTables()
        sql_dump = "%s%s\n%s" %\
            (prefix_comment, getConfig().TABLE_PREFIX, sql_dump)

        f = open(self._getFile(filename), "w")
        f.write(sql_dump)
        f.close()

        if len(sql_dump) < 500:
            print sql_dump[0:100]
            raise Exception('ERROR: Something in mysqldump went wrong!')
示例#19
0
    def showUpload(self, ftype, id=0, linkonly=0):
        file = model.Files.getFileById(id)

        ns = {
            'site': self,
            'BASE_URL': getConfig().BASE_URL,
            'file': file,
            'page_id': amiweb.session()['current_page_id'],
            'ftype': ftype,
            'linkonly': linkonly
        }
        return render("skeletonz/plugins/upload/view/upload.tmpl", ns)
示例#20
0
 def isCacheUp2Date(self, page_id):
     page_id = str(page_id)
     if not getConfig().USE_CACHING:
         return False
     #(should_do_update:bool, value)
     if self.pages_cached.get(page_id, False):
         #Check to see if we should get a new update
         if self.pages_cached[page_id][0] == False:
             return True
         else:
             return False
     else:
         return False
示例#21
0
    def checkLogin(self, username, password):
        if not getConfig().CHECK_LOGIN:
            return True

        if username == "" or password == "":
            return False

        if username == getConfig().ADMIN_USERNAME and password == getConfig(
        ).ADMIN_PASSWORD:
            return True

        user = self.getUserByUsername(username)
        if user == None:
            return False

        #If an extra function is provided then use it to check password
        internal = self.checkPassword(user, password)

        try:
            external = getConfig().PASSWORD_LOOKUP(username, password)
        except AttributeError:
            external = False

        return internal or external
示例#22
0
    def __init__(self, name):
        self.template = None  #Is set from skeletonz/server.py - markChildren

        self.styles = []
        self.scripts = []
        self.script_datas = []
        self.styles_datas = []

        self.static_script_data = []
        self.static_style_data = []

        prefix = str(self.__class__)
        prefix = prefix.replace("'>", "").split(".")[-1]

        self.truncator = Truncator(prefix)
        self.setPrefix(name)

        self.append_ajs = False

        self.sc_path = "%s/static_core" % getConfig().BASE_URL
示例#23
0
    def cacheAllPages(self):
        if not getConfig().USE_CACHING:
            return False

        #Maybe function called from a new thread
        try:
            gb = db()
        except AttributeError:
            setUpConnection()

        self.expireAllPages()

        pages = Model.Pages.getAllPages()

        cur_page = getCurrentPage()

        for page in pages:
            session()['current_page_id'] = page.id
            self.cachePage(page)

        session()['current_page_id'] = cur_page
        return "ok"
示例#24
0
    def cachePage(self, page):
        print "[amicache] Amicacher cachePage: hit the cache logic<br>"
        from skeletonz.Site import Site, renderView, getCurrentInfo

        tmpl = getConfig().CURRENT_TEMPLATE.SiteTemplate()
        tmpl.markChildren()

        site = Site(tmpl)

        getFormatManager().resetPagePlugins()

        current_info = getCurrentInfo(site.template, page.id, False)
        current_info['is_admin'] = False
        current_info['logged_in'] = False
        current_info['edit_mode'] = False
        current_info['edit_permission'] = None

        content = renderView(current_info, "site_structure")

        #Append sections to this
        content = sections.fillSections(current_info, content, page)

        self.updateCache(page.id, content)
示例#25
0
    def renderText(self):
        from skeletonz import Site
        if Site.Users.getViewEditMode() == 'off':
            self.edit_mode = False

        #Set the URL
        URL = server.getConfig().BASE_URL
        self.URL = URL

        ns = {
            'template': self.template,
            'BASE_URL': URL,
            'parent_list': self.getParentList(),
            'page_obj': self.page_obj,
            'bodyclass': self.bodyclass,
            'edit_mode': self.edit_mode,
            'edit_permission': self.edit_permission,
            'logged_in': self.logged_in,
            'appendSiteEdit': appendSiteEdit(self.logged_in)
        }
        return render(
            "templates/%s/view/%s" % (self.template.getName(), self.file_name),
            ns)
示例#26
0
 def fn(x):
     if x.find(getConfig().TABLE_PREFIX) == 0:
         return True
     else:
         return False
示例#27
0
 def expireCache(self, page_id):
     page_id = str(page_id)
     if not getConfig().USE_CACHING:
         return False
     self.pages_cached[page_id] = (True, None)
示例#28
0
 def __init__(self):
     self.table_prefix = getConfig().TABLE_PREFIX
示例#29
0
 def expireCurrentPage(self):
     if not getConfig().USE_CACHING:
         return False
     page_id = session()['current_page_id']
     self.expireCache(page_id)
示例#30
0
 def getValue(self, page_id):
     page_id = str(page_id)
     if not getConfig().USE_CACHING:
         return False
     return self.pages_cached[page_id][1]