Skip to content

Commit eb20099

Browse files
committed
1 parent 686f754 commit eb20099

File tree

149 files changed

+7832
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+7832
-0
lines changed

demos/simple-blog/.htaccess

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Deny directory browsing
2+
Options -Indexes
3+
4+
## Mod Rewrite
5+
<IfModule mod_rewrite.c>
6+
RewriteEngine On
7+
8+
RewriteCond %{REQUEST_FILENAME} !-d
9+
RewriteCond %{REQUEST_FILENAME} !-f
10+
RewriteCond %{REQUEST_FILENAME} !-l
11+
12+
# Rewrite all other URLs to index.php/URL
13+
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
14+
</IfModule>
15+
16+
<IfModule !mod_rewrite.c>
17+
ErrorDocument 404 index.php
18+
</IfModule>
19+
1.95 KB
Loading

demos/simple-blog/index.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Public index file
4+
*
5+
* @project ApPHP Framework
6+
* @author ApPHP <[email protected]>
7+
* @link http://www.apphpframework.com/
8+
* @copyright Copyright (c) 2012 - 2013 ApPHP Framework
9+
* @license http://www.apphpframework.com/license/
10+
*/
11+
12+
// change the following paths if necessary
13+
defined('APPHP_PATH') || define('APPHP_PATH', dirname(__FILE__));
14+
// directory separator
15+
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
16+
// production | debug | demo | test
17+
defined('APPHP_MODE') or define('APPHP_MODE', 'production');
18+
19+
20+
$apphp = dirname(__FILE__).'/../../framework/Apphp.php';
21+
$config = APPHP_PATH.'/protected/config/';
22+
23+
require_once($apphp);
24+
A::init($config)->run();
25+

demos/simple-blog/protected/.htaccess

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deny from all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
class BlogHelper extends CComponent
4+
{
5+
6+
/**
7+
* Cuts the string by whole words up to maximum length.
8+
* @param string $string
9+
* @param int $maxLength
10+
* @return string
11+
*/
12+
public static function strTruncate($string, $maxLength)
13+
{
14+
$string = substr($string, 0, $maxLength);
15+
$string = substr($string, 0, strrpos($string, ' '));
16+
return $string;
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
class BlogMenu extends CComponent
4+
{
5+
6+
/**
7+
* Class constructor
8+
* @return void
9+
*/
10+
public function __construct()
11+
{
12+
parent::__construct();
13+
}
14+
15+
/**
16+
* Returns the static model of the specified AR class
17+
*/
18+
public static function init()
19+
{
20+
return parent::init(__CLASS__);
21+
}
22+
23+
public function adminTopMenu($viewRightMenu = '')
24+
{
25+
$output = CWidget::create('CMenu', array(
26+
'type'=>'horizontal',
27+
'class'=>'user_menu',
28+
'items'=>array(
29+
array('label'=>($viewRightMenu) ? 'Back to Admin Panel' : 'Home', 'url'=>'authors/index'),
30+
array('label'=>'Logout', 'url'=>'login/logout'),
31+
),
32+
'return'=>true
33+
));
34+
35+
$author = Authors::model()->findByPk(1);
36+
if($author){
37+
$output .= '<img class="avatar_small" src="templates/default/images/authors/'.$author->avatar_file.'">';
38+
}
39+
40+
return $output;
41+
}
42+
43+
public function adminLeftMenu($activeLink = '')
44+
{
45+
if(!empty($activeLink)){
46+
$this->view->renderContent('adminLeftMenu');
47+
}
48+
}
49+
50+
public function blogSideMenu($viewRightMenu = '')
51+
{
52+
$output = '';
53+
54+
if($viewRightMenu){
55+
$author = Authors::model()->findByPk(1);
56+
$categories = Categories::model();
57+
58+
$output .= '<aside class="right_side">
59+
<div class="about_me">
60+
<div class="right_menu_header">ABOUT ME</div>
61+
<div class="right_menu_content">
62+
<img class="avatar_about_me" src="templates/default/images/authors/'.$author->avatar_file.'">
63+
<div class="about_text">'.$author->about_text.'</div>
64+
</div>
65+
</div>
66+
<div class="categories_list">
67+
<div class="right_menu_header">CATEGORIES</div>
68+
<div class="right_menu_content">';
69+
70+
// categories box
71+
$cats = $categories->findAll();
72+
if(!$cats){
73+
CDebug::addMessage('warnings', 'warning', 'No categories have been created yet.');
74+
}else{
75+
foreach($cats as $cat) {
76+
$output .= '<a href="categories/view/id/'.$cat['id'].'">'.$cat['name'].' ('.$cat['posts_count'].')</a><br>';
77+
}
78+
}
79+
80+
$output .= '</div>
81+
</div>
82+
</aside>';
83+
}
84+
85+
return $output;
86+
}
87+
88+
}
89+
90+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<aside class="left_side">
2+
General
3+
<ul>
4+
<li><a class="<?php echo (($activeLink == 'home') ? ' active' : ''); ?>" href="authors/index">Home</a>
5+
<li><a href="index/index">View Site</a>
6+
<li><a class="<?php echo (($activeLink == 'settings') ? ' active' : ''); ?>" href="settings/edit">Site Settings</a>
7+
<li><a class="<?php echo (($activeLink == 'author') ? ' active' : ''); ?>" href="authors/edit">My Account</a>
8+
</ul>
9+
Categories Management
10+
<ul>
11+
<li><a class="<?php echo (($activeLink == 'add_category') ? ' active' : ''); ?>" href="categories/add">New Category</a>
12+
<li><a class="<?php echo (($activeLink == 'edit_category') ? ' active' : ''); ?>" href="categories/index">Categories</a>
13+
</ul>
14+
Posts Management
15+
<ul>
16+
<li><a class="<?php echo (($activeLink == 'add_post') ? ' active' : ''); ?>" href="posts/add">New Post</a>
17+
<li><a class="<?php echo (($activeLink == 'edit_post') ? ' active' : ''); ?>" href="posts/index">Posts</a>
18+
</ul>
19+
</aside>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
/**
3+
* AuthorsController
4+
*
5+
* PUBLIC: PRIVATE
6+
* ----------- ------------------
7+
* __construct
8+
* indexAction
9+
* editAction
10+
* updateAction
11+
*
12+
*/
13+
class AuthorsController extends CController
14+
{
15+
public function __construct()
16+
{
17+
parent::__construct();
18+
19+
// block access to this controller for not-logged users
20+
CAuth::handleLogin();
21+
22+
$this->_loggedId = CAuth::getLoggedId();
23+
24+
$settings = Settings::model()->findByPk(1);
25+
$this->view->setMetaTags('title', 'Account | '.$settings->metatag_title);
26+
$this->view->setMetaTags('keywords', $settings->metatag_keywords);
27+
$this->view->setMetaTags('description', $settings->metatag_description);
28+
$this->view->blogName = $settings->blog_name;
29+
$this->view->blogSlogan = $settings->slogan;
30+
$this->view->blogFooter = $settings->footer;
31+
32+
$this->view->activeLink = 'home';
33+
$this->view->viewRightMenu = false;
34+
$this->view->errorField = '';
35+
$this->view->actionMessage = '';
36+
}
37+
38+
public function indexAction()
39+
{
40+
$this->view->setMetaTags('title', 'Dashboard | '.$this->view->blogName);
41+
$this->view->mainHeader = 'Welcome to Admin Panel!';
42+
$this->view->mainText = 'The administrator panel is an integrated place to manage your site.
43+
Use navigation menu links from the left to access required page.';
44+
$this->view->render('authors/index');
45+
}
46+
47+
48+
public function editAction()
49+
{
50+
$this->view->activeLink = 'author';
51+
52+
$author = Authors::model()->findByPk($this->_loggedId);
53+
if(empty($this->_loggedId) || !$author){
54+
$this->redirect('authors/index');
55+
}
56+
57+
$this->view->login = $author->login;
58+
$this->view->password = '';
59+
$this->view->passwordRetype = '';
60+
$this->view->email = $author->email;
61+
$this->view->aboutText = $author->about_text;
62+
$this->view->avatarFile = $author->avatar_file;
63+
64+
$this->view->render('authors/edit');
65+
}
66+
67+
public function updateAction()
68+
{
69+
$this->view->activeLink = 'author';
70+
$cRequest = A::app()->getRequest();
71+
$msg = '';
72+
$errorType = '';
73+
74+
if($cRequest->getPost('act') == 'send'){
75+
76+
$author = Authors::model()->findByPk($this->_loggedId);
77+
78+
$this->view->login = $cRequest->getPost('login');
79+
$this->view->password = $cRequest->getPost('password');
80+
$this->view->passwordRetype = $cRequest->getPost('passwordRetype');
81+
$this->view->email = $cRequest->getPost('email');
82+
$this->view->aboutText = $cRequest->getPost('aboutText');
83+
$this->view->avatarFile = !empty($_FILES['avatar']['name']) ? $_FILES['avatar']['name'] : $author->avatar_file;
84+
85+
$result = CWidget::create('CFormValidation', array(
86+
'fields'=>array(
87+
'password' =>array('title'=>'Password', 'validation'=>array('required'=>false, 'type'=>'password', 'minLength'=>6, 'maxlength'=>20)),
88+
'passwordRetype' =>array('title'=>'Repeat Password', 'validation'=>array('required'=>false, 'type'=>'confirm', 'confirmField'=>'password', 'minLength'=>6, 'maxlength'=>20)),
89+
'email' =>array('title'=>'Email', 'validation'=>array('required'=>true, 'type'=>'email', 'maxLength'=>100)),
90+
'aboutText' =>array('title'=>'About Me', 'validation'=>array('required'=>true, 'type'=>'any', 'maxLength'=>300)),
91+
'avatar' =>array('title'=>'Avatar', 'validation'=>array('required'=>false, 'type'=>'image', 'targetPath'=>'templates/default/images/authors/', 'maxSize'=>'100k', 'mimeType'=>'image/jpeg, image/png, image/gif, image/jpg')),
92+
),
93+
));
94+
if($result['error']){
95+
$msg = $result['errorMessage'];
96+
$this->view->errorField = $result['errorField'];
97+
$errorType = 'validation';
98+
99+
if($this->view->errorField == 'avatar'){
100+
$this->view->avatarFile = $author->avatar_file;
101+
}
102+
}else{
103+
$author->email = $this->view->email;
104+
$author->about_text = $this->view->aboutText;
105+
unset($author->password);
106+
unset($author->avatar_file);
107+
if($this->view->password != ''){
108+
$author->password = ((CConfig::get('password.encryption')) ? CHash::create(CConfig::get('password.encryptAlgorithm'), $this->view->password, CConfig::get('password.hashKey')) : $this->view->password);
109+
}
110+
if($this->view->avatarFile != ''){
111+
$author->avatar_file = $this->view->avatarFile;
112+
}
113+
114+
if(APPHP_MODE == 'demo'){
115+
$msg = '<b>:(</b> Sorry, but update operation is blocked in DEMO version!';
116+
$errorType = 'warning';
117+
}else{
118+
if($author->save()){
119+
$msg = 'Author settings have been successfully saved!';
120+
$errorType = 'success';
121+
$this->view->password = '';
122+
$this->view->passwordRetype = '';
123+
}else{
124+
$msg = 'An error occurred while saving the settings! Please re-enter.';
125+
$this->view->errorField = '';
126+
$errorType = 'error';
127+
}
128+
}
129+
}
130+
}else{
131+
$this->redirect('authors/edit');
132+
}
133+
if(!empty($msg)){
134+
$this->view->actionMessage = CWidget::create('CMessage', array($errorType, $msg, array('button'=>true)));
135+
}
136+
137+
$this->view->render('authors/edit');
138+
}
139+
140+
}

0 commit comments

Comments
 (0)