What is wrong in my lang tool function?

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
hjortsberg
Joomla! Explorer
Joomla! Explorer
Posts: 359
Joined: Sun Jun 22, 2008 4:25 pm

What is wrong in my lang tool function?

Post by hjortsberg » Wed Aug 31, 2011 2:29 pm

I have a function in my controller, that function is ment to change rows in my lang files.
Some rows can be edited but some won't change, can't figure out why...

Can someone please check what I am doing wrong (I am soon out of hair:/)

Code: Select all

function edit_help_topic() 
	{ 
		global $option;
		
switch (JRequest::getVar('save', 0, '','string'))
			{	
				case 'Save':
				
				function replaceLineInTextFile($file, $pattern, $replacement)
				{
					if(!file_exists($file))
					{ // if file doesn't exist...
						$this->setRedirect('index.php?option=' . $option .'&view=help', 'File does not exist...'); // ...stop executing code.
					}
					else
					{ // if file exists...
						$f = file($file); // ...make new variable...
						$content; // ...and another...
				
						for($i = 0; $i < count($f); $i++)
						{ // ...run through the loop...
							if(eregi($pattern, $f[$i]))
							{ // and
								$content .= $replacement . "\n"; // get
							}
							else
							{ // the
								$content .= $f[$i]; // content.
							}
						}
						$fi = fopen($file, "w"); // open specified file...
						fwrite($fi, $content); // and rewrite it's content.
						fclose($fi); // close file.
					}
				}
				
				if(JRequest::getVar('language', '', 'post','string') == '' || JRequest::getVar('language', '', 'post','string') == 'sv-SE'){
				preg_match_all("/(".JRequest::getVar('old_big_lang', '', 'post','string').")=(.*)/", file_get_contents(JPATH_SITE.DS.'language'.DS.'sv-SE'.DS.'sv-SE'.'.com_mycomponent.ini'), $matches);
				$language = 'sv-SE';
				}
				else{
					preg_match_all("/(".JRequest::getVar('old_big_lang', '', 'post','string').")=(.*)/", file_get_contents(JPATH_SITE.DS.'language'.DS.JRequest::getVar('language', '', 'post','string').DS.JRequest::getVar('language', '', 'post','string').'.com_mycomponent.ini'), $matches);
					$language = JRequest::getVar('language', '', 'post', 'string');
				}
				
				$white_removed = str_replace(array('\r\n', '\r', '\n', '\t'), ' ', JRequest::getVar('text_langfile', '', 'post', 'string', JREQUEST_ALLOWRAW));
				 				
				replaceLineInTextFile(JPATH_SITE.DS.'language'.DS.$language.DS.$language.'.com_mycomponent.ini', JRequest::getVar('old_big_lang', 0, 'post','string').'='.$matches[2][0], JRequest::getVar('old_big_lang', 0, 'post','string').'='.$white_removed); // testing...
				
				$this->setRedirect('index.php?option=' . $option .'&view=help&del=edit&tmpl=component&old_big_lang='.JRequest::getVar('old_big_lang', 0, '','string').'&language='.JRequest::getVar('language', 0, 'post','string').'&help_view='.JRequest::getVar('help_view', 0, 'post','string'), 'String replaced...');
							
				break;
			}

	}

hjortsberg
Joomla! Explorer
Joomla! Explorer
Posts: 359
Joined: Sun Jun 22, 2008 4:25 pm

Re: What is wrong in my lang tool function?

Post by hjortsberg » Wed Aug 31, 2011 4:25 pm

It seems like when the string in lang file contains html it won't work...

Somewhere about here I think, but it is a guess...

Code: Select all

for($i = 0; $i < count($f); $i++)
                  { // ...run through the loop...
                     if(eregi($pattern, $f[$i]))
                     { // and
                        $content .= $replacement . "\n"; // get
                     }
                     else
                     { // the
                        $content .= $f[$i]; // content.
                     }
                  }
                  $fi = fopen($file, "w"); // open specified file...
                  fwrite($fi, $content); // and rewrite it's content.


Locked

Return to “Joomla! 1.5 Coding”