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


RegExp Help
Based on the discussion on ValidPageNames, I wanted to use JavaWoman's suggestion for a robust RegExp, but I cannot get it to work:

<?php
define('LCLETTER', 'a-z\xe0-\xf6\xf8-\xff');
define('UCLETTER', 'A-Z\xc0-\xd6\xd8-\xdf');
define('LETTERS', LCLETTER.UCLETTER);
define('DIGITS', '0-9');
define('ALLCHARS', LETTERS.DIGITS);

function IsWikiName($text) {
    $pattern = '/^['.UCLETTER.']['.LCLETTER.']+['.UCLETTER.DIGITS.']['.ALLCHARS.']*$/';
    return preg_match($pattern, $text);
}

$x = "ThisTest";
if (IsWikiName($x)) {print("<p>YES!</p>");}
else {print("<p>NO!</p>");}

$y = "ThisÜbertest";
if (IsWikiName($y)) {print("<p>YES!</p>");}
else {print("<p>NO!</p>");}
?>


This should be YES YES output but it outputs YES NO. Using PHP 5.03 and Apache 2.0.52 serving as UTF-8 by default. Any ideas what is wrong here? --IanAndolina
" When you manipulate (trim, split, splice, etc.) strings encoded in a multibyte encoding, you need to use special functions since two or more consecutive bytes may represent a single character in such encoding schemes. Otherwise, if you apply a non-multibyte-aware string function to the string, it probably fails to detect the beginning or ending of the multibyte character and ends up with a corrupted garbage string that most likely loses its original meaning."


Can anyone tell me how I can write a hyperlink in an Action which includes (dynamically) the wikka page id.
The hyperlink has to look something like this
http://www.mysite.co.uk/fpdf/wikka_pdf.php?id= Link Name
where ?id=page_id
This is similar to the WikkaMenulets code. I just don't know how to echo the page_id
--JamesMcl

Embedding decoded image into wikka

If I open the following script directly (as a file) it shows a small "you've got mail" sort of image. But, if I "call it" as an action in wikka it just shows the raw GIF89a image code content. What do I need to do to show the image on the wiki page calling the file as an action? Thanks.
<?
echo base64_decode(
'R0lGODlhHAASALMPAP+qKv+/v/yOkc6c//40LWRmYv8MA87//2'.
'MAnM7O/83NzQ8MZP/MM5mZmf///wAAACH5BAEAAA8ALAAAAAAc'.
'ABIAAASv8MlJq71W4M3NK0gojiRSTEIgCUazFMohz/S8IFNgEA'.
'HhL4OFwkEsGhWLA25CMDgBhkUiODQWkQklRccAdKUOqtWhKCQc'.
'2lXTy2CAw8KjmZh2EtjtN7xaPtOXDwJrbW5+DgVUfQVFaRJcXg'.
'Bvi3BzDgt/FE1PUWeTRAOGlmiAOjw+BFKVY0UFjSkrBgIvCbS1'.
'trYgGC0FC72+v8AvGAoNxcbHyMYbCszNzs/OHNIcEQA7'.
'');
?>


Spam repair and defense
Copied from RichardBerg hoping it might get more exposure here -- JavaWoman
(Moved to WikkaSpamFighting now (where all Spam-related issues are being gathered) - I realise it's asking for help, but we'll need to have facilities like these in Wikka!)

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

Moving Java Variables to PHP
That's a pretty weak description, but it's the best I've got. I'm beginning to play with adapting Tom's Corkboard so that it'll work in wikka as a brainstorming/project development tool. Ultimately, if the problem here is solvable, it'll be usable to enter series (and threads) of notes that you can move around and locate near other related ones...or filter by color, box outline, or word search. The problem I'm trying to address (seen here) is that I can move around the boxes (at this point IE only, although I hear there's other drag & drop code around that'll work w/ firefox, but I couldn't find it anywhere...ideas?) but cannot see a way of "obtaining" the new top corner x,y coordinates....does anybody know of any way to do this? (when I look at the source code, no matter where the tables are, the x-y coordinates haven't changed) When I figure THAT out then I'll want to figure out how to write them to the database so that clusterings of the boxes is permanent...again, ideas? Thanks. -- GmBowen



Resolved Issues


regexp
I want to replace the following :// but can't find a regexp doing this :( --NilsLindenberg

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

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 \>';
?>


Parsing Dates
Is there a simple way to parse a data string in the database that is structured like this...."20050128002912"....so that is shows "January 28, 2005. 00:29" ? I've tried all sorts of things with no success. I've tried parsing the line using the following....
  $mysqltime=$row[SentDate];
  $hour = substr($mysqltime, 8, 2)*1;
  if (strlen($hour)==1) {$hour="0".$hour;}
  $min = substr($mysqltime, 10, 2)*1;
  if (strlen($min)==1) {$min="0".$min;}
  $sec = substr($mysqltime, 12, 2)*1;
  if (strlen($sec)==1) {$sec="0".$sec;}
  $month = substr($mysqltime, 4, 2)*1;
  $day = substr($mysqltime, 6, 2)*1;
  $year = substr($mysqltime, 0, 4);
  $datetime=$hour.":".$min.":".$sec."&nbsp;&nbsp;".$month."-".$day."-".$year;
  echo $datetime;

Is this the best way of doing this? It seems awfully server intensive. Ideas? -- GmBowen

Designing mass action
To realize the ACL mass-action, in the page admin tool, I have two possible solutions. First after choice the ACL action in the combobox, I can open a small form under the combo box, to add the needed data. Or Second I open a new page to enter the needed Data and after that than comes the action for the before selected pages. What do you prefer? --AndreasTengicki


Unresolvable Issues


Javascript Help
I know v. little about using javascript, but thought that the following code snippet might be a useful addition to one of my wiki's (making it easy to increase/decrease font size) in the header....but I can't get it to work. (I snitched the code from here.) Any ideas? I keep getting "error on page" when I stick it in the header.php file. Thanks. --GmBowen

<a href="javascript:cF(-1,0);" class="uImg" title="decrease body text to the default size"><img src="http://z.about.com/f/bt/tfm.gif" alt="decrease font size" border="0" /></a> <a href="javascript:cF(1,0);" class="uImg" title="increase body text to the largest size" ><img src="http://z.about.com/f/bt/tfp.gif" alt="increase font size" border="0" /></a>


Embedding HTML for VML successfully in Wikka?

Although I KNOW this is for IE only (and thus many of you can't help me), I came across this open source drawing package that works nicely (see http://www.foundmyself.com/paintboard/editor.php) and which generates html code that you can use to re-create the image....as an example....
<html>
<head>

<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>
<style type="text/css">
v\:* { behavior: url(#default#VML);}
</style>

</head>
<body>

<?xml:namespace prefix = v /><v:shape id=nr1 style="LEFT: 0px; WIDTH: 803px; POSITION: absolute; TOP: 0px; HEIGHT: 563px" coordsize = "803,563" filled = "f" strokecolor = "black" strokeweight = "8.25pt" path = " m204,221 l204,221,188,230,189,232,196,238,207,247,221,259,242,275,267,294,292,313,313,331,334,347,342,358,350,369,361,378,373,387,386,393,398,396,406,397,415,397,422,395 429,391,434,387,438,382,442,376,444,369,445,361,447,352,448,342,449,333,450,325,453,316,455,309,459,303,465,298,471,294,480,291,488,288,497,286,506,284,514,284 521,284,526,284,527,284,528,284,529,284,529,283,529,281,529,276,528,271,526,265,523,258,522,251,522,244,523,237,528,230,534,225,542,220,552,216,564,215,576,215 588,216,599,217,610,223,621,228,630,236,641,246,649,255,656,266,659,274,662,282,663,286,663,287,663,286,663,285,663,279,662,270,659,258,656,246,652,234,647,222 639,208,630,197,619,186,605,174,588,164,573,157,553,149,529,144,504,141,476,139,455,139,437,140,421,144,408,150,397,155,388,162,380,171,374,179,367,186,362,194 356,203,349,212,342,221,334,231,325,240,314,248,309,256,303,261,291,266,274,270,253,272,228,275,200,277,176,277,157,278,141,281,127,284,115,286,106,290,96,294 87,299,79,304,72,309,66,314,60,318,58,318,54,320,53,321,51,320,49,316,48,309,48,299,51,287,56,272,63,254,75,234,87,214,100,194,115,176,126,163 136,152,145,144,153,138,157,136,159,137,163,140,166,146,170,153,172,163,175,175,176,189,176,202,176,215,176,229,176,242,176,253,176,262,178,272,179,281,180,288 183,295,186,302,188,308,192,314,194,318,196,324,200,329,201,335,203,342,206,348,209,353,214,361,220,369,230,375,242,382,257,389,277,395,285,398,309,404,345,411 383,413,418,414,446,416,468,418,478,418,486,418,487,418,488,418,489,418,489,417,490,417 e"><v:path></v:path><v:fill></v:fill><v:stroke></v:stroke></v:shape>
</body>
</html>

I thought if I just escaped it it might embed images in wikka, but no luck (including removing the body/html stuff). Anybody have any ideas on whether/if/how to embed this code into wikka so it would show up (of course, knowing this will only work in IE). --GmBowen
    1. (Optionally) translate your VML to the standard SVG (that will ensure wider though not complete browser support)
    1. Make sure it's embedded according to the rules of XML (the SVG standard gives good examples); this also entails changing the header.php in Wikka (currently misplaced in actions) to define the namespace to be used by the embedded language in the html element
    1. Research the language (completely) to determine what security risks there might be - similar to what Roman Ivanov has done for us all with respect to HTML (+ JavaScript)
    1. Extend the SafeHTML class to teach it about the embedded language and its security risks (do not change it - extend it so you don't have to do it all over again when a new version of SafeHTML comes out)

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