CMS  Version 3.9
comment_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 
40 {
44  var $imported = false;
45 
47  {
48  $this->component = $component;
49  $this->parentClass = $parentClass;
50  $this->xrefClass = $xrefClass;
51  }
52 
53  function importComponent()
54  {
55  if (!$this->imported)
56  {
57  Fakoli::using($this->component);
58  $this->imported = true;
59  }
60  }
61 
62  function createParent()
63  {
64  $this->importComponent();
66  if (isset($_GET[$parent->getPrimaryKey()]) && checkNumeric($_GET[$parent->getPrimaryKey()]))
67  {
68  $parent->load($_GET[$parent->getPrimaryKey()]);
69  }
70 
71  return $parent;
72  }
73 
74  function createXref()
75  {
76  $this->importComponent();
77  return new $this->xrefClass;
78  }
79 }
80 
82 {
83  static $adapters = array();
84 
85  function CommentManager()
86  {
87 
88  }
89 
90  static function setDefaults()
91  {
92  Settings::setDefaultValue("comment", "allow_anonymous_commenting", false, Boolean, "", "Commenting Rules");
93  Settings::setDefaultValue("comment", "publish_automatically", true, Boolean, "", "Commenting Rules");
94  Settings::setDefaultValue("comment", "use_captcha", "Never", String, "Specify when to use a Captcha to verify the user", "Commenting Rules", "Never\nAnonymous Only\nAlways");
95 
96  Settings::setDefaultValue("comment", "enable_item_rating", false, Boolean, "Specifies whether to display the rating control", "Comment Configuration", null, 2);
97  Settings::setDefaultValue("comment", "show_subject_field", true, Boolean, "Specifies whether users can have a title as part of their comment", "Comment Configuration", null, 1);
98 
99  Settings::setDefaultValue("comment", "username_format", "Full Name", String,
100  "Specifies whether to display the full name or username (handle) of logged in commenters", "Comment Configuration", "Full Name\nUsername", 3);
101 
102  Settings::setDefaultValue("comment", "anonymous_preamble_text", "", String,
103  "Identifier of a Text Lookup item containing preamble text that appears at the top of the comment panel for anonymous users",
104  "Comment Configuration", null, 4);
105 
106  Settings::setDefaultValue("comment", "logged_in_preamble_text", "", String,
107  "Identifier of a Text Lookup item containing preamble text that appears at the top of the comment panel for logged in users",
108  "Comment Configuration", null, 5);
109 
112  }
113 
114 
119  static function setDefaultEmailTemplates()
120  {
121  global $config;
122 
123  $sitename = $config["sitename"];
124  $contact = $config["email_contact"];
125 
126  $message = "This is an automated message from the {$sitename}.<br><br>A new comment has been posted. To review and publish this comment, click the link below:<br><br>[article_comment_url]";
127  EmailTemplate::setDefaultTemplate("new_comment", $contact, "[article_title] Comment ([comment_title])", $message, "ArticleCommentXref");
128  }
129 
137  static function setDefaultMergeCodes()
138  {
139  MergeCode::setDefaultMergeCode("comment_article_id", "Article.article_id", "ArticleCommentXref", "Comment Article ID");
140  MergeCode::setDefaultMergeCode("comment_title", "Comment.title", "ArticleCommentXref", "Comment Title");
141  MergeCode::setDefaultMergeCode("article_title", "Article.title", "ArticleCommentXref", "Article Title");
142  MergeCode::setDefaultMergeCode("article_url", "Article.getUrl", "ArticleCommentXref", "URL of article with list of comments");
143  MergeCode::setDefaultMergeCode("article_comment_url", "getUrl", "ArticleCommentXref", "URL of article with list of comments");
144  }
145 
146  static function onInitialize()
147  {
148  }
149 
150  static function upgradeComponent($version)
151  {
152  $mgr = new CommentUpgradeManager();
153  $mgr->upgrade($version);
154  }
155 
156  static function registerAdapter($component, $parentClass, $xrefClass)
157  {
158  trace("Registering CommentAdapter for $component", 3);
159  $adapter = new CommentAdapter($component, $parentClass, $xrefClass);
160  $proto = $adapter->createParent();
161  CommentManager::$adapters[$proto->getPrimaryKey()] = $adapter;
162  }
163 
171  static function deleteUser($user)
172  {
173  $pk = $user->getPrimaryKey();
174  $user_id = $user->$pk;
175 
176  trace("Component comment is deleting objects dependent on user_id {$user_id}", 3);
177 
178  $comment = new Comment();
179  $comment->delete("WHERE user_id={$user_id}");
180 
181  return $user;
182  }
183 
184  static function getAdapters()
185  {
186  if (count(CommentManager::$adapters) == 0)
187  {
188  ComponentManager::fireEvent("RegisterCommentAdapters");
189  }
191  }
192 
193  static function getAdapter()
194  {
196 
197  trace(print_r($adapters, true), 3);
198 
199  foreach($_GET as $key => $value)
200  {
201  if (array_key_exists($key, $adapters))
202  {
203  return $adapters[$key];
204  }
205  }
206  }
207 }?>
$user_id
$component
Definition: help.inc:38
$parent
Definition: templates.inc:42
__construct($component, $parentClass, $xrefClass)
static setDefaultMergeCodes()
Merge codes for ArticleCommentXref: comment_article_id comment_title article_title article_url.
static registerAdapter($component, $parentClass, $xrefClass)
static setDefaultEmailTemplates()
For comment, need default template: new_comment.
static upgradeComponent($version)
static deleteUser($user)
Respond to fired event DeleteUser.
static setDefaults()
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
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 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 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
global $user
$comment
global $config
Definition: import.inc:4
$message
Definition: mail_to.inc:49