Ejemplo n.º 1
0
$lang = 'en';
$r = node_set_contents($lang, $node_id, array($content_download, $content_file, $content_text, $content_infile));
dump($r);
$content_text['content_ignored'] = true;
$content_text['content_text_text'] = '<p>Un peu de \'texte\' qui est "très" intéressant ! ;)</p>';
$content_text['content_text_eval'] = true;
$lang = 'fr';
$r = node_set_contents($lang, $node_id, array($content_download, $content_file, $content_text, $content_infile));
dump($r);
$r = node_get_contents($lang, $node_id);
dump($r);
$content_id = $content_file['content_id'];
$content_type = $content_file['content_type'];
$r = node_delete_content($node_id, $content_id, $content_type);
dump($r);
$r = node_get_contents($lang, $node_id);
dump($r);
$text = 'Rien à dire de spécial LOL !';
$locale = 'fr';
$r = node_add_comment($node_id, 1, '192.168.1.2', $text, $locale);
dump($r);
$comment_id = $r;
$r = node_get_comment($node_id, $comment_id, $locale);
dump($r);
$text = 'Toujours rien à dire d\'intéressant LOL LOL !!!';
$r = node_set_comment($node_id, $comment_id, $text, $locale);
$r = node_get_comment($node_id, $comment_id, $locale);
dump($r);
$r = node_get_all_comments($node_id, $locale);
dump($r);
$r = node_delete_comment($node_id, $comment_id);
Ejemplo n.º 2
0
function nodecontent($lang, $node_id)
{
    $contents = array();
    $r = node_get_contents($lang, $node_id);
    if ($r) {
        foreach ($r as $c) {
            if ($c['content_ignored']) {
                continue;
            }
            $type = $c['content_type'];
            switch ($type) {
                case 'text':
                    $s = $c['content_text_text'];
                    if (!empty($s)) {
                        $eval = $c['content_text_eval'] == 1 ? true : false;
                        if ($eval) {
                            require_once 'seval.php';
                            $s = seval($s);
                        }
                        $text = $s;
                        $contents[] = compact('type', 'text');
                    }
                    break;
                case 'infile':
                    $infile = $c['content_infile_path'];
                    if ($infile) {
                        $contents[] = compact('type', 'infile');
                    }
                    break;
                case 'download':
                    $file = $c['content_download_name'];
                    if ($file) {
                        $download_url = url('download', $lang) . '/' . $node_id . '/' . urlencode($file);
                        $contents[] = compact('type', 'file', 'download_url');
                    }
                    break;
                case 'file':
                    $path = $c['content_file_path'];
                    $start = $c['content_file_start'];
                    $end = $c['content_file_end'];
                    $format = $c['content_file_format'];
                    $lineno = $c['content_file_lineno'] == 1 ? true : false;
                    if ($path) {
                        require_once 'prettyfile.php';
                        $file = pretty_file($path, $format, $start, $end, $lineno);
                        if ($file) {
                            head('stylesheet', 'geshi' . '/' . $format, 'screen');
                            $contents[] = compact('type', 'file', 'start', 'end', 'format', 'lineno');
                        }
                    }
                    break;
                case 'youtube':
                    $id = $c['content_youtube_id'];
                    $width = $c['content_youtube_width'];
                    $height = $c['content_youtube_height'];
                    $miniature = $c['content_youtube_miniature'];
                    $title = $c['content_youtube_title'];
                    $autoplay = $c['content_youtube_autoplay'];
                    $controls = $c['content_youtube_controls'];
                    $fs = $c['content_youtube_fs'];
                    $rel = $c['content_youtube_rel'];
                    $theme = $c['content_youtube_theme'];
                    if ($id and $width > 0 and $height > 0) {
                        $contents[] = compact('type', 'id', 'width', 'height', 'miniature', 'title', 'autoplay', 'theme', 'controls', 'fs', 'rel');
                    }
                    break;
                case 'longtail':
                    $file = $c['content_longtail_file'];
                    $image = $c['content_longtail_image'];
                    $width = $c['content_longtail_width'];
                    $height = $c['content_longtail_height'];
                    $icons = $c['content_longtail_icons'];
                    $skin = $c['content_longtail_skin'];
                    $controlbar = $c['content_longtail_controlbar'];
                    $duration = $c['content_longtail_duration'];
                    $autostart = $c['content_longtail_autostart'] == 1 ? true : false;
                    $repeat = $c['content_longtail_repeat'] == 1 ? true : false;
                    if ($file) {
                        head('javascript', 'jwplayer');
                        $contents[] = compact('type', 'file', 'image', 'width', 'height', 'icons', 'skin', 'controlbar', 'duration', 'autostart', 'repeat');
                    }
                    break;
                default:
                    break;
            }
        }
    }
    $output = view('nodecontent', false, compact('contents'));
    return $output;
}
Ejemplo n.º 3
0
function nodecontenteditor($lang, $clang, $node_id, $content_types)
{
    global $contents_model;
    $action = 'init';
    if (isset($_POST['content_modify'])) {
        $action = 'modify';
    } else {
        if (isset($_POST['content_create'])) {
            $action = 'create';
        } else {
            if (isset($_POST['content_delete'])) {
                $action = 'delete';
            }
        }
    }
    $new_content_type = $new_content_number = false;
    $old_content_number = false;
    $node_contents = false;
    $id = false;
    $p = false;
    switch ($action) {
        case 'init':
        case 'reset':
            $r = node_get_contents($clang, $node_id);
            if ($r) {
                $pos = 1;
                $node_contents = array();
                foreach ($r as $c) {
                    $c['content_pos'] = $c['content_number'];
                    $node_contents[$pos] = $c;
                    $pos++;
                }
            }
            break;
        case 'modify':
        case 'create':
        case 'delete':
            if (isset($_POST['content_new_type'])) {
                $new_content_type = readarg($_POST['content_new_type']);
            }
            if (isset($_POST['content_new_number'])) {
                $new_content_number = readarg($_POST['content_new_number']);
            }
            if (isset($_POST['content_old_number'])) {
                $old_content_number = readarg($_POST['content_old_number']);
            }
            if (isset($_POST['content_id'])) {
                $id = $_POST['content_id'];
                // DON'T readarg!
            }
            if (isset($_POST['content_p'])) {
                $p = $_POST['content_p'];
                // DON'T readarg!
            }
            if (isset($_POST['content_ignored'])) {
                $ignored = $_POST['content_ignored'];
                // DON'T readarg!
            }
            break;
        default:
            break;
    }
    $bad_contents = false;
    switch ($action) {
        case 'create':
        case 'delete':
        case 'modify':
            if (!$id or !$p and !(is_array($id) and is_array($p) and count($id) == count($p))) {
                $bad_contents = true;
            } else {
                foreach ($id as $i => $v) {
                    if (!is_numeric($v) or !(isset($p[$i]) and is_numeric($p[$i]))) {
                        $bad_contents = true;
                        break;
                    }
                }
            }
            if ($bad_contents) {
                break;
            }
            $node_contents = array();
            foreach ($contents_model as $type => $fields) {
                foreach ($fields as $fname => $props) {
                    $fieldname = "content_{$type}_{$fname}";
                    if (isset($_POST[$fieldname]) and is_array($_POST[$fieldname])) {
                        foreach ($_POST[$fieldname] as $i => $value) {
                            $v = readarg($value, true, false);
                            // trim but DON'T strip_tags!
                            if (!isset($node_contents[$i])) {
                                $content_ignored = isset($ignored[$i]) && $ignored[$i] == 'on';
                                $node_contents[$i] = array('content_id' => $id[$i], 'content_pos' => $p[$i], 'content_ignored' => $content_ignored, 'content_type' => $type, $fieldname => $v);
                            } else {
                                $node_contents[$i][$fieldname] = $v;
                            }
                        }
                    }
                }
            }
            if (!$node_contents) {
                $bad_contents = true;
                break;
            }
            ksort($node_contents);
            break;
        default:
            break;
    }
    $missing_new_content_type = false;
    $bad_new_content_type = false;
    $bad_new_content_number = false;
    $missing_old_content_number = false;
    $bad_old_content_number = false;
    switch ($action) {
        case 'create':
            if (empty($new_content_type)) {
                $missing_new_content_type = true;
            } else {
                if (!$content_types or !in_array($new_content_type, $content_types)) {
                    $bad_new_content_type = true;
                }
            }
            if (empty($new_content_number)) {
                $new_content_number = false;
            } else {
                if (!is_numeric($new_content_number)) {
                    $bad_new_content_number = true;
                } else {
                    if ($new_content_number < 1) {
                        $bad_new_content_number = true;
                    } else {
                        if ($new_content_number > count($node_contents)) {
                            $new_content_number = false;
                        }
                    }
                }
            }
            break;
        case 'delete':
            if (empty($old_content_number)) {
                $missing_old_content_number = true;
            } else {
                if (!is_numeric($old_content_number)) {
                    $bad_old_content_number = true;
                } else {
                    if ($old_content_number < 1 or $old_content_number > count($node_contents)) {
                        $bad_old_content_number = true;
                    }
                }
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'create':
            if ($missing_new_content_type or $bad_new_content_type or $bad_new_content_number) {
                break;
            }
            $nc = node_create_content($clang, $node_id, $new_content_type, $new_content_number);
            if (!$nc) {
                break;
            }
            $content_id = $nc['content_id'];
            $content_pos = $nc['content_number'];
            $content_type = $new_content_type;
            $content_ignored = false;
            $fields = compact('content_pos', 'content_id', 'content_type', 'content_ignored');
            foreach ($contents_model[$content_type] as $fname => $props) {
                $fieldname = "content_{$content_type}_{$fname}";
                $fields[$fieldname] = isset($props['default']) ? $props['default'] : false;
            }
            if ($node_contents) {
                foreach ($node_contents as &$c) {
                    if ($c['content_pos'] >= $content_pos) {
                        $c['content_pos']++;
                    }
                }
                array_splice($node_contents, $content_pos - 1, 0, array($fields));
            } else {
                $content_pos = 1;
                $node_contents = array($content_pos => $fields);
            }
            if ($new_content_number) {
                $new_content_number++;
            }
            $new_content_type = false;
            break;
        case 'delete':
            if ($missing_old_content_number or $bad_old_content_number) {
                break;
            }
            $c = $node_contents[$old_content_number];
            $content_id = $c['content_id'];
            $content_type = $c['content_type'];
            $r = node_delete_content($node_id, $content_id, $content_type);
            if (!$r) {
                break;
            }
            unset($node_contents[$old_content_number]);
            $node_contents = array_values($node_contents);
            foreach ($node_contents as &$c) {
                if ($c['content_pos'] >= $old_content_number) {
                    $c['content_pos']--;
                }
            }
            $old_content_number = false;
            break;
        case 'modify':
            if ($bad_contents) {
                break;
            }
            $neworder = range(1, count($p));
            array_multisort($p, SORT_NUMERIC, $neworder);
            $number = 1;
            $nc = array();
            foreach ($neworder as $i) {
                $c =& $node_contents[$i];
                $c['content_pos'] = $number;
                $nc[$number++] = $c;
            }
            $node_contents = $nc;
            $r = node_set_contents($clang, $node_id, $node_contents);
            if (!$r) {
                break;
            }
            break;
        default:
            break;
    }
    $errors = compact('missing_new_content_type', 'bad_new_content_type', 'bad_new_content_number', 'missing_old_content_number', 'bad_old_content_number');
    $output = view('editing/nodecontenteditor', $lang, compact('clang', 'content_types', 'new_content_type', 'new_content_number', 'old_content_number', 'node_contents', 'errors'));
    return $output;
}