aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/html/Download-CSS-styles-from-an-OPML-list
diff options
context:
space:
mode:
Diffstat (limited to 'doc/html/Download-CSS-styles-from-an-OPML-list')
-rw-r--r--doc/html/Download-CSS-styles-from-an-OPML-list/index.html496
1 files changed, 0 insertions, 496 deletions
diff --git a/doc/html/Download-CSS-styles-from-an-OPML-list/index.html b/doc/html/Download-CSS-styles-from-an-OPML-list/index.html
deleted file mode 100644
index e697b39d..00000000
--- a/doc/html/Download-CSS-styles-from-an-OPML-list/index.html
+++ /dev/null
@@ -1,496 +0,0 @@
1<!DOCTYPE html>
2<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
3<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
4<head>
5 <meta charset="utf-8">
6 <meta http-equiv="X-UA-Compatible" content="IE=edge">
7 <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
9
10 <link rel="shortcut icon" href="../img/favicon.ico">
11 <title>Download CSS styles from an OPML list - Shaarli Documentation</title>
12 <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
13
14 <link rel="stylesheet" href="../css/theme.css" type="text/css" />
15 <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
16 <link rel="stylesheet" href="../css/highlight.css">
17 <link href="../github-markdown.css" rel="stylesheet">
18
19 <script>
20 // Current page data
21 var mkdocs_page_name = "Download CSS styles from an OPML list";
22 var mkdocs_page_input_path = "Download-CSS-styles-from-an-OPML-list.md";
23 var mkdocs_page_url = "/Download-CSS-styles-from-an-OPML-list/";
24 </script>
25
26 <script src="../js/jquery-2.1.1.min.js"></script>
27 <script src="../js/modernizr-2.8.3.min.js"></script>
28 <script type="text/javascript" src="../js/highlight.pack.js"></script>
29
30</head>
31
32<body class="wy-body-for-nav" role="document">
33
34 <div class="wy-grid-for-nav">
35
36
37 <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
38 <div class="wy-side-nav-search">
39 <a href=".." class="icon icon-home"> Shaarli Documentation</a>
40 <div role="search">
41 <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
42 <input type="text" name="q" placeholder="Search docs" />
43 </form>
44</div>
45 </div>
46
47 <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
48 <ul class="current">
49
50
51 <li class="toctree-l1">
52
53 <a class="" href="..">Home</a>
54 </li>
55
56 <li class="toctree-l1">
57
58 <span class="caption-text">Setup</span>
59 <ul class="subnav">
60 <li class="">
61
62 <a class="" href="../Download-and-Installation/">Download and Installation</a>
63 </li>
64 <li class="">
65
66 <a class="" href="../Upgrade-and-migration/">Upgrade and migration</a>
67 </li>
68 <li class="">
69
70 <a class="" href="../Server-requirements/">Server requirements</a>
71 </li>
72 <li class="">
73
74 <a class="" href="../Server-configuration/">Server configuration</a>
75 </li>
76 <li class="">
77
78 <a class="" href="../Server-security/">Server security</a>
79 </li>
80 <li class="">
81
82 <a class="" href="../Shaarli-configuration/">Shaarli configuration</a>
83 </li>
84 <li class="">
85
86 <a class="" href="../Plugins/">Plugins</a>
87 </li>
88 </ul>
89 </li>
90
91 <li class="toctree-l1">
92
93 <span class="caption-text">Docker</span>
94 <ul class="subnav">
95 <li class="">
96
97 <a class="" href="../Docker-101/">Docker 101</a>
98 </li>
99 <li class="">
100
101 <a class="" href="../Shaarli-images/">Shaarli images</a>
102 </li>
103 <li class="">
104
105 <a class="" href="../Reverse-proxy-configuration/">Reverse proxy configuration</a>
106 </li>
107 <li class="">
108
109 <a class="" href="../Docker-resources/">Docker resources</a>
110 </li>
111 </ul>
112 </li>
113
114 <li class="toctree-l1">
115
116 <span class="caption-text">Usage</span>
117 <ul class="subnav">
118 <li class="">
119
120 <a class="" href="../Features/">Features</a>
121 </li>
122 <li class="">
123
124 <a class="" href="../Bookmarklet/">Bookmarklet</a>
125 </li>
126 <li class="">
127
128 <a class="" href="../Browsing-and-searching/">Browsing and searching</a>
129 </li>
130 <li class="">
131
132 <a class="" href="../Firefox-share/">Firefox share</a>
133 </li>
134 <li class="">
135
136 <a class="" href="../RSS-feeds/">RSS feeds</a>
137 </li>
138 <li class="">
139
140 <a class="" href="../REST-API/">REST API</a>
141 </li>
142 </ul>
143 </li>
144
145 <li class="toctree-l1">
146
147 <span class="caption-text">How To</span>
148 <ul class="subnav">
149 <li class="">
150
151 <a class="" href="../Backup,-restore,-import-and-export/">Backup, restore, import and export</a>
152 </li>
153 <li class="">
154
155 <a class="" href="../Copy-an-existing-installation-over-SSH-and-serve-it-locally/">Copy an existing installation over SSH and serve it locally</a>
156 </li>
157 <li class="">
158
159 <a class="" href="../Create-and-serve-multiple-Shaarlis-(farm)/">Create and serve multiple Shaarlis (farm)</a>
160 </li>
161 <li class=" current">
162
163 <a class="current" href="./">Download CSS styles from an OPML list</a>
164 <ul class="subnav">
165
166 <li class="toctree-l3"><a href="#download-css-styles-for-shaarlis-listed-in-an-opml-file">Download CSS styles for shaarlis listed in an opml file</a></li>
167
168
169 </ul>
170 </li>
171 <li class="">
172
173 <a class="" href="../Datastore-hacks/">Datastore hacks</a>
174 </li>
175 </ul>
176 </li>
177
178 <li class="toctree-l1">
179
180 <a class="" href="../Troubleshooting/">Troubleshooting</a>
181 </li>
182
183 <li class="toctree-l1">
184
185 <span class="caption-text">Development</span>
186 <ul class="subnav">
187 <li class="">
188
189 <a class="" href="../Development-guidelines/">Development guidelines</a>
190 </li>
191 <li class="">
192
193 <a class="" href="../Continuous-integration-tools/">Continuous integration tools</a>
194 </li>
195 <li class="">
196
197 <a class="" href="../GnuPG-signature/">GnuPG signature</a>
198 </li>
199 <li class="">
200
201 <a class="" href="../Coding-guidelines/">Coding guidelines</a>
202 </li>
203 <li class="">
204
205 <a class="" href="../Directory-structure/">Directory structure</a>
206 </li>
207 <li class="">
208
209 <a class="" href="../3rd-party-libraries/">3rd party libraries</a>
210 </li>
211 <li class="">
212
213 <a class="" href="../Plugin-System/">Plugin System</a>
214 </li>
215 <li class="">
216
217 <a class="" href="../Release-Shaarli/">Release Shaarli</a>
218 </li>
219 <li class="">
220
221 <a class="" href="../Versioning-and-Branches/">Versioning and Branches</a>
222 </li>
223 <li class="">
224
225 <a class="" href="../Security/">Security</a>
226 </li>
227 <li class="">
228
229 <a class="" href="../Static-analysis/">Static analysis</a>
230 </li>
231 <li class="">
232
233 <a class="" href="../Theming/">Theming</a>
234 </li>
235 <li class="">
236
237 <a class="" href="../Unit-tests/">Unit tests</a>
238 </li>
239 </ul>
240 </li>
241
242 <li class="toctree-l1">
243
244 <span class="caption-text">About</span>
245 <ul class="subnav">
246 <li class="">
247
248 <a class="" href="../FAQ/">FAQ</a>
249 </li>
250 <li class="">
251
252 <a class="" href="../Community-&-Related-software/">Community & Related software</a>
253 </li>
254 </ul>
255 </li>
256
257 </ul>
258 </div>
259 &nbsp;
260 </nav>
261
262 <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
263
264
265 <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
266 <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
267 <a href="..">Shaarli Documentation</a>
268 </nav>
269
270
271 <div class="wy-nav-content">
272 <div class="rst-content">
273 <div role="navigation" aria-label="breadcrumbs navigation">
274 <ul class="wy-breadcrumbs">
275 <li><a href="..">Docs</a> &raquo;</li>
276
277
278
279 <li>How To &raquo;</li>
280
281
282
283 <li>Download CSS styles from an OPML list</li>
284 <li class="wy-breadcrumbs-aside">
285
286 <a href="https://github.com/shaarli/Shaarli/edit/master/docs/Download-CSS-styles-from-an-OPML-list.md"
287 class="icon icon-github"> Edit on GitHub</a>
288
289 </li>
290 </ul>
291 <hr/>
292</div>
293 <div role="main">
294 <div class="section">
295
296 <h3 id="download-css-styles-for-shaarlis-listed-in-an-opml-file">Download CSS styles for shaarlis listed in an opml file</h3>
297<p>Example php script:</p>
298<pre><code class="php">&lt;!---- ?php --&gt;
299&lt;!---- Copyright (c) 2014 Nicolas Delsaux (https://github.com/Riduidel) --&gt;
300&lt;!---- License: zlib (http://www.gzip.org/zlib/zlib_license.html) --&gt;
301
302/**
303 * Source: https://github.com/Riduidel
304 * Download css styles for shaarlis listed in an opml file
305 */
306define(&quot;SHAARLI_RSS_OPML&quot;, &quot;https://www.ecirtam.net/shaarlirss/custom/people.opml&quot;);
307
308define(&quot;THEMES_TEMP_FOLDER&quot;, &quot;new_themes&quot;);
309
310if(!file_exists(THEMES_TEMP_FOLDER)) {
311 mkdir(THEMES_TEMP_FOLDER);
312}
313
314function siteUrl($pathInSite) {
315 $indexPos = strpos($pathInSite, &quot;index.php&quot;);
316 if(!$indexPos) {
317 return $pathInSite;
318 } else {
319 return substr($pathInSite, 0, $indexPos);
320 }
321}
322
323function createShaarliHashFromOPMLL($opmlFile) {
324 $result = array();
325 $opml = file_get_contents($opmlFile);
326 $opmlXml = simplexml_load_string($opml);
327 $outlineElements = $opmlXml-&gt;xpath(&quot;body/outline&quot;);
328 foreach($outlineElements as $site) {
329 $siteUrl = siteUrl((string) $site['htmlUrl']);
330 $result[$siteUrl]=((string) $site['text']);
331 }
332 return $result;
333}
334
335function getSiteFolder($url) {
336 $domain = parse_url($url, PHP_URL_HOST);
337 return THEMES_TEMP_FOLDER.&quot;/&quot;.str_replace(&quot;.&quot;, &quot;_&quot;, $domain);
338}
339
340function get_http_response_code($theURL) {
341 $headers = get_headers($theURL);
342 return substr($headers[0], 9, 3);
343}
344
345/**
346 * This makes the code PHP-5 only (particularly the call to &quot;get_headers&quot;)
347 */
348function copyUserStyleFrom($url, $name, $knownStyles) {
349 $userStyle = $url.&quot;inc/user.css&quot;;
350 if(in_array($url, $knownStyles)) {
351 // TODO add log message
352 } else {
353 $statusCode = get_http_response_code($userStyle);
354 if(intval($statusCode)&lt;300) {
355 $styleSheet = file_get_contents($userStyle);
356 $siteFolder = getSiteFolder($url);
357 if(!file_exists($siteFolder)) {
358 mkdir($siteFolder);
359 }
360 if(!file_exists($siteFolder.'/user.css')) {
361 // Copy stylesheet
362 file_put_contents($siteFolder.'/user.css', $styleSheet);
363 }
364 if(!file_exists($siteFolder.'/README.md')) {
365 // Then write a readme.md file
366 file_put_contents($siteFolder.'/README.md',
367 &quot;User style from &quot;.$name.&quot;\n&quot;
368 .&quot;=============================&quot;
369 .&quot;\n\n&quot;
370 .&quot;This stylesheet was downloaded from &quot;.$userStyle.&quot; on &quot;.date(DATE_RFC822)
371 );
372 }
373 if(!file_exists($siteFolder.'/config.ini')) {
374 // Write a config file containing useful informations
375 file_put_contents($siteFolder.'/config.ini',
376 &quot;site_url=&quot;.$url.&quot;\n&quot;
377 .&quot;site_name=&quot;.$name.&quot;\n&quot;
378 );
379 }
380 if(!file_exists($siteFolder.'/home.png')) {
381 // And finally copy generated thumbnail
382 $homeThumb = $siteFolder.'/home.png';
383 file_put_contents($siteFolder.'/home.png', file_get_contents(getThumbnailUrl($url)));
384 }
385 echo 'Theme have been downloaded from &lt;a href=&quot;'.$url.'&quot;&gt;'.$url.'&lt;/a&gt; into '.$siteFolder
386 .'. It looks like &lt;img src=&quot;'.$homeThumb.'&quot;&gt;&lt;br/&gt;';
387 }
388 }
389}
390
391function getThumbnailUrl($url) {
392 return 'http://api.webthumbnail.org/?url='.$url;
393}
394
395function copyUserStylesFrom($urlToNames, $knownStyles) {
396 foreach($urlToNames as $url =&gt; $name) {
397 copyUserStyleFrom($url, $name, $knownStyles);
398 }
399}
400
401/**
402 * Reading directory list, courtesy of http://www.laughing-buddha.net/php/dirlist/
403 * @param directory the directory we want to list files of
404 * @return a simple array containing the list of absolute file paths. Notice that current file (&quot;.&quot;) and parent one(&quot;..&quot;)
405 * are not listed here
406 */
407function getDirectoryList ($directory) {
408 $realPath = realpath($directory);
409 // create an array to hold directory list
410 $results = array();
411 // create a handler for the directory
412 $handler = opendir($directory);
413 // open directory and walk through the filenames
414 while ($file = readdir($handler)) {
415 // if file isn't this directory or its parent, add it to the results
416 if ($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot;) {
417 $results[] = realpath($realPath . &quot;/&quot; . $file);
418 }
419 }
420 // tidy up: close the handler
421 closedir($handler);
422 // done!
423 return $results;
424}
425
426/**
427 * Start in themes folder and look in all subfolders for config.ini files.
428 * These config.ini files allow us not to download styles again and again
429 */
430function findKnownStyles() {
431 $result = array();
432 $subFolders = getDirectoryList(&quot;themes&quot;);
433 foreach($subFolders as $folder) {
434 $configFile = $folder.&quot;/config.ini&quot;;
435 if(file_exists($configFile)) {
436 $iniParameters = parse_ini_file($configFile);
437 array_push($result, $iniParameters['site_url']);
438 }
439 }
440 return $result;
441}
442
443$knownStyles = findKnownStyles();
444copyUserStylesFrom(createShaarliHashFromOPMLL(SHAARLI_RSS_OPML), $knownStyles);
445
446&lt;!--- ? ----&gt;
447</code></pre>
448
449 </div>
450 </div>
451 <footer>
452
453 <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
454
455 <a href="../Datastore-hacks/" class="btn btn-neutral float-right" title="Datastore hacks">Next <span class="icon icon-circle-arrow-right"></span></a>
456
457
458 <a href="../Create-and-serve-multiple-Shaarlis-(farm)/" class="btn btn-neutral" title="Create and serve multiple Shaarlis (farm)"><span class="icon icon-circle-arrow-left"></span> Previous</a>
459
460 </div>
461
462
463 <hr/>
464
465 <div role="contentinfo">
466 <!-- Copyright etc -->
467
468 </div>
469
470 Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
471</footer>
472
473 </div>
474 </div>
475
476 </section>
477
478 </div>
479
480 <div class="rst-versions" role="note" style="cursor: pointer">
481 <span class="rst-current-version" data-toggle="rst-current-version">
482
483 <a href="https://github.com/shaarli/Shaarli" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
484
485
486 <span><a href="../Create-and-serve-multiple-Shaarlis-(farm)/" style="color: #fcfcfc;">&laquo; Previous</a></span>
487
488
489 <span style="margin-left: 15px"><a href="../Datastore-hacks/" style="color: #fcfcfc">Next &raquo;</a></span>
490
491 </span>
492</div>
493 <script src="../js/theme.js"></script>
494
495</body>
496</html>