Added BlogWrite Function
This commit is contained in:
parent
2a83fb61ff
commit
9b88f96c4d
27
BlogDB.c
27
BlogDB.c
|
|
@ -11,6 +11,7 @@ static MYSQL* conn2maria();
|
||||||
static int AddPost(char title[], int authorId, char datePosted[], char post[], int tags[], size_t tagSize, MYSQL* con);
|
static int AddPost(char title[], int authorId, char datePosted[], char post[], int tags[], size_t tagSize, MYSQL* con);
|
||||||
static int EditPost(int postID, char title[], char post[], MYSQL* con);
|
static int EditPost(int postID, char title[], char post[], MYSQL* con);
|
||||||
static int AddFilePost(int authorID, char filePath[], MYSQL* con);
|
static int AddFilePost(int authorID, char filePath[], MYSQL* con);
|
||||||
|
static int BlogWrite(MYSQL* con);
|
||||||
static int PullPostData(char* strings[6], int postID, MYSQL* con);
|
static int PullPostData(char* strings[6], int postID, MYSQL* con);
|
||||||
static int AddTag(char tagTitle[], MYSQL* con);
|
static int AddTag(char tagTitle[], MYSQL* con);
|
||||||
static int DeleteTag(int tagID, MYSQL* con);
|
static int DeleteTag(int tagID, MYSQL* con);
|
||||||
|
|
@ -217,7 +218,7 @@ int AddFilePost(int authorID, char filePath[], MYSQL* con)
|
||||||
// This is done to remove the <h3> tags
|
// This is done to remove the <h3> tags
|
||||||
for (int i = 4; i < BufferLength; ++i) {
|
for (int i = 4; i < BufferLength; ++i) {
|
||||||
|
|
||||||
if (Buffer[i + 5] == StringEnd[0]) {
|
if (Buffer[i + 6] == StringEnd[0]) {
|
||||||
Buffer[i - 4] = StringEnd[0];
|
Buffer[i - 4] = StringEnd[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -255,6 +256,29 @@ int AddFilePost(int authorID, char filePath[], MYSQL* con)
|
||||||
return postID;
|
return postID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open a temporary file containing the standard template,
|
||||||
|
// and add the contents as a post
|
||||||
|
int BlogWrite(MYSQL* con)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char* tmpName = tmpnam(NULL);
|
||||||
|
|
||||||
|
//fp = tmpfile();
|
||||||
|
|
||||||
|
fp = fopen(tmpName, "w+");
|
||||||
|
fprintf(fp, "<h3></h3>\n<p></p>\n");
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
char* command;
|
||||||
|
if(0 > asprintf(&command, "$EDITOR %s", tmpName)) exit(1);
|
||||||
|
system(command);
|
||||||
|
AddFilePost(1, tmpName, con);
|
||||||
|
|
||||||
|
remove(tmpName);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Pulls a single post's data into the supplied array
|
// Pulls a single post's data into the supplied array
|
||||||
int PullPostData(char* strings[6], int postID, MYSQL* con)
|
int PullPostData(char* strings[6], int postID, MYSQL* con)
|
||||||
{
|
{
|
||||||
|
|
@ -933,6 +957,7 @@ int main(int argc, char *argv[])
|
||||||
//TogglePost(81, con);
|
//TogglePost(81, con);
|
||||||
//printf("%s\n", IsEnabled(81, con) ? "True" : "False");
|
//printf("%s\n", IsEnabled(81, con) ? "True" : "False");
|
||||||
//AddFilePost(1, "/home/adam/Documents/html/linuxenv.html", con);
|
//AddFilePost(1, "/home/adam/Documents/html/linuxenv.html", con);
|
||||||
|
BlogWrite(con);
|
||||||
|
|
||||||
// =================================
|
// =================================
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue