Пример #1
0
 function checkAllowedExt($file)
 {
     require LIB_PATH . 'osclass/mimes.php';
     if ($file != '') {
         $aMimesAllowed = array();
         $aExt = explode(',', osc_allowed_extension());
         foreach ($aExt as $ext) {
             if (isset($mimes[$ext])) {
                 $mime = $mimes[$ext];
                 if (is_array($mime)) {
                     foreach ($mime as $aux) {
                         if (!in_array($aux, $aMimesAllowed)) {
                             array_push($aMimesAllowed, $aux);
                         }
                     }
                 } else {
                     if (!in_array($mime, $aMimesAllowed)) {
                         array_push($aMimesAllowed, $mime);
                     }
                 }
             }
         }
         $bool_img = false;
         $fileMime = '';
         if (function_exists('finfo_file') && function_exists('finfo_open')) {
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $fileMime = finfo_file($finfo, $file);
         } else {
             if (function_exists('mime_content_type')) {
                 $fileMime = mime_content_type($file);
             } else {
                 // *WARNING* There's no way check the mime type of the file, you should not blindly trust on your users' input!
                 $ftmp = Params::getFiles('qqfile');
                 $fileMime = @$ftmp['type'];
             }
         }
         if (stripos($fileMime, "image/") !== FALSE) {
             if (function_exists("getimagesize")) {
                 $info = getimagesize($file);
                 if (isset($info['mime'])) {
                     $fileMime = $info['mime'];
                 } else {
                     $fileMime = '';
                 }
             }
         }
         if (in_array($fileMime, $aMimesAllowed)) {
             return true;
         }
     }
     return false;
 }
Пример #2
0
        private function checkAllowedExt($aResources)
        {
            $success = true;
            require LIB_PATH . 'osclass/mimes.php';
            if($aResources != '') {
                // get allowedExt
                $aMimesAllowed = array();
                $aExt = explode(',', osc_allowed_extension() );
                foreach($aExt as $ext){
                    if(isset($mimes[$ext])) {
                        $mime = $mimes[$ext];
                        if( is_array($mime) ){
                            foreach($mime as $aux){
                                if( !in_array($aux, $aMimesAllowed) ) {
                                    array_push($aMimesAllowed, $aux );
                                }
                            }
                        } else {
                            if( !in_array($mime, $aMimesAllowed) ) {
                                array_push($aMimesAllowed, $mime );
                            }
                        }
                    }
                }
                foreach ($aResources['error'] as $key => $error) {
                    $bool_img = false;
                    if ($error == UPLOAD_ERR_OK) {
                        // check mime file
                        $fileMime = $aResources['type'][$key];
                        if(stripos($fileMime, "image/")!==FALSE) {
                            if(function_exists("getimagesize")) {
                                $info = getimagesize($aResources['tmp_name'][$key]);
                                if(isset($info['mime'])) {
                                    $fileMime = $info['mime'];
                                } else {
                                    $fileMime = '';
                                }
                            };
                        };


                        if(in_array($fileMime,$aMimesAllowed)) {
                            $bool_img = true;
                        }
                        if(!$bool_img && $success) {$success = false;}
                    }
                }

                if(!$success){
                    osc_add_flash_error_message( _m("The file you tried to upload does not have a valid extension"));
                }
            }
            return $success;
        }
Пример #3
0
    public static function location_javascript($path = "front")
    {
        ?>
<script type="text/javascript">
    $(document).ready(function(){
        $("#countryId").live("change",function(){
            var pk_c_code = $(this).val();
            <?php 
        if ($path == "admin") {
            ?>
                var url = '<?php 
            echo osc_admin_base_url(true) . "?page=ajax&action=regions&countryId=";
            ?>
' + pk_c_code;
            <?php 
        } else {
            ?>
                var url = '<?php 
            echo osc_base_url(true) . "?page=ajax&action=regions&countryId=";
            ?>
' + pk_c_code;
            <?php 
        }
        ?>
            var result = '';

            if(pk_c_code != '') {

                $("#regionId").attr('disabled',false);
                $("#cityId").attr('disabled',true);

                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: 'json',
                    success: function(data){
                        var length = data.length;
                        
                        if(length > 0) {

                            result += '<option value=""><?php 
        _e("Select a region...");
        ?>
</option>';
                            for(key in data) {
                                result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
                            }

                            $("#region").before('<select name="regionId" id="regionId" ></select>');
                            $("#region").remove();

                            $("#city").before('<select name="cityId" id="cityId" ></select>');
                            $("#city").remove();
                            
                            $("#regionId").val("");

                        } else {

                            $("#regionId").before('<input type="text" name="region" id="region" />');
                            $("#regionId").remove();
                            
                            $("#cityId").before('<input type="text" name="city" id="city" />');
                            $("#cityId").remove();
                            
                        }

                        $("#regionId").html(result);
                        $("#cityId").html('<option selected value=""><?php 
        _e("Select a city...");
        ?>
</option>');
                    }
                 });

             } else {

                 // add empty select
                 $("#region").before('<select name="regionId" id="regionId" ><option value=""><?php 
        _e("Select a region...");
        ?>
</option></select>');
                 $("#region").remove();
                 
                 $("#city").before('<select name="cityId" id="cityId" ><option value=""><?php 
        _e("Select a city...");
        ?>
</option></select>');
                 $("#city").remove();

                 if( $("#regionId").length > 0 ){
                     $("#regionId").html('<option value=""><?php 
        _e("Select a region...");
        ?>
</option>');
                 } else {
                     $("#region").before('<select name="regionId" id="regionId" ><option value=""><?php 
        _e("Select a region...");
        ?>
</option></select>');
                     $("#region").remove();
                 }
                 if( $("#cityId").length > 0 ){
                     $("#cityId").html('<option value=""><?php 
        _e("Select a city...");
        ?>
</option>');
                 } else {
                     $("#city").before('<select name="cityId" id="cityId" ><option value=""><?php 
        _e("Select a city...");
        ?>
</option></select>');
                     $("#city").remove();
                 }
                 $("#regionId").attr('disabled',true);
                 $("#cityId").attr('disabled',true);
             }
        });

        $("#regionId").live("change",function(){
            var pk_c_code = $(this).val();
            <?php 
        if ($path == "admin") {
            ?>
                var url = '<?php 
            echo osc_admin_base_url(true) . "?page=ajax&action=cities&regionId=";
            ?>
' + pk_c_code;
            <?php 
        } else {
            ?>
                var url = '<?php 
            echo osc_base_url(true) . "?page=ajax&action=cities&regionId=";
            ?>
' + pk_c_code;
            <?php 
        }
        ?>

            var result = '';

            if(pk_c_code != '') {
                
                $("#cityId").attr('disabled',false);
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: 'json',
                    success: function(data){
                        var length = data.length;
                        if(length > 0) {
                            result += '<option selected value=""><?php 
        _e("Select a city...");
        ?>
</option>';
                            for(key in data) {
                                result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
                            }

                            $("#city").before('<select name="cityId" id="cityId" ></select>');
                            $("#city").remove();
                        } else {
                            result += '<option value=""><?php 
        _e('No results');
        ?>
</option>';
                            $("#cityId").before('<input type="text" name="city" id="city" />');
                            $("#cityId").remove();
                        }
                        $("#cityId").html(result);
                    }
                 });
             } else {
                $("#cityId").attr('disabled',true);
             }
        });

        if( $("#regionId").attr('value') == "")  {
            $("#cityId").attr('disabled',true);
        }

        if($("#countryId").length != 0) {
            if( $("#countryId").attr('type').match(/select-one/) ) {
                if( $("#countryId").attr('value') == "")  {
                    $("#regionId").attr('disabled',true);
                }
            }
        }

        /**
         * Validate form
         */

        // Validate description without HTML.
        $.validator.addMethod(
            "minstriptags",
            function(value, element) {
                altered_input = strip_tags(value);
                if (altered_input.length < 3) {
                    return false;
                } else {
                    return true;
                }
            },
            "<?php 
        _e("Description: needs to be longer");
        ?>
."
        );

        // Code for form validation
        $("form[name=item]").validate({
            rules: {
                catId: {
                    required: true,
                    digits: true
                },
                <?php 
        if (osc_price_enabled_at_items()) {
            ?>
                price: {
                    maxlength: 15
                },
                currency: "required",
                <?php 
        }
        ?>
                <?php 
        if (osc_images_enabled_at_items()) {
            ?>
                "photos[]": {
                    accept: "<?php 
            echo osc_allowed_extension();
            ?>
"
                },
                <?php 
        }
        ?>
                <?php 
        if ($path == 'front') {
            ?>
                contactName: {
                    minlength: 3,
                    maxlength: 35
                },
                contactEmail: {
                    required: true,
                    email: true
                },
                <?php 
        }
        ?>
                regionId: {
                    required: true,
                    digits: true
                },
                cityId: {
                    required: true,
                    digits: true
                },
                cityArea: {
                    minlength: 3,
                    maxlength: 50
                },
                address: {
                    minlength: 3,
                    maxlength: 100
                }
            },
            messages: {
                catId: "<?php 
        _e('Choose one category');
        ?>
.",
                <?php 
        if (osc_price_enabled_at_items()) {
            ?>
                price: {
                    maxlength: "<?php 
            _e("Price: no more than 50 characters");
            ?>
."
                },
                currency: "<?php 
            _e("Currency: make your selection");
            ?>
.",
                <?php 
        }
        ?>
                <?php 
        if (osc_images_enabled_at_items()) {
            ?>
                "photos[]": {
                    accept: "<?php 
            printf(__("Photo: must be %s"), osc_allowed_extension());
            ?>
."
                },
                <?php 
        }
        ?>
                <?php 
        if ($path == 'front') {
            ?>
                contactName: {
                    minlength: "<?php 
            _e("Name: enter at least 3 characters");
            ?>
.",
                    maxlength: "<?php 
            _e("Name: no more than 35 characters");
            ?>
."
                },
                contactEmail: {
                    required: "<?php 
            _e("Email: this field is required");
            ?>
.",
                    email: "<?php 
            _e("Invalid email address");
            ?>
."
                },
                <?php 
        }
        ?>
                regionId: "<?php 
        _e("Select a region");
        ?>
.",
                cityId: "<?php 
        _e("Select a city");
        ?>
.",
                cityArea: {
                    minlength: "<?php 
        _e("City area: enter at least 3 characters");
        ?>
.",
                    maxlength: "<?php 
        _e("City area: no more than 50 characters");
        ?>
."
                },
                address: {
                    minlength: "<?php 
        _e("Address: enter at least 3 characters");
        ?>
.",
                    maxlength: "<?php 
        _e("Address: no more than 100 characters");
        ?>
."
                }
            },
            errorLabelContainer: "#error_list",
            wrapper: "li",
            invalidHandler: function(form, validator) {
                $('html,body').animate({ scrollTop: $('h1').offset().top }, { duration: 250, easing: 'swing'});
            }
        });
    });

    /**
     * Strip HTML tags to count number of visible characters.
     */
    function strip_tags(html) {
        if (arguments.length < 3) {
            html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
        } else {
            var allowed = arguments[1];
            var specified = eval("["+arguments[2]+"]");
            if (allowed){
                var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
                html=html.replace(new RegExp(regex, 'gi'), '');
            } else{
                var regex='</?(' + specified.join('|') + ')\b[^>]*>';
                html=html.replace(new RegExp(regex, 'gi'), '');
            }
        }
        return html;
    }
    
    function delete_image(id, item_id,name, secret) {
        //alert(id + " - "+ item_id + " - "+name+" - "+secret);
        var result = confirm('<?php 
        echo osc_esc_js(__("This action can't be undone. Are you sure you want to continue?"));
        ?>
');
        if(result) {
            $.ajax({
                type: "POST",
                url: '<?php 
        echo osc_base_url(true);
        ?>
?page=ajax&action=delete_image&id='+id+'&item='+item_id+'&code='+name+'&secret='+secret,
                dataType: 'json',
                success: function(data){
                    var class_type = "error";
                    if(data.success) {
                        $("div[name="+name+"]").remove();
                        class_type = "ok";
                    }
                    var flash = $("#flash_js");
                    var message = $('<div>').addClass('pubMessages').addClass(class_type).attr('id', 'FlashMessage').html(data.msg);
                    flash.html(message);
                    $("#FlashMessage").slideDown('slow').delay(3000).slideUp('slow');
                }
            });
        }
    }
    
    
</script>
<?php 
    }
Пример #4
0
_e('Maximum size, in KB');
?>
</label><br />
                                    <input type="text" name="maxSizeKb" id="maxSize" value="<?php 
echo osc_max_size_kb();
?>
" />
                                </p>

                                <p>
                                    <label for="allowedExt"><?php 
_e('Allowed format extensions (eg: png, jpg, gif)');
?>
</label><br />
                                    <input type="text" name="allowedExt" id="allowedExt" value="<?php 
echo osc_allowed_extension();
?>
" />
                                </p>
                                <?php 
if (extension_loaded('imagick')) {
    ?>
                                <p>
                                    <input id="use_imagick" type="checkbox" name="use_imagick" value="1" <?php 
    echo osc_use_imagick() ? 'checked' : '';
    ?>
/><label for="use_imagick"><?php 
    _e('Use imagick instead of GD');
    ?>
</label>
                                    <br />
Пример #5
0
    public static function ajax_photos($resources = null)
    {
        if ($resources == null) {
            $resources = osc_get_item_resources();
        }
        $aImages = array();
        if (Session::newInstance()->_getForm('photos') != '') {
            $aImages = Session::newInstance()->_getForm('photos');
            $aImages = $aImages['name'];
            Session::newInstance()->_drop('photos');
            Session::newInstance()->_dropKeepForm('photos');
        }
        ?>
            <div id="restricted-fine-uploader"></div>
            <div style="clear:both;"></div>
            <?php 
        if (count($aImages) > 0 || $resources != null && is_array($resources) && count($resources) > 0) {
            ?>
                <h3><?php 
            _e('Images already uploaded');
            ?>
</h3>
                <ul class="qq-upload-list">
                    <?php 
            foreach ($resources as $_r) {
                $img = $_r['pk_i_id'] . '.' . $_r['s_extension'];
                ?>
                        <li class=" qq-upload-success">
                            <span class="qq-upload-file"><?php 
                echo $img;
                ?>
</span>
                            <a class="qq-upload-delete" href="#" photoid="<?php 
                echo $_r['pk_i_id'];
                ?>
" itemid="<?php 
                echo $_r['fk_i_item_id'];
                ?>
" photoname="<?php 
                echo $_r['s_name'];
                ?>
" photosecret="<?php 
                echo Params::getParam('secret');
                ?>
" style="display: inline; cursor:pointer;"><?php 
                _e('Delete');
                ?>
</a>
                            <div class="ajax_preview_img"><img src="<?php 
                echo osc_apply_filter('resource_path', osc_base_url() . $_r['s_path']) . $_r['pk_i_id'] . '_thumbnail.' . $_r['s_extension'];
                ?>
" alt="<?php 
                echo osc_esc_html($img);
                ?>
"></div>
                        </li>
                    <?php 
            }
            ?>
                    <?php 
            foreach ($aImages as $img) {
                ?>
                        <li class=" qq-upload-success">
                            <span class="qq-upload-file"><?php 
                echo $img;
                $img = osc_esc_html($img);
                ?>
</span>
                            <a class="qq-upload-delete" href="#" ajaxfile="<?php 
                echo $img;
                ?>
" style="display: inline; cursor:pointer;"><?php 
                _e('Delete');
                ?>
</a>
                            <div class="ajax_preview_img"><img src="<?php 
                echo osc_base_url();
                ?>
oc-content/uploads/temp/<?php 
                echo $img;
                ?>
" alt="<?php 
                echo $img;
                ?>
"></div>
                            <input type="hidden" name="ajax_photos[]" value="<?php 
                echo $img;
                ?>
">
                        </li>
                    <?php 
            }
            ?>
                </ul>
            <?php 
        }
        ?>
            <div style="clear:both;"></div>
            <?php 
        $aExt = explode(',', osc_allowed_extension());
        foreach ($aExt as $key => $value) {
            $aExt[$key] = "'" . $value . "'";
        }
        $allowedExtensions = join(',', $aExt);
        $maxSize = (int) osc_max_size_kb() * 1024;
        $maxImages = (int) osc_max_images_per_item();
        ?>

            <script>
                $(document).ready(function() {

                    $('.qq-upload-delete').on('click', function(evt) {
                        evt.preventDefault();
                        var parent = $(this).parent()
                        var result = confirm('<?php 
        echo osc_esc_js(__("This action can't be undone. Are you sure you want to continue?"));
        ?>
');
                        var urlrequest = '';
                        if($(this).attr('ajaxfile')!=undefined) {
                            urlrequest = 'ajax_photo='+$(this).attr('ajaxfile');
                        } else {
                            urlrequest = 'id='+$(this).attr('photoid')+'&item='+$(this).attr('itemid')+'&code='+$(this).attr('photoname')+'&secret='+$(this).attr('photosecret');
                        }
                        if(result) {
                            $.ajax({
                                type: "POST",
                                url: '<?php 
        echo osc_base_url(true);
        ?>
?page=ajax&action=delete_image&'+urlrequest,
                                dataType: 'json',
                                success: function(data){
                                    parent.remove();
                                }
                            });
                        }
                    });

                    $('#restricted-fine-uploader').on('click','.primary_image', function(event){
                        if(parseInt($("div.primary_image").index(this))>0){

                            var a_src   = $(this).parent().find('.ajax_preview_img img').attr('src');
                            var a_title = $(this).parent().find('.ajax_preview_img img').attr('alt');
                            var a_input = $(this).parent().find('input').attr('value');
                            // info
                            var a1 = $(this).parent().find('span.qq-upload-file').text();
                            var a2 = $(this).parent().find('span.qq-upload-size').text();

                            var li_first =  $('ul.qq-upload-list li').get(0);

                            var b_src   = $(li_first).find('.ajax_preview_img img').attr('src');
                            var b_title = $(li_first).find('.ajax_preview_img img').attr('alt');
                            var b_input = $(li_first).find('input').attr('value');
                            var b1      = $(li_first).find('span.qq-upload-file').text();
                            var b2      = $(li_first).find('span.qq-upload-size').text();

                            $(li_first).find('.ajax_preview_img img').attr('src', a_src);
                            $(li_first).find('.ajax_preview_img img').attr('alt', a_title);
                            $(li_first).find('input').attr('value', a_input);
                            $(li_first).find('span.qq-upload-file').text(a1);
                            $(li_first).find('span.qq-upload-size').text(a2);

                            $(this).parent().find('.ajax_preview_img img').attr('src', b_src);
                            $(this).parent().find('.ajax_preview_img img').attr('alt', b_title);
                            $(this).parent().find('input').attr('value', b_input);
                            $(this).parent().find('span.qq-upload-file').text(b1);
                            $(this).parent().find('span.qq-upload-file').text(b2);
                        }
                    });

                    $('#restricted-fine-uploader').on('click','.primary_image', function(event){
                        $(this).addClass('over primary');
                    });

                    $('#restricted-fine-uploader').on('mouseenter mouseleave','.primary_image', function(event){
                        if(event.type=='mouseenter') {
                            if(!$(this).hasClass('primary')) {
                                $(this).addClass('primary');
                            }
                        } else {
                            if(parseInt($("div.primary_image").index(this))>0){
                                $(this).removeClass('primary');
                            }
                        }
                    });


                    $('#restricted-fine-uploader').on('mouseenter mouseleave','li.qq-upload-success', function(event){
                        if(parseInt($("li.qq-upload-success").index(this))>0){

                            if(event.type=='mouseenter') {
                                $(this).find('div.primary_image').addClass('over');
                            } else {
                                $(this).find('div.primary_image').removeClass('over');
                            }
                        }
                    });

                    window.removed_images = 0;
                    $('#restricted-fine-uploader').on('click', 'a.qq-upload-delete', function(event) {
                        window.removed_images = window.removed_images+1;
                        $('#restricted-fine-uploader .flashmessage-error').remove();
                    });

                    $('#restricted-fine-uploader').fineUploader({
                        request: {
                            endpoint: '<?php 
        echo osc_base_url(true) . "?page=ajax&action=ajax_upload";
        ?>
'
                        },
                        multiple: true,
                        validation: {
                            allowedExtensions: [<?php 
        echo $allowedExtensions;
        ?>
],
                            sizeLimit: <?php 
        echo $maxSize;
        ?>
,
                            itemLimit: <?php 
        echo $maxImages;
        ?>
                        },
                        messages: {
                            tooManyItemsError: '<?php 
        echo osc_esc_js(__('Too many items ({netItems}) would be uploaded. Item limit is {itemLimit}.'));
        ?>
',
                            onLeave: '<?php 
        echo osc_esc_js(__('The files are being uploaded, if you leave now the upload will be cancelled.'));
        ?>
',
                            typeError: '<?php 
        echo osc_esc_js(__('{file} has an invalid extension. Valid extension(s): {extensions}.'));
        ?>
',
                            sizeError: '<?php 
        echo osc_esc_js(__('{file} is too large, maximum file size is {sizeLimit}.'));
        ?>
',
                            emptyError: '<?php 
        echo osc_esc_js(__('{file} is empty, please select files again without it.'));
        ?>
'
                        },
                        deleteFile: {
                            enabled: true,
                            method: "POST",
                            forceConfirm: false,
                            endpoint: '<?php 
        echo osc_base_url(true) . "?page=ajax&action=delete_ajax_upload";
        ?>
'
                        },
                        retry: {
                            showAutoRetryNote : true,
                            showButton: true
                        },
                        text: {
                            uploadButton: '<?php 
        echo osc_esc_js(__('Click or Drop for upload images'));
        ?>
',
                            waitingForResponse: '<?php 
        echo osc_esc_js(__('Processing...'));
        ?>
',
                            retryButton: '<?php 
        echo osc_esc_js(__('Retry'));
        ?>
',
                            cancelButton: '<?php 
        echo osc_esc_js(__('Cancel'));
        ?>
',
                            failUpload: '<?php 
        echo osc_esc_js(__('Upload failed'));
        ?>
',
                            deleteButton: '<?php 
        echo osc_esc_js(__('Delete'));
        ?>
',
                            deletingStatusText: '<?php 
        echo osc_esc_js(__('Deleting...'));
        ?>
',
                            formatProgress: '<?php 
        echo osc_esc_js(__('{percent}% of {total_size}'));
        ?>
'
                        }
                    }).on('error', function (event, id, name, errorReason, xhrOrXdr) {
                            $('#restricted-fine-uploader .flashmessage-error').remove();
                            $('#restricted-fine-uploader').append('<div class="flashmessage flashmessage-error">' + errorReason + '<a class="close" onclick="javascript:$(\'.flashmessage-error\').remove();" >X</a></div>');
                    }).on('statusChange', function(event, id, old_status, new_status) {
                        $(".alert.alert-error").remove();
                    }).on('complete', function(event, id, fileName, responseJSON) {
                        if (responseJSON.success) {
                            var new_id = id - removed_images;
                            var li = $('.qq-upload-list li')[new_id];
                            <?php 
        if (Params::getParam('action') == 'item_add') {
            ?>
                            if(parseInt(new_id)==0) {
                                $(li).append('<div class="primary_image primary"></div>');
                            } else {
                                $(li).append('<div class="primary_image"><a title="<?php 
            echo osc_esc_js(osc_esc_html(__('Make primary image')));
            ?>
"></a></div>');
                            }
                            <?php 
        }
        // @TOFIX @FIXME escape $responseJSON_uploadName below
        // need a js function similar to osc_esc_js(osc_esc_html())
        ?>
                            $(li).append('<div class="ajax_preview_img"><img src="<?php 
        echo osc_base_url();
        ?>
oc-content/uploads/temp/'+responseJSON.uploadName+'" alt="' + responseJSON.uploadName + '"></div>');
                            $(li).append('<input type="hidden" name="ajax_photos[]" value="'+responseJSON.uploadName+'"></input>');
                        }
                        <?php 
        if (Params::getParam('action') == 'item_edit') {
            ?>
                    }).on('validateBatch', function(event, fileOrBlobDataArray) {
                        // clear alert messages
                        if($('#restricted-fine-uploader .alert-error').size()>0) {
                            $('#restricted-fine-uploader .alert-error').remove();
                        }

                        var len = fileOrBlobDataArray.length;
                        var result = canContinue(len);
                        return result.success;

                    });

                    function canContinue(numUpload) {
                        // strUrl is whatever URL you need to call
                        var strUrl      = "<?php 
            echo osc_base_url(true) . "?page=ajax&action=ajax_validate&id=" . osc_item_id() . "&secret=" . osc_item_secret();
            ?>
";
                        var strReturn   = {};

                        jQuery.ajax({
                            url: strUrl,
                            success: function(html) {
                                strReturn = html;
                            },
                            async:false
                        });
                        var json  = JSON.parse(strReturn);
                        var total = parseInt(json.count) + $("#restricted-fine-uploader input[name='ajax_photos[]']").size() + (numUpload);
                        <?php 
            if ($maxImages > 0) {
                ?>
                            if(total<=<?php 
                echo $maxImages;
                ?>
) {
                                json.success = true;
                            } else {
                                json.success = false;
                                $('#restricted-fine-uploader .qq-uploader').after($('<div class="alert alert-error"><?php 
                echo osc_esc_js(sprintf(__('Too many items were uploaded. Item limit is %d.'), $maxImages));
                ?>
</div>'));
                            }
                        <?php 
            } else {
                ?>
                            json.success = true;
                        <?php 
            }
            ?>
                        return json;
                    }

                    <?php 
        } else {
            ?>
                });
                <?php 
        }
        ?>
                });

            </script>
        <?php 
    }
Пример #6
0
    public static function location_javascript($path = "front")
    {
        ?>
<script type="text/javascript">
    $(document).ready(function(){
        $("#countryId").change(function(){
            var pk_c_code = $(this).val();
            <?php 
        if ($path == "admin") {
            ?>
                var url = '<?php 
            echo osc_admin_base_url(true) . "?page=ajax&action=regions&countryId=";
            ?>
' + pk_c_code;
            <?php 
        } else {
            ?>
                var url = '<?php 
            echo osc_base_url(true) . "?page=ajax&action=regions&countryId=";
            ?>
' + pk_c_code;
            <?php 
        }
        ?>
            var result = '';

            if(pk_c_code != '') {
                $("#regionId").attr('disabled',false);
                $("#cityId").attr('disabled',true);
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: 'json',
                    success: function(data){
                        var length = data.length;
                        if(length > 0) {
                            result += '<option value=""><?php 
        _e("Select a region...");
        ?>
</option>';
                            for(key in data) {
                                result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
                            }
                            $("#region").before('<select name="regionId" id="regionId" ></select>');
                            $("#region").remove();
                        } else {
                            result += '<option value=""><?php 
        _e('No results');
        ?>
</option>';
                            $("#regionId").before('<input type="text" name="region" id="region" />');
                            $("#regionId").remove();
                        }
                        $("#regionId").html(result);
                    }
                 });
             } else {
                $("#regionId").attr('disabled',true);
                $("#cityId").attr('disabled',true);
             }
        });


        $("#regionId").change(function(){
            var pk_c_code = $(this).val();
            <?php 
        if ($path == "admin") {
            ?>
                var url = '<?php 
            echo osc_admin_base_url(true) . "?page=ajax&action=cities&regionId=";
            ?>
' + pk_c_code;
            <?php 
        } else {
            ?>
                var url = '<?php 
            echo osc_base_url(true) . "?page=ajax&action=cities&regionId=";
            ?>
' + pk_c_code;
            <?php 
        }
        ?>

            var result = '';

            if(pk_c_code != '') {
                $("#cityId").attr('disabled',false);
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: 'json',
                    success: function(data){
                        var length = data.length;
                        if(length > 0) {
                            result += '<option value=""><?php 
        _e("Select a city...");
        ?>
</option>';
                            for(key in data) {
                                result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
                            }
                            $("#city").before('<select name="cityId" id="cityId" ></select>');
                            $("#city").remove();
                        } else {
                            result += '<option value=""><?php 
        _e('No results');
        ?>
</option>';
                            $("#cityId").before('<input type="text" name="city" id="city" />');
                            $("#cityId").remove();
                        }
                        $("#cityId").html(result);
                    }
                 });
             } else {
                $("#cityId").attr('disabled',true);
             }
        });


        if( $("#regionId").attr('value') == "")  {
            $("#cityId").attr('disabled',true);
        }
        
        if( $("#countryId").attr('type').match(/select-one/) ) {
            if( $("#countryId").attr('value') == "")  {
                $("#regionId").attr('disabled',true);
            }
        }
    
        /**
         * Validate form
         */
         
        // Validate description without HTML.
        $.validator.addMethod(
            "minstriptags", 
            function(value, element) { 
                altered_input = strip_tags(value);
                if (altered_input.length < 10) {
                    return false;
                } else {
                    return true;
                }
            }, 
            "<?php 
        _e("Description: needs to be longer");
        ?>
."
        );
        
        // Validate fields in each locale.
        $("form[name=item] button").click(function() {
            lang_count = $(".title input").length;
            // Title
            $(".title input").each(function(){
                lang_name   = $(this).parent().prev('h2').text().replace(/^(.+) \((.+)\)$/, '$1');
                lang_locale = $(this).attr('name').replace(/^title\[(.+)\]$/,'$1');

                str = ((lang_count > 1) ? lang_name + ' ' : '');
                $(this).rules("add", {
                    required: true,
                    minlength: 9,
                    maxlength: 80,
                    messages: {
                        required: str + "<?php 
        _e("Title: this field is required");
        ?>
.",
                        minlength: str + "<?php 
        _e("Title: enter at least 9 characters");
        ?>
.",
                        maxlength: str + "<?php 
        _e("Title: no more than 80 characters");
        ?>
."
                    }
                });                   
            });
            // Description
            $(".description textarea").each(function(){
                lang_name   = $(this).parent().prev('h2').text().replace(/^(.+) \((.+)\)$/, '$1');
                lang_locale = $(this).attr('name').replace(/^title\[(.+)\]$/,'$1');

                str = ((lang_count > 1) ? lang_name + ' ' : '');
                $(this).rules("add", {
                    required: true,
                    minlength: 10,
                    maxlength: 5000,
                    'minstriptags': true,
                    messages: {
                        required: str + "<?php 
        _e("Description: this field is required");
        ?>
.",
                        minlength: str + "<?php 
        _e("Description: needs to be longer");
        ?>
.",
                        maxlength: str + "<?php 
        _e("Description: no more than 5000 characters");
        ?>
."
                    }
                });                   
            });
        });
        
        // Code for form validation
        $("form[name=item]").validate({
            rules: {
                catId: {
                    required: true,
                    digits: true
                },
                <?php 
        if (osc_price_enabled_at_items()) {
            ?>
                price: {
                    number: true,
                    maxlength: 15
                },
                currency: "required",
                <?php 
        }
        ?>
                <?php 
        if (osc_images_enabled_at_items()) {
            ?>
                "photos[]": {
                    accept: "<?php 
            echo osc_allowed_extension();
            ?>
"
                },
                <?php 
        }
        ?>
                <?php 
        if ($path == 'front') {
            ?>
                contactName: {
                    minlength: 3,
                    maxlength: 35
                },
                contactEmail: {
                    required: true,
                    email: true
                },
                <?php 
        }
        ?>
                regionId: {
                    required: true,
                    digits: true
                },
                cityId: {
                    required: true,
                    digits: true
                },
                cityArea: {
                    minlength: 3,
                    maxlength: 35
                },
                address: {
                    minlength: 5,
                    maxlength: 50
                }
            },
            messages: {
                catId: "<?php 
        _e('Choose one category');
        ?>
.",
                <?php 
        if (osc_price_enabled_at_items()) {
            ?>
                price: {
                    number: "<?php 
            _e('Price: enter a valid number');
            ?>
.",
                    maxlength: "<?php 
            _e("Price: no more than 15 characters");
            ?>
."
                },
                currency: "<?php 
            _e("Currency: make your selection");
            ?>
.",
                <?php 
        }
        ?>
                <?php 
        if (osc_images_enabled_at_items()) {
            ?>
                "photos[]": {
                    accept: "<?php 
            printf(__("Photo: must be %s"), osc_allowed_extension());
            ?>
."
                },
                <?php 
        }
        ?>
                <?php 
        if ($path == 'front') {
            ?>
                contactName: {
                    minlength: "<?php 
            _e("Name: enter at least 3 characters");
            ?>
.",
                    maxlength: "<?php 
            _e("Name: no more than 35 characters");
            ?>
."
                },
                contactEmail: {
                    required: "<?php 
            _e("Email: this field is required");
            ?>
.",
                    email: "<?php 
            _e("Invalid email address");
            ?>
."
                },
                <?php 
        }
        ?>
                regionId: "<?php 
        _e("Select a region");
        ?>
.",
                cityId: "<?php 
        _e("Select a city");
        ?>
.",
                cityArea: {
                    minlength: "<?php 
        _e("City area: enter at least 3 characters");
        ?>
.",
                    maxlength: "<?php 
        _e("City area: no more than 35 characters");
        ?>
."
                },
                address: {
                    minlength: "<?php 
        _e("Address: enter at least 5 characters");
        ?>
.",
                    maxlength: "<?php 
        _e("Address: no more than 50 characters");
        ?>
."
                }
            },
            errorLabelContainer: "#error_list",
            wrapper: "li",
            invalidHandler: function(form, validator) {
                $('html,body').animate({ scrollTop: $('h1').offset().top }, { duration: 250, easing: 'swing'});
            }
        });
    });

    /**
     * Strip HTML tags to count number of visible characters.
     */
    function strip_tags(html) {
        if (arguments.length < 3) {
            html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
        } else {
            var allowed = arguments[1];
            var specified = eval("["+arguments[2]+"]");
            if (allowed){
                var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
                html=html.replace(new RegExp(regex, 'gi'), '');
            } else{
                var regex='</?(' + specified.join('|') + ')\b[^>]*>';
                html=html.replace(new RegExp(regex, 'gi'), '');
            }
        }
        return html;
    }
</script>
<?php 
    }
Пример #7
0
                        <div class="flashmessage flashmessage-warning flashmessage-inline">
                            <p><?php 
printf(__('Maximum size PHP configuration allows: %d KB'), $maxPHPsize);
?>
</p>
                        </div>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-label"><?php 
_e('Allowed formats');
?>
</div>
                    <div class="form-controls">
                        <input type="text" class="input-medium" name="allowedExt" value="<?php 
echo osc_esc_html(osc_allowed_extension());
?>
" />
                        <span class="help-box"><?php 
_e('For example: jpg, png, gif');
?>
</span>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-label"><?php 
_e('ImageMagick');
?>
</div>
                    <div class="form-controls">
                        <div class="form-label-checkbox">
Пример #8
0
 private function checkAllowedExt($aResources)
 {
     $success = true;
     require LIB_PATH . 'osclass/classes/mimes.php';
     if ($aResources != '') {
         // get allowedExt
         $aMimesAllowed = array();
         $aExt = explode(',', osc_allowed_extension());
         foreach ($aExt as $ext) {
             $mime = $mimes[$ext];
             if (is_array($mime)) {
                 foreach ($mime as $aux) {
                     if (!in_array($aux, $aMimesAllowed)) {
                         array_push($aMimesAllowed, $aux);
                     }
                 }
             } else {
                 if (!in_array($mime, $aMimesAllowed)) {
                     array_push($aMimesAllowed, $mime);
                 }
             }
         }
         foreach ($aResources['error'] as $key => $error) {
             $bool_img = false;
             if ($error == UPLOAD_ERR_OK) {
                 // check mime file
                 $fileMime = $aResources['type'][$key];
                 if (in_array($fileMime, $aMimesAllowed)) {
                     $bool_img = true;
                 }
                 if (!$bool_img && $success) {
                     $success = false;
                 }
             }
         }
         if (!$success) {
             osc_add_flash_message(_m("The file you tried to upload does not have an allowed extension"));
         }
     }
     return $success;
 }