CMS  Version 3.9
article_manager.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("component", "comment", "blog", "versioned_content");
8 
10 {
11  function ArticleManager()
12  {
13 
14  }
15 
16  static function buildArticleForm($article)
17  {
18  if (!$article->article_id)
19  {
20  global $user;
21 
22  $mgr = new UserManager();
23  $article->author = (method_exists($mgr, getUserFullName)) ? $mgr->getUserFullName($user) : "";
24  }
25 
26  $form = new AutoForm($article);
27  $form->required("title");
28  $form->allowDelete = true;
29  $imageSelect = new ImageSelectFieldRenderer($form, "image_id");
30  $form->alias("image_id", "Associated Image");
31  $form->readonly("created_date");
32  $form->hide("author_id"); //TODO - allow author selection/re-assignment?
33  $articleTypeSelect = new SelectFieldRenderer($form, "article_type", "Article Type", Blog::getArticleTypeOptions());
34  //$articleTypeSelect->allowAddEntry();
35 
36  $form->annotate("identifier", "(Optional) identifier for this article for friendlier URLs");
37 
38  $form->annotate("post_date", "The date that will be displayed in the article's tagline.");
39  $form->annotate("publish_date", "The date the article will be published on the site.");
40  $form->annotate("archive_date", "The date the article will be archived from the site.");
41 
42  $form->getRenderer("message")->height = "480px";
43  $form->getRenderer("teaser")->height = "120px";
44 
45  $sites = query(Site, "ORDER BY site_name");
46 
47  $siteSelect = new CrossReferenceSelectFieldRenderer($form, "sites", "Sites", $sites, "site_name", ArticleSiteXref);
48 
49  $form->getRenderer("archive_date")->validator->required = false;
50 
52 
53  return $form;
54  }
55 
63  static function onPublishArticle($article)
64  {
65  if($article->published && !$article->publish_date)
66  {
67  $article->publish_date = today();
68  $article->filter = new InclusionFilter("publish_date");
69  $article->save();
70  }
71 
72  if($article->published)
73  {
75  }
76  }
77 
87  static function sendEmailToSubscribers($article, $email_template_name)
88  {
89  if(!$article->published) return;
90 
91  $blog = $article->Blog();
92  if(!$blog) return;
93 
94  $subscribers = $blog->Subscribers("WHERE subscription_type='instant'");
95 
96  if(!count($subscribers)) return;
97 
98  $emailTemplate = EmailTemplate::getEmailTemplate($email_template_name);
99 
100  if(!$emailTemplate) return;
101 
102  // Get the article id now before sending to email manager which won't be able to get it
103  // from the subscriber obj.
104  $emailTemplate->message = str_replace("[article_id]", $article->article_id, $emailTemplate->message);
105  $emailTemplate->message = str_replace("[article_title]", $article->title, $emailTemplate->message);
106  $emailTemplate->message = str_replace("[teaser]", $article->teaser, $emailTemplate->message);
107 
108  foreach($subscribers as $subscriber)
109  {
111  $rtn = $mgr->sendEmail();
112  }
113  }
114 
115  static function registerCommentAdapter()
116  {
118  }
119 
120  static function registerSearchables($searchables)
121  {
122  trace("ArticleManager registerSearchables", 3);
123  $searchables["article"] = array(Article);
124  return $searchables;
125  }
126 
127  static function registerSolrAdapter()
128  {
129  SolrManager::registerSolrAdapter(Article, new ArticleSolrAdapter());
130  }
131 
133  {
134  $classes[] = Article;
135  return $classes;
136  }
137 
138  static function registerVersionedContent()
139  {
141  }
142 
150  static function deleteUser($user)
151  {
152  $pk = $user->getPrimaryKey();
153  $user_id = $user->$pk;
154 
155  trace("Component article is deleting objects dependent on user_id {$user_id}", 3);
156 
157  $article = new Article();
158  $article->delete("WHERE author_id={$user_id}");
159 
160  return $user;
161  }
162 
163  static function preprocessURI($identifier)
164  {
165  global $section;
166 
168  if (!$article) return null;
169  $blog = $article->getBlog();
170  if (SectionManager::isInSection($section->section, $blog->identifier))
171  {
172  $_GET["article_id"] = $article->article_id;
173  $_POST["article_id"] = $article->article_id;
174  $_GET["blog"] = $blog->identifier;
175  return $blog->identifier;
176  }
177 
178  return null;
179  }
180 
181  static function upgradeComponent($version)
182  {
183  $mgr = new ArticleUpgradeManager();
184  $mgr->upgrade($version);
185  }
186 }?>
$user_id
$form
$article
$blog
$_POST["owner_id"]
Definition: blog_form.inc:54
$section
Definition: event_form.inc:44
if(! $token) $subscriber
Definition: article.inc:336
Defines the Article class.
Definition: article.inc:45
static fromIdentifier($identifier)
Definition: article.inc:134
static registerSolrAdapter()
ArticleManager()
static sendEmailToSubscribers($article, $email_template_name)
When an article is published, send an email to instant notification subscribers.
static registerTaxonomyClasses($classes)
static upgradeComponent($version)
static buildArticleForm($article)
static registerSearchables($searchables)
static preprocessURI($identifier)
static deleteUser($user)
Respond to fired event DeleteUser.
static registerVersionedContent()
static registerCommentAdapter()
static onPublishArticle($article)
If an article is marked published but no publish date set (user may wish to set a future publish date...
Definition: article.inc:309
Definition: article.inc:391
static getArticleTypeOptions()
Definition: blog.inc:197
static registerAdapter($component, $parentClass, $xrefClass)
Takes an email template and an obj of any DataItem class and sends email to a list of recipients afte...
static getEmailTemplate($name)
Retrieves the named email templated.
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static isInSection($section_folder, $identifier)
Definition: site.inc:40
Provides the interface to the user model for the application.
global $user
$sites
Definition: event_edit.inc:83
$identifier
Definition: rss.inc:37