SimpleMansCMS - A simple web page built from Instagram posts

This page (below the ruler) is dynamically created using these instagram posts:

Check here for an explanation and source.

All photos by @mortenkjarulff


0) { $link=explode(' ',$links); for ($i=0;$i < count($link);$i++) { unlink("current.$i.thumbnail_url"); unlink("current.$i.title"); } } unlink('current.links'); echo "

Backup NOT done - it exists

\n"; } else { # Create a backup from the current version $links=file_get_contents('current.links'); if (strlen($links) > 0) { $link=explode(' ',$links); for ($i=0;$i < count($link);$i++) { rename("current.$i.thumbnail_url","backup.$i.thumbnail_url"); rename("current.$i.title" ,"backup.$i.title"); } } rename('current.links','backup.links'); echo "

Backup done

\n"; } # Get the "root" post $curl=curl_init(); curl_setopt_array($curl,array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => 'https://api.instagram.com/oembed/?url=https://instagram.com/p/nuaVSqC_Tm/' )); $page=curl_exec($curl); curl_close($curl); $info=json_decode($page,true); # The caption holds our links to the posts we want to use $links=$info['title']; # Except the first line $links=preg_replace('/[^\n]*\n/','',$links,1); # Links are separated by newlines or spaces $links=preg_replace('/\n/',' ',$links,-1); # Save them file_put_contents('current.links',$links); # If any links if (strlen($links) > 0) { $link=explode(' ',$links); # Loop trhough them for ($i=0;$i < count($link);$i++) { # Get the post $curl=curl_init(); curl_setopt_array($curl,array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => "https://api.instagram.com/oembed/?url=$link[$i]" )); $page=curl_exec($curl); curl_close($curl); $info=json_decode($page,true); # Save caption $title=$info['title']; file_put_contents("current.$i.title",$title); # Save photo $thumbnail_url=$info['thumbnail_url']; file_put_contents("current.$i.thumbnail_url",$thumbnail_url); } } echo "

Build done

\n"; # Copy this file to a .txt file, we can share copy('index.php','index.txt'); } # Use ?action=commit to commit the current version (delete the backup) # On a real page this would be a more secret word if ($_GET['action'] == 'commit') { # If a backup exists if (file_exists('backup.links')) { # Delete the backup $links=file_get_contents('backup.links'); if (strlen($links) > 0) { $link=explode(' ',$links); for ($i=0;$i < count($link);$i++) { unlink("backup.$i.thumbnail_url"); unlink("backup.$i.title"); } } unlink('backup.links'); echo "

Commit done

\n"; } else { echo "

Commit NOT done - no backup

\n"; } } # Use ?action=fallback to go to the backup version # On a real page this would be a more secret word if ($_GET['action'] == 'fallback') { # If a backup exists if (file_exists('backup.links')) { # Delete the current version $links=file_get_contents('current.links'); if (strlen($links) > 0) { $link=explode(' ',$links); for ($i=0;$i < count($link);$i++) { unlink("current.$i.thumbnail_url"); unlink("current.$i.title"); } } unlink('current.links'); # Make the backup the current $links=file_get_contents('backup.links'); if (strlen($links) > 0) { $link=explode(' ',$links); for ($i=0;$i < count($link);$i++) { rename("backup.$i.thumbnail_url","current.$i.thumbnail_url"); rename("backup.$i.title" ,"current.$i.title"); } } rename('backup.links','current.links'); echo "

Fallback done

\n"; } else { echo "

Fallback NOT done - no backup

\n"; } } # If a backup exists if (file_exists('backup.links')) { echo "

Under construction

\n"; } # If any links $links=file_get_contents('current.links'); if (strlen($links) > 0) { $link=explode(' ',$links); # Loop trough them for ($i=0;$i < count($link);$i++) { echo "

\n"; # Get the photo $thumbnail_url=file_get_contents("current.$i.thumbnail_url"); # Show the photo echo "
\n"; # Get the caption $title=file_get_contents("current.$i.title"); # Replace & < > $title=preg_replace('/&/','&',$title,-1); $title=preg_replace('//','>' ,$title,-1); # Do a few markdown-like substitutions: # [text](http://example.com) # [text](https://example.com) # [text](mailto:me@example.com) # [text](tel:12345678) $title=preg_replace('/\[([^\]]*)\]\((http:[^\)]*)\)/' ,'
${1}',$title,-1); $title=preg_replace('/\[([^\]]*)\]\((https:[^\)]*)\)/' ,'${1}',$title,-1); $title=preg_replace('/\[([^\]]*)\]\((mailto:[^\)]*)\)/','${1}',$title,-1); $title=preg_replace('/\[([^\]]*)\]\((tel:[^\)]*)\)/' ,'${1}',$title,-1); # Newlines $title=preg_replace('/\n/','
',$title,-1); # Show the caption echo "$title\n"; echo "

\n"; } } ?>