Beispiel #1
0
 public static function format($date, $format = null)
 {
     if (!$format) {
         $format = JO_Translate::getInstance()->translate('dd.mm.yy');
     }
     return (string) new JO_Date($date, $format);
 }
Beispiel #2
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;
    }
Beispiel #3
0
 public static function getType($type)
 {
     static $result = array(), $translate = null;
     if (isset($result[$type])) {
         return $result[$type];
     }
     if ($translate === null) {
         $translate = JO_Translate::getInstance();
     }
     $array = array(self::REPIN => $translate->translate('repinned your pin.'), self::FOLLOW => $translate->translate('is now following your pins.'), self::UNFOLLOW => $translate->translate('has unfollow your pins.'), self::FOLLOW_USER => $translate->translate('is now following you'), self::UNFOLLOW_USER => $translate->translate('has unfollow you'), self::ADDPIN => $translate->translate('Pinned to'), self::ADDBOARD => $translate->translate('Created'), self::LIKEPIN => $translate->translate('Like your pin'), self::UNLIKEPIN => $translate->translate('Unlike your pin'), self::COMMENTPIN => $translate->translate('Comment your pin'));
     if (isset($array[$type])) {
         $result[$type] = $array[$type];
         return $array[$type];
     } else {
         return false;
     }
 }
Beispiel #4
0
 public static function prepare_bbcode_template($bbcode_tpl)
 {
     $translate = JO_Translate::getInstance();
     $bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']);
     $bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $translate->translate('Quote'), $bbcode_tpl['quote_open']);
     $bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']);
     // We do URLs in several different ways..
     $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
     $bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);
     $bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
     $bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);
     $bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
     $bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);
     $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
     $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);
     $bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']);
     self::$BBCODE_TPL_READY = true;
     return $bbcode_tpl;
 }
Beispiel #5
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;
    }
Beispiel #6
0
 public function translate($string)
 {
     return JO_Translate::getInstance()->translate($string);
 }
Beispiel #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' => ''));
                    }
                }
            }
        }
    }
Beispiel #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));
 }
Beispiel #9
0
 public function depositIsPay($id)
 {
     $row = self::getDeposit($id);
     if ($row) {
         if ($row['added'] == 'true') {
             return;
         }
         $db = JO_Db::getDefaultAdapter();
         if (JO_Session::get('user_id')) {
             $user_data = Model_Users::getUser($row['user_id']);
             /* razkomentirame, ako iskame da nachislqva pari na referral_id i pri deposit
             			if($user_data['referal_id'] > 0) {
             				
             				$referal = Model_Users::getUser($user_data['referal_id']);
             				
             				$referal_cnt = JO_Registry::forceGet('referal_sum');
             				
             				$percent = str_replace('%', '', JO_Registry::forceGet('referal_percent'));
             				$sum = $row['deposit'] * ((int) $percent / 100);
             				
             				if($referal_cnt > 0) {
             					$cnt = Model_Users::getTotalReferals($user_data['user_id'], $user_data['referal_id']);
             					if(($cnt + 1) >= $referal_cnt)
             						$user_data['referal_id'] = 0;
             				}
             				
             				$db->update(Model_Users::getPrefixDB().'users', array(
             					'earning' => new JO_Db_Expr('earning + ' . $sum),
             					'total' => new JO_Db_Expr('total + ' . $sum)
             				), array('user_id = ?' => (int)$referal['user_id']));
             				
             				$db->insert(Model_Users::getPrefixDB().'users_referals_count', array(
             					'user_id' => (int)$row['user_id'],
             					'referal_id' => (int)$referal['user_id'],
             					'datetime' => new JO_Db_Expr('NOW()'),
             					'order_type' => 'deposit',
             					'referal_sum' => (float) $sum
             				));
             			}
             			*/
             $db->update(Model_Users::getPrefixDB() . 'users', array('deposit' => new JO_Db_Expr('deposit + ' . $row['deposit']), 'total' => new JO_Db_Expr('total + ' . $row['deposit'])), array('user_id = ?' => (int) $row['user_id']));
             $db->update(Model_Users::getPrefixDB() . 'deposit', array('added' => 'true'), array('id = ?' => (int) $id));
             if ($user_data) {
                 $groups = unserialize($user_data['groups']);
                 if (is_array($groups) && count($groups) > 0) {
                     $query_group = $db->select()->from(Model_Users::getPrefixDB() . 'user_groups')->where("ug_id IN (?)", new JO_Db_Expr(implode(',', array_keys($groups))));
                     $fetch_all = $db->fetchAll($query_group);
                     $user_data['access'] = array();
                     if ($fetch_all) {
                         foreach ($fetch_all as $row) {
                             $modules = unserialize($row['rights']);
                             if (is_array($modules)) {
                                 foreach ($modules as $module => $ison) {
                                     $user_data['access'][$module] = $module;
                                 }
                             }
                         }
                     }
                 }
             }
             if ($user_data) {
                 if (isset($user_data['access']) && count($user_data['access'])) {
                     $user_data['is_admin'] = true;
                 }
                 JO_Session::set($user_data);
             }
         }
         $translate = JO_Translate::getInstance();
         Model_History::add($translate->translate('Deposit from') . ' ' . WM_Currency::format($row['deposit']), $id, $row['user_id']);
     }
 }
Beispiel #10
0
    public function add_commentAction()
    {
        $this->noViewRenderer(true);
        $request = $this->getRequest();
        if (!JO_Session::get('user_id')) {
            JO_Session::set('msg_error', $this->translate('You must be logged to change your profile'));
            $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
        }
        if ($request->getRequest('add_comment')) {
            $item = Model_Items::get($request->getRequest('add_comment'));
            $user = Model_Users::getUser($item['user_id']);
            if ($item) {
                $comment = trim($request->getPost('comment'));
                if (!empty($comment)) {
                    $data = array('owner_id' => (int) $item['user_id'], 'item_id' => (int) $item['id'], 'item_name' => $item['name'], 'user_id' => JO_Session::get('user_id'), 'comment' => $comment, 'notify' => $request->getPost('reply_notification') ? 'true' : 'false', 'reply_to' => 0);
                    $id = Model_Comments::add($data);
                    if ($id && JO_Session::get('user_id') != $item['user_id']) {
                        $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);
                        $href = '<a href="' . WM_Router::create($request->getBaseUrl() . '?controller=items&action=comments&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name'])) . '">' . $item['name'] . ' - ' . $this->translate('Comments') . '</a>';
                        $not_template = Model_Notification::getNotification('new_comment_item');
                        if ($not_template) {
                            $title = $not_template['title'];
                            $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                            $html = str_replace('{ITEMNAME}', $item['name'], $html);
                            $html = str_replace('{URL}', $href, $html);
                        } else {
                            $title = "[" . $domain . "] " . $translate->translate('Have new reply to your comment');
                            $html = nl2br($translate->translate('A reply is added to your comment') . '
									
							 ' . $href . '
							');
                        }
                        $mail->setSubject($title);
                        $mail->setHTML($html);
                        $mail->send(array($user['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
                    }
                    JO_Session::set('msg_success', $this->translate('The comment has been added successfully'));
                } else {
                    JO_Session::set('msg_error', $this->translate('Your comment is empty'));
                }
            } else {
                JO_Session::set('msg_error', $this->translate('The item not found'));
            }
        } else {
            JO_Session::set('msg_error', $this->translate('The comment has not been added'));
        }
        $this->redirect($request->getServer('HTTP_REFERER') . ($id ? '#c_' . $id : ''));
    }
Beispiel #11
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']));
            }
        }
    }
Beispiel #12
0
 public static function deleteBalance($balance_id)
 {
     $db = JO_Db::getDefaultAdapter();
     $row = self::getBalance($balance_id);
     if (!$row) {
         return;
     }
     $aff = $db->delete('deposit', array('id = ?' => (int) $balance_id));
     if ($aff) {
         $db->update(Model_Users::getPrefixDB() . 'users', array('deposit' => new JO_Db_Expr('deposit - ' . (int) $row['deposit']), 'total' => new JO_Db_Expr('total - ' . (int) $row['deposit'])), array('user_id = ?' => (int) $row['user_id']));
         $translate = JO_Translate::getInstance();
         Model_History::add($translate->translate('[Delete from admin ' . ($row['paid'] == 'true' ? '"paid"' : '"not paid"') . '] Deposit from') . ' ' . WM_Currency::format($row['deposit']), $balance_id, $row['user_id']);
     }
     return $balance_id;
 }