/** * gets a file pointer from a specified file * @param string $filename * @param array $options * @return mixed $res file pointer | true | false */ public static function getFPFromFile($filename, $options = array()) { if (isset($options)) { self::$options = $options; } if (!file_exists($filename)) { self::$errors[] = lang::translate('File does not exists') . ' : ' . $options['filename']; return false; } if (isset($options['maxsize'])) { $size = filesize($options['filename']); // check the file is less than the maximum file size if ($size > $options['maxsize']) { $error = lang::translate('File is too large.'); $error .= lang::translate('Max size is ') . bytes::bytesToGreek($options['maxsize']); error_log($error); self::$errors[] = $error; return false; } } // check for right content if (isset($options['allow_mime'])) { $type = file::getMime($options['filename']); if (!in_array($type, $options['allow_mime'])) { self::$errors[] = lang::translate('This Content type is not allowed') . MENU_SUB_SEPARATOR_SEC . $type; return false; } } $fp = fopen($filename, 'rb'); return $fp; }
protected function _doImages_inline_callback($matches) { $whole_match = $matches[1]; $alt_text = $matches[2]; $url = $matches[3] == '' ? $matches[4] : $matches[3]; $title =& $matches[7]; $alt_text = $this->encodeAttribute($alt_text); $url = $this->encodeAttribute($url); $type = $this->getType($url); if (!$this->isFigure($type, $url)) { return $str = "![{$alt_text}]({$url})"; } if (empty($alt_text)) { $alt_text = ''; } $video = lang::translate('Video'); $figure = lang::translate('Figure'); $id = uniqid(); $str = "<div id =\"{$id}\">"; $str .= '</div>'; $str .= "![{$alt_text}]({$url})"; if ($type == 'mp4') { $m = ++self::$m; self::$media['movie'][] = "{$video} {$m} [{$alt_text}](#{$id})."; } else { $f = ++self::$f; self::$media['figure'][] = "{$figure} {$f} [{$alt_text}](#{$id})."; } return $str; }
/** * checks if a user if locked * if locked set 403 error * @return boolean $res true if locked else false */ public static function lockedSet403($message = null) { if (self::locked()) { moduleloader::$status['403'] = true; if (!$message) { $message = lang::translate('You can not access this page, because your account has been locked!'); } moduleloader::$message = $message; return true; } return false; }
/** * method for creating a confirm form * @param string $legend text of the legend * @param string $submit text of the submit * @return string $form the confirm form. */ public static function confirmForm($legend, $submit_value = null, $submit_name = 'submit') { $html = new html(); $html->setAutoEncode(true); $html->formStart('custom_delete_form'); $html->legend($legend); if (!$submit_value) { $submit_value = lang::translate('Submit'); } $html->submit($submit_name, $submit_value); $html->formEnd(); return $html->getStr(); }
/** * Get translations * @return array $ary array with translations */ public function getTranslations() { if (class_exists('\\diversen\\lang')) { return array('altPrev' => \diversen\lang::translate('Previous'), 'altNext' => \diversen\lang::translate('Next page'), 'altPage' => \diversen\lang::translate('Page')); } else { return array('altPrev' => 'Previous', 'altNext' => 'Next page', 'altPage' => 'Page'); } }
/** * method for getting child menus to a module. * @param string $module * @return array children menus items */ public static function getChildrenMenus($module) { $db = new db(); $children = $db->selectAll('menus', null, array('parent' => $module)); foreach ($children as $key => $val) { $children[$key]['title'] = lang::translate($val['title']); } return $children; }
/** * 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; }
/** * getting filter help from filters * @param array $filters * @return string $filters_help */ public static function getFiltersHelp($filters) { if (empty($filters)) { return ''; } $str = '<span class="small-font">'; $i = 1; if (is_string($filters)) { $ary = array(); $ary[] = $filters; $filters = $ary; } foreach ($filters as $val) { $t = lang::translate("filter_" . $val . "_help"); if ($t == "NT: filter_" . $val . "_help") { continue; } $str .= $i . ") " . $t . "<br />"; $i++; } $str .= '</span>'; return $str; }
/** * checks if if size is allowed * @param string $filename the name of the file * @param int $maxsize bytes * @return boolean $res */ public static function checkMaxSize($file, $maxsize = null) { if (!$maxsize) { $maxsize = self::$options['maxsize']; } if ($file['size'] > $maxsize) { $error = lang::translate('File is too large.') . ' '; $error .= lang::translate('Max size is ') . ' ' . bytes::bytesToGreek($maxsize); log::error($error); self::$errors[] = $error; return false; } return true; }
/** * sets a file field with info about max file size * @param string $filename * @param int $max_bytes * @param array $options */ public static function fileWithLabel($filename, $max_bytes, $options = array()) { $bytes = bytes::getNativeMaxUpload(); if ($max_bytes < $bytes) { $bytes = $max_bytes; } self::hidden('MAX_FILE_SIZE', $bytes); $label = lang::translate('Max size per file') . ". "; $size = bytes::bytesToGreek($bytes); $label .= $size; if (isset($options['multiple'])) { $max_files = ini_get('max_file_uploads'); $label .= "<br />"; $label .= lang::translate('Max number of files: <span class="notranslate">{MAX_FILES}</span>', array('MAX_FILES' => $max_files)); } else { $label .= "<br />"; $label .= lang::translate('Only one file at a time'); } if (isset($options['allowed'])) { $label .= '<br />'; $label .= lang::translate('Allowed file-types: ') . $options['allowed']; } self::label($filename, $label); self::file($filename, $options); }
public function getAdminLink($id) { $str = html::createLink("/account/admin/edit/{$id}", lang::translate('(Admin) Edit profile')); return $str; }