/** * Returns a flag indicating if the user still has free views left. * * @return True if the user still has free views left, false otherwise */ public static function hasFreeViews() { $clazz = get_class(); $meteredUserData = static::getMeteredUserData(); if (is_null($meteredUserData)) { $limitParam = filter_input(INPUT_GET, "meteredLimitReached"); if ($limitParam !== FALSE && !is_null($limitParam) && $limitParam === 'true') { PlenigoManager::notice($clazz, "Limit reached by URL parameter. You shall NOT pass!"); return false; } PlenigoManager::warn($clazz, "Returning TRUE but I have no metered Data!!!!!"); return true; } $active = $meteredUserData->isMeteredViewActivated(); if (is_null($active) || $active === false) { PlenigoManager::notice($clazz, "Metered view deactivated!!"); return false; } $loggedIn = UserService::isLoggedIn(); if (is_null($loggedIn)) { $loggedIn = false; } $limitReached = $meteredUserData->isLimitReached(); if (is_null($limitReached)) { $limitReached = false; } $viewsAvailable = $meteredUserData->getFreeViewsAllowed(); $viewsUsed = $meteredUserData->getFreeViewsTaken(); $loginLimitReached = $meteredUserData->isLoginLimitReached(); if (is_null($loginLimitReached)) { $loginLimitReached = false; } $loginViewsAvailable = $meteredUserData->getLoginFreeViewsAllowed(); $loginViewsUsed = $meteredUserData->getLoginFreeViewsTaken(); $validCookie = self::checkCookieValidity($meteredUserData); //invalid Metered cookie, the Javascript should take care of it if ($validCookie === false) { PlenigoManager::notice($clazz, "Invalid. You shall pass this time!"); return true; } $limitToCheck = $limitReached; $viewsToCheck = $viewsAvailable; $viewsUsedToCheck = $viewsUsed; //if login views enabled if ($loggedIn === true && $loginViewsAvailable > 0) { $limitToCheck = $loginLimitReached; $viewsToCheck = $loginViewsAvailable; $viewsUsedToCheck = $loginViewsUsed; } if ($limitToCheck === true) { PlenigoManager::notice($clazz, "Limit reached. You shall NOT pass!"); return false; } PlenigoManager::notice($clazz, "Limit not reached. You shall pass! (" . $viewsUsedToCheck . "/" . $viewsToCheck . ")"); return true; }
/** * This method retrieves the category data of a provided category id. * This can only be used for plenigo managed categories. * * @param string $categoryId The category id to use. * @return the category data related to the access token * @throws PlenigoException whenever an error happens */ public static function getCategoryData($categoryId) { $clazz = get_class(); PlenigoManager::notice($clazz, "Getting Category data for CategoryID=" . $categoryId); $params = array(ApiParams::COMPANY_ID => PlenigoManager::get()->getCompanyId(), ApiParams::SECRET => PlenigoManager::get()->getSecret()); $request = static::getRequest(ApiURLs::GET_CATEGORY . "/" . $categoryId, false, $params); $categoryDataRequest = new static($request); try { $response = $categoryDataRequest->execute(); } catch (PlenigoException $exc) { $errorCode = ErrorCode::getTranslation(ApiURLs::GET_CATEGORY, $exc->getCode()); if (empty($errorCode) || is_null($errorCode)) { $errorCode = $exc->getCode(); } // Specific Error Code if ($errorCode === ErrorCode::CATEGORY_NOT_FOUND) { PlenigoManager::warn($clazz, self::ERR_MSG_NOT_FOUND . $categoryId, $exc); throw new PlenigoException(self::ERR_MSG_NOT_FOUND . $categoryId, $errorCode, $exc); } throw self::getException($exc, $errorCode, self::ERR_MSG_CAT_DATA); } try { $categoryData = self::buildCategoryData($response); } catch (\Exception $exc) { $clazz = get_class(); PlenigoManager::error($clazz, self::ERR_MSG_CDATA_BUILD, $exc); throw new PlenigoException(self::ERR_MSG_CDATA_BUILD, $exc->getCode(), $exc); } return $categoryData; }
/** * This method generates the cross-site request forgery (CSRF) token. * * @return string the CSRF Token or NULL if there is a problem generating the CSRF Token */ public static function createCsrfToken() { $clazz = get_class(); PlenigoManager::notice($clazz, "Creating a random CSRF Token!"); $randomtoken = null; try { if (function_exists("openssl_random_pseudo_bytes")) { $randomtoken = md5(base64_encode(openssl_random_pseudo_bytes(32))); } else { $randomtoken = md5(uniqid(rand(), true)); } } catch (Exception $exc) { $clazz = get_class(); PlenigoManager::warn($clazz, self::ERR_MSG_TOKEN_CREATE, $exc); } return $randomtoken; }