Быстрая регистрация пользователя

21.02.2013 Bitrix, php скрипты No comments ,

function simpleRegister($strMail){

 global $APPLICATION, $USER, $DB;
 
 // стандартная процедура регистрации пользователя
 $bConfirmReq = COption::GetOptionString("main", "new_user_registration_email_confirmation", "N") == "Y";

 $arUser["PASSWORD"]     = randString(music);
 $arUser["LOGIN"]           = $strMail;
 $arUser["EMAIL"]           = $strMail;
 $arUser["LAST_NAME"]       = '';
 $arUser["SECOND_NAME"]     = '';
 $arUser["PERSONAL_PHONE"]  = '';
 $arUser["NAME"]            = '';  
 $arUser["CHECKWORD"]       = randString(music);
 $arUser["~CHECKWORD_TIME"] = $DB->CurrentTimeFunction();
 $arUser["ACTIVE"]          = $bConfirmReq? "N": "Y";
 $arUser["CONFIRM_CODE"]    = $bConfirmReq? randString(music): "";
 $arUser["LID"]             = SITE_ID;
 $arUser["USER_IP"]         = $_SERVER["REMOTE_ADDR"];
 $arUser["USER_HOST"]       = @gethostbyaddr($REMOTE_ADDR);
   
 if($arUser["AUTO_TIME_ZONE"] <> "Y" && $arUser["AUTO_TIME_ZONE"] <> "N")
  $arUser["AUTO_TIME_ZONE"] = "";

 $def_group = COption::GetOptionString("main", "new_user_registration_def_group", "");
 if($def_group != "")
  $arUser["GROUP_ID"] = explode(",", $def_group);

 $bOk = true;

 $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("USER", $arUser);

 $events = GetModuleEvents("main", "OnBeforeUserRegister");
 while($arEvent = $events->Fetch())
 {
  if(ExecuteModuleEventEx($arEvent, array(&$arUser)) === false)
  {
  if($err = $APPLICATION->GetException())
   $arErr[] = $err->GetString();
   $bOk = false;
   break;
  }
 }
   
 
 
 if ($bOk)
 {
  $user = new CUser();
  if($ID  = $user->Add($arUser)){
   //$USER->Authorize($ID);
   $event = new CEvent;
   $event->SendImmediate("USER_INVITE", SITE_ID, $arUser);
   if(COption::GetOptionString("main", "event_log_register", "N") === "Y")
    CEventLog::Log("SECURITY", "USER_REGISTER", "main", $ID);
  }  
  return true;
 }else{
  return false;
 }
 
 

}

Функа для проверки пользователя по эл. почте

21.02.2013 Bitrix No comments ,

function checkUserExist($strMail){

 $filter = Array("EMAIL" => $strMail);
 $rsUsers = CUser::GetList(($by="personal_country"), ($order="desc"), $filter); // выбираем пользователей  
 if($user = $rsUsers->GetNext()){
  return true;
 }else{
  return false;
 }

}

robots.txt для битрикса

21.02.2013 Bitrix No comments

User-agent: *
Disallow: /bitrix/
Disallow: /search/
Disallow: /auth/
Disallow: /auth.php
Disallow: /*/search/
Disallow: /*PAGE_NAME=search
Disallow: /*PAGE_NAME=user_post
Disallow: /*PAGE_NAME=detail_slide_show
Disallow: /*/slide_show/
Disallow: /*/gallery/*order=*
Disallow: /*?print=
Disallow: /*&print=
Disallow: /*register=yes
Disallow: /*forgot_password=yes
Disallow: /*change_password=yes
Disallow: /*login=yes
Disallow: /*logout=yes
Disallow: /*auth=yes
Disallow: /*action=ADD_TO_COMPARE_LIST
Disallow: /*action=DELETE_FROM_COMPARE_LIST
Disallow: /*action=ADD2BASKET
Disallow: /*action=BUY
Disallow: /*print_course=Y
Disallow: /*bitrix_*=
Disallow: /*backurl=*
Disallow: /*BACKURL=*
Disallow: /*back_url=*
Disallow: /*BACK_URL=*
Disallow: /*back_url_admin=*

Многоуровневое меню BITRIX

19.02.2013 Bitrix, php скрипты No comments ,

result_modifier.php

if (!function_exists("getChild")){
  function getChild ( $arInput = array(), $parentIndex = 0 ){
    if (!isSet($arInput[$parentIndex])) {
      return $arInput;
    } else {
      if ($arInput[$parentIndex]["IS_PARENT"]){
        $parentDepth = $arInput[$parentIndex]["DEPTH_LEVEL"];
        $index = $parentIndex+1;
        $child = array();
        while (isset($arInput[$index]) && $arInput[$index]["DEPTH_LEVEL"] > $parentDepth){
          $child[] = $arInput[$index];
          unSet($arInput[$index]);
          $index++;
        }
        unSet($index);
        $child = getChild($child);
        $arInput[$parentIndex]["CHILD"] = $child;
        unSet($child);
      }
      $result = array();
      foreach($arInput as $index=>$item){
        $result[] = $item;
      }
      $arInput = $result;
      unSet($result);
      return getChild($arInput, $parentIndex+1);
    }
  }
}

$arResult = getChild($arResult);

template.php

<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>

<?
$generateMenu = function ($arResult = array(), $depth = 1, $maxDepth = 4, $parentTitle = "") use (&$generateMenu){
    if ($depth > $maxDepth || $depth < 1) return false;
    if ($depth == 1){?>
    <ul class="header-navigation-list">
      <?
      foreach ($arResult as $index=>$arItem){
        if ($arItem["DEPTH_LEVEL"] == 1){
          $addClass = "";
          if (!isSet($arResult[$index-1])) {
            $addClass .= " first";
          } elseif (!isSet($arResult[$index+1])){
            $addClass .= " last";
          };
          if ($arItem["SELECTED"]){
            $addClass .= " selected";
          };
          ?>
          <li class="menu-inner<?=$addClass?>"><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a>
            <?if (isSet($arItem["CHILD"]) && ($depth+1<=$maxDepth))
                $generateMenu($arItem["CHILD"], $depth+1, $maxDepth, $arItem["TEXT"]);?>
          </li>
        <?
        }
      }?>
    </ul>
    <?
    } elseif ($depth == 2) {?>
      <div class="sub-menu-box">
        <div class="sub-menu-bottom-bg">
          <div class="sub-menu-inner">
            <?if (strpos($arResult[0]["LINK"], "services/")) {
              foreach ($arResult as $index=>$arItem){?>
                <div class="sub-menu-list-title">
                  <?=$arItem["TEXT"]?>
                </div>
                <?if (isSet($arItem["CHILD"]) && ($depth+1<=$maxDepth))
                  $generateMenu($arItem["CHILD"], $depth+1, $maxDepth, $arItem["TEXT"]);
              }
            } else {?>
              <div class="sub-menu-list-title"><?=$parentTitle;?></div>
                  <ul class="sub-menu-list">
                    <?foreach ($arResult as $index=>$arItem):?>
                      <li><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a>
                      <?if (isSet($arItem["CHILD"]) && ($depth+1<=$maxDepth))
                        $generateMenu($arItem["CHILD"], $depth+1, $maxDepth, $arItem["TEXT"]);?>
                      </li>
                    <?endforeach;?>
                  </ul>
            <?
            }
            ?>
          </div>
        </div>
      </div><?
    } else {?>
      <ul class="sub-menu-list">
        <?foreach ($arResult as $index=>$arItem):?>
          <li><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a>
          <?if (isSet($arItem["CHILD"]) && ($depth+1<=$maxDepth))
            $generateMenu($arItem["CHILD"], $depth+1, $maxDepth);?>
          </li>
        <?endforeach;?>
      </ul><?
    }
  }
?>

<div class="header-navigation-box">
<?if (!empty($arResult))
  $generateMenu($arResult, 1, $arParams["MAX_LEVEL"]);?>
</div>

Делает любой компонент ajax

19.02.2013 Bitrix, javascript No comments , ,

<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");?>
<script type="text/javascript" src="/bitrix/js/main/ajax.js"></script>
<?$APPLICATION->IncludeComponent(
 "bitrix:form.result.new",
 "",
 Array(
  "AJAX_MODE" => "Y",  // режим AJAX
  "AJAX_OPTION_SHADOW" => "N", // затемнять область
  "AJAX_OPTION_JUMP" => "Y", // скроллить страницу до компонента
  "AJAX_OPTION_STYLE" => "Y", // подключать стили
  "AJAX_OPTION_HISTORY" => "N",
 ),
false
);?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");?>

Содержимое этого файла подключить через include или jQuery().load();

Ввод только русских символов

06.02.2013 javascript No comments , , ,



// Решени для javascript
function setValidator(id, regex) {
  var element = document.getElementById(id);
  if (element) {
    var lastValue = element.value;
    if (!regex.test(lastValue))
      lastValue = '';
    setInterval(function() {
      var value = element.value;
      if (value != lastValue) {
        if (regex.test(value))
          lastValue = value;
        else
          element.value = lastValue;
      }
    }, 10);
  }
}

// Решение для jQuery
$(document).ready(function(){
	$('.inputField').keyup(function(){
		var login			= $(this).val();
		var shablon			= /[А-Яа-я]{1,50}/;
		var resultCheck		= login.match(shablon);
		if (resultCheck==login && resultCheck!=null){
				//$('#info').text("");
			}
		else{
			var kolich= login.length;
			//$('#info').text("Разрешены  буквы");
			login = login.slice(0,kolich-1);
			$(this).val(login);
		}
	});
});/*end ready*/


<input type="text" id="test" class='inputField'/>
<input type="text" id="test2" class='inputField'/>
<input type="text" id="test3" class='inputField'/>
<input type="text" id="test4" class='inputField'/>
<script type="text/javascript">
	setValidator('test', /^[а-яА-я-]*$/);
</script>

Рандомное целое число javascript

02.02.2013 javascript No comments


var randomnumber=Math.floor(Math.random()*11)

console.log(randomnumber)

Формат цен BITRIX price

01.02.2013 Bitrix No comments , , ,

 $number = 123465789.45;
 $numbre_format_francais = number_format($number, 2, '.', ' ');  // 123 465 789.45

echo CurrencyFormat(11800.95, "USD");

CCurrencyLang::CurrencyFormat(5000, 'RUB'); // 5 000
CCurrencyLang::CurrencyFormat(5000, 'RUB', true); // 5 000 руб.

лови ссылочку, бро, тут больше инфы
http://dev.1c-bitrix.ru/api_help/currency/functions/currencyformat.php

Вывод размер в КБ, МБ, ГБ

29.01.2013 php, php скрипты No comments ,

function fSize($file){
    $file = $_SERVER['DOCUMENT_ROOT'].$file;
    $FZ = ($file && @is_file($file)) ? filesize($file) : NULL;
    $FS = array("B","kB","MB","GB","TB","PB","EB","ZB","YB");
    return number_format($FZ/pow(1024, $I=floor(log($FZ, 1024))), ($i >= 1) ? 2 : 0) . ' ' . $FS[$I];
}
function fSize($FZ){
    $FS = array("B","kB","MB","GB","TB","PB","EB","ZB","YB");
    return number_format($FZ/pow(1024, $I=floor(log($FZ, 1024))), ($i >= 1) ? 2 : 0) . ' ' . $FS[$I];
}

array_map_deep

25.01.2013 php, php скрипты 1 comment

Пробегает по все элементам массива

function array_map_deep($array, $callback) { 
    $new = array(); 
    foreach ($array as $key => $val) { 
        if (is_array($val)) { 
            $new[$key] = array_map_deep($val, $callback); 
        } else { 
            $new[$key] = call_user_func($callback, $val); 
        } 
    } 
    return $new; 
}