function patchForum($undo = false, $patch_full)
 {
     global $mainframe;
     jimport('joomla.filesystem.file');
     $patch_status = "";
     $success = true;
     $phpbb3_path = $this->getForumPath();
     $advsrch_file = JPATH_SITE . DS . $phpbb3_path . DS . "styles" . DS . "prosilver" . DS . "template" . DS . "search_body.html";
     $advsrch_data = JFile::read($advsrch_file);
     $old_advsrch = "<form method=\"get\"";
     $new_advsrch = "<form method=\"post\"";
     if ($undo) {
         $advsrch_data = str_replace($new_advsrch, $old_advsrch, $advsrch_data);
         $patch_status = "PATCH_SMALL_UNINSTALLED";
     } else {
         $advsrch_data = str_replace($old_advsrch, $new_advsrch, $advsrch_data);
         $patch_status = "PATCH_SMALL_INSTALLED";
     }
     if (!Jfile::write($advsrch_file, $advsrch_data)) {
         $mainframe->enqueueMessage(sprintf(JText::_('CANNOT_WRITE'), $advsrch_file), "error");
         $success = false;
     } else {
         $success = true;
     }
     if ($patch_full == 1) {
         $functions_file = JPATH_SITE . DS . $phpbb3_path . DS . "includes" . DS . "functions.php";
         $functions_data = JFile::read($functions_file);
         $funcsadmin_file = JPATH_SITE . DS . $phpbb3_path . DS . "includes" . DS . "functions_admin.php";
         $funcsadmin_data = JFile::read($funcsadmin_file);
         $old_return = "return \$phpbb_root_path . str_replace('&', '&amp;', \$redirect);";
         $new_return = "return str_replace('&', '&amp;', \$redirect);";
         $old_funcsadmin = "\$matches = array();";
         $new_funcsadmin = "\$matches = array();\r\n//patch for bridged mode only\r\nif (PHPBB_EMBEDDED===true) {\r\n\t\$rootdir = str_replace(PHPBB_ROOT_PATH,\"../\".PHPBB_BASE_PATH.\"/\", \$rootdir );\r\n}";
         if ($undo) {
             $functions_data = str_replace($new_return, $old_return, $functions_data);
             $funcsadmin_data = str_replace($new_funcsadmin, $old_funcsadmin, $funcsadmin_data);
             $patch_status = "PATCH_UNINSTALLED";
         } else {
             $functions_data = str_replace($old_return, $new_return, $functions_data);
             $funcsadmin_data = str_replace($old_funcsadmin, $new_funcsadmin, $funcsadmin_data);
             $patch_status = "PATCH_INSTALLED";
         }
         if (!Jfile::write($functions_file, $functions_data)) {
             $mainframe->enqueueMessage(sprintf(JText::_('CANNOT_WRITE'), $functions_file), "error");
             $success = false;
         } else {
             $success = true;
         }
         if (!Jfile::write($funcsadmin_file, $funcsadmin_data)) {
             $mainframe->enqueueMessage(sprintf(JText::_('CANNOT_WRITE'), $funcsadmin_file), "error");
             $success = false;
         } else {
             $success = true;
         }
     }
     if ($success) {
         $mainframe->enqueueMessage(JText::_($patch_status));
     }
 }
 /**
  * Processing File(s)
  * @param array $options		The configuration array for the component
  * @param string $task  		a specific task (overrides $options)
  * @param mixed $file  		a specific filename or array of filenames to process (overrides $options)
  * @param string $redirect_task	the task to use when redirecting (blank means no redirection)
  * @param boolean $report	whether or not to report processing success/failure
  */
 function multitask($task = null, $file = null, $redirect_task = 'language_files', $report = true)
 {
     global $option;
     // variables
     $options = Language_manager::getOptions();
     //$task = strtolower( is_null($task) ? $this->_task : $task );
     // validate the task
     if ($task == 'cancel') {
         $task = 'checkin';
         $redirect_task = 'language_files';
         $report = false;
     }
     // validate the filename
     // 1: use a specific file or files
     // 2: use the client_lang
     // 3: check that we have at least one file
     if ($file) {
         $options['cid'] = is_array($file) ? $file : array($file);
     } else {
         if (empty($options['cid'][0]) && $task != 'checkin') {
             echo "<script> alert('" . JText::_('Please make a selection from the list to') . ' ' . JText::_(str_replace('xml', '', $task)) . "'); window.history.go(-1);</script>\n";
             exit;
         }
     }
     // initialise file classes
     jimport('joomla.filesystem.file');
     // initialise checkout file content
     if ($task == 'checkout') {
         $user =& JFactory::getUser();
         $chk_file_content = time() . '#' . $user->get('id', '0') . '#' . $user->get('name', '[ Unknown User ]');
     }
     // initialise variables
     global $mainframe;
     $file_list = array();
     $nofile_list = array();
     $inifile_list = array();
     $last = '';
     // process each passed file name (always the 'real' filename)
     foreach ($options['cid'] as $file) {
         // validate the filename language prefix
         if (preg_match('/^[a-z]{2,3}-[A-Z]{2}[.].*/', $file)) {
             // get the language and language path
             $lang = substr($file, 0, $options['langLen']);
             $langPath = JLanguage::getLanguagePath($options['basePath'], $lang);
             // ensure that XML files are only affected by XML tasks
             if (substr($file, -4) == '.xml' && substr($task, -3) != 'xml') {
                 // continue without error warning
                 continue;
             }
             // get file path-names
             $chk_file = 'chk.' . $file;
             $pub_file = $file;
             $unpub_file = 'xx.' . $file;
             // check for an unpublished file
             if (JFile::exists($langPath . DS . $unpub_file)) {
                 $file = $unpub_file;
             } else {
                 if (!JFile::exists($langPath . DS . $file)) {
                     // error and continue
                     $nofile_list[$file] = $file;
                     continue;
                 }
             }
             // cancel/checkin a file
             // checkout a file
             // delete a file
             // delete an XML file
             // publish a file
             // unpublish a file
             // otherwise break because the task isn't recognised
             if ($task == 'checkin' && JFile::exists($langPath . DS . $chk_file)) {
                 $do = JFile::delete($langPath . DS . $chk_file);
             } else {
                 if ($task == 'checkout') {
                     $do = Jfile::write($langPath . DS . $chk_file, $chk_file_content);
                 } else {
                     if ($task == 'remove') {
                         $do = JFile::delete($langPath . DS . $file);
                     } else {
                         if ($task == 'publish') {
                             $do = JFile::move($file, $pub_file, $langPath);
                         } else {
                             if ($task == 'unpublish') {
                                 $do = JFile::move($file, $unpub_file, $langPath);
                             } else {
                                 break;
                             }
                         }
                     }
                 }
             }
             // build an array of things to hide form the filename
             $filename_hide = array();
             // add the function to the file list on success
             if ($do) {
                 $file_list[$file] = str_replace('xx.' . $lang, $lang, substr($file, 0, -4));
             }
         }
     }
     if ($report) {
         // report processing success
         if (count($file_list)) {
             $mainframe->enqueueMessage(sprintf(JText::_($task . ' success'), count($file_list), implode(', ', $file_list)));
         }
         // report existing ini files
         if (count($inifile_list)) {
             $mainframe->enqueueMessage(sprintf(JText::_($task . ' inifile'), count($inifile_list), implode(', ', $inifile_list)));
         }
     }
     // redirect
     if ($redirect_task) {
         $mainframe->redirect('index.php?option=' . $option . '&client_lang=' . $options['client_lang'] . '&task=' . $redirect_task);
     }
 }
Example #3
0
 /**
  * @param string $file
  * @param string $buffer
  * @param bool $append
  * @throws SPException
  * @return bool
  */
 public static function write($file, &$buffer, $append = false)
 {
     if ($append) {
         $content = self::read($file);
         $buffer = $content . $buffer;
     }
     $return = Jfile::write($file, $buffer);
     if ($return === false) {
         throw new SPException(SPLang::e('CANNOT_WRITE_TO_FILE_AT', $file));
         return false;
     } else {
         return $return;
     }
 }