Exemplo n.º 1
0
function osc_runAlert($type = null, $last_exec = null)
{
    if (!in_array($type, array('HOURLY', 'DAILY', 'WEEKLY', 'INSTANT'))) {
        return;
    }
    if ($last_exec == null) {
        $cron = Cron::newInstance()->getCronByType($type);
        if (is_array($cron)) {
            $last_exec = $cron['d_last_exec'];
        } else {
            $last_exec = '0000-00-00 00:00:00';
        }
    }
    $internal_name = 'alert_email_hourly';
    switch ($type) {
        case 'HOURLY':
            $internal_name = 'alert_email_hourly';
            break;
        case 'DAILY':
            $internal_name = 'alert_email_daily';
            break;
        case 'WEEKLY':
            $internal_name = 'alert_email_weekly';
            break;
        case 'INSTANT':
            $internal_name = 'alert_email_instant';
            break;
    }
    $active = TRUE;
    $searches = Alerts::newInstance()->findByTypeGroup($type, $active);
    foreach ($searches as $s_search) {
        // Get if there're new ads on this search
        $json = $s_search['s_search'];
        $array_conditions = (array) json_decode($json);
        $new_search = Search::newInstance();
        $new_search->setJsonAlert($array_conditions);
        $new_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' ", DB_TABLE_PREFIX, $last_exec));
        $items = $new_search->doSearch();
        $totalItems = $new_search->count();
        if (count($items) > 0) {
            // If we have new items from last check
            // Catch the user subscribed to this search
            $users = Alerts::newInstance()->findUsersBySearchAndType($s_search['s_search'], $type, $active);
            if (count($users) > 0) {
                $ads = '';
                foreach ($items as $item) {
                    $ads .= '<a href="' . osc_item_url_ns($item['pk_i_id']) . '">' . $item['s_title'] . '</a><br/>';
                }
                foreach ($users as $user) {
                    osc_run_hook('hook_' . $internal_name, $user, $ads, $s_search, $items, $totalItems);
                    AlertsStats::newInstance()->increase(date('Y-m-d'));
                }
            }
        }
    }
}
Exemplo n.º 2
0
 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;
         }
     }
 }
Exemplo n.º 3
0
 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&amp;action=delete&amp;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;
     }
 }
Exemplo n.º 4
0
/**
 * Create automatically the url of the item details page
 *
 * @param string $locale
 * @return string
 */
function osc_premium_url($locale = '')
{
    if (osc_rewrite_enabled()) {
        $sanitized_categories = array();
        $cat = Category::newInstance()->hierarchy(osc_premium_category_id());
        for ($i = count($cat); $i > 0; $i--) {
            $sanitized_categories[] = $cat[$i - 1]['s_slug'];
        }
        $url = str_replace('{CATEGORIES}', implode("/", $sanitized_categories), str_replace('{ITEM_ID}', osc_premium_id(), str_replace('{ITEM_TITLE}', osc_sanitizeString(osc_premium_title()), osc_get_preference('rewrite_item_url'))));
        if ($locale != '') {
            $path = osc_base_url() . $locale . "/" . $url;
        } else {
            $path = osc_base_url() . $url;
        }
    } else {
        $path = osc_item_url_ns(osc_premium_id(), $locale);
    }
    return $path;
}
Exemplo n.º 5
0
        $options[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&amp;action=status&amp;id=' . $comment['pk_i_id'] . '&amp;value=INACTIVE">' . __('Deactivate') . '</a>';
    } else {
        $options[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&amp;action=status&amp;id=' . $comment['pk_i_id'] . '&amp;value=ACTIVE">' . __('Activate') . '</a>';
    }
    if ($comment['b_enabled']) {
        $options[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&amp;action=status&amp;id=' . $comment['pk_i_id'] . '&amp;value=DISABLE">' . __('Unblock') . '</a>';
    } else {
        $options[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&amp;action=status&amp;id=' . $comment['pk_i_id'] . '&amp;value=ENABLE">' . __('Block') . '</a>';
    }
    $options[] = '<a onclick="javascript:return confirm(\'' . osc_esc_js(__("This action can't be undone. Are you sure you want to continue?")) . '\')" href="' . osc_admin_base_url(true) . '?page=comments&amp;action=delete&amp;id=' . $comment['pk_i_id'] . '" id="dt_link_delete">' . __('Delete') . '</a>';
    $row[] = '<input type="checkbox" name="id[]" value="' . $comment['pk_i_id'] . '" />';
    if (empty($comment['s_author_name'])) {
        $user = User::newInstance()->findByPrimaryKey($comment['fk_i_user_id']);
        $comment['s_author_name'] = $user['s_email'];
    }
    $row[] = $comment['s_author_name'] . ' (<a target="_blank" href="' . osc_item_url_ns($comment['fk_i_item_id']) . '">' . $comment['s_title'] . '</a>)<div class="datatables_quick_edit" style="display:none;">' . implode(' &middot; ', $options) . '</div>';
    $row[] = $comment['s_body'];
    $row[] = $comment['dt_pub_date'];
    $aData[] = $row;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="<?php 
echo str_replace('_', '-', osc_current_user_locale());
?>
">
    <head>
        <?php 
osc_current_admin_theme_path('head.php');
?>
        <link href="<?php 
Exemplo n.º 6
0
CommentForm::primary_input_hidden($comment);
?>
                        <div class="FormElement">
                            <div class="FormElementName">
                                <?php 
_e('Edit a comment on item:');
?>
                                <?php 
$item = Item::newInstance()->findByPrimaryKey($comment['fk_i_item_id']);
?>
                                <b><?php 
echo $item['s_title'];
?>
</b>
                                ( <a href="<?php 
echo osc_item_url_ns($comment['fk_i_item_id']);
?>
" target="_blank"><?php 
_e('View');
?>
</a> |
                                <a href="<?php 
echo osc_admin_base_url(true);
?>
?page=items&action=item_edit&id=<?php 
echo $item['pk_i_id'];
?>
"><?php 
_e('Edit');
?>
</a> )
Exemplo n.º 7
0
 function doModel()
 {
     //calling the view...
     $locales = OSCLocale::newInstance()->listAllEnabled();
     $this->_exportVariableToView('locales', $locales);
     switch ($this->action) {
         case 'item_add':
             // post
             if (!osc_users_enabled()) {
                 osc_add_flash_message(_m('Users not enabled'));
                 $this->redirectTo(osc_base_url(true));
             }
             if (osc_reg_user_post() && $this->user == null) {
                 // CHANGEME: This text
                 osc_add_flash_message(_m('Only registered users are allowed to post items'));
                 $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()->getByCountry($this->user['fk_c_country_code']);
             } else {
                 if (count($countries) > 0) {
                     $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']);
                 }
             }
             $cities = array();
             if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') {
                 $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $this->user['fk_i_region_id']);
             } else {
                 if (count($regions) > 0) {
                     $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']);
                 }
             }
             $this->_exportVariableToView('countries', $countries);
             $this->_exportVariableToView('regions', $regions);
             $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_users_enabled()) {
                 osc_add_flash_message(_m('Users not allowed'));
                 $this->redirectTo(osc_base_url(true));
             }
             if (osc_reg_user_post() && $this->user == null) {
                 osc_add_flash_message(_m('Only registered users are allowed to post items'));
                 $this->redirectTo(osc_base_url(true));
             }
             // POST ITEM ( ADD ITEM )
             $mItems = new ItemActions(false);
             $success = $mItems->add();
             if ($success) {
                 $PcontactName = Params::getParam('contactName');
                 $PcontactEmail = Params::getParam('contactEmail');
                 $itemId = Params::getParam('itemId');
                 $item = array();
                 if (Session::newInstance()->_get('userId') == '') {
                     $mPages = new Page();
                     $aPage = $mPages->findByInternalName('email_new_item_non_register_user');
                     $locale = osc_current_user_locale();
                     $content = array();
                     if (isset($aPage['locale'][$locale]['s_title'])) {
                         $content = $aPage['locale'][$locale];
                     } else {
                         $content = current($aPage['locale']);
                     }
                     $item = $this->itemManager->findByPrimaryKey($itemId);
                     $item_url = osc_item_url();
                     // before page = user , action = item_edit
                     $edit_url = osc_item_edit_url($item['s_secret'], $itemId);
                     // before page = user , action = item_delete
                     $delete_url = osc_item_delete_url($item['s_secret'], $itemId);
                     $words = array();
                     $words[] = array('{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{EDIT_LINK}', '{EDIT_URL}', '{DELETE_LINK}', '{DELETE_URL}');
                     $words[] = array($itemId, $PcontactName, $PcontactEmail, osc_base_url(), $item['s_title'], $item_url, osc_page_title(), '<a href="' . $edit_url . '">' . $edit_url . '</a>', $edit_url, '<a href="' . $delete_url . '">' . $delete_url . '</a>', $delete_url);
                     $title = osc_mailBeauty($content['s_title'], $words);
                     $body = osc_mailBeauty($content['s_text'], $words);
                     $emailParams = array('subject' => $title, 'to' => $PcontactEmail, 'to_name' => $PcontactName, 'body' => $body, 'alt_body' => $body);
                     osc_sendMail($emailParams);
                 }
                 osc_run_hook('posted_item', $item);
                 $category = Category::newInstance()->findByPrimaryKey(Params::getParam('catId'));
                 View::newInstance()->_exportVariableToView('category', $category);
                 $this->redirectTo(osc_search_category_url());
             } else {
                 $this->redirectTo(osc_item_post_url());
             }
             break;
         case 'item_edit':
             $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'))", $id, $secret, $this->userId);
             if (count($item) == 1) {
                 $item = Item::newInstance()->findByPrimaryKey($id);
                 $categories = Category::newInstance()->toTree();
                 $countries = Country::newInstance()->listAll();
                 $regions = array();
                 if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') {
                     $regions = Region::newInstance()->getByCountry($this->user['fk_c_country_code']);
                 } else {
                     if (count($countries) > 0) {
                         $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']);
                     }
                 }
                 $cities = array();
                 if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') {
                     $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $this->user['fk_i_region_id']);
                 } else {
                     if (count($regions) > 0) {
                         $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']);
                     }
                 }
                 $currencies = Currency::newInstance()->listAll();
                 $this->_exportVariableToView('item', $item);
                 //$this->_exportVariableToView('user', $this->user) ;
                 $this->doView('item-edit.php');
             } else {
                 // add a flash message [ITEM NO EXISTE]
                 //$this->redirectTo(osc_base_url(true));
                 osc_add_flash_message(_m('Sorry, we don\'t have any items 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'))", $id, $secret, $this->userId);
             if (count($item) == 1) {
                 $this->_exportVariableToView('item', $item[0]);
                 $mItems = new ItemActions(false);
                 $success = $mItems->edit();
                 if ($success) {
                     osc_add_flash_message(_m('Great! We\'ve just updated your item'));
                     $this->redirectTo(osc_base_url(true) . "?page=item&id={$id}");
                 } else {
                     $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' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId);
             View::newInstance()->_exportVariableToView('item', $item[0]);
             if ($item[0]['e_status'] == 'INACTIVE') {
                 // ACTIVETE ITEM
                 $mItems = new ItemActions(false);
                 $success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']);
                 if ($success) {
                     osc_add_flash_message(_m('The item has been validated'));
                 } else {
                     osc_add_flash_message(_m('The item can\'t be validated'));
                 }
             } else {
                 osc_add_flash_message(_m('The item 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' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $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_message(_m('Your item has been deleted'));
                 } else {
                     osc_add_flash_message(_m('The item 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_message(_m('The item you are trying to delete couldn\'t be deleted'));
                 $this->redirectTo(osc_base_url());
             }
             break;
         case 'deleteResource':
             $id = Params::getParam('id');
             $item = Params::getParam('item');
             $code = Params::getParam('code');
             $secret = Params::getParam('secret');
             // Check for required fields
             if (!(is_numeric($id) && is_numeric($item) && preg_match('/^([a-z0-9]+)$/i', $code))) {
                 osc_add_flash_message(_m("The selected photo couldn't be deleted, the url doesn't exist"));
                 if ($this->userId == null) {
                     $this->redirectTo(osc_base_url());
                 } else {
                     $this->redirectTo(osc_user_dashboard_url());
                 }
             }
             $aItem = $this->itemManager->findByPrimaryKey($item);
             // Check if the item exists
             if (count($aItem) == 0) {
                 osc_add_flash_message(_m('The item doesn\'t exist'));
                 $this->redirectTo(osc_base_url());
             }
             // Check if the item belong to the user
             if ($this->userId != null && $this->userId != $aItem['fk_i_user_id']) {
                 osc_add_flash_message(_m('The item doesn\'t belong to you'));
                 $this->redirectTo(osc_item_url_ns($item));
             }
             // Check if the secret passphrase match with the item
             if ($this->userId == null && $secret != $aItem['s_secret']) {
                 osc_add_flash_message(_m('The item doesn\'t belong to you'));
                 $this->redirectTo(osc_item_url_ns($item));
             }
             // Does id & code combination exist?
             $result = ItemResource::newInstance()->getResourceSecure($id, $code);
             if ($result > 0) {
                 // Delete: file, db table entry
                 osc_deleteResource($id);
                 ItemResource::newInstance()->delete(array('pk_i_id' => $id, 'fk_i_item_id' => $item, 's_name' => $code));
                 osc_add_flash_message(_m('The selected photo has been successfully deleted'));
             } else {
                 osc_add_flash_message(_m("The selected photo couldn't be deleted"));
             }
             // Redirect to item_edit. If unregistered user, include $secret.
             $this->redirectTo(osc_item_edit_url($secret, $item));
             break;
         case 'mark':
             $mItem = new ItemActions(false);
             $id = Params::getParam('id');
             $as = Params::getParam('as');
             $item = Item::newInstance()->findByPrimaryKey($id);
             View::newInstance()->_exportVariableToView('item', $item);
             $mItem->mark($id, $as);
             osc_add_flash_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':
             $mItem = new ItemActions(false);
             $mItem->send_friend();
             $item_url = Params::getParam('item_url');
             $this->redirectTo($item_url);
             break;
         case 'contact':
             $item = $this->itemManager->findByPrimaryKey(Params::getParam('id'));
             $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']);
             if ($category['i_expiration_days'] > 0) {
                 $item_date = strtotime($item['dt_pub_date']) + $category['i_expiration_days'] * (24 * 3600);
                 $date = time();
                 if ($item_date < $date) {
                     // The item is expired, we can not contact the seller
                     osc_add_flash_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller'));
                     $this->redirectTo(osc_create_item_url($item));
                 }
             }
             $this->_exportVariableToView('item', $item);
             $this->doView('item-contact.php');
             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_message(_m('The Recaptcha code is wrong'));
                     $this->redirectTo(osc_item_url());
                     return false;
                     // BREAK THE PROCESS, THE RECAPTCHA IS WRONG
                 }
             }
             $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']);
             if ($category['i_expiration_days'] > 0) {
                 $item_date = strtotime($item['dt_pub_date']) + $category['i_expiration_days'] * (24 * 3600);
                 $date = time();
                 if ($item_date < $date) {
                     // The item is expired, we can not contact the seller
                     osc_add_flash_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller'));
                     $this->redirectTo(osc_item_url());
                 }
             }
             $mItem = new ItemActions(false);
             $mItem->contact();
             osc_add_flash_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');
                     break;
                 case 1:
                     $msg = _m('Your comment is awaiting moderation');
                     break;
                 case 2:
                     $msg = _m('Your comment has been approved');
                     break;
                 case 3:
                     $msg = _m('Please fill the required fields (name, email)');
                     break;
                 case 4:
                     $msg = _m('Please type a comment');
                     break;
                 case 5:
                     $msg = _m('Your comment has been marked as spam');
                     break;
             }
             osc_add_flash_message($msg);
             $this->redirectTo(Params::getParam('itemURL'));
             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_message(_m('This item doesn\'t exist'));
                 $this->redirectTo(osc_base_url(true));
             }
             View::newInstance()->_exportVariableToView('item', $item);
             if ($this->userId == null) {
                 osc_add_flash_message(_m('You have to be logged to delete a comment'));
                 $this->redirectTo(osc_item_url());
             }
             $commentManager = ItemComment::newInstance();
             $aComment = $commentManager->findByPrimaryKey($commentId);
             if (count($aComment) == 0) {
                 osc_add_flash_message(_m('The comment doesn\'t exist'));
                 $this->redirectTo(osc_item_url());
             }
             if ($aComment['e_status'] != 'ACTIVE') {
                 osc_add_flash_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_message(_m('You cannot delete the comment'));
                 $this->redirectTo(osc_item_url());
             }
             $commentManager->deleteByPrimaryKey($commentId);
             osc_add_flash_message(_m('The comment has been deleted correctly'));
             $this->redirectTo(osc_item_url());
             break;
         default:
             if (Params::getParam('id') == '') {
                 $this->redirectTo(osc_base_url());
             }
             if (Params::getParam('lang') != '') {
                 Session::newInstance()->_set('userLocale', Params::getParam('lang'));
             }
             $item = $this->itemManager->findByPrimaryKey(Params::getParam('id'));
             // if item doesn't exist redirect to base url
             if (count($item) == 0) {
                 osc_add_flash_message(_m('This item doesn\'t exist'));
                 $this->redirectTo(osc_base_url(true));
             } else {
                 if ($item['e_status'] != 'ACTIVE') {
                     if ($this->userId == $item['fk_i_user_id']) {
                         osc_add_flash_message(_m('The item hasn\'t been validated. Please validate it in order to show it to the rest of users'));
                     } else {
                         osc_add_flash_message(_m('This item hasn\'t been validated'));
                         $this->redirectTo(osc_base_url(true));
                     }
                 }
                 $mStats = new ItemStats();
                 $mStats->increase('i_num_views', $item['pk_i_id']);
                 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']));
                 }
                 $this->_exportVariableToView('items', array($item));
                 osc_run_hook('show_item', $item);
                 $this->doView('item.php');
             }
             break;
         case 'dashboard':
             //dashboard...
             break;
     }
 }
Exemplo n.º 8
0
function osc_runAlert($type = null)
{
    if ($type == null) {
        return;
    }
    $internal_name = 'alert_email_hourly';
    switch ($type) {
        case 'HOURLY':
            $internal_name = 'alert_email_hourly';
            break;
        case 'DAILY':
            $internal_name = 'alert_email_daily';
            break;
        case 'WEEKLY':
            $internal_name = 'alert_email_weekly';
            break;
        case 'INSTANT':
            $internal_name = 'alert_email_instant';
            break;
    }
    $searches = Alerts::newInstance()->getAlertsByTypeGroup($type);
    foreach ($searches as $s_search) {
        $a_search = Search::newInstance();
        // Get if there're new ads on this search
        $a_search = osc_unserialize(base64_decode($s_search['s_search']));
        $crons = Cron::newInstance()->getCronByType($type);
        if (isset($crons[0])) {
            $last_exec = $crons[0]['d_last_exec'];
        } else {
            $last_exec = '0000-00-00 00:00:00';
        }
        $a_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' ", DB_TABLE_PREFIX, $last_exec));
        $totalItems = $a_search->count();
        $items = $a_search->doSearch();
        if (count($items) > 0) {
            //If we have new items from last check
            //Catch the user subscribed to this search
            $users = Alerts::newInstance()->getUsersBySearchAndType($s_search['s_search'], $type);
            if (count($users) > 0) {
                $prefLocale = osc_language();
                $page = Page::newInstance()->findByInternalName($internal_name);
                $page = Page::newInstance()->findByInternalName($internal_name);
                $page_description = $page['locale'];
                $_title = $page_description[$prefLocale]['s_title'];
                $_body = $page_description[$prefLocale]['s_text'];
                $ads = "";
                foreach ($items as $item) {
                    $ads .= '<a href="' . osc_item_url_ns($item['pk_i_id']) . '">' . $item['s_title'] . '</a><br/>';
                }
                foreach ($users as $user) {
                    if ($user['fk_i_user_id'] != 0) {
                        $user = User::newInstance()->findByPrimaryKey($user['fk_i_user_id']);
                    } else {
                        $user['s_name'] = $user['s_email'];
                    }
                    $unsub_link = osc_user_unsubscribe_alert_url($user['s_email'], $s_search['s_search']);
                    //osc_create_url(array('file' => 'user', 'action' => 'unsub_alert', 'email' => $user['s_email'], 'alert' => $s_search['s_search'])) ;
                    $unsub_link = '<a href="' . $unsub_link . '">unsubscribe alert</a>';
                    $words = array();
                    $words[] = array('{USER_NAME}', '{USER_EMAIL}', '{ADS}', '{UNSUB_LINK}');
                    $words[] = array($user['s_name'], $user['s_email'], $ads, $unsub_link);
                    $title = osc_mailBeauty($_title, $words);
                    $body = osc_mailBeauty($_body, $words);
                    $params = array('subject' => $title, 'to' => $user['s_email'], 'to_name' => $user['s_name'], 'body' => $body, 'alt_body' => $body);
                    osc_sendMail($params);
                }
            }
        }
    }
}
Exemplo n.º 9
0
/**
 * Create automatically the url of the item details page
 *
 * @return string
 */
function osc_item_url($locale = '')
{
    if (osc_rewrite_enabled()) {
        $sanitized_title = osc_sanitizeString(osc_item_title());
        $sanitized_category = '';
        $cat = Category::newInstance()->hierarchy(osc_item_category_id());
        for ($i = count($cat); $i > 0; $i--) {
            $sanitized_category .= $cat[$i - 1]['s_slug'] . '/';
        }
        if ($locale != '') {
            $path = osc_base_url() . sprintf('%s_%s%s_%d', $locale, $sanitized_category, $sanitized_title, osc_item_id());
        } else {
            $path = osc_base_url() . sprintf('%s%s_%d', $sanitized_category, $sanitized_title, osc_item_id());
        }
    } else {
        //$path = osc_base_url(true) . sprintf('?page=item&id=%d', osc_item_id()) ;
        $path = osc_item_url_ns(osc_item_id(), $locale);
    }
    return $path;
}
Exemplo n.º 10
0
 private function toDatatablesFormat()
 {
     $this->sOutput = '{';
     $this->sOutput .= '"iTotalRecords": ' . $this->total . ', ';
     $this->sOutput .= '"iTotalDisplayRecords": ' . $this->filtered_total . ', ';
     $this->sOutput .= '"iExtraCols": ' . $this->extraCols . ', ';
     $this->sOutput .= '"sExtraCols": [';
     $this->sOutput .= '], ';
     $this->sOutput .= '"aaData": [ ';
     if (count($this->result) > 0) {
         $count = 0;
         foreach ($this->result as $r) {
             $this->sOutput .= "[";
             $this->sOutput .= "\"<input type='checkbox' name='id[]' value='" . $r['pk_i_id'] . "' />\",";
             $this->sOutput .= "\"<div id='media_list_pic'><img src='" . osc_apply_filter('resource_path', osc_base_url() . $r['s_path']) . $r['pk_i_id'] . "_thumbnail." . $r['s_extension'] . "' style='max-width: 60px; max-height: 60px;' /></div> <div id='media_list_filename'>" . $r['s_content_type'] . "\",";
             $this->sOutput .= "\"<a onclick='javascript:return confirm(\\'" . __('This action can not be undone. Are you sure you want to continue?') . "\\')\\' href='" . osc_admin_base_url(true) . "?page=media&action=delete&amp;id[]=" . $r['pk_i_id'] . "' id='dt_link_delete'>" . __('Delete') . "</a>\",";
             $this->sOutput .= "\"<a target='_blank' href='" . osc_item_url_ns($r['fk_i_item_id']) . "'>item #" . $r['fk_i_item_id'] . "</a>\",";
             $this->sOutput .= "\"" . $r['dt_pub_date'] . "\"";
             if (end($this->result) == $r) {
                 $this->sOutput .= "]";
             } else {
                 $this->sOutput .= "],";
             }
         }
     }
     $this->sOutput .= ']}';
 }
Exemplo n.º 11
0
                     }
                    ,"sPaginationType": "full_numbers"
                    ,"aaData": [
                        <?php 
foreach (__get('comments') as $c) {
    ?>
                            [
                                "<input type='checkbox' name='id[]' value='<?php 
    echo $c['pk_i_id'];
    ?>
' />"
                                ,"<?php 
    echo addcslashes($c['s_author_name'], '"');
    ?>
 (<a target='_blank' href='<?php 
    echo osc_item_url_ns($c['fk_i_item_id']);
    ?>
'><?php 
    echo $c['s_title'];
    ?>
</a>)<div id='datatables_quick_edit'><a href='<?php 
    echo osc_admin_base_url(true);
    ?>
?page=comments&action=comment_edit&id=<?php 
    echo $c['pk_i_id'];
    ?>
' id='dt_link_edit'><?php 
    _e('Edit');
    ?>
</a><?php 
    if (isset($c['b_active']) && $c['b_active'] == 1) {