/** * Get a HeaderInformation from a book object : used on book pages * @param \Sb\Service\Sb\Db\Model\Book $book a book object * @return \Sb\Model\HeaderInformation HeaderInformation object for book pages */ public function get(Book $book) { try { $result = new HeaderInformation(); // Set url canonical $result->setUrlCanonical(HTTPHelper::Link($book->getLink())); // Set title tag $publisherName = ""; if ($book->getPublisher()) { $publisherName = $book->getPublisher()->getName(); } // // Get if book is an ebook $bookIsEbook = !$book->getISBN10() && substr($book->getASIN(), 0, 1) == "B"; // For tag title, maximum length recommended is 60 $titlePrefix = ""; if ($bookIsEbook) { $titlePrefix = "ebook "; } // $title = StringHelper::tronque(sprintf(__("%s de %s par %s", "s1b"), $book->getTitle(), $book->getOrderableContributors(), $publisherName), 60 - strlen("...") - strlen($titlePrefix)); $title = $titlePrefix . $title; $result->setTitle($title); // Set description // For meta description, maximum length recommended is 160 $descriptionSuffix = ""; if ($bookIsEbook) { $descriptionSuffix = " | numérique"; } // $description = StringHelper::tronque($book->getDescription(), 160 - strlen("...") - strlen($descriptionSuffix)); $description .= $descriptionSuffix; // Remove double quotes $result->setDescription(str_replace("\"", "", $description)); // Set keywords // Get 2 first tags for keywords $bookTags = TagSvc::getInstance()->getTagsForBooks(array($book)); $tags = ""; if ($bookTags && count($bookTags) > 0) { $firstTags = array_slice($bookTags, 0, 5); $firstTagNames = array_map(array(&$this, "getTagName"), $firstTags); $tags = implode(" | ", $firstTagNames); } $keywords = sprintf(__("%s | %s | %s", "s1b"), $book->getTitle(), $book->getOrderableContributors(), $publisherName); if ($tags != "") { $keywords = sprintf(__("%s | %s | %s | %s", "s1b"), $book->getTitle(), $book->getOrderableContributors(), $publisherName, $tags); } // // Remove double quotes $keywords = str_replace("\"", "", $keywords); $result->setKeywords($keywords); // Set page image $result->setPageImage($book->getImageUrl()); return $result; } catch (\Exception $exc) { $this->logException(get_class(), __FUNCTION__, $exc); } }
public function sendByEmailAction() { $uid = $this->_getParam('uid'); $emails = $this->_getParam('emails'); $origin = $this->getRequest()->getHeader('referer'); $origin .= "&emails=" . $emails; // Checking if parameters are passed if ($uid && $emails) { // Checking if uid is a valid user $user = UserDao::getInstance()->get($uid); if ($user) { // Getting user wished books $wishedUserbooks = $user->getNotDeletedUserBooks(); $wishedUserbooks = array_filter($wishedUserbooks, array(&$this, "isWished")); // Cheking if some valid emails are passed $emailsArray = array($emails); if (strpos(",", $emails) !== 0) { $emailsArray = explode(",", $emails); } foreach ($emailsArray as $email) { if (!StringHelper::isValidEmail($email)) { Flash::addItem(__("Un des emails renseigné n'est pas valide.", "s1b")); $this->_redirect($origin); exit; } } // Building the mail content $emailContent = \Sb\Helpers\MailHelper::wishedUserBooksEmailBody($user, $wishedUserbooks); // Sending mail MailSvc::getInstance()->send($emails, sprintf(__("%s - Liste des livres souhaités par %s", "s1b"), Constants::SITENAME, $user->getFriendlyName()), $emailContent); Flash::addItem(__("La liste a bien été envoyée par email.", "s1b")); $this->_redirect($origin); exit; } } Flash::addItem(__("Une erreur s'est produite lors de l'envoi de la liste par email", "s1b")); $this->_redirect($origin); exit; }
public function get() { $tplBook = new \Sb\Templates\Template("pushedBooks/pushedBook"); // préparation des champs pour le template // Prepare variables $avgRating = $this->book->getAverageRating(); $roundedRating = floor($avgRating); $ratingCss = "rating-" . $roundedRating; $viewBookLink = \Sb\Helpers\HTTPHelper::Link($this->book->getLink()); $img = \Sb\Helpers\BookHelper::getMediumImageTag($this->book, $this->defImg); $bookTitle = $this->book->getTitle(); $bookDescription = \Sb\Helpers\StringHelper::tronque($this->book->getDescription(), 250); $bookPublication = $this->book->getPublicationInfo(); $bookAuthors = ""; if ($this->book->getContributors()) { $bookAuthors = sprintf("Auteur(s) : %s", $this->book->getOrderableContributors()); } $nbRatings = $this->book->getNbRatedUserBooks(); $nbBlowOfHearts = $this->book->getNbOfBlowOfHearts(); // Set variables $tplBook->setVariables(array("averageRating" => round($avgRating, 2), "ratingCss" => $ratingCss, "isBlowOfHeart" => $this->boh, "nbBlowOfHearts" => $nbBlowOfHearts, "roundedRating" => $roundedRating, "bookTitle" => $bookTitle, "bookDescription" => $bookDescription, "bookPublication" => $bookPublication, "bookAuthors" => $bookAuthors, "viewBookLink" => $viewBookLink, "image" => $img, "nbRatings" => $nbRatings)); return $tplBook->output(); }
public function testIsValidEmailKO() { $emailToTest = "*****@*****.**"; $validEmail = \Sb\Helpers\StringHelper::isValidEmail($emailToTest); $this->assertEquals($validEmail, false, "\\Sb\\Helpers\\StringHelper::isValidEmail failed testing a unvalid email."); }
/** * Send invitation to users */ public function inviteAction() { try { $globalContext = new \Sb\Context\Model\Context(); $user = $globalContext->getConnectedUser(); $continue = true; $emails = ArrayHelper::getSafeFromArray($_POST, 'Emails', null); $message = ArrayHelper::getSafeFromArray($_POST, 'Message', null); if (!$emails || !$message) { Flash::addItem(__("Vous devez renseigner tous les champs obligatoires.", "s1b")); $continue = false; } if ($continue) { $emailsListFromPost = explode(",", $emails); // Getting emails list if ($emailsListFromPost) { // Looping through all emails for validating all of them // At the end of the loop: // we will have an array of emails to be processed // and flag to process or not the sendings $emailsList = array(); foreach ($emailsListFromPost as $emailToInvite) { $addEmail = true; $emailToInvite = strtolower(trim($emailToInvite)); if ($emailToInvite != "") { // Testing if the email is valid if (!StringHelper::isValidEmail($emailToInvite)) { Flash::addItem(sprintf(__("%s n'est pas un email valide.", "s1b"), $emailToInvite)); // We will stop invitation sending $continue = false; // Current email not added to the array of emails to be processed $addEmail = false; } else { // Testing if the email does not match an existing user $userInDb = UserDao::getInstance()->getByEmail($emailToInvite); if ($userInDb && !$userInDb->getDeleted()) { $friendRequestUrl = HTTPHelper::Link(Urls::USER_FRIENDS_REQUEST, array("fid" => $userInDb->getId())); Flash::addItem(sprintf(__("Un utilisateur existe déjà avec l'email : %s. <a class=\"link\" href=\"%s\">Envoyer lui une demande d'ami</a>", "s1b"), $emailToInvite, $friendRequestUrl)); // We will stop invitation sending $continue = false; // Current email not added to the array of emails to be processed $addEmail = false; } else { // Testing if invitations have been sent to that guest (email) by the current user $invitations = InvitationDao::getInstance()->getListForSenderAndGuestEmail($user, $emailToInvite); if ($invitations && count($invitations) > 0) { Flash::addItem(sprintf(__("Vous avez déjà envoyé une invitation à cet email : %s.", "s1b"), $emailToInvite)); // We will stop invitation sending $continue = false; // Current email not added to the array of emails to be processed $addEmail = false; } } } } if ($addEmail) { $emailsList[] = $emailToInvite; } } if ($continue) { // Looping through all emails for sending invitation $initialMessage = $message; foreach ($emailsList as $emailToInvite) { $emailToInvite = strtolower(trim($emailToInvite)); if ($emailToInvite != "") { $sendInvitation = true; // Testing again if invitations have been sent to that guest (email) by the current user $invitations = InvitationDao::getInstance()->getListForSenderAndGuestEmail($user, $emailToInvite); if ($invitations && count($invitations) > 0) { $sendInvitation = false; } if ($sendInvitation) { // Getting existing guests matching email, and take first 1 $guest = null; $guests = GuestDao::getInstance()->getListByEmail($emailToInvite); if ($guests && count($guests) > 0) { $guest = $guests[0]; } $token = sha1(uniqid(rand())); // Send invite email $message = str_replace("\n", "<br/>", $initialMessage); $message .= "<br/><br/>"; $message .= sprintf(__("<a href=\"%s\">S'inscrire</a> ou <a href=\"%s\">Refuser</a>", "s1b"), HTTPHelper::Link(Urls::SUBSCRIBE), HTTPHelper::Link(Urls::REFUSE_INVITATION, array("Token" => $token, "Email" => $emailToInvite))); $message .= "<br/><br/>"; $message .= "<strong>" . sprintf(__("L'équipe %s", "s1b"), Constants::SITENAME) . "<strong/>"; MailSvc::getNewInstance($user->getEmail(), $user->getEmail())->send($emailToInvite, sprintf(__("Invitation à rejoindre %s", "s1b"), Constants::SITENAME), $message); // Create invitation $invitation = new Invitation(); $invitation->setSender($user); $invitation->setToken($token); $invitation->setLast_modification_date(new \DateTime()); if ($guest) { // Updating guest $guest->addInvitations($invitation); GuestDao::getInstance()->update($guest); } else { // Create guest $guest = new Guest(); $guest->setEmail($emailToInvite); $guest->setCreation_date(new \DateTime()); $guest->addInvitations($invitation); GuestDao::getInstance()->add($guest); } Flash::addItem(sprintf(__("Une invitation a été envoyée à %s.", "s1b"), $emailToInvite)); } } } HTTPHelper::redirectToHome(); } } } // If we arrive here : an error occured, then redirect to the invite form HTTPHelper::redirect(Urls::USER_FRIENDS_INVITE, array("emails" => $emails)); } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString())); $this->forward("error", "error", "default"); } }
/** * Get detail page link for chronicle * @return string the detail page link */ public function getDetailLink() { if ($this->getTitle()) { return HTTPHelper::Link("chronique/" . StringHelper::sanitize(StringHelper::cleanHTML($this->getTitle())) . "-" . $this->getId()); } else { return HTTPHelper::Link("chronique/chronique-" . $this->getId()); } }
/** * Set ChronicleViewModelLight object member with the chronicle * @param ChronicleViewModelLight $lightChronicle */ private function setChronicleViewModelLight(ChronicleViewModelLight $lightChronicle) { // Set title, description and link $lightChronicle->setChronicleId($this->chronicle->getId()); $lightChronicle->setTitle(StringHelper::cleanHTML($this->chronicle->getTitle())); $lightChronicle->setLink($this->chronicle->getLink()); $lightChronicle->setCreationDate($this->chronicle->getCreation_date()); $lightChronicle->setShortenText(StringHelper::cleanHTML(StringHelper::tronque($this->chronicle->getText(), 100))); $lightChronicle->setNbViews($this->chronicle->getNb_views()); // Set internal detail page link $lightChronicle->setDetailLink($this->chronicle->getDetailLink()); // Set Image if ($this->chronicle->getBook() && $this->chronicle->getBook()->getId() > 0) { $lightChronicle->setImage($this->chronicle->getBook()->getLargeImageUrl()); } else { if ($this->chronicle->getImage()) { $lightChronicle->setImage($this->chronicle->getImage()); } else { if ($this->chronicle->getTag()) { $lightChronicle->setImage(sprintf("/images/tag/tag_id%s.jpg", $this->chronicle->getTag()->getId())); } else { $lightChronicle->setImage("/Resources/images/chronicle-default-img.png"); } } } }
public function get() { $globalContext = new \Sb\Context\Model\Context(); $tplEvent = new \Sb\Templates\Template("userEvents/userEvent"); $friend = $this->userEvent->getUser(); $friendImg = UserHelper::getSmallImageTag($friend); if ($friendImg == "") { $friendImg = UserHelper::getSmallImageTag($friend); } $friendName = $friend->getUserName(); $friendProfileLink = HTTPHelper::Link(Urls::USER_PROFILE, array("uid" => $friend->getId())); $userBookRelated = false; $friendRelated = false; // used for cases of new friend event $additionalContent = ""; $friendId = null; $friendFriendImg = null; $friendFriendProfileLink = null; switch ($this->userEvent->getType_id()) { case EventTypes::USERBOOK_ADD: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a ajouté un livre.", $friendProfileLink, $friendName); $userBookRelated = true; break; case EventTypes::USERBOOK_RATING_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $newRating = $this->userEvent->getNew_value(); $resume = sprintf("<div class=\"ue-rating-label\"><a href=\"%s\" class=\"link\">%s</a> a noté.</div> <div class=\"rating rating-" . $newRating . "\"></div>", $friendProfileLink, $friendName); $userBookRelated = true; break; case EventTypes::USERBOOK_BLOWOFHEART_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $isBoh = $this->userEvent->getNew_value(); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a supprimé son coup de coeur.", $friendProfileLink, $friendName); if ($isBoh) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a marqué comme coup de coeur.", $friendProfileLink, $friendName); } $userBookRelated = true; break; case EventTypes::USERBOOK_REVIEW_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $oldReview = $this->userEvent->getOld_value(); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a modifié son commentaire.", $friendProfileLink, $friendName); if ($oldReview == "") { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a ajouté un commentaire.", $friendProfileLink, $friendName); } $additionalContent = StringHelper::tronque(strip_tags($this->userEvent->getNew_value()), 120); $userBookRelated = true; break; case EventTypes::USERBOOK_HYPERLINK_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $oldHyperLink = $this->userEvent->getOld_value(); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a modifié son lien hypertexte.", $friendProfileLink, $friendName); if ($oldHyperLink == "") { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a ajouté un lien hypertexte.", $friendProfileLink, $friendName); } $hyperLink = "http://" . $this->userEvent->getNew_value(); $truncatedHyperLink = \Sb\Helpers\StringHelper::tronque($hyperLink, 100); $additionalContent = sprintf(__("<a href=\"%s\" target=\"_blank\" class=\"hyperlink link\" >%s</a>", "s1b"), $hyperLink, $truncatedHyperLink); $userBookRelated = true; break; case EventTypes::USERBOOK_READINGSTATE_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $newReadingSateId = $this->userEvent->getNew_value(); switch ($newReadingSateId) { case ReadingStates::NOTREAD: $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a marqué non lu.", $friendProfileLink, $friendName); break; case ReadingStates::READING: $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> lit actuellement.", $friendProfileLink, $friendName); break; case ReadingStates::READ: $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a lu.", $friendProfileLink, $friendName); break; } $userBookRelated = true; break; case EventTypes::USERBOOK_WISHEDSTATE_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $newWishedSateValue = $this->userEvent->getNew_value(); $oldWishedSateValue = $this->userEvent->getOld_value(); if ($newWishedSateValue) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a marqué comme souhaité.", $friendProfileLink, $friendName); } elseif ($oldWishedSateValue) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> ne souhaite plus.", $friendProfileLink, $friendName); } $userBookRelated = true; break; case EventTypes::USER_ADD_FRIEND: $friendNewFriendProfileLink = null; $newFriendId = $this->userEvent->getNew_value(); if ($this->getContext()->getConnectedUser() && $newFriendId == $this->getContext()->getConnectedUser()->getId()) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> est ami avec moi.", $friendProfileLink, $friendName); $friendFriendImg = UserHelper::getXSmallImageTag($this->getContext()->getConnectedUser()); } else { $friendNewFriend = UserDao::getInstance()->get($newFriendId); $friendNewFriendProfileLink = HTTPHelper::Link(Urls::USER_PROFILE, array("uid" => $friendNewFriend->getId())); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> est ami avec <a class=\"link\" href=\"%s\">%s</a>.", $friendProfileLink, $friendName, $friendNewFriendProfileLink, $friendNewFriend->getUserName()); $friendFriendImg = UserHelper::getXSmallImageTag($friendNewFriend); } $friendId = $newFriendId; $friendFriendProfileLink = $friendNewFriendProfileLink; $friendRelated = true; break; case EventTypes::USER_BORROW_USERBOOK: $lendingId = $this->userEvent->getNew_value(); $lending = LendingDao::getInstance()->get($lendingId); $userBookBorrowed = $lending->getUserBook(); $userBook = $userBookBorrowed; $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a emprunté le livre à %s.", $friendProfileLink, $friendName, $userBookBorrowed->getUser()->getUserName()); if ($this->getContext()->getConnectedUser()) { if ($userBookBorrowed->getUser()->getId() == $this->getContext()->getConnectedUser()->getId()) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> m'a emprunté le livre.", $friendProfileLink, $friendName); } } $userBookRelated = true; break; case EventTypes::USER_LEND_USERBOOK: $lendingId = $this->userEvent->getNew_value(); $lending = LendingDao::getInstance()->get($lendingId); $userBookLended = $lending->getBorrower_UserBook(); $userBook = $userBookLended; $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a prêté le livre à %s.", $friendProfileLink, $friendName, $userBookLended->getUser()->getUserName()); if ($this->getContext()->getConnectedUser()) { if ($userBookLended->getUser()->getId() == $this->getContext()->getConnectedUser()->getId()) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> m'a prêté le livre.", $friendProfileLink, $friendName); } } $userBookRelated = true; break; default: break; } $creationDate = $this->userEvent->getCreation_date()->format(__("d/m/Y à H:m", "s1b")); $bookImageUrl = null; $bookLink = null; $bookTitle = null; $bookAuthor = null; $bookId = null; $bookImgTag = null; if ($userBookRelated) { $bookImageUrl = $userBook->getBook()->getSmallImageUrl(); $bookImgTag = BookHelper::getSmallImageTag($userBook->getBook(), $this->getContext()->getDefaultImage()); $bookLink = HTTPHelper::Link($userBook->getBook()->getLink()); $bookTitle = $userBook->getBook()->getTitle(); $bookAuthor = $userBook->getBook()->getOrderableContributors(); $bookId = $userBook->getBook()->getId(); } $showAddButton = false; if ($globalContext->getConnectedUser()) { $showAddButton = true; } // Set variables $tplEvent->setVariables(array("friendImg" => $friendImg, "friendName" => $friendName, "resume" => $resume, "bookImageUrl" => $bookImageUrl, "bookImgTag" => $bookImgTag, "friendProfileLink" => $friendProfileLink, "friendId" => $friendId, "bookTitle" => $bookTitle, "bookId" => $bookId, "bookAuthor" => $bookAuthor, "creationDate" => $creationDate, "bookLink" => $bookLink, "additionalContent" => $additionalContent, "userBookRelated" => $userBookRelated, "userFriendRelated" => $friendRelated, "friendFriendImg" => $friendFriendImg, "friendFriendProfileLink" => $friendFriendProfileLink, "showOwner" => $this->showOwner, "showAddButton" => $showAddButton)); return $tplEvent->output(); }
/** * @return mixed|string */ public function get() { $lineIdx = 0; foreach (array_values($this->shownResults) as $book) { $lineIdx++; $addSep = true; if ($lineIdx == 1) { $addSep = false; } $bk = $book; $language = urlencode($bk->getLanguage()); if ($bk->getImageUrl()) { $imgSrc = $bk->getImageUrl(); } else { $imgSrc = $this->defImg; } // Utilisation de urlencode à la place htmlspecialchars car ce dernier pose des pbs qd la valeur est ensuite passée en post $title = $bk->getTitle(); $titleEsc = urlencode($bk->getTitle()); // encodé $author = $bk->getOrderableContributors(); $authorEsc = urlencode($bk->getOrderableContributors()); // encodé $id = $bk->getId(); $isbn10 = $bk->getISBN10(); $isbn13 = $bk->getISBN13(); $asin = $bk->getASIN(); $desc = StringHelper::tronque($bk->getDescription(), 350); $descEsc = urlencode($bk->getDescription()); // encodé $smallImg = $bk->getSmallImageUrl(); $img = $bk->getImageUrl(); $largeImg = $bk->getLargeImageUrl(); $pubEsc = ""; $pubInfo = ""; if ($bk->getPublisher()) { $pubEsc = urlencode($bk->getPublisher()->getName()); // encodé $pubInfo = $bk->getPublicationInfo(); } $pubDtStr = ""; if ($book->getPublishingDate()) { $pubDtStr = $book->getPublishingDate()->format("Y-m-d H:i:s"); } $amazonUrl = $book->getAmazonUrl(); $nbOfPages = $book->getNb_of_pages(); $cssClass = $lineIdx % 2 ? "lineA" : "lineB"; $viewBookLink = null; $bookInDB = false; if ($bk->getId()) { $viewBookLink = HTTPHelper::Link($bk->getLink()); $bookInDB = true; } $resultTpl = new Template('searchBook/resultRow'); $resultTpl->setVariables(array('addSep' => $addSep, 'viewBookLink' => $viewBookLink, 'bookInDB' => $bookInDB, 'cssClass' => $cssClass . ' ' . ($bookInDB ? 'indb' : ''), 'title' => $title, 'publisher' => $pubInfo, 'author' => $author, 'id' => $id, 'isbn10' => $isbn10, 'isbn13' => $isbn13, 'asin' => $asin, 'titleEsc' => $titleEsc, 'descEsc' => $descEsc, 'desc' => $desc, 'smallImg' => $smallImg, 'img' => $img, 'largeImg' => $largeImg, 'imgSrc' => $imgSrc, 'authorEsc' => $authorEsc, 'pubEsc' => $pubEsc, 'pubDtStr' => $pubDtStr, 'amazonUrl' => $amazonUrl, 'language' => $language, 'nbOfPages' => $nbOfPages)); $resultTplArr[] = $resultTpl; } $results = Template::merge($resultTplArr); $resultsTpl = new Template('searchBook/results'); $resultsTpl->set("resultRows", $results); $links = $this->pagerLinks; $resultsTpl->set("links", $links['all']); $resultsTpl->set("first", $this->firstItemIdx); $resultsTpl->set("last", $this->lastItemIdx); $resultsTpl->set("nbItemsTot", $this->nbItemsTot); return $resultsTpl->output(); }
/** * Get a collection of chronicles with same keywords * @param Array of String $keywords the keywords to search chronicle having one of them * @param int $numberOfChronicles number of maximum chronicle to get * @return Collection of chronicle */ public function getChroniclesWithKeywords($keywords, $numberOfChronicles, $useCache = true) { try { $results = null; if ($useCache) { // Get cache key : sanitize keywords string and replace "-" by "_" $key = self::CHRONICLES_WITH_KEYWORDS . "_k_" . str_replace("-", "_", StringHelper::sanitize(implode("_", $keywords))) . "_m_" . $numberOfChronicles; $results = $this->getData($key); } if (!isset($results) || $results === false) { /* @var $dao ChronicleDao */ $dao = $this->getDao(); $criteria = array(); // Add is_validated criteria $criteria["is_validated"] = array(false, "=", 1); // Add keywords criteria $criteria["keywords"] = array(false, "LIKE", $keywords); $orderBy = array("creation_date" => "DESC"); $results = $dao->getList($criteria, $orderBy, $numberOfChronicles); if ($useCache) { $this->setData($key, $results); } } return $results; } catch (\Exception $e) { $this->logException(get_class(), __FUNCTION__, $e); } }
private function validateUserInputForm() { $ret = true; if ($_POST) { if (strlen(ArrayHelper::getSafeFromArray($_POST, "guest_name", NULL)) < 3) { Flash::addItem(__("Le nom doit comprendre au moins 3 caractères.", "s1b")); $ret = false; } if (ArrayHelper::getSafeFromArray($_POST, "send_invitation", NULL) == 1) { $guestEmail = ArrayHelper::getSafeFromArray($_POST, "guest_email", NULL); if (!$guestEmail) { Flash::addItem(__("Vous devez renseigné un email si vous souhaitez envoyer une invitation.", "s1b")); $ret = false; } else { if (!StringHelper::isValidEmail($guestEmail)) { Flash::addItem(__("L'email que vous avez renseigné n'est pas valide. Merci de réessayer.", "s1b")); $ret = false; } } } } else { $ret = false; } return $ret; }
public function getFriendlyName() { return ucfirst(\Sb\Helpers\StringHelper::tronque(strtolower($this->getFirstName()), 20)) . " " . strtoupper(mb_substr($this->getLastName(), 0, 1)) . "."; }
public function getLink() { $encodedTitle = StringHelper::sanitize($this->getTitle()); return sprintf("livre/%s-%s", $encodedTitle, $this->getId()); }