Revision [4529]

This is an old revision of ProgrammingHelp made by JavaWoman on 2005-01-12 15:39:53.

 

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



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;
}


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


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