Deploying to gh-pages from @ RSS-Bridge/rss-bridge@3ff2ef94e0 🚀

This commit is contained in:
dvikan 2024-04-04 17:29:24 +00:00
parent a73ac3887e
commit 98f89d1284
44 changed files with 110 additions and 44 deletions

View file

@ -100,7 +100,7 @@
<div class="Page__header">
<h1><a href="../Helper_functions/index.html">Helper functions</a></h1>
<span class="ModifiedDate">
March 30, 2024 at 8:12 AM </span>
April 4, 2024 at 10:29 AM </span>
<span class="EditOn">
<a href="https://github.com/RSS-Bridge/rss-bridge/tree/master/docs/06_Helper_functions/index.md" target="_blank">
Edit on GitHub </a>
@ -114,6 +114,7 @@
</code></pre>
<p><code>getInput</code> will either return the value for your parameter
or <code>null</code> if the parameter is unknown or not specified.</p>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/BridgeAbstract.php" class="Link--external" rel="noopener noreferrer">Defined in lib/BridgeAbstract.php</a></p>
<h1><a id="getkey" href="#getkey" class="Permalink" aria-hidden="true" title="Permalink">#</a>getKey</h1>
<p>The <code>getKey</code> function is used to receive the key name to a selected list
value given the name of the list, specified in <code>const PARAMETERS</code>
@ -141,6 +142,7 @@ $this-&gt;getKey('country');
</code></pre>
<p><code>getKey</code> will either return the key name for your parameter or <code>null</code> if the parameter
is unknown or not specified.</p>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/BridgeAbstract.php" class="Link--external" rel="noopener noreferrer">Defined in lib/BridgeAbstract.php</a></p>
<h1><a id="getcontents" href="#getcontents" class="Permalink" aria-hidden="true" title="Permalink">#</a>getContents</h1>
<p>The <code>getContents</code> function uses <a href="https://secure.php.net/manual/en/book.curl.php" class="Link--external" rel="noopener noreferrer">cURL</a> to acquire data from the specified URI while respecting the various settings defined at a global level by RSS-Bridge (i.e., proxy host, user agent, etc.). This function accepts a few parameters:</p>
<table>
@ -183,11 +185,13 @@ is unknown or not specified.</p>
$opts = array(CURLOPT_POST =&gt; 1);
$html = getContents($url, $header, $opts);
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/contents.php" class="Link--external" rel="noopener noreferrer">Defined in lib/contents.php</a></p>
<h1><a id="getsimplehtmldom" href="#getsimplehtmldom" class="Permalink" aria-hidden="true" title="Permalink">#</a>getSimpleHTMLDOM</h1>
<p>The <code>getSimpleHTMLDOM</code> function is a wrapper for the
<a href="https://simplehtmldom.sourceforge.io/" class="Link--external" rel="noopener noreferrer">simple_html_dom</a> <a href="https://simplehtmldom.sourceforge.io/docs/1.9/api/file_get_html/" class="Link--external" rel="noopener noreferrer">file_get_html</a> function in order to provide context by design.</p>
<pre><code class="language-PHP">$html = getSimpleHTMLDOM('your URI');
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/contents.php" class="Link--external" rel="noopener noreferrer">Defined in lib/contents.php</a></p>
<h1><a id="getsimplehtmldomcached" href="#getsimplehtmldomcached" class="Permalink" aria-hidden="true" title="Permalink">#</a>getSimpleHTMLDOMCached</h1>
<p>The <code>getSimpleHTMLDOMCached</code> function does the same as the
<a href="#getsimplehtmldom"><code>getSimpleHTMLDOM</code></a> function,
@ -198,18 +202,21 @@ was not reached.</p>
This function allows to specify the cache duration with the second parameter.</p>
<pre><code class="language-PHP">$html = getSimpleHTMLDOMCached('your URI', 86400); // Duration 24h
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/contents.php" class="Link--external" rel="noopener noreferrer">Defined in lib/contents.php</a></p>
<h1><a id="returnclienterror" href="#returnclienterror" class="Permalink" aria-hidden="true" title="Permalink">#</a>returnClientError</h1>
<p>The <code>returnClientError</code> function aborts execution of the current bridge
and returns the given error message with error code <strong>400</strong>:</p>
<pre><code class="language-PHP">returnClientError('Your error message')
</code></pre>
<p>Use this function when the user provided invalid parameter or a required parameter is missing.</p>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class="Link--external" rel="noopener noreferrer">Defined in lib/utils.php</a></p>
<h1><a id="returnservererror" href="#returnservererror" class="Permalink" aria-hidden="true" title="Permalink">#</a>returnServerError</h1>
<p>The <code>returnServerError</code> function aborts execution of the current bridge and returns the given error message with error code <strong>500</strong>:</p>
<pre><code class="language-PHP">returnServerError('Your error message')
</code></pre>
<p>Use this function when a problem occurs that has nothing to do with the parameters provided by the user.
(like: Host service gone missing, empty data received, etc…)</p>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class="Link--external" rel="noopener noreferrer">Defined in lib/utils.php</a></p>
<h1><a id="defaultlinkto" href="#defaultlinkto" class="Permalink" aria-hidden="true" title="Permalink">#</a>defaultLinkTo</h1>
<p>Automatically replaces any relative URL in a given string or DOM object
(i.e. the one returned by <a href="#getsimplehtmldom">getSimpleHTMLDOM</a>) with an absolute URL.</p>
@ -229,11 +236,13 @@ $html = defaultLinkTo($html, <span class="hljs-keyword">$this</span>-&gt;getURI(
<span class="hljs-comment">// Output</span>
<span class="hljs-comment">// &lt;img src="https://www.github.com/rss-bridge/rss-bridge/blob/master/README.md"&gt;</span>
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="backgroundtoimg" href="#backgroundtoimg" class="Permalink" aria-hidden="true" title="Permalink">#</a>backgroundToImg</h1>
<p>Replaces tags with styles of <code>backgroud-image</code> by <code>&lt;img /&gt;</code> tags.</p>
<pre><code class="hljs php">backgroundToImg(mixed $htmlContent) : object
</code></pre>
<p>Returns a DOM object (even if provided a string).</p>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="extractfromdelimiters" href="#extractfromdelimiters" class="Permalink" aria-hidden="true" title="Permalink">#</a>extractFromDelimiters</h1>
<p>Extract the first part of a string matching the specified start and end delimiters.</p>
<pre><code class="hljs php"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">extractFromDelimiters</span><span class="hljs-params">(string $string, string $start, string $end)</span> : <span class="hljs-title">mixed</span>
@ -248,6 +257,7 @@ $extracted = extractFromDelimiters($string, $start, $end);
<span class="hljs-comment">// Output</span>
<span class="hljs-comment">// 'John Doe'</span>
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="stripwithdelimiters" href="#stripwithdelimiters" class="Permalink" aria-hidden="true" title="Permalink">#</a>stripWithDelimiters</h1>
<p>Remove one or more part(s) of a string using a start and end delimiter.
It is the inverse of <code>extractFromDelimiters</code>.</p>
@ -263,6 +273,7 @@ $cleaned = stripWithDelimiters($string, $start, $end);
<span class="hljs-comment">// Output</span>
<span class="hljs-comment">// 'foobar'</span>
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="striprecursivehtmlsection" href="#striprecursivehtmlsection" class="Permalink" aria-hidden="true" title="Permalink">#</a>stripRecursiveHTMLSection</h1>
<p>Remove HTML sections containing one or more sections using the same HTML tag.</p>
<pre><code class="hljs php"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">stripRecursiveHTMLSection</span><span class="hljs-params">(string $string, string $tag_name, string $tag_start)</span> : <span class="hljs-title">string</span>
@ -276,6 +287,7 @@ $cleaned = stripRecursiveHTMLSection($string, $tag_name, $tag_start);
<span class="hljs-comment">// Output</span>
<span class="hljs-comment">// 'foobar'</span>
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="markdowntohtml" href="#markdowntohtml" class="Permalink" aria-hidden="true" title="Permalink">#</a>markdownToHtml</h1>
<p>Converts markdown input to HTML using <a href="https://parsedown.org/" class="Link--external" rel="noopener noreferrer">Parsedown</a>.</p>
<table>
@ -352,6 +364,60 @@ $html = markdownToHtml($input);
<span class="hljs-comment">// &lt;li&gt;Translation improvements&lt;/li&gt;</span>
<span class="hljs-comment">// &lt;/ul&gt;</span>
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="e" href="#e" class="Permalink" aria-hidden="true" title="Permalink">#</a>e</h1>
<p>The <code>e</code> function is used to convert special characters to HTML entities</p>
<pre><code class="language-PHP">e('0 &lt; 1 and 2 &gt; 1');
</code></pre>
<p><code>e</code> will return the content of the string escape that can be rendered as is in HTML</p>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="truncate" href="#truncate" class="Permalink" aria-hidden="true" title="Permalink">#</a>truncate</h1>
<p>The <code>truncate</code> function is used to shorten a string if exceeds a certain length, and add a string indicating that the string has been shortened.</p>
<pre><code class="language-PHP">truncate('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a neque nunc. Nam nibh sem.', 20 , '...');
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="sanitize" href="#sanitize" class="Permalink" aria-hidden="true" title="Permalink">#</a>sanitize</h1>
<p>The <code>sanitize</code> function is used to remove some tags from a given HTML text.</p>
<pre><code class="language-PHP">$html = '&lt;head&gt;&lt;title&gt;Sample Page&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit...&lt;/p&gt;
&lt;iframe src=&quot;https://www.example.com&quot; width=&quot;600&quot; height=&quot;400&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;
&lt;/body&gt;
&lt;/html&gt;';
$tags_to_remove = ['script', 'iframe', 'input', 'form'];
$attributes_to_keep = ['title', 'href', 'src'];
$text_to_keep = [];
sanitize($html, $tags_to_remove, $attributes_to_keep, $text_to_keep);
</code></pre>
<p>This function returns a simplehtmldom object of the remaining contents.</p>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="convertlazyloading" href="#convertlazyloading" class="Permalink" aria-hidden="true" title="Permalink">#</a>convertLazyLoading</h1>
<p>The <code>convertLazyLoading</code> function is used to convert onvert lazy-loading images and frames (video embeds) into static elements. It accepts the HTML content as HTML objects or string objects. It returns the HTML content with fixed image/frame URLs (same type as input).</p>
<pre><code class="language-PHP">$html = '&lt;html&gt;
&lt;body style=&quot;background-image: url('bgimage.jpg');&quot;&gt;
&lt;h1&gt;Hello world!&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;
backgroundToImg($html);
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class="Link--external" rel="noopener noreferrer">Defined in lib/html.php</a></p>
<h1><a id="json-encode" href="#json-encode" class="Permalink" aria-hidden="true" title="Permalink">#</a>Json::encode</h1>
<p>The <code>Json::encode</code> function is used to encode a value as à JSON string.</p>
<pre><code class="language-PHP">$array = [
&quot;foo&quot; =&gt; &quot;bar&quot;,
&quot;bar&quot; =&gt; &quot;foo&quot;,
];
Json::encode($array, true, true);
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class="Link--external" rel="noopener noreferrer">Defined in lib/utils.php</a></p>
<h1><a id="json-decode" href="#json-decode" class="Permalink" aria-hidden="true" title="Permalink">#</a>Json::decode</h1>
<p>The <code>Json::decode</code> function is used to decode a JSON string into à PHP variable.</p>
<pre><code class="language-PHP">$json = '{
&quot;foo&quot;: &quot;bar&quot;,
&quot;bar&quot;: &quot;foo&quot;
}';
Json::decode($json);
</code></pre>
<p><a href="https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class="Link--external" rel="noopener noreferrer">Defined in lib/utils.php</a></p>
</div>
<nav>