/src/install/z_install_defaultdata.erl

http://github.com/zotonic/zotonic · Erlang · 186 lines · 131 code · 27 blank · 28 comment · 2 complexity · 72a62c9f963f5cf889a0a281d3dd27be MD5 · raw file

  1. %% @author Arjan Scherpenisse <arjan@scherpenisse.net>
  2. %% @copyright 2011 Arjan Scherpenisse
  3. %%
  4. %% @doc Installs default data in a Zotonic site.
  5. %% Copyright 2011 Arjan Scherpenisse
  6. %%
  7. %% Licensed under the Apache License, Version 2.0 (the "License");
  8. %% you may not use this file except in compliance with the License.
  9. %% You may obtain a copy of the License at
  10. %%
  11. %% http://www.apache.org/licenses/LICENSE-2.0
  12. %%
  13. %% Unless required by applicable law or agreed to in writing, software
  14. %% distributed under the License is distributed on an "AS IS" BASIS,
  15. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. %% See the License for the specific language governing permissions and
  17. %% limitations under the License.
  18. -module(z_install_defaultdata).
  19. -author("Arjan Scherpenisse <arjan@scherpenisse.net>").
  20. -include("zotonic.hrl").
  21. %% interface functions
  22. -export([
  23. install/2,
  24. default_menu/1
  25. ]).
  26. install(basesite, Context) ->
  27. Datamodel = #datamodel{
  28. resources =
  29. [
  30. {page_home,
  31. text,
  32. [{title, <<"Home">>},
  33. {summary, <<"Welcome to your new site!">>},
  34. {page_path, <<"/">>}]
  35. }
  36. ]
  37. },
  38. ?DEBUG("Installing basesite data"),
  39. z_datamodel:manage(?MODULE, Datamodel, Context);
  40. install(blog, Context) ->
  41. Now = {{2012,12,14},{9,12,0}},
  42. Datamodel =
  43. #datamodel{
  44. resources =
  45. [
  46. %% MENU ENTRIES
  47. {page_home,
  48. text,
  49. [{title, <<"Home">>},
  50. {summary, <<"Welcome to your blog!">>},
  51. {page_path, <<"/">>}]
  52. },
  53. {page_about,
  54. text,
  55. [{title, <<"About this blog">>},
  56. {summary, <<"This is your blog!! It would be wise to type some text here on what you will be writing about. Of course, this page is just a demo page and can be deleted just as well.">>}]
  57. },
  58. {page_contact,
  59. text,
  60. [{title, <<"Contact">>},
  61. {summary, <<"Get in contact with us! Use the form below to send this site's administrator some feedback on how you perceive this site.">>},
  62. {page_path, <<"/contact">>}]
  63. },
  64. %% BLOG ENTRIES
  65. {blog_article_welcome,
  66. article,
  67. [{title, <<"Welcome to Zotonic!">>},
  68. {publication_start, Now},
  69. {summary, <<"Zotonic is the content management system for people that want a fast, extensible, flexible and complete system for dynamic web sites. It is built from the ground up with rich internet applications and web publishing in mind.">>},
  70. {body, {file, datafile(blog, "welcome.html")}}
  71. ]
  72. },
  73. {blog_article_learnmore,
  74. article,
  75. [{title, <<"Want to learn more?">>},
  76. {publication_start, z_datetime:prev_day(Now)},
  77. {summary, <<"This blog website you're looking demonstrates only a small part of what you can do with a Zotonic site. For instance, did you know that sending mass-mailings is a builtin module? That it does OAuth out of the box? That Zotonic sites are SEO optimized by default?">>},
  78. {body, {file, datafile(blog, "learnmore.html")}}
  79. ]
  80. },
  81. {blog_article_demo,
  82. article,
  83. [{title, <<"Zotonic's Typography">>},
  84. {publication_start, z_datetime:prev_month(Now)},
  85. {summary, <<"This article demonstrates the typographic features that Zotonic has. It shows creating ordered and unordered lists, blockquotes, and different methods of embedding media, even even showing an embedded video from Vimeo.com.">>},
  86. {body, {file, datafile(blog, "demo.html")}}
  87. ]
  88. },
  89. %% KEYWORDS
  90. {kw_announcement,
  91. keyword,
  92. [{title, <<"Announcement">>}]
  93. },
  94. {kw_technical,
  95. keyword,
  96. [{title, <<"Technical">>}]
  97. },
  98. {kw_support,
  99. keyword,
  100. [{title, <<"Support">>}]
  101. }
  102. ],
  103. media =
  104. [
  105. {media_learning,
  106. datafile(blog, "learning.jpg"),
  107. [{title, <<"A bunch of computer books">>},
  108. {summary, <<"Taken by Sibi from Flickr, licensed Attribution-Noncommercial-No Derivative Works 2.0.">>}]
  109. },
  110. {media_welcome,
  111. datafile(blog, "welcome.jpg"),
  112. [{title, <<"Rocky sunrise">>},
  113. {summary, <<"Taken by Grant MacDonald from Flickr, CC licensed Attribution-Noncommercial 2.0.">>}]
  114. },
  115. {media_video,
  116. [{title, <<"Zotonic introduction video">>},
  117. {oembed_url, <<"http://vimeo.com/7630916">>}]
  118. }
  119. ],
  120. edges =
  121. [
  122. {blog_article_learnmore, author, administrator},
  123. {blog_article_welcome, author, administrator},
  124. {blog_article_demo, author, administrator},
  125. {blog_article_learnmore, subject, kw_support},
  126. {blog_article_demo, subject, kw_technical},
  127. {blog_article_welcome, subject, kw_support},
  128. {blog_article_welcome, subject, kw_announcement},
  129. {blog_article_welcome, depiction, media_welcome},
  130. {blog_article_learnmore, depiction, media_learning},
  131. {blog_article_demo, depiction, media_welcome}
  132. ]
  133. },
  134. ?DEBUG("Installing blog data"),
  135. z_datamodel:manage(?MODULE, Datamodel, Context);
  136. install(_, _) ->
  137. %% no/unknown skeleton = no default data
  138. ok.
  139. %% @doc Retrieve the default menu structure for a given site. Used by mod_menu to create the menu.
  140. %% The menu can be defined in the site config file as a list of menu items under the key <tt>install_menu</tt>.
  141. %% If that is not defined, a default menu for the skeleton is used, if any.
  142. -spec default_menu(#context{}) -> MenuItems | undefined when
  143. MenuItems :: [MenuItem],
  144. MenuItem :: {PageName, MenuItems},
  145. PageName :: atom().
  146. default_menu(Context) ->
  147. case m_site:get(install_menu, Context) of
  148. Menu when is_list(Menu) -> Menu;
  149. _ -> default_skeleton_menu(m_site:get(skeleton, Context))
  150. end.
  151. default_skeleton_menu(blog) ->
  152. [{page_home, []}, {page_about, []}, {page_contact, []}];
  153. default_skeleton_menu(_) ->
  154. %% no/unknown skeleton = no default menu
  155. undefined.
  156. %% @doc Helper function for getting an absolute path to a data file
  157. %% that is part of the default data for a site skeleton.
  158. datafile(Skeleton, Filename) ->
  159. filename:join([z_utils:lib_dir(priv), "install", Skeleton, Filename]).