CMS  Version 3.9
blog_manager.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::using("component", "versioned_content");
40 
42 {
44  {
45  }
46 
47 
48  function export()
49  {
50  $xml = "\n<ArticleMap>";
51  $xml .= SerializationManager::serialize(Article, "ORDER BY article_id");
52  $xml .= SerializationManager::serialize(Blog, "ORDER BY blog_id");
53  $xml .= "</ArticleMap>";
54 
55  return $xml;
56  }
57 
58  function import($doc, $tx)
59  {
62  }
63 }
64 
66 {
67  static function displayBlog($identifier, &$continue)
68  {
69  try
70  {
71  trace("Searching for blog with identifier '$identifier'", 2);
73  $page = ComponentPage::findByIdentifier("blog", "WHERE enabled=1");
74  $_GET["blog"] = $identifier;
75 
76  $pageView = new ComponentPageView($page, "{$page->template}.tpl");
77 
78  $page_role = $page->role;
79 
80  if (!checkRole($page->role))
81  {
83  redirect("/login");
84  }
85 
86  echo $pageView->drawView();
87 
88  $continue = false;
89  }
90  catch(DataNotFoundException $e)
91  {
92 
93  }
94 
95  return $identifier;
96  }
97 
98  static function inlineEditingControls($blog)
99  {
100 
101  if (Settings::getValue("settings", "enable_inline_editing") && Settings::checkPermission("settings", "editor_roles"))
102  {
103  echo "<p id='inline_editing'><a href='#' onclick='new BlogManager().editBlog({$blog->blog_id}); return false;'>Edit</a>&nbsp;&nbsp;<a href='#' onclick='new ArticleManager().editArticle(\"\", {$blog->blog_id}); return false;'>Add an Article</a></p>";
104  }
105  }
106 
107  static function enumerateItems($items)
108  {
109  $blogs = Query::create(Blog, "ORDER BY title")->execute();
110 
111  $items["Blogs"] = $blogs;
112  return $items;
113  }
114 
115 
116  static function registerSearchables($searchables)
117  {
118  trace("BlogManager registerSearchables", 3);
119  $searchables["blog"] = array(Blog);
120  return $searchables;
121  }
122 
123  static function registerSolrAdapter()
124  {
125  SolrManager::registerSolrAdapter(Blog, new BlogSolrAdapter());
126  }
127 
128 
130  {
131  $form = new AutoForm($blog);
132  $form->hide("owner_id", "created_date");
133  $form->button("Cancel", $redirect);
134 
135  $blogTypes = array_keys($blogView->handlers);
136  $blogTypes = array_combine($blogTypes, $blogTypes);
137 
138  $orderSelect = new SelectFieldRenderer($form, "default_article_order", "Default Article Order", array("DESC" => "Newest to Oldest", "ASC" => "Oldest to Newest", "SORT" => "Sorted Order"));
139  $readSelect = new CheckListFieldRenderer($form, "read_access", "Read Access", SiteRole::getRolesArray());
140  $readSelect->setSize(350, 150, 10);
141  $writeSelect = new CheckListFieldRenderer($form, "write_access", "Write Access", SiteRole::getRolesArray());
142  $writeSelect->setSize(350, 150, 10);
143  $typeSelect = new SelectFieldRenderer($form, "blog_type", "Blog Type", $blogTypes);
144  $imageSelect = new ImageSelectFieldRenderer($form, "image_id", false);
145  $form->alias("image_id", "Image");
146  $form->alias("enable_rss_feed", "Enable RSS Feed");
147  $form->alias("max_rss_articles", "Max # of Articles in RSS Feed");
148  $form->annotate("max_rss_articles", "(A value of zero means no limit)");
149 
150 
152 
153  return $form;
154  }
155 
156  static function blogTabs($blog_id)
157  {
158  $tabs = array(
159  "Blog Definition" => "blog_form",
160  "Articles" => "blog_articles"
161  );
162 
163  $bar = new TabBar("tabs", $tabs, "blog_id=$blog_id");
164 
165  return $bar;
166  }
167 
169  {
170  $form = new AutoForm($article);
171  $form->required("title");
172  $form->allowDelete = true;
173  $redirect = "/admin/blog_articles?blog_id={$blog->blog_id}";
174  $form->button("Cancel", $redirect);
175  $imageSelect = new ImageSelectFieldRenderer($form, "image_id");
176  $form->alias("image_id", "Associated Image");
177  $form->readonly("created_date");
178  $form->hide("author_id"); //TODO - allow author selection/re-assignment?
179  $form->hide("article_type");
180 
181  $sites = query(Site, "ORDER BY site_name");
182  $siteSelect = new CrossReferenceSelectFieldRenderer($form, "sites", "Sites", $sites, "site_name", ArticleSiteXref);
183 
184  $form->getRenderer("archive_date")->validator->required = false;
185 
186  return $form;
187  }
188 
189  static function getStyles()
190  {
191  $styles .= "<link href=\"/fakoli/css/tabs.css\" rel=\"stylesheet\"/>\n";
192 
193  return $styles;
194  }
195 
196  static function upgradeComponent($version)
197  {
198  $mgr = new BlogUpgradeManager();
199  $mgr->upgrade($version);
200  }
201 
202  static function setDefaults()
203  {
204  Settings::setDefaultValue("blog", "allow_subscription_options", "0", Boolean, "Whether to allow users to choose subscription type options. Cron job must be setup for the website to call handler file 'send_digest'.");
205  Settings::setDefaultValue("blog", "weekly_digest_day", "Mon", String, "The day of the week when the weekly digest will be sent for sites that allow that option.", "", "Sun\nMon\nTue\nWed\nThu\nFri\nSat");
206  Settings::setDefaultValue("blog", "subscribe_button_format", "Subscribe to {title}", String, "Format string to use for subscribe buttons");
207  Settings::setDefaultValue("blog", "enable_extended_subscription_fields", false, Boolean, "Ask subscribers for their name and organization when subscribing");
208 
211  }
212 
219  static function setDefaultEmailTemplates()
220  {
221  global $config;
222 
223  $sitename = $config["sitename"];
224 
225  $message = "This is an automated message from {$sitename}. You have successfully subscribed to the {Blog.title}.<br><br>To unsubscribe, <a href='{getUnsubscribeUrl()}'>click here</a> or follow this link: {getUnsubscribeUrl()}.";
226  EmailTemplate::setDefaultTemplate("blog_subscription", "{subscriber_email}", "{$sitename} Blog Subscription: {Blog.title}", $message, "BlogSubscriber");
227 
228  $message = "Greetings. This is an automated message from {$sitename}. A new post has been published on {Blog.title}. Click the link below to read it.<br><br>{getBlogUrl()}?article_id=[article_id]<br><br>You are receiving this message because you subscribed to {Blog.title}. To unsubscribe, please follow this link: {getUnsubscribeUrl()}";
229  EmailTemplate::setDefaultTemplate("blog_published", "{subscriber_email}", "{$sitename} post: {Blog.title}", $message, "BlogSubscriber");
230 
231  $message = "This is an automated message from {$sitename}. You have successfully unsubscribed to the {Blog.title}.";
232  EmailTemplate::setDefaultTemplate("blog_unsubscribe_confirmation", "{subscriber_email}", "{$sitename} Blog Subscription: {Blog.title}", $message, "BlogSubscriber");
233 
234  }
235 
245  static function setDefaultMergeCodes()
246  {
247  MergeCode::setDefaultMergeCode("blog_title", "Blog.title", "BlogSubscriber", "Blog Title");
248  MergeCode::setDefaultMergeCode("article_id", "", "BlogSubscriber", "ID of the article whose publication is the cause of the subscriber email being sent. This value is provided in the calling code b/c it can't be accessed through the blog subscriber.");
249  MergeCode::setDefaultMergeCode("blog_identifier", "Blog.identifier", "BlogSubscriber", "The CMS page identifier of the blog.");
250  MergeCode::setDefaultMergeCode("unsubscribe_url", "getUnsubscribeUrl", "BlogSubscriber", "The url to unsubscribe from a blog.");
251  MergeCode::setDefaultMergeCode("blog_url", "getBlogUrl", "BlogSubscriber", "The url to view blog posts.");
252  }
253 
255  {
256  $classes[] = Blog;
257  return $classes;
258  }
259 
260  static function registerVersionedContent()
261  {
263  }
264 
272  static function deleteUser($user)
273  {
274  $pk = $user->getPrimaryKey();
275  $user_id = $user->$pk;
276 
277  trace("Component blog is deleting objects dependent on user_id {$user_id}", 3);
278 
279  $blog = new Blog();
280  $blog->delete("WHERE owner_id={$user_id}");
281 
282  return $user;
283  }
284 
291  static function saveBlogSubscription($form)
292  {
293  $blogSubscriber = &$form->data;
294 
295  $subscriptions = Query::create(BlogSubscriber, "WHERE subscriber_email=:email AND blog_id=:blog_id")
296  ->bind(":email", $blogSubscriber->subscriber_email, ":blog_id", $blogSubscriber->blog_id)
297  ->execute();
298 
299  $subscription = (count($subscriptions)) ? $subscriptions[0] : null;
300 
301  if($subscription && $subscription->subscription_type != $blogSubscriber->subscription_type)
302  {
303  $subscription->subscription_type = $blogSubscriber->subscription_type;
304  $subscription->filter = new InclusionFilter("subscription_type");
305  $subscription->save();
306 
307  $form->data = $subscription;
308  }
309  else if(!$subscription)
310  {
311  if (!$blogSubscriber->subscription_token)
312  {
313  $blogSubscriber->subscription_token = BlogSubscriptionManager::generateToken();
314  }
315  $blogSubscriber->save();
316  }
317 
318  return true;
319  }
320 
321  static function sendDigests()
322  {
323  $mgr = new BlogSubscriptionManager();
324 
325  $mgr->sendDigests();
326  }
327 
329  {
330  SerializationManager::registerHandler("blog", "Articles and Blogs", new BlogSerializationHandler());
331  return true;
332  }
333 
335  {
336  ScheduledTaskManager::registerWorker("blog", "Send Digests", array(BlogManager, sendDigests));
337  }
338 }
339 ?>
$user_id
$form
$article
$redirect
$blog
$tabs
$blogView
Definition: blog_form.inc:62
$page
Definition: help.inc:39
$blog_id
Definition: edit.inc:45
Defines the Article class.
Definition: article.inc:45
Definition: article.inc:309
Definition: blog.inc:41
static findByIdentifier($identifier)
Definition: blog.inc:155
static registerSerializationHandler()
static setDefaults()
static buildBlogForm($blog, $redirect, $blogView)
static sendDigests()
static setDefaultEmailTemplates()
For blog, need default templates: blog_subscription blog_published blog_unsubscribe_confirmation.
static deleteUser($user)
Respond to fired event DeleteUser.
static buildBlogArticleForm($article, $blog)
static registerTaxonomyClasses($classes)
static displayBlog($identifier, &$continue)
static registerSolrAdapter()
static registerVersionedContent()
static registerScheduledTaskWorkers()
static enumerateItems($items)
static upgradeComponent($version)
static setDefaultMergeCodes()
Merge codes: blog_title article_id blog_identifier unsubscribe_url blog_url.
static saveBlogSubscription($form)
Custom save handlerf or blog_subscription_form.
static getStyles()
static inlineEditingControls($blog)
static registerSearchables($searchables)
static blogTabs($blog_id)
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
static setDefaultTemplate($name, $recipients, $subject, $message, $class_name, $sender_email="")
Create a default template for emails that are sent through Fakoli components (e.g....
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
Definition: login.inc:493
static setDefaultMergeCode($name, $map, $class_name, $description="")
Create a default merge codes for emails that are sent through Fakoli components (e....
Definition: merge_code.inc:58
static registerWorker($component, $task_name, $handler, $hourly=false)
Registers a Scheduled Task worker method.
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174
static checkPermission($component, $name, $account=null)
Check whether a user has a specific permission.
Definition: settings.inc:241
Definition: site.inc:40
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
Definition: role.inc:75
global $user
$sites
Definition: event_edit.inc:83
global $config
Definition: import.inc:4
$message
Definition: mail_to.inc:49
$styles
$identifier
Definition: rss.inc:37