Ejemplo n.º 1
0
 /**
  * Add a new action
  *
  * This method is invoked whenever the action adding controller
  * is invokved. It calls $this->generateAction() and creates a
  * new action file if it doesn't exist.
  *
  * @param array $data The data to create the action with.
  *
  * @return boolean true
  */
 public function add(array $data)
 {
     $whitelist = array('name', 'enabled', 'description', 'public', 'param', 'required', 'route', 'use_custom_route');
     $this->whiteList($whitelist, $data);
     // Replace spaces with underscores, to attempt to make it a valid name
     $data['name'] = ucfirst(strtolower(str_replace(' ', '_', $data['name'])));
     // Validate the action doesn't already exist and is valid
     if (in_array($data['name'], $this->getList())) {
         throw new RuntimeException('There is already an action with this name.');
     } else {
         if (!preg_match('/^[A-Z][a-z0-9\\_\\-]+$/', $data['name'])) {
             throw new RuntimeException('Action name does not validate. Please ensure it contains only alpha-numeric characters, underscores and dashes.');
         }
     }
     // Routes can only be lower case!
     $data['route'] = strtolower($data['route']);
     // Validate the route does not already exist and is valid
     $router = new Frapi_Router();
     $router->loadAndPrepareRoutes();
     if ($router->match($data['route'])) {
         throw new RuntimeException('There is already an action with this route.');
     }
     $segments = Frapi_Router::parseSegments($data['route']);
     foreach ($segments as $key => $value) {
         if ($key == 0) {
             if (!preg_match('/^[a-z0-9\\-\\_\\*]+$/', $value)) {
                 throw new RuntimeException('Action route does not validate. Please ensure each part contains only alpha-numeric characters, underscores, dashes and colons.');
             }
         } else {
             if (!preg_match('/^:?[a-z0-9\\-\\_\\*]+$/', $value)) {
                 throw new RuntimeException('Action route does not validate. Please ensure each part contains only alpha-numeric characters, underscores, dashes and colons.');
             }
         }
     }
     $values = array('name' => $data['name'], 'enabled' => $data['enabled'], 'public' => $data['public'], 'description' => $data['description'], 'route' => $data['route']);
     $values['parameters'] = array();
     if (isset($data['param'])) {
         if (isset($data['required']) && is_array($data['required'])) {
             foreach ($data['required'] as $key => $value) {
                 if (isset($data['param'][$key])) {
                     $values['parameters']['parameter'][] = array('name' => $data['param'][$key], 'required' => '1');
                     unset($data['param'][$key]);
                 }
             }
         }
         foreach ($data['param'] as $param => $value) {
             $values['parameters']['parameter'][] = array('name' => $value, 'required' => '0');
         }
     }
     /*
      * If we have no parameters we still need a <parameters> entry in the
      * config file.
      */
     if (!count($values['parameters'])) {
         $values['parameters'] = '';
     }
     $this->config->add('action', $values);
     $this->refreshAPCCache();
     return true;
 }
Ejemplo n.º 2
0
 /** 
  * Add a new users
  *
  * This method is invoked whenever the user adding controller
  * is invoked. 
  *
  * @param array $data The data to create the user with.
  *
  * @return boolean true
  */
 public function add(array $data)
 {
     if (!$this->handleAvailable($data['handle'])) {
         return false;
     }
     $whitelist = array('handle', 'password');
     $this->whitelist($whitelist, $data);
     // I'd like to create a configurable salt here for when
     // people go through the install wizard, a salt gets defined
     // in order to insure more safety for their users passwords.
     $values = array('handle' => $data['handle'], 'password' => sha1($data['password']), 'active' => 1, 'role' => 'admin');
     try {
         $this->config->add('user', $values);
     } catch (Exception $e) {
     }
     return true;
 }
Ejemplo n.º 3
0
 private function upgradeConfig($file)
 {
     file_put_contents($file, '<frapi-config><mimetypes/></frapi-config>');
     $config = new Lupin_Config_Xml('mimetypes');
     $mimetypes = array('application/xml' => 'xml', 'text/xml' => 'xml', 'application/json' => 'json', 'text/json' => 'json', 'text/html' => 'html', 'text/plain' => 'json', 'text/javascript' => 'js', 'text/php-printr' => 'printr');
     foreach ($mimetypes as $mimetype => $format) {
         $data = array('mimetype' => $mimetype, 'output_format' => $format, 'description' => '');
         $config->add('mimetype', $data);
     }
     return $config;
 }