Часть 12 из 12
Строки: 22001-24000 из 22262
================================================================================

    public static function add( $code = -1, $massage = "", $place = "", $function = "",  $user_id = 0 ) {
        
        try{
            $aRecord = array('user_id'    => $user_id,
                             'date'       => SConfig::$time,
                             'place'      => $place,
                             'function'   => $function,
                             'code'       => $code,
                             'massage'    => $massage);
            DBAccess::insert ( 'log_crash', $aRecord, array('id'));
        } catch(Exception $e) {
            $massage = $e->getMessage(); 
        }
    }
}

?>

================================================================================
ФАЙЛ: lib/jsonView.php
================================================================================

<?php

/**
 * Обертка для json шаблонизатора
 */
class jsonView extends View
{
	/**
	 * Преобразует информацию в формат json
	 * @param array $res массив аргументов
	 * @return string json-строка
	 */
	public function fetch($res)
	{
		//return json_encode($res);
		return $this->json_encode_cyr($res);
	}
	
	public function json_encode_cyr($str) {
        
	    $arr_replace_utf = array('\u0410', '\u0430','\u0411','\u0431','\u0412','\u0432',
	    '\u0413','\u0433','\u0414','\u0434','\u0415','\u0435','\u0401','\u0451','\u0416',
	    '\u0436','\u0417','\u0437','\u0418','\u0438','\u0419','\u0439','\u041a','\u043a',
	    '\u041b','\u043b','\u041c','\u043c','\u041d','\u043d','\u041e','\u043e','\u041f',
	    '\u043f','\u0420','\u0440','\u0421','\u0441','\u0422','\u0442','\u0423','\u0443',
	    '\u0424','\u0444','\u0425','\u0445','\u0426','\u0446','\u0427','\u0447','\u0428',
	    '\u0448','\u0429','\u0449','\u042a','\u044a','\u042b','\u044b','\u042c','\u044c',
	    '\u042d','\u044d','\u042e','\u044e','\u042f','\u044f', '\/','\\\\n', '\u2013');
	
	    $arr_replace_cyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е',
	    'Ё', 'ё', 'Ж','ж','З','з','И','и','Й','й','К','к','Л','л','М','м','Н','н','О','о',
	    'П','п','Р','р','С','с','Т','т','У','у','Ф','ф','Х','х','Ц','ц','Ч','ч','Ш','ш',
	    'Щ','щ','Ъ','ъ','Ы','ы','Ь','ь','Э','э','Ю','ю','Я','я','/', '\n', '-');
	
        //старый способ---------------------------------------------
	    //$str1 = json_encode($str);  
	    //$str2 = str_replace($arr_replace_utf,$arr_replace_cyr,$str1);
        //старый способ---------------------------------------------
        
        //новый способ----------------------------------------------
        $str1 = JsonCoder::jsonEncode($str);
        $str2 = str_replace($arr_replace_utf,$arr_replace_cyr,$str1);
        //новый способ----------------------------------------------
	
	    return $str2;
	}
	
}

?>

================================================================================
ФАЙЛ: index_for_watch.php
================================================================================

<?php   
require ("common.php");    //Подключаются библиотеки и основыне классы
$response = array ();
    $TYPE_APPLYCATION = Sconfig::$test_flag;
    $sVisualKey = rand(1000, 9999);
                            
    $data      = $_REQUEST['m'];
    //------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------
    //подпись для каждого запроса:
    if(true == Sconfig::$request_signature_flag){
        
        //вынести этот параметр в конфигурационный файл
        $sKeySig = INTERNAL_SECRET_KEY;
                        
        //$sSig = md5(strtolower($_REQUEST['m']).$sKeySig);
        $sSig = md5( Model::factory("word")->strtolower_rus($_REQUEST['m']).$sKeySig);
       
        //setlocale(LC_ALL, 'ru_RU.CP1251');
        //$c = strtoupper(  $_REQUEST['m'] );
        //$c = Model::factory("word")->convert_to_in( $_REQUEST['m'] );
        //$sSig = md5( mb_strtolower( $c ).$sKeySig );
        
        $keyClient = $_REQUEST['k'];
           
        $sPiceMd5 = substr($sSig,0,15); 
        if(0 != strcmp( $sPiceMd5, $keyClient )){
//!!!//            die("Invalid COD private key from string"); 
        }
    } 
    //------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------
   
    $aComp = explode("|||", $data);
    $aCommand = array();
    $aCommand['m'] = array();
    
    for( $Index = 0; $Index < count( $aComp); $Index++ )
    {
        $Command = explode("||", $aComp[$Index]);  
        if( $Command[0] != "m")
        {
            $aCommand[ $Command[0] ] = $Command[1];
        }
        else
        {
            if( ! array_key_exists( $Command[1], $aCommand['m']) )
                $aCommand['m'][ $Command[1]] = array();
            $aCommand['m'][ $Command[1]][ $Command[2]] = $Command[3];
        } 
    }
 
/* Парсим входящие данные */
try 
{       
    $uid_1 = 0;
    $u = $aCommand ['uid'];
    $a = $aCommand ['auth_key'];
    if (! isset ( $aCommand ['uid'] ) ){
        errors::exc ( errors::errorIncorrectInput, 'Wrong auth' );
    }
    $s_key = "";    
    $socialId = SOCIAL_ID;
    $uid_1 = $aCommand ['uid'];  
    if (! isset ( SConfig::$social [$socialId] ) || ! $aCommand ['uid'])
    {
        $uid_1 = $aCommand ['uid'];
        errors::exc ( errors::errorIncorrectInput, 'Cant find social network' );
    }    
    $ip = new inputParser ( $aCommand );
                            
    $user = Model::factory ( 'user', $uid_1 );
    while ( $cmd = $ip->getCmd () ) 
    { 
        if (is_array ( $cmd )) 
        {
            $ca = $cmd [0];
            
            $args = JsonCoder::jsonDecode( $cmd [1], true );
            //$args = json_decode ( $cmd [1], true );

            $ca2 = explode ( ".", $ca );
            
            if (count ( $ca2 ) == 2) {
                $controller = $ca2 [0] . "Controller";
                $action = $ca2 [1] . "Action";
            } 
            else if (count ( $ca2 ) == 1){
                $controller = "indexController";
                $action = $ca2 [0] . "Action";
            } 
            else {
                $response [] = array ($ca, '', errors::errorIncorrectCommand );
                continue;
            }

            if (class_exists ( $controller )){ 
                //Если контроллер существует
                $ctrl = new $controller ( $user );
                if (method_exists ( $ctrl, $action )){
                // Если действие существует
                    try {
                        $id = $uid_1;
                        if (
                            //strtolower ( $ca ) != 'user.saveprofile' &&
                            strtolower ( $ca ) != 'user.new_user'        &&                        
                            strtolower ( $ca ) != 'description.get_data' && 
                            strtolower ( $ca ) != 'user.init'            &&
                            strtolower ( $ca ) != 'general.get_data'            
                            ) //initial commands - always miss them   
                        {
                            $answer = $ctrl->user->checkExist ();    //if return "-1" => user is not created
                            if($answer == -1){
       
                            }
                            if(Sconfig::$session_key_flag == TRUE){
                                $ctrl->user->checkSessionKey( $aCommand ['s_key'] );
                                $s_key = $aCommand ['s_key'];
                            }
                        }
                        else
                        {
                        }

                        $response [] = array ($ca, $ctrl->$action ( $args ) );
                        $id_user  = $uid_1;
                        $stringCA = strtolower ( $ca );
                        $id = $uid_1;
                        if(strtolower ( $ca ) == 'user.new_user'  ||  strtolower ( $ca ) == 'user.init'){
                              if(Sconfig::$session_key_flag == TRUE){
                                  $s_key =  $response[0][1]['s_key'];
                              }
                        }
                        else if(strtolower ( $ca ) == 'general.get_data' ){
                        }                                                                                                       
                        else{
                        }
                    } 
                    
                    catch ( Exception $e ){ 
                        //Обертка эксепшеном контроллера для того чтобы очередь команд не прерывалась
                        $response [] = array ($ca, $e->getMessage (), $e->getCode () );
                    }
                } 
                else{
                // Если действие не существует
                    $response [] = array ($ca, '', errors::errorNoAction );
                }
            } 
            else 
            {
            //Если контроллер не существует
                $response [] = array ($ca, '', errors::errorNoController );
            }
        } 
        else 
        {
            $response [] = array ('', $cmd, errors::errorUnknown );
        }
    }
} 
catch ( Exception $e ){ 
    //Эксепшен для всего остального(работа с соц.апи, очередью команд)
    
   // errors::$errorQueue [] = array ('', $e->getMessage (), $e->getCode () );
    errors::$errorQueue [] = array ('', $e->getMessage (), $e->getCode () );
}

if (notifications::exist ()){
    $response = array_merge ( $response, notifications::getList () );
}

if (count ( errors::$errorQueue ) > 0){
    $response = array_merge ( $response, errors::$errorQueue );
}
       
$viewClass = SConfig::$defaultView . "View";
$view = new $viewClass ();
$view->display ( $response );

?>


