Programming Wordpress: data export import links lynx opml xml
by bseanvt
leave a comment
How to Import/Export Your WordPress Blogroll… er, Your Links
It’s not immediately apparent how to import/export the links in your WordPress blogroll. One would expect that the import/export tool, used to backup/restore WordPress posts and pages would handle this functionality as well. But the import/export tool has many options. You need to select the Blogroll import option (located near the top of the list) and provide the tool with either the destination of a valid OPML XML url, or upload a valid OPML XML file. If you’re running on WordPress, this can be found by appending a “/wp-links-opml.php” to the URL of your domain. For example, http://seanbehan.com/wp-links-opml.php will show you my blogroll in XML. If your running out of a subdirectory, don’t forget to include that path in the URL.
If for some reason you’re running a development website on your localhost, obviously the live, remote site will not be able to contact your localhost for the data. You will have to upload the XML file to the remote site. The WordPress export tool does not provide the means to generate a the OPML XML file for you. You will have to visit the /wp-links-opml.php file and download the contents yourself, but this depends on how your browser handles XML files. Firefox will show you the raw XML, however, Safari will show you the contents of the XML nodes… which will most likely be only the name of your website. You’ll need to go to “View Source” option to see the actual XML code.Copy and past the XML to a file with the .xml file extension somewhere on your hard drive. Visit the import > blogroll tool and upload the file!
A simple way to download the file contents is to use the command line web browser Lynx. http://en.wikipedia.org/wiki/Lynx_%28web_browser%29
Just give Lynx the destination URL and the file to write to (it doesn’t have to exist) and then you can upload this file
<pre>
lynx -source URL > my-links.xml
</pre>
More info on lynx available here: http://kb.iu.edu/data/aczi.html
Programming moodle php: context course has_capbility moodle php teacher
by bseanvt
1 comment
How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function
After an hour of fruitless searching through the docs and forums, I finally found an answer to my simple question, of course buried in the depths of the shark infested, murky water that is the Moodle code base .
How do I check if a user is a course creator for a given course? I’m still not 100% sure, the access control policy seems needlessly confusing on first glance and even after reading the heady and mostly pointless, expose on how roles/perms are calculated (Available Here: http://docs.moodle.org/en/How_permissions_are_calculated ) If you notice the section titled “Some Practical Examples” is 100% empty! (I’ve added my code to the wiki so not 100% empty any longer) The most useful part of the docs are completely empty! Instead boatloads of time went into a treatise on the internals and lovely graphs like this one 
But you could always hop into the forum dedicated just to this chunk of the code base (Available here: http://moodle.org/mod/forum/view.php?f=941&page=0) and search through the 500 topics w/ 5000+(i didn’t actually count) nested discussions (including version 1.7 of moodle as well).
No, instead, ACK came to the rescue and I found a snippet that performed the task.
Without further ado
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if (has_capability('moodle/course:update', $coursecontext)) {
/** do stuff here */
}
There it is. That could have saved me an hour if mentioned in the docs!
Moodle's Most Important Function Gets No Attention
Arguably the most important function in the Moodle API, is the create_course function. One would think… after all Moodle is an LMS. Courses are the bread and butter for course management platforms, right? Taking a look at the function in the course/lib.php file reveals almost nothing about the function! WTF? … btw, the function starts at line 3260
/**
* Create a course and either return a $course object or false
*
* @param object $data - all the data needed for an entry in the 'course' table
*/
function create_course($data) {
global $CFG, $USER;
/** omitted for your sanity */
}
Wow, I think I know less about this function now than before I went digging into the code. How do I assign a teacher to my new course, how do I populate the data object it takes as a parameter (is there a course setup function)? Since courses aren’t really objects in Moodle (just glorified arrays), am I just supposed to set them up by hand… $object->param = val? Are there default values and/or required attributes that need to be set, otherwise my program is going to come to a halt? What about student enrollments? No example to help for how one might actually use this function? Do I have to really read through the code, starting at around line 3260, then jump between the rest of this monstrous 4000 line piece of spaghetti coded file and try and make sense of it works (somehow).
How is it possible that the most important function (since the core problem Moodle solves is creating courses) in the entire application has no meaningful documentation? I think I have an answer. The entire code base is soooo convoluted and a giant waste of CPU cycles, that it would too embarrassing to actually document how it even works.
Linux Programming: compression exclude photoshop psd zip
by bseanvt
leave a comment
Recursively Zip Up a Directory while Excluding Certain Files Based on File Extension Type
In the example below, I’m going to zip up a directory that includes images in both PNG and PSD file formats. However, I want to exclude the PSDs because they are huge!
zip -r my-compressed-dir-without-psd.zip directory-to-zip -x '*.psd'
Linux Programming: bzip2 commands compression tar uncompress unix
by bseanvt
leave a comment
Uncompress A Bz2 File Using Tar Command
Uncompress a bz2 file using tar command
tar --use-compress-program bzip2 -xvf your-file-to-uncompress.tar.bz2
@source http://www.kde.gr.jp/help/doc/kdebase/doc/khelpcenter/faq/HTML/bzip2.html
Convert Array to Object in PHP
function array2obj($data) {
return is_array($data) ? (object) array_map(__FUNCTION__,$data) : $data;
}
Source: http://www.serversidemagazine.com/php/how-to-convert-array-notation-to-object-notation