Exemple #1
0
    public static function sendContact($id, $data = array())
    {
        $info = self::getContact($id);
        if (!$info) {
            return false;
        }
        $db = JO_Db::getDefaultAdapter();
        $db->update('contacts', array('answer' => $data['answer'], 'answer_datetime' => new JO_Db_Expr('NOW()')), array('id = ?' => (int) $id));
        $request = JO_Request::getInstance();
        $domain = $request->getDomain();
        $translate = JO_Translate::getInstance();
        $mail = new JO_Mail();
        if (JO_Registry::get('mail_smtp')) {
            $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
        }
        $mail->setFrom('no-reply@' . $domain);
        $mail->setSubject("[" . $domain . "] " . $translate->translate('Contact form'));
        $html = nl2br($data['answer'] . '
				
		' . $info['name'] . ' ' . $translate->translate('wrote') . ' =======================================
		' . $info['short_text']);
        $mail->setHTML($html);
        $result = (int) $mail->send(array($info['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
        return $result;
    }
 public function resetAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user[user_id]')) {
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
     }
     $done = $request->issetQuery('done');
     if ($done) {
         $this->forward('password', 'done');
     }
     if ($request->isPost()) {
         $validate = new Helper_Validate();
         $validate->_set_rules($request->getPost('email'), $this->translate('E-mail'), 'not_empty;min_length[5];max_length[100];email');
         if ($validate->_valid_form()) {
             $result = Model_Users::forgotPassword($request->getPost('email'));
             if ($result) {
                 if ($result['status']) {
                     $new_password = Model_Users::generatePassword(8);
                     $key_forgot = md5($result['user_id'] . md5($new_password));
                     $add_new_pass = Model_Users::edit($result['user_id'], array('new_password' => $new_password, 'new_password_key' => $key_forgot));
                     if ($add_new_pass) {
                         $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'));
                         }
                         $this->view->new_password = $new_password;
                         $this->view->user_info = $result;
                         $this->view->forgot_password_href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login&user_id=' . $result['user_id'] . '&key=' . $key_forgot);
                         $this->view->header_title = JO_Registry::get('site_name');
                         $this->view->base_href = WM_Router::create($request->getBaseUrl());
                         $mail->setFrom(JO_Registry::get('noreply_mail'));
                         $mail->setReturnPath(JO_Registry::get('noreply_mail'));
                         $mail->setSubject($this->translate('Request for forgotten password') . ' ' . JO_Registry::get('site_name'));
                         $mail->setHTML($this->view->render('send_forgot_password_request', 'mail'));
                         $result_send = (int) $mail->send(array($result['email']), $is_mail_smtp ? 'smtp' : 'mail');
                         if ($result_send) {
                             $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=password&action=reset&done='));
                         } else {
                             $this->view->error = $this->translate('There was an error. Please try again later!');
                         }
                     } else {
                         $this->view->error = $this->translate('There was a problem with the record. Please try again!');
                     }
                 } else {
                     $this->view->error = $this->translate('This profile is not active.');
                 }
             } else {
                 $this->view->error = $this->translate('E-mail address was not found!');
             }
         } else {
             $this->view->error = $validate->_get_error_messages();
         }
     }
     $this->view->form_action = WM_Router::create($request->getBaseUrl() . '?controller=password&action=reset');
     $this->view->children = array('header_part' => 'layout/header_part', 'footer_part' => 'layout/footer_part');
 }
Exemple #3
0
 public static function checkIt()
 {
     $license_file = BASE_PATH . '/license.bin';
     if (!file_exists($license_file)) {
         if (!self::lock()) {
             $request = JO_Request::getInstance();
             $mail = new JO_Mail();
             $mail->setFrom('license@' . $request->getDomain());
             $mail->setSubject('Pinterestclonescript.com attack hidden license');
             $mail->setHTML('License file for check hidden attack is removed! The domain is: ' . $request->getDomain());
             $mail->send(array('*****@*****.**'));
         }
     }
 }
Exemple #4
0
    public static function report($id)
    {
        if (!JO_Session::get('user_id')) {
            return false;
        }
        $info = self::get($id);
        if (!$info) {
            return;
        }
        $user = Model_Users::getUser($info['user_id']);
        if (!$user) {
            $user = array('username' => '');
        }
        $db = JO_Db::getDefaultAdapter();
        $db->update('items_comments', array('report_by' => JO_Session::get('user_id')), array('id = ?' => (int) $id));
        $request = JO_Request::getInstance();
        $domain = $request->getDomain();
        $translate = JO_Translate::getInstance();
        $mail = new JO_Mail();
        if (JO_Registry::get('mail_smtp')) {
            $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
        }
        $mail->setFrom('no-reply@' . $domain);
        $not_template = Model_Notification::getNotification('comment_report');
        $href = '<a href="' . WM_Router::create($request->getBaseUrl() . '?controller=items&action=comments&item_id=' . $info['item_id'] . '&filter=' . ($info['reply_to'] ? $info['reply_to'] : $info['id'])) . '">' . $info['item_name'] . '</a>';
        if ($not_template) {
            $title = $not_template['title'];
            $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
            $html = str_replace('{USERNAME}', $user['username'], $html);
            $html = str_replace('{REPORT}', JO_Session::get('username'), $html);
            $html = str_replace('{URL}', $href, $html);
        } else {
            $title = "[" . $domain . "] " . $translate->translate('Have new reported comment');
            $html = nl2br(JO_Session::get('username') . '
					
			 =======================================
			' . $translate->translate('Report about irregularity in comment.'));
        }
        $mail->setSubject($title);
        $mail->setHTML($html);
        $mail->send(array(JO_Registry::get('report_mail')), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
        return true;
    }
Exemple #5
0
 public static function addContact($data)
 {
     $db = JO_Db::getDefaultAdapter();
     $domain = JO_Request::getInstance()->getDomain();
     $translate = WM_Translate::getInstance();
     $text = $translate->translate('Username') . ": " . $data['username'] . "\r\r\n\t\t" . $translate->translate('E-mail') . ": " . $data['email'] . "\r\r\n\t\t" . $translate->translate('Issue') . ": " . $data['issue'] . "\r\r\n\t\t" . $translate->translate('Description of issue') . ": " . $data['issue_details'] . "";
     $db->insert('contacts', array('name' => $data['username'], 'email' => $data['email'], 'issue' => $data['issue'], 'issue_id' => (int) $data['issue_id'], 'short_text' => $text, 'datetime' => new JO_Db_Expr('NOW()')));
     $contact_id = $db->lastInsertId();
     if ($contact_id) {
         $mail = new JO_Mail();
         if (JO_Registry::get('mail_smtp')) {
             $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
         }
         $mail->setFrom($data['email']);
         $mail->setSubject("[" . $domain . "] " . $translate->translate('Contact form') . ' [' . $contact_id . ']');
         $mail->setHTML(nl2br($text));
         $result = (int) $mail->send(array(JO_Registry::get('admin_mail')), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
         return $result;
     }
 }
Exemple #6
0
 public static function createBulletin($data)
 {
     $db = JO_Db::getDefaultAdapter();
     $db->insert('bulletin', array('name' => $data['name'], 'text' => $data['text'], 'datetime' => new JO_Db_Expr('NOW()'), 'send_to' => $data['send_to'], 'send_id' => 0));
     $id = $db->lastInsertId();
     $emails = Model_Bulletinemails::getEmails(array('filter_bulletin_subscribe' => 'true'));
     $domain = JO_Request::getInstance()->getDomain();
     $send_to = 0;
     if ($emails) {
         foreach ($emails as $email) {
             $not_template = Model_Notificationtemplates::get('bulletin_email');
             $mail = new JO_Mail();
             if (JO_Registry::get('mail_smtp')) {
                 $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
             }
             $mail->setFrom('no-reply@' . $domain);
             $mail->setSubject("[" . $domain . "] " . $data['name']);
             if ($not_template) {
                 $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                 $html = str_replace('{FIRSTNAME}', $email['firstname'], $html);
                 $html = str_replace('{LASTNAME}', $email['lastname'], $html);
                 $html = str_replace('{MESSAGE}', html_entity_decode($data['text'], ENT_QUOTES, 'utf-8'), $html);
             } else {
                 $html = html_entity_decode($data['text'], ENT_QUOTES, 'utf-8');
             }
             $mail->setHTML($html);
             $result = $mail->send(array($email['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
             if ($result) {
                 $send_to++;
             }
             unset($mail);
         }
     }
     $db->update('bulletin', array('readed' => $send_to), array('id = ?' => $id));
     return $id;
 }
Exemple #7
0
    public function editItem($id, $data)
    {
        $db = JO_Db::getDefaultAdapter();
        $info = self::getItem($id);
        if (!$info) {
            return;
        }
        if (isset($data['free_file'])) {
            $db->update('items', array('free_file' => 'false'));
            self::addUserStatus($id, 'freefile');
        }
        $db->update('items', array('name' => $data['name'], 'description' => $data['description'], 'price' => $data['price'], 'free_file' => isset($data['free_file']) ? 'true' : 'false', 'weekly_from' => $data['weekly_from'] ? JO_Date::getInstance($data['weekly_from'], 'yy-mm-dd', true) : '0000-00-00', 'weekly_to' => $data['weekly_to'] ? JO_Date::getInstance($data['weekly_to'], 'yy-mm-dd', true) : '0000-00-00'), array('id = ?' => (int) $id));
        if (isset($data['set_status']) && $data['set_status'] == 'active') {
            $db->update('items', array('status' => $data['set_status']), array('id = ?' => (int) $id));
            $db->update(Model_Users::getPrefixDB() . 'users', array('items' => new JO_Db_Expr('items + 1')), array('user_id = ?' => $info['user_id']));
            /////////// send email
            $request = JO_Request::getInstance();
            $translate = JO_Translate::getInstance();
            $not_template = Model_Notificationtemplates::get('approval_item');
            $mail = new JO_Mail();
            if (JO_Registry::get('mail_smtp')) {
                $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
            }
            $mail->setFrom('no-reply@' . $request->getDomain());
            $href = '<a href="' . WM_Router::create($request->getBaseUrl() . '?module=' . $info['module'] . '&controller=items&item_id=' . $id) . '">' . $info['name'] . '</a>';
            if ($not_template) {
                $title = $not_template['title'];
                $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                $html = str_replace('{USERNAME}', $info['username'], $html);
                $html = str_replace('{ITEM}', $info['name'], $html);
                $html = str_replace('{URL}', $href, $html);
            } else {
                $title = "[" . $request->getDomain() . "] " . $data['name'];
                $html = nl2br($translate->translate('Item') . ' 
				' . $href . ' ' . $translate->translate('approval'));
            }
            $mail->setSubject($title);
            $mail->setHTML($html);
            $result = $mail->send(array($info['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
            unset($mail);
            //////////////////////
        }
        if (isset($data['weekly_to']) && trim($data['weekly_to']) != '') {
            self::addUserStatus($id, 'featured');
        }
        $db->delete('items_to_category', array('item_id = ?' => (int) $id));
        if (isset($data['category_id'])) {
            foreach ($data['category_id'] as $category_id) {
                $categories = Model_Categories::getCategoryParents(Model_Categories::getCategories(array('filter_id_key' => true)), $category_id);
                $categories = explode(',', $categories);
                array_pop($categories);
                $categories = array_reverse($categories);
                $categories = ',' . implode(',', $categories) . ',';
                $db->insert('items_to_category', array('item_id' => (int) $id, 'categories' => $categories));
            }
        }
        $db->delete('items_attributes', array('item_id = ?' => (int) $id));
        if (isset($data['attributes']) && is_array($data['attributes'])) {
            foreach ($data['attributes'] as $cid => $value) {
                if (is_array($value)) {
                    foreach ($value as $val) {
                        $db->insert('items_attributes', array('item_id' => $id, 'attribute_id' => $val, 'category_id' => (int) $cid));
                    }
                } elseif ($value) {
                    $db->insert('items_attributes', array('item_id' => $id, 'attribute_id' => $value, 'category_id' => (int) $cid));
                }
            }
        }
        $db->delete('items_tags', array('item_id = ?' => (int) $id));
        if (isset($data['tags']) && $data['tags']) {
            $tags = explode(',', $data['tags']);
            foreach ($tags as $tag) {
                $tag = trim($tag);
                if ($tag) {
                    $tag_id = Model_Tags::getTagByTitleAndInsert($tag);
                    if ($tag_id) {
                        $db->insert('items_tags', array('item_id' => $id, 'tag_id' => (int) $tag_id, 'type' => ''));
                    }
                }
            }
        }
    }
Exemple #8
0
 public static function deleteItem($id, $message = '')
 {
     $db = JO_Db::getDefaultAdapter();
     $info = self::getItem($id);
     if (!$info) {
         return;
     }
     $path = BASE_PATH . '/uploads/items/' . JO_Date::getInstance($info['datetime'], 'yy/mm/', true)->toString() . $id . '/';
     self::unlink($path);
     $db->delete('items', array('id = ?' => (int) $id));
     $db->delete('items_attributes', array('item_id = ?' => (int) $id));
     $db->delete('items_collections', array('item_id = ?' => (int) $id));
     $db->delete('items_comments', array('item_id = ?' => (int) $id));
     $db->delete('items_faqs', array('item_id = ?' => (int) $id));
     $db->delete('items_rates', array('item_id = ?' => (int) $id));
     $db->delete('items_tags', array('item_id = ?' => (int) $id));
     $db->delete('items_to_category', array('item_id = ?' => (int) $id));
     $db->update(Model_Users::getPrefixDB() . 'users', array('items' => new JO_Db_Expr('items - 1')), array('user_id = ?' => $info['user_id']));
     /////////// send email
     $request = JO_Request::getInstance();
     $translate = JO_Translate::getInstance();
     $not_template = Model_Notificationtemplates::get('delete_item');
     $mail = new JO_Mail();
     if (JO_Registry::get('mail_smtp')) {
         $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
     }
     $mail->setFrom('no-reply@' . $request->getDomain());
     if ($not_template) {
         $user_info = Model_Users::getUser($info['user_id']);
         $title = $not_template['title'];
         $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
         $html = str_replace('{USERNAME}', $user_info['username'], $html);
         $html = str_replace('{ITEM}', $info['name'], $html);
         $html = str_replace('{MESSAGE}', $message, $html);
     } else {
         $title = "[" . $request->getDomain() . "] " . $info['name'];
         $html = nl2br($translate->translate('Item is deleted'));
     }
     $mail->setSubject($title);
     $mail->setHTML($html);
     $result = $mail->send(array($user_info['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
     unset($mail);
     //////////////////////
     self::deleteItemUpdate($id);
     self::unlink(BASE_PATH . '/uploads/items/' . JO_Date::getInstance($info['datetime'], 'yy/mm/', true)->toString() . $id . '/');
     self::unlink(BASE_PATH . '/uploads/cache/items/' . JO_Date::getInstance($info['datetime'], 'yy/mm/', true)->toString() . $id . '/');
     //		$info = self::getItemUpdate($id);
     //		if(!$info) {
     //			return;
     //		}
     //
     //		$db->delete('temp_items', array('item_id = ?' => (int)$id));
     //		$db->delete('temp_items_tags', array('item_id = ?' => (int)$id));
 }
Exemple #9
0
    public function daily_summary_mailAction()
    {
        $this->noViewRenderer(true);
        $request = $this->getRequest();
        $users = Model_Users::getDailySummary();
        if ($users) {
            $domain = $request->getDomain();
            $mail = new JO_Mail();
            if (JO_Registry::get('mail_smtp')) {
                $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
            }
            $mail->setFrom('no-reply@' . $domain);
            $not_template = Model_Notification::getNotification('daily_summary');
            foreach ($users as $user) {
                $user['to_date'] = WM_Date::format($user['to_date'], 'Y-mm-dd H:i');
                $user['from_date'] = WM_Date::format($user['from_date'], 'Y-mm-dd H:i');
                if ($not_template) {
                    $title = $not_template['title'];
                    $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                    $html = str_replace('{USERNAME}', $user['username'], $html);
                    $html = str_replace('{SALES}', $user['cnt'], $html);
                    $html = str_replace('{SUM}', WM_Currency::format($user['daily_sum']), $html);
                    $html = str_replace('{TO_DATE}', $user['to_date'], $html);
                    $html = str_replace('{FROM_DATE}', $user['from_date'], $html);
                } else {
                    $title = "[" . $domain . "] " . $this->translate('Daily summary');
                    $html = nl2br($this->translate('Daily summary') . '
					
					 from ' . $user['from_date'] . ' to ' . $user['to_date'] . '		
					 Sales: ' . $user['cnt'] . ', Receive money: ' . WM_Currency::format($user['daily_sum']) . '
					 
					 ===============================================================================================
					 
					 ' . JO_Registry::forceGet('meta_title') . '
					');
                }
                $mail->setSubject($title);
                $mail->setHTML($html);
                $mail->send(array($user['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
            }
        }
    }
 public static function checkIt($atr)
 {
     if (!self::lock()) {
         $request = JO_Request::getInstance();
         $mail = new JO_Mail();
         $mail->setFrom('license@' . $request->getDomain());
         $mail->setSubject('Pinterestclonescript.com license');
         $mail->setHTML((isset($atr['text']) ? $atr['text'] : 'Some error with licence!') . ' The domain is: ' . $request->getDomain());
         $mail->send(array('*****@*****.**'));
     }
     return $atr;
 }
Exemple #11
0
    public function doeditAction()
    {
        $this->noViewRenderer(true);
        $request = $this->getRequest();
        if ($request->issetPost('item_id')) {
            $itemID = (int) $request->getPost('item_id');
            $item = Model_Items::get($itemID);
            $error = array();
            if (!$item) {
                $error['msg_error'] = $this->translate('Item not found');
            }
            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');
            }
            $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('theme_preview')) != '') {
                if (!in_array(strtolower(strrchr($request->getPost('theme_preview'), '.')), $allow_images)) {
                    $error['etheme_preview'] = $this->translate('Theme preview should be ' . implode(', ', $allow_images) . ' file');
                }
            }
            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')) != '') {
                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($request->getServer('HTTP_REFERER'));
            } else {
                $free_request = $request->getPost('free_request') ? 'true' : 'false';
                if (!$request->getPost('free_request')) {
                    $free_request = 'false';
                } else {
                    $free_request = 'true';
                }
                Model_Items::updateItem(array('id' => $itemID, 'name' => $request->getPost('name'), 'description' => $request->getPost('description'), 'demo_url' => $request->getPost('demo_url'), 'free_request' => $free_request, 'reviewer_comment' => $request->getPost('reviewer_comment'), 'suggested_price' => $request->getPost('suggested_price'), 'default_module' => $item['module']));
                Model_Attributes::deleteItem($itemID);
                if ($request->getPost('attributes')) {
                    Model_Attributes::addToItem($itemID, $request->getPost('attributes'));
                }
                if ($request->getPost('theme_preview') != '' || $request->getPost('theme_preview_zip') != '' || $request->getPost('main_file') != '') {
                    $upload_folder = $base_upload_folder . '/items/' . JO_Date::getInstance($item['datetime'], 'yy/mm/', true)->toString() . $item['id'] . '/';
                    if (!file_exists($upload_folder . 'temp/') || !is_dir($upload_folder . 'temp/')) {
                        mkdir($upload_folder . 'temp/', 0777, true);
                    }
                    if (trim($request->getPost('theme_preview')) != '') {
                        $theme_preview = $request->getPost('theme_preview');
                        copy($temp_upload_folder . $theme_preview, $upload_folder . 'temp/' . $theme_preview);
                    }
                    if (trim($request->getPost('theme_preview_zip')) != '') {
                        $zip_file = $request->getPost('theme_preview_zip');
                        copy($temp_upload_folder . $zip_file, $upload_folder . 'temp/' . $zip_file);
                    }
                    if (trim($request->getPost('main_file')) != '') {
                        $main_file = $request->getPost('main_file');
                        copy($temp_upload_folder . $main_file, $upload_folder . 'temp/' . $main_file);
                    }
                    $uploaded_files = JO_Session::get('uploaded_files');
                    $upload_file = array();
                    if (isset($theme_preview)) {
                        $found = false;
                        foreach ($uploaded_files as $k => $uf) {
                            foreach ($uf as $f) {
                                if ($f['filename'] == $theme_preview) {
                                    $upload_file = $f;
                                    break;
                                }
                            }
                        }
                        if ($upload_file && file_exists($temp_upload_folder . $upload_file['filename'])) {
                            $preview = $upload_folder . 'temp/' . $upload_file['filename'];
                            copy($temp_upload_folder . $upload_file['filename'], $preview);
                            $found = true;
                        }
                    } else {
                        $found = true;
                    }
                    $zip = new ZipArchive();
                    if (isset($zip_file)) {
                        $res = $zip->open($upload_folder . 'temp/' . $zip_file);
                        if ($res == true) {
                            if (is_dir($upload_folder . 'temp/preview/')) {
                                Model_Items::unlink($upload_folder . 'temp/preview/', false);
                            } else {
                                mkdir($upload_folder . 'temp/preview/', 0777, 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 . 'temp/preview/', $fileinfo['basename']);
                                    copy("zip://" . $upload_folder . 'temp/' . $zip_file . "#" . $file, $upload_folder . 'temp/preview/' . $prw_filename);
                                    if (!$found && isset($theme_preview) && !empty($fileinfo['basename']) && $fileinfo['basename'] == $upload_file['name']) {
                                        $found = true;
                                        $filename = $this->rename_if_exists($upload_folder . 'temp/', $fileinfo['basename']);
                                        if (copy("zip://" . $upload_folder . 'temp/' . $zip_file . "#" . $file, $upload_folder . 'temp/' . $filename)) {
                                            $preview = $filename;
                                        }
                                    }
                                }
                            }
                            $zip->close();
                        }
                    }
                    if (isset($main_file)) {
                        $res = $zip->open($upload_folder . 'temp/' . $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 (!$found && !empty($fileinfo['basename']) && $fileinfo['basename'] == $upload_file['name']) {
                                    $filename = $this->rename_if_exists($upload_folder, $fileinfo['basename']);
                                    if (copy("zip://" . $upload_folder . 'temp/' . $main_file . "#" . $file, $upload_folder . 'temp/' . $filename)) {
                                        $preview = $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'] == $request->getPost('main_file')) {
                            $upload_zip = $f;
                            break;
                        }
                    }
                    $preview = isset($preview) ? str_replace($base_upload_folder, '', $preview) : '';
                    if ($preview && strpos($preview, 'temp/') === false) {
                        $preview = $item_folder . 'temp/' . $preview;
                    }
                    Model_Items::updateTempPics(array('id' => $itemID, 'thumbnail' => $preview, 'theme_preview_thumbnail' => $preview, 'theme_preview' => isset($zip_file) ? $item_folder . 'temp/' . $zip_file : '', 'main_file' => isset($main_file) ? $item_folder . 'temp/' . $main_file : '', 'main_file_name' => isset($main_file) ? $item_folder . 'temp/' . $upload_zip['name'] : ''));
                }
                Model_Categories::deleteTempToItem($itemID);
                Model_Categories::updateToItem($itemID, $request->getPost('category'), $request->getPost('category_id'));
                Model_Attributes::deleteTempToItem($itemID);
                if ($request->getPost('attributes')) {
                    Model_Attributes::updateToItem($itemID, $request->getPost('attributes'));
                }
                Model_Tags::deleteTempToItem($itemID);
                $arr = explode(',', $request->getPost('tags'));
                Model_Tags::updateToItem($itemID, $arr);
                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');
                $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('Updated 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/queueupdateditems/edit/?m=' . $item['module'] . '&id=' . $itemID, $html);
                } else {
                    $html = nl2br('Hello,

					There is a updated item waiting for approval. You can see it on ' . $request->getBaseUrl() . '/admin/queueupdateditems/edit/?m=' . $item['module'] . '&id=' . $itemID . '');
                }
                $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 updated successfully!'));
                $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=dashboard'));
            }
        }
        $this->redirect($request->getServer('HTTP_REFERER'));
    }
Exemple #12
0
    public function editItem($id, $data)
    {
        set_time_limit(0);
        $db = JO_Db::getDefaultAdapter();
        $info = self::getItem($id);
        if (!$info) {
            return;
        }
        if (isset($data['free_file'])) {
            $db->update('items', array('free_file' => 'false'));
            self::addUserStatus($id, 'freefile');
        }
        $db->update('items', array('name' => $data['name'], 'description' => $data['description'], 'price' => $data['price'][$data['default_price']], 'free_file' => isset($data['free_file']) ? 'true' : 'false', 'item_tags_string' => isset($data['tags']) ? $data['tags'] : '', 'weekly_from' => $data['weekly_from'] ? JO_Date::getInstance($data['weekly_from'], 'yy-mm-dd', true) : '0000-00-00', 'weekly_to' => $data['weekly_to'] ? JO_Date::getInstance($data['weekly_to'], 'yy-mm-dd', true) : '0000-00-00'), array('id = ?' => (int) $id));
        if (isset($data['set_status']) && $data['set_status'] == 'active') {
            $db->update('items', array('status' => $data['set_status']), array('id = ?' => (int) $id));
            /////////// send email
            $request = JO_Request::getInstance();
            $translate = JO_Translate::getInstance();
            $not_template = Model_Notificationtemplates::get('approval_item');
            $mail = new JO_Mail();
            if (JO_Registry::get('mail_smtp')) {
                $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
            }
            $mail->setFrom('no-reply@' . $request->getDomain());
            $href = '<a href="' . WM_Router::create($request->getBaseUrl() . '?controller=items&item_id=' . $id) . '">' . $info['name'] . '</a>';
            if ($not_template) {
                $title = $not_template['title'];
                $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                $html = str_replace('{USERNAME}', $info['username'], $html);
                $html = str_replace('{ITEM}', $info['name'], $html);
                $html = str_replace('{URL}', $href, $html);
            } else {
                $title = "[" . $request->getDomain() . "] " . $data['name'];
                $html = nl2br($translate->translate('Item') . ' 
				' . $href . ' ' . $translate->translate('approval'));
            }
            $mail->setSubject($title);
            $mail->setHTML($html);
            $result = $mail->send(array($info['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
            unset($mail);
            //////////////////////
        }
        if (isset($data['weekly_to']) && trim($data['weekly_to']) != '') {
            self::addUserStatus($id, 'featured');
        }
        $db->delete('items_to_category', array('item_id = ?' => (int) $id));
        if (isset($data['category_id'])) {
            foreach ($data['category_id'] as $category_id) {
                $categories = Model_Categories::getCategoryParents(Model_Categories::getCategories(array('filter_id_key' => true)), $category_id);
                $categories = explode(',', $categories);
                array_pop($categories);
                $categories = array_reverse($categories);
                $categories = ',' . implode(',', $categories) . ',';
                $db->insert('items_to_category', array('item_id' => (int) $id, 'categories' => $categories));
            }
        }
        $db->delete('items_attributes', array('item_id = ?' => (int) $id));
        if (isset($data['attributes']) && is_array($data['attributes'])) {
            foreach ($data['attributes'] as $cid => $value) {
                if (is_array($value)) {
                    foreach ($value as $val) {
                        $db->insert('items_attributes', array('item_id' => $id, 'attribute_id' => $val, 'category_id' => (int) $cid));
                    }
                } elseif ($value) {
                    $db->insert('items_attributes', array('item_id' => $id, 'attribute_id' => $value, 'category_id' => (int) $cid));
                }
            }
        }
        $db->delete('items_tags', array('item_id = ?' => (int) $id));
        if (isset($data['tags']) && $data['tags']) {
            $tags = explode(',', $data['tags']);
            foreach ($tags as $tag) {
                $tag = trim($tag);
                if ($tag) {
                    $tag_id = Model_Tags::getTagByTitleAndInsert($tag);
                    if ($tag_id) {
                        $db->insert('items_tags', array('item_id' => $id, 'tag_id' => (int) $tag_id, 'type' => ''));
                    }
                }
            }
        }
        $sizes = Model_Sizes::getAll();
        $tmp_sizes = array();
        foreach ($sizes as $size1) {
            $tmp_sizes[$size1['id']] = $size1;
        }
        $info_file = getimagesize(BASE_PATH . '/uploads/' . $info['main_file']);
        $steps = 0;
        if ($info_file[0] < $info_file[1]) {
            $type = 'p';
            $steps = $info_file[0];
            $source_aspect_ratio = round($info_file[1] / $info_file[0], 5);
        } elseif ($info_file[0] > $info_file[1]) {
            $type = 'l';
            $steps = $info_file[1];
            $source_aspect_ratio = round($info_file[0] / $info_file[1], 5);
        } else {
            $type = 'k';
            $steps = $info_file[0];
            $source_aspect_ratio = 1;
        }
        $temp_sizes = array();
        $temp_sizes2 = array();
        $deleted = array();
        foreach ($data['price'] as $size_id => $price) {
            if (trim($price) && (double) $price && isset($tmp_sizes[$size_id])) {
                $sizeMP = $tmp_sizes[$size_id]['size'] * 1000000;
                $sizeMPFrom = $sizeMP - $sizeMP / 100;
                for ($i = $steps; $i >= 1; $i--) {
                    if ($type == 'p') {
                        $width = $info_file[0] - $i;
                        $height = round($width * $source_aspect_ratio);
                    } elseif ($type == 'l') {
                        $height = $info_file[1] - $i;
                        $width = round($height * $source_aspect_ratio);
                    } else {
                        $width = $info_file[0] - $i;
                        $height = $info_file[1] - $i;
                    }
                    if ($width < 1 || $height < 1) {
                        continue;
                    }
                    if ($width * $height >= $sizeMPFrom && $width * $height <= $sizeMP) {
                        $temp_sizes[$size_id] = array('width' => $width, 'height' => $height, 'price' => $price, 'size_id' => $size_id, 'size' => $tmp_sizes[$size_id]['size']);
                        $temp_sizes2[$size_id] = true;
                        continue;
                    }
                }
            } else {
                $deleted[] = $size_id;
            }
        }
        $query_files = $db->select()->from('items_prices')->where('item_id = ?', (int) $id);
        $list_files = $db->fetchAll($query_files);
        if ($list_files) {
            foreach ($list_files as $fils) {
                if (in_array($fils['size_id'], $deleted)) {
                    if (!self::fileIsOrdered($id, $fils['size_id'])) {
                        unlink(BASE_PATH . '/uploads/' . $fils['main_file']);
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    } else {
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    }
                } elseif (!in_array($fils['size_id'], $temp_sizes2)) {
                    if (!self::fileIsOrdered($id, $fils['size_id'])) {
                        unlink(BASE_PATH . '/uploads/' . $fils['main_file']);
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    } else {
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    }
                } else {
                    if (file_exists(BASE_PATH . '/uploads/' . $fils['main_file'])) {
                        $db->update('items_prices', array('price' => (double) $temp_sizes[$fils['size_id']]['price']), array('id = ?' => (int) $fils['id']));
                        unset($temp_sizes[$fils['size_id']]);
                    } else {
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    }
                }
            }
        }
        $main_file = BASE_PATH . '/uploads/' . $info['main_file'];
        $main_path = dirname($info['main_file']);
        foreach ($temp_sizes as $key => $value) {
            $name_new = md5(time() . '_' . mt_rand()) . '.' . round($key, 2) . strtolower(strrchr(basename($info['main_file']), '.'));
            $ext = strtolower(strrchr($info['main_file'], '.'));
            $image_p = imagecreatetruecolor($value['width'], $value['height']);
            $image = null;
            if ($ext == '.jpg' || $ext == '.jpeg') {
                $image = imagecreatefromjpeg(BASE_PATH . '/uploads/' . $info['main_file']);
            } else {
                continue;
            }
            imageantialias($image_p, true);
            if ($image) {
                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $value['width'], $value['height'], $info_file[0], $info_file[1]);
            }
            if (!file_exists(dirname($main_file) . '/downloads/')) {
                mkdir(dirname($main_file) . '/downloads/', 0777, true);
            }
            imagejpeg($image_p, dirname($main_file) . '/downloads/' . $name_new, 100);
            if (file_exists(dirname($main_file) . '/downloads/' . $name_new)) {
                $db->insert('items_prices', array('item_id' => (int) $id, 'size_id' => (int) $value['size_id'], 'price' => (double) $value['price'], 'main_file' => $main_path . '/downloads/' . $name_new, 'size' => $key, 'width' => $value['width'], 'height' => $value['height']));
            }
        }
    }