Вы находитесь на странице: 1из 135

230201.

65

web-
1-:
101

..

, ...
..

, ...
..

2013


230201.65
-101 :

web-

1-

:
139 ., 9 ., 4 ., 13 , 5 .
WEB-, , 1C-, ,
, , AJAX, API, .
web-
1 : .
web- 1
: .

web-, web-,
.

web-.

Subversion.
web-

web- .
web-,

Internet. Web-

1.

10

1.1.

10

1.2. PHP

10

1.3. Web- Apache

11

1.4. MySQL

12

1.5. JavaScript

12

1.6. AJAX

13

1.7. CSS

14

1.8. web-

14

2. 1 :

16

2.1.

16

2.2.

16

2.3.

18

2.4.

19

3. API 1 :

21

3.1.

21

3.2. API

21

3.3. API

23

4. web-

26

4.1.

26

4.2.

26

5.

29

5.1.

29

5.2. ER web-

29

5.3.

31

6.

34

6.1. web-

34

6.2. web-,

36

6.3.

39

6.3.1.

39

6.3.2.

40

6.3.3.

42

6.3.4. 100

43

6.3.5.

44

6.3.6.

45

6.3.7.

46

6.3.8.

47

6.3.9.

48

6.3.10.

48

6.3.11.

49

6.3.12.

50

6.4. web-

51

6.5. web-.

51

6.5.1.

51

6.5.2. AJAX

52

6.5.3. .

55

7. web-.

59

7.1.

59

7.2.

59

7.3.

62

7.3.1. Subversion

62

7.3.2. Subversion web-

64

8.

69

8.1.

69

8.2.

69

8.3.

71

76

77

A. 1 :

78

.1.

78

.2.

78

.2.1.

79

.2.2.

79

.2.3.

80

.3.

81

.3.1.

81
4

.3.2.

81

.3.3.

85

.3.4.

87

.3.4.1. web-

87

.3.4.2.

87

.3.4.3. web-

88

.3.4.4. web-

88

. web- -

90

95

.1. games.calendar

95

.2. games.raiting

99

.3. games.filter

102

.4. games.search

113

.5. games.detail

117

.6. search_autocomplete

121

.7. reviews.list

126

. script.js ( JavaScript web-)


129
. init.php

133



AJAX Asynchronous Javascript and XML ( JavaScript XML)
API Application Programming Interface ( )
CMS Content management system ( )
CSS Cascading Style Sheets ( )
HTML HyperText Markup Language ( )
JS JavaScript
XML eXtensible Markup Language ( )

.
Web- - ,
web-, ,
web-. web-
, ,
.
Web - , HTTP- , , HTTP-, HTML-,
, , - .
CMS (Content management system) ,
,
.
API (Application Programming Interface) , ,
, (, )

API

, (, ),
API ,
.
1C-: ,

, .

, web-
, ,
, . web-
, ..
.
7

( ) ,

.
,
()
.
,
.


web . web
.
web-
. web-
web-
. ,
web- web-, web- .
web web-.
web-
.
web-
.
web-
web-
.
,
web-

. web-
web-,
PHP, JavaScript, AJAX.
.

1.

1.1.
web-
. ,
,
.
web-
:
web-: PHP;
web-
HTTP: web- Apache;
: MySQL;
web-: AJAX;
: JavaScript
jQuery;
web-: CSS.
1.2. PHP
PHP (PHP: Hypertext Preprocessor PHP: )
, web-
. PHP
, web-.
PHP - ,
.
.
PHP
.

10

, , .
PHP .
web- PHP
, ,
web-,
web-
web- .
1.3. Web- Apache
Apache web-, Unix . Apache
. Apache
web- (httpd.conf),
(.htaccess).
web-
web-.
Web- Apache
URL

mod_rewrite. URL,

web-,
(RewriteRule).
URL (Regular expressions).
, web-,
URL, web- web-, ,
.
web- , web , Web- Apache
web-
web-

HTTP,

web-

, web, URL, web-.


11

1.4. MySQL
MySQL
SQL. MySQL
, . MySQL
. MyISAM InnoDB.
InnoDB .
MySQL API PHP ( ),
ODBC ODBC- MyODBC.
web- , web , MySQL
, web.
1.5. JavaScript
JavaScript

. JavaScript

web-,

web-.

Web-

JavaScript,
web-. ,
JavaScript
. JavaScript
web- .

JavaScript , ,
web- - .
, -
, .

jQuery [7]. JavaScript
, .

12

web- JavaScript jQuery


web-
AJAX.
1.6. AJAX
AJAX (Asynchronous Javascript and XML - JavaScript XML)
,
web-. , ,
web- [8].
AJAX -
(, )
web-, web. , ,
web- , ,
, . ,
, ,
web-.
AJAX :
JavaScript.
web- ;
XML (eXtensible Markup Language ) -
,
;
web- AJAX
web- web-
,
web- web .

13

1.7. CSS
CSS (Cascading Style Sheets - ) -
, .
CSS ( HTML
) ( CSS).
,
,
[6].
web- CSS
web-
web-
web-.
1.8. web-

Web -

HTTP- web-
Web- Apache

CSS

JS

web-

PHP

..

MySQL

web -

(.. , JS JavaScript)
1 web-
1 web-
web-.

14

web-, web-
HTTP web-, web Apache. Web- ,
web- AJAX. Web-
Apache , web-
web- ,
web-, web-,
PHP. PHP
, web- ,
API MySQL,
, web-
Apache web-.
web- JavaScript
CSS.
web- , JavaScript
, ,
web-
AJAX.

15

2. 1 :
2.1.
1C :
web- .
1 : API
web- CMS web-
.
,
,
.
1-: 28 .
, , ,
,

.
2.2.
. 1 :
.
1 :
CMS, web-.
, 1 :
40 000.
:
. Web-,
(

, API ),
.

16

(SiteUpdate),
.
.
.
web-.
.
, API . API
,
web-
.
.
web-
,
API .
web-, .
web-
. (
) ,
.

.
API .

, .. ,
,
.
, web-
API ,

.
17

2.3.
web-
. ,
,


, ,
, , API. ,
, .
, web-
.
API,
.
web-.
, ,
API , ,
, web-.

web-

web-, API
.
, ,
.
,
. , ,
,
,
.

18

2.4.
1 :
,
. 1 :
UMI.CMS.
web- (CMS) API web. UMI.CMS
.
UMI.CMS , 1
: , , ,
, ..
. , UMI.CMS
1 : ,

. UMI.CMS
.

, ,
1 - , UMI.CMS
. UMI.CMS 1 :
API . ,
, UMI.CMS
web- API
1 - , , -
. UMI.CMS
, 1
: .
,
, .
1 : ,
19

web-
,
web-.
UMI.CMS ,
web- , 1 :
.
, 1 :
web-.
1 :
A.

20

3. API 1 :
3.1.
(API) ,

web-

. ,
. web :
API ;
API ;
3.2. API
API
web-.
,
web-
web-.
,
web-.
CMain.
CMain web-.

$APPLICATION.
void ShowTitle(string property_code=title, bool strip_tags = true)

.
void SetTitle(string title)

.
void ShowCSS(bool external = true, bool XhtmlStyle = true)

CSS .
void ShowMeta(string property_id = , string meta_name = false, bool
XhtmlStyle = true)
21

id = property_id - (<meta>).
void

ShowProperty(string

property_id

mixed

default_value

false)

id=property_id, .
string GetCurPageParam(string add_params = , array remove_params =
array(), bool get_index_page = false)

web-,
() .
mixed IncludeComponent(string componentName, string componentTemplate,
array

arParams=array(),

object

parentComponent=null,

array

arFunctionParams=array())

. .
.
int AddToTimeStamp(array add, int timestamp = false)

Unix- .
Unix-.
CFile.
CFile web-.
array GetFileArray(int file_id)

, ( , ,
) file_id.
CDBResult.
CDBResult .
array GetNext(bool text_html=true, bool text_original = true)

, HTML- .
, false.
void

NavStart(int

page_size=10,

bool

show_all=true,

int

page_number=false)

.
void

NavPrint(string

title,

bool

show_always=false,

text_css_class="text", string template_path=false)

.
22

string

CModule.
CModule .
bool IncludeModule(string module_id)

module_id ,
. "true", , - "false".
CBitrixComponent.
CBitrixComponent web-.
bool StartResultCache(int cacheTime, string additionalCacheID, string
cachePath)

. ,
. ,
true, .
void AbortResultCache()

.
bool ClearResultCache(string additionalCacheID, string cachePath)

.
true.
void IncludeComponentTemplate(string templatePage)

.
3.3. API

web-.
API
, .
,
web-.
IBlock.
CIBlock .
DBResult GetList(array arOrder = array("SORT"=>"ASC), array arFilter)

23

arFilter,

arOrder.
CDBResult GetByID(int ID)

ID.
CIBlockElement.
CIBlockElement .
.
CIBlockResult

GetList(array

arOrder

array("SORT"=>"ASC"),

array

arFilter = array(), mixed arGroupBy = false, mixed arNavStartParams =


false, array arSelectFields = array())

arFilter,
arOrder. ,
arGroupBy, ,
arNavStartParams. ,
arSelectFields.
bool SetPropertyValueCode(int ELEMENT_ID, string PROPERTY_CODE, string
PROPERTY_VALUE)

, PROPERTY_CODE, ID,
ELEMENT_ID, PROPERTY_VALUE.
CIBlockSection.
CIBlockSection .
CIBlockResult

GetList(array

arOrder

array("SORT"=>"ASC"),

array

arFilter = array(), bool bIncCnt = false)

,
arOrder , arFilter.
CIBlockResult GetNavChain(int IBLOCK_ID, int SECTION_ID)

SECTION_ID.
CIBlockResult.
CIBlockResult -
, CDBResult .
void SetUrlTemplates(string DetailUrl = "", string SectionUrl = "",
string ListUrl = "")
24

,
, .
_CIBElement GetNextElement()

_CIBElement,

( ),
false.
_CIBElement.
_CIBElement - ,
CIBlockResult::GetNextElement.
array GetFields()

.
array GetProperties(arOrder = array(), arFilter = array())

25

4. web
4.1.
1 : web ,
web-.
, (
) web-,
,
web-,
.

, ,
.

web-

-,
..

web-,


. web web .
web-
web-,
,
web-. -
.
4.2.

web-:
26

web- ;
,
, ;
web-
,
;
;
web- ;
web- ;
web-
;
;
web-
;
web- 100
;
web- ;
web-
;
web-
, .. ,
;
, ;
web- ;
web- ;

;
27

web- ;
web-
;
web-
;
web- ;
web- .

2 web-
2 web-
. ,
.
,
, .

28

5.
5.1.
,
,
, - .
5.2. ER web-
, :




.
:

.
.
:

29

.
.
:

.
.
:

.
, :

30

3 -
5.3.

ER-,

, .

, , ,
.
, ,
1 : ,
,
,
, -
.
31

,
. ,
, .
.
,
- .
,
. , ,

,
.
,
, .
, .

.
, -
. ,
.
,
( ).

.
,
.
,
. ,
.

.
32

33

6.
6.1. web-
web-,
,
web-.
web-,
, web-
.

web-,
.
Web- .
,
, ,
.
Web-
.
.
,
,
.
Web-
.
. ,
.
Web-

,
.
34

,
,
, .
Web- 100
.
100 .
Web-


. web ,
-
, web , ..
, .
Web-
.
.
Web-
.
.
Web- .

.
, ,
:

35

5 web-
.
web-.
, 5, .
, .. web. ,
web-.
6.2. web-,
web-

web-.
,
web-
web-,
index.php, . ,
36

web-,

URL

http://www.metagames.ru/index/new/ index.php.
,
web-, :

6 web-
,
6, :
1 web








100

index.php
pc, xbox_360, index ()
/ new
/ new / all
/ new / upcoming
/ upcoming / all
/ top
/ top / all
/ top_100
37

Search
Detail
Developer
/ year_top

, :
_
index.php
pc
new
index.php
all
index.php
upcoming
index.php
all
index.php
top
index.php
all
index.php
top_100
index.php
year_top
index.php
--- _ --search
index.php
detail
index.php
developer
index.php
38

6.3.
, web- ,
. 1
:
.

. ,
() ,
, .
6.3.1.

games.main
1, 2

:
.
, ,
. ,
.

.
:

.
IBLOCK_TYPE

IBLOCK_ID

IBLOCK_SECTION_CODE
COUNT

FILTER

DETAIL_URL

SORT_BY1
SORT_ORDER1
SORT_BY2
SORT_ORDER2

39


ID
()


.default

6.3.2.

games.calendar
6, 7, 8

DATES_DATE_REL_RUS
. , ,

. ,
, ..
DATES_DATE_REL_RUS,
.
, ,
,
.
:

IBLOCK_TYPE
IBLOCK_ID
IBLOCK_SECTION_CODE
COUNT
FILTER
DETAIL_URL
DATE_BORDER
CURRENT_MONTH_DEFAULT
SORT_BY1
SORT_ORDER1

ID

()

40

SORT_BY2

main_page

.

web-
,

Short

.default



6.3.3.

games.raiting
9

:
,
MAIN_METAMARK
( ). ,
, .
, ,
.
:

IBLOCK_TYPE

IBLOCK_ID

ID
IBLOCK_SECTION_CODE

()
COUNT


FILTER


DETAIL_URL


SORT_BY1

41

SORT_ORDER1
SORT_BY2
SORT_ORDER2

Short

,


,

main_page


.default

6.3.4. 100

games.top100
10

:
100 ,
MAIN_METAMARK .
, ,
.
:

.
IBLOCK_TYPE

IBLOCK_ID

IBLOCK_SECTION_CODE


ID
()

42

.default

,
100

6.3.5.

games.filter
3, 4, 5, 8

:
, ,

. : , ,
.
. , .
, ,
.
, .
,
, .
,
AJAX; ,
.
:

IBLOCK_TYPE

ID

(: <_>

IBLOCK_ID
FILTER_VARIABLE_NAME
PERIOD_LIST

[_])
43

MARKS_LIST

(: <_>
[__
]

[_])

USE_ALPHA
OUT_PLATFORM
SHOW_METAMARK_FILTE

R
SHOW_DATE_FILTER

DETAIL_DATE_MAX
DETAIL_DATE_MIN
MAIN_GENRE

month_switcher

,


,

main_page

.default
6.3.6.

games.search
11, 12

:

, , , .
:
44


.
IBLOCK_TYPE

IBLOCK_ID

IBLOCK_SECTION_CODE
COUNT

DETAIL_URL

SORT_BY1
SORT_ORDER1
SORT_BY2
SORT_ORDER2


ID
()

.default

6.3.7.

search.autocomplete
13

:
,
search.form.
, ( NAME)
MAIN_ENG_NAME.
:

search_page

.default

6.3.8.

reviews.list
16, 17

:
45


. (
ID=35),
. MARK
ID=35 .
:

IBLOCK_TYPE
IBLOCK_ID
GAME_ID
TRUNCATE_LEN
ENG_REVIEWS




ID

ID

DETAIL_TEXT

.default

6.3.9.

games.detail
15, 18

:
, ..
- .
.
:

.
IBLOCK_TYPE

IBLOCK_ID

IBLOCK_SECTION_CODE
ELEMENT_CODE


ID
()

.default


46

6.3.10.

search.form
5

:
.

.
:

IBLOCK_TYPE
IBLOCK_ID
SEARCH_PAGE


ID

search_page

.default

6.3.11.

developer.detail
21

:
, ..

- .
:

IBLOCK_TYPE
IBLOCK_ID
DEVELOPER_NAME


ID

47

.default

6.3.12.

games.year_top
22

:
,
MAIN_METAMARK ,
DATES_DATE_REL_RUS,
.
.
, ,

.
:

.
IBLOCK_TYPE

IBLOCK_ID

IBLOCK_SECTION_CODE
DETAIL_URL


ID
()

search_page

.default

48

6.4. web-

7 web-

web-.

, ..

.
.

component.php,

result_modifier.php,

script.js

.
6.5. web-.
6.5.1.
,
API ,
3.
49

AJAX web-
.
6.5.2. AJAX
web- JavaScript.

AJAX

web AJAX - . AJAX


JavaScript, ,
, . ,
,

www.metagames.ru/index/top/index.php,

web-

web-,
- ,
.
web-.
,
JavaScript.
.
.
,
, , ,
, ,
#, ..
www.metagames.ru/index/top/index.php
,

www.metagames.ru/index/top/index.php#filter:up
.

50

, web-
.
JavaScript
, .
window. window 2
: window
JavaScript . window
location,

, .
window.location += #some_text;
,
JavaScript, , ,

web-.


.
location, .
,
, .

, , games.filter, ..

AJAX- .

web-

. JavaScript ,
, web-:
function ajax_state_string(url, exclude_array){}
web, ,
AJAX. ,
51

, web . exclude_array ,
,
, url, .
, 0
web-
AJAX; , 1, ,
.
Array([0]

=>

__AJAX,

[1]

=>

__)

, AJAX, ,
.
:
//
var paths = ajax_state_string(http://www.metagames.ru/index.php?
filter=up&datei=10, new Array());
/*
ajax- AJAX
paths[0]
*/
//
window.location += #+paths[1];


:
function restore_hash_part(path, result_block, ar_next,
ajax_status_id, filterupped){}

:
path , ;
result_block ID ,
;

52

ar_next , ( - 0)
, ( 1) ,
, (
, ajax-);
ajax_status_id ID
;
filterupped . true,
;
.
:
//
window.onLoad = function()
{
restore_hash_part(window.location, result_block_id, new
Array(filter, up), ajax_status_id, false));

}

web-
web- AJAX-.

web-, ,
AJAX-,
. .
6.5.3. .
web-
,
.
, .
, ,

53

web-. ,
40 , .
200 ,
.

, , .., ,

MAIN_METAMARK

,
,
GAME_ID .

. , ,
.

.

:
.
, .
OnAfterIblockElementAdd;
.
OnAfterIblockElementUpdate;
.
OnBeforeIblockElementDelete;
,
.
, ;
, ;

54


, ;
(
GAME_ID);

MAIN_METAMARK .
,
API :
void AddEventHandler(string from_module_id, string event_id, mixed
callback, int sort = 100, mixed full_path = false)

from_module_id , ;
event_id ;
callback ;
sort (), ;
full_path
callback;
,
:
AddEventHandler("iblock", "OnAfterIblockElementAdd",
"add_review_handler");
AddEventHandler("iblock", "OnAfterIblockElementUpdate",
"add_review_handler");
AddEventHandler("iblock", "OnBeforeIblockElementDelete",
"delete_review_handler");

, , :
void delete_review_handler(int ID)


ID.
void add_review_handler(array &arFields)

55

.
$arFields .
.
,

web- .
.

56

7. web-.

7.1.
web- , ,

. ( ,
) web-
web- , ..
web-.
, ,
, web-
. ,
, PHP, JavaScript,
web-.

, web-,
web-.
web-,
.
7.2.
, ,
, . mysqldump [5],
MySQL.
, web-.
GNU/Linux, ..
Bourne Shell [3].
Bourne Shell,

57


web-.
DUMP_FILE_NAME=`date +%Y%m%d%H%M%S`
mysqldump u[_] p[] -f
[__] > /tmp/$DUMP_FILE_NAME.sql
if [ $? -eq 0 ]
then
gzip -c /tmp/$DUMP_FILE_NAME.sql

>

/home/bitrix/www/bitrix/backup/$DUMP_FILE_NAME.auto.sql.gz
chmod 644 /home/bitrix/www/bitrix/backup/
$DUMP_FILE_NAME.auto.sql.gz
chown bitrix:bitrix /home/bitrix/www/bitrix/backup/
$DUMP_FILE_NAME.auto.sql.gz
fi
rm -f /tmp/$DUMP_FILE_NAME.sql
mysqldump
, .

gzip
1 :
. . ,
mysql_dump.sh,
:
[root@v8733 sh_scripts]# ./mysql_dump.sh

file_dump.sh.
DUMP_FILE_NAME=`date +%Y%m%d%H%M%S`
tar --exclude=bitrix/backup -czf
/home/bitrix/www/bitrix/backup/
$DUMP_FILE_NAME.auto.file.tar.gz /home/bitrix/www
58

web-

if [ $? -eq 0 ]
then
chown bitrix:bitrix /home/bitrix/www/bitrix/backup/
$DUMP_FILE_NAME.auto.file.tar.gz
fi
tar
web-.
,
. ,
:
[root@v8733 sh_scripts]# ./file_dump.sh
,
web-,

..

. ,
cron.
,
web- .
cron.tasks. ,
web- ,
cron.tasks :
01 3 * * * /home/bitrix/sh_scripts/mysql_dump.sh
1>/dev/null 2>/home/bitrix/logs/mysql_dump.log
10 3 * * 2 /home/bitrix/sh_scripts/file_dump.sh
1>/dev/null 2>/home/bitrix/logs/file_dump.log
,
, ,
. , mysql_dump.sh,
, 3:01:00 ,
59

3:10:00
, .. . ,
, ,
, 10 .
.
, (.. )
web- 30 .
.
,
web-. ,
2 , ,
, , 2 ,
10
.
, ,
crontab:
[root@v8733 sh_scripts]# crontab cron.tasks
.


.
web- web-.
7.3.
7.3.1. Subversion

web-.
.

web- .
60


.

.

Subversion.
Subversion, SVN
, ,
web-.
Subversion [4],
web,
, , web.

.
. ,

. Subversion
. 8.

8
Subversion
. ( )
: .
61

, ()
, .
- () . (
web-) (checkout)
.
. Subversion
,
( .svn).

.
(commit) . ,
, (update)
.
.
, .
web-
(revert) .
,
, .
7.3.2. Subversion web-
GNU/Linux, web, Subversion . Subversion,
, :
1. ;
2. web-;
3. ;

.
62

svnadmin

create

<_>. metagames.
, :
[root@v8733 ~]# svnadmin create /home/svn/metagames
/home/svn.
,
,
. svnserve.conf,
/home/svn/metagames:
anon-access=none
auth-access=write
password-db=passwd
realm=metagames
,
, (metagames) ,
(passwd).

Subversion, killall svnserve.
[bitrix@v8733 ~]# killall svnserve;
[bitrix@v8733 ~]# svnserve d r /home/svn
, web- Apache (httpd) web bitrix. ,
web- .
Subversion svnserve
bitrix,
.

:
branches
63

trunk
tags
,

(, init) web-, checkout
svn checkout svn://metagames.ru/metagames/ init
, ,
add
svn add init/branches
.
commit
svn commit init m Start doings.
.
web-.
, web-,
, ,
. checkout,
:
svn

checkout

svn://metagames.ru/metagames/trunk

/home/bitrix/www/index/

add.
svn add home/bitrix/www/index/all/
svn add home/bitrix/www/index/index.php
, commit
svn

commit

home/bitrix/www/index

.
, web, .
64

.
, web- ,

.
Subversion Tortoise SVN. ,
.
update, add, commit .. web web-,
Tortoise SVN checkout
.
web- :
1. , , /home/bitrix/index.php ;
2.
Tortoise SVN commit;
3. svn update web-
, web-
;

web- web web-
.
,
web-,
. ,
web-
FTP HTTP,
,
web-.
web- ,

65

. ,
web- ,
, Web-,
.

66

8.
8.1.
, ,
web-

, -,
, web-
, web-, ..
web-,
, web- ,
web-.
8.2.
,
:
1. web-;
2. ,
;
3.
;

:
;
;
web, ,
Internet
( ..);

67

Siege [12],
.
GNU/Linux,
GNU/Linux Ubuntu 10.4.

.
.
, 1
: .
web, ,
, web-
web-
.
web-,
,
.

9 ,
, , ,
Siege
web-
,
web-.

68

.
, web-,

Siege:
[root@v8733 ~]# siege -c 50 -d 1 -t300S -f /home/dima/access_log.log

-c 50 web-, t300S
, -d 1 ( 0 1 ),
/home/dima/access_log.log ,
. access_log.log
,
web-
. web-,
. ,
, 150 .
, web-,
GET POST.
:
void write_access_log(string filepath)
, filepath ,
.
.

Siege

.
,
web-
.
8.3.

, 100 (=100) , 300 (t=300S).
69

[root@v8733

~]#

siege

-c

100

-d

-t300S

-f

/home/dima/access_log.log

:
2 1; =100, t=300S

/pc/index.php
/index/new/all/index.php
/pc/new/index.php
/detail/index.php
/index/top/index.php
/xbox_360/index.php
/about/index.php
/advertisement/index.php
/contacts/index.php
/pc/upcoming/index.php
/pc/top/index.php
/search/index.php
/index/new/index.php

%
49.43
18.92
9.87
5.99
1.39
1.20
0.80
0.74
0.63
0.57
5.62
2.92
1.94

6.0035
10.6723
3.7513
1.7449
3.0484
2.0960
1.9985
1.8442
1.5661
1.6750
0.4352
0.7424
2.6039

,
, -

.
/index/new/all/index.php. ,
7 ( 6), games.calendar.

, ,
_CIBElement::GetProperties(), ,
web-
( 1 ).
:
.
.
70

,
,
.
,
, 3.
3 2. =100, t=300S

/pc/index.php
/index/new/all/index.php
/pc/new/index.php
/detail/index.php
/index/top/index.php
/xbox_360/index.php
/about/index.php
/advertisement/index.php
/contacts/index.php
/pc/upcoming/index.php
/pc/top/index.php
/search/index.php
/index/new/index.php

%
29.72
22.06
4.13
5.37
2.11
1.51
0.48
0.72
0.48
1.03
3.31
9.08
3.43

0.9559
0.6110
0.7122
0.4817
0.4624
0.6463
0.2360
0.5875
0.4291
0.9263
1.0613
1.9390
0.4970

2, 2,
web .
/search/index.php /pc/top/index.php .
, games.search games.raiting
.
.
, , ,

300 600 (10 ),
web- .
71

[root@v8733

~]#

siege

-c

300

-d

t600S

-f

/home/dima/access_log.log
:
4 3. =300, t=600S

/pc/index.php
33.79
0.4454
4 3. =300, t=600S.
/index/new/all/index.php
23.66
0.2403
/pc/new/index.php
5.00
0.3264
/detail/index.php
4.28
0.1797
/index/top/index.php
2.49
0.2138
/xbox_360/index.php
1.74
0.3262
/about/index.php
0.26
0.1330
/advertisement/index.php
0.61
0.1560
/contacts/index.php
0.45
0.1843
/pc/upcoming/index.php
0.48
0.2465
/pc/top/index.php
2.82
0.3863
/search/index.php
5.28
0.3390
/index/new/index.php
3.78
0.2219
c=300 t=600S,
web-
,

. 300

(
1-2 ), ,
web-
.

72


web-
1 : .

web-,
web-, .

web-.

Subversion. web-

web-
.
web-,

73

Internet. Web-


1. .., .. PHP 5. .: ,
2004. 560 .
2.

..,

..

PHP. .: , 2007. 608 .


3.

.., .., ..
UNIX. 2- ., . . .: -, 2007. 656 .

4.

Ben Collins-Sussman, Brian W. Firzpatrick, C. Michael Pilato. Version Control


with Subversion.: OReilly Media, Inc. 1005 Gravenstein Highway North,
Sebastopol, 2004. 277 p.

5.

. MySQL. .:
, 2006. 528 .

6.

., ., . CSS:
Web . . : .. , 2007. 272 .

7.

., . jQuery. JavaScript.
.: -, 2009. 384 .

8.

., ., - ., . AJAX PHP:
-. .: -, 2007. 336 .

9.

., ., .. PHP 5 MySQL. . . :
, 2009. 1216 .

10. 1 : . . URL:
http://dev.1c-bitrix.ru/api_help/ ( : 30.03.2010 01.06.2010).
11. . URL: http://ru.wikipedia.org/wiki/
( : 30.03.2010 01.06.2010)
12. Joe Dog Software Siege Home. URL: http://joedog.org/index/siege-home (
: 10.05.2010)
13. World Wide Web Consortium (W3C). URL: http://www.w3.org/ ( :
05.04.2010).

74

A. 1 :

.1.
,
, web. PHP,
, .
.
, ,
main, , ,
modules.
1 : .
,
.

.
web-. ,
, ()
, ,
.
.
web-,
, .
Internet, .
web- (, ),
Internet.
.2.
, 1 :
, ..
75

,
. ,
,
. :
;
;
;
.2.1.

web-. :
URL web- web;
web-;
;
API ;
web-;
web-;
web-.
web API
. ,
, 3.4.1.

dbconn.php, ,
,
.
.2.2.
:
76

web- (,
, );
, ..
;
web;

web-.
.2.3.
- ,
() .
- ,
web-.
,
.
:
, (
, );
(, ,
);
;
API .
:
.

( ) .
.

77

,
.
.

.

web-.
.3.
.3.1.
,
web-. ,

web-.
,
PHP. , ,

.
()
web-. .., , ,

. ,
, .
.
, .
.3.2.
1 :
,
. web-
bitrix/components.
78

:
<__>
<_>
lang
templates
<__>
lang
images
template.php
style.css
script.js
.parameters.php
result_modifier.php
component.php
.description.php
.parameters.php
<__> - ,
,
, web-. ,
web-
file_structure.
lang , ,
, .
, web-
. ,
,
.
lang / ru ( ) -
.php , ,
lang.
79

PHP, $MESS,
, .
<?php $MESS[EMPTY_LIST] = ; ?>
, ,
API GetMessage, :
<?php echo GetMessage(EMPTY_LIST); ?>
component.php ,
,

, ,
, ,
.
.
parameters.php ,
. , ,
, .., component.php.
, .parameters.php
$arComponentParameters, :
$arComponentParameters = array(
GROUPS => array(
__N => array(
NAME => _
),
),
PARAMETERS => array(
__N => array(
NAME => _,
TYPE => _,
PARENT => _,
)
));
80

description.php , ,
( ),
2.0
.
a $arComponentDescription:
$arComponentDescription = array(
NAME => _,
DESCRIPTION => _,
PATH => array(
ID => ___,
NAME => __
)
);
templates , , ..
, web-,
web- .
templates / .default ( ) .
.
templates / .default / template.php , ,
.
$arTemplateParameters,
$arComponentParameters.
$arTemplateParameters = array(
__N => array(
NAME => _,
TYPE => _,
)
);

81

templates / .default / style.css , CSS,


web-
.
templates / .default / script.js ,
JavaScript, web- .
templates / .default / template.php , ,
HTML ,
web- , web-.
templates / .default / lang lang, .
templates / .default / images ,
, .
templates / .default / result_modifirer.php ,

.3.3.
web-.
3.4.4., , web .

$arParams,
id

component.php
1

result_modifier.ph
p
template.php

result_modifier.ph
p

template.php

$arParams,
$arResult

result_modifier.ph
p

template.php

.1
82

.1
web-.
web-
, $arParams
component.php.

component.php

IncludeComponentTemplate CBitrixComponent
. id web .
, template.php ,
component.php
$arParams , , component.php $arResult.
result_modifier.php,
template.php.

component.php, ..
. , $arResult ,
component.php .
.3.4.
.3.4.1. web-
web-
, web-
, ,
web-.
,
. , ..
web-.
1. /bitrix/php_interface/dbconn.php
2. . $DB CDatabase
3. /bitrix/php_interface/after_connect.php
83

4. . $APPLICATION CMain
SITE_ID, SITE_DIR, SITE_SERVER_NAME,
SITE_CHARSET, FORMAT_DATE, FORMAT_DATETIME, LANGUAGE_ID.
.
5. /bitrix/php_interface/init.php
6. . $_SESSION.
7. , . CUser $USER.
8.
9.
10. /bitrix/templates/ID /header.php
11.
12. /bitrix/templates/ID /footer.php
13.
14. . $DB .
.3.4.2.
web-
API , web .
, , :
CModule::IncludeModule(_)
, ,
API .
.3.4.3. web-
web- web. ,
,
:

84

<?php
require_once($_SERVER[DOCUMENT_ROOT]./bitrix/header.php)
?>
-------------------

..--------------------<?php
require_once($_SERVER[DOCUMENT_ROOT]./bitrix/footer.php)
?>
.3.4.4. web-
, , API
, CMain,
$APPLICATION:
$APPLICATION -> InculdeComponent(
__:_,
id__,
Array(
__1 => __1,
__N => __N
) //
);
,
: .
,
.
,
,
.

85

. web-
-
metagames.ru

1.

2.

3.
4.
5.

12

,





:
:
1.
2. ( )
3. ( )
4.
5.
6.
7.
8.
9.
10.
11. ozon.ru
12. ( ,
)
,
:
13.
:
14. ( div
)
15.
16.
86

17.
, :
( )
, .
:
1.
2.
3.
4.


10
12 . 1 .
. ,
.
,
.

87



. ,
( ,
).


,
- (
).
,
. :
1. -
2. ( )
3.
4.
5.
6.

88


.
,

. 15
12 .
:
1. ( )
2.
3.
4.
5.

:
1.
2.
3.
4.
5.
6.
7.
8.

.
, ,
:
1. ( )
2. ( )
3. ( )
,
( ).


xhtml 1.0 strict
validator.w3.org.
,
:
1. Internet explorer 7.0+
2. Mozilla firefox 3.0+
89

3. Opera 9.0+
4. Google Chrome
5. Safari (!! )
UTF-8


1-
, , (1-)
. :
1. ,

2. .
(init.php)
3. ( ,
)
2.0
. ,
, ,
.

( ). ,
, .

90

.
.1. games.calendar
component.php
<?php
//
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
try
{
//
global $arMonthNames;
// $arParams
prepare_params($arParams);
//
if(strlen($arParams["IBLOCK_TYPE"]) <= 0){
$arParams["IBLOCK_TYPE"] = IB_TYPE_GAMES;
}
$arParams["COUNT"] = intval($arParams["COUNT"]);
if($arParams["COUNT"] <= 0){
$arParams["COUNT"] = 10;
}
if(strlen($arParams["SORT_BY1"]) <= 0){
$arParams["SORT_BY1"] = "PROPERTY_MAIN_METAMARK";
}
if($arParams["SORT_ORDER1"] != "DESC"){
$arParams["SORT_ORDER1"] = "ASC";
}
if(strlen($arParams["SORT_BY2"]) <= 0){
$arParams["SORT_BY2"] = "NAME";
}
if($arParams["SORT_ORDER2"] != "DESC"){
$arParams["SORT_ORDER2"] = "ASC";
}
$arParams["MIN_METAMARK_YELLOW"] = intval($arParams["MIN_METAMARK_YELLOW"]);
$arParams["MIN_METAMARK_GREEN"] = intval($arParams["MIN_METAMARK_GREEN"]);
if($arParams["MIN_METAMARK_YELLOW"] <= 0){
$arParams["MIN_METAMARK_YELLOW"] = 50;
}
if($arParams["MIN_METAMARK_GREEN"] <= 0){
$arParams["MIN_METAMARK_GREEN"] = 75;
}
//
$arSortOrder = array(
$arParams["SORT_BY1"] => $arParams["SORT_ORDER1"],
$arParams["SORT_BY2"] => $arParams["SORT_ORDER2"],
"ID" => "DESC"
);
//
$arFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"ACTIVE" => "Y",
"SECTION_ACTIVE" => "Y"
);
// (),
if(!empty($arParams["IBLOCK_SECTION_CODE"])){
$arFilter["SECTION_CODE"] = $arParams["IBLOCK_SECTION_CODE"];
}
$current_year = intval(date("Y"));
$current_month = intval(date("m"));
$current_day = intval(date("d"));
$top_day = get_max_day($current_month, $current_year);
// ,
if(isset($arParams["FILTER"]) && is_array($arParams["FILTER"]) &&
count($arParams["FILTER"]) > 0){
$arFilter = array_merge($arFilter, $arParams["FILTER"]);
if(isset($arFilter[">=PROPERTY_DATES_DATE_REL_RUS"])){

91

$selected_month = intval(date("m",
strtotime($arFilter[">=PROPERTY_DATES_DATE_REL_RUS"])));
$selected_year = intval(date("Y",
strtotime($arFilter[">=PROPERTY_DATES_DATE_REL_RUS"])));
if($arParams["DATE_BORDER"] == "bottom"){
if($selected_year < $current_year){
$arFilter[">=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
elseif($selected_year == $current_year){
if($selected_month <= $current_month){
$arFilter[">=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
}
}
}
else{
$selected_month = date("m");
if($arParams["DATE_BORDER"] == "bottom" && $selected_month == $current_month){
$arFilter[">=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
}
if(isset($arFilter["<=PROPERTY_DATES_DATE_REL_RUS"])){
$selected_month = intval(date("m",
strtotime($arFilter["<=PROPERTY_DATES_DATE_REL_RUS"])));
$selected_year = intval(date("Y",
strtotime($arFilter["<=PROPERTY_DATES_DATE_REL_RUS"])));
if($arParams["DATE_BORDER"] == "top"){
if($selected_year > $current_year){
$arFilter["<=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
elseif($selected_year == $current_year){
if($selected_month >= $current_month){
$arFilter["<=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
}
}
}
else{
$selected_month = date("m");
if($arParams["DATE_BORDER"] == "top" && $selected_month == $current_month){
$arFilter["<=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
}
}
else{
//
if($arParams["DATE_BORDER"] == "top"){
$arFilter["<=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
elseif($arParams["DATE_BORDER"] == "bottom"){
$arFilter[">=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
//
if($arParams["CURRENT_MONTH_DEFAULT"] == "Y"){
if($arParams["DATE_BORDER"] != "bottom"){
$arFilter[">=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d", strtotime("01.".
$current_month.".".$current_year));
}
else{
$arFilter[">=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
if($arParams["DATE_BORDER"] != "top"){
$arFilter["<=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d",
strtotime($top_day.".".$current_month.".".$current_year));
}
else{
$arFilter["<=PROPERTY_DATES_DATE_REL_RUS"] = date("Y-m-d");
}
}
}
// , ID

92

//
$cache_id_arr = array(CDBResult::NavStringForCache($arParams["COUNT"]));
//
foreach($arFilter as $filt){
$cache_id_arr[] = trim(str_replace(array(";", ":", " ","-"), "", $filt));
}
$cache_id = implode("", $cache_id_arr);
//
if($this->StartResultCache(false, $cache_id)){
// ,
$arResult = array(
"ITEMS" => array(),
//
"NO_ITEMS" => false, //
"PAGENAV" => "",
//
"IS_ERROR" => false
// -
);
//,
if(!CModule::IncludeModule("iblock")){
$arResult["IS_ERROR"] = true;
throw new Exception(GetMessage("C_MODULE_ERROR"));
}
$arSelect = array(
"NAME", "ID", "DETAIL_PAGE_URL", "PREVIEW_PICTURE",
"PROPERTY_DATES_DATE_REL_RUS", "PROPERTY_MAIN_METAMARK",
"PROPERTY_GENRE_GENRE", "IBLOCK_SECTION_ID", "PROPERTY_DATES_DATE_REL"
);
$db_element = CIBlockElement::GetList($arSortOrder, $arFilter, false,
array("nPageSize" => $arParams["COUNT"]), $arSelect);
//
if(!$db_element){
$arResult["IS_ERROR"] = true;
throw new Exception(DB_ERROR_TEXT);
}
//
if($db_element->SelectedRowsCount() <= 0){
$arResult["IS_ERROR"] = true;
$arResult["NO_ITEMS"] = true;
throw new Exception(GetMessage("C_NO_ITEMS"));
}
//
$db_element->NavStart($arParams["COUNT"]);
//
$arResult["PAGENAV"] = $db_element->GetNavPrint("", false, "",
"/bitrix/templates/.default/pagenav_template.php");
// . ,

if(!empty($arParams["DETAIL_URL"])){
$db_element->SetUrlTemplates($arParams["DETAIL_URL"]);
}
// ID ()
$section_ids = array();
// ( )
$section_id_elem = array();
//
while($fetch_element = $db_element->GetNext()){
// ()
$fields["NAME"] = htmlspecialchars($fetch_element["NAME"]);
$fields["DETAIL_PAGE_URL"] = $fetch_element["DETAIL_PAGE_URL"];
$fields["PREVIEW_PICTURE"] = intval($fetch_element["PREVIEW_PICTURE"]);
$fields["IBLOCK_SECTION_ID"] = intval($fetch_element["IBLOCK_SECTION_ID"]);
$fields["ID"] = intval($fetch_element["ID"]);
// -,
if($fields["PREVIEW_PICTURE"] > 0){
$fields["PREVIEW_PICTURE"] = CFile::GetFileArray($fields["PREVIEW_PICTURE"]);
}
else{
$fields["PREVIEW_PICTURE"] = false;
}
//
$props["DATES_DATE_REL_RUS"]["VALUE"] =
trim(htmlspecialchars($fetch_element["PROPERTY_DATES_DATE_REL_RUS_VALUE"]));

93

$props["DATES_DATE_REL"]["VALUE"] =
trim(htmlspecialchars($fetch_element["PROPERTY_DATES_DATE_REL_VALUE"]));
// ,
$props["MAIN_METAMARK"]["VALUE"] =
floatval($fetch_element["PROPERTY_MAIN_METAMARK_VALUE"]);
$props["GENRE_GENRE"]["VALUE"] = $fetch_element["PROPERTY_GENRE_GENRE_VALUE"];
if(empty($props["DATES_DATE_REL_RUS"]["VALUE"])){
$props["DATES_DATE_REL_RUS"]["VALUE"] = $props["DATES_DATE_REL"]["VALUE"];
}
//
if(!empty($props["DATES_DATE_REL_RUS"]["VALUE"])){
$day = intval(date("d", strtotime($props["DATES_DATE_REL_RUS"]["VALUE"])));
$month_name = mb_substr($arMonthNames[intval(date("m",
strtotime($props["DATES_DATE_REL_RUS"]["VALUE"])))]["month_a"], 0, 3, LANG_CHARSET);
$month_name_full = $arMonthNames[intval(date("m",
strtotime($props["DATES_DATE_REL_RUS"]["VALUE"])))]["month_a"];
$year = date("Y", strtotime($props["DATES_DATE_REL_RUS"]["VALUE"]));
$props["DATES_DATE_REL_RUS"]["VALUE"] = $day." ".$month_name." ".$year;
$props["DATES_DATE_REL_RUS"]["VALUE_FULL"] = $day." ".$month_name_full." ".
$year;
}
/*** ,
***/
if($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "green";
}
elseif($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_YELLOW"] &&
$props["MAIN_METAMARK"]["VALUE"] < $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "yellow";
}
elseif($props["MAIN_METAMARK"]["VALUE"] > 0){
$props["STYLE_RAITING"] = "red";
}
else{
$props["STYLE_RAITING"] = "no_mark";
}
/*** ***/
//
$arResult["ITEMS"][$fields["ID"]] = array(
"FIELDS" => $fields,
"PROPS" => $props
);
// ID ,
if(!in_array($fields["IBLOCK_SECTION_ID"], $section_ids)){
$section_ids[] = $fields["IBLOCK_SECTION_ID"];
}
//
$section_id_elem[$fields["IBLOCK_SECTION_ID"]][] = $fields["ID"];
}
//
$arSectionFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ID" => $section_ids,
"ACTIVE" => "Y"
);
// ()
$db_section = CIBlockSection::GetList(array(), $arSectionFilter, false, array("NAME",
"CODE", "PICTURE", "UF_*"));
// , ( )
while($ar_section = $db_section->GetNext()){
foreach($section_id_elem[$ar_section["ID"]] as $elem_to_id){
// ()
$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_NAME"] =
$ar_section["NAME"];
// ()
$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_CODE"] =
$ar_section["CODE"];
//

94

$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_TEXT_COLOR"] =
$ar_section["UF_TEXT_COLOR"];
// (),
if(intval($ar_section["PICTURE"]) > 0){
$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_PICTURE"] =
CFile::GetFileArray(intval($ar_section["PICTURE"]));
}
}
}
//
$this->IncludeComponentTemplate();
}
}
catch(Exception $e)
{
// ,
//
if(!$arResult["NO_ITEMS"]){
$this->ClearResultCache($cache_id);
}
$this->AbortResultCache();
// arResult
$arResult["ERROR"] = $e->getMessage();
//
$this->IncludeComponentTemplate();
}?>

.2. games.raiting
component.php
<?php
//
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
try
{
global $arMonthNames;
// $arParams
prepare_params($arParams);
//
if(strlen($arParams["IBLOCK_TYPE"]) <= 0){
$arParams["IBLOCK_TYPE"] = IB_TYPE_GAMES;
}
$arParams["COUNT"] = intval($arParams["COUNT"]);
if($arParams["COUNT"] <= 0){
$arParams["COUNT"] = 10;
}
if(strlen($arParams["SORT_BY1"]) <= 0){
$arParams["SORT_BY1"] = "PROPERTY_MAIN_METAMARK";
}
if($arParams["SORT_ORDER1"] != "DESC"){
$arParams["SORT_ORDER1"] = "ASC";
}
if(strlen($arParams["SORT_BY2"]) <= 0){
$arParams["SORT_BY2"] = "NAME";
}
if($arParams["SORT_ORDER2"] != "DESC"){
$arParams["SORT_ORDER2"] = "ASC";
}
$arParams["MIN_METAMARK_YELLOW"] = intval($arParams["MIN_METAMARK_YELLOW"]);
$arParams["MIN_METAMARK_GREEN"] = intval($arParams["MIN_METAMARK_GREEN"]);
if($arParams["MIN_METAMARK_YELLOW"] <= 0){
$arParams["MIN_METAMARK_YELLOW"] = 50;
}
if($arParams["MIN_METAMARK_GREEN"] <= 0){
$arParams["MIN_METAMARK_GREEN"] = 75;
}
//
$arSortOrder = array(
$arParams["SORT_BY1"] => $arParams["SORT_ORDER1"],

95

$arParams["SORT_BY2"] => $arParams["SORT_ORDER2"],


"ID" => "DESC"
);
//
$arFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"ACTIVE" => "Y",
"SECTION_ACTIVE" => "Y"
);
// (),
if(!empty($arParams["IBLOCK_SECTION_CODE"])){
$arFilter["SECTION_CODE"] = $arParams["IBLOCK_SECTION_CODE"];
}
// ,
if(isset($arParams["FILTER"]) && is_array($arParams["FILTER"]) &&
count($arParams["FILTER"]) > 0){
$arFilter = array_merge($arFilter, $arParams["FILTER"]);
}
// , ID
//
$cache_id_arr = array(CDBResult::NavStringForCache($arParams["COUNT"]));
//
foreach($arFilter as $filt){
$cache_id_arr[] = trim(str_replace(array(";", ":", " ","-"), "", $filt));
}
$cache_id = implode("", $cache_id_arr);
//
if($this->StartResultCache(false, $cache_id)){
// ,
$arResult = array(
"ITEMS" => array(),
//
"NO_ITEMS" => false, //
"PAGENAV" => "",
//
"IS_ERROR" => false
// -
);
//,
if(!CModule::IncludeModule("iblock")){
$arResult["IS_ERROR"] = true;
throw new Exception(GetMessage("C_MODULE_ERROR"));
}
$arSelect = array(
"NAME", "ID", "DETAIL_PAGE_URL", "PREVIEW_PICTURE",
"PROPERTY_DATES_DATE_REL_RUS", "PROPERTY_MAIN_METAMARK",
"PROPERTY_GENRE_GENRE", "IBLOCK_SECTION_ID", "PROPERTY_DATES_DATE_REL"
);
$db_element = CIBlockElement::GetList($arSortOrder, $arFilter, false,
array("nPageSize" => $arParams["COUNT"]), $arSelect);
//
if(!$db_element){
$arResult["IS_ERROR"] = true;
throw new Exception(DB_ERROR_TEXT);
}
//
if($db_element->SelectedRowsCount() <= 0){
$arResult["IS_ERROR"] = true;
$arResult["NO_ITEMS"] = true;
throw new Exception(GetMessage("C_NO_ITEMS"));
}
//
$db_element->NavStart($arParams["COUNT"]);
//
$arResult["PAGENAV"] = $db_element->GetNavPrint("", false, "",
"/bitrix/templates/.default/pagenav_template.php");
// . ,

if(!empty($arParams["DETAIL_URL"])){
$db_element->SetUrlTemplates($arParams["DETAIL_URL"]);
}
// ID ()
$section_ids = array();
// ( )

96

$section_id_elem = array();
//
while($fetch_element = $db_element->GetNext()){
// ()
$fields["NAME"] = htmlspecialchars($fetch_element["NAME"]);
$fields["DETAIL_PAGE_URL"] = $fetch_element["DETAIL_PAGE_URL"];
$fields["PREVIEW_PICTURE"] = intval($fetch_element["PREVIEW_PICTURE"]);
$fields["IBLOCK_SECTION_ID"] = intval($fetch_element["IBLOCK_SECTION_ID"]);
$fields["ID"] = intval($fetch_element["ID"]);
// -,
if($fields["PREVIEW_PICTURE"] > 0){
$fields["PREVIEW_PICTURE"] = CFile::GetFileArray($fields["PREVIEW_PICTURE"]);
}
else{
$fields["PREVIEW_PICTURE"] = false;
}
//
$props["DATES_DATE_REL_RUS"]["VALUE"] =
trim(htmlspecialchars($fetch_element["PROPERTY_DATES_DATE_REL_RUS_VALUE"]));
$props["DATES_DATE_REL"]["VALUE"] =
trim(htmlspecialchars($fetch_element["PROPERTY_DATES_DATE_REL_VALUE"]));
// ,
$props["MAIN_METAMARK"]["VALUE"] =
floatval($fetch_element["PROPERTY_MAIN_METAMARK_VALUE"]);
$props["GENRE_GENRE"]["VALUE"] = $fetch_element["PROPERTY_GENRE_GENRE_VALUE"];
if(empty($props["DATES_DATE_REL_RUS"]["VALUE"])){
$props["DATES_DATE_REL_RUS"]["VALUE"] = $props["DATES_DATE_REL"]["VALUE"];
}
//
if(!empty($props["DATES_DATE_REL_RUS"]["VALUE"])){
$day = intval(date("d", strtotime($props["DATES_DATE_REL_RUS"]["VALUE"])));
$month_name = mb_substr($arMonthNames[intval(date("m",
strtotime($props["DATES_DATE_REL_RUS"]["VALUE"])))]["month_a"], 0, 3, LANG_CHARSET);
$month_name_full = $arMonthNames[intval(date("m",
strtotime($props["DATES_DATE_REL_RUS"]["VALUE"])))]["month_a"];
$year = date("Y", strtotime($props["DATES_DATE_REL_RUS"]["VALUE"]));
$props["DATES_DATE_REL_RUS"]["VALUE"] = $day." ".$month_name." ".$year;
$props["DATES_DATE_REL_RUS"]["VALUE_FULL"] = $day." ".$month_name_full." ".
$year;
}
/*** ,
***/
if($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "green";
}
elseif($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_YELLOW"] &&
$props["MAIN_METAMARK"]["VALUE"] < $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "yellow";
}
elseif($props["MAIN_METAMARK"]["VALUE"] > 0){
$props["STYLE_RAITING"] = "red";
}
else{
$props["STYLE_RAITING"] = "no_mark";
}
/*** ***/
//
$arResult["ITEMS"][$fields["ID"]] = array(
"FIELDS" => $fields,
"PROPS" => $props
);
// ID ,
if(!in_array($fields["IBLOCK_SECTION_ID"], $section_ids)){
$section_ids[] = $fields["IBLOCK_SECTION_ID"];
}
//
$section_id_elem[$fields["IBLOCK_SECTION_ID"]][] = $fields["ID"];
}
//

97

$arSectionFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ID" => $section_ids,
"ACTIVE" => "Y"
);
// ()
$db_section = CIBlockSection::GetList(array(), $arSectionFilter, false,
array("UF_*"));
// , ( )
while($ar_section = $db_section->GetNext()){
foreach($section_id_elem[$ar_section["ID"]] as $elem_to_id){
// ()
$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_NAME"] =
$ar_section["NAME"];
// ()
$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_CODE"] =
$ar_section["CODE"];
//
$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_TEXT_COLOR"] =
$ar_section["UF_TEXT_COLOR"];
// (),
if(intval($ar_section["PICTURE"]) > 0){
$arResult["ITEMS"][$elem_to_id]["FIELDS"]["SECTION_PICTURE"] =
CFile::GetFileArray(intval($ar_section["PICTURE"]));
}
}
}
//
$this->IncludeComponentTemplate();
}
}
catch(Exception $e)
{
// ,
//
if(!$arResult["NO_ITEMS"]){
$this->ClearResultCache($cache_id);
}
$this->AbortResultCache();
// arResult
$arResult["ERROR"] = $e->getMessage();
//
$this->IncludeComponentTemplate();
}
?>

.3. games.filter
component.php
<?php
//
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
try
{
// $arParams
prepare_params($arParams);
//
if(strlen($arParams["IBLOCK_TYPE"]) <= 0){
$arParams["IBLOCK_TYPE"] = IB_TYPE_GAMES;
}
if(empty($arParams["IBLOCK_ID"])){
$arParams["IBLOCK_ID"] = IB_GAMES_PC;
}
$arParams["COUNT"] = intval($arParams["COUNT"]);
if($arParams["COUNT"] <= 0){
$arParams["COUNT"] = 10;
}
if(strlen($arParams["SORT_BY1"]) <= 0){

98

$arParams["SORT_BY1"] = "ID";
}
if($arParams["SORT_ORDER1"] != "DESC"){
$arParams["SORT_ORDER1"] = "ASC";
}
if(strlen($arParams["SORT_BY2"]) <= 0){
$arParams["SORT_BY2"] = "NAME";
}
if($arParams["SORT_ORDER2"] != "DESC"){
$arParams["SORT_ORDER2"] = "ASC";
}
if(empty($arParams["DATE_REL_RUS_PROPERTY_CODE"])){
$arParams["DATE_REL_RUS_PROPERTY_CODE"] = "DATES_DATE_REL_RUS";
}
if(empty($arParams["MAIN_METAMARK_PROPERTY_CODE"])){
$arParams["MAIN_METAMARK_PROPERTY_CODE"] = "MAIN_METAMARK";
}
if(empty($arParams["FILTER_VARIABLE_NAME"])){
$arParams["FILTER_VARIABLE_NAME"] = "arrFilter";
}
$arParams["DETAIL_DATE_MIN"] = intval($arParams["DETAIL_DATE_MIN"]);
if($arParams["DETAIL_DATE_MIN"] <= 0){
$arParams["DETAIL_DATE_MIN"] = 1997;
}
$arParams["DETAIL_DATE_MAX"] = intval($arParams["DETAIL_DATE_MAX"]);
if($arParams["DETAIL_DATE_MAX"] <= 0){
$arParams["DETAIL_DATE_MAX"] = date("Y");
}
$period_list = $arParams["PERIOD_LIST"];
$arParams["PERIOD_LIST"] = array();
//
$j = 1;
foreach($period_list as $key => $value){
if(!$matches = get_parts_reg($value, "/\[(\-|\+*)(\d+)(.)\]/i")){
continue;
}
$text = $matches["text"];
$matches = $matches["matches"];
//print_r($matches);
$matches[3] = mb_strtolower($matches[3], LANG_CHARSET);
if($matches[3] != "m" && $matches[3] != "d" && $matches[3] != "y"){
continue;
}
$arParams["PERIOD_LIST"][$j] = array(
"TITLE" => $text,
"TYPE" => $matches[3],
"VALUE" => ($matches[1] == "-" ? (-1)*intval($matches[2]) : intval($matches[2]))
);
$j++;
}
//
$mark_list = $arParams["MARKS_LIST"];
$arParams["MARKS_LIST"] = array();
$j = 1;
foreach($mark_list as $key => $value){
if(!$matches = get_parts_reg($value, "/\[\b(\d+)\]\[(.+)\]/i")){
continue;
}
$text = $matches["text"];
$matches = $matches["matches"];
$arParams["MARKS_LIST"][$j] = array(
"TITLE" => $text,
"VALUE" => intval($matches[1]),
"COLOR" => $matches[2]
);
$j++;
}
$arResult = array(
"GENRES" => array(),
"PLATFORMS" => array(),
"POST_VARIABLES" => array()

99

);
/******

******/
if(isset($_REQUEST["filter"]) || isset($_REQUEST["with_no_script"])){
//
$filter_var = array();
//
$_REQUEST["marki"] = intval($_REQUEST["marki"]);
$_REQUEST["datei"] = intval($_REQUEST["datei"]);
$_REQUEST["platform"] = trim($_REQUEST["platform"]);
$_REQUEST["genre"] = trim(htmlspecialchars(urldecode($_REQUEST["genre"])));
$_REQUEST["markv"] = floatval($_REQUEST["markv"]);
$_REQUEST["daterange"] = intval($_REQUEST["daterange"]);
$_REQUEST["dfrom"] = trim($_REQUEST["dfrom"]);
$_REQUEST["dto"] = trim($_REQUEST["dto"]);
$_REQUEST["alpha"] = mb_substr(trim(urldecode($_REQUEST["alpha"])), 0, 1,
LANG_CHARSET);
if(!empty($_REQUEST["platform"])){
$filter_var["SECTION_CODE"] = $_REQUEST["platform"];
}
if(strlen($_REQUEST["alpha"]) > 0){
if($_REQUEST["alpha"] == "1"){
$numbs = array();
for($i=0; $i <= 9; $i++){
$numbs[] = $i."%";
}
//$filter_var["NAME"] = implode("|", $numbs);
$filter_var[">NAME"] = "-1%";
$filter_var["<=NAME"] = "9%";
}
else{
$filter_var["NAME"] = $_REQUEST["alpha"]."%";
}
//echo $filter_var["NAME"];
}
if(eregi("^[0-9]{4}$", $_REQUEST["dfrom"])){
$f_date_from = "year";
$_REQUEST["dfrom"] = intval($_REQUEST["dfrom"]);
if($_REQUEST["dfrom"] <= 0){
$_REQUEST["dfrom"] = $arParams["DETAIL_DATE_MIN"];
}
}
else{
if(strtotime($_REQUEST["dfrom"]) <= 0){
$_REQUEST["daterange"] = 0;
}
}
if(eregi("^[0-9]{4}$", $_REQUEST["dto"])){
$f_date_to = "year";
if($_REQUEST["dto"] <= 0){
$_REQUEST["dto"] = $arParams["DETAIL_DATE_MAX"];
}
}
else{
if(strtotime($_REQUEST["dto"]) <= 0){
$_REQUEST["daterange"] = 0;
}
}
//
$datei_key = $_REQUEST["datei"];
if($_REQUEST["daterange"] == 1){
$datei_key = 0;
$date_from = $_REQUEST["dfrom"];
$date_to = $_REQUEST["dto"];
if($f_date_from == "year" && $f_date_to == "year" && $date_to < $date_from){
$date_to = $date_from;
}
if($f_date_from == "year"){

100

$filter_var[">=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Ym-d", strtotime("01.01.".$date_from));


}
else{
$filter_var[">=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Ym-d", strtotime($date_from));
}
if($f_date_to == "year"){
$filter_var["<=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Ym-d", strtotime("31.12.".$date_to));
}
else{
$filter_var["<=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Ym-d", strtotime($date_to));
}
$arResult["POST_VARIABLES"]["datei"] = $date_from." - ".$date_to;
}
if($datei_key > 0){
// ,
$filter_var["<=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Y-md");
$datei_type = $arParams["PERIOD_LIST"][$datei_key]["TYPE"];
$datei_value = intval($arParams["PERIOD_LIST"][$datei_key]["VALUE"]);
switch($datei_type)
{
//
case "d":
//
$interval_from = AddToTimestamp(array("DD" => -$datei_value));
break;
//
case "m":
$interval_from = AddToTimestamp(array("MM" => -$datei_value));
break;
//
case "y":
$interval_from = AddToTimestamp(array("YYYY" => -$datei_value));
break;
default:
break;
}
if($datei_value > 0){
$filter_var[">=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Ym-d", $interval_from);
}
else{
$filter_var["<=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Ym-d", $interval_from);
}
$arResult["POST_VARIABLES"]["datei"] = $arParams["PERIOD_LIST"][$datei_key]
["TITLE"];
}
// ,
$_REQUEST["month"] = intval($_REQUEST["month"]);
$_REQUEST["year"] = intval($_REQUEST["year"]);
if($_REQUEST["month"] > 0 && $_REQUEST["year"] > 0){
$top_day = get_max_day($_REQUEST["month"], $_REQUEST["year"]);
// echo $top_day;
$filter_var[">=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Y-m-d",
strtotime("01.".$_REQUEST["month"].".".$_REQUEST["year"]));
$filter_var["<=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Y-m-d",
strtotime($top_day.".".$_REQUEST["month"].".".$_REQUEST["year"]));
}
//
$marki_key = $_REQUEST["marki"];
$markv = $_REQUEST["markv"];
//
// ,
if($markv > 0){
$marki_key = -1;
$filter_var["PROPERTY_".$arParams["MAIN_METAMARK_PROPERTY_CODE"]] = $markv;

101

$arResult["POST_VARIABLES"]["marki"] = $markv;
}
// ,
if($marki_key > 0){
$filter_var[">=PROPERTY_".$arParams["MAIN_METAMARK_PROPERTY_CODE"]] =
$arParams["MARKS_LIST"][$marki_key]["VALUE"];
$arResult["POST_VARIABLES"]["marki"] = $arParams["MARKS_LIST"][$marki_key]
["TITLE"];
}
//
$genre = $_REQUEST["genre"];
if(!empty($genre)){
$p_enum = CIBlockProperty::GetPropertyEnum($arParams["GENRE_PROPERTY_CODE"],
array(), array("XML_ID" => $genre));
$ar_enum = $p_enum->GetNext();
$filter_var["PROPERTY_".$arParams["GENRE_PROPERTY_CODE"]."_VALUE"] =
$ar_enum["VALUE"];
$arResult["POST_VARIABLES"]["GENRE"] = $ar_enum["VALUE"];
}
}
else{
// ,
if($arParams["MAIN_PAGE"] == "Y"){
$value_period_finded = false;
foreach($arParams["PERIOD_LIST"] as $key => $per){
if($per["TYPE"] == "m" && $per["VALUE"] == 6){
$value_period_finded = true;
break;
}
}
if($value_period_finded){
$_REQUEST["datei"] = $key;
$interval_from = AddToTimestamp(array("MM" => -6));
$filter_var[">=PROPERTY_".$arParams["DATE_REL_RUS_PROPERTY_CODE"]] = date("Ym-d", $interval_from);
$arResult["POST_VARIABLES"]["datei"] = $arParams["PERIOD_LIST"][$key]
["TITLE"];
}
}
}
$GLOBALS[$arParams["FILTER_VARIABLE_NAME"]] = $filter_var;
// ( - )
$arIblockOrder = array(
$arParams["SORT_BY1"] => $arParams["SORT_ORDER1"],
$arParams["SORT_BY2"] => $arParams["SORT_ORDER2"],
"ID" => "DESC"
);
$arIblockFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ACTIVE" => "Y"
);
$db_iblock = CIBlockSection::GetList($arIblockOrder, $arIblockFilter);
if(!$db_iblock){
throw new Exception(DB_ERROR_TEXT);
}
// , ,
if($db_iblock->SelectedRowsCount() <= 0){
$this->IncludeComponentTemplate();
return;
}
while($fetch = $db_iblock->GetNext()){
$arResult["PLATFORMS"][$fetch["CODE"]] = array(
"NAME" => $fetch["NAME"],
"ID" => $fetch["ID"],
);
}
//
$arEnumOrder = array(
"SORT" => "ASC",
"ID" => "ASC"

102

);
$arEnumFilter = array(
"CODE" => $arParams["GENRE_PROPERTY_CODE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"]
);
$db_enum = CIBlockPropertyEnum::GetList($arEnumOrder, $arEnumFilter);
while($fetch = $db_enum->GetNext()){
$genre_list[$fetch["XML_ID"]] = $fetch["VALUE"];
}
$arResult["ALL_GENRE"] = $genre_list;
//
foreach($arParams["MAIN_GENRE"] as $val){
$arResult["MAIN_GENRE"][$val] = $genre_list[$val];
}
//
$this->IncludeComponentTemplate();
}
catch(Exception $ex)
{
$arResult["ERROR"] = $ex->getMessage();
}
?>

script.js
/**/
// input
check_form_submit
function set_platform(path, form, iblock_id, result_block)
{
$("#iblock_id").val(iblock_id);
return check_form_submit(path, form, result_block);
}
function set_alpha(path, form, alpha, result_block)
{
$("#alpha").val(alpha);
return check_form_submit(path, form, result_block);
}
// id = ob
function check_form_submit(path, ob, result_block, additional_pars)
{
if($("#detail_date_enabled").val() == "0" || $("#detail_date_enabled").val() == ""){
$("#detail-date-from-catcher").val("");
$("#detail-date-to-catcher").val("");
}
if($("#mark_value").val() > 0){
document.getElementById("mark_interval").selectedIndex = 0;
}
//
var query_string_arr = new Array("ajax_request_mode=Y");
var state_string_arr = new Array();
var query_string = "";
var state_string;
var query_string_ajax;
$("#"+ob.id+" input, #"+ob.id+" select").each(function(){
var name = $(this).attr("name");
var value = $(this).val();
if(name.length > 0 && value.length > 0 && name != "with_no_script"){
var val = parseInt(value);
if(!isNaN(val) && name != "dfrom" && name != "dto"){
if(val > 0 || name == "alpha"){
query_string_arr.push(name+"="+value);
state_string_arr.push(name+":"+value);
}
}
else{
query_string_arr.push(name+"="+value);
state_string_arr.push(name+":"+value);
}
}

103

});
query_string_arr.push(additional_pars);
query_string_ajax = query_string_arr.join("&");
query_string_arr.push("ajax_request_mode=Y");
query_string = query_string_arr.join("&");
state_string = state_string_arr.join("&");
set_server_request(path, query_string, "ajax-status", result_block, state_string);
return false;
}
$(function(){
// ID , select'
var select_list_ids = new Array();
select_list_ids[0] = new Array("date_interval", "date-select-box", "date-select-catcher",
"date-select-opener", "detail_date_enabled");
select_list_ids[1] = new Array("mark_interval", "mark-select-box", "mark-select-catcher",
"mark-select-opener", "mark_value");
// ,
for(var j in select_list_ids)
{
var select_id = "#"+select_list_ids[j][0];
var select_id_v = select_list_ids[j][0];
var box_id = "#"+select_list_ids[j][1];
var catcher_id = "#"+select_list_ids[j][2];
var opener_id = "#"+select_list_ids[j][3];
var additional_id = "#" + select_list_ids[j][4];
// select
if(!document.getElementById(select_id_v)){
continue;
}
var list = document.getElementById(select_id_v).options;
for(var i=list.length - 1; i >=0; i--){
if($(list[i]).val().length <= 0){
continue;
}
//
var a = document.createElement("a");
//
var html = list[i].text;
if(html.length <= 0){
continue;
}
if(html.indexOf("[") != -1 && html.indexOf("]") != -1){
from_index = html.indexOf("[");
to_index = html.indexOf("]");
var color = html.substring(from_index + 1, to_index);
if(color.length > 0){
var span = document.createElement("span");
$(span).css("color", color);
$(a).append(span);
}
html = html.substring(0, from_index);
list[i].text = list[i].text.substring(0, from_index);
$(span).html(html);
}
else{
$(a).html(html);
}
// a -
$(a).hover(
function(e)
{
$(this).addClass("next_hover");
},
function(e)
{
$(this).removeClass("next_hover");
}
);
$(a).bind(
"click",

104

{list_option: list[i], b_id: box_id, add_id: additional_id, catcher:


catcher_id},
function(event){
$(event.data.add_id).val("");
var html = $(this).html();
$(event.data.catcher).attr("title", event.data.list_option.text);
$(event.data.catcher).val(event.data.list_option.text);
// option
$(event.data.list_option).attr("selected", "selected");
//
document.getElementById("filter-box-form-sended").click();
$(event.data.b_id).hide();
});
$(a).addClass("next");
$(a).prependTo(box_id);
}
//
$(opener_id).bind(
"click",
{b_id : box_id, select_list_ids: select_list_ids},
function(event){
if($(event.data.b_id).css("display") == "none"){
$(event.data.b_id).show();
}
else{
$(event.data.b_id).hide();
}
for(var i in event.data.select_list_ids){
if(event.data.b_id != "#"+event.data.select_list_ids[i][1]){
$("#"+event.data.select_list_ids[i][1]).hide();
}
}
$("#genre-select-box").hide();
$("#detail-date-from-select-box").hide();
$("#detail-date-to-select-box").hide();
return false;
}
);
}
$("#detail-date-from-opener").bind(
"click",
function(event){
if($("#detail-date-from-select-box").css("display") == "none"){
$("#detail-date-from-select-box").show();
}
else{
$("#detail-date-from-select-box").hide();
}
$("#detail-date-to-select-box").hide();
return false;
}
);
$("#detail-date-to-opener").bind(
"click",
function(event){
if($("#detail-date-to-select-box").css("display") == "none"){
$("#detail-date-to-select-box").show();
}
else{
$("#detail-date-to-select-box").hide();
}
$("#detail-date-from-select-box").hide();
return false;
}
);
$("#detail-date-from-select-box a.next").bind("click", {list_option: false, b_id:
"#detail-date-from-select-box", catcher: "#detail-date-from-catcher"}, function(event){
$(event.data.catcher).attr("title", $(this).html());
$(event.data.catcher).datepicker('option',"defaultDate", "01.01."+$(this).html());
$(event.data.catcher).val($(this).html());
$(event.data.b_id).hide();

105

return false;
});
$("#detail-date-to-select-box a.next").bind("click", {list_option: false, b_id: "#detaildate-to-select-box", catcher: "#detail-date-to-catcher"}, function(event){
$(event.data.catcher).attr("title", $(this).html());
$(event.data.catcher).datepicker('option', "defaultDate", "31.12."+$(this).html());
$(event.data.catcher).val($(this).html());
$(event.data.b_id).hide();
return false;
});
// #genre-select-box
$("#genre-select-opener").bind(
"click",
{b_id : "#genre-select-box"},
function(event){
if($(event.data.b_id).css("display") == "none"){
$(event.data.b_id).show();
}
else{
$(event.data.b_id).hide();
}
$("#date-select-box").hide();
$("#mark-select-box").hide();
//$("#")
return false;
}
);
$("#genre-select-box a.next").bind("click", {list_option: false, b_id: "#genre-selectbox", catcher: "#genre-select-catcher"}, function(event){
$(event.data.catcher).attr("title", $(this).html());
$(event.data.catcher).val($(this).html());
var genre_list = document.getElementById("genre").options;
var check_flag = false;
for(var i = 0; i < genre_list.length; i++){
if(genre_list[i].text == $(this).html()){
$(genre_list[i]).attr("selected", "selected");
check_flag = true;
break;
}
}
if(!check_flag){
$(genre_list[0]).attr("selected", "selected");
}
//
document.getElementById("filter-box-form-sended").click();
$(event.data.b_id).hide();
return false;
});
$("#genre-select-box p.more a").bind("click", function(event){
if($("#genre-select-box .col").css("display") != "none"){
$("#genre-select-box .col").hide();
$("#genre-select-box .main").show();
$("#genre-select-box").addClass("genre_small");
$("#genre-select-box").removeClass("genre_wide");
$(this).html(" ");
}
else{
$("#genre-select-box .col").show();
$("#genre-select-box .main").hide();
$("#genre-select-box").addClass("genre_wide");
$("#genre-select-box").removeClass("genre_small");
$(this).html("");
}
return false;
});
$("div.filter-box .select-box .js-included").show();
$("div.filter-box .select-box .js-not-included").hide();
var def_date_from = $("#detail-date-from-catcher").val();
if(def_date_from && def_date_from.length > 0 && def_date_from.length <= 4){
def_date_from = "01.01."+def_date_from;

106

}
var def_date_to = $("#detail-date-to-catcher").val();
if(def_date_to && def_date_to.length > 0 && def_date_to.length <= 4){
def_date_to = "31.12."+def_date_to;
}
$("#detail_date_sender").bind("click", function(){
$("#detail_date_enabled").val("1");
});
$.datepicker.setDefaults(
$.extend($.datepicker.regional["ru"])
);
if(def_date_from && def_date_to){
$("#detail-date-from-catcher").datepicker({
dateFormat:"dd.mm.yy",
defaultDate: def_date_from
});
$("#detail-date-to-catcher").datepicker({
dateFormat:"dd.mm.yy",
defaultDate: def_date_to
});
}
$("#date_from_calendar").bind("click", function(){
$("#detail-date-from-catcher").datepicker("show");
return false;
});
$("#date_to_calendar").bind("click", function(){
$("#detail-date-to-catcher").datepicker("show");
return false;
});
$(".ui-datepicker").bind("click", function(event){
$("#date-select-box").show();
event.stopPropagation();
});
});

result_modifier.php month_switcher
<?php
/* */
global $arMonthNames;
//
if($arParams["DISPLAY_MONTHS_COUNT"] <= 0){
$arParams["DISPLAY_MONTHS_COUNT"] = 3;
}
//
if(strlen($arParams["BORDER"]) <= 0){
$arParams["BORDER"] = "bottom";
}
//
$arParams["MIN_YEAR"] = intval($arParams["MIN_YEAR"]);
$arParams["MAX_YEAR"] = intval($arParams["MAX_YEAR"]);
if($arParams["MIN_YEAR"] <= 0){
$arParams["MIN_YEAR"] = 1990;
}
if($arParams["MAX_YEAR"] <= 0){
$arParams["MAX_YEAR"] = 2013;
}
$b_redirect = false;
$_REQUEST["month"] = intval($_REQUEST["month"]);
$_REQUEST["year"] = intval($_REQUEST["year"]);
if($_REQUEST["month"] > 12){
$_REQUEST["month"] = 12;
$b_redirect = true;
}
if($_REQUEST["month"] > 0 && $_REQUEST["year"] > 0 && !isset($_REQUEST["filter"])){
$b_redirect = true;
}
// ,
if($_REQUEST["month"] > 0){
$current_month = $_REQUEST["month"];

107

}
else{
$current_month = intval(date("m"));
}
////
if($_REQUEST["year"] > 0){
$current_year = $_REQUEST["year"];
}
else{
$current_year = intval(date("Y"));
}
/* */
if($arParams["DISPLAY_MONTHS_COUNT"] % 2 == 0){
$center = floor($arParams["DISPLAY_MONTHS_COUNT"] / 2);
}
else{
$center = ceil($arParams["DISPLAY_MONTHS_COUNT"] / 2);
}
// ,
$current_date_flag = false;
if($current_year == intval(date("Y")) && $current_month == intval(date("m"))){
$current_flag = true;
}
if($current_year < $arParams["MIN_YEAR"]){
$current_year = $arParams["MIN_YEAR"];
$current_month = 1;
$b_redirect = true;
}
$bottom_move_flag = false;
if($arParams["BORDER"] == "bottom" && ($current_year < intval(date("Y")) || ($current_month <
intval(date("m")) && $current_year <= intval(date("Y"))))){
$current_year = intval(date("Y"));
$current_month = intval(date("m"));
$b_redirect = true;
$bottom_move_flag = true;
}
if($current_year == $arParams["MIN_YEAR"] && $current_month == 1){
$bottom_move_flag = true;
}
$top_move_flag = false;
if($current_year > $arParams["MAX_YEAR"]){
$current_year = $arParams["MAX_YEAR"];
$current_month = 12;
$b_redirect = true;
$top_move_flag = true;
}
if($current_year == $arParams["MAX_YEAR"] && $current_month == 12){
$top_move_flag = true;
}
if($arParams["BORDER"] == "top" && ($current_year > intval(date("Y")) || ($current_month >
intval(date("m")) && $current_year >= intval(date("Y"))))){
$current_year = intval(date("Y"));
$current_month = intval(date("m"));
$b_redirect = true;
$top_move_flag = true;
}
$k = 1;
//
$arResult["PREV_MONTHS"] = array();
$prev_year = $current_year;
$prev_month = $current_month;
if(!$bottom_move_flag && ($arParams["BORDER"] != "bottom" || !$current_flag)){
while($k < $center){
if($prev_month - 1 <= 0){
$prev_year -= 1;
$prev_month = 12;
}
else{
$prev_month = $prev_month - 1;
}

108

$arResult["PREV_MONTHS"][] = array(
"month" => $prev_month,
"month_name" => $arMonthNames[$prev_month]["month"],
"month_year" => $prev_year,
);
$k++;
}
}
if($b_redirect){
LocalRedirect($APPLICATION->GetCurPageParam("filter=up&month=".$current_month."&year=".
$current_year, array("filter", "month", "year")));
exit(1);
}
$arResult["CURRENT_MONTH"] = $current_month;
$arResult["CURRENT_MONTH_NAME"] = $arMonthNames[$current_month]["month"];
$arResult["CURRENT_YEAR"] = $current_year;
$k = $center + 1;
$arResult["NEXT_MONTHS"] = array();
$next_month = $current_month;
$next_year = $current_year;
if(!$top_move_flag && ($arParams["BORDER"] != "top" || !$current_flag)){
while($k <= $arParams["DISPLAY_MONTHS_COUNT"]){
if($next_month + 1 > 12){
$next_year += 1;
$next_month = 1;
}
else{
$next_month = $next_month + 1;
}
$arResult["NEXT_MONTHS"][] = array(
"month" => $next_month,
"month_name" => $arMonthNames[$next_month]["month"],
"month_year" => $next_year,
);
$k++;
}
}
$arResult["PREV_MONTHS"] = array_reverse($arResult["PREV_MONTHS"]);
?>

.4. games.search
component.php
<?php
//
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
function declension($numb, $forms = array())
{
$numb = strval($numb);
$numb_2 = substr($numb, strlen($numb) - 2);
$numb_1 = substr($numb, strlen($numb) - 1);
if($numb_2 == "11"){
return $forms[1];
}
if(intval($numb_2) > 9 && intval($numb_2) < 20){
return $forms[1];
}
if($numb_1 == "1"){
return $forms[0];
}
if($numb_1 == "2" || $numb_1 == "3" || $numb_1 == "4"){
return $forms[2];
}
return $forms[1];
}
try
{
// $arParams

109

prepare_params($arParams);
//
if(strlen($arParams["IBLOCK_TYPE"]) <= 0){
$arParams["IBLOCK_TYPE"] = IB_TYPE_GAMES;
}
$arParams["COUNT"] = intval($arParams["COUNT"]);
if($arParams["COUNT"] <= 0){
$arParams["COUNT"] = 10;
}
if(strlen($arParams["SORT_BY1"]) <= 0){
$arParams["SORT_BY1"] = "PROPERTY_MAIN_METAMARK";
}
if($arParams["SORT_ORDER1"] != "DESC"){
$arParams["SORT_ORDER1"] = "ASC";
}
if(strlen($arParams["SORT_BY2"]) <= 0){
$arParams["SORT_BY2"] = "NAME";
}
if($arParams["SORT_ORDER2"] != "DESC"){
$arParams["SORT_ORDER2"] = "ASC";
}
$arParams["MIN_METAMARK_YELLOW"] = intval($arParams["MIN_METAMARK_YELLOW"]);
$arParams["MIN_METAMARK_GREEN"] = intval($arParams["MIN_METAMARK_GREEN"]);
if($arParams["MIN_METAMARK_YELLOW"] <= 0){
$arParams["MIN_METAMARK_YELLOW"] = 50;
}
if($arParams["MIN_METAMARK_GREEN"] <= 0){
$arParams["MIN_METAMARK_GREEN"] = 75;
}
//
$arSortOrder = array(
$arParams["SORT_BY1"] => $arParams["SORT_ORDER1"],
$arParams["SORT_BY2"] => $arParams["SORT_ORDER2"],
"ID" => "DESC"
);
$search_text = trim(htmlspecialchars($_REQUEST["q"]));
if(empty($search_text)){
throw new Exception();
}
//
$arFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"ACTIVE" => "Y",
"SECTION_ACTIVE" => "Y"
);
if(strlen($search_text) > 0){
$arFilter["NAME"] = "%".$search_text."%";
}
$platform = trim(htmlspecialchars($_REQUEST["platform"]));
if(!empty($platform)){
$arFilter["SECTION_CODE"] = $platform;
}
// , ID
//
$cache_id_arr = array(CDBResult::NavStringForCache($arParams["COUNT"]));
//
$cache_id_arr[] = $search_text;
$cache_id_arr[] = $platform;
$cache_id = implode("", $cache_id_arr);
//
if($this->StartResultCache(false, $cache_id)){
//,
if(!CModule::IncludeModule("iblock")){
$arResult["IS_ERROR"] = true;
throw new Exception(GetMessage("C_MODULE_ERROR"));
}
// ,
$arResult = array(
"ITEMS" => array(),
//
"NO_ITEMS" => false, //
"PAGENAV" => "",
//

110

"IS_ERROR" => false, // -


"SEARCH_TEXT" => $search_text,
"TOTAL_COUNT" => 0,
"PLATFORMS" => array()
);
//
$arSectionFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ACTIVE" => "Y"
);
// ()
$db_section = CIBlockSection::GetList(array("SORT" => "ASC"), $arSectionFilter, false,
array("UF_*"));
// , ( )
$ar_section = array();
$section_current_id = 0;
while($fetch = $db_section->GetNext()){
if($fetch["CODE"] == $arParams["IBLOCK_SECTION_CODE"]){
$section_current_id = $fetch["ID"];
}
$ar_section[$fetch["ID"]]["NAME"] = $fetch["NAME"];
// ()
$ar_section[$fetch["ID"]]["CODE"] = $fetch["CODE"];
//
$ar_section[$fetch["ID"]]["TEXT_COLOR"] = $fetch["UF_TEXT_COLOR"];
//
$ar_section[$fetch["ID"]]["PICTURE"] = $fetch["PICTURE"];
//
if(strlen($arParams["PATH_TO"]) > 0){
$ar_section[$fetch["ID"]]["PATH_TO"] = str_replace("#SECTION_CODE#",
$fetch["CODE"], $arParams["PATH_TO"]);
}
else{
$ar_section[$fetch["ID"]]["PATH_TO"] = $ar_section["SECTION_PAGE_URL"];
}
}
$arResult["PLATFORMS"] = $ar_section;
// ""
$db_element = CIBlockElement::GetList($arSortOrder, $arFilter, false/*,
$arNavParams*/);
//
if(!$db_element){
$arResult["IS_ERROR"] = true;
throw new Exception(DB_ERROR_TEXT);
}
$arResult["TOTAL_COUNT"] += $db_element->SelectedRowsCount();
unset($arFilter["NAME"]);
$arFilter["!NAME"] = "%".$search_text."%";
if(strlen($search_text) > 0){
$arFilter["PROPERTY_MAIN_ENG_NAME"] = "%".$search_text."%";
}
$db_element_eng = CIBlockElement::GetList($arSortOrder, $arFilter, false/*,
$arNavParams*/);
if(!$db_element_eng){
$arResult["IS_ERROR"] = true;
throw new Exception(DB_ERROR_TEXT);
}
$arResult["TOTAL_COUNT"] += $db_element_eng->SelectedRowsCount();
//echo $arResult["TOTAL_COUNT"];
//
if($arResult["TOTAL_COUNT"] <= 0){
$arResult["IS_ERROR"] = true;
$arResult["NO_ITEMS"] = true;
throw new Exception(GetMessage("C_NO_ITEMS"));
}
// . ,

if(!empty($arParams["DETAIL_URL"])){
$db_element->SetUrlTemplates($arParams["DETAIL_URL"]);
$db_element_eng->SetUrlTemplates($arParams["DETAIL_URL"]);

111

}
$objects = array($db_element, $db_element_eng);
// ID ()
$section_ids = array();
// ( )
$section_id_elem = array();
//
foreach($objects as $ob){
while($ob_element = $ob->GetNextElement()){
// ()
$fields = $ob_element->GetFields();
$fields["NAME"] = htmlspecialchars($fields["NAME"]);
// -,
if($fields["PREVIEW_PICTURE"] > 0){
$fields["PREVIEW_PICTURE"] =
CFile::GetFileArray($fields["PREVIEW_PICTURE"]);
}
else{
$fields["PREVIEW_PICTURE"] = false;
}
//
$props = $ob_element->GetProperties();
// ,
if(empty($props["DATES_DATE_REL_RUS"]["VALUE"])){
$props["DATES_DATE_REL_RUS"]["VALUE"] = $props["DATES_DATE_REL"]["VALUE"];
}
/*** ,
***/
if($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "green";
}
elseif($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_YELLOW"] &&
$props["MAIN_METAMARK"]["VALUE"] < $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "yellow";
}
elseif($props["MAIN_METAMARK"]["VALUE"] > 0){
$props["STYLE_RAITING"] = "red";
}
else{
$props["STYLE_RAITING"] = "no_mark";
}
/*** ***/
//
$arResult["ITEMS"][$fields["ID"]] = array(
"FIELDS" => $fields,
"PROPS" => $props
);
$arResult["ITEMS"][$fields["ID"]]["FIELDS"]["SECTION_NAME"] =
$ar_section[$fields["IBLOCK_SECTION_ID"]]["NAME"];
// ()
$arResult["ITEMS"][$fields["ID"]]["FIELDS"]["SECTION_CODE"] =
$ar_section[$fields["IBLOCK_SECTION_ID"]]["CODE"];
//
$arResult["ITEMS"][$fields["ID"]]["FIELDS"]["SECTION_TEXT_COLOR"] =
$ar_section[$fields["IBLOCK_SECTION_ID"]]["TEXT_COLOR"];
// (),
if(intval($ar_section[$fields["IBLOCK_SECTION_ID"]]["PICTURE"]) > 0){
$arResult["ITEMS"][$fields["ID"]]["FIELDS"]["SECTION_PICTURE"] =
CFile::GetFileArray(intval($ar_section[$fields["IBLOCK_SECTION_ID"]]["PICTURE"]));
}
}
}
$cdbresult = new CDBResult;
$cdbresult->InitFromArray($arResult["ITEMS"]);
//
$cdbresult->NavStart($arParams["COUNT"]);
//
$arResult["PAGENAV"] = $cdbresult->GetNavPrint("", false, "",
"/bitrix/templates/.default/pagenav_template.php");

112

$arResult["ITEMS"] = array();
while($res = $cdbresult->GetNext()){
$arResult["ITEMS"][] = $res;
}
//
$this->IncludeComponentTemplate();
}
}
catch(Exception $e)
{
// ,
//
if(!$arResult["NO_ITEMS"]){
$this->ClearResultCache($cache_id);
}
$this->AbortResultCache();
// arResult
$arResult["ERROR"] = $e->getMessage();
//
$this->IncludeComponentTemplate();
}
?>

.5. games.detail
component.php
<?php
//
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
function get_file_parts($filename){
$ext = "";
//
$fname = ""; //
$pos = strrpos($filename, ".");
//
if($pos !== false){
//
$fname = substr($filename, 0, $pos);
//
$ext = ToLower(substr($filename, $pos + 1));
}
else{
$fname = $filename;
}
return array("file" => $filename, "extension" => $ext, "filename" => $fname);
}
function get_screens_by_game_code($gamecode, $path, $allow_extensions = array("jpg", "jpeg",
"gif", "png"))
{
$directory_path_full = $_SERVER["DOCUMENT_ROOT"].$path;
$gamecode = trim(htmlspecialchars($gamecode));
// ,
if(empty($gamecode)){
return false;
}
// ,
if(!file_exists($directory_path_full) || is_file($directory_path_full)){
return false;
}
//
//,
$fdir = @opendir($directory_path_full);
if(!$fdir){
return false;
}
//
$screen_paths = array();
if($path[strlen($path) - 1] != "/"){
$path .= "/";

113

}
while($ffile = readdir($fdir)){
if($ffile != "." && $ffile != ".." && !is_dir($directory_path_full.$ffile)){
//,
$ffile_parts = get_file_parts($ffile);
if(!eregi("^[a-zA-Z0-9\-_\.]", $ffile_parts["filename"])){
continue;
}
if(in_array($ffile_parts["extension"], $allow_extensions)){
$screen_paths[$ffile_parts["filename"]] = $path.$ffile;
}
}
}
return $screen_paths;
}
try
{
// $arParams
prepare_params($arParams);
//
if(strlen($arParams["IBLOCK_TYPE"]) <= 0){
$arParams["IBLOCK_TYPE"] = IB_TYPE_GAMES;
}
if(strlen($arParams["REVIEWS_IBLOCK_TYPE"]) <= 0){
$arParams["REVIEWS_IBLOCK_TYPE"] = IB_TYPE_REVIEWS;
}
/*
$arParams["REVIEWS_IBLOCK_ID"] = intval($arParams["REVIEWS_IBLOCK_ID"]);
if(intval($arParams["REVIEWS_IBLOCK_ID"]) <= 0){
$arParams["REVIEWS_IBLOCK_ID"] = 2;
}
*/
$arParams["IBLOCK_ID"] = intval($arParams["IBLOCK_ID"]);
if($arParams["IBLOCK_ID"] <= 0){
$arParams["IBLOCK_ID"] = IB_GAMES_PC;
}
if(strlen($arParams["IBLOCK_SECTION_CODE"]) <= 0){
$no_section = true;
throw new Exception(GetMessage("C_NO_IBLOCK_SECTION_CODE"));
}
if(strlen($arParams["ELEMENT_CODE"]) <= 0){
$no_elem = true;
throw new Exception(GetMessage("C_NO_IBLOCK_ELEMENT_CODE"));
}
$arParams["MIN_METAMARK_YELLOW"] = intval($arParams["MIN_METAMARK_YELLOW"]);
$arParams["MIN_METAMARK_GREEN"] = intval($arParams["MIN_METAMARK_GREEN"]);
if($arParams["MIN_METAMARK_YELLOW"] <= 0){
$arParams["MIN_METAMARK_YELLOW"] = 50;
}
if($arParams["MIN_METAMARK_GREEN"] <= 0){
$arParams["MIN_METAMARK_GREEN"] = 75;
}
//
$arFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"SECTION_CODE" => $arParams["IBLOCK_SECTION_CODE"],
"CODE" => $arParams["ELEMENT_CODE"],
"SECTION_ACTIVE" => "Y",
"ACTIVE" => "Y",
);
//
$arNavParams = array(
"nTopCount" => 1
);
// ,
$cache_id = implode("_", $arFilter);
if($this->StartResultCache(false, $cache_id)){
// ""
$db_enum_list = CIBlockPropertyEnum::GetList(array("SORT" => "ASC"),
array("PROPERTY_ID" => 35));

114

$ar_enum = array();
while($fetch = $db_enum_list->GetNext()){
$ar_enum[$fetch["ID"]] = $fetch;
}
$arResult = array(
"NO_ITEMS" => false,
"ITEM" => array(),
"REVIEWS" => array(),
"NO_REVIEWS" => false
);
//
$db_element = CIBlockElement::GetList(array(), $arFilter, false, $arNavParams);
//
if(!$db_element || $db_element->SelectedRowsCount() <= 0){
$arResult["NO_ITEMS"] = true;
throw new Exception();
}
$ar_element_ob = $db_element->GetNextElement();
$fields = $ar_element_ob->GetFields();
//
$fields["NAME"] = htmlspecialchars($fields["NAME"]);
if($fields["DETAIL_PICTURE"] > 0){
$fields["DETAIL_PICTURE"] = CFile::GetFileArray($fields["DETAIL_PICTURE"]);
}
else{
$fields["DETAIL_PICTURE"] = false;
}
//
$props = $ar_element_ob->GetProperties();
if($props["VIDEO_SCREEN"]["VALUE"] > 0){
$props["VIDEO_SCREEN"]["VALUE"] = CFile::GetFileArray($props["VIDEO_SCREEN"]
["VALUE"]);
}
else{
$$props["VIDEO_SCREEN"]["VALUE"] = false;
}
if(!empty($arParams["OZON_PATH_TEMPLATE"]) && !empty($props["OZON_ID"]["VALUE"])){
$arParams["OZON_PATH_TEMPLATE_SET"] = str_replace(array("#OZON_ID#"),
array($props["OZON_ID"]["VALUE"]), $arParams["OZON_PATH_TEMPLATE"]);
}
if($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "green";
}
elseif($props["MAIN_METAMARK"]["VALUE"] >= $arParams["MIN_METAMARK_YELLOW"] &&
$props["MAIN_METAMARK"]["VALUE"] < $arParams["MIN_METAMARK_GREEN"]){
$props["STYLE_RAITING"] = "yellow";
}
elseif($props["MAIN_METAMARK"]["VALUE"] > 0){
$props["STYLE_RAITING"] = "red";
}
else{
$props["STYLE_RAITING"] = "no_mark";
}
// ID -
$db_section = CIBlockSection::GetByID($fields["IBLOCK_SECTION_ID"]);
$ar_section = $db_section->GetNext();
//print_r($ar_section);
$fields["SECTION_NAME"] = $ar_section["NAME"];
if(intval($ar_section["DETAIL_PICTURE"]) > 0){
$ar_section["DETAIL_PICTURE"] =
CFile::GetFileArray(intval($ar_section["DETAIL_PICTURE"]));
}
else{
$ar_section["DETAIL_PICTURE"] = false;
}
$fields["SECTION_DETAIL_PICTURE"] = $ar_section["DETAIL_PICTURE"];
$arResult["ITEM"]["FIELDS"] = $fields;
//
$screens_small = get_screens_by_game_code(
$fields["CODE"],
str_replace(

115

array("#SECTION_CODE#", "#CODE#"),
array($arParams["IBLOCK_SECTION_CODE"], $fields["CODE"]),
$arParams["SCREEN_PATH_TEMPLATE_SMALL"]
)
);
if($screens_small){
foreach($screens_small as $code => $val){
$arResult["ITEM"]["FIELDS"]["SCREENS"][$code]["SMALL"] = $val;
}
}
//$arResult["ITEM"]["FIELDS"]["SCREENS"]
$screens_big = get_screens_by_game_code(
$fields["CODE"],
str_replace(
array("#SECTION_CODE#", "#CODE#"),
array($arParams["IBLOCK_SECTION_CODE"], $fields["CODE"]),
$arParams["SCREEN_PATH_TEMPLATE_BIG"]
)
);
if($screens_big){
foreach($screens_big as $code => $val){
$arResult["ITEM"]["FIELDS"]["SCREENS"][$code]["BIG"] = $val;
}
}
$arResult["ITEM"]["PROPS"] = $props;
//
$arRevOrder = array(
"PROPERTY_MARK" => "DESC",
"PROPERTY_35" => "ASC",
"NAME" => "ASC"
);
$arRevFilter = array(
"IBLOCK_TYPE" => $arParams["REVIEWS_IBLOCK_TYPE"],
"PROPERTY_GAME_ID" => $arResult["ITEM"]["FIELDS"]["ID"],
"ACTIVE" => "Y"
);
$arRevSelect = array(
"ID", "NAME", "PROPERTY_MARK", "PROPERTY_35"
);
$db_reviews = CIBlockElement::GetList($arRevOrder, $arRevFilter, false, false,
$arRevSelect);
if($db_reviews && $db_reviews->SelectedRowsCount() > 0){
while($arReviews = $db_reviews->GetNext()){
$arResult["REVIEWS"][] = array(
"MARK" => $arReviews["PROPERTY_MARK_VALUE"],
"MAGAZINE" => $arReviews["PROPERTY_35_VALUE"],
"MAGAZINE_SORT" => $ar_enum[$arReviews["PROPERTY_35_ENUM_ID"]]["SORT"],
);
}
}
for($i=0; $i < count($arResult["REVIEWS"]); $i++)
for($j=$i+1; $j < count($arResult["REVIEWS"]); $j++)
{
if($arResult["REVIEWS"][$i]["MARK"] == $arResult["REVIEWS"][$j]["MARK"] &&
$arResult["REVIEWS"][$i]["MAGAZINE_SORT"] > $arResult["REVIEWS"][$j]["MAGAZINE_SORT"]){
$tmp = $arResult["REVIEWS"][$i];
$arResult["REVIEWS"][$i] = $arResult["REVIEWS"][$j];
$arResult["REVIEWS"][$j] = $tmp;
}
}
//
$chain_title_arr = array($arResult["ITEM"]["FIELDS"]["IBLOCK_NAME"]);
//
$db_chain = CIBlockSection::GetNavChain($arParams["IBLOCK_ID"], $arResult["ITEM"]
["FIELDS"]["IBLOCK_SECTION_ID"]);
if($db_chain -> SelectedRowsCount() > 0){
while($fetch = $db_chain->GetNext()){
$chain_title_arr[] = $fetch["NAME"];
}
}
$chain_title_arr[] = $arResult["ITEM"]["FIELDS"]["NAME"];

116

$arResult["ITEM"]["FIELDS"]["FOR_TITLE"] = implode(" ", $chain_title_arr);


$this->IncludeComponentTemplate();
}
// ,
if($arParams["SET_TITLE"]){
$APPLICATION->SetTitle($arResult["ITEM"]["FIELDS"]["FOR_TITLE"]);
}
// $GLOBALS " "
$GLOBALS["GAME_ID"] = intval($arResult["ITEM"]["FIELDS"]["ID"]);
}
catch(Exception $e)
{
//
if($no_section || $no_elem){
$arResult["NO_ITEMS"] = true;
}
$this->ClearResultCache($cache_id);
$this->AbortResultCache();
$this->IncludeComponentTemplate();
}
?>

.6. search_autocomplete
component.php
<?php
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
// $arParams
foreach($arParams as $key => $param){
if(!is_array($param)){
$arParams[$key] = trim($param);
}
else{
foreach($param as $p_key => $p_param){
$param[$p_key] = trim($p_param);
}
$arParams[$key] = $param;
}
}
// , ,
//,
if(strlen($arParams["IBLOCK_TYPE"]) <= 0){
$arParams["IBLOCK_TYPE"] = IB_TYPE_GAMES;
}
//, , , init.php PC
if(empty($arParams["IBLOCK_ID"])){
$arParams["IBLOCK_ID"] = IB_GAMES_PC;
}
//,
$arParams["CACHE_TIME"] = intval($arParams["CACHE_TIME"]);
if(intval($arParams["CACHE_TIME"]) <= 0){
$arParams["CACHE_TIME"] = CACHE_TIME;
}
//, ""
if(strlen($arParams["PROPERTY_METAMARK"]) <= 0){
$arParams["PROPERTY_METAMARK"] = MAIN_METAMARK;
}
$arParams["COUNT"] = intval($arParams["COUNT"]);
if($arParams["COUNT"] <= 0){
$arParams["COUNT"] = 10;
}
if(empty($arParams["SEARCH_PAGE"])){
$arParams["SEARCH_PAGE"] = "/search/index.php?q=#REQUEST#";
}
//
try
{
//
$arOrder = array(

117

"NAME" => "ASC",


);
//
$arFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ACTIVE" => "Y",
"NAME" => "%".$_REQUEST["q"]."%"
);
$arSelect = array(
"NAME", "PROPERTY_".MAIN_METAMARK
);
$arNavParams = array(
//"nTopCount" => 10
);
//, 10 ,
if($this->StartResultCache(60*10, $_REQUEST["q"])){
//, .
if(!CModule::IncludeModule("iblock")){
throw new Exception(GetMessage("ERROR_MODULE_NOT_INCLUDED"));
}
//
$db_element = CIBlockElement::GetList($arOrder, $arFilter, false, false, $arSelect);
// API
if(!$db_element){
throw new Exception(DB_ERROR_TEXT);
}
if($db_element->SelectedRowsCount() <= 0){
// ,
$this->AbortResultCache();
return;
}
while($fetch = $db_element->GetNext()){
$mark_color = "";
$mark = floatval($fetch["PROPERTY_".MAIN_METAMARK."_VALUE"]);
if($mark >= 75.00){
$mark_color = $arParams["MARK_75"];
}
elseif($mark >= 50.00 && $mark < 75.00){
$mark_color = $arParams["MARK_50"];
}
elseif($mark > 0.00 && $mark < 50.00){
$mark_color = $arParams["MARK_49"];
}
$arResult["ITEMS"][] = array(
"name" => $fetch["NAME"],
"mark" => $mark,
"search_page" => str_replace("#REQUEST#", urlencode($fetch["NAME"]),
$arParams["SEARCH_PAGE"]),
"mark_color" => $mark_color
);
}
// ,
for($i = 0; $i < count($arResult["ITEMS"]); $i++)
for($j = $i+1; $j < count($arResult["ITEMS"]); $j++)
{
if((mb_stripos($arResult["ITEMS"][$j]["name"], $_REQUEST["q"], 0, LANG_CHARSET) ==
0 && mb_stripos($arResult["ITEMS"][$i]["name"], $_REQUEST["q"], 0, LANG_CHARSET) != 0)){
$tmp = $arResult["ITEMS"][$i];
$arResult["ITEMS"][$i] = $arResult["ITEMS"][$j];
$arResult["ITEMS"][$j] = $tmp;
}
}
$k = 0;
$tmp = array();
foreach($arResult["ITEMS"] as $key => $item){
$word = "";
$name = $item["name"];
if($k >= $arParams["COUNT"]){
break;
}

118

//
//
$start_pos = mb_stripos($name, $_REQUEST["q"], 0, LANG_CHARSET);
$word = mb_substr($name, $start_pos, mb_strlen($_REQUEST["q"], LANG_CHARSET),
LANG_CHARSET);
//echo $word;
$name = mb_eregi_replace($word, "<b>".$word."</b>", $name);
$item["name"] = $name;
$tmp[$key] = $item;
$k++;
}
$arResult["ITEMS"] = $tmp;
$this->IncludeComponentTemplate();
}
}
catch(Exception $e)
{
//
$this->AbortResultCache();
}
?>

search_autocomplete.js
var b_enter_pressed = false;
var b_keys_pressed = false;
// ( - down).
function search_autocomplete_keydown(event)
{
if($(event.data.vars_box_id).css("display") == "none" || $(event.data.vars_box_id + "
a").size() <= 0){
return;
}
var selected_index = -1;
var next_index = 0;
var keyCode = event.keyCode;
if(keyCode == 38 || keyCode == 40){
b_keys_pressed = true;
var list = $(event.data.vars_box_id + " a").get();
for(var i=0; i < list.length; i++){
if($(list[i]).hasClass("hover")){
selected_index = i;
break;
}
}
if(keyCode == 40){
next_index = selected_index + 1;
if(next_index == list.length){
next_index = 0;
}
}
else if(keyCode == 38){
next_index = selected_index - 1;
if(next_index <= -1){
next_index = list.length - 1;
}
}
$(event.data.vars_box_id + " a").removeClass("hover");
$(list[next_index]).addClass("hover");
}
return;
}
// ( ). Enter

function search_autocomplete_keypress(event)
{
var keyCode = event.keyCode;
if(keyCode == 13){

119

if($(event.data.vars_box_id).css("display") != "none"){
//,
var b_has_link = false;
if($(event.data.vars_box_id + " a.hover").attr("title").length > 0){
set_to_search(this.id, event.data.vars_box_id, $(event.data.vars_box_id + "
a.hover").attr("title"));
b_enter_pressed = true;
return false;
}
}
}
}
// -
function search_field_focus(ob, default_value)
{
if(ob == null){
return false;
}
if(default_value.toLowerCase() == ob.value.toLowerCase()){
ob.value = "";
}
$(ob).addClass("active");
/*
if(ob.value.length > 2){
search_autocomplete(ob.name, ob.value);
}*/
}
// -
function search_field_blur(ob, default_value)
{
if(ob == null){
return false;
}
if(ob.value == "" || ob.value.toLowerCase() == default_value.toLowerCase()){
ob.value = default_value;
$(ob).removeClass("active");
}
//$("#search_variants").hide();
}
// -
function set_quick_search_text(href, input)
{
if(!href || !input){
return false;
}
input.value=$(href).attr("title");
input.className = "active";
return false;
}
//
function set_to_search(field, block, value)
{
$("#"+field).attr("value", value).addClass("active");
$(block).hide();
return false;
}
//
var tm;
var XMLHttp;
//

function search_autocomplete(field_name, current_value, count_of_items, iblock_type,
iblock_id, block_id, path_to_script)
{
//
if(tm){
clearInterval(tm);
}
if(b_enter_pressed){
b_enter_pressed = false;
return;

120

}
// AJAX-
XMLHttp = get_request_object();
if(!XMLHttp || XMLHttp.readyState != 0){
return;
}
//
XMLHttp = send_request(XMLHttp, path_to_script, "GET",
field_name+"="+current_value+"&count="+count_of_items+"&iblock_type="+iblock_type+"&iblock_id=
"+iblock_id);
if(!XMLHttp){
return;
}
//
XMLHttp.onreadystatechange = function()
{
// = 4 ( )
if(XMLHttp.readyState == 4){
// 200 ,
if(XMLHttp.status != 200){
//alert("Server response is not 200 OK. Response: " + XMLHttp.status + " " +
XMLHttp.statusText);
}
else{
//, ,
if(XMLHttp.responseText.length > 0){
$(block_id).html(XMLHttp.responseText);
$(block_id).show();
$(block_id+" a").hover(
function(){
if(!b_keys_pressed){
$(block_id +" a").removeClass("hover");
$(this).addClass("hover");
}
},
function(){
if(b_keys_pressed){
b_keys_pressed = false;
}
$(this).removeClass("hover");
}
);
}
else{
$(block_id).hide();
}
}
}
};
}
// -
function search_autocomplete_handler(event)
{
//
this.focus();
field_name = this.name;
count_of_items = event.data.count_of_items;
iblock_type = event.data.iblock_type;
iblock_id = event.data.iblock_id;
block_id = event.data.vars_block_id;
path_to_script = event.data.path;
// keyup,
if(event.type != "keyup"){
return;
}
//,
var keyCode = event.keyCode;
// ,
if((keyCode < 13 && keyCode != 8) ||
(keyCode >=14 && keyCode < 32) ||
(keyCode >= 33 && keyCode <= 46) ||

121

(keyCode >= 112 && keyCode <= 123)){


return;
}
//
current_value = this.value;
// ,
if(current_value.length < 3){
$(event.data.vars_block_id).hide();
clearInterval(tm);
return;
}
// , , ,

if(tm){
clearInterval(tm);
}
// ,
tm = setInterval("search_autocomplete(field_name, current_value, count_of_items,
iblock_type, iblock_id, block_id, path_to_script)", 200);
}

.7. reviews.list
component.php
<?php
//
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
try
{
// $arParams
prepare_params($arParams);
//
if(strlen($arParams["IBLOCK_TYPE"]) <= 0){
$arParams["IBLOCK_TYPE"] = IB_TYPE_REVIEWS;
}
if(empty($arParams["IBLOCK_ID"])){
$arParams["IBLOCK_ID"] = IB_REVIEWS_PC;
}
$arParams["GAME_ID"] = intval($arParams["GAME_ID"]);
if($arParams["GAME_ID"] <= 0){
return;
}
if(strlen($arParams["SORT_BY1"]) <= 0){
$arParams["SORT_BY1"] = "SORT";
}
if($arParams["SORT_ORDER1"] != "DESC"){
$arParams["SORT_ORDER1"] = "ASC";
}
if(strlen($arParams["SORT_BY2"]) <= 0){
$arParams["SORT_BY2"] = "ID";
}
if($arParams["SORT_ORDER2"] != "DESC"){
$arParams["SORT_ORDER2"] = "ASC";
}
$arParams["MIN_METAMARK_YELLOW"] = intval($arParams["MIN_METAMARK_YELLOW"]);
$arParams["MIN_METAMARK_GREEN"] = intval($arParams["MIN_METAMARK_GREEN"]);
if($arParams["MIN_METAMARK_YELLOW"] <= 0){
$arParams["MIN_METAMARK_YELLOW"] = 50;
}
if($arParams["MIN_METAMARK_GREEN"] <= 0){
$arParams["MIN_METAMARK_GREEN"] = 75;
}
$arParams["TRUNCATE_LEN"] = intval($arParams["TRUNCATE_LEN"]);
//
$arSortOrder = array(
$arParams["SORT_BY1"] => $arParams["SORT_ORDER1"],
$arParams["SORT_BY2"] => $arParams["SORT_ORDER2"],
"ID" => "DESC"
);

122

//
$arFilter = array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ACTIVE" => "Y",
"PROPERTY_GAME_ID" => $arParams["GAME_ID"],
);
$arSelectedFields = array(
"NAME", "ID", "DETAIL_TEXT",
"PROPERTY_MARK", "PROPERTY_GAME_ID",
"PROPERTY_35", "PROPERTY_36"
);
//
$cache_id = $arParams["GAME_ID"];
if($this->StartResultCache(false, $cache_id)){
//,
if(!CModule::IncludeModule("iblock")){
throw new Exception(GetMessage("C_MODULE_ERROR"));
}
// ""
$db_enum_list = CIBlockPropertyEnum::GetList(array("SORT" => "ASC"),
array("PROPERTY_ID" => 35));
$ar_enum = array();
while($fetch = $db_enum_list->GetNext()){
$ar_enum[$fetch["ID"]] = $fetch;
}
//
$db_element = CIBlockElement::GetList($arSortOrder, $arFilter, false, false,
$arSelectedFields);
// ,
if(!$db_element){
throw new Exception(DB_ERROR_TEXT);
}
$arResult = array(
"ITEMS" => array(),
"NO_ITEMS" => false
);
if($db_element->SelectedRowsCount() <= 0){
$arResult["NO_ITEMS"] = true;
throw new Exception();
}
// . ,

if(!empty($arParams["DETAIL_URL"])){
$db_element->SetUrlTemplates($arParams["DETAIL_URL"]);
}
//
$arResult["ENG_COUNT"] = 0;
//
$arResult["RUS_COUNT"] = 0;
while($fetch = $db_element->GetNext()){
$mark = intval($fetch["PROPERTY_MARK_VALUE"]);
$style_raiting = "";
if($mark >= $arParams["MIN_METAMARK_GREEN"]){
$style_raiting = "green";
}
elseif($mark >= $arParams["MIN_METAMARK_YELLOW"] && $mark <
$arParams["MIN_METAMARK_GREEN"]){
$style_raiting = "yellow";
}
elseif($mark > 0){
$style_raiting = "red";
}
else{
$style_raiting = "no_mark";
}
$arResult["ITEMS"][] = array(
"NAME" => $fetch["NAME"],
"DETAIL_PAGE_URL" => $fetch["DETAIL_PAGE_URL"],
"MARK" => $mark,
"PREVIEW" => strip_tags($fetch["DETAIL_TEXT"]),

123

"LINK" => $fetch["PROPERTY_36_VALUE"],


"MAGAZINE" => $fetch["PROPERTY_35_VALUE"],
"MAGAZINE_ID" => $fetch["PROPERTY_35_ENUM_ID"],
"MAGAZINE_SORT" => $ar_enum[$fetch["PROPERTY_35_ENUM_ID"]]["SORT"],
"STYLE_RAITING" => $style_raiting
);
if(in_array($fetch["PROPERTY_35_ENUM_ID"], $arParams["ENG_REVIEWS"])){
$arResult["ENG_COUNT"]++;
}
else{
$arResult["RUS_COUNT"]++;
}
}
for($k = 0; $k < count($arResult["ITEMS"]); $k++){
if($arParams["TRUNCATE_LEN"] != 0){
$arResult["ITEMS"][$k]["PREVIEW"] = TruncateText($arResult["ITEMS"][$k]
["PREVIEW"], $arParams["TRUNCATE_LEN"]);
}
}
for($i=0; $i < count($arResult["ITEMS"]); $i++)
for($j=$i+1; $j < count($arResult["ITEMS"]); $j++)
{
if($arResult["ITEMS"][$i]["MARK"] == $arResult["ITEMS"][$j]["MARK"] &&
$arResult["ITEMS"][$i]["MAGAZINE_SORT"] > $arResult["ITEMS"][$j]["MAGAZINE_SORT"]){
$tmp = $arResult["ITEMS"][$i];
$arResult["ITEMS"][$i] = $arResult["ITEMS"][$j];
$arResult["ITEMS"][$j] = $tmp;
}
}
$this->IncludeComponentTemplate();
}
}
catch(Exception $e)
{
// ,
//
$this->ClearResultCache($cache_id);
$this->AbortResultCache();
// arResult
$arResult["ERROR"] = $e->getMessage();
//
$this->IncludeComponentTemplate();
}
?>

124

. script.js (
JavaScript web-)
/**
* void restore_hash_part(string path, string result_block, string
* ajax_status_id, bool filterupped)
*
* http://site.domain#param1:value1&...,
* http://site.domain?param1=value1&...
* path AJAX, *
result_block
* string path -
* string result_block - id ,
* string ajax_status_id - id AJAX
* string filterupped - , , ,
*
*/
function restore_hash_part(path, result_block, ar_next, ajax_status_id, filterupped)
{
if(filterupped == 1){
return;
}
// URL, hash-part ,
ajax -
var location = document.location.toString();
var hash_part_pos = location.indexOf("#");
// hash-part
if(hash_part_pos != -1){
var hash_part = location.substring(hash_part_pos + 1);
var query_string = "";
var query_string_arr = new Array("ajax_request_mode=Y");
// hash_part =
var tmp = hash_part.split("&");
var flag_next = false;
for(var i in tmp){
var tmp_detail = tmp[i].split(":");
if(tmp_detail[0] == ar_next[0] && tmp_detail[1] == ar_next[1]){
flag_next = true;
}
query_string_arr.push(tmp_detail[0]+"="+tmp_detail[1]);
}
query_string = query_string_arr.join("&");
if(flag_next){
set_server_request(path, query_string, ajax_status_id, result_block,
hash_part);
}
return;
}
}
//
function pageY(elem)
{
return elem.offsetParent ?
elem.offsetTop + pageY( elem.offsetParent ) :
elem.offsetTop;
}
/** ajax- path
* query_string id = result_block,
* state_string
*/

125

function set_server_request(path, query_string, ajax_status_id, result_block,


state_string)
{
var XMLHttp = get_request_object();
if(XMLHttp.readyState == 0 || XMLHttp.readyState == 4){
XMLHttp = send_request(XMLHttp, path, "GET", query_string);
var status_block_pos = pageY(document.getElementById(result_block));
var block_top = status_block_pos;
var scroll_top = $(window).scrollTop();
if(block_top < scroll_top){
$("#"+ajax_status_id).css("top", scroll_top + 10);
}
$("#"+ajax_status_id).fadeIn();
}
XMLHttp.onreadystatechange = function(){
if(XMLHttp.readyState == 4){
if(XMLHttp.status == 200){
$("#"+result_block).html(XMLHttp.responseText);
if(state_string.length > 0){
document.location = "#"+state_string;
}
$("#"+ajax_status_id).hide();
}
}
}
}
/** array ajax_state_string(string url, array exclude_array)
* url
* ajax- ( 0 ) *
( 1 )
* exclude_array ,
*
*/
function ajax_state_string(url, exclude_array)
{
if(url == undefined || url.length <= 0){
return false;
}
if(url.indexOf("?") == -1){
return url;
}
var query_string_arr = new Array("ajax_request_mode=Y");
var query_string = "";
var state_string_arr = new Array();
var state_string = "";
var q_string;
if(url.lastIndexOf("#") != -1){
q_string = url.substring(url.indexOf("?") + 1, url.lastIndexOf("#"));
}
else{
q_string = url.substring(url.indexOf("?") + 1);
}
var q_pairs = q_string.split("&");
var q_pair;
var not_in_list = false;
var filterupped = false;
for(var i in q_pairs){
not_in_list = false;
q_pair = q_pairs[i].split("=");
if(q_pair[0] == "filter"){
filterupped = true;
}
for(var j = 0; j < exclude_array.length; j++){
if(exclude_array[j] == q_pair[0]){

126

not_in_list = true;
break;
}
}
if(not_in_list){
continue;
}
query_string_arr.push(q_pair[0]+"="+decodeURIComponent(q_pair[1]));
if(q_pair[0] != "ajax_request_mode"){
state_string_arr.push(q_pair[0]+":"+q_pair[1]);
}

}
if(!filterupped){
query_string_arr.push("filter=up");
state_string_arr.push("filter:up");
}
query_string = query_string_arr.join("&");
state_string = state_string_arr.join("&");
return new Array(query_string, state_string);

}
/**
* ,
*/
$(function(){
$("#signin-show-box").bind("click", function()
{
$(".auth-box").show();
$("#mark-select-box").hide();
$("#genre-select-box").hide();
$("#detail-date-from-select-box").hide();
$("#detail-date-to-select-box").hide();
$("#date-select-box").hide();
return false;
});
$(".auth-box").bind("click", function()
{
$(".auth-box").show();
return false;
});
$(document).bind("click", function(event)
{
$("#genre-select-box").hide();
var obj = event.target;
k = 0;
var date_select_box_flag = false;
var mark_select_box_flag = false;
while($(obj).attr("id") != undefined){
if($(obj).attr("id") == "date-select-box"){
$("#detail-date-from-select-box").hide();
$("#detail-date-to-select-box").hide();
date_select_box_flag = true;
break;
}
if($(obj).attr("id") == "mark-select-box"){
mark_select_box_flag = true;
}
obj = $(obj).parent();
k++;
//if(k > 100) break;
}
if(!mark_select_box_flag){
$("#mark-select-box").hide();
}
if(!date_select_box_flag){

127

$("#date-select-box").hide();
}
$(".auth-box").hide();
if(!event.target.id || event.target.id != "search_q"){
$("#search_variants").hide();
}
if(!event.target.id || event.target.id != "search_q_main"){
$("#search_variants_main").hide();
}
});});

128

. init.php
<?php
CPageOption::SetOptionString("main", "nav_page_in_session", "N");
/**
* bool write_access_log(string filepath) -

* @param string filepath - ,
* @return true , false
*/
function write_access_log($filepath)
{
if(SITE_SERVER_NAME == ""){
return false;
}
global $APPLICATION;
// URL ,
$current_uri = "http://".SITE_SERVER_NAME.ToLower(
$APPLICATION->GetCurPageParam("", array(), true));
//$filepath = $_SERVER["DOCUMENT_ROOT"]."/".$filepath;
//, , URL
$can_write = true;
//
if(@file_exists($filepath)){
$fp_read = @fopen($filepath, "r");
if(!$fp_read){
fclose($fp_read);
return false;
}
//
while(!feof($fp_read)){
$exist_link = trim(fgets($fp_read));
// URL ,
if(strcasecmp($exist_link, $current_uri) == 0){
$can_write = false;
break;
}
}
fclose($fp_read);
}
// URL
if($can_write){
if(@file_exists($filepath)){
//
$fp_append = @fopen($filepath, "a");
if(filesize($filepath) > 0){
$str = PHP_EOL.$current_uri;
}
else{
$str = $current_uri;
}
}
else{
//
$fp_append = @fopen($filepath, "w");
$str = $current_uri;
}
fwrite($fp_append, $str);
fclose($fp_append);
}
return true;
}

129

write_access_log($_SERVER["DOCUMENT_ROOT"]."/access_log.log");
/**
* ,

*/
/**
* ""
*/
define("IB_TYPE_GAMES", "ib_games");
/**
* ""
*/
define("IB_TYPE_REVIEWS", "ib_reviews");
/**
* "" => ""
*/
define("IB_GAMES_PC", 1);
/**
* "" => ""
*/
define("IB_REVIEWS_PC", 2);
/**
* ,
"" ""
*/
/**
* "" ""
*/
define("REVIEWS_PC_PROP_GAME", "GAME_ID");
/**
* "" ""
*/
define("GAMES_PC_PROP_METAMARK", "MAIN_METAMARK");
/**
* "" ""
*/
define("REVIEWS_PC_PROP_MARK", "MARK");
/**
* , AddMessage2Log
*/
define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/init.log");
/**
*
*/
define("DB_ERROR_TEXT", " ");
/**
*/
define("CACHE_TIME", 3600);
/**
*
*/
define("MIN_METAMARK_GREEN", 75);
define("MIN_METAMARK_YELLOW", 50);
/**
* , -
*/
define("AJAX_REQUEST_MODE_PARAM", "ajax_request_mode");
//
$arMonthNames = array(
1 => array("month" => "", "month_a" => ""),
2 => array("month" => "", "month_a" => ""),

130

3 => array("month" => "", "month_a" => ""),


4 => array("month" => "", "month_a" => ""),
5 => array("month" => "", "month_a" => ""),
6 => array("month" => "", "month_a" => ""),
7 => array("month" => "", "month_a" => ""),
8 => array("month" => "", "month_a" => ""),
9 => array("month" => "", "month_a" => ""),
10 => array("month" => "", "month_a" => ""),
11 => array("month" => "", "month_a" => ""),
12 => array("month" => "", "month_a" => "")
);
// " "
CModule::IncludeModule("iblock");
//
AddEventHandler("iblock", "OnAfterIblockElementAdd", "add_review_handler");
AddEventHandler("iblock", "OnAfterIblockElementUpdate", "add_review_handler");
AddEventHandler("iblock", "OnBeforeIblockElementDelete", "delete_review_handler");
AddEventHandler("iblock", "onBeforeIblockElementAdd", "check_element_code");
AddEventHandler("iblock", "onBeforeIblockElementUpdate", "check_element_code");
/**
* bool delete_review_handler(int ID) -
"" => "PC"
* @author dda
* @param int ID
* @return true , false
*/
function delete_review_handler($ID)
{
AddMessage2Log(" delete_review_handler
OnAfterIblockElementDelete\n");
$db_current_element = CIBlockElement::GetByID($ID);
$ob_current_element = $db_current_element->GetNextElement();
//
$arFields = $ob_current_element->GetFields();
//
$arProperties = $ob_current_element->GetProperties();
// ""
// ,
if($arFields["IBLOCK_ID"] != IB_REVIEWS_PC){
AddMessage2Log(" . - \n");
//return $arFields;
return true;
}
//
if(!array_key_exists(REVIEWS_PC_PROP_GAME, $arProperties)){
return false;
}
$game_id = intval($arProperties[REVIEWS_PC_PROP_GAME]["VALUE"]);
//, ID=$game_id , ,
$db_game_check = CIBlockElement::GetByID($game_id);
if($db_game_check->SelectedRowsCount() <= 0){
AddMessage2Log(" . ID=".$game_id);
return false;
}
// ID=$game_id
$review_filter = array(
"PROPERTY_".REVIEWS_PC_PROP_GAME => $game_id
);
$review_select = array(
"PROPERTY_".REVIEWS_PC_PROP_MARK,
);

131

$db_reviews_exists = CIBlockElement::GetList(array(), $review_filter, false,


false, $review_select);
//
$summ_mark_for_game = 0 - $arProperties[REVIEWS_PC_PROP_MARK]["VALUE"];
while($ar_reviews_exists =$db_reviews_exists->GetNext()){
$summ_mark_for_game +=
$ar_reviews_exists["PROPERTY_".REVIEWS_PC_PROP_MARK."_VALUE"];
}
// GAMES_PC_PROP_METAMARK
ID=$game_id
$average = round($summ_mark_for_game/($db_reviews_exists->SelectedRowsCount() 1));
CIBlockElement::SetPropertyValueCode($game_id, GAMES_PC_PROP_METAMARK, $average);
#------- 4,5
AddMessage2Log(" . ID=".$game_id."
".GAMES_PC_PROP_METAMARK." ".$average."\n");
return true;
}
/** bool check_element_code(array &arFields)
* - .

* @param array arFields - .
* @return true, false,
*/
function check_element_code(&$arFields)
{
global $APPLICATION;
if(!eregi("^[a-zA-Z0-9_]+$", $arFields["CODE"])){
$APPLICATION->throwException("
, \"_\"");
return false;
}
return true;
}
/**
* void add_review_handler(array &arFields) -
"" => "PC"
* @author dda
* @param array arFields ( ).

* @return
*/
function add_review_handler(&$arFields)
{
AddMessage2Log(" add_review_handler
OnAfterIblockElementAdd(Update)\n");
// ""
// ,
if($arFields["IBLOCK_ID"] != IB_REVIEWS_PC){
return;
}
//,
if($arFields["ID"] > 0 && empty($arFields["RESULT_MESSAGE"])){
//
$db_prop = CIBlockElement::GetProperty($arFields["IBLOCK_ID"],
$arFields["ID"], array(), array("CODE" => REVIEWS_PC_PROP_GAME));
if($db_prop->SelectedRowsCount() <= 0){
AddMessage2Log(" .
".REVIEWS_PC_PROP_GAME."\n");
return;
}
$fetch = $db_prop->GetNext();
$game_id = intval($fetch["VALUE"]);
//, ID=$game_id , ,

132

$db_game_check = CIBlockElement::GetByID($game_id);
if($db_game_check->SelectedRowsCount() <= 0){
AddMessage2Log(" . ID=".
$game_id);
return;
}
// ID=$game_id
$review_filter = array(
"PROPERTY_".REVIEWS_PC_PROP_GAME => $game_id
);
$review_select = array(
"PROPERTY_".REVIEWS_PC_PROP_MARK,
);
$db_reviews_exists = CIBlockElement::GetList(array(), $review_filter, false,
false, $review_select);
//
$summ_mark_for_game = 0;
while($ar_reviews_exists =$db_reviews_exists->GetNext()){
$summ_mark_for_game +=
$ar_reviews_exists["PROPERTY_".REVIEWS_PC_PROP_MARK."_VALUE"];
}
// GAMES_PC_PROP_METAMARK
ID=$game_id
$average = round($summ_mark_for_game/$db_reviews_exists>SelectedRowsCount());
CIBlockElement::SetPropertyValueCode($game_id, GAMES_PC_PROP_METAMARK,
$average);
AddMessage2Log(" . ID=".$game_id."
".GAMES_PC_PROP_METAMARK." ".$average."\n");
}
}
/**
* array get_iblock_type_list(array ar_sort) -

* @author dda
* @param array ar_sort - ("_" => "_"),
,
* @return array ar_iblock_type -
*/
function get_iblock_type_list($ar_sort)
{
$db_iblock_type = CIBlockType::GetList(array("NAME" => "ASC"));
$ar_iblock_type = array();
while($fetch = $db_iblock_type->GetNext()){
if($fetch_lang = CIBlockType::GetByIDLang($fetch["ID"], LANG)){
$ar_iblock_type[$fetch_lang["ID"]] = "[".$fetch_lang["ID"]."] ".
$fetch_lang["NAME"];
}
}
return $ar_iblock_type;
}
/**
* array get_iblock_list(string type_id, array ar_sort, bool bActive = true) -
type_id
* @author dda
* @param string type_id - ()
* @param array ar_sort - ("_" => "_"),
,
* @param bool bActive - , , .
, true, ..
* @return array ar_iblock -
*/
function get_iblock_list($type_id, $ar_sort, $bActive = true, $field = "ID")
{

133

$arFilter = array(
"TYPE" => $type_id,
);
if($bActive){
$arFilter["ACTIVE"] = "Y";
}
$db_iblock = CIBlock::GetList($ar_sort, $arFilter);
$ar_iblock = array();
while($fetch = $db_iblock->GetNext()){
$ar_iblock[$fetch[$field]] = "[".$fetch[$field]."] ".$fetch["NAME"];
}
return $ar_iblock;
}
/**
* void prepare_params(&arParams)
* $arParams, component.php
( , ..)
* @author dda
* @param arParams - ,
* @return
*/
function prepare_params(&$arParams)
{
foreach($arParams as $key => $param){
if(!is_array($param)){
$arParams[$key] = trim($param);
}
else{
foreach($param as $p_key => $p_param){
$param[$p_key] = trim($p_param);
}
$arParams[$key] = $param;
}
}
}
/**
* bool is_ajax_request()
* , ajax-
* @return true , ajax- false

*/
function is_ajax_request()
{
return (isset($_REQUEST[AJAX_REQUEST_MODE_PARAM]) &&
$_REQUEST[AJAX_REQUEST_MODE_PARAM] == "Y");
}
/**
* string get_ajax_param()
* , ajax
*/
function get_ajax_param()
{
return defined(AJAX_REQUEST_MODE_PARAM) ? AJAX_REQUEST_MODE_PARAM :
"ajax_request_mode";
}
/** array get_parts_reg(string value[,string pattern]) -
<> []
* false
* @param string value - ,
* @param string pattern - . , - "/\
[\b(\d+)(.)\]/i"
*/
function get_parts_reg($value, $pattern = "/\[\b(\d+)(.)\]/i")

134

//
$skob_pos = mb_strpos($value, "[", 0, LANG_CHARSET);
// ,
if($skob_pos === false){
return false;
}
// 2 -
$text = trim(mb_substr($value, 0, $skob_pos, LANG_CHARSET));
$val = trim(mb_substr($value, $skob_pos, (mb_strlen($value, LANG_CHARSET) mb_strlen($text, LANG_CHARSET)), LANG_CHARSET));
// -
if(!preg_match($pattern, $val, $matches)){
return false;
}
return array("matches" => $matches, "text" => $text);
}
/** int get_max_day(int month, int year) -

* @param int current_month -
* @param int current_year -
* @return
*/
function get_max_day($current_month, $current_year)
{
if($current_month == 2){
if($_REQUEST["year"] % 4 == 0){
$top_day = 29;
}
else{
$top_day = 28;
}
}
elseif($current_month < 8){
if($current_month % 2 == 0){
$top_day = 30;
}
else{
$top_day = 31;
}
}
elseif($current_month >= 8){
if($current_month % 2 != 0){
$top_day = 30;
}
else{
$top_day = 31;
}
}
return $top_day;
}
?>

135