Commit 7ecdd449 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4384 (Tempcode optimisations)

parent 1055d20d
Loading
Loading
Loading
Loading
+0 −0

File changed.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.

+1 −1
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ The following escaping filters are provided ([color="green"]green[/color] indica
	<tbody>
		<tr style="background-color: #FFDDDD">
			<td>[tt]-[/tt]</td>
			<td colspan="3">Special code to indicate that a construct should not be pre-processed. This is useful very occasionally if you want to stop something like a block being preloaded if it is buried under a Tempcode IF directive and hence doesn't always run. Stopping pre-processing will stop any JavaScript or [abbr="Cascading Style Sheets"]CSS[/abbr] dependencies being called up, however.</td>
			<td colspan="3">Special code to indicate that a construct should not be pre-processed. This is useful very occasionally if you want to stop something like a block being preloaded if it is buried under a Tempcode IF directive and hence doesn't always run. It also reduces the Tempcode tree memory usage a lot. Stopping pre-processing will stop any JavaScript or [abbr="Cascading Style Sheets"]CSS[/abbr] dependencies being called up, however.</td>
		</tr>
		<tr style="background-color: #FFDDDD">
			<td>[tt]+[/tt]</td>
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ function render_download_box($row, $pic = true, $include_breadcrumbs = true, $zo
        'RATING' => $rating,
        'VIEWS' => integer_format($row['download_views']),
        'SUBMITTER' => strval($row['submitter']),
        'DESCRIPTION' => $description,
        'DESCRIPTION' => reasonable_html_reduce($description),
        'FILE_SIZE' => $file_size,
        'DOWNLOADS' => integer_format($row['num_downloads']),
        'DATE_RAW' => strval($date_raw),
+11 −2
Original line number Diff line number Diff line
@@ -284,7 +284,12 @@ function get_rating_box($content_url, $content_title, $content_type, $content_id
 */
function display_rating($content_url, $content_title, $content_type, $content_id, $display_tpl = 'RATING_INLINE_STATIC', $submitter = null)
{
    $rating_data = get_rating_simple_array($content_url, $content_title, $content_type, $content_id, 'RATING_FORM', $submitter);
    if ($display_tpl == 'RATING_INLINE_STATIC') {
        $form_tpl = null;
    } else {
        $form_tpl = 'RATING_FORM';
    }
    $rating_data = get_rating_simple_array($content_url, $content_title, $content_type, $content_id, $form_tpl, $submitter);

    if (is_null($rating_data)) {
        return new Tempcode();
@@ -300,7 +305,7 @@ function display_rating($content_url, $content_title, $content_type, $content_id
 * @param  ?string $content_title The title to where the commenting will pass back to (to put into the comment topic header) (null: don't know, but not first post so not important)
 * @param  ID_TEXT $content_type The type (download, etc) that this rating is for
 * @param  ID_TEXT $content_id The ID of the type that this rating is for
 * @param  ID_TEXT $form_tpl The template to use to display the rating box
 * @param  ?ID_TEXT $form_tpl The template to use to display the rating box (null: none)
 * @param  ?MEMBER $submitter Content owner (null: none)
 * @return ?array Current rating information (ready to be passed into a template). RATING is the rating (out of 10), NUM_RATINGS is the number of ratings so far, RATING_FORM is the Tempcode of the rating box (null: rating disabled)
 */
@@ -418,7 +423,11 @@ function get_rating_simple_array($content_url, $content_title, $content_type, $c
            'LIKES' => $likes,
            'LIKED_BY' => $liked_by,
        ) + $all_rating_criteria[$content_type]/*so can assume single rating criteria if want and reference that directly*/;
        if ($form_tpl === null) {
            $rating_form = new Tempcode();
        } else {
            $rating_form = do_template($form_tpl, $tpl_params);
        }
        $ret = $tpl_params + array(
            'RATING_FORM' => $rating_form,
        );
+16 −0
Original line number Diff line number Diff line
@@ -2204,3 +2204,19 @@ function debug_call_user_func($function, $a, $b = null, $c = null)
{
    return call_user_func($function, $a, $b, $c);
}

/**
 * Reduce down a template parameter to a maximum reasonable length, to avoid too much data being stuck in Tempcode trees.
 *
 * @param  Tempcode $text Text
 * @param  integer $max_length Maximum length
 * @return Tempcode Reduced length version of $text if required
 */
function reasonable_html_reduce($text, $max_length = 1000)
{
    $text_flat = $text->evaluate();
    if (strlen($text_flat) > $max_length) {
        $text = make_string_tempcode(symbol_truncator(array($text_flat, strval($max_length), '0', '1'), 'left'));
    }
    return $text;
}
Loading