<?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,
            ),

        );
    }

    function add_a_http($content){
        $reg = '/http(?:s?):\/\/((?:[A-za-z0-9-]+\.)+[A-za-z]{2,4})/';
        preg_match_all($reg, $content, $data);
        $math = $data[1];
        if (is_array($math))
            foreach ($math as $httpval){
                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;
    }
}