getSubType() == 'disctopic' ) { $entity = $params['entity']; $m = ""; $m .= list_annotations($entity->getGUID(),'generic_comment', 10); $m .= elgg_view('discussions/forms/leave_comment', array('entity' => $entity)); return $m; } } function discussions_pages() { global $CONFIG; if (get_context() == "discussions") { /* if (isLoggedIn()) { } */ /*translation:All topics*/ add_submenu_item(elgg_echo('koolielu:submenu_item_all_topics'), $CONFIG->wwwroot . "pg/discussions"); /*translation:New topic*/ add_submenu_item(elgg_echo('koolielu:submenu_item_new_topic'), $CONFIG->wwwroot . "pg/discussions/new_topic"); } } function disctopic_url($dt) { global $CONFIG; return $CONFIG->url . "pg/discussions/read/" . $dt->getGUID(); } function shorten_text($text, $max_length) { if (strlen($text) <= $max_length) { return $text; } $text = substr($text, 0, $max_length); $text = substr($text, 0, strrpos($text, ' ')); $text .= "..."; return $text; } function discussions_handler($page) { global $CONFIG; switch ($page[0]) { case "new_topic": include($CONFIG->pluginspath . "discussions/new_topic.php"); break; case "edit_topic": include($CONFIG->pluginspath . "discussions/edit_topic.php"); break; case "read": set_input('threadid', $page[1]); include($CONFIG->pluginspath . "discussions/read.php"); break; case "section": include($CONFIG->pluginspath . "discussions/disc_section.php"); break; default: include($CONFIG->pluginspath . "discussions/disc_index.php"); break; } return true; } function disctopic_hook($hook_name, $entity_type, $return_value, $parameters) { $entity = $parameters['entity']; if ($entity->getSubtype() == 'disctopic' && isEditor()) { return true; } } function get_discussions_sections() { return array( /*translation:General educational*/ 'ge' => elgg_echo('koolielu:discussions:topic:general_educational'), /*translation:Colleague advice*/ 'ca' => elgg_echo('koolielu:discussions:topic:colleague_advice'), /*translation:Student asking for advice*/ 'sq' => elgg_echo('koolielu:discussions:topic:student_quistion'), /*translation:Partent and teacher discussions*/ 'pt' => elgg_echo('koolielu:discussions:topic:parent_and_teacher') ); } function get_current_discussions_section_id() { $sections = get_discussions_sections(); $section = get_input('section'); if (!($section && array_key_exists($section, $sections))) { $section = 'ge'; } return $section; } /** * Return a list of entities based on the given search criteria. * * @param mixed $meta_name * @param mixed $meta_value * @param string $entity_type The type of entity to look for, eg 'site' or 'object' * @param string $entity_subtype The subtype of the entity. * @param int $limit * @param int $offset * @param string $order_by Optional ordering. * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites. * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false) * * @return int|array A list of entities, or a count if $count is set to true */ function discussions_get_last_commented_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) { global $CONFIG; $meta_n = get_metastring_id($meta_name); $meta_v = get_metastring_id($meta_value); $entity_type = sanitise_string($entity_type); $entity_subtype = get_subtype_id($entity_type, $entity_subtype); $limit = (int)$limit; $offset = (int)$offset; if ($order_by == "") $order_by = "e.time_created desc"; else $order_by = "e.time_created, {$order_by}"; $order_by = sanitise_string($order_by); $site_guid = (int) $site_guid; if ((is_array($owner_guid) && (count($owner_guid)))) { foreach($owner_guid as $key => $guid) { $owner_guid[$key] = (int) $guid; } } else { $owner_guid = (int) $owner_guid; } if ($site_guid == 0) $site_guid = $CONFIG->site_guid; //$access = get_access_list(); $where = array(); if ($entity_type!=="") $where[] = "e.type='$entity_type'"; if ($entity_subtype) $where[] = "e.subtype=$entity_subtype"; if ($meta_name!=="") $where[] = "m.name_id='$meta_n'"; if ($meta_value!=="") $where[] = "m.value_id='$meta_v'"; if ($site_guid > 0) $where[] = "e.site_guid = {$site_guid}"; if (is_array($owner_guid)) { $where[] = "e.container_guid in (".implode(",",$owner_guid).")"; } else if ($owner_guid > 0) $where[] = "e.container_guid = {$owner_guid}"; if (!$count) { $query = "SELECT distinct e.* "; } else { $query = "SELECT count(distinct e.guid) as total "; } // Join latest annotation $annotation_join = " JOIN (SELECT MAX(time_created) as time_created, entity_guid FROM {$CONFIG->dbprefix}annotations GROUP BY entity_guid) ea on e.guid = ea.entity_guid "; $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid {$annotation_join} where"; foreach ($where as $w) $query .= " $w and "; $query .= get_access_sql_suffix("e"); // Add access controls $query .= ' and ' . get_access_sql_suffix("m"); // Add access controls // Custom order $order_by = "ea.time_created desc"; if (!$count) { $query .= " order by $order_by limit $offset, $limit"; // Add order and limit return get_data($query, "entity_row_to_elggstar"); } else { if ($row = get_data_row($query)) return $row->total; } return false; } /** * Return a list of entities based on the given search criteria. * * @param mixed $meta_name * @param mixed $meta_value * @param string $entity_type The type of entity to look for, eg 'site' or 'object' * @param string $entity_subtype The subtype of the entity. * @param int $limit * @param int $offset * @param string $order_by Optional ordering. * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites. * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false) * * @return int|array A list of entities, or a count if $count is set to true */ function search_discussions_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false, $search_criteria = "") { global $CONFIG; $meta_n = get_metastring_id($meta_name); $meta_v = get_metastring_id($meta_value); $entity_type = sanitise_string($entity_type); $entity_subtype = get_subtype_id($entity_type, $entity_subtype); $limit = (int)$limit; $offset = (int)$offset; if ($order_by == "") $order_by = "e.time_created desc"; else $order_by = "e.time_created, {$order_by}"; $order_by = sanitise_string($order_by); $site_guid = (int) $site_guid; if ((is_array($owner_guid) && (count($owner_guid)))) { foreach($owner_guid as $key => $guid) { $owner_guid[$key] = (int) $guid; } } else { $owner_guid = (int) $owner_guid; } if ($site_guid == 0) $site_guid = $CONFIG->site_guid; //$access = get_access_list(); $where = array(); if ($entity_type!=="") $where[] = "e.type='$entity_type'"; if ($entity_subtype) $where[] = "e.subtype=$entity_subtype"; if ($meta_name!=="") $where[] = "m.name_id='$meta_n'"; if ($meta_value!=="") $where[] = "m.value_id='$meta_v'"; if ($site_guid > 0) $where[] = "e.site_guid = {$site_guid}"; if (is_array($owner_guid)) { $where[] = "e.container_guid in (".implode(",",$owner_guid).")"; } else if ($owner_guid > 0) $where[] = "e.container_guid = {$owner_guid}"; if (!$count) { $query = "SELECT distinct e.* "; } else { $query = "SELECT count(distinct e.guid) as total "; } $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid JOIN {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid where"; // Add search criteria $search_criteria = sanitise_string($search_criteria); $query .= " o.title like \"%{$search_criteria}%\" and"; foreach ($where as $w) $query .= " $w and "; $query .= get_access_sql_suffix("e"); // Add access controls $query .= ' and ' . get_access_sql_suffix("m"); // Add access controls if (!$count) { $query .= " order by $order_by limit $offset, $limit"; // Add order and limit return get_data($query, "entity_row_to_elggstar"); } else { if ($row = get_data_row($query)) return $row->total; } return false; } global $CONFIG; register_elgg_event_handler('init', 'system', 'discussions_init'); register_elgg_event_handler('pagesetup', 'system', 'discussions_pages'); register_action("discussions/add", true, $CONFIG->pluginspath . "discussions/actions/add.php"); register_action("discussions/edit", false, $CONFIG->pluginspath . "discussions/actions/edit.php"); register_action("discussions/delete", false, $CONFIG->pluginspath . "discussions/actions/delete.php"); register_action("discussions/frontpage_topic", false, $CONFIG->pluginspath . "discussions/actions/frontpage_topic.php"); register_action("discussions/leave_comment", true, $CONFIG->pluginspath . "discussions/actions/leave_comment.php"); ?>