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
606c4ced
Commit
606c4ced
authored
Dec 08, 2006
by
Alastair Pharo
Committed by
Alastair Pharo
Dec 11, 2006
Browse files
More blog functionality.
parent
3b991bd4
Changes
16
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/blog/editpost/index.php
0 → 100644
View file @
606c4ced
<?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'
);
$blogpost
=
new
ArtefactTypeBlogPost
(
$id
);
if
(
$blogpost
->
get
(
'owner'
)
!=
$USER
->
get
(
'id'
))
{
return
;
}
$form
=
pieform
(
array
(
'name'
=>
'editpost'
,
'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
),
'defaultvalue'
=>
$blogpost
->
get
(
'title'
)
),
'description'
=>
array
(
'type'
=>
'wysiwyg'
,
'rows'
=>
5
,
'cols'
=>
80
,
'title'
=>
get_string
(
'postbody'
,
'artefact.blog'
),
'description'
=>
get_string
(
'postbodydesc'
,
'artefact.blog'
),
'rules'
=>
array
(
'required'
=>
true
),
'defaultvalue'
=>
$blogpost
->
get
(
'description'
)
),
'thisisdraft'
=>
array
(
'type'
=>
'checkbox'
,
'title'
=>
get_string
(
'thisisdraft'
,
'artefact.blog'
),
'description'
=>
get_string
(
'thisisdraftdesc'
,
'artefact.blog'
),
'checked'
=>
!
$blogpost
->
get
(
'published'
)
),
'submit'
=>
array
(
'type'
=>
'submitcancel'
,
'value'
=>
array
(
get_string
(
'save'
,
'artefact.blog'
),
get_string
(
'cancel'
,
'artefact.blog'
)
)
)
)
));
$smarty
=
smarty
();
$smarty
->
assign_by_ref
(
'editpostform'
,
$form
);
$smarty
->
display
(
'artefact:blog:editpost.tpl'
);
exit
;
/**
* This function gets called to create a new blog post, and publish it
* simultaneously.
*
* @param array
*/
function
editpost_submit
(
array
$values
)
{
global
$USER
;
$values
[
'published'
]
=
!
$values
[
'thisisdraft'
];
if
(
ArtefactTypeBlogPost
::
edit_post
(
$USER
,
$values
))
{
// Redirect to the blog page.
$id
=
get_field
(
'artefact'
,
'parent'
,
'id'
,
$values
[
'id'
]);
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/view/?id='
.
$id
);
}
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/list/'
);
}
/**
* This function get called to cancel the form submission. It returns to the
* blog list.
*/
function
editpost_cancel_submit
()
{
$id
=
param_integer
(
'id'
);
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/view/?id='
.
$id
);
}
?>
htdocs/artefact/blog/lang/en.utf8/artefact.blog.php
0 → 100644
View file @
606c4ced
<?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 lang
* @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
*
*/
defined
(
'INTERNAL'
)
||
die
();
$string
[
'myblogs'
]
=
'My Blogs'
;
$string
[
'title'
]
=
'Title'
;
$string
[
'description'
]
=
'description'
;
$string
[
'addblog'
]
=
'Add Blog'
;
$string
[
'newblog'
]
=
'New Blog'
;
$string
[
'blogtitle'
]
=
'Title'
;
$string
[
'blogtitledesc'
]
=
'e.g., ‘Jill’s Travel Blog’.'
;
$string
[
'blogdesc'
]
=
'Description'
;
$string
[
'blogdescdesc'
]
=
'e.g., ‘Follow Jill on her exciting adventures in New Zealand’.'
;
$string
[
'commentsallowed'
]
=
'Comments'
;
$string
[
'commentsalloweddesc'
]
=
'Comments can be made on your blog posts if you turn on this option.'
;
$string
[
'commentsallowedyes'
]
=
'Allow logged in users to comment on this blog'
;
$string
[
'commentsallowedno'
]
=
'Don’t allow comments on this blog'
;
$string
[
'commentsnotify'
]
=
'Comment Notification'
;
$string
[
'commentsnotifydesc'
]
=
'You can optionally receive notification whenever someone adds a comment to one of your blog posts.'
;
$string
[
'commentsnotifyyes'
]
=
'Notify me of comments to this blog'
;
$string
[
'commentsnotifyno'
]
=
'Do not notify me of comments to this blog'
;
$string
[
'createblog'
]
=
'Create Blog'
;
$string
[
'cancel'
]
=
'Cancel'
;
$string
[
'viewblog'
]
=
'View Blog'
;
$string
[
'blogsettings'
]
=
'Blog Settings'
;
$string
[
'settings'
]
=
'Settings'
;
$string
[
'addpost'
]
=
'Add Post'
;
$string
[
'newblogpost'
]
=
'New Blog Post'
;
$string
[
'posttitle'
]
=
'Title'
;
$string
[
'posttitledesc'
]
=
'The title appears above your post.'
;
$string
[
'postbody'
]
=
'Body'
;
$string
[
'postbodydesc'
]
=
'This is where your actual post goes.'
;
$string
[
'saveandpublish'
]
=
'Save and Publish'
;
$string
[
'createandpublishdesc'
]
=
'This will create the blog post and make it available to others.'
;
$string
[
'saveasdraft'
]
=
'Save as Draft'
;
$string
[
'createasdraftdesc'
]
=
'This will create the blog post, but it will not become available to others until you choose to publish it.'
;
$string
[
'savesettings'
]
=
'Save Settings'
;
$string
[
'publish'
]
=
'Publish'
;
$string
[
'published'
]
=
'Published'
;
$string
[
'edit'
]
=
'Edit'
;
$string
[
'delete'
]
=
'Delete'
;
$string
[
'editblogpost'
]
=
'Edit Blog Post'
;
$string
[
'thisisdraft'
]
=
'This post is a draft'
;
$string
[
'thisisdraftdesc'
]
=
'When your post is a draft, no one except you can see it.'
;
$string
[
'save'
]
=
'Save'
;
?>
htdocs/artefact/blog/lib.php
View file @
606c4ced
...
...
@@ -69,11 +69,15 @@ class ArtefactTypeBlog extends ArtefactType {
/**
* Whether comments are allowed on this blog or not.
*
* @var boolean
*/
protected
$commentsallowed
=
false
;
/**
* Whether the blog owner will be notified of comments or not.
*
* @var boolean
*/
protected
$commentsnotify
=
false
;
...
...
@@ -98,7 +102,7 @@ class ArtefactTypeBlog extends ArtefactType {
// Reset dirtyness for the time being.
$this
->
dirty
=
true
;
$data
=
array
(
$data
=
(
object
)
array
(
'blog'
=>
$this
->
get
(
'id'
),
'commentsallowed'
=>
(
$this
->
get
(
'commentsallowed'
)
?
1
:
0
),
'commentsnotify'
=>
(
$this
->
get
(
'commentsnotify'
)
?
1
:
0
)
...
...
@@ -182,7 +186,7 @@ class ArtefactTypeBlog extends ArtefactType {
* @param User
* @param array
*/
public
static
function
new_blog
(
User
$user
,
$values
)
{
public
static
function
new_blog
(
User
$user
,
array
$values
)
{
$artefact
=
new
ArtefactTypeBlog
();
$artefact
->
set
(
'title'
,
$values
[
'title'
]);
$artefact
->
set
(
'description'
,
$values
[
'description'
]);
...
...
@@ -191,6 +195,26 @@ class ArtefactTypeBlog extends ArtefactType {
$artefact
->
set
(
'commentsnotify'
,
$values
[
'commentsnotify'
]
?
true
:
false
);
$artefact
->
commit
();
}
/**
* This function updates an existing blog.
*
* @param User
* @param array
*/
public
static
function
edit_blog
(
User
$user
,
array
$values
)
{
if
(
empty
(
$values
[
'id'
])
||
!
is_numeric
(
$values
[
'id'
]))
{
return
;
}
$artefact
=
new
ArtefactTypeBlog
(
$values
[
'id'
]);
$artefact
->
set
(
'title'
,
$values
[
'title'
]);
$artefact
->
set
(
'description'
,
$values
[
'description'
]);
$artefact
->
set
(
'owner'
,
$user
->
get
(
'id'
));
$artefact
->
set
(
'commentsallowed'
,
$values
[
'commentsallowed'
]
?
true
:
false
);
$artefact
->
set
(
'commentsnotify'
,
$values
[
'commentsnotify'
]
?
true
:
false
);
$artefact
->
commit
();
}
}
/**
...
...
@@ -202,23 +226,77 @@ class ArtefactTypeBlogPost extends ArtefactType {
* This gives the number of blog posts to display at a time.
*/
const
pagination
=
10
;
/**
* Just the basic commit.
* This defines whether the blogpost is published or not.
*
* @var boolean
*/
protected
$published
=
false
;
/**
* We override the constructor to fetch the extra data.
*
* @param integer
* @param object
*/
public
function
__construct
(
$id
=
0
,
$data
=
null
)
{
parent
::
__construct
(
$id
,
$data
);
if
(
!
$data
&&
$this
->
id
&&
(
$bpdata
=
get_record
(
'artefact_blog_blogpost'
,
'blogpost'
,
$this
->
id
)))
{
foreach
(
$bpdata
as
$name
=>
$value
)
{
if
(
property_exists
(
$this
,
$name
))
{
$this
->
$name
=
$value
;
}
}
}
}
/**
* This function extends ArtefactType::commit() by adding additional data
* into the artefact_blog_blogpost table.
*/
public
function
commit
()
{
$this
->
commit_basic
();
if
(
empty
(
$this
->
dirty
))
{
return
;
}
$new
=
empty
(
$this
->
id
);
parent
::
commit
();
$this
->
dirty
=
true
;
$data
=
(
object
)
array
(
'blogpost'
=>
$this
->
get
(
'id'
),
'published'
=>
(
$this
->
get
(
'published'
)
?
1
:
0
)
);
if
(
$new
)
{
insert_record
(
'artefact_blog_blogpost'
,
$data
);
}
else
{
update_record
(
'artefact_blog_blogpost'
,
$data
,
'blogpost'
);
}
$this
->
dirty
=
false
;
}
/**
* @todo
* This function extends ArtefactType::delete() by also deleting anything
* that's in blogpost.
*/
public
function
delete
()
{
log_debug
(
'Deleting blogpost:'
.
$this
->
id
)
;
$this
->
delete_basic
()
;
}
if
(
empty
(
$this
->
id
)
)
{
return
;
}
delete_records
(
'artefact_blog_blogpost'
,
'blogpost'
,
$this
->
id
);
parent
::
delete
();
}
public
function
render
(
$format
,
$options
)
{
}
...
...
@@ -245,11 +323,13 @@ class ArtefactTypeBlogPost extends ArtefactType {
*/
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 = ?
SELECT a.id, a.title, a.description, a.ctime, a.mtime, bp.published
FROM "
.
get_config
(
'dbprefix'
)
.
"artefact a
LEFT OUTER JOIN "
.
get_config
(
'dbprefix'
)
.
"artefact_blog_blogpost bp
ON a.id = bp.blogpost
WHERE a.parent = ?
AND a.artefacttype = 'blogpost'
AND a.owner = ?
ORDER BY ctime DESC
LIMIT ? OFFSET ?;"
,
array
(
$id
,
...
...
@@ -274,10 +354,54 @@ class ArtefactTypeBlogPost extends ArtefactType {
$artefact
=
new
ArtefactTypeBlogPost
();
$artefact
->
set
(
'title'
,
$values
[
'title'
]);
$artefact
->
set
(
'description'
,
$values
[
'description'
]);
$artefact
->
set
(
'published'
,
$values
[
'published'
]);
$artefact
->
set
(
'owner'
,
$user
->
get
(
'id'
));
$artefact
->
set
(
'parent'
,
$values
[
'id'
]);
$artefact
->
commit
();
}
/**
* This function updates an existing blog post.
*
* @param User
* @param array
*/
public
static
function
edit_post
(
User
$user
,
array
$values
)
{
$artefact
=
new
ArtefactTypeBlogPost
(
$values
[
'id'
]);
if
(
$user
->
get
(
'id'
)
!=
$artefact
->
get
(
'owner'
))
{
return
false
;
}
$artefact
->
set
(
'title'
,
$values
[
'title'
]);
$artefact
->
set
(
'description'
,
$values
[
'description'
]);
$artefact
->
set
(
'published'
,
$values
[
'published'
]);
$artefact
->
commit
();
return
true
;
}
/**
* This function publishes the blog post.
*
* @return boolean
*/
public
function
publish
()
{
if
(
!
$this
->
id
)
{
return
false
;
}
$data
=
(
object
)
array
(
'blogpost'
=>
$this
->
id
,
'published'
=>
1
);
if
(
get_field
(
'artefact_blog_blogpost'
,
'COUNT(*)'
,
'blogpost'
,
$this
->
id
))
{
update_record
(
'artefact_blog_blogpost'
,
$data
,
'blogpost'
);
}
else
{
insert_record
(
'artefact_blog_blogpost'
,
$data
);
}
return
true
;
}
}
?>
htdocs/artefact/blog/list/index.php
View file @
606c4ced
...
...
@@ -43,7 +43,7 @@ var bloglist = new TableRenderer(
function(r) {
return TD(
null,
A({'href':'{$wwwroot}
/
artefact/blog/view/?id=' + r.id}, r.title)
A({'href':'{$wwwroot}artefact/blog/view/?id=' + r.id}, r.title)
);
},
'description'
...
...
htdocs/artefact/blog/new/index.php
View file @
606c4ced
...
...
@@ -45,7 +45,7 @@ $form = pieform(array(
)
),
'description'
=>
array
(
'type'
=>
'
textarea
'
,
'type'
=>
'
wysiwyg
'
,
'rows'
=>
10
,
'cols'
=>
80
,
'title'
=>
get_string
(
'blogdesc'
,
'artefact.blog'
),
...
...
@@ -73,8 +73,11 @@ $form = pieform(array(
)
),
'submit'
=>
array
(
'type'
=>
'submit'
,
'value'
=>
get_string
(
'newblog'
,
'artefact.blog'
)
'type'
=>
'submitcancel'
,
'value'
=>
array
(
get_string
(
'createblog'
,
'artefact.blog'
),
get_string
(
'cancel'
,
'artefact.blog'
)
)
)
)
));
...
...
@@ -93,7 +96,14 @@ function newblog_submit($values) {
global
$USER
;
ArtefactTypeBlog
::
new_blog
(
$USER
,
$values
);
redirect
(
get_config
(
'wwwroot'
)
.
'/artefact/blog/list/'
);
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/list/'
);
}
/**
* This function gets called to cancel a submission.
*/
function
newblog_cancel_submit
()
{
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/list/'
);
}
?>
htdocs/artefact/blog/newpost/index.php
View file @
606c4ced
...
...
@@ -54,7 +54,7 @@ $form = pieform(array(
)
),
'description'
=>
array
(
'type'
=>
'
textarea
'
,
'type'
=>
'
wysiwyg
'
,
'rows'
=>
5
,
'cols'
=>
80
,
'title'
=>
get_string
(
'postbody'
,
'artefact.blog'
),
...
...
@@ -63,28 +63,63 @@ $form = pieform(array(
'required'
=>
true
)
),
's
ubmit
'
=>
array
(
's
aveandpublish
'
=>
array
(
'type'
=>
'submit'
,
'value'
=>
get_string
(
'newpost'
,
'artefact.blog'
)
'description'
=>
get_string
(
'createandpublishdesc'
,
'artefact.blog'
),
'value'
=>
get_string
(
'saveandpublish'
,
'artefact.blog'
)
),
'saveasdraft'
=>
array
(
'type'
=>
'submit'
,
'description'
=>
get_string
(
'createasdraftdesc'
,
'artefact.blog'
),
'value'
=>
get_string
(
'saveasdraft'
,
'artefact.blog'
)
),
'cancel'
=>
array
(
'type'
=>
'cancel'
,
'value'
=>
get_string
(
'cancel'
,
'artefact.blog'
)
)
)
));
$smarty
=
&
smarty
();
$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.
* This function gets called to create a new blog post, and publish it
* simultaneously.
*
* @param array
*/
function
newpost_submit
(
array
$values
)
{
function
newpost_submit
_saveandpublish
(
array
$values
)
{
global
$USER
;
ArtefactTypeBlogPost
::
new_post
(
$USER
,
$values
);
redirect
(
get_config
(
'wwwroot'
)
.
'/artefact/blog/view/?id='
.
$values
[
'id'
]);
$values
[
'published'
]
=
true
;
$id
=
ArtefactTypeBlogPost
::
new_post
(
$USER
,
$values
);
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/view/?id='
.
$values
[
'id'
]);
}
/**
* This function gets called to create a new blog post and mark it as a draft.
*
* @param array
*/
function
newpost_submit_saveasdraft
(
array
$values
)
{
global
$USER
;
$values
[
'published'
]
=
false
;
$id
=
ArtefactTypeBlogPost
::
new_post
(
$USER
,
$values
);
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/view/?id='
.
$values
[
'id'
]);
}
/**
* This function get called to cancel the form submission. It returns to the
* blog list.
*/
function
newpost_cancel_cancel
()
{
$id
=
param_integer
(
'id'
);
redirect
(
get_config
(
'wwwroot'
)
.
'artefact/blog/view/?id='
.
$id
);
}
?>
htdocs/artefact/blog/settings/index.php
0 → 100644
View file @
606c4ced
<?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'
);
$id
=
param_integer
(
'id'
);
$blog
=
new
ArtefactTypeBlog
(
$id
);
$form
=
pieform
(
array
(
'name'
=>
'editblog'
,
'method'
=>
'post'
,
'action'
=>
''
,
'plugintype'
=>
'artefact'
,
'pluginname'
=>
'blog'
,
'elements'
=>
array
(
'id'
=>
array
(
'type'
=>
'hidden'
,
'value'
=>
$id
),
'title'
=>
array
(
'type'
=>
'text'
,
'title'
=>
get_string
(
'blogtitle'
,
'artefact.blog'
),
'description'
=>
get_string
(
'blogtitledesc'
,
'artefact.blog'
),
'rules'
=>
array
(
'required'
=>
true
),
'defaultvalue'
=>
$blog
->
get
(
'title'
)
),
'description'
=>
array
(
'type'
=>
'wysiwyg'
,
'rows'
=>
10
,
'cols'
=>
80
,
'title'
=>
get_string
(
'blogdesc'
,
'artefact.blog'
),
'description'
=&g