From ba7426b54ea511a2370b4cfb7d5d1dbb2c705d75 Mon Sep 17 00:00:00 2001 From: Shaik Masthan Date: Sat, 6 Jul 2024 01:43:10 +0530 Subject: [PATCH 1/4] Comments page added --- qa-include/app/format.php | 5 +++++ qa-include/db/selects.php | 6 ++++++ qa-include/lang/qa-lang-misc.php | 1 + qa-include/lang/qa-lang-profile.php | 2 ++ qa-include/pages/user.php | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/qa-include/app/format.php b/qa-include/app/format.php index bf4450305..c6ff5419b 100644 --- a/qa-include/app/format.php +++ b/qa-include/app/format.php @@ -1518,6 +1518,11 @@ function qa_user_sub_navigation($handle, $selected, $ismyuser = false) 'label' => qa_lang_html('misc/nav_user_as'), 'url' => qa_path_html('user/' . $handle . '/answers'), ), + + 'comments' => array( + 'label' => qa_lang_html('misc/nav_user_cs'), + 'url' => qa_path_html('user/' . $handle . '/comments'), + ), ); if (isset($navigation[$selected])) diff --git a/qa-include/db/selects.php b/qa-include/db/selects.php index 1a093ad7a..a64f853eb 100644 --- a/qa-include/db/selects.php +++ b/qa-include/db/selects.php @@ -1321,6 +1321,12 @@ function qa_db_user_recent_c_qs_selectspec($voteuserid, $identifier, $count = nu qa_db_add_selectspec_opost($selectspec, 'cposts'); + $selectspec['columns']['oupvotes'] = 'cposts.upvotes'; + $selectspec['columns']['odownvotes'] = 'cposts.downvotes'; + $selectspec['columns']['onetvotes'] = 'cposts.netvotes'; + + + $selectspec['source'] .= " JOIN ^posts AS parentposts ON" . " ^posts.postid=(CASE parentposts.type WHEN 'A' THEN parentposts.parentid ELSE parentposts.postid END)" . diff --git a/qa-include/lang/qa-lang-misc.php b/qa-include/lang/qa-lang-misc.php index 5dc13c623..f01384a35 100644 --- a/qa-include/lang/qa-lang-misc.php +++ b/qa-include/lang/qa-lang-misc.php @@ -72,6 +72,7 @@ 'nav_my_favorites' => 'My favorites', 'nav_user_activity' => 'Recent activity', 'nav_user_as' => 'All answers', + 'nav_user_cs' => 'All comments', 'nav_user_pms' => 'Private messages', 'nav_user_qs' => 'All questions', 'nav_user_wall' => 'Wall', diff --git a/qa-include/lang/qa-lang-profile.php b/qa-include/lang/qa-lang-profile.php index 3c2a027b1..0420d1cf6 100644 --- a/qa-include/lang/qa-lang-profile.php +++ b/qa-include/lang/qa-lang-profile.php @@ -29,12 +29,14 @@ 'answers_by_x' => 'Answers by ^', 'bonus_points' => 'Bonus points:', 'comments' => 'Comments:', + 'comments_by_x' => 'Comments by ^', 'delete_pm_popup' => 'Delete this private message', 'delete_wall_post_popup' => 'Delete this wall post', 'extra_privileges' => 'Extra privileges:', 'gave_out' => 'Gave out:', 'my_account_title' => 'My account', 'no_answers_by_x' => 'No answers by ^', + 'no_comments_by_x' => 'No comments by ^', 'no_posts_by_x' => 'No posts by ^', 'no_questions_by_x' => 'No questions by ^', 'permit_anon_view_ips' => 'Viewing IPs of anonymous posts', diff --git a/qa-include/pages/user.php b/qa-include/pages/user.php index 53601f8db..57c51d070 100644 --- a/qa-include/pages/user.php +++ b/qa-include/pages/user.php @@ -71,6 +71,10 @@ qa_set_template('user-answers'); $qa_content = include QA_INCLUDE_DIR . 'pages/user-answers.php'; break; + case 'comments': + qa_set_template('user-comments'); + $qa_content = include QA_INCLUDE_DIR . 'pages/user-comments.php'; + break; case null: $qa_content = include QA_INCLUDE_DIR . 'pages/user-profile.php'; From 90e4728ccd2ae3e582fdc6a97b6835f51706e33d Mon Sep 17 00:00:00 2001 From: Shaik Masthan Date: Sat, 6 Jul 2024 01:54:54 +0530 Subject: [PATCH 2/4] MISSING Comments page added --- qa-include/pages/user-comments.php | 104 +++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 qa-include/pages/user-comments.php diff --git a/qa-include/pages/user-comments.php b/qa-include/pages/user-comments.php new file mode 100644 index 000000000..4fdb7cabb --- /dev/null +++ b/qa-include/pages/user-comments.php @@ -0,0 +1,104 @@ + 'method="post" action="' . qa_self_html() . '"', + + 'hidden' => array( + 'code' => qa_get_form_security_code('vote'), + ), +); + +$qa_content['q_list']['qs'] = array(); + +$htmldefaults = qa_post_html_defaults('Q'); +$htmldefaults['whoview'] = false; +$htmldefaults['avatarsize'] = 0; +$htmldefaults['ovoteview'] = true; +$htmldefaults['answersview'] = false; + +foreach ($questions as $question) { + $options = qa_post_html_options($question, $htmldefaults); + $options['voteview'] = qa_get_vote_view('C', false, false); + + $qa_content['q_list']['qs'][] = qa_other_to_q_html_fields($question, $loginuserid, qa_cookie_get(), + $usershtml, null, $options); +} + +$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next')); + + +// Sub menu for navigation in user pages + +$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']); +$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'comments', $ismyuser); + + +return $qa_content; From 643303e275802489f860f875084ca85bd3b65353 Mon Sep 17 00:00:00 2001 From: SHAIK MASTHAN <84255313+csemasthan@users.noreply.github.com> Date: Mon, 12 May 2025 19:56:53 +0530 Subject: [PATCH 3/4] Update user-comments.php Pagination issue resolved --- qa-include/pages/user-comments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa-include/pages/user-comments.php b/qa-include/pages/user-comments.php index 4fdb7cabb..b7c4d18f3 100644 --- a/qa-include/pages/user-comments.php +++ b/qa-include/pages/user-comments.php @@ -92,7 +92,7 @@ $usershtml, null, $options); } -$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next')); +$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, count($questions), qa_opt('pages_prev_next')); // Sub menu for navigation in user pages From 3c9b912f02358237f6fbf9d3b611250aabacfe17 Mon Sep 17 00:00:00 2001 From: SHAIK MASTHAN <84255313+csemasthan@users.noreply.github.com> Date: Wed, 17 Dec 2025 21:56:07 +0530 Subject: [PATCH 4/4] "dependency_level" of a plugin In the metadata.json, a new variable "dependency_level": 2, may be added. Which indicates the loading order in the plugins. Dependency level of the plugin useful while loading it. Lower the dependency number, loads earlier. --- qa-include/Q2A/Plugin/PluginManager.php | 77 ++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/qa-include/Q2A/Plugin/PluginManager.php b/qa-include/Q2A/Plugin/PluginManager.php index 3230682cc..64679ae85 100644 --- a/qa-include/Q2A/Plugin/PluginManager.php +++ b/qa-include/Q2A/Plugin/PluginManager.php @@ -26,8 +26,8 @@ class Q2A_Plugin_PluginManager const PLUGIN_DELIMITER = ';'; const OPT_ENABLED_PLUGINS = 'enabled_plugins'; - private $loadBeforeDbInit = array(); - private $loadAfterDbInit = array(); + private $loadBeforeDbInit = array(); //New structure: [dependency_level => [pluginKey => pluginInfo]] + private $loadAfterDbInit = array(); //New structure: [dependency_level => [pluginKey => pluginInfo]] public function readAllPluginMetadatas() { @@ -49,13 +49,20 @@ public function readAllPluginMetadatas() } // skip plugin which requires a later version of Q2A - if (qa_qa_version_below($metadata['min_q2a'] ?? '')) { + if (qa_qa_version_below(isset($metadata['min_q2a']) ? $metadata['min_q2a'] : '')) { continue; } // skip plugin which requires a later version of PHP - if (qa_php_version_below($metadata['min_php'] ?? '')) { + if (qa_php_version_below(isset($metadata['min_php']) ? $metadata['min_php'] : '')) { continue; } + + //Dependency level of the plugin useful while loading it. Lower the dependency number, loads earlier. + $dependencyLevel = 1; + if (isset($metadata['dependency_level']) && ctype_digit((string)$metadata['dependency_level'])) { + $dependencyLevel = (int)$metadata['dependency_level']; + } + $pluginInfoKey = basename($pluginDirectory); $pluginInfo = array( @@ -67,19 +74,22 @@ public function readAllPluginMetadatas() if (isset($metadata['load_order'])) { switch ($metadata['load_order']) { case 'after_db_init': - $this->loadAfterDbInit[$pluginInfoKey] = $pluginInfo; + //$this->loadAfterDbInit[$pluginInfoKey] = $pluginInfo; + $this->loadAfterDbInit[$dependencyLevel][$pluginInfoKey] = $pluginInfo; break; case 'before_db_init': - $this->loadBeforeDbInit[$pluginInfoKey] = $pluginInfo; + //$this->loadBeforeDbInit[$pluginInfoKey] = $pluginInfo; + $this->loadBeforeDbInit[$dependencyLevel][$pluginInfoKey] = $pluginInfo; break; default: } } else { - $this->loadBeforeDbInit[$pluginInfoKey] = $pluginInfo; + $this->loadBeforeDbInit[$dependencyLevel][$pluginInfoKey] = $pluginInfo; } } } + //This function is not useful anymore private function loadPlugins($pluginInfos) { global $qa_plugin_directory, $qa_plugin_urltoroot; @@ -94,15 +104,55 @@ private function loadPlugins($pluginInfos) $qa_plugin_directory = null; $qa_plugin_urltoroot = null; } + + //New function to load plugins + private function loadPluginsByDependency(array $groupedPlugins) + { + global $qa_plugin_directory, $qa_plugin_urltoroot; + + if (empty($groupedPlugins)) { + return; + } + + ksort($groupedPlugins, SORT_NUMERIC); + + foreach ($groupedPlugins as $level => $pluginsAtLevel) { + + //SAFETY: level may accidentally contain flat array + if (!is_array($pluginsAtLevel)) { + continue; + } + + foreach ($pluginsAtLevel as $pluginKey => $pluginInfo) { + + //SAFETY: pluginInfo must be an array + if (!is_array($pluginInfo) || !isset($pluginInfo['pluginfile'])) { + continue; + } + + $qa_plugin_directory = $pluginInfo['directory']; + $qa_plugin_urltoroot = $pluginInfo['urltoroot']; + + require_once $pluginInfo['pluginfile']; + } + } + + $qa_plugin_directory = null; + $qa_plugin_urltoroot = null; + } + + public function loadPluginsBeforeDbInit() { - $this->loadPlugins($this->loadBeforeDbInit); + //$this->loadPlugins($this->loadBeforeDbInit); + $this->loadPluginsByDependency($this->loadBeforeDbInit); } public function loadPluginsAfterDbInit() { $enabledPlugins = $this->getEnabledPlugins(false); + /* Old way $enabledForAfterDbInit = array(); foreach ($enabledPlugins as $enabledPluginDirectory) { @@ -112,6 +162,17 @@ public function loadPluginsAfterDbInit() } $this->loadPlugins($enabledForAfterDbInit); + */ + + $enabledGrouped = array(); + foreach ($this->loadAfterDbInit as $level => $pluginsAtLevel) { + foreach ($pluginsAtLevel as $pluginKey => $pluginInfo) { + if (in_array($pluginKey, $enabledPlugins, true)) { + $enabledGrouped[$level][$pluginKey] = $pluginInfo; + } + } + } + $this->loadPluginsByDependency($enabledGrouped); } public function getEnabledPlugins($fullPath = false)