help on full code to create the blog

help on full code to create the blog

Postby gastoncs on Sat Feb 23, 2008 10:04 pm

I am trying to create a blog throw my interface this code does the following.
1. creates a user
2. adds the user
3. ass permission to the owner(user)
4. creates a blog
5. add the blog
from here on does not work, i am trying to add the category
and the default article post the congratulation! but I cant make it work I don’t know what is missing with this code, I am new at oop in php.

//////////////////////////////////////////////////////////////////////////////////////

Code: Select all

<?php
     
   //header("Location:objectives_list.php");   
   
   if (!defined( "PLOG_CLASS_PATH" )) {
       define( "PLOG_CLASS_PATH", "/var/www/html/humanities/blog/lifetype-1.2.5/");
   }
   
   // necessary classes
   require_once( PLOG_CLASS_PATH."class/bootstrap.php" );   
   lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
   lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
   lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
   lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
   lt_include( PLOG_CLASS_PATH."class/dao/userpermission.class.php" );
   lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );

   // we assume that these have already been intialized
   $blogname =   "Blog name" //$_GET['blogname'];
   $userName =  "Patricio Lopez"//$_GET['blogname'];
   $password = 1234;
   $bloginfo = "This blog is made for ...." //$_GET['bloginfo'];
   $email    = "pat@hotmail.com" //$_GET['email'];
   
   // UserInfo object holding information about a user
   // See http://lifetype.net/api/class_user_info.php for more information
   $user = new UserInfo(
      $userName,         // username
      $password,         // password
      $email,            // email address
      "",               // "about myself", we don't care
      ""                 // we don't care
   );
   
   // Once we have create the user, we can add it via Users::addUser();
   // See http://lifetype.net/api/class_users.php
   $users = new Users();
   $result = $users->addUser( $user );
   
   if( !$result ) {
      die( "There was an error adding the user, make sure that the data is correct and that
          the username does not already exist!" );
   }
   
   // grant the login_perm permission so that this user can log in
   // we have to build a UserPermission object with the information required,
   // see http://www.lifetype.net/api/class_user_permission.php
   $perms = new Permissions();
   $loginPerm = $perms->getPermissionByName( "login_perm" );
   
   $perm = new UserPermission($user->getId(),    // user id
                                    0,   // it's a global permission, no blog id needed
                                    $loginPerm->getId()  // id of the permission
   );
   
   $userPerms = new UserPermissions();
   $result = $userPerms->grantPermission( $perm );
   
   if( !$result ) {
      die( "There was an error assigning the permission" );
   }
   
   // If everything was fine, now we have to create a blog. Users cannot log in unless they
   // have at least one blog so we're going to create one with the BlogInfo object
   // See http://lifetype.net/api/class_blog_info.php
   $blog = new BlogInfo(
   
      $blogname,             // name of the blog
      $user->getId(),        // id of the user who owns this blog
      $bloginfo,             // no "about" for this blog yet
      new BlogSettings()     // blog settings will be stored here
   );
   
   // Now we use Blogs::addBlog() to add the blog
   // See http://lifetype.net/api/class_blogs.php
   $blogs = new Blogs();
   $newBlogId = $blogs->addBlog( $blog );
   
   if( !$result ) {
      die( "There was an error adding the blog!" );
   }
   
   print( "User successfully added" );   
 
  //FROM HERE UP WORKS PERFECTLY
  ////////////////////////////////////////////////
 
 
  //FORM HERE DOWN IT DOES NOT WORK 
  //////////////////////////////////////////////////
 
  // get the default global article category id
   lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );   
 
  $globalArticleCategories = new GlobalArticleCategories();
  $globalArticleCategoryId = $this->_config->getValue("default_global_article_category_id");
 
   if( !empty( $globalArticleCategoryId ) ) {
                
              $globalArticleCategory = $globalArticleCategories->getGlobalArticleCategory( $globalArticleCategoryId );
   
    if( empty( $globalArticleCategory ) )
                
              $globalArticleCategoryId = 0;
             
  } else {
 
        $globalArticleCategoryId = 0;
   }   

   // Get the defaul locale object
  $config =& Config::getConfig();
  $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
 
  // add a default category and a default post
  lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
  lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 
  $articleCategories = new ArticleCategories();
  $articleCategory = new ArticleCategory( $locale->tr( "register_default_category" ), "", $newBlogId, true );
 
  $catId = $articleCategories->addArticleCategory( $articleCategory );
  $articleTopic = $locale->tr( "register_default_article_topic" );
  $articleText  = $locale->tr( "register_default_article_text" );

  $article = new Article( $articleTopic,
                          $articleText,
                          Array( $catId ),
                          $user->getId(),
                          $newBlogId,
                          POST_STATUS_PUBLISHED,
                          0,
                          Array(),
                          "welcome" );
                         
  $article->setGlobalCategoryId( $globalArticleCategoryId );  // set the default ArticleGlobalCategory id to article
  $t = new Timestamp();
  $article->setDateObject( $t );
  $article->setInSummary( false );
  $articles = new Articles();
  $articles->addArticle( $article );
 
    // add a new first album so that users can start uploading stuff right away
  lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
  lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbum.class.php" );
             
  $album = new GalleryAlbum( $newBlogId,   // blog id
                             $locale->tr( "register_default_album_name" ), // album name
                             $locale->tr( "register_default_album_description" ), // album description
                             GALLERY_RESOURCE_PREVIEW_AVAILABLE,   // flags
                             0,   // no parent id
                             $t->getTimestamp(),   // current date
                             Array(),   // no properties
                             true );  // show the album in the interface
                             
  $albums = new GalleryAlbums();
  $albums->addAlbum( $album );
 
  // add a new default mylinkscategory
  lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
 
  $linksCategory = new MyLinksCategory( $locale->tr("register_default_category" ), $newBlogId );
  $linksCategories = new MyLinksCategories();
  $linksCategories->addMyLinksCategory( $linksCategory );

?>
gastoncs
 
Posts: 25
Joined: Wed Feb 13, 2008 11:24 am

Postby jondaley on Sun Feb 24, 2008 1:48 am

You should look at the return value of each function to see if it is returning the right thing. Do you get any php errors, or just the article isn't created?

do a print_r($var) for each variable that is returned from a function.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Postby gastoncs on Sun Feb 24, 2008 2:02 am

No I dont get error it just not create the blog, let me see the return values thanks
gastoncs
 
Posts: 25
Joined: Wed Feb 13, 2008 11:24 am


Return to LifeType 2.0 Development

cron