<?php

if (!defined('ROOT')) exit('Can\'t Access !');

class question extends table {
    public $name='question';
    static $me;
    public static function getInstance() {
        if (!self::$me) {
            $class=new question();
            self::$me=$class;
        }
        return self::$me;
    }

    function getcols($act) {
        return '*';
    }

    function get_form() {
        return array(
            'typeid'=>array(
                'selecttype'=>'select',
                'select'=>form::arraytoselect(questiontype::gettypeoption()),
            ),
            'isadminsee'=>array(
                'selecttype'=>'radio',
                'select'=>form::arraytoselect(array(0=>lang_admin('no'),1=>lang_admin('yes'))),
                'default'=>0,
            ),
            'topping'=>array(
                'selecttype'=>'select',
                'select'=>form::arraytoselect(array(0=>lang_admin('no'),1=>lang_admin('yes'))),
                'default'=>0,
            ),

        );
    }

    function add_a_http($content){
        //$reg = '/http(?:s?):\/\/((?:[A-za-z0-9-]+\.)+[A-za-z]{2,4})/';
        $reg = "/(http(?:s?):[\/]{2})[a-z\d\?]+[.]{1}[a-z\d\-]+[.]{1}[a-z\d\.]*[\/]*[A-Za-z\d\.\?\&\=]*[\/]*[A-Za-z\d\.\?\&\=]*[\/]*[A-Za-z\d]*[\/]*[A-Za-z\d\.\?\&\=]*/";
        preg_match_all($reg, $content, $data);
        $math = $data[0];
        if (is_array($math))
            foreach ($math as $httpval){
                if (strpos($content, $httpval) !== false) {
                    $url=url('question/go/url/'.user::lockString($httpval,'gourl'));
                    $newhttpval='<a style="color: blue;" target="_blank" href="'.$url.'">'.$httpval.'</a>';
                    $content= str_replace($httpval,$newhttpval,$content);
                }

            /*    if(strpos($content,'https://'.$httpval.'/') !== false ){
                    $oldhttp='https://'.$httpval.'/';
                    $url=url('question/go/url/'.user::lockString($oldhttp,'gourl'));
                    $newhttpval='<a style="color: blue;" target="_blank" href="'.$url.'">https://'.$httpval.'/</a>';
                    $content= str_replace($oldhttp,$newhttpval,$content);
                }
                else  if(strpos($content,'https://'.$httpval) !== false ){
                        $oldhttp='https://'.$httpval;
                        $url=url('question/go/url/'.user::lockString($oldhttp,'gourl'));
                        $newhttpval='<a style="color: blue;" target="_blank" href="'.$url.'">https://'.$httpval.'</a>';
                        $content= str_replace($oldhttp,$newhttpval,$content);
                }
                else  if(strpos($content,'http://'.$httpval.'/') !== false ){
                    $oldhttp='http://'.$httpval.'/';
                    $url=url('question/go/url/'.user::lockString($oldhttp,'gourl'));
                    $newhttpval='<a style="color: blue;"  target="_blank" href="'.$url.'">http://'.$httpval.'/</a>';
                    $content= str_replace($oldhttp,$newhttpval,$content);
                }
                else  if(strpos($content,'http://'.$httpval) !== false ){
                    $oldhttp='http://'.$httpval;
                    $url=url('question/go/url/'.user::lockString($oldhttp,'gourl'));
                    $newhttpval='<a style="color: blue;" target="_blank" href="'.$url.'">http://'.$httpval.'</a>';
                    $content= str_replace($oldhttp,$newhttpval,$content);
                }*/
            }
        return $content;
    }
}