Moodle is great for handling courses and testing, but it seems to lack in providing a simple front-page Content Management System. The only way to get "pages" is to create a course, type content into the first summary area, and hide all of the other topics. Messy to say the least.
My school has been using Moodle for over a year now, and we wanted to launch 1.9 with some added features, including support for pages that could easily be updated through the Moodle interface.
You can see an example at http://www.thomashaney.ca/page/1/.
This uses its own page type (defined in pagelib.php) and grabs data from a table in the database (mdl_page).
I want to make the code available for everyone, but I'm wondering what the best way to do so would be. It does involve editing a few lib files and the admin sidebar, as well as a new database table.
Should I zip the files up, provide a diff patch, or both?
I would say "both". As a potential user, I would welcome all the detail and instructions I could get! Once you get a few people to try it out and give you feedback, then you probably would want to upload the files to the modules and plugins database. You will be able to reference this discussion as part of your documentation.
atw
Enter the following SQL into your database to create a new table.
CREATE TABLE IF NOT EXISTS `mdl_page` (
`id` bigint(10) unsigned NOT NULL auto_increment,
`fullname` varchar(254) NOT NULL default '',
`shortname` varchar(100) NOT NULL default '',
`content` text,
`visible` tinyint(1) unsigned NOT NULL default '1',
`lang` varchar(30) NOT NULL default '',
`theme` varchar(50) NOT NULL default '',
`timecreated` bigint(10) unsigned NOT NULL default '0',
`timemodified` bigint(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `mdl_page_sho_ix` (`shortname`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Central page table';
Add the following lines to /admin/settings/top.php. These are needed to create the link on the admin sidebar.
$ADMIN->add('root', new admin_category('pages', get_string('pages','admin')));
$ADMIN->add('pages', new admin_externalpage('pagemgmt', get_string('pagemgmt', 'admin'), "$CFG->wwwroot/page/index.php", 'moodle/course:update'));
The page.zip file contains folders which must be extracted to the root Moodle dir.
My instructions probably make no sense to anyone other than myself, so let me know if you have any questions. Ask either here, or send me an email. This was much more tied to Moodle's core on my production site, and I'm trying to make it easier to add as an extension. However, they may be lingering errors due to strings or roles. Please complain, and I'll get them fixed.
I've got another version here that should work drag and drop into any existing 1.9 installation, and doesn't require any edits to existing files.
There is a file included (database.txt) that contains the SQL code to create the table.
Go to your root Moodle directory (the folder that contains config.php).
Drag those 3 folders from the .zip file into that root folder. It should request to overwrite one file (admin/settings/courses.php) in order to add the links to the admin sidebar.
note: If you're on a Mac, you might have issues where it will overwrite the entire folder leaving you with a lot of missing files. I'm not sure what causes the issue, but you might need to move things manually.
Hopefully you have phpMyAdmin installed (or some other method of editing your database). Open the database.txt file and copy the SQL code into phpMyAdmin to create the necessary tables.
Visit http://<your moodle>/page/index.php to double check that everything worked. You should be able to add a page.
Let me know if you have any trouble
It looks like this thread has been 'dormant' for a while so I'm not sure if I'll get a response but...
Just wanted to check/confirm that this 'Content pages' modification is not compatible with 1.8? I gave it a try and couldn't get it to work and am thus assuming that it's not compatible but thought I'd check.
I know, the subject line says 1.9
When I installed everything (including the database table) and then visit my site (and login as admin) I get a broken front page (i.e. only a minor portion of the front page is displayed - it appears to stop when it gets to the 'admin' block that should appear on the front page).
Jason
If you manually edit /admin/settings/course.php and replace page:update with course:update it should work. I was hoping that this feature might make it into the 2.0 release as a contribution so that the page capabilities and roles would be available.
If you have any issues, and I don't seem to be replying in a timely fashion, send me an email with a link to this thread. The Moodle forums (unfortunately) are not a site that I check routinely.
Thanks but unfortunately the change didn't fix the problem. But again, I am trying to make it work in 1.8 so there may be other compatibility issues?
I am planning upgrade our production site to 1.9 soon and have verified that it works fine for us under 1.9 so making it work on 1.8 is not a crucial issue for us.
Thanks for the help and the e-mail.
Jason
Thanks again for the reply. I have finally managed to get upgraded to 1.9 and am using the Pages addon. I'm wondering if it is possible to tweak it so that no blocks appear on the pages that are created with this addon?
I'm trying to make the pages as clean as possible and have already removed the edited date and title from view.php for a slightly sleeker look. If I can turn off blocks too I'm thinking that might be even nicer. I haven't started picking at the code yet as I don't want to mess it up. Thought I'd check here first and see if I could get some advice
Jason
In pagelib.php there's a setting somewhere in the file that contains an array of the default blocks on a newly created page. Easiest way to find it would be to search for the string "calendar". If you make the array empty, it shouldn't add blocks to newly created pages.
In theory, you could also disable the code where blocks are actually printed to the page, but that gets messy if you ever want a block on a specific page.
I went in pagelib.php and on line 155 changed:
$blocknames = 'admin_tree,site_news:login,messages,calendar_month';
to
$blocknames = '';
and that did the trick! Thanks! Now I can work on customizing the drop down menus in the college_blue theme and have some of them sent to some clean static pages created with the 'content pages' addon.

Thanks again for your help.
Jason
if(isguestuser()) {
redirect($CFG->wwwroot);
}
Another (probably more elegant) option would be to add a new moodle/page:view capability, and require that capability in order to view the page.
I just experienced a problem after upgrading from 1.9.3 to 1.9.4+ in which I could not turn editing on when viewing my course list when logged in as admin. (detailed explanation in another forum)
It took me some time to figure out that the cause lies somewhere in the courses.php file included in the Content Pages package. I overwrote the file with the one from the Moodle core and the problem was resolved.
I'd like to be able to continue to use the Content Pages feature so I thought I'd bring up the issue here and see if you were already aware of it...?
If so, maybe there is already a fix for this issue?
Jason
Re: CMS integrations: Content Pages using Moodle 1.9
I thought I'd try and see if I could get things working and compared the two courses.php files and the only code in the one customized for the Content Pages modification (that I could see was)
$ADMIN->add('root', new admin_category('pages', get_string('pages','page')));
$ADMIN->add('pages', new admin_externalpage('pagemgmt', get_string('pagemgmt', 'page'), "$CFG->wwwroot/page/index.php", 'moodle/page:update'));
so I tried adding those two lines in roughly the same location as they were before but when I gave the file a try I didn't get anything. No errors but no "Pages" folder in the Site Admin block either....
Oh well it was worth a try.
I noticed that you are working with Anthony on getting this feature included for 2.0. Any plans on patching it for 1.9.4?
Jason
P.S. Strangely, I can edit the pages that I have already created but I cannot create new ones because when I try to access mysite/page/index.php I get a "Section Error!".
I tried adding the two lines I mentioned above to the top.php file but that did not have any effect.
I looked through the contrib page that Anthony referenced and downloaded the diff file and picked out the two new lines (almost the same as the ones posted in my previous post) and tried them in the top.php file but had no luck there either. I'm not getting any errors from the front page but the "Pages" folder does not show up in the Site Admin block and if I try to navigate to mysite/pages/index.php I get and "Access denied" error.
Any ideas?
Jason
P.S. The diff file that Anthony referenced involves several core files. Is the information in that file for 2.0 compatibility? I only made changes to top.php.
Any ideas on what it might take to get Pages to work with 1.9.4+ ?
As Darryl pointed out, it looks like some code has been shuffled around between a few files in the /admin/settings folder.
I don't know enough, unfortunately, to be able to start poking around extensively without breaking something
With a little direction I'm willing to test stuff and experiment though
Jason
Thank you very much for the personal communication via e-mail. I ended up taking the 'easy' route and installed the Pages block from the zipped file you posted in the tracker in CONTRIB-870.
The only issue for me was an error that the mdl_page table already exists. I dumped the contents of the table, renamed the table temporarily, and then initiated the install of the block again by clicking on the Notifications link in the Site Admin block. Then imported the dumped SQL file from my old mdl_pages table into the newly created table. Everything was in order with the pages I had previously created displayed correctly so I then deleted the 'old' renamed table.
Just wanted to outline the process for others like me that are 'lower' tech
Jason
Re: CMS integrations: Content Pages using Moodle 1.9
This is a brief explanation of a low tech method of how to get Pages up and running on 1.9.4+ using the package provided by Anthony. (link in previous post)
If you didn't already have the Pages 'extension' installed, you should be able to add the contents of the package provided by Anthony to your current instance of Moodle (overwrite the files that are already in your Moodle directory with those found in the package) and then visit your Moodle page and login as Admin. Click on the 'notifications' link in the Site Admin block and everything will be setup.
If you already had Pages installed please see my previous post.
The contents of the package should go in the directories indicated by their location(s) in the package and you won't need to reboot the server.
The contents of the package (and locations where they should be placed) provided by Anthony are as follows:
/admin/roles/tabs.php
/admin/settings/top.php
/blocks/page (the entire page directory should be placed in your blocks directory)
/lib/accesslib.php
The low tech way to do this is place the files 'manually' using ftp, cpannel, or whatever method you use to access your server. Once you have them all in the correct location then login as Admin as I mentioned above and click on 'notifications'.
Hope this helps a little.
Jason
P.S. The method I have described here is not the best way in terms of avoiding versioning issues but is a quick and easy way to get it done if you are not familiar with how to use the 'patch' command and need to get Pages up and running asap. (that was my case
I've been using the patch for a while now and have just run into what looks like an issue.
I am trying to assign roles to the pages but when I click on Assign Roles I just get a white page. Sorry, I haven't checked the error log on my server....I'll do that.
Just thought I'd throw this out real quick in case it was something that you may already be aware of.
Jason
Just posted this in the Tracker (Contrib-1303) as well but thought I'd throw it out here too.
I just upgraded to 1.9.5+ and now cannot use Pages at all
http://www.nuelp.com/blocks/page/view.php?id=6
I get the following error
Error: get_context_instance() called with incorrect context level "CONTEXT_PAGE"
I tried adding the CONTEXT_PAGE case from the tabs.diff file but that didn't have any affect.
Any ideas? My site is a little handicapped now
Jason
Re: CMS integrations: Content Pages using Moodle 1.9
Re: CMS integrations: Content Pages using Moodle 1.9
Hello Antony,
I have installed recently page block (by installing the moodle195-pages.zip) on 1.9.5+ and it works well ... until I have tried to do the same as Jason did:
- Tried to assign some roles to a page.
On my case the behaviour is different because it is coorectly evoqued the admin/roles/assign.php and appears the assign role page but with 0 Potential users to assign.
Can you help me to understand whts happening and potentially correct it ?
Thanks in advance!
Re: CMS integrations: Content Pages using Moodle 1.9
-
As previously informed when I tried to assign roles on any page, I detected the "0 Potential users";
-
And when I tried to "override roles", it gave me the error:
-
"You have an error in your SQL syntax ..."
-
This error was on 3671 line of accesslib.php, on fetch_context_capabilities() function because the SQL string created under CONTEXT_PAGE was:
-
SELECT * FROM {capabilities} WHERE ...
-
-
So, I realized, that the bug was dure to the lack of the prefix "mdl_", and the correct SQL string should be:
-
SELECT * FROM mdl_capabilities WHERE ...
-
-
-
As result of this debugging analysis results, and in order to Fix the detected BUG, I have changed the /lib/accesslib.php file, as follows on the line 3604:
case CONTEXT_PAGE: // course context and bellow
$SQL = "SELECT *
FROM {$CFG->prefix}capabilities
WHERE contextlevel IN (".CONTEXT_BLOCK.",".CONTEXT_PAGE.")";
//
// XXX - BUG FIX 11Jan2010
// THE original patch following lines have a small bug ...
// $SQL = "SELECT *
// FROM {capabilities}
// WHERE contextlevel IN (".CONTEXT_PAGE.",".CONTEXT_BLOCK.")";
break;
I have also changed the positions of CONTEXT_PAGE and CONTEXT_BLOCK., in order to appear (80, 90) and not (90, 80), but I don't know it it is really necessary ...
Could you test it and add it to the HEAD version in order to be present on the next version of this excellent patch ?
I hope that it helps to improve this excellent Content Pages Block
Re: CMS integrations: Content Pages using Moodle 1.9
Doing a deeper accesslib.php check on the SQL FROM clauses building searching for possible missing of {$CFG->prefix}, I noted the following lines:
Re: CMS integrations: Content Pages using Moodle 1.9
Darryl,
I got the following error when I copied the files from page.zip from your contribution on this page. There is no "update" page in the page folder.
I've copied the full error message below.
regards,
Richard
PHP Notice: Capability "moodle/page:update" was not found! This should be fixed in code.
- line 382 of lib\accesslib.php: call to debugging()
- line 32 of page\index.php: call to has_capability()
- line 5772 of lib\weblib.php: call to debugging()
- line 4248 of lib\adminlib.php: call to print_error()
- line 50 of page\index.php: call to admin_externalpage_setup()
The patches provided by the .zip files in this thread are outdated, this has been implemented as a patch in Moodle contrib for the latest version of Moodle (1.9.5).
You should download the patch file from http://cvs.moodle.org/contrib/patches/block_page/block_page.patch?revision=1.1.2.4&view=markup and (on linux) use the patch -p1 command from the root of your Moodle installation.
Make sure that you get rid of the files from the .zip folder first (everything in the pages folder of your Moodle installation). If you have a mdl_pages database table, you will need to delete that in order for the patch to install properly.
I'll be gone for a week, but please report any issues in the Moodle Tracker.
~Darryl
PS - Is there a way to remove the attachments from those earlier posts to prevent future confusion?
Darryl,
Thanks for that. I've unzipped your file, and copied across the new files. Where to from there? Should this appear as a new type of block, or do I change the page settings?
Also ... do I need to re-create the mdl_pages table in the database. I previously deleted this.
regards,
Richard
We have been enjoying the Content Pages 'hack' (block) now for some time and I just ran into a little hitch that I'm wondering how to work around.
I tried to embed (link to) a Flash movie but for some reason the multimedia plugin in Moodle is not identifying it in the Page. I can do the same thing in a News post, forums etc. and the movie is displayed correctly but it's not working on a page created with the Content Pages addition. I'm assuming that the Moodle core multimedia plugin isn't called but not sure if that's a correct assumption...or even if I'm wording it correctly.
Any help would be appreciated. We'd like to add some more flashy (excuse the pun) content in the pages we've created.
Jason
Hello, I’m quite new to Moodle and are very interested on this block!
I'm using Moodle 1.9.5+ and I will try this block on it.
So, looking into the zip contents I detected one thing that I believe that could be a bug:
On line 57 of file tabs.php, there is:
$navlinks[] = array('name' => get_string('roles'), 'link' => "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=$context->id", 'type' => 'misc');
The second "$CFG->" is correct ?
I whish to you, Darryl and all, a very good yr 2010!
Thanks Darryl, for your prompt feedback, which shows how newbie I am concerning moodle programming!
I have also some doubts concernig the CONTEXT_GROUP:
- Why it is removed (from $CFG/admin/roles/tabs.php, $CFG/lib/accesslib.php, as example) on the implementation of this block al the referrences to CONTEXT_GROUP ?
- What could be the implications of this removings on the overall Moodle?
Many thanks in advance for any replies it
You helped me, some time back, to change a setting that removes all blocks from pages created by the Content Pages block. For some reason though, with a newer version of Moodle and changes that have taken place since then, I have blocks on my pages (messages and the calendar) that I want to remove. Do you have any idea how I might go about getting these to disappear?
I went back and checked the setting that you pointed me to before:
$blocknames = 'admin_tree,site_news:login,messages,calendar_month';
to
$blocknames = '';
but it no longer successfully removes the blocks.
Thanks in advance for any help you can provide.
Jason
Thanks so much for the reply. I guess I was close but since I'm still a novice when it comes to php, it was right in front of me and I didn't even realize it.
I just commented out the entire 'right column' portion as follows:
// The right column
//if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || $PAGE->user_allowed_editing()) {
// echo '<td id="right-column">';
// print_container_start();
// blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
// print_container_end();
// echo '</td>';
// }
// break;
I don't think this is going to cause any issues for us. We are using the Content Pages block to add content to our front page and don't want the blocks to appear just for cleanliness purposes. Also, I've noticed on some older browsers that the appearance of the blocks causes the formatting to be very strange. I know, we should upgrade our browsers but the tech office is slow at getting things done unless there is a BIG problem.
On a different note, I noticed a while back that mp3 files, flv files, etc. embedded into one of the pages made by the Content Pages block do not get interpreted by Moodle's multimedia plugin. Is this by design, something that was missed, or something that would be difficult to accomplish?
Thanks again for your help.
Jason
Darryl,
I notice that it has been some time since there was any activity here so I suspect that maintenance of this block has been ceased but I wanted to ask anyway, are there any plans to upgrade this for Moodle 2.X? I am now solidly in Moodle 2, as I'm sure are more and more users, but don't see this functionality in the new version of Moodle Maybe this is already compatible with Moodle 2 and I just haven't realized it...?
Jason
Hello, I’m quite new to Moodle and would appreciate some help!
I’ve installed Contents Page as per ftp drag and drop instruction posted above, I clicked on notifications, click on continue and got the message that Content Page had been successfully installed – On accessing Contents Page from the Admin menu when the page loads (moodle/blocks/page/index.php) I get a HTTP 500 internal server error – can anyone please help?
I’m using Moodle 1.9.2
Thanks
This error is encountered if you do not have admin privileges or if you are not logged in. This means that you are not authorized to enter such an area or run such scripts.
But I am logged in as the administrator and just did this installation with moodle 1.9.5 so am totally lost on the cause for this. Any help?