function synved_option_item_addon_install($id, $name, $item) { $return = null; $type = synved_option_item_type($item); $target = synved_option_item_property($item, 'target'); $folder = synved_option_item_property($item, 'folder'); $field_name = synved_option_name_default($id); $path = null; if (file_exists($target)) { $path = $target; } if ($type != 'addon' || $path == null) { return false; } $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); if (substr($path, -1) != DIRECTORY_SEPARATOR) { $path .= DIRECTORY_SEPARATOR; } if (isset($_FILES[$field_name])) { foreach ($_FILES[$field_name]["error"] as $key => $error) { if ($key == $name && $error == UPLOAD_ERR_OK) { $tmp_name = $_FILES[$field_name]["tmp_name"][$key]; $name = $_FILES[$field_name]["name"][$key]; $tmpfname = wp_tempnam($name . '.zip'); if (move_uploaded_file($tmp_name, $tmpfname)) { global $wp_filesystem; $unzip_path = realpath($path); $dirs = glob($path . '*', GLOB_ONLYDIR); if ($wp_filesystem != null) { $unzip_path = $wp_filesystem->find_folder($unzip_path); } wp_mkdir_p(realpath($path)); $return = unzip_file($tmpfname, $unzip_path); if ($wp_filesystem != null) { $wp_filesystem->delete($tmpfname); } $dirs_new = glob($path . '*', GLOB_ONLYDIR); $dirs_diff = array_values(array_diff($dirs_new, $dirs)); $addon_path = $path; if ($dirs_diff != null) { $folder_path = null; foreach ($dirs_diff as $dir) { if (basename($dir) == $folder) { $folder_path = $dir; } } // XXX no correct path, was unzip successful? if ($folder_path == null) { $folder_path = $dirs_diff[0]; } $addon_path = $folder_path; } synved_option_set($id, $name, $addon_path); } } } } return $return; }
function synved_option_wp_plugin_action_links($links, $file) { global $synved_option_list; if ($synved_option_list != null) { foreach ($synved_option_list as $id => $list) { $items = synved_option_item_list($id); $pages = $synved_option_list[$id]['pages']; foreach ($pages as $name => $page) { $link_label = synved_option_item_property($page, 'link-label'); $link_target = synved_option_item_property($page, 'link-target'); $link_url = synved_option_page_link_url($id, $name, $page); if ($link_label == null) { $link_label = __('Settings'); } if ($file == $link_target) { $links[] = '<a href="' . $link_url . '">' . $link_label . '</a>'; } } } } return $links; }
function synved_option_item_addon_is_installed(array $item) { if ($item != null) { $type = synved_option_item_type($item); if ($type == 'addon') { $target = synved_option_item_property($item, 'target'); $folder = synved_option_item_property($item, 'folder'); $path = $target; if ($path != null) { $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); if (substr($path, -1) != DIRECTORY_SEPARATOR) { $path .= DIRECTORY_SEPARATOR; } $path .= $folder; if (is_dir($path)) { return true; } } $module = synved_option_item_property($item, 'module'); if ($module != null) { $addon_list = synved_plugout_module_addon_list($module); if (isset($addon_list[$folder])) { return true; } } } } return false; }