Exemplo n.º 1
0
/**
 * validates the config form output, fills in any gaps by using the defaults,
 * and ensures that arrayed items are stored as such
 */
function config_ValidateSettings($in)
{
    //DebugEcho("config_ValidateSettings");
    $out = array();
    //DebugDump($in);
    // use the default as a template:
    // if a field is present in the defaults, we want to store it; otherwise we discard it
    $allowed_keys = config_GetDefaults();
    foreach ($allowed_keys as $key => $default) {
        if (is_array($in)) {
            $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default;
        } else {
            $out[$key] = $default;
        }
    }
    // some fields are always forced to lower case:
    $lowercase = array('authorized_addresses', 'smtp', 'supported_file_types', 'video1types', 'video2types', 'audiotypes');
    foreach ($lowercase as $field) {
        $out[$field] = is_array($out[$field]) ? array_map("strtolower", $out[$field]) : strtolower($out[$field]);
    }
    $arrays = config_ArrayedSettings();
    foreach ($arrays as $sep => $fields) {
        foreach ($fields as $field) {
            if (!is_array($out[$field])) {
                $out[$field] = explode($sep, trim($out[$field]));
            }
            foreach ($out[$field] as $key => $val) {
                $tst = trim($val);
                if (empty($tst)) {
                    unset($out[$field][$key]);
                } else {
                    $out[$field][$key] = $tst;
                }
            }
        }
    }
    config_Update($out);
    return $out;
}
Exemplo n.º 2
0
function activate_postie()
{
    static $init = false;
    $options = config_Read();
    if ($init) {
        return;
    }
    if (!$options) {
        $options = array();
    }
    $default_options = config_GetDefaults();
    $old_config = array();
    $result = config_GetOld();
    if (is_array($result)) {
        foreach ($result as $key => $val) {
            $old_config[strtolower($key)] = $val;
        }
    }
    // overlay the options on top of each other:
    // the current value of $options takes priority over the $old_config, which takes priority over the $default_options
    $options = array_merge($default_options, $old_config, $options);
    $options = config_ValidateSettings($options);
    update_option('postie-settings', $options);
    $init = true;
}
Exemplo n.º 3
0
 public function testReplaceImagePlaceHolders()
 {
     $c = "";
     $config = config_GetDefaults();
     $config['allow_html_in_body'] = true;
     $attachements = array("image.jpg" => '<img title="{CAPTION}" />');
     filter_ReplaceImagePlaceHolders($c, array(), $config);
     $this->assertEquals("", $c);
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('<img title="" />', $c);
     $c = "#img1#";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('<img title="" />', $c);
     $c = "test #img1# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="" /> test', $c);
     $c = "test #img1 caption='1'# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="1" /> test', $c);
     $c = "test #img1 caption=# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="" /> test', $c);
     $c = "test #img1 caption=1# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="1" /> test', $c);
     $c = "test #img1 caption='! @ % ^ & * ( ) ~ \"Test\"'# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="! @ % ^ &amp; * ( ) ~ &quot;Test&quot;" /> test', $c);
     $c = "test <div>#img1 caption=&#39;! @ % ^ &amp; * ( ) ~ &quot;Test&quot;&#39;#</div> test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <div><img title="&amp;" />39;! @ % ^ &amp; * ( ) ~ &quot;Test&quot;&#39;#</div> test', $c);
     $c = "test #img1 caption=\"I'd like some cheese.\"# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="I&#039;d like some cheese." /> test', $c);
     $c = "test #img1 caption=\"Eiskernbrecher mögens laut\"# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="Eiskernbrecher mögens laut" /> test', $c);
     $c = "test #img1 caption='[image-caption]'# test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="[image-caption]" /> test', $c);
     $c = "test #img1 caption='1'# test #img2 caption='2'#";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals('test <img title="1" /> test #img2 caption=\'2\'#', $c);
     $attachements = array("image1.jpg" => 'template with {CAPTION}', "image2.jpg" => 'template with {CAPTION}');
     $c = "test #img1 caption='1'# test #img2 caption='2'#";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals("test template with 1 test template with 2", $c);
     $config['auto_gallery'] = true;
     $config['images_append'] = false;
     $c = "test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals("[gallery]\ntest", $c);
     $config['images_append'] = true;
     $c = "test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals("test\n[gallery]", $c);
     $config['images_append'] = true;
     $c = "test";
     filter_ReplaceImagePlaceHolders($c, $attachements, $config);
     $this->assertEquals("test\n[gallery]", $c);
     $c = "test";
     filter_ReplaceImagePlaceHolders($c, array(), $config);
     $this->assertEquals("test", $c);
 }
Exemplo n.º 4
0
 public function test_Remove_signature()
 {
     $config = config_GetDefaults();
     $c = "";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("", $c);
     $c = "test";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("test", $c);
     $c = "";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("", $c);
     $c = "test";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("test", $c);
     $c = "line 1\nline 2\n--\nsig line 1\nsig line 2";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("line 1\nline 2\n", $c);
     $c = "line 1\nline 2\n---\nsig line 1\nsig line 2";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("line 1\nline 2\n", $c);
     $c = "line 1\nline 2\n-- \nsig line 1\nsig line 2";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("line 1\nline 2\n", $c);
     $c = "line 1\nline 2\n--\nsig line 1\nsig line 2";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("line 1\nline 2\n", $c);
     $c = "line 1\nline 2\n--";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("line 1\nline 2\n", $c);
     $c = "test content<div><br></div><div>--</div><div>signature</div>";
     filter_RemoveSignature($c, $config);
     $this->assertEquals("test content<div><br></div>", $c);
 }