Big bug sur mon site

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Big bug sur mon site

Re: Big bug sur mon site

par sirakawa » 26 août 2012, 18:11

S'agit-il d'in site fait avec Oscommerce? dans ce cas, les auteurs seraient plus à même d'aider.
J'ai relu le message d'origine et, si je comprends bien, l'affichage se fait dans la langue locale du consultant, sauf pour les catégories.
Est-ce bien ça?
Le problème, c'est que le javascript est mêlé de php qui appelle des fonctions dont on ne sait rien·
par exemple, tout au début:
[javascript]twitter_theme.text_select_subcategory = "<?php _e('Select a subcategory...', 'twitter') ; ?>" ;[/javascript]
il ya un appel à une fonction php _e qui doit être définie dieu sait où...
et juste après ce qui doit merder:
[javascript]twitter_theme.category_selected_id = "<?php echo item_selected_category_id() ; ?>" ;[/javascript]

et plus loin:
<?php item_category_select_js() ; ?>
et encore plus loin:
<!-- category input -->
<div class="clearfix">
<label><?php _e('Category', 'twitter') ; ?></label>
<div class="input">
<?php item_category_select( __('Select a category...', 'twitter') ) ; ?>
</div>
</div>
<!-- category input end -->
Tout ça ne rend pas les choses faciles...

Re: Big bug sur mon site

par keish » 26 août 2012, 16:15

Où est le point d'entrée?
et que peut on tester à ce niveau?
Hello Sirakawa,

Je suis désolé, mais je n'ai pas bien compris tes questions...
Aimerais-tu le lien Internet du siteweb pour vérifier par toi même?
Autrement, juste m'expliquer un peu plus ce qu'il manque.
Tu sais, je comprends vite mais faut m'expliquer longtemps :-)

Encore merci de ton aide.

Re: Big bug sur mon site

par sirakawa » 26 août 2012, 14:58

Où est le point d'entrée?
et que peut on tester à ce niveau?

Re: Big bug sur mon site

par keish » 26 août 2012, 13:34

Pas d'idée? :cry:

Re: Big bug sur mon site

par keish » 25 août 2012, 18:01

Hello sirakawa,

Merci de ta réponse, j'avais cru que le fichier JS était celui en cause...

Ci-dessous, j'espère que cette fois c'est le bon code ;):
Bjr,

A vue de perchoir aux oiseaux, le code intéressant ceux qui t'ont déjà répondu c'est celui qui est appelé par ce formulaire :
<form class="well" name="item" action="<?php echo osc_base_url(true) ; ?>" method="post" enctype="multipart/form-data">
ou si tu préfères, le script qui est lancé quand on clique sur le bouton envoyé.
<?php if ( ! defined('ABS_PATH')) exit('ABS_PATH is not loaded. Direct access is not allowed.');

    class CWebItem extends BaseModel
    {
        private $itemManager;
        private $user;
        private $userId;

        function __construct()
        {
            parent::__construct() ;
            $this->itemManager = Item::newInstance();

            // here allways userId == ''
            if( osc_is_web_user_logged_in() ) {
                $this->userId = osc_logged_user_id();
                $this->user = User::newInstance()->findByPrimaryKey($this->userId);
            } else {
                $this->userId = null;
                $this->user = null;
            }
        }

        //Business Layer...
        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']);
                    if( $itemURI != $URI ) {
                        $this->redirectTo(osc_base_url() . $itemURI);
                    }

                    $this->doView('item.php') ;
                break;
            }
        }

        //hopefully generic...
        function doView($file)
        {
            osc_run_hook("before_html");
            osc_current_web_theme_path($file) ;
            Session::newInstance()->_clearVariables();
            osc_run_hook("after_html");
        }
    }

    /* file end: ./item.php */
?>
En dehors de ce point et de mon horreur pour ces codes qui mettent du <?PHP ?> à tous les coins de ligne, que veut dire:
twitter_theme.text_select_subcategory = "<?php _e('Select a subcategory...', 'twitter') ; ?>" ;
<?php
    /**
     * Gets current category
     *
     * @return array
     */
    function osc_category() {
        if (View::newInstance()->_exists('subcategories')) {
            $category = View::newInstance()->_current('subcategories') ;
        } elseif (View::newInstance()->_exists('categories')) {
            $category = View::newInstance()->_current('categories') ;
        } elseif (View::newInstance()->_exists('category')) {
            $category = View::newInstance()->_get('category') ;
        } else {
            $category = null;
        }
        return($category) ;
    }

    /**
     * Low level function: Gets the list of categories as a tree
     *
     * <code>
     * <?php
     *  $c = osc_get_categories() ;
     * ?>
     * </code>
     *
     * @return <array>
     */
    function osc_get_categories() {
       if ( !View::newInstance()->_exists('categories') ) {
            View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;
        }
        return  View::newInstance()->_get('categories') ;
    }
    
    /* #dev.conquer: review that. If the result of toTree had the same format as items or comments, it would be the same as osc_field */
    function osc_field_toTree($item, $field) {
        if(isset($item[$field])) {
            return $item[$field] ;
        }
        return '' ;
    }

    /**
     * Low level function: Gets the value of the category attribute
     *
     * @return <array>
     */
    function osc_category_field($field, $locale = '') {
        return osc_field_toTree(osc_category(), $field) ;
    }

    /**
     * Gets the number of categories
     *
     * @return int
     */
    function osc_priv_count_categories() {
        return View::newInstance()->_count('categories') ;
    }

    /**
     * Gets the number of subcategories
     *
     * @return int
     */
    function osc_priv_count_subcategories() {
        return View::newInstance()->_count('subcategories') ;
    }

    /**
     * Gets the total of categories. If categories are not loaded, this function will load them.
     *
     * @return int
     */
    function osc_count_categories() {
        if ( !View::newInstance()->_exists('categories') ) {
            View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;
        }
        return osc_priv_count_categories() ;
    }

    /**
     * Let you know if there are more categories in the list. If categories are not loaded, this function will load them.
     *
     * @return boolean
     */
    function osc_has_categories() {
        if ( !View::newInstance()->_exists('categories') ) {
            View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;
        }
        return View::newInstance()->_next('categories') ;
    }

    /**
     * Gets the total of subcategories for the current category. If subcategories are not loaded, this function will load them and
     * it will prepare the the pointer to the first element
     *
     * @return int
     */
    function osc_count_subcategories() {
        $category = View::newInstance()->_current('categories') ;
        if ( $category == '' ) return -1 ;
        if ( !isset($category['categories']) ) return 0 ;
        if ( !is_array($category['categories']) ) return 0 ; 
        if ( count($category['categories']) == 0 ) return 0;
        if ( !View::newInstance()->_exists('subcategories') ) {
            View::newInstance()->_exportVariableToView('subcategories', $category['categories']) ;
        }
        return osc_priv_count_subcategories() ;
    }

    /**
     * Let you know if there are more subcategories for the current category in the list. If subcategories are not loaded, this
     * function will load them and it will prepare the pointer to the first element
     *
     * @return boolean
     */
    function osc_has_subcategories() {
        $category = View::newInstance()->_current('categories') ;
        if ( $category == '' ) return -1 ;
        if ( !isset($category['categories']) ) return false ;

        if ( !View::newInstance()->_exists('subcategories') ) {
            View::newInstance()->_exportVariableToView('subcategories', $category['categories']) ;
        }
        $ret = View::newInstance()->_next('subcategories') ;
        //we have to delete for next iteration
        if (!$ret) View::newInstance()->_erase('subcategories') ;
        return $ret ;
    }

    /**
     * Gets the name of the current category
     *
     * @param string $locale
     * @return string
     */
    function osc_category_name($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("s_name", $locale) ;
    }

    /**
     * Gets the description of the current category
     *
     * @param string $locale
     * @return string
     */
    function osc_category_description($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("s_description", $locale) ;
    }

    /**
     * Gets the id of the current category
     *
     * @param string $locale
     * @return string
     */
    function osc_category_id($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("pk_i_id", $locale) ;
    }
    
    /**
     * Gets the slug of the current category. WARNING: This slug could NOT be used as a valid W3C HTML tag attribute as it could have other characters besides [A-Za-z0-9-_] We only did a urlencode to the variable
     *
     * @param string $locale
     * @return string
     */
    function osc_category_slug($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("s_slug", $locale) ;
    }

    /**
     * Gets the total items related with the current category
     *
     * @return int
     */
    function osc_category_total_items() {
        return osc_category_field("i_num_items", "") ;
        //$category = osc_category() ;
        //return CategoryStats::newInstance()->getNumItems($category) ;
    }

    /**
     * Reset the pointer of the array to the first category
     * 
     * @return void
     */
    function osc_goto_first_category() {
        View::newInstance()->_reset('categories') ;
    }
    
    /**
     * Gets list of non-empty categories
     * 
     * @return void
     */
    function osc_get_non_empty_categories() {
        $aCategories = Category::newInstance()->toTree(false);
        View::newInstance()->_exportVariableToView('categories', $aCategories );
        return  View::newInstance()->_get('categories') ;
    }
    
    /**
     * Prints category select
     * 
     * @return void
     */
    function osc_categories_select($name = 'sCategory', $category = null, $default_str = null) {
        if($default_str == null) $default_str = __('Select a category');
        CategoryForm::category_select(Category::newInstance()->toTree(), $category, $default_str, $name) ;
    }

    /**
     * Get th category by id or slug
     * 
     * @since 3.0
     * @param $by two possibilities: slug or id
     * @param $what the id or slug category we're looking for
     * @return array
     */
    function osc_get_category($by, $what) {
        if( !in_array($by, array('slug', 'id')) ) {
            return false;
        }

        switch ($by) {
            case 'slug':
                return Category::newInstance()->findBySlug($what);
            break;
            case 'id':
                return Category::newInstance()->findByPrimaryKey($what);
            break;
        }
    }

?>
Voili, voilou.
Encore merci à tous de l'aide pour m'aider à trouver le mystère du bug... :priere:

Re: Big bug sur mon site

par sirakawa » 25 août 2012, 08:49

Bjr,

A vue de perchoir aux oiseaux, le code intéressant ceux qui t'ont déjà répondu c'est celui qui est appelé par ce formulaire :
<form class="well" name="item" action="<?php echo osc_base_url(true) ; ?>" method="post" enctype="multipart/form-data">
ou si tu préfères, le script qui est lancé quand on clique sur le bouton envoyé.

En dehors de ce point et de mon horreur pour ces codes qui mettent du <?PHP ?> à tous les coins de ligne, que veut dire:
twitter_theme.text_select_subcategory = "<?php _e('Select a subcategory...', 'twitter') ; ?>" ;

Re: Big bug sur mon site

par keish » 24 août 2012, 22:19

Ce n'est qu'une mise en bouche ce code, celui du traitement serai plus intéressant. :)
Et en utilisant la balise bbcode php svp.
Voili, voilou, le code javascript:

[javascript]
var is_loading = true ;

function fill_subcategory_select ( id ) {
var category = $("select.category") ;
var subcategory = $("select.subcategory") ;

// reset subcategory select
subcategory.html("") ;

// check that the category has subcategories
if( typeof twitter_theme.categories["id_" + id] === "undefined" ) {
subcategory.append( $("<option>").attr('value', id) ) ;
subcategory.css("display", "none") ;
$("select.subcategory").trigger('change') ;
return true;
}

subcategory.html()
subcategory.append( $("<option>").attr('value', id).html(twitter_theme.text_select_subcategory) ) ;
$.each(twitter_theme.categories["id_" + id], function(key, value) {
subcategory.append( $("<option>").attr('value', value.id).html(value.name) ) ;
}) ;
subcategory.css("display", "") ;
return true;
}

/* PHOTO */
function add_photo_field() {
var num_img = $('.photos input[name="photos[]"]').size() + $(".photos ul li").length ;
if( twitter_theme.max_number_photos != 0 && num_img < twitter_theme.max_number_photos ) {
var file = $("<input>").attr('type', 'file').attr('name', 'photos[]') ;
var remove_link = $("<a>").attr('href', 'javascript://').addClass('remove').html(twitter_theme.photo_remove_text) ;
remove_link.bind('click', function(event) {
$(this).parent().parent().remove() ;
}) ;
var remove = $("<span>").addClass("help-inline").html(twitter_theme.remove_link) ;
var div = $("<div>").addClass('input-file').append(file).append(remove) ;

$(".more-photos").append(div) ;
} else {
alert(twitter_theme.max_images_fields_txt) ;
}
}

function delete_image(photo_id, item_id, name, secret) {
var result = confirm(twitter_theme.delete_photo_txt);

if(result) {
$.ajax({
type: "POST",
url: twitter_theme.ajax_url,
data: { action: "delete_image", id: photo_id, item: item_id, code: name, secret: secret },
dataType: 'json',
success: function(data) {
if(data.success) {
$("li[name=" + name + "]").fadeOut('slow') ;
$("li[name=" + name + "]").remove() ;
}
}
}) ;
}
}

function ajax_country (input) {
var country_code = $(input).attr('value') ;
if(country_code != "") {
$.ajax({
type: "POST",
url: twitter_theme.ajax_url,
dataType: "json",
data: { action: "regions", countryId: country_code },
success: function(data) {
if( data.length > 0 ) {
$("select.region_id").html($("<option>").attr('value', '').html(twitter_theme.text_select_region)) ;
$.each(data, function(key, value){
$("select.region_id").append( $("<option>").attr('value', value.pk_i_id).html(value.s_name) ) ;
}) ;
$("select.region_id").attr('disabled', false) ;
$("select.city_id").html($("<option>").html(twitter_theme.text_select_city)) ;
} else {
$("select.region_id").html($("<option>").html(twitter_theme.text_no_regions)) ;
$("select.city_id").html($("<option>").html(twitter_theme.text_no_cities)) ;
}
if( is_loading && twitter_theme.region_select_id != "" ) {
$("select.region_id").val(twitter_theme.region_select_id) ;
$("select.region_id").trigger('change') ;
if( $("select.region_id").length == 0 ) {
ajax_region($("input.region_id")) ;
}
}
}
}) ;
} else {
$("select.region_id").attr('disabled', true) ;
$("select.region_id").html($("<option>").html(twitter_theme.text_select_region)) ;
$("select.city_id").attr('disabled', true) ;
$("select.city_id").html($("<option>").html(twitter_theme.text_select_city)) ;
}
}

function ajax_region (input) {
var region_code = $(input).attr('value') ;
if(region_code != "") {
$.ajax({
type: "POST",
url: twitter_theme.ajax_url,
dataType: "json",
data: { action: "cities", regionId: region_code },
success: function(data) {
if( data.length > 0 ) {
$("select.city_id").html($("<option>").html(twitter_theme.text_select_city)) ;
$.each(data, function(key, value){
$("select.city_id").append( $("<option>").attr('value', value.pk_i_id).html(value.s_name) ) ;
}) ;
$("select.city_id").attr('disabled', false) ;
if( is_loading ) {
$("select.city_id").val(twitter_theme.city_select_id) ;
}
} else {
$("select.city_id").html($("<option>").html(twitter_theme.text_no_cities)) ;
}
is_loading = false;
}
}) ;
} else {
$("select.city_id").attr('disabled', true) ;
$("select.city_id").html($("<option>").html(twitter_theme.text_select_city)) ;
}
}

$(document).ready(function() {
$("select.category").bind("change", function(event) {
fill_subcategory_select( $(this).attr("value") ) ;
})

if( twitter_theme.category_selected_id !== "null" ) {
$("select.category").val(twitter_theme.category_selected_id) ;
fill_subcategory_select( twitter_theme.category_selected_id ) ;
}
$("select.subcategory").val(twitter_theme.subcategory_selected_id) ;

/* JS location */
$("select.country_id").val(twitter_theme.country_select_id) ;
/* init selects */
if( $("select.country_id").val() == "" ) {
$("select.region_id").attr('disabled', true);
}

if( $("select.region_id").val() == "" ) {
$("select.city_id").attr('disabled', true);
}

$("select.country_id").bind('change', function(event) {
ajax_country( $(this) ) ;
}) ;

$("select.region_id").bind('change', function(event) {
ajax_region( $(this) ) ;
}) ;

$("select.country_id").trigger('change') ;
if( $("select.country_id").length == 0 ) {
ajax_country($("input.country_id")) ;
}
/* JS location end */

/* Plugins hooks */
$("select.subcategory").bind('change', function(event) {
var cat_id = $(this).val();
if( cat_id != "" ) {
$.ajax({
type: "POST",
url: twitter_theme.ajax_url,
data: { action: "runhook", hook: "item_" + twitter_theme.page, catId: cat_id, itemId: twitter_theme.item_id } ,
dataType: 'html',
success: function(data){
$("#plugin-hook").html(data);
}
});
}
});
/* Plugins hooks end */
$("select.subcategory").trigger('change') ;
}) ;
[/javascript]

Toujours une mise en bouche ;)

Encore merci de l'aide.

Re: Big bug sur mon site

par xTG » 24 août 2012, 06:51

Ce n'est qu'une mise en bouche ce code, celui du traitement serai plus intéressant. :)
Et en utilisant la balise bbcode php svp.

Re: Big bug sur mon site

par keish » 23 août 2012, 23:09

du code plutôt, au pif une requete SQL mal faite ?

on ne peux pas deviner ;)

@+
Hello,

Alors va pour le code catégorie ;) :

<?php $aLocales = osc_get_locales() ; ?>
<!DOCTYPE html>
<html dir="ltr" lang="<?php echo str_replace('_', '-', osc_current_user_locale()) ; ?>">
<head>
<?php osc_current_web_theme_path('head.php') ; ?>
<meta name="robots" content="noindex, nofollow" />
<meta name="googlebot" content="noindex, nofollow" />
<script type="text/javascript">
twitter_theme.text_select_subcategory = "<?php _e('Select a subcategory...', 'twitter') ; ?>" ;
twitter_theme.category_selected_id = "<?php echo item_selected_category_id() ; ?>" ;
twitter_theme.subcategory_selected_id = "<?php echo item_selected_subcategory_id() ; ?>" ;
twitter_theme.max_number_photos = <?php echo osc_max_images_per_item() ; ?> ;
twitter_theme.photo_remove_text = "<?php _e('Remove', 'twitter') ; ?>" ;
twitter_theme.max_images_fields_txt = "<?php _e('Sorry, you have reached the maximum number of images per ad', 'twitter') ; ?>" ;
twitter_theme.country_select_id = "<?php echo get_country_id((osc_item() != null) ? osc_item() : array()) ; ?>" ;
twitter_theme.region_select_id = "<?php echo get_region_id((osc_item() != null) ? osc_item() : array()) ; ?>" ;
twitter_theme.city_select_id = "<?php echo get_city_id((osc_item() != null) ? osc_item() : array()) ; ?>" ;
twitter_theme.ajax_url = "<?php echo osc_base_url(true) . '?page=ajax' ; ?>" ;
twitter_theme.text_select_country = "<?php _e('Select a country...', 'twitter') ; ?>" ;
twitter_theme.text_select_region = "<?php _e('Select a region...', 'twitter') ; ?>" ;
twitter_theme.text_select_city = "<?php _e('Select a city...', 'twitter') ; ?>" ;
twitter_theme.text_no_regions = "<?php _e('No regions available', 'twitter') ; ?>" ;
twitter_theme.text_no_cities = "<?php _e('No cities available', 'twitter') ; ?>" ;
twitter_theme.page = "edit" ;
twitter_theme.item_id = "<?php echo osc_item_id() ; ?>" ;
twitter_theme.delete_photo_txt = "<?php _e('This action cannot be undone. Are you sure you want to continue?', 'twitter') ; ?>";
</script>
<script type="text/javascript" src="<?php echo osc_current_web_theme_js_url('bootstrap-tabs.js') ; ?>"></script>
<script type="text/javascript" src="<?php echo osc_current_web_theme_js_url('item_form.js') ; ?>"></script>
<?php item_category_select_js() ; ?>
</head>
<body>
<?php osc_current_web_theme_path('header.php') ; ?>
<div class="container margin-top-10">
<?php twitter_show_flash_message() ; ?>
</div>
<div class="container item-edit">
<?php echo twitter_breadcrumb('&raquo;') ; ?>
<div class="row">
<div class="span16 columns">
<form class="well" name="item" action="<?php echo osc_base_url(true) ; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="item_edit_post" />
<input type="hidden" name="page" value="item" />
<input type="hidden" name="id" value="<?php echo osc_item_id() ; ?>" />
<input type="hidden" name="secret" value="<?php echo osc_item_secret() ; ?>" />
<fieldset>
<h1><?php _e('Update your item', 'twitter') ; ?></h1>
<!-- category input -->
<div class="clearfix">
<label><?php _e('Category', 'twitter') ; ?></label>
<div class="input">
<?php item_category_select( __('Select a category...', 'twitter') ) ; ?>
</div>
</div>
<!-- category input end -->
<!-- title and description -->
<div class="clearfix">
<?php if( count($aLocales) > 1 ) { ?>
<?php item_title_description_multilanguage_box(__('Title', 'twitter'), __('Description', 'twitter'), $aLocales) ; ?>
<?php } else { ?>
<?php item_title_description_box(__('Title', 'twitter'), __('Description', 'twitter'), $aLocales) ; ?>
<?php } ?>
</div>
<!-- title and description end -->
<?php if( osc_price_enabled_at_items() ) { ?>
<!-- price -->
<div class="clearfix">
<label for="price"><?php _e('Price', 'twitter') ; ?></label>
<div class="input">
<?php item_price_input( ) ; ?>
<?php item_currency_select( ) ; ?>
<span class="help-block">
<?php _e("<strong>Note:</strong> If you are giving away your item, enter a price of 0. If you don't want to publish the price, leave empty the field", 'twitter') ; ?>
</span>
</div>
</div>
<!-- price end -->
<?php } ?>
<?php if( osc_images_enabled_at_items() ) { ?>
<!-- photo -->
<h3><?php _e('Photos', 'twitter') ; ?></h3>
<div class="clearfix photos">
<?php
$resources = osc_get_item_resources();
if( $resources != null && is_array($resources) && count($resources) > 0) { ?>
<ul class="media-grid">
<?php foreach($resources as $r) { ?>
<li id="<?php echo $r['pk_i_id'] ; ?>" fkid="<?php echo $r['fk_i_item_id'] ; ?>" name="<?php echo $r['s_name'] ; ?>">
<a href="javascript://">
<img class="thumbnail quimby_search_image" src="<?php echo osc_base_url() . $r['s_path'] . $r['pk_i_id'] . '_thumbnail.' . $r['s_extension'] ; ?>" />
</a>
<span>
<a class="btn danger" 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', 'twitter') ; ?></a>
</span>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php if(osc_max_images_per_item()==0 || (osc_max_images_per_item()!=0 && osc_count_item_resources()< osc_max_images_per_item())) { ?>
<div class="input input-file">
<input type="file" name="photos[]" />
</div>
<?php } ?>
<div class="more-photos">
</div>
<div class="input">
<a href="javascript://" onClick="return add_photo_field();"><?php _e('Add new photo', 'modern'); ?></a>
</div>
</div>
<!-- photo end -->
<?php } ?>
<!-- location -->
<h3><?php _e('Location', 'twitter') ?></h3>
<?php item_country_box(__("Country", "twitter"), __("Select a country...", "twitter")) ; ?>
<?php item_region_box(__("Region", "twitter"), __("Select a region...", "twitter")) ; ?>
<?php item_city_box(__("City", "twitter"), __("Select a city...", "twitter")) ; ?>
<div class="clearfix">
<label for="cityArea"><?php _e('Neighborhood', 'twitter') ; ?></label>
<div class="input">
<?php item_city_area( ) ; ?>
</div>
</div>
<div class="clearfix">
<label for="address"><?php _e('Address', 'twitter') ; ?></label>
<div class="input">
<?php item_address( ) ; ?>
</div>
</div>
<!-- location end -->
<div class="clearfix">
<div id="plugin-hook"></div>
</div>
<?php if( osc_recaptcha_items_enabled() ) { ?>
<div class="clearfix">
<?php osc_show_recaptcha(); ?>
</div>
<?php } ?>
<div class="actions">
<button class="btn" type="submit"><?php _e('Update', 'twitter') ; ?></button>
<a class="btn" href="javascript:history.back(-1)"><?php _e('Cancel', 'twitter') ; ?></a>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<?php osc_current_web_theme_path('footer.php') ; ?>
</body>
</html>

Je ne sais pas si c'est un problème de requet ou simplement du code :(

Je ne sais pas si tu as besoin de plus d'info?

Encore merci de l'aide.

Re: Big bug sur mon site

par moogli » 23 août 2012, 22:43

du code plutôt, au pif une requete SQL mal faite ?

on ne peux pas deviner ;)

@+

Re: Big bug sur mon site

par keish » 23 août 2012, 21:47

Il faudrait être plus précis si tu veux que l'on puisse te répondre. Quel bug, quand tu fais quoi, dans quelles circonstances ?
Hello,

Merci de ta réponse. Je n'ai pas osé donner de suite toute les précisions pour ne pas faire peur ;)

Je suis en train de mettre en place un site d'annonce multi-langue. Lors de la modification d'une annonce, j'ai un champ catégorie qui ne veut pas se mettre à jour au niveau de la langue donc il reste en anglais. Par contre, le champ sous catégorie lui il fonctionne parfaitement.

Devrais-je te transmettre le lien du site Internet pour que tu puisse tester?

D'avance merci.

Re: Big bug sur mon site

par AB » 22 août 2012, 20:28

Il faudrait être plus précis si tu veux que l'on puisse te répondre. Quel bug, quand tu fais quoi, dans quelles circonstances ?

Big bug sur mon site

par keish » 22 août 2012, 18:46

Salut à tous,
J'ai besoin d'aide pour un bug que j'ai sur mon site.
Quelqu'un serait-il pr^^et à m'aider pour debuger un script sur mon site svp?

D'avance merci.