function Table_Super_Replace($Array, $Matches) { #--------------------------------------------------------------------------- $Result = array(); #--------------------------------------------------------------------------- if (Is_Array($Array)) { #------------------------------------------------------------------------- foreach (Array_Keys($Array) as $ElementID) { #----------------------------------------------------------------------- $Element = $Array[$ElementID]; #----------------------------------------------------------------------- $Result[$ElementID] = Is_Array($Element) ? Table_Super_Replace($Element, $Matches) : Str_Replace(Array_Keys($Matches), Array_Values($Matches), $Element); } } #--------------------------------------------------------------------------- return $Result; }
function IspManager4_Get_Email_Boxes($Settings) { /****************************************************************************/ $__args_types = array('array'); #----------------------------------------------------------------------------- $__args__ = Func_Get_Args(); eval(FUNCTION_INIT); /****************************************************************************/ $authinfo = SPrintF('%s:%s', $Settings['Login'], $Settings['Password']); #----------------------------------------------------------------------------- $HTTP = IspManager4_Build_HTTP($Settings); #----------------------------------------------------------------------------- $Response = HTTP_Send('/manager/ispmgr', $HTTP, array(), array('authinfo' => $authinfo, 'out' => 'xml', 'func' => 'emaildomain')); if (Is_Error($Response)) { return new gException('NOT_CONNECTED_TO_SERVER', 'Не удалось соедениться с сервером'); } #----------------------------------------------------------------------------- $Response = Trim($Response['Body']); #----------------------------------------------------------------------------- $XML = String_XML_Parse($Response); if (Is_Exception($XML)) { return new gException('WRONG_SERVER_ANSWER', $Response, $XML); } #----------------------------------------------------------------------------- $XML = $XML->ToArray('elem'); #----------------------------------------------------------------------------- $Result = $XML['doc']; #----------------------------------------------------------------------------- if (!Is_Array($Result)) { return new gException('BOXES_NOT_FOUND', 'Почтовых доменов не обнаружено'); } #----------------------------------------------------------------------------- if (isset($Result['error'])) { return ERROR | @Trigger_Error('[IspManager4_Get_Email_Boxes]: не удалось получить список почтовых ящиков'); } #----------------------------------------------------------------------------- $Domains = array(); #----------------------------------------------------------------------------- foreach ($Result as $Domain) { #--------------------------------------------------------------------------- if (!Is_Array($Domain)) { continue; } #--------------------------------------------------------------------------- $Owner = $Domain['owner']; #--------------------------------------------------------------------------- if (!isset($Users[$Owner])) { $Users[$Owner] = array(); } #--------------------------------------------------------------------------- $Domains[$Domain['name']] = array('Owner' => $Owner, 'Boxes' => array()); } #----------------------------------------------------------------------------- $Response = HTTP_Send('/manager/ispmgr', $HTTP, array(), array('authinfo' => $authinfo, 'out' => 'xml', 'func' => 'email')); if (Is_Error($Response)) { return new gException('NOT_CONNECTED_TO_SERVER', 'Не удалось соедениться с сервером'); } #----------------------------------------------------------------------------- $Response = $Response['Body']; #----------------------------------------------------------------------------- $XML = String_XML_Parse($Response); if (Is_Exception($XML)) { return new gException('WRONG_SERVER_ANSWER', 'Неверный ответ от сервера'); } #----------------------------------------------------------------------------- $XML = $XML->ToArray('elem', array('used', 'limit')); #----------------------------------------------------------------------------- $Result = $XML['doc']; #----------------------------------------------------------------------------- if (!Is_Array($Result)) { return new gException('BOXES_NOT_FOUND', 'Почтовых ящиков не обнаружено'); } #----------------------------------------------------------------------------- if (isset($Result['error'])) { return ERROR | @Trigger_Error('[IspManager4_Get_Email_Boxes]: не удалось получить список почтовых ящиков'); } #----------------------------------------------------------------------------- foreach ($Result as $Box) { #--------------------------------------------------------------------------- if (!Is_Array($Box)) { continue; } #--------------------------------------------------------------------------- $Name = Explode('@', $Box['name']); #--------------------------------------------------------------------------- if (!isset($Domains[$Domain = Next($Name)])) { continue; } #--------------------------------------------------------------------------- $Domains[$Domain]['Boxes'][$Box['name']] = Array_Values($Box['size']); } #----------------------------------------------------------------------------- $Users = array(); #----------------------------------------------------------------------------- foreach ($Domains as $DomainID => $Domain) { #--------------------------------------------------------------------------- $Owner = $Domain['Owner']; #--------------------------------------------------------------------------- if (!isset($Users[$Owner])) { $Users[$Owner] = array(); } #--------------------------------------------------------------------------- foreach ($Domain['Boxes'] as $Email => $Box) { $Users[$Owner][$Email] = $Box; } } #----------------------------------------------------------------------------- return $Users; }
function Resize_Image($src, $width = 0, $height = 0, $dst) { if ($height <= 0 && $width <= 0) { return false; } // Setting defaults and meta $image = ''; $final_width = 0; $final_height = 0; list($width_old, $height_old, $image_type) = GetImageSize($src); // Calculating proportionality if ($width == 0) { $factor = $height / $height_old; } elseif ($height == 0) { $factor = $width / $width_old; } else { $factor = Min($width / $width_old, $height / $height_old); } $final_width = Round($width_old * $factor); $final_height = Round($height_old * $factor); // Loading image to memory according to type switch ($image_type) { case IMAGETYPE_GIF: $image = imagecreatefromgif($src); break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($src); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($src); break; default: return false; } // This is the resizing/resampling/transparency-preserving magic $image_resized = ImageCreateTrueColor($final_width, $final_height); if ($image_type == IMAGETYPE_GIF || $image_type == IMAGETYPE_PNG) { $transparency = ImageColorTransparent($image); if ($image_type == IMAGETYPE_GIF && $transparency >= 0) { list($r, $g, $b) = Array_Values(ImageColorsForIndex($image, $transparency)); $transparency = ImageColorAllocate($image_resized, $r, $g, $b); Imagefill($image_resized, 0, 0, $transparency); ImageColorTransparent($image_resized, $transparency); } elseif ($image_type == IMAGETYPE_PNG) { ImageAlphaBlending($image_resized, false); $color = ImageColorAllocateAlpha($image_resized, 0, 0, 0, 127); ImageFill($image_resized, 0, 0, $color); ImageSaveAlpha($image_resized, true); } } ImageCopyResampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old); // Writing image switch ($image_type) { case IMAGETYPE_GIF: imagegif($image_resized, $dst); break; case IMAGETYPE_JPEG: imagejpeg($image_resized, $dst, 85); break; case IMAGETYPE_PNG: imagepng($image_resized, $dst); break; default: return false; } }
private function HandleResponse($File, $Data) { if ($File === 'API/SupportedAPIList.json') { $Data = JSON_Decode($Data, true); if (!isset($Data['apilist']['interfaces'])) { return false; } foreach ($Data['apilist']['interfaces'] as $Interface) { $File = __DIR__ . '/API/' . $Interface['name'] . '.json'; $Interface = JSON_Encode($Interface, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL; if (!File_Exists($File) || StrCmp(File_Get_Contents($File), $Interface) !== 0) { File_Put_Contents($File, $Interface); } } return true; } else { if ($File === 'ClientManifest/steam_client_publicbeta_osx' || $File === 'ClientManifest/steam_cmd_publicbeta_osx') { foreach ($this->ClientArchives as $Archive) { if (Preg_Match('/"' . Str_Replace('.', '\\.', $Archive) . '\\.([a-f0-9]{40})"/m', $Data, $Test) === 1) { $Test = $Test[1]; if (!isset($this->ETags[$Archive]) || $this->ETags[$Archive] !== $Test) { $this->Log('Downloading {lightblue}' . $Archive . '{normal} - checksum: ' . $Test); $this->ETags[$Archive] = $Test; $this->URLsToFetch[] = array('URL' => 'https://steamcdn-a.akamaihd.net/client/' . $Archive . '.' . $Test, 'File' => '.support/' . $Archive); } else { $this->Log('Matched {lightblue}' . $Archive . '{normal}, but we already have it cached'); } } else { $this->Log('{yellow}Failed to find {lightblue}' . $Archive); } } unset($Test); } else { if ($File === 'Random/ValveGroup.json' || $File === 'Random/SteamModerators.json') { LibXML_Use_Internal_Errors(true); $Data = SimpleXML_Load_String($Data); if ($Data === false || empty($Data->members->steamID64)) { return false; } $Data = Array_Values((array) $Data->members->steamID64); Sort($Data); $Data = JSON_Encode($Data, JSON_PRETTY_PRINT); } else { if ($File === 'Scripts/Dota2/heropickerdata.json') { $Data = JSON_Decode($Data, true); $Data = JSON_Encode($Data, JSON_PRETTY_PRINT); } else { if ($File === 'Scripts/Dota2/heropedia.js') { $Data = preg_replace('/\\?v=[0-9]+/', '?v=ayyvalve', $Data); } else { if (SubStr($File, 0, 13) === 'ItemSchemaURL') { $Data = JSON_Decode($Data, true); if (isset($Data['result']['items_game_url'])) { $this->URLsToFetch[] = array('URL' => $Data['result']['items_game_url'], 'File' => str_replace('ItemSchemaURL', 'ItemSchema', $File)); } return true; } else { if (SubStr($File, -4) === '.zip') { $File = __DIR__ . '/' . $File; File_Put_Contents($File, $Data); $Archive = SubStr(StrrChr($File, '/'), 1); if (SHA1_File($File) !== $this->ETags[$Archive]) { $this->Log('{lightred}Checksum mismatch for ' . $Archive); return false; } $this->ExtractClientArchives = true; return true; } else { if (SubStr($File, -5) === '.html') { if (StrrPos($Data, '</html>') === false) { return false; } } } } } } } } } $File = __DIR__ . '/' . $File; $Folder = dirname($File); if (!is_dir($Folder)) { $this->Log('{lightblue}Creating ' . $Folder); mkdir($Folder, 0755, true); } if (File_Exists($File) && StrCmp(File_Get_Contents($File), $Data) === 0) { return false; } File_Put_Contents($File, $Data); return true; }
function rlike($x) { $rlike = array("\\?" => "\\\\?", "(" => "\\(", ")" => "\\)", "|" => "\\|"); return str_ireplace(Array_keys($rlike), Array_Values($rlike), $x); }
function Resample_Image() { if ($this->dst_height <= 0 && $this->dst_width <= 0) { return False; } # Setting defaults and meta $image = $this->image; $final_width = 0; $final_height = 0; # Get File Information if ($arr_image_size = GetImageSize($this->attachment_file)) { list($width_old, $height_old, $image_type) = $arr_image_size; } else { return False; } if ($this->crop) { $factor = Max($this->dst_width / $width_old, $this->dst_height / $height_old); $final_width = $this->dst_width; $final_height = $this->dst_height; } else { # Calculating proportionality if ($this->dst_width == 0) { $factor = $this->dst_height / $height_old; } elseif ($this->dst_height == 0) { $factor = $this->dst_width / $width_old; } else { $factor = Min($this->dst_width / $width_old, $this->dst_height / $height_old); } $final_width = $width_old * $factor; $final_height = $height_old * $factor; } # Resample the image if (!Function_Exists('ImageCreateTrueColor')) { return False; } if (!($this->image = ImageCreateTrueColor($final_width, $final_height))) { return False; } # Copy the Transparency properties if ($image_type == IMAGETYPE_GIF || $image_type == IMAGETYPE_PNG) { if ($image_type == IMAGETYPE_GIF && $transparency >= 0) { $transparency = ImageColorTransparent($image); list($r, $g, $b) = Array_Values(ImageColorsForIndex($image, $transparency)); ImageColorAllocate($this->image, $r, $g, $b); Imagefill($this->image, 0, 0, $transparency); ImageColorTransparent($this->image, $transparency); } elseif ($image_type == IMAGETYPE_PNG) { ImageAlphaBlending($this->image, False); ImageSaveAlpha($this->image, True); } } if (!Function_Exists('ImageCopyResampled')) { return False; } if ($this->crop) { # Crop the image ImageCopyResampled($this->image, $image, 0, 0, ($width_old * $factor - $final_width) / (2 * $factor), ($height_old * $factor - $final_height) / (2 * $factor), $final_width, $final_height, $final_width / $factor, $final_height / $factor); // int $src_w , int $src_h } else { # Resample aspect ratio ImageCopyResampled($this->image, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old); } return True; }