Пример #1
0
 public function Publish()
 {
     $publishedBlogs = PostFactory::GetPublishedBlogs();
     //but only if there is at least one post in the category
     $numofblogs = sizeof($publishedBlogs);
     $post_rows = '';
     for ($x = 0; $x < $numofblogs; $x++) {
         $post_row = '<div class=row>';
         $blogPost = $publishedBlogs[$x++];
         $post_row .= Post::blog_snippet($blogPost);
         if ($x < $numofblogs) {
             $blogPost = $publishedBlogs[$x++];
             $post_row .= Post::blog_snippet($blogPost);
             if ($x < $numofblogs) {
                 $blogPost = $publishedBlogs[$x];
                 $post_row .= Post::blog_snippet($blogPost);
             }
         }
         $post_row .= '</div>' . "\n";
         $post_rows .= $post_row;
     }
     $file_contents_string = file_get_contents($this->TemplateFolder . $this->IndexTemplateName);
     $file_contents_string = str_replace('{{post_rows}}', $post_rows, $file_contents_string);
     file_put_contents($this->IndexFolder . $this->IndexFileName, $file_contents_string);
 }
Пример #2
0
 /**
  * @param string $pathInfo
  * @return bool|DataObject
  */
 public function match($pathInfo)
 {
     $identifier = trim($pathInfo, '/');
     $parts = explode('/', $identifier);
     if (count($parts) >= 1) {
         $parts[count($parts) - 1] = $this->trimSuffix($parts[count($parts) - 1]);
     }
     if ($parts[0] != $this->config->getBaseRoute()) {
         return false;
     }
     if (count($parts) > 1) {
         unset($parts[0]);
         $parts = array_values($parts);
         $urlKey = implode('/', $parts);
         $urlKey = urldecode($urlKey);
         $urlKey = $this->trimSuffix($urlKey);
     } else {
         $urlKey = '';
     }
     if ($urlKey == '') {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'index', 'params' => []]);
     }
     if ($parts[0] == 'search') {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'search', 'action_name' => 'result', 'params' => []]);
     }
     if ($parts[0] == 'tag' && isset($parts[1])) {
         $tag = $this->tagFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem();
         if ($tag->getId()) {
             return new DataObject(['module_name' => 'blog', 'controller_name' => 'tag', 'action_name' => 'view', 'params' => ['id' => $tag->getId()]]);
         } else {
             return false;
         }
     }
     if ($parts[0] == 'author' && isset($parts[1])) {
         $author = $this->authorFactory->create()->getCollection()->addFieldToFilter('user_id', $parts[1])->getFirstItem();
         if ($author->getId()) {
             return new DataObject(['module_name' => 'blog', 'controller_name' => 'author', 'action_name' => 'view', 'params' => ['id' => $author->getId()]]);
         } else {
             return false;
         }
     }
     if ($parts[0] == 'rss' && isset($parts[1])) {
         $category = $this->categoryFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem();
         if ($category->getId()) {
             return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => ['id' => $category->getId()]]);
         } else {
             return false;
         }
     } elseif ($parts[0] == 'rss') {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => []]);
     }
     $post = $this->postFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem();
     if ($post->getId()) {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'post', 'action_name' => 'view', 'params' => ['id' => $post->getId()]]);
     }
     $category = $this->categoryFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem();
     if ($category->getId()) {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'view', 'params' => ['id' => $category->getId()]]);
     }
     return false;
 }
Пример #3
0
 public static function GetBlogsByState($state)
 {
     $retval = array();
     //get all posts
     $posts = PostFactory::GetAllPosts();
     //then filter
     //unpublished
     foreach ($posts as $post) {
         if ($state == 'unpublished') {
             if (isset($post->UnpublishDate) && $post->UnpublishDate > $post->PublishDate) {
                 array_push($retval, $post);
             }
         } else {
             if ($state == 'notpublished') {
                 if (isset($post->PublishDate) == FALSE) {
                     array_push($retval, $post);
                 }
             } else {
                 if ($state == 'outdated') {
                     if (isset($post->PublishDate) && $post->ModifiedDate > $post->PublishDate) {
                         array_push($retval, $post);
                     }
                 }
             }
         }
     }
     return $retval;
 }
Пример #4
0
    $GLOBALS['mysqli'] = MySQLConnection::Open();
    $relatedPosts = PostFactory::GetRelatedPosts($postid);
    MySQLConnection::Close($GLOBALS['mysqli']);
    //allow cors
    cors();
    echo json_encode($relatedPosts);
});
$app->get('/getrecentposts/', function () {
    require_once 'common/dbconnection.php';
    require_once 'category.php';
    require_once 'post.php';
    require_once 'posttype.php';
    require_once 'userresponse.php';
    require_once 'userreply.php';
    $GLOBALS['mysqli'] = MySQLConnection::Open();
    $relatedPosts = PostFactory::GetRecentPosts();
    MySQLConnection::Close($GLOBALS['mysqli']);
    //allow cors
    cors();
    echo json_encode($relatedPosts);
});
$app->run();
class User
{
    public function __construct($username, $password)
    {
        $this->UserName = $username;
        $this->Password = $password;
        if ($username == 'gapeterb' && $password == 'danielb') {
            $this->IsValidUser = TRUE;
        }