Exemple #1
0
 public static function main()
 {
     Log::open_file(Carbon::now()->format("F-Y-g-i-A") . ".log");
     Database::connect();
     Crawler::crawl();
     //echo htmlentities( \utf8_decode(  "(AGIELLE) - Galvagni (Cisl): Milano è una pentola a pressione, reagire subito - RPT" ) );
     /*	$query = "SELECT ID as 'identification', post_title FROM wp_posts";
     			$exec = Database::exec( $query );
     			while( $res = $exec->fetch_assoc() ){
     				//Log::log( $res[ 'post_title' ] );
     				$old = $res[ 'post_title' ];
     				$new = htmlentities( $old );
     				$query = "UPDATE wp_posts SET post_title = '".Database::escape( @!!$new ? $new : $old )."' WHERE id = ".$res[ 'identification' ];
     				Log::log( "<red>".$query );
     				
     				Database::exec( $query );
     				//exit();
     				Log::log( "Updated post #".$res[ 'identification' ] );
     			}*/
     /*$post = new Post( Carbon::now(), "Wassup bruh, dis is the contnt", "Taitol", "wassup-bruh1", [ "New Cat 1", "New Cat 2" ] );
     		$post->save();
     		$post = new Post( Carbon::now(), "Wassup bruh, dis is the contnt", "Taitol", "wassup-bruh2", [ "New Cat 2", "New Cat 3" ] );
     		$post->save();*/
     Log::close_file();
 }
Exemple #2
0
 public function save_id()
 {
     $verbose = Config::$env == "dev" ? true : false;
     $id = null;
     if ($verbose) {
         Log::log("<blue>Creating the category `" . $this->name . "`..");
     }
     $slug = Database::escape(strtolower(App::clean($this->name)));
     $query = "INSERT INTO `" . Config::$db_name . "`.`" . Config::$wp_prefix . "terms`( `name`, `slug`, `term_group` ) VALUE( '" . Database::escape($this->name) . "', '" . $slug . "', 0 )";
     $exec = Database::exec($query);
     if ($exec === false) {
         Log::log("<red>Cannot save the category:");
         Log::log("<red>[" . Database::$conn->errno . "] " . Database::$conn->error);
         Log::log("<red>" . $query);
         exit;
     } else {
         $term_id = Database::$conn->insert_id;
         if ($verbose) {
             Log::log("<green>Created the category `" . $this->name . "` with the slug `" . $slug . "` and ID '" . $term_id . "'.");
         }
     }
     $query = "INSERT INTO `" . Config::$db_name . "`.`" . Config::$wp_prefix . "term_taxonomy`( `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUE( '" . $term_id . "', 'category', '', 0, 0 );";
     $exec = Database::exec($query);
     if ($exec === false) {
         Log::log("<red>Cannot save the taxonomy:");
         Log::log("<red>[" . Database::$conn->errno . "] " . Database::$conn->error);
         Log::log("<red>" . $query);
         exit;
     } else {
         if ($verbose) {
             Log::log("<green>Taxonomy created.");
         }
         $tax_id = Database::$conn->insert_id;
     }
     return [$term_id, $tax_id];
 }
Exemple #3
0
 public function save()
 {
     $verbose = Config::$env == "dev" ? true : false;
     $post_save_query = $this->get_query();
     $post_saved = Database::exec($post_save_query);
     if ($post_saved === false) {
         Log::log("<red>Cannot save the article:");
         Log::log("<red>[" . Database::$conn->errno . "] " . Database::$conn->error);
         Log::log("<red>" . $post_save_query);
         exit;
     }
     $this->post_id = Database::$conn->insert_id;
     if ($verbose) {
         Log::log("<green>Article with ID [" . $this->post_id . "] saved.");
     }
     foreach ($this->category as $cat_key => $cat) {
         $cat->check_exists();
         $relation_query = "INSERT INTO `" . Config::$db_name . "`.`" . Config::$wp_prefix . "term_relationships` ( `object_id`, `term_taxonomy_id`, `term_order` ) VALUE ( " . $this->post_id . ", " . $cat->tax_id . ", 0 )";
         $relation_exec = Database::exec($relation_query);
         if ($relation_exec === false) {
             Log::log("<red>Cannot save the link between the article and the taxonomy:");
             Log::log("<red>[" . Database::$conn->errno . "] " . Database::$conn->error);
             Log::log("<red>" . $relation_query);
             exit;
         }
         $count_query = "UPDATE `" . Config::$db_name . "`.`" . Config::$wp_prefix . "term_taxonomy` SET count = count +1 WHERE `term_taxonomy_id` = " . $cat->tax_id . ";";
         $count_exec = Database::exec($count_query);
         if ($count_exec === false) {
             Log::log("<red>Cannot add the article to the counter:");
             Log::log("<red>[" . Database::$conn->errno() . "] " . Database::$conn->error);
             Log::log("<red>" . $count_query);
             exit;
         }
     }
     Log::log("<green>Article #" . $this->post_id . " saved with its categories.");
 }