Revision [4790]

This is an old revision of ProgrammingHelp made by DaveBradshaw on 2005-01-17 22:42:32.

 

Programming Help


 


Many people work at developing various aspects of code for wikka and yet we often struggle for hours, or even days, to solve programming problems that others in the wikka community know the answer to. Even more of an issue, sometimes coding problems aren't rectified until after initial code releases and feedback from other members lead to new code being posted (which means that the old code might now be running on others' wikka implementations) because the initial developer could not figure out how to solve a problem. To reduce these problems, this page is intended for people to be able to pose programming issues they've encountered and have the opportunity to draw on the knowledge of others' in our community as to how to resolve those issues. There are two sections...."Issues Needing assistance" & "Solved Issues". When a user has either solved an issue on their own that they've posted, or received help on the issue that satisfactorily addresses it, then the solution should be posted and it should be moved from the first to the second category.

Issues Needing Assistance


ShowCsv
I haven't tried out much, but since the content of the *.csv file is put into the hmtl-code of the page, it is possible to enter own code through the file (html is possible and php/javscript perhaps). I am not sure if the output of actions runs through safehtml. If not, would that be the best solution for the problem? Or find and replace of every < and >? --NilsLindenberg

2 Dimensional Array Sort
another issue: is it possible to sort an array[x][y] the following way: you choose an [y] after which the [x] are sorted? --NilsLindenberg


Resolved Issues


Replace
How would you replace every 2nd occurence of a "needle" in a haystack string? I'm sure you can see where I'm going with this, I want to parse output from a table read so that **'s and //'s are replaced alternately with and etc in a string so I can minimally format table content in the output tales in the forum and calendar actions after stripping out html on the way "in" to the database (both of which pick up on what other wikkausers suggested as desireable features for them). I've searched everywhere on this & spent ages on it and have found bupkuss. Thanks for any guidance. -- GmBowen
Finding a function that replaces only the first occurence in the string led me to the solution. I've coded 3 functions that can be included to turn bold & italics wikka code into html tags for output into a table (such as in my scheduler & wikka forum). Code below....
function str_replace_once($needle, $replace, $haystack) {
   // Looks for the first occurence of $needle in $haystack
   // and replaces it with $replace.
   $pos = strpos($haystack, $needle);
   if ($pos === false) {
       // Nothing found
       return $haystack;
   }
   return substr_replace($haystack, $replace, $pos, strlen($needle));
}

function bold_formatting_replace($haystack) {
    //replaces bold wikka formatting (**) with html bold tags
    $needle="**";
    $count=(int)(substr_count($haystack, $needle)/2);
    $replace="<strong>";
    $replace2="</strong>";
    while ($counter<$count)
    {
        $counter++;
        $haystack=str_replace_once($needle, $replace2, str_replace_once($needle, $replace, $haystack));
    }
    return $haystack;
}

function italics_formatting_replace($haystack) {
    //replaces italics wikka formatting (//) with html italics tags
    $needle="//";
    $count=(int)(substr_count($haystack, $needle)/2);
    $replace="<em>";
    $replace2="</em>";
    while ($counter<$count)
    {
        $counter++;
        $haystack=str_replace_once($needle, $replace2, str_replace_once($needle, $replace, $haystack));
    }
    return $haystack;
}

Okay, I came up with the following to go into Show_SForum_Threads function....it strips out header code etc, and converts }} and {{ to |.| (I wanted to de-activate action code, but not use ||)
                $printtext = (stripslashes($row['for_text']));
        $brackets = Array ('/{{/i', '/}}/i');
        $changeto = '|.|';
        $printtext = preg_replace($brackets, $changeto, $printtext);
        $remove = array('#%', '======', '=====', '====', '===', '==', '[[', ']]', '||', '% %', '&lt;&lt;', '&gt;&gt;', '::c::', '&quot;&quot;');
        $printtext = str_replace($remove, '', $printtext);
        $printtext = $wakka->format($printtext);

(except for the spaces between the percent signs)

Multiple copies of actions
Not being able to put multiple copies of an action on a page. Can be caused by multiple copies of the same functions being loaded. Solution: have the functions "included" from a separate file using include_once() which stops repeated loading of the functions. Example where implemented: WikkaForum

Only single copies of generated images on a wikka page
In developing my WikkaGrapher action I have it both generating an image and wikka code (that calls an action) that can be placed on a page to place the graph on the page. The action is below (saved as graph.php) and examples of the code are at http://gmbowen.educ.unb.ca/wiki/wakka.php?wakka=Sandbox5 (the code generating interface is at SandBox6). Only the code for the first image is processed for some reason (as can be seen at Sandbox5). Not surprisingly, I'd like users to be able to place more than one graph on a page. Ideas? The graphing engine is at http://www.phpclasses.org/browse/package/1993.html.
<?php
echo '<img src="./scripts/graphmaker.php?'.$code.'><br \>';
?>



Unresolvable Issues


Double-Click Edit
Is there any way to insert code into an action that disables the double-click editing on a page? I thought I saw something on this site but cannot find it anymore.
Rats. I was hoping for a workaround. - m

Not tried this but if you where to change the ondbclick event to a call function, say dbClickEdit(), instead of inlining the javascript code. You could then create an action to null the function.

 <script language="javascript">
	dbClickEdit = function () {} 
</script> 

Bit of a nasty polymorphic hack mind you. The other option would be to create a JS object to handle the event, and the action could then set a property to turn the event off.

var dbClickEdit = new Object();

dbClickEdit.enabled = true;

dbClickEdit.clicked = function()
{
	  if (this.enabled) location.href=location.href+'/edit';
}

--DaveBradshaw


CategoryUserContributions
There are 5 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki