예제 #1
0
파일: CMDStore.php 프로젝트: dethegeek/mqtt
 /**
  * Delete
  *
  * @param int $message_type
  * @param int $msgid
  */
 public function delWait($message_type, $msgid)
 {
     if (isset($this->command_awaits[$message_type][$msgid])) {
         Debug::Log(Debug::DEBUG, "Forget " . Message::$name[$message_type] . " msgid={$msgid}");
         unset($this->command_awaits[$message_type][$msgid]);
         --$this->command_awaits_counter;
     }
 }
예제 #2
0
 /**
  * Append some content to file
  *
  * @access public
  * @param string $sContent
  * @return boolean
  */
 public function Append($sContent)
 {
     try {
         return file_put_contents($this->sFile, $sContent, FILE_APPEND);
     } catch (Exception $e) {
         Debug::Log($e, ERROR);
         return false;
     }
 }
예제 #3
0
/**
 *
 * @param string $class_name
 * @return void
 */
function __autoload($class_name)
{
    if (stristr($class_name, "exception")) {
        require_once "include/" . 'exceptions.class.php';
        Debug::Log("Exceptions loaded!");
    } else {
        require_once "include/" . strtolower($class_name) . '.class.php';
        Debug::Log("Class " . $class_name . " loaded!");
    }
}
예제 #4
0
 public static function Load()
 {
     $file = PREFIX . "/lang/" . LANG . ".php";
     if (is_readable($file)) {
         require $file;
     } else {
         require PREFIX . "/lang/en.php";
     }
     /* default system language */
     self::$language = $lang;
     Debug::Log("Language '" . LANG . "', file : '" . $file) . "'";
 }
예제 #5
0
 /**
  *
  * @access public
  * @static
  * @param Rate $obj
  * @return Rate|false
  */
 public static function Add($obj)
 {
     $cmd = sprintf("INSERT INTO zi_rates (user_id,idea_id) VALUES(%d,%d)", $obj->user_id, $obj->idea_id);
     try {
         if (!Database::Query($cmd, false)) {
             throw new RateException("can't add rate");
         }
         $obj->rate_id = Database::GetLastInsertId();
     } catch (Exception $e) {
         Debug::Log($e, ERROR);
         return false;
     }
     return $obj;
 }
예제 #6
0
 /**
  *  function to not repeating same code in every method
  *  $query   sql query
  *  $message  message throwed by exception
  *  @access private
  *  @static
  *  @return Ideas|false
  */
 private static function GetCollectionData($query, $message = "error while getting ideas")
 {
     if (empty($query)) {
         return false;
     }
     $obj = new Ideas();
     try {
         $data = Database::Query($query);
         if (empty($data)) {
             throw new IdeasException($message);
         }
         foreach ($data as $row) {
             $obj->collection[] = Idea::GetById($row["idea_id"]);
         }
     } catch (Exception $e) {
         Debug::Log($e, WARNING);
         return false;
     }
     return $obj->collection;
 }
예제 #7
0
                            registerUid($formid);
                            $result = "STATE_VALID";
                        }
                        // Debug info
                        $debugtmp .= ", FORMID: " . $formid;
                    } else {
                        $txid = $reward->txid;
                        // Debug info
                        $debugtmp .= ", TXID VIA REWARD: " . $txid;
                        $result = "STATE_ALREADY_CLAIMED";
                    }
                } else {
                    $txid = $reward->txid;
                    // Debug info
                    $debugtmp .= ", TXID VIA IP: " . $txid;
                    $result = "STATE_ALREADY_CLAIMED";
                }
            } else {
                $txid = retrieveCookie();
                // Debug info
                $debugtmp .= ", TXID VIA COOKIE: " . $txid;
                $result = "STATE_ALREADY_CLAIMED";
            }
        }
    }
} else {
    $result = "STATE_SESSION_ERROR";
}
if ($result != "STATE_VALID") {
    Debug::Log("state_google.php, STATE: " . $result . $debugtmp);
}
 /**
  *
  * @access public
  * @return boolean
  */
 public static function Remove($comment, $user)
 {
     try {
         if ($user->user_id == $comment->user_id || $user->IsAdmin()) {
             $cmd = sprintf("DELETE FROM zi_comments WHERE comment_id=%d;", $comment->comment_id);
             if (!Database::Query($cmd, false)) {
                 throw new IdeaException("can't remove comment - database problem");
             }
         } else {
             throw new IdeaException("can't remove comment - user is not an owner of the comment ");
         }
     } catch (Exception $e) {
         Debug::Log($e, WARNING);
         return false;
     }
     return true;
 }
                                $txid = $reward->txid;
                                // Debug info
                                $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA REWARD: " . $txid;
                                $result = "STATE_ALREADY_CLAIMED";
                            }
                        } else {
                            $txid = $reward->txid;
                            // Debug info
                            $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA IP: " . $txid;
                            $result = "STATE_ALREADY_CLAIMED";
                        }
                    } else {
                        $txid = retrieveCookie();
                        // Debug info
                        $debugtmp .= ", TXID VIA COOKIE: " . $txid;
                        $result = "STATE_ALREADY_CLAIMED";
                    }
                } else {
                    $result = "STATE_NOT_QUALIFIED";
                }
            } else {
                $result = "STATE_INVALID_SIGNATURE";
            }
        }
    }
} else {
    $result = "STATE_SESSION_ERROR";
}
if ($result != "STATE_VALID") {
    Debug::Log("state_bitcointalk.php, STATE: " . $result . $debugtmp);
}
예제 #10
0
 /**
  *
  * @access public
  * @return boolean
  */
 public static function RateMinus($idea)
 {
     $cmd = sprintf("UPDATE zi_ideas SET idea_rate=%d WHERE idea_id=%d", $idea->idea_rate -= 1, $idea->idea_id);
     try {
         if (!Database::Query($cmd, false)) {
             throw new IdeaException("can't rate minus idea");
         }
     } catch (Exception $e) {
         Debug::Log($e, ERROR);
         return false;
     }
     return true;
 }
 /**
  *
  * @access public
  * @static
  * @param Idea $idea
  * @return integer|false
  */
 public static function GetCountByIdea($idea)
 {
     $cmd = sprintf("SELECT count(comment_id) AS comments_count FROM zi_comments WHERE idea_id=%d", $idea->idea_id);
     try {
         $data = Database::Query($cmd);
         if (empty($data)) {
             throw new IdeaException("can't get comments count for idea");
         }
     } catch (Exception $e) {
         Debug::Log($e, ERROR);
         return false;
     }
     return $data[0]["comments_count"];
 }
예제 #12
0
                            // Debug info
                            $debugtmp .= ", FORMID: " . $formid;
                        } else {
                            $txid = $reward->txid;
                            // Debug info
                            $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA REWARD: " . $txid;
                            $result = "STATE_ALREADY_CLAIMED";
                        }
                    } else {
                        $txid = $reward->txid;
                        // Debug info
                        $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA IP: " . $txid;
                        $result = "STATE_ALREADY_CLAIMED";
                    }
                } else {
                    $txid = retrieveCookie();
                    // Debug info
                    $debugtmp .= ", TXID VIA COOKIE: " . $txid;
                    $result = "STATE_ALREADY_CLAIMED";
                }
            } else {
                $result = "STATE_NOT_QUALIFIED";
            }
        }
    }
} else {
    $result = "STATE_SESSION_ERROR";
}
if ($result != "STATE_VALID") {
    Debug::Log("state_reddit.php, STATE: " . $result . $debugtmp);
}
 /**
  *
  * @access public
  * @static
  * @return integer|false
  */
 public static function GetLastInsertId()
 {
     if (empty(self::$db_connection)) {
         if (!self::Init()) {
             return false;
         }
     }
     try {
         $id = @mysql_insert_id(self::$db_connection);
         if (mysql_error()) {
             throw new DatabaseException(mysql_error());
         }
     } catch (Exception $e) {
         Debug::Log($e, ERROR);
         return false;
     }
     return $id;
 }
예제 #14
0
 public function send()
 {
     if (!$this->isSetHeader()) {
         $this->setHeader();
     }
     try {
         if (empty($this->to)) {
             throw new MailerException("no recipient of email");
         }
     } catch (Exception $e) {
         Debug::Log($e, WARNING);
         return false;
     }
     try {
         if (!@mail($this->to, $this->subject, $this->content, $this->header)) {
             throw new MailerException("mail function error");
         }
     } catch (Exception $e) {
         Debug::Log($e, WARNING);
         return false;
     }
     return true;
 }
예제 #15
0
                            // Debug info
                            $debugtmp .= ", FORMID: " . $formid;
                        } else {
                            $txid = $reward->txid;
                            // Debug info
                            $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA REWARD: " . $txid;
                            $result = "STATE_ALREADY_CLAIMED";
                        }
                    } else {
                        $txid = $reward->txid;
                        // Debug info
                        $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA IP: " . $txid;
                        $result = "STATE_ALREADY_CLAIMED";
                    }
                } else {
                    $txid = retrieveCookie();
                    // Debug info
                    $debugtmp .= ", TXID VIA COOKIE: " . $txid;
                    $result = "STATE_ALREADY_CLAIMED";
                }
            } else {
                $result = "STATE_NOT_QUALIFIED";
            }
        }
    }
} else {
    $result = "STATE_SESSION_ERROR";
}
if ($result != "STATE_VALID") {
    Debug::Log("state_github.php, STATE: " . $result . $debugtmp);
}
예제 #16
0
 /**
  * Update user account
  * For now used only for new password
  *
  * @param object $user
  *
  * @return boolean if updated
  */
 public static function Update($user)
 {
     if (!User::GetById($user->user_id)) {
         Debug::Log($e, ERROR);
         return false;
     }
     $cmd = sprintf("UPDATE zi_users SET user_password=md5('%s'),user_name='%s',user_email='%s' WHERE user_id=%d", $user->user_password, $user->user_name, $user->user_email, $user->user_id);
     try {
         if (!Database::Query($cmd, false)) {
             throw new UserException("can't update user");
         }
     } catch (Exception $e) {
         Debug::Log($e, ERROR);
         return false;
     }
     return true;
 }
예제 #17
0
 /**
  * Close socket
  *
  * @return bool
  */
 public function close()
 {
     if (is_resource($this->socket)) {
         Debug::Log(Debug::DEBUG, 'socket_close()');
         return fclose($this->socket);
     }
     return true;
 }
예제 #18
0
                            registerUid($formid);
                            $result = "STATE_VALID";
                        }
                        // Debug info
                        $debugtmp .= ", FORMID: " . $formid;
                    } else {
                        $txid = $reward->txid;
                        // Debug info
                        $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA REWARD: " . $txid;
                        $result = "STATE_ALREADY_CLAIMED";
                    }
                } else {
                    $txid = $reward->txid;
                    // Debug info
                    $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA IP: " . $txid;
                    $result = "STATE_ALREADY_CLAIMED";
                }
            } else {
                $txid = retrieveCookie();
                // Debug info
                $debugtmp .= ", TXID VIA COOKIE: " . $txid;
                $result = "STATE_ALREADY_CLAIMED";
            }
        }
    }
} else {
    $result = "STATE_SESSION_ERROR";
}
if ($result != "STATE_VALID") {
    Debug::Log("state_facebook.php, STATE: " . $result . $debugtmp);
}
예제 #19
0
 /**
  *
  * @static
  * @return bool
  */
 public static function Show()
 {
     try {
         if (!self::CheckTemplate()) {
             throw new ViewerException("can't parse template");
         }
         $path = THEME_PREFIX . Settings::$page_templates_path . self::$template;
         include $path;
     } catch (Exception $e) {
         Debug::Log($e, ERROR);
         return false;
     }
     return true;
 }
예제 #20
0
파일: Utility.php 프로젝트: dethegeek/mqtt
 /**
  * Check Topic Filter
  *
  * Based on 4.7 Topic Names and Topic Filters
  *
  * @param string $topic_filter
  * @throws Exception
  */
 public static function CheckTopicFilter($topic_filter)
 {
     if (!isset($topic_filter[0]) || isset($topic_filter[65535])) {
         throw new Exception('Topic filter must be at 1~65535 bytes long');
     }
     self::ValidateUTF8($topic_filter);
     if (false !== strpos($topic_filter, chr(0))) {
         throw new Exception('Null character is not allowed in topic');
     }
     $length = strlen($topic_filter);
     /*
     The multi-level wildcard character MUST be specified either on its own or following a topic level separator.
     In either case it MUST be the last character specified in the Topic Filter [MQTT-4.7.1-2].
     */
     if (($p = strpos($topic_filter, '#')) !== false) {
         if ($p != $length - 1) {
             throw new Exception('"#" MUST be the last char in topic filter');
         } else {
             if ($length > 1 && $topic_filter[$length - 2] != '/') {
                 throw new Exception('"#" MUST occupy an entire level of the filter');
             }
         }
     }
     $levels = explode('/', $topic_filter);
     foreach ($levels as $l) {
         if ($l == '') {
             continue;
         } else {
             if (strpos($l, '+') !== false && isset($l[1])) {
                 /*
                 The single-level wildcard can be used at any level in the Topic Filter, including first and last levels.
                 Where it is used it MUST occupy an entire level of the filter [MQTT-4.7.1-3].
                 */
                 throw new Exception('"+" MUST occupy an entire level of the filter');
             }
         }
     }
     if ($topic_filter[0] == '#') {
         Debug::Log(Debug::DEBUG, 'If you want to subscribe topic begin with $, please subscribe both "#" and "$SOMETOPIC/#"');
     }
 }
예제 #21
0
                            // Debug info
                            $debugtmp .= ", FORMID: " . $formid;
                        } else {
                            $txid = $reward->txid;
                            // Debug info
                            $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA REWARD: " . $txid;
                            $result = "STATE_ALREADY_CLAIMED";
                        }
                    } else {
                        $txid = $reward->txid;
                        // Debug info
                        $debugtmp .= ", REQUESTID: " . $reward->requestid . ", TXID VIA IP: " . $txid;
                        $result = "STATE_ALREADY_CLAIMED";
                    }
                } else {
                    $txid = retrieveCookie();
                    // Debug info
                    $debugtmp .= ", TXID VIA COOKIE: " . $txid;
                    $result = "STATE_ALREADY_CLAIMED";
                }
            } else {
                $result = "STATE_NOT_QUALIFIED";
            }
        }
    }
} else {
    $result = "STATE_SESSION_ERROR";
}
if ($result != "STATE_VALID") {
    Debug::Log("state_twitter.php, STATE: " . $result . $debugtmp);
}
예제 #22
0
                        } else {
                            // Couldn't connect to rpc server or tx sign failed
                            $result = "STATE_TRANSACTION_ERROR";
                        }
                    } else {
                        // There are not enough funds available
                        $result = "STATE_NO_MORE_FUNDS";
                    }
                } else {
                    // This address already claimed a reward
                    $result = "STATE_ALREADY_CLAIMED";
                }
            } else {
                // Address is not a valid Bitcoin address
                $result = "STATE_INVALID_ADDRESS";
            }
        } else {
            // There is no address
            $result = "STATE_INVALID_ADDRESS";
        }
    } else {
        // No request was stored for this session id
        $result = "STATE_SESSION_ERROR";
    }
} else {
    // Session is invalid
    $result = "STATE_SESSION_ERROR";
}
if ($result != "STATE_VALID") {
    Debug::Log("state_claim.php, STATE: " . $result . $debugtmp);
}