コード例 #1
0
ファイル: post.php プロジェクト: greenanu/phpsimpl
    $myPost->SetValues($_POST);
    switch ($_POST['submit_button']) {
        case 'Save Draft and Continue Editing':
            $myPost->SetValue('status', 'Draft');
            $redirect = false;
            break;
        case 'Save and Publish':
            $myPost->SetValue('status', 'Published');
        default:
            break;
    }
    // Save the info to the DB if there is no errors
    if ($myPost->Save()) {
        // Sync in the Tags
        $myPostTag = new PostTag();
        $myPostTag->SetValue('post_id', $myPost->GetPrimary());
        $myPostTag->Sync($myPost->GetValue('tags'));
        SetAlert('Post Information Saved.', 'success');
        // Redirect if needed
        if ($redirect) {
            header('location:posts.php');
            die;
        }
    }
}
// If Deleting the Page
if ($_POST['submit_button'] == 'Delete') {
    // Get all the form data
    $myPost->SetValues($_POST);
    // Remove the info from the DB
    if ($myPost->Delete()) {
コード例 #2
0
ファイル: classes.php プロジェクト: greenanu/phpsimpl
 public function Sync($tag_list)
 {
     // Requere a valid post_id
     $myPost = new Post();
     $myPost->SetPrimary($this->GetValue('post_id'));
     if (!$myPost->GetInfo()) {
         return false;
     }
     // Get a list of all the tags for this post
     $tmpPostTag = new PostTag();
     $tmpPostTag->SetValue('post_id', $myPost->GetPrimary());
     $tmpTag = new Tag();
     $tmpPostTag->Join($tmpTag, 'tag_id', 'LEFT');
     $tmpPostTag->GetList();
     // Create an array worth using
     $old_tags = array();
     foreach ($tmpPostTag->results as $tag) {
         $old_tags[$tag['post_tag_id']] = $tag['tag'];
     }
     // Split up the categories and make sure there is tags
     $new_tags = explode(',', strtolower($tag_list));
     foreach ($new_tags as $key => $data) {
         $new_tags[$key] = trim($data);
     }
     // Get the difference
     $diff_tags = array_diff($new_tags, $old_tags);
     // Add the different tags to the database
     foreach ($diff_tags as $tag) {
         // Save the Tag
         $tmpTag->ResetValues();
         $tmpTag->SetValue('tag', $tag);
         $item = $tmpTag->GetAssoc('tag', 'tag', 'ASC', 0, 1);
         if (count($item) == 1) {
             $tmpTag->SetPrimary(key($item));
         } else {
             $tmpTag->Save();
         }
         $tmpPostTag->ResetValues();
         $tmpPostTag->SetValue('post_id', $myPost->GetPrimary());
         $tmpPostTag->SetValue('tag_id', $tmpTag->GetPrimary());
         $tmpPostTag->Save();
     }
     // Get a list of the tags to remove
     $rem_tags = array_diff($old_tags, $new_tags);
     // Remove the non-needed tags
     foreach ($rem_tags as $id => $tag) {
         $tmpPostTag->ResetValues();
         $tmpPostTag->SetPrimary($id);
         $tmpPostTag->Delete();
     }
 }