/** * URL handler * * @param int $user_id - The user_id * @param int $blog_id - The blog_id * @param int $reply_id - The reply_id * @param array $url_data - Data to put in the url's. Everything will get built in the url from this array. * For exmaple, if array('page' => 'blog', 'mode' => 'add') is sent it would be built as blog.php?page=blog&mode=add * Send 'anchor' (if needed) as the anchor for the page which will get added to the end of the url as # . $url_data['anchor'] * @param array $extra_data - Extra data that will be used in the URL when required. * When building the url this function checks the blog_data::$(user|blog|reply) arrays to see if the username, blog title, and/or reply title exist for that (user|blog|reply)_id. * If they do not exist in that array and you would like to manually send it you can send it in this array. array('username' => (the username), 'blog_subject' => (blog title), 'reply_subject' => (reply title)) * These are not required to be sent, just send them if you want/need to. * @param bool $force_no_seo - If set to true this will build a normal url (needed for some places), not the pretty ones with the username, title, etc in. */ function blog_url($user_id, $blog_id = false, $reply_id = false, $url_data = array(), $extra_data = array(), $force_no_seo = false) { global $config, $user, $_SID; blog_plugins::plugin_do('function_blog_url'); // don't call the generate_board_url function a whole bunch of times, get it once and keep using it static $start_url = ''; $start_url = $start_url == '' ? (defined('BLOG_ROOT') ? generate_board_url(true) . BLOG_ROOT : generate_board_url()) . '/' : $start_url; $extras = $anchor = ''; // Add the category stuff if c is in the url static $blog_categories = false; if (isset($_GET['c']) && !isset($url_data['c'])) { $category_id = request_var('c', 0); if ($blog_categories === false) { $blog_categories = get_blog_categories('category_id'); } if (!isset($url_data['page']) && isset($blog_categories[$category_id]) && isset($config['user_blog_seo']) && $config['user_blog_seo'] && !$force_no_seo) { $url_data['page'] = $blog_categories[$category_id]['category_name']; } $url_data['c'] = $category_id; } // Add the blogstyle setting if required if (isset($_GET['blogstyle']) && !isset($url_data['blogstyle'])) { $url_data['blogstyle'] = request_var('blogstyle', ''); } // Handle the anchor if (isset($url_data['anchor'])) { $anchor = '#' . $url_data['anchor']; unset($url_data['anchor']); } else { if ($reply_id) { $anchor = '#r' . $reply_id; } } if (isset($config['user_blog_seo']) && $config['user_blog_seo'] && !$force_no_seo) { $title_match = '/([^a-zA-Z0-9\\s_])/'; // Replace HTML Entities, and non alphanumeric/space/underscore characters $replace_page = true; // match everything except the page if this is set to false if (!isset($url_data['page']) && $user_id !== false) { $username_check = '#&+/\\:?"<>%|'; if ($user_id == $user->data['user_id'] && !strpbrk($user->data['username'], $username_check)) { $url_data['page'] = urlencode($user->data['username']); } else { if (isset($extra_data['username']) && !strpbrk($extra_data['username'], $username_check)) { $url_data['page'] = urlencode($extra_data['username']); } else { if (class_exists('blog_data') && isset(blog_data::$user[$user_id]) && !strpbrk(blog_data::$user[$user_id]['username'], $username_check)) { $url_data['page'] = urlencode(blog_data::$user[$user_id]['username']); } else { $url_data['u'] = $user_id; } } } } else { if (isset($url_data['page']) && $user_id !== false) { $url_data['u'] = $user_id; } } if ($reply_id) { $url_data['r'] = $reply_id; if (!isset($url_data['mode'])) { if (class_exists('blog_data') && array_key_exists($reply_id, blog_data::$reply)) { $url_data['mode'] = utf8_clean_string(blog_data::$reply[$reply_id]['reply_subject']); } else { if (array_key_exists('reply_subject', $extra_data)) { $url_data['mode'] = utf8_clean_string($extra_data['reply_subject']); } } } } else { if ($blog_id) { $url_data['b'] = $blog_id; if (!isset($url_data['mode'])) { if (class_exists('blog_data') && array_key_exists($blog_id, blog_data::$blog)) { $url_data['mode'] = utf8_clean_string(blog_data::$blog[$blog_id]['blog_subject']); } else { if (array_key_exists('blog_subject', $extra_data)) { $url_data['mode'] = utf8_clean_string($extra_data['blog_subject']); } } } } } // Add style= to the url data if it is in there if (isset($_GET['style']) && !isset($url_data['style'])) { $url_data['style'] = request_var('style', ''); } // Add the Session ID if required. if ($_SID) { $url_data['sid'] = $_SID; } if (sizeof($url_data)) { foreach ($url_data as $name => $value) { if ($name == 'page' || $name == 'mode' || $value == '*skip*') { continue; } $extras .= '_' . url_replace($name) . '-' . url_replace($value); } } if (isset($url_data['page']) && $url_data['page']) { if (isset($url_data['mode']) && $url_data['mode']) { $url_data['mode'] = url_replace($url_data['mode']); //return $start_url . "blog/{$url_data['page']}/{$url_data['mode']}{$extras}{$anchor}"; return $start_url . "blog/{$url_data['page']}/{$url_data['mode']}{$extras}.html{$anchor}"; } else { if ($extras || $anchor) { //return $start_url . "blog/{$url_data['page']}/index{$extras}{$anchor}"; return $start_url . "blog/{$url_data['page']}/index{$extras}.html{$anchor}"; } else { //return $start_url . "blog/{$url_data['page']}"; return $start_url . "blog/{$url_data['page']}/"; } } } else { if (isset($url_data['mode']) && $url_data['mode']) { $url_data['mode'] = url_replace($url_data['mode']); //return $start_url . "blog/view/{$url_data['mode']}{$extras}{$anchor}"; return $start_url . "blog/view/{$url_data['mode']}{$extras}.html{$anchor}"; } else { if ($extras || $anchor) { //return $start_url . "blog/index{$extras}{$anchor}"; return $start_url . "blog/index{$extras}.html{$anchor}"; } else { return $start_url . 'blog/'; } } } } // No SEO Url's :( global $phpEx; // Do not add the sid multiple times unset($url_data['sid']); // add this stuff first $extras .= $user_id ? '&u=' . $user_id : (isset($url_data['u']) ? '&u=' . $url_data['u'] : ''); $extras .= $blog_id ? '&b=' . $blog_id : (isset($url_data['b']) ? '&b=' . $url_data['b'] : ''); $extras .= $reply_id ? '&r=' . $reply_id : (isset($url_data['r']) ? '&r=' . $url_data['r'] : ''); if (sizeof($url_data)) { foreach ($url_data as $name => $var) { // Do not add the blog/reply/user id to the url string, they've already been added if ($name == 'b' || $name == 'u' || $name == 'r' || $var == '*skip*') { continue; } $extras .= '&' . $name . '=' . $var; } } $extras = substr($extras, 5); // remove the first & return append_sid($start_url . 'blog.' . $phpEx, $extras) . $anchor; }
if (count($writefiles) > 0) { foreach ($writefiles as $idx => $filearray) { $fd = fopen($filearray['image'], 'w'); fwrite($fd, $filearray['data']); fclose($fd); } } logger(sprintf(MAIL2S9Y_MAILINFO, $from, $subject, strlen($body), $images)); if ($post > 0) { $msg = sprintf(MAIL2S9Y_ALREADY_BLOGGED, $falsefile); echo $msg; mail($from, MAIL2S9Y_POSTING_FAILED, $msg); logger($msg); } else { logger($body); $newbody = url_replace($body); if (isset($params['nl2br']) && $params['nl2br']) { $newbody = nl2br($newbody); } logger($body); $entry = array('id' => '', 'title' => $subject, 'timestamp' => '', 'body' => $newbody, 'extended' => '', 'categories' => array($params['category']), 'isdraft' => 'false', 'allow_comments' => $params['allow_comments']); $cats = ''; if (!($cats = is_categorizer($body))) { $res = serendipity_updertEntry($entry); } else { $res = array(); } if (is_string($res)) { echo MAIL2S9Y_POSTING_FAILED . ': ' . $res; mail($from, MAIL2S9Y_POSTING_FAILED, $res); logger(MAIL2S9Y_POSTING_FAILED . ': ' . $res);