Exemplo n.º 1
0
 public static function InstallDataSanple()
 {
     call_user_func(JVLibrary::getFnCheat('ini'), "memory_limit", "1024M");
     call_user_func(JVLibrary::getFnCheat('ini'), "max_execution_time", "30000000");
     call_user_func(JVLibrary::getFnCheat('ini'), "max_input_time", "30000000");
     call_user_func(JVLibrary::getFnCheat('ini'), "post_max_size", "1024M");
     @set_time_limit(0);
     self::import(self::path('theme') . 'library/import/import.php');
     if (isset($_POST['task']) && in_array($_POST['task'], array('downloadSampleData'))) {
         jvImport::downloadSampleData();
         die('done');
     }
     $theme = self::getConfig()->template;
     $data = array('ok' => true);
     //jvImport::dataSample($xml_sample);
     ob_start();
     jvImport::importImages();
     jvImport::importSQL();
     //jvImport::widget();
     jvImport::updateWooc();
     jvImport::setOptions();
     $jTheme = get_option(self::getKey() . '_theme_settings');
     $jTheme['datasample'] = 1;
     update_option(self::getKey() . '_theme_settings', $jTheme);
     $data['msg'] = ob_get_clean();
     echo json_encode($data);
     exit;
 }
Exemplo n.º 2
0
 public static function importSQL()
 {
     //@ini_set('mysql.connect_timeout', 2000);
     //@ini_set('default_socket_timeout', 2000);
     @set_time_limit(0);
     global $wp_filesystem;
     $sql = JVLibrary::path('theme') . "library/import/data/jv_allinone.sql";
     $sample = JVLibrary::urls('demo') . '/jv_allinone.sql';
     $contents = $wp_filesystem->get_contents($sample);
     $wp_filesystem->put_contents($sql, $contents);
     $db = self::getDb();
     $jvfn = 'f' . 'open';
     if (!($file = $jvfn($sql, 'r'))) {
         return;
     }
     $query = "";
     $queries = $totalqueries = $querylines = $inparents = $linenumber = 0;
     while ($linenumber < self::$max_query_lines || $query != "") {
         // Read the whole next line
         $dumpline = "";
         while (!feof($file) && substr($dumpline, -1) != "\n" && substr($dumpline, -1) != "\r") {
             $dumpline .= fgets($file, self::$DATA_CHUNK_LENGTH);
             //else $dumpline .= gzgets($file, self::$DATA_CHUNK_LENGTH);
         }
         if ($dumpline === "") {
             break;
         }
         // Remove UTF8 Byte Order Mark at the file beginning if any
         $dumpline = preg_replace('|^\\xEF\\xBB\\xBF|', '', $dumpline);
         // Handle DOS and Mac encoded linebreaks (I don't know if it really works on Win32 or Mac Servers)
         $dumpline = str_replace("\r\n", "\n", $dumpline);
         $dumpline = str_replace("\r", "\n", $dumpline);
         // DIAGNOSTIC
         // echo ("<p>Line $linenumber: $dumpline</p>\n");
         // Recognize delimiter statement
         if (!$inparents && strpos($dumpline, "DELIMITER ") === 0) {
             self::$delimiter = str_replace("DELIMITER ", "", trim($dumpline));
         }
         // Skip comments and blank lines only if NOT in parents
         if (!$inparents) {
             $skipline = false;
             reset(self::$comment);
             foreach (self::$comment as $comment_value) {
                 if (trim($dumpline) == "" || strpos(trim($dumpline), $comment_value) === 0) {
                     $skipline = true;
                     break;
                 }
             }
             if ($skipline) {
                 $linenumber++;
                 continue;
             }
         }
         // Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings)
         $dumpline_deslashed = str_replace("\\\\", "", $dumpline);
         // Count ' and \' (or " and \") in the dumpline to avoid query break within a text field ending by $delimiter
         $string_quotes = self::$string_quotes;
         $parents = substr_count($dumpline_deslashed, self::$string_quotes) - substr_count($dumpline_deslashed, "\\{$string_quotes}");
         if ($parents % 2 != 0) {
             $inparents = !$inparents;
         }
         // Add the line to query
         $query .= $dumpline;
         // Don't count the line if in parents (text fields may include unlimited linebreaks)
         if (!$inparents) {
             $querylines++;
         }
         // Stop if query contains more lines as defined by $max_query_lines
         if ($querylines > self::$max_query_lines) {
             $error[] = 'Too long';
             break;
         }
         // Execute query if end of query detected ($delimiter as last character) AND NOT in parents
         $query = self::replaceImageUrl($query);
         if ((preg_match('/' . preg_quote(self::$delimiter, '/') . '$/', trim($dumpline)) || self::$delimiter == '') && !$inparents) {
             // Cut off delimiter of the end of the query
             $query = substr(trim($query), 0, -1 * strlen(self::$delimiter));
             // echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
             if (!$db->query($query)) {
                 //echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n");
                 echo "<p>Query: " . trim(nl2br(htmlentities($query))) . "</p>\n";
                 echo "<p>MySQL: " . $db->last_error . "</p>\n";
                 break;
             }
             $totalqueries++;
             $queries++;
             $query = "";
             $querylines = 0;
         }
         $linenumber++;
     }
     $wp_filesystem->delete($sql);
 }