Example #1
0
 public function init()
 {
     //get ini file options
     $iniOptions = $this->getOptions();
     //set ZFDebug to autoload
     $autoloader = Zend_Loader_Autoloader::getInstance();
     $autoloader->registerNamespace('ZFDebug');
     //initialized Front Controller
     $bootstrap = $this->getBootstrap();
     $bootstrap->bootstrap('frontController');
     $frontController = $bootstrap->getResource('frontController');
     if (RFLib_Core::getIsDeveloperMode() && trim($iniOptions['enable'])) {
         //set ZFDebug options
         $options = array('plugins' => array('Variables', 'File' => array('basePath' => APPLICATION_PATH . '/..'), 'Memory', 'Time', 'Registry', 'Exception'));
         //add cache option if specified
         if ($bootstrap->hasPluginResource('cache')) {
             $bootstrap->bootstrap('cache');
             $cache = $bootstrap->getPluginResource('cache')->getBackend();
             $options['plugins']['Cache']['backend'] = $cache;
         }
         // add db option if specified
         if ($bootstrap->hasPluginResource('db')) {
             $bootstrap->bootstrap('db');
             $db = $bootstrap->getPluginResource('db')->getDbAdapter();
             $options['plugins']['Database']['adapter'] = $db;
         }
         $debug = new ZFDebug_Controller_Plugin_Debug($options);
         $frontController->registerPlugin($debug);
     }
 }
Example #2
0
    public function replyAction()
    {
        $request = $this->getRequest();
        $postId = $request->getParam('postid');
        if (!isset($postId)) {
            echo '数据传送错误!';
            exit;
        }
        $userName = RFLib_Core::getModel('Answer')->getUserNameById($postId);
        $url = $this->view->urlFor('question/reply');
        if (!empty($userName)) {
            $replayForm = <<<EOD
<div id="ajaxbox">
    <h2 id="title">评论“{$userName}”的答案</h2>
    <div id="content">
        <div style="display:none" class="poperror-msg" id="s_error_msg"></div>
        <div style="display:none" class="popsuccess-msg" id="s_success_msg"></div>
        <form method="post" action="question/reply" id="frm_q_detail">
            <input type="hidden" value="{$postId}" name="parent_id" id="parent_id" />
            <div>请输入评论内容:</div>
            <div><textarea style="width: 400px; height: 120px;" id="rp_content" name="rp_content"></textarea></div>
            <div><input type="button" onclick="post_reply('{$url}');" id="bt_submit_new_reply" value="发表评论"/>
            <a href="javascript:closeit()">取消</a></div>
        </form>
    </div>
</div>
EOD;
            echo $replayForm;
        }
        exit;
    }
Example #3
0
 public function indexAction()
 {
     $categories = RFLib_Core::getModel('Category')->getCached('rootcategory')->getRoot();
     $firstCatId = isset($categories[0]) ? $categories[0]['id'] : 1;
     $qModel = RFLib_Core::getModel('Question');
     $showTypes = array('unsolve', 'solve', 'zero');
     $request = $this->getRequest();
     $categoryId = $request->getParam('catalog', $firstCatId);
     $show = $request->getParam('show', $showTypes[0]);
     $page = $request->getParam('page', 1);
     switch ($show) {
         case 'solve':
             $this->view->questions = $qModel->getCached($categoryId . $page)->solves($categoryId, $page, self::PAGE_ROWS);
             break;
         case 'zero':
             $this->view->questions = $qModel->getCached($categoryId . $page)->zeros($categoryId, $page, self::PAGE_ROWS);
             break;
         case 'unsolve':
         default:
             $this->view->questions = $qModel->getCached($categoryId . $page)->unsolves($categoryId, $page, self::PAGE_ROWS);
     }
     $this->view->selCatId = $categoryId;
     $this->view->questionTab = $show;
     $this->view->hotKeywords = RFLib_Core::getModel('Keyword')->getCached($categoryId . 'keyword')->getHots($categoryId, 50);
     $this->view->topUsers = RFLib_Core::getModel('User')->getCached($categoryId . 'topusers')->getTopUsers($categoryId, 50);
 }
Example #4
0
 public function menuAction()
 {
     $categories = RFLib_Core::getModel('Category')->getCached('rootcategory')->getRoot();
     $firstCatId = isset($categories[0]) ? $categories[0]['id'] : 1;
     $this->view->showCatTab = true;
     $this->view->showAsk = true;
     $controller = $this->_getParam('controller');
     $action = $this->_getParam('action');
     if ($controller == 'customer') {
         $this->view->showCatTab = false;
     } elseif ($controller == 'question') {
         switch ($action) {
             case 'show':
             case 'index':
                 $firstCatId = null;
                 break;
             case 'create':
                 $this->view->selAsk = true;
                 $firstCatId = null;
                 break;
         }
     }
     $this->view->selCatId = $this->_getParam('catalog', $firstCatId);
     $this->view->categories = $categories;
     $this->_helper->viewRenderer->setResponseSegment($this->_getParam('responseSegment'));
 }
Example #5
0
 protected function _initInstalled()
 {
     $installed = RFLib_Core::isInstalled();
     $baseUrl = RFLib_Core::getBaseUrl();
     if ($installed) {
         header('location: ' . $baseUrl);
     }
 }
Example #6
0
 protected function _initInstalled()
 {
     $baseUrl = RFLib_Core::getBaseUrl();
     if (!RFLib_Core::isInstalled()) {
         header('location: ' . $baseUrl . 'install.php');
     } elseif (strpos(strtolower($_SERVER['REQUEST_URI']), 'install')) {
         header('location: ' . $baseUrl);
     }
 }
Example #7
0
 public function init()
 {
     if (!RFLib_Core::getIsDeveloperMode()) {
         $classFileCache = VAR_PATH . DS . self::CACHE_FOLDER . DS . self::CACHE_FILE;
         if (file_exists($classFileCache)) {
             include_once $classFileCache;
         }
         Zend_Loader_PluginLoader::setIncludeFileCache($classFileCache);
     }
 }
Example #8
0
 /**
  * Get user info from the auth session
  *
  * @param string|null $info
  * @return null|Zend_View_Helper_AuthInfo
  */
 public function authInfo($info = null)
 {
     if (null === $this->_authService) {
         $this->_authService = RFLib_Core::getService('authentication');
     }
     if (null === $info) {
         return $this;
     }
     if (false === $this->isLogined()) {
         return null;
     }
     return $this->_authService->getIdentity()->{$info};
 }
Example #9
0
 /**
  * Create user post data
  *
  * @param array $data
  * @param string $type 'Q'=Question 'A'=Answer or Reply
  * @return boolean
  */
 public function posted($data, $type = 'Q')
 {
     $auth = RFLib_Core::getService('authentication')->getAuth();
     if (!$auth->hasIdentity()) {
         return false;
     }
     $user = $auth->getStorage()->read();
     if (!isset($data['post_id']) | !isset($data['post_category_id'])) {
         return false;
     }
     $date = new Zend_Date();
     $default = array('user_id' => $user['id'], 'post_type' => $type, 'post_at' => $date->getTimestamp());
     $data = array_merge($data, $default);
     return $this->getTable('Userpost')->saveRow($data, null);
 }
Example #10
0
 public function authenticateAction()
 {
     $loginErrorMsg = array('登录失败,请确认是否输入正确的邮箱地址和密码!');
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return $this->_helper->redirector('login');
     }
     // Validate by form
     $postData = $request->getPost();
     $form = RFLib_Core::getForm('userLogin');
     if (!$form->isValid($postData)) {
         $this->view->errorMsg = $loginErrorMsg;
         return $this->render('login');
     }
     // validate by tabledb
     if (false === $this->_authService->authenticate($form->getValues())) {
         $this->view->errorMsg = $loginErrorMsg;
         return $this->render('login');
     }
     return $this->_redirect("index");
 }
Example #11
0
 public function init()
 {
     parent::init();
     // add path to custom validators
     $this->addElementPrefixPath('RFLib_Validate', LIBRARY_PATH . '/RFLib/Validate/', 'validate');
     //add email element
     $this->addElement('text', 'email', array('filters' => array('StringTrim', 'StringToLower'), 'validators' => array(array('StringLength', true, array(6, 30)), array('EmailAddress')), 'required' => true, 'label' => '邮箱'));
     //add display name element
     $this->addElement('text', 'name', array('filters' => array('StringTrim'), 'validators' => array(array('Alnum'), array('StringLength', true, array(4, 12)), array('UniqueName', false, array(RFLib_Core::getModel('User')))), 'required' => true, 'label' => '姓名'));
     //add password element
     $this->addElement('password', 'password', array('filters' => array('StringTrim'), 'validators' => array(array('StringLength', true, array(4, 128))), 'required' => true, 'label' => '密码'));
     //add password verification element
     $this->addElement('password', 'password2', array('filters' => array('StringTrim'), 'validators' => array('PasswordVerification'), 'required' => true, 'label' => '密码确认'));
     //add gender element
     $this->addElement('radio', 'gender', array('required' => true, 'label' => '姓别', 'MultiOptions' => array('boy', 'girl')));
     //add city element
     $this->addElement('text', 'city', array('filters' => array('StringTrim', 'StringToLower'), 'validators' => array(array('StringLength', true, array(1, 20))), 'required' => false, 'label' => '居住地区'));
     //add userId element
     $this->addElement('hidden', 'id', array('filters' => array('StringTrim'), 'required' => true));
     //add submit button element
     $this->addElement('submit', 'submit', array('required' => false, 'ignore' => true, 'label' => 'Submit'));
 }
Example #12
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $scope = $request->getParam('scope', 'bbs');
     $query = $request->getParam('q');
     $page = $request->getParam('page', 1);
     $results = RFLib_Core::getModel('Question')->getCached(str_replace(' ', '', $query . $page))->getBySearchQuery($query, $page, 50);
     $words = explode(' ', $query);
     $patterns = array();
     $replacements = array();
     foreach ($words as $i => $word) {
         $patterns[] = '/' . preg_quote($word) . '/i';
         $replacements[] = '<span class="highlight">\\0</span>';
     }
     $arr = array();
     $i = 0;
     foreach ($results as $row) {
         $arr[$i] = $row;
         $arr[$i]['subject'] = preg_replace($patterns, $replacements, $arr[$i]['subject']);
         $arr[$i]['content'] = preg_replace($patterns, $replacements, $arr[$i]['content']);
         $i++;
     }
     $this->view->results = $arr;
 }
Example #13
0
 *
 * @category   Wenda
 * @package    Wenda
 * @copyright  Copyright (c) 2010 Ricky Feng (ricky.feng@163.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
// Check PHP version
if (version_compare(phpversion(), '5.2', '<')) {
    die('ERROR: Your PHP version is ' . phpversion() . '. Wenda requires PHP 5.2.0 or newer.');
}
// Error reporting
error_reporting(E_ALL | E_STRICT);
// Define root path
define('WEB_ROOT', realpath(dirname(__FILE__)));
define('DS', DIRECTORY_SEPARATOR);
define('APPLICATION_PATH', WEB_ROOT . DS . 'application');
define('LIBRARY_PATH', WEB_ROOT . DS . 'library');
define('VAR_PATH', WEB_ROOT . DS . 'var');
define('UPLOAD_PATH', WEB_ROOT . DS . 'uploads');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(LIBRARY_PATH, get_include_path())));
// Set application mode
require_once 'RFLib/Core.php';
RFLib_Core::setIsDeveloperMode(TRUE);
/**
 * Zend_Application
 */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . DS . 'configs' . DS . 'application.ini');
$application->bootstrap()->run();
Example #14
0
 /**
  * Construct
  *
  * @param null|Wenda_Model_User $userModel
  */
 public function __construct(Wenda_Model_User $userModel = null)
 {
     $this->_userModel = null === $userModel ? RFLib_Core::getModel('User') : $userModel;
 }
Example #15
0
 /**
  * Get a Form
  *
  * @param string $name
  * @return Zend_Form
  */
 public function getForm($name)
 {
     if (!isset($this->_forms[$name])) {
         $class = join('_', array($this->_getNamespace(), 'Form', RFLib_Core::getInflected($name)));
         $this->_forms[$name] = new $class(array('model' => $this));
     }
     return $this->_forms[$name];
 }
Example #16
0
 private function _save($form, $data, $defaults = array())
 {
     if (!isset($data['user_id'])) {
         $auth = RFLib_Core::getService('authentication')->getAuth();
         if (!$auth->hasIdentity()) {
             return false;
         }
         $user = $auth->getStorage()->read();
         $data['user_id'] = $user['id'];
     }
     if (!$form->isValid($data)) {
         return false;
     }
     $defaults['ip_address'] = ip2long(Zend_Controller_Front::getInstance()->getRequest()->getClientIp());
     // apply any defaults
     foreach ($defaults as $col => $value) {
         $data[$col] = $value;
     }
     $date = new Zend_Date();
     $data['updated_at'] = $date->getTimestamp();
     $row = array_key_exists('id', $data) ? $this->findById($data['id']) : null;
     if (null === $row) {
         $date = new Zend_Date();
         $data['created_at'] = $date->getTimestamp();
     }
     return $this->getTable('Answer')->saveRow($data, $row);
 }
Example #17
0
 public function indexAction()
 {
     $tag = $this->_getParam('tagname');
     $this->view->tagname = $tag;
     $this->view->questionTab = $this->_getParam('show', 'unsolve');
     $this->view->questions = RFLib_Core::getModel('Question')->getAllByKeywords($tag, 1, 50);
 }
Example #18
0
 /**
  * Retrieve application installation flag
  *
  * @param string|array $options
  * @return bool
  */
 public static function isInstalled()
 {
     if (null === self::$_isInstalled) {
         $configFile = APPLICATION_PATH . DS . 'configs' . DS . 'application.ini';
         self::$_isInstalled = false;
         if (is_readable($configFile)) {
             require_once 'Zend/Config/Ini.php';
             $config = new Zend_Config_Ini($configFile);
             date_default_timezone_set('UTC');
             if (($date = $config->production->installed->date) && strtotime($date)) {
                 self::$_isInstalled = true;
             }
         }
     }
     return self::$_isInstalled;
 }
Example #19
0
 /**
  * Save question data
  * @param array|Wenda_Model_DbTable_QuestionTable $data
  * @return boolean
  */
 protected function _save($data)
 {
     $auth = RFLib_Core::getService('authentication')->getAuth();
     if (!$auth->hasIdentity()) {
         return false;
     }
     $user = $auth->getStorage()->read();
     $date = new Zend_Date();
     if (isset($data['id'])) {
         $row = $this->getTable('Question')->findById($data['id']);
     } else {
         $row = null;
     }
     if (null === $row) {
         $data['user_id'] = $user['id'];
         $data['created_at'] = $date->getTimestamp();
         $data['expired_at'] = $date->addWeek(1)->getTimestamp();
         $data['ip_address'] = ip2long(Zend_Controller_Front::getInstance()->getRequest()->getClientIp());
     } else {
         $data['updated_at'] = $date->getTimestamp();
     }
     $date = null;
     return $this->getTable('Question')->saveRow($data, $row);
 }