Ejemplo n.º 1
0
 /**
  *  This function processes the specified action.
  *
  *  @param  $action  			The action name.
  *  @param  $enable_callbacks	Default is true. Use this to disable callback processing.
  *
  *  @returns 	Returns an array containing results returned from action and callback processing.
  *				Elements of this array are keyed by strings:
  *					action:before
  *					<actionname>:before
  *					<actionname>
  *					<actionname>:after
  *					action:after
  *
  *  @internal
  */
 function _processAction($action, $enable_callbacks = true)
 {
     if (!YDStringUtil::startsWith($action, 'action')) {
         $action = 'action' . $action;
     }
     $results = array();
     if ($enable_callbacks == true) {
         $results['action:before'] = $this->_executeCallbacks('action', true);
         $results[$action . ':before'] = $this->_executeCallbacks($action, true);
     }
     $results[$action] = call_user_func(array($this, $action));
     if ($enable_callbacks == true) {
         $results[$action . ':after'] = $this->_executeCallbacks($action, false);
         $results['action:after'] = $this->_executeCallbacks('action', false);
     }
     return $results;
 }
 function actionUpdate()
 {
     // Check if a software update is going on
     YDDatabaseTools::checkLockDb();
     // Download the needed files
     foreach ($this->changed_files as $file => $action) {
         if ($action != 'D') {
             $this->updateDb->downloadFile($file);
         }
     }
     // Lock the weblog application
     YDDatabaseTools::lockDb();
     // Install the new files
     foreach ($this->changed_files as $file => $action) {
         YDUpdateTools::installFile($file, $action);
     }
     // Update the init file
     if ($this->updateDb->isUpdated('%YD_WEBLOG_HOME%/include/YDWeblog_init.php')) {
         YDUpdateTools::replaceInFile('%YD_WEBLOG_HOME%/include/YDWeblog_init.php', '\'/../../../YDFramework2/YDF2_init.php\' );', '\'/YDFramework2/YDF2_init.php\' );');
     }
     // Update the database if needed
     foreach ($this->changed_files as $file => $action) {
         if (YDStringUtil::startsWith(YDUpdateTools::shortPath($file), '%YD_WEBLOG_HOME%/include/dbupdates/')) {
             YDDatabaseTools::installDbUpdate($file);
         }
     }
     // Save the new version number
     $this->updateDb->saveVersionNumber();
     // Unlock the weblog application
     YDDatabaseTools::unlockDb();
     // Delete the downloaded files
     YDUpdateLog::info('Cleaning up the file downloads...');
     foreach ($this->changed_files as $file => $action) {
         @unlink(YDUpdateTools::tempPath($file));
     }
     // Clear the weblog cache
     YDUpdateLog::info('Clearing the weblog cache...');
     $cachePatterns = array(YD_WEBLOG_CACHE_PREFIX . '*.' . YD_WEBLOG_CACHE_SUFFIX, YD_TMP_PRE . 'N_*.*', '*.wch', '*.tpl.php', YD_TMP_PRE . 'U_*.upd');
     $dir = new YDFSDirectory(YD_DIR_TEMP);
     foreach ($cachePatterns as $pattern) {
         $filesToDelete = $dir->getContents($pattern, null);
         foreach ($filesToDelete as $file) {
             @unlink($file->getAbsolutePath());
         }
     }
     // Show a message
     echo '</p><p class="title">Software is now updated to version ' . $this->updateDb->getLastRevision() . '</p>';
 }
 /**
  *  This function returns a list with an instance of each loaded module.
  *
  *  @returns    A list with an instance of each loaded module.
  */
 function getModuleList()
 {
     $modules = array();
     foreach (get_declared_classes() as $class) {
         if (YDStringUtil::startsWith($class, YD_SIMPLECMS_MODULE_PREFIX)) {
             $modules[$class] = new $class($this);
         }
     }
     return $modules;
 }
 /**
  *  This checks if the specified text is a valid HTTP url. It should start with http:// and it should have at
  *  least one dot in there.
  *
  *  @param $val     The value to test.
  *  @param $opts    (not required)
  */
 function httpurl($val, $opts = array())
 {
     // Return true if empty
     if (empty($val)) {
         return true;
     }
     // Convert to lowercase and trim
     $val = strtolower(trim($val));
     // Add http:// if needed
     if (substr($val, 0, 7) != 'http://') {
         $val = 'http://' . $val;
     }
     // Check if it starts with http://
     if (!YDStringUtil::startsWith($val, 'http://')) {
         return false;
     }
     // Check the hostname
     $host = substr($val, 7);
     if (strpos($host, '/') !== false) {
         $host = trim(substr($host, 0, strpos($host, '/')));
     }
     if (strpos($host, ':') !== false) {
         $host = trim(substr($host, 0, strpos($host, ':')));
     }
     // Localhost is allowed
     if ($host == 'localhost') {
         return true;
     }
     // Check that we have at least a dot
     return strpos($host, '.') === false ? false : true;
 }
 /**
  *  This function removes the default table prefix to the field name.
  *
  *  @param  $field  The name of the field to remove the prefix from.
  *
  *  @returns    The name of the field with the prefix removed from it.
  */
 function _removeTablePrefix($field)
 {
     $field = explode(', ', $field);
     foreach ($field as $key => $val) {
         if (YDStringUtil::startsWith($val, $this->tablePrefix . '.')) {
             $field[$key] = substr($val, strlen($this->tablePrefix) + 1);
         }
         $pos = strpos($val, '.');
         if ($pos !== false) {
             $field[$key] = substr($val, $pos + 1);
         }
     }
     return join(', ', $field);
 }