function csp_po_get_theme_capabilities($theme, $values, $active) {
	$data = array();
	$data['locale'] = get_locale();
	$data['type'] = 'themes';
	$data['img_type'] = 'themes';	
	$data['type-desc'] = __('Theme',CSP_PO_TEXTDOMAIN);	
	$data['name'] = $values['Name'];
	$data['author'] = $values['Author'];
	$data['version'] = $values['Version'];
	$data['description'] = $values['Description'];
	$data['status'] = $theme == $active->name ? __("activated",CSP_PO_TEXTDOMAIN) : __("deactivated",CSP_PO_TEXTDOMAIN);
	$data['base_path'] = str_replace("\\","/", WP_CONTENT_DIR.str_replace('wp-content', '', dirname($values['Template Files'][0])).'/');
	if (file_exists($values['Template Files'][0])){
		$data['base_path'] = dirname(str_replace("\\","/",$values['Template Files'][0])).'/';
	}

	$data['special-path'] = '';
	foreach($values['Template Files'] as $themefile) {
		$main = '';
		if (!file_exists($themefile)) {
			$main = file_get_contents(WP_CONTENT_DIR.str_replace('wp-content', '', $themefile));
		}else {
			$main = file_get_contents($themefile);
		}
		if (preg_match("/load_theme_textdomain\s*\(\s*(\'|\"|)([\w\-_]+|[A-Z\-_]+)(\'|\"|)\s*(,|\))/", $main, $hits)) break;
	}
	$data['is-path-unclear'] = false;
	$data['gettext_ready'] = empty($hits) === false;
	if ($data['gettext_ready']) {
		$data['textdomain'] = array('identifier' => $hits[2], 'is_const' => empty($hits[1]) );
		$data['languages'] = array();
	
		$const_list = array();
		if (!($data['gettext_ready'] && !$data['textdomain']['is_const'])) {
			if (preg_match_all("/define\s*\(([^\)]+)\)/" , $main, $hits)) {
				$const_list = array_merge($const_list, $hits[1]);
			}
		}
		if ($data['gettext_ready']) {			
			if ($data['textdomain']['is_const']) {
				foreach($const_list as $e) {
					$a = split(',', $e);
					$c = trim($a[0], "\"' \t");
					if ($c == $data['textdomain']['identifier']) {
						$data['textdomain']['is_const'] = $data['textdomain']['identifier'];
						$data['textdomain']['identifier'] = trim($a[1], "\"' \t");
					}
				}
			}		
		}		
	
		$tmp = array();
		$dn = dirname(str_replace("\\","/",WP_CONTENT_DIR).str_replace('wp-content', '', $values['Template Files'][0]));
		if (file_exists($values['Template Files'][0])){
			$dn = dirname(str_replace("\\","/",$values['Template Files'][0]));
		}
		$files = rscandir($dn.'/', "/(.\mo|\.po|\.pot)$/", $tmp);
		$sub_dirs = array();
		foreach($files as $filename) {
			preg_match("/\/([a-z][a-z]_[A-Z][A-Z]).(mo|po)$/", $filename, $hits);
			if (empty($hits[1]) === false) {
				$data['languages'][$hits[1]][$hits[2]] = array(
					'class' => "-".(is_readable($filename) ? 'r' : '').(is_writable($filename) ? 'w' : ''),
					'stamp' => date(__('m/d/Y H:i:s',CSP_PO_TEXTDOMAIN), filemtime($filename))." ".file_permissions($filename)
				);
				$data['filename'] = '';
				$sd = dirname(str_replace($dn.'/', '', $filename));
				if ($sd == '.') $sd = '';
				if (!in_array($sd, $sub_dirs)) $sub_dirs[] = $sd;
			}
		}
		//completely other directories can be defined WP if >= 2.7.0
		global $wp_version;
		if (version_compare($wp_version, '2.7', '>=')) {
			if (count($data['languages']) == 0) {
				$data['is-path-unclear'] = has_subdirs($dn.'/');
				if ($data['is-path-unclear'] && (count($files) > 0)) {
					foreach($files as $file) {
						$f = str_replace($dn.'/', '', $file);
						if (preg_match("/^([a-z][a-z]_[A-Z][A-Z]).(mo|po|pot)$/", basename($f))) {
							$data['special_path'] = (dirname($f) == '.' ? '' : dirname($f));
							$data['is-path-unclear'] = false;
							break;
						}
					}
				}
			}
			else{
				if ($sub_dirs[0] != '') {
					$data['special_path'] = ltrim($sub_dirs[0], "/");
				}
			}
		}
	}
	
	$data['base_file'] = (empty($data['special_path']) ? '' : $data['special_path']."/");

	return $data;
}
Ejemplo n.º 2
0
function index_array($directory = "../../../data/pages/", $pattern = 'index.txt', $recursive = true)
{
    $array_items = array();
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($directory . "/" . $file)) {
                    if ($recursive) {
                        if (substr($file, 0, 4) != ".tmp" and substr($file, 0, 2) != "z_") {
                            $array_items = array_merge($array_items, index_array($directory . "/" . $file, $pattern, $recursive));
                        }
                    }
                    // No és un directori
                } else {
                    // mirar si s'inclou a la llista
                    $newdir = str_replace("//", "/", $directory) . '/';
                    $subdirs = has_subdirs($newdir);
                    $ext = substr(strtolower($file), -strlen($pattern));
                    if (!is_dir($file) && $ext == $pattern && $subdirs) {
                        $file = $directory . "/" . $file;
                        $array_items[] = preg_replace("/\\/\\//si", "/", $file);
                    }
                }
            }
        }
        closedir($handle);
    }
    foreach ($array_items as &$item) {
        $item = str_replace("../../../data/pages/", "", $item);
    }
    deleteFromArray($array_items, $pattern, $useOldKeys = FALSE);
    $result = natsort($array_items);
    return $array_items;
}
Ejemplo n.º 3
0
function csp_po_get_theme_capabilities($theme, $values, $active)
{
    $data = array();
    $data['dev-hints'] = null;
    $data['deny_scanning'] = false;
    //let's first check the whether we have a child or base theme
    if (is_object($values) && get_class($values) == 'WP_Theme') {
        //WORDPRESS Version 3.4 changes theme handling!
        $theme_root = trailingslashit(str_replace("\\", "/", get_theme_root()));
        $firstfile = array_values($values['Template Files']);
        $firstfile = array_shift($firstfile);
        $firstfile = str_replace("\\", "/", $firstfile);
        $firstfile = str_replace($theme_root, '', $firstfile);
        $firstfile = explode('/', $firstfile);
        $firstfile = reset($firstfile);
        $data['base_path'] = $theme_root . $firstfile . '/';
    } else {
        $data['base_path'] = str_replace("\\", "/", WP_CONTENT_DIR . str_replace('wp-content', '', dirname($values['Template Files'][0])) . '/');
        if (file_exists($values['Template Files'][0])) {
            $data['base_path'] = dirname(str_replace("\\", "/", $values['Template Files'][0])) . '/';
        }
    }
    $fc = explode('/', untrailingslashit($data['base_path']));
    $folder_filesys = end($fc);
    $folder_data = $values['Template'];
    $is_child_theme = $folder_filesys != $folder_data;
    $data['theme-self'] = $folder_filesys;
    $data['theme-template'] = $folder_data;
    $data['locale'] = get_locale();
    $data['type'] = 'themes';
    $data['img_type'] = $is_child_theme ? 'childthemes' : 'themes';
    $data['type-desc'] = $is_child_theme ? __('Childtheme', CSP_PO_TEXTDOMAIN) : __('Theme', CSP_PO_TEXTDOMAIN);
    $data['name'] = $values['Name'];
    $data['author'] = $values['Author'];
    $data['version'] = $values['Version'];
    $data['description'] = $values['Description'];
    $data['status'] = $values['Name'] == $active->name ? __("activated", CSP_PO_TEXTDOMAIN) : __("deactivated", CSP_PO_TEXTDOMAIN);
    //	$data['status'] = $theme == $active->name ? __("activated",CSP_PO_TEXTDOMAIN) : __("deactivated",CSP_PO_TEXTDOMAIN);
    if ($is_child_theme) {
        $data['status'] .= ' / <b></i>' . __('child theme of', CSP_PO_TEXTDOMAIN) . ' ' . $values['Parent Theme'] . '</i></b>';
    }
    $data['special-path'] = '';
    $data['is-path-unclear'] = false;
    $data['gettext_ready'] = false;
    $data['translation_template'] = null;
    $data['is-simple'] = false;
    $data['simple-filename'] = '';
    //now scanning the child's own files
    $parent_files = array();
    $files = array();
    $const_list = array();
    $tmp = array();
    $files = rscandir($data["base_path"], "/\\.(php|phtml)\$/", $tmp);
    foreach ($files as $themefile) {
        $main = file_get_contents($themefile);
        if (preg_match("/[^_^!]load_(child_theme_|theme_|)textdomain\\s*\\(\\s*(\\'|\"|)([\\w\\d\\-_]+|[A-Z\\d\\-_]+)(\\'|\"|)\\s*(,|\\))/", $main, $hits) || preg_match("/[^_^!]load_(child_theme_|theme_|)textdomain\\s*\\(\\s*/", $main, $hits)) {
            if (isset($hits[1]) && $hits[1] != 'child_theme_' && $hits[1] != 'theme_') {
                $data['dev-hints'] = __("<strong>Loading Issue: </strong>Author is using <em>load_textdomain</em> instead of <em>load_theme_textdomain</em> or <em>load_child_theme_textdomain</em> function. This may break behavior of WordPress, because some filters and actions won't be executed anymore. Please contact the Author about that.", CSP_PO_TEXTDOMAIN);
            }
            //fallback for variable names used to load textdomain, assumes theme name
            if (isset($hits[3]) && strpos($hits[3], '$') !== false) {
                unset($hits[3]);
                if (isset($data['dev-hints'])) {
                    $data['dev-hints'] .= "<br/><br/>";
                }
                $data['dev-hints'] = __("<strong>Textdomain Naming Issue: </strong>Author uses a variable to load the textdomain. It will be assumed to be equal to theme name now.", CSP_PO_TEXTDOMAIN);
            }
            //make it short
            $data['gettext_ready'] = true;
            if ($data['gettext_ready']) {
                if (!isset($hits[3])) {
                    $data['textdomain'] = array('identifier' => $values['Template'], 'is_const' => false);
                } else {
                    $data['textdomain'] = array('identifier' => $hits[3], 'is_const' => empty($hits[2]));
                }
                $data['languages'] = array();
            }
            $dn = $data["base_path"];
            $tmp = array();
            $lng_files = rscandir($dn, "/(\\.mo|\\.po|\\.pot)\$/", $tmp);
            $data['translation_template'] = csp_find_translation_template($lng_files);
            $sub_dirs = array();
            $naming_convention_error = false;
            foreach ($lng_files as $filename) {
                //somebody did place buddypress themes at sub folder hierarchy like:  themes/buddypress/bp-default
                //results at $values['Template'] to 'buddypress/bp-default' which damages the preg_match
                $v = explode('/', $values['Template']);
                $theme_langfile_check = end($v);
                preg_match("/\\/(|" . preg_quote($theme_langfile_check) . "\\-)([a-z][a-z]_[A-Z][A-Z])\\.(mo|po)\$/", $filename, $hits);
                if (empty($hits[1]) === false) {
                    $naming_convention_error = true;
                    $data['filename'] = '';
                    $sd = dirname(str_replace($dn, '', $filename));
                    if ($sd == '.') {
                        $sd = '';
                    }
                    if (!in_array($sd, $sub_dirs)) {
                        $sub_dirs[] = $sd;
                    }
                } elseif (empty($hits[2]) === false) {
                    $data['languages'][$hits[2]][$hits[3]] = array('class' => "-" . (is_readable($filename) ? 'r' : '') . (is_writable($filename) ? 'w' : ''), 'stamp' => date(__('m/d/Y H:i:s', CSP_PO_TEXTDOMAIN), filemtime($filename)) . " " . file_permissions($filename));
                    $data['filename'] = '';
                    $sd = dirname(str_replace($dn, '', $filename));
                    if ($sd == '.') {
                        $sd = '';
                    }
                    if (!in_array($sd, $sub_dirs)) {
                        $sub_dirs[] = $sd;
                    }
                }
            }
            if ($naming_convention_error && count($data['languages']) == 0) {
                if (isset($data['dev-hints'])) {
                    $data['dev-hints'] .= "<br/><br/>";
                }
                $data['dev-hints'] .= sprintf(__("<strong>Naming Issue: </strong>Author uses unsupported language file naming convention! Instead of example <em>de_DE.po</em> the non theme standard version <em>%s</em> has been used. If you translate this Theme, only renamed language files will be working!", CSP_PO_TEXTDOMAIN), $values['Template'] . '-de_DE.po');
            }
            //completely other directories can be defined WP if >= 2.7.0
            global $wp_version;
            if (version_compare($wp_version, '2.7', '>=')) {
                if (count($data['languages']) == 0) {
                    $data['is-path-unclear'] = has_subdirs($dn);
                    if ($data['is-path-unclear'] && count($lng_files) > 0) {
                        foreach ($lng_files as $file) {
                            $f = str_replace($dn, '', $file);
                            if (preg_match("/^([a-z][a-z]_[A-Z][A-Z])\\.(mo|po|pot)\$/", basename($f)) || preg_match("/\\.po(t|)\$/", basename($f))) {
                                $data['special_path'] = dirname($f) == '.' ? '' : dirname($f);
                                $data['is-path-unclear'] = false;
                                break;
                            }
                        }
                    }
                } else {
                    if ($sub_dirs[0] != '') {
                        $data['special_path'] = ltrim($sub_dirs[0], "/");
                    }
                }
            }
        }
        if ($data['gettext_ready'] && !$data['textdomain']['is_const']) {
            break;
        }
        //make it short :-)
        if (preg_match_all("/define\\s*\\(([^\\)]+)\\)/", $main, $hits)) {
            $const_list = array_merge($const_list, $hits[1]);
        }
    }
    $data['base_file'] = empty($data['special_path']) ? '' : $data['special_path'] . "/";
    $constant_failed = false;
    if ($data['gettext_ready']) {
        if ($data['textdomain']['is_const']) {
            foreach ($const_list as $e) {
                $a = explode(',', $e);
                $c = trim($a[0], "\"' \t");
                if ($c == $data['textdomain']['identifier']) {
                    $data['textdomain']['is_const'] = $data['textdomain']['identifier'];
                    $data['textdomain']['identifier'] = trim($a[1], "\"' \t");
                }
            }
        }
        //fallback for constants defined by variables! assume the theme name instead
        if (strpos($data['textdomain']['identifier'], '$') !== false || strpos($data['textdomain']['identifier'], '"') !== false || strpos($data['textdomain']['identifier'], '\'') !== false) {
            $constant_failed = true;
            $data['textdomain']['identifier'] = $values['Template'];
            if (isset($data['dev-hints'])) {
                $data['dev-hints'] .= "<br/><br/>";
            }
            $data['dev-hints'] = __("<strong>Textdomain Naming Issue: </strong>Author uses a variable to define the textdomain constant. It will be assumed to be equal to theme name now.", CSP_PO_TEXTDOMAIN);
        }
    }
    //check now known issues for themes
    if (isset($data['textdomain']['identifier']) && $data['textdomain']['identifier'] == 'woothemes') {
        if (isset($data['dev-hints'])) {
            $data['dev-hints'] .= "<br/><br/>";
        }
        $data['dev-hints'] .= __("<strong>WooThemes Issue: </strong>The Author is known for not supporting a translatable backend. Please expect only translations for frontend or contact the Author for support!", CSP_PO_TEXTDOMAIN);
    }
    if (isset($data['textdomain']['identifier']) && $data['textdomain']['identifier'] == 'ares' && $constant_failed) {
        if (isset($data['dev-hints'])) {
            $data['dev-hints'] .= "<br/><br/>";
        }
        $data['dev-hints'] .= __("<strong>Ares Theme Issue: </strong>This theme uses a textdomain defined by string concatination code. The textdomain will be patched to 'AresLanguage', please contact the theme author to change this into a fix constant value! ", CSP_PO_TEXTDOMAIN);
        $data['textdomain']['identifier'] = 'AresLanguage';
    }
    return $data;
}