Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as PHP by Vlad ( 13 years ago )
<?php
class Profitraf
{
private $config = array();
private $errstr = 'Нет ошибок';
private function setArray($config, $par)
{
if (!isset($config[$par]))
$this->config[$par] = array();
else
$this->config[$par] = $config[$par];
}
private function setBool($config, $par)
{
if (isset($config[$par]) and $config[$par] === true)
$this->config[$par] = true;
else
$this->config[$par] = false;
}
private function setString($config, $par)
{
if (isset($config[$par]))
$this->config[$par] = $config[$par];
else
$this->config[$par] = '';
}
// loads configuration
public function loadConfig()
{
if (is_file(profitraf_conffile)) {
include profitraf_conffile;
}
// state
$this->setBool($config, 'on');
// hosts
$this->setArray($config, 'hosts');
// groups
$this->setArray($config, 'groups');
// attachments
$this->setBool($config, 'attach');
// news
$this->setBool($config, 'post');
// static
$this->setBool($config, 'static');
// link name
$this->setString($config, 'linkname');
// link size
$this->setString($config, 'linksize');
// link type
$this->setString($config, 'linktype');
}
// saves configuration
public function saveConfig($on, $hosts, $groups, $attach, $post, $static)
{
// parsing hosts
$phosts = array();
$tmp_hosts = explode("\n", $hosts);
foreach ($tmp_hosts as $host)
if (($tmp = trim($host)) != '')
$phosts[] = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $tmp));
$phosts = array_unique($phosts);
// parsing groups
$pgroups = array();
if (isset($groups))
foreach ($groups as $group)
$pgroups[] = intval($group);
$pgroups = array_unique($pgroups);
// parsing strings
$linkname = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $this->config['linkname']));
$linksize = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $this->config['linksize']));
$linktype = str_replace('\'', '\\\'', str_replace('\\', '\\\\', $this->config['linktype']));
$str = '<?php
$config = array(
\'on\' => ' . ($on ? 'true' : 'false') . ',
\'attach\' => ' . ($attach ? 'true' : 'false') . ',
\'post\' => ' . ($post ? 'true' : 'false') . ',
\'static\' => ' . ($static ? 'true' : 'false') . ',
\'hosts\' => array(';
$tmp = '';
foreach ($phosts as $host)
$tmp .= '
\'' . $host . '\',';
$str .= substr($tmp, 0, -1) . '
),
\'groups\' => array(';
$tmp = '';
foreach ($pgroups as $group)
$tmp .= '
' . $group . ',';
$str .= substr($tmp, 0, -1) . '
),
\'linkname\' => \'' . $linkname . '\',
\'linksize\' => \'' . $linksize . '\',
\'linktype\' => \'' . $linktype . '\'
);';
if (false === file_put_contents(profitraf_conffile, $str)) {
$this->errstr = 'Не могу записать конфигурацию в файл "' . realpath(profitraf_conffile) . '"';
return false;
}
return true;
}
public function getType($ext)
{
$types = array('archive' => '.7z.bz2.cab.deb.jar.rar.rpm.tar.zip.',
'video' => ".3gp.aaf.asf.flv.mkv.mov.mpeg.qt.wmv.hdv.mpeg4.mp4.dvd.mxf.avi.",
'audio' => ".aac.asf.cda.fla.mp3.ogg.wav.wma.cd.ac3.dts.flac.midi.mod.aud.",
'image' => ".bmp.cpt.gif.jpeg.jpg.jp2.pcx.png.psd.tga.tpic.tiff.tif.wdp.hdp.cdr.svg.ico.ani.cur.xcf.",
'torrent' => ".torrent.",
'android' => ".apk.",
'book' => ".ps.eps.pdf.doc.txt.rtf.djvu.opf.chm.sgml.xml.fb2.fb3.tex.lit.exebook.prc.epub.",
'disk' => ".img.iso.nrg.mdf.uif.bin.cue.daa.pqi.cso.ccd.sub.wim.swm.rwm.");
$ext = '.' . strtolower($ext) . '.';
foreach ($types as $type => $exts)
if (false !== strpos($exts, $ext))
return $type;
return 'setup';
}
// returns profitraf url
public function createUrl($url, $group, $name = null, $size = null, $isattach = false)
{
global $config;
if (!isset($this->config))
return '';
if (!$this->config['on'])
return '';
if (count($this->config['groups']) and !in_array($group, $this->config['groups']))
return '';
// leech
if (substr($url, 0, strlen($config['http_home_url'])) == $config['http_home_url'] and false !== $leechPos = strpos($url, 'go.php?url='))
$url = base64_decode(urldecode(substr($url, $leechPos + 11)));
// remove last slashes
$url = preg_replace('@/*$@', '', $url);
// name
if (false === $lastSlash = strrpos($url, '/'))
$urlName = $url;
else
$urlName = substr($url, $lastSlash + 1);
// extension
if (false === $lastDot = strrpos($urlName, '.'))
$urlExt = '';
else
$urlExt = substr($urlName, $lastDot + 1);
// domain
if (false === $firstSlash = strpos($url, '/')) {
$urlProtocol = '';
$urlDomain = $url;
} else {
if ($firstSlash != 0 and $firstSlash != strlen($url) - 2 and $url[$firstSlash - 1] == ':' and $url[$firstSlash + 1] == '/') {
$urlProtocol = substr($url, 0, $firstSlash - 1);
if (false === $secondSlash = strpos($url, '/', $firstSlash + 2))
$urlDomain = substr($url, $firstSlash + 2);
else
$urlDomain = substr($url, $firstSlash + 2, $secondSlash - $firstSlash - 2);
} else {
$urlProtocol = '';
$urlDomain = substr($url, 0, $firstSlash);
}
}
// check domain
if (!$isattach and count($this->config['hosts'])) {
$found = false;
foreach ($this->config['hosts'] as $host)
if (substr($urlDomain, -strlen($host)) == $host) {
$found = true;
break;
}
} else
$found = true;
if (!$found)
return '';
// get ext
if ($name) {
// extension
if (false === $nameDot = strrpos($name, '.'))
$ext = $urlExt;
else
$ext = substr($name, $nameDot + 1);
} else {
$name = $urlName;
$ext = $urlExt;
}
// get type
$type = $this->getType($ext);
$str = $this->config['linktype'] . '="' . str_replace('"', '', $type) . '" ';
if ($name)
$str .= $this->config['linkname'] . '="' . str_replace('"', '', $name) . '" ';
if ($size)
$str .= $this->config['linksize'] . '="' . str_replace('"', '', $size) . '" ';
return $str;
}
// returns error string
public function error()
{
return $this->errstr;
}
// returns hosts
public function getHosts()
{
return $this->config['hosts'];
}
// returns groups
public function getGroups()
{
return $this->config['groups'];
}
// returns state
public function isOn()
{
return $this->config['on'];
}
// returns attachments
public function isAttachments()
{
return $this->config['attach'];
}
// returns news
public function isPost()
{
return $this->config['post'];
}
// returns static
public function isStatic()
{
return $this->config['static'];
}
public function replaceLinks($str, $group)
{
$resstr = '';
$pos2 = 0;
while (false !== $pos = strpos($str, 'href="', $pos2)) {
$resstr .= substr($str, $pos2, $pos - $pos2);
if (false === $pos2 = strpos($str, '"', $pos + 6)) {
$pos2 = $pos;
break;
}
$url = substr($str, $pos + 6, $pos2 - $pos - 6);
$resstr .= $this->createUrl($url, $group) . substr($str, $pos, $pos2 - $pos);
}
$resstr .= substr($str, $pos2);
return $resstr;
}
Revise this Paste