'name="' . $prefix . qa_dhp_admin::DELETE_Q_BTN . '" class="qa-form-light-button qa-form-light-button-delete" onclick="dhp_ask_user_confirmation(event);"', 'label' => dhp_lang('delete_q'), 'popup' => qa_lang('question/delete_q_popup'), ); } } } if ( !function_exists('ami_dhp_add_a_delete_button')) { /** * Adds delete button to the answer * * @param $buttons * @param $post */ function ami_dhp_add_a_delete_button(&$buttons, $post) { if ( !qa_opt(qa_dhp_admin::PLUGIN_ENABLED) || !(ami_dhp_is_user_eligible_to_delete(qa_get_logged_in_userid(), @$post['userid'])) || isset($buttons['delete'])) { // if the feature is not enabled from the admin panel , then return a falsy value , do not process anything return false; } $prefix = 'a' . $post['postid'] . '_'; if (qa_clicked($prefix . qa_dhp_admin::DELETE_A_BTN)) { ami_dhp_post_delete_recursive($post['postid']); qa_redirect(qa_request()); exit; } else { // add the anonymous buton $buttons[ qa_dhp_admin::DELETE_A_BTN ] = array( 'tags' => 'name="' . $prefix . qa_dhp_admin::DELETE_A_BTN . '" class="qa-form-light-button qa-form-light-button-delete" onclick="dhp_ask_user_confirmation(event);"', 'label' => dhp_lang('delete_a'), 'popup' => qa_lang('question/delete_a_popup'), ); } } } if ( !function_exists('ami_dhp_add_c_delete_button')) { /** * Adds delete button to the comment * * @param $buttons * @param $post */ function ami_dhp_add_c_delete_button(&$buttons, $post) { if ( !qa_opt(qa_dhp_admin::PLUGIN_ENABLED) || !(ami_dhp_is_user_eligible_to_delete(qa_get_logged_in_userid(), @$post['userid'])) || isset($buttons['delete'])) { // if the feature is not enabled from the admin panel , then return a falsy value , do not process anything return false; } $prefix = 'c' . $post['postid'] . '_'; if (qa_clicked($prefix . qa_dhp_admin::DELETE_C_BTN)) { ami_dhp_post_delete_recursive($post['postid']); qa_redirect(qa_request()); exit; } else { // add the anonymous buton $buttons[ qa_dhp_admin::DELETE_C_BTN ] = array( 'tags' => 'name="' . $prefix . qa_dhp_admin::DELETE_C_BTN . '" class="qa-form-light-button qa-form-light-button-delete" onclick="dhp_ask_user_confirmation(event);"', 'label' => dhp_lang('delete_c'), 'popup' => qa_lang('question/delete_c_popup'), ); } } } if ( !function_exists('ami_dhp_is_user_eligible_to_delete')) { /** * Checks if the user is eligible to delete the post * * @param null $userid if the userid is not passed uses loggedin userid * @param null $post_userid * * @return bool */ function ami_dhp_is_user_eligible_to_delete($userid = null, $post_userid = null) { // if the plugin is not enabled first reuturn false if ( !qa_opt(qa_dhp_admin::PLUGIN_ENABLED)) { return false; } if (is_null($userid) || !isset($userid)) { // if the userid is not set then get the logged in userid $userid = qa_get_logged_in_userid(); } if (is_null($userid) && !qa_is_logged_in()) { // if still it is null then ret false return false; } // return true for all special users that is allowed from admin panel if (qa_get_logged_in_level() >= qa_opt(qa_dhp_admin::MIN_LEVEL_TO_DELETE_Q)) { return true; } if (qa_opt(qa_dhp_admin::SAME_USER_CAN_DELETE_QA) && !is_null($post_userid) && ((int) $userid == (int) $post_userid)) { return true; } return false; } } /** * Returns the language value as defined in qa-dhp-lang-*.php * * @param $indentifier * @param null $subs * * @return mixed|string */ function dhp_lang($indentifier, $subs = null) { if ( !is_array($subs)) return empty($subs) ? qa_lang('ami_dhp/' . $indentifier) : qa_lang_sub('ami_dhp/' . $indentifier, $subs); else return strtr(qa_lang('ami_dhp/' . $indentifier), $subs); } /* Omit PHP closing tag to help avoid accidental output */