Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
b5738e60
Commit
b5738e60
authored
Dec 04, 2006
by
Alastair Pharo
Committed by
Alastair Pharo
Dec 04, 2006
Browse files
Basic blog functionality
parent
4bfb9627
Changes
11
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/blog/lib.php
View file @
b5738e60
...
...
@@ -46,7 +46,7 @@ class PluginArtefactBlog extends PluginArtefact {
return
array
(
array
(
'name'
=>
'myblogs'
,
'link'
=>
'
blogs
/'
,
'link'
=>
'
list
/'
,
)
);
}
...
...
@@ -61,13 +61,35 @@ class PluginArtefactBlog extends PluginArtefact {
*/
class
ArtefactTypeBlog
extends
ArtefactType
{
/**
* This constant gives the per-page pagination for listing blogs.
*/
const
pagination
=
10
;
/**
* Just the basic commit.
*/
public
function
commit
()
{
$this
->
commit_basic
();
}
/**
* Just the basic delete. FIXME - needs to delete posts too.
*/
public
function
delete
()
{
$this
->
delete_basic
();
}
/**
* FIXME - Not sure about this. It is copied entirely from
* ArtefactTypeProfile
*/
public
function
render
(
$format
,
$options
)
{
if
(
$format
==
ARTEFACT_FORMAT_LISTITEM
&&
$this
->
title
)
{
return
$this
->
title
;
}
return
false
;
}
public
function
get_icon
()
{
...
...
@@ -76,10 +98,42 @@ class ArtefactTypeBlog extends ArtefactType {
public
static
function
get_render_list
()
{
}
public
static
function
c
an_render_to
(
$format
)
{
public
static
function
c
ollapse_config
(
)
{
}
public
static
function
collapse_config
()
{
/**
* This function returns a list of the given user's blogs.
*
* @param User
* @return array (count: integer, data: array)
*/
public
static
function
get_blog_list
(
User
$user
,
$limit
=
self
::
pagination
,
$offset
=
0
)
{
(
$result
=
get_records_sql_array
(
"
SELECT id, title, description
FROM "
.
get_config
(
'dbprefix'
)
.
"artefact
WHERE owner = ?
AND artefacttype = 'blog'
ORDER BY title
LIMIT ? OFFSET ?"
,
array
(
$user
->
get
(
'id'
),
$limit
,
$offset
)))
||
(
$result
=
array
());
$count
=
(
int
)
get_field
(
'artefact'
,
'COUNT(*)'
,
'owner'
,
$user
->
get
(
'id'
),
'artefacttype'
,
'blog'
);
return
array
(
$count
,
$result
);
}
/**
* This function creates a new blog.
*
* @param User
* @param array
*/
public
static
function
new_blog
(
User
$user
,
$values
)
{
$artefact
=
new
ArtefactTypeBlog
();
$artefact
->
set
(
'title'
,
$values
[
'title'
]);
$artefact
->
set
(
'description'
,
$values
[
'description'
]);
$artefact
->
set
(
'owner'
,
$user
->
get
(
'id'
));
$artefact
->
commit
();
}
}
...
...
@@ -88,7 +142,14 @@ class ArtefactTypeBlog extends ArtefactType {
*/
class
ArtefactTypeBlogPost
extends
ArtefactType
{
/**
* This gives the number of blog posts to display at a time.
*/
const
pagination
=
10
;
public
function
commit
()
{
$this
->
commit_basic
();
}
public
function
delete
()
{
...
...
@@ -103,9 +164,50 @@ class ArtefactTypeBlogPost extends ArtefactType {
public
static
function
get_render_list
()
{
}
public
static
function
c
an_render_to
(
$format
)
{
public
static
function
c
ollapse_config
(
)
{
}
public
static
function
collapse_config
()
{
/**
* This function returns a list of the current user's blog posts, for the
* given blog.
*
* @param User
* @param integer
* @param integer
*/
public
static
function
get_posts
(
User
$user
,
$id
,
$limit
=
self
::
pagination
,
$offset
=
0
)
{
(
$result
=
get_records_sql_array
(
"
SELECT id, title, description, ctime, mtime
FROM "
.
get_config
(
'dbprefix'
)
.
"artefact
WHERE parent = ?
AND artefacttype = 'blogpost'
AND owner = ?
ORDER BY ctime DESC
LIMIT ? OFFSET ?;"
,
array
(
$id
,
$user
->
get
(
'id'
),
$limit
,
$offset
)))
||
(
$result
=
array
());
$count
=
(
int
)
get_field
(
'artefact'
,
'COUNT(*)'
,
'owner'
,
$user
->
get
(
'id'
),
'artefacttype'
,
'blogpost'
,
'parent'
,
$id
);
return
array
(
$count
,
$result
);
}
/**
* This function creates a new blog post.
*
* @param User
* @param array
*/
public
static
function
new_post
(
User
$user
,
array
$values
)
{
$artefact
=
new
ArtefactTypeBlogPost
();
$artefact
->
set
(
'title'
,
$values
[
'title'
]);
$artefact
->
set
(
'description'
,
$values
[
'description'
]);
$artefact
->
set
(
'owner'
,
$user
->
get
(
'id'
));
$artefact
->
set
(
'parent'
,
$values
[
'id'
]);
$artefact
->
commit
();
}
}
htdocs/artefact/blog/list/index.json.php
0 → 100644
View file @
b5738e60
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
require
(
dirname
(
dirname
(
dirname
(
dirname
(
__FILE__
))))
.
'/init.php'
);
safe_require
(
'artefact'
,
'blog'
);
json_headers
();
$limit
=
param_integer
(
'limit'
,
ArtefactTypeBlog
::
pagination
);
$offset
=
param_integer
(
'offset'
,
0
);
list
(
$count
,
$data
)
=
ArtefactTypeBlog
::
get_blog_list
(
$USER
,
$limit
,
$offset
);
echo
json_encode
(
array
(
'count'
=>
$count
,
'limit'
=>
$limit
,
'offset'
=>
$offset
,
'data'
=>
$data
));
?>
htdocs/artefact/blog/list/index.php
0 → 100644
View file @
b5738e60
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
define
(
'MENUITEM'
,
'myblogs'
);
require
(
dirname
(
dirname
(
dirname
(
dirname
(
__FILE__
))))
.
'/init.php'
);
safe_require
(
'artefact'
,
'blog'
);
// This is the wwwroot.
$wwwroot
=
get_config
(
'wwwroot'
);
// This JavaScript creates a table to display the blog entries.
$js
=
<<<EOJAVASCRIPT
var bloglist = new TableRenderer(
'bloglist',
'index.json.php',
[
function(r) {
return TD(
null,
A({'href':'{$wwwroot}/artefact/blog/view/?id=' + r.id}, r.title)
);
},
'description'
]
);
bloglist.updateOnLoad();
EOJAVASCRIPT;
$smarty
=
smarty
(
array
(
'tablerenderer'
));
$smarty
->
assign_by_ref
(
'INLINEJAVASCRIPT'
,
$js
);
$smarty
->
assign_by_ref
(
'blogs'
,
$blogs
);
$smarty
->
display
(
'artefact:blog:list.tpl'
);
?>
htdocs/artefact/blog/new/index.php
0 → 100644
View file @
b5738e60
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-internal
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
define
(
'MENUITEM'
,
'myblogs'
);
require
(
dirname
(
dirname
(
dirname
(
dirname
(
__FILE__
))))
.
'/init.php'
);
require_once
(
'pieforms/pieform.php'
);
safe_require
(
'artefact'
,
'blog'
);
$form
=
pieform
(
array
(
'name'
=>
'newblog'
,
'method'
=>
'post'
,
'action'
=>
''
,
'elements'
=>
array
(
'title'
=>
array
(
'type'
=>
'text'
,
'title'
=>
get_string
(
'blogtitle'
,
'artefact.blog'
),
'description'
=>
get_string
(
'blogtitledesc'
,
'artefact.blog'
),
'rules'
=>
array
(
'required'
=>
true
)
),
'description'
=>
array
(
'type'
=>
'textarea'
,
'rows'
=>
10
,
'cols'
=>
80
,
'title'
=>
get_string
(
'blogdesc'
,
'artefact.blog'
),
'description'
=>
get_string
(
'blogdescdesc'
,
'artefact.blog'
),
'rules'
=>
array
(
'required'
=>
true
)
),
'submit'
=>
array
(
'type'
=>
'submit'
,
'value'
=>
get_string
(
'newblog'
,
'artefact.blog'
)
)
)
));
$smarty
=&
smarty
();
$smarty
->
assign_by_ref
(
'newblogform'
,
$form
);
$smarty
->
display
(
'artefact:blog:new.tpl'
);
exit
;
/**
* This function gets called to submit the new blog.
*
* @param array
*/
function
newblog_submit
(
$values
)
{
global
$USER
;
ArtefactTypeBlog
::
new_blog
(
$USER
,
$values
);
redirect
(
get_config
(
'wwwroot'
)
.
'/artefact/blog/list/'
);
}
?>
htdocs/artefact/blog/newpost/index.php
0 → 100644
View file @
b5738e60
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
define
(
'MENUITEM'
,
'myblogs'
);
require
(
dirname
(
dirname
(
dirname
(
dirname
(
__FILE__
))))
.
'/init.php'
);
require_once
(
'pieforms/pieform.php'
);
safe_require
(
'artefact'
,
'blog'
);
$id
=
param_integer
(
'id'
);
$form
=
pieform
(
array
(
'name'
=>
'newpost'
,
'method'
=>
'post'
,
'action'
=>
''
,
'elements'
=>
array
(
'id'
=>
array
(
'type'
=>
'hidden'
,
'value'
=>
$id
,
'rules'
=>
array
(
'required'
=>
true
)
),
'title'
=>
array
(
'type'
=>
'text'
,
'title'
=>
get_string
(
'posttitle'
,
'artefact.blog'
),
'description'
=>
get_string
(
'posttitledesc'
,
'artefact.blog'
),
'rules'
=>
array
(
'required'
=>
true
)
),
'description'
=>
array
(
'type'
=>
'textarea'
,
'rows'
=>
5
,
'cols'
=>
80
,
'title'
=>
get_string
(
'postbody'
,
'artefact.blog'
),
'description'
=>
get_string
(
'postbodydesc'
,
'artefact.blog'
),
'rules'
=>
array
(
'required'
=>
true
)
),
'submit'
=>
array
(
'type'
=>
'submit'
,
'value'
=>
get_string
(
'newpost'
,
'artefact.blog'
)
)
)
));
$smarty
=&
smarty
();
$smarty
->
assign_by_ref
(
'newpostform'
,
$form
);
$smarty
->
display
(
'artefact:blog:newpost.tpl'
);
exit
;
/**
* This function gets called to create a new blog post.
*
* @param array
*/
function
newpost_submit
(
array
$values
)
{
global
$USER
;
ArtefactTypeBlogPost
::
new_post
(
$USER
,
$values
);
redirect
(
get_config
(
'wwwroot'
)
.
'/artefact/blog/view/?id='
.
$values
[
'id'
]);
}
?>
htdocs/artefact/blog/theme/default/list.tpl
0 → 100644
View file @
b5738e60
{*
This template displays a list of the user's blogs. The list is populated
using javascript.
*}
{
include
file
=
"header.tpl"
}
{
include
file
=
"adminmenu.tpl"
}
<div
class=
"content"
>
<h2>
{
str
section
=
"artefact.blog"
tag
=
"blogs"
}
</h2>
<div
class=
"newblog"
>
<a
href=
"
{
$WWWROOT
}
/artefact/blog/new/"
>
{
str
section
=
"artefact.blog"
tag
=
"newblog"
}
</a>
</div>
<table
id=
"bloglist"
>
<thead>
<tr>
<th>
{
str
section
=
"artefact.blog"
tag
=
"title"
}
</th>
<th>
{
str
section
=
"artefact.blog"
tag
=
"description"
}
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div
class=
"newblog"
>
<a
href=
"
{
$WWWROOT
}
/artefact/blog/new/"
>
{
str
section
=
"artefact.blog"
tag
=
"newblog"
}
</a>
</div>
</div>
{
include
file
=
"footer.tpl"
}
htdocs/artefact/blog/theme/default/new.tpl
0 → 100644
View file @
b5738e60
{*
This template displays the 'new blog' form
*}
{
include
file
=
"header.tpl"
}
{
include
file
=
"adminmenu.tpl"
}
<div
class=
"content"
>
<h2>
{
str
section
=
"artefact.blog"
tag
=
"newblog"
}
</h2>
{
$newblogform
}
ADD RADIO BUTTONS
</div>
{
include
file
=
"footer.tpl"
}
htdocs/artefact/blog/theme/default/newpost.tpl
0 → 100644
View file @
b5738e60
{*
This template displays the 'new blog post' form
*}
{
include
file
=
"header.tpl"
}
{
include
file
=
"adminmenu.tpl"
}
<div
class=
"content"
>
<h2>
{
str
section
=
"artefact.blog"
tag
=
"newpost"
}
</h2>
{
$newpostform
}
ADD RADIO BUTTONS
</div>
{
include
file
=
"footer.tpl"
}
htdocs/artefact/blog/theme/default/view.tpl
0 → 100644
View file @
b5738e60
{*
This template displays a list of the user's blog posts for a particular blog.
*}
{
include
file
=
"header.tpl"
}
{
include
file
=
"adminmenu.tpl"
}
<div
class=
"content"
>
<h2>
{
$blog
->
get
(
'title'
)
}
</h2>
<div>
<a
href=
"
{
$WWWROOT
}
/artefact/blog/newpost/?id=
{
$blog
->
get
(
'id'
)
}
"
>
{
str
section
=
"artefact.blog"
tag
=
"newpost"
}
</a>
</div>
<table
id=
"postlist"
>
<thead>
</thead>
<tbody>
</tbody>
</table>
<div>
<a
href=
"
{
$WWWROOT
}
/artefact/blog/newpost/?id=
{
$blog
->
get
(
'id'
)
}
"
>
{
str
section
=
"artefact.blog"
tag
=
"newpost"
}
</a>
</div>
</div>
htdocs/artefact/blog/view/index.json.php
0 → 100644
View file @
b5738e60
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
require
(
dirname
(
dirname
(
dirname
(
dirname
(
__FILE__
))))
.
'/init.php'
);
safe_require
(
'artefact'
,
'blog'
);
json_headers
();
$id
=
param_integer
(
'id'
);
$limit
=
param_integer
(
'limit'
,
ArtefactTypeBlogPost
::
pagination
);
$offset
=
param_integer
(
'offset'
,
0
);
list
(
$count
,
$data
)
=
ArtefactTypeBlogPost
::
get_posts
(
$USER
,
$id
,
$limit
,
$offset
);
echo
json_encode
(
array
(
'count'
=>
$count
,
'limit'
=>
$limit
,
'offset'
=>
$offset
,
'data'
=>
$data
));
?>
htdocs/artefact/blog/view/index.php
0 → 100644
View file @
b5738e60
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
define
(
'MENUITEM'
,
'myblogs'
);
require
(
dirname
(
dirname
(
dirname
(
dirname
(
__FILE__
))))
.
'/init.php'
);
safe_require
(
'artefact'
,
'blog'
);
$id
=
param_integer
(
'id'
);
$enc_id
=
json_encode
(
$id
);