Example #1
0
 public function __construct(Silex\Application $app)
 {
     $this->app = $app;
     $currentuser = $this->app['users']->getCurrentUser();
     $stack_items = false;
     if (isset($_SESSION['stack'])) {
         $stack_items = smart_unserialize($_SESSION['stack']);
     }
     if (!is_array($stack_items)) {
         $stack_items = smart_unserialize($currentuser['stack']);
     }
     if (!is_array($stack_items)) {
         $stack_items = array();
     }
     // intersect the allowed types with the types set
     $this->imagetypes = array_intersect($this->imagetypes, $app['config']->get('general/accept_file_types'));
     $this->documenttypes = array_intersect($this->documenttypes, $app['config']->get('general/accept_file_types'));
     $this->items = $stack_items;
 }
Example #2
0
 public function setValue($key, $value)
 {
     // Check if the value need to be unserialized..
     if (is_string($value) && substr($value, 0, 2) == "a:") {
         $unserdata = @smart_unserialize($value);
         if ($unserdata !== false) {
             $value = $unserdata;
         }
     }
     if ($key == 'id') {
         $this->id = $value;
     }
     // Set the user in the object.
     if ($key === 'ownerid' && !empty($value)) {
         $this->user = $this->app['users']->getUser($value);
     }
     // Only set values if they have are actually a field.
     $allowedcolumns = self::getBaseColumns();
     $allowedcolumns[] = 'taxonomy';
     if (!isset($this->contenttype['fields'][$key]) && !in_array($key, $allowedcolumns)) {
         return;
     }
     if ($key == 'datecreated' || $key == 'datechanged' || $key == 'datepublish' || $key == 'datedepublish') {
         if (!preg_match("/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $value)) {
             // @todo Try better date-parsing, instead of just setting it to 'now'..
             $value = date("Y-m-d H:i:s");
         }
     }
     if (!isset($this->values['datechanged']) || !preg_match("/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $this->values['datechanged'])) {
         $this->values['datechanged'] = date("Y-m-d H:i:s");
     }
     $this->values[$key] = $value;
 }