/** * Smarty {list_tags} function plugin * * Type: function<br> * Name: str<br> * Date: June 22, 2006<br> * Purpose: Render a list of tags * @author Richard Mansfield <*****@*****.**> * @author Penny Leach <*****@*****.**> * @version 1.0 * @param array * @param Smarty * @return Internationalized string */ function Dwoo_Plugin_list_tags(Dwoo $dwoo, $tags, $owner) { global $USER; if (!is_array($tags)) { return ''; } if ($owner != $USER->get('id')) { return join(', ', array_map('hsc', $tags)); } foreach ($tags as &$t) { $t = '<a class="tag" href="' . get_config('wwwroot') . 'tags.php?tag=' . urlencode($t) . '">' . hsc(str_shorten_text($t, 50)) . '</a>'; } return join(', ', $tags); }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $result = ''; if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $artefactid) { try { $artefact = $instance->get_artefact_instance($artefactid); } catch (ArtefactNotFoundException $e) { continue; } $icondata = array('id' => $artefactid, 'viewid' => $instance->get('view')); $detailsurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view'); if ($artefact instanceof ArtefactTypeProfileIcon) { require_once 'file.php'; $downloadurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid; $size = filesize(get_dataroot_image_path('artefact/file/profileicons/', $artefactid)); } else { if ($artefact instanceof ArtefactTypeFile) { $downloadurl = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid . '&view=' . $icondata['viewid']; $size = $artefact->get('size'); } } $result .= '<div title="' . hsc($artefact->get('title')) . '">'; $result .= '<div class="fl"><a href="' . hsc($downloadurl) . '">'; $result .= '<img src="' . hsc(call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', $icondata)) . '" alt=""></a></div>'; $result .= '<div style="margin-left: 30px;">'; $result .= '<h4><a href="' . hsc($detailsurl) . '">' . str_shorten_text($artefact->get('title'), 20) . '</a></h4>'; $description = $artefact->get('description'); if ($description) { $result .= '<p style="margin: 0;"><strong>' . hsc($description) . '</strong></p>'; } $result .= '' . display_size($size) . ' | ' . strftime(get_string('strftimedaydate'), $artefact->get('ctime')); $result .= '</div>'; $result .= '</div>'; } } return $result; }
/** * * @package mahara * @subpackage form-element * @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later * @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ function pieform_element_checkboxes(Pieform $form, $element) { /*{{{*/ $global = $form->get_property('method') == 'get' ? $_GET : $_POST; $submitted = $form->is_submitted(); if ($submitted) { $value = isset($global[$element['name']]) ? $global[$element['name']] : array(); } $result = ''; if (count($element['elements']) > 1) { $id = hsc($form->get_name() . '_' . $element['name']) . '_container'; $result .= '<a href="" onclick="pieform_element_checkboxes_update(\'' . $id . '\', true); return false;">' . get_string('selectall') . '</a>' . ' ' . ' <a href="" onclick="pieform_element_checkboxes_update(\'' . $id . '\', false); return false;">' . get_string('selectnone') . '</a>'; } $result .= '<div class="cl"></div>'; $element['name'] .= '[]'; // Number of characters in checkbox labels (use 0 or false for no limit). $labelwidth = isset($element['labelwidth']) ? (int) $element['labelwidth'] : 17; $elementtitle = ''; if (isset($element['title'])) { $elementtitle = '<span class="accessible-hidden">' . $element['title'] . ': </span>'; } foreach ($element['elements'] as $e) { $id = $form->get_name() . '_' . $element['id']; $idsuffix = substr(md5(microtime()), 0, 4); if (!$submitted || !empty($e['disabled'])) { $checked = $e['defaultvalue']; } else { $checked = !empty($value[$e['value']]) || in_array($e['value'], $value); } $attributes = $form->element_attributes($element); $attributes = preg_replace("/\\bid=\"{$id}\"/", "id=\"{$id}{$idsuffix}\"", $attributes); $title = $labelwidth ? str_shorten_text($e['title'], $labelwidth, true) : $e['title']; $result .= '<div class="checkboxes-option"><input type="checkbox" value="' . $e['value'] . '" ' . $attributes . ($checked ? ' checked="checked"' : '') . (!empty($e['disabled']) ? ' disabled' : '') . '>' . ' <label class="checkbox" for="' . $id . $idsuffix . '">' . $elementtitle . Pieform::hsc($title) . '</label></div>'; } $result .= '<div class="cl"></div>'; return $result; }
<?php /** * * @package mahara * @subpackage core * @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later * @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ define('INTERNAL', 1); define('JSON', 1); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'searchlib.php'; $tag = param_variable('tag', null); $limit = param_integer('limit', 10); $offset = param_integer('offset', 0); $sort = param_alpha('sort', 'name'); $type = param_alpha('type', null); $owner = (object) array('type' => 'user', 'id' => $USER->get('id')); $data = get_portfolio_items_by_tag($tag, $owner, $limit, $offset, $sort, $type); build_portfolio_search_html($data); $data->tagdisplay = is_null($tag) ? get_string('alltags') : hsc(str_shorten_text($tag, 50)); $data->tagurl = urlencode($tag); json_reply(false, array('data' => $data));
/** * Always use this function for all emails to users * * @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email * @param object $userfrom user object to send email from. If null, email will come from mahara * @param string $subject email subject * @param string $messagetext text version of email * @param string $messagehtml html version of email (will send both html and text) * @param array $customheaders email headers * @throws EmailException * @throws EmailDisabledException */ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml = '', $customheaders = null) { global $IDPJUMPURL; static $mnetjumps = array(); if (!get_config('sendemail')) { // You can entirely disable Mahara from sending any e-mail via the // 'sendemail' configuration variable return true; } if (empty($userto)) { throw new InvalidArgumentException("empty user given to email_user"); } if (!($mailinfo = can_receive_email($userto))) { throw new EmailDisabledException("email for this user has been disabled"); } // If the user is a remote xmlrpc user, trawl through the email text for URLs // to our wwwroot and modify the url to direct the user's browser to login at // their home site before hitting the link on this site if (!empty($userto->mnethostwwwroot) && !empty($userto->mnethostapp)) { require_once get_config('docroot') . 'auth/xmlrpc/lib.php'; // Form the request url to hit the idp's jump.php if (isset($mnetjumps[$userto->mnethostwwwroot])) { $IDPJUMPURL = $mnetjumps[$userto->mnethostwwwroot]; } else { $mnetjumps[$userto->mnethostwwwroot] = $IDPJUMPURL = PluginAuthXmlrpc::get_jump_url_prefix($userto->mnethostwwwroot, $userto->mnethostapp); } $wwwroot = get_config('wwwroot'); $messagetext = preg_replace_callback('%(' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))%', 'localurl_to_jumpurl', $messagetext); $messagehtml = preg_replace_callback('%href=["\'`](' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))["\'`]%', 'localurl_to_jumpurl', $messagehtml); } require_once 'phpmailer/class.phpmailer.php'; $mail = new phpmailer(); // Leaving this commented out - there's no reason for people to know this //$mail->Version = 'Mahara ' . get_config('release'); $mail->PluginDir = get_config('libroot') . 'phpmailer/'; $mail->CharSet = 'UTF-8'; $smtphosts = get_config('smtphosts'); if ($smtphosts == 'qmail') { // use Qmail system $mail->IsQmail(); } else { if (empty($smtphosts)) { // use PHP mail() = sendmail $mail->IsMail(); } else { $mail->IsSMTP(); // use SMTP directly $mail->Host = get_config('smtphosts'); if (get_config('smtpuser')) { // Use SMTP authentication $mail->SMTPAuth = true; $mail->Username = get_config('smtpuser'); $mail->Password = get_config('smtppass'); } } } if (get_config('bounces_handle') && isset($mailinfo->owner)) { $mail->Sender = generate_email_processing_address($mailinfo->owner, $userto); } if (empty($userfrom) || $userfrom->email == get_config('noreplyaddress')) { if (empty($mail->Sender)) { $mail->Sender = get_config('noreplyaddress'); } $mail->From = get_config('noreplyaddress'); $mail->FromName = isset($userfrom->id) ? display_name($userfrom, $userto) : get_config('sitename'); $customheaders[] = 'Precedence: Bulk'; // Try to avoid pesky out of office responses $messagetext .= "\n\n" . get_string('pleasedonotreplytothismessage') . "\n"; if ($messagehtml) { $messagehtml .= "\n\n<p>" . get_string('pleasedonotreplytothismessage') . "</p>\n"; } } else { if (empty($mail->Sender)) { $mail->Sender = $userfrom->email; } $mail->From = $userfrom->email; $mail->FromName = display_name($userfrom, $userto); } $replytoset = false; if (!empty($customheaders) && is_array($customheaders)) { foreach ($customheaders as $customheader) { $mail->AddCustomHeader($customheader); if (0 === stripos($customheader, 'reply-to')) { $replytoset = true; } } } if (!$replytoset) { $mail->AddReplyTo($mail->From, $mail->FromName); } $mail->Subject = substr(stripslashes($subject), 0, 900); if ($to = get_config('sendallemailto')) { // Admins can configure the system to send all email to a given address // instead of whoever would receive it, useful for debugging. $mail->addAddress($to); $notice = get_string('debugemail', 'mahara', display_name($userto, $userto), $userto->email); $messagetext = $notice . "\n\n" . $messagetext; if ($messagehtml) { $messagehtml = '<p>' . hsc($notice) . '</p>' . $messagehtml; } $usertoname = display_name($userto, $userto, true) . ' (' . get_string('divertingemailto', 'mahara', $to) . ')'; } else { $usertoname = display_name($userto, $userto); if (empty($userto->email)) { throw new EmailException("Cannot send email to {$usertoname} with subject {$subject}. User has no primary email address set."); } $mail->AddAddress($userto->email, $usertoname); $to = $userto->email; } $mail->WordWrap = 79; if ($messagehtml) { $mail->IsHTML(true); $mail->Encoding = 'quoted-printable'; $mail->Body = $messagehtml; $mail->AltBody = $messagetext; } else { $mail->IsHTML(false); $mail->Body = $messagetext; } if ($mail->Send()) { if ($logfile = get_config('emaillog')) { $docroot = get_config('docroot'); @($client = (string) $_SERVER['REMOTE_ADDR']); @($script = (string) $_SERVER['SCRIPT_FILENAME']); if (strpos($script, $docroot) === 0) { $script = substr($script, strlen($docroot)); } $line = "{$to} <- {$mail->From} - " . str_shorten_text($mail->Subject, 200); @error_log('[' . date("Y-m-d h:i:s") . "] [{$client}] [{$script}] {$line}\n", 3, $logfile); } // Update the count of sent mail update_send_count($userto); return true; } throw new EmailException("Couldn't send email to {$usertoname} with subject {$subject}. " . "Error from phpmailer was: " . $mail->ErrorInfo); }
/** * Returns a short name for the artefact to be used in a list of artefacts in a view */ public function display_title($maxlen = null) { if ($maxlen) { return str_shorten_text($this->get('title'), $maxlen, true); } return $this->get('title'); }
/** * Optional method. If specified, allows the blocktype class to munge the * artefactchooser element data before it's templated */ public static function artefactchooser_get_element_data($artefact) { $folderdata = ArtefactTypeFileBase::artefactchooser_folder_data($artefact); $artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id)); $artefact->hovertitle = $artefact->description; $path = $artefact->parent ? ArtefactTypeFileBase::get_full_path($artefact->parent, $folderdata->data) : ''; $artefact->description = str_shorten_text($folderdata->ownername . $path . $artefact->title, 30); return $artefact; }
/** * Always use this function for all emails to users * * @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email * @param object $userfrom user object to send email from. If null, email will come from mahara * @param string $subject email subject * @param string $messagetext text version of email * @param string $messagehtml html version of email (will send both html and text) * @param array $customheaders email headers * @throws EmailException * @throws EmailDisabledException */ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml = '', $customheaders = null) { global $IDPJUMPURL; static $mnetjumps = array(); if (!get_config('sendemail')) { // You can entirely disable Mahara from sending any e-mail via the // 'sendemail' configuration variable return true; } if (empty($userto)) { throw new InvalidArgumentException("empty user given to email_user"); } if (isset($userto->id) && empty($userto->ignoredisabled)) { $maildisabled = property_exists($userto, 'maildisabled') ? $userto->maildisabled : get_account_preference($userto->id, 'maildisabled') == 1; if ($maildisabled) { throw new EmailDisabledException("email for this user has been disabled"); } } // If the user is a remote xmlrpc user, trawl through the email text for URLs // to our wwwroot and modify the url to direct the user's browser to login at // their home site before hitting the link on this site if (!empty($userto->mnethostwwwroot) && !empty($userto->mnethostapp)) { require_once get_config('docroot') . 'auth/xmlrpc/lib.php'; // Form the request url to hit the idp's jump.php if (isset($mnetjumps[$userto->mnethostwwwroot])) { $IDPJUMPURL = $mnetjumps[$userto->mnethostwwwroot]; } else { $mnetjumps[$userto->mnethostwwwroot] = $IDPJUMPURL = PluginAuthXmlrpc::get_jump_url_prefix($userto->mnethostwwwroot, $userto->mnethostapp); } $wwwroot = get_config('wwwroot'); $messagetext = preg_replace_callback('%(' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))%', 'localurl_to_jumpurl', $messagetext); $messagehtml = preg_replace_callback('%href=["\'`](' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))["\'`]%', 'localurl_to_jumpurl', $messagehtml); } require_once 'phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer(true); $mail->CharSet = 'UTF-8'; $smtphosts = get_config('smtphosts'); if ($smtphosts == 'qmail') { // use Qmail system $mail->IsQmail(); } else { if (empty($smtphosts)) { // use PHP mail() = sendmail $mail->IsMail(); } else { $mail->IsSMTP(); // use SMTP directly $mail->Host = get_config('smtphosts'); if (get_config('smtpuser')) { // Use SMTP authentication $mail->SMTPAuth = true; $mail->Username = get_config('smtpuser'); $mail->Password = get_config('smtppass'); $mail->SMTPSecure = get_config('smtpsecure'); $mail->Port = get_config('smtpport'); if (get_config('smtpsecure') && !get_config('smtpport')) { // Encrypted connection with no port. Use default one. if (get_config('smtpsecure') == 'ssl') { $mail->Port = 465; } elseif (get_config('smtpsecure') == 'tls') { $mail->Port = 587; } } } } } if (get_config('bounces_handle') && !empty($userto->id) && empty($maildisabled)) { $mail->Sender = generate_email_processing_address($userto->id, $userto); } if (empty($userfrom) || $userfrom->email == get_config('noreplyaddress')) { if (empty($mail->Sender)) { $mail->Sender = get_config('noreplyaddress'); } $mail->From = get_config('noreplyaddress'); $mail->FromName = isset($userfrom->id) ? display_name($userfrom, $userto) : get_config('sitename'); $customheaders[] = 'Precedence: Bulk'; // Try to avoid pesky out of office responses $messagetext .= "\n\n" . get_string('pleasedonotreplytothismessage') . "\n"; if ($messagehtml) { $messagehtml .= "\n\n<p>" . get_string('pleasedonotreplytothismessage') . "</p>\n"; } } else { if (empty($mail->Sender)) { $mail->Sender = $userfrom->email; } $mail->From = $userfrom->email; $mail->FromName = display_name($userfrom, $userto); } $replytoset = false; if (!empty($customheaders) && is_array($customheaders)) { foreach ($customheaders as $customheader) { // To prevent duplicated declaration of the field "Message-ID", // don't add it into the $mail->CustomHeader[]. if (false === stripos($customheader, 'message-id')) { // Hack the fields "In-Reply-To" and "References": // add touser<userID> if (0 === stripos($customheader, 'in-reply-to') || 0 === stripos($customheader, 'references')) { $customheader = preg_replace('/<forumpost(\\d+)/', '<forumpost${1}touser' . $userto->id, $customheader); } $mail->AddCustomHeader($customheader); } else { list($h, $msgid) = explode(':', $customheader, 2); // Hack the "Message-ID": add touser<userID> to make sure // the "Message-ID" is unique $msgid = preg_replace('/<forumpost(\\d+)/', '<forumpost${1}touser' . $userto->id, $msgid); $mail->MessageID = trim($msgid); } if (0 === stripos($customheader, 'reply-to')) { $replytoset = true; } } } $mail->Subject = substr(stripslashes($subject), 0, 900); try { if ($to = get_config('sendallemailto')) { // Admins can configure the system to send all email to a given address // instead of whoever would receive it, useful for debugging. $usertoname = display_name($userto, $userto, true) . ' (' . get_string('divertingemailto', 'mahara', $to) . ')'; $mail->addAddress($to); $notice = get_string('debugemail', 'mahara', display_name($userto, $userto), $userto->email); $messagetext = $notice . "\n\n" . $messagetext; if ($messagehtml) { $messagehtml = '<p>' . hsc($notice) . '</p>' . $messagehtml; } } else { $usertoname = display_name($userto, $userto); $mail->AddAddress($userto->email, $usertoname); $to = $userto->email; } if (!$replytoset) { $mail->AddReplyTo($mail->From, $mail->FromName); } } catch (phpmailerException $e) { // If there's a phpmailer error already, assume it's an invalid address throw new InvalidEmailException("Cannot send email to {$usertoname} with subject {$subject}. Error from phpmailer was: " . $mail->ErrorInfo); } $mail->WordWrap = 79; if ($messagehtml) { $mail->IsHTML(true); $mail->Encoding = 'quoted-printable'; $mail->Body = $messagehtml; $mail->AltBody = $messagetext; } else { $mail->IsHTML(false); $mail->Body = $messagetext; } try { $sent = $mail->Send(); } catch (phpmailerException $e) { $sent = false; } if ($sent) { if ($logfile = get_config('emaillog')) { $docroot = get_config('docroot'); @($client = (string) $_SERVER['REMOTE_ADDR']); @($script = (string) $_SERVER['SCRIPT_FILENAME']); if (strpos($script, $docroot) === 0) { $script = substr($script, strlen($docroot)); } $line = "{$to} <- {$mail->From} - " . str_shorten_text($mail->Subject, 200); @error_log('[' . date("Y-m-d h:i:s") . "] [{$client}] [{$script}] {$line}\n", 3, $logfile); } if (get_config('bounces_handle')) { // Update the count of sent mail update_send_count($userto); } return true; } throw new EmailException("Couldn't send email to {$usertoname} with subject {$subject}. " . "Error from phpmailer was: " . $mail->ErrorInfo); }
public function render_self($options) { $smarty = smarty_core(); $smarty->assign('title', $this->get('title')); $smarty->assign('description', $this->get('description')); $smarty->assign('viewid', isset($options['viewid']) ? $options['viewid'] : 0); $smarty->assign('simpledisplay', isset($options['simpledisplay']) ? $options['simpledisplay'] : false); if ($childrecords = $this->folder_contents()) { $this->add_to_render_path($options); usort($childrecords, array('ArtefactTypeFileBase', 'my_files_cmp')); $children = array(); foreach ($childrecords as &$child) { $c = artefact_instance_from_id($child->id); $child->title = $child->hovertitle = $c->get('title'); if (!empty($options['simpledisplay'])) { $child->title = str_shorten_text($child->title, 20); } $child->date = format_date(strtotime($child->mtime), 'strfdaymonthyearshort'); $child->iconsrc = call_static_method(generate_artefact_class_name($child->artefacttype), 'get_icon', array('id' => $child->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0)); } $smarty->assign('children', $childrecords); } return array('html' => $smarty->fetch('artefact:file:folder_render_self.tpl'), 'javascript' => null); }
public static function artefactchooser_get_file_data($artefact) { $artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id)); if ($artefact->artefacttype == 'profileicon') { $artefact->hovertitle = $artefact->note; if ($artefact->title) { $artefact->hovertitle .= ': ' . $artefact->title; } } else { $artefact->hovertitle = $artefact->title; if ($artefact->description) { $artefact->hovertitle .= ': ' . $artefact->description; } } $folderdata = self::artefactchooser_folder_data($artefact); if ($artefact->artefacttype == 'profileicon') { $artefact->description = str_shorten_text($artefact->title, 30); } else { $path = $artefact->parent ? self::get_full_path($artefact->parent, $folderdata->data) : ''; $artefact->description = str_shorten_text($folderdata->ownername . $path . $artefact->title, 30); } return $artefact; }
public function __construct($data, $cron = false) { parent::__construct($data, $cron); $this->overridemessagecontents = true; $post = get_record_sql(' SELECT p.subject, p.body, p.poster, p.parent, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id AS topicid, fp.subject AS topicsubject, f.title AS forumtitle, g.name AS groupname, f.id AS forumid FROM {interaction_forum_post} p INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic AND t.deleted = 0) INNER JOIN {interaction_forum_post} fp ON (fp.parent IS NULL AND fp.topic = t.id) INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted = 0) INNER JOIN {group} g ON (f.group = g.id AND g.deleted = 0) WHERE p.id = ? AND p.deleted = 0', array($this->postid)); // The post may have been deleted during the activity delay if (!$post) { $this->users = array(); return; } // A user may be subscribed via the forum or the specific topic. If they're subscribed to both, we want // to focus on the topic subscription because it's more specific. $sql = ' SELECT subq2.subscriber, (CASE WHEN subq2.topickey IS NOT NULL THEN subq2.topickey ELSE subq2.forumkey END) AS "key", (CASE WHEN subq2.topickey IS NOT NULL THEN \'topic\' ELSE \'forum\' END) AS "type" FROM ( SELECT subq1.subscriber, max(topickey) AS topickey, max(forumkey) AS forumkey FROM ( SELECT "user" AS subscriber, "key" AS topickey, NULL AS forumkey FROM {interaction_forum_subscription_topic} WHERE topic = ? UNION ALL SELECT "user" AS subscriber, NULL AS topickey, "key" AS forumkey FROM {interaction_forum_subscription_forum} WHERE forum = ? ) subq1 GROUP BY subq1.subscriber ) subq2 INNER JOIN {usr} u ON subq2.subscriber = u.id WHERE u.deleted = 0 '; $params = array($post->topicid, $post->forumid); if ($cron) { $sql .= ' AND subq2.subscriber > ? '; $params[] = (int) $data->last_processed_userid; $limitfrom = 0; $limitnum = self::USERCHUNK_SIZE; } else { $limitfrom = ''; $limitnum = ''; } $sql .= ' ORDER BY subq2.subscriber'; $subscribers = get_records_sql_assoc($sql, $params, $limitfrom, $limitnum); $this->users = $subscribers ? activity_get_users($this->get_id(), array_keys($subscribers)) : array(); $this->fromuser = $post->poster; // When emailing forum posts, create Message-Id headers for threaded display by email clients $urlinfo = parse_url(get_config('wwwroot')); $hostname = $urlinfo['host']; $cleanforumname = clean_email_headers($post->forumtitle); $cleangroupname = clean_email_headers($post->groupname); $cleanforumname = str_replace('"', "'", strip_tags($cleanforumname)); $cleangroupname = str_replace('"', "'", strip_tags($cleangroupname)); $this->customheaders = array('List-Id: "' . $cleanforumname . '" <forum' . $post->forumid . '@' . $hostname . '>', 'List-Help: ' . get_config('wwwroot') . 'interaction/forum/view.php?id=' . $post->forumid, 'Message-ID: <forumpost' . $this->postid . '@' . $hostname . '>', 'X-Mahara-Group: ' . $cleangroupname, 'X-Mahara-Forum: ' . $cleanforumname); if ($post->parent) { $this->customheaders[] = 'In-Reply-To: <forumpost' . $post->parent . '@' . $hostname . '>'; $this->customheaders[] = 'References: <forumpost' . $post->parent . '@' . $hostname . '>'; } $post->posttime = strftime(get_string('strftimedaydatetime'), $post->ctime); // Some messages are all html and when they're 'cleaned' with // strip_tags(str_shorten_html($post->body, 200, true)) for display, // they are left empty. Use html2text instead. $this->message = str_shorten_text(trim(html2text($post->body)), 200, true); // For internal notifications. $post->textbody = trim(html2text($post->body)); $post->htmlbody = clean_html($post->body); $this->url = 'interaction/forum/topic.php?id=' . $post->topicid . '&post=' . $this->postid; $this->add_urltext(array('key' => 'Topic', 'section' => 'interaction.forum')); $this->strings->subject = (object) array('key' => 'newforumpostnotificationsubjectline', 'section' => 'interaction.forum', 'args' => array($post->subject ? $post->subject : get_string('Re:', 'interaction.forum') . ($post->parent ? get_ancestorpostsubject($post->parent, true) : $post->topicsubject))); foreach ($this->users as &$user) { $user->subscribetype = $subscribers[$user->id]->type; $user->unsubscribekey = $subscribers[$user->id]->key; } $this->temp = (object) array('post' => $post); }
/** * Provides an element to manage a view ACL * * @param array $element The element to render * @param Pieform $form The form to render the element for * @return string The HTML for the element */ function pieform_element_viewacl(Pieform $form, $element) { global $USER, $SESSION, $LANGDIRECTION; $strlen = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen'; $smarty = smarty_core(); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $value = $form->get_value($element); // Look for the presets and split them into two groups require_once get_config('libroot') . 'antispam.php'; $public = false; if (is_probationary_user()) { $public = false; } else { if (get_config('allowpublicviews') && $USER->institution_allows_public_views()) { $public = true; } else { if (get_config('allowpublicprofiles') && $element['viewtype'] == 'profile') { $public = true; } } } $allpresets = array('public', 'loggedin', 'friends'); $allowedpresets = array(); $loggedinindex = 0; if ($public) { $allowedpresets[] = 'public'; $loggedinindex = 1; } $allowedpresets[] = 'loggedin'; if ($form->get_property('userview')) { $allowedpresets[] = 'friends'; } $accesslist = array(); if ($value) { foreach ($value as $item) { if (is_array($item)) { if ($item['type'] == 'public') { $item['publicallowed'] = (int) $public; } if (in_array($item['type'], $allpresets)) { $item['name'] = get_string($item['type'] == 'loggedin' ? 'registeredusers' : $item['type'], 'view'); $item['preset'] = true; } else { $item['name'] = pieform_render_viewacl_getvaluebytype($item['type'], $item['id']); } if ($strlen($item['name']) > 30) { $item['shortname'] = str_shorten_text($item['name'], 30, true); } // only show access that is still current. Expired access will be deleted if the form is saved if ($form->is_submitted() || empty($item['stopdate']) || time() <= strtotime($item['stopdate'])) { $accesslist[] = $item; } } } } $defaultaccesslist = $accesslist ? 0 : 1; $myinstitutions = array(); foreach ($USER->get('institutions') as $i) { $myinstitutions[] = array('type' => 'institution', 'id' => $i->institution, 'start' => null, 'end' => null, 'name' => hsc($i->displayname), 'preset' => false); } foreach ($allowedpresets as &$preset) { $preset = array('type' => $preset, 'id' => $preset, 'start' => null, 'end' => null, 'name' => get_string($preset == 'loggedin' ? 'registeredusers' : $preset, 'view'), 'preset' => true); } $allgroups = array('type' => 'allgroups', 'id' => 'allgroups', 'start' => null, 'end' => null, 'name' => get_string('allmygroups', 'group'), 'preset' => true); $mygroups = array(); foreach (group_get_user_groups($USER->get('id')) as $g) { $group = array('type' => 'group', 'id' => $g->id, 'start' => null, 'end' => null, 'name' => $g->name, 'preset' => false); if ($strlen($g->name) > 30) { $group['shortname'] = str_shorten_text($g->name, 30, true); } $mygroups[] = $group; } $faves = array(); foreach (get_user_favorites($USER->get('id')) as $u) { $fave = array('type' => 'user', 'id' => $u->id, 'start' => null, 'end' => null, 'name' => $u->name, 'preset' => false); if ($strlen($u->name) > 30) { $fave['shortname'] = str_shorten_text($u->name, 30, true); } $faves[] = $fave; } require_once get_config('libroot') . 'pieforms/pieform/elements/calendar.php'; $options = array('dateFormat' => get_string('calendar_dateFormat', 'langconfig'), 'timeFormat' => get_string('calendar_timeFormat', 'langconfig'), 'stepHour' => 1, 'stepMinute' => 5); $options = pieform_element_calendar_get_lang_strings($options, $LANGDIRECTION); $datepickeroptionstr = ''; foreach ($options as $key => $option) { if (is_numeric($option)) { $datepickeroptionstr .= $key . ': ' . $option . ','; } else { if (is_array($option)) { foreach ($option as $k => $v) { if (!is_numeric($v)) { if (preg_match('/^\'(.*)\'$/', $v, $match)) { $v = $match[1]; } $option[$k] = json_encode($v); } } $option = '[' . implode(',', $option) . ']'; $datepickeroptionstr .= $key . ': ' . $option . ','; } else { $datepickeroptionstr .= $key . ': ' . json_encode($option) . ','; } } } $smarty->assign('datepickeroptions', $datepickeroptionstr); $smarty->assign('viewtype', $element['viewtype']); $smarty->assign('potentialpresets', json_encode($allowedpresets)); $smarty->assign('loggedinindex', $loggedinindex); $smarty->assign('accesslist', json_encode($accesslist)); $smarty->assign('defaultaccesslist', $defaultaccesslist); $smarty->assign('viewid', $form->get_property('viewid')); $smarty->assign('formname', $form->get_property('name')); $smarty->assign('myinstitutions', json_encode($myinstitutions)); $smarty->assign('allowcomments', $element['allowcomments']); $smarty->assign('allgroups', json_encode($allgroups)); $smarty->assign('mygroups', json_encode($mygroups)); $smarty->assign('faves', json_encode($faves)); return $smarty->fetch('form/viewacl.tpl'); }
/** * Renders a set of radio buttons for scale type questions in surveys. * * @param array $element The element to render * @param Pieform $form The form to render the element for * @return string The HTML for the element */ function pieform_element_scale(Pieform $form, $element) { /*{{{*/ $global = $form->get_property('method') == 'get' ? $_GET : $_POST; $submitted = $form->is_submitted(); if ($submitted && isset($global[$element['name']])) { $value = $global[$element['name']]; } $result = ''; $separator = null; //$separator = ''; if (isset($element['separator'])) { $separator = $element['separator']; } $length = 17; if (isset($element['length'])) { $length = $element['length']; } if (!isset($element['options'])) { $steps = 5; if (isset($element['steps'])) { if ($element['steps'] < 2) { $steps = 2; } elseif ($element['steps'] > 10) { $steps = 10; } else { $steps = $element['steps']; } } $element['options'] = array(); for ($i = 0; $i < $steps; $i++) { $element['options'] = array_merge($element['options'], array(array('value' => strval($i), 'title' => ''))); } } // If needed, set answers in reverse order if (isset($element['reverse']) && $element['reverse'] == 'true') { $element['options'] = array_reverse($element['options']); } //$result .= "<span style='display:block-inline'>"; $result .= "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>"; $result .= "<td width='45%' valign='top' align='right'>"; if (isset($element['labelleft'])) { $result .= "<strong>" . $element['labelleft'] . "</strong>"; } if (isset($element['titleleft'])) { $result .= $element['titleleft']; } $result .= "</td>"; $result .= "<td width='10%' valign='top' align='center'>"; $result .= "<div style='white-space:nowrap;'>"; foreach ($element['options'] as $e) { $checked = $form->get_value($element) === $e['value'] && !is_null($form->get_value($element)); if ($e['value'] == null) { $checked = false; } $result .= '<input type="radio" value="' . $e['value'] . '" ' . $form->element_attributes($element) . ($checked ? ' checked="checked"' : '') . ' style="vertical-align:top">' . Pieform::hsc(str_shorten_text($e['title'], $length, true)); $result .= $separator; } // Strip the separator after the last option... //$result = substr($result, 0, -strlen($separator)); $result .= "</div>"; $result .= "</td>"; $result .= "<td width='45%' valign='top' align='left'>"; if (isset($element['titleright'])) { $result .= $element['titleright']; } if (isset($element['labelright'])) { $result .= "<strong>" . $element['labelright'] . "</strong>"; } $result .= "</td>"; $result .= "</tr></table>"; //$result .= "</span>"; $result .= '<div class="cl"></div>'; return $result; }
/** * This function returns a list of browsable items. * * @param limit how many items to display per page * @param offset current page to display * @return array (count: integer, data: array) */ public static function get_browsable_items($filters, $offset=0, $limit=20) { global $USER; $contents = array(); $texttitletrim = 20; $onetimeclause = false; $count = 0; if (is_postgres()) { $selectclause = 'SELECT * FROM ( SELECT DISTINCT ON (va.view) va.view, a.id, v.mtime, v.owner'; $grouporderclause = ') p ORDER BY mtime DESC'; } else if (is_mysql()) { $selectclause = 'SELECT va.view, a.id, v.mtime, v.owner'; $grouporderclause = 'GROUP BY va.view ORDER BY a.mtime DESC'; } $fromclause = ' FROM {view_access} va'; $joinclause = " INNER JOIN {view} v ON (va.view = v.id AND v.type = 'profile')"; $join2clause = " JOIN {view_artefact} var ON v.id = var.view"; $join3clause = " JOIN {artefact} a ON (a.artefacttype = 'image' AND a.id = var.artefact)"; $join4clause = ''; $whereclause = ' WHERE (v.owner > 0)'; $andclause = " AND (v.startdate IS NULL OR v.startdate < current_timestamp) AND (v.stopdate IS NULL OR v.stopdate > current_timestamp) AND (va.startdate IS NULL OR va.startdate < current_timestamp) AND (va.stopdate IS NULL OR va.stopdate > current_timestamp)"; foreach ($filters as $filterkey => $filterval) { switch ($filterkey) { case 'keyword': $join4clause = ' LEFT JOIN {usr} u ON u.id = v.owner'; // replace spaces with commas so that we can search on each term separately $filterval = str_replace(' ', ',', $filterval); $keywords = explode(",", $filterval); if (count($keywords) == 1 ) { $andclause .= " AND ( LOWER(u.firstname) LIKE LOWER('%$filterval%') OR LOWER(u.lastname) LIKE LOWER('%$filterval%') OR LOWER(u.preferredname) LIKE LOWER('%$filterval%') )"; } else { foreach($keywords as $key => $word) { if ($key == 0) { $andclause .= " AND (( LOWER(u.firstname) LIKE LOWER('%$word%') OR LOWER(u.lastname) LIKE LOWER('%$word%') OR LOWER(u.preferredname) LIKE LOWER('%$word%') )"; } else { $andclause .= " AND ( LOWER(u.firstname) LIKE LOWER('%$word%') OR LOWER(u.lastname) LIKE LOWER('%$word%') OR LOWER(u.preferredname) LIKE LOWER('%$word%') )"; } if ($key == count($keywords)-1) { $andclause .= ')'; } } } break; case 'college' : if (!empty($filterval) && !$onetimeclause) { $join4clause .= ' JOIN {usr_enrolment} e ON e.usr = v.owner'; $selectclause .= ', e.college, e.course'; $ontimeclause = true; } $andclause .= " AND e.college IN ($filterval)"; break; case 'course' : if (!empty($filterval) && !$onetimeclause) { $join4clause .= ' JOIN {usr_enrolment} e ON e.usr = v.owner'; $selectclause .= ', e.college, e.course'; $ontimeclause = true; } $courseidgroups = explode(";", $filterval); if (count($courseidgroups) == 1) { // one course submitted, could have multiple csv ids if selected by name $courseids = explode(",", $courseidgroups[0]); if (count($courseids) == 1 ) { $andclause .= " AND (e.course LIKE '%$courseids[0]%' AND e.usr = v.owner)"; } else if (count($courseids) > 1 ) { foreach($courseids as $key => $id) { if ($key == 0) { $andclause .= " AND (e.course LIKE '%$id%'"; } else { $andclause .= " OR e.course LIKE '%$id%'"; } if ($key == count($courseids)-1) { $andclause .= ')'; } } } } else if (count($courseidgroups) > 1) { // more than one course submitted foreach($courseidgroups as $key => $coursegroup) { if ($key == 0) { $courseids = explode(",", $coursegroup); if (count($courseids) == 1 ) { $andclause .= " AND ((e.course LIKE '%$courseids[0]%')"; } else if (count($courseids) > 1 ) { foreach($courseids as $key => $id) { if ($key == 0) { $andclause .= " AND ((e.course LIKE '%$id%'"; } else { $andclause .= " OR e.course LIKE '%$id%'"; } if ($key == count($courseids)-1) { $andclause .= ')'; } } } } else { // key != 0 $courseids = explode(",", $coursegroup); if (count($courseids) == 1 ) { $andclause .= " AND (e.course LIKE '%$courseids[0]%')"; } else if (count($courseids) > 1 ) { foreach($courseids as $key => $id) { if ($key == 0) { $andclause .= " AND (e.course LIKE '%$id%'"; } else { $andclause .= " OR e.course LIKE '%$id%'"; } if ($key == count($courseids)-1) { $andclause .= ')'; } } } } } } break; } } /** * The query checks for profile page images. */ $profileimagesids = get_records_sql_array(" $selectclause $fromclause $joinclause $join2clause $join3clause $join4clause $whereclause $andclause $grouporderclause ", array(), $offset, $limit); if ($profileimagesids) { foreach ($profileimagesids as $key => $profileimageid) { $view = new View($profileimageid->view); $view->set('dirty', false); $fullurl = $view->get_url(); $avatarurl = profile_icon_url($profileimageid->owner,50,50); $pagetitle = str_shorten_text(display_name($profileimageid->owner), $texttitletrim, true); $contents['profiles'][] = array("id" => "p" . $profileimageid->id, "type" => "profile", "image" => array( "id" => $profileimageid->id, "view" => $profileimageid->view ), "page" => array( "url" => $fullurl, "title" => $pagetitle ), "owner" => array( "avatarurl" => $avatarurl ) ); } // foreach } if ($profileimagesids) { $allprofileswithimages = get_records_sql_array(" SELECT va.view $fromclause $joinclause $join2clause $join3clause $join4clause $whereclause $andclause GROUP BY va.view ", array()); $count = count($allprofileswithimages); } $items = array( 'count' => $count, 'data' => $contents, 'offset' => $offset, 'limit' => $limit, ); return $items; }
/** Code copied from blocktype::groupviews **/ public static function get_data($groupid, $offset = 0, $limit = 20) { global $USER; $texttitletrim = 20; $items2 = null; if (!defined('GROUP')) { define('GROUP', $groupid); } // get the currently requested group $group = group_current_group(); $role = group_user_access($group->id); if ($role) { // For group members, display a list of views that others have shared to the group // Params for get_sharedviews_data is $limit=0,$offset=0, $groupid $data['sharedviews'] = View::get_sharedviews_data($limit, $offset, $group->id); /* foreach ($data['sharedviews']->data as &$view) { if (isset($view['template']) && $view['template']) { $view['form'] = pieform(create_view_form($group, null, $view->id)); } } */ //the array that is returned from View::get_sharedviews_data($limit, $offset, $group->id) //contains a few other things but we just wanted to focus on sharedviews //the foreach below will loop through all views shared with the group foreach ($data['sharedviews'] as $aView) { if (is_array($aView)) { //20140909 JW sort the array returned by View::get_sharedviews_data($limit, $offset, $group->id) //by ctime, this requires the query within get_sharedviews_data to have ctime in its select string $aView = self::array_msort($aView, array('ctime' => SORT_DESC)); //the foreach below will loop through all the properties for a view (returned by get_data method) and assigns them to the required variables foreach ($aView as $aViewProperty) { //get the view $viewID = $aViewProperty['id']; //the page shared $fullurl = $aViewProperty['fullurl']; //full url of the page shared $viewTitle = str_shorten_text($aViewProperty['displaytitle'], $texttitletrim, true); //view's title //get the owner of the view $viewOwnerName = $aViewProperty['user']->firstname . " " . $aViewProperty['user']->lastname; //owner of the view's name $userobj = new User(); $userobj->find_by_id($aViewProperty['user']->id); $profileurl = profile_url($userobj); //owner of the view's proflie page $avatarurl = profile_icon_url($aViewProperty['user']->id, 50, 50); //owner of the view's profile picture //get the artefact id of an image in the view $theView = new View($aViewProperty['id']); //create the view $artefactInView = $theView->get_artefact_metadata(); //get all artefacts in the view foreach ($artefactInView as $anArtefact) { //for each artefact if ($anArtefact->artefacttype == 'image') { $artefactID = $anArtefact->id; //if it is an image artefact assign the id and break the loop break; } //20150331 JW added that if page contains a folder with images (galleries count as folders) //it will pull an image from that folder and use it as the cover if ($anArtefact->artefacttype == 'folder') { $query = "SELECT id FROM {artefact} where parent = ? AND artefacttype = 'image'"; $imagesInAFolder = get_records_sql_array($query, array($anArtefact->id)); //only assign the id of an image if the folder contains at least 1 image if (!empty($imagesInAFolder)) { $artefactID = $imagesInAFolder[0]->id; break; } } //20140903 JW if there are no images on the page then set to artefactID to 0 //this way, when display each page, instead of a blank box it will show a place holder image $artefactID = 0; } //the items variable below requires the contents array to be in this format $contents['photos'][] = array("image" => array("id" => $artefactID, "view" => $viewID), "type" => "photo", "page" => array("url" => $fullurl, "title" => $viewTitle), "owner" => array("name" => $viewOwnerName, "profileurl" => $profileurl, "avatarurl" => $avatarurl)); } } } //20150723 JW added the if statement to check if $content is set, if not then skip if (isset($contents)) { $items2 = array('count' => $data['sharedviews']->count, 'data' => $contents, 'offset' => $offset, 'limit' => $limit); } } //$data['group'] = $group; return $items2; }