public function parseData(Website $website, $id) { $settingsArray = []; // Title $settingsArray["title"] = trim($website->getRequestString("title_" . $id, "")); // Amount $settingsArray["amount"] = $website->getRequestInt("amount_" . $id, 5); $amount = $settingsArray["amount"]; if (!Validate::range($amount, self::MIN_COMMENTS, self::MAX_COMMENTS)) { $settingsArray["valid"] = false; $website->addError($website->t("comments.count") . " " . Validate::getLastError($website)); } return $settingsArray; }
public function parseData(Website $website, $id) { $data = []; // Title $data["title"] = trim($website->getRequestString("title_" . $id, "")); if (strLen($data["title"]) > 200) { $website->addError($website->t("widgets.title") . " " . $website->t("errors.is_too_long_num", 200)); $data["valid"] = false; } // Categories $categories = isset($_REQUEST["categories_" . $id]) ? $_REQUEST["categories_" . $id] : []; if (!is_array($categories)) { // Check for valid array $website->addError($website->tReplacedKey("errors.none_set", "main.categories", true)); $data["valid"] = false; $categories = []; } // Add all categories to the real array $data["categories"] = []; foreach ($categories as $category_id) { $category_id = (int) $category_id; if ($category_id > 0) { $data["categories"][] = $category_id; } } // Check the real array if (count($data["categories"]) == 0) { $website->addError($website->tReplacedKey("errors.none_set", "main.categories", true)); $data["valid"] = false; } // Count if (isset($_REQUEST["count_" . $id])) { $data["count"] = (int) $_REQUEST["count_" . $id]; if (!Validate::range($data["count"], 1, 20)) { $website->addError($website->t("articles.count") . " " . Validate::getLastError($website)); $data["valid"] = false; } } else { $website->addError($website->t("articles.count") . " " . $website->t("errors.not_found")); $data["valid"] = false; } // Display type if (isset($_REQUEST["display_type_" . $id])) { $data["display_type"] = (int) $_REQUEST["display_type_" . $id]; if ($data["display_type"] != self::TYPE_LIST && $data["display_type"] != self::TYPE_WITHOUT_METADATA && $data["display_type"] != self::TYPE_WITH_METADATA && $data["display_type"] != self::TYPE_LIST_WITH_IMAGES) { $website->addError($website->t("articles.count") . " " . $website->t("errors.not_found")); $data["valid"] = false; } } else { $website->addError($website->t("articles.count") . " " . $website->t("errors.not_found")); $data["valid"] = false; } // Order if (isset($_REQUEST["order_" . $id])) { $data["order"] = (int) $_REQUEST["order_" . $id]; if ($data["order"] != self::SORT_NEWEST_TOP && $data["order"] != self::SORT_OLDEST_TOP) { $website->addError($website->t("articles.order") . " " . $website->t("errors.not_found")); $data["valid"] = false; } } else { $website->addError($website->t("articles.order") . " " . $website->t("errors.not_found")); $data["valid"] = false; } // Archive if (isset($_REQUEST["archive_" . $id])) { $data["archive"] = true; } else { $data["archive"] = false; } return $data; }