aboutsummaryrefslogtreecommitdiff
path: root/bridges/KernelBugTrackerBridge.php
blob: d617b80fd17955afeb19f105b3bd671e7d9f621f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
class KernelBugTrackerBridge extends BridgeAbstract {

	const NAME = 'Kernel Bug Tracker';
	const URI = 'https://bugzilla.kernel.org';
	const DESCRIPTION = 'Returns feeds for bug comments';
	const MAINTAINER = 'logmanoriginal';
	const PARAMETERS = array(
		'Bug comments' => array(
			'id' => array(
				'name' => 'Bug tracking ID',
				'type' => 'number',
				'required' => true,
				'title' => 'Insert bug tracking ID',
				'exampleValue' => 121241
			),
			'limit' => array(
				'name' => 'Number of comments to return',
				'type' => 'number',
				'required' => false,
				'title' => 'Specify number of comments to return',
				'defaultValue' => -1
			),
			'sorting' => array(
				'name' => 'Sorting',
				'type' => 'list',
				'required' => false,
				'title' => 'Defines the sorting order of the comments returned',
				'defaultValue' => 'of',
				'values' => array(
					'Oldest first' => 'of',
					'Latest first' => 'lf'
				)
			)
		)
	);

	private $bugid = '';
	private $bugdesc = '';

	public function getIcon() {
		return self::URI . '/images/favicon.ico';
	}

	public function collectData(){
		$limit = $this->getInput('limit');
		$sorting = $this->getInput('sorting');

		// We use the print preview page for simplicity
		$html = getSimpleHTMLDOMCached($this->getURI() . '&format=multiple',
		86400,
		null,
		null,
		true,
		true,
		DEFAULT_TARGET_CHARSET,
		false, // Do NOT remove line breaks
		DEFAULT_BR_TEXT,
		DEFAULT_SPAN_TEXT);

		if($html === false)
			returnServerError('Failed to load page!');

		// Store header information into private members
		$this->bugid = $html->find('#bugzilla-body', 0)->find('a', 0)->innertext;
		$this->bugdesc = $html->find('table.bugfields', 0)->find('tr', 0)->find('td', 0)->innertext;

		// Get and limit comments
		$comments = $html->find('div.bz_comment');

		if($limit > 0 && count($comments) > $limit) {
			$comments = array_slice($comments, count($comments) - $limit, $limit);
		}

		// Order comments
		switch($sorting) {
			case 'lf': $comments = array_reverse($comments, true);
			case 'of':
			default: // Nothing to do, keep original order
		}

		foreach($comments as $comment) {
			$comment = $this->inlineStyles($comment);

			$item = array();
			$item['uri'] = $this->getURI() . '#' . $comment->id;
			$item['author'] = $comment->find('span.bz_comment_user', 0)->innertext;
			$item['title'] = $comment->find('span.bz_comment_number', 0)->find('a', 0)->innertext;
			$item['timestamp'] = strtotime($comment->find('span.bz_comment_time', 0)->innertext);
			$item['content'] = $comment->find('pre.bz_comment_text', 0)->innertext;

			// Fix line breaks (they use LF)
			$item['content'] = str_replace("\n", '<br>', $item['content']);

			// Fix relative URIs
			$item['content'] = $this->replaceRelativeURI($item['content']);

			$this->items[] = $item;
		}

	}

	public function getURI(){
		switch($this->queriedContext) {
			case 'Bug comments':
				return parent::getURI()
				. '/show_bug.cgi?id='
				. $this->getInput('id');
				break;
			default: return parent::getURI();
		}
	}

	public function getName(){
		switch($this->queriedContext) {
			case 'Bug comments':
				return 'Bug '
				. $this->bugid
				. ' tracker for '
				. $this->bugdesc
				. ' - '
				. parent::getName();
				break;
			default: return parent::getName();
		}
	}

	/**
	 * Replaces all relative URIs with absolute ones
	 *
	 * @param string $content The source string
	 * @return string Returns the source string with all relative URIs replaced
	 * by absolute ones.
	 */
	private function replaceRelativeURI($content){
		return preg_replace('/href="(?!http)/', 'href="' . self::URI . '/', $content);
	}

	/**
	 * Adds styles as attributes to tags with known classes
	 *
	 * @param object $html A simplehtmldom object
	 * @return object Returns the original object with styles added as
	 * attributes.
	 */
	private function inlineStyles($html){
		foreach($html->find('.bz_obsolete') as $element) {
			$element->style = 'text-decoration:line-through;';
		}

		return $html;
	}
}
sg191/astro/commit/pnpm-lock.yaml?h=fix-s-island-fallback&id=e723e9e8ea21531b5200b22a14aca333b3a0580d&follow=1'>[ci] release (#12403)astro@4.16.11Gravatar Houston (Bot) 30-73/+68 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2024-11-11[ci] formatGravatar Sarah Rainsberger 1-38/+38 2024-11-11update markdown config docs (#12382)Gravatar Sarah Rainsberger 1-4/+45 Co-authored-by: ArmandPhilippot <59021693+ArmandPhilippot@users.noreply.github.com> Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com> Co-authored-by: jsparkdev <39112954+jsparkdev@users.noreply.github.com> Co-authored-by: bluwy <34116392+bluwy@users.noreply.github.com> 2024-11-08Fix incorrect status code in dev server for action errors (#12401)Gravatar Ben Holmes 2-13/+21 * remove default status that swallows response.status * refactor status compute to be more readable * changeset 2024-11-08fix(actions): better runtime check for invalid usages (#12402)Gravatar Emanuele Stoppa 8-5/+47 2024-11-08fix: error overlay message escape (#12305)Gravatar Florian Lefebvre 3-0/+28 Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com> 2024-11-06[ci] release (#12369)astro@4.16.10@astrojs/svelte@5.7.3Gravatar Houston (Bot) 34-81/+74 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2024-11-06[ci] formatGravatar Bjorn Lu 2-18/+17 2024-11-06Add support for Svelte 5 @render syntax (#12390)Gravatar Bjorn Lu 3-0/+30 Co-authored-by: Jonas Robertsson <jonas.robertsson@icloud.com> 2024-11-06fix(deps): update all non-major dependencies (#12366)Gravatar renovate[bot] 29-533/+552 Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: bluwy <bjornlu.dev@gmail.com> 2024-11-06add `checked` to htmlBooleanAttributes (#12311)Gravatar Sujal Gurung 2-1/+6 Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> 2024-11-06fix: show file name with invalid frontmatter errors for MDX (#12355)Gravatar Arpan Patel 6-63/+50 Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com> 2024-11-06[ci] formatGravatar Emanuele Stoppa 2-3/+3 2024-11-06chore: codspeed benchmark (#12347)Gravatar Emanuele Stoppa 19-42/+527 2024-11-06Fix `astro add` generated import identifier (#12363)Gravatar Luiz Ferraz 2-1/+11 2024-11-04Improve tinyexec errors (#12368)Gravatar Bjorn Lu 11-5/+45 2024-11-04[ci] release (#12345)astro@4.16.9Gravatar Houston (Bot) 33-79/+65 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2024-11-04fix: honor getViteConfig inlineAstroConfig.logLevel setting (#12358)Gravatar Paul Welsh 2-7/+8 Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> 2024-11-04Fix watchfile multiple dev server restart (#12353)Gravatar Hippo 2-1/+8 2024-11-01fix: revert #12227 (#12351)Gravatar Florian Lefebvre 4-8/+11 2024-11-01[ci] formatGravatar Vladislav Mamon 2-5/+7 2024-11-01fix(assets): fix `getImage` options type (#12349)Gravatar Vladislav Mamon 3-3/+13 2024-11-01Fix prefetch sourcemap generation (#12346)Gravatar Bjorn Lu 2-6/+21 2024-10-31fix: Destroy the node http server response stream if there was a caught ↵Gravatar Matt Callaway 2-2/+9 error (#12333) 2024-10-31[ci] release (#12290)astro@4.16.8@astrojs/mdx@3.1.9Gravatar Houston (Bot) 36-93/+80 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2024-10-31Fix cli command typo (#12342)Gravatar liruifengv 2-1/+6 Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> 2024-10-31[ci] formatGravatar situ2001 1-1/+1 2024-10-31fix(cli): reset `NODE_ENV` to ensure install command run in dev mode (#12338)Gravatar situ2001 2-1/+12