Beispiel #1
0
function _ago($tm, $rcs = 0)
{
    $currentTime = time();
    $dif = $currentTime - $tm;
    $pds = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
    $sexondsInSecond = 1;
    $secondsInMinute = 60;
    $secondsInHour = $secondsInMinute * 60;
    $secondsInDay = $secondsInHour * 24;
    $secondsInWeek = $secondsInDay * 7;
    $secondsInMonth = $secondsInWeek * (4 + 1 / 3);
    $secondsInYear = $secondsInMonth * 12;
    $secondsInDecade = $secondsInYear * 10;
    $sizes = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
    for ($v = sizeof($sizes) - 1; $v >= 0 && ($no = $dif / $sizes[$v]) <= 1; $v--) {
    }
    if ($v < 0) {
        $v = 0;
    }
    $_tm = $currentTime - $dif % $sizes[$v];
    $no = floor($no);
    if ($no != 1) {
        $pds[$v] .= 's';
    }
    $x = sprintf("%d %s ", $no, $pds[$v]);
    if ($rcs > 0 && $v >= 1 && $currentTime - $_tm > 0) {
        $x .= _ago($_tm, --$rcs);
    }
    return $x;
}
function pugpig_set_cache_headers($modified_time, $expires)
{
    $last_modified = gmdate('D, d M Y H:i:s', $modified_time) . ' GMT';
    $etag = '"' . md5($last_modified) . '"';
    header("Cache-Control: max-age=" . $expires);
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
    header("Last-Modified: " . $last_modified);
    header("ETag: " . $etag);
    header("X-Pugpig-LM-Ago: " . _ago($modified_time) . "ago");
}
Beispiel #3
0
function _ago($tm, $rcs = 0)
{
    $cur_tm = time();
    $dif = $cur_tm - $tm;
    $pds = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
    $lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
    for ($v = sizeof($lngh) - 1; $v >= 0 && ($no = $dif / $lngh[$v]) <= 1; $v--) {
    }
    if ($v < 0) {
        $v = 0;
    }
    $_tm = $cur_tm - $dif % $lngh[$v];
    $no = floor($no);
    if ($no != 1) {
        $pds[$v] .= 's';
    }
    $x = sprintf("%d %s ", $no, $pds[$v]);
    if ($rcs > 0 && $v >= 1 && $cur_tm - $_tm > 0) {
        $x .= _ago($_tm, --$rcs);
    }
    return $x;
}
Beispiel #4
0
        $fxlt_set->clear();
    }
} else {
    // Loop through images in this set
    foreach ($protos->getSetImages() as $i => $image) {
        // Break images to new row if max reached
        if ($i % $images_per_row == 0) {
            $fxlt_image->assign('IMAGE_FIRST', ' class="first"');
        }
        // Show title if available from the XML, otherwise just show the filename
        $image_title = $image->getAttribute('title') ? $image->getAttribute('title') : $image->getAttribute('src');
        // Define the path to the image for display
        $image_src = $protos->getBasePath() . '/' . $protos->getSetName() . '/' . $image->getAttribute('src');
        // Define other image attributes
        $fxlt_image->assign('IMAGE_TITLE', $image_title);
        $fxlt_image->assign('IMAGE_MODIFIED', _ago($image->getAttribute('data-last-modified')));
        $fxlt_image->assign('IMAGE_SRC', $image_src);
        // Treat PDFs a little differently, loading a blank image instead
        if ($image->getAttribute('data-extension') == "pdf") {
            $fxlt_image->assign('IMAGE_THUMB_SRC', $pdf_thumb);
        } else {
            if ($image->getAttribute('data-extension') == "mov") {
                $fxlt_image->assign('IMAGE_THUMB_SRC', $mov_thumb);
                $fxlt_image->assign('IMAGE_REL', 'video');
            } else {
                $fxlt_image->assign('IMAGE_THUMB_SRC', resize($image_src, $resize_settings));
                $fxlt_image->assign('IMAGE_REL', 'lightbox');
            }
        }
        // Append image to page
        $fxlt->assign('image', $fxlt_image);
Beispiel #5
0
    }
    $x = sprintf("%d %s ", $no, $pds[$v]);
    if ($rcs == 1 && $v >= 1 && $cur_tm - $_tm > 0) {
        $x .= time_ago($_tm);
    }
    return $x;
}
$query = sprintf("select * from mailchecked order by time desc limit 0, 1");
$result = mysql_query($query);
$curtime = time();
while ($row = mysql_fetch_assoc($result)) {
    if ($curtime - $row["time"] > 10000) {
        echo "<h1>NO</h1>";
    } else {
        echo "<h1>YES</h1>";
        echo _ago($row["time"]) . " ago";
    }
}
?>

<?php 
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = '******';
$password = '******';
/* try to connect */
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox, 'UNSEEN');
/* if emails are returned, cycle through each... */
if ($emails) {
Beispiel #6
0
function htmlLastPollerTime()
{
    global $path_rrd;
    if (is_readable($path_rrd . "lastpolltime.txt")) {
        $lastpolltime = file_get_contents($path_rrd . "lastpolltime.txt");
        if (time() - $lastpolltime > 400) {
            $color = '<span class="red">';
        } else {
            $color = '<span>';
        }
        echo "Last poll time: {$color}" . _ago($lastpolltime) . " ago</span>";
    } else {
        echo '<span class="red">Never polled or permissions issue</span>';
    }
}
function _pugpig_show_batch($rows, $file_warning_size_kb = 250, $file_warning_time_secs = 10)
{
    echo "<table style='font-size:small;''>\n";
    echo "<tr>";
    echo "<th colspan='5'>Metrics</th>";
    echo "<th colspan='2'>Cache Headers</th>";
    echo "<th colspan='4'>Edge</th>";
    echo "<th></th>";
    echo "</tr>";
    echo "<tr>";
    echo "<th>HTTP</th>";
    echo "<th>Time</th>";
    echo "<th>Type</th>";
    echo "<th>Size</th>";
    echo "<th>Valid</th>";
    echo "<th>Modified</th>";
    echo "<th>Expires</th>";
    echo "<th>Server</th>";
    echo "<th>Encoding</th>";
    echo "<th>Auth</th>";
    echo "<th>Status</th>";
    echo "<th>URL</th>";
    echo "</tr>";
    foreach ($rows as $key => $vals) {
        echo "<tr>";
        $vals['h'] = _getHeadersFromString($vals['headers']);
        if (isset($vals['curl_info'])) {
            $http_code = $vals['curl_info']['http_code'];
            $http_code_style = '';
            if ($http_code != 200) {
                $http_code_style = 'background:#ff6600';
            }
            echo "<td style='{$http_code_style}'>{$http_code}</td>\n";
            $time = $vals['curl_info']['total_time'];
            $percentage = $time / $file_warning_time_secs * 100;
            $barcolor = "lightblue";
            if ($percentage > 100) {
                $barcolor = "orange";
            }
            if ($percentage > 200) {
                $barcolor = "red";
            }
            $time_style = "white-space: nowrap; background: -webkit-gradient(linear, left top,right top, color-stop({$percentage}%,{$barcolor}), color-stop({$percentage}%,white))";
            echo "<td style='{$time_style}'>" . $vals['curl_info']['total_time'] . "</td>\n";
        } else {
            echo "<td> - </td>\n";
            echo "<td> - </td>\n";
        }
        $content_type = "";
        $content_type_style = "";
        if (isset($vals['h']['content-type'])) {
            $content_type = $vals['h']['content-type'];
        } else {
            $content_type_style = 'background: pink';
        }
        $char = pugpig_get_download_char($key, $content_type);
        echo "<td style='{$content_type_style}'>" . $char . "</td>";
        $bytes = 0;
        if (file_exists($vals['file'])) {
            $bytes = filesize($vals['file']);
        }
        $percentage = $bytes / (1024 * $file_warning_size_kb) * 100;
        $barcolor = "lightblue";
        if ($percentage > 100) {
            $barcolor = "orange";
        }
        if ($percentage > 200) {
            $barcolor = "red";
        }
        $size_style = "white-space: nowrap; background: -webkit-gradient(linear, left top,right top, color-stop({$percentage}%,{$barcolor}), color-stop({$percentage}%,white))";
        echo "<td style='{$size_style}'>" . pugpig_bytestosize($bytes) . "</td>\n";
        $error = pugpig_validate_file($vals['file'], $content_type);
        if (!empty($error)) {
            echo "<td style='background: pink'>{$error}</td>\n";
        } else {
            echo "<td>Y</td>\n";
        }
        if (isset($vals['h']['last-modified'])) {
            echo "<td>" . _ago(strtotime($vals['h']['last-modified']), 0, true) . " ago</td>\n";
        } else {
            echo "<td style='background: pink'>?</td>\n";
        }
        if (isset($vals['h']['expires'])) {
            echo "<td>in " . _ago(strtotime($vals['h']['expires']), 0, false) . "</td>\n";
        } else {
            if (isset($vals['h']['etag'])) {
                echo "<td>eTag</td>\n";
            } else {
                echo "<td style='background: pink'>?</td>\n";
            }
        }
        $cache_layer = _pugpig_get_cache_layer($vals['h']);
        $cache_layer_style = "";
        if (in_array($cache_layer, array('PPITC', 'AKAMAI', 'CLOUDFRONT'))) {
            $cache_layer_style = 'background:#6ce1c4';
        } elseif (in_array($cache_layer, array('VARNISH'))) {
            $cache_layer_style = 'background:#66ccff';
        } elseif (in_array($cache_layer, array('PHP'))) {
            $cache_layer_style = 'background:#b20047';
        }
        echo "<td style='{$cache_layer_style}'>{$cache_layer}</td>\n";
        $content_encoding = "";
        $content_encoding_style = '';
        if (isset($vals['h']['content-encoding'])) {
            $content_encoding .= $vals['h']['content-encoding'] . " ";
        }
        if (isset($vals['h']['transfer-encoding'])) {
            $content_encoding .= $vals['h']['transfer-encoding'] . " ";
        }
        if (in_array($content_encoding, array('gzip'))) {
            $content_encoding_style = 'background:#6ce1c4';
        }
        echo "<td style='{$content_encoding_style}'>{$content_encoding}</td>\n";
        if (isset($vals['h']["x-pugpig-entitlement"])) {
            echo "<td>LOCKED</td>\n";
        } else {
            echo "<td>-</td>\n";
        }
        $status = "";
        if (isset($vals['h']["x-pugpig-status"])) {
            $status .= $vals['h']["x-pugpig-status"];
        }
        echo "<td>{$status}</td>\n";
        $suspect_style = pugpig_check_suspect_path($key) ? 'background:#ff6600' : ($char == 'f' ? 'background:#66ccff' : '');
        echo "<td style=' {$suspect_style}'><a title='" . $vals['headers'] . "' target='_blank' href='{$key}'>" . pugpig_strip_domain($key) . "</a></td>\n";
        echo "</tr>";
    }
    echo "</table>\n";
}
Beispiel #8
0
$i = 0;
// fix time bug next time
foreach ($newsList->find('.content tr') as $aNews) {
    if ($i < 18) {
        $i++;
        if ($i == 1) {
            continue;
        }
        $comments = substr(trim($aNews->find('.numbers', 0)->plaintext), 0, 3) + 0;
        $title = trim($aNews->find('a', 0)->plaintext);
        $link = "http://www.gosugamers.net" . trim($aNews->find('a', 0)->href);
        // $timeago = explode(' ', trim($aNews->find('td', 1)->plaintext));
        // $timeago = $timeago[0].substr($timeago[1], 0, 1)." ago";
        $date = $aNews->find('td', 1)->plaintext;
        $timeStamp = strtotime($date);
        $timeago = _ago($timeStamp);
        $titleIfNameis2Long = '';
        if (strlen($title) > 40) {
            $titleIfNameis2Long = str_replace(array("'", '"'), "", $title);
            $title = substr($title, 0, 40) . "..";
        }
        if ($comments >= 50) {
            $title = "<b>{$title}</b>";
        }
        $newsArray["gg"][] = "<tr class='d2mtrow news_gg' href='{$link}' title='{$comments} comments' rel='tooltip'><td alt='{$timeStamp}' class='push-tt news_date muted'>{$timeago}</td><td title='{$titleIfNameis2Long}'>{$title}</td></tr>";
    } else {
        break;
    }
}
$str = json_encode($newsArray);
$filestr = "api.json";
function showEditionsAndCovers($user, $opds, $edition_file_root)
{
    $entries = array();
    $save_path = pugpig_get_local_save_path($edition_file_root, $opds);
    // Remove the query string
    $save_path = preg_replace('/\\/?\\?.*/', '', $save_path);
    $entries[$opds] = $save_path;
    $entries = _pugpig_package_download_batch("OPDS Feeds", $entries);
    $format_failures = array();
    foreach (array_keys($entries) as $entry) {
        // Read the ATOM from the file
        $fhandle = fopen($entries[$entry], 'r');
        $opds_body = fread($fhandle, filesize($entries[$entry]));
        fclose($fhandle);
        // Parse the OPDS file
        $opds_ret = _pugpig_package_parse_opds($opds_body);
        if (!empty($opds_ret['failure'])) {
            echo "<font color='red'>Not Valid OPDS: " . $opds_ret['failure'] . "</font>";
            return;
        }
        echo "<h1>Your Editions</h1>";
        $covers = array();
        echo "<table>";
        foreach ($opds_ret['editions'] as $edition) {
            echo "<tr>";
            $cover_url = url_to_absolute($opds, $edition['cover']);
            $atom_url = url_to_absolute($opds, $edition['url']);
            $cover_save_path = pugpig_get_local_save_path($edition_file_root, $cover_url);
            // $save_path = $edition_file_root . 'cover/' . hash('md5', $edition['cover']). '.jpg';
            if (count($covers) < 10) {
                $covers[$cover_url] = $cover_save_path;
                // showSingleEdition($user, $opds, $atom_url, $edition_file_root);
            }
            echo "<td><img height='80' src='" . $cover_url . "' /></td>";
            echo "<td>";
            echo "<b>" . $edition['title'] . "</b><br />";
            echo "<i>" . $edition['summary'] . "</i><br />";
            $updated_ts = strtotime($edition['updated']);
            echo _ago($updated_ts) . " ago) - (" . $edition['updated'] . ") ({$updated_ts})<br />";
            echo $edition['draft'] ? "<font color='orange'>DRAFT</font> " : "";
            echo ($edition['free'] ? "free" : "paid") . ($edition['samples'] ? " with samples" : "");
            echo "<br />";
            echo "</td>";
            echo "<td>";
            //echo count($edition['categories']) . " categories";
            foreach ($edition['categories'] as $schema => $term) {
                echo "<b>{$schema}</b>: {$term}<br />";
            }
            echo "</td>";
            echo "<td>";
            if ($edition['type'] == 'atom') {
                $q = http_build_query(array('opds' => $opds, 'atom' => $atom_url, 'user' => $user));
                echo "<a href='?{$q}'>TEST PAGES</a><br />\n";
            } else {
                echo "EPUB<br />";
            }
            echo "<a href='" . url_to_absolute($opds, $atom_url) . "' target='_blank'>FEED</a></br />";
            echo "FLATPLAN</br />";
            echo "PREVIEW IN WEB<br />";
            echo "</tr>";
        }
        echo "</table>";
        $entries = _pugpig_package_download_batch("Valdating Covers (only 10)", $covers);
    }
}
Beispiel #10
0
            <?php 
connectToDB();
$result = mysql_query('SELECT * FROM ports WHERE host="' . mysql_real_escape_string($viewhost) . '" AND graphtype="' . mysql_real_escape_string($viewtype) . '" AND safename="' . mysql_real_escape_string($viewport) . '" ');
if (mysql_num_rows($result) > 0) {
    $row = mysql_fetch_assoc($result);
    echo "<div>";
    echo "<p>Port Name: <a href=\"viewport.php?host={$row['host']}&port={$row['safename']}\">{$row['name']}</a> </p>";
    echo "<p>Port Alias: <pre>{$row['alias']}</pre></p>";
    echo '<p>On host: <a href="viewhost.php?host=' . $row['host'] . '">' . $row['host'] . '</a>';
    echo "<p>Status: ";
    if (time() - $row['lastpoll'] > $staleage) {
        echo '<span class="red">STALE</span></p>';
    } else {
        echo '<span class="green">OK</span></p>';
    }
    echo "<p>Last polled: " . _ago($row['lastpoll']) . " ago </p>";
    # Insert the graph
    $friendlytitle = urlencode("{$viewhost} - {$row['name']} ({$row['alias']})");
    $basegraphurl = "graph.php?host={$viewhost}&rrdname={$viewhost}-{$row['safename']}&type={$row['graphtype']}{$start}&friendlytitle={$friendlytitle}";
    echo '<img src="' . $basegraphurl . '&height=300&width=800" alt="' . $row['alias'] . '">';
} else {
    echo "Port/host/type combination not found! Was it polled yet?";
}
?>

    <div>
</div>


</body>
</html>