public function create($infos = array()) { $blogDAO = _dao('blog|blog'); $res = null; $tabBlogFunctions = returnAllBlogFunctions(); $blog = _record('blog|blog'); if ($infos['title']) { $blog->name_blog = $infos['title'] . (isset($infos['subtitle']) && strlen($infos['subtitle']) > 0 ? ' (' . $infos['subtitle'] . ')' : ''); } else { $blog->name_blog = CopixI18N::get('blog|blog.default.titre'); } $blog->id_ctpt = 1; $blog->style_blog_file = 0; $is_public_default = CopixConfig::exists('blog|blog.default.is_public') ? CopixConfig::get('blog|blog.default.is_public') : 1; $blog->is_public = isset($infos['is_public']) ? $infos['is_public'] : $is_public_default; $blog->has_comments_activated = 0; $blog->type_moderation_comments = CopixConfig::get('blog|blog.default.type_moderation_comments'); $blog->default_format_articles = CopixConfig::get('blog|blog.default.default_format_articles'); $blog->privacy = CopixConfig::exists('blog|blog.default.privacy') ? CopixConfig::get('blog|blog.default.privacy') : 0; $blogDAO->insert($blog); if ($blog->id_blog !== NULL) { // On détermine l'URL titre $blog->url_blog = KernelBlog::calcule_url_blog($blog->id_blog, $blog->name_blog); $blogDAO->update($blog); // On ajoute une catégorie $categoryDAO = _dao('blog|blogarticlecategory'); $category = _record('blog|blogarticlecategory'); $category->id_blog = $blog->id_blog; $category->name_bacg = CopixI18N::get('blog|blog.default.categorie'); $category->url_bacg = killBadUrlChars($category->name_bacg) . date('YmdHis'); $category->order_bacg = $categoryDAO->getNewPos($blog->id_blog); $categoryDAO->insert($category); } return $blog->id_blog !== NULL ? $blog->id_blog : NULL; }
/** * */ public function doValidBlog() { $id_blog = $this->getRequest('id_blog', null); $blogDAO = CopixDAOFactory::create('blog|blog'); $blog = $blogDAO->get($id_blog); if (!BlogAuth::canMakeInBlog('ADMIN_OPTIONS', $blog)) { return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('blog.error.cannotManageBlog'), 'back' => $blog ? CopixUrl::get('|', array('blog' => $blog->url_blog)) : CopixUrl::get('||'))); } $tpl = new CopixTpl(); // Récupération de toutes les fonctions du blog $tabFunctions = returnAllBlogFunctions(); $tabSelectedFunctions = (array) $this->getRequest('tabBlogFunctions', ''); $tabBlogFunctions = array(); foreach ($tabFunctions as $fct) { if (in_array($fct->value, $tabSelectedFunctions)) { $fct->selected = 1; } array_push($tabBlogFunctions, $fct); } if ($id_blog != null) { // EDITION D'UN BLOG $blog->name_blog = $this->getRequest('name_blog', ''); $blog->is_public = $this->getRequest('is_public', 1); $blog->privacy = $this->getRequest('privacy'); $blog->has_comments_activated = $this->getRequest('has_comments_activated', 1); $blog->type_moderation_comments = $this->getRequest('type_moderation_comments', 'POST'); $blog->default_format_articles = $this->getRequest('default_format_articles', 'wiki'); //$blog->id_ctpt = $this->getRequest('id_ctpt', ''); //$blog->url_blog = $this->getRequest('url_blog', ''); // Gestion du LOGO if (is_uploaded_file($_FILES['logoFile']['tmp_name'])) { $file = COPIX_VAR_PATH . CopixConfig::get('blog|logoPath') . $blog->logo_blog; if (file_exists($file)) { @unlink($file); } $blog->logo_blog = $blog->id_blog . '_' . $_FILES['logoFile']['name']; $file = COPIX_VAR_PATH . CopixConfig::get('blog|logoPath') . $blog->logo_blog; move_uploaded_file($_FILES['logoFile']['tmp_name'], $file); } $tpl->assign('TITLE_PAGE', CopixI18N::get('blog.get.edit.blog.title')); $errors = _dao('blog|blog')->check($blog); if ($errors != 1) { // Traitement des erreurs $showErrors = true; } else { // Modification dans la base $blogDAO->update($blog); /* $blogFunctionsDAO = CopixDAOFactory::create('blog|blogfunctions'); $blogFunctionsDAO->updateBlogFunctions($id_blog, $tabBlogFunctions); */ return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('blog|admin|showBlog', array('id_blog' => $id_blog, 'kind' => $this->getRequest('kind', 0)))); } } else { // CREATION D'UN BLOG $blog = CopixDAOFactory::createRecord('blog'); $blog->name_blog = $this->getRequest('name_blog', ''); $blog->id_ctpt = $this->getRequest('id_ctpt', ''); $blog->url_blog = $this->getRequest('url_blog', ''); // Gestion du LOGO if (is_uploaded_file($_FILES['logoFile']['tmp_name'])) { $file = COPIX_VAR_PATH . CopixConfig::get('blog|logoPath') . $blog->logo_blog; if (file_exists($file)) { @unlink($file); } $blog->logo_blog = $blog->id_blog . '_' . $_FILES['logoFile']['name']; $file = COPIX_VAR_PATH . CopixConfig::get('blog|logoPath') . $blog->logo_blog; move_uploaded_file($_FILES['logoFile']['tmp_name'], $file); } $tpl->assign('TITLE_PAGE', CopixI18N::get('blog.get.create.blog.title')); $errors = _dao('blog|blog')->check($blog); if ($errors != 1) { // Traitement des erreurs $showErrors = true; } else { // Insertion dans la base $blogDAO->insert($blog); $blogFunctionsDAO = CopixDAOFactory::create('blog|blogfunctions'); $blogFunctionsDAO->createBlogFunctions($blog->id_blog, $tabBlogFunctions); return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('||')); } } $tpl->assign('MAIN', CopixZone::process('EditBlog', array('id_blog' => $id_blog, 'blog' => $blog, 'errors' => $errors, 'showErrors' => $showErrors, 'kind' => $this->getRequest('kind', 0), 'tabBlogFunctions' => $tabBlogFunctions))); return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl); }