Jump to content

kreativmonkey

Members
  • Posts

    56
  • Joined

  • Last visited

Posts posted by kreativmonkey

  1. On 23.1.2017 at 3:58 PM, matjazp said:

    Could you try simple if/else instead of ternary:

    
    if($small) $template = new TemplateFile($config->paths->templates . "markup/events.inc");
    else $template = new TemplateFile($config->paths->templates . "markup/event.inc");

    Yes if i use normal if/else the code will accepted. But why dose the code never work with the new PW? 

    On 23.1.2017 at 4:31 PM, adrian said:

    @kreativmonkey - I would also recommend upgrading the to latest stable, if not the latest dev. 3.0.4 is very old now and there have been many bug fixes and especially, lots of improvements to the file compiler.

    Hi @adrian, i updateted to the 3.0.42 sorry for the confusion! I use the new ProcessWire Core (Master).

    @gebeer, i don't know if the PHP namespace solve my issue, it is a lot of work to include it on all template files and i think it is not the best practice, right?

  2. @gebeer no i don't add some lines to my code i only update processwire to 3.x not more. I don't touch my code between the update and the code works for me for 2 years.... 

    When i add the namespace i must change some of my code right? I add the line to the function.php and this happened:

    Fatal error: Uncaught Error: Call to undefined function renderSidebar() in processwire/dev/site/assets/cache/FileCompiler/site/templates/home.php:75 Stack trace: 
    #0 processwire/dev/wire/core/TemplateFile.php(268): require() 
    #1 [internal function]: ProcessWire\TemplateFile->___render() 
    #2 processwire/dev/wire/core/Wire.php(374): call_user_func_array(Array, Array) 
    #3 processwire/dev/wire/core/WireHooks.php(549): ProcessWire\Wire->_callMethod('___render', Array) 
    #4 processwire/dev/wire/core/Wire.php(399): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) 
    #5 processwire/dev/wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array) 
    #6 [internal function]: ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent)) 
    #7 processwire/dev/wire/core/Wire.php(374): call_user_func_array(Array, Array) 
    #8 / in processwire/www.mta-r.de/dev/site/assets/cache/FileCompiler/site/templates/home.php on line 75

     

  3. I have some code in my template that works fine for my. Now i upgrade to 3.0.4 and i've got this error:

    Parse error: syntax error, unexpected ':', expecting ',' or ')' in processwire/dev/site/assets/cache/FileCompiler/site/templates/_function.inc on line 106

    The code on my _function.php is a short if else:

    $template = $small ? new TemplateFile($config->paths->templates . "markup/events.inc") : new TemplateFile($config->paths->templates . "markup/event.inc");

    PHP Version: 5.6 and 7 shows the same issue. On my productive installation the code works fine with the same PHP Versions (Processwire 2.6.0).

    What has changed that the code no longer works?

  4. I'm working on a notification Module that hooks into Page::saveReady . Then i will check if a page is New, Changed or Deleted to notify with different text and filter the right template.

    I'm working on a notification Module that hooks into Page::saveReady . Then i will check if a page is New, Changed or Deleted to notify with different text and filter the right template.

    public function hookPageSave(HookEvent $event){
      $page = $event->arguments[0];
      $template = $page->template;
      $templates = $this->notificationChange;
    
      // if page have no id => return
      if(!$page->id || !$page->title) return;
    
    
      // Check if page is Deleted
      if($page->isTrash()){
        if(!in_array($template->name, $this->notificationDelete)) return;
    
        $this->log->save('debug', "Page is Deleted: $page->title");
        //$this->hookPageDelete($event);
        return;
      }
    
      if($page->isNew()){
        if(!in_array($template->name, $this->notificationPublish)) return;
    
        $this->log->save('debug', "New Page: $page->title");
        return;
      }
    
      // Check if page is Changed
      if($page->isChanged() && !$page->isNew()){
        if(!in_array($template->name, $this->notificationChange)) return;
    
        $this->log->save('debug', "Page Changed: $page->title");
        //$this->hookPageChange($event);
        return;
      }

    i create a new post and if i publish this post i've got false on the $page->isNew() call. I worked around a little bit but i don't know how i can find out if a page is new ore just changed.

    For trigger changes i must change the hook to Page::saveReady (from Page::saved) but what do i need to trigger if the page is new?

  5. @flydev,

    that is exactly what i have done now. For a few minutes my module works and stores data on the table but now i have an issue and i don't find out what happens. I'll finish the job for now and see what tomorrow brings

     

    @Craig A Rodway,

    this is exactly what i'm doing currently. I have a field for each information on my router page but i think its much better for performance to bring this information in one database table. The second Idea is to publish my work for other communitys who want to do the same. At the moment i have a module that calls an external server and get a json with lot of data. I filter this data and store the information for each router/node in the page. That works fine and now i would like to complete my work and add one field for this information.

  6. Hi Robin,

    thanks for your answer. Sorry for my bad english it is not so easy to express my situation. The Code is really well commanded but i have problems to filter out the core parts that i need. On my page (it's a page for a unsalaried project) i need to save data for a page in a lot of text fields, no repeat, no multiple only 1 field for 1 information but this information are from the same group.

    I'll try to explain. On the project we have a list of nodes (routers), each router are a page and now i get information to each node from a external api. This informations are all "nodeinfo" and contains IP addr, Lat, Long, Hardware, Firmware, Connection time.... At the moment each information is stored on a separate text field and in a separate database table.  I think that it is much more efficient when i store this information on one database table, is it?

    I don't want to use profield ore get a job done. I ask for a learning exercise. I find it easier to read a manual as to analyse only the code.  For constructing modules there are many such introductions like this:  http://processwire.com/api/modules/

    ore this:

     

  7. I use the page-edit-created Permission for the blog that users can only edit there own post.
    At the front end i've displayed a pencil in the user Menu for all pages where the user can edit.
    I started with ``wire('user')->hasPermission('page-edit', $page)`` that works fine for all pages where the user has permission to edit but not at the blog!

    At the Blog the pencil will shown to booth, article from the user and article from other users. When the user click this link, he got the message that he hasn't access to edit this post. I think that ``wire('user')->hasPermission('page-edit', $page)`` should check if user has permission to edit THIS page. Wrong? Is there another way i don't know?

    To check the author (created User) ID is no option because on other templates the user has permission to all pages!

  8. Hi there,

    my problem is to understand how i can create my own fieldtype. I look into the Events Fieldtype Topic but i don't find any tutorial like creating Processwire Modules. A look into the code dose not help me.

    The field i want to create stores multiple informations like a address field. "IP, Connection, Hardware, Firmware, Lat, Long"

    For this i need a FieldtypeNode.module and ImputfieldNode.module right? But what do i need insight this two modules? Where to set the database schema?

    Much things are so easy in ProcessWire but this let me stuck.
     

     

  9. ok, i think i found the issue but now i got the same problem again and i don't know why!

    i loop thorw pages and want to set the expire_date to a new timestamp

    $changeDate = wire("pages")->find(....);
    foreach($changeDate as $p){
      $p->of(false);
      // Add 60 days to the publish date and store it to expire_date
      $p->expire_date = strtotime('+60 days', $p->publish_date);
      $p->save();
      $p->of(true);
    }

    but the first page in the loop will always store the wrong time: 30 Nov, -0001 00:00  (timestamp: -62169987208).

    edit: i echo the output directly after save and of(true) and it is correct, but when I open the page ore output the field after reload, the wrong time is saved.

    It's always the first page, tested with different pages. I don't know what i make wrong!

  10. Hi,

    i want to set a date field value by api but i have problems to do so. I think this should be work:

    $page->of(false);
    $page->expire_date = time();
    $page->save();
    $page->of(true);

    but when i look into the field i get not the saved time. The output is always: 30 Nov, -0001 00:00  (timestamp: -62169987208).

    when i echo the time directly after the $page->of(true); than i get the current time but avter reload and output the time bevor $page->of(false); i get the time above!

    do you have any idea whats the problem?

  11. The second change could easily be made by a hook to FieldtypeComments::getConfigInputfields, where $event->return is the form you can edit. $f->insertAfter() will make this really easy to add in.

    Thank you for the hint. I updated the Module and use the hook. Is it possible that the Plugin now must be "Autoload"?

  12. Hi Guys,

    since i start with Processwire last year, i miss a module for filter Spam at the comment field without any external service. I know about a good module from the time i use Wordpress. Now i have move the most part of the module to work on Processwire.

    I have write about the Module idea previously: https://processwire.com/talk/topic/10028-comment-spamprotection-without-akismat/#entry116684

    And now there is a first alpha on Github: https://github.com/kreativmonkey/antispam-guard

    Actually functions:

    • Check bbcode
    • Check regexe
    • Check if the commenter is knowen as approved or spam
    • Check the IP is no fake
    • Automatically approve ore pending no spam comments
    • Automatically approve trusted commenter
    • Automatically mark spam
    • Check Gravatar
    • Check external Spamdb

    Future:

    • Local spam IP database
    • Add Honeypot to Commentform
    • Only permit certain languages

    Testing

    For testing the module you need some Modification to the FieldtypeComments.module :

    if($field->useAkismet) {
         $akismet = $this->modules->get('CommentFilterAkismet');
         $akismet->setComment($comment);
         $akismet->checkSpam(); // automatically sets status if spam
      } else {
         $comment->status = Comment::statusPending;
      }
    
    if($field->useAntispamguard) {
          $antispam = $this->modules->get('CommentFilterAntispamguard');
          $antispam->setComment($comment);
          $antispam->checkSpam(); // automatically sets status if spam
       } else {
          $comment->status = Comment::statusPending;
       }
    
    

    Now you place the CommentFilterAntispamguard.module and CommentFilterAntispamguardConfig.php in the same Folder as FieldtypeComments.module and activate it in the Processwire Module admin section.

    At the last step go to you comment field -> options and activate "Use Antispamguard".

     
    I am pleased with your feedback and suggestions for improvement
    • Like 6
  13. You are right. This is a broken version of code...

    Damn!!! Thanks kongondo, now i have seen what you meant in your first post...

    • In PHP, you cannot refer to a static method using $this. you need self::staticMethodName()

    the _verify_comment_request() should not be static!!! I don't know why i have type this at night. I have only see the "public static function getModuleInfo()" and not the other!

    Sorry guys i have a lot to learn and sleep more time.

  14. Thanks, this article i've already read. (see the first post)

    I think i can not use the "config.module" because my module is not placed in a separate folder. At the moment i place my module inside the FieldtypeComment folder where the Akismet module is placed.

    Did you even read our responses? :-) What do you mean by 'But nothing will work for me....' ??

    yes i read it all and i try a lot of changes and tests in the background.

    Non of the exemples worked on my code....

    I delete everything and start from scratch.

  15. I have testet a lot of things and i don't know what is wrong... I look into many other modules and each module have a other solution for this problem.

    I found this:

    public function __construct() {
    		parent::__construct();
    		$this->set('appUserAgent', "ProcessWire/2 | AkismetCommentFilter/1"); 
    		$this->set('apiKey', ''); 
    	}
    
    protected function verifyKey() {
    		if(!$this->comment) throw new WireException("No Comment provided to CommentFilter"); 
    		if(!$this->apiKey) throw new WireException("apiKey must be set to use this filter"); 
    		$request = "key={$this->apiKey}&blog=" . urlencode($this->homeURL);
    		$response = $this->httpPost($request, 'rest.akismet.com', '/1.1/verify-key');
    		if($response[1] == 'valid') return true; 
    		if($response[1] == 'invalid') throw new WireException("Invalid Akismet Key $request, " . print_r($response, true)); 
    		// some other error
    		return false; 
    	}
    
    static public function getModuleConfigInputfields(array $data) {
    
    		$inputfields = new InputfieldWrapper();
    
    		$name = "apiKey";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldText'); 
    		$f->attr('name', $name); 
    		$f->attr('value', $data[$name]); 
    		$f->label = __('Akismet Key');
    		$f->description = __('If you want to have comments automatically identified as spam, the Comments fieldtype can utilize the Akismet service to do this. In order to use it, you must enter an Akismet API key obtained from akismet.com. Use of this service is optional but recommended.'); // Akismet description
    
    		$inputfields->append($f);
    
    		return $inputfields;
    
    	}
    

    in the CommentFilterAkismet.module from Ryan and this:

    // ------------------------------------------------------------------------
        // Init global configuration variables.
        // ------------------------------------------------------------------------
        private static $cacheMaxLifetime;
        private static $cssCachePrefix;
        private static $jsCachePrefix;
        private static $enableHTMLMinify;
        private static $developmentMode;
        private static $directoryTraversal;
        private static $domainSharding;
        private static $domainShardingSSL;
        private static $templateUseSSL;
    
    public function init(){
     // ------------------------------------------------------------------------
            // Set module configuration
            // ------------------------------------------------------------------------
            self::$cssCachePrefix       = wire('sanitizer')->name($this->stylesheet_prefix);
            self::$jsCachePrefix        = wire('sanitizer')->name($this->javascript_prefix);
            self::$cacheMaxLifetime     = self::_sanitizeNumericCacheTime($this->max_cache_lifetime);
            self::$enableHTMLMinify     = ($this->html_minify == 1) ? true : false;
            self::$developmentMode      = ($this->development_mode == 1) ? true : false;
            self::$directoryTraversal   = ($this->directory_traversal == 1) ? true : false;
            self::$domainSharding       = self::_validateURL($this->domain_sharding);
            self::$domainShardingSSL    = self::_validateURL($this->domain_sharding_ssl);
    }
    
     private static function _clearCache($force_all = false) {
           if(self::$developmentMode) return true;
    }
    

    (some code shortened) in the All in one Minify Module....

    or

    static protected $defaults = array(
        'fullname' => '',
        'color' => 'blue',
        'age' => 40
      );
      public function __construct() {
        // populate defaults, which will get replaced with actual
        // configured values before the init/ready methods are called
        $this->setArray(self::$defaults);
      }
      public function ready() {
        if($this->fullname && !count($this->input->post)) {
          $msg = "Hi $this->fullname! ";
          $msg .= "Your age: $this->age. ";
          $msg .= "Favorite color: $this->color.";
          $this->message($msg);
        }
      }
    

    at https://processwire.com/blog/posts/new-module-configuration-options/

    But nothing will work for me....

    What is the best solution for getting setup variables inside the module and how to call this variables? In one of my modules i use the method set AIOM use. But there are some modules without global variables but with settings inside and call this settings in the module. I think its better to do

  16. Hi guys, i give up.

    Since last night, i try to get the module setting inside a module function. I do it as the many ways i have found on the forum and wiki and documentation but nothing works! I think i have a big stone in my head....

    class CommentFilterAntispamguard extends CommentFilter implements Module, ConfigurableModule {
    
    	public static function getModuleInfo() {
    		return array(
    			'title' => __('Comment Filter: Antispam Guard', __FILE__),
    			'version' => 102,
    			'summary' => __('Uses a couple of filters to protect your comments from spam.', __FILE__),
    			'permanent' => false,
    			'singular' => false,
    			'autoload' => false,
    			'requires' => 'FieldtypeComments',
    			);
    	}
    
    	static public function getDefaultConfig(){
    		return array(
                    'require_email_author' => '',
                    'honeypot' => '',
                    'already_commented' => 'checked',
    		'gravatar_check' => '',
    		'bbcode_check' => 'checked',
    		'advanced_check' => 'checked',
    		'regexp_check' => '',
    		'spam_ip_local' => '',
    		'dnspl_check' => '',
    		'approve_comment' => ''
            );
    
    	public function __construct() {
    		parent::__construct();
    		$this->comment->ip = $this->get_client_ip();
    		foreach(self::getDefaultConfig() as $key => $value) {
    			$this->$key = $value;
    		}
    	}
    
    	private static function _verify_comment_request($comment){
    
    	  /* Kommentarwerte */
    	  $ip = $comment->ip;
    	  $url = $comment->website;
    	  $body = $comment->text;
    	  $email = $comment->email;
    	  $author = $comment->cite;
    
    	  /* Optionen */
    
    	  /* Bereits kommentiert? */
    	  if ( $data['already_commented'] && ! empty($email) && self::_is_approved_email($email) ) {
    	    return;
    	  }
    
    	  /* Check for a Gravatar */
    	  if ( $data['gravatar_check']
    				&& ! empty($email)
    				&& self::_has_valid_gravatar($email) ) {
    	      return;
    	  }
    
    	  /* Bot erkannt
    	  if ( ! empty($_POST['ab_spam__hidden_field']) ) {
    	    return array( 'reason' => 'css' );
    	  } */
    
    	  /* Action time
    	  if ( isset $this->data['time_check']
    				&& self::_is_shortest_time() ) {
    	    return array( 'reason' => 'time' );
    	  } */
    
    	  /* BBCode Spam */
    	  if ( $data['bbcode_check'] && self::_is_bbcode_spam($body) ) {
    	    return array( 'reason' => 'bbcode' );
    	  }
    
    	  /* Erweiterter Schutz */
    	  if ( $data['advanced_check'] && self::_is_fake_ip($ip) ) {
    	    return array( 'reason' => 'server' );
    	  }
    
    	  /* Regexp für Spam */
    	  if ( $data['regexp_check'] && self::_is_regexp_spam(
    					    array(
    					      'ip'	 => $ip,
    					      //'host'	 => parse_url($url, PHP_URL_HOST),
    					      'body'	 => $body,
    					      'email'	 => $email,
    					      'author' => $author
    					    ) ) ) {
    	    return array( 'reason' => 'regexp' );
    	  }
    
    	  /* IP im lokalen Spam */
    	  if ( $data['spam_ip_local'] && self::_is_db_spam($ip, $url, $email) ) {
    	    return array( 'reason' => 'localdb' );
    	  }
    
    	  /* DNSBL Spam */
    	  if ( $data['dnsbl_check'] && self::_is_dnsbl_spam($ip) ) {
    	    return array( 'reason' => 'dnsbl' );
    	  }
    	}
    
    	static public function getModuleConfigInputfields(array $data) {
    
    		$inputfields = new InputfieldWrapper();
    
    		$name = "require_email_author";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Require E-Mail');
    		$f->description = __('Require the E-Mail from commenters.');
    		$inputfields->add($f);
    
    		$name = "honeypot";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Activate Honeypot');
    		$f->description = __('Add a hidden Field to your Commentform to protect from Spambot.');
    		$inputfields->add($f);
    
    		$name = "already_commented";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Trust approved commenters');
    		$f->description = __('Always approve previously approved users.');
    		$inputfields->add($f);
    
    		$name = "gravatar_check";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Trust Gravatar');
    		$f->description = __('Automatically approve Comments from Authors with Gravatar. (Pleas note the Privacy hint)');
    		$inputfields->add($f);
    
    		$name = "bbcode_check";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('BBcode as Spam.');
    		$f->description = __('Review the comment contents for BBCode links.');
    		$inputfields->add($f);
    
    		$name = "advanced_check";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Validate commenters IP');
    		$f->description = __('Validity check for used ip address.');
    		$inputfields->add($f);
    
    		$name = "regexp_check";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Use regular expressions');
    		$f->description = __('Predefined and custom patterns by plugin hook (not now!).');
    		$inputfields->add($f);
    
    		$name = "spam_ip_local";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Look in the local spam database');
    		$f->description = __('Already marked as spam? Yes? No?.');
    		$inputfields->add($f);
    
    		$name = "dnspl_check";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Use public Spam database');
    		$f->description = __('Use the public Spam database from https://stopforumspam.com to check for knowen Spamer IP\'s.');
    		$inputfields->add($f);
    
    		$name = "approve_comment";
    		if(!isset($data[$name])) $data[$name] = '';
    		$f = Wire::getFuel('modules')->get('InputfieldCheckbox');
    		$f->attr('name', $name);
    		$f->attr('checked', $data[$name] ? 'checked' : '' );
    		$f->label = __('Auto Approve');
    		$f->description = __('Automatically approve all comments without spam.');
    		$inputfields->add($f);
    
    		return $inputfields;
    
    	}
    }
    
    

    I found many ways to get the settings inside the module. I read all of this posts:

    and many more...

    i have try

    if ( $this->data['already_commented'] );
    if ( $data['already_commented'] );
    if ( isset($this->data['already_commented']) );
    if ( isset($this->already_commented) );
    if ( isset($field->already_commented) );
    

    nothing works! While i use $this i get this Error:

    Error: Using $this when not in object context (line 86 of site/modules/FieldtypeComments/CommentFilterAntispamguard.module)
    

    I don't know what i can do!!!

    Pleas help me, i'm despairing.

  17. Hi gRegor,

    thanks for your input. I forgot to maintain that i will include a honeypot field ;-). This is a really good spam protection. But not enough to give up the rest. The most important in the creation of this plugin is privacy. That is why i will make all filters optional.

    I welcome further suggestions

×
×
  • Create New...