Utiliser le BBCode
MrToine Membre non connecté
Booster Bazooka
- Booster Bazooka
- Voir le profil du membre MrToine
- Inscrit le : 26/10/2014
- Groupes :
Pour ajouter le BBcode à l'affichage d'un texte quelle est la fonction utiliser ?
est-ce celle-ci ?
Code PHP :
<?php FormatingHelper::second_parse($this->contents); ?>
Édité par MrToine Le 12/10/2017 à 12h53
janus57 Membre non connecté
- Booster Fusée
- Voir le profil du membre janus57
- Inscrit le : 07/12/2007
- Groupes :
- Equipe Assistance
qu'est-ce que tu entend par "ajouter le BBcode à l'affichage" ?
Cordialement, janus57
MrToine Membre non connecté
Booster Bazooka
- Booster Bazooka
- Voir le profil du membre MrToine
- Inscrit le : 26/10/2014
- Groupes :
janus57 Membre non connecté
- Booster Fusée
- Voir le profil du membre janus57
- Inscrit le : 07/12/2007
- Groupes :
- Equipe Assistance
effectivement dans ce cas il faut faire appel à la fonction :
Code PHP :
FormatingHelper::second_parse();
Cordialement, janus57
MrToine Membre non connecté
Booster Bazooka
- Booster Bazooka
- Voir le profil du membre MrToine
- Inscrit le : 26/10/2014
- Groupes :
janus57 Membre non connecté
- Booster Fusée
- Voir le profil du membre janus57
- Inscrit le : 07/12/2007
- Groupes :
- Equipe Assistance
en générale elle est appelé avant d'afficher le contenu via la fonction get_array_tpl_vars()
Exemple :
<a href="https://github.com/PHPBoost/PHPBoost/blob/5.1/bugtracker/services/Bug.class.php#L396">https://github.com/PHPBoost/PHPBoost/blob/5.1/bugtracker/services/Bug.class.php#L396</a>
<a href="https://github.com/PHPBoost/PHPBoost/blob/5.1/articles/controllers/ArticlesDisplayArticlesController.class.php#L132">https://github.com/PHPBoost/PHPBoost/blob/5.1/articles/controllers/ArticlesDisplayArticlesController.class.php#L132</a> (ici on écrase par un ternaire à cause de la pagination).
<a href="https://github.com/PHPBoost/PHPBoost/blob/5.1/articles/services/Article.class.php#L444">https://github.com/PHPBoost/PHPBoost/blob/5.1/articles/services/Article.class.php#L444</a>
<a href="https://github.com/PHPBoost/PHPBoost/blob/5.1/download/services/DownloadFile.class.php#L467">https://github.com/PHPBoost/PHPBoost/blob/5.1/download/services/DownloadFile.class.php#L467</a>
Cordialement, janus57
MrToine Membre non connecté
Booster Bazooka
- Booster Bazooka
- Voir le profil du membre MrToine
- Inscrit le : 26/10/2014
- Groupes :
Code PHP :
public function get_array_tpl_vars() { return array( 'ID' => $this->_id, 'BLOG_ID' => $this->_blog_id, 'AUTHOR_ID' => $this->_author_id, 'NAME' => $this->_name, 'SLUG' => $this->_slug, 'CONTENT' => FormatingHelper::second_parse($this->_content), 'SHORT_CONTENT' => substr(@strip_tags($this->_content, '<br>'), 0, 500), 'CREATED' => date('d/m/Y', $this->_created), 'APPROVED' => $this->_approved, ); }
janus57 Membre non connecté
- Booster Fusée
- Voir le profil du membre janus57
- Inscrit le : 07/12/2007
- Groupes :
- Equipe Assistance
le plus simple pour aider dans ce genre de cas est d'avoir le module au complet.
Note : pour les dates il existe aussi une fonction au niveau du noyau plutôt que de faire appel à date(), idem pour le contenu court il y a une fonction pré-faite qui empêche de couper dans une balise qui pourrait casser le parsing du BBCode.
Cordialement, janus57
MrToine Membre non connecté
Booster Bazooka
- Booster Bazooka
- Voir le profil du membre MrToine
- Inscrit le : 26/10/2014
- Groupes :
class BlogUser.class.php (tout ce qui est lié aux articles du blog)
Code PHP :
<?php /*################################################## * BlogUser.class.php * ------------------- * begin : November 01, 2014 * copyright : (C) 2014 Anthony VIOLET * email : anthony.violet@outlook.fr * * ################################################### * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ###################################################*/ class BlogUser { private $_id, $_blog_id, $_author_id, $_name, $_slug, $_content, $_created, $_approved; public function get_id(){ return $this->_id; } public function get_blog_id(){ return $this->_blog_id; } public function get_author_id(){ return $this->_author_id; } public function get_name(){ return $this->_name; } public function get_slug(){ return $this->_slug; } public function get_content(){ return $this->_content; } public function get_created(){ return $this->_created; } public function get_approved(){ return $this->_approved; } public function set_id($id){ $id = (int) $id; if($id > 0){ $this->_id = $id; } } public function set_blog_id($blog_id){ $blog_id = (int) $blog_id; if($blog_id > 0){ $this->_blog_id = $blog_id; } } public function set_author_id($author_id){ $author_id = (int) $author_id; if($author_id > 0){ $this->_author_id = $author_id; } } public function set_name($name){ if(is_string($name)){ $this->_name = htmlspecialchars($name); } } public function set_slug($slug){ if(is_string($slug)){ $this->_slug = htmlspecialchars($slug); } } public function set_content($content){ $this->_content = $content; } public function set_created($created){ $created = (int) $created; if($created > 0){ $this->_created = date('d/m/Y', $created); } } public function approved($approved){ $approved = (int) $approved; if($approved == 0 || $approved == 1){ $this->_approved = $approved; } } public function get_properties() { return array( 'id' => $this->get_id(), 'blog_id' => $this->get_blog_id(), 'author_id' => $this->get_author_id(), 'name' => TextHelper::htmlspecialchars($this->get_name()), 'slug' => TextHelper::htmlspecialchars($this->get_slug()), 'content' => $this->get_content(), 'created' => TextHelper::htmlspecialchars($this->get_created()), 'approved' => TextHelper::htmlspecialchars($this->get_approved()) ); } public function set_properties(array $properties) { $this->_id = $properties['id']; $this->_blog_id = $properties['blog_id']; $this->_author_id = $properties['author_id']; $this->_name = $properties['name']; $this->_slug = $properties['slug']; $this->_content = $properties['content']; $this->_created = $properties['created']; $this->_approved = $properties['approved']; } public function get_array_tpl_vars() { return array( 'ID' => $this->_id, 'BLOG_ID' => $this->_blog_id, 'AUTHOR_ID' => $this->_author_id, 'NAME' => $this->_name, 'SLUG' => $this->_slug, 'CONTENT' => FormatingHelper::second_parse($this->_content), 'SHORT_CONTENT' => substr(@strip_tags($this->_content, '<br>'), 0, 500), 'CREATED' => date('d/m/Y', $this->_created), 'APPROVED' => $this->_approved, ); } }
class BlogPostController.php (controller d'affichage d'un billet)
Code PHP :
<?php /*################################################## * BlogPostController.class.php * ------------------- * begin : November 07, 2014 * copyright : (C) 2014 Anthony VIOLET * email : anthony.violet@outlook.fr * * ################################################### * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ###################################################*/ class BlogPostController extends ModuleController { private $view, $blog_name, $blog_post, $post_name, $lang, $user; public function execute(HTTPRequestCustom $request) { $this->blog_post = $request->get_getstring('post_slug'); $this->init(); $this->user = AppContext::get_current_user(); $result = BlogService::get_blog_articles($this->blog_post); $post = new BlogUser(); $post->set_properties($result); /* Comments */ $comments_topic = new BlogCommentsTopic(); $comments_topic->set_id_in_module($post->get_id()); $comments_topic->set_url(BlogUrlBuilder::display_comments_posts($post->get_slug())); if($this->user->get_id() == $post->get_author_id()){ $this->view->put('IS_AUTHOR_BLOG', True); } $this->view->put_all(array( 'ID' => $post->get_id(), 'NAME' => $post->get_name(), 'SLUG' => $post->get_slug(), 'CONTENT' => $post->get_content(), 'CREATED' => date('d/m/Y', $post->get_created()), 'APPROVED' => $post->get_approved(), 'USER' => $result['display_name'], 'LINK_USER_PROFILE' => UserUrlBuilder::profile($result['user_id'])->absolute(), 'MANAGE_BLOG_LINK' => BlogUrlBuilder::manage_blog($post->get_blog_id())->absolute(), 'MANAGE_NEWS_LINK' => BlogUrlBuilder::manage_news($post->get_blog_id())->absolute(), 'CREATE_POST_LINK' => BlogUrlBuilder::create_post($post->get_blog_id())->absolute(), 'USER_ID' => $result['user_id'], 'USER_LEVEL_CLASS' => UserService::get_level_class($result['level']), 'COMMENTS' => $comments_topic->display() )); $this->post_name = $post->get_name(); return $this->generate_response(); } private function init() { $this->lang = LangLoader::get('common', 'blog'); $this->view = new FileTemplate('blog/BlogPostController.tpl'); $this->view->add_lang($this->lang); } private function get_blog(){ $this->blog = BlogService::get_blog($this->blog_post); return $this->blog; } private function generate_response() { $response = new SiteDisplayResponse($this->view); $graphical_environment = $response->get_graphical_environment(); $graphical_environment->set_page_title($this->lang['module_title']); $breadcrumb = $graphical_environment->get_breadcrumb(); $breadcrumb->add($this->lang['module_title'], BlogUrlBuilder::home()->rel()); $breadcrumb->add($this->blog_name); $breadcrumb->add($this->post_name); return $response; } }
et le TPL de BlogPostController :
Code HTML :
<section> # IF IS_AUTHOR_BLOG # <div class="content"> <div class="options info"> <h3>Gestion du blog</h3> <p><a href="{CREATE_POST_LINK}">{@manager.create_post}</a></p> <p><a href="{MANAGE_NEWS_LINK}">{@manager.manage_posts}</a></p> <p><a href="{MANAGE_BLOG_LINK}">{@manager.admin_blog}</a></p> </div> </div> # ENDIF # <header> <h1>{NAME}</h1> <div class="more"> ${LangLoader::get_message('by', 'common')} <a href="{LINK_USER_PROFILE}" class="{USER_LEVEL_CLASS}" # IF C_USER_GROUP_COLOR # style="color:{USER_GROUP_COLOR}" # ENDIF #>{USER} </a> ${LangLoader::get_message('the', 'common')} {CREATED} </div> </header> <p>{CONTENT}</p> <footer></footer> </section> <section> <header> <h1>Commentaires</h1> <div class="more"></div> # INCLUDE COMMENTS # </header> </section>
Répondre
Vous n'êtes pas autorisé à écrire dans cette catégorie