/** * get types as radio buttons * * @param string the current type * @return the HTML to insert in the page * * @see comments/edit.php */ public static function get_radio_buttons($name, $type) { global $context; // a 2-column layout $content = '<div style="float: left;">' . "\n"; // col 1 - attention - also the default $content .= '<input type="radio" name="' . $name . '" value="attention"'; if ($type == 'attention' || !trim($type)) { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('attention') . ' ' . i18n::s('Attention') . BR; // col 1 - an idea $content .= '<input type="radio" name="' . $name . '" value="idea"'; if ($type == 'idea' || $type == 'suggestion') { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('idea') . ' ' . i18n::s('A suggestion') . BR; // col 1 - a question $content .= '<input type="radio" name="' . $name . '" value="question"'; if ($type == 'question') { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('question') . ' ' . i18n::s('A question') . BR; // col 1 - like $content .= '<input type="radio" name="' . $name . '" value="like"'; if ($type == 'like') { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('like') . ' ' . i18n::s('I like...'); // from column 1 to column 2 $content .= '</div>' . "\n" . '<div style="float: left;">'; // col 2 - warning $content .= '<input type="radio" name="' . $name . '" value="warning"'; if ($type == 'warning') { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('warning') . ' ' . i18n::s('Warning!') . BR; // col 2 - done $content .= '<input type="radio" name="' . $name . '" value="done"'; if ($type == 'done') { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('done') . ' ' . i18n::s('Job has been completed') . BR; // col 2 - information $content .= '<input type="radio" name="' . $name . '" value="information"'; if ($type == 'information') { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('information') . ' ' . i18n::s('My two cents') . BR; // col2 - dislike $content .= '<input type="radio" name="' . $name . '" value="dislike"'; if ($type == 'dislike') { $content .= ' checked="checked"'; } $content .= '/>' . Comments::get_img('dislike') . ' ' . i18n::s('I don\'t like...'); // end of columns $content .= '</div>' . "\n"; return $content; }
/** * list comments * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // empty list if (!SQL::count($result)) { $output = array(); return $output; } // sanity check if (!isset($this->layout_variant)) { $this->layout_variant = 'full'; } // we return an array of ($url => $attributes) $items = array(); // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; while ($item = SQL::fetch($result)) { // get the anchor $anchor = Anchors::get($item['anchor']); // initialize variables $prefix = $suffix = ''; // there is no zoom page for comments $label = '_'; // the icon is a link to comment permalink $suffix .= Skin::build_link(Comments::get_url($item['id']), Comments::get_img($item['type']), 'basic', i18n::s('View this comment')); // a link to the user profile if ($item['create_name']) { $suffix .= ' ' . Users::get_link($item['create_name'], $item['create_address'], $item['create_id']); } else { $suffix .= ' ' . Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']); } $menu = array(); // the edition date if ($item['create_date']) { $menu[] = Skin::build_date($item['create_date']); } else { $menu[] = Skin::build_date($item['edit_date']); } // the menu bar for associates, editors and poster if (Comments::allow_modification($anchor, $item)) { $menu[] = Skin::build_link(Comments::get_url($item['id'], 'edit'), i18n::s('edit'), 'span'); $menu[] = Skin::build_link(Comments::get_url($item['id'], 'delete'), i18n::s('delete'), 'span'); } if ($menu) { $suffix .= ' -' . Skin::finalize_list($menu, 'menu'); } // new line $suffix .= BR; // description if ($description = ucfirst(trim(Codes::beautify($item['description'] . Users::get_signature($item['create_id']))))) { $suffix .= ' ' . $description; } // url to view the comment $url = Comments::get_url($item['id']); // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'comment', NULL); } // end of processing SQL::free($result); return $items; }
$fields[] = $field; } } // the type if (is_object($anchor)) { $label = i18n::s('Your intent'); if (isset($item['type'])) { $type = $item['type']; } elseif (isset($_REQUEST['type'])) { $type = $_REQUEST['type']; } else { $type = ''; } // this is an approval if ($type == 'approval') { $input = Comments::get_img('approval') . ' ' . sprintf(i18n::s('You are approving %s'), Skin::build_link($anchor->get_url(), $anchor->get_title())) . '<input type="hidden" name="type" value="approval" />'; $hint = ''; // warn in case of multiple approval if (!isset($item['id']) && isset($_REQUEST['type']) && $_REQUEST['type'] == 'approval' && Surfer::get_id() && Comments::count_approvals_for_anchor($anchor->get_reference(), Surfer::get_id())) { $input .= '<p class="details">' . i18n::s('It is not your first approval for this page.') . '</p>'; } // change page title too $context['page_title'] = sprintf(i18n::s('%s: %s'), i18n::s('Approval'), $anchor->get_title()); // else select a regular type } else { $input = Comments::get_radio_buttons('type', $type); $hint = i18n::s('Please carefully select a type adequate for your comment.'); } $fields[] = array($label, $input, $hint); } // the description
/** * list comments as successive notes in a thread * * @param resource the SQL result * @return string the rendered text **/ function layout($result) { global $context; // we return some text $output = ''; // empty list if (!SQL::count($result)) { return $output; } // build a list of comments $rows = array(); include_once $context['path_to_root'] . 'comments/comments.php'; while ($item = SQL::fetch($result)) { // get the anchor $anchor = Anchors::get($item['anchor']); // get poster information $poster = array(); if ($item['create_name']) { if (!($poster = Users::get($item['create_id']))) { $poster['id'] = 0; $poster['full_name'] = $item['create_name']; $poster['email'] = $item['create_address']; } } else { if (!($poster = Users::get($item['edit_id']))) { $poster['id'] = 0; $poster['full_name'] = $item['edit_name']; $poster['email'] = $item['edit_address']; } } // author description $author = ''; // avatar, but not for notifications if ($item['type'] != 'notification' && isset($poster['avatar_url']) && $poster['avatar_url']) { $author .= '<img src="' . $poster['avatar_url'] . '" alt="" title="avatar" class="avatar" />' . BR; } // link to poster, if possible if (isset($poster['id'])) { $author .= Users::get_link($poster['full_name'], $poster['email'], $poster['id']); } // commands to handle this comment $menu = array(); // get an icon for this comment $icon = Comments::get_img($item['type']); // link to comment permalink $label = Skin::build_link(Comments::get_url($item['id']), $icon, 'basic', i18n::s('View this comment')) . ' '; // the creation date if ($item['create_date']) { $label .= Skin::build_date($item['create_date'], 'with_hour'); } else { $label .= Skin::build_date($item['edit_date'], 'with_hour'); } // flag new comments if ($item['create_date'] >= $context['fresh']) { $label .= NEW_FLAG; } $menu[] = $label; // an approval -- can be modified, but not deleted if ($item['type'] == 'approval') { // additional commands for associates and poster and editor if ($anchor->is_owned()) { Skin::define_img('COMMENTS_EDIT_IMG', 'comments/edit.gif'); $menu[] = Skin::build_link(Comments::get_url($item['id'], 'edit'), COMMENTS_EDIT_IMG . i18n::s('Edit'), 'basic'); } // an automatic notification -- can be deleted, but not modified } elseif ($item['type'] == 'notification') { // additional commands for associates and poster and editor if ($anchor->is_owned()) { Skin::define_img('COMMENTS_DELETE_IMG', 'comments/delete.gif'); $menu[] = Skin::build_link(Comments::get_url($item['id'], 'delete'), COMMENTS_DELETE_IMG . i18n::s('Delete'), 'basic'); } // regular case } else { // additional commands for associates and poster and editor if (Comments::allow_modification($anchor, $item)) { Skin::define_img('COMMENTS_EDIT_IMG', 'comments/edit.gif'); $menu[] = Skin::build_link(Comments::get_url($item['id'], 'edit'), COMMENTS_EDIT_IMG . i18n::s('Edit'), 'basic'); Skin::define_img('COMMENTS_DELETE_IMG', 'comments/delete.gif'); $menu[] = Skin::build_link(Comments::get_url($item['id'], 'delete'), COMMENTS_DELETE_IMG . i18n::s('Delete'), 'basic'); } } // comment main text $text = ''; // state clearly that this is an approval if ($item['type'] == 'approval' && isset($poster['id'])) { $text .= '<p>' . sprintf(i18n::s('%s has provided his approval'), Users::get_link($poster['full_name'], $poster['email'], $poster['id'])) . '</p>'; } // display comment main text $text .= $item['description']; // display signature, but not for notifications if ($item['type'] != 'notification') { $text .= Users::get_signature($item['create_id']); } // format and display $text = ucfirst(trim($text)); // float the menu on the right if (count($menu)) { $text = '<div style="text-align: right">' . Skin::finalize_list($menu, 'menu') . '</div>' . $text; } // comment has been modified if ($item['create_name'] && $item['edit_name'] != $item['create_name']) { $text .= '<p class="details">' . ucfirst(sprintf(i18n::s('edited by %s %s'), $item['edit_name'], Skin::build_date($item['edit_date']))) . '</p>'; } // potential replies to this comment if ($item['type'] != 'notification') { // look for replies if ($replies = Comments::list_next($item['id'], 'replies')) { if (is_array($replies)) { $replies = Skin::build_list($replies, 'compact'); } $text .= '<div>' . $replies . '</div>'; } // allow to reply to this comment if (Comments::allow_creation($anchor)) { // the form to edit a comment $text .= '<form method="post" action="' . $context['url_to_root'] . Comments::get_url($item['id'], 'reply') . '" onsubmit="return validateDocumentPost(this)" enctype="multipart/form-data"><div style="margin-top: 1em;">'; // reference the anchor page $text .= '<input type="hidden" name="anchor" value="' . $item['anchor'] . '" />'; // remember the id of the replied comment $text .= '<input type="hidden" name="previous_id" value="' . $item['id'] . '" />'; // notify watchers $text .= '<input type="hidden" name="notify_watchers" value="Y" />'; // ensure id uniqueness static $fuse_id; if (!isset($fuse_id)) { $fuse_id = 1; } else { $fuse_id++; } // a textarea that grow on focus Page::insert_script('var reply' . $fuse_id . '=1;'); $text .= '<textarea name="description" id="reply' . $fuse_id . '"' . ' rows="1" cols="50"' . ' onfocus="if(reply' . $fuse_id . '){$(\'div#submit' . $fuse_id . '\').slideDown(600);reply' . $fuse_id . '=0;}">' . '</textarea>' . "\n"; // fix number of rows in firefox Page::insert_script('$(function(){' . '$("textarea#reply' . $fuse_id . '")' . '.each(function(){' . 'var lineHeight = parseFloat($(this).css("line-height"));' . 'var lines = $(this).attr("rows")*1 || $(this).prop("rows")*1;' . '$(this).css("height", lines*lineHeight);' . '})' . '.autogrow();' . '});' . "\n"); // the submit button $text .= '<div class="menu_bar" style="display: none;" id="submit' . $fuse_id . '">' . Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's') . '</div>'; // end of the form $text .= '</div></form>'; } } // the main part of the comment, with an id $text = '<td class="comment ' . $item['type'] . '" id="comment_' . $item['id'] . '">' . $text . '</td>'; // this is another row of the output $rows[] = '<td class="author ' . $item['type'] . '">' . $author . '</td>' . $text; } // end of processing SQL::free($result); // sanity check if (!count($rows)) { return ''; } // return a table $output = Skin::table_prefix('yabb'); $count = 1; foreach ($rows as $row) { if ($count % 2) { $output .= '<tr class="odd">' . $row . '</tr>'; } else { $output .= '<tr class="even">' . $row . '</tr>'; } $count++; } $output .= '</table>'; // process yacs codes $output = Codes::beautify($output); return $output; }
$context['text'] .= Skin::neighbours($neighbours, 'slideshow'); // link to the previous comment in thread, if any if ($item['previous_id'] && ($previous = Comments::get($item['previous_id']))) { $context['text'] .= ' <p>' . sprintf(i18n::s('Comment inspired from %s'), Skin::build_link(Comments::get_url($previous['id']), $previous['create_name'])) . '</p>'; } // display the full comment $context['text'] .= Skin::build_block($item['description'], 'description'); // list follow-ups in thread, if any if ($next = Comments::list_next($item['id'], 'compact')) { $context['text'] .= ' <p style="margin-bottom: 0; padding-bottom: 0;">' . i18n::s('This comment has inspired:') . '</p>' . Skin::build_list($next, 'compact'); } // some details about this item $details = array(); // the type if (is_object($anchor)) { $details[] = Comments::get_img($item['type']); } // the poster of this comment if ($poster = Users::get_link($item['create_name'], $item['create_address'], $item['create_id'])) { $details[] = sprintf(i18n::s('by %s %s'), $poster, Skin::build_date($item['create_date'], 'with_hour')); } else { $details[] = Skin::build_date($item['create_date'], 'with_hour'); } // the last edition of this comment if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('edited by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'], 'with_hour')); } // all details if ($details) { $context['text'] .= '<p class="details">' . ucfirst(implode(' ', $details)) . "</p>\n"; }