/** * Converts an array of strings to utf8 * @param array $ary input array * @return array $ary utf8 array */ public static function toUTF8Ary($ary) { $new = array(); foreach ($ary as $key => $val) { $new[$key] = strings::toUTF8($val); } return $new; }
/** * Substring without losing word meaning and * tiny words (length 3 by default) are included on the result. * "..." is added if result do not reach original string length * Found on php.net * * @param string $str string to operate on * @param int $length the maxsize of the string to return * @param int $minword minimum size of word to cut from * @param boolean $use_dots * @return string $str the substringed string * */ public static function substr2_min($str, $length, $minword = 3, $use_dots = true) { $sub = $ret = ''; $len = 0; foreach (explode(' ', $str) as $word) { $part = ($sub != '' ? ' ' : '') . $word; $sub .= $part; $len += strings::strlen($part); if (strings::strlen($word) > $minword && strings::strlen($sub) >= $length) { break; } $ret .= $part; } if ($use_dots) { return $ret . ($len < strings::strlen($str) ? '...' : ''); } return $ret; }
/** * sets all <head></head> meta info. * Params should not be encoded * @param string $title html page title * @param string $description html page description and og description * @param string $keywords keywords * @param string $image image * @param string $type og type */ public static function setMetaAll($title, $description = '', $keywords = '', $image = '', $type = '', $author = '') { // title assets::setTitle(html::specialEncode($title)); self::setMetaAsStr('<meta property="og:title" content="' . html::specialEncode($title) . '" />' . "\n"); // description if (empty($description)) { $description = conf::getMainIni('meta_desc'); } $desc = strings::substr2($description, 255); $og_desc = html::specialEncode(strings::substr2($description, 320)); if (!empty($og_desc)) { self::setMetaAsStr('<meta property="og:description" content="' . $og_desc . '"/>' . "\n"); } if (!empty($desc)) { self::setMeta(array('description' => $desc)); } if (!empty($author)) { self::setMeta(array('author' => $author)); } // keywords if (empty($keywords)) { $keywords = conf::getMainIni('meta_meywords'); } if (!empty($keywords)) { self::setMeta(array('keywords' => $keywords)); } // image if (!empty($image)) { $server = conf::getSchemeWithServerName(); $image = $server . $image; } if (!empty($image)) { self::setMetaAsStr('<meta property="og:image" content="' . $image . '"/>' . "\n"); } // type if (!empty($type)) { self::setMetaAsStr('<meta property="og:type" content="' . $type . '"/>' . "\n"); } }
/** * gets a messages attached parts * @param type $message * @return array $parts attachments */ function getParts($message) { $parts = array(); $gen_sub = false; try { $parts['subject'] = $message->subject; } catch (Exception $e) { $gen_sub = true; } $parts['plain'] = ''; $parts['images'] = array(); $parts['movies'] = array(); $parts['unknown'] = array(); $parts['date'] = $message->getHeader('Date', 'string'); $from = $message->getHeader('From', 'string'); $parts['from'] = trim($this->extractMailFrom($from)); $parts['html'] = array(); // test if it is not a multi part message if (!$message->isMultipart()) { $parts['plain'] = $this->decodePlain($message); } foreach (new RecursiveIteratorIterator($message) as $part) { try { $type = $this->getContentType($part); if ($type == 'text/plain') { // text plain $parts['plain'] = $this->decodePlain($part); } else { if ($type == 'image/jpeg' || $type == 'image/png' || $type == 'image/jpg') { // image $file = base64_decode($part->getContent()); $human = $this->getHeadersHuman($part); $parts['images'][] = array('name' => $human['content-name'], 'type' => $human['content-type'], 'file' => $file); } else { if ($type == 'text/html') { // thtml $parts['html'][] = $part->getContent(); } else { // else unknown $parts['unknown'][] = $part; } } } } catch (Exception $e) { error_log($e->getMessage()); } } if (empty($parts['plain'])) { $parts['plain'] = lang::translate('No title'); } if ($gen_sub) { $parts['subject'] = strings::substr2($parts['plain'], 20, 3, false); } return $parts; }