Skip to content

Instantly share code, notes, and snippets.

View umidjons's full-sized avatar
🏠
Working from home

Umid umidjons

🏠
Working from home
View GitHub Profile
@umidjons
umidjons / print_json.php
Last active December 18, 2015 22:49
Print JSON data to response for some request
<?php
function PrintJSON( $jsonData )
{
header( 'Content-Type: application/json; charset=utf8' );
echo $jsonData;
}
?>
@umidjons
umidjons / addmessage2log.php
Created June 26, 2013 04:37
BX: AddMessage2Log() implementation from Bitrix Framework
<?php
function AddMessage2Log( $sText, $sModule = "" )
{
if ( defined( "LOG_FILENAME" ) && strlen( LOG_FILENAME ) > 0 ) {
if ( strlen( $sText ) > 0 ) {
ignore_user_abort( true );
if ( $fp = @fopen( LOG_FILENAME, "ab+" ) ) {
if ( flock( $fp, LOCK_EX ) ) {
@fwrite( $fp, date( "Y-m-d H:i:s" ) . " - " . $sModule . " - " . $sText . "\n" );
if ( function_exists( "debug_backtrace" ) ) {
@umidjons
umidjons / file_get_contents_through_load_balancer.php
Created June 26, 2013 06:59
For those who use file_get_contents for JSON or other RESTful services. Site using get urls go through load balancer instead of hitting the local server. Load this function through a local url and set the Host: header for virtualhost entries on the site we wanted to load.
<?php
// set the header context stream for virtualhost lookup
$context = stream_context_create( array( 'http' => array( 'header' => 'Host: www.someurl.uz' ) ) );
// use a localhost url or alternatively 127.0.0.1 ip
$url = 'http://localhost/api/filter.org.php?login=test_user&password=mypassword&otherparam=itsvalue';
// fetch the data through webserver using the Host http header we set
$data = json_decode( file_get_contents( $url, 0, $context ) );
// verify you have your data
var_dump( $data );
?>
@umidjons
umidjons / datepicker_with_calendardate.php
Created June 26, 2013 09:33
BX: Date picker with Bitrix's CalendarDate()
<form action="<?=$APPLICATION->GetCurPage()?>" method="POST" name="form1">
<?php echo CalendarDate("birthdate", "25.11.1975", "form1", "15", "class=\"my_input\""); ?>
<?php echo CalendarDate("deathdate", ConvertTimeStamp(), "form1", "15", "class=\"my_input\""); ?>
</form>
@umidjons
umidjons / bx_prolog_epilog.php
Created June 27, 2013 09:22
Include Bitrix header and footer without template
<?php
require( $_SERVER[ 'DOCUMENT_ROOT' ] . '/bitrix/modules/main/include/prolog_before.php' ); // header
// other stuff here...
require( $_SERVER[ 'DOCUMENT_ROOT' ] . '/bitrix/modules/main/include/epilog_after.php' ); // footer
?>
@umidjons
umidjons / bx_active_users_list_in_groups.php
Created June 28, 2013 05:11
BX: Retrieves active users list in specified groups.
<?
/**
* Callback to use in array_filter function, which filters only active users.
* @param $userID int id of the user
* @return bool true if user is active, otherwise false
*/
function IsActive( $userID )
{
$rsUser = CUser::GetByID( $userID );
$user = $rsUser->Fetch();
@umidjons
umidjons / is_extension_loaded.php
Created July 1, 2013 06:31
Check, is PHP extension loaded.
<?php
if ( extension_loaded( "soap" ) ) {
echo 'Soap loaded';
}
else {
echo 'Soap NOT loaded';
}
?>
@umidjons
umidjons / basic_auth
Created July 2, 2013 05:46
Basic Authentication through .htaccess
# create password for user admin in /etc/httpd/mypasswd file
htpasswd -c /etc/httpd/mypasswd admin
# create .htaccess file in directory that you want restrict access
# write these rules
AuthType Basic
AuthName "Restricted Area"
AuthBasicProvider file
AuthUserFile /etc/httpd/mypasswd
Require valid-user
@umidjons
umidjons / organization.wsdl
Created July 2, 2013 09:12
SOAP server/client example in WSDL mode
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="Organization"
targetNamespace="urn:Organization"
xmlns:tns="urn:Organization"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
@umidjons
umidjons / thumbnail_create.php
Created July 3, 2013 11:10
Dynamically create thumbnails
<?php
class ImgUtils {
/**
* Creates and returns image resource if type is supported.
* Currently supported types (JPEG, GIF, PNG)
* @param string $file URL to the file
* @return bool|resource image resource if image type supported, otherwise false
*/
private static function OpenImage( $file )
{