| 4 | | // register links -- |
|---|
| 5 | | global $profile_id; |
|---|
| 6 | | global $PAGE; |
|---|
| 7 | | global $CFG; |
|---|
| 8 | | |
|---|
| 9 | | $page_owner = $profile_id; |
|---|
| 10 | | |
|---|
| 11 | | // main menu |
|---|
| 12 | | if (isloggedin() && user_info("user_type",$_SESSION['userid']) != "external") { |
|---|
| 13 | | |
|---|
| 14 | | if (defined("context") && context == "weblog" && $page_owner == $_SESSION['userid']) { |
|---|
| 15 | | |
|---|
| 16 | | $PAGE->menu[] = array( 'name' => 'weblog', |
|---|
| 17 | | 'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/weblog\" class=\"selected\" >" .__gettext("Your Blog").'</a></li>'); |
|---|
| 18 | | |
|---|
| 19 | | } else { |
|---|
| 20 | | $PAGE->menu[] = array( 'name' => 'weblog', |
|---|
| 21 | | 'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/weblog\" >" .__gettext("Your Blog").'</a></li>'); |
|---|
| 22 | | }; |
|---|
| 23 | | } |
|---|
| 24 | | |
|---|
| 25 | | $weblog_username = user_info('username', $page_owner); |
|---|
| 26 | | |
|---|
| 27 | | // submenu |
|---|
| 28 | | if (defined("context") && context == "weblog") { |
|---|
| | 3 | // register links -- |
|---|
| | 4 | global $profile_id; |
|---|
| | 5 | global $PAGE; |
|---|
| | 6 | global $CFG; |
|---|
| | 7 | require_once (dirname(__FILE__))."/default_template.php"; |
|---|
| | 8 | |
|---|
| | 9 | $page_owner= $profile_id; |
|---|
| | 10 | |
|---|
| | 11 | // main menu |
|---|
| | 12 | if (isloggedin() && user_info("user_type", $_SESSION['userid']) != "external") { |
|---|
| | 13 | |
|---|
| | 14 | if (defined("context") && context == "weblog" && $page_owner == $_SESSION['userid']) { |
|---|
| | 15 | |
|---|
| | 16 | $PAGE->menu[]= array ( |
|---|
| | 17 | 'name' => 'weblog', |
|---|
| | 18 | 'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/weblog\" class=\"selected\" >" . __gettext("Your Blog") . '</a></li>'); |
|---|
| | 19 | |
|---|
| | 20 | } else { |
|---|
| | 21 | $PAGE->menu[]= array ( |
|---|
| | 22 | 'name' => 'weblog', |
|---|
| | 23 | 'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/weblog\" >" . __gettext("Your Blog") . '</a></li>'); |
|---|
| | 24 | }; |
|---|
| | 25 | } |
|---|
| | 26 | |
|---|
| | 27 | $weblog_username= user_info('username', $page_owner); |
|---|
| | 28 | |
|---|
| | 29 | // submenu |
|---|
| | 30 | if (defined("context") && context == "weblog") { |
|---|
| | 31 | |
|---|
| | 32 | if ($page_owner != -1) { |
|---|
| | 33 | |
|---|
| | 34 | $PAGE->menu_sub[]= array ( |
|---|
| | 35 | 'name' => 'blog:rssfeed', |
|---|
| | 36 | 'html' => "<a href=\"{$CFG->wwwroot}{$weblog_username}/weblog/rss/\"><img src=\"{$CFG->wwwroot}mod/template/icons/rss.png\" border=\"0\" alt=\"rss\" /></a>" |
|---|
| | 37 | ); |
|---|
| | 38 | |
|---|
| | 39 | if (run("permissions:check", "weblog") && logged_on) { |
|---|
| | 40 | $PAGE->menu_sub[]= array ( |
|---|
| | 41 | 'name' => 'blog:post', |
|---|
| | 42 | 'html' => "<a href=\"{$CFG->wwwroot}{$weblog_username}/weblog/edit\">" . __gettext("Post a new entry") . '</a>'); |
|---|
| | 43 | } |
|---|
| | 44 | |
|---|
| | 45 | $PAGE->menu_sub[]= array ( |
|---|
| | 46 | 'name' => 'blog:view', |
|---|
| | 47 | 'html' => "<a href=\"{$CFG->wwwroot}{$weblog_username}/weblog/\">" . __gettext("View blog") . '</a>'); |
|---|
| | 48 | |
|---|
| | 49 | $PAGE->menu_sub[]= array ( |
|---|
| | 50 | 'name' => 'blog:archive', |
|---|
| | 51 | 'html' => "<a href=\"{$CFG->wwwroot}{$weblog_username}/weblog/archive/\">" . __gettext("Archive") . '</a>'); |
|---|
| | 52 | |
|---|
| | 53 | $PAGE->menu_sub[]= array ( |
|---|
| | 54 | 'name' => 'blog:friends', |
|---|
| | 55 | 'html' => "<a href=\"{$CFG->wwwroot}{$weblog_username}/weblog/friends/\">" . __gettext("Friends' blogs") . '</a>'); |
|---|
| | 56 | |
|---|
| | 57 | if ($page_owner == $_SESSION['userid']) { |
|---|
| | 58 | $PAGE->menu_sub[]= array ( |
|---|
| | 59 | 'name' => 'blog:interesting', |
|---|
| | 60 | 'html' => "<a href=\"{$CFG->wwwroot}{$weblog_username}/weblog/interesting/\">" . __gettext("Interesting posts") . '</a>'); |
|---|
| | 61 | } |
|---|
| | 62 | } |
|---|
| | 63 | |
|---|
| | 64 | $PAGE->menu_sub[]= array ( |
|---|
| | 65 | 'name' => 'blog:everyone', |
|---|
| | 66 | 'html' => "<a href=\"{$CFG->wwwroot}weblog/everyone\">" . __gettext("View all posts") . '</a>'); |
|---|
| | 67 | |
|---|
| | 68 | } |
|---|
| | 69 | |
|---|
| | 70 | } |
|---|
| | 71 | |
|---|
| | 72 | function blog_init() { |
|---|
| | 73 | |
|---|
| | 74 | global $CFG, $function; |
|---|
| | 75 | |
|---|
| | 76 | |
|---|
| | 77 | // Functions to perform upon initialisation |
|---|
| | 78 | $function['weblogs:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_init.php"; |
|---|
| | 79 | $function['weblogs:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_actions.php"; |
|---|
| | 80 | |
|---|
| | 81 | // Load default template |
|---|
| | 82 | $function['init'][] = $CFG->dirroot . "mod/blog/default_template.php"; |
|---|
| | 83 | |
|---|
| | 84 | // Init for search |
|---|
| | 85 | $function['search:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_init.php"; |
|---|
| | 86 | $function['search:all:tagtypes'][] = $CFG->dirroot . "mod/blog/lib/function_search_all_tagtypes.php"; |
|---|
| | 87 | |
|---|
| | 88 | // Function to search through weblog posts |
|---|
| | 89 | $function['search:display_results'][] = $CFG->dirroot . "mod/blog/lib/function_search.php"; |
|---|
| | 90 | $function['search:display_results:rss'][] = $CFG->dirroot . "mod/blog/lib/function_search_rss.php"; |
|---|
| | 91 | |
|---|
| | 92 | // Edit / create weblog posts |
|---|
| | 93 | $function['weblogs:edit'][] = $CFG->dirroot . "mod/blog/lib/weblogs_edit.php"; |
|---|
| | 94 | $function['weblogs:posts:add'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_add.php"; |
|---|
| | 95 | $function['weblogs:posts:edit'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_edit.php"; |
|---|
| | 96 | |
|---|
| | 97 | // View weblog posts |
|---|
| | 98 | //$function['weblogs:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_post_field_wrapper.php"; |
|---|
| | 99 | $function['weblogs:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_view.php"; |
|---|
| | 100 | $function['weblogs:posts:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_view.php"; |
|---|
| | 101 | $function['weblogs:posts:view:individual'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_view.php"; |
|---|
| | 102 | $function['weblogs:friends:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_friends_view.php"; |
|---|
| | 103 | $function['weblogs:everyone:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_all_users_view.php"; |
|---|
| 86 | | |
|---|
| 87 | | function blog_widget_display($widget) { |
|---|
| 88 | | |
|---|
| 89 | | global $CFG; |
|---|
| 90 | | |
|---|
| 91 | | $blog_id = widget_get_data("blog_id",$widget->ident); |
|---|
| 92 | | $blog_posts = widget_get_data("blog_posts",$widget->ident); |
|---|
| 93 | | |
|---|
| 94 | | $body = ""; |
|---|
| 95 | | |
|---|
| 96 | | if (empty($blog_id)) { |
|---|
| 97 | | global $page_owner; |
|---|
| 98 | | $blog_id = $page_owner; |
|---|
| 99 | | } |
|---|
| 100 | | if (empty($blog_posts)) { |
|---|
| 101 | | $blog_posts = 1; |
|---|
| 102 | | } |
|---|
| 103 | | |
|---|
| 104 | | |
|---|
| 105 | | $where = run("users:access_level_sql_where",$_SESSION['userid']); |
|---|
| 106 | | $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts"); |
|---|
| 107 | | |
|---|
| 108 | | if (is_array($posts) && !empty($posts)) { |
|---|
| 109 | | foreach($posts as $post) { |
|---|
| 110 | | $body .= run("weblogs:posts:view",$post); |
|---|
| 111 | | } |
|---|
| 112 | | } |
|---|
| 113 | | |
|---|
| 114 | | return array('title'=>__gettext("Weblog"),'content'=>$body); |
|---|
| 115 | | |
|---|
| 116 | | } |
|---|
| 117 | | |
|---|
| 118 | | // KJ - converted to widget sytem |
|---|
| 119 | | |
|---|
| 120 | | function blog_widget_edit($widget) { |
|---|
| 121 | | |
|---|
| 122 | | global $CFG, $page_owner; |
|---|
| 123 | | |
|---|
| 124 | | $blog_id = widget_get_data("blog_id",$widget->ident); |
|---|
| 125 | | $blog_posts = widget_get_data("blog_posts",$widget->ident); |
|---|
| 126 | | if (empty($blog_posts)) { |
|---|
| 127 | | $blog_posts = 1; |
|---|
| 128 | | } |
|---|
| 129 | | if (empty($blog_id)) { |
|---|
| 130 | | $blog_id = $page_owner; |
|---|
| 131 | | } |
|---|
| 132 | | |
|---|
| 133 | | $connections = get_records_sql("select u.ident, u.name from ".$CFG->prefix."friends f join ".$CFG->prefix."users u on u.ident = f.friend where f.owner = " . $_SESSION['userid'] . " order by u.name asc"); |
|---|
| 134 | | $data = new stdClass; |
|---|
| 135 | | $data->ident = $page_owner; |
|---|
| 136 | | $data->name = run("profile:display:name", $page_owner); |
|---|
| 137 | | $connections[] = $data; |
|---|
| 138 | | if ($page_owner != $_SESSION['userid']) { |
|---|
| 139 | | $data = new stdClass; |
|---|
| 140 | | $data->ident = $_SESSION['userid']; |
|---|
| 141 | | $data->name = run("profile:display:name", $_SESSION['userid']); |
|---|
| 142 | | $connections[] = $data; |
|---|
| 143 | | } |
|---|
| 144 | | |
|---|
| 145 | | $body = "<h2>" . __gettext("Blog widget") . "</h2>"; |
|---|
| 146 | | $body .= "<p>" . __gettext("This widget displays the last couple of blog posts from an individual user. To begin, select the user from your connections below:") . "</p>"; |
|---|
| 147 | | |
|---|
| 148 | | $body .= "<p><select name=\"widget_data[blog_id]\">\n"; |
|---|
| 149 | | if (is_array($connections) && !empty($connections)) { |
|---|
| 150 | | foreach ($connections as $connection) { |
|---|
| 151 | | if ($connection->ident == $blog_id) { |
|---|
| 152 | | $selected = "selected=\"selected\""; |
|---|
| 153 | | } else { |
|---|
| 154 | | $selected = ""; |
|---|
| 155 | | } |
|---|
| 156 | | $body .= "<option value=\"" . $connection->ident . "\" $selected>" . $connection->name . "</option>\n"; |
|---|
| 157 | | } |
|---|
| 158 | | } |
|---|
| 159 | | $body .= "</select></p>\n"; |
|---|
| 160 | | |
|---|
| 161 | | $body .= "<p>" . __gettext("Then enter the number of blog posts you'd like to display:") . "</p>"; |
|---|
| 162 | | |
|---|
| 163 | | $body .= "<p><input type=\"text\" name=\"widget_data[blog_posts]\" value=\"" . $blog_posts . "\" /></p>"; |
|---|
| 164 | | |
|---|
| 165 | | return $body; |
|---|
| 166 | | |
|---|
| 167 | | } |
|---|
| 168 | | |
|---|
| 169 | | function blog_keyword($vars) { |
|---|
| 170 | | global $CFG, $db; |
|---|
| 171 | | |
|---|
| 172 | | $body = ""; |
|---|
| 173 | | |
|---|
| 174 | | if (!isset($vars[1])) { |
|---|
| 175 | | $blog_posts = 2; |
|---|
| 176 | | } else { |
|---|
| 177 | | $blog_posts = $vars[1]; |
|---|
| 178 | | } |
|---|
| 179 | | |
|---|
| 180 | | $where = run("users:access_level_sql_where",$_SESSION['userid']); |
|---|
| 181 | | |
|---|
| 182 | | if (!isset($vars[2]) || $vars[2] == "all") { |
|---|
| 183 | | $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts where ($where) order by posted desc limit $blog_posts"); |
|---|
| 184 | | } else { |
|---|
| 185 | | $blog_id = (int) user_info_username('ident',$vars[2]); |
|---|
| 186 | | $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts"); |
|---|
| 187 | | } |
|---|
| 188 | | |
|---|
| 189 | | if (is_array($posts) && !empty($posts)) { |
|---|
| 190 | | foreach($posts as $post) { |
|---|
| 191 | | if ($vars[3] != "slim") { |
|---|
| 192 | | $body .= run("weblogs:posts:view",$post); |
|---|
| 193 | | } else { |
|---|
| 194 | | $body .= "<div class=\"frontpage-blog-contents\">"; |
|---|
| 195 | | $body .= "<h4>" . $post->title . "</h4>"; |
|---|
| 196 | | $body .= "<p class=\"frontpage-blog-date\">" . strftime("%B %d, %Y",$post->posted) . "</p>"; |
|---|
| 197 | | $body .= "<p class=\"frontpage-blog-body\">" . run("weblogs:text:process", $post->body) . "</p>"; |
|---|
| 198 | | $body .= "<p class=\"frontpage-blog-from\">" . __gettext("From:") . " <a href=\"{$CFG->wwwroot}" . user_info("username",$post->weblog) . "\">" . user_info("name",$post->weblog) . "</a> - "; |
|---|
| 199 | | $body .= "<a href=\"{$CFG->wwwroot}" . user_info("username",$post->weblog) . "/weblog/" . $post->ident . ".html\">" . __gettext("Read more") . "</a></p>"; |
|---|
| 200 | | $body .= "</div>"; |
|---|
| 201 | | } |
|---|
| 202 | | } |
|---|
| 203 | | } |
|---|
| 204 | | |
|---|
| 205 | | return $body; |
|---|
| 206 | | } |
|---|
| 207 | | |
|---|
| 208 | | function blog_summary_keyword($vars) { |
|---|
| 209 | | global $CFG; |
|---|
| 210 | | $body = ""; |
|---|
| 211 | | |
|---|
| 212 | | if (!isset($vars[1])) { |
|---|
| 213 | | $blog_posts = 2; |
|---|
| 214 | | } else { |
|---|
| 215 | | $blog_posts = $vars[1]; |
|---|
| 216 | | } |
|---|
| 217 | | |
|---|
| 218 | | $where = run("users:access_level_sql_where",$_SESSION['userid']); |
|---|
| 219 | | |
|---|
| 220 | | if (!isset($vars[2]) || $vars[2] == "all") { |
|---|
| 221 | | $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts where ($where) order by posted desc limit $blog_posts"); |
|---|
| 222 | | } else { |
|---|
| 223 | | $blog_id = (int) user_info_username('ident',$vars[2]); |
|---|
| 224 | | $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts"); |
|---|
| 225 | | } |
|---|
| 226 | | |
|---|
| 227 | | if (is_array($posts) && !empty($posts)) { |
|---|
| 228 | | foreach($posts as $post) { |
|---|
| 229 | | $body .= "<div class=\"frontpage-blog-summary\">"; |
|---|
| 230 | | $body .= "<h4>" . $post->title . "</h4>"; |
|---|
| 231 | | $body .= "<p class=\"frontpage-blog-date\">" . strftime("%B %d, %Y",$post->posted) . "</p>"; |
|---|
| 232 | | $body .= "<p class=\"frontpage-blog-from\">" . __gettext("From:") . " <a href=\"{$CFG->wwwroot}" . user_info("username",$post->weblog) . "\">" . user_info("name",$post->weblog) . "</a> - "; |
|---|
| 233 | | $body .= "<a href=\"{$CFG->wwwroot}" . user_info("username",$post->weblog) . "/weblog/" . $post->ident . ".html\">" . __gettext("Read more") . "</a></p>"; |
|---|
| 234 | | $body .= "</div>"; |
|---|
| 235 | | } |
|---|
| 236 | | } |
|---|
| 237 | | |
|---|
| 238 | | return $body; |
|---|
| 239 | | } |
|---|
| 240 | | |
|---|
| | 112 | $function['weblogs:archives:view'][] = $CFG->dirroot . "mod/blog/lib/archives_view.php"; |
|---|
| | 113 | $function['weblogs:archives:month:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_view_month.php"; |
|---|
| | 114 | $function['weblogs:interesting:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_interesting_view.php"; |
|---|
| | 115 | |
|---|
| | 116 | // Mark posts as interesting (or not) |
|---|
| | 117 | $function['weblogs:interesting:form'][] = $CFG->dirroot . "mod/blog/lib/display_interesting_post_form.php"; |
|---|
| | 118 | |
|---|
| | 119 | // Edit / create weblog comments |
|---|
| | 120 | $function['weblogs:comments:add'][] = $CFG->dirroot . "mod/blog/lib/weblogs_comments_add.php"; |
|---|
| | 121 | |
|---|
| | 122 | // Log on bar down the right hand side |
|---|
| | 123 | // $function['profile:log_on_pane'][] = $CFG->dirroot . "units/weblogs/weblogs_user_info_menu.php"; |
|---|
| | 124 | $function['display:sidebar'][] = $CFG->dirroot . "mod/blog/lib/weblogs_user_info_menu.php"; |
|---|
| | 125 | |
|---|
| | 126 | // Weblog preview |
|---|
| | 127 | $function['templates:preview'][] = $CFG->dirroot . "mod/blog/templates_preview.php"; |
|---|
| | 128 | |
|---|
| | 129 | // Establish permissions |
|---|
| | 130 | $function['permissions:check'][] = $CFG->dirroot . "mod/blog/lib/permissions_check.php"; |
|---|
| | 131 | |
|---|
| | 132 | // Actions to perform when an access group is deleted |
|---|
| | 133 | $function['groups:delete'][] = $CFG->dirroot . "mod/blog/lib/groups_delete.php"; |
|---|
| | 134 | |
|---|
| | 135 | // Publish static RSS file of posts |
|---|
| | 136 | $function['weblogs:rss:getitems'][] = $CFG->dirroot . "mod/blog/lib/function_rss_getitems.php"; |
|---|
| | 137 | $function['weblogs:rss:publish'][] = $CFG->dirroot . "mod/blog/lib/function_rss_publish.php"; |
|---|
| | 138 | |
|---|
| | 139 | // Removing function from weblogs_init.php |
|---|
| | 140 | $function['weblogs:html_activate_urls'][] = $CFG->dirroot . "mod/blog/lib/function_html_activate_urls.php"; |
|---|
| | 141 | |
|---|
| | 142 | //$CFG->widgets->display['blog'] = "blog_widget_display"; |
|---|
| | 143 | //$CFG->widgets->edit['blog'] = "blog_widget_edit"; |
|---|
| | 144 | |
|---|
| | 145 | $CFG->widgets->list[]= array ('name' => __gettext("Blog widget"), |
|---|
| | 146 | 'description' => __gettext("Displays the latest blog posts from a blog of your choice."),'type' => "blog::blog"); |
|---|
| | 147 | |
|---|
| | 148 | $CFG->templates->variables_substitute['blog'][]= "blog_keyword"; |
|---|
| | 149 | $CFG->templates->variables_substitute['blogsummary'][]= "blog_summary_keyword"; |
|---|
| | 150 | $CFG->templates->variables_substitute['blogexecutivesummary'][] = "blog_executive_summary_keyword"; |
|---|
| | 151 | // Delete users |
|---|
| | 152 | listen_for_event("user", "delete", "blog_user_delete"); |
|---|
| | 153 | |
|---|
| | 154 | if (!isset ($CFG->display_field_module)) { |
|---|
| | 155 | $CFG->display_field_module= array (); |
|---|
| | 156 | } |
|---|
| | 157 | |
|---|
| | 158 | if (!array_key_exists("select", $CFG->display_field_module)) { |
|---|
| | 159 | $CFG->display_field_module["select"]= "blog"; |
|---|
| | 160 | } |
|---|
| | 161 | if (!array_key_exists("selectg", $CFG->display_field_module)) { |
|---|
| | 162 | $CFG->display_field_module["selectg"]= "blog"; |
|---|
| | 163 | } |
|---|
| | 164 | if (!array_key_exists("selectd", $CFG->display_field_module) && !array_key_exists("date_select", $CFG->display_field_module)) { |
|---|
| | 165 | $CFG->display_field_module["selectd"]= "blog"; |
|---|
| | 166 | $CFG->display_field_module["date_select"]= "blog"; |
|---|
| | 167 | } |
|---|
| | 168 | if (!array_key_exists("radio", $CFG->display_field_module)) { |
|---|
| | 169 | $CFG->display_field_module["radio"]= "blog"; |
|---|
| | 170 | } |
|---|
| | 171 | if (!array_key_exists("vertical_radio", $CFG->display_field_module)) { |
|---|
| | 172 | $CFG->display_field_module["vertical_radio"]= "blog"; |
|---|
| | 173 | } |
|---|
| | 174 | |
|---|
| | 175 | if (!isset ($CFG->weblog_extensions)) { |
|---|
| | 176 | $CFG->weblog_extensions= array (); |
|---|
| | 177 | } |
|---|
| | 178 | $CFG->weblog_extensions['weblog']= array (); |
|---|
| | 179 | |
|---|
| | 180 | } |
|---|
| | 181 | |
|---|
| | 182 | function blog_widget_display($widget) { |
|---|
| | 183 | |
|---|
| | 184 | global $CFG; |
|---|
| | 185 | |
|---|
| | 186 | $blog_id= widget_get_data("blog_id", $widget->ident); |
|---|
| | 187 | $blog_posts= widget_get_data("blog_posts", $widget->ident); |
|---|
| | 188 | |
|---|
| | 189 | $body= ""; |
|---|
| | 190 | |
|---|
| | 191 | if (empty ($blog_id)) { |
|---|
| | 192 | global $page_owner; |
|---|
| | 193 | $blog_id= $page_owner; |
|---|
| | 194 | } |
|---|
| | 195 | if (empty ($blog_posts)) { |
|---|
| | 196 | $blog_posts= 1; |
|---|
| | 197 | } |
|---|
| | 198 | |
|---|
| | 199 | $where= run("users:access_level_sql_where", $_SESSION['userid']); |
|---|
| | 200 | $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts"); |
|---|
| | 201 | |
|---|
| | 202 | if (is_array($posts) && !empty ($posts)) { |
|---|
| | 203 | foreach ($posts as $post) { |
|---|
| | 204 | $body .= run("weblogs:posts:view", $post); |
|---|
| | 205 | } |
|---|
| | 206 | } |
|---|
| | 207 | |
|---|
| | 208 | return array ( |
|---|
| | 209 | 'title' => __gettext("Weblog" |
|---|
| | 210 | ), 'content' => $body); |
|---|
| | 211 | |
|---|
| | 212 | } |
|---|
| | 213 | |
|---|
| | 214 | // KJ - converted to widget sytem |
|---|
| | 215 | |
|---|
| | 216 | function blog_widget_edit($widget) { |
|---|
| | 217 | |
|---|
| | 218 | global $CFG, $page_owner; |
|---|
| | 219 | |
|---|
| | 220 | $blog_id= widget_get_data("blog_id", $widget->ident); |
|---|
| | 221 | $blog_posts= widget_get_data("blog_posts", $widget->ident); |
|---|
| | 222 | if (empty ($blog_posts)) { |
|---|
| | 223 | $blog_posts= 1; |
|---|
| | 224 | } |
|---|
| | 225 | if (empty ($blog_id)) { |
|---|
| | 226 | $blog_id= $page_owner; |
|---|
| | 227 | } |
|---|
| | 228 | |
|---|
| | 229 | $connections= get_records_sql("select u.ident, u.name from " . $CFG->prefix . "friends f join " . $CFG->prefix . "users u on u.ident = f.friend where f.owner = " . $_SESSION['userid'] . " order by u.name asc"); |
|---|
| | 230 | $data= new stdClass; |
|---|
| | 231 | $data->ident= $page_owner; |
|---|
| | 232 | $data->name= run("profile:display:name", $page_owner); |
|---|
| | 233 | $connections[]= $data; |
|---|
| | 234 | if ($page_owner != $_SESSION['userid']) { |
|---|
| | 235 | $data= new stdClass; |
|---|
| | 236 | $data->ident= $_SESSION['userid']; |
|---|
| | 237 | $data->name= run("profile:display:name", $_SESSION['userid']); |
|---|
| | 238 | $connections[]= $data; |
|---|
| | 239 | } |
|---|
| | 240 | |
|---|
| | 241 | $body= "<h2>" . __gettext("Blog widget") . "</h2>"; |
|---|
| | 242 | $body .= "<p>" . __gettext("This widget displays the last couple of blog posts from an individual user. To begin, select the user from your connections below:") . "</p>"; |
|---|
| | 243 | |
|---|
| | 244 | $body .= "<p><select name=\"widget_data[blog_id]\">\n"; |
|---|
| | 245 | if (is_array($connections) && !empty ($connections)) { |
|---|
| | 246 | foreach ($connections as $connection) { |
|---|
| | 247 | if ($connection->ident == $blog_id) { |
|---|
| | 248 | $selected= "selected=\"selected\""; |
|---|
| | 249 | } else { |
|---|
| | 250 | $selected= ""; |
|---|
| | 251 | } |
|---|
| | 252 | $body .= "<option value=\"" . $connection->ident . "\" $selected>" . $connection->name . "</option>\n"; |
|---|
| | 253 | } |
|---|
| | 254 | } |
|---|
| | 255 | $body .= "</select></p>\n"; |
|---|
| | 256 | |
|---|
| | 257 | $body .= "<p>" . __gettext("Then enter the number of blog posts you'd like to display:") . "</p>"; |
|---|
| | 258 | |
|---|
| | 259 | $body .= "<p><input type=\"text\" name=\"widget_data[blog_posts]\" value=\"" . $blog_posts . "\" /></p>"; |
|---|
| | 260 | |
|---|
| | 261 | return $body; |
|---|
| | 262 | |
|---|
| | 263 | } |
|---|
| | 264 | |
|---|
| | 265 | function blog_keyword($vars) { |
|---|
| | 266 | global $CFG, $db; |
|---|
| | 267 | |
|---|
| | 268 | $body= ""; |
|---|
| | 269 | |
|---|
| | 270 | if (!isset ($vars[1])) { |
|---|
| | 271 | $blog_posts= 2; |
|---|
| | 272 | } else { |
|---|
| | 273 | $blog_posts= $vars[1]; |
|---|
| | 274 | } |
|---|
| | 275 | |
|---|
| | 276 | $where= run("users:access_level_sql_where", $_SESSION['userid']); |
|---|
| | 277 | |
|---|
| | 278 | if (!isset ($vars[2]) || $vars[2] == "all") { |
|---|
| | 279 | $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) order by posted desc limit $blog_posts"); |
|---|
| | 280 | } else { |
|---|
| | 281 | $blog_id= (int) user_info_username('ident', $vars[2]); |
|---|
| | 282 | $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts"); |
|---|
| | 283 | } |
|---|
| | 284 | |
|---|
| | 285 | if (is_array($posts) && !empty ($posts)) { |
|---|
| | 286 | foreach ($posts as $post) { |
|---|
| | 287 | if ($vars[3] != "slim") { |
|---|
| | 288 | $body .= run("weblogs:posts:view", $post); |
|---|
| | 289 | } else { |
|---|
| | 290 | $body .= "<div class=\"frontpage-blog-contents\">"; |
|---|
| | 291 | $body .= "<h4>" . $post->title . "</h4>"; |
|---|
| | 292 | $body .= "<p class=\"frontpage-blog-date\">" . strftime("%B %d, %Y", $post->posted) . "</p>"; |
|---|
| | 293 | $body .= "<p class=\"frontpage-blog-body\">" . run("weblogs:text:process", $post->body) . "</p>"; |
|---|
| | 294 | $body .= "<p class=\"frontpage-blog-from\">" . __gettext("From:") . " <a href=\"{$CFG->wwwroot}" . user_info("username", $post->weblog) . "\">" . user_info("name", $post->weblog) . "</a> - "; |
|---|
| | 295 | $body .= "<a href=\"{$CFG->wwwroot}" . user_info("username", $post->weblog) . "/weblog/" . $post->ident . ".html\">" . __gettext("Read more") . "</a></p>"; |
|---|
| | 296 | $body .= "</div>"; |
|---|
| | 297 | } |
|---|
| | 298 | } |
|---|
| | 299 | } |
|---|
| | 300 | |
|---|
| | 301 | return $body; |
|---|
| | 302 | } |
|---|
| | 303 | |
|---|
| | 304 | function blog_summary_keyword($vars) { |
|---|
| | 305 | global $CFG; |
|---|
| | 306 | $body= ""; |
|---|
| | 307 | |
|---|
| | 308 | if (!isset ($vars[1])) { |
|---|
| | 309 | $blog_posts= 2; |
|---|
| | 310 | } else { |
|---|
| | 311 | $blog_posts= $vars[1]; |
|---|
| | 312 | } |
|---|
| | 313 | |
|---|
| | 314 | $where= run("users:access_level_sql_where", $_SESSION['userid']); |
|---|
| | 315 | |
|---|
| | 316 | if (!isset ($vars[2]) || $vars[2] == "all") { |
|---|
| | 317 | $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) order by posted desc limit $blog_posts"); |
|---|
| | 318 | } else { |
|---|
| | 319 | $blog_id= (int) user_info_username('ident', $vars[2]); |
|---|
| | 320 | $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts"); |
|---|
| | 321 | } |
|---|
| | 322 | |
|---|
| | 323 | if (is_array($posts) && !empty ($posts)) { |
|---|
| | 324 | foreach ($posts as $post) { |
|---|
| | 325 | $body .= "<div class=\"frontpage-blog-summary\">"; |
|---|
| | 326 | $body .= "<h4>" . $post->title . "</h4>"; |
|---|
| | 327 | $body .= "<p class=\"frontpage-blog-date\">" . strftime("%B %d, %Y", $post->posted) . "</p>"; |
|---|
| | 328 | $body .= "<p class=\"frontpage-blog-from\">" . __gettext("From:") . " <a href=\"{$CFG->wwwroot}" . user_info("username", $post->weblog) . "\">" . user_info("name", $post->weblog) . "</a> - "; |
|---|
| | 329 | $body .= "<a href=\"{$CFG->wwwroot}" . user_info("username", $post->weblog) . "/weblog/" . $post->ident . ".html\">" . __gettext("Read more") . "</a></p>"; |
|---|
| | 330 | $body .= "</div>"; |
|---|
| | 331 | } |
|---|
| | 332 | } |
|---|
| | 333 | |
|---|
| | 334 | return $body; |
|---|
| | 335 | } |
|---|
| 284 | | |
|---|
| 285 | | } |
|---|
| 286 | | |
|---|
| 287 | | // Removes all widgets for a user |
|---|
| 288 | | |
|---|
| 289 | | function blog_user_delete($object_type, $event, $object) { |
|---|
| 290 | | |
|---|
| 291 | | global $CFG, $data; |
|---|
| 292 | | if (!empty($object->ident) && $object_type == "user" && $event == "delete") { |
|---|
| 293 | | if ($posts = get_records_sql("select * from {$CFG->prefix}weblog_posts where owner = {$object->ident} or weblog = {$object->ident}")) { |
|---|
| 294 | | foreach($posts as $post_info) { |
|---|
| 295 | | $post_info = plugin_hook("weblog_post","delete",$post_info); |
|---|
| 296 | | if (!empty($post_info)) { |
|---|
| 297 | | delete_records('weblog_posts','ident',$post_info->ident); |
|---|
| 298 | | delete_records('weblog_comments','post_id',$post_info->ident); |
|---|
| 299 | | delete_records('weblog_watchlist','weblog_post',$post_info->ident); |
|---|
| 300 | | delete_records('tags','tagtype','weblog','ref',$post_info->ident); |
|---|
| 301 | | } |
|---|
| 302 | | } |
|---|
| 303 | | } |
|---|
| 304 | | execute_sql("update {$CFG->prefix}weblog_comments set owner = -1 where owner = {$object->ident}",false); |
|---|
| 305 | | delete_records('weblog_watchlist','owner',$object->ident); |
|---|
| 306 | | } |
|---|
| 307 | | return $object; |
|---|
| 308 | | |
|---|
| 309 | | } |
|---|
| 310 | | |
|---|
| | 396 | } |
|---|
| | 397 | } |
|---|
| | 398 | execute_sql("update {$CFG->prefix}weblog_comments set owner = -1 where owner = {$object->ident}", false); |
|---|
| | 399 | delete_records('weblog_watchlist', 'owner', $object->ident); |
|---|
| | 400 | } |
|---|
| | 401 | return $object; |
|---|
| | 402 | |
|---|
| | 403 | } |
|---|
| | 404 | |
|---|
| | 405 | /** |
|---|
| | 406 | * Function that extends the display_input_field functionality for support:<br> |
|---|
| | 407 | * <ul> |
|---|
| | 408 | * <li>the 'select' input field that receives an assosiative array as parameter</li> |
|---|
| | 409 | * </ul> |
|---|
| | 410 | * @param array $parameter an array where: |
|---|
| | 411 | * 0 => input name to display (for forms etc) |
|---|
| | 412 | * 1 => data |
|---|
| | 413 | * 2 => type of input field |
|---|
| | 414 | * 3 => reference name (for tag fields and so on) |
|---|
| | 415 | * 4 => ID number (if any) |
|---|
| | 416 | * 5 => Owner |
|---|
| | 417 | * 6 => Array() |
|---|
| | 418 | *@return string the string that represent the specified input type |
|---|
| | 419 | */ |
|---|
| | 420 | function blog_display_input_field($parameter) { |
|---|
| | 421 | $cleanid= $parameter[0]; |
|---|
| | 422 | |
|---|
| | 423 | switch ($parameter[2]) { |
|---|
| | 424 | |
|---|
| | 425 | case "vertical_radio": |
|---|
| | 426 | foreach($parameter[6] as $option){ |
|---|
| | 427 | $run_result .= "<input type=\"radio\" name=\"".$parameter[0]."\" value=\"$option\" id=\"".$cleanid."\" "; |
|---|
| | 428 | if($parameter[1]==$option){$run_result .= " checked ";} |
|---|
| | 429 | $run_result .= " /> ".$option." "; |
|---|
| | 430 | } |
|---|
| | 431 | break; |
|---|
| | 432 | |
|---|
| | 433 | case "radio": |
|---|
| | 434 | foreach($parameter[6] as $option){ |
|---|
| | 435 | $run_result .= "<input type=\"radio\" name=\"".$parameter[0]."\" value=\"$option\" id=\"".$cleanid."\" "; |
|---|
| | 436 | if($parameter[1]==$option){$run_result .= " checked ";} |
|---|
| | 437 | $run_result .= " />".$option."<br>"; |
|---|
| | 438 | } |
|---|
| | 439 | break; |
|---|
| | 440 | |
|---|
| | 441 | case "select": |
|---|
| | 442 | $run_result .= "<select name=\"".$parameter[0]."\" id=\"".$cleanid."\" />"; |
|---|
| | 443 | foreach($parameter[6] as $option){ |
|---|
| | 444 | $run_result .="<option value=\"".htmlspecialchars(stripslashes($option), ENT_COMPAT, 'utf-8')."\" "; |
|---|
| | 445 | if($parameter[1]==$option){$run_result .= " selected ";} |
|---|
| | 446 | $run_result .= " >$option</option>"; |
|---|
| | 447 | } |
|---|
| | 448 | $run_result .="</select><br>"; |
|---|
| | 449 | break; |
|---|
| | 450 | |
|---|
| | 451 | case "selectg": |
|---|
| | 452 | $run_result .= "<select name=\"".$parameter[0]."\" id=\"".$cleanid."\" />"; |
|---|
| | 453 | foreach($parameter[6] as $optiong => $grp){ |
|---|
| | 454 | $run_result .="<optgroup label=\"".htmlspecialchars(stripslashes($optiong), ENT_COMPAT, 'utf-8')."\" />"; |
|---|
| | 455 | foreach($grp as $option){ |
|---|
| | 456 | $run_result .="<option value=\"".htmlspecialchars(stripslashes($optiong.", $option $optiong"), ENT_COMPAT, 'utf-8')."\" "; |
|---|
| | 457 | if($parameter[1]=="$option $optiong"){$run_result .= " selected ";} |
|---|
| | 458 | $run_result .= " >$option</option> |
|---|
| | 459 | "; |
|---|
| | 460 | } |
|---|
| | 461 | $run_result .="</optgroup><br>"; |
|---|
| | 462 | } |
|---|
| | 463 | $run_result .="</select><br>"; |
|---|
| | 464 | break; |
|---|
| | 465 | |
|---|
| | 466 | case "date_select": |
|---|
| | 467 | case "selectd": |
|---|
| | 468 | $par = explode("/",$parameter[1]); |
|---|
| | 469 | $run_result .= " |
|---|
| | 470 | <script language=\"JavaScript\"> |
|---|
| | 471 | function select_date(form){ |
|---|
| | 472 | var date = \"\"+form.dd.value+\"/\"+form.mm.value+\"/\"+form.aaaa.value; |
|---|
| | 473 | form.$cleanid.value = date; |
|---|
| | 474 | } |
|---|
| | 475 | </script>"; |
|---|
| | 476 | for($i=0;$i<31;$i++){ |
|---|
| | 477 | $data['dd'][] = ($i+1); |
|---|
| | 478 | } |
|---|
| | 479 | for($i=0;$i<12;$i++){ |
|---|
| | 480 | $data['mm'][] = ($i+1); |
|---|
| | 481 | } |
|---|
| | 482 | $ya = getdate(); |
|---|
| | 483 | for($i=0;$i<100;$i++){ |
|---|
| | 484 | $data['aaaa'][] = (($ya['year']-99)+$i); |
|---|
| | 485 | } |
|---|
| | 486 | $i = 0; |
|---|
| | 487 | foreach($data as $key=>$option){ |
|---|
| | 488 | $run_result .= "$key <select name=\"".$key."\" onchange=\"select_date(this.form)\" />"; |
|---|
| | 489 | foreach($option as $valor){ |
|---|
| | 490 | $run_result .="<option value=\"".htmlspecialchars(stripslashes($valor), ENT_COMPAT, 'utf-8')."\" "; |
|---|
| | 491 | if($par[$i]==$valor){$run_result .= " selected ";} |
|---|
| | 492 | $run_result .= " >$valor</option>\n"; |
|---|
| | 493 | } |
|---|
| | 494 | $run_result .="</select> "; |
|---|
| | 495 | $i++; |
|---|
| | 496 | } |
|---|
| | 497 | $run_result .=" |
|---|
| | 498 | <input type=\"hidden\" name=\"".$parameter[0]."\" value=\"".$parameter[1]."\" id=\"".$cleanid."\" >"; |
|---|
| | 499 | break; |
|---|
| | 500 | |
|---|
| | 501 | } |
|---|
| | 502 | return $run_result; |
|---|
| | 503 | } |
|---|
| | 504 | |
|---|
| | 505 | function blog_validate_input_field(){ |
|---|
| | 506 | |
|---|
| | 507 | } |
|---|