Example #1
0
 public function setImage($value)
 {
     if (is_object($value) && $value->getClassName() == 'Image') {
         $id = $value->getId();
         parent::setImage(Multilingual::set(parent::getImage(), $id));
     }
 }
Example #2
0
 public static function config()
 {
     if (null === self::$available_languages || null === self::$default_language) {
         self::$default_language = Router::$language;
         self::$available_languages = array_map(trim, explode(',', Config::get('AVAILABLE_LANGUAGES')));
     }
 }
Example #3
0
 public static function create($urlname)
 {
     global $ratatoeskr_settings;
     global $db_con;
     if (!self::test_urlname($urlname)) {
         throw new InvalidDataError("invalid_urlname");
     }
     try {
         self::by_urlname($urlname);
     } catch (DoesNotExistError $e) {
         $obj = new self();
         $obj->urlname = $urlname;
         $obj->title = Multilingual::create();
         $obj->text = Multilingual::create();
         $obj->excerpt = Multilingual::create();
         $obj->meta = "";
         $obj->custom = array();
         $obj->article_image = NULL;
         $obj->status = ARTICLE_STATUS_HIDDEN;
         $obj->section_id = $ratatoeskr_settings["default_section"];
         $obj->timestamp = time();
         $obj->allow_comments = $ratatoeskr_settings["allow_comments_default"];
         qdb("INSERT INTO `PREFIX_articles` (`urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments`) VALUES ('', ?, ?, ?, '', ?, 0, ?, ?, ?, ?)", $obj->title->get_id(), $obj->text->get_id(), $obj->excerpt->get_id(), base64_encode(serialize($obj->custom)), $obj->status, $obj->section_id, $obj->timestamp, $obj->allow_comments ? 1 : 0);
         $obj->id = $db_con->lastInsertId();
         return $obj;
     }
     throw new AlreadyExistsError();
 }
Example #4
0
    if ($result !== $output) {
        echo "Returned serial does not match\n";
        $pass = false;
    }
    return $pass;
};
$tests['Type check'] = function () {
    $pass = true;
    $c = new stdClass();
    $c->my = 'MY';
    $c->std = 'STD';
    $c->class = 'CLASS';
    $battery = array(null, true, false, -1, 0, 1, -1.0, 0.0, 1.0, "text string", array("this", "is", "an", "array"), $c);
    foreach ($battery as $input) {
        $raw = Multilingual::set('', $input);
        $output = Multilingual::get($raw);
        $type_ok = gettype($input) === gettype($output);
        if ($type_ok) {
            echo gettype($input) . "\tOK\n";
        } else {
            echo gettype($input) . "\tERR\n";
        }
        if (!$type_ok) {
            echo "^^^^ Type does not match \n";
            $pass = false;
        }
    }
    return $pass;
};
$tests['Performance json_encode vs serialize'] = function () {
    // Small arrays