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]-->
6 <meta http-equiv=
"X-UA-Compatible" content=
"IE=edge">
7 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0">
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'
>
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">
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/";
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>
32 <body class=
"wy-body-for-nav" role=
"document">
34 <div class=
"wy-grid-for-nav">
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>
41 <form id =
"rtd-search-form" class=
"wy-form" action=
"../search.html" method=
"get">
42 <input type=
"text" name=
"q" placeholder=
"Search docs" />
47 <div class=
"wy-menu wy-menu-vertical" data-spy=
"affix" role=
"navigation" aria-label=
"main navigation">
51 <li class=
"toctree-l1">
53 <a class=
"" href=
"..">Home
</a>
56 <li class=
"toctree-l1">
58 <span class=
"caption-text">Setup
</span>
62 <a class=
"" href=
"../Download-and-Installation/">Download and Installation
</a>
66 <a class=
"" href=
"../Upgrade-and-migration/">Upgrade and migration
</a>
70 <a class=
"" href=
"../Server-requirements/">Server requirements
</a>
74 <a class=
"" href=
"../Server-configuration/">Server configuration
</a>
78 <a class=
"" href=
"../Server-security/">Server security
</a>
82 <a class=
"" href=
"../Shaarli-configuration/">Shaarli configuration
</a>
86 <a class=
"" href=
"../Plugins/">Plugins
</a>
91 <li class=
"toctree-l1">
93 <span class=
"caption-text">Docker
</span>
97 <a class=
"" href=
"../Docker-101/">Docker
101</a>
101 <a class=
"" href=
"../Shaarli-images/">Shaarli images
</a>
105 <a class=
"" href=
"../Reverse-proxy-configuration/">Reverse proxy configuration
</a>
109 <a class=
"" href=
"../Docker-resources/">Docker resources
</a>
114 <li class=
"toctree-l1">
116 <span class=
"caption-text">Usage
</span>
120 <a class=
"" href=
"../Features/">Features
</a>
124 <a class=
"" href=
"../Bookmarklet/">Bookmarklet
</a>
128 <a class=
"" href=
"../Browsing-and-searching/">Browsing and searching
</a>
132 <a class=
"" href=
"../Firefox-share/">Firefox share
</a>
136 <a class=
"" href=
"../RSS-feeds/">RSS feeds
</a>
140 <a class=
"" href=
"../REST-API/">REST API
</a>
145 <li class=
"toctree-l1">
147 <span class=
"caption-text">How To
</span>
151 <a class=
"" href=
"../Backup,-restore,-import-and-export/">Backup, restore, import and export
</a>
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>
159 <a class=
"" href=
"../Create-and-serve-multiple-Shaarlis-(farm)/">Create and serve multiple Shaarlis (farm)
</a>
161 <li class=
" current">
163 <a class=
"current" href=
"./">Download CSS styles from an OPML list
</a>
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>
173 <a class=
"" href=
"../Datastore-hacks/">Datastore hacks
</a>
178 <li class=
"toctree-l1">
180 <a class=
"" href=
"../Troubleshooting/">Troubleshooting
</a>
183 <li class=
"toctree-l1">
185 <span class=
"caption-text">Development
</span>
189 <a class=
"" href=
"../Development-guidelines/">Development guidelines
</a>
193 <a class=
"" href=
"../Continuous-integration-tools/">Continuous integration tools
</a>
197 <a class=
"" href=
"../GnuPG-signature/">GnuPG signature
</a>
201 <a class=
"" href=
"../Coding-guidelines/">Coding guidelines
</a>
205 <a class=
"" href=
"../Directory-structure/">Directory structure
</a>
209 <a class=
"" href=
"../3rd-party-libraries/">3rd party libraries
</a>
213 <a class=
"" href=
"../Plugin-System/">Plugin System
</a>
217 <a class=
"" href=
"../Release-Shaarli/">Release Shaarli
</a>
221 <a class=
"" href=
"../Versioning-and-Branches/">Versioning and Branches
</a>
225 <a class=
"" href=
"../Security/">Security
</a>
229 <a class=
"" href=
"../Static-analysis/">Static analysis
</a>
233 <a class=
"" href=
"../Theming/">Theming
</a>
237 <a class=
"" href=
"../Unit-tests/">Unit tests
</a>
242 <li class=
"toctree-l1">
244 <span class=
"caption-text">About
</span>
248 <a class=
"" href=
"../FAQ/">FAQ
</a>
252 <a class=
"" href=
"../Community-&-Related-software/">Community & Related software
</a>
262 <section data-toggle=
"wy-nav-shift" class=
"wy-nav-content-wrap">
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>
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> »</li>
279 <li>How To
»</li>
283 <li>Download CSS styles from an OPML list
</li>
284 <li class=
"wy-breadcrumbs-aside">
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>
294 <div class=
"section">
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"><!---- ?php --
>
299 <!---- Copyright (c)
2014 Nicolas Delsaux (https://github.com/Riduidel) --
>
300 <!---- License: zlib (http://www.gzip.org/zlib/zlib_license.html) --
>
303 * Source: https://github.com/Riduidel
304 * Download css styles for shaarlis listed in an opml file
306 define(
"SHAARLI_RSS_OPML
",
"https://www.ecirtam.net/shaarlirss/custom/people.opml
");
308 define(
"THEMES_TEMP_FOLDER
",
"new_themes
");
310 if(!file_exists(THEMES_TEMP_FOLDER)) {
311 mkdir(THEMES_TEMP_FOLDER);
314 function siteUrl($pathInSite) {
315 $indexPos = strpos($pathInSite,
"index.php
");
319 return substr($pathInSite,
0, $indexPos);
323 function createShaarliHashFromOPMLL($opmlFile) {
325 $opml = file_get_contents($opmlFile);
326 $opmlXml = simplexml_load_string($opml);
327 $outlineElements = $opmlXml-
>xpath(
"body/outline
");
328 foreach($outlineElements as $site) {
329 $siteUrl = siteUrl((string) $site['htmlUrl']);
330 $result[$siteUrl]=((string) $site['text']);
335 function getSiteFolder($url) {
336 $domain = parse_url($url, PHP_URL_HOST);
337 return THEMES_TEMP_FOLDER.
"/
".str_replace(
".
",
"_
", $domain);
340 function get_http_response_code($theURL) {
341 $headers = get_headers($theURL);
342 return substr($headers[
0],
9,
3);
346 * This makes the code PHP-
5 only (particularly the call to
"get_headers
")
348 function copyUserStyleFrom($url, $name, $knownStyles) {
349 $userStyle = $url.
"inc/user.css
";
350 if(in_array($url, $knownStyles)) {
351 // TODO add log message
353 $statusCode = get_http_response_code($userStyle);
354 if(intval($statusCode)
<300) {
355 $styleSheet = file_get_contents($userStyle);
356 $siteFolder = getSiteFolder($url);
357 if(!file_exists($siteFolder)) {
360 if(!file_exists($siteFolder.'/user.css')) {
362 file_put_contents($siteFolder.'/user.css', $styleSheet);
364 if(!file_exists($siteFolder.'/README.md')) {
365 // Then write a readme.md file
366 file_put_contents($siteFolder.'/README.md',
367 "User style from
".$name.
"\n
"
368 .
"=============================
"
370 .
"This stylesheet was downloaded from
".$userStyle.
" on
".date(DATE_RFC822)
373 if(!file_exists($siteFolder.'/config.ini')) {
374 // Write a config file containing useful informations
375 file_put_contents($siteFolder.'/config.ini',
376 "site_url=
".$url.
"\n
"
377 .
"site_name=
".$name.
"\n
"
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)));
385 echo 'Theme have been downloaded from
<a href=
"'.$url.'
">'.$url.'
</a
> into '.$siteFolder
386 .'. It looks like
<img src=
"'.$homeThumb.'
"><br/
>';
391 function getThumbnailUrl($url) {
392 return 'http://api.webthumbnail.org/?url='.$url;
395 function copyUserStylesFrom($urlToNames, $knownStyles) {
396 foreach($urlToNames as $url =
> $name) {
397 copyUserStyleFrom($url, $name, $knownStyles);
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 (
".
") and parent one(
"..
")
405 * are not listed here
407 function getDirectoryList ($directory) {
408 $realPath = realpath($directory);
409 // create an array to hold directory list
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 !=
".
" && $file !=
"..
") {
417 $results[] = realpath($realPath .
"/
" . $file);
420 // tidy up: close the handler
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
430 function findKnownStyles() {
432 $subFolders = getDirectoryList(
"themes
");
433 foreach($subFolders as $folder) {
434 $configFile = $folder.
"/config.ini
";
435 if(file_exists($configFile)) {
436 $iniParameters = parse_ini_file($configFile);
437 array_push($result, $iniParameters['site_url']);
443 $knownStyles = findKnownStyles();
444 copyUserStylesFrom(createShaarliHashFromOPMLL(SHAARLI_RSS_OPML), $knownStyles);
453 <div class=
"rst-footer-buttons" role=
"navigation" aria-label=
"footer navigation">
455 <a href=
"../Datastore-hacks/" class=
"btn btn-neutral float-right" title=
"Datastore hacks">Next
<span class=
"icon icon-circle-arrow-right"></span></a>
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>
465 <div role=
"contentinfo">
466 <!-- Copyright etc -->
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>.
480 <div class=
"rst-versions" role=
"note" style=
"cursor: pointer">
481 <span class=
"rst-current-version" data-toggle=
"rst-current-version">
483 <a href=
"https://github.com/shaarli/Shaarli" class=
"fa fa-github" style=
"float: left; color: #fcfcfc"> GitHub
</a>
486 <span><a href=
"../Create-and-serve-multiple-Shaarlis-(farm)/" style=
"color: #fcfcfc;">« Previous
</a></span>
489 <span style=
"margin-left: 15px"><a href=
"../Datastore-hacks/" style=
"color: #fcfcfc">Next
»</a></span>
493 <script src=
"../js/theme.js"></script>