function actionDefault() { // Test the formatting of filesizes $filesizes = array('1152921504606846977', '1125899906842625', '1099511627777', '75715455455', '1048577', '6543', '42'); // Format the filesizes foreach ($filesizes as $filesize) { YDDebugUtil::dump(YDStringUtil::formatFileSize($filesize), 'Formatting filesize: ' . $filesize); } // Test the formatDate function YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'date'), 'Formatting date - date'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'time'), 'Formatting date - time'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'datetime'), 'Formatting date - datetime'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), '%x'), 'Formatting date - %x'); // Test the encode string function $string = 'Pieter Claerhout @ creo.com "générales obsolète"'; YDDebugUtil::dump(YDStringUtil::encodeString($string), 'Encoding: ' . $string); // Test the truncate function YDDebugUtil::dump(YDStringUtil::truncate($string), 'Truncate (default): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20), 'Truncate (20): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]'), 'Truncate (20/more): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]', true), 'Truncate (20/more/true): ' . $string); // Test the normalizing of newlines $string = "line1\nline2\rline3\r\nline4"; YDDebugUtil::dump(explode("\n", $string), 'Original string'); YDDebugUtil::dump(explode(YD_CRLF, YDStringUtil::normalizeNewlines($string)), 'normalizeNewlines'); // Test the normalizing of newlines $string = " line1 \n line2 \r line3 \r\n line4 "; YDDebugUtil::dump(YDStringUtil::removeWhiteSpace($string), 'removeWhiteSpace'); }
/** * This function will add a new item to the feed. You need to at least give in a title, link. A description is * advised but optional. Also a GUID is optional. If no GUID is given, an automatic one will be created which * is the md5 checksum of the different elememts. * * @param $title The title of the feed item. * @param $link The link to the feed item. * @param $desc (optional) The description for the feed item. * @param $guid (optional) The guid for the feed item. * @param $enclosure (optional) The url of the enclosure. * @param $enclosure_size (optional) The size in bytes of the enclosure. * @param $enclosure_type (optional) The mime-type of the enclosure. * @param $commentlink (optional) The link to the comment page for the item. * * @remark * Enclosures are only supported for ATOM and RSS 2.0 feeds. */ function addItem($title, $link, $desc = null, $guid = null, $enclosure = null, $enclosure_size = null, $enclosure_type = null, $commentlink = null) { $link = YDUrl::makeLinkAbsolute($link, $this->_link); $desc = YDUrl::makeLinksAbsolute($desc, $this->_link); if (empty($guid)) { $checkSum = $this->_link . $title . $link; if ($desc != null) { $checkSum .= $desc; } $guid = md5($checkSum); } if (!is_null($enclosure) && (is_null($enclosure_size) || is_null($enclosure_type))) { trigger_error('Enclosures must have both type and size specified!', YD_ERROR); } $item = array('title' => $this->_encodeStrings ? YDStringUtil::encodeString($title) : $title, 'link' => $link, 'description' => $this->_encodeStrings ? YDStringUtil::encodeString($desc) : $desc, 'guid' => $guid, 'enclosure' => $enclosure, 'enclosure_size' => $enclosure_size, 'enclosure_type' => $enclosure_type, 'comments' => $commentlink); $this->_items[$guid] = $item; }
/** * This function will return the feed in the specified format. The following formats are recognized: RSS0.91, * RSS1.0, RSS2.0, ATOM * * @remark * The default format is "RSS2.0". If you specify no argument indicating the requested format, the "RSS2.0" * format will be used. * * @param $format (optional) The format in which the items should be converted. * * @returns String with the data in the requested format. */ function toXml($format = 'RSS2.0') { // Convert the format to uppercase $format = strtoupper($format); // Check if the format is an allowed one if (!in_array($format, array('RSS0.91', 'RSS1.0', 'RSS2.0', 'ATOM'))) { trigger_error('The YDFeedCreator does not support the format called "' . $format . '". Only the formats "RSS0.91"' . ', "RSS1.0", "RSS2.0" and "ATOM" are supported.', YD_ERROR); } // Start with the first XML line $xml = '<?xml version="1.0" encoding="' . $this->_encoding . '"?>'; // Formatter for RSS 0.91 if ($format == 'RSS0.91' || $format == 'RSS2.0') { if ($format == 'RSS0.91') { $xml .= '<rss version="0.91">'; } else { $xml .= '<rss version="2.0">'; } $xml .= '<channel>'; $xml .= '<title>' . $this->_title . '</title>'; if (!empty($this->_description)) { $xml .= '<description>' . $this->_description . '</description>'; } $xml .= '<link>' . $this->_link . '</link>'; $xml .= '<generator>' . $this->_generator . '</generator>'; foreach ($this->_items as $item) { $item['description'] = YDStringUtil::encodeString($item['description'], true); $xml .= '<item>'; $xml .= '<title>' . $item['title'] . '</title>'; $xml .= '<link>' . $item['link'] . '</link>'; $xml .= '<guid isPermanlink="false">' . $item['guid'] . '</guid>'; if (!empty($item['description'])) { $xml .= '<description>' . $item['description'] . '</description>'; } $xml .= '</item>'; } $xml .= '</channel>'; $xml .= '</rss>'; } // Formatter for RSS1.0 if ($format == 'RSS1.0') { $xml .= '<rdf:RDF'; $xml .= ' xmlns="http://purl.org/rss/1.0/"'; $xml .= ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'; $xml .= ' xmlns:dc="http://purl.org/dc/elements/1.1/">'; $xml .= '<channel rdf:about="">'; $xml .= '<title>' . $this->_title . '</title>'; $xml .= '<description>' . $this->_description . '</description>'; $xml .= '<link>' . $this->_link . '</link>'; $xml .= '<items>'; $xml .= '<rdf:Seq>'; foreach ($this->_items as $item) { $xml .= '<rdf:li rdf:resource="' . $item['link'] . '"/>'; } $xml .= '</rdf:Seq>'; $xml .= '</items>'; $xml .= '</channel>'; foreach ($this->_items as $item) { $item['description'] = YDStringUtil::encodeString($item['description'], true); $xml .= '<item rdf:about="' . $item['link'] . '">'; $xml .= '<dc:format>text/html</dc:format>'; $xml .= '<title>' . $item['title'] . '</title>'; $xml .= '<link>' . $item['link'] . '</link>'; if (!empty($item['description'])) { $xml .= '<description>' . $item['description'] . '</description>'; } $xml .= '</item>'; } $xml .= '</rdf:RDF>'; } // Formatter for ATOM if ($format == 'ATOM') { $xml .= '<feed version="0.3" xmlns="http://purl.org/atom/ns#">'; $xml .= '<title>' . $this->_title . '</title>'; if (!empty($this->_description)) { $xml .= '<tagline>' . $this->_description . '</tagline>'; } $xml .= '<link rel="alternate" type="text/html" href="' . $this->_link . '"/>'; $xml .= '<id>' . $this->_link . '</id>'; $xml .= '<generator>' . $this->_generator . '</generator>'; foreach ($this->_items as $item) { $xml .= '<entry>'; $xml .= '<title>' . $item['title'] . '</title>'; $xml .= '<link rel="alternate" type="text/html" href="' . $item['link'] . '"/>'; $xml .= '<id>' . $item['guid'] . '</id>'; if (!empty($item['description'])) { $xml .= '<content type="text/html" mode="escaped" xml:base="' . $item['link'] . '"><![CDATA[ '; $xml .= $item['description']; $xml .= ' ]]></content>'; } $xml .= '</entry>'; } $xml .= '</feed>'; } // Return the XML return $xml; }
/** * This function will take a piece of text and convert the BBCode tags to their HTML equivalents. You can * optionally convert line breaks as well as convert the remaining HTML tags to their entities. * * @param $data The data you want to convert. * @param $convertBr (optional) Boolean to indicate that new lines should be converted to <br/> tags. * This is turned on by default. * @param $convertTags (optional) Boolean to indicate that tags should be converted to HTML. This is turned * on by default. * @param $convertLinks (optional) Boolean to indicate if links should be automatically highlighted or not. * This is turned on by default. * @param $baseUrl (optional) If you give this a non-null value, it will convert all links to absolute * links using this url as the base url. * * @returns The HTML equivalent of the string with all the BBCode's converted according to the conversion table * of this class. */ function toHtml($data, $convertBr = true, $convertTags = true, $convertLinks = true, $baseUrl = null) { // Encode the references $data = YDStringUtil::encodeString($data); // Convert the links to BBcode if ($convertLinks === true) { $data = $this->convertLinks($data); } // Convert tags if needed if ($convertTags === true) { $data = str_replace('<', '<', $data); $data = str_replace('>', '>', $data); } // Fix common problems $data = str_replace("\r\n", "\n", $data); $data = str_replace("\r", "\n", $data); $data = str_replace("[/quote]\n\n", "[/quote]\n", $data); // Convert the tags $data = $this->parser->parse($data); // Strip the leftover tags $data = trim(preg_replace('/\\[\\/[a-z]+\\]/i', '', $data)); // Open http links in a new window $data = str_replace(' href="http://', ' target="_blank" href="http://', $data); // Convert tags if needed if ($convertBr === true) { $data = nl2br(trim($data)); } // Convert smilies if needed $smilies_path = YDConfig::get('YD_BBCODE_SMILIES_DIR', ''); $smilies_url = YDConfig::get('YD_BBCODE_SMILIES_URL', ''); if (is_dir($smilies_path)) { foreach ($this->smilies as $smilie => $file) { $data = str_replace($smilie, '<img src="' . $smilies_url . '/' . $file . '" width="15" height="15" />', $data); } } // Make links absolute if needed if (!is_null($baseUrl)) { include_once dirname(__FILE__) . '/../../YDClasses/YDUrl.php'; $data = YDUrl::makeLinksAbsolute($data, $baseUrl); } // Return the data return $data; }
function YDTplModDate($text, $format = null) { if (is_null($format)) { $format = '%A, %d %b %Y'; } return YDStringUtil::encodeString(ucwords(strtolower(YDTemplate_modifier_date_format($text, $format)))); }
/** * This function will take a piece of text and convert the BBCode tags to their HTML equivalents. You can * optionally convert line breaks as well as convert the remaining HTML tags to their entities. * * @param $data The data you want to convert. * @param $convertBr (optional) Boolean to indicate that new lines should be converted to <br/> tags. * This is turned on by default. * @param $convertTags (optional) Boolean to indicate that tags should be converted to HTML. This is turned * on by default. * @param $convertLinks (optional) Boolean to indicate if links should be automatically highlighted or not. * This is turned on by default. * * @returns The HTML equivalent of the string with all the BBCode's converted according to the conversion table * of this class. */ function toHtml($data, $convertBr = true, $convertTags = true, $convertLinks = true) { // Encode the references $data = YDStringUtil::encodeString($data); // Convert the links to BBcode if ($convertLinks === true) { $data = $this->convertLinks($data); } // Convert tags if needed if ($convertTags === true) { $data = str_replace('<', '<', $data); $data = str_replace('>', '>', $data); } // Convert the tags $data = preg_replace(array_keys($this->_conversions), array_values($this->_conversions), $data); // Open http links in a new window $data = str_replace(' href="http://', ' target="_blank" href="http://', $data); // Convert tags if needed if ($convertBr === true) { $data = nl2br(trim($data)); } // Return the data return $data; }
/** * This function will take a piece of text and convert the BBCode tags to their HTML equivalents. You can * optionally convert line breaks as well as convert the remaining HTML tags to their entities. * * @param $data The data you want to convert. * @param $convertBr (optional) Boolean to indicate that new lines should be converted to <br/> tags. * This is turned on by default. * @param $convertTags (optional) Boolean to indicate that tags should be converted to HTML. This is turned * on by default. * @param $convertLinks (optional) Boolean to indicate if links should be automatically highlighted or not. * This is turned on by default. * @param $baseUrl (optional) If you give this a non-null value, it will convert all links to absolute * links using this url as the base url. * * @returns The HTML equivalent of the string with all the BBCode's converted according to the conversion table * of this class. */ function toHtml($data, $convertBr = true, $convertTags = true, $convertLinks = true, $baseUrl = null) { // Encode the references $data = YDStringUtil::encodeString($data); // Convert the links to BBcode if ($convertLinks === true) { $data = $this->convertLinks($data); } // Convert tags if needed if ($convertTags === true) { $data = str_replace('<', '<', $data); $data = str_replace('>', '>', $data); } // Convert the tags $data = preg_replace(array_keys($this->_conversions), array_values($this->_conversions), $data); // Open http links in a new window $data = str_replace(' href="http://', ' target="_blank" href="http://', $data); // Convert tags if needed if ($convertBr === true) { $data = nl2br(trim($data)); } // Make links absolute if needed if (!is_null($baseUrl)) { include_once dirname(__FILE__) . '/../../YDClasses/YDUrl.php'; $data = YDUrl::makeLinksAbsolute($data, $baseUrl); } // Return the data return $data; }