Exemplo n.º 1
0
 public function indexAction()
 {
     $where = '';
     $category = null;
     if ($this->getRequest()->getQuery('username')) {
         $userinfo = Model_Users::getByUsername($this->getRequest()->getQuery('username'));
         if ($userinfo) {
             $where = "users.username = '******'username') . "'";
         }
     }
     if ($this->getRequest()->getQuery('category')) {
         $catinfo = Model_Categories::get($this->getRequest()->getQuery('category'));
         if ($catinfo) {
             $category = $this->getRequest()->getQuery('category');
         }
     }
     $items = Model_Items::getAll($category, 0, 20, 'id desc', $where);
     $this->view->item = array();
     if ($items) {
         $model_images = new Model_Images();
         $categories = Model_Categories::get_all();
         foreach ($items as $item) {
             $categories_string = '';
             if ($category) {
                 foreach ($item['categories'] as $cats) {
                     if (in_array($category, $cats)) {
                         foreach ($cats as $cat) {
                             if (isset($categories[$cat]['name'])) {
                                 $categories_string .= $categories_string ? ' › ' : '';
                                 $categories_string .= $categories[$cat]['name'];
                             }
                         }
                         break;
                     }
                 }
             } else {
                 $cats = array_pop($item['categories']);
                 if ($cats && is_array($cats)) {
                     foreach ($cats as $cat) {
                         if (isset($categories[$cat]['name'])) {
                             $categories_string .= $categories_string ? ' › ' : '';
                             $categories_string .= $categories[$cat]['name'];
                         }
                     }
                 }
             }
             if ((int) JO_Registry::get($item['module'] . '_items_preview_width') && (int) JO_Registry::get($item['module'] . '_items_preview_height')) {
                 $item['theme_preview_thumbnail'] = $this->getRequest()->getBaseUrl() . $model_images->resize($item['theme_preview_thumbnail'], JO_Registry::forceGet($item['module'] . '_items_preview_width'), JO_Registry::forceGet($item['module'] . '_items_preview_height'), true);
             } elseif ((int) JO_Registry::get($item['module'] . '_items_preview_width')) {
                 $item['theme_preview_thumbnail'] = $this->getRequest()->getBaseUrl() . $model_images->resizeWidth($item['theme_preview_thumbnail'], JO_Registry::forceGet($item['module'] . '_items_preview_width'));
             } elseif ((int) JO_Registry::get($item['module'] . '_items_preview_height')) {
                 $item['theme_preview_thumbnail'] = $this->getRequest()->getBaseUrl() . $model_images->resizeHeight($item['theme_preview_thumbnail'], JO_Registry::forceGet($item['module'] . '_items_preview_height'));
             } else {
                 $item['theme_preview_thumbnail'] = false;
             }
             $this->view->item[] = array('title' => $item['name'], 'link' => WM_Router::create($this->getRequest()->getBaseUrl() . '?module=' . $item['module'] . '&controller=items&item_id=' . $item['id']), 'description' => html_entity_decode($item['description'], ENT_QUOTES, 'utf-8'), 'author' => $item['username'], 'category' => $categories_string, 'guid' => $item['id'], 'enclosure' => $item['theme_preview_thumbnail'], 'pubDate' => JO_Date::getInstance($item['datetime'], JO_Date::RSS_FULL, true)->toString());
         }
     }
     echo $this->renderScript('rss');
 }
Exemplo n.º 2
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';
 }
Exemplo n.º 3
0
    public function uploadAction()
    {
        $this->noViewRenderer(true);
        $request = $this->getRequest();
        if ($request->isPost()) {
            $error = array();
            $base_upload_folder = realpath(BASE_PATH . '/uploads');
            $temp_upload_folder = $base_upload_folder . '/temporary/' . JO_Date::getInstance(JO_Session::get('register_datetime'), 'yy/mm', true) . '/';
            $fileTypes = JO_Registry::get('upload_theme');
            if (isset($fileTypes['archives'])) {
                $ew = explode(',', $fileTypes['archives']);
                foreach ($ew as $ar) {
                    $allow_archives[] = '.' . strtolower($ar);
                }
            }
            $allow_images = array();
            if (isset($fileTypes['images'])) {
                $ew = explode(',', $fileTypes['images']);
                foreach ($ew as $ar) {
                    $allow_images[] = '.' . strtolower($ar);
                }
            }
            if (trim($request->getPost('name')) == '') {
                $error['ename'] = $this->translate('You have to input a name');
            }
            if (trim($request->getPost('description')) == '') {
                $error['edescription'] = $this->translate('You have to input a description');
            }
            if (trim($request->getPost('theme_preview')) == '') {
                $error['etheme_preview'] = $this->translate('You have to choose a theme preview');
            }
            if (trim($request->getPost('theme_preview_zip')) == '') {
                $error['etheme_preview_zip'] = $this->translate('You have to choose a file');
            } else {
                if (!in_array(strtolower(strrchr($request->getPost('theme_preview_zip'), '.')), $allow_archives)) {
                    $error['etheme_preview_zip'] = $this->translate('Preview archive file should be ' . implode(', ', $allow_archives) . ' file');
                } elseif (!file_exists($temp_upload_folder . $request->getPost('theme_preview_zip'))) {
                    $error['etheme_preview_zip'] = $this->translate('Preview archive file should be ' . implode(', ', $allow_archives) . ' file');
                }
            }
            if (trim($request->getPost('main_file')) == '') {
                $error['emain_file'] = $this->translate('You have to choose a file');
            } else {
                if (!in_array(strtolower(strrchr($request->getPost('main_file'), '.')), $allow_archives)) {
                    $error['emain_file'] = $this->translate('Main file should be ' . implode(', ', $allow_archives) . ' file');
                } elseif (!file_exists($temp_upload_folder . $request->getPost('main_file'))) {
                    $error['emain_file'] = $this->translate('Main file should be ' . implode(', ', $allow_archives) . ' file');
                }
            }
            if (!$request->getPost('category')) {
                $error['ecategory'] = $this->translate('You have to choose a category');
            } elseif (!is_array($request->getPost('category'))) {
                $error['ecategory'] = $this->translate('You have to choose a category');
            } elseif (!count($request->getPost('category'))) {
                $error['ecategory'] = $this->translate('You have to choose a category');
            }
            $attributes = Model_Attributes::getAllWithCategories("attributes_categories.categories LIKE '%," . (int) $request->getPost('category_id') . ",%'");
            if (is_array($attributes)) {
                $attributesError = false;
                $cnt = count($attributes);
                for ($i = 0; $i < $cnt; $i++) {
                    if (!$request->getPost('attributes[' . $attributes[$i]['head_id'] . ']') && $attributes[$i]['required']) {
                        $attributesError = true;
                        break;
                    }
                }
                if ($attributesError) {
                    $error['eattributes'] = $this->translate('You have to mark all the attributes');
                }
            }
            if (trim($request->getPost('tags')) == '') {
                $error['etags'] = $this->translate('You have to fill the field with tags');
            }
            if (!$request->getPost('source_license')) {
                $error['esource_license'] = $this->translate('You have to confirm that you have rights to use all the materials in your template');
            }
            if ($request->getPost('demo_url') && filter_var($request->getPost('demo_url'), FILTER_VALIDATE_URL) === false) {
                $error['edemo_url'] = $this->translate('Please enter valid url for demo preview');
            }
            if (!$request->getPost('suggested_price') || !preg_match('#^\\d+(?:\\.\\d{1,})?$#', $request->getPost('suggested_price'))) {
                $error['esuggested_price'] = $this->translate('Suggested price should be in the format: number(.number)');
            }
            if (count($error) > 0) {
                $error['msg_error'] = $this->translate('Upload error');
                JO_Session::set('msg_error', $error);
                JO_Session::set('data', $request->getParams());
                $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=upload&action=form&category_id=' . $request->getPost('category_id')));
            } else {
                $free_request = $request->getPost('free_request') ? 'true' : 'false';
                $id = Model_Items::add(array('user_id' => JO_Session::get('user_id'), 'name' => $request->getPost('name'), 'description' => $request->getPost('description'), 'demo_url' => $request->getPost('demo_url'), 'reviewer_comment' => $request->getPost('reviewer_comment'), 'suggested_price' => $request->getPost('suggested_price'), 'free_request' => $free_request, 'default_module' => 'themes'));
                $upload_folder = $base_upload_folder . '/items/' . date("Y/m/") . $id . '/';
                if (!is_dir($upload_folder)) {
                    mkdir($upload_folder, 0777, true);
                }
                $theme_preview = $request->getPost('theme_preview');
                $zip_file = $request->getPost('theme_preview_zip');
                $main_file = $request->getPost('main_file');
                copy($temp_upload_folder . $zip_file, $upload_folder . $zip_file);
                copy($temp_upload_folder . $main_file, $upload_folder . $main_file);
                $uploaded_files = JO_Session::get('uploaded_files');
                $upload_file = array();
                foreach ($uploaded_files[0] as $f) {
                    if ($f['filename'] == $theme_preview) {
                        $upload_file = $f;
                        break;
                    }
                }
                if (!is_dir($upload_folder . 'preview/')) {
                    mkdir($upload_folder . 'preview/', 0777, true);
                }
                $found = false;
                if (file_exists($temp_upload_folder . $theme_preview)) {
                    copy($temp_upload_folder . $theme_preview, $upload_folder . $theme_preview);
                    $preview = $theme_preview;
                    $found = true;
                }
                $zip = new ZipArchive();
                $res = $zip->open($upload_folder . $zip_file);
                if ($res == true) {
                    for ($i = 0; $i < $zip->numFiles; $i++) {
                        $file = $zip->getNameIndex($i);
                        if (stripos($file, '_MACOSX') !== false) {
                            continue;
                        }
                        if (in_array(strtolower(strrchr($file, '.')), $allow_images)) {
                            $fileinfo = pathinfo($file);
                            $prw_filename = $this->rename_if_exists($upload_folder . 'preview/', $fileinfo['basename']);
                            copy("zip://" . $upload_folder . $zip_file . "#" . $file, $upload_folder . 'preview/' . $prw_filename);
                            if (!$found && !empty($fileinfo['basename']) && $fileinfo['basename'] == $upload_file['name']) {
                                $filename = $this->rename_if_exists($upload_folder, $fileinfo['basename']);
                                $found = true;
                                if (copy("zip://" . $upload_folder . $zip_file . "#" . $file, $upload_folder . $filename)) {
                                    $preview = $filename;
                                }
                            }
                        }
                    }
                    $zip->close();
                }
                if (!$found) {
                    $res = $zip->open($upload_folder . $main_file);
                    for ($i = 0; $i < $zip->numFiles; $i++) {
                        $file = $zip->getNameIndex($i);
                        if (stripos($file, '_MACOSX') !== false) {
                            continue;
                        }
                        if (in_array(strtolower(strrchr($file, '.')), $allow_images)) {
                            $fileinfo = pathinfo($file);
                            if (!empty($fileinfo['basename']) && $fileinfo['basename'] == $upload_file['name']) {
                                $filename = $this->rename_if_exists($upload_folder, $fileinfo['basename']);
                                if (copy("zip://" . $upload_folder . $main_file . "#" . $file, $upload_folder . $filename)) {
                                    $preview = $upload_folder . $filename;
                                }
                            }
                        }
                    }
                    $zip->close();
                }
                $item_folder = str_replace($base_upload_folder, '', $upload_folder);
                $uploaded_arhives = JO_Session::get('uploaded_arhives');
                $upload_zip = array();
                foreach ($uploaded_arhives[0] as $f) {
                    if ($f['filename'] == $main_file) {
                        $upload_zip = $f;
                        break;
                    }
                }
                Model_Items::updatePics(array('id' => $id, 'thumbnail' => $item_folder . $preview, 'theme_preview_thumbnail' => $item_folder . $preview, 'theme_preview' => $item_folder . $zip_file, 'main_file' => $item_folder . $main_file, 'main_file_name' => $upload_zip['name']));
                $cats = $request->getPost('category');
                Model_Categories::addToItem($id, $cats, $request->getPost('category_id'));
                $str_tags = trim($request->getPost('tags'), ',');
                $arr = explode(',', $str_tags);
                Model_Tags::addToItem($id, $arr);
                if ($request->getPost('attributes')) {
                    Model_Attributes::addToItem($id, $request->getPost('attributes'));
                }
                if ($uploaded_files) {
                    foreach ($uploaded_files[0] as $f) {
                        if (file_exists($temp_upload_folder . $f['filename'])) {
                            unlink($temp_upload_folder . $f['filename']);
                        }
                    }
                }
                JO_Session::clear('uploaded_files');
                if ($uploaded_arhives) {
                    foreach ($uploaded_arhives[0] as $f) {
                        if (file_exists($temp_upload_folder . $f['filename'])) {
                            unlink($temp_upload_folder . $f['filename']);
                        }
                    }
                }
                JO_Session::clear('uploaded_arhives');
                $category_info = Model_Categories::get($request->getPost('category_id'));
                $is_mail_smtp = JO_Registry::forceGet('config_mail_smtp');
                $not_template = Model_Notification::getNotification('item_added');
                $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('no-reply@' . $domain);
                $mail->setReturnPath('no-reply@' . $domain);
                $mail->setSubject($this->translate('New item for approval') . ' ' . JO_Registry::get('store_meta_title'));
                if ($not_template) {
                    $title = $not_template['title'];
                    $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                    $html = str_replace('{URL}', $request->getBaseUrl() . '/admin/queueitems/edit/?m=' . $category_info['module'] . '&id=' . $id, $html);
                } else {
                    $html = nl2br('Hello,

					There is a new item waiting for approval. You can see it on ' . $request->getBaseUrl() . '/admin/queueitems/edit/?m=' . $category_info['module'] . '&id=' . $id . '');
                }
                $mail->setHTML($html);
                $result = (int) $mail->send(array(JO_Registry::get('report_mail')), $is_mail_smtp ? 'smtp' : 'mail');
                JO_Session::set('msg_success', $this->translate('Your item has been added successfully!'));
                $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=dashboard'));
            }
        }
        $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=upload'));
    }