Example #1
0
 public function toString($field)
 {
     $item = $this->{$field} ?? null;
     if (!array_key_exists($field, $this->_data)) {
         return null;
     } elseif (is_null($item)) {
         return var_export($item, true);
     } elseif (is_bool($item)) {
         return var_export($item, true);
     } elseif (is_string($item)) {
         return $item;
     } elseif (is_numeric($item)) {
         return $item;
     } elseif (is_array($item)) {
         return \mongo\format\JSON::encode($item);
     } elseif ($item instanceof \mongo\type\Timestamp) {
         return $item->__toString();
     } elseif ($item instanceof \mongo\type\DateTime) {
         return $item->__toString();
     } elseif ($item instanceof \MongoDB\BSON\ObjectId) {
         return $item->__toString();
     } elseif ($item instanceof \MongoDB\BSON\Binary) {
         return pretty_size(strlen($item->getData()));
     } elseif ($item instanceof \MongoDB\BSON\Javascript) {
         return \mongo\type\Javascript::bsonExport($item);
     } elseif ($item instanceof \MongoDB\BSON\Regex) {
         return \mongo\type\Regex::bsonExport($item);
     } elseif ($item instanceof \MongoDB\BSON\MaxKey) {
         return '$MaxKey';
     } elseif ($item instanceof \MongoDB\BSON\MinKey) {
         return '$MinKey';
     } else {
         return \mongo\format\JSON::encode($item);
     }
 }
Example #2
0
 public function fetch($hash)
 {
     $infohash = [];
     $filelist = [];
     $info = $this->infohash_model->get(['hash' => $hash]);
     if (empty($info)) {
         return ['infohash' => $infohash, 'filelist' => $filelist];
     }
     $filelist = $this->filelist_model->select('*', 'infohash_id=?', [$info['id']]);
     foreach ($filelist as $k => $v) {
         $filelist[$k]['pretty_size'] = pretty_size($v['length']);
     }
     return ['infohash' => $info, 'filelist' => $filelist];
 }
Example #3
0
 public function post($return = false)
 {
     if (!$return and !$this->app->request->isAjax()) {
         return false;
     }
     $query = trim($this->app->request->params('q', ''));
     $page = (int) $this->app->request->params('p', 1);
     if ($page <= 0) {
         $page = 1;
     }
     $limit = 30;
     $fetch_search = $this->fetch($query, $page, $limit);
     $view_data['q'] = $query;
     $view_data['p'] = $page;
     $view_data['total'] = $total = $fetch_search['sphinx']['total'];
     if ($total <= 0) {
         $view_data['result'] = [];
         $view_data['has_more'] = false;
     } else {
         $view_data['result'] = $fetch_search['db'];
         // 匹配到的关键字生成样式
         if (!empty($view_data['result'])) {
             $keywords = explode(' ', $query);
             $pattern = '#';
             foreach ($keywords as $k2 => $v2) {
                 $pattern .= '(' . $v2 . ')|';
             }
             $pattern = rtrim($pattern, '|') . '#i';
             foreach ($view_data['result'] as $k => $v) {
                 $view_data['result'][$k]['name'] = preg_replace($pattern, '<span class="keyword">\\0</span>', $v['name']);
                 $view_data['result'][$k]['magnet'] = 'magnet:?xt=urn:btih:' . strtoupper($v['hash']);
                 $view_data['result'][$k]['pretty_size'] = pretty_size(getattr($v, 'total_size', 0));
             }
         }
         $view_data['has_more'] = $total > $limit * $page;
     }
     if ($return) {
         return $view_data;
     } else {
         header('Content-Type: application/json');
         $view_data['code'] = 0;
         echo json_encode($view_data);
     }
 }
Example #4
0
    echo WWW_BASE_PATH;
    ?>
user/<?php 
    echo $user->name;
    ?>
"><?php 
    echo $user->name;
    ?>
</a>
				<br />
				<span class="info">
				<?php 
    echo pretty_size($user->downloaded);
    ?>
 downloaded;
				ratio <?php 
    echo $user->ratio;
    ?>
				</span>
			</td>
			<td class="uploaded">
				<?php 
    echo pretty_size($user->uploaded);
    ?>
			</td>
		</tr>
	<?php 
}
?>
</table>
<div class="torrent_file">
    <!--    <?php 
echo $torrent->getFile(), '(', $torrent->getMimeType(), ') ', pretty_size($torrent->getSize());
?>
 -->
    
    <?php 
echo $torrent->getFeed()->getTitle();
?>
    
    <ul class="links">
      <div class="divider">&nbsp;</div>
      <li>
         <span>Web </span>
         <?php 
echo link_to($torrent->getUrl(false), $torrent->getUrl(false));
?>
      </li>
      <li>
         <span>Torrent </span>
         <?php 
echo link_to($torrent->getUrl(true), $torrent->getUrl(true));
?>
      </li>
      <li class="clearfix">
         <span>Magnet </span>
         <?php 
echo '<a href="', $torrent->getMagnet(), '">', $torrent->getFileSha1(), '</a>';
?>
 
      </li>
Example #6
0
$max_form_size = 100 * 1024;
// 100K
/*
 * whether to place uploaded file contents in the raw input field
 * (useful for re-submitting content without having to re-select the file from 
 * an upload dialog).
 */
$post_file_input = false;
// if $post_file_input is true, the max number of displayed input lines from
// uploaded files
$show_max_lines = 10000;
$max_upload_size = ini_get('upload_max_filesize');
if (isset($max_form_size)) {
    $max_upload_size = min($max_form_size, $max_upload_size);
}
$max_upload_size = pretty_size($max_upload_size);
// if using an uploaded file, grab its temp file name
if (isset($_FILES['upload']) && $_FILES['upload']['error'] != UPLOAD_ERR_NO_FILE) {
    $error_code = $_FILES['upload']['error'];
    if ($error_code == UPLOAD_ERR_OK) {
        $filename = $_FILES['upload']['tmp_name'];
        if ($post_file_input) {
            $fp = fopen($filename, 'r');
            $input = array();
            while (!feof($fp) && count($input) < $show_max_lines) {
                $input[] = fgets($fp, 1024);
            }
            $input = trim(implode("\n", $input));
        }
    } else {
        switch ($error) {
Example #7
0
torrent/<?php 
    echo $torrent->fid;
    ?>
/edit">Edit</a> / <a href="<?php 
    echo WWW_BASE_PATH;
    ?>
torrent/<?php 
    echo $torrent->fid;
    ?>
/delete">Delete</a><?php 
}
?>
			<br />
			<span class="info">
			<?php 
echo pretty_size($torrent->size);
?>
;
			added <?php 
echo time_diff($torrent->ctime);
?>
			by
			<?php 
$this->renderElement('user_byline', array('user' => $torrent->user));
?>
			in category <a href="<?php 
echo WWW_BASE_PATH;
?>
browse/<?php 
echo $torrent->category->slug;
?>
Example #8
0
function list_directory($display_name, $path)
{
    global $localconfig;
    // Allow local configuration file to override any of these globals.
    global $mimetype, $disposition, $cacheable, $ignore, $recurse, $indexfile;
    // And these locals.
    $title = '';
    $annotation = '';
    if (file_exists("{$path}/{$localconfig}")) {
        include "{$path}/{$localconfig}";
    }
    $handle = @opendir($path) or die("Directory {$display_name} not found.");
    $files = array();
    $subdirs = array();
    while ($entry = readdir($handle)) {
        if (is_indexfile($entry)) {
            closedir($handle);
            send_file("{$path}/{$entry}");
            return;
        } elseif ($entry != '..' && $entry != '.' && !is_ignored($entry)) {
            if (!is_dir("{$path}/{$entry}")) {
                $files[] = $entry;
            } elseif ($recurse) {
                $subdirs[] = $entry;
            }
        }
    }
    closedir($handle);
    sort_array($files);
    sort_array($subdirs);
    open_doc($title);
    announce_directory($display_name, $title, $annotation);
    print "<table width=\"100%\" border=0 cellspacing=1 cellpadding=2>\n";
    for ($s = reset($subdirs); $s; $s = next($subdirs)) {
        print_entry("{$s}/", '(dir)', '&nbsp');
    }
    for ($s = reset($files); $s; $s = next($files)) {
        print_entry($s, solidify(pretty_size(filesize("{$path}/{$s}"))), solidify(pretty_date(filemtime("{$path}/{$s}"))));
    }
    print "</table>\n";
    close_doc();
}
Example #9
0
<tr class="<?php 
echo $i % 2 ? 'odd' : 'even';
?>
 ">
	<td class="file">
		<?php 
echo $file->path;
?>
	</td>
	<td class="size"><?php 
echo pretty_size($file->size);
?>
</td>
</tr>
Example #10
0
if ($is_active_user) {
    ?>
<p><em>Ratios aren't currently enforced, but will be shortly. Keep an eye on yours. If it's lower than 0.20, you should start seeding more and leeching less.</em></p><?php 
}
?>
<p>
	Current ratio: <?php 
echo $user->ratio;
?>
<br />
	Total uploaded: <?php 
echo pretty_size($user->uploaded);
?>
<br />
	Total downloaded: <?php 
echo pretty_size($user->downloaded);
?>
</p>

<?php 
if ($total_active == 0) {
    ?>
	<h3>Active Torrents (0)</h3>
	<?php 
    if ($is_active_user) {
        ?>
		<p><em>You don't have any active torrents. Your torrent client is probably offline, or you haven't gotten around to up/downloading anything.</em></p>
	<?php 
    } else {
        ?>
		<p><em><?php 
Example #11
0
      <?php 
    if (!empty($cmd)) {
        ?>
      <pre id="cmd">$ <?php 
        echo $cmd;
        ?>
</pre>
      <?php 
    }
    ?>

      <?php 
    if (!empty($json)) {
        ?>
      <p class="patience"><em>Be patient. Writing <?php 
        echo pretty_size(mb_strlen($json));
        ?>
 of JSON...</em></p>
      <textarea id="output" cols="50" rows="32"><?php 
        echo escape(trim($json), false);
        ?>
</textarea>
      <?php 
    }
    ?>

    </form>
    <?php 
}
?>