Example #1
0
 public static function create($urlname)
 {
     global $ratatoeskr_settings;
     global $db_con;
     if (!self::test_urlname($urlname)) {
         throw new InvalidDataError("invalid_urlname");
     }
     try {
         self::by_urlname($urlname);
     } catch (DoesNotExistError $e) {
         $obj = new self();
         $obj->urlname = $urlname;
         $obj->title = Multilingual::create();
         $obj->text = Multilingual::create();
         $obj->excerpt = Multilingual::create();
         $obj->meta = "";
         $obj->custom = array();
         $obj->article_image = NULL;
         $obj->status = ARTICLE_STATUS_HIDDEN;
         $obj->section_id = $ratatoeskr_settings["default_section"];
         $obj->timestamp = time();
         $obj->allow_comments = $ratatoeskr_settings["allow_comments_default"];
         qdb("INSERT INTO `PREFIX_articles` (`urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments`) VALUES ('', ?, ?, ?, '', ?, 0, ?, ?, ?, ?)", $obj->title->get_id(), $obj->text->get_id(), $obj->excerpt->get_id(), base64_encode(serialize($obj->custom)), $obj->status, $obj->section_id, $obj->timestamp, $obj->allow_comments ? 1 : 0);
         $obj->id = $db_con->lastInsertId();
         return $obj;
     }
     throw new AlreadyExistsError();
 }