/** * prepare content method, search for string {loadcontest_##} , where ## is the contest id. * if found render the contest. * * Method is called by the view * * @param string The context of the content being passed to the plugin. * @param object The content object. Note $article->text is also available * @param object The content params * @param integer The 'page' number * @since 1.6 */ public function onContentPrepare($context, &$article, &$params, $limitstart) { //error_log("In plgContentAkcontests::onContentPrepare"); // Don't run this plugin when the content is being indexed if ($context == 'com_finder.indexer') { return true; } $app = JFactory::getApplication(); // Simple performance check to determine whether bot should process further if (strpos($article->text, 'loadcontest') === false) { return true; } // Expression to search for (positions) $regex = '/{loadcontest\\s(.*?)}/i'; // Find all instances of plugin and put in $matchesmod for loadmodule preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER); // If no matches, skip this if ($matches) { foreach ($matches as $matchedcontest) { $contest_id = $matchedcontest[1]; $contest_model = AkrecipesFrontendHelper::getModel('Contest'); $contest_item = $contest_model->getData($contest_id); $output = $this->renderContest($contest_item); // We should replace only first occurrence in order to allow positions with the same name to regenerate their content: $article->text = preg_replace("|{$matchedcontest['0']}|", addcslashes($output, '\\$'), $article->text, 1); } } }
/** * Parse method for URLs * This method is meant to transform the human readable URL back into * query parameters. It is only executed when SEF mode is switched on. * * @param array &$segments The segments of the URL to parse. * * @return array The URL attributes to be used by the application. * * @since 3.3 */ public function parse(&$segments) { $vars = array(); // View is always the first element of the array $vars['view'] = array_shift($segments); $model = AkrecipesFrontendHelper::getModel($vars['view']); while (!empty($segments)) { $segment = array_pop($segments); // If it's the ID, let's put on the request if (is_numeric($segment)) { $vars['id'] = $segment; } else { $vars['task'] = $vars['view'] . '.' . $segment; } } return $vars; }
protected function getFullDescription($item) { $recipe_model = AkrecipesFrontendHelper::getModel('recipe'); $recipe_item = $recipe_model->getData($item->id); $feed_description = ''; $feed_description = $feed_description . '<div class="recipe-description">' . $recipe_item->recipe_description . $recipe_item->pre_ingredient_notes . '</div>'; $feed_description = $feed_description . '<div class="recipe_ingredients><h3>Ingredients for ' . $recipe_item->recipe_name . '</h3>'; $ingredients_list = ''; if (isset($recipe_item->ingredient) && is_array($recipe_item->ingredient)) { $ingredients_list = '<ul>'; foreach ($recipe_item->ingredient as $key => $ingredient_item) { $ingredient_description = trim($recipe_item->ingredient_description[$key]); if (strpos($ingredient_description, '*') === 0 || strpos($ingredient_description, '<p>*') === 0) { $ingredients_list = $ingredients_list . '<li><b>' . str_replace('*', '', $ingredient_description) . '</b></li>'; } else { $qty = trim($recipe_item->qty[$key]); $unit = trim($recipe_item->unit[$key]); $ingredient = trim($recipe_item->ingredient[$key]); $ingredient_tooltip = trim($recipe_item->ingredient_tooltip[$key]); $ingredient_description = trim($recipe_item->ingredient_description[$key]); $ingredient_url = trim($recipe_item->ingredient_url[$key]); $ingredient_qty_unit = (!empty($qty) ? $qty . ' ' : '') . (!empty($unit) ? $unit . ' ' : ''); $ingredients_list = $ingredients_list . '<li>'; $ingredients_list = $ingredients_list . $ingredient_qty_unit . ' ' . $ingredient; if (!empty($ingredient_description)) { $qty_unit_ing = $qty . $unit . $ingredient; $ingredients_list = $ingredients_list . (!empty($qty_unit_ing) ? ', ' : ' ') . $ingredient_description; } $ingredients_list = $ingredients_list . '</li>'; } } $ingredients_list = $ingredients_list . '</ul>'; } else { $ingredients_list = '<ul>'; $ingredients = explode("\n", $recipe_item->ingredients_list); foreach ($ingredients as $key => $ingredient) { if (strpos($ingredient, '*') === 0 || strpos($ingredient, "<p>*") === 0) { $ingredient = str_replace('*', "", $ingredient); $ingredients_list = $ingredients_list . '<b class="ingredientssubtitle">' . trim(strip_tags($ingredient)) . '</b>'; } else { if (trim($ingredient) != '<p> </p>') { $ingredients_list = $ingredients_list . trim(strip_tags($ingredient, '<a>')) . '</li>'; } } } $ingredients_list = $ingredients_list . '</ul>'; } $feed_description = $feed_description . $ingredients_list . '</div>'; $feed_description = $feed_description . '<div class="recipe_instructions">'; $feed_description = $feed_description . '<h3 class="recipeinstructionstitle">Directions for ' . $recipe_item->recipe_name . '</h3>'; $recipe_instruction_list = explode("\n", $recipe_item->recipe_instructions); $ulopened = false; $ulclosed = false; foreach ($recipe_instruction_list as $instructions) { if (strpos($instructions, '*') === 0 || strpos($instructions, "<p>*") === 0) { $instructions = str_replace('*', "", $instructions); if ($ulopened) { $feed_description = $feed_description . '</ol>'; $ulopened = false; $ulclosed = true; } $feed_description = $feed_description . '<b class="recipeinstructionssubtitle">' . trim(strip_tags($instructions)) . '</b>'; } else { if (!$ulopened) { $feed_description = $feed_description . '<ol>'; $ulopened = true; $ulclosed = false; } if (trim($instructions) != '<p> </p>') { $feed_description = $feed_description . '<li itemprop="recipeInstructions">' . trim($instructions) . '</li>'; } } } if (!$ulclosed) { $feed_description = $feed_description . '</ol>'; } $feed_description = $feed_description . '</div>'; $feed_description = $feed_description . '<div class="footnote">' . $recipe_item->recipe_footnote . '</div>'; return $feed_description; }