当前位置: 首页>>代码示例>>PHP>>正文


PHP WikiPage::canEdit方法代码示例

本文整理汇总了PHP中WikiPage::canEdit方法的典型用法代码示例。如果您正苦于以下问题:PHP WikiPage::canEdit方法的具体用法?PHP WikiPage::canEdit怎么用?PHP WikiPage::canEdit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WikiPage的用法示例。


在下文中一共展示了WikiPage::canEdit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: edit

 /**
  * Edit a wiki page
  * 
  * @return void
  */
 function edit()
 {
     if (!WikiPage::canEdit(logged_user())) {
         flash_error(lang('no wiki page edit permissions'));
         $this->redirectToReferer(get_url('wiki'));
     }
     //Get the page from the url params
     $page = Wiki::getPageById(get_id(), active_project());
     if (!instance_of($page, 'WikiPage')) {
         //If the page doesn't exist, redirect to wiki index
         flash_error(lang('wiki page dnx'));
         $this->redirectToReferer(get_url('wiki'));
     }
     // if
     //Check that the user can edit this entry
     if (!$page->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo(get_url('wiki'));
     }
     // if
     // Check that the page isn't locked
     if ($page->isLocked() && !$page->canUnlock(logged_user())) {
         flash_error(lang('wiki page locked by', $page->getLockedByUser()->getUsername()));
         $this->redirectToUrl($page->getViewUrl());
     }
     // if
     //Here we will edit a wiki page
     $preview = false;
     $data = array_var($_POST, 'wiki', false);
     if (false !== $data) {
         $preview = array_key_exists('preview', $data);
     }
     if (!$preview && $data) {
         //if(null !== ($data = array_var($_POST, 'wiki'))){
         //If we have received data
         //Make a new revision
         $revision = $page->makeRevision();
         $revision->setFromAttributes($data);
         $page->setProjectIndex($data['project_index']);
         $page->setProjectSidebar($data['project_sidebar']);
         $page->setPublish($data['publish']);
         $page->setParentId($data['parent_id']);
         // Check to see if we want to lock this page
         if (isset($data['locked'])) {
             if ($data['locked'] == 1 && $page->canLock(logged_user()) && !$page->isLocked()) {
                 // If we want to lock this page and the user has permissions to lock it, and the page is not already locked
                 $page->setLocked(true);
                 $page->setLockedById(logged_user()->getId());
                 $page->setLockedOn(DateTimeValueLib::now());
             } elseif ($data['locked'] == 0 & $page->canUnlock(logged_user()) && $page->isLocked()) {
                 // Else if we want to unlock the page, and the user is allowed to, and the page is locked
                 $page->setLocked(false);
             }
             // if
         }
         // if
         //Set the users ID
         $revision->setCreatedById(logged_user()->getId());
         try {
             //Start the transaction
             DB::beginWork();
             //Save the page and create revision
             //The page will make sure that the revision's project and page Id are correct
             $page->save();
             ApplicationLogs::createLog($page, active_project(), ApplicationLogs::ACTION_EDIT);
             if (plugin_active('tags')) {
                 //Set the tags
                 $page->setTagsFromCSV($data['tags']);
             }
             //Commit changes
             DB::commit();
             flash_success(lang('success edit wiki page'));
             //Redirect to the page we just created
             $this->redirectToUrl($page->getViewUrl());
         } catch (Exception $e) {
             //Get rid of any Db changes we've made
             DB::rollback();
             //Assign the problem to the template so we can tell the user
             tpl_assign('error', $e);
         }
         //try
     } else {
         if (array_var($_GET, 'revision')) {
             //If we want to make a new revision based off a revision
             $revision = $page->getRevision($_GET['revision']);
         } else {
             $revision = $page->getLatestRevision();
         }
     }
     //if
     if (!$data) {
         // there was no input POSTed
         $data['content'] = $revision->getContent();
     }
     $data['preview_content'] = do_textile($data['content']);
//.........这里部分代码省略.........
开发者ID:bklein01,项目名称:Project-Pier,代码行数:101,代码来源:WikiController.class.php

示例2: edit

 /**
  * Edit a wiki page
  * 
  * @return void
  */
 function edit()
 {
     if (!WikiPage::canEdit(logged_user())) {
         flash_error(lang('no wiki page edit permissions'));
         $this->redirectToReferer(get_url('wiki'));
     }
     //Get the page from the url params
     $page = Wiki::getPageById(get_id(), active_project());
     if (!instance_of($page, 'WikiPage')) {
         //If the page doesn't exist, redirect to wiki index
         flash_error(lang('wiki page dnx'));
         $this->redirectToReferer(get_url('wiki'));
     }
     // if
     //Check that the user can edit this entry
     if (!$page->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo();
     }
     // if
     //Here we will edit a wiki page
     if (null !== ($data = array_var($_POST, 'wiki'))) {
         //If we have received data
         //Make a new revision
         $revision = $page->makeRevision();
         $revision->setFromAttributes($data);
         $page->setProjectIndex($data['project_index']);
         $page->setProjectSidebar($data['project_sidebar']);
         //Set the users ID
         $revision->setCreatedById(logged_user()->getId());
         try {
             //Start the transaction
             DB::beginWork();
             //Save the page and create revision
             //The page will make sure that the revision's project and page Id are correct
             $page->save();
             ApplicationLogs::createLog($page, active_project(), ApplicationLogs::ACTION_EDIT);
             if (plugin_active('tags')) {
                 //Set the tags
                 $page->setTagsFromCSV($data['tags']);
             }
             //Commit changes
             DB::commit();
             flash_success(lang('success edit wiki page'));
             //Redirect to the page we just created
             $this->redirectToUrl($page->getViewUrl());
         } catch (Exception $e) {
             //Get rid of any Db changes we've made
             DB::rollback();
             //Assign the problem to the template so we can tell the user
             tpl_assign('error', $e);
         }
         //try
     } else {
         if (array_var($_GET, 'revision')) {
             //If we want to make a new revision based off a revision
             $revision = $page->getRevision($_GET['revision']);
         } else {
             $revision = $page->getLatestRevision();
         }
     }
     //if
     //Assign revision object
     tpl_assign('revision', $revision);
     //Assign the page object
     tpl_assign('page', $page);
     //Set the template
     $this->setTemplate('edit');
 }
开发者ID:469306621,项目名称:Languages,代码行数:74,代码来源:WikiController.class.php


注:本文中的WikiPage::canEdit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。