Ejemplo n.º 1
0
function checkDirForWidget($dir)
{
    $process = true;
    $error;
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            $index = 0;
            while (($file = readdir($dh)) !== false) {
                if (!preg_match("/\\./", $file)) {
                    //checkDirForWidget($dir.$file."/");
                    $filename = $dir . $file . "/widget.php";
                    $configPath = $dir . $file . "/config.xml";
                    $xml = simplexml_load_file($configPath);
                    $className = $xml->className;
                    $name = $xml->name;
                    $description = $xml->description;
                    $version = $xml->version;
                    $title = $xml->title;
                    if (isset($className) && $className != "") {
                        $allWidgets = Widgets::get_widgets();
                        $exists = false;
                        foreach ($allWidgets as $id => $value) {
                            $tempWidget = new Widgets($id);
                            if ($tempWidget->get_filename() == $filename) {
                                $exists = true;
                                $widget = new Widgets($id);
                            }
                        }
                        if (!$exists) {
                            $widget = new Widgets();
                        }
                        $widget->set_name($name);
                        $widget->set_description($description);
                        $widget->set_filename($filename);
                        $widget->set_class_name($className);
                        $widget->set_conf_path($configPath);
                        $widget->set_version($version);
                        if (!$exists) {
                            if ($widget->insert_widget()) {
                                $process = true;
                            } else {
                                $error = $widget->get_error();
                                $process = false;
                                break;
                            }
                        } else {
                            if ($widget->update_widget()) {
                                $process = true;
                            } else {
                                $error = $widget->get_error();
                                $process = false;
                                break;
                            }
                        }
                    }
                }
                if ($index > 9999) {
                    break;
                }
            }
            closedir($dh);
        }
    }
    if ($process) {
        return true;
    } else {
        return $error;
    }
}