Exemplo n.º 1
0
Arquivo: pdf.php Projeto: rair/yacs
 /**
  * page footer
  * @see included/fpdf.php
  */
 function Footer()
 {
     global $context;
     // go to 1.5 cm from bottom
     $this->SetY(-15);
     // select Arial italic 8
     $this->SetFont('Times', '', 8);
     // print centered page number
     $this->SetTextColor(0, 0, 0);
     $this->Cell(0, 4, 'Page ' . $this->PageNo() . '/{nb}', 0, 1, 'C');
     // we are proud of it
     $this->SetTextColor(0, 0, 180);
     $this->Cell(0, 4, utf8::to_iso8859(utf8::transcode(i18n::s('PDF export created by YACS'), TRUE)), 0, 0, 'C', 0, 'http://www.yacs.fr/');
 }
Exemplo n.º 2
0
 /**
  * suppress tags and codes from a string
  *
  * This function will remove any yacs code, and also any html tag, from the input string.
  *
  * @param string a label to check
  * @param allowed html tags
  * @return a clean string
  */
 function clean($label, $allowed = '')
 {
     // strip all yacs codes
     $label = preg_replace(array('/\\[(.*?)\\]/s', '/\\[\\/(.*?)\\]/s'), ' ', $label);
     // reintroduce new lines
     $label = preg_replace('/<br\\s*\\/>/i', "\n", $label);
     // make some room around titles, paragraphs, and divisions
     $label = preg_replace('/<(code|div|h1|h2|h3|ol|li|p|pre|ul)>/i', ' <$1>', $label);
     $label = preg_replace('#</(code|div|h1|h2|h3|ol|li|p|pre|ul)>#i', '</$1> ', $label);
     // strip all html tags and encode
     $label = strip_tags($label, $allowed);
     // transform Unicode entities
     $label = utf8::transcode($label);
     // strip all html tags and encode
     return encode_field($label);
 }
Exemplo n.º 3
0
Arquivo: fetch.php Projeto: rair/yacs
     Safe::header("icy-notice2: provided by a YACS server<BR>");
     Safe::header("icy-pub: 1");
     // name
     $name = array();
     if ($value = implode(' & ', @$data['comments_html']['artist'])) {
         $name[] = $value;
     }
     if ($value = implode(', ', @$data['comments_html']['title'])) {
         $name[] = $value;
     }
     if ($name = implode(' - ', $name)) {
         Safe::header("icy-name: " . utf8::to_iso8859(utf8::transcode($name)));
     }
     // genre
     if ($value = implode(', ', @$data['comments_html']['genre'])) {
         Safe::header("icy-genre: " . utf8::to_iso8859(utf8::transcode($value)));
     }
     // audio bitrate
     if ($value = @$data['audio']['bitrate']) {
         Safe::header("icy-br: " . substr($value, 0, -3));
     }
     // this server
     Safe::header("icy-url: " . $context['url_to_home'] . $context['url_to_root']);
 }
 // serve the right type
 Safe::header('Content-Type: ' . Files::get_mime_type($item['file_name']));
 // suggest a name for the saved file
 $file_name = utf8::to_ascii($item['file_name']);
 Safe::header('Content-Disposition: attachment; filename="' . str_replace('"', '', $file_name) . '"');
 // we accepted (limited) range requests
 Safe::header('Accept-Ranges: bytes');
Exemplo n.º 4
0
Arquivo: tables.php Projeto: rair/yacs
 /**
  * build one table
  *
  * Accept following variants:
  * - csv - to provide a downloadable csv page
  * - json - to provide all values in one column
  * - inline - to render tables within articles
  * - simple - the legacy fixed table
  * - sortable - click on column to sort the row
  *
  * @param the id of the table to build
  * @param string the variant to provide - default is 'simple'
  * @return a displayable string
  */
 public static function build($id, $variant = 'simple')
 {
     global $context;
     // split parameters
     $attributes = preg_split("/\\s*,\\s*/", $id, 3);
     $id = $attributes[0];
     // get the table object
     if (!($table = Tables::get($id))) {
         return NULL;
     }
     // do the SELECT statement
     if (!($rows = SQL::query($table['query']))) {
         Logger::error(sprintf(i18n::s('Error in table query %s'), $id) . BR . htmlspecialchars($table['query']) . BR . SQL::error());
         return NULL;
     }
     // build the resulting string
     $text = '';
     switch ($variant) {
         // produce a table readable into MS-Excel
         case 'csv':
             // comma separated values
             $separator = ",";
             // one row for the title
             if ($table['title']) {
                 $label = preg_replace('/\\s/', ' ', $table['title']);
                 // encode to ASCII
                 $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 // escape quotes to preserve them in the data
                 $label = str_replace('"', '""', $label);
                 $text .= '"' . $label . '"';
                 $text .= "\n";
             }
             // one row for header fields
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 if ($index++) {
                     $text .= $separator;
                 }
                 $label = trim(preg_replace('/\\s/', ' ', ucfirst($field->name)));
                 // encode
                 $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 // escape quotes to preserve them in the data
                 $label = str_replace('"', '""', $label);
                 $text .= '"' . $label . '"';
             }
             $text .= "\n";
             // process every table row
             $row_index = 0;
             while ($row = SQL::fetch($rows)) {
                 // one cell at a time
                 $index = 0;
                 foreach ($row as $name => $value) {
                     // glue cells
                     if ($index++) {
                         $text .= $separator;
                     }
                     // remove HTML tags
                     $value = strip_tags(str_replace('</', ' </', str_replace(BR, ' / ', $value)));
                     // clean spaces
                     $label = trim(preg_replace('/\\s+/', ' ', $value));
                     // encode
                     $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // make a link if this is a reference
                     if ($index == 1 && $table['with_zoom'] == 'Y') {
                         $label = $context['url_to_home'] . $context['url_to_root'] . $label;
                     }
                     // quote data
                     $text .= '"' . $label . '"';
                 }
                 // new line
                 $text .= "\n";
             }
             return $text;
             // a JSON set of values
         // a JSON set of values
         case 'json':
             // get header labels
             $labels = array();
             while ($field = SQL::fetch_field($rows)) {
                 $labels[] = trim(preg_replace('/[^\\w]+/', '', ucfirst($field->name)));
             }
             // all items
             $data = array();
             $data['items'] = array();
             while ($row = SQL::fetch_row($rows)) {
                 // all rows
                 $datum = array();
                 $label = FALSE;
                 $index = 0;
                 $link = NULL;
                 foreach ($row as $name => $value) {
                     $index++;
                     // first column is only a link
                     if ($index == 1 && $table['with_zoom'] == 'Y') {
                         $link = $context['url_to_home'] . $context['url_to_root'] . ltrim($value, '/');
                         continue;
                     }
                     // adjust types to not fool the json encoder
                     if (preg_match('/^(\\+|-){0,1}[0-9]+$/', $value)) {
                         $value = intval($value);
                     } elseif (preg_match('/^(\\+|-){0,1}[0-9\\.,]+$/', $value)) {
                         $value = floatval($value);
                     } elseif (preg_match('/^(true|false)$/i', $value)) {
                         $value = intval($value);
                     }
                     // ensure we have some label for SIMILE Exhibit
                     if (!$label) {
                         $label = $value;
                     }
                     // combine first and second columns
                     if ($index == 2 && $link) {
                         $value = Skin::build_link($link, $value, 'basic');
                     }
                     // save this value
                     $datum[$labels[$name]] = utf8::to_ascii($value, PRINTABLE_SAFE_ALPHABET);
                 }
                 if ($label && !in_array('label', $labels)) {
                     $datum['label'] = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 }
                 // add a tip, if any
                 $data['items'][] = $datum;
             }
             include_once $context['path_to_root'] . 'included/json.php';
             $text .= json_encode2($data);
             return $text;
             // list of facets for SIMILE Exhibit
         // list of facets for SIMILE Exhibit
         case 'json-facets':
             // columns are actual facets
             $facets = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $index++;
                 // first column is only a link
                 if ($index == 1 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // first column has a link
                 if ($index == 2 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // column is a facet
                 $label = '.' . trim(preg_replace('/[^\\w]+/', '', ucfirst($field->name)));
                 $title = trim(str_replace(',', '', ucfirst($field->name)));
                 $facets[] = '<div ex:role="facet" ex:expression="' . $label . '" ex:facetLabel="' . $title . '"></div>';
                 // only last columns can be faceted
                 if (count($facets) > 7) {
                     array_shift($facets);
                 }
             }
             // reverse facet order
             $facets = array_reverse($facets);
             // job done
             $text = join("\n", $facets);
             return $text;
             // list of columns for SIMILE Exhibit
         // list of columns for SIMILE Exhibit
         case 'json-labels':
             // get header labels
             $labels = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $index++;
                 // first column is only a link
                 if ($index == 1 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // column id
                 $labels[] = '.' . trim(preg_replace('/[^\\w]+/', '', ucfirst($field->name)));
                 // limit the number of columns put on screen
                 if (count($labels) >= 7) {
                     break;
                 }
             }
             // job done
             $text = join(', ', $labels);
             return $text;
             // titles of columns for SIMILE Exhibit
         // titles of columns for SIMILE Exhibit
         case 'json-titles':
             // get header labels
             $labels = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $index++;
                 // first column is only a link
                 if ($index == 1 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // column header
                 $labels[] = trim(str_replace(',', '', ucfirst($field->name)));
             }
             $text = join(', ', $labels);
             return $text;
             // produce an HTML table
         // produce an HTML table
         default:
         case 'inline':
         case 'sortable':
             // a table with a grid
             $text .= Skin::table_prefix('grid');
             // the title, with a menu to download the table into Excel
             if ($variant == 'inline') {
                 $item_bar = array();
                 $item_bar += array(Tables::get_url($id) => $table['title']);
                 $item_bar += array(Tables::get_url($id, 'fetch_as_csv') => 'CSV (Excel)');
                 if (Surfer::is_associate()) {
                     $item_bar += array(Tables::get_url($id, 'edit') => i18n::s('edit'));
                 }
                 if (count($item_bar)) {
                     $text .= '<caption>' . Skin::build_list($item_bar, 'menu') . "</caption>\n";
                 }
             }
             // column headers are clickable links
             $cells = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 if ($index++ != 0 || $table['with_zoom'] != 'Y') {
                     $cells[] = ucfirst($field->name);
                 }
             }
             $text .= "\t\t" . Skin::table_row($cells, 'sortable');
             // the table body
             $count = 0;
             $row_index = 0;
             while ($row = SQL::fetch_row($rows)) {
                 $cells = array();
                 $link = '';
                 for ($index = 0; $index < count($row); $index++) {
                     if ($index == 0 && $table['with_zoom'] == 'Y') {
                         $link = $row[$index];
                     } elseif ($link) {
                         $cells[] = Skin::build_link($link, $row[$index]);
                         $link = '';
                     } else {
                         $cells[] = $row[$index];
                     }
                 }
                 $text .= "\t\t" . Skin::table_row($cells, $count++);
             }
             $text .= Skin::table_suffix();
             return $text;
             // adapted to open chart flash
         // adapted to open chart flash
         case 'chart':
             // get title for y series
             $y_title = $y2_title = $y3_title = NULL;
             $y_index = $y2_index = $y3_index = 0;
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 // time will be used for x labels
                 if ($index == 0 && $table['with_zoom'] == 'T') {
                 } elseif ($index == 0 && $table['with_zoom'] == 'Y') {
                 } elseif (!$y_title) {
                     $y_title = '"' . ucfirst($field->name) . '"';
                     $y_index = $index;
                 } elseif (!$y2_title) {
                     $y2_title = '"' . ucfirst($field->name) . '"';
                     $y2_index = $index;
                 } elseif (!$y3_title) {
                     $y3_title = '"' . ucfirst($field->name) . '"';
                     $y3_index = $index;
                     break;
                 }
                 $index++;
             }
             // process every table row
             $x_labels = array();
             $y_values = array();
             $y2_values = array();
             $y3_values = array();
             $y_min = $y_max = NULL;
             $count = 1;
             while ($row = SQL::fetch($rows)) {
                 // one cell at a time
                 $index = 0;
                 foreach ($row as $name => $value) {
                     // clean spaces
                     $label = trim(preg_replace('/\\s/', ' ', $value));
                     // encode in iso8859
                     $label = utf8::to_iso8859($label);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // quote data
                     if (preg_match('/-*[^0-9\\,\\.]/', $label)) {
                         $label = '"' . $label . '"';
                     }
                     // x labels
                     if ($index == 0) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($x_labels, $label);
                         } else {
                             $x_labels[] = $count++;
                         }
                         // y value
                     } elseif ($index == $y_index) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($y_values, $label);
                         } else {
                             $y_values[] = $label;
                         }
                         if (!isset($y_min) || intval($label) < $y_min) {
                             $y_min = intval($label);
                         }
                         if (!isset($y_max) || intval($label) > $y_max) {
                             $y_max = intval($label);
                         }
                         // y2 value
                     } elseif ($index == $y2_index) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($y2_values, $label);
                         } else {
                             $y_values[] = $label;
                         }
                         if (!isset($y_min) || intval($label) < $y_min) {
                             $y_min = intval($label);
                         }
                         if (!isset($y_max) || intval($label) > $y_max) {
                             $y_max = intval($label);
                         }
                         // y3 value
                     } elseif ($index == $y3_index) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($y3_values, $label);
                         } else {
                             $y_values[] = $label;
                         }
                         if (!isset($y_min) || intval($label) < $y_min) {
                             $y_min = intval($label);
                         }
                         if (!isset($y_max) || intval($label) > $y_max) {
                             $y_max = intval($label);
                         }
                         // we won't process the rest
                         break;
                     }
                     // next column
                     $index++;
                 }
             }
             // y minimum
             if ($y_min > 0) {
                 $y_min = 0;
             }
             // y maximum
             $y_max = strval($y_max);
             if (strlen($y_max) == 1) {
                 $y_max = 10;
             } elseif (strlen($y_max) == 2) {
                 $y_max = (intval(substr($y_max, 0, 1)) + 1) * 10;
             } elseif (strlen($y_max) == 3) {
                 $y_max = (intval(substr($y_max, 0, 2)) + 1) * 10;
             } else {
                 $y_max = strval(intval(substr($y_max, 0, 2)) + 1) . substr('0000000000000000000000000000000000000000000000000000', 0, strlen($y_max) - 2);
             }
             // data series
             $elements = array();
             if (count($y_values)) {
                 $elements[] = '{ "type":"bar_glass", "colour":"#BF3B69", "values": [ ' . join(',', $y_values) . ' ], "text": ' . $y_title . ', "font-size": 12 }';
             }
             if (count($y2_values)) {
                 $elements[] = '{ "type": "line", "width": 1, "colour": "#5E4725", "values": [ ' . join(',', $y2_values) . ' ], "text": ' . $y2_title . ', "font-size": 12 }';
             }
             if (count($y3_values)) {
                 $elements[] = '{ "type":"bar_glass", "colour":"#5E0722", "values": [ ' . join(',', $y3_values) . ' ], "text": ' . $y3_title . ', "font-size": 12 }';
             }
             // the full setup
             $text = '{ "elements": [ ' . join(',', $elements) . ' ], "x_axis": { "offset": false, "steps": 1, "labels": { "steps": 3, "rotate": 310, "labels": [ ' . join(',', $x_labels) . ' ] } }, "y_axis": { "min": ' . $y_min . ', "max": ' . $y_max . ' } }';
             return $text;
             // first number
         // first number
         case 'column':
             // comma separated values
             $separator = ",";
             // process every table row
             while ($row = SQL::fetch($rows)) {
                 // not always the first column
                 $index = 0;
                 foreach ($row as $name => $value) {
                     $index++;
                     // skip dates and links
                     if ($index == 1 && $table['with_zoom'] != 'N') {
                         continue;
                     }
                     // glue cells
                     if ($text) {
                         $text .= $separator;
                     }
                     // clean spaces
                     $label = trim(preg_replace('/\\s/', ' ', $value));
                     // encode in iso8859
                     $label = utf8::to_iso8859($label);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // quote data
                     if (preg_match('/[^a-zA-Z0-9\\,\\.\\-_]/', $label)) {
                         $text .= '"' . $label . '"';
                     } else {
                         $text .= $label;
                     }
                     // only first column
                     break;
                 }
             }
             return $text;
             // produce a raw table
         // produce a raw table
         case 'raw':
             // comma separated values
             $separator = ",";
             // process every table row
             while ($row = SQL::fetch($rows)) {
                 // one cell at a time
                 $index = 0;
                 foreach ($row as $name => $value) {
                     // glue cells
                     if ($index++) {
                         $text .= $separator;
                     }
                     // clean spaces
                     $label = trim(preg_replace('/\\s/', ' ', $value));
                     // encode in iso8859
                     $label = utf8::to_iso8859($label);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // make a link if this is a reference
                     if ($index == 0 && $table['with_zoom'] == 'Y') {
                         $label = $context['url_to_home'] . $context['url_to_root'] . $label;
                     }
                     // quote data
                     if (preg_match('/[^a-zA-Z0-9\\-_]/', $label)) {
                         $text .= '"' . $label . '"';
                     } else {
                         $text .= $label;
                     }
                 }
                 // new line
                 $text .= "\n";
             }
             return $text;
             // a simple table
         // a simple table
         case 'simple':
             $text .= Skin::table_prefix('table');
             // columns headers
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $cells[] = ucfirst($field->name);
             }
             $text .= Skin::table_row($cells, 'header');
             // other rows
             while ($row = SQL::fetch_row($rows)) {
                 $text .= Skin::table_row($row, $count++);
             }
             $text .= Skin::table_suffix();
             return $text;
             // xml table
         // xml table
         case 'xml':
             $text = '';
             while ($row = SQL::fetch($rows)) {
                 $text .= '	<item>' . "\n";
                 foreach ($row as $name => $value) {
                     $type = preg_replace('/[^a-z0-9]+/i', '_', $name);
                     if (preg_match('/^[^a-z]/i', $type)) {
                         $type = '_' . $type;
                     }
                     $text .= '		<' . $type . '>' . preg_replace('/&(?!(amp|#\\d+);)/i', '&amp;', utf8::transcode(str_replace(array('left=', 'right='), '', $value))) . '</' . $type . '>' . "\n";
                 }
                 $text .= '	</item>' . "\n\n";
             }
             return '<?xml version="1.0" encoding="' . $context['charset'] . '"?>' . "\n" . '<items>' . "\n" . $text . '</items>' . "\n";
     }
 }
Exemplo n.º 5
0
Arquivo: utf8.php Projeto: rair/yacs
 /**
  * transcode multi-byte characters to HTML representations for Unicode
  *
  * This function is aiming to preserve Unicode characters through storage in a ISO-8859-1 compliant system.
  *
  * Every multi-byte UTF-8 character is transformed to its equivalent HTML numerical entity (eg, &amp;#4568;)
  * that may be handled safely by PHP and by MySQL.
  *
  * Of course, this solution does not allow for full-text search in the database and therefore, is not a
  * definitive solution to internationalization issues.
  * It does enable, however, practical use of Unicode to build pages in foreign languages.
  *
  * Also, this function transforms HTML entities into their equivalent Unicode entities.
  * For example, w.bloggar posts pages using HTML entities.
  * If you have to modify these pages using web forms, you would like to get UTF-8 instead.
  *
  * @link http://www.evolt.org/article/A_Simple_Character_Entity_Chart/17/21234/ A Simple Character Entity Chart
  *
  * @param mixed the original UTF-8 string, or an array
  * @return a string acceptable in an ISO-8859-1 storage system (ie., PHP4 + MySQL 3)
  */
 public static function &to_unicode($input)
 {
     global $context;
     // transcode arrays as well
     if (is_array($input)) {
         utf8::to_unicode_recursively($input);
         $output = $input;
         return $output;
     }
     // scan the whole string
     $output = '';
     $index = 0;
     $tick = 0;
     while ($index < strlen($input)) {
         // for jumbo pages --observed 167 seconds processing time for 414kbyte input
         $tick++;
         if (!($tick % 25000)) {
             Safe::set_time_limit(30);
         }
         // look at one char
         $char = ord($input[$index]);
         // one byte (0xxxxxxx)
         if ($char < 0x80) {
             // some chars may be undefined
             $output .= chr($char);
             $index += 1;
             // two bytes (110xxxxx 10xxxxxx)
         } elseif ($char < 0xe0) {
             // strip weird sequences (eg, C0 80 -> NUL)
             if ($value = $char % 0x20 * 0x40 + ord($input[$index + 1]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 2;
             // three bytes (1110xxxx 10xxxxxx 10xxxxxx) example: euro sign = \xE2\x82\xAC -> &#8364;
         } elseif ($char < 0xf0) {
             // strip weird sequences
             if ($value = $char % 0x10 * 0x1000 + ord($input[$index + 1]) % 0x40 * 0x40 + ord($input[$index + 2]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 3;
             // four bytes (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx)
         } elseif ($char < 0xf8) {
             // strip weird sequences
             if ($value = $char % 0x8 * 0x40000 + ord($input[$index + 1]) % 0x40 * 0x1000 + ord($input[$index + 2]) % 0x40 * 0x40 + ord($input[$index + 3]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 4;
             // five bytes (111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
         } elseif ($char < 0xfc) {
             // strip weird sequences
             if ($value = $char % 0x4 * 0x1000000 + ord($input[$index + 1]) % 0x40 * 0x40000 + ord($input[$index + 2]) % 0x40 * 0x1000 + ord($input[$index + 3]) % 0x40 * 0x40 + ord($input[$index + 4]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 5;
             // six bytes (1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
         } else {
             // strip weird sequences
             if ($value = $char % 0x2 * 0x40000000 + ord($input[$index + 1]) % 0x40 * 0x1000000 + ord($input[$index + 2]) % 0x40 * 0x40000 + ord($input[$index + 3]) % 0x40 * 0x1000 + ord($input[$index + 4]) % 0x40 * 0x40 + ord($input[$index + 4]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 6;
         }
     }
     // transcode explicit unicode entities %u2019 -> &#8217;
     $output = preg_replace_callback('/%u([0-9a-z]{4})/is', function ($matches) {
         return '&#' . hexdec($matches[1]);
     }, $output);
     // transcode HTML entities to Unicode entities
     $output =& utf8::transcode($output);
     // translate extended ISO8859-1 chars, if any, to utf-8
     $output = utf8_encode($output);
     // return the translated string
     return $output;
 }
Exemplo n.º 6
0
 /**
  * get some introductory text from an article
  *
  * This function is used to introduce comments, or any sub-item related to an anchor.
  * Compared to the standard anchor implementation, this one adds the ability to handle overlay data.
  *
  * If there is some introductory text, it is used. Else the description text is used instead.
  * The number of words is capped in both cases.
  *
  * Also, the number of remaining words is provided.
  *
  * Following variants may be selected to adapt to various situations:
  * - 'basic' - strip every tag, we want almost plain ASCII - maybe this will be send in a mail message
  * - 'hover' - some text to be displayed while hovering a link
  * - 'quote' - strip most HTML tags
  * - 'teaser' - limit the number of words, tranform YACS codes, and link to permalink
  *
  * @see shared/anchor.php
  *
  * @param string an optional variant, including
  * @return NULL, of some text
  */
 function &get_teaser($variant = 'basic')
 {
     global $context;
     // no item bound
     if (!isset($this->item['id'])) {
         $text = NULL;
         return $text;
     }
     // the text to be returned
     $text = '';
     // use the introduction field, if any
     if ($this->item['introduction']) {
         $text = trim($this->item['introduction']);
         // may be rendered as an empty strings
         if ($variant != 'hover') {
             // remove toc and toq codes
             $text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
             // render all codes
             if (is_callable(array('Codes', 'beautify'))) {
                 $text = Codes::beautify($text, $this->item['options']);
             }
         }
         // combine with description
         if ($variant == 'quote') {
             $text .= BR . BR;
         }
     }
     // use overlay data, if any
     if (!$text) {
         if (!isset($this->overlay) && isset($this->item['overlay'])) {
             $this->overlay = Overlay::load($this->item, 'article:' . $this->item['id']);
         }
         if (is_object($this->overlay)) {
             $text .= $this->overlay->get_text('list', $this->item);
         }
     }
     // use the description field, if any
     $in_description = FALSE;
     if (!$text && $variant != 'hover') {
         $text .= trim($this->item['description']);
         $in_description = TRUE;
         // remove toc and toq codes
         $text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
         // render all codes
         if ($variant == 'teaser' && is_callable(array('Codes', 'beautify'))) {
             $text = Codes::beautify($text, $this->item['options']);
         }
     }
     // turn html entities to unicode entities
     $text = utf8::transcode($text);
     // now we have to process the provided text
     switch ($variant) {
         // strip everything
         case 'basic':
         default:
             // strip every HTML and limit the size
             if (is_callable(array('Skin', 'strip'))) {
                 $text = Skin::strip($text, 70, NULL, '');
             }
             // done
             return $text;
             // some text for pop-up panels
         // some text for pop-up panels
         case 'hover':
             // strip every HTML and limit the size
             if (is_callable(array('Skin', 'strip'))) {
                 $text = Skin::strip($text, 70, NULL, '');
             }
             // ensure we have some text
             if (!$text) {
                 $text = i18n::s('View the page');
             }
             // mention shortcut to article
             if (Surfer::is_associate()) {
                 $text .= ' [article=' . $this->item['id'] . ']';
             }
             // done
             return $text;
             // quote this
         // quote this
         case 'quote':
             // strip every HTML and limit the size
             if (is_callable(array('Skin', 'strip'))) {
                 $text = Skin::strip($text, 300, NULL, '<a><b><br><i><img><strong><u>');
             }
             // done
             return $text;
             // preserve as much as possible
         // preserve as much as possible
         case 'teaser':
             // lower level of titles
             $text = str_replace(array('<h4', '</h4'), array('<h5', '</h5'), $text);
             $text = str_replace(array('<h3', '</h3'), array('<h4', '</h4'), $text);
             $text = str_replace(array('<h2', '</h2'), array('<h3', '</h3'), $text);
             // limit the number of words
             if (is_callable(array('Skin', 'cap'))) {
                 $text = Skin::cap($text, WORDS_IN_TEASER, $this->get_url());
             }
             // done
             return $text;
     }
 }
Exemplo n.º 7
0
 /**
  * get some introductory text from a section
  *
  * This function is used to introduce comments, or any sub-item related to an anchor.
  * Compared to the standard anchor implementation, this one adds the ability to handle overlay data.
  *
  * If there is some introductory text, it is used. Else the description text is used instead.
  * The number of words is capped in both cases.
  *
  * Also, the number of remaining words is provided.
  *
  * Following variants may be selected to adapt to various situations:
  * - 'basic' - strip every tag, we want almost plain ASCII - maybe this will be send in a mail message
  * - 'hover' - some text to be displayed while hovering a link
  * - 'quote' - transform YACS codes, then strip most HTML tags
  * - 'teaser' - limit the number of words, tranform YACS codes, and link to permalink
  *
  * @see shared/anchor.php
  *
  * @param string an optional variant
  * @return NULL, of some text
  */
 function &get_teaser($variant = 'basic')
 {
     global $context;
     // nothing to do
     if (!isset($this->item['id'])) {
         $text = NULL;
         return $text;
     }
     // the text to be returned
     $text = '';
     // use the introduction field, if any
     if ($this->item['introduction']) {
         $text = trim($this->item['introduction']);
         // may be rendered as an empty strings
         if ($variant != 'hover') {
             // remove toc and toq codes
             $text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
             // render all codes
             if (is_callable(array('Codes', 'beautify'))) {
                 $text =& Codes::beautify($text, $this->item['options']);
             }
         }
         // remove most html
         if ($variant != 'teaser') {
             $text = xml::strip_visible_tags($text);
         }
         // combine with description
         if ($variant == 'quote') {
             $text .= BR . BR;
         }
     }
     // use overlay data, if any
     if (!$text) {
         $overlay = Overlay::load($this->item, 'section:' . $this->item['id']);
         if (is_object($overlay)) {
             $text .= $overlay->get_text('list', $this->item);
         }
     }
     // use the description field, if any
     $in_description = FALSE;
     if (!$text && $variant != 'hover' || $variant == 'quote') {
         $text .= trim($this->item['description']);
         $in_description = TRUE;
         // remove toc and toq codes
         $text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
         // render all codes
         if (is_callable(array('Codes', 'beautify'))) {
             $text =& Codes::beautify($text, $this->item['options']);
         }
         // remove most html
         $text = xml::strip_visible_tags($text);
     }
     // turn html entities to unicode entities
     $text =& utf8::transcode($text);
     // now we have to process the provided text
     switch ($variant) {
         // strip everything
         case 'basic':
         default:
             // remove most html
             $text = xml::strip_visible_tags($text);
             // limit the number of words
             $text =& Skin::cap($text, 70);
             // done
             return $text;
             // some text for pop-up panels
         // some text for pop-up panels
         case 'hover':
             // remove most html
             $text = xml::strip_visible_tags($text);
             // limit the number of words
             $text =& Skin::strip($text, 70);
             // ensure we have some text
             if (!$text) {
                 $text = i18n::s('View the page');
             }
             // mention shortcut to section
             if (Surfer::is_associate()) {
                 $text .= ' [section=' . $this->item['id'] . ']';
             }
             // done
             return $text;
             // quote this
         // quote this
         case 'quote':
             // remove most html
             $text = xml::strip_visible_tags($text);
             // limit the number of words
             $text =& Skin::cap($text, 300);
             // done
             return $text;
             // preserve as much as possible
         // preserve as much as possible
         case 'teaser':
             // limit the number of words
             $text =& Skin::cap($text, 12, $this->get_url());
             // done
             return $text;
     }
 }
Exemplo n.º 8
0
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    // react to overlaid POST by a overlaid response
    global $render_overlaid;
    if ($render_overlaid) {
        $context['text'] .= '<div class="hidden require-overlaid"></div>' . "\n";
    }
    // target user statut doesn't allow MP, except from associates
    if (!Surfer::is_associate() && ($overlay->attributes['user_status'] == 'donotdisturb' || $overlay->attributes['user_status'] == 'anonymous' || $item['without_alerts'] == 'Y')) {
        $context['text'] .= sprintf(i18n::s('Sorry, %s wish not to receive private message'), $item['nick_name']);
        render_skin();
        finalize_page(TRUE);
    }
    // the new thread
    $article = array();
    $article['anchor'] = $anchor;
    $article['title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : utf8::transcode(Skin::build_date(gmstrftime('%Y-%m-%d %H:%M:%S GMT'), 'full'));
    $article['active_set'] = 'N';
    // this is private
    $article['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S');
    // no review is required
    $article['options'] = 'view_as_zic_pm';
    // include some overlay
    $overlay = Overlay::bind('thread');
    $article['overlay'] = $overlay->save();
    $article['overlay_id'] = $overlay->get_id();
    // ensure everything is positioned as expected
    Surfer::empower();
    // post the new thread
    if (!($article['id'] = Articles::post($article))) {
        Logger::error(i18n::s('Impossible to add a page.'));
    } else {
Exemplo n.º 9
0
Arquivo: i18n.php Projeto: rair/yacs
 /**
  * lookup a localised string in an array
  *
  * This can be used to parse manifest files for example.
  *
  * This function also transcode HTML entities to Unicode entities, if any.
  *
  * @param array the array containing localized strings
  * @param string the label identifying string
  * @param string desired language, if any
  * @return string the localized string, if any
  */
 public static function &l(&$strings, $name, $forced = '')
 {
     global $context;
     // sanity check
     if (!$name) {
         return $name;
     }
     // select a string
     if ($forced && ($key = $name . '_' . $forced) && array_key_exists($key, $strings)) {
         $text = $strings[$key];
     } elseif (($key = $name . '_' . $context['language']) && array_key_exists($key, $strings)) {
         $text = $strings[$key];
     } elseif (($key = $name . '_en') && array_key_exists($key, $strings)) {
         $text = $strings[$key];
     } elseif (array_key_exists($name, $strings)) {
         $text = $strings[$name];
     } else {
         $text = $name;
         if ($context['with_debug'] == 'Y') {
             logger::remember('i18n/i18n.php: ' . $name . ' is not localized', '', 'debug');
         }
     }
     // the file may be absent during updates
     Safe::load('shared/utf8.php');
     // transcode to utf8
     if (isset($context['charset']) && $context['charset'] == 'utf-8' && is_callable(array('utf8', 'transcode'))) {
         $text =& utf8::transcode($text);
     }
     return $text;
 }