function theme_ffd_category_filter_menu_hook_handler($hook, $type, $return_value, $params) { if (elgg_in_context("questions")) { $return_value[] = ElggMenuItem::factory(array("name" => "most_viewed", "text" => elgg_echo("theme_ffd:questions:filter:most_viewed"), "href" => "questions/most_viewed", "priority" => 600)); $return_value[] = ElggMenuItem::factory(array("name" => "filter-category", "text" => elgg_echo("theme_ffd:questions:filter:category") . elgg_view_icon("caret-down"), "href" => "#", "priority" => 1000, "item_class" => "float-alt")); $options = array("type" => "group", "limit" => false, "metadata_name_value_pairs" => array("name" => "questions_enable", "value" => "yes"), "joins" => "JOIN " . elgg_get_config("dbprefix") . "groups_entity ge ON e.guid = ge.guid", "order_by" => "ge.name"); $group_batch = new ElggBatch("elgg_get_entities_from_metadata", $options); foreach ($group_batch as $group) { if (elgg_in_context("workflow")) { if (questions_workflow_enabled($group)) { $context = "workflow"; } else { $context = false; } } else { $context = "all"; } if ($context) { $return_value[] = ElggMenuItem::factory(array("name" => "filter-category_" . $group->getGUID(), "text" => elgg_view_icon("share-square", "mrs") . $group->name, "href" => "questions/group/" . $group->getGUID() . "/" . $context, "parent_name" => "filter-category")); } } } elseif (elgg_in_context('cafe')) { $return_value[] = ElggMenuItem::factory(array("name" => "filter-category", "text" => elgg_echo("theme_ffd:questions:filter:category") . elgg_view_icon("caret-down"), "href" => "#", "priority" => 1000, "item_class" => "float-alt")); $options = array('search', 'share', 'experience'); foreach ($options as $option) { $return_value[] = ElggMenuItem::factory(array("name" => "filter-category_" . $option, "text" => elgg_view_icon("share-square", "mrs") . elgg_echo('theme_ffd:cafe:purpose:' . $option), "href" => "cafe/purpose/" . $option, "parent_name" => "filter-category")); } } return $return_value; }
/** * Group plugin settings * * @package Questions */ $group = elgg_extract("entity", $vars); $noyes_options = array("no" => elgg_echo("option:no"), "yes" => elgg_echo("option:yes")); if (!empty($group) && elgg_instanceof($group, "group") && $group->canEdit() && $group->questions_enable == "yes") { $solution_time = questions_get_solution_time($group); $content = "<div>"; $content .= elgg_echo("questions:settings:general:solution_time"); $content .= elgg_view("input/dropdown", array("name" => "solution_time", "value" => $solution_time, "options" => range(0, 30), "class" => "mls")); $content .= "<div class='elgg-subtext'>" . elgg_echo("questions:group_settings:solution_time:description") . "</div>"; $content .= "</div>"; if (questions_workflow_enabled()) { if (questions_workflow_enabled($group)) { $workflow_enabled = "yes"; } else { $workflow_enabled = "no"; } $content .= "<div>"; $content .= elgg_echo("questions:groupsettings:workflow:enable"); $content .= elgg_view("input/dropdown", array("name" => "workflow_enabled", "value" => $workflow_enabled, "options_values" => $noyes_options, "class" => "mls")); $content .= "<div class='elgg-subtext'>" . elgg_echo("questions:groupsettings:workflow:enable:description") . "</div>"; $content .= "</div>"; } $content .= "<div class='elgg-foot'>"; $content .= elgg_view("input/hidden", array("name" => "group_guid", "value" => $group->getGUID())); $content .= elgg_view("input/submit", array("value" => elgg_echo("save"))); $content .= "</div>"; $form = elgg_view("input/form", array("body" => $content, "action" => "action/questions/group_settings"));
/** * Return the number of days it should take to solve a question. * * @param ElggEntity $container if a group is provided, first the setting of the group is checked, then the default setting of the site * * @return int the number of days it should take to solve the question. 0 for infinite */ function questions_get_solution_time(ElggEntity $container) { $result = 0; if (questions_workflow_enabled()) { return 0; } // get site setting $result = (int) elgg_get_plugin_setting("site_solution_time", "questions"); // check is group if (elgg_instanceof($container, "group")) { // get group setting $group_setting = $container->getPrivateSetting("questions_solution_time"); if ($group_setting !== false && $group_setting !== null) { // we have a valid group setting $result = (int) $group_setting; } } return $result; }
// build page elements $title_icon = ""; $content = elgg_view_entity($question, array('full_view' => true)); // add the rest of the answers $options = array('type' => 'object', 'subtype' => 'answer', 'container_guid' => $question->guid, 'count' => true, 'limit' => false, 'order_by' => 'e.time_created', 'pagination' => false); if (elgg_is_active_plugin("likes")) { // order answers based on likes $dbprefix = elgg_get_config("dbprefix"); $likes_id = add_metastring("likes"); $options["selects"] = array("(SELECT count(a.name_id) AS likes_count\n\t\tFROM " . $dbprefix . "annotations a\n\t\tWHERE a.entity_guid = e.guid\n\t\tAND a.name_id = " . $likes_id . ") AS likes_count"); } $answers = elgg_list_entities($options); $count = elgg_get_entities($options); $answer_title = elgg_view_icon("comment-o", "mrs") . $count . " " . elgg_echo('answers'); $content .= elgg_view_module('info', $answer_title, $answers, array("class" => "mtm ffd-answers")); // add answer form if ($question->getStatus() == "open" && $question->canWriteToContainer(0, 'object', 'answer')) { $add_form = elgg_view_form('object/answer/add', array(), array('container_guid' => $question->guid)); $content .= elgg_view_module('info', elgg_echo('answers:addyours'), $add_form, array('id' => 'questions-answer-add')); } elseif ($question->getStatus() == "closed") { // add an icon to show this question is closed $title_icon = elgg_view_icon("lock-closed"); } // switch to go from frontend to backend if (questions_workflow_enabled() && questions_is_expert()) { $overview = elgg_view('questions/overview', array('question' => $question)); } else { $overview = ""; } $body = elgg_view_layout('content', array('content' => $overview . $content, 'filter' => '')); echo elgg_view_page($title, $body);
/** * This function is executed when the system is initialized * * @return void */ function questions_init() { // extend CSS/JS elgg_extend_view("css/elgg", "css/questions/site"); elgg_extend_view("js/elgg", "js/questions/site"); elgg_extend_view("js/admin", "js/questions/admin"); elgg_register_menu_item("site", array("name" => 'questions', "text" => elgg_echo('questions'), "href" => "questions/all")); // make question and answer searchable elgg_register_entity_type("object", QUESTION_OBJECT); elgg_register_entity_type("object", ANSWER_OBJECT); if (questions_workflow_enabled()) { elgg_register_entity_type("object", INTANSWER_OBJECT); } // register widget elgg_register_widget_type('questions', elgg_echo("widget:questions:title"), elgg_echo("widget:questions:description"), "index,profile,dashboard,groups", true); // register page handler for nice urls elgg_register_page_handler('questions', 'questions_page_handler'); elgg_register_page_handler('answers', 'answers_page_handler'); elgg_register_page_handler('intanswers', 'intanswers_page_handler'); // register group admin options add_group_tool_option('questions', elgg_echo("questions:enable"), false); elgg_extend_view("groups/tool_latest", "questions/group_module"); elgg_extend_view("groups/edit", "plugins/questions/group_settings"); // plugin hooks elgg_register_plugin_hook_handler("register", "menu:owner_block", 'questions_owner_block_menu_handler'); elgg_register_plugin_hook_handler("register", "menu:user_hover", 'questions_user_hover_menu_handler'); elgg_register_plugin_hook_handler("register", 'menu:entity', 'questions_entity_menu_handler'); elgg_register_plugin_hook_handler("register", 'menu:filter', 'questions_filter_menu_handler'); elgg_register_plugin_hook_handler("register", 'menu:workflow_filter', 'questions_workflow_menu_handler'); elgg_register_plugin_hook_handler("container_permissions_check", "object", 'questions_container_permissions_handler'); elgg_register_plugin_hook_handler("permissions_check", "object", 'questions_permissions_handler'); elgg_register_plugin_hook_handler("widget_url", "widget_manager", 'questions_widget_url_handler'); elgg_register_plugin_hook_handler("cron", "daily", 'questions_daily_cron_handler'); elgg_register_plugin_hook_handler("notify:annotation:message", "answer", "questions_notify_message_handler"); elgg_register_plugin_hook_handler("notify:annotation:subject", "answer", "questions_notify_subject_handler"); // events elgg_register_event_handler("leave", "group", "questions_leave_group_handler"); elgg_register_event_handler("delete", "member_of_site", "questions_leave_site_handler"); // actions elgg_register_action("questions/toggle_expert", dirname(__FILE__) . "/actions/toggle_expert.php"); elgg_register_action("questions/group_settings", dirname(__FILE__) . "/actions/group_settings.php"); // admin actions elgg_register_action("questions/settings/save", dirname(__FILE__) . "/actions/admin/settings_save.php", "admin"); elgg_register_action("questions/admin/csv_export", dirname(__FILE__) . "/actions/admin/csv_export.php", "admin"); elgg_register_action("questions/admin/workflow_phase/add", dirname(__FILE__) . "/actions/admin/workflow_phase/add.php", "admin"); elgg_register_action("questions/admin/workflow_phase/delete", dirname(__FILE__) . "/actions/admin/workflow_phase/delete.php", "admin"); elgg_register_action("questions/admin/workflow_phase/reorder", dirname(__FILE__) . "/actions/admin/workflow_phase/reorder.php", "admin"); // question $actions_base = dirname(__FILE__) . '/actions/object/question'; elgg_register_action("object/question/save", "{$actions_base}/save.php"); elgg_register_action("object/question/move_to_discussions", "{$actions_base}/move_to_discussions.php"); elgg_register_action("questions/delete", "{$actions_base}/delete.php"); elgg_register_action("object/question/workflow_open", "{$actions_base}/workflow_open.php"); elgg_register_action("object/question/workflow_keep_closed", "{$actions_base}/workflow_keep_closed.php"); elgg_register_action("object/question/workflow_claim", "{$actions_base}/workflow_claim.php"); // answer $actions_base = dirname(__FILE__) . "/actions/object/answer"; elgg_register_action('object/answer/add', "{$actions_base}/save.php"); elgg_register_action('object/answer/edit', "{$actions_base}/save.php"); elgg_register_action('answers/delete', "{$actions_base}/delete.php"); elgg_register_action('answers/toggle_mark', "{$actions_base}/toggle_mark.php"); // intanswer $actions_base = dirname(__FILE__) . "/actions/object/intanswer"; elgg_register_action('object/intanswer/add', "{$actions_base}/save.php"); elgg_register_action('object/intanswer/edit', "{$actions_base}/save.php"); elgg_register_action('intanswers/delete', "{$actions_base}/delete.php"); elgg_register_plugin_hook_handler('unit_test', 'system', 'questions_test'); }
/** * Handles all question pages * * @param array $segments */ function questions_page_handler($segments) { elgg_push_breadcrumb(elgg_echo('questions'), "questions/all"); $pages = dirname(dirname(__FILE__)) . "/pages/questions"; switch ($segments[0]) { case "all": include "{$pages}/all.php"; break; case "owner": include "{$pages}/owner.php"; break; case "view": set_input('guid', $segments[1]); include "{$pages}/view.php"; break; case "add": gatekeeper(); include "{$pages}/add.php"; break; case "todo": if (isset($segments[1]) && is_numeric($segments[1])) { set_input("group_guid", $segments[1]); } include "{$pages}/todo.php"; break; case "edit": gatekeeper(); set_input('guid', $segments[1]); include "{$pages}/edit.php"; break; case "group": group_gatekeeper(); set_input("group_guid", $segments[1]); $container = get_entity($segments[1]); if (!$container instanceof ElggGroup) { register_error(elgg_echo('questions:workflow:nogroup')); forward(REFERER); } switch ($segments[2]) { case "all": include "{$pages}/owner.php"; break; case "workflow": if (!questions_workflow_enabled()) { register_error(elgg_echo('questions:workflow:notenabled')); forward(REFERER); } questions_expert_gatekeeper(); $workflow = true; include "{$pages}/workflow.php"; break; default: include "{$pages}/owner.php"; } break; case "workflow": if (!questions_workflow_enabled()) { register_error(elgg_echo('questions:workflow:notenabled')); forward(REFERER); } if (!elgg_is_logged_in()) { $_SESSION['last_forward_from'] = current_page_url(); forward('/login'); } questions_expert_gatekeeper(); $workflow = true; switch ($segments[1]) { case "view": set_input('guid', $segments[2]); $question = get_entity($segments[2]); include "{$pages}/view.php"; break; default: include "{$pages}/workflow.php"; } break; case "experts": if (isset($segments[1]) && is_numeric($segments[1])) { elgg_set_page_owner_guid($segments[1]); } include "{$pages}/experts.php"; break; case "admin": if ($segments[1] == "forms" && $segments[2] == "phase_field") { set_input('guid', $segments[3]); include dirname(dirname(__FILE__)) . "/pages/forms/phase_field.php"; } else { return false; } break; default: forward("questions/all"); return false; } return true; }
/** * In some cases we want to block writing to a question, or we want to * For questions we need to make an exception as a user wants someone else to be able * to comment on his question. * * @param string $hook the 'permission' hook * @param string $type the type * @param unknown_type $returnvalue default return value * @param array $params supplied params * * @return bool */ function questions_permissions_handler($hook, $type, $returnvalue, $params) { $entity = elgg_extract("entity", $params); $user = elgg_extract("user", $params); if (!empty($user) && !empty($params) && is_array($params)) { if (elgg_instanceof($entity, "object", "question")) { // user is owner if ($user->getGUID() == $entity->getOwnerGUID()) { if ($entity->getStatus() == "closed") { return false; } else { return true; } } // enable access for expert $container = $entity->getContainerEntity(); if (questions_experts_enabled()) { if (questions_workflow_enabled()) { return questions_is_expert(); } else { return questions_is_expert($container, $user); } } } if (elgg_instanceof($entity, "object", "answer") | elgg_instanceof($entity, "object", "intanswer")) { // reset rights inherited from container if ($entity->getOwnerGUID() != $user->getGUID()) { return false; } } } }