function __construct() { parent::__construct(); // check if is moderator and can enter to this page if ($this->isModerator()) { if (!in_array($this->page, osc_apply_filter('moderator_access', array('items', 'comments', 'media', 'login', 'admins', 'ajax', 'stats', '')))) { osc_add_flash_error_message(_m("You don't have enough permissions"), 'admin'); $this->redirectTo(osc_admin_base_url()); } } osc_run_hook('init_admin'); $config_version = str_replace('.', '', OSCLASS_VERSION); $config_version = preg_replace('|-.*|', '', $config_version); if ($config_version > osc_get_preference('version')) { if (get_class($this) == 'CAdminTools') { } else { if (get_class($this) != 'CAdminUpgrade') { $this->redirectTo(osc_admin_base_url(true) . '?page=upgrade'); } } } // show donation successful if (Params::getParam('donation') == 'successful') { osc_add_flash_ok_message(_m('Thank you very much for your donation'), 'admin'); } // enqueue scripts osc_enqueue_script('jquery'); osc_enqueue_script('jquery-ui'); osc_enqueue_script('admin-osc'); osc_enqueue_script('admin-ui-osc'); }
function admin_header_favicons() { $favicons = array(); $favicons[] = array('rel' => 'shortcut icon', 'sizes' => '', 'href' => osc_current_admin_theme_url('images/favicon-48.png')); $favicons[] = array('rel' => 'apple-touch-icon-precomposed', 'sizes' => '144x144', 'href' => osc_current_admin_theme_url('images/favicon-144.png')); $favicons[] = array('rel' => 'apple-touch-icon-precomposed', 'sizes' => '114x114', 'href' => osc_current_admin_theme_url('images/favicon-114.png')); $favicons[] = array('rel' => 'apple-touch-icon-precomposed', 'sizes' => '72x72', 'href' => osc_current_admin_theme_url('images/favicon-72.png')); $favicons[] = array('rel' => 'apple-touch-icon-precomposed', 'sizes' => '', 'href' => osc_current_admin_theme_url('images/favicon-57.png')); $favicons = osc_apply_filter('admin_favicons', $favicons); foreach ($favicons as $f) { ?> <link <?php if ($f['rel'] !== '') { ?> rel="<?php echo $f['rel']; ?> " <?php } if ($f['sizes'] !== '') { ?> sizes="<?php echo $f['sizes']; ?> " <?php } ?> href="<?php echo $f['href']; ?> "> <?php } }
private function processData($products) { if (!empty($products)) { $total = 0; foreach ($products as $aRow) { $row = array(); $row['id'] = $aRow['id']; $row['description'] = $aRow['description']; $row['amount'] = osc_format_price(1000000 * $aRow['amount'], osc_get_preference('currency', 'payment_pro')); $row['quantity'] = $aRow['quantity']; $row['total'] = osc_format_price(1000000 * $aRow['amount'] * $aRow['quantity'], osc_get_preference('currency', 'payment_pro')); $row['delete'] = '<a href="' . osc_route_url('payment-pro-cart-delete', array('id' => $aRow['id'])) . '" >' . __('Delete', 'payment_pro') . '</a>'; $row = osc_apply_filter('payment_pro_processing_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; $total += $aRow['amount'] * $aRow['quantity']; } $row = array(); $row['id'] = ''; $row['description'] = ''; $row['amount'] = ''; $row['quantity'] = '<b>' . __('Total', 'payment_pro') . '</b>'; $row['total'] = '<b>' . osc_format_price(1000000 * $total, osc_get_preference('currency', 'payment_pro')) . '</b>'; $row['delete'] = ''; $this->addRow($row); //$this->rawRows[] = $row; } }
private function processData($pages) { if (!empty($pages)) { $prefLocale = osc_current_user_locale(); foreach ($pages as $aRow) { $row = array(); $content = array(); if (isset($aRow['locale'][$prefLocale]) && !empty($aRow['locale'][$prefLocale]['s_title'])) { $content = $aRow['locale'][$prefLocale]; } else { $content = current($aRow['locale']); } // -- options -- $options = array(); View::newInstance()->_exportVariableToView('page', $aRow); $options[] = '<a href="' . osc_static_page_url() . '" target="_blank">' . __('View page') . '</a>'; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=pages&action=edit&id=' . $aRow['pk_i_id'] . '">' . __('Edit') . '</a>'; if (!$aRow['b_indelible']) { $options[] = '<a onclick="return delete_dialog(\'' . $aRow['pk_i_id'] . '\');" href="' . osc_admin_base_url(true) . '?page=pages&action=delete&id=' . $aRow['pk_i_id'] . '&' . osc_csrf_token_url() . '">' . __('Delete') . '</a>'; } $auxOptions = '<ul>' . PHP_EOL; foreach ($options as $actual) { $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL; } $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL; $row['bulkactions'] = '<input type="checkbox" name="id[]"" value="' . $aRow['pk_i_id'] . '"" />'; $row['internal_name'] = $aRow['s_internal_name'] . $actions; $row['title'] = $content['s_title']; $row['order'] = '<div class="order-box">' . $aRow['i_order'] . ' <img class="up" onclick="order_up(' . $aRow['pk_i_id'] . ');" src="' . osc_current_admin_theme_url('images/arrow_up.png') . '" alt="' . __('Up') . '" title="' . __('Up') . '" /> <img class="down" onclick="order_down(' . $aRow['pk_i_id'] . ');" src="' . osc_current_admin_theme_url('images/arrow_down.png') . '" alt="' . __('Down') . '" title="' . __('Down') . '" /></div>'; $row = osc_apply_filter('pages_processing_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; } } }
function payment_pro_check_items_blockchain($items, $total, $rate = 1, $error = 0.15) { $subtotal = 0; foreach ($items as $item) { $item['amount'] = $item['amount'] / 1000000; $subtotal += $item['amount']; $str = substr($item['id'], 0, 3); if ($str == 'PUB') { $cat = explode("-", $item['id']); $price = ModelPaymentPro::newInstance()->getPublishPrice(substr($cat[0], 3)); if ($item['quantity'] != 1 || $price != $item['amount']) { return PAYMENT_PRO_WRONG_AMOUNT_ITEM; } } if ($str == 'PRM') { $cat = explode("-", $item['id']); $price = ModelPaymentPro::newInstance()->getPremiumPrice(substr($cat[0], 3)); if ($item['quantity'] != 1 || $price != $item['amount']) { return PAYMENT_PRO_WRONG_AMOUNT_ITEM; } } else { $correct_price = osc_apply_filter('payment_pro_price_' . strtolower($str), true, $item); if (!$correct_price) { return PAYMENT_PRO_WRONG_AMOUNT_ITEM; } } } if (abs($subtotal * $rate - $total) > $total * $error) { return PAYMENT_PRO_WRONG_AMOUNT_TOTAL; } return PAYMENT_PRO_COMPLETED; }
public function setCurrentThemeUrl() { if ($this->theme_exists) { $this->theme_url = osc_apply_filter('theme_url', osc_base_url() . str_replace(osc_base_path(), '', $this->theme_path)); } else { $this->theme_url = osc_apply_filter('theme_url', osc_base_url() . 'oc-includes/osclass/gui/'); } }
function customPageHeader() { ?> <h1><?php echo osc_apply_filter('custom_appearance_title', __('Appearance')); ?> </h1> <?php }
function customPageHeader() { ?> <h1><?php echo osc_apply_filter('custom_plugin_title', __('Plugins')); ?> </h1> <?php }
/** * Gets the root url of oc-admin for your installation * * @param boolean $with_index true if index.php in the url is needed * @return string */ function osc_admin_base_url($with_index = false) { $path = osc_base_url(false) . 'oc-admin/'; // add the index.php if it's true if ($with_index) { $path .= "index.php"; } return osc_apply_filter('admin_base_url', $path, $with_index); }
/** * * @param type $email */ function getVariables($email) { $array = array(); $variables = array('email_alert_validation' => array('{USER_NAME}', '{USER_EMAIL}', '{VALIDATION_LINK}'), 'alert_email_hourly' => array('{USER_NAME}', '{USER_EMAIL}', '{ADS}', '{UNSUB_LINK}'), 'alert_email_daily' => array('{USER_NAME}', '{USER_EMAIL}', '{ADS}', '{UNSUB_LINK}'), 'alert_email_weekly' => array('{USER_NAME}', '{USER_EMAIL}', '{ADS}', '{UNSUB_LINK}'), 'alert_email_instant' => array('{USER_NAME}', '{USER_EMAIL}', '{ADS}', '{UNSUB_LINK}'), 'email_comment_validated' => array('{COMMENT_AUTHOR}', '{COMMENT_EMAIL}', '{COMMENT_TITLE}', '{COMMENT_BODY}', '{ITEM_URL}', '{ITEM_LINK}', '{ITEM_TITLE}'), 'email_new_item_non_register_user' => array('{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{ITEM_TITLE}', '{ITEM_URL}', '{ITEM_LINK}', '{EDIT_LINK}', '{EDIT_URL}', '{DELETE_LINK}', '{DELETE_URL}'), 'email_user_forgot_password' => array('{USER_NAME}', '{USER_EMAIL}', '{PASSWORD_LINK}', '{PASSWORD_URL}', '{DATE_TIME}'), 'email_user_registration' => array('{USER_NAME}', '{USER_EMAIL}'), 'email_new_email' => array('{USER_NAME}', '{USER_EMAIL}', '{VALIDATION_LINK}', '{VALIDATION_URL}'), 'email_user_validation' => array('{USER_NAME}', '{USER_EMAIL}', '{VALIDATION_LINK}', '{VALIDATION_URL}'), 'email_send_friend' => array('{FRIEND_NAME}', '{USER_NAME}', '{USER_EMAIL}', '{FRIEND_EMAIL}', '{ITEM_TITLE}', '{COMMENT}', '{ITEM_URL}', '{ITEM_LINK}'), 'email_item_inquiry' => array('{CONTACT_NAME}', '{USER_NAME}', '{USER_EMAIL}', '{USER_PHONE}', '{ITEM_TITLE}', '{ITEM_URL}', '{ITEM_LINK}', '{COMMENT}'), 'email_new_comment_admin' => array('{COMMENT_AUTHOR}', '{COMMENT_EMAIL}', '{COMMENT_TITLE}', '{COMMENT_TEXT}', '{ITEM_TITLE}', '{ITEM_ID}', '{ITEM_URL}', '{ITEM_LINK}'), 'email_item_validation' => array('{ITEM_DESCRIPTION_ALL_LANGUAGES}', '{ITEM_DESCRIPTION}', '{ITEM_COUNTRY}', '{ITEM_PRICE}', '{ITEM_REGION}', '{ITEM_CITY}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{ITEM_TITLE}', '{ITEM_URL}', '{ITEM_LINK}', '{VALIDATION_LINK}', '{VALIDATION_URL}'), 'email_admin_new_item' => array('{EDIT_LINK}', '{EDIT_URL}', '{ITEM_DESCRIPTION_ALL_LANGUAGES}', '{ITEM_DESCRIPTION}', '{ITEM_COUNTRY}', '{ITEM_PRICE}', '{ITEM_REGION}', '{ITEM_CITY}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{ITEM_TITLE}', '{ITEM_URL}', '{ITEM_LINK}', '{VALIDATION_LINK}', '{VALIDATION_URL}'), 'email_item_validation_non_register_user' => array('{ITEM_DESCRIPTION_ALL_LANGUAGES}', '{ITEM_DESCRIPTION}', '{ITEM_COUNTRY}', '{ITEM_PRICE}', '{ITEM_REGION}', '{ITEM_CITY}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{ITEM_TITLE}', '{ITEM_URL}', '{ITEM_LINK}', '{VALIDATION_LINK}', '{VALIDATION_URL}', '{EDIT_LINK}', '{EDIT_URL}', '{DELETE_LINK}', '{DELETE_URL}'), 'email_admin_new_user' => array('{USER_NAME}', '{USER_EMAIL}'), 'email_contact_user' => array('{CONTACT_NAME}', '{USER_NAME}', '{USER_EMAIL}', '{USER_PHONE}', '{COMMENT}'), 'email_new_comment_user' => array('{COMMENT_AUTHOR}', '{COMMENT_EMAIL}', '{COMMENT_TITLE}', '{COMMENT_TEXT}', '{ITEM_TITLE}', '{ITEM_ID}', '{ITEM_URL}', '{ITEM_LINK}', '{SELLER_NAME}', '{SELLER_EMAIL}'), 'email_new_admin' => array('{ADMIN_NAME}', '{USERNAME}', '{PASSWORD}', '{WEB_ADMIN_LINK}'), 'email_warn_expiration' => array('{USER_NAME}', '{ITEM_TITLE}', '{ITEM_ID}', '{ITEM_EXPIRATION_DATE}', '{ITEM_URL}', '{ITEM_LINK}', '{SELLER_NAME}', '{SELLER_EMAIL}', '{CONTACT_NAME}', '{CONTACT_EMAIL}')); if (isset($email['s_internal_name']) && isset($variables[$email['s_internal_name']])) { foreach ($variables[$email['s_internal_name']] as $word) { $array[$word] = $this->variables[$word]; } } return osc_apply_filter('email_legend_words', $array, @$email['s_internal_name']); }
public static function getItemUrl(&$item) { $gn_id = $item['gn_id']; $gn_title = $item['gn_title']; $friendly_title = osc_sanitizeString(osc_apply_filter('slug', $gn_title)); $item_url = GZ_NEWS_URL . 'pages/item.php'; if (self::isModRewriteEnabled()) { $item_url = osc_base_url() . "news/read/{$gn_id}/{$friendly_title}.html"; } else { $item_url = $item_url . "?i={$gn_id}&title={$friendly_title}"; } return $item_url; }
function __construct() { parent::__construct(); // check if is moderator and can enter to this page if( $this->isModerator() ) { if( !in_array($this->page, osc_apply_filter('moderator_access', array('items', 'comments', 'media', 'login', 'admins', 'ajax', 'stats',''))) ) { osc_add_flash_error_message(_m("You don't have enough permissions"), 'admin'); $this->redirectTo(osc_admin_base_url()); } } osc_run_hook( 'init_admin' ); // check if exist a new version each day if( (time() - osc_last_version_check()) > (24 * 3600) ) { $data = osc_file_get_contents('http://osclass.org/latest_version_v1.php?callback=?'); $data = preg_replace('|^\?\((.*?)\);$|', '$01', $data); $json = json_decode($data); if( $json->version > osc_version() ) { osc_set_preference( 'update_core_json', $data ); } else { osc_set_preference( 'update_core_json', '' ); } osc_set_preference( 'last_version_check', time() ); osc_reset_preferences(); } $config_version = str_replace('.', '', OSCLASS_VERSION); $config_version = preg_replace('|-.*|', '', $config_version); if( $config_version > osc_get_preference('version') ) { if(get_class($this) == 'CAdminTools') { } else { if(get_class($this) != 'CAdminUpgrade' ) $this->redirectTo(osc_admin_base_url(true) . '?page=upgrade'); } } // show donation successful if( Params::getParam('donation') == 'successful' ) { osc_add_flash_ok_message(_m('Thank you very much for your donation'), 'admin'); } // enqueue scripts osc_enqueue_script('jquery'); osc_enqueue_script('jquery-ui'); osc_enqueue_script('admin-osc'); osc_enqueue_script('admin-ui-osc'); }
function doModel() { $id = Params::getParam('id'); $page = false; if (is_numeric($id)) { $page = $this->pageManager->findByPrimaryKey($id); } else { $page = $this->pageManager->findByInternalName(Params::getParam('slug')); } // page not found if ($page == false) { $this->do404(); return; } // this page shouldn't be shown (i.e.: e-mail templates) if ($page['b_indelible'] == 1) { $this->do404(); return; } $kwords = array('{WEB_URL}', '{WEB_TITLE}'); $rwords = array(osc_base_url(), osc_page_title()); foreach ($page['locale'] as $k => $v) { $page['locale'][$k]['s_title'] = str_ireplace($kwords, $rwords, osc_apply_filter('email_description', $v['s_title'])); $page['locale'][$k]['s_text'] = str_ireplace($kwords, $rwords, osc_apply_filter('email_description', $v['s_text'])); } // export $page content to View $this->_exportVariableToView('page', $page); if (Params::getParam('lang') != '') { Session::newInstance()->_set('userLocale', Params::getParam('lang')); } $meta = json_decode($page['s_meta'], true); // load the right template file if (file_exists(osc_themes_path() . osc_theme() . '/page-' . $page['s_internal_name'] . '.php')) { $this->doView('page-' . $page['s_internal_name'] . '.php'); } else { if (isset($meta['template']) && file_exists(osc_themes_path() . osc_theme() . '/' . $meta['template'])) { $this->doView($meta['template']); } else { if (isset($meta['template']) && file_exists(osc_plugins_path() . '/' . $meta['template'])) { osc_run_hook('before_html'); require osc_plugins_path() . '/' . $meta['template']; Session::newInstance()->_clearVariables(); osc_run_hook('after_html'); } else { $this->doView('page.php'); } } } }
private function processData($media) { if (!empty($media)) { foreach ($media as $aRow) { $row = array(); $row['bulkactions'] = '<input type="checkbox" name="id[]" value="' . $aRow['pk_i_id'] . '" />'; $row['file'] = '<div id="media_list_pic"><img src="' . osc_apply_filter('resource_path', osc_base_url() . $aRow['s_path']) . $aRow['pk_i_id'] . '_thumbnail.' . $aRow['s_extension'] . '" style="max-width: 60px; max-height: 60px;" /></div> <div id="media_list_filename">' . $aRow['s_content_type']; $row['action'] = '<a onclick="return delete_dialog(\'' . $aRow['pk_i_id'] . '\');" >' . __('Delete') . '</a>'; $row['attached_to'] = '<a target="_blank" href="' . osc_item_url_ns($aRow['fk_i_item_id']) . '">item #' . $aRow['fk_i_item_id'] . '</a>'; $row['date'] = osc_format_date($aRow['dt_pub_date']); $row = osc_apply_filter('media_processing_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; } } }
private function processData($rules) { if (!empty($rules)) { $csrf_token_url = osc_csrf_token_url(); foreach ($rules as $aRow) { $row = array(); $options = array(); $options_more = array(); // first column $options[] = '<a href="' . osc_admin_base_url(true) . '?page=users&action=edit_ban_rule&id=' . $aRow['pk_i_id'] . '">' . __('Edit') . '</a>'; $options[] = '<a onclick="return delete_dialog(\'' . $aRow['pk_i_id'] . '\');" href="' . osc_admin_base_url(true) . '?page=users&action=delete_ban_rule&id[]=' . $aRow['pk_i_id'] . '">' . __('Delete') . '</a>'; $options_more = osc_apply_filter('more_actions_manage_rules', $options_more, $aRow); // more actions $moreOptions = '<li class="show-more">' . PHP_EOL . '<a href="#" class="show-more-trigger">' . __('Show more') . '...</a>' . PHP_EOL . '<ul>' . PHP_EOL; foreach ($options_more as $actual) { $moreOptions .= '<li>' . $actual . "</li>" . PHP_EOL; } $moreOptions .= '</ul>' . PHP_EOL . '</li>' . PHP_EOL; $options = osc_apply_filter('actions_manage_rules', $options, $aRow); // create list of actions $auxOptions = '<ul>' . PHP_EOL; foreach ($options as $actual) { $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL; } $auxOptions .= $moreOptions; $auxOptions .= '</ul>' . PHP_EOL; $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL; $row['bulkactions'] = '<input type="checkbox" name="id[]" value="' . $aRow['pk_i_id'] . '" /></div>'; $row['name'] = $aRow['s_name'] . $actions; $row['ip'] = $aRow['s_ip']; $row['email'] = $aRow['s_email']; $row = osc_apply_filter('rules_processing_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; } } }
private function processData($invoices) { if (!empty($invoices)) { foreach ($invoices as $aRow) { $row = array(); $row['status'] = $aRow['i_status']; $row['date'] = $aRow['dt_date']; $row['code'] = $aRow['s_code']; $row['items'] = $this->_invoiceRows($aRow['pk_i_id'], $aRow['s_currency_code']); if ($aRow['s_currency_code'] == "BTC") { // FORGET FORMAT IF BTC $row['amount'] = $aRow['i_amount'] / 1000000 . " " . $aRow['s_currency_code']; } else { $row['amount'] = osc_format_price($aRow['i_amount'], $aRow['s_currency_code']); } $row['email'] = $aRow['s_email']; $row['user'] = $aRow['fk_i_user_id']; $row['source'] = $aRow['s_source']; $row = osc_apply_filter('payment_pro_invoices_processing_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; } } }
public function insert($fields, $aFieldsDescription = null) { $columns = implode(', ', array_keys($fields)); $set = ""; foreach ($fields as $value) { if ($set != "") { $set .= ", "; } $set .= $this->formatValue($value); } $sql = 'INSERT INTO ' . $this->getTableName() . ' (' . $columns . ') VALUES (' . $set . ')'; $this->conn->osc_dbExec($sql); $category_id = $this->conn->get_last_id(); foreach ($aFieldsDescription as $k => $fieldsDescription) { $fieldsDescription['fk_i_category_id'] = $category_id; $fieldsDescription['fk_c_locale_code'] = $k; $fieldsDescription['s_slug'] = osc_sanitizeString(osc_apply_filter('slug', $fieldsDescription['s_name'])); $columns = implode(', ', array_keys($fieldsDescription)); $set = ""; foreach ($fieldsDescription as $value) { if ($set != "") { $set .= ", "; } $set .= $this->formatValue($value); } $sql = 'INSERT INTO ' . $this->getTableDescriptionName() . ' (' . $columns . ') VALUES (' . $set . ')'; $this->conn->osc_dbExec($sql); } }
private function toDatatablesFormat() { $this->result['iTotalRecords'] = $this->total; $this->result['iTotalDisplayRecords'] = $this->total_filtered; $this->result['sEcho'] = $this->sEcho; $this->result['aaData'] = array(); if (count($this->media) == 0) { return; } $count = 0; foreach ($this->media as $aRow) { $row = array(); $row[] = '<input type="checkbox" name="id[]" value="' . $aRow['pk_i_id'] . '" />'; $row[] = '<div id="media_list_pic"><img src="' . osc_apply_filter('resource_path', osc_base_url() . $aRow['s_path']) . $aRow['pk_i_id'] . '_thumbnail.' . $aRow['s_extension'] . '" style="max-width: 60px; max-height: 60px;" /></div> <div id="media_list_filename">' . $aRow['s_content_type']; $row[] = '<a onclick="javascript:return confirm(\'' . osc_esc_js(__('This action can not be undone. Are you sure you want to continue?')) . '\')" href="' . osc_admin_base_url(true) . '?page=media&action=delete&id[]=' . $aRow['pk_i_id'] . '" id="dt_link_delete">' . __('Delete') . '</a>'; $row[] = '<a target="_blank" href="' . osc_item_url_ns($aRow['fk_i_item_id']) . '">item #' . $aRow['fk_i_item_id'] . '</a>'; $row[] = $aRow['dt_pub_date']; $count++; $this->result['aaData'][] = $row; } }
<input type="submit" id="bulk_apply" class="btn" value="<?php echo osc_esc_html( __('Apply') ); ?>" /> </label> </div> <div class="table-contains-actions"> <table class="table" cellpadding="0" cellspacing="0"> <thead> <tr> <?php foreach($columns as $k => $v) { echo '<th class="col-'.$k.' '.($sort==$k?($direction=='desc'?'sorting_desc':'sorting_asc'):'').'">'.$v.'</th>'; }; ?> </tr> </thead> <tbody> <?php if( count($rows) > 0 ) { ?> <?php foreach($rows as $key => $row) { ?> <tr class="<?php echo implode(' ', osc_apply_filter('datatable_user_class', array(), $aRawRows[$key], $row)); ?>"> <?php foreach($row as $k => $v) { ?> <td class="col-<?php echo $k; ?>"><?php echo $v; ?></td> <?php }; ?> </tr> <?php }; ?> <?php } else { ?> <tr> <td colspan="9" class="text-center"> <p><?php _e('No data available in table'); ?></p> </td> </tr> <?php } ?> </tbody> </table> <div id="table-row-actions"></div> <!-- used for table actions -->
/** * Shows all the pending flash messages in session and cleans up the array. * * @param $section * @param $class * @param $id * @return void */ function osc_show_flash_message($section = 'pubMessages', $class = "flashmessage", $id = "flashmessage") { $messages = Session::newInstance()->_getMessage($section); if (is_array($messages)) { foreach ($messages as $message) { echo '<div id="flash_js"></div>'; if (isset($message['msg']) && $message['msg'] != '') { echo '<div id="' . $id . '" class="' . strtolower($class) . ' ' . strtolower($class) . '-' . $message['type'] . '"><a class="btn ico btn-mini ico-close">x</a>'; echo osc_apply_filter('flash_message_text', $message['msg']); echo '</div>'; } else { if ($message != '') { echo '<div id="' . $id . '" class="' . $class . '">'; echo osc_apply_filter('flash_message_text', $message); echo '</div>'; } else { echo '<div id="' . $id . '" class="' . $class . '" style="display:none;">'; echo osc_apply_filter('flash_message_text', ''); echo '</div>'; } } } } Session::newInstance()->_dropMessage($section); }
function doModel() { //calling the view... $locales = OSCLocale::newInstance()->listAllEnabled(); $this->_exportVariableToView('locales', $locales); switch ($this->action) { case 'item_add': // post if (osc_reg_user_post() && $this->user == null) { osc_add_flash_warning_message(_m('Only registered users are allowed to post listings')); $this->redirectTo(osc_user_login_url()); } $countries = Country::newInstance()->listAll(); $regions = array(); if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') { $regions = Region::newInstance()->findByCountry($this->user['fk_c_country_code']); } else { if (count($countries) > 0) { $regions = Region::newInstance()->findByCountry($countries[0]['pk_c_code']); } } $cities = array(); if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') { $cities = City::newInstance()->findByRegion($this->user['fk_i_region_id']); } else { if (count($regions) > 0) { $cities = City::newInstance()->findByRegion($regions[0]['pk_i_id']); } } $this->_exportVariableToView('countries', $countries); $this->_exportVariableToView('regions', $regions); $this->_exportVariableToView('cities', $cities); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } if (Session::newInstance()->_getForm('countryId') != "") { $countryId = Session::newInstance()->_getForm('countryId'); $regions = Region::newInstance()->findByCountry($countryId); $this->_exportVariableToView('regions', $regions); if (Session::newInstance()->_getForm('regionId') != "") { $regionId = Session::newInstance()->_getForm('regionId'); $cities = City::newInstance()->findByRegion($regionId); $this->_exportVariableToView('cities', $cities); } } $this->_exportVariableToView('user', $this->user); osc_run_hook('post_item'); $this->doView('item-post.php'); break; case 'item_add_post': //post_item if (osc_reg_user_post() && $this->user == null) { osc_add_flash_warning_message(_m('Only registered users are allowed to post listings')); $this->redirectTo(osc_base_url(true)); } $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(true); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_post_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } if (!osc_is_web_user_logged_in()) { $user = User::newInstance()->findByEmail($mItems->data['contactEmail']); // The user exists but it's not logged if (isset($user['pk_i_id'])) { foreach ($mItems->data as $key => $value) { Session::newInstance()->_keepForm($key); } osc_add_flash_error_message(_m('A user with that email address already exists, if it is you, please log in')); $this->redirectTo(osc_user_login_url()); } } // POST ITEM ( ADD ITEM ) $success = $mItems->add(); if ($success != 1 && $success != 2) { osc_add_flash_error_message($success); $this->redirectTo(osc_item_post_url()); } else { Session::newInstance()->_dropkeepForm('meta_' . $key); if ($success == 1) { osc_add_flash_ok_message(_m('Check your inbox to validate your listing')); } else { osc_add_flash_ok_message(_m('Your listing has been published')); } $itemId = Params::getParam('itemId'); $item = $this->itemManager->findByPrimaryKey($itemId); osc_run_hook('posted_item', $item); $category = Category::newInstance()->findByPrimaryKey(Params::getParam('catId')); View::newInstance()->_exportVariableToView('category', $category); $this->redirectTo(osc_search_category_url()); } break; case 'item_edit': // edit item $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $item = Item::newInstance()->findByPrimaryKey($id); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } $this->_exportVariableToView('item', $item); osc_run_hook("before_item_edit", $item); $this->doView('item-edit.php'); } else { // add a flash message [ITEM NO EXISTE] osc_add_flash_error_message(_m("Sorry, we don't have any listings with that ID")); if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } break; case 'item_edit_post': // recoger el secret y el $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $this->_exportVariableToView('item', $item[0]); $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(false); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_edit_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $success = $mItems->edit(); osc_run_hook('edited_item', Item::newInstance()->findByPrimaryKey($id)); if ($success == 1) { osc_add_flash_ok_message(_m("Great! We've just updated your listing")); View::newInstance()->_exportVariableToView("item", Item::newInstance()->findByPrimaryKey($id)); $this->redirectTo(osc_item_url()); } else { osc_add_flash_error_message($success); $this->redirectTo(osc_item_edit_url($secret)); } } break; case 'activate': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); // item doesn't exist if (count($item) == 0) { $this->do404(); return; } View::newInstance()->_exportVariableToView('item', $item[0]); if ($item[0]['b_active'] == 0) { // ACTIVETE ITEM $mItems = new ItemActions(false); $success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']); if ($success) { osc_add_flash_ok_message(_m('The listing has been validated')); } else { osc_add_flash_error_message(_m("The listing can't be validated")); } } else { osc_add_flash_warning_message(_m('The listing has already been validated')); } $this->redirectTo(osc_item_url()); break; case 'item_delete': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $mItems = new ItemActions(false); $success = $mItems->delete($item[0]['s_secret'], $item[0]['pk_i_id']); if ($success) { osc_add_flash_ok_message(_m('Your listing has been deleted')); } else { osc_add_flash_error_message(_m("The listing you are trying to delete couldn't be deleted")); } if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } else { osc_add_flash_error_message(_m("The listing you are trying to delete couldn't be deleted")); $this->redirectTo(osc_base_url()); } break; case 'mark': $id = Params::getParam('id'); $as = Params::getParam('as'); $item = Item::newInstance()->findByPrimaryKey($id); View::newInstance()->_exportVariableToView('item', $item); require_once osc_lib_path() . 'osclass/user-agents.php'; foreach ($user_agents as $ua) { if (preg_match('|' . $ua . '|', @$_SERVER['HTTP_USER_AGENT'])) { // mark item if it's not a bot $mItem = new ItemActions(false); $mItem->mark($id, $as); break; } } osc_add_flash_ok_message(_m("Thanks! That's very helpful")); $this->redirectTo(osc_item_url()); break; case 'send_friend': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); $this->doView('item-send-friend.php'); break; case 'send_friend_post': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("friendName", Params::getParam('friendName')); Session::newInstance()->_setForm("friendEmail", Params::getParam('friendEmail')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_send_friend_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $mItem = new ItemActions(false); $success = $mItem->send_friend(); if ($success) { Session::newInstance()->_clearVariables(); $this->redirectTo(osc_item_url()); } else { $this->redirectTo(osc_item_send_friend_url()); } break; case 'contact': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); if (empty($item)) { osc_add_flash_error_message(_m("This listing doesn't exist")); $this->redirectTo(osc_base_url(true)); } else { $this->_exportVariableToView('item', $item); if (osc_item_is_expired()) { osc_add_flash_error_message(_m("We're sorry, but the listing has expired. You can't contact the seller")); $this->redirectTo(osc_item_url()); } if (osc_reg_user_can_contact() && osc_is_web_user_logged_in() || !osc_reg_user_can_contact()) { $this->doView('item-contact.php'); } else { osc_add_flash_error_message(_m("You can't contact the seller, only registered users can")); $this->redirectTo(osc_item_url()); } } break; case 'contact_post': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("phoneNumber", Params::getParam('phoneNumber')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); $this->redirectTo(osc_item_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } if (osc_isExpired($item['dt_expiration'])) { osc_add_flash_error_message(_m("We're sorry, but the listing has expired. You can't contact the seller")); $this->redirectTo(osc_item_url()); } $mItem = new ItemActions(false); $result = $mItem->contact(); if (is_string($result)) { osc_add_flash_error_message($result); } else { osc_add_flash_ok_message(_m("We've just sent an e-mail to the seller")); } $this->redirectTo(osc_item_url()); break; case 'add_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); switch ($status) { case -1: $msg = _m('Sorry, we could not save your comment. Try again later'); osc_add_flash_error_message($msg); break; case 1: $msg = _m('Your comment is awaiting moderation'); osc_add_flash_info_message($msg); break; case 2: $msg = _m('Your comment has been approved'); osc_add_flash_ok_message($msg); break; case 3: $msg = _m('Please fill the required field (email)'); osc_add_flash_warning_message($msg); break; case 4: $msg = _m('Please type a comment'); osc_add_flash_warning_message($msg); break; case 5: $msg = _m('Your comment has been marked as spam'); osc_add_flash_error_message($msg); break; } $this->redirectTo(osc_item_url()); break; case 'delete_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); $itemId = Params::getParam('id'); $commentId = Params::getParam('comment'); $item = Item::newInstance()->findByPrimaryKey($itemId); if (count($item) == 0) { osc_add_flash_error_message(_m("This listing doesn't exist")); $this->redirectTo(osc_base_url(true)); } View::newInstance()->_exportVariableToView('item', $item); if ($this->userId == null) { osc_add_flash_error_message(_m('You must be logged in to delete a comment')); $this->redirectTo(osc_item_url()); } $commentManager = ItemComment::newInstance(); $aComment = $commentManager->findByPrimaryKey($commentId); if (count($aComment) == 0) { osc_add_flash_error_message(_m("The comment doesn't exist")); $this->redirectTo(osc_item_url()); } if ($aComment['b_active'] != 1) { osc_add_flash_error_message(_m('The comment is not active, you cannot delete it')); $this->redirectTo(osc_item_url()); } if ($aComment['fk_i_user_id'] != $this->userId) { osc_add_flash_error_message(_m('The comment was not added by you, you cannot delete it')); $this->redirectTo(osc_item_url()); } $commentManager->deleteByPrimaryKey($commentId); osc_add_flash_ok_message(_m('The comment has been deleted')); $this->redirectTo(osc_item_url()); break; default: // if there isn't ID, show an error 404 if (Params::getParam('id') == '') { $this->do404(); return; } if (Params::getParam('lang') != '') { Session::newInstance()->_set('userLocale', Params::getParam('lang')); } $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); // if item doesn't exist show an error 404 if (count($item) == 0) { $this->do404(); return; } if ($item['b_active'] != 1) { if ($this->userId == $item['fk_i_user_id']) { osc_add_flash_warning_message(_m("The listing hasn't been validated. Please validate it in order to make it public")); } else { osc_add_flash_warning_message(_m("This listing hasn't been validated")); $this->redirectTo(osc_base_url(true)); } } else { if ($item['b_enabled'] == 0) { osc_add_flash_warning_message(_m('The listing has been suspended')); $this->redirectTo(osc_base_url(true)); } } if (!osc_is_admin_user_logged_in()) { require_once osc_lib_path() . 'osclass/user-agents.php'; foreach ($user_agents as $ua) { if (preg_match('|' . $ua . '|', @$_SERVER['HTTP_USER_AGENT'])) { $mStats = new ItemStats(); $mStats->increase('i_num_views', $item['pk_i_id']); break; } } } foreach ($item['locale'] as $k => $v) { $item['locale'][$k]['s_title'] = osc_apply_filter('item_title', $v['s_title']); $item['locale'][$k]['s_description'] = nl2br(osc_apply_filter('item_description', $v['s_description'])); } if ($item['fk_i_user_id'] != '') { $user = User::newInstance()->findByPrimaryKey($item['fk_i_user_id']); $this->_exportVariableToView('user', $user); } $this->_exportVariableToView('item', $item); osc_run_hook('show_item', $item); // redirect to the correct url just in case it has changed $itemURI = str_replace(osc_base_url(), '', osc_item_url()); $URI = preg_replace('|^' . REL_WEB_URL . '|', '', $_SERVER['REQUEST_URI']); // do not clean QUERY_STRING if permalink is not enabled if (osc_rewrite_enabled()) { $URI = str_replace('?' . $_SERVER['QUERY_STRING'], '', $URI); } else { $params_keep = array('page', 'id'); $params = array(); foreach (Params::getParamsAsArray('get') as $k => $v) { if (in_array($k, $params_keep)) { $params[] = "{$k}={$v}"; } } $URI = 'index.php?' . implode('&', $params); } // redirect to the correct url if ($itemURI != $URI) { $this->redirectTo(osc_base_url() . $itemURI); } $this->doView('item.php'); break; } }
if (osc_is_search_page()) { if (osc_count_items() == 0) { osc_add_filter('meta_robots', 'meta_robots_custom'); function meta_robots_custom() { return 'noindex, nofollow'; } } } ?> <meta name="robots" content="<?php echo osc_apply_filter('meta_robots', 'index, follow'); ?> " /> <meta name="googlebot" content="<?php echo osc_apply_filter('meta_robots', 'index, follow'); ?> " /> </head> <body> <?php if (osc_get_preference('header-728x90', 'realestate') != '') { ?> <!-- header ad 728x60--> <div style="width: 728px; height: 120px; margin-left: auto;margin-right: auto;"> <?php echo osc_get_preference('header-728x90', 'realestate'); ?> </div> <!-- /header ad 728x60-->
function doModel() { parent::doModel(); //specific things for this class switch ($this->action) { case 'bulk_actions': osc_csrf_check(); $id = Params::getParam('id'); if ($id) { switch (Params::getParam('bulk_actions')) { case 'delete_all': $this->itemCommentManager->delete(array(DB_CUSTOM_COND => 'pk_i_id IN (' . implode(', ', $id) . ')')); foreach ($id as $_id) { $iUpdated = $this->itemCommentManager->delete(array('pk_i_id' => $_id)); osc_add_hook("delete_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been deleted'), 'admin'); break; case 'activate_all': foreach ($id as $_id) { $iUpdated = $this->itemCommentManager->update(array('b_active' => 1), array('pk_i_id' => $_id)); if ($iUpdated) { $this->sendCommentActivated($_id); } osc_add_hook("activate_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been approved'), 'admin'); break; case 'deactivate_all': foreach ($id as $_id) { $this->itemCommentManager->update(array('b_active' => 0), array('pk_i_id' => $_id)); osc_add_hook("deactivate_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been disapproved'), 'admin'); break; case 'enable_all': foreach ($id as $_id) { $iUpdated = $this->itemCommentManager->update(array('b_enabled' => 1), array('pk_i_id' => $_id)); if ($iUpdated) { $this->sendCommentActivated($_id); } osc_add_hook("enable_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been unblocked'), 'admin'); break; case 'disable_all': foreach ($id as $_id) { $this->itemCommentManager->update(array('b_enabled' => 0), array('pk_i_id' => $_id)); osc_add_hook("disable_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been blocked'), 'admin'); break; default: if (Params::getParam("bulk_actions") != "") { osc_run_hook("item_bulk_" . Params::getParam("bulk_actions"), Params::getParam('id')); } break; } } $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; case 'status': osc_csrf_check(); $id = Params::getParam('id'); $value = Params::getParam('value'); if (!$id) { return false; } $id = (int) $id; if (!is_numeric($id)) { return false; } if (!in_array($value, array('ACTIVE', 'INACTIVE', 'ENABLE', 'DISABLE'))) { return false; } if ($value == 'ACTIVE') { $iUpdated = $this->itemCommentManager->update(array('b_active' => 1), array('pk_i_id' => $id)); if ($iUpdated) { $this->sendCommentActivated($id); } osc_add_hook("activate_comment", $id); osc_add_flash_ok_message(_m('The comment has been approved'), 'admin'); } else { if ($value == 'INACTIVE') { $iUpdated = $this->itemCommentManager->update(array('b_active' => 0), array('pk_i_id' => $id)); osc_add_hook("deactivate_comment", $id); osc_add_flash_ok_message(_m('The comment has been disapproved'), 'admin'); } else { if ($value == 'ENABLE') { $iUpdated = $this->itemCommentManager->update(array('b_enabled' => 1), array('pk_i_id' => $id)); osc_add_hook("enable_comment", $id); osc_add_flash_ok_message(_m('The comment has been enabled'), 'admin'); } else { if ($value == 'DISABLE') { $iUpdated = $this->itemCommentManager->update(array('b_enabled' => 0), array('pk_i_id' => $id)); osc_add_hook("disable_comment", $id); osc_add_flash_ok_message(_m('The comment has been disabled'), 'admin'); } } } } $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; case 'comment_edit': $comment = ItemComment::newInstance()->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('comment', $comment); $this->doView('comments/frm.php'); break; case 'comment_edit_post': osc_csrf_check(); $msg = ''; if (!osc_validate_email(Params::getParam('authorEmail'), true)) { $msg .= _m('Email is not correct') . "<br/>"; } if (!osc_validate_text(Params::getParam('body'), 1, true)) { $msg .= _m('Comment is required') . "<br/>"; } if ($msg != '') { osc_add_flash_error_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=comments&action=comment_edit&id=" . Params::getParam('id')); } $this->itemCommentManager->update(array('s_title' => Params::getParam('title'), 's_body' => Params::getParam('body'), 's_author_name' => Params::getParam('authorName'), 's_author_email' => Params::getParam('authorEmail')), array('pk_i_id' => Params::getParam('id'))); osc_run_hook('edit_comment', Params::getParam('id')); osc_add_flash_ok_message(_m('Great! We just updated your comment'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; case 'delete': osc_csrf_check(); $this->itemCommentManager->deleteByPrimaryKey(Params::getParam('id')); osc_add_flash_ok_message(_m('The comment has been deleted'), 'admin'); osc_run_hook('delete_comment', Params::getParam('id')); $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; default: require_once osc_lib_path() . "osclass/classes/datatables/CommentsDataTable.php"; // set default iDisplayLength if (Params::getParam('iDisplayLength') != '') { Cookie::newInstance()->push('listing_iDisplayLength', Params::getParam('iDisplayLength')); Cookie::newInstance()->set(); } else { // set a default value if it's set in the cookie if (Cookie::newInstance()->get_value('listing_iDisplayLength') != '') { Params::setParam('iDisplayLength', Cookie::newInstance()->get_value('listing_iDisplayLength')); } else { Params::setParam('iDisplayLength', 10); } } $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength')); // Table header order by related if (Params::getParam('sort') == '') { Params::setParam('sort', 'date'); } if (Params::getParam('direction') == '') { Params::setParam('direction', 'desc'); } $page = (int) Params::getParam('iPage'); if ($page == 0) { $page = 1; } Params::setParam('iPage', $page); $params = Params::getParamsAsArray(); $commentsDataTable = new CommentsDataTable(); $commentsDataTable->table($params); $aData = $commentsDataTable->getData(); if (count($aData['aRows']) == 0 && $page != 1) { $total = (int) $aData['iTotalDisplayRecords']; $maxPage = ceil($total / (int) $aData['iDisplayLength']); $url = osc_admin_base_url(true) . '?' . Params::getServerParam('QUERY_STRING', false, false); if ($maxPage == 0) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url); $this->redirectTo($url); } if ($page > 1) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url); $this->redirectTo($url); } } $this->_exportVariableToView('aData', $aData); $this->_exportVariableToView('aRawRows', $commentsDataTable->rawRows()); $bulk_options = array(array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')), array('value' => 'delete_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Delete'))), 'label' => __('Delete')), array('value' => 'activate_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Activate'))), 'label' => __('Activate')), array('value' => 'deactivate_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Deactivate'))), 'label' => __('Deactivate')), array('value' => 'disable_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Block'))), 'label' => __('Block')), array('value' => 'enable_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Unblock'))), 'label' => __('Unblock'))); $bulk_options = osc_apply_filter("comment_bulk_filter", $bulk_options); $this->_exportVariableToView('bulk_options', $bulk_options); $this->doView('comments/index.php'); break; } }
/** * Prints the user's account menu * * @param array $options array with options of the form array('name' => 'display name', 'url' => 'url of link') * @return void */ function osc_private_user_menu($options = null) { if ($options == null) { $options = array(); $options[] = array('name' => __('Public Profile'), 'url' => osc_user_public_profile_url(), 'class' => 'opt_publicprofile'); $options[] = array('name' => __('Dashboard'), 'url' => osc_user_dashboard_url(), 'class' => 'opt_dashboard'); $options[] = array('name' => __('Manage your listings'), 'url' => osc_user_list_items_url(), 'class' => 'opt_items'); $options[] = array('name' => __('Manage your alerts'), 'url' => osc_user_alerts_url(), 'class' => 'opt_alerts'); $options[] = array('name' => __('My profile'), 'url' => osc_user_profile_url(), 'class' => 'opt_account'); $options[] = array('name' => __('Logout'), 'url' => osc_user_logout_url(), 'class' => 'opt_logout'); } $options = osc_apply_filter('user_menu_filter', $options); echo '<script type="text/javascript">'; echo '$(".user_menu > :first-child").addClass("first");'; echo '$(".user_menu > :last-child").addClass("last");'; echo '</script>'; echo '<ul class="user_menu">'; $var_l = count($options); for ($var_o = 0; $var_o < $var_l - 1; $var_o++) { echo '<li class="' . $options[$var_o]['class'] . '" ><a href="' . $options[$var_o]['url'] . '" >' . $options[$var_o]['name'] . '</a></li>'; } osc_run_hook('user_menu'); echo '<li class="' . $options[$var_l - 1]['class'] . '" ><a href="' . $options[$var_l - 1]['url'] . '" >' . $options[$var_l - 1]['name'] . '</a></li>'; echo '</ul>'; }
function doModel() { switch ($this->action) { case 'add': // caliing add view $this->doView('languages/add.php'); break; case 'add_post': // adding a new language if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } osc_csrf_check(); $filePackage = Params::getFiles('package'); if (isset($filePackage['size']) && $filePackage['size'] != 0) { $path = osc_translations_path(); (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path)); @unlink($filePackage['tmp_name']); } else { $status = 3; } switch ($status) { case 0: $msg = _m('The translation folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; case 1: if (osc_checkLocales()) { $msg = _m('The language has been installed correctly'); osc_add_flash_ok_message($msg, 'admin'); } else { $msg = _m('There was a problem adding the language'); osc_add_flash_error_message($msg, 'admin'); } break; case 2: $msg = _m('The zip file is not valid'); osc_add_flash_error_message($msg, 'admin'); break; case 3: $msg = _m('No file was uploaded'); osc_add_flash_warning_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=languages&action=add"); break; case -1: default: $msg = _m('There was a problem adding the language'); osc_add_flash_error_message($msg, 'admin'); break; } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'edit': // editing a language $sLocale = Params::getParam('id'); if (!preg_match('/.{2}_.{2}/', $sLocale)) { osc_add_flash_error_message(_m('Language id isn\'t in the correct format'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } $aLocale = $this->localeManager->findByPrimaryKey($sLocale); if (count($aLocale) == 0) { osc_add_flash_error_message(_m('Language id doesn\'t exist'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } $this->_exportVariableToView("aLocale", $aLocale); $this->doView('languages/frm.php'); break; case 'edit_post': // edit language post osc_csrf_check(); $iUpdated = 0; $languageCode = Params::getParam('pk_c_code'); $enabledWebstie = Params::getParam('b_enabled'); $enabledBackoffice = Params::getParam('b_enabled_bo'); $languageName = Params::getParam('s_name'); $languageShortName = Params::getParam('s_short_name'); $languageDescription = Params::getParam('s_description'); $languageCurrencyFormat = Params::getParam('s_currency_format'); $languageDecPoint = Params::getParam('s_dec_point'); $languageNumDec = Params::getParam('i_num_dec'); $languageThousandsSep = Params::getParam('s_thousands_sep'); $languageDateFormat = Params::getParam('s_date_format'); $languageStopWords = Params::getParam('s_stop_words'); // formatting variables if (!preg_match('/.{2}_.{2}/', $languageCode)) { osc_add_flash_error_message(_m('Language id isn\'t in the correct format'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } $enabledWebstie = $enabledWebstie != '' ? true : false; $enabledBackoffice = $enabledBackoffice != '' ? true : false; $languageName = strip_tags($languageName); $languageName = trim($languageName); $languageShortName = strip_tags($languageShortName); $languageShortName = trim($languageShortName); $languageDescription = strip_tags($languageDescription); $languageDescription = trim($languageDescription); $languageCurrencyFormat = strip_tags($languageCurrencyFormat); $languageCurrencyFormat = trim($languageCurrencyFormat); $languageDateFormat = strip_tags($languageDateFormat); $languageDateFormat = trim($languageDateFormat); $languageStopWords = strip_tags($languageStopWords); $languageStopWords = trim($languageStopWords); $msg = ''; if (!osc_validate_text($languageName)) { $msg .= _m("Language name field is required") . "<br/>"; } if (!osc_validate_text($languageShortName)) { $msg .= _m("Language short name field is required") . "<br/>"; } if (!osc_validate_text($languageDescription)) { $msg .= _m("Language description field is required") . "<br/>"; } if (!osc_validate_text($languageCurrencyFormat)) { $msg .= _m("Currency format field is required") . "<br/>"; } if (!osc_validate_int($languageNumDec)) { $msg .= _m("Number of decimals must only contain numeric characters") . "<br/>"; } if ($msg != '') { osc_add_flash_error_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages&action=edit&id=' . $languageCode); } $array = array('b_enabled' => $enabledWebstie, 'b_enabled_bo' => $enabledBackoffice, 's_name' => $languageName, 's_short_name' => $languageShortName, 's_description' => $languageDescription, 's_currency_format' => $languageCurrencyFormat, 's_dec_point' => $languageDecPoint, 'i_num_dec' => $languageNumDec, 's_thousands_sep' => $languageThousandsSep, 's_date_format' => $languageDateFormat, 's_stop_words' => $languageStopWords); $iUpdated = $this->localeManager->update($array, array('pk_c_code' => $languageCode)); if ($iUpdated > 0) { osc_add_flash_ok_message(sprintf(_m('%s has been updated'), $languageShortName), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'enable_selected': osc_csrf_check(); $msg = _m('Selected languages have been enabled for the website'); $iUpdated = 0; $aValues = array('b_enabled' => 1); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { osc_translate_categories($i); $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($iUpdated > 0) { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'disable_selected': osc_csrf_check(); $msg = _m('Selected languages have been disabled for the website'); $msg_warning = ''; $iUpdated = 0; $aValues = array('b_enabled' => 0); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { if (osc_language() == $i) { $msg_warning = sprintf(_m("%s can't be disabled because it's the default language"), osc_language()); continue; } $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($msg_warning != '') { if ($iUpdated > 0) { osc_add_flash_warning_message($msg . '</p><p>' . $msg_warning, 'admin'); } else { osc_add_flash_warning_message($msg_warning, 'admin'); } } else { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'enable_bo_selected': osc_csrf_check(); $msg = _m('Selected languages have been enabled for the backoffice (oc-admin)'); $iUpdated = 0; $aValues = array('b_enabled_bo' => 1); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { osc_translate_categories($i); $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($iUpdated > 0) { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'disable_bo_selected': osc_csrf_check(); $msg = _m('Selected languages have been disabled for the backoffice (oc-admin)'); $msg_warning = ''; $iUpdated = 0; $aValues = array('b_enabled_bo' => 0); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { if (osc_language() == $i) { $msg_warning = sprintf(_m("%s can't be disabled because it's the default language"), osc_language()); continue; } $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($msg_warning != '') { if ($iUpdated > 0) { osc_add_flash_warning_message($msg . '</p><p>' . $msg_warning, 'admin'); } else { osc_add_flash_warning_message($msg_warning, 'admin'); } } else { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'delete': osc_csrf_check(); if (is_array(Params::getParam('id'))) { $default_lang = osc_language(); foreach (Params::getParam('id') as $code) { if ($default_lang != $code) { if ($this->localeManager->deleteLocale($code)) { if (!osc_deleteDir(osc_translations_path() . $code)) { osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed"), $code), 'admin'); } else { osc_add_flash_ok_message(sprintf(_m('Directory "%s" has been successfully removed'), $code), 'admin'); } } else { osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed;)"), $code), 'admin'); } } else { osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed because it's the default language. Set another language as default first and try again"), $code), 'admin'); } } } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; default: if (Params::getParam('checkUpdated') != '') { osc_admin_toolbar_update_languages(true); } if (Params::getParam("action") != "") { osc_run_hook("language_bulk_" . Params::getParam("action"), Params::getParam('id')); } // ----- if (Params::getParam('iDisplayLength') == '') { Params::setParam('iDisplayLength', 10); } // ? $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength')); $p_iPage = 1; if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') >= 1) { $p_iPage = Params::getParam('iPage'); } Params::setParam('iPage', $p_iPage); $aLanguages = OSCLocale::newInstance()->listAll(); // pagination $start = ($p_iPage - 1) * Params::getParam('iDisplayLength'); $limit = Params::getParam('iDisplayLength'); $count = count($aLanguages); $displayRecords = $limit; if ($start + $limit > $count) { $displayRecords = $start + $limit - $count; } // ---- $aLanguagesToUpdate = json_decode(osc_get_preference('languages_to_update')); $bLanguagesToUpdate = is_array($aLanguagesToUpdate) ? true : false; // ---- $aData = array(); $max = $start + $limit; if ($max > $count) { $max = $count; } for ($i = $start; $i < $max; $i++) { $l = $aLanguages[$i]; $row = array(); $row[] = '<input type="checkbox" name="id[]" value="' . $l['pk_c_code'] . '" />'; $options = array(); $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&action=edit&id=' . $l['pk_c_code'] . '">' . __('Edit') . '</a>'; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&action=' . ($l['b_enabled'] == 1 ? 'disable_selected' : 'enable_selected') . '&id[]=' . $l['pk_c_code'] . '&' . osc_csrf_token_url() . '">' . ($l['b_enabled'] == 1 ? __('Disable (website)') : __('Enable (website)')) . '</a> '; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&action=' . ($l['b_enabled_bo'] == 1 ? 'disable_bo_selected' : 'enable_bo_selected') . '&id[]=' . $l['pk_c_code'] . '&' . osc_csrf_token_url() . '">' . ($l['b_enabled_bo'] == 1 ? __('Disable (oc-admin)') : __('Enable (oc-admin)')) . '</a>'; $options[] = '<a onclick="return delete_dialog(\'' . $l['pk_c_code'] . '\');" href="' . osc_admin_base_url(true) . '?page=languages&action=delete&id[]=' . $l['pk_c_code'] . '&' . osc_csrf_token_url() . '">' . __('Delete') . '</a>'; $auxOptions = '<ul>' . PHP_EOL; foreach ($options as $actual) { $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL; } $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL; $sUpdate = ''; // get languages to update from t_preference if ($bLanguagesToUpdate) { if (in_array($l['pk_c_code'], $aLanguagesToUpdate)) { $sUpdate = '<a class="btn-market-update btn-market-popup" href="#' . htmlentities($l['pk_c_code']) . '">' . __("Update here") . '</a>'; } } $row[] = $l['s_name'] . $sUpdate . $actions; $row[] = $l['s_short_name']; $row[] = $l['s_description']; $row[] = $l['b_enabled'] ? __('Yes') : __('No'); $row[] = $l['b_enabled_bo'] ? __('Yes') : __('No'); $aData[] = $row; } // ---- $array['iTotalRecords'] = $displayRecords; $array['iTotalDisplayRecords'] = count($aLanguages); $array['iDisplayLength'] = $limit; $array['aaData'] = $aData; $page = (int) Params::getParam('iPage'); if (count($array['aaData']) == 0 && $page != 1) { $total = (int) $array['iTotalDisplayRecords']; $maxPage = ceil($total / (int) $array['iDisplayLength']); $url = osc_admin_base_url(true) . '?' . $_SERVER['QUERY_STRING']; if ($maxPage == 0) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url); $this->redirectTo($url); } if ($page > 1) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url); $this->redirectTo($url); } } $this->_exportVariableToView('aLanguages', $array); $bulk_options = array(array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')), array('value' => 'enable_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Enable (Website)'))), 'label' => __('Enable (Website)')), array('value' => 'disable_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Disable (Website)'))), 'label' => __('Disable (Website)')), array('value' => 'enable_bo_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Enable (oc-admin)'))), 'label' => __('Enable (oc-admin)')), array('value' => 'disable_bo_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Disable (oc-admin)'))), 'label' => __('Disable (oc-admin)')), array('value' => 'delete', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Delete'))), 'label' => __('Delete'))); $bulk_options = osc_apply_filter("language_bulk_filter", $bulk_options); $this->_exportVariableToView('bulk_options', $bulk_options); $this->doView('languages/index.php'); break; } }
function pop_meta_image() { $url = pop_logo_url(); // listing if (osc_is_ad_page()) { if (osc_has_item_resources()) { $url = osc_resource_thumbnail_url(); } } return osc_apply_filter('pop_meta_image_filter', $url); }
function doModel() { switch ($this->action) { case 'contact_post': //contact_post osc_csrf_check(); $yourName = Params::getParam('yourName'); $yourEmail = Params::getParam('yourEmail'); $subject = Params::getParam('subject'); $message = Params::getParam('message'); if (osc_recaptcha_private_key() != '') { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); Session::newInstance()->_setForm('yourName', $yourName); Session::newInstance()->_setForm('yourEmail', $yourEmail); Session::newInstance()->_setForm('subject', $subject); Session::newInstance()->_setForm('message_body', $message); $this->redirectTo(osc_contact_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $banned = osc_is_banned($yourEmail); if ($banned == 1) { osc_add_flash_error_message(_m('Your current email is not allowed')); $this->redirectTo(osc_contact_url()); } else { if ($banned == 2) { osc_add_flash_error_message(_m('Your current IP is not allowed')); $this->redirectTo(osc_contact_url()); } } $user = User::newInstance()->newInstance()->findByEmail($yourEmail); if (isset($user['b_active']) && ($user['b_active'] == 0 || $user['b_enabled'] == 0)) { osc_add_flash_error_message(_m('Your current email is not allowed')); $this->redirectTo(osc_contact_url()); } if (!preg_match('|.*?@.{2,}\\..{2,}|', $yourEmail)) { osc_add_flash_error_message(_m('Please enter a correct email')); Session::newInstance()->_setForm('yourName', $yourName); Session::newInstance()->_setForm('subject', $subject); Session::newInstance()->_setForm('message_body', $message); $this->redirectTo(osc_contact_url()); } $message_name = sprintf(__('Name: %s'), $yourName); $message_email = sprintf(__('Email: %s'), $yourEmail); $message_subject = sprintf(__('Subject: %s'), $subject); $message_body = sprintf(__('Message: %s'), $message); $message_date = sprintf(__('Date: %s at %s'), date('l F d, Y'), date('g:i a')); $message_IP = sprintf(__('IP Address: %s'), get_ip()); $message = <<<MESSAGE {$message_name} {$message_email} {$message_subject} {$message_body} {$message_date} {$message_IP} MESSAGE; $params = array('from' => osc_contact_email(), 'to' => osc_contact_email(), 'to_name' => osc_page_title(), 'reply_to' => $yourEmail, 'subject' => '[' . osc_page_title() . '] ' . __('Contact'), 'body' => nl2br($message)); $error = false; if (osc_contact_attachment()) { $attachment = Params::getFiles('attachment'); if (isset($attachment['error']) && $attachment['error'] == UPLOAD_ERR_OK) { $mime_array = array('text/php', 'text/x-php', 'application/php', 'application/x-php', 'application/x-httpd-php', 'application/x-httpd-php-source', 'application/x-javascript'); $resourceName = $attachment['name']; $tmpName = $attachment['tmp_name']; $resourceType = $attachment['type']; if (function_exists('mime_content_type')) { $resourceType = mime_content_type($tmpName); } if (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME); $output = finfo_file($finfo, $tmpName); finfo_close($finfo); $output = explode("; ", $output); if (is_array($output)) { $output = $output[0]; } $resourceType = $output; } // check mime file if (!in_array($resourceType, $mime_array)) { $emailAttachment = array('path' => $tmpName, 'name' => $resourceName); $error = false; } else { $error = true; } // --- check mime file } else { $error = true; } } if (!$error) { if (isset($emailAttachment)) { $params['attachment'] = $emailAttachment; } osc_run_hook('pre_contact_post', $params); osc_sendMail(osc_apply_filter('contact_params', $params)); if (isset($tmpName)) { @unlink($tmpName); } osc_add_flash_ok_message(_m('Your email has been sent properly. Thank you for contacting us!')); } else { osc_add_flash_error_message(_m('The file you tried to upload does not have a valid extension')); } $this->redirectTo(osc_contact_url()); break; default: //contact $this->doView('contact.php'); } }
public static function photos($resources = null) { if ($resources == null) { $resources = osc_get_item_resources(); } if ($resources != null && is_array($resources) && count($resources) > 0) { foreach ($resources as $_r) { ?> <div id="<?php echo $_r['pk_i_id']; ?> " fkid="<?php echo $_r['fk_i_item_id']; ?> " name="<?php echo $_r['s_name']; ?> "> <img src="<?php echo osc_apply_filter('resource_path', osc_base_url() . $_r['s_path']) . $_r['pk_i_id'] . '_thumbnail.' . $_r['s_extension']; ?> " /><a href="javascript:delete_image(<?php echo $_r['pk_i_id'] . ", " . $_r['fk_i_item_id'] . ", '" . $_r['s_name'] . "', '" . Params::getParam('secret') . "'"; ?> );" class="delete"><?php _e('Delete'); ?> </a> </div> <?php } } }
public function uploadItemResources($aResources,$itemId) { if($aResources != '') { $itemResourceManager = ItemResource::newInstance(); $folder = osc_uploads_path().(floor($itemId/100))."/"; $numImagesItems = osc_max_images_per_item(); $numImages = $itemResourceManager->countResources($itemId); foreach ($aResources['error'] as $key => $error) { if($numImagesItems==0 || ($numImagesItems>0 && $numImages<$numImagesItems)) { if ($error == UPLOAD_ERR_OK) { $tmpName = $aResources['tmp_name'][$key]; $imgres = ImageResizer::fromFile($tmpName); $extension = osc_apply_filter('upload_image_extension', $imgres->getExt()); $mime = osc_apply_filter('upload_image_mime', $imgres->getMime()); // Create normal size $normal_path = $path = $tmpName."_normal"; $size = explode('x', osc_normal_dimensions()); $img = ImageResizer::fromFile($tmpName)->autoRotate()->resizeTo($size[0], $size[1]); if( osc_is_watermark_text() ) { $img->doWatermarkText(osc_watermark_text(), osc_watermark_text_color()); } else if ( osc_is_watermark_image() ){ $img->doWatermarkImage(); } $img->saveToFile($path, $extension); // Create preview $path = $tmpName."_preview"; $size = explode('x', osc_preview_dimensions()); ImageResizer::fromFile($normal_path)->resizeTo($size[0], $size[1])->saveToFile($path, $extension); // Create thumbnail $path = $tmpName."_thumbnail"; $size = explode('x', osc_thumbnail_dimensions()); ImageResizer::fromFile($normal_path)->resizeTo($size[0], $size[1])->saveToFile($path, $extension); $numImages++; $itemResourceManager->insert(array( 'fk_i_item_id' => $itemId )); $resourceId = $itemResourceManager->dao->insertedId(); if(!is_dir($folder)) { if (!@mkdir($folder, 0755, true)) { return 3; // PATH CAN NOT BE CREATED } } osc_copy($tmpName.'_normal', $folder.$resourceId.'.'.$extension); osc_copy($tmpName.'_preview', $folder.$resourceId.'_preview.'.$extension); osc_copy($tmpName.'_thumbnail', $folder.$resourceId.'_thumbnail.'.$extension); if( osc_keep_original_image() ) { $path = $folder.$resourceId.'_original.'.$extension; osc_copy($tmpName, $path); } @unlink($tmpName."_normal"); @unlink($tmpName."_preview"); @unlink($tmpName."_thumbnail"); @unlink($tmpName); $s_path = str_replace(osc_base_path(), '', $folder); $itemResourceManager->update( array( 's_path' => $s_path ,'s_name' => osc_genRandomPassword() ,'s_extension' => $extension ,'s_content_type' => $mime ) ,array( 'pk_i_id' => $resourceId ,'fk_i_item_id' => $itemId ) ); osc_run_hook('uploaded_file', ItemResource::newInstance()->findByPrimaryKey($resourceId)); } } } unset($itemResourceManager); } return 0; // NO PROBLEMS }
/** * Formats the price using the appropiate currency. * * @param float $price * @return string */ function osc_format_price($price) { if ($price == null) { return osc_apply_filter('item_price_null', __('Check with seller')); } if ($price == 0) { return osc_apply_filter('item_price_zero', __('Free')); } $price = $price / 1000000; $currencyFormat = osc_locale_currency_format(); $currencyFormat = str_replace('{NUMBER}', number_format($price, osc_locale_num_dec(), osc_locale_dec_point(), osc_locale_thousands_sep()), $currencyFormat); $currencyFormat = str_replace('{CURRENCY}', osc_item_currency(), $currencyFormat); return osc_apply_filter('item_price', $currencyFormat); }