Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
hbashton authored and StyleCIBot committed May 20, 2017
1 parent dee5184 commit 7981286
Show file tree
Hide file tree
Showing 28 changed files with 2,265 additions and 2,257 deletions.
28 changes: 14 additions & 14 deletions add.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ function add_group($update, $MadelineProto)
$peer = $chat['peer'];
$title = htmlentities($chat['title']);
$ch_id = $chat['id'];
$default = array(
'peer' => $peer,
$default = [
'peer' => $peer,
'reply_to_msg_id' => $msg_id,
'parse_mode' => 'html',
);
'parse_mode' => 'html',
];
if (from_admin($update, $MadelineProto, $mods, true)) {
check_json_array('chatlist.json', $ch_id, false);
$file = file_get_contents("chatlist.json");
$file = file_get_contents('chatlist.json');
$chatlist = json_decode($file, true);
if (!in_array($ch_id, $chatlist)) {
array_push($chatlist, $ch_id);
file_put_contents('chatlist.json', json_encode($chatlist));
$str = $MadelineProto->responses['add_group']['added'];
$repl = array("title" => $title);
$repl = ['title' => $title];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
} else {
$str = $MadelineProto->responses['add_group']['already'];
$repl = array("title" => $title);
$repl = ['title' => $title];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
}
Expand Down Expand Up @@ -57,14 +57,14 @@ function rm_group($update, $MadelineProto)
$peer = $chat['peer'];
$title = htmlentities($chat['title']);
$ch_id = $chat['id'];
$default = array(
'peer' => $peer,
$default = [
'peer' => $peer,
'reply_to_msg_id' => $msg_id,
'parse_mode' => 'html',
);
'parse_mode' => 'html',
];
if (from_admin($update, $MadelineProto, $mods, true)) {
check_json_array('chatlist.json', $ch_id, false);
$file = file_get_contents("chatlist.json");
$file = file_get_contents('chatlist.json');
$chatlist = json_decode($file, true);
if (in_array($ch_id, $chatlist)) {
if (($key = array_search(
Expand All @@ -76,12 +76,12 @@ function rm_group($update, $MadelineProto)
}
file_put_contents('chatlist.json', json_encode($chatlist));
$str = $MadelineProto->responses['rm_group']['removed'];
$repl = array("title" => $title);
$repl = ['title' => $title];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
} else {
$str = $MadelineProto->responses['rm_group']['not_there'];
$repl = array("title" => $title);
$repl = ['title' => $title];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
}
Expand Down
65 changes: 44 additions & 21 deletions arabic.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
<?php

function check_utf8($str) {
function check_utf8($str)
{
$len = strlen($str);
for($i = 0; $i < $len; $i++){
for ($i = 0; $i < $len; $i++) {
$c = ord($str[$i]);
if ($c > 128) {
if (($c > 247)) return false;
elseif ($c > 239) $bytes = 4;
elseif ($c > 223) $bytes = 3;
elseif ($c > 191) $bytes = 2;
else return false;
if (($i + $bytes) > $len) return false;
if (($c > 247)) {
return false;
} elseif ($c > 239) {
$bytes = 4;
} elseif ($c > 223) {
$bytes = 3;
} elseif ($c > 191) {
$bytes = 2;
} else {
return false;
}
if (($i + $bytes) > $len) {
return false;
}
while ($bytes > 1) {
$i++;
$b = ord($str[$i]);
if ($b < 128 || $b > 191) return false;
if ($b < 128 || $b > 191) {
return false;
}
$bytes--;
}
}
}

return true;
} // end of check_utf8

function uniord($u) {
function uniord($u)
{
// i just copied this function fron the php.net comments, but it should work fine!
$k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
$k1 = ord(substr($k, 0, 1));
$k2 = ord(substr($k, 1, 1));

return $k2 * 256 + $k1;
}
function is_arabic($str) {
if(mb_detect_encoding($str) !== 'UTF-8') {
$str = mb_convert_encoding($str,mb_detect_encoding($str),'UTF-8');
function is_arabic($str)
{
if (mb_detect_encoding($str) !== 'UTF-8') {
$str = mb_convert_encoding($str, mb_detect_encoding($str), 'UTF-8');
}

/*
Expand All @@ -43,21 +58,22 @@ function is_arabic($str) {
$arabic_count = 0;
$latin_count = 0;
$total_count = 0;
foreach($chars as $char) {
foreach ($chars as $char) {
//$pos = ord($char); we cant use that, its not binary safe
$pos = uniord($char);

if($pos >= 1536 && $pos <= 1791) {
if ($pos >= 1536 && $pos <= 1791) {
$arabic_count++;
} else if($pos > 123 && $pos < 123) {
} elseif ($pos > 123 && $pos < 123) {
$latin_count++;
}
$total_count++;
}
if(($arabic_count/$total_count) > 0.6) {
if (($arabic_count / $total_count) > 0.6) {
// 60% arabic chars, its probably arabic
return true;
}

return false;
}

Expand All @@ -66,21 +82,28 @@ function check_for_links($update, $MadelineProto)
if (array_key_exists('message', $update['update'])) {
if (array_key_exists('message', $update['update']['message'])) {
$pattern = '~[a-z]+://\S+~';
if (preg_match_all($pattern, $update['update']['message']['message'], $out)) return true;
if (preg_match_all($pattern, $update['update']['message']['message'], $out)) {
return true;
}
if (array_key_exists('entities', $update['update']['message'])) {
foreach ($update['update']['message']['entities'] as $entity) {
if (isset($entity['_'])) {
$links = ["messageEntityUrl", "messageEntityTextUrl"];
if (in_array($entity['_'], $links)) return true;
$links = ['messageEntityUrl', 'messageEntityTextUrl'];
if (in_array($entity['_'], $links)) {
return true;
}
}
}
}
if (array_key_exists('media', $update['update']['message'])) {
if (isset($update['update']['message']['media']['_'])) {
if ($update['update']['message']['media']['_'] == "messageMediaWebPage") return true;
if ($update['update']['message']['media']['_'] == 'messageMediaWebPage') {
return true;
}
}
}
}
}

return false;
}
Loading

0 comments on commit 7981286

Please sign in to comment.