function parse_csv($data)
{
    $data = str_replace("\r", '', $data);
    $lines = csv_explode("\n", $data, "\"");
    $csv_lines = array();
    foreach ($lines as $line) {
        if (trim(trim($line, chr(0xc2) . chr(0xa0))) == '') {
            continue;
        }
        $line = csv_explode("\t", $line, "\"");
        $cells = array();
        foreach ($line as $cell) {
            $cells[] = preg_replace('/[\\x00-\\x1F]/', '', $cell);
        }
        $csv_lines[] = $cells;
    }
    return $csv_lines;
}
Esempio n. 2
0
function ref_get_data($page, $uniquekey = 1)
{
    $file = ref_get_filename($page);
    if (!file_exists($file)) {
        return array();
    }
    $result = array();
    $fp = @fopen($file, 'r');
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    rewind($fp);
    while ($data = @fgets($fp, 8192)) {
        $data = csv_explode(',', $data);
        $result[rawurldecode($data[$uniquekey])] = $data;
    }
    @flock($fp, LOCK_UN);
    fclose($fp);
    return $result;
}
function import_csv($window)
{
    global $statusbar;
    $filename = wb_sys_dlg_open($window, "Import CSV", "CSV files (*.csv, *.txt)*.csv;*.txtAll files (*.*)*.*" . "");
    if ($filename) {
        $csv = file($filename);
    } else {
        return false;
    }
    $n = 0;
    foreach ($csv as $line) {
        $line = trim($line);
        if ($line) {
            $entry = csv_explode(stripcslashes($line));
            if (edit_record("item", 0, "name\ndescription\ncat\npriority\nseverity", $entry)) {
                $n++;
            }
        }
    }
    wb_set_text($statusbar, basename($filename) . " imported successfully ({$n} items added).");
    return true;
}
Esempio n. 4
0
     if ($match === false) {
         $found2[$i] = -1;
     } else {
         $found2[$i] = $match;
         if ($columns[$match] == 'associate number') {
             $realtorid = $match;
         }
         if ($columns[$match] == 'office id') {
             $officeid = $match;
         }
     }
 }
 while (!feof($handle)) {
     $data = fgets($handle, 4096);
     $data = str_replace("'", "", $data);
     $col = csv_explode(',', $data, '"');
     $update = false;
     $sql = 'select * from tb_other_realtors where realtorid="' . $col[$realtorid] . '"';
     $res = mysql_query($sql);
     if (mysql_num_rows($res) > 0) {
         $update = true;
         $list = mysql_fetch_array($res, MYSQL_ASSOC);
         $isql = 'update tb_other_realtors set office="' . $offices[$col[$officeid]] . '"';
     } else {
         $isql = 'insert into tb_other_realtors (office,';
         $k = count($fieldsneeded);
         for ($j = 1; $j < $k; $j++) {
             if ($datafield[$j] != '') {
                 if ($found2[$j] >= 0) {
                     if ($j < count($datafield) && $j > 1) {
                         $isql .= ',';
Esempio n. 5
0
 function toString()
 {
     $styles = array();
     switch ($this->name) {
         case 'br':
             return '<p><br class="block" /></p>';
         case 'hr':
             return '<hr class="short_line" />';
         case 'ref':
             $param = $this->param != '' ? csv_explode(',', $this->param) : array();
             return guiedit_convert_ref($param);
         case 'clear':
             $styles[] = 'clear:both;';
     }
     if ($this->text) {
         $this->text = str_replace(' ', '&nbsp;', _htmlspecialchars($this->text));
         $this->text = preg_replace("/\r/", "<br />", $this->text);
     }
     $this->param = _htmlspecialchars($this->param);
     $inner = "#{$this->name}" . ($this->param ? "({$this->param})" : '') . $this->text;
     if (MSIE) {
         $styles[] = 'cursor:default;';
     }
     $style = '';
     if ($styles) {
         $style = ' style="' . join('', $styles) . '"';
     }
     //$inner = '<pre>'. $inner . '</pre>';
     global $xpwiki;
     $attr = $xpwiki->func->exist_plugin_convert($this->name) ? ' class="plugin" contenteditable="true"' : '';
     return $this->wrap($inner, 'div', $attr . $style);
 }
Esempio n. 6
0
function plugin_table_edit2_action()
{
    global $vars, $post, $auth_users, $_string;
    $table_num = $vars['table_num'];
    $page = isset($vars['refer']) ? $vars['refer'] : null;
    if (empty($page)) {
        Utility::dieMessage('Page name is null.');
    }
    $wiki = Factory::Wiki($page);
    if (is_freeze($page)) {
        check_editable($page, true, true);
    }
    if ($wiki->isFreezed()) {
        $wiki->checkEditable(true);
    }
    //	Cancel
    $anchr_jump = PLUGIN_TABLE_EDIT2_ANCHR_JUMP ? '#TableEdit2TableNumber' . $table_num : '';
    if (isset($vars['cancel'])) {
        Utility::redirect($wiki->uri() . $anchr_jump);
        exit;
    }
    $line_count = 1;
    $table_sub_num = 1;
    //td
    $table_sub_num_chk = 1;
    //td
    $setting = 0;
    $import = $export = $csv_cancel = 0;
    $edit_mod = isset($vars['edit_mod']) ? $vars['edit_mod'] : '';
    $td_edit = $edit_mod == 't_edit_td' || $edit_mod == 'td' ? 1 : 0;
    $tr_edit = $edit_mod == 't_edit' || $edit_mod == 'tr' ? 1 : 0;
    $t_edit = $edit_mod == 't_edit_td' || $edit_mod == 't_edit' ? 1 : 0;
    $edit_show = $edit_mod == 'tdshow' || $edit_mod == 'show' ? 1 : 0;
    // Petit SPAM Check (Client(Browser)-Server Ticket Check)
    $spam = FALSE;
    if (!function_exists('honeypot_write') && $t_edit) {
        $spam = plugin_table_edit2_spam($post['encode_hint']);
    }
    if ($spam) {
        return plugin_table_edit2_honeypot();
    }
    if (Auth::check_role('readonly')) {
        die_message('PKWK_READONLY prohibits editing');
    }
    if (PLUGIN_TABLE_EDIT2_HTTP_REFERER) {
        if (!function_exists('path_check')) {
            if (!preg_match('/^(' . $script_uri . ')/', $_SERVER['HTTP_REFERER'])) {
                return;
            }
        } else {
            if (!path_check($script_uri, $_SERVER['HTTP_REFERER'])) {
                return;
            }
        }
    }
    if ($edit_mod === 'setting') {
        $set = new TableEdit2SettingWrite($vars);
        if (!$set->sc) {
            return $set->error;
        }
        $setting = 1;
        unset($vars['table_mod']);
    }
    $notimestamp = FALSE;
    if (isset($vars['csv_mod']) || isset($vars['ex_cancel']) || isset($vars['im_cancel']) || isset($vars['set_csv']) || isset($vars['csv_back'])) {
        $csv = new TableEdit2CsvAction();
        if (isset($vars['csv_mod']) && $vars['csv_mod'] === 'import') {
            $csv->csv_import($vars);
            $import = 1;
        } else {
            if (isset($vars['csv_mod']) && $vars['csv_mod'] === 'export') {
                $export = 1;
                $csv_export_data = array();
            } else {
                if (isset($vars['ex_cancel']) || isset($vars['im_cancel'])) {
                    $csv_cancel = 1;
                    $notimestamp = TRUE;
                } else {
                    if (isset($vars['set_csv'])) {
                        $set_csv = 1;
                        $notimestamp = TRUE;
                    } else {
                        if (isset($vars['csv_back'])) {
                            if (PLUGIN_TABLE_EDIT2_CSV_UNLINK) {
                                $con = new TableEdit2CsvConversion($page, array('name' => $vars['file_name']));
                                unlink($con->filename);
                                unlink($con->logname);
                            }
                            Utility::redirect($wiki->uri());
                            exit;
                        } else {
                            return array('msg' => 'csv error', 'body' => 'csv option error');
                            // . join("\n", $csv_data)
                        }
                    }
                }
            }
        }
    }
    if (isset($vars['table_mod'])) {
        $chg = new TableEdit2TableMod($vars['table_mod']);
    }
    if ($td_edit || $tr_edit) {
        $edit = new TableEdit2Edit($vars);
    }
    if ($edit_show) {
        $show = new TableEdit2Show($vars, $page);
    }
    $args = get_source($page);
    static $count = 0;
    $source_s = '';
    $body = '';
    $row_title = 0;
    $td_title_count = 0;
    if ($td_edit || $tr_edit || $setting || $import) {
        $notimestamp = isset($vars['notimestamp']) ? TRUE : FALSE;
    }
    foreach ($wiki->get() as $args_key => $args_line) {
        if (preg_match('/^#([^\\(\\{]+)(?:\\(([^\\r]*)\\))?(\\{*)/', $args_line, $matches) !== FALSE) {
            if (isset($matches[1]) && ($matches[1] == 'table_edit2' || $matches[1] == "table_edit2\n")) {
                $table_find = 1;
                $count++;
                if ($line_count === 1 && $count == $table_num) {
                    if (preg_match('/auth_check[=_](on|off)/i', $matches[2], $auth_check)) {
                        if ($auth_check[1] == 'on') {
                            if (!auth::auth_pw($auth_users)) {
                                $user = TableEdit2Auth::basic_auth();
                                if (empty($user)) {
                                    return;
                                }
                            }
                        }
                    } else {
                        check_editable($page, true, true);
                    }
                    if ($setting) {
                        $args_line = $set->plugin_set_opt($matches[3]);
                    }
                    if ($import) {
                        $args_line = $csv->import_data_set($matches[2], $matches[3]);
                    }
                    if (isset($vars['ex_cancel'])) {
                        $args_line = $csv->cancel($matches[2], $matches[3], 'export');
                    }
                    if (isset($vars['im_cancel'])) {
                        $args_line = $csv->cancel($matches[2], $matches[3], 'import');
                    }
                    if (isset($set_csv)) {
                        $args_line = $csv->set_csv_opt($matches[2], $matches[3], $vars['set_csv']);
                    }
                    if ($edit_mod == 'tdshow') {
                        //tdshow - td_title - 06.11.11
                        if (preg_match('/title_c=(\\d+)/i', $matches[2], $match_title)) {
                            $td_title_count = $match_title[1] - 1;
                        }
                    }
                    if ($edit_mod == 'show') {
                        //show				header
                        if (preg_match('/title_r=(\\d+)/i', $matches[2], $m_row_title)) {
                            $row_title = $m_row_title[1];
                        }
                    }
                    if ($edit_show) {
                        $show->text_type($matches[2]);
                    }
                    if (isset($vars['table_mod'])) {
                        //table_mod
                        $notimestamp = TRUE;
                        $args_line = $chg->table_mod_chg($matches, $args_line);
                    }
                }
                $end_line = strlen($matches[3]);
            }
        }
        if (isset($end_line) && preg_match('/^\\}{' . $end_line . '}/', $args_line) || !isset($end_line)) {
            $table_find = 0;
        }
        if ($table_find && $table_num == $count && !isset($vars['table_mod']) && !$setting && !$import) {
            $table_sub_num_count_chk = 0;
            $table_f_chose = preg_match('/^\\|(.+)\\|([hHfFcC]?)$/', $args_line, $match_line) ? 1 : 0;
            if ($args_line[0] == ',' && $args_line != ',') {
                $table_f_chose = 2;
            }
            if ($td_edit || $tr_edit) {
                $edit->chose = $table_f_chose;
            }
            if ($table_f_chose) {
                if ($table_f_chose === 1) {
                    $match_t = explode("|", $match_line[1]);
                } elseif ($table_f_chose === 2) {
                    $match_t = csv_explode(',', substr(str_replace("\n", '', $args_line), 1));
                    $match_line = array(1 => join(',', $match_t), 2 => '');
                }
                if ($export) {
                    $csv_export_data[] = $match_line[1];
                }
                if (isset($vars['table_sub_num']) && $table_sub_num === $vars['table_sub_num'] && $table_sub_num_chk) {
                    //td 06.09.18
                    $show->chk_table_sub_first_line = $line_count;
                    $table_sub_num_chk = 0;
                }
                if (isset($vars['line_count']) && $vars['line_count'] === $line_count || strtolower($match_line[2]) === 'h' || $edit_mod == 'tdshow' || $td_edit || $row_title) {
                    //					$match_t = explode("|", $match_line[1]);
                    if ($edit_mod == 'tdshow') {
                        //tdshow - td_title - 06.11.11
                        $show->td_title[$line_count] = $match_t[$td_title_count];
                    }
                }
                if ($edit_mod == 'show') {
                    //show				header
                    if ($match_line[2] == 'h' && !$row_title) {
                        $show->table_header($match_t);
                    }
                    if ($line_count == $row_title) {
                        $show->table_header($match_t);
                    }
                }
                if ($vars['line_count'] == $line_count || $table_sub_num == $vars['table_sub_num']) {
                    // textarea 06.11.12
                    if ($edit_show) {
                        if ($show->t_type == 'textarea') {
                            $show->text_type_textarea(count($match_t));
                        }
                    }
                }
                if ($td_edit && $table_sub_num_chk == 0 && $table_sub_num == $vars['table_sub_num']) {
                    $source_s .= $edit->td_edit($match_t) . $match_line[2] . "\n";
                    $table_sub_num_count_chk = 1;
                } else {
                    if (isset($vars['line_count']) && $vars['line_count'] == $line_count && !$td_edit) {
                        if ($tr_edit) {
                            //t_edit tr_add
                            if (isset($vars['add_show']) && $vars['add_show'] === 1) {
                                $source_s .= $args_line;
                                if ($edit->chose !== 2) {
                                    $edit->chk_csv_source($args, $args_key);
                                }
                            }
                            $source_s .= $edit->tr_edit($args_line, $match_t, $match_line[2]);
                        } else {
                            if ($edit_show) {
                                //show or tdshow
                                $show->line_count = $line_count;
                                $body = $show->show_mod($match_t);
                            }
                        }
                    } else {
                        if ($edit_mod == 'tdshow') {
                            //tdshow and edit_td
                            $show->cells[$line_count] = $match_t;
                        }
                        $table_sub_num_count_chk = 1;
                        //td06.09.18
                        $source_s .= $args_line;
                    }
                }
                $line_count++;
            } else {
                if ($table_sub_num_count_chk == 1 && substr($args_line, 0, 2) != '//') {
                    //td
                    $table_sub_num++;
                    $table_sub_num_count_chk = 0;
                }
                $source_s .= $args_line;
            }
        } else {
            $source_s .= $args_line . "\n";
        }
    }
    if ($export) {
        return $csv->csv_export($vars, $csv_export_data);
    }
    $collision = 0;
    if ($tr_edit || $td_edit) {
        if (Factory::Wiki($vars['refer'])->digest() !== $vars['digest']) {
            global $_string, $_title;
            $title = $_title['collided'];
            $body = $_string['msg_collided_auto'] . make_pagelink($vars['refer']);
            $collision = 1;
        }
    }
    if ($tr_edit || $td_edit || isset($vars['table_mod']) || $setting || $import || $csv_cancel || isset($set_csv)) {
        $source = explode("\n", $source_s);
        array_pop($source);
        // 末尾に余計な改行が入るので削除
        //		var_dump($source);
        //		die;
        $wiki->set(explode("\n", $source_s), $notimestamp);
    }
    $get['page'] = $post['page'] = $vars['page'] = $page;
    if ($collision) {
        return array('msg' => $title, 'body' => $body);
    }
    if ($edit_show) {
        return array('msg' => $show->title, 'body' => $body);
    }
    //header('Location: ' . $script_uri . '?' . rawurlencode($page) . $anchr_jump);
    Utility::redirect($wiki->uri() . $anchr_jump);
    exit;
}
 function replace_plugin_options($oldoption, $optionnum, $newoption, $regexp, $plugin_strs)
 {
     if ($oldoption == '' && $optionnum == '') {
         return $plugin_strs;
     }
     $search = '/^([^(]+)(?:\\(([^\\r]*)\\))(.*)$/';
     foreach ($plugin_strs as $i => $line) {
         $matches = array();
         if (preg_match($search, $line, $matches) == 0) {
             continue;
         }
         $head =& $matches[1];
         $options =& $matches[2];
         $tail =& $matches[3];
         $options = csv_explode(',', $options);
         foreach ($options as $j => $option) {
             if (strpos($option, ',') !== FALSE) {
                 $options[$j] = '"' . $option . '"';
                 // csv recover
             }
         }
         if ($oldoption != '') {
             foreach ($options as $j => $option) {
                 if ($options[$j] == '') {
                     continue;
                 }
                 if ($regexp) {
                     $options[$j] = preg_replace('/' . str_replace('/', '\\/', $oldoption) . '/', $newoption, $options[$j]);
                 } else {
                     $options[$j] = $oldoption == $option ? $newoption : $options[$j];
                     //$options[$j] = str_replace($oldoption, $newoption, $options[$j]);
                 }
                 if ($options[$j] == '') {
                     unset($options[$j]);
                 }
             }
         } else {
             $num = $optionnum >= 0 ? $optionnum : count($options) + $optionnum;
             if ($regexp) {
                 $options[$num] = preg_replace(preg_quote($options[$num], '/'), $newoption, $options[$num]);
             } else {
                 $options[$num] = $newoption;
             }
             if ($options[$num] == '') {
                 unset($options[$num]);
             }
         }
         // no csv implode.
         $options = implode(',', $options);
         $plugin_strs[$i] = "{$head}({$options}){$tail}";
     }
     return $plugin_strs;
 }
Esempio n. 8
0
 function splitbody(&$body)
 {
     $lines = explode("\n", $body);
     $splitargs = array();
     $bodies = array();
     $line = current($lines);
     $matches = array();
     if (preg_match('/' . $this->splittag . '(?:\\(([^)]*)\\))?(.*)$/', $line, $matches)) {
         $splitargs[] = csv_explode(',', $matches[1]);
         $bodies[0] = '';
     } else {
         $bodies[0] = $line . "\n";
     }
     $i = 0;
     while (($line = next($lines)) !== false) {
         $matches = array();
         if (preg_match('/' . $this->splittag . '(?:\\(([^)]*)\\))?(.*)$/', $line, $matches)) {
             $splitargs[] = csv_explode(',', $matches[1]);
             $bodies[++$i] = '';
         } else {
             $bodies[$i] .= $line . "\n";
         }
     }
     if (count($bodies) > count($splitargs)) {
         array_unshift($splitargs, array());
     }
     return array(&$bodies, &$splitargs);
 }
Esempio n. 9
0
function tb_get($file, $key = 1)
{
    if (!file_exists($file)) {
        return array();
    }
    $result = array();
    $fp = @fopen($file, 'r');
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    rewind($fp);
    while ($data = @fgets($fp, 8192)) {
        // $data[$key] = URL
        $data = csv_explode(',', $data);
        $result[rawurldecode($data[$key])] = $data;
    }
    @flock($fp, LOCK_UN);
    fclose($fp);
    return $result;
}
Esempio n. 10
0
function ninja_forms_import_list_options()
{
    $options = $_REQUEST['options'];
    $field_id = absint($_REQUEST['field_id']);
    $options = str_replace('\\,', '-comma-replace-placeholder-', $options);
    $options = csv_explode($options);
    if (is_array($options)) {
        $tmp_array = array();
        $x = 0;
        foreach ($options as $option) {
            $label = stripslashes($option[0]);
            $value = stripslashes($option[1]);
            $calc = stripslashes($option[2]);
            $label = str_replace("''", "", $label);
            $label = str_replace("-comma-replace-placeholder-", ",", $label);
            $value = str_replace("''", "", $value);
            $value = str_replace("-comma-replace-placeholder-", ",", $value);
            $calc = str_replace("''", "", $calc);
            $calc = str_replace("-comma-replace-placeholder-", ",", $calc);
            $tmp_array[$x]['label'] = $label;
            $tmp_array[$x]['value'] = $value;
            $tmp_array[$x]['calc'] = $calc;
            $x++;
        }
        $x = 0;
        foreach ($tmp_array as $option) {
            $hidden = 0;
            ninja_forms_field_list_option_output($field_id, $x, $option, $hidden);
            $x++;
        }
    }
    die;
}
function bank_import_csv($structure, $filename, $bank_gl_acct)
{
    global $db, $messageStack;
    include DIR_FS_WORKING . 'classes/import_banking.php';
    $bankimport = new impbanking();
    $data = file($_FILES[$filename]['tmp_name']);
    // read the header and build array
    if (sizeof($data) < 2) {
        $messageStack->add('The number of lines in the file is to small, a csv file must contain a header line and at least on input line!', 'error');
        return false;
    }
    $header = csv_explode(trim(array_shift($data)));
    // build the map structure
    $temp = $structure->Module->Table;
    $map_array = array();
    foreach ($structure->Module->Table as $table) {
        foreach ($table->Field as $field) {
            $key = array_search($field->TagName, $header);
            if ($key !== false) {
                $map_array[$key] = array('cnt' => 0, 'table' => $table->Name, 'field' => $field->Name);
            }
        }
        break;
    }
    // 	build dependent map tables
    $ref_mapping = array();
    if (is_object($table->LinkTable)) {
        $table->LinkTable = array($table->LinkTable);
    }
    if (isset($table->LinkTable)) {
        foreach ($table->LinkTable as $subtable) {
            foreach ($structure->Module->Table as $working) {
                if ($subtable->Name == $working->Name) {
                    $ref_mapping[$subtable->Name] = array('pri_field' => $subtable->PrimaryField, 'ref_field' => $subtable->DependentField);
                    for ($i = 1; $i <= MAX_IMPORT_CSV_ITEMS; $i++) {
                        foreach ($working->Field as $field) {
                            $key = array_search($field->TagName . '_' . $i, $header);
                            if ($key !== false) {
                                $map_array[$key] = array('cnt' => $i, 'table' => $subtable->Name, 'field' => $field->Name);
                            }
                        }
                    }
                }
            }
        }
    }
    $countline = 0;
    foreach ($data as $line) {
        if (!($line = trim($line))) {
            continue;
        }
        // blank line
        $line_array = $map_array;
        $sql_array = array();
        $working = csv_explode($line);
        for ($i = 0; $i < sizeof($working); $i++) {
            $line_array[$i]['value'] = $working[$i];
        }
        foreach ($line_array as $value) {
            $sql_array[$value['table']][$value['cnt']][$value['field']] = $value['value'];
        }
        $db->transStart();
        foreach ($sql_array as $table => $count) {
            foreach ($count as $cnt => $table_array) {
                if ($table_array['debit_amount'] == '' && $table_array['credit_amount'] == '') {
                    if ($table_array['debit_credit'] == DEBIT_CREDIT_DESCRIPTION) {
                        $table_array['debit_amount'] = 0;
                        $table_array['credit_amount'] = $table_array['amount'];
                    } else {
                        $table_array['debit_amount'] = $table_array['amount'];
                        $table_array['credit_amount'] = 0;
                    }
                }
                if (isset($table_array['debit_amount']) && isset($table_array['credit_amount'])) {
                    //	echo 'inserting data: '; print_r($table_array); echo '<br>';
                    $bankimport->start_import($table_array['our_account_number'], $table_array['date'], $table_array['account_number_to'], $table_array['credit_amount'], $table_array['debit_amount'], $table_array['description'] . ' ' . $table_array['anouncement'], $bank_gl_acct, $table_array['iban_to']);
                    if ($bankimport->_succes == true) {
                        $countline++;
                    }
                }
            }
        }
    }
    if ($countline != 0) {
        if (!$bankimport->update_chart_history_periods($bankimport->first_period)) {
            $db->transRollback();
            $messageStack->add("Chart of accounts are out of balance. When we try to import the file\n Removed the journals. Please try to import again when balances are fine.");
        } else {
            $db->transCommit();
            $messageStack->add("succesfully posted {$countline} number of lines", 'caution');
        }
    }
    $messageStack->write_debug();
}
 function read_updatelist()
 {
     $datfile = CACHE_DIR . 'updateplugin.dat';
     $lines = file($datfile);
     $list = array();
     foreach ($lines as $line) {
         $metas = csv_explode(',', rtrim($line));
         $data = array();
         foreach ($metas as $meta) {
             list($key, $val) = explode('=', $meta, 2);
             $data[$key] = $val;
         }
         $list[$data['filename']] = $data;
     }
     return $list;
 }
Esempio n. 13
0
function &Factory_YTableEx(&$root, $text)
{
    if ($text == ',') {
        return Factory_InlineEx($text);
    } else {
        // return new YTableEx(csv_explode(',', substr($text, 1)));
        $obj = new YTableEx(csv_explode(',', substr($text, 1)));
        return $obj;
    }
}
 function r_metalines($page, $detected = false)
 {
     if (array_key_exists($page, $this->visited)) {
         return array();
     }
     if (!is_page($page)) {
         return array();
     }
     $this->visited[$page] = '';
     $lines = $this->get_source($page);
     $multiline = 0;
     $metalines = array();
     foreach ($lines as $i => $line) {
         // multiline plugin. refer lib/convert_html
         if (defined('PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK') && PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK === 0) {
             $matches = array();
             if ($multiline < 2) {
                 if (preg_match('/^#([^\\(\\{]+)(?:\\(([^\\r]*)\\))?(\\{*)/', $line, $matches)) {
                     $multiline = strlen($matches[3]);
                 }
             } else {
                 if (preg_match('/^\\}{' . $multiline . '}$/', $line, $matches)) {
                     $multiline = 0;
                 }
                 continue;
             }
         }
         // fromhere
         if ($this->options['page'][1] == $page && !$detected) {
             if (preg_match('/^#' . $this->plugin . '/', $line, $matches)) {
                 $detected = true;
                 continue;
             }
         }
         if (preg_match($this->conf['def_headline'], $line, $matches)) {
             $depth = strlen($matches[1]);
             $anchor = '#' . $this->make_heading($line);
             // *** [id] is removed from $line
             $headline = trim($line);
             $metalines[] = array(page => $page, headline => $headline, anchor => $anchor, depth => $depth, linenum => $i, fromhere => $detected);
             continue;
         }
         if (preg_match($this->conf['def_include'], $line, $matches)) {
             $args = csv_explode(',', $matches[1]);
             $inclpage = array_shift($args);
             $options = array();
             foreach ($args as $arg) {
                 list($key, $val) = array_pad(explode('=', $arg, 2), 2, true);
                 $options[$key] = $val;
             }
             $inclpage = get_fullname($inclpage, $page);
             if (!$this->is_page($inclpage)) {
                 continue;
             }
             // $anchor = PluginIncludex::get_page_anchor($inclpage)
             $anchor = 'z' . md5($inclpage);
             $anchor = '#' . htmlspecialchars($anchor);
             if (exist_plugin('includex') & is_callable(array('PluginIncludex', 'get_titlestr'))) {
                 $titlestr = PluginIncludex::get_titlestr($inclpage, $options['titlestr']);
             } else {
                 $titlestr = $inclpage;
             }
             $metalines[] = array(page => $inclpage, headline => $titlestr, anchor => $anchor, depth => 0, linenum => $i, fromhere => $detected);
             $metalines = array_merge($metalines, $this->r_metalines($inclpage, $detected));
             continue;
         }
         if (preg_match($this->conf['def_title'], $line, $matches)) {
             $title = $matches[1];
             $this->visited[$page] = $title;
             continue;
         }
     }
     return $metalines;
 }
Esempio n. 15
0
function do_plugin_inline($name, $args, &$body)
{
    global $digest;
    if (do_plugin_init($name) === FALSE) {
        return '[Plugin init failed: ' . $name . ']';
    }
    if ($args !== '') {
        $aryargs = csv_explode(',', $args);
    } else {
        $aryargs = array();
    }
    // NOTE: A reference of $body is always the last argument
    $aryargs[] =& $body;
    // func_num_args() != 0
    $_digest = $digest;
    $retvar = call_user_func_array('plugin_' . $name . '_inline', $aryargs);
    $digest = $_digest;
    // Revert
    if ($retvar === FALSE) {
        // Do nothing
        return htmlsc('&' . $name . ($args ? '(' . $args . ')' : '') . ';');
    } else {
        return $retvar;
    }
}
Esempio n. 16
0
function &Factory_YTable(&$root, $text)
{
    if ($text == ',') {
        $ret = Factory_Inline($text);
        return $ret;
        //return Factory_Inline($text);
    } else {
        $ret = new YTable(csv_explode(',', substr($text, 1)));
        return $ret;
        //return new YTable(csv_explode(',', substr($text, 1)));
    }
}
function &Factory_PukiWikiYTable(&$root, $text)
{
    $_value = csv_explode(',', substr($text, 1));
    if (count($_value) == 0) {
        return Factory_PukiWikiInline($text);
    } else {
        return new PukiWikiYTable($_value);
    }
}
Esempio n. 18
0
/**
 * Split text into key value hash. 
 * 
 * Keys must not start with "@@" or "@_". 
 * Split text at $d2 (|#|) into lines. Split lines at first $d1 (=) into key value.
 * If key is not found return $text or use "@_N" as key (N is autoincrement 1, 2, ...) if mulitple keys are missing.
 * If key already exists rename to key.N (N is autoincrement 1, 2, ...).
 * If value starts with "@N" use conf[@@N]="sd1","sd2" and set value = conf2kv(value, sd1, sd2).
 * Default values are [@@1="",","] and [@@2=$d1,$d2]. 
 * All keys and values are trimmed. Use Quote character ["] to preserve whitespace and delimiter.
 * Use double quote [""] to escape ["]. If $d1 is empty return array with $d2 as delimiter.
 * If text is empty return empty array.
 *
 * @author Roland Kujundzic <*****@*****.**>
 * @param string $text
 * @param string $d1 (default is "=")
 * @param string $d2 (default is "|#|")
 * @param map ikv (config hash - default [ ])
 * @return string|array|hash
 */
function conf2kv($text, $d1 = '=', $d2 = '|#|', $ikv = array())
{
    $ld1 = mb_strlen($d1);
    if (empty($text)) {
        return array();
    }
    if ($ld1 == 0 || mb_strpos($text, $d1) === false) {
        $res = $text;
        if (mb_strlen($d2) > 0 && mb_strpos($text, $d2) !== false) {
            $res = csv_explode($text, $d2, '"', 4);
        } else {
            if (mb_substr($res, 0, 1) == '"' && mb_substr($res, -1) == '"') {
                $res = mb_substr($res, 1, -1);
            }
        }
        return $res;
    }
    $tmp = csv_explode($text, $d2, '"', 15);
    $kv = array();
    $kn = array();
    $n = 1;
    foreach ($tmp as $line) {
        if (($pos = mb_strpos($line, $d1)) > 0) {
            $key = trim(mb_substr($line, 0, $pos));
            $value = trim(mb_substr($line, $pos + $ld1));
            if (mb_substr($key, 0, 1) != '@') {
                $value = str_replace('""', '"', $value);
                if (isset($kv[$key])) {
                    if (!isset($kn[$key])) {
                        $kn[$key] = 0;
                    }
                    $kn[$key]++;
                    $key .= '.' . $kn[$key];
                }
            }
        } else {
            $key = '@_' . $n;
            $value = $line;
            $n++;
        }
        if (preg_match('/^"(@[0-9]+)\\s(.+)"$/s', $value, $match) || preg_match('/^(@[0-9]+)\\s(.+)$/s', $value, $match)) {
            $sf = $match[1];
            if (!isset($ikv[$sf])) {
                if ($sf == '@1') {
                    $ikv['@1'] = array('', ',');
                } else {
                    if ($sf == '@2') {
                        $ikv['@2'] = array($d1, $d2);
                    }
                }
            }
            if (isset($ikv[$sf])) {
                $kv[$key] = conf2kv(trim($match[2]), $ikv[$sf][0], $ikv[$sf][1], $ikv);
            }
        } else {
            if (mb_substr($key, 0, 2) == '@@') {
                if (mb_substr($value, 0, 1) == '"' && mb_substr($value, -1) == '"') {
                    $ikv[mb_substr($key, 1)] = explode('","', mb_substr($value, 1, -1));
                }
            } else {
                if (mb_substr($value, 0, 1) == '"' && mb_substr($value, -1) == '"') {
                    $value = mb_substr($value, 1, -1);
                }
                $kv[$key] = $value;
            }
        }
    }
    if ($n == 2 && count($kv) == 1 && isset($kv['@_1'])) {
        return $kv['@_1'];
    }
    return $kv;
}
Esempio n. 19
0
 /**
  * Update Vote for convert plugin
  *
  * @param array &$lines
  * @param integer $vote_id
  * @parram string $choice_id
  * @param string $addchoice
  * @return array array($linenum, $updated_line, $updated_text, $updated_votes)
  */
 function get_update_convert(&$lines, $vote_id, $choice_id, $addchoice = null)
 {
     $vote_count = 0;
     foreach ($lines as $linenum => $line) {
         $matches = array();
         if (preg_match('/^#votex(?:\\((.*)\\)(.*))?$/i', $line, $matches) && $vote_id == $vote_count++) {
             $args = csv_explode(',', $matches[1]);
             $remain = isset($matches[2]) ? $matches[2] : '';
             list($votes, $options) = $this->parse_args_convert($args, $this->default_options);
             if ($options['readonly']) {
                 return array(false, false, false, false);
             }
             if (isset($addchoice)) {
                 $votes[] = array($addchoice, 1);
             } elseif (isset($votes[$choice_id])) {
                 list($choice, $count) = $votes[$choice_id];
                 $votes[$choice_id] = array($choice, $count + 1);
             }
             $new_args = $this->restore_args_convert($votes, $options, $this->default_options);
             $new_arg = csv_implode(',', $new_args);
             $newtext = '#votex(' . $new_arg . ')';
             $newline = $newtext . $remain . "\n";
             return array($linenum, $newline, $newtext, $votes);
         }
     }
     return array(false, false, false, false);
 }
 function restore_time()
 {
     $this->cachefile = CACHE_DIR . "remakepage.dat";
     if (($lines = file($this->cachefile)) === FALSE) {
         return "<p><b>timestamp cache file, {$this->cachefile}, does not exist or not readable. </b></p>";
     }
     $oldpages = array();
     $failedpages = array();
     foreach ($lines as $line) {
         $line = rtrim($line);
         list($page, $time) = csv_explode(',', $line);
         $oldpages[] = $page;
         if (is_page($page) && pkwk_touch_file(get_filename($page), $time) === false) {
             $failedpages[] = $page;
         }
     }
     put_lastmodified();
     $body = '<p>';
     $body .= '<b>Restored timestamps.</b><br />';
     $nonexists = array_diff($oldpages, get_existpages());
     if (!empty($nonexists)) {
         $body .= "<b>Following pages do not exist in current wiki,</b><br />\n";
         $body .= implode("<br />\n", $nonexists) . "<br />";
     }
     if (!empty($failedpages)) {
         $body .= "<b>Failed to restore timestamp of </b><br />\n";
         $body .= implode("<br />\n", $failedpages) . "<br />";
         $body .= "<b>Skipped.</b><br />";
     }
     $body .= '</p>';
     return $body;
 }
Esempio n. 21
0
 /**
  * Read a page and construct Toc (This is THE constructor)
  *
  * @access public
  * @todo should be able to separate functionalities more
  */
 function construct_toc($page)
 {
     $lines = get_source($page);
     $title = null;
     $headlines = $includes = $extra = array();
     sonots::remove_multilineplugin_lines($lines);
     foreach ($lines as $linenum => $line) {
         if (!isset($extra['fromhere'])) {
             if (preg_match($this->syntax['contents'], $line, $matches)) {
                 $extra['fromhere'] = $linenum;
                 continue;
             }
         }
         if (!isset($extra['readmore'])) {
             if (preg_match($this->syntax['readmore'], $line, $matches)) {
                 $extra['readmore'] = $linenum;
                 continue;
             }
         }
         if (preg_match($this->syntax['headline'], $line, $matches)) {
             $depth = strlen($matches[1]);
             list($string, $anchor) = sonots::make_heading($line);
             $headlines[$linenum] = new PluginSonotsHeadline($page, $linenum, $depth, $string, $anchor);
             continue;
         }
         if (preg_match($this->syntax['include'], $line, $matches)) {
             $inclargs = csv_explode(',', $matches[1]);
             $inclpage = array_shift($inclargs);
             $inclpage = get_fullname($inclpage, $page);
             if (!is_page($inclpage)) {
                 continue;
             }
             $includes[$linenum] = new PluginSonotsIncludeline($linenum, $inclpage, $inclargs);
             continue;
         }
         if (preg_match($this->syntax['title'], $line, $matches)) {
             $title = $matches[1];
             continue;
         }
     }
     $this->page = $page;
     $this->title = $title;
     $this->headlines = $headlines;
     $this->includes = $includes;
     $this->extra = $extra;
 }