comparison libervia/backend/plugins/plugin_misc_static_blog.py @ 4071:4b842c1fb686

refactoring: renamed `sat` package to `libervia.backend`
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 11:49:51 +0200
parents sat/plugins/plugin_misc_static_blog.py@524856bd7b19
children
comparison
equal deleted inserted replaced
4070:d10748475025 4071:4b842c1fb686
1 #!/usr/bin/env python3
2
3
4 # SAT plugin for static blogs
5 # Copyright (C) 2014 Adrien Cossa (souliane@mailoo.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 from libervia.backend.core.log import getLogger
21
22 log = getLogger(__name__)
23
24 from libervia.backend.core.i18n import _, D_
25 from libervia.backend.core.constants import Const as C
26 from libervia.backend.core import exceptions
27 from libervia.backend.tools import xml_tools
28
29 from twisted.internet import defer
30 from twisted.words.protocols.jabber import jid
31
32
33 PLUGIN_INFO = {
34 C.PI_NAME: "Static Blog Plugin",
35 C.PI_IMPORT_NAME: "STATIC-BLOG",
36 C.PI_TYPE: "MISC",
37 C.PI_PROTOCOLS: [],
38 C.PI_DEPENDENCIES: [],
39 C.PI_RECOMMENDATIONS: [
40 "MISC-ACCOUNT"
41 ], # TODO: remove when all blogs can be retrieved
42 C.PI_MAIN: "StaticBlog",
43 C.PI_HANDLER: "no",
44 C.PI_DESCRIPTION: _("""Plugin for static blogs"""),
45 }
46
47
48 class StaticBlog(object):
49
50 params = """
51 <params>
52 <individual>
53 <category name="{category_name}" label="{category_label}">
54 <param name="{title_name}" label="{title_label}" value="" type="string" security="0"/>
55 <param name="{banner_name}" label="{banner_label}" value="" type="string" security="0"/>
56 <param name="{background_name}" label="{background_label}" value ="" type="string" security="0"/>
57 <param name="{keywords_name}" label="{keywords_label}" value="" type="string" security="0"/>
58 <param name="{description_name}" label="{description_label}" value="" type="string" security="0"/>
59 </category>
60 </individual>
61 </params>
62 """.format(
63 category_name=C.STATIC_BLOG_KEY,
64 category_label=D_(C.STATIC_BLOG_KEY),
65 title_name=C.STATIC_BLOG_PARAM_TITLE,
66 title_label=D_("Page title"),
67 banner_name=C.STATIC_BLOG_PARAM_BANNER,
68 banner_label=D_("Banner URL"),
69 background_name="Background",
70 background_label=D_("Background image URL"),
71 keywords_name=C.STATIC_BLOG_PARAM_KEYWORDS,
72 keywords_label=D_("Keywords"),
73 description_name=C.STATIC_BLOG_PARAM_DESCRIPTION,
74 description_label=D_("Description"),
75 )
76
77 def __init__(self, host):
78 try: # TODO: remove this attribute when all blogs can be retrieved
79 self.domain = host.plugins["MISC-ACCOUNT"].account_domain_new_get()
80 except KeyError:
81 self.domain = None
82 host.memory.update_params(self.params)
83 # host.import_menu((D_("User"), D_("Public blog")), self._display_public_blog, security_limit=1, help_string=D_("Display public blog page"), type_=C.MENU_JID_CONTEXT)
84
85 def _display_public_blog(self, menu_data, profile):
86 """Check if the blog can be displayed and answer the frontend.
87
88 @param menu_data: %(menu_data)s
89 @param profile: %(doc_profile)s
90 @return: dict
91 """
92 # FIXME: "public_blog" key has been removed
93 # TODO: replace this with a more generic widget call with URIs
94 try:
95 user_jid = jid.JID(menu_data["jid"])
96 except KeyError:
97 log.error(_("jid key is not present !"))
98 return defer.fail(exceptions.DataError)
99
100 # TODO: remove this check when all blogs can be retrieved
101 if self.domain and user_jid.host != self.domain:
102 info_ui = xml_tools.XMLUI("popup", title=D_("Not available"))
103 info_ui.addText(
104 D_("Retrieving a blog from an external domain is not implemented yet.")
105 )
106 return {"xmlui": info_ui.toXml()}
107
108 return {"public_blog": user_jid.userhost()}