Fixed minor things and added missing file
[vanilla-miry.git] / extensions / BlogThis / default.php
blob473fb572dec86047555300f01313bf4303297214
1 <?php
2 /*
3 Extension Name: BlogThis
4 Extension Url: http://lussumo.com/addons/index.php?PostBackAction=AddOn&AddOnID=364
5 Description: Blog page built from any comments from any discussions chosen.
6 Version: 1.14
7 Author: Andrew Miller (Spode)
8 Author Url: http://www.thinkabouttech.com
9 */
12 Based on the original "Blog" extension by Ziyad (MySchizoBuddy) Saeed.
15 //Permissions
16 // Can blog/unblog any comment.
17 $Context->Configuration['PERMISSION_CANBLOGALL'] = '0';
18 // Can blog/unblog own comments.
19 $Context->Configuration['PERMISSION_CANBLOGTHIS'] = '0';
20 // Allow HTML in BlogThis profile?
21 $Context->Configuration['PERMISSION_BLOGPROFILEHTML'] = '0';
23 // Blog Path
24 $BlogPath = dirname(__FILE__);
26 // Libraries
27 include($BlogPath . '/library/Function.BlogThis.php');
28 include($BlogPath . '/library/Control.BlogThis.php');
29 include($BlogPath . '/library/PostBackControl.BlogForm.php');
31 // BlogThis Preferences
32 if( !array_key_exists('BLOG_TAB_NAME', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_TAB_NAME', 'Blog');}
33 if( !array_key_exists('BLOG_TAB_POSITION', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_TAB_POSITION', '1');}
34 if( !array_key_exists('BLOG_ADSENSE', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_ADSENSE', '0');}
35 if( !array_key_exists('BLOG_SOCIALBOOKMARKS_DIGG', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_SOCIALBOOKMARKS_DIGG', '0');}
36 if( !array_key_exists('BLOG_SOCIALBOOKMARKS_DELICIOUS', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_SOCIALBOOKMARKS_DELICIOUS', '0');}
37 if( !array_key_exists('BLOG_SOCIALBOOKMARKS_STUMBLE', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_SOCIALBOOKMARKS_STUMBLE', '0');}
38 if( !array_key_exists('BLOG_SOCIALBOOKMARKS_TECHNORATI', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_SOCIALBOOKMARKS_TECHNORATI', '0');}
39 if( !array_key_exists('BLOG_PER_PAGE', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_PER_PAGE', '10');}
40 if( !array_key_exists('BLOG_WORD_LIMIT', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_WORD_LIMIT', '0');}
41 if( !array_key_exists('BLOG_DATE', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_DATE', 'jS F, Y');}
42 if( !array_key_exists('BLOG_TITLE', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_TITLE', 'My Blog');}
43 if( !array_key_exists('BLOG_PROFILETEXT', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_PROFILETEXT', '1');}
44 if( !array_key_exists('BLOG_FULLNAME', $Configuration)) {AddConfigurationSetting($Context, 'BLOG_FULLNAME', '0');}
46 //Install BlogThis
47 if (!array_key_exists('BLOGTHIS', $Configuration) || @$_GET['UpgradeBlogThis'])
49 //check to see if the column exists in the database
50 $query = "SHOW COLUMNS FROM `".$Configuration['DATABASE_TABLE_PREFIX']."Comment` LIKE 'BlogThis';";
51 $result = $Context->Database->Execute($query,'','','An error occured checking for the existence of the BlogThis field.');
52 $result = $Context->Database->GetRow($result);
54 //BlogThis field doesn't exist!
55 if (!$result)
57 $query = "ALTER TABLE `".$Configuration['DATABASE_TABLE_PREFIX']."Comment` ADD `BlogThis` TINYINT(1) DEFAULT 0 NOT NULL ;";
58 $result = $Context->Database->Execute($query,'','','An error occured adding the BlogThis field - does your database user have the correct priviliges?.');
61 $query = "SHOW COLUMNS FROM `".$Configuration['DATABASE_TABLE_PREFIX']."User` LIKE 'ProfileText';";
62 $result = $Context->Database->Execute($query,'','','An error occured checking for the existence of the ProfileText field.');
63 $result = $Context->Database->GetRow($result);
66 if (!$result)
68 $query = "ALTER TABLE `".$Configuration['DATABASE_TABLE_PREFIX']."User` ADD `ProfileText` TEXT;";
69 $result = $Context->Database->Execute($query,'','','An error occured adding the ProfileText field - does your database user have the correct priviliges?.');
72 //Add configurations
73 AddConfigurationSetting($Context, 'BLOGTHIS', '1');
76 $DatabaseColumns['Comment']['BlogThis'] = 'BlogThis';
77 $DatabaseColumns['User']['ProfileText'] = 'ProfileText';
79 //if the user has permission, add the blogthis buttons
80 if ($Context->Session->User->Permission('PERMISSION_CANBLOGTHIS') || $Context->Session->User->Permission('PERMISSION_CANBLOGALL'))
82 $Context->AddToDelegate("CommentGrid", "PostCommentOptionsRender", "AddBlogThis");
84 //As they can Blog, also enable ability to modify blog profile
85 if ($Context->Configuration['BLOG_PROFILETEXT'])
87 $Context->AddToDelegate("IdentityForm", "PreCustomInputsRender", "AddModifyProfile");
88 $Context->AddToDelegate("UserManager", "PreIdentityUpdate", "AddProfileText");
92 //Add tab to main menu
93 if (isset($Menu))
95 $Menu->AddTab($Configuration['BLOG_TAB_NAME'], 'Blog', GetUrl($Configuration, 'extension.php', '', '', '', '', 'PostBackAction=Blog'), '', $Context->Configuration['BLOG_TAB_POSITION']);
98 //Add stylesheet for the user account page
99 if ($Context->SelfUrl == 'account.php')
101 $Head->AddStyleSheet( 'extensions/BlogThis/theme/accountstyle.css');
104 //Show Blog User Profiles
105 if ($Context->Configuration['BLOG_PROFILETEXT'])
107 $Context->AddToDelegate("Account", "PostProfileRender", "AddProfileDetails");
110 //add text link for viewing blog posts
111 $Context->AddToDelegate("Account", "PostProfileRender", "AddViewBlogPosts");
113 //UnBlog/Blog a post, assuming correct permissions and on the right page
114 if (in_array($Context->SelfUrl, array("comments.php")) && ($Context->Session->User->Permission('PERMISSION_CANBLOGTHIS') || $Context->Session->User->Permission('PERMISSION_CANBLOGALL')))
117 if (ForceIncomingString('PostBackAction', '') == 'BlogThis') {$blogvalue = 1;}
118 if (ForceIncomingString('PostBackAction', '') == 'UnBlogThis') {$blogvalue = 0;}
120 $cmid = ForceIncomingString('BlogCommentID', '');
122 if (($cmid) && isset($blogvalue))
124 $sql = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder');
125 $sql->SetMainTable('Comment','c');
126 $sql->AddFieldNameValue('BlogThis', $blogvalue, 0);
127 $sql->AddWhere('c', 'CommentID', '', FormatStringForDatabaseInput($cmid), '=');
129 //stops people without permission blogging other people's posts
130 if ($Context->Session->User->Permission('PERMISSION_CANBLOGTHIS') && !$Context->Session->User->Permission('PERMISSION_CANBLOGALL'))
132 $sql->AddWhere('c', 'AuthUserID', '', $Context->Session->UserID, '=');
135 $result = $Context->Database->Update ($sql, '', '' , 'Could not change the Blogged/UnBlogged status of the comment.');
137 //if it returns 0, either the user doesn't have permission, or something odd is going on!
138 if ($result)
140 $Context->AddToDelegate("CommentGrid", "PreRender", "DisplaySuccess");
142 else
144 $Context->AddToDelegate("CommentGrid", "PreRender", "DisplayFail");
149 //If this is the "Blog" page, display the blog grid
151 if ($Context->SelfUrl == 'extension.php' && ForceIncomingString('PostBackAction', '') == 'Blog')
153 $Head->AddStyleSheet( 'extensions/BlogThis/theme/style.css');
154 $Head->BodyId = 'Blog';
156 //changes current tab to Blog
157 if (isset($Menu)) $Menu->CurrentTab = 'Blog';
159 $Context->PageTitle = $Context->Configuration['BLOG_TITLE'];
160 $Blog = $Context->ObjectFactory->NewContextObject($Context, 'Blog');
161 $Page->AddRenderControl($Blog, $Configuration['CONTROL_POSITION_BODY_ITEM']);
164 //Settings panel for BlogThis
165 if (($Context->SelfUrl == 'settings.php') && $Context->Session->User->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS'))
167 $BlogForm = $Context->ObjectFactory->NewContextObject($Context, 'BlogForm');
168 $Page->AddRenderControl($BlogForm, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
169 $ExtensionOptions = $Context->GetDefinition('ExtensionOptions');
170 $Panel->AddList($ExtensionOptions);
171 $Panel->AddListItem($ExtensionOptions, $Context->GetDefinition('BlogSettings'), GetUrl($Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction=Blog'));
174 //this was added in for compatibility with FeedPublisher and now FeedThis
175 //The url /search.php?PostBackAction=Search&Type=Comments&BlogSearch=1&Feed=RSS2 is used in FeedPublisher. FeedThis works automatically.
176 $Context->AddToDelegate("CommentManager", "SearchBuilder_PostWhere", "Search_AddQuery");
178 //Adds the "Start a blog post" link
179 $Context->AddToDelegate("Panel", "PostStartButtonRender", "AddStartBlog");
181 //Add extra bits to post page
182 if (($Context->SelfUrl == 'post.php') && ($Context->Session->User->Permission('PERMISSION_CANBLOGALL') || $Context->Session->User->Permission('PERMISSION_CANBLOGTHIS')))
184 $Head->AddStyleSheet('extensions/BlogThis/theme/post.css');
185 $Context->AddToDelegate("DiscussionForm", "DiscussionForm_PostButtonsRender", "AddBlogTick");
186 $Context->AddToDelegate("DiscussionForm", "PostSaveDiscussion", "PostBlogThis");