예제 #1
0
 public function change_doc_domain_name_desc()
 {
     $project_id = $this->post('projectID');
     $domain_handle = $this->post('itemDomain');
     $item_type = $this->post('itemType');
     $item_value = $this->post('itemValue');
     $json = Loader::helper('json');
     $pas = new PageActionStatus();
     $pas->action = t('Change Domain Name/Desc');
     $pas->status = t('Unkown error');
     $pas->time = time();
     if (!fse_try_to_login()) {
         $pas->message = t('You do not sign in or session expired.');
         echo $json->encode($pas);
         exit(0);
     }
     if (!in_array($domain_handle, $this->mDomainList)) {
         $pas->message = t('Bad domain handle!');
         echo $json->encode($pas);
         exit(0);
     }
     if (!preg_match("/^[a-z0-9_\\-]{4,64}\$/", $project_id)) {
         $pas->message = t('Invalid project identifier!');
         echo $json->encode($pas);
         exit(0);
     }
     $project_home_page = ProjectInfo::getProjectPage($project_id, 'home');
     if ($project_home_page == false) {
         $pas->message = t('No such project!');
         echo $json->encode($pas);
         exit(0);
     }
     if ($item_type == 'name') {
         if (!preg_match("/^.{1,64}\$/", $item_value)) {
             $pas->message = t('Bad domain name!');
             echo $json->encode($pas);
             exit(0);
         }
         $page_property = 'cName';
     } else {
         if ($item_type == 'desc') {
             if (!preg_match("/^.{2,255}\$/", $item_value)) {
                 $pas->message = t('Bad domain description!');
                 echo $json->encode($pas);
                 exit(0);
             }
             $page_property = 'cDescription';
         } else {
             if ($item_type == 'long_desc') {
                 if (!preg_match("/^.{2,255}\$/", $item_value)) {
                     $pas->status = "error";
                     $pas->message = t('Bad long domain description!');
                     echo $json->encode($pas);
                     exit(0);
                 }
                 $page_property = false;
             } else {
                 $pas->status = "error";
                 $pas->message = "Bad item type: {$item_type}!";
                 echo $json->encode($pas);
                 exit(0);
             }
         }
     }
     $project_info = ProjectInfo::getBasicInfo($project_id);
     if ($project_info['fse_id'] != $_SESSION['FSEInfo']['fse_id']) {
         $pas->message = t('You are not the owner of the project!');
         echo $json->encode($pas);
         exit(0);
     }
     $db = Loader::db();
     $res = $db->Execute("UPDATE fsen_project_doc_domains SET domain_{$item_type}=?\n\tWHERE project_id=? AND domain_handle=?", array($item_value, $project_id, $domain_handle));
     if ($db->Affected_Rows() == 0) {
         $pas->message = t('Nothing changed!');
         echo $json->encode($pas);
         exit(0);
     }
     ProjectInfo::onUpdateProjectDomainInfo($project_id, $domain_handle);
     /* update page attributes and refresh block caches */
     $cache = PageCache::getLibrary();
     if ($domain_handle != 'home') {
         $domain_page = ProjectInfo::getProjectPage($project_id, $domain_handle);
         if ($domain_page != false) {
             $cache->purge($domain_page);
         }
         if ($page_property) {
             $domain_page->update(array($page_property => $item_value));
         }
     }
     $cache->purge($project_home_page);
     $pas->status = 'success';
     $pas->message = t('Item changed!');
     echo $json->encode($pas);
     exit(0);
 }