Changeset 441 for trunk/lib/PEdit.inc.php
- Timestamp:
- Dec 5, 2013 6:58:11 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/PEdit.inc.php
r421 r441 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 35 35 * and call printing/editing functions where you want data and forms to 36 36 * show up. 37 * 37 * 38 38 * @author Quinn Comendant <quinn@strangecode.com> 39 39 * @concept Beau Smith <beau@beausmith.com> 40 * @version 2.0 41 * 40 * @version 2.0 41 * 42 42 * Example of use: 43 43 44 44 // Initialize PEdit object. 45 45 require_once 'codebase/lib/PEdit.inc.php'; … … 48 48 'authorized' => true, 49 49 )); 50 50 51 51 // Setup content data types. 52 52 $pedit->set('title'); 53 53 $pedit->set('content', array('type' => 'textarea')); 54 54 55 55 // After setting all parameters and data, load the data. 56 56 $pedit->start(); 57 57 58 58 // Print content. 59 59 echo $pedit->get('title'); 60 60 echo $pedit->get('content'); 61 61 62 62 // Print additional PEdit functionality. 63 63 $pedit->formBegin(); … … 96 96 { 97 97 $this->setParam($params); 98 98 99 99 if ($this->getParam('authorized') === true) { 100 100 $this->_authorized = true; 101 101 } 102 102 103 103 // Setup PEAR XML libraries. 104 104 require_once 'XML/Serializer.php'; … … 114 114 )); 115 115 } 116 116 117 117 /** 118 118 * Set (or overwrite existing) parameters by passing an array of new parameters. … … 143 143 { 144 144 $app =& App::getInstance(); 145 145 146 146 if (isset($this->_params[$param])) { 147 147 return $this->_params[$param]; … … 151 151 } 152 152 } 153 153 154 154 /* 155 155 * Load the pedit data and run automatic functions. … … 166 166 trigger_error(sprintf('PEdit data directory not found: %s', $this->getParam('data_dir')), E_USER_WARNING); 167 167 } 168 168 169 169 // The location of the data file. (i.e.: "COMMON_DIR/html/_pedit_data/news/index.xml") 170 170 $this->_data_file = sprintf('%s%s.xml', $this->getParam('data_dir'), $_SERVER['SCRIPT_NAME']); 171 172 // Make certain the evaluated path matches the assumed path (realpath will expand /../../); 171 172 // Make certain the evaluated path matches the assumed path (realpath will expand /../../); 173 173 // if realpath returns FALSE we're not concerned because it means the file doesn't exist (_initializeDataFile() will create it). 174 174 if (false !== realpath($this->_data_file) && $this->_data_file !== realpath($this->_data_file)) { … … 199 199 break; 200 200 } 201 201 202 202 // Load data. 203 203 $this->_loadDataFile(); … … 258 258 return false; 259 259 } 260 ?> 260 ?> 261 261 <form action="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" method="post" id="sc-pedit-form"> 262 262 <input type="hidden" name="filename" value="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" /> … … 307 307 function printForm($name, $type='text') 308 308 { 309 if ($this->_authorized && $this->op == 'Edit' && $this->_data_loaded) { 309 if ($this->_authorized && $this->op == 'Edit' && $this->_data_loaded) { 310 310 ?> 311 311 <div class="sc-pedit-item"> … … 468 468 } 469 469 $xml_file_contents = file_get_contents($this->_data_file); 470 $status = $this->xml_unserializer->unserialize($xml_file_contents, false); 470 $status = $this->xml_unserializer->unserialize($xml_file_contents, false); 471 471 if (PEAR::isError($status)) { 472 472 $app->logMsg(sprintf('XML_Unserialize error: %s', $status->getMessage()), LOG_WARNING, __FILE__, __LINE__); … … 487 487 return true; 488 488 } 489 489 490 490 /* 491 491 * Start a new data file. … … 535 535 return false; 536 536 } 537 537 538 538 // Collect posted data that is already specified in _data (by set()). 539 539 foreach ($new_data as $name => $content) { … … 542 542 } 543 543 } 544 544 545 545 if (is_array($this->_data) && !empty($this->_data)) { 546 546 $xml_file_contents = $this->xml_serializer->serialize($this->_data); … … 549 549 } 550 550 } 551 551 552 552 /* 553 553 * Writes content to the specified file. … … 587 587 if ($fp = fopen($filename, 'w')) { 588 588 if (flock($fp, LOCK_EX)) { 589 fwrite($fp, $content , mb_strlen($content));589 fwrite($fp, $content); 590 590 flock($fp, LOCK_UN); 591 591 } else { … … 639 639 return true; 640 640 } 641 641 642 642 /* 643 643 * Delete all versions older than versions_min_days if there are more than versions_min_qty or 100. … … 714 714 return false; 715 715 } 716 716 717 717 // The file to restore. 718 718 $version_file = sprintf('%s__%s.xml', preg_replace('/\.xml$/', '', $this->_data_file), $version); 719 719 720 720 // Ensure specified version exists. 721 721 if (!file_exists($version_file)) {
Note: See TracChangeset
for help on using the changeset viewer.