wwwroot . "pg/waramu/collections/" . $_SESSION['user']->username);
}
// Register cron hooks
//register_plugin_hook('cron', 'fifteenmin', 'collection_tags_update_cron');
register_plugin_hook('cron', 'daily', 'materials_moderation_message_cron');
register_action("waramu/upload_subject_logo", false, $CONFIG->pluginspath . "waramu/actions/upload_subject_logo.php");
}
function waramuresource_url($dt) {
global $CONFIG;
return $CONFIG->url . "pg/waramu/view/" . $dt->waramuID;
}
function collection_url($entity) {
global $CONFIG;
return $CONFIG->url . "pg/waramu/view_collection/" . $entity->getGUID();
}
function waramu_handler($page) {
global $CONFIG;
switch ($page[0]) {
case "oldnew":
include($CONFIG->pluginspath . "waramu/newresource.php");
break;
case "new2":
include($CONFIG->pluginspath . "waramu/upload/newresource2.php");
break;
case "upload_form":
include($CONFIG->pluginspath . "waramu/upload/upload_form.php");
break;
case "browse":
include($CONFIG->pluginspath . "waramu/search2.php");
break;
case "browse2":
include($CONFIG->pluginspath . "waramu/search2.php");
break;
case "search":
include($CONFIG->pluginspath . "waramu/search2.php");
break;
case "search2":
include($CONFIG->pluginspath . "waramu/search2.php");
break;
case "results":
include($CONFIG->pluginspath . "waramu/results.php");
break;
case "myfavorites":
set_input('uname', $page[1]);
include($CONFIG->pluginspath . "waramu/myfavorites.php");
break;
case "browser":
include($CONFIG->pluginspath . "waramu/Browser.php");
break;
case "myresources":
include($CONFIG->pluginspath . "waramu/myresources.php");
break;
case "view":
set_input('resourceid', $page[1]);
include($CONFIG->pluginspath . "waramu/view.php");
break;
case "media":
set_input('resourceid', $page[1]);
include($CONFIG->pluginspath . "waramu/std_media.php");
break;
case "edit":
set_input('resourceid', $page[1]);
include($CONFIG->pluginspath . "waramu/edit_form.php");
break;
case "download":
set_input('resourceid', $page[1]);
include($CONFIG->pluginspath . "waramu/download.php");
break;
case "moderate":
include($CONFIG->pluginspath . "waramu/moderate.php");
break;
case "rejected":
include($CONFIG->pluginspath . "waramu/rejected.php");
break;
case "frontpage":
set_input('resourceid', $page[1]);
include($CONFIG->pluginspath . "waramu/frontpage_resource.php");
break;
case "collections":
set_input('user_to_show', $page[1]);
include($CONFIG->pluginspath . "waramu/waramu_collections.php");
break;
case "translate":
include($CONFIG->pluginspath . "waramu/ajax/translate.php");
break;
case "vocabulary":
include($CONFIG->pluginspath . "waramu/ajax/vocabulary.php");
break;
case "autosuggest":
include($CONFIG->pluginspath . "waramu/ajax/autosuggest.php");
break;
case "tree":
include($CONFIG->pluginspath . "waramu/ajax/curriculumtree.php");
break;
case "lrekeywords":
include($CONFIG->pluginspath . "waramu/ajax/lrekeywords.php");
break;
case "checkurl":
include($CONFIG->pluginspath . "waramu/ajax/checkurl.php");
break;
case "acoll":
include($CONFIG->pluginspath . "waramu/ajax/collections.php");
break;
case "uploadcheck":
include($CONFIG->pluginspath . "waramu/upload/ajax_check.php");
break;
case "view_collection":
set_input('collection_id', $page[1]);
include($CONFIG->pluginspath . "waramu/view_collection.php");
break;
case "edit_collection":
set_input('collection_id', $page[1]);
include($CONFIG->pluginspath . "waramu/edit_collection.php");
break;
case "subjects":
set_input('subject_id', $page[1]);
include($CONFIG->pluginspath . "waramu/subjects_index.php");
break;
case "keywords":
set_input('keyword', $page[1]);
include($CONFIG->pluginspath . "waramu/waramu_keywords_index.php");
break;
case "embed":
include($CONFIG->pluginspath . "waramu/embed.php");
break;
default:
include($CONFIG->pluginspath . "waramu/subjects_index.php");
}
return true;
}
function waramu_pages() {
global $CONFIG;
if (get_context() == 'waramu') {
/*translation:Search materials*/
add_submenu_item(elgg_echo('koolielu:submenu_item_Search'), $CONFIG->wwwroot . "pg/waramu/search2");
/*translation:Koolielu keywords*/
//add_submenu_item(elgg_echo('koolielu:submenu_item_Keywords'), $CONFIG->wwwroot . "pg/waramu/keywords");
if (isLoggedIn()) {
/*translation:New resource*/
add_submenu_item(elgg_echo('koolielu:New_resource'), $CONFIG->wwwroot . "pg/waramu/new2");
//add_submenu_item("New Coll NG", $CONFIG->wwwroot . "pg/waramu/newcollng");
}
if (isModerator()) {
/*translation:Pending resources*/
add_submenu_item(elgg_echo('koolielu:Pending_resources'), $CONFIG->wwwroot . "pg/waramu/moderate");
}
if (isadminloggedin()) {
/*translation:Rejected resources*/
add_submenu_item(elgg_echo('koolielu:rejected_resources'), $CONFIG->wwwroot . "pg/waramu/rejected");
}
if ((page_owner() == $_SESSION['guid'] || !page_owner()) && isloggedin()) {
$logged_in_user = get_loggedin_user()->username;
/*translation:My resources*/
add_submenu_item(elgg_echo('koolielu:myresources'), $CONFIG->wwwroot . "pg/waramu/myresources");
/*translation:My collections*/
add_submenu_item(elgg_echo('koolielu:my_collections'), $CONFIG->wwwroot . "pg/waramu/collections/{$_SESSION['user']->username}");
/*translation:My favorites*/
add_submenu_item(elgg_echo('koolielu:my_favorites'), $CONFIG->wwwroot . "pg/waramu/myfavorites");
} else if (page_owner()) {
$page_owner = page_owner_entity();
/*translation:%s's collections*/
add_submenu_item(sprintf(elgg_echo("koolielu:users_collections"), $page_owner->name), $CONFIG->wwwroot."pg/waramu/collections/" . $page_owner->username);
}
/*translation:Publishing materialn in Koolielu*/
add_submenu_item(elgg_echo('koolielu:publishing_materials_menu'), $CONFIG->wwwroot . "pg/info/news/31");
/*translation:Embed searchbox*/
add_submenu_item(elgg_echo("koolielu:embedable_searchbox_link"), $CONFIG->wwwroot . "pg/waramu/embed");
}
}
function waramu_get() {
try {
$w = new Waramu(
get_plugin_setting('wurl', 'waramu'),
get_plugin_setting('wuser', 'waramu'),
get_plugin_setting('wpass', 'waramu'));
if ( isset($_SESSION['waramu_session']) ) {
$w->setSid($_SESSION['waramu_session']);
} else {
$conn_status = $w->connect();
if ( $conn_status ) {
die("Invalid Waramu connection parameters");
} else {
$_SESSION['waramu_session'] = $w->sid;
}
}
return $w;
} catch (SoapFault $sf) {
return new DummyWaramu();
}
}
/**
* Get a Waramu resource by ID
* */
function waramu_getResource($au, $wid) {
if ( is_null($wid) )
return new WaramuResource(null, '', '');
$w = waramu_get();
$obj = $w->getResource($au, $wid);
return $obj;
}
function waramu_list_resources($ids=null, $additional_icons=true, $show_koolielu=true, $params=null) {
$limit = $params['limit'];
$use_pagination = $params['use_pagination'];
$showall = $params['showall'];
if (is_null($use_pagination)) $use_pagination = true;
if (is_null($show_koolielu)) $show_koolielu = true;
if (is_null($showall)) $showall = false;
global $CONFIG;
if ( is_null($ids) ) {
$ids = $_SESSION['results'];
}
$w = waramu_get();
$ents = array();
$offset = get_input('offset');
if ( !$offset ) {
$offset = 0;
}
if (is_null($limit))
$limit = 10;
$t = 0;
foreach($ids as $id) {
if ( ($t >= $offset) && $t < $offset+$limit) {
if (gettype($id) == 'string') {
// We need to check if the resource even exists
try {
$wo = waramu_getResource("", $id);
// TODO: kind of sucks
if (!$showall) {
if ($show_koolielu && !$wo->isPublished()) {
continue;
}
if (!$show_koolielu && $wo->isPublished()) {
continue;
}
}
$ents[] = $wo;
if (!is_null($params['cp'])) {
$params['cp']($wo);
}
} catch ( Exception $e ) {
//print $id;
// If resource does not exist, we just omit it
}
} else {
// its a object here already
$ents[] = $id;
}
} else {
//$ents[] = null;
}
$t++;
}
//$res = elgg_view_entity_list($ents, count($ids), $offset, $limit);
$res = "";
if ($use_pagination) {
// TODO:XXX: need to verify if this works!
$pagination = elgg_view('navigation/pagination', array(
'baseurl' => $_SERVER['REQUEST_URI'],
'offset' => $offset,
'count' => count($ids),
'limit' => $limit
));
$res .= $pagination;
}
$res .= elgg_view('waramu/resource_list',
array('objects' => $ents, 'additional_icons' => $additional_icons, 'opts' => $params));
if ($use_pagination)
$res .= $pagination;
return $res;
}
// Cron defines
// update collection tags
// I think this is not needed anymore
function collection_tags_update_cron($hook, $entity_type, $returnvalue, $params) {
// log in as admin or else it's not possible to change entities
login(get_entity(2));
$collections = get_entities_from_metadata("needs_update", "1", "object", "collection");
foreach ($collections as $collection) {
updateCollectionTags($collection);
$collection->needs_update = 0;
$collection->save();
}
logout();
}
// send messages to moderators
function materials_moderation_message_cron($hook, $entity_type, $returnvalue, $params) {
//TODO: materials_moderation_message_cron - need refactoring!
global $CONFIG;
$moderation_limit = 1;
// XXX See if we have already run this today, and do not run that for the second time
// log in as admin or else it's not possible to change entities
login(get_entity(2));
$s_materials = array();
$main_subjects = getSubjects(); // review!
// Prepopulate subjects array
foreach ($main_subjects as $key => $title) {
$s_materials[$key] = array();
}
// Get all pending materials and populate the array
$m_ids = get_data("SELECT ID FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE status=0 ORDER BY time");
foreach ($m_ids as $m_id) {
$rid = $m_id->ID;
try {
$obj = waramu_getResource("", $rid);
} catch (Exception $e) {
continue;
}
$obj_subjects = $obj->getCurriculumSubjects();
if (is_array($obj_subjects)) {
foreach ($obj_subjects as $key => $subj_id) {
if (array_key_exists($subj_id, $s_materials)) {
$tmp_arr = $s_materials[$subj_id];
array_push($tmp_arr, $rid);
$s_materials[$subj_id] = $tmp_arr;
}
}
}
}
// Get all moderators and see if any messages need to be sent
$all_moderators = getAllModerators();
foreach ($all_moderators as $moderator) {
$m_to_moderate = array();
$moderator_subjects = $moderator->subjects;
if (!is_array($moderator_subjects)) {
$moderator_subjects = array($moderator_subjects);
}
foreach ($moderator_subjects as $key => $m_subject) {
if (array_key_exists($m_subject, $s_materials)) {
foreach ($s_materials[$m_subject] as $key => $value) {
if (!in_array($value, $m_to_moderate)) {
array_push($m_to_moderate, $value);
}
}
}
}
// See if we need to send any messages
if (sizeof($m_to_moderate) >= $moderation_limit) {
/*translation:Please moderate materials*/
$mess_title = elgg_echo("koolielu:message_title_please_moderate_materials");
/*translation:There are several materials that require your attention in Koolielu. Please go to Materials section and review them.*/
$mess_description = elgg_echo("koolielu:message_desc_please_moderate_materials");
messages_send($mess_title, $mess_description, $moderator->getGUID(), 0, 0, true, false);
}
}
// Trigger logout
logout();
}
// send messages to users
function materials_weekly_created_message_cron ($hook, $entity_type, $returnvalue, $params) {
global $CONFIG;
// log in admin or else it's not possible to change entities
$today = now();
// XXX only run if today is monday
// XXX this is not finished and should not be ran, second condition takes care of that
if ((date("w", $today) == 1) && (1 == 2)) {
login(get_entity(2));
// XXX Add entry to crons table, so that it would not run again
// Set periodics XXX see if those are right
$week_ends = now();
$week_begins = now() - (7 * 24 * 60 * 60);
//XXX See if all needed materials are included
$s_materials = array();
$main_subjects = getSubjects();
// Prepopulate subjects array
foreach ($main_subjects as $key => $title) {
$s_materials[$key] = array();
}
// Get all published materials and populate the array
$m_ids = get_data("SELECT waramu_id FROM {$CONFIG->dbprefix}koolielu_waramu_resources WHERE time BETWEEN FROM_UNIXTIME({$week_begins}) and FROM_UNIXTIME({$week_ends})");//XXX add timestamp checking for WHERE condition
foreach ($m_ids as $m_id) {
try {
$obj = waramu_getResource("", $m_id->waramu_id);
$obj_subjects = $obj->getCurriculumSubjects();
if (is_array($obj_subjects)) {
foreach ($obj_subjects as $key => $subj_id) {
if (array_key_exists($subj_id, $s_materials)) {
$tmp_arr = $s_materials[$subj_id];
// Data is stored with array >>> waramu_id, title
array_push($tmp_arr, array("waramu_id" => $m_id->waramu_id, "title" => $obj->getTitle()));
$s_materials[$subj_id] = $tmp_arr;
}
}
}
} catch (Exception $exe) {
// For some reason object could not be retrieved.
}
}
// Get all portal users
$all_users_count = get_entities("user", "", 0, "", 10, 0, true);
$all_users = get_entities("user", "", 0, "", $all_users_count, 0);
//XXX Maybe splitting into chunks might be a good idea
foreach ($all_users as $single_user) {
if (get_plugin_usersetting('waramupublishedweekly', $single_user->guid, 'waramu') == "yes") {
$suitable_ids = array();
$suitable_materials = array();
$user_subjects = $single_user->subjects;
if (!is_array($user_subjects)) {
$user_subjects = array($user_subjects);
}
foreach ($user_subjects as $key => $u_subject) {
if (array_key_exists($u_subject, $s_materials)) {
foreach($s_materials[$u_subject] as $key => $m_values) {
if (!in_array($m_values['waramu_id'], $suitable_ids)) {
array_push($suitable_ids, $m_values['waramu_id']);
array_push($suitable_materials, $m_values);
}
}
}
// See if there are materials to send message about
if ($sizeof($suitable_ids) > 0) {
//XXX Creating message
/*translation:Dear %s,*/
$sent_message = sprintf(elgg_echo("koolitlu:weekly_materials_firstline"), $single_user->name). "\n\n";
/*translation:You have shown your interest for these subjects: %s*/
$sent_message .= sprintf(elgg_echo("koolitlu:weekly_materials_subjects"), implode(", ", $user_subjects)) . "\n";
/*translation:This message is meant to inform you that within past week %s - %s time these resources have been published in subjects of your interest:*/
$sent_message .= sprintf(elgg_echo("koolielu:weekly_materials_resources"), date("d.m.Y", $week_begins), date("d.m.Y", $week_ends)) . "\n\n";
$numbering = 1;
foreach($suitabe_materials as $s_m) {
$sent_message .= $numbering . ". " . $s_m->title . " " . $CONFIG->wwwroot . "pg/waramu/view/" . $s_m->waramu_id . "\n";
$numbering += 1;
}
/*translation:Best wishes,*/
$sent_message .= "\n\n" . elgg_echo("koolielu:weekly_materials_best_wishes") . "\nKoolielu";
/*translation:Koolielu materials created last week*/
notify_user($single_user->guid, get_loggedin_user()->guid, elgg_echo("koolielu:message_weekly_notification_subject"), $sent_message);
}
}
}
}
// Trigger logout
logout();
}
}
register_elgg_event_handler('init', 'system', 'waramu_init');
register_elgg_event_handler('pagesetup', 'system', 'waramu_pages');
register_action('waramu/search', true, $CONFIG->pluginspath . "waramu/actions/search.php");
register_action('waramu/advsearch', true, $CONFIG->pluginspath . "waramu/actions/advsearch.php");
register_action('waramu/advsearchx', true, $CONFIG->pluginspath . "waramu/actions/advsearch2.php");
register_action('waramu/new_with_link', true, $CONFIG->pluginspath . "waramu/actions/new_with_link.php");
register_action('waramu/new_with_files', true, $CONFIG->pluginspath . "waramu/actions/new_with_files.php");
register_action('waramu/new_with_reserved', true, $CONFIG->pluginspath . "waramu/actions/new_with_reserved.php");
register_action('waramu/saveMetadata', false, $CONFIG->pluginspath . "waramu/actions/save_metadata.php");
register_action('waramu/goedit', false, $CONFIG->pluginspath . "waramu/actions/goedit.php");
register_action('waramu/resubmit', false, $CONFIG->pluginspath . "waramu/actions/resubmit.php");
register_action('waramu/delete', false, $CONFIG->pluginspath . "waramu/actions/delete.php");
register_action('waramu/frontpage_resource', false, $CONFIG->pluginspath . "waramu/actions/frontpage_resource.php");
register_action('waramu/remove_frontpage_resource', false, $CONFIG->pluginspath . "waramu/actions/remove_frontpage_resource.php");
register_action('waramu/reviewPending', true, $CONFIG->pluginspath . "waramu/actions/review_pending.php");
register_action('waramu/addComment', true, $CONFIG->pluginspath . "waramu/actions/add_comment.php");
register_action('waramu/deleteComment', true, $CONFIG->pluginspath . "waramu/actions/delete_comment.php");
register_action('waramu/favorite', true, $CONFIG->pluginspath . "waramu/actions/favorite.php");
register_action('waramu/go_collection_selection', true, $CONFIG->pluginspath . "waramu/actions/go_collection_selection.php");
register_action('waramu/add_to_collection', true, $CONFIG->pluginspath . "waramu/actions/add_to_collection.php");
register_action('waramu/delete_from_collection', true, $CONFIG->pluginspath . "waramu/actions/delete_from_collection.php");
register_action('waramu/goedit_collection', true, $CONFIG->pluginspath . "waramu/actions/goedit_collection.php");
register_action('waramu/edit_collection', true, $CONFIG->pluginspath . "waramu/actions/edit_collection.php");
register_action('waramu/delete_collection', true, $CONFIG->pluginspath . "waramu/actions/delete_collection.php");
register_action('waramu/save_quality_marks', true, $CONFIG->pluginspath . "waramu/actions/save_quality_marks.php");
register_action('waramu/requestpublish', true, $CONFIG->pluginspath . "waramu/actions/request_publish.php");
?>