public function prepare()
  {
    $params = array();
    $params['id'] = $this->get('node_id');
    $params['action'] = 'order';
    $params['rn'] = time();
    $params['popup'] = 1;

    $this->set('order_up_alt', Strings :: get('order_up'));
    $this->set('order_down_alt', Strings :: get('order_down'));

    if (!$this->get('is_first_child'))
    {
      $params['direction'] = 'up';
      $this->set('order_up_href', addUrlQueryItems($_SERVER['PHP_SELF'], $params));
    }
    else
      $this->set('order_up_href', '');

    if (!$this->get('is_last_child'))
    {
      $params['direction'] = 'down';
      $this->set('order_down_href', addUrlQueryItems($_SERVER['PHP_SELF'], $params));
    }
    else
      $this->set('order_down_href', '');

    return parent :: prepare();
  }
  public function validate($dataspace)
  {
    if(!$value = $dataspace->get($this->field_name))
      return;

    $tree = Limb :: toolkit()->getTree();

    if(!$tree->isNode($this->parent_node_id))
      return;

    if(!$nodes = $tree->getChildren($this->parent_node_id))
      return;

    foreach($nodes as $id => $node)
    {
      if($node['identifier'] != $value)
        continue;

      if($this->node_id == self :: UNKNOWN_NODE_ID)
      {
        $this->error(Strings :: get('error_duplicate_tree_identifier', 'error'));
        break;
      }
      elseif($id != $this->node_id)
      {
        $this->error(Strings :: get('error_duplicate_tree_identifier', 'error'));
        break;
      }
    }
  }
  protected function check($value)
  {
    $value = "$value";

    if(!preg_match("~^[a-zA-Z]\d[a-zA-Z]\s\d[a-zA-Z]\d$~", $value))
      $this->error(Strings :: get('error_invalid_zip_format', 'error'));
  }
  public function validate($dataspace)
  {
    $value = $dataspace->get($this->field_name);

    if(!Limb :: toolkit()->getTree()->getNodeByPath($value))
      $this->error(Strings :: get('error_invalid_tree_path', 'error'));
  }
  function testGetActions()
  {
    $j = new ActionsComponent();

    $actions = array(
      'display' => array(),
      'edit' => array(
          'JIP' => false,
          'action_name' => Strings :: get('edit'),
          'img_src' => '/shared/images/edit.gif',
      ),
      'delete' => array(
          'JIP' => true,
          'action_name' => Strings :: get('delete'),
          'img_src' => '/shared/images/rem.gif',
      ),
    );

    $j->setActions($actions);
    $j->setNodeId(100);

    $actions = $j->getActions();

    $this->assertTrue(is_array($actions));
    $this->assertEqual(count($actions), 1);

    $action = reset($actions);
    $this->assertEqual($action['action'], 'delete');

    $this->assertWantedPattern('/^\/root\?.+$/', $action['action_href']);
    $this->assertWantedPattern('/&*action=delete/', $action['action_href']);
    $this->assertWantedPattern('/&*node_id=100/', $action['action_href']);
  }
 protected function _validPerform($request, $response)
 {
     $mail_data = $this->dataspace->export();
     if (isset($mail_data['sender_name'])) {
         $sender_name = $mail_data['sender_name'];
     } else {
         $sender_name = $mail_data['sender_firstname'] . ' ' . $mail_data['sender_lastname'];
     }
     $body = sprintf(Strings::get('body_template', 'feedback'), $sender_name, $mail_data['sender_email'], $mail_data['body']);
     $body = str_replace('<br>', "\n", $body);
     $subject = $this->_getMailSubject();
     $recipient_email = $this->_getEmail();
     $mailer = $this->_getMailer();
     $headers['From'] = $mail_data['sender_email'];
     $headers['To'] = $recipient_email;
     $headers['Subject'] = $subject;
     if (!$recipient_email || !$mailer->send($recipient_email, $headers, $body)) {
         MessageBox::writeNotice(Strings::get('mail_not_sent', 'feedback'));
         $request->setStatus(Request::STATUS_FAILUER);
         return;
     }
     MessageBox::writeNotice(Strings::get('message_was_sent', 'feedback'));
     $request->setStatus(Request::STATUS_FORM_SUBMITTED);
     $response->redirect($_SERVER['PHP_SELF']);
 }
 protected function check($value)
 {
   if(empty($value))
     $this->error(Strings :: get('error_invalid_tree_node_id', 'error'));
   elseif(!Limb :: toolkit()->getTree()->getNode((int)$value))
     $this->error(Strings :: get('error_invalid_tree_node_id', 'error'));
 }
  public function redirect($path)
  {
    include_once(LIMB_DIR . '/class/i18n/Strings.class.php');

    $message = Strings :: get('redirect_message');//???
    $message = str_replace('%path%', $path, $message);
    $this->response_string = "<html><head><meta http-equiv=refresh content='0;url={$path}'></head><body bgcolor=white><font color=707070><small>{$message}</small></font></body></html>";
  }
  public function validate($dataspace)
  {
    $value = $dataspace->get($this->field_name);

    if (!isset($value) ||  $value === '')
    {
      $this->error(Strings :: get('error_required', 'error'));
    }
  }
 protected function check($value)
 {
   if (!is_null($this->min_len) &&  (strlen($value) < $this->min_len))
   {
     $this->error(Strings :: get('size_too_small', 'error'));
   }
   elseif (strlen($value) > $this->max_len)
   {
     $this->error(Strings :: get('size_too_big', 'error'));
   }
 }
  function testCanadaZipRuleInvalid3()
  {
    $this->validator->addRule(new CanadaZipRule('test'));

    $data = new Dataspace();
    $data->set('test', 'H2V2K1');

    $this->error_list->expectOnce('addError', array('test', Strings :: get('error_invalid_zip_format', 'error'), array()));

    $this->validator->validate($data);
    $this->assertFalse($this->validator->isValid());
  }
  function testTreeIdentifierRuleError()
  {
    $this->validator->addRule(new TreePathRule('test'));

    $data = new Dataspace();
    $data->set('test', '/root/document/1');

    $this->error_list->expectOnce('addError', array('test', Strings :: get('error_invalid_tree_path', 'error'), array()));

    $this->validator->validate($data);
    $this->assertFalse($this->validator->isValid());
  }
  function testUniqueUserRuleError()
  {
    $this->validator->addRule(new UniqueUserRule('test'));

    $data = new Dataspace();
    $data->set('test', 'vasa');

    $this->error_list->expectOnce('addError', array('test', Strings :: get('error_duplicate_user', 'error'), array()));

    $this->validator->validate($data);
    $this->assertFalse($this->validator->isValid());
  }
 protected function _validPerform($request, $response)
 {
     $object = Limb::toolkit()->createSiteObject('PollContainer');
     $data = $this->dataspace->export();
     $request->setStatus(Request::STATUS_FAILURE);
     if (!isset($data['answer'])) {
         MessageBox::writeNotice(Strings::get('no_answer', 'poll'));
         return;
     }
     $object->registerAnswer($data['answer']);
     $request->setStatus(Request::STATUS_FORM_SUBMITTED);
 }
 protected function check($value)
 {
   if (is_integer(strpos($value, '@')))
   {
     list($user, $domain) = split('@', $value, 2);
     $this->checkUser($user);
     $this->checkDomain($domain);
   }
   else
   {
     $this->error(Strings :: get('invalid_email', 'error'));
   }
 }
  function testMatchRuleFailure()
  {
    $this->validator->addRule(new MatchRule('testfield', 'testmatch'));

    $data = new Dataspace();
    $data->set('testfield', 'peaches');
    $data->set('testmatch', 'cream');

    $this->error_list->expectOnce('addError', array('testfield', Strings :: get('error_no_match', 'error'), array('match_field' => 'testmatch')));

    $this->validator->validate($data);
    $this->assertFalse($this->validator->isValid());
  }
  public function validate($dataspace)
  {
    $value = $dataspace->get($this->field_name);

    $invalid_value = $this->invalid_value;

    settype($invalid_value, 'string');//???

    if ($value == $invalid_value)
    {
      $this->error(Strings :: get('error_invalid_value', 'error'));
    }
  }
  public function validate($dataspace)
  {
    $value1 = $dataspace->get($this->field_name);
    $value2 = $dataspace->get($this->match_field);

    if (isset($value1) &&  isset($value2))
    {
      if (strcmp($value1, $value2))
      {
        $this->error(Strings :: get('error_no_match', 'error'), array('match_field' => $this->match_field_name));
      }
    }
  }
  protected function check($value)
  {
    // Check for entirely numberic domains.  Is 666.com valid?
    // Don't check for 2-4 character length on TLD because of things like .local
    // We can't be too restrictive by default.
    if (!preg_match("/^[a-zA-Z0-9.-]+$/i", $value))
    {
      $this->error(Strings :: get('bad_domain_characters', 'error'));
    }

    if (is_integer(strpos($value, '--', $value)))
    {
      $this->error('BAD_DOMAIN_DOUBLE_HYPHENS');
    }

    if (0 === strpos($value, '.'))
    {
      $this->error('BAD_DOMAIN_STARTING_PERIOD');
    }

    if (strlen($value) -1 == strrpos($value, '.'))
    {
      $this->error('BAD_DOMAIN_ENDING_PERIOD');
    }

    if (is_integer(strpos($value, '..', $value)))
    {
      $this->error('BAD_DOMAIN_DOUBLE_DOTS');
    }

    $segments = explode('.', $value);
    foreach($segments as $dseg)
    {
      $len = strlen($dseg);
      /* ignore empty segments that're due to other errors */
      if (1 > $len)
      {
        continue;
      }
      if ($len > 63)
      {
        $this->error('BAD_DOMAIN_SEGMENT_TOO_LARGE',
          array('segment' => $dseg));
      }
      if ($dseg{$len-1} == '-' ||  $dseg{0} == '-')
      {
        $this->error('BAD_DOMAIN_HYPHENS', array('segment' => $dseg));
      }
    }
  }
 protected function _validPerform($request, $response)
 {
     $user_object = Limb::toolkit()->createSiteObject('UserObject');
     $data = $this->dataspace->export();
     try {
         $user_object->changeOwnPassword($data['password']);
     } catch (SQLException $e) {
         throw $e;
     } catch (LimbException $e) {
         $request->setStatus(Request::STATUS_FAILED);
     }
     $request->setStatus(Request::STATUS_FORM_SUBMITTED);
     Limb::toolkit()->getUser()->logout();
     MessageBox::writeWarning(Strings::get('need_relogin', 'user'));
 }
 public function _validPerform($request, $response)
 {
     parent::_validPerform($request, $response);
     if ($this->_changingOwnPassword()) {
         Limb::toolkit()->getUser()->logout();
         MessageBox::writeWarning(Strings::get('need_relogin', 'user'));
     } else {
         $object_data = $this->_loadObjectData();
         Limb::toolkit()->getSession()->storageDestroyUser($object_data['id']);
     }
     if ($request->getStatus() == Request::STATUS_SUCCESS) {
         if ($request->hasAttribute('popup')) {
             $response->write(closePopupResponse($request, '/'));
         }
     }
 }
示例#22
0
  function getValue()
  {
    require_once(LIMB_DIR . '/core/i18n/Strings.class.php');

    $locale_value = $this->_getLocale();

    if(isset($this->parameters[0]) && $this->parameters[0]->getValue())
      $file = $this->parameters[0]->getValue();
    else
      $file = 'common';

    $value = $this->base->getValue();

    if ($this->isConstant())
      return  Strings :: get($value, $file, $locale_value);
    else
      RaiseError('compiler', 'UNRESOLVED_BINDING');
  }
  protected function check($value)
  {
    $value = "$value";

    if(strlen($value) == 5)
    {
      if(!preg_match("~^\d{5}$~", $value))
        $this->error(Strings :: get('error_invalid_zip_format', 'error'));
      else
        return;
    }
    elseif(strlen($value) == 10)
    {
      if(!preg_match("~^\d{5}\s\d{4}$~", $value))
        $this->error(Strings :: get('error_invalid_zip_format', 'error'));
      else
        return;
    }
    else
      $this->error(Strings :: get('error_invalid_zip_format', 'error'));
  }
  public function validate($dataspace)
  {
    if(!$value = $dataspace->get($this->field_name))
      return;

    if(	$this->current_identifier && 
        $this->current_identifier == $value)
      return;

    $db = Limb :: toolkit()->getDB();

    $sql = 'SELECT *
            FROM sys_site_object as sco, user as tn
            WHERE sco.identifier="' . $db->escape($value) . '"
            AND sco.id=tn.object_id
            AND sco.current_version=tn.version';

    $db->sqlExec($sql);

    $arr = $db->getArray();

    if(is_array($arr) &&  count($arr))
      $this->error(Strings :: get('error_duplicate_user', 'error'));
  }
 protected function _getObjectsToDelete($node_ids)
 {
     $datasource = Limb::toolkit()->getDatasource('SiteObjectsByNodeIdsDatasource');
     $datasource->setNodeIds($node_ids);
     $objects = $datasource->fetch();
     $tree = Limb::toolkit()->getTree();
     foreach ($objects as $id => $item) {
         if (!isset($item['actions']['delete'])) {
             $objects[$id]['delete_status'] = 1;
             $objects[$id]['delete_reason'] = Strings::get('delete_action_not_accessible', 'error');
             continue;
         }
         $site_object = wrapWithSiteObject($item);
         if (!$site_object->canDelete()) {
             $objects[$id]['delete_status'] = 1;
             $objects[$id]['delete_reason'] = Strings::get('cant_be_deleted', 'error');
             continue;
         }
         $objects[$id]['delete_reason'] = Strings::get('ok');
         $objects[$id]['delete_status'] = 0;
         $objects[$id]['ids'][$item['node_id']] = 1;
     }
     return $objects;
 }
  function testTreeNodeIdRuleError()
  {
    $this->validator->addRule(new TreeNodeIdRule('test'));

    $data = new Dataspace();
    $data->set('test', -10000);

    $this->error_list->expectOnce('addError', array('test', Strings :: get('error_invalid_tree_node_id', 'error'), array()));

    $this->validator->validate($data);
    $this->assertFalse($this->validator->isValid());
  }
  function testTreeIdentifierNodeIdNotSetError()
  {
    $this->validator->addRule(new TreeIdentifierRule('test', $this->node_id_ru));

    $data = new Dataspace();
    $data->set('test', 'doc1');

    $this->error_list->expectOnce('addError', array('test', Strings :: get('error_duplicate_tree_identifier', 'error'), array()));

    $this->validator->validate($data);
    $this->assertFalse($this->validator->isValid());
  }
 protected function _defineActions()
 {
     return array('display' => array('action_path' => '/feedback_object/send_feedback_action', 'template_path' => '/feedback_object/display.html'), 'admin_display' => array('template_path' => '/feedback_object/admin_display.html'), 'edit' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('edit_feedback_content', 'feedback'), 'action_path' => '/feedback_object/edit_feedback_action', 'template_path' => '/feedback_object/edit.html', 'img_src' => '/shared/images/edit.gif'), 'delete' => array('JIP' => true, 'popup' => true, 'action_name' => Strings::get('delete'), 'action_path' => 'form_delete_site_object_action', 'template_path' => '/site_object/delete.html', 'img_src' => '/shared/images/rem.gif'));
 }
 protected function _defineActions()
 {
     return array('display' => array('template_path' => '/news_object/display.html'), 'edit' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('edit_newsline', 'newsline'), 'action_path' => '/news/edit_news_action', 'template_path' => '/news_object/edit.html', 'img_src' => '/shared/images/edit.gif'), 'publish' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('publish'), 'action_path' => '/doc_flow_object/set_publish_status_action', 'img_src' => '/shared/images/publish.gif', 'can_have_access_template' => true), 'unpublish' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('unpublish'), 'action_path' => '/doc_flow_object/set_publish_status_action', 'img_src' => '/shared/images/unpublish.gif', 'can_have_access_template' => true), 'delete' => array('JIP' => true, 'popup' => true, 'action_name' => Strings::get('delete_newsline', 'newsline'), 'action_path' => 'form_delete_site_object_action', 'template_path' => '/site_object/delete.html', 'img_src' => '/shared/images/rem.gif'));
 }
 function _defineActions()
 {
     return array('display' => array('template_path' => '/documents_folder/display.html'), 'admin_display' => array('template_path' => '/documents_folder/admin_display.html', 'action_name' => Strings::get('admin_display')), 'set_metadata' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('set_metadata'), 'action_path' => '/site_object/set_metadata_action', 'template_path' => '/site_object/set_metadata.html', 'img_src' => '/shared/images/configure.gif'), 'create_document' => array('template_path' => '/document/create.html', 'action_path' => '/document/create_document_action', 'JIP' => true, 'popup' => true, 'action_name' => Strings::get('create_document', 'document'), 'img_src' => '/shared/images/new.generic.gif', 'can_have_access_template' => true), 'create_documents_folder' => array('template_path' => '/documents_folder/create.html', 'action_path' => '/documents_folder/create_documents_folder_action', 'JIP' => true, 'popup' => true, 'action_name' => Strings::get('create_document_folder', 'document'), 'img_src' => '/shared/images/new.folder.gif', 'can_have_access_template' => true), 'edit' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('edit'), 'action_path' => '/site_object/edit_action', 'template_path' => '/site_object/edit.html', 'img_src' => '/shared/images/edit.gif'), 'publish' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('publish'), 'action_path' => '/doc_flow_object/set_publish_status_action', 'img_src' => '/shared/images/publish.gif', 'can_have_access_template' => true), 'unpublish' => array('popup' => true, 'JIP' => true, 'action_name' => Strings::get('unpublish'), 'action_path' => '/doc_flow_object/set_publish_status_action', 'img_src' => '/shared/images/unpublish.gif', 'can_have_access_template' => true), 'delete' => array('JIP' => true, 'popup' => true, 'action_name' => Strings::get('delete'), 'action_path' => 'form_delete_site_object_action', 'template_path' => '/site_object/delete.html', 'img_src' => '/shared/images/rem.gif'));
 }