Changeset 3489910
- Timestamp:
- 03/24/2026 11:17:45 AM (9 days ago)
- Location:
- praison-file-content-git
- Files:
-
- 4 edited
- 1 copied
-
tags/1.1.1 (copied) (copied from praison-file-content-git/trunk)
-
tags/1.1.1/praisonpressgit.php (modified) (1 diff)
-
tags/1.1.1/src/Core/Bootstrap.php (modified) (5 diffs)
-
trunk/praisonpressgit.php (modified) (1 diff)
-
trunk/src/Core/Bootstrap.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
praison-file-content-git/tags/1.1.1/praisonpressgit.php
r3489866 r3489910 3 3 * Plugin Name: PraisonAI Git Posts 4 4 * Description: Load WordPress content from files (Markdown, JSON, YAML) without database writes, with Git-based version control 5 * Version: 1.1. 05 * Version: 1.1.1 6 6 * Author: MervinPraison 7 7 * Author URI: https://mer.vin -
praison-file-content-git/tags/1.1.1/src/Core/Bootstrap.php
r3488026 r3489910 17 17 private $postLoaders = []; 18 18 private $postTypes = []; 19 private $allowedPostTypes = null; 19 20 20 21 /** … … 104 105 105 106 /** 107 * Get the allowed post types from site-config.ini 108 * 109 * @return array|null Array of allowed types, or null if setting doesn't exist (allow all) 110 */ 111 private function getAllowedPostTypes() { 112 if ($this->allowedPostTypes !== null) { 113 return $this->allowedPostTypes; 114 } 115 116 $config_file = PRAISON_PLUGIN_DIR . '/site-config.ini'; 117 if (file_exists($config_file)) { 118 $config = parse_ini_file($config_file, true); 119 if (isset($config['content']['post_types']) && is_array($config['content']['post_types'])) { 120 $this->allowedPostTypes = $config['content']['post_types']; 121 return $this->allowedPostTypes; 122 } 123 } 124 125 $this->allowedPostTypes = false; // Use false internally to denote "checked but not found" 126 return null; // Return null to mean "allow all" 127 } 128 129 /** 106 130 * Dynamically discover post types from content directory 107 131 * Scans folders and auto-registers them as post types … … 120 144 $items = scandir(PRAISON_CONTENT_DIR); 121 145 146 $allowed = $this->getAllowedPostTypes(); 147 122 148 foreach ($items as $item) { 123 149 // Skip hidden files, current/parent directory references … … 130 156 // Only process directories 131 157 if (is_dir($path)) { 158 // If allowed list is defined in config, skip post types not in the list 159 // Note: The directory name for 'post' is 'posts', so check both 160 if ($allowed !== null) { 161 $check_name = ($item === 'posts') ? 'post' : $item; 162 if (!in_array($check_name, $allowed, true)) { 163 continue; 164 } 165 } 166 132 167 $types[] = $item; 133 168 } … … 215 250 if (empty($post_type)) { 216 251 if ($query->is_main_query() && (is_home() || is_archive())) { 217 // Check if posts loader exists before calling 218 if (isset($this->postLoaders['posts'])) { 219 return $this->postLoaders['posts']->loadPosts($query); 252 $allowed = $this->getAllowedPostTypes(); 253 // Check if 'post' is allowed to be file-based 254 if ($allowed === null || in_array('post', $allowed, true)) { 255 // Check if posts loader exists before calling 256 if (isset($this->postLoaders['posts'])) { 257 return $this->postLoaders['posts']->loadPosts($query); 258 } 220 259 } 221 260 } 222 261 return $posts; 262 } 263 264 // Skip injection if this post type is explicitly excluded from site-config.ini 265 $allowed = $this->getAllowedPostTypes(); 266 if ($allowed !== null) { 267 // Handle array of post types or single string 268 $types_to_check = is_array($post_type) ? $post_type : [$post_type]; 269 $has_allowed = false; 270 271 foreach ($types_to_check as $type) { 272 // Translate internal post type back to standard if needed 273 $check_type = ($type === 'praison_post') ? 'post' : $type; 274 if (in_array($check_type, $allowed, true)) { 275 $has_allowed = true; 276 break; 277 } 278 } 279 280 if (!$has_allowed) { 281 return $posts; 282 } 223 283 } 224 284 -
praison-file-content-git/trunk/praisonpressgit.php
r3489866 r3489910 3 3 * Plugin Name: PraisonAI Git Posts 4 4 * Description: Load WordPress content from files (Markdown, JSON, YAML) without database writes, with Git-based version control 5 * Version: 1.1. 05 * Version: 1.1.1 6 6 * Author: MervinPraison 7 7 * Author URI: https://mer.vin -
praison-file-content-git/trunk/src/Core/Bootstrap.php
r3488026 r3489910 17 17 private $postLoaders = []; 18 18 private $postTypes = []; 19 private $allowedPostTypes = null; 19 20 20 21 /** … … 104 105 105 106 /** 107 * Get the allowed post types from site-config.ini 108 * 109 * @return array|null Array of allowed types, or null if setting doesn't exist (allow all) 110 */ 111 private function getAllowedPostTypes() { 112 if ($this->allowedPostTypes !== null) { 113 return $this->allowedPostTypes; 114 } 115 116 $config_file = PRAISON_PLUGIN_DIR . '/site-config.ini'; 117 if (file_exists($config_file)) { 118 $config = parse_ini_file($config_file, true); 119 if (isset($config['content']['post_types']) && is_array($config['content']['post_types'])) { 120 $this->allowedPostTypes = $config['content']['post_types']; 121 return $this->allowedPostTypes; 122 } 123 } 124 125 $this->allowedPostTypes = false; // Use false internally to denote "checked but not found" 126 return null; // Return null to mean "allow all" 127 } 128 129 /** 106 130 * Dynamically discover post types from content directory 107 131 * Scans folders and auto-registers them as post types … … 120 144 $items = scandir(PRAISON_CONTENT_DIR); 121 145 146 $allowed = $this->getAllowedPostTypes(); 147 122 148 foreach ($items as $item) { 123 149 // Skip hidden files, current/parent directory references … … 130 156 // Only process directories 131 157 if (is_dir($path)) { 158 // If allowed list is defined in config, skip post types not in the list 159 // Note: The directory name for 'post' is 'posts', so check both 160 if ($allowed !== null) { 161 $check_name = ($item === 'posts') ? 'post' : $item; 162 if (!in_array($check_name, $allowed, true)) { 163 continue; 164 } 165 } 166 132 167 $types[] = $item; 133 168 } … … 215 250 if (empty($post_type)) { 216 251 if ($query->is_main_query() && (is_home() || is_archive())) { 217 // Check if posts loader exists before calling 218 if (isset($this->postLoaders['posts'])) { 219 return $this->postLoaders['posts']->loadPosts($query); 252 $allowed = $this->getAllowedPostTypes(); 253 // Check if 'post' is allowed to be file-based 254 if ($allowed === null || in_array('post', $allowed, true)) { 255 // Check if posts loader exists before calling 256 if (isset($this->postLoaders['posts'])) { 257 return $this->postLoaders['posts']->loadPosts($query); 258 } 220 259 } 221 260 } 222 261 return $posts; 262 } 263 264 // Skip injection if this post type is explicitly excluded from site-config.ini 265 $allowed = $this->getAllowedPostTypes(); 266 if ($allowed !== null) { 267 // Handle array of post types or single string 268 $types_to_check = is_array($post_type) ? $post_type : [$post_type]; 269 $has_allowed = false; 270 271 foreach ($types_to_check as $type) { 272 // Translate internal post type back to standard if needed 273 $check_type = ($type === 'praison_post') ? 'post' : $type; 274 if (in_array($check_type, $allowed, true)) { 275 $has_allowed = true; 276 break; 277 } 278 } 279 280 if (!$has_allowed) { 281 return $posts; 282 } 223 283 } 224 284
Note: See TracChangeset
for help on using the changeset viewer.