示例#1
0
文件: import.php 项目: taeche/SoDoEx
 public static function widget()
 {
     global $wp_filesystem;
     $import_file = JVLibrary::path('theme') . "library/import/data/widget_data.txt";
     self::clear_widgets();
     $json_data = $wp_filesystem->get_contents($import_file);
     $json_data = self::replaceImageUrl($json_data);
     $json_data = json_decode($json_data, true);
     $widgets = self::parseWidget($json_data[1]);
     $sidebar_data = $json_data[0];
     $widget_data = $json_data[1];
     foreach ($sidebar_data as $title => $sidebar) {
         $count = count($sidebar);
         for ($i = 0; $i < $count; $i++) {
             $widget = array();
             $widget['type'] = trim(substr($sidebar[$i], 0, strrpos($sidebar[$i], '-')));
             $widget['type-index'] = trim(substr($sidebar[$i], strrpos($sidebar[$i], '-') + 1));
             if (!isset($widgets[$widget['type']][$widget['type-index']])) {
                 unset($sidebar_data[$title][$i]);
             }
         }
         $sidebar_data[$title] = array_values($sidebar_data[$title]);
     }
     foreach ($widgets as $widget_title => $widget_value) {
         foreach ($widget_value as $widget_key => $widget_value) {
             $widgets[$widget_title][$widget_key] = $widget_data[$widget_title][$widget_key];
         }
     }
     $sidebar_data = array(array_filter($sidebar_data), $widgets);
     return self::parse_import_data($sidebar_data);
 }