* * Author: Jane * * *\endcode * @param string $plugin the name of the plugin * @return array with the plugin information */ function get_plugin_info($plugin){ $m = array(); $info = array( 'name' => $plugin, 'description' => '', 'author' => array(), 'maintainer' => array(), 'version' => '', 'requires' => '' ); if (!is_file("addon/$plugin/$plugin.php")) return $info; $f = file_get_contents("addon/$plugin/$plugin.php"); $r = preg_match("|/\*.*\*/|msU", $f, $m); if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { $l = trim($l, "\t\n\r */"); if ($l != ""){ list($k, $v) = array_map("trim", explode(":", $l, 2)); $k = strtolower($k); if ($k == 'author' || $k == 'maintainer'){ $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); if ($r) { $info[$k][] = array('name' => $m[1], 'link' => $m[2]); } else { $info[$k][] = array('name' => $v); } } else { $info[$k] = $v; } } } } return $info; } function check_plugin_versions($info) { if(! is_array($info)) return true; if(array_key_exists('minversion',$info)) { if(! version_compare(STD_VERSION,trim($info['minversion']), '>=')) { logger('minversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } } if(array_key_exists('maxversion',$info)) { if(version_compare(STD_VERSION,trim($info['maxversion']), '>')) { logger('maxversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } } if(array_key_exists('minphpversion',$info)) { if(! version_compare(PHP_VERSION,trim($info['minphpversion']), '>=')) { logger('minphpversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } } if(array_key_exists('serverroles',$info)) { $role = \Zotlabs\Lib\System::get_server_role(); if(! ( stristr($info['serverroles'],'*') || stristr($info['serverroles'],'any') || stristr($info['serverroles'],$role))) { logger('serverrole limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } } if(array_key_exists('requires',$info)) { $arr = explode(',',$info['requires']); $found = true; if($arr) { foreach($arr as $test) { $test = trim($test); if(! $test) continue; if(strpos($test,'.')) { $conf = explode('.',$test); if(get_config(trim($conf[0]),trim($conf[1]))) return true; else return false; } if(! in_array($test,App::$plugins)) $found = false; } } if(! $found) return false; } return true; } /** * @brief Parse theme comment in search of theme infos. * * like * \code * * Name: My Theme * * Description: My Cool Theme * * Version: 1.2.3 * * Author: John * * Maintainer: Jane * * Compat: Friendica [(version)], Red [(version)] * * * \endcode * @param string $theme the name of the theme * @return array */ function get_theme_info($theme){ $m = array(); $info = array( 'name' => $theme, 'description' => '', 'author' => array(), 'version' => '', 'minversion' => '', 'maxversion' => '', 'compat' => '', 'credits' => '', 'maintainer' => array(), 'experimental' => false, 'unsupported' => false ); if(file_exists("view/theme/$theme/experimental")) $info['experimental'] = true; if(file_exists("view/theme/$theme/unsupported")) $info['unsupported'] = true; if (!is_file("view/theme/$theme/php/theme.php")) return $info; $f = file_get_contents("view/theme/$theme/php/theme.php"); $r = preg_match("|/\*.*\*/|msU", $f, $m); if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { $l = trim($l, "\t\n\r */"); if ($l != ""){ list($k, $v) = array_map("trim", explode(":", $l, 2)); $k = strtolower($k); if ($k == 'author'){ $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); if ($r) { $info['author'][] = array('name' => $m[1], 'link' => $m[2]); } else { $info['author'][] = array('name' => $v); } } elseif ($k == 'maintainer'){ $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); if ($r) { $info['maintainer'][] = array('name' => $m[1], 'link' => $m[2]); } else { $info['maintainer'][] = array('name' => $v); } } else { if (array_key_exists($k, $info)){ $info[$k] = $v; } } } } } return $info; } /** * @brief Returns the theme's screenshot. * * The screenshot is expected as view/theme/$theme/img/screenshot.[png|jpg]. * * @param sring $theme The name of the theme * @return string */ function get_theme_screenshot($theme) { $exts = array('.png', '.jpg'); foreach($exts as $ext) { if(file_exists('view/theme/' . $theme . '/img/screenshot' . $ext)) return(z_root() . '/view/theme/' . $theme . '/img/screenshot' . $ext); } return(z_root() . '/images/blank.png'); } /** * @brief add CSS to \ * * @param string $src * @param string $media change media attribute (default to 'screen') */ function head_add_css($src, $media = 'screen') { App::$css_sources[] = array($src, $media); } function head_remove_css($src, $media = 'screen') { $index = array_search(array($src, $media), App::$css_sources); if($index !== false) unset(App::$css_sources[$index]); } function head_get_css() { $str = ''; $sources = App::$css_sources; if(count($sources)) { foreach($sources as $source) $str .= format_css_if_exists($source); } return $str; } function head_add_link($arr) { if($arr) { App::$linkrel[] = $arr; } } function head_get_links() { $str = ''; $sources = App::$linkrel; if(count($sources)) { foreach($sources as $source) { if(is_array($source) && count($source)) { $str .= ' $v) { $str .= ' ' . $k . '="' . $v . '"'; } $str .= ' />' . "\r\n"; } } } return $str; } function format_css_if_exists($source) { // script_path() returns https://yoursite.tld $path_prefix = script_path(); $script = $source[0]; if(strpos($script, '/') !== false) { // The script is a path relative to the server root $path = $script; // If the url starts with // then it's an absolute URL if(substr($script,0,2) === '//') { $path_prefix = ''; } } else { // It's a file from the theme $path = '/' . theme_include($script); } if($path) { $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; return '' . "\r\n"; } } /* * This basically calculates the baseurl. We have other functions to do that, but * there was an issue with script paths and mixed-content whose details are arcane * and perhaps lost in the message archives. The short answer is that we're ignoring * the URL which we are "supposed" to use, and generating script paths relative to * the URL which we are currently using; in order to ensure they are found and aren't * blocked due to mixed content issues. */ function script_path() { if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) $scheme = 'https'; elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) $scheme = 'https'; elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') $scheme = 'https'; else $scheme = 'http'; // Some proxy setups may require using http_host if(intval(App::$config['system']['script_path_use_http_host'])) $server_var = 'HTTP_HOST'; else $server_var = 'SERVER_NAME'; if(x($_SERVER,$server_var)) { $hostname = $_SERVER[$server_var]; } else { return z_root(); } return $scheme . '://' . $hostname; } function head_add_js($src, $priority = 0) { if(! is_array(App::$js_sources[$priority])) App::$js_sources[$priority] = array(); App::$js_sources[$priority][] = $src; } function head_remove_js($src, $priority = 0) { $index = array_search($src, App::$js_sources[$priority]); if($index !== false) unset(App::$js_sources[$priority][$index]); } // We should probably try to register main.js with a high priority, but currently we handle it // separately and put it at the end of the html head block in case any other javascript is // added outside the head_add_js construct. function head_get_js() { $str = ''; if(App::$js_sources) { ksort(App::$js_sources,SORT_NUMERIC); foreach(App::$js_sources as $sources) { if(count($sources)) { foreach($sources as $source) { if($source === 'main.js') continue; $str .= format_js_if_exists($source); } } } } return $str; } function head_get_main_js() { $str = ''; $sources = array('main.js'); if(count($sources)) foreach($sources as $source) $str .= format_js_if_exists($source,true); return $str; } function format_js_if_exists($source) { $path_prefix = script_path(); if(strpos($source,'/') !== false) { // The source is a known path on the system $path = $source; // If the url starts with // then it's an absolute URL if(substr($source,0,2) === '//') { $path_prefix = ''; } } else { // It's a file from the theme $path = '/' . theme_include($source); } if($path) { $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; return '' . "\r\n" ; } } function theme_include($file, $root = '') { // Make sure $root ends with a slash / if it's not blank if($root !== '' && $root[strlen($root)-1] !== '/') $root = $root . '/'; $theme_info = App::$theme_info; if(array_key_exists('extends',$theme_info)) $parent = $theme_info['extends']; else $parent = 'NOPATH'; $theme = Zotlabs\Render\Theme::current(); $thname = $theme[0]; $ext = substr($file,strrpos($file,'.')+1); $paths = array( "{$root}view/theme/$thname/$ext/$file", "{$root}view/theme/$parent/$ext/$file", "{$root}view/site/$ext/$file", "{$root}view/$ext/$file", ); foreach($paths as $p) { // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php) if(strpos($p,'NOPATH') !== false) continue; if(file_exists($p)) return $p; } return ''; } function get_intltext_template($s, $root = '') { $t = App::template_engine(); $template = $t->get_intltext_template($s, $root); return $template; } function get_markup_template($s, $root = '') { $t = App::template_engine(); $template = $t->get_markup_template($s, $root); return $template; } function folder_exists($folder) { // Get canonicalized absolute pathname $path = realpath($folder); // If it exist, check if it's a directory return (($path !== false) && is_dir($path)) ? $path : false; }