예제 #1
0
 /**
  * Generates html for the Form
  *
  * @return string
  */
 protected function getFormHtml()
 {
     $template = $this->getTemplate();
     $form = $template->getFormWrapper();
     $heading = human_readable($this->getMapper()->getTableName());
     $html = '<h1 class="text-center">' . $heading . ' Form </h1>';
     $html .= $form->openTag();
     $hiddenFields = '';
     foreach ($this->getElements() as $element) {
         if (!$element instanceof Element\Hidden) {
             $element->setAttribute('class', $template->getInputClass());
             $element->getLabel()->setAttribute('class', $template->getLabelClass());
             $row = $template->getInputRowWrapper();
             $inputWrapper = $template->getInputWrapper();
             $inputWrapper->setElements([$element]);
             $row->setElements([$element->getLabel(), $inputWrapper]);
             $html .= $row->getHtml();
         } else {
             $hiddenFields .= $element->getHtml() . "\n";
         }
     }
     $row = $template->getInputRowWrapper();
     $row->setElements([new Button(['name' => 'submit', 'id' => 'submit-button', 'value' => 'Submit', 'class' => $template->getSubmitButtonClass() . ' pull-right'])]);
     $html .= $row->getHtml();
     $html .= $hiddenFields;
     $html .= $form->closeTag();
     return $html;
 }
예제 #2
0
 public function testHumanReadableNumber()
 {
     $result = human_readable('address1');
     $this->assertEquals('Address 1', $result);
 }
예제 #3
0
 /**
  * @param ElementInterface $element
  */
 public function __construct(ElementInterface $element)
 {
     $this->setElement($element);
     $this->setText(human_readable($element->getName()));
     $this->setAttributes(['for' => $this->getElement()->getId()]);
 }
예제 #4
0
<?php 
/* Now, get the top 5 downloaders */
$sql = 'SELECT SUM(upl_bytes) + SUM(downl_bytes) as traffic, nas_info';
$sql .= ' FROM "' . $PROCESSED . '"';
if ($sql_cond) {
    $sql .= ' WHERE ' . $sql_cond;
}
$sql .= ' GROUP BY nas_info';
$sql .= ' ORDER BY traffic desc, nas_info';
$sql .= ' LIMIT 8';
/* Execute the query */
$result = pg_query($dbconn, $sql) or die('Query failed: ' . pg_last_error() . "\n");
while ($data = pg_fetch_array($result, null, PGSQL_ASSOC)) {
    echo "    <tr>\n";
    echo "      <td>" . htmlentities(pg_unescape_bytea($data["nas_info"])) . "</td>\n";
    echo "      <td>" . human_readable($data["traffic"]) . "</td>\n";
    echo "    </tr>\n";
}
pg_free_result($result);
?>
  </table>

  <hr />
<?php 
/* Closing connection */
pg_close($dbconn);
?>
<p><small>Data generated by scripts from the <a href="http://www.freediameter.net">freeDiameter</a> project.</small></p>
</body>
</html>
예제 #5
0
function torInfo($torHash)
{
    global $config_values;
    switch ($config_values['Settings']['Client']) {
        case 'Transmission':
            $request = array('arguments' => array('fields' => array('id', 'leftUntilDone', 'hashString', 'totalSize', 'uploadedEver', 'downloadedEver', 'status', 'peersSendingToUs', 'peersGettingFromUs', 'peersConnected', 'recheckProgress'), 'ids' => $torHash), 'method' => 'torrent-get');
            $response = transmission_rpc($request);
            $totalSize = $response['arguments']['torrents']['0']['totalSize'];
            $leftUntilDone = $response['arguments']['torrents']['0']['leftUntilDone'];
            $Uploaded = $response['arguments']['torrents']['0']['uploadedEver'];
            $Downloaded = $response['arguments']['torrents']['0']['downloadedEver'];
            $validProgress = 100 * $response['arguments']['torrents']['0']['recheckProgress'];
            if ($totalSize) {
                $percentage = round(($totalSize - $leftUntilDone) / $totalSize * 100, 2);
            }
            if ($percentage < 100) {
                $dlStatus = "downloading";
            }
            if (!$totalSize) {
                return array('dlStatus' => 'old_download');
            } else {
                if (!$Downloaded || !$Uploaded) {
                    $ratio = 0;
                } else {
                    $ratio = $Uploaded / $Downloaded;
                    $ratio = round($ratio, 2);
                }
                $bytesDone = $totalSize - $leftUntilDone;
                if (!$bytesDone) {
                    $bytesDone = 0;
                }
                $sizeDone = human_readable($totalSize - $leftUntilDone);
                $totalSize = human_readable($totalSize);
                if (!($clientId = $response['arguments']['torrents']['0']['id'])) {
                    $clientId = '';
                }
                if (!($status = $response['arguments']['torrents']['0']['status'])) {
                    $status = 0;
                }
                if (isset($response['arguments']['torrents']['0']['seedRatioLimit'])) {
                    $seedRatioLimit = round($response['arguments']['torrents']['0']['seedRatioLimit'], 2);
                }
                $peersSendingToUs = $response['arguments']['torrents']['0']['peersSendingToUs'];
                $peersGettingFromUs = $response['arguments']['torrents']['0']['peersGettingFromUs'];
                $peersConnected = $response['arguments']['torrents']['0']['peersConnected'];
                #FIX ME! BUILD DECENT STATUS TABLE!
                if ($status == 0) {
                    $status = 16;
                }
                if ($status == 3) {
                    $status = 4;
                }
                if ($status == 5) {
                    $status = 8;
                }
                if ($status == 6) {
                    $status = 8;
                }
                if ($status == 1) {
                    $stats = "Waiting to verify";
                } else {
                    if ($status == 2) {
                        $stats = "Verifying files ({$validProgress}%)";
                    } else {
                        if ($status == 4) {
                            $stats = "Downloading from {$peersSendingToUs} of {$peersConnected} peers:\n                      {$sizeDone} of {$totalSize} ({$percentage}%)  -  Ratio: {$ratio}";
                        } else {
                            if ($status == 8) {
                                $stats = "Seeding to {$peersGettingFromUs} of {$peersConnected} peers  -  Ratio: {$ratio}";
                            } else {
                                if ($status == 16) {
                                    if ($ratio >= $seedRatioLimit && $percentage == 100) {
                                        $stats = "Downloaded and seed ratio met. This torrent can be removed.";
                                    } else {
                                        $stats = "Paused";
                                    }
                                } else {
                                    $stats = '';
                                }
                            }
                        }
                    }
                }
                return array('stats' => $stats, 'clientId' => $clientId, 'status' => $status, 'bytesDone' => $bytesDone);
            }
            exit;
    }
}
예제 #6
0
<P>
The total space used by the FreshPorts database is:
<blockquote><code class="code">
# select pg_database_size('freshports.org');<br>
&nbsp;pg_database_size<br>
------------------<br>
<?php 
$Value = DBSize($db);
echo number_format($Value) . '<br>';
?>
(1 row)<br>
</code></blockquote>

<p>That's bytes...
<p>This value might be easier to parse: <?php 
echo human_readable($Value);
?>
</TD></TR>


</TABLE>
</TD>

  <TD VALIGN="top" WIDTH="*" ALIGN="center">
	<?php 
echo freshports_SideBar();
?>
  </td>

</TABLE>
예제 #7
0
      <th>Duration</th>
      <th>Downloaded</th>
      <th>Uploaded</th>
    </tr>
<?php 
    while ($record = pg_fetch_array($result, null, PGSQL_ASSOC)) {
        echo "    <tr title='" . htmlentities(pg_unescape_bytea($record["user_name"])) . "'>\n";
        echo "      <td>";
        echo htmlentities(pg_unescape_bytea($record["user_device"]));
        echo "</td>\n";
        echo "      <td>";
        echo htmlentities(pg_unescape_bytea($record["nas_info"]));
        echo "</td>\n";
        echo "      <td>";
        echo $record["fmt_sess_start"];
        echo "</td>\n";
        echo "      <td>";
        echo htmlentities($record["sess_duration"]);
        echo "</td>\n";
        echo "      <td>";
        echo human_readable($record["downl_bytes"]) . " (" . $record["downl_packets"] . "pckts)";
        echo "</td>\n";
        echo "      <td>";
        echo human_readable($record["upl_bytes"]) . " (" . $record["upl_packets"] . "pckts)";
        echo "</td>\n";
        echo "    </tr>\n";
    }
}
pg_free_result($result);
/* Closing connection */
pg_close($dbconn);