function toString($list = PLUGIN_TRACKER_DEFAULT_LIST, $limit = NULL, $jscount = 0) { $list = trim($list); if ($list == '') { $list = PLUGIN_TRACKER_DEFAULT_LIST; } if ($limit == NULL) { $limit = PLUGIN_TRACKER_DEFAULT_LIMIT; } if (!is_numeric($limit)) { $this->error = "Limit seems not numeric: " . $limit; return FALSE; } $form =& $this->form; $this->_list = $list; // For _replace_title() only $list = $form->config->page . '/' . $list; $source = array(); $regex = '/\\[([^\\[\\]]+)\\]/'; // Loading template $template = plugin_tracker_get_source($list, TRUE); if ($template === FALSE || empty($template)) { $this->error = 'List not found: ' . $list; return FALSE; } // Try to create $form->fields just you need if ($form->initFields('_real', plugin_tracker_field_pickup($template), array_keys($this->orders)) === FALSE) { $this->error = $form->error; return FALSE; } // Load and sort $this->rows if ($this->loadRows() === FALSE || $this->sortRows() === FALSE) { return FALSE; } $rows = $this->rows; // toString() $count = count($this->rows); $limit = intval($limit); if ($limit != 0) { $limit = max(1, $limit); } if ($limit != 0 && $count > $limit) { $source[] = str_replace(array('$1', '$2'), array($count, $limit), plugin_tracker_message('msg_limit')) . "\n"; $rows = array_slice($this->rows, 0, $limit); } // Loading template // TODO: How do you feel single/multiple table rows with 'c'(decolation)? $matches = $t_header = $t_body = $t_footer = array(); $template = plugin_tracker_get_source($list); if ($template === FALSE) { $this->error = 'Page not found or seems empty: ' . $list; return FALSE; } foreach ($template as $line) { if (preg_match('/^\\|.+\\|([hfc])$/i', $line, $matches)) { if (strtolower($matches[1]) == 'f') { $t_footer[] = $line; // Table footer } else { $t_header[] = $line; // Table header, or decoration } } else { $t_body[] = $line; } } unset($template); // Header and decolation foreach ($t_header as $line) { $source[] = preg_replace_callback($regex, array(&$this, '_replace_title'), $line); } unset($t_header); // Repeat foreach ($rows as $row) { $this->_row = $row; // Body foreach ($t_body as $line) { if (ltrim($line) != '') { $this->_the_first_character_of_the_line = $line[0]; $line = preg_replace_callback($regex, array(&$this, '_replace_item'), $line); } $source[] = $line; } } unset($t_body); // Footer foreach ($t_footer as $line) { $source[] = preg_replace_callback($regex, array(&$this, '_replace_title'), $line); } unset($t_footer); return implode('', $source); }
function toString($limit = NULL) { global $_tracker_messages; $source = ''; $body = array(); if ($limit !== NULL and count($this->rows) > $limit) { $source = str_replace(array('$1', '$2'), array(count($this->rows), $limit), $_tracker_messages['msg_limit']) . "\n"; $this->rows = array_splice($this->rows, 0, $limit); } if (count($this->rows) == 0) { return ''; } foreach (plugin_tracker_get_source($this->config->page . '/' . $this->list) as $line) { if (preg_match('/^\\|(.+)\\|[hHfFcC]$/', $line)) { $source .= preg_replace_callback('/\\[([^\\[\\]]+)\\]/', array(&$this, 'replace_title'), $line); } else { $body[] = $line; } } foreach ($this->rows as $key => $row) { if (!TRACKER_LIST_SHOW_ERROR_PAGE and !$row['_match']) { continue; } $this->items = $row; foreach ($body as $line) { if (trim($line) == '') { $source .= $line; continue; } $this->pipe = ($line[0] == '|' or $line[0] == ':'); $source .= preg_replace_callback('/\\[([^\\[\\]]+)\\]/', array(&$this, 'replace_item'), $line); } } return convert_html($source); }