Пример #1
0
 public function indexAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user_id')) {
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
     }
     if (JO_Session::get('msg_success')) {
         $this->view->msg_error = JO_Session::get('msg_success');
         JO_Session::clear('msg_success');
     }
     if (JO_Session::get('msg_error')) {
         $this->view->msg_error = JO_Session::get('msg_error');
         JO_Session::clear('msg_error');
     }
     $this->view->questions = $questions = Model_Quiz::getAllQuestions(0, 0, '', 'RAND()');
     $this->view->answers = $answers = Model_Quiz::getAllAnswers(0, 0, '', true);
     if ($request->isPost()) {
         $rightAnswers = 0;
         $user_answers = $request->getPost('answers');
         if (is_array($user_answers)) {
             foreach ($user_answers as $question => $answer) {
                 if (isset($answers[$question][$answer]) && $answers[$question][$answer]['right'] == 'true') {
                     $rightAnswers++;
                 }
             }
         }
         if ($rightAnswers > 0 && count($questions) == $rightAnswers) {
             $_SESSION['user']['quiz'] = 'true';
             JO_Session::set('quiz', 'true');
             Model_Users::updateQuiz(JO_Session::get('user_id'), 'true');
             JO_Session::set('msg_success', 'You have successfully completed the quiz');
             $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=upload'));
         } else {
             JO_Session::set('msg_error', 'You have to answer all questions correctly. You have ' . $rightAnswers . ' right answers from ' . $question . ' questions');
             $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=quiz'));
         }
     }
     $this->view->usersCount = Model_Users::countUsers();
     $this->view->itemsCount = Model_Items::countItems();
     $this->getLayout()->meta_title = $this->translate('Quiz');
     $this->getLayout()->meta_description = $this->translate('Quiz');
     $this->view->page_name = $this->translate('Quiz');
     /* CRUMBS */
     $this->view->crumbs = array();
     $this->view->crumbs[] = array('name' => $this->view->translate('Home'), 'href' => $request->getBaseUrl());
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
Пример #2
0
 public function indexAction()
 {
     $this->view->usersCount = Model_Users::countUsers();
     $this->view->itemsCount = Model_Items::countItems();
     $pageID = $this->getRequest()->getRequest('page_id');
     $this->view->page = Model_Pages::get($pageID);
     if ($this->view->page['sub_of'] == 0) {
         $headPage = $this->view->page;
         $subPages = Model_Pages::getSubPages($pageID);
         //		if(!$subPages) {
         //			$this->view->usersCount = Model_Users::countUsers();
         //			$this->view->itemsCount = Model_Items::countItems();
         //		}
     } else {
         $headPage = Model_Pages::get($this->view->page['sub_of']);
         $subPages = Model_Pages::getSubPages($this->view->page['sub_of']);
         $crumbs = array();
         $parentPages = Model_Pages::getPageParents($this->view->page['sub_of']);
         if ($parentPages) {
             $cnt = count($parentPages);
             for ($i = 0; $i < $cnt; $i++) {
                 $crumbs[$i + 1] = array('name' => $parentPages[$i]['name'], 'href' => WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=pages&page_id=' . $parentPages[$i]['id'] . '&name=' . WM_Router::clearName($parentPages[$i]['name'])));
             }
         }
     }
     $this->view->crumbs = array(array('name' => $this->view->translate('Home'), 'href' => $this->getRequest()->getBaseUrl()));
     if (isset($crumbs)) {
         $this->view->crumbs += $crumbs;
     }
     if ($subPages) {
         $this->view->subPages[] = array('name' => $headPage['name'], 'href' => WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=pages&page_id=' . $headPage['id'] . '&name=' . WM_Router::clearName($headPage['name'])), 'is_selected' => $headPage['id'] == $pageID ? true : false);
         foreach ($subPages as $page) {
             $this->view->subPages[] = array('name' => $page['name'], 'href' => WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=pages&page_id=' . $page['id'] . '&name=' . WM_Router::clearName($page['name'])), 'is_selected' => $page['id'] == $pageID ? true : false);
         }
     }
     if (!$this->view->page) {
         $this->forward('error', 'error404');
     }
     $model_images = new Model_Images();
     $this->view->page['text'] = html_entity_decode($this->view->page['text'], ENT_QUOTES, 'utf-8');
     $this->view->page['text'] = $model_images->fixEditorText($this->view->page['text']);
     $this->getLayout()->meta_title = $this->view->page['meta_title'];
     $this->getLayout()->meta_description = $this->view->page['meta_description'];
     $this->getLayout()->meta_keywords = $this->view->page['meta_keywords'];
     $this->view->quiz_link = WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=quiz');
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
Пример #3
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $model_images = new Model_Images();
     $this->view->usersCount = Model_Users::countUsers();
     $this->view->itemsCount = Model_Items::countItems();
     /* LAST ITEM */
     $lastItem = Model_Items::getLastItem();
     if ($lastItem) {
         $thumb = $model_images->resizeWidth($lastItem['theme_preview_thumbnail'], 200);
         $thumb_size = getimagesize($thumb);
         if ($thumb_size[1] > 161) {
             $image = new JO_GDThumb($thumb);
             $image->crop(0, 0, $thumb_size[0], 161);
             $image->save($thumb);
         }
         $this->view->lastItem = array('name' => $lastItem['name'], 'href' => WM_Router::create($request->getBaseUrl() . '?module=' . $lastItem['module'] . '&controller=items&item_id=' . $lastItem['id'] . '&name=' . $lastItem['name']), 'thumb' => $thumb);
     }
     /* FREE ITEM */
     $this->view->freeItems = '';
     $freeItems = Model_Items::getFreeFiles();
     if ($freeItems) {
         foreach ($freeItems as $fi) {
             $cats = explode(',', $fi['categories']);
             $cat_name = Helper_Items::getCategory($cats[1]);
             $thumb = $model_images->resizeWidth($fi['theme_preview_thumbnail'], JO_Registry::forceGet($fi['module'] . '_items_thumb_width'));
             $thumb_size = getimagesize($thumb);
             if ($thumb_size[1] > JO_Registry::forceGet($fi['module'] . '_items_thumb_height')) {
                 $image = new JO_GDThumb($thumb);
                 $image->crop(0, 0, $thumb_size[0], JO_Registry::forceGet($fi['module'] . '_items_thumb_height'));
                 $image->save($thumb);
             }
             $this->view->freeItems[] = array('href' => WM_Router::create($request->getBaseUrl() . '?controller=items&item_id=' . $fi['id'] . '&name=' . WM_Router::clearName($fi['name'])), 'thumb' => $thumb, 'cat_name' => $cat_name['name'], 'name' => $fi['name']);
         }
     }
     /* ITEMS */
     $this->view->items = array();
     $listType = $request->getParam('list_type');
     if (is_null($listType)) {
         $listType = 'recent';
     }
     $this->view->all_items = array('name' => $this->view->translate('View all items'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=categories&action=' . $listType));
     switch ($listType) {
         case 'featured':
             JO_Session::set('redirect', $request->getBaseUrl() . $request->getUri());
             $this->view->title_items = $this->view->translate('Featured Items');
             $featuredItems = Model_Items::getWeekly($request->getParam('category_filter'));
             if ($featuredItems) {
                 foreach ($featuredItems as $n => $item) {
                     if (!empty($item['demo_url'])) {
                         $item['demo_url'] = WM_Router::create($request->getBaseUrl() . '?module=' . $item['module'] . '&controller=items&action=preview&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
                     }
                     $this->view->items[] = Helper_Items::returnViewIndex($item);
                 }
             }
             break;
         case 'author':
             JO_Session::set('redirect', $request->getBaseUrl() . $request->getUri());
             $this->view->title_items = $this->view->translate('Featured Author');
             $this->view->author = Model_Users::getFeatUser();
             if ($this->view->author) {
                 $this->view->author['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&username='******'username']);
                 $this->view->author['userhref_pf'] = WM_Router::create($request->getBaseUrl() . '?controller=users&username='******'username']);
                 if ($this->view->author['avatar']) {
                     $this->view->author['avatar'] = $model_images->resize($this->view->author['avatar'], JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
                 } else {
                     $this->view->author['avatar'] = 'data/themes/images/avatar-author.png';
                 }
                 $this->view->items = array();
                 $items = Model_Items::getByUser($this->view->author['user_id'], 0, 11, false);
                 if (empty($items)) {
                     $items = array(0 => array('no_items' => true, 'thumbnail' => 'data/themes/images/missing-item.png', 'module' => 'themes'));
                 }
                 if ($items) {
                     foreach ($items as $n => $item) {
                         if (!empty($item['demo_url'])) {
                             $item['demo_url'] = WM_Router::create($request->getBaseUrl() . '?module=' . $item['module'] . '&controller=items&action=preview&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
                         }
                         $this->view->items[] = Helper_Items::returnViewIndex($item);
                     }
                 }
             }
             $this->view->all_items = array('name' => $this->view->translate('View portfolio'), 'href' => $this->view->author['userhref_pf']);
             break;
         default:
             /* RECENT ITEMS */
             JO_Session::set('redirect', $request->getBaseUrl());
             $this->view->title_items = $this->view->translate('Recent Items');
             $recentItems = Model_Items::getRecent($request->getParam('category_filter'));
             if ($recentItems) {
                 foreach ($recentItems as $n => $item) {
                     if (!empty($item['demo_url'])) {
                         $item['demo_url'] = WM_Router::create($request->getBaseUrl() . '?module=' . $item['module'] . '&controller=items&action=preview&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
                     }
                     $this->view->items[] = Helper_Items::returnViewIndex($item);
                 }
             }
             shuffle($this->view->items);
     }
     $this->view->listType = $listType;
     $this->view->recent_items = WM_Router::create($request->getBaseUrl() . '?controller=recent');
     $this->view->featured = WM_Router::create($request->getBaseUrl() . '?controller=featured');
     $this->view->featuredAuthor = WM_Router::create($request->getBaseUrl() . '?controller=author');
     /* CATEGORIES */
     $this->view->categories = Model_Categories::getMain();
     $this->view->top_categories = $this->view->categories;
     if ($this->view->categories) {
         if ($this->view->categories) {
             foreach ($this->view->categories as $k => $v) {
                 $this->view->categories[$k]['href'] = WM_Router::create($request->getBaseUrl() . '?controller=' . $listType . '&category_filter=' . $v['id']);
             }
         }
     }
     if ($this->view->top_categories) {
         foreach ($this->view->top_categories as $k => $v) {
             $this->view->top_categories[$k]['href'] = WM_Router::create($request->getBaseUrl() . '?controller=categories&category_id=' . $v['id'] . '&name=' . $v['name']);
         }
         shuffle($this->view->top_categories);
         $this->view->top_categories = array_slice($this->view->top_categories, 0, 4);
     }
     $this->view->all_categories = WM_Router::create($request->getBaseUrl() . '?controller=categories&category_id=' . $listType);
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
Пример #4
0
 public function reset_passwordAction()
 {
     $request = $this->getRequest();
     if (JO_Session::get('user_id')) {
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit'));
     }
     $this->view->usersCount = Model_Users::countUsers();
     $this->view->itemsCount = Model_Items::countItems();
     $this->getLayout()->meta_title = $this->translate('Reset password');
     $this->getLayout()->meta_description = $this->translate('Reset password');
     if (JO_Session::get('msg_success')) {
         $this->view->msg_success = JO_Session::get('msg_success');
         JO_Session::clear('msg_success');
     } elseif (JO_Session::get('msg_error')) {
         $this->view->msg_error = JO_Session::get('msg_error');
         JO_Session::clear('msg_error');
     } elseif (JO_Session::get('error')) {
         $this->view->error = JO_Session::get('error');
         JO_Session::clear('error');
     }
     if ($request->isPost() && $request->getPost('send')) {
         $this->view->username = trim($request->getPost('username'));
         $this->view->email = trim($request->getPost('email'));
         $this->view->error = array();
         if (empty($this->view->username)) {
             $this->view->error['username'] = $this->translate('You must type your username');
         } elseif (!preg_match('/^[a-zA-Z0-9_]+$/i', $this->view->username)) {
             $this->view->error['username'] = $this->translate('The username you have entered is not valid');
         }
         if (empty($this->view->email)) {
             $this->view->error['email'] = $this->translate('You must type your email');
         } elseif (!Model_Users::ValidMail($this->view->email)) {
             $this->view->error['email'] = $this->translate('You must type valid email');
         }
         if (empty($this->view->error)) {
             $user = Model_Users::getByEmail($this->view->email);
             if ($user) {
                 $alphabet = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '2', '3', '4', '5', '6', '7', '8', '9');
                 $password = '';
                 for ($i = 0; $i < 7; $i++) {
                     $random_number = rand(0, count($alphabet) - 1);
                     $password .= $alphabet[$random_number];
                 }
                 Model_Users::editPass($user['user_id'], $password);
                 $is_mail_smtp = JO_Registry::forceGet('config_mail_smtp');
                 $mail = new JO_Mail();
                 if ($is_mail_smtp) {
                     $mail->setSMTPParams(JO_Registry::forceGet('config_mail_smtp_host'), JO_Registry::forceGet('config_mail_smtp_port'), JO_Registry::forceGet('config_mail_smtp_user'), JO_Registry::forceGet('config_mail_smtp_password'));
                 }
                 $domain = $request->getDomain();
                 $mail->setFrom('noreply@' . $domain);
                 $mail->setReturnPath('noreply@' . $domain);
                 $mail->setSubject($this->translate('Reset password') . ' ' . JO_Registry::get('store_meta_title'));
                 $html = 'Your new password for ' . $user['username'] . ' is ' . $password;
                 $mail->setHTML($html);
                 $result = (int) $mail->send(array($request->getPost('email')), $is_mail_smtp ? 'smtp' : 'mail');
                 JO_Session::set('msg_success', $this->translate('Your new password was send to your email'));
             } else {
                 JO_Session::set('msg_error', $this->translate('No match found between your username and the email you have input '));
             }
         } else {
             JO_Session::set('error', $this->view->error);
         }
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=reset_password'));
     }
     $this->view->lost_username = WM_Router::create($request->getBaseUrl() . '?controller=users&action=lost_username');
     $this->view->new_account = WM_Router::create($request->getBaseUrl() . '?controller=users&action=registration');
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
Пример #5
0
 public function indexAction()
 {
     $request = $this->getRequest();
     JO_Session::set('redirect', $request->getBaseUrl() . $request->getUri());
     $category_id = $request->getParam('category_id');
     if (!$category_id) {
         return $this->forward('error', 'error404');
     }
     $page = (int) $request->getRequest('page', 1);
     if ($page < 1) {
         $page = 1;
     }
     $limit = JO_Registry::get('front_limit');
     $order = $request->getRequest('order');
     if (is_null($order)) {
         $order = 'desc';
     }
     $sort = $request->getRequest('sort');
     if (is_null($sort)) {
         $sort = 'datetime';
     }
     if ($sort == 'username') {
         $prefix = 'users.';
     } else {
         $prefix = 'items.';
     }
     if (is_numeric($category_id)) {
         $this->view->category = Model_Categories::get($category_id);
         $this->getLayout()->meta_title = $this->view->category['name'];
         $this->getLayout()->meta_description = $this->view->category['name'];
         if ($this->view->category['sub_of'] == 0) {
             $categories = Model_Categories::getMain();
         } else {
             $categories = Model_Categories::getCategories($this->view->category['sub_of']);
             $crumbs_categories = Model_Categories::get_all();
             if ($crumbs_categories) {
                 $parents = Model_Categories::getCategoryParents($crumbs_categories, $category_id);
                 $parents = explode(',', $parents);
                 $parents = array_reverse($parents);
                 $cnt = count($parents) - 1;
                 $crumbs = array();
                 for ($i = 1; $i < $cnt; $i++) {
                     $crumbs[$i] = array('name' => $crumbs_categories[$parents[$i]]['name'], 'href' => WM_Router::create($request->getBaseUrl() . '?controller=categories&category_id=' . $parents[$i] . '&name=' . WM_Router::clearName($crumbs_categories[$parents[$i]]['name'])));
                 }
             }
         }
         /* SORT */
         $link = $request->getBaseUrl() . '?&controller=categories&category_id=' . $category_id;
         $total_records = Model_Items::CountItems($category_id);
         $start = $page * $limit - $limit;
         if ($start > $total_records) {
             $page = max(ceil($total_records / $limit), 1);
             $start = $page * $limit - $limit;
         } elseif ($start < 0) {
             $start = 0;
         }
         $items = Model_Items::getAll($category_id, $start, $limit, ($sort == 'price' ? 'rprice' : $prefix . $sort) . ' ' . $order);
     } else {
         if (in_array($category_id, array('recent', 'featured', 'popular'))) {
             switch ($category_id) {
                 case 'featured':
                     $where = 'items.weekly_to >= \'' . date('Y-m-d') . '\'';
                     $this->view->category['name'] = $this->view->translate('Featured Items');
                     $total_records = Model_Items::countWeekly();
                     break;
                 default:
                     $this->view->category['name'] = $this->view->translate('Recent Items');
                     $total_records = Model_Items::countItems();
             }
             $this->getLayout()->meta_title = $this->view->category['name'];
             $this->getLayout()->meta_description = $this->view->category['name'];
             /* SORT */
             $link = $request->getBaseUrl() . '?controller=categories&action=' . $category_id;
             $start = $page * $limit - $limit;
             if ($start > $total_records) {
                 $last_page = max(ceil($total_records / $limit), 1);
                 $start = $last_page * $limit - $limit;
             } elseif ($start < 0) {
                 $start = 0;
             }
             $items = Model_Items::getAll($category_id, $start, $limit, ($sort == 'price' ? 'rprice' : $prefix . $sort) . ' ' . $order, !empty($where) ? $where : '');
             $categories = Model_Categories::getMain();
         }
     }
     $this->view->sort_by = array(array('name' => $this->view->translate('date'), 'href' => WM_Router::create($link . '&sort=datetime'), 'is_selected' => $sort == 'datetime' ? true : false), array('name' => $this->view->translate('title'), 'href' => WM_Router::create($link . '&sort=name'), 'is_selected' => $sort == 'name' ? true : false), array('name' => $this->view->translate('rating'), 'href' => WM_Router::create($link . '&sort=rating'), 'is_selected' => $sort == 'rating' ? true : false), array('name' => $this->view->translate('sales'), 'href' => WM_Router::create($link . '&sort=sales'), 'is_selected' => $sort == 'sales' ? true : false), array('name' => $this->view->translate('price'), 'href' => WM_Router::create($link . '&sort=price'), 'is_selected' => $sort == 'price' ? true : false), array('name' => $this->view->translate('author name'), 'href' => WM_Router::create($link . '&sort=username'), 'is_selected' => $sort == 'username' ? true : false));
     /* ORDER */
     $link .= '&sort=' . $sort;
     $this->view->orders = array(array('name' => '&raquo;', 'href' => WM_Router::create($link . '&order=desc'), 'is_selected' => $order == 'desc' ? true : false), array('name' => '&laquo;', 'href' => WM_Router::create($link . '&order=asc'), 'is_selected' => $order == 'asc' ? true : false));
     /* CRUMBS */
     $this->view->crumbs = array();
     $this->view->crumbs[] = array('name' => $this->view->translate('Home'), 'href' => $request->getBaseUrl());
     if (isset($crumbs)) {
         $this->view->crumbs += $crumbs;
     }
     /* CATEGORIES */
     if ($categories) {
         $this->view->all_categories_name = $this->translate('All Categories');
         $this->view->categories = array();
         foreach ($categories as $k => $v) {
             $this->view->categories[$k] = array('name' => $v['name'], 'href' => WM_Router::create($request->getBaseUrl() . '?controller=categories&category_id=' . $v['id'] . '&name=' . WM_Router::clearName($v['name'])));
         }
     }
     /* PAGENATION */
     $link .= '&order=' . $order;
     $pagination = new Model_Pagination();
     $pagination->setLimit($limit);
     $pagination->setPage($page);
     $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next')));
     $pagination->setTotal($total_records);
     $pagination->setUrl(WM_Router::create($link . '&page={page}'));
     $this->view->pagination = $pagination->render();
     if (!empty($this->view->pagination)) {
         $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination);
     }
     /* ITEMS */
     if ($items) {
         $this->view->items = array();
         foreach ($items as $n => $item) {
             if (!empty($item['demo_url'])) {
                 $item['demo_url'] = WM_Router::create($request->getBaseUrl() . '?module=' . $item['module'] . '&controller=items&action=preview&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name']));
             }
             $this->view->items[] = Helper_Items::returnViewIndex($item, 'category');
         }
     }
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }