$fields['introduction'] = i18n::c('Sample support request'); $fields['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S'); $overlay = Overlay::bind('issue'); $fields['overlay'] = $overlay->save(); $fields['overlay_id'] = $overlay->get_id(); if (Articles::post($fields)) { $text .= sprintf(i18n::s('A page "%s" has been created.'), $fields['nick_name']) . BR . "\n"; $overlay->remember('insert', $fields, 'article:' . $fields['id']); } else { $text .= Logger::error_pop() . BR . "\n"; } } // add sample comments to 'bugzilla_page' if ($anchor = Articles::lookup('bugzilla_page')) { // add a bunch of comments $stats = Comments::stat_for_anchor($anchor); if ($stats['count'] < 50) { for ($index = 1; $index <= 10; $index++) { $fields = array(); $fields['anchor'] = $anchor; $fields['description'] = sprintf(i18n::c('Comment #%d'), $index); $fields['edit_name'] = $names[rand(0, 2)]; if (!Comments::post($fields)) { $text .= Logger::error_pop() . BR . "\n"; break; } } if ($index > 1) { $text .= sprintf(i18n::s('Comments have been added to "%s".'), 'bugzilla_page') . BR . "\n"; } }
/** * list articles * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // the script used to check all pages at once Page::insert_script('function cascade_selection_to_all_article_rows(handle) {' . "\n" . ' $("div#articles_panel input[type=\'checkbox\'].row_selector").each(' . "\n" . ' function() { $(this).attr("checked", $(handle).is(":checked"));}' . "\n" . ' );' . "\n" . '}' . "\n"); // table prefix $text .= Skin::table_prefix('yc-grid'); // table headers $main = '<input type="checkbox" class="row_selector" onclick="cascade_selection_to_all_article_rows(this);" />'; $cells = array($main, i18n::s('Page'), i18n::s('Rank')); $text .= Skin::table_row($cells, 'header'); // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; $count = 0; while ($item = SQL::fetch($result)) { $cells = array(); // get the related overlay, if any $overlay = Overlay::load($item, 'article:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // column to select the row $cells[] = '<input type="checkbox" name="selected_articles[]" id="article_selector_' . $count . '" class="row_selector" value="' . $item['id'] . '" />'; // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag sticky pages if ($item['rank'] < 10000) { $prefix .= STICKY_FLAG; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y') { $suffix .= ' ' . LOCKED_FLAG; } // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $suffix .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= ' ' . UPDATED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // the introductory text if (is_object($overlay)) { $introduction = $overlay->get_text('introduction', $item); } else { $introduction = $item['introduction']; } if ($introduction) { $suffix .= BR . Codes::beautify_introduction($introduction); } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item); } // append details to the suffix $suffix .= BR . '<span class="details">'; // details $details = array(); // the author if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') { if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('by %s, %s'), $item['create_name'], $item['edit_name']); } else { $details[] = sprintf(i18n::s('by %s'), $item['create_name']); } } // the last action $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']); // the number of hits if (Surfer::is_logged() && $item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('hits')); } // info on related files $stats = Files::stat_for_anchor('article:' . $item['id']); if ($stats['count']) { $details[] = sprintf(i18n::ns('%d file', '%d files', $stats['count']), $stats['count']); } // info on related links $stats = Links::stat_for_anchor('article:' . $item['id']); if ($stats['count']) { $details[] = sprintf(i18n::ns('%d link', '%d links', $stats['count']), $stats['count']); } // info on related comments $stats = Comments::stat_for_anchor('article:' . $item['id']); if ($stats['count']) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $stats['count']), $stats['count']); } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // combine in-line details if (count($details)) { $suffix .= ucfirst(trim(implode(', ', $details))); } // list up to three categories by title, if any $anchors = array(); if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) { foreach ($members as $id => $attributes) { // add background color to distinguish this category against others if (isset($attributes['background_color']) && $attributes['background_color']) { $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>'; } $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic'); } } if (count($anchors)) { $suffix .= BR . sprintf(i18n::s('In %s'), implode(' / ', $anchors)); } // end of details $suffix .= '</span>'; // strip empty details $suffix = str_replace(BR . '<span class="details"></span>', '', $suffix); $suffix = str_replace('<span class="details"></span>', '', $suffix); // the icon to put in the left column if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } // commands $commands = array(Skin::build_link(Articles::get_url($item['id'], 'edit'), i18n::s('edit'), 'basic'), Skin::build_link(Articles::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic')); // link to this page $cells[] = $prefix . Skin::build_link($url, $title, 'article') . ' - ' . Skin::finalize_list($commands, 'menu') . $suffix; // ranking $cells[] = '<input type="text" size="5" name="article_rank_' . $item['id'] . '" value="' . $item['rank'] . '" onfocus="$(\'#article_selector_' . $count . '\').attr(\'checked\', \'checked\');" onchange="$(\'#act_on_articles\').prop(\'selectedIndex\', 9);" />'; // append the row $text .= Skin::table_row($cells, $count++); } // select all rows $cells = array('<input type="checkbox" class="row_selector" onclick="cascade_selection_to_all_article_rows(this);" />', i18n::s('Select all/none'), ''); $text .= Skin::table_row($cells, $count++); // table suffix $text .= Skin::table_suffix(); // end of processing SQL::free($result); return $text; }
/** * count related items * * This function draws a nice table to show how many items are related to * the anchor that has the focus. * * @param string the target reference * @param string the label to use, if any * @return string some XHTML snippet to send to the browser */ public static function stat_related_to($anchor, $label = NULL) { global $context; // describe related content $related = ''; $lines = 2; // stats for related categories, but only within categories if (strpos($anchor, 'category:') === 0) { if (($stats = Categories::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Categories'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } } // stats for related sections, but only within sections if (strpos($anchor, 'section:') === 0) { if (($stats = Sections::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Sections'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } } // stats for related articles, but only within sections if (strpos($anchor, 'section:') === 0) { if (($stats = Articles::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Pages'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } } // stats for related images include_once $context['path_to_root'] . 'images/images.php'; if (($stats = Images::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Images'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // stats for related locations include_once $context['path_to_root'] . 'locations/locations.php'; if (($stats = Locations::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Locations'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // stats for related tables include_once $context['path_to_root'] . 'tables/tables.php'; if (($stats = Tables::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Tables'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // stats for related files if (($stats = Files::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Files'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // stats for related dates include_once $context['path_to_root'] . 'dates/dates.php'; if (($stats = Dates::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Dates'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // stats for related comments include_once $context['path_to_root'] . 'comments/comments.php'; if (($stats = Comments::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Comments'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // stats for related links include_once $context['path_to_root'] . 'links/links.php'; if (($stats = Links::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Links'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // stats for related versions include_once $context['path_to_root'] . 'versions/versions.php'; if (($stats = Versions::stat_for_anchor($anchor)) && $stats['count']) { $cells = array(); $cells[] = i18n::s('Versions'); $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . Skin::build_date($stats['oldest_date']); $cells[] = 'center=' . Skin::build_date($stats['newest_date']); $related .= Skin::table_row($cells, $lines++); } // ensure we have a label if (!$label) { $label = i18n::s('Following items are attached to this record and will be impacted as well.'); } // stats for related items in a neat table if ($related) { // make a nice table $related = '<p>' . $label . "</p>\n" . Skin::table_prefix('') . Skin::table_row(array(i18n::s('Table'), i18n::s('Records'), i18n::s('Creation date'), i18n::s('Last edition')), 'header') . $related . Skin::table_suffix(); // put it in a box $related = Skin::build_box(i18n::s('Related items'), $related); } // job done return $related; }