function edit($id = 0) { if (!$id) { redirect('admin/news/index'); } $this->load->library('validation'); $this->validation->set_rules($this->rules); $this->validation->set_fields(); $article = $this->news_m->getArticle($id, 'all'); if ($this->validation->run()) { if ($this->news_m->updateArticle($_POST, $id)) { $this->session->set_flashdata(array('success' => 'The article "' . $this->input->post('title') . '" was updated.')); // The twitter module is here, and enabled! if ($this->settings->item('twitter_news') == 1 && ($article->status != 'live' && $this->input->post('status') == 'live')) { $url = shorten_url('news/' . $this->input->post('created_on_year') . '/' . str_pad($this->input->post('created_on_month'), 2, '0', STR_PAD_LEFT) . '/' . url_title($this->input->post('title'))); $this->load->module_model('twitter', 'twitter_m'); $this->twitter_m->update(sprintf('Posted "%s" %s', $this->input->post('title'), $url)); } // End twitter code } else { $this->session->set_flashdata(array('error' => 'An error occurred.')); } redirect('admin/news/index'); } // Go through all the known fields and get the post values foreach (array_keys($this->rules) as $field) { if (isset($_POST[$field])) { $article->{$field} = $this->validation->{$field}; } } $this->data->article =& $article; // Load WYSIWYG editor $this->layout->extra_head($this->load->view('fragments/wysiwyg', $this->data, TRUE)); $this->layout->create('admin/form', $this->data); }
/** * Edit news article * @access public * @param int $id the ID of the news article to edit * @return void */ public function edit($id = 0) { $date = $this->input->post('date'); $date = explode('/', $date); $id or redirect('admin/news'); $this->load->library('form_validation'); $this->form_validation->set_rules($this->validation_rules); $article = $this->news_m->get($id); if ($this->form_validation->run()) { $result = $this->news_m->update($id, array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'intro' => $this->input->post('intro'), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on_hour' => $this->input->post('created_on_hour'), 'created_on_minute' => $this->input->post('created_on_minute'), 'created_on_day' => $date[1], 'created_on_month' => $date[0], 'created_on_year' => $date[2])); if ($result) { $this->session->set_flashdata(array('success' => sprintf($this->lang->line('news_edit_success'), $this->input->post('title')))); // The twitter module is here, and enabled! if ($this->settings->item('twitter_news') == 1 && ($article->status != 'live' && $this->input->post('status') == 'live')) { $url = shorten_url('news/' . $date[2] . '/' . str_pad($date[0], 2, '0', STR_PAD_LEFT) . '/' . url_title($this->input->post('title'))); $this->load->model('twitter/twitter_m'); if (!$this->twitter_m->update(sprintf($this->lang->line('news_twitter_posted'), $this->input->post('title'), $url))) { $this->session->set_flashdata('error', lang('news_twitter_error') . ": " . $this->twitter->last_error['error']); } } // End twitter code } else { $this->session->set_flashdata(array('error' => $this->lang->line('news_edit_error'))); } // Redirect back to the form or main page $this->input->post('btnAction') == 'save_exit' ? redirect('admin/news') : redirect('admin/news/edit/' . $id); } // Go through all the known fields and get the post values foreach (array_keys($this->validation_rules) as $field) { if (isset($_POST[$field])) { $article->{$field} = $this->form_validation->{$field}; } } // Load WYSIWYG editor $this->template->title($this->module_details['name'], sprintf(lang('news_edit_title'), $article->title))->append_metadata($this->load->view('fragments/wysiwyg', $this->data, TRUE))->append_metadata(js('news_form.js', 'news'))->set('article', $article)->build('admin/form'); }
function edit($id = 0) { if (!$id) { redirect('admin/news/index'); } $this->load->library('validation'); $this->validation->set_rules($this->rules); $this->validation->set_fields(); $article = $this->news_m->getArticle($id, 'all'); $spaw_cfg = array('name' => 'body', 'content' => $article->body); $this->load->library('spaw', $spaw_cfg); // setting directories for a SPAW editor instance: $this->spaw->setConfigItem('PG_SPAWFM_DIRECTORIES', array(array('dir' => '/uploads/news/flash/', 'caption' => 'Flash movies', 'params' => array('allowed_filetypes' => array('flash'))), array('dir' => '/uploads/news/images/', 'caption' => 'Images', 'params' => array('default_dir' => true, 'allowed_filetypes' => array('images')))), SPAW_CFG_TRANSFER_SECURE); if ($this->validation->run()) { if ($this->news_m->updateArticle($_POST, $id)) { $this->session->set_flashdata(array('success' => 'The article "' . $this->input->post('title') . '" was updated.')); // The twitter module is here, and enabled! $this->load->module_config('twitter', 'twitter'); if ($this->settings->item('twitter_news') == 1 && ($article->status != 'live' && $this->input->post('status') == 'live')) { $url = shorten_url('news/' . $this->input->post('created_on_year') . '/' . str_pad($this->input->post('created_on_month'), 2, '0', STR_PAD_LEFT) . '/' . url_title($this->input->post('title'))); $this->load->module_model('twitter', 'twitter_m'); $this->twitter_m->update(sprintf('Posted "%s" %s', $this->input->post('title'), $url)); } // End twitter code } else { $this->session->set_flashdata(array('error' => 'An error occurred.')); } redirect('admin/news/index'); } // Go through all the known fields and get the post values foreach (array_keys($this->rules) as $field) { if (isset($_POST[$field])) { $article->{$field} = $this->validation->{$field}; } } $this->data->article =& $article; $this->layout->create('admin/form', $this->data); }
} else { if ($_POST['url2']) { $name2 = $_POST['url2']; $filecontents2 = wget($_POST['url2']); } else { if ($_FILES['file2']['tmp_name']) { $source2 = 'Uploaded'; $name2 = $_FILES['file2']['name']; $filecontents2 = read_file_contents($_FILES['file2']['tmp_name']); } else { print "<p>No document was specified for Document 2.</p>"; } } } $shorturl1 = htmlspecialchars(shorten_url($name1)); $shorturl2 = htmlspecialchars(shorten_url($name2)); echo '<html>' . "\r\n"; echo "<head><title>Duplicate Detector: {$shorturl1} x {$shorturl2}</title></head>\r\n"; echo '<body>' . "\r\n"; $minwords = $_GET['minwords'] ? $_GET['minwords'] : $_POST['minwords']; if (!$minwords || $minwords < 2) { $minwords = 2; } $minchars = $_GET['minchars'] ? $_GET['minchars'] : $_POST['minchars']; if (!$minchars) { $minchars = 13; } $removequotations = $_GET['removequotations'] ? $_GET['removequotations'] : $_POST['removequotations']; $removenumbers = $_GET['removenumbers'] ? $_GET['removenumbers'] : $_POST['removenumbers']; print '<p><i><a href=".">Return to home page</a></i></p>'; print '<p><b>Warning</b>: Duplication Detector may in some cases give no results or incomplete results. This does not necessarily indicate copying has not occurred. Manually examine the source document to verify.</p>';
function edit($id = 0) { if (!$id) { redirect('admin/news'); } $this->load->library('validation'); $this->validation->set_rules($this->rules); $this->validation->set_fields(); $article = $this->news_m->get($id); if ($this->validation->run()) { $result = $this->news_m->update($id, array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'intro' => $this->input->post('intro'), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on_hour' => $this->input->post('created_on_hour'), 'created_on_minute' => $this->input->post('created_on_minute'), 'created_on_day' => $this->input->post('created_on_day'), 'created_on_month' => $this->input->post('created_on_month'), 'created_on_year' => $this->input->post('created_on_year'))); if ($result) { $this->session->set_flashdata(array('success' => sprintf($this->lang->line('news_edit_success'), $this->input->post('title')))); // The twitter module is here, and enabled! if ($this->settings->item('twitter_news') == 1 && ($article->status != 'live' && $this->input->post('status') == 'live')) { $url = shorten_url('news/' . $this->input->post('created_on_year') . '/' . str_pad($this->input->post('created_on_month'), 2, '0', STR_PAD_LEFT) . '/' . url_title($this->input->post('title'))); $this->load->model('twitter/twitter_m'); if (!$this->twitter_m->update(sprintf($this->lang->line('news_twitter_posted'), $this->input->post('title'), $url))) { $this->session->set_flashdata('error', lang('news_twitter_error') . ": " . $this->twitter->last_error['error']); } } // End twitter code } else { $this->session->set_flashdata(array('error' => $this->lang->line('news_edit_error'))); } redirect('admin/news'); } // Go through all the known fields and get the post values foreach (array_keys($this->rules) as $field) { if (isset($_POST[$field])) { $article->{$field} = $this->validation->{$field}; } } $this->data->article =& $article; // Load WYSIWYG editor $this->template->append_metadata($this->load->view('fragments/wysiwyg', $this->data, TRUE)); $this->template->build('admin/form', $this->data); }
$short_url = shorten_url($_POST['full_url']); $long_url = $_POST['full_url']; require 'display_url.view.php'; } else { require 'form.view.php'; } } elseif (isset($_POST['specify_short'])) { // Validate the full URL input via functions.php $error = validate_full_url(); // Make sure user specified a short form if (strlen(trim($_POST['short_url'])) == 0) { $error['short_url'] = "You must specify a shortened form of the URL."; } if ($error == FALSE) { // Attempt to shorten the URL via functions.php $short_url = shorten_url($_POST['full_url'], $short_domain . $_POST['short_url']); // UGLY!!! if (is_array($short_url) && array_key_exists('error_short_url', $short_url)) { $error['short_url'] = $short_url['error_short_url']; require 'form.view.php'; exit; } $long_url = $_POST['full_url']; require 'display_url.view.php'; } else { require 'form.view.php'; } } elseif (isset($_POST['retrieve_short'])) { $long_url = get_long_url($_POST['short_url']); if (is_array($long_url) && array_key_exists('error_short_url', $long_url)) { $error['short_url'] = $long_url['error_short_url'];
$marker_color = "red"; break; default: $color = "danger"; $marker_color = "red"; break; } $label = chr(65 + $key); $marker_info = "markers=color:" . $marker_color . "|label:" . $label . "|" . urlencode($value["address"]); $gmap_url .= $marker_info; if ($value !== end($store_info)) { $gmap_url .= "&"; } $payload["attachments"][$key] = array("fallback" => $label . $value["name"], "pretext" => $label . $value["name"], "text" => $value["address"], "color" => $color, "fields" => array(array("title" => "混雑状況", "value" => $value["text"]))); } $short_url = shorten_url($gmap_url); //$payload["text"] = $gmap_url; $payload["text"] = $short_url["id"]; $payload = json_encode($payload); echo $payload; /* * mapのURLが長いので短縮する * googleのapishortenerを利用してメールアドレスを短縮する * レスポンス内容例 * { * "kind": "urlshortener#url", * "id": "http://goo.gl/fbsS", * "longUrl": "http://www.google.com/" * } * */ function shorten_url($url)
/** * processes BBCode links */ function do_bbcode_url($action, $attributes, $content, $params, &$node_object) { // 1) the code is validated if ($action == 'validate') { // the code has been eneterd like this: [url]http://.../[/url] if (!isset($attributes['default'])) { // is it a valid url? return is_valid_url($content); } // the code has been eneterd like this: [url=http://.../]Text[/url] // is it a valid url? return is_valid_url($attributes['default']); } else { // the code has been eneterd like this: [url]http://.../[/url] if (!isset($attributes['default'])) { return '<a href="' . htmlspecialchars($content) . '">' . htmlspecialchars(shorten_url($content)) . '</a>'; } // the code has been eneterd like this: [url=http://.../]Text[/url] return '<a href="' . htmlspecialchars($attributes['default']) . '">' . $content . '</a>'; } }
function top_opt_tweet_post($oldest_post) { global $wpdb; $post = get_post($oldest_post); $content = ""; $to_short_url = true; $shorturl = ""; $tweet_type = get_option('top_opt_tweet_type'); $additional_text = get_option('top_opt_add_text'); $additional_text_at = get_option('top_opt_add_text_at'); $include_link = get_option('top_opt_include_link'); $custom_hashtag_option = get_option('top_opt_custom_hashtag_option'); $custom_hashtag_field = get_option('top_opt_custom_hashtag_field'); $twitter_hashtags = get_option('top_opt_hashtags'); $url_shortener = get_option('top_opt_url_shortener'); $custom_url_option = get_option('top_opt_custom_url_option'); $to_short_url = get_option('top_opt_use_url_shortner'); $use_inline_hashtags = get_option('top_opt_use_inline_hashtags'); $hashtag_length = get_option('top_opt_hashtag_length'); if ($include_link != "false") { $permalink = get_permalink($oldest_post); if ($custom_url_option) { $custom_url_field = get_option('top_opt_custom_url_field'); if (trim($custom_url_field) != "") { $permalink = trim(get_post_meta($post->ID, $custom_url_field, true)); } } if ($to_short_url) { if ($url_shortener == "bit.ly") { $bitly_key = get_option('top_opt_bitly_key'); $bitly_user = get_option('top_opt_bitly_user'); $shorturl = shorten_url($permalink, $url_shortener, $bitly_key, $bitly_user); } else { $shorturl = shorten_url($permalink, $url_shortener); } } else { $shorturl = $permalink; } } if ($tweet_type == "title" || $tweet_type == "titlenbody") { $title = stripslashes($post->post_title); $title = strip_tags($title); $title = preg_replace('/\\s\\s+/', ' ', $title); } else { $title = ""; } if ($tweet_type == "body" || $tweet_type == "titlenbody") { $body = stripslashes($post->post_content); $body = strip_tags($body); $body = preg_replace('/\\s\\s+/', ' ', $body); } else { $body = ""; } if ($tweet_type == "titlenbody") { if ($title == null) { $content = $body; } elseif ($body == null) { $content = $title; } else { $content = $title . " - " . $body; } } elseif ($tweet_type == "title") { $content = $title; } elseif ($tweet_type == "body") { $content = $body; } if ($additional_text != "") { if ($additional_text_at == "end") { $content = $content . " - " . $additional_text; } elseif ($additional_text_at == "beginning") { $content = $additional_text . ": " . $content; } } $hashtags = ""; $newcontent = ""; if ($custom_hashtag_option != "nohashtag") { if ($custom_hashtag_option == "common") { //common hashtag $hashtags = $twitter_hashtags; } elseif ($custom_hashtag_option == "custom") { if (trim($custom_hashtag_field) != "") { $hashtags = trim(get_post_meta($post->ID, $custom_hashtag_field, true)); } } elseif ($custom_hashtag_option == "categories") { $post_categories = get_the_category($post->ID); if ($post_categories) { foreach ($post_categories as $category) { $tagname = str_replace(".", "", str_replace(" ", "", $category->cat_name)); if ($use_inline_hashtags) { if (strrpos($content, $tagname) === false) { $hashtags = $hashtags . "#" . $tagname . " "; } else { $newcontent = preg_replace('/\\b' . $tagname . '\\b/i', "#" . $tagname, $content, 1); } } else { $hashtags = $hashtags . "#" . $tagname . " "; } } } } elseif ($custom_hashtag_option == "tags") { $post_tags = get_the_tags($post->ID); if ($post_tags) { foreach ($post_tags as $tag) { $tagname = str_replace(".", "", str_replace(" ", "", $tag->name)); if ($use_inline_hashtags) { if (strrpos($content, $tagname) === false) { $hashtags = $hashtags . "#" . $tagname . " "; } else { $newcontent = preg_replace('/\\b' . $tagname . '\\b/i', "#" . $tagname, $content, 1); } } else { $hashtags = $hashtags . "#" . $tagname . " "; } } } } if ($newcontent != "") { $content = $newcontent; } } if ($include_link != "false") { if (!is_numeric($shorturl) && strncmp($shorturl, "http", strlen("http")) == 0) { } else { return "OOPS!!! problem with your URL shortning service. Some signs of error " . $shorturl . "."; } } $message = set_tweet_length($content, $shorturl, $hashtags, $hashtag_length); $status = urlencode(stripslashes(urldecode($message))); if ($status) { $poststatus = top_update_status($message); if ($poststatus == true) { return "Success! Just tweeted successfully."; } else { return "Oh no! Something went wrong. Please try again."; } } return "Oh no! Looks like there are problems. Please email flavio@themana.gr."; }
/** * from https://github.com/wikigit/Duplication-Detector * * Copyright (c) 2011, Derrick Coetzee (User:Dcoetzee) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ function do_copycat($formatter, $params = array()) { global $DBInfo; $charset = $DBInfo->charset; //ini_set('display_errors',1); //error_reporting(E_ALL|E_STRICT); // Get starting time to measure time elapsed later. $time_start = microtime_float(); $source1 = 'Downloaded'; if (!empty($params['source'])) { $source1 = 'Text'; $name1 = 'source'; $filecontents1 = $params['source']; } else { if (!empty($params['url0']) && preg_match("@^https?://@", $params['url0'])) { $name1 = $params['url0']; $filecontents1 = wget($params['url0']); } else { if (isset($_FILES['file0']) && $_FILES['file0']['tmp_name']) { $source1 = 'Uploaded'; $name1 = $_FILES['file0']['name']; $filecontents1 = read_file_contents($_FILES['file0']['tmp_name']); } else { $source1 = 'Wiki'; $name1 = $formatter->page->name; $filecontents1 = $formatter->page->_get_raw_body(); } } } $source2 = 'Downloaded'; if (!empty($params['url']) && preg_match("@^https?://@", $params['url'])) { $name2 = $params['url']; $filecontents2 = wget($params['url']); } else { if (isset($_FILES['file']) && $_FILES['file']['tmp_name']) { $source2 = 'Uploaded'; $name2 = $_FILES['file']['name']; $filecontents2 = read_file_contents($_FILES['file']['tmp_name']); } else { if (!empty($params['target'])) { $source2 = 'Text'; $name2 = 'target'; $filecontents2 = $params['target']; } else { $params['.title'] = _("Copycat detector"); $formatter->send_header('', $params); $formatter->send_title('', '', $params); $comp_btn = _("Detect"); $diff_btn = _("Diff"); $raw_check = _("Raw"); $source_lab = _("Source (URL or PageName)"); $target_lab = _("Target (URL)"); $min_num_words = _("Minimum number of words"); $min_num_chars = _("Minimum number of characters"); $remove_quotes = _("Remove quotations"); $remove_number = _("Remove numbers"); $or = _("or"); echo <<<FORM <form name="comparesimple" method="post"> <input type="hidden" name="action" value="copycat" /> {$source_lab}: <input style="width: 99%" type="text" name="url0" value="{$name1}" size="120"><br/> {$or} <br /> <textarea style="width: 100%; height: 408px; box-sizing: border-box" name="source" cols="80" rows="10"> </textarea> <br/> {$target_lab}: <input style="width: 99%" type="text" name="url" size="120"><br /> {$or} <br /> <textarea style="width: 100%; height: 408px; box-sizing: border-box" name="target" cols="80" rows="10"> </textarea> <br/> {$min_num_words}: <input type="text" name="minwords" value="2"><br/> {$min_num_chars}: <input type="text" name="minchars" value="13"><br/> <input type="checkbox" name="removequotations" checked="checked"> {$remove_quotes}<br/> <input type="checkbox" name="removenumbers" checked="checked"> {$remove_number}<br/> <br/> <input type="submit" name="btn_compare" value="{$comp_btn}" /> {$or} <input type="submit" name="btn_diff" value="{$diff_btn}" /> <input type="checkbox" name="raw" /> {$raw_check} </form> FORM; $formatter->send_footer('', $params); return; } } } $shorturl1 = htmlspecialchars(shorten_url($name1)); $shorturl2 = htmlspecialchars(shorten_url($name2)); $title = "Duplicate Detector: {$shorturl1} v {$shorturl2}"; $button_diff = !empty($params['btn_diff']) ? true : false; if ($button_diff) { $diff = get_diff($filecontents1, $filecontents2, $params); if (!empty($params['raw'])) { header("Content-Type: text/plain"); echo $diff; return; } $params['.title'] = "Diff: {$shorturl1} v {$shorturl2}"; $formatter->send_header('', $params); $formatter->send_title('', '', $params); if (isset($diff[0])) { echo "<div id='wikiDiffPreview'>\n"; echo $formatter->processor_repl('diff', $diff, $params); echo "</div>\n"; } $formatter->send_footer('', $params); return; } $minwords = $params['minwords']; if (!$minwords || $minwords < 2) { $minwords = 2; } $minchars = $params['minchars']; if (!$minchars) { $minchars = 13; } $removequotations = $params['removequotations']; $removenumbers = $params['removenumbers']; $params['.title'] = $title; $formatter->send_header('', $params); $formatter->send_title('', '', $params); print '<p><b>Warning</b>: Duplication Detector may in some cases give no results or incomplete results. This does not necessarily indicate copying has not occurred. Manually examine the source document to verify.</p>'; print "<h2>Comparing documents for duplicated text:</h2>"; print '<ul>'; if (preg_match('/^https?:\\/\\//', $name1)) { print '<li><a href="' . htmlspecialchars($name1) . '">' . htmlspecialchars($name1) . '</a></li>'; } else { print '<li>' . htmlspecialchars($name1) . '</li>'; } if (preg_match('/^https?:\\/\\//', $name2)) { print '<li><a href="' . htmlspecialchars($name2) . '">' . htmlspecialchars($name2) . '</a></li>'; } else { print '<li>' . htmlspecialchars($name2) . '</li>'; } print '</ul>'; echo "<p>", "\n"; $terms1 = get_terms($name1, $source1, $filecontents1, $removenumbers, $removequotations, $charset); $terms2 = get_terms($name2, $source2, $filecontents2, $removenumbers, $removequotations, $charset); // print("terms1: " . join(',', $terms1) . "\n"); // print("terms2: " . join(',', $terms2) . "\n"); $terms1_posts = compute_posts($terms1, $minwords); $matches1 = compute_matches($terms1, $terms2, $terms1_posts, $minwords); echo "<h3>Total match candidates found: ", count($matches1), "</h3>", "\n"; echo " (before eliminating redundant matches)</p>", "\n"; echo "</p>", "\n"; usort($matches1, 'cmp_by_length_desc'); $already_matched_phrases = (array) null; $num_matches = 0; $context_words = 30; $min_context_words = 6; $max_context_words = 20; echo "<h2>Matched phrases:</h2>", "\n"; foreach ($matches1 as $value) { list($pos1, $pos2, $length, $phrase) = $value; $skip = 0; foreach ($already_matched_phrases as $already_phrase) { if (strpos($already_phrase, $phrase) !== false) { $skip = 1; break; } } $characters = mb_strlen($phrase, $charset); if (!$skip && $characters >= $minchars) { if ($length > $context_words - $min_context_words) { print "<p><ins class='diff-added'>{$phrase}</ins>" . " ({$length} words, {$characters} characters)</p>"; } else { $context_len = ($context_words - $length) / 2; if ($context_len * 2 >= $max_context_words) { $context_len = $max_context_words / 2; } $phraseprefix1 = join(' ', array_slice($terms1, max($pos1 - $context_len, 0), $pos1 - max($pos1 - $context_len, 0))); $phrasesuffix1 = join(' ', array_slice($terms1, $pos1 + $length, min(count($terms1) - ($pos1 + $length), $context_len))); $phraseprefix2 = join(' ', array_slice($terms2, max($pos2 - $context_len, 0), $pos2 - max($pos2 - $context_len, 0))); $phrasesuffix2 = join(' ', array_slice($terms2, $pos2 + $length, min(count($terms2) - ($pos2 + $length), $context_len))); print "<p>{$phraseprefix1} <ins class='diff-added'>{$phrase}</ins> {$phrasesuffix1}<br/>"; print "{$phraseprefix2} <ins class='diff-added'>{$phrase}</ins> {$phrasesuffix2}<br/>"; print "({$length} words, {$characters} characters)</p>"; } $num_matches++; } $already_matched_phrases[] = $phrase; } echo "<h3>Matching phrases found: ", $num_matches, "<h3>\n"; $time_delta = microtime_float() - $time_start; echo '<p>', 'Elapsed time:', $time_delta, '</p>'; $formatter->send_footer('', $params); return; }
<?php ##################################################################################################### /* exec:~shorten|20|0|0|1|*||||php scripts/shorten.php %%trailing%% */ ##################################################################################################### require_once "lib.php"; $trailing = $argv[1]; $short = shorten_url($trailing); if ($short === False) { privmsg(" error"); } else { privmsg(" {$short}"); } #####################################################################################################
/** * Parse the supplied text for any kind of hyperlinks and "linkify" them. * Assumes the text provided has already been ran through filter(). * * @param $string * @param bool|false $is_admin * @param bool|false $parse_video * @param bool|false $embed_video * @return mixed */ public function links($string, $is_admin = FALSE, $parse_video = FALSE, $embed_video = FALSE) { $patterns = array(); $replaces = array(); // Strip Javascript links. $patterns[] = '!\\[url=\\s*j\\s*a\\s*v\\s*a\\s*s\\s*c\\s*r\\s*i\\s*p\\s*t\\s*:.*?\\](.*?)\\[/url\\]!i'; $replaces[] = '$1'; $patterns[] = '!\\[url\\]\\s*j\\s*a\\s*v\\s*a\\s*s\\s*c\\s*r\\s*i\\s*p\\s*t\\s*:(.*?)\\[/url\\]!i'; $replaces[] = '$1'; if ($is_admin) { $patterns[] = '!\\[img\\](.+)\\[/img\\]!i'; $replaces[] = '<img class="bbcode bbcode_img" src="$1">'; } $result = preg_replace($patterns, $replaces, $string); // named [url] tag $result = preg_replace_callback('!\\[url=([^\\]]+)\\](.+?)\\[/url\\]!i', function ($matches) { $url = trim($matches[1]); $text = trim($matches[2]); if (!filter_var($url, FILTER_VALIDATE_URL) && !preg_match('!^/[/_a-zA-Z0-9]+/?!', $url)) { $url = '#'; } return '<a class="auto_link" href="' . $url . '">' . $text . '</a>'; }, $result); // anonymous [url] tag $result = preg_replace_callback('!\\[url\\](.*?)\\[/url\\]!i', function ($matches) { $url = $matches[1]; if (!filter_var($url, FILTER_VALIDATE_URL) && !preg_match('!^/[/_a-zA-Z0-9]+/?!', $url)) { $url = '#'; } return shorten_url($url, $url); }, $result); if ($parse_video) { // youtube video $patterns = array('!\\[yt\\](https?://www\\.youtube\\.com/watch\\?v=([A-Za-z0-9._%-]+)([^\\[]*))\\[/yt\\]!i', '!\\[yt\\](https?://youtu\\.be/([A-Za-z0-9._%-]+)([^\\[]*))\\[/yt\\]!i'); $result = preg_replace_callback($patterns, function ($matches) use($embed_video) { $vid = $matches[2]; if ($embed_video) { // $url = 'https://www.youtube.com/v/' . $vid; return '' . '<object class="auto_link youtube" width="560" height="340">' . '<param name="movie" value="' . $url . '&color1=0x6A7283&color2=0x6A7283"></param>' . '<param name="allowFullScreen" value="true"></param>' . '<param name="allowscriptaccess" value="always"></param>' . '<embed src="' . $url . '&color1=0x6A7283&color2=0x6A7283" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed>' . '</object>'; } else { return $matches[1]; } }, $result); } // email addres $result = preg_replace_callback('!(([.-_\\w\\d]+)(\\.[-_\\w\\d]+)*@([-\\w\\d]+)(\\.[-\\w\\d]+)+)(\\s|$)!i', function ($matches) { $email = trim($matches[1]); return '<a class="auto_link email" href="mailto:' . $email . '">' . str_replace(array('@'), array('[at]'), $email) . '</a>' . $matches[6]; }, $result); // proper links $result = preg_replace_callback('!([">]?)((https?|ftp)://[^\\s"<]+)(["<]?)!i', function ($matches) { $url = trim($matches[2]); return strlen($matches[1]) > 0 ? $matches[0] : $this->_shortenUrl($url, $url) . $matches[4]; }, $result); // plain links $result = preg_replace_callback('!(^|[\\s\\]>\\(])(www.[^<> \\n\\r\\)]+)!i', function ($matches) { $url = trim($matches[2]); return strlen($url) > 0 ? $matches[1] . $this->_shortenUrl('http://' . $url, $url) : $matches[0]; }, $result); return $result; }