コード例 #1
0
ファイル: common.php プロジェクト: uakfdotb/oneapp
function page_convert($str)
{
    $config = $GLOBALS['config'];
    //see if style provides this function
    $styleFunction = style_function("page_convert");
    if ($styleFunction !== FALSE) {
        return $styleFunction($str);
    }
    $str = htmlentities($str);
    $bbcode = array('[color="', "[/color]", "[size=\"", "[/size]", "[quote]", "[/quote]", '"]');
    $htmlcode = array("<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">');
    $str = str_replace($bbcode, $htmlcode, $str);
    $str = str_replace("[p]", "<p>", $str);
    $str = str_replace("[/p]", "</p>", $str);
    $str = str_replace("\r", "", $str);
    $str = str_replace("[br]", "<br>", $str);
    $str = str_replace("[b]", "<b>", $str);
    $str = str_replace("[/b]", "</b>", $str);
    $str = str_replace("[h1]", "<h1>", $str);
    $str = str_replace("[/h1]", "</h1>", $str);
    $str = str_replace("[h2]", "<h2>", $str);
    $str = str_replace("[/h2]", "</h2>", $str);
    $str = str_replace("[h3]", "<h3>", $str);
    $str = str_replace("[/h3]", "</h3>", $str);
    $str = str_replace("[h4]", "<h4>", $str);
    $str = str_replace("[/h4]", "</h4>", $str);
    $str = str_replace("[table]", "<table>", $str);
    $str = str_replace("[/table]", "</table>", $str);
    $str = str_replace("[tr]", "<tr>", $str);
    $str = str_replace("[/tr]", "</tr>", $str);
    $str = str_replace("[td]", "<td>", $str);
    $str = str_replace("[/td]", "</td>", $str);
    $str = str_replace("[th]", "<th>", $str);
    $str = str_replace("[/th]", "</th>", $str);
    $str = str_replace("[strong]", "<strong>", $str);
    $str = str_replace("[/strong]", "</strong>", $str);
    $str = preg_replace('@\\[(?i)image\\]\\s*(.*?)\\[/(?i)image\\]@si', '<img src="\\1">', $str);
    $str = preg_replace('@\\[(?i)url=\\s*(.*?)\\]\\s*(.*?)\\[/(?i)url\\]@si', '<a href="\\1" target="_blank">\\2</a>', $str);
    $str = str_replace("[u]", "<u>", $str);
    $str = str_replace("[/u]", "</u>", $str);
    $str = str_replace("[i]", "<i>", $str);
    $str = str_replace("[/i]", "</i>", $str);
    $str = str_replace("[hr]", "<hr>", $str);
    $str = str_replace('$site_name$', $config['site_name'], $str);
    //now add linebreaks if the user didn't add them manually
    // before we add them we delete all linebreaks that we don't need
    $str = str_replace(">\n<", "><", $str);
    $str = str_replace(">\n\n<", "><", $str);
    // now just replace
    $str = str_replace("\n", "<br>", $str);
    return $str;
}
コード例 #2
0
ファイル: apply_gen.php プロジェクト: uakfdotb/oneapp
function writeField($id, $answer_id, $name, $desc, $type, $answer = "", $mutable = true, $repeat_id = 256)
{
    //see if style provides this function
    $styleFunction = style_function("writeField");
    if ($styleFunction !== FALSE) {
        return $styleFunction($str);
    }
    $mutableString = "";
    if (!$mutable) {
        $mutableString = "readonly=\"readonly\"";
    }
    //trim the string fields
    $name = trim($name);
    $desc = trim($desc);
    $type = trim($type);
    $fieldName = "a_" . $id . "_" . $answer_id . "_" . $repeat_id;
    $type_array = getTypeArray($type);
    $maxLength = $type_array['length'];
    $lengthRemaining = $maxLength - strlen($answer);
    if ($type_array['type'] == "essay") {
        $height = "";
        if ($type_array['size'] == "large") {
            $height = "height:200px";
        } else {
            if ($type_array['size'] == "huge") {
                $height = "height:400px";
            }
        }
        echo '<label for="">';
        if ($type_array['status'] != "optional") {
            echo "<em>*</em>";
        }
        echo "{$name}</label>";
        echo "<textarea ";
        if ($type_array['showchars']) {
            echo "onKeyDown=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" ";
            echo "onKeyUp=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" ";
        }
        echo "name=\"{$fieldName}\" {$mutableString} style=\"resize:vertical;{$height}\" />" . htmlspecialchars($answer) . "</textarea>";
        echo "<p class=\"formHint\">{$desc}";
        if ($type_array['showchars']) {
            echo "<br />Characters Remaining: <input type=\"text\" name=\"countdown{$fieldName}\" style=\"background-color:none;border:solid 1px #FFFFFF;font-size:10px;max-width:50px;color:#71777D\" value=\"{$lengthRemaining}\" readonly=\"readonly\" class=\"changeBackground\" />";
        }
        echo "</p>";
    } else {
        if ($type_array['type'] == "short") {
            echo '<label for="">';
            if ($type_array['status'] != "optional") {
                echo "<em>*</em>";
            }
            echo "{$name}</label>";
            echo "<input ";
            if ($type_array['showchars']) {
                echo "onKeyDown=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" ";
                echo "onKeyUp=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" maxlength=\"{$maxLength}\" ";
            }
            echo "type=\"text\" name=\"{$fieldName}\" {$mutableString} value=\"" . htmlspecialchars($answer) . "\" /> ";
            echo "<p class=\"formHint\">{$desc}";
            if ($type_array['showchars']) {
                echo "<br />Characters remaining: <input type=\"text\" name=\"countdown{$fieldName}\" style=\"background-color:none;border:solid 1px #FFFFFF;font-size:10px;max-width:50px;color:#71777D\" value=\"{$lengthRemaining}\" readonly=\"readonly\" class=\"changeBackground\" />";
            }
            echo "</p>";
        } else {
            if ($type_array['type'] == "select") {
                echo '<p class="label">';
                if ($type_array['status'] != "optional") {
                    echo "<em>*</em>";
                }
                echo "{$name}</p>";
                $choices = explode(";", $desc);
                $tname = "checkbox";
                if ($type_array['method'] == "multiple") {
                    $tname = "checkbox";
                    $fieldName .= "[]";
                    //for multiple selection, PHP needs to know with an [] at the end of field name
                    echo "<ul>";
                } else {
                    if ($type_array['method'] == "single") {
                        $tname = "radio";
                        echo "<ul>";
                    } else {
                        if ($type_array['method'] == "dropdown") {
                            $tname = false;
                            echo "<select name=\"{$fieldName}\"{$mutableString}>";
                        }
                    }
                }
                //for checkboxes, answer will be an array separated by $config['form_array_delimiter']
                // we just explode it anyway for convenience and get one element if it's single selection
                $config = $GLOBALS['config'];
                $answerArray = explode($config['form_array_delimiter'], $answer);
                foreach ($choices as $choice) {
                    $selectedString = "";
                    if (in_array($choice, $answerArray)) {
                        if ($tname === false) {
                            $selectedString = " selected";
                        } else {
                            $selectedString = " checked";
                        }
                    }
                    if ($tname == false) {
                        echo "<option{$selectedString} value=\"{$choice}\">{$choice}</option>";
                    } else {
                        echo "<li><label for=\"\"><input{$selectedString} type=\"{$tname}\" name=\"{$fieldName}\"{$mutableString} value=\"{$choice}\" /> {$choice}</label></li>";
                    }
                }
                if ($tname == false) {
                    //select
                    echo "</select>";
                } else {
                    echo "</ul>";
                }
                //need to add some sort of hint factor for selects (change hint so that it is a type variable)
            } else {
                if ($type_array['type'] == "text") {
                    echo '<label for="">';
                    if ($type_array['status'] != "optional") {
                        echo "<em>*</em>";
                    }
                    echo "{$name}</label>{$desc}";
                } else {
                    if ($type_array['type'] == "repeat") {
                        $num = $type_array['num'];
                        $subtype_array = explode("|", $type_array['subtype']);
                        $desc_array = explode("|", $desc);
                        $name_array = explode("|", $name);
                        if ($answer != '') {
                            $answer_array = toArray($answer, "|", "=");
                        } else {
                            $answer_array = array_fill(0, count($name_array) * $num, '');
                        }
                        //find minimum length, which will be the number to repeat for
                        $min_length = min(count($subtype_array), count($desc_array), count($name_array));
                        for ($i = 0; $i < $min_length * $num; $i++) {
                            $index = $i % $min_length;
                            $n = intval($i / $min_length);
                            $thisName = getRepeatThisValue($name_array, $index, $n);
                            $thisDesc = getRepeatThisValue($desc_array, $index, $n);
                            $thisType = str_replace(",", ";", getRepeatThisValue($subtype_array, $index, $n));
                            if ($type_array['globalstatus'] == 1) {
                                $thisType .= "; status:optional";
                            }
                            writeField($id, $answer_id, $thisName, $thisDesc, $thisType, $answer_array[$i], $mutable, $i);
                        }
                    } else {
                        if ($type_array['type'] == "code") {
                            echo page_convert($desc);
                        } else {
                            if ($type_array['type'] == "upload") {
                                echo '<label for="">';
                                if ($type_array['status'] != "optional") {
                                    echo "<em>*</em>";
                                }
                                echo "{$name}</label>";
                                echo "<input type=\"file\" name=\"{$fieldName}\" {$mutableString} />";
                                echo "<p class=\"formHint\">{$desc}<br />Currently Uploaded: ";
                                if ($answer != "") {
                                    $answer_parts = explode(":", $answer, 3);
                                    $file_id = $answer_parts[1];
                                    $file_name = $answer_parts[2];
                                    echo "<a href=\"../download.php?file={$file_id}&filename={$file_name}\">View Here</a>";
                                } else {
                                    echo "None";
                                }
                                echo '</p>';
                            }
                        }
                    }
                }
            }
        }
    }
}