--- /dev/null
+<?
+
+include('/home/quilime/i/php/function.php');
+
+session_start();
+
+define('ROOT', 'agg/');
+define('DESC', 'desc/');
+define('WWW', 'http://quilime.com/aggregate/' . ROOT);
+define('PW', 'aggaggagg');
+
+
+$page = isset($_GET['page']) ? $_GET['page'] : 0 ;
+$bin = isset($_GET['bin']) ? $_GET['bin'].'/' : '';
+$link = isset($_GET['l']) ? $_GET['l'] : '';
+$return = isset($_GET['return']) ? $_GET['return'] : false;
+$admin = isset($_GET['login']) && $_GET['login'] == PW ? true : false;
+$num_pp = $_SESSION['num_pp'] = setSessionVar('num_pp', 50);
+$offset = $page * $num_pp;
+
+
+if($link && is_dir(ROOT . $link))
+ header('Location: ?bin=' . $link);
+
+if($bin)
+ clearkeywords();
+
+if(!$link) {
+ $agg = fileArray(ROOT . $bin, array(), array('.','..'), WWW . $bin);
+ $agg = sortFiles($agg, 'D', 'M');
+ getkeywords();
+ $agg = filterkeywords($agg);
+}
+
+switch ($return) {
+ case 'rss' : rss(); exit();
+ case 'js' : js(); exit();
+}
+
+function rss()
+{
+ $count = 20;
+
+ global $agg;
+ header("Content-Type: application/xml;");
+ header("Pragma: no-cache");
+ header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
+ echo '<?xml version="1.0" encoding="UTF-8"?>
+ <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
+ <channel>
+ <title>aggregate</title>
+ <link>http://quilime.com/aggregate/</link>
+ <generator>media.quilime.com</generator>
+ <description>aggregate</description>
+ ';
+
+ foreach($agg as $i) {
+ $count--;
+ if($count == 0) break;
+ echo '
+ <item>
+ <img>'.$i['url'].'</img>
+ <reference>[reference url]</reference>
+ <title>'.$i['name'].'</title>
+ <description>
+ <p><a href="?l='.$i['name'].'"><img src="'.$i['url'].'" alt="" border="0"></a></p><p>
+ </description>
+ <link>http://quilime.com/aggregate/?l='.$i['name'].'</link>
+ </item>
+ ';
+ }
+
+ echo '</channel>
+ </rss>
+ ';
+}
+
+
+
+
+
+function filterkeywords($agg)
+{
+ if(sizeof($_SESSION['keywords']) > 0) {
+ $filtered = array();
+ foreach($agg as $f) {
+ foreach($_SESSION['keywords'] as $keyword) {
+ $pattern = '/'.strtolower($keyword).'/';
+ preg_match($pattern,strtolower($f['name']), $matches);
+ if(sizeof($matches) > 0) {
+ $filtered[] = $f;
+ }
+ }
+ }
+ $agg = $filtered;
+ }
+ return $agg;
+}
+
+
+
+
+function aggTitle()
+{
+ global $link;
+
+ $keywords = keywords();
+
+ if($link)
+ return ' - '.$link;
+ else if(isset($_GET['s']) && $_GET['s'] != '___')
+ return ' - results for : ' . $keywords .'';
+ else
+ return $bin ? ' - ' . $bin : '';
+}
+
+
+
+function keywords()
+{
+ $r = "";
+ if($_SESSION['keywords']) {
+ foreach($_SESSION['keywords'] as $k) {
+ if(trim($k) == "") continue;
+ $r .= $k . ' ';
+ //echo '<a href="?r='.$k.'">x</a>';
+ //echo '<br/>';
+ }
+ }
+ return $r;
+}
+
+
+function clearkeywords()
+{
+ $_SESSION['keywords'] = array();
+ return;
+}
+
+
+function getkeywords()
+{
+ $k = $_GET['s'];
+ $remove = $_GET['r'];
+
+ if($k == "___") {
+ clearkeywords();
+ return;
+ }
+
+ if(!is_array($_SESSION['keywords']))
+ $_SESSION['keywords'] = array();
+
+ $kex = explode(" ", $k);
+
+ foreach($kex as $k) {
+ if(!in_array($k, $_SESSION['keywords']))
+ $_SESSION['keywords'][] = $k;
+ }
+
+ foreach($_SESSION['keywords'] as $key => $keyw) {
+ if(trim($keyw) == trim($remove))
+ unset($_SESSION['keywords'][$key]);
+ }
+
+ $_SESSION['keywords'] = array_unique($_SESSION['keywords']);
+ $_SESSION['keywords'] = array_filter($_SESSION['keywords']);
+}
+
+
+function pages($numImages)
+{
+ global $page, $num_pp, $bin;
+
+ if($bin) return;
+ if($numImages < $num_pp) return;
+
+ $num = $numImages / $num_pp;
+ echo $page > 0 ? '<a href="?page='.($page-1).'" title="next page">←</a> ' : '<span>← </span>';
+ $c = 0;
+ for($i = 0; $i < $num; $i++) {
+ if($page == $i) echo '<span>' . $i . '</span>';
+ else echo '<a href="?page='.$i.'">'.$i.'</a>';
+ echo " ";
+ $c++;
+ }
+ echo $page < $c++-1 ? '<a href="?page='.($page+1).'" title="prev page">→</a>' : '<span>→</span>';
+
+ echo '<br/><br/>';
+
+ echo '# PER PAGE: ';
+ $n = array(1, 5, 10, 20, 50);
+ foreach($n as $nn) {
+ if($nn == $num_pp) {
+ echo $num_pp.' ';
+ continue;
+ }
+ echo '<a href="?num_pp='.$nn.'">'.$nn.'</a> ';
+ }
+
+}
+
+
+function agg($agg)
+{
+ global $admin, $link, $bin, $num_pp, $offset;
+
+ if($link) {
+ //echo '<p><img title="' . $link.'" src="' . ROOT . $link . '"></p>';
+
+ echo '<img border="0" title="'.ROOT . $link.'" src="'. ROOT . $link.'" onMouseOver="showInfo(\'inf\');">';
+ if(file_exists(DESC . $link . '.txt')) {
+ echo '<div onMouseOut="hideInfo(\'inf\');" class="desc" id="inf">';
+ $img_json = file_get_contents( DESC . $link . '.txt' );
+ $img_desc = json_decode($img_json, true);
+ echo '<a href="' . $img_desc['link'] . '">' . $img_desc['link'] . '</a>';
+ echo '</div>';
+ }
+
+ return;
+ }
+
+ $off = $bin ? 0 : $offset;
+ $num = $bin ? sizeof($agg) : $num_pp;
+
+ for($i = $off; $i < $off + $num; $i++) {
+
+ echo '<div class="aggim">';
+
+ if($i > sizeof($agg)-1) break;
+ $file = $agg[$i];
+
+ if($file['type'] == 'Folder') {
+
+ echo '<div class="bin"><a href="?bin='.$file['name'].'">'.$file['name'].'</a></div>';
+ continue;
+
+ }
+ else {
+
+ if($admin) {
+ echo '
+ <form class="ed" name="ed_' . $i . '" id="ed_' . $i . '">
+ <input type="hidden" name="img"/ value="' . $bin.$file['name'] . '">
+ <label>link</label> <input type="text" name="link" /><br/>
+ <label>title</label> <input type="text" name="title"/><br/>
+ <label>tags</label> <input type="text" name="tags"/><br/>
+ <label>desc</label> <input type="text" name="desc" /><br/>
+ <input type="button" value="edit" onClick="sub(\'ed_' . $i . '\');">
+ </form>
+ ';
+ }
+ echo '<img border="0" title="'.$file['name'].'" src="'.$file['url'].'" onMouseOver="showInfo(\'' . $i . '_inf\');">';
+ if(file_exists(DESC . $file['name'] . '.txt')) {
+ echo '<div onMouseOut="hideInfo(\'' . $i . '_inf\');" class="desc" id="' . $i . '_inf">';
+ $img_json = file_get_contents( DESC . $file['name'] . '.txt' );
+ $img_desc = json_decode($img_json, true);
+ echo '<a href="' . $img_desc['link'] . '">' . $img_desc['link'] . '</a>';
+ echo '</div>';
+ }
+
+ }
+
+ echo '</div>';
+ }
+}
+
+
+function fopen_recursive($path, $mode, $chmod=0755)
+{
+ $directory = dirname($path);
+ $file = basename($path);
+ if (!is_dir($directory)){
+ if (!mkdir($directory, $chmod, 1)) {
+ return FALSE;
+ }
+ }
+ return fopen ($path, $mode);
+}
+
+
+function js()
+{
+ header("Content-Type: text/javascript;");
+ header("Pragma: no-cache");
+ header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
+
+ $img = isset($_GET['img']) ? $_GET['img'] : false;
+
+ $json = '{';
+ foreach($_GET as $k=>$param) {
+ $json .= '"'.$k.'"'.' : '.'"'.$param.'", ';
+ }
+ $json .= '"json":0}';
+
+ if($img) {
+ $file = fopen_recursive(DESC . $img . '.txt',"w");
+ fwrite($file,$json);
+ fclose($file);
+ ?>
+ $("<?php echo $_GET['formid']; ?>").style.display = 'none';
+ <?php
+ }
+}
+
+
+?>
+
+<html>
+
+<head>
+
+<link rel="alternate" type="application/rss+xml" title="aggregate" href="?return=rss" />
+
+ <title>aggregate<?=aggTitle();?></title>
+
+ <script>
+
+
+ function $()
+ {
+ var elements = new Array();
+ for (var i = 0; i < arguments.length; i++) {
+ var element = arguments[i];
+ if (typeof element == 'string') element = document.getElementById(element);
+ if (arguments.length == 1) return element;
+ elements.push(element);
+ }
+ return elements;
+ }
+
+
+ window.onload = function()
+ {
+ resizeImages();
+ }
+
+
+ function resizeImages()
+ {
+ for each(var img in document.getElementsByTagName('img')) {
+ if(img.offsetWidth + 60 > window.innerWidth)
+ img.style.width = window.innerWidth - 100 + 'px';
+ }
+ }
+
+
+ function sub(form)
+ {
+ var img = document.forms[form].img.value;
+ var link = document.forms[form].link.value;
+ var tags = document.forms[form].tags.value;
+ var title = document.forms[form].title.value;
+ var desc = document.forms[form].desc.value;
+ doURL( '?return=js&tags=' + tags + '&formid=' + form + '&img=' + escape(img) + '&link=' + escape(link) + '&title=' + escape(title) + '&desc=' + escape(desc) );
+ }
+
+
+ function doURL(url) {
+ var jsel = document.createElement('script');
+ jsel.type = 'text/javascript';
+ jsel.src = url;
+ document.body.appendChild (jsel);
+ }
+
+
+ function showInfo(inf)
+ {
+ if($(inf))
+ $(inf).style.visibility = 'visible';
+ }
+
+
+ function hideInfo(inf)
+ {
+ $(inf).style.visibility = 'hidden';
+ }
+
+ </script>
+
+ <style type="text/css">
+
+ body { font-family:monospace; margin:20px; margin-left:50px; font-size:12px; color:#999; }
+
+ #agg { margin:100px 0; }
+ #agg .aggim { margin-bottom:120px;}
+
+ a {color:#555; text-decoration:underline; }
+ a:hover {color:#000; text-decoration:none;}
+
+ .bin a { font-size:34px; }
+ .bin { margin-bottom:100px; }
+ .pages { margin-bottom:40px; line-height:2em; }
+ .pages a, pages span { padding:2px 6px;}
+ .pages a:hover { }
+
+ #s { position:absolute; right:20px; top:20px; }
+ #s form { }
+
+ pre { margin:0; padding:0; }
+
+ .desc {visibility:hidden; }
+
+ .ed input[type='text']{ width:400px; }
+
+ </style>
+
+</head>
+
+
+<body>
+
+ <a href="?s=___">aggregate</a><?=aggTitle();?>
+
+ <div id="s">
+ <form method="get" action="<?=$_SERVER['PHP_SELF'];?>?t=sdf">
+ <input type="text" value="" name="s" style="width:100px;" />
+ </form>
+ </div>
+
+ <br/><br/>
+
+ <div id="agg">
+ <? agg($agg); ?>
+ </div>
+
+ <div class="pages">
+ <? pages(sizeof($agg)); ?>
+ </div>
+
+ <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "UA-351774-1";urchinTracker();</script>
+
+</body>
+
+</html>