[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/ -> addcontent.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program is distributed in the hope that it will be useful,
  12  #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #GNU General Public License for more details.
  15  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  #
  19  #$Id: addcontent.php 3774 2007-01-24 02:51:41Z elijahlofgren $
  20  
  21  $CMS_ADMIN_PAGE=1;
  22  
  23  require_once ("../include.php");
  24  
  25  check_login();
  26  $userid = get_userid();
  27  
  28  require_once(dirname(dirname(__FILE__)) . '/lib/xajax/xajax.inc.php');
  29  $xajax = new xajax();
  30  $xajax->registerFunction('ajaxpreview');
  31  
  32  $xajax->processRequests();
  33  $headtext = $xajax->getJavascript('../lib/xajax')."\n";
  34  
  35  if (isset($_POST["cancel"]))
  36  {
  37      redirect("listcontent.php");
  38  }
  39  
  40  require_once ("header.php");
  41  
  42  $tmpfname = '';
  43  
  44  $error = FALSE;
  45  
  46  $firsttime = "1"; #Flag to make sure we're not trying to fill params on the first display
  47  if (isset($_POST["firsttime"])) $firsttime = $_POST["firsttime"];
  48  
  49  $preview = false;
  50  if (isset($_POST["previewbutton"])) $preview = true;
  51  
  52  $submit = false;
  53  if (isset($_POST["submitbutton"])) $submit = true;
  54  
  55  $apply = false;
  56  if (isset($_POST["applybutton"])) $apply = true;
  57  
  58  $parent_id = get_site_preference('default_parent_page', -1);
  59  if (isset($_GET["parent_id"])) $parent_id = $_GET["parent_id"];
  60  
  61  $contentobj = '';
  62  
  63  function ajaxpreview($params)
  64  {
  65      global $gCms;
  66      $config =& $gCms->GetConfig();
  67      $contentops =& $gCms->GetContentOperations();
  68  
  69      $contentobj = '';
  70      if (isset($params["serialized_content"]) && $params["serialized_content"] != '')
  71      {
  72          $content_type = $params['content_type'];
  73          $contentops->LoadContentType($content_type);
  74          $contentobj = UnserializeObject($params["serialized_content"]);
  75          if (strtolower(get_class($contentobj)) != strtolower($content_type))
  76          {
  77              copycontentobj($contentobj, $content_type, $params);
  78          }
  79      }
  80      else
  81      {
  82          $content_type = $params['content_type'];
  83          $contentobj = $contentops->CreateNewContent($content_type);
  84      }
  85      updatecontentobj($contentobj, true, $params);
  86      $tmpfname = createtmpfname($contentobj);
  87      $url = $config["root_url"].'/preview.php?tmpfile='.urlencode(basename($tmpfname));
  88      
  89      $objResponse = new xajaxResponse();
  90      $objResponse->addAssign("previewframe", "src", $url);
  91      $objResponse->addAssign("serialized_content", "value", SerializeObject($contentobj));
  92      $count = 0;
  93      foreach ($contentobj->TabNames() as $tabname)
  94      {
  95          $objResponse->addScript("Element.removeClassName('editab".$count."', 'active');Element.removeClassName('editab".$count."_c', 'active');$('editab".$count."_c').style.display = 'none';");
  96          $count++;
  97      }
  98      $objResponse->addScript("Element.addClassName('edittabpreview', 'active');Element.addClassName('edittabpreview_c', 'active');$('edittabpreview_c').style.display = '';");
  99      return $objResponse->getXML();
 100  }
 101  
 102  function updatecontentobj(&$contentobj, $preview, $params = null)
 103  {
 104      if ($params == null)
 105          $params = $_POST;
 106  
 107      $userid = get_userid();
 108      $adminaccess = (
 109          check_ownership($userid, $contentobj->Id()) ||
 110          check_permission($userid, 'Modify Any Page') || 
 111          check_permission($userid, 'Modify Page Structure')
 112      );
 113          
 114      #Fill contentobj with parameters
 115      $contentobj->FillParams($params);
 116      if ($preview)
 117      {
 118          $error = $contentobj->ValidateData();
 119      }
 120  
 121      if (isset($params["ownerid"]))
 122      {
 123          $contentobj->SetOwner($params["ownerid"]);
 124      }
 125  
 126      $contentobj->SetLastModifiedBy($userid);
 127  
 128      #Fill Additional Editors (kind of kludgy)
 129      if (isset($params["additional_editors"]))
 130      {
 131          $addtarray = array();
 132          foreach ($params["additional_editors"] as $addt_user_id)
 133          {
 134              $addtarray[] = $addt_user_id;
 135          }
 136          $contentobj->SetAdditionalEditors($addtarray);
 137      }
 138      else if ($adminaccess)
 139      {
 140          $contentobj->SetAdditionalEditors(array());
 141      }
 142  }
 143  
 144  function copycontentobj(&$contentobj, $content_type, $params = null)
 145  {
 146      global $gCms;
 147      $contentops =& $gCms->GetContentOperations();
 148      
 149      if ($params == null)
 150          $params = $_POST;
 151  
 152      $newcontenttype = strtolower($content_type);
 153      $contentops->LoadContentType($newcontenttype);
 154      $contentobj->FillParams($params);
 155      $tmpobj = $contentops->CreateNewContent($newcontenttype);
 156      $tmpobj->SetId($contentobj->Id());
 157      $tmpobj->SetName($contentobj->Name());
 158      $tmpobj->SetMenuText($contentobj->MenuText());
 159      $tmpobj->SetTemplateId($contentobj->TemplateId());
 160      $tmpobj->SetParentId($contentobj->ParentId());
 161      $tmpobj->SetOldParentId($contentobj->OldParentId());
 162      $tmpobj->SetAlias($contentobj->Alias());
 163      $tmpobj->SetOwner($contentobj->Owner());
 164      $tmpobj->SetActive($contentobj->Active());
 165      $tmpobj->SetItemOrder($contentobj->ItemOrder());
 166      $tmpobj->SetOldItemOrder($contentobj->OldItemOrder());
 167      $tmpobj->SetShowInMenu($contentobj->ShowInMenu());
 168      //Some content types default to false for a reason... don't override it
 169      if (!(!$tmpobj->mCachable && $contentobj->Cachable()))
 170          $tmpobj->SetCachable($contentobj->Cachable());
 171      $tmpobj->SetHierarchy($contentobj->Hierarchy());
 172      $tmpobj->SetLastModifiedBy($contentobj->LastModifiedBy());
 173      $tmpobj->SetAdditionalEditors($contentobj->GetAdditionalEditors());
 174      $contentobj = $tmpobj;
 175  }
 176  
 177  function createtmpfname(&$contentobj)
 178  {
 179      global $gCms;
 180      $config =& $gCms->GetConfig();
 181      $templateops =& $gCms->GetTemplateOperations();
 182  
 183      $data["content_id"] = $contentobj->Id();
 184      $data["title"] = $contentobj->Name();
 185      $data["menutext"] = $contentobj->MenuText();
 186      $data["content"] = $contentobj->Show();
 187      $data["template_id"] = $contentobj->TemplateId();
 188      $data["hierarchy"] = $contentobj->Hierarchy();
 189      
 190      $templateobj = $templateops->LoadTemplateById($contentobj->TemplateId());
 191      $data['template'] = $templateobj->content;
 192  
 193      $stylesheetobj = get_stylesheet($contentobj->TemplateId());
 194      $data['encoding'] = $stylesheetobj['encoding'];
 195      // $data['stylesheet'] = $stylesheetobj['stylesheet'];
 196  
 197      $tmpfname = '';
 198      if (is_writable($config["previews_path"]))
 199      {
 200          $tmpfname = tempnam($config["previews_path"], "cmspreview");
 201      }
 202      else
 203      {
 204          $tmpfname = tempnam(TMP_CACHE_LOCATION, "cmspreview");
 205      }
 206      $handle = fopen($tmpfname, "w");
 207      fwrite($handle, serialize($data));
 208      fclose($handle);
 209      
 210      return $tmpfname;
 211  }
 212  
 213  #Get current userid and make sure they have permission to add something
 214  $access = (check_permission($userid, 'Add Pages') || check_permission($userid, 'Modify Page Structure'));
 215  
 216  #Get a list of content types and pick a default if necessary
 217  global $gCms;
 218  $contentops =& $gCms->GetContentOperations();
 219  $existingtypes = $contentops->ListContentTypes();
 220  $content_type = "";
 221  if (isset($_POST["content_type"]))
 222  {
 223      $content_type = $_POST["content_type"];
 224  }
 225  else
 226  {
 227      if (isset($existingtypes) && count($existingtypes) > 0)
 228      {
 229          $content_type = 'content';
 230      }
 231      else
 232      {
 233          $error = "No content types loaded!";
 234      }
 235  }
 236  
 237  $contentobj = "";
 238  if (isset($_POST["serialized_content"]))
 239  {
 240      $contentops =& $gCms->GetContentOperations();
 241      $contentops->LoadContentType($_POST['orig_content_type']);
 242      $contentobj = unserialize(base64_decode($_POST["serialized_content"]));
 243      if (strtolower(get_class($contentobj)) != $content_type)
 244      {
 245          #Fill up the existing object with values in form
 246          #Create new object
 247          #Copy important fields to new object
 248          #Put new object on top of old on
 249          copycontentobj($contentobj, $content_type);
 250      }
 251  }
 252  else
 253  {
 254      $contentops =& $gCms->GetContentOperations();
 255      $contentobj = $contentops->CreateNewContent($content_type);
 256      $contentobj->SetOwner($userid);
 257      $contentobj->SetActive(True);
 258      $contentobj->SetShowInMenu(True);
 259      $contentobj->SetLastModifiedBy($userid);
 260      $contentobj->SetPropertyValue('content_en', get_site_preference('defaultpagecontent'));
 261      if ($parent_id!=-1) $contentobj->SetParentId($parent_id);
 262  }
 263  
 264  if ($access)
 265  {
 266      if ($submit || $apply)
 267      {
 268          #Fill contentobj with parameters
 269          $contentobj->FillParams($_POST);
 270          $contentobj->SetOwner($userid);
 271  
 272          #Fill Additional Editors (kind of kludgy)
 273          if (isset($_POST["additional_editors"]))
 274          {
 275              $addtarray = array();
 276              foreach ($_POST["additional_editors"] as $addt_user_id)
 277              {
 278                  $addtarray[] = $addt_user_id;
 279              }
 280              $contentobj->SetAdditionalEditors($addtarray);
 281          }
 282  
 283          $error = $contentobj->ValidateData();
 284          if ($error === FALSE)
 285          {
 286              $contentobj->Save();
 287              global $gCms;
 288              $contentops =& $gCms->GetContentOperations();
 289              $contentops->SetAllHierarchyPositions();
 290              if ($submit)
 291              {
 292                  audit($contentobj->Id(), $contentobj->Name(), 'Added Content');
 293                  redirect('listcontent.php?message=contentadded');
 294              }
 295          }
 296      }
 297      else if ($firsttime == "0") #Either we're a preview or a template postback
 298      {
 299          $contentobj->FillParams($_POST);
 300          if ($preview) #If preview, check for errors...
 301          {
 302              $error = $contentobj->ValidateData();
 303          }
 304          if (isset($_POST["additional_editors"]))
 305          {
 306              $addtarray = array();
 307              foreach ($_POST["additional_editors"] as $addt_user_id)
 308              {
 309                  $addtarray[] = $addt_user_id;
 310              }
 311              $contentobj->SetAdditionalEditors($addtarray);
 312          }
 313      }
 314      else
 315      {
 316          $firsttime = "0";
 317      }
 318  }
 319  
 320  if (!$access)
 321  {
 322      echo "<div class=\"pageerrorcontainer pageoverflow\"><p class=\"pageerror\">".lang('noaccessto',array(lang('addcontent')))."</p></div>";
 323  }
 324  else
 325  {
 326  #Get a list of content_types and build the dropdown to select one
 327  $typesdropdown = '<select name="content_type" onchange="document.contentform.submit()" class="standard">';
 328  $cur_content_type = '';
 329  foreach ($gCms->contenttypes as $onetype)
 330  {
 331      $typesdropdown .= '<option value="' . $onetype->type . '"';
 332      if ($onetype->type == $content_type)
 333      {
 334          $typesdropdown .= ' selected="selected" ';
 335          $cur_content_type = $onetype->type;
 336      }
 337      $typesdropdown .= ">".($onetype->friendlyname)."</option>";
 338  }
 339  $typesdropdown .= "</select>";
 340  
 341  if (FALSE == empty($error))
 342  {
 343      echo $themeObject->ShowErrors($error);
 344  }
 345  else if ($preview)
 346  {
 347      $tmpfname = createtmpfname($contentobj);
 348  
 349  ?>
 350  
 351  <!--
 352  <div class="pagecontainer">
 353      <p class="pageheader"><?php echo lang('preview')?></p>
 354      <iframe name="previewframe" class="preview" src="<?php echo $config["root_url"] ?>/preview.php?tmpfile=<?php echo urlencode(basename($tmpfname))?>"></iframe>
 355  </div>
 356  -->
 357  <?php
 358  }
 359  
 360  #$contentarray = $contentobj->EditAsArray(true, 0);
 361  #$contentarray2 = $contentobj->EditAsArray(true, 1);
 362  
 363  $tabnames = $contentobj->TabNames();
 364  
 365  ?>
 366  
 367  <div class="pagecontainer">
 368  <div class="pageoverflow">
 369      <?php
 370      echo $themeObject->ShowHeader('addcontent').'</div>';
 371      ?>
 372      <div id="page_tabs">
 373          <?php
 374          $count = 0;
 375  
 376          #We have preview, but no tabs
 377          if (count($tabnames) == 0)
 378          {
 379              ?>
 380              <div id="editab0" class="active"><?php echo lang('content')?></div>
 381              <?php
 382          }
 383          else
 384          {
 385              foreach ($tabnames as $onetab)
 386              {
 387                  ?>
 388                  <div id="editab<?php echo $count?>"><?php echo $onetab?></div>
 389                  <?php
 390                  $count++;
 391              }
 392          }
 393  
 394          if ($contentobj->mPreview)
 395          {
 396              echo '<div id="edittabpreview"'.($tmpfname!=''?' class="active"':'').' onclick="##INLINESUBMITSTUFFGOESHERE##xajax_ajaxpreview(xajax.getFormValues(\'contentform\'));return false;">'.lang('preview').'</div>';
 397          }
 398          ?>
 399      </div>
 400      <div style="clear: both;"></div>
 401      <form method="post" action="addcontent.php" name="contentform" enctype="multipart/form-data" id="contentform"##FORMSUBMITSTUFFGOESHERE##>
 402      <input type="hidden" id="serialized_content" name="serialized_content" value="<?php echo SerializeObject($contentobj); ?>" />            
 403      <div id="page_content">
 404          <div class="pageoverflow">    
 405          <?php
 406          
 407          $submit_buttons = '
 408              <p class="pagetext">&nbsp;</p>
 409              <p class="pageinput">';
 410          $submit_buttons .= ' <input type="submit" name="submitbutton" value="'.lang('submit').'" class="pagebutton" onmouseover="this.className=\'pagebuttonhover\'" onmouseout="this.className=\'pagebutton\'" />';
 411          if (isset($contentobj->mPreview) && $contentobj->mPreview == true) {
 412              $submit_buttons .= ' <input type="submit" name="previewbutton" value="'.lang('preview').'" class="pagebutton" onmouseover="this.className=\'pagebuttonhover\'" onmouseout="this.className=\'pagebutton\'" onclick="##INLINESUBMITSTUFFGOESHERE##xajax_ajaxpreview(xajax.getFormValues(\'contentform\'));return false;" />';
 413          }
 414          $submit_buttons .= ' <input type="submit" name="cancel" value="'.lang('cancel').'" class="pagebutton" onmouseover="this.className=\'pagebuttonhover\'" onmouseout="this.className=\'pagebutton\'" /></p>';
 415          
 416          $numberoftabs = count($tabnames);
 417          $showtabs = 1;
 418          if ($numberoftabs == 0)
 419          {
 420              $numberoftabs = 1;
 421              $showtabs = 1;
 422          }
 423          for ($currenttab = 0; $currenttab < $numberoftabs; $currenttab++)
 424          {
 425              if ($showtabs == 1)
 426              {
 427                  ?><div id="editab<?php echo $currenttab ?>_c"><?php
 428              }
 429              if ($currenttab == 0)
 430              {
 431                  echo $submit_buttons;
 432                  ?>
 433  
 434                  <div class="pageoverflow">
 435                      <p class="pagetext"><?php echo lang('contenttype'); ?>:</p>
 436                      <p class="pageinput"><?php echo $typesdropdown; ?></p>
 437                  </div>
 438                  <?php
 439              }
 440              $contentarray = $contentobj->EditAsArray(true, $currenttab, $access);
 441              for($i=0;$i<count($contentarray);$i++)
 442              {
 443                  ?>
 444                  <div class="pageoverflow">
 445                      <p class="pagetext"><?php echo $contentarray[$i][0]; ?></p>
 446                      <p class="pageinput"><?php echo $contentarray[$i][1]; ?></p>
 447                  </div>
 448                  <?php
 449              }
 450              echo '<input type="hidden" name="firsttime" value="0" /><input type="hidden" name="orig_content_type" value="'.$cur_content_type.'" />';
 451                      ?>
 452              </div>
 453              <div style="clear: both;"></div>
 454                    <?php
 455          }
 456          if ($contentobj->mPreview)
 457          {
 458              echo '<div class="pageoverflow"><div id="edittabpreview_c"'.($tmpfname!=''?' class="active"':'').'>';
 459                  ?>
 460                      <iframe name="previewframe" class="preview" id="previewframe"<?php if ($tmpfname != '') { ?> src="<?php echo $config["root_url"] ?>/preview.php?tmpfile=<?php echo urlencode(basename($tmpfname))?>"<?php } ?>></iframe>
 461                  <?php
 462              echo '<div style="clear: both;"></div>';
 463          }
 464  ?>
 465  </div>
 466  </div>
 467  <div class="pageoverflow">
 468  <?php
 469  echo $submit_buttons;
 470  ?>
 471  </div>
 472  </div>
 473  </div>
 474  </form>
 475  </div>
 476  <?php
 477  }
 478  echo '<p class="pageback"><a class="pageback" href="'.$themeObject->BackUrl().'">&#171; '.lang('back').'</a></p>';
 479  
 480  include_once ("footer.php");
 481  
 482  # vim:ts=4 sw=4 noet
 483  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7