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