Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pquery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pquery
Commits
232df72c
Commit
232df72c
authored
Nov 05, 2011
by
Taddes Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added base of template parser.
parent
2198131d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
17 deletions
+119
-17
index.php
index.php
+8
-7
pquery.array.php
pquery.array.php
+1
-1
pquery.php
pquery.php
+14
-6
pquery.sql.php
pquery.sql.php
+3
-3
pquery.template.php
pquery.template.php
+93
-0
No files found.
index.php
View file @
232df72c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
include_once
'../debug.php'
;
include_once
'../debug.php'
;
include_once
'pquery.php'
;
include_once
'pquery.php'
;
__p
::
require_plugins
(
'array'
,
'sql'
);
__p
::
require_plugins
(
'array'
,
'sql'
,
'template'
);
// Array test
// Array test
/*$a = _p(range(0, 10));
/*$a = _p(range(0, 10));
...
@@ -11,16 +11,17 @@ while( !$a->is_empty() ) {
...
@@ -11,16 +11,17 @@ while( !$a->is_empty() ) {
debug($a->pop(), $a->reverse()->pop());
debug($a->pop(), $a->reverse()->pop());
}*/
}*/
echo
'<br><br>'
;
// SQL test
// SQL test
$sql
=
_sql
(
"select * from posts where slug = '[slug]'"
)
/*
$sql = _sql("select * from posts where slug = '[slug]'")
->set(array('slug' => 'contact'));
->set(array('slug' => 'contact'));
$results = $sql->fetch_all('object');
$results = $sql->fetch_all('object');
$results = _arr($results);
$results = _arr($results);
debug
(
$results
);
debug($results);*/
__tpl
::
set_root
(
'templates'
);
$tpl
=
_tpl
(
'test.tpl'
);
debug
(
$tpl
->
content
);
?>
?>
\ No newline at end of file
pquery.array.php
View file @
232df72c
...
@@ -51,7 +51,7 @@ class pQueryArray extends pQuery implements pQueryExtension {
...
@@ -51,7 +51,7 @@ class pQueryArray extends pQuery implements pQueryExtension {
* @see pQuerySql::__construct
* @see pQuerySql::__construct
*/
*/
function
_arr
(
$array
)
{
function
_arr
(
$array
)
{
return
pQuery
::
create
(
'
pQueryA
rray'
,
$array
);
return
pQuery
::
create
(
'
a
rray'
,
$array
);
}
}
pQuery
::
extend
(
'pQueryArray'
,
'array'
);
pQuery
::
extend
(
'pQueryArray'
,
'array'
);
...
...
pquery.php
View file @
232df72c
...
@@ -113,11 +113,11 @@ class pQuery {
...
@@ -113,11 +113,11 @@ class pQuery {
*
*
* @param string $error The error message to display.
* @param string $error The error message to display.
*/
*/
static
function
error
(
$error
/*, $arg1, $arg2...
*/
)
{
static
function
error
(
$error
/* , $arg1, $arg2...
*/
)
{
$args
=
func_get_args
();
$args
=
func_get_args
();
if
(
DEBUG
)
{
if
(
DEBUG
)
{
call_user_func_array
(
'printf'
,
$args
);
echo
nl2br
(
call_user_func_array
(
'sprintf'
,
$args
)
);
//echo debug_backtrace();
//echo debug_backtrace();
}
}
...
@@ -132,12 +132,20 @@ class pQuery {
...
@@ -132,12 +132,20 @@ class pQuery {
*/
*/
static
function
create
()
{
static
function
create
()
{
$args
=
func_get_args
();
$args
=
func_get_args
();
$class_name
=
array_shift
(
$args
);
$plugin
=
array_shift
(
$args
);
$obj
=
$class_name
===
null
?
new
self
()
:
new
$class_name
();
$variable
=
array_shift
(
$args
);
if
(
$plugin
===
null
)
$class_name
=
'self'
;
elseif
(
isset
(
self
::
$plugins
[
$plugin
])
)
$class_name
=
self
::
$plugins
[
$plugin
];
elseif
(
in_array
(
$plugin
,
self
::
$plugins
)
)
$class_name
=
$plugin
;
else
return
self
::
error
(
'Plugin "%s" does not exist.'
,
$plugin
);
$obj
=
new
$class_name
();
$obj
->
arguments
=
$args
;
$obj
->
arguments
=
$args
;
$obj
->
set_variable
(
$variable
);
$obj
->
set_variable
(
array_shift
(
$args
)
);
return
$obj
;
return
$obj
;
}
}
...
...
pquery.sql.php
View file @
232df72c
...
@@ -236,13 +236,13 @@ class pQuerySql extends pQuery implements pQueryExtension {
...
@@ -236,13 +236,13 @@ class pQuerySql extends pQuery implements pQueryExtension {
/**
/**
* Shortcut constructor for {@link pQuerySql}.
* Shortcut constructor for {@link pQuerySql}.
*
*
* @
returns pQuerySql A new pQuerySql instanc
e.
* @
param string $query A MySQL query to evaluat
e.
* @
see pQuerySql::__construct
* @
returns pQuerySql A new SQL query instance.
*/
*/
function
_sql
(
$query
/* [ , $arg1, ... ] */
)
{
function
_sql
(
$query
/* [ , $arg1, ... ] */
)
{
$args
=
func_get_args
();
$args
=
func_get_args
();
$query
=
array_shift
(
$args
);
$query
=
array_shift
(
$args
);
array_unshift
(
$args
,
'
pQueryS
ql'
,
$query
);
array_unshift
(
$args
,
'
s
ql'
,
$query
);
return
call_user_func_array
(
'pQuery::create'
,
$args
);
return
call_user_func_array
(
'pQuery::create'
,
$args
);
}
}
...
...
pquery.template.php
0 → 100644
View file @
232df72c
<?php
/**
* pQuery plugin for parsing templates.
*
* @package pQuery
*/
/**
* @todo Documentation
* @property $ Alias for {@link pQuery::variable}.
*/
class
pQueryTemplate
extends
pQuery
implements
pQueryExtension
{
static
$accepts
=
array
(
'string'
=>
'open_template_file'
);
/**
* Root folders from which template files will be included.
*
* @var string
*/
static
$include_path
=
array
();
/**
* @see pQuery::$variable_alias
* @var string|array
*/
static
$variable_alias
=
'template'
;
/**
* Open the given template filename in the current variable.
*/
function
open_template_file
()
{
$found
=
false
;
foreach
(
self
::
$include_path
as
$root
)
{
$path
=
$root
.
$this
->
variable
;
if
(
is_file
(
$path
)
)
{
$found
=
true
;
break
;
}
}
if
(
!
$found
)
{
return
self
::
error
(
"Could not find template file
\"
%s
\"
, looked in folders:
\n
%s"
,
$this
->
variable
,
implode
(
"
\n
"
,
self
::
$include_path
));
}
$this
->
content
=
file_get_contents
(
$path
);
}
/**
* Replace all include paths by a single new one.
*
* @param str $path The path to set.
* @param bool $relative Indicates whether the path is relative to the document root.
*/
static
function
set_root
(
$path
,
$relative
=
true
)
{
self
::
$include_path
=
array
();
self
::
add_root
(
$path
);
}
/**
* Add a new include path.
*
* @param str $path The path to add.
* @param bool $relative Indicates whether the path is relative to the document root.
*/
static
function
add_root
(
$path
,
$relative
=
true
)
{
$relative
&&
$path
=
PQUERY_ROOT
.
$path
;
preg_match
(
'%/$%'
,
$path
)
||
$path
.=
'/'
;
if
(
!
is_dir
(
$path
)
)
return
self
::
error
(
'"%s" is not a directory.'
,
$path
);
self
::
$include_path
[]
=
$path
;
}
}
/**
* Shortcut constructor for {@link pQueryTemplate}.
*
* @param string $path The path to a template file.
* @returns pQueryTemplate A new template instance.
*/
function
_tpl
(
$path
)
{
return
pQuery
::
create
(
'tpl'
,
$path
);
}
__p
::
extend
(
'pQueryTemplate'
,
'tpl'
);
__tpl
::
set_root
(
''
);
?>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment