Esempio n. 1
0
 /**
  * list comments as successive reader notes
  *
  * @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;
     }
     // return some formatted text
     $text = '<dl class="wiki_comments">';
     // build a list of comments
     $index = 0;
     include_once $context['path_to_root'] . 'comments/comments.php';
     while ($item = SQL::fetch($result)) {
         // odd or even
         $index++;
         if ($index % 2) {
             $class = 'odd';
         } else {
             $class = 'even';
         }
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // include a link to comment permalink
         $text .= '<dt class="' . $class . ' details">';
         // a link to the user profile
         $text .= Users::get_link($item['create_name'], $item['create_address'], $item['create_id']);
         $menu = array();
         // the creation date
         $label = Skin::build_date($item['create_date']);
         // flag new comments
         if ($item['create_date'] >= $context['fresh']) {
             $label .= NEW_FLAG;
         }
         $menu[] = $label;
         // the menu bar for associates and poster
         if (Comments::allow_modification($anchor, $item)) {
             $menu[] = Skin::build_link(Comments::get_url($item['id'], 'edit'), i18n::s('edit'), 'basic');
             $menu[] = Skin::build_link(Comments::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic');
         }
         $text .= ' - ' . Skin::finalize_list($menu, 'menu');
         $text .= '</dt>';
         // each comment has an id
         $text .= '<dd class="' . $class . '" id="comment_' . $item['id'] . '">';
         // the comment itself
         $text .= ucfirst(trim($item['description'] . Users::get_signature($item['create_id'])));
         // comment has been modified
         if ($item['create_name'] && $item['edit_name'] != $item['create_name']) {
             $text .= BR . '<span class="details">(' . sprintf(i18n::s('modified by %s'), $item['edit_name']) . ')</span>';
         }
         // end of this note
         $text .= '</dd>';
     }
     // end of the list
     $text .= '</dl>';
     // process yacs codes
     $text = Codes::beautify($text);
     // end of processing
     SQL::free($result);
     return $text;
 }
Esempio n. 2
0
File: delete.php Progetto: rair/yacs
// the title of the page
if (is_object($overlay)) {
    $context['page_title'] = $overlay->get_label('delete_title', 'comments');
}
if (!$context['page_title']) {
    $context['page_title'] = i18n::s('Delete a comment');
}
// stop crawlers
if (Surfer::is_crawler()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // not found
} elseif (!isset($item['id'])) {
    include '../error.php';
    // permission denied
} elseif (!Comments::allow_modification($anchor, $item)) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // deletion is confirmed
} elseif (isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 'yes') {
    // touch the related anchor before actual deletion, since the item has to be accessible at that time
    if (is_object($anchor)) {
        $anchor->touch('comment:delete', $item['id']);
    }
    // if no error, back to the anchor or to the index page
    if (Comments::delete($item['id'])) {
        Comments::clear($item);
        if ($render_overlaid && isset($_REQUEST['follow_up']) && $_REQUEST['follow_up'] == 'close') {
            echo "deleting done";
            finalize_page(true);
        } elseif (is_object($anchor)) {
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
File: edit.php Progetto: rair/yacs
// fight hackers
$id = strip_tags($id);
$target_anchor = strip_tags($target_anchor);
// get the item from the database
$item = Comments::get($id);
// get the related anchor, if any
$anchor = NULL;
if (isset($item['anchor']) && $item['anchor']) {
    $anchor = Anchors::get($item['anchor']);
} elseif ($target_anchor) {
    $anchor = Anchors::get($target_anchor);
}
// associates and authenticated editors can modify any comment
if ($action != 'edit' && Comments::allow_creation($anchor)) {
    $permitted = TRUE;
} elseif ($action == 'edit' && Comments::allow_modification($anchor, $item)) {
    $permitted = TRUE;
} else {
    $permitted = FALSE;
}
// do not always show the edition form
$with_form = FALSE;
// load the skin, maybe with a variant
load_skin('comments', $anchor);
// clear the tab we are in, if any
if (is_object($anchor)) {
    $context['current_focus'] = $anchor->get_focus();
}
// the path to this page
if (is_object($anchor) && $anchor->is_viewable() && !$render_overlaid) {
    $context['path_bar'] = $anchor->get_path_bar();