Create a new template record.

You can pass $attrs['constants'] as a hash (constant => value), and it
will be correctly converted to string.

@param  int  $pid
@param  array  $attrs
@return  int|null
353265
public function create($pid, $attrs = [])
    {
        if (isset($attrs['constants'])) {
            $attrs['constants'] = $this->parseTsConstants($attrs['constants']);
        }

        return parent::create($pid, $attrs);
    }
201938
protected function determine_id( $pid ) {
		global $wp_query;
		if ( $pid === null &&
			isset($wp_query->queried_object_id)
			&& $wp_query->queried_object_id
			&& isset($wp_query->queried_object)
			&& is_object($wp_query->queried_object)
			&& get_class($wp_query->queried_object) == 'WP_Post'
		) {
			$pid = $wp_query->queried_object_id;
		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) {
			//hack for static page as home page
			$pid = $wp_query->queried_object_id;
		} else if ( $pid === null ) {
			$gtid = false;
			$maybe_post = get_post();
			if ( isset($maybe_post->ID) ) {
				$gtid = true;
			}
			if ( $gtid ) {
				$pid = get_the_ID();
			}
			if ( !$pid ) {
				global $wp_query;
				if ( isset($wp_query->query['p']) ) {
					$pid = $wp_query->query['p'];
				}
			}
		}
		if ( $pid === null && ($pid_from_loop = PostGetter::loop_to_id()) ) {
			$pid = $pid_from_loop;
		}
		return $pid;
	}
899437
protected function Autogen(array $attrs) {
        $ignore = !empty($attrs['ignore']) ? explode('|', $attrs['ignore']) : array();
        $er = error_reporting(0);
        ob_start();
        $classPath = $this->openClassForWriting();
        $methods = '';
        foreach ($this->_table->getColumns() as $name => $attrsRow) {
            if (in_array(Util::camelTo_($name), $ignore))
                continue;
            echo "\r\n";
            echo "\t/**\r\n";
            echo "\t * @DBS\\" . $this->fetchColumnProperties($attrsRow) . "\r\n";
            echo "\t */\r\n";
            echo "\tprotected $" . Util::_toCamel($name) . ";\r\n";

            $methods .= "\r\n";
            $methods .= "\tpublic function set" . ucfirst(Util::_toCamel($name)) . '($' . Util::_toCamel($name) . ") {\r\n";
            $methods .= "\t\t" . '$this->' . Util::_toCamel($name) . ' = $' . Util::_toCamel($name) . ";\r\n";
            $methods .= "\t\t" . 'return $this;' . "\r\n";
            $methods .= "\t}\r\n";

            $methods .= "\r\n";
            $methods .= "\tpublic function get" . ucfirst(Util::_toCamel($name)) . "() {\r\n";
            $methods .= "\t\t" . 'return $this->' . Util::_toCamel($name) . ";\r\n";
            $methods .= "\t}\r\n";
        }
        echo $methods . "\r\n";
        echo "}\r\n";
        error_reporting($er);
        return file_put_contents($classPath, ob_get_clean());
    }
198001
private function generateOptionsRecursively($pid = 0, $prefix = '')
    {
        $options = [];
        $records = $this->db->fetchAll('SELECT * FROM tl_news_category WHERE pid=? ORDER BY sorting', [$pid]);

        foreach ($records as $record) {
            $options[$record['id']] = $prefix . $record['title'];

            foreach ($this->generateOptionsRecursively($record['id'], $record['title'] . ' / ') as $k => $v) {
                $options[$k] = $v;
            }
        }

        return $options;
    }
546323
private function attrs_to_string($attrs)
    {
        $attrs_string ='';

        foreach($attrs as $name => $node)
        {
            $attrs_string.= sprintf(' %s="%s"',$name,$node->nodeValue);
        }

        return $attrs_string;
    }
425018
protected function createAttachRecords($ids, array $attributes)
	{
		$records = array();

		$timed = ($this->hasPivotColumn($this->createdAt()) ||
			      $this->hasPivotColumn($this->updatedAt()));

		// To create the attachment records, we will simply spin through the IDs given
		// and create a new record to insert for each ID. Each ID may actually be a
		// key in the array, with extra attributes to be placed in other columns.
		foreach ($ids as $key => $value)
		{
			$records[] = $this->attacher($key, $value, $attributes, $timed);
		}

		return $records;
	}
523115
public static function parseAttrsString($attrs,$excludeAttrs = array())
	{
		$result = '';
		if(is_array($attrs))
		{
			if(isset($attrs['disabled']) && 0==$attrs['disabled'])
			{
				unset($attrs['disabled']);
			}
			if(isset($attrs['readonly']) && 0==$attrs['readonly'])
			{
				unset($attrs['readonly']);
			}
			foreach($attrs as $key=>$attr)
			{
				if(false===in_array($key,$excludeAttrs))
				{
					$result .= " {$key}=\"{$attr}\"";
				}
			}
		}
		return $result;
	}
1139924
public static function findPublishedByIds(array $ids, $pid = null)
    {
        if (0 === \count($ids)) {
            return null;
        }

        $t = static::getTableAlias();
        $columns = ["$t.id IN (".\implode(',', \array_map('intval', $ids)).')'];
        $values = [];

        // Filter by pid
        if (null !== $pid) {
            $columns[] = "$t.pid=?";
            $values[] = $pid;
        }

        if (!BE_USER_LOGGED_IN) {
            $columns[] = "$t.published=?";
            $values[] = 1;
        }

        return static::findBy($columns, $values, ['order' => "$t.sorting"]);
    }
1091064
private function readInc($pid)
    {
        $res = shm_attach($pid);
        if (!shm_has_var($res, 0)) {
            shm_put_var($res, 0, 0);
        }

        $inc = shm_get_var($res, 0);
        if ($inc === 16777215) {
            $inc = 0;
        }

        ++$inc;

        shm_put_var($res, 0, $inc);

        return $inc;
    }
1020889
def attr_writer(*methods)
      methods.each do |method|
        define_method("#{method}=") do |value|
          instance_variable_set(:"@#{method}", value)
        end
      end
    end
281948
public static function buildAttrs(array $attributes, array $cssClasses = []): string
    {
        $output = '';
        if ($cssClasses) {
            if (array_key_exists('class', $attributes) && $attributes['class']) {
                $attributes['class'] .= ' ' . implode(' ', $cssClasses);
            } else {
                $attributes['class'] = implode(' ', $cssClasses);
            }
        }
        foreach ($attributes as $key => $value) {
            $output .= ' ' . $key . ($value !== null ? '="' . str_replace('"', '\"', $value) . '"' : '');
        }
        return $output;
    }
636654
static public function update($id, array $attrs)
    {
        if (is_array($id)) {
            foreach ($id as $k => $i) {
                static::update($i, $attrs[$k]);
            }
        } else {
            $object = static::find($id);
            $object->updateAttributes($attrs);
            return $object;
        }
    }
178696
private function _resolveIds($attr, $values=null)
    {
        $cls = get_called_class();

        if (!array_key_exists($cls, self::$_has_many_maps)
            || !array_key_exists($attr, self::$_has_many_maps[$cls])
        ) {
            return null;
        }

        $klass   = self::hasManyClass(self::$_has_many_maps[$cls][$attr]);
        $foreign = self::hasManyForeignKey(Inflections::pluralize(strtolower($klass)));
        $value   = $this->_data[self::getPK()];
        $klasspk = $klass::getPK();

        // if values sent, set them
        if ($values) {
            $this->_has_many_ids = $values;
            $ids = join(",", $values);
            $this->_nullNotPresentIds($klass, $foreign, $ids, $value);
        } else {
            $data = $klass::where(array($foreign => $value));
            $this->_has_many_ids = array();
            while ($row=$data->next()) {
                array_push($this->_has_many_ids, $row->get($klasspk));
            }
        }
        return $this->_has_many_ids;
    }
295876
public function create($objectID, $categoryConst, array $attributes) {
        $params = [
            'objID' => $objectID,
            'data' => $attributes,
            'category' => $categoryConst
        ];

        $result = $this->api->request(
            'cmdb.category.create',
            $params
        );

        if (!array_key_exists('id', $result) ||
            !is_numeric($result['id']) ||
            !array_key_exists('success', $result) ||
            $result['success'] !== true) {
            if (array_key_exists('message', $result)) {
                throw new RuntimeException(sprintf('Bad result: %s', $result['message']));
            } else {
                throw new RuntimeException('Bad result');
            }
        }

        return (int) $result['id'];
    }
403131
public function form_open(array $attrAdd = null)
    {
        $attr = $this->merge_attr($this->form[ 'open' ][ 'attr' ], $attrAdd);

        return '<form'
            . $this->getAttributesInput($attr)
            . $this->getAttributesCSS($attr)
            . ">\r\n";
    }
469658
public function addMeta($pId, array $pAttributes)
	{
		$meta = array();
        foreach ($pAttributes as $attribute => $value) {
	        $meta[] = $attribute . '="' . $value . '"';
	    }

		$this->_meta[$pId] = '<meta ' . implode(' ', $meta) . '>';
		return $this;
	}
1349675
protected function _attr($attributes = [])
    {
        $attribute = '';

        if( is_array($attributes) )
        {
            foreach( $attributes as $key => $values )
            {
                if( is_numeric($key) )
                {
                    $key = $values;
                }

                $attribute .= ' '.$key.':'.$values.';';
            }
        }

        return $attribute;
    }