function do_header($title = null) { global $session, $settings, $memcache; header('Content-Type: text/html; charset=utf-8'); if ($session->level == 'anonymous') { $cached = $memcache->get('header'); if ($cached !== false) { $this->output .= $cached; return true; } } $topic = array('text' => format_whitespace(format_link($settings->topic_text)), 'nick' => $settings->topic_nick); $timestamp['core'] = md5(sprintf('%s%s', filemtime('templates/core.css'), $settings->site_key)); $timestamp['js'] = md5(sprintf('%s%s', filemtime('statics/fearqdb.js'), $settings->site_key)); $timestamp['fearqdb'] = md5(sprintf('%s%s', filemtime('statics/fearqdb.png'), $settings->site_key)); if ($settings->analytics_code) { $timestamp['ga'] = md5(sprintf('%s%s', filemtime('statics/ga.js'), $settings->site_key)); } $timestamp['zepto'] = md5(sprintf('%s%s', filemtime('statics/zepto.js'), $settings->site_key)); $vars = compact('title', 'topic', 'session', 'timestamp'); $cached = Haanga::Load('header.html', $vars, true); if ($session->level == 'anonymous') { $memcache->set('header', $cached); } $this->output .= $cached; }
private function text_clean($text, $for = 'www_body') { // this is real crap. global $settings, $session; // clean only for www. rss uses the CDATA structure which does not require escaping if ($for == 'www_body' || $for == 'www_comment') { $text = htmlspecialchars($text); } // mark the search criterium if ($session->search && ($for == 'www_body' || $for == 'www_comment')) { $text = highlight($text, $session->search); } // clean special chars from copypasting from irc $text = preg_replace('/[\\x00-\\x09\\x0b-\\x1F\\x7F]/', '', $text); // delete timestamps $text = preg_replace('/^[\\(\\[]?\\d+:\\d+(:\\d+)?[\\)\\]]?\\s/m', '', $text); if ($for == 'www_body' || $for == 'rss_body' || $for == 'rss_title' || $for == 'excerpt') { // add * to mark actions, joins, parts etc $text = preg_replace('/^([a-z0-9\\[\\]\\{\\}_])/smi', '* $1', $text); // :D } // hack for this db. old quotes came this way. so remove this once it's fixed or remove it if you start with a db from scratch. $text = preg_replace("/^\n/", '', $text); if ($for == 'www_body') { // nicks for the website $text = preg_replace_callback('/^<[@\\+\\s]?([a-z0-9\\-\\[\\]\\{\\}_`~\\|]+)>/mi', array($this, 'nick_colour'), $text); } if ($for == 'rss_body' || $for == 'rss_title') { // escape the cdata structure (avoid injections) + nicks for rss // nicks for rss never use < or < because they DON'T WORK for rss readers // < works for some, < for some... so we use () $text = str_replace(']]>', ']]]]><![CDATA[>', $text); // http://en.wikipedia.org/wiki/CDATA#Nesting $text = preg_replace('/<[@\\+\\s]?([a-z0-9\\-\\[\\]\\{\\}_`~\\|]+)>/msi', '($1)', $text); } if ($for == 'excerpt') { $text = preg_replace('/<[@\\+\\s]?([a-z0-9\\-\\[\\]\\{\\}_`~\\|]+)>/msi', '<$1>', $text); } if ($for == 'www_body' || $for == 'rss_body' || $for == 'www_comment') { // don't add links to rss titles! $text = format_link($text); $text = str_replace("\n", '<br />', $text); // respect \s\s to fix asciis $text = format_whitespace($text); } else { $text = str_replace("\n", ' ', $text); } // cut long title if ($for == 'rss_title' || $for == 'www_tweet' || $for == 'excerpt') { if (mb_strlen($text) > 110) { $text = sprintf('%s...', mb_substr($text, 0, 110)); } } return $text; }
public function render_self($options) { return array('html' => format_whitespace($this->title), 'javascript' => null); }
function pieform_element_wysiwyg_get_value(Pieform $form, $element) { $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (isset($element['value'])) { return clean_html($element['value']); } else { if ($form->is_submitted() && isset($global[$element['name']])) { $value = $global[$element['name']]; if (!is_html_editor_enabled()) { $value = format_whitespace($value); } return $value; } else { if (isset($element['defaultvalue'])) { return clean_html($element['defaultvalue']); } } } return null; }
/** * Creates a comment from the given entry * * @param SimpleXMLElement $entry The entry to create the comment from * @param PluginImportLeap $importer The importer * @return array A list of artefact IDs created, to be used with the artefact mapping. */ private static function create_comment(SimpleXMLElement $entry, PluginImportLeap $importer) { $createdartefacts = array(); $comment = new ArtefactTypeComment(); $comment->set('title', (string) $entry->title); $description = PluginImportLeap::get_entry_content($entry, $importer); $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text'; if ($type == 'text') { $description = format_whitespace($description); } $comment->set('description', $description); if ($published = strtotime((string) $entry->published)) { $comment->set('ctime', $published); } if ($updated = strtotime((string) $entry->updated)) { $comment->set('mtime', $updated); } $private = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private'); $comment->set('private', (int) $private); $comment->set('owner', $importer->get('usr')); if (isset($entry->author->name) && strlen($entry->author->name)) { $comment->set('authorname', $entry->author->name); } else { $comment->set('author', $importer->get('usr')); } if (empty(self::$tempview)) { self::create_temporary_view($importer->get('usr')); } $comment->set('onview', self::$tempview); $comment->set('tags', PluginImportLeap::get_entry_tags($entry)); $comment->commit(); array_unshift($createdartefacts, $comment->get('id')); return $createdartefacts; }
function format_notification_whitespace($message, $type = null) { $message = preg_replace('/<br( ?\\/)?>/', '', $message); $message = preg_replace('/^(\\s| |\\xc2\\xa0)*/', '', $message); $message = format_whitespace($message); // @todo: Sensibly distinguish html notifications, notifications where the full text // appears on another page and this is just an abbreviated preview, and text-only // notifications where the entire text must appear here because there's nowhere else // to see it. $replace = $type == 'newpost' || $type == 'feedback' ? '<br>' : '<br><br>'; return preg_replace('/(<br( ?\\/)?>\\s*){2,}/', $replace, $message); }
$count = count_records_select('notification_internal_activity', 'usr = ? AND type IN ( SELECT id FROM {activity_type} WHERE admin = ?)', array($userid, 1)); $sql = 'SELECT a.*, at.name AS type,at.plugintype, at.pluginname FROM {notification_internal_activity} a JOIN {activity_type} at ON a.type = at.id WHERE a.usr = ? AND at.admin = ? ORDER BY ctime DESC'; $records = get_records_sql_array($sql, array($userid, 1), $offset, $limit); } else { $count = count_records_select('notification_internal_activity', 'usr = ? AND type = ?', array($userid, $type)); $sql = 'SELECT a.*, at.name AS type,at.plugintype, at.pluginname FROM {notification_internal_activity} a JOIN {activity_type} at ON a.type = at.id WHERE a.usr = ? AND a.type = ?'; $records = get_records_sql_array($sql, array($userid, $type), $offset, $limit); } } if (empty($records)) { $records = array(); } $data = array(); $star = theme_get_url('images/star.png'); $unread = get_string('unread', 'activity'); foreach ($records as &$r) { $r->date = format_date(strtotime($r->ctime)); $section = 'activity'; if (!empty($r->plugintype)) { $section = $r->plugintype . '.' . $r->pluginname; } $r->type = get_string('type' . $r->type, $section); $r->message = format_whitespace($r->message); } $activity = array('count' => $count, 'offset' => $offset, 'limit' => $limit, 'data' => $records, 'star' => $star, 'unread' => $unread); echo json_encode($activity);
function pieform_element_wysiwyg_get_value(Pieform $form, $element) { global $USER; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (isset($element['value'])) { return $element['value']; } else { if (isset($global[$element['name']])) { $value = $global[$element['name']]; if (!get_account_preference($USER->get('id'), 'wysiwyg')) { $value = format_whitespace($value); } return $value; } else { if (isset($element['defaultvalue'])) { return $element['defaultvalue']; } } } return null; }
/** * Creates a blogpost from the given entry * * @param SimpleXMLElement $entry The entry to create the blogpost from * @param PluginImportLeap $importer The importer * @param int $blogid The blog in which to put the post * @return array A list of artefact IDs created, to be used with the artefact mapping. * There will either be one (the blogpost ID), or two. If there is two, the * second one will be the ID of the file created to hold the out-of-line * content associated with the blogpost */ private static function create_blogpost(SimpleXMLElement $entry, PluginImportLeap $importer, $blogid) { $createdartefacts = array(); $blogpost = new ArtefactTypeBlogPost(); $blogpost->set('title', (string) $entry->title); // If the entry has out of line content, we import that separately as a // file and set the content to refer to it if (isset($entry->content['src']) && isset($entry->content['type'])) { $file = LeapImportFile::create_file($entry, $importer); $createdartefacts[] = $file->get('id'); $content = '<a href="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '"' . ' title="' . hsc($file->get('title')) . '">'; if (is_image_mime_type($file->get('filetype'))) { $content .= '<img src="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '&maxwidth=500&maxheight=500"' . ' alt="' . hsc($file->get('title')) . '">'; } $content .= '</a>'; $blogpost->set('description', $content); } else { $description = PluginImportLeap::get_entry_content($entry, $importer); $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text'; if ($type == 'text') { $description = format_whitespace($description); } $blogpost->set('description', $description); } if ($published = strtotime((string) $entry->published)) { $blogpost->set('ctime', $published); } if ($updated = strtotime((string) $entry->updated)) { $blogpost->set('mtime', $updated); } $draftpost = count($entry->xpath('a:category[(' . $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'readiness#') . ') and @term="Unready"]')) == 1; $blogpost->set('published', $draftpost ? 0 : 1); $blogpost->set('owner', $importer->get('usr')); $blogpost->set('parent', $blogid); $blogpost->set('tags', PluginImportLeap::get_entry_tags($entry)); $blogpost->commit(); array_unshift($createdartefacts, $blogpost->get('id')); return $createdartefacts; }
/** * Logic to figure out how to process an entry into a comment * Used by import_using_strategy() and add_import_entry_request_using_strategy(). * * @param SimpleXMLElement $entry * @param PluginImportLeap $importer * @param unknown_type $strategy * @param array $otherentries * @return array An array of config stuff to either create the comment, or store an import request. * @throws ImportException */ private static function get_entry_data_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries) { if ($strategy != self::STRATEGY_IMPORT_AS_COMMENT) { throw new ImportException($importer, 'TODO: get_string: unknown strategy chosen for importing entry'); } $description = PluginImportLeap::get_entry_content($entry, $importer); $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text'; if ($type == 'text') { $description = format_whitespace($description); } if (isset($entry->author->name) && strlen($entry->author->name)) { $authorname = (string) $entry->author->name; } else { $author = $importer->get('usr'); } return array('owner' => $importer->get('usr'), 'type' => 'comment', 'content' => array('title' => (string) $entry->title, 'description' => $description, 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'private' => (int) PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private'), 'authorname' => isset($authorname) ? $authorname : null, 'author' => isset($author) ? $author : null, 'tags' => PluginImportLeap::get_entry_tags($entry))); }
private static function get_annotationfeedback_entry_data(SimpleXMLElement $entry, PluginImportLeap $importer, $annotationentryid) { $description = PluginImportLeap::get_entry_content($entry, $importer); $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text'; if ($type == 'text') { $description = format_whitespace($description); } if (isset($entry->author->name) && strlen($entry->author->name)) { $authorname = (string) $entry->author->name; } else { $author = $importer->get('usr'); } return array('owner' => $importer->get('usr'), 'type' => 'annotationfeedback', 'parent' => $annotationentryid, 'content' => array('title' => (string) $entry->title, 'description' => $description, 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'authorname' => isset($authorname) ? $authorname : null, 'author' => isset($author) ? $author : null, 'tags' => PluginImportLeap::get_entry_tags($entry), 'private' => (int) PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private'), 'onannotation' => $annotationentryid)); }
public function render_self($options) { $smarty = smarty_core(); $fields = ArtefactTypeContactinformation::get_profile_fields(); foreach ($fields as $f) { try { ${$f} = artefact_instance_from_type($f, $this->get('owner')); $rendered = ${$f}->render_self(array()); $smarty->assign($f, format_whitespace($rendered['html'])); $smarty->assign('hascontent', true); } catch (Exception $e) { } } $template = 'artefact:resume:fragments/contactinformation.'; if (!empty($options['editing'])) { $template .= 'editing.'; } $template .= 'tpl'; return array('html' => $smarty->fetch($template)); }
private static function get_blogpost_entry_data(SimpleXMLElement $entry, PluginImportLeap $importer, $blogentryid) { // If the entry has out of line content, we import that separately as a // file and set the content to refer to it if (LeapImportFile::is_file($entry, $importer)) { $isfile = true; } else { $isfile = false; $description = PluginImportLeap::get_entry_content($entry, $importer); $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text'; if ($type == 'text') { $description = format_whitespace($description); } } return $config = array('isfile' => $isfile, 'owner' => $importer->get('usr'), 'type' => 'blogpost', 'parent' => $blogentryid, 'content' => array('title' => (string) $entry->title, 'description' => isset($description) ? $description : null, 'files' => self::add_files_to_import_entry_request_blogpost($entry, $importer, $blogentryid), 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'published' => PluginImportLeap::is_correct_category_scheme($entry, $importer, 'readiness', 'Unready') ? 0 : 1, 'tags' => PluginImportLeap::get_entry_tags($entry))); }