/** * This loads the list of products. * * @param boolean $reload * * @return array */ public static function LoadProducts($reload = FALSE) { $dbr = wfGetDB(DB_SLAVE); /** * If we have content in our list, just return that unless $reload is true. */ if (sizeof(self::$sProductList) && !$reload) { return self::$sProductList; } self::$sProductList = array(); // Use 0 as the last parameter to enforce getting latest revision of this article. $article = new Article(Title::newFromText(PONYDOCS_DOCUMENTATION_PRODUCTS_TITLE), 0); $content = $article->getContent(); if (!$article->exists()) { // There is no products file found -- just return. return array(); } /** * The content of this topic should be of this form: * {{#product:shortName|Long Product Name|description|parent}}{{#product:anotherProduct|... */ // explode on the closing tag to get an array of products $tags = explode('}}', $content); foreach ($tags as $tag) { $tag = trim($tag); if (strpos($tag, '{{#product:') === 0) { // Remove the opening tag and prefix $product = str_replace('{{#product:', '', $tag); $parameters = explode('|', $product); $parameters = array_map('trim', $parameters); // Pad out array to avoid notices $parameters = array_pad($parameters, 5, ''); // Set static flag if defined as static $static = FALSE; if (strpos($parameters[0], PONYDOCS_PRODUCT_STATIC_PREFIX) === 0) { $parameters[0] = substr($parameters[0], strlen(PONYDOCS_PRODUCT_STATIC_PREFIX)); $static = TRUE; } // Allow admins to omit optional parameters foreach (array(1, 2, 3) as $index) { if (!array_key_exists($index, $parameters)) { $parameters[$index] = ''; } } // Avoid wedging the product page with a fatal error if shortName is omitted by some crazy nihilist if (isset($parameters[0]) && $parameters[0] != '') { $pProduct = new PonyDocsProduct($parameters[0], $parameters[1], $parameters[2], $parameters[3], $parameters[4]); $pProduct->setStatic($static); self::$sDefinedProductList[$pProduct->getShortName()] = $pProduct; self::$sProductList[$parameters[0]] = $pProduct; // Handle child products if (isset($parameters[3]) && $parameters[3] != '') { self::$sParentChildMap[$parameters[3]][] = $parameters[0]; } // Handle product categories if (isset($parameters[4]) && $parameters[4] != '') { $categories = explode(',', $parameters[4]); foreach ($categories as $category) { self::$sCategoryMap[$category][$parameters[0]] = $pProduct; } } else { self::$sCategoryMap[PONYDOCS_NO_CATEGORY][$parameters[0]] = $pProduct; } } } } return self::$sProductList; }