Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1084311
tag-class.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 6, 11:08 AM
Size
13 KB
Mime Type
text/x-php
Expires
Fri, Aug 8, 11:08 AM (2 h, 14 m)
Engine
blob
Format
Raw Data
Handle
704319
Attached To
rINP In-Portal
tag-class.php
View Options
<?php
class
clsAttribute
extends
clsItemDB
{
/* var $name;
var $default;
var $description;
var $required;
*/
function
clsAttribute
(
$id
=
NULL
)
{
$this
->
clsItemDB
();
$this
->
tablename
=
GetTablePrefix
().
"TagAttributes"
;
$this
->
id_field
=
"AttrId"
;
$this
->
type
=-
99
;
$this
->
NoResourceId
=
1
;
}
function
LoadFromDatabase
(
$Id
)
{
global
$objSession
,
$Errors
;
if
(!
isset
(
$Id
))
{
$Errors
->
AddError
(
"error.AppError"
,
NULL
,
'Internal error: LoadFromDatabase id'
,
""
,
get_class
(
$this
),
"LoadFromDatabase"
);
return
false
;
}
$sql
=
sprintf
(
"SELECT * FROM "
.
$this
->
tablename
.
" WHERE "
.
$this
->
id_field
.
" = '%s'"
,
$Id
);
$result
=
$this
->
adodbConnection
->
Execute
(
$sql
);
if
(
$result
===
false
)
{
$Errors
->
AddError
(
"error.DatabaseError"
,
NULL
,
$this
->
adodbConnection
->
ErrorMsg
(),
""
,
get_class
(
$this
),
"LoadFromDatabase"
);
return
false
;
}
$data
=
$result
->
fields
;
if
(
is_array
(
$data
))
$this
->
SetFromArray
(
$data
);
$this
->
Clean
();
return
TRUE
;
}
function
Write
(
$value
)
{
$ret
=
$name
.
"=
\"
$value
\"
"
;
return
$ret
;
}
}
class
clsTagAttribs
extends
clsItemCollection
{
function
clsTagAttribs
(
$TagId
=
NULL
)
{
$this
->
clsItemCollection
();
$this
->
SourceTable
=
GetTablePrefix
().
"TagAttributes"
;
$this
->
classname
=
"clsAttribute"
;
if
(
$TagId
)
$this
->
LoadTag
(
$TagId
);
}
function
LoadTag
(
$TagId
)
{
$sql
=
"SELECT * FROM "
.
$this
->
SourceTable
.
" WHERE TagId=$TagId"
;
$this
->
Query_Item
(
$sql
);
}
}
class
clsTagFunction
extends
clsItemDB
{
var
$attribs
;
function
clsTagFunction
()
{
$this
->
clsItemDB
();
$this
->
tablename
=
GetTablePrefix
().
"TagLibrary"
;
$this
->
id_field
=
"TagId"
;
$this
->
type
=-
99
;
$this
->
NoResourceId
=
1
;
$this
->
attribs
=
new
clsTagAttribs
();
}
function
LoadAttribs
()
{
if
(
$this
->
attribs
->
NumItems
()<
1
)
{
$this
->
attribs
->
LoadTag
(
$this
->
Get
(
"TagId"
));
}
}
function
AddAttribute
(
$name
,
$Type
=
"str"
,
$desc
=
""
,
$default
=
""
,
$required
=
FALSE
)
{
if
(
$this
->
attribs
->
NumItems
()<
1
)
$this
->
attribs
->
LoadTag
(
$this
->
Get
(
"TagId"
));
$a
=
$this
->
attribs
->
GetItemByField
(
"Name"
,
$name
,
FALSE
);
if
(!
is_object
(
$a
))
{
$a
=
new
clsAttribute
();
$a
->
Set
(
"TagId"
,
$this
->
Get
(
"TagId"
));
$a
->
Set
(
"Name"
,
$name
);
$a
->
Set
(
"AttrType"
,
$Type
);
$a
->
Set
(
"DefValue"
,
$default
);
$a
->
Set
(
"Description"
,
$desc
);
$a
->
Set
(
"Required"
,
$required
);
$a
->
Create
();
}
else
{
if
(
$a
->
Get
(
"Name"
)!=
$name
)
{
$a
=
new
clsAttribute
();
$a
->
Set
(
"TagId"
,
$this
->
Get
(
"TagId"
));
$a
->
Set
(
"Name"
,
$name
);
$a
->
Set
(
"AttrType"
,
$Type
);
$a
->
Set
(
"DefValue"
,
$default
);
$a
->
Set
(
"Description"
,
$desc
);
$a
->
Set
(
"Required"
,
$required
);
$a
->
Create
();
}
else
{
$a
->
Set
(
"TagId"
,
$this
->
Get
(
"TagId"
));
$a
->
Set
(
"Name"
,
$name
);
$a
->
Set
(
"AttrType"
,
$Type
);
$a
->
Set
(
"DefValue"
,
$default
);
$a
->
Set
(
"Description"
,
$desc
);
$a
->
Set
(
"Required"
,
$required
);
$a
->
Update
();
}
}
$this
->
attribs
->
Items
[]
=&
$a
;
}
function
LoadFromDatabase
(
$Id
)
{
global
$objSession
,
$Errors
;
if
(!
isset
(
$Id
))
{
$Errors
->
AddError
(
"error.AppError"
,
NULL
,
'Internal error: LoadFromDatabase id'
,
""
,
get_class
(
$this
),
"LoadFromDatabase"
);
return
false
;
}
$sql
=
sprintf
(
"SELECT * FROM "
.
$this
->
tablename
.
" WHERE "
.
$this
->
id_field
.
" = '%s'"
,
$Id
);
$result
=
$this
->
adodbConnection
->
Execute
(
$sql
);
if
(
$result
===
false
)
{
$Errors
->
AddError
(
"error.DatabaseError"
,
NULL
,
$this
->
adodbConnection
->
ErrorMsg
(),
""
,
get_class
(
$this
),
"LoadFromDatabase"
);
return
false
;
}
$data
=
$result
->
fields
;
if
(
is_array
(
$data
))
$this
->
SetFromArray
(
$data
);
$this
->
attribs
->
LoadTag
(
$this
->
Get
(
"TagId"
));
$this
->
Clean
();
return
TRUE
;
}
}
class
clsTagList
extends
clsItemCollection
{
function
clsTagList
()
{
$this
->
clsItemCollection
();
$this
->
SourceTable
=
GetTablePrefix
().
"TagLibrary"
;
$this
->
classname
=
"clsTagFunction"
;
//$this->tags = array();
}
function
DeleteTags
()
{
$this
->
adodbConnection
->
Execute
(
"DELETE FROM "
.
$this
->
SourceTable
);
$this
->
adodbConnection
->
Execute
(
"DELETE FROM "
.
GetTablePrefix
().
"TagAttributes"
);
}
function
FindStr
(
$code
,
$str
,
$offset
,
$limit
=
0
)
{
$x
=
$offset
;
$found
=
FALSE
;
while
(
$x
<
count
(
$code
)
&&
!
$found
&&
(
$x
<
$limit
||
$limit
==
0
))
{
$found
=
(
strpos
(
$code
[
$x
],
$str
)!==
false
);
if
(!
$found
)
$x
++;
}
if
(
$found
)
return
$x
;
return
""
;
}
function
GetTagName
(
$func
)
{
$f
=
explode
(
" "
,
$func
);
//echo "$func:<PRE>";print_r($f); echo "</PRE>";
$fname
=
$f
[
1
];
$fname
=
substr
(
$fname
,
0
,
strpos
(
$fname
,
"("
));
return
$fname
;
}
function
ParseComments
(
$name
,
$code
)
{
//echo "function $name:<br>\n";
$data
=
array
();
$attribs
=
array
();
$field
=
''
;
for
(
$l
=
0
;
$l
<
count
(
$code
);
$l
++)
{
$attr_default_val
=
''
;
$line
=
trim
(
$code
[
$l
]);
if
(
substr
(
$line
,
0
,
1
)
==
'@'
)
{
if
(
substr
(
$line
,
1
,
6
)
==
'attrib'
)
{
$field
=
'attrib'
;
$line
=
trim
(
substr
(
$line
,
8
)
);
$parts
=
explode
(
':'
,
$line
,
3
);
if
(
strpos
(
$parts
[
0
],
'='
)
>
0
)
{
$p
=
explode
(
$parts
[
0
],
'='
,
2
);
$attr
=
$p
[
0
];
$attr_default_val
=
$p
[
1
];
}
else
{
$attr
=
$parts
[
0
];
$attr_default
=
''
;
}
if
(
count
(
$parts
)
==
3
)
{
$atype
=
$parts
[
1
];
$attr_desc
=
$parts
[
2
];
}
else
{
$attr_desc
=
$parts
[
1
];
$atype
=
''
;
}
$attribs
[
$attr
]
=
$attr_desc
;
$attr_default
[
$attr
]
=
$attr_default_val
;
$attr_type
[
$attr
]
=
$atype
;
}
else
{
$parts
=
explode
(
':'
,
$line
,
2
);
$field
=
strtolower
(
substr
(
$parts
[
0
],
1
)
);
$data
[
$field
]
=
htmlentities
(
$parts
[
1
]);
}
}
else
{
if
(
substr
(
$line
,
0
,
2
)!=
"*/"
)
{
if
(
strlen
(
$field
))
{
if
(
$field
==
"attrib"
)
{
$attribs
[
$attr
]
.=
$line
;
}
else
$data
[
$field
]
.=
$line
;
}
}
}
}
if
(
strlen
(
$name
)>
0
)
{
$data
[
"name"
]
=
$name
;
$data
[
"scope"
]=
"global"
;
}
else
{
if
(
isset
(
$data
[
"field"
])
)
// process something, but don't work
{
$field
=
$data
[
"field"
];
$fparts
=
explode
(
"."
,
$field
,
2
);
$data
[
"name"
]=
$fparts
[
1
];
$data
[
"scope"
]=
$fparts
[
0
];
unset
(
$data
[
"field"
]);
}
}
$t
=&
$this
->
AddItemFromArray
(
$data
);
//echo "<PRE>";print_r($data); echo "</PRE>";
$t
->
Dirty
();
if
(
strlen
(
$t
->
get
(
"name"
))>
0
&&
strlen
(
$t
->
Get
(
"description"
))>
0
)
{
$t
->
Create
();
if
(
count
(
$attribs
)>
0
)
{
foreach
(
$attribs
as
$field
=>
$desc
)
{
$req
=
(
substr
(
$field
,
0
,
1
)==
"*"
);
$t
->
AddAttribute
(
$field
,
getArrayValue
(
$attr_type
,
$field
),
$desc
,
getArrayValue
(
$attr_default
,
$field
),
$req
);
}
}
}
}
function
ParseFile
(
$file
)
{
$code
=
file
(
$file
);
//echo count($code)." lines<br>\n";
if
(
count
(
$code
))
{
$funcline
=
$this
->
FindStr
(
$code
,
"function "
,
0
);
//echo "First function $funcline :".$code[$funcline];
while
(
is_numeric
(
$funcline
)
&&
$funcline
<
count
(
$code
))
{
$TagName
=
""
;
$TagName
=
$this
->
GetTagName
(
$code
[
$funcline
]);
//echo "Parsing function $TagName <br>\n";
$comment_start
=
$funcline
-
1
;
$temp
=
$code
[
$funcline
-
1
];
while
((
$comment_start
>
0
)
&&
(
substr
(
$temp
,
0
,
1
)
!=
"}"
))
{
$comment_start
--;
$temp
=
$code
[
$comment_start
];
}
//echo "Comment Start: $comment_start End: $funcline<br>\n";
if
(
substr
(
$code
[
$comment_start
],
0
,
1
)==
"}"
)
$comment_start
++;
$x
=
$comment_start
;
$comments
=
array
();
while
(
$x
<
$funcline
)
{
$comments
[]
=
$code
[
$x
];
$x
++;
}
$this
->
ParseComments
(
$TagName
,
$comments
);
$funcline
=
$this
->
FindStr
(
$code
,
"function "
,
$funcline
+
1
);
}
}
}
function
ParseItemFile
(
$file
)
{
$code
=
file
(
$file
);
if
(
count
(
$code
))
{
$funcline
=
$this
->
FindStr
(
$code
,
"function ParseObject("
,
0
);
if
(
$funcline
>
0
)
{
$nextfunc
=
$this
->
FindStr
(
$code
,
"function "
,
$funcline
+
1
);
if
(
$nextfunc
==
0
)
$nextfunc
=
count
(
code
);
$comment_line
=
$this
->
FindStr
(
$code
,
"/*"
,
$funcline
,
$nextfunc
);
while
(
is_numeric
(
$comment_line
))
{
$end_comment
=
$this
->
FindStr
(
$code
,
"*/"
,
$comment_line
+
1
,
$nextfunc
);
if
(
is_numeric
(
$end_comment
))
{
$x
=
$comment_line
+
1
;
$comments
=
array
();
while
(
$x
<
$end_comment
)
{
$comments
[]
=
$code
[
$x
];
$x
++;
}
$this
->
ParseComments
(
""
,
$comments
);
//echo "<PRE>";print_r($comments);echo "</PRE>";
unset
(
$comments
);
$comment_line
=
$this
->
FindStr
(
$code
,
"/*"
,
$end_comment
+
1
,
$nextfunc
);
}
else
$comment_line
=
""
;
}
}
}
}
function
LoadGlobalTags
()
{
$this
->
Clear
();
$this
->
Query_Item
(
"SELECT * FROM "
.
$this
->
SourceTable
);
for
(
$i
=
0
;
$i
<
$this
->
NumItems
();
$i
++)
{
$this
->
Items
[
$i
]->
LoadAttribs
();
}
}
function
ParseInportalTags
()
{
global
$ParserFiles
,
$ItemTagFiles
,
$pathtoroot
;
$this
->
DeleteTags
();
$t
=
new
clsTagFunction
();
$t
->
Set
(
"name"
,
"include"
);
$t
->
Set
(
"description"
,
"insert template output into the current template"
);
$t
->
Create
();
$t
->
AddAttribute
(
"_template"
,
"tpl"
,
"Template to insert"
,
""
,
TRUE
);
$t
->
AddAttribute
(
"_supresserror"
,
"bool"
,
"Supress missing template errors"
,
""
,
FALSE
);
unset
(
$t
);
$t
=
new
clsTagFunction
();
$t
->
Set
(
"name"
,
"perm_include"
);
$t
->
Set
(
"description"
,
"insert template output into the current template if permissions are set"
);
$t
->
Create
();
$t
->
AddAttribute
(
"_template"
,
"tpl"
,
"Template to insert"
,
""
,
TRUE
);
$t
->
AddAttribute
(
"_noaccess"
,
"tpl"
,
"Template to insert if access is denied"
,
""
,
FALSE
);
$t
->
AddAttribute
(
"_permission"
,
""
,
"Comma-separated list of permissions, any of which will grant access"
,
""
,
FALSE
);
$t
->
AddAttribute
(
"_module"
,
""
,
"Used in place of the _permission attribute, this attribute verifies the module listed is enabled"
,
""
,
FALSE
);
$t
->
AddAttribute
(
"_system"
,
"bool"
,
"Must be set to true if any permissions in _permission list is a system permission"
,
""
,
FALSE
);
$t
->
AddAttribute
(
"_supresserror"
,
"bool"
,
"Supress missing template errors"
,
""
,
FALSE
);
unset
(
$t
);
$t
=
new
clsTagFunction
();
$t
->
Set
(
"name"
,
"mod_include"
);
$t
->
Set
(
"description"
,
"insert templates from all enabled modules. No error occurs if the template does not exist."
);
$t
->
Create
();
$t
->
AddAttribute
(
"_template"
,
"tpl"
,
"Template to insert. This template path should be relative to the module template root directory"
,
""
,
TRUE
);
$t
->
AddAttribute
(
"_modules"
,
""
,
"Comma-separated list of modules. Defaults to all enabled modules if not set"
,
""
,
FALSE
);
unset
(
$t
);
$t
=
new
clsTagFunction
();
$t
->
Set
(
"name"
,
"lang_include"
);
$t
->
Set
(
"description"
,
"Include a template based on the current language"
);
$t
->
Create
();
$t
->
AddAttribute
(
"_template"
,
"tpl"
,
"Template to insert. This template path should be relative to the module template root directory"
,
""
,
TRUE
);
$t
->
AddAttribute
(
"_language"
,
""
,
"Pack name of language"
,
""
,
FALSE
);
unset
(
$t
);
if
(
is_array
(
$ParserFiles
))
{
foreach
(
$ParserFiles
as
$file
)
{
$this
->
ParseFile
(
$pathtoroot
.
$file
);
}
}
if
(
is_array
(
$ItemTagFiles
))
{
foreach
(
$ItemTagFiles
as
$file
)
{
$this
->
ParseItemFile
(
$pathtoroot
.
$file
);
}
}
}
}
Event Timeline
Log In to Comment