Welcome Guest, Not a member yet? Register   Sign In
Extending display() array with html content
#1

[eluser]atrioom[/eluser]
Hi CI-Community,

Following problem i have come accross:
We have a bunch of translators working in our databases. For easier comparison of DB-Content and Look and Feel on the website I wanted to make it easier for them to reference these two sections.
The best way I can think of doing this is appending the element-name (as in the DB) of the substituted text-block in an HTML-Comment after or before it starts.

So for every element there is in the display array i want to append its own index as HTML-Content after/before the element just before output.

I am mediocre good in PHP and semi-versatile in CI. I looked over the display and the fetch function, the Model Class, etc... but couldnt find a place i feel comfortable working this piece of code into.

What do you think of the idea itself and if its good, where could i implement this?
Thank you in advance,

Alex
#2

[eluser]atrioom[/eluser]
Okay, I figured where I could enventually put all this.

Beside the fetch() and the display() function I created the function append_comment() in
'tlib_page_data.php':

Code:
function append_comment($array = FALSE)
    {
        $CI =& get_instance();
        
        // If server is not test -> return unchanged
        if($CI->config->item('server_type') !== 'TEST' )
        {
            return $array;
        }
        
        // Define exclude rules
        $exclude = array('/^[^<].*[\w\d]+\/[\w\d]+.*[^>]$/');

        if($array === FALSE)
        {
            return false;
        }
        
        foreach($array as $key => $value)
        {
            foreach($exclude as $rule)
            {
                if(preg_match($rule, $value) !== 0)
                {
                    continue 2;
                }
            }
            
            if(is_array($value) === FALSE && strlen($value) >= 3 )
            {
                $array[$key] = "&lt;!-- $key START --&gt;".$value."&lt;!-- $key END --&gt;";
            }
        }
        
        return $array;
    }

append_comment() gets called within the display() function like this:

Code:
$this->tvar_query_data = $this->append_comment($this->tvar_query_data);
$page_links            = $this->append_comment($page_links);
$page_data             = $this->append_comment($page_data);
$CI->data_to_pass      = $this->append_comment($CI->data_to_pass);

With the exludes-array its possible to keep the script from destroying the stylesheet link for example. This is pure beta and still very buggy... I will have to play around with the excludes a lot to get this working, but it's a start...
#3

[eluser]atrioom[/eluser]
--- CLOSED ---




Theme © iAndrew 2016 - Forum software by © MyBB