示例#1
0
function api_call()
{
    try {
        $method_array = array();
        //if(SC::getParam("controller")) $method_array[] = SC::getParam("controller");
        //if(SC::getParam("action")) $method_array[] = SC::getParam("action");
        $uri = $_SERVER["REQUEST_URI"];
        $route_parts = SCRoutes::parseUrl(true);
        if (!$route_parts) {
            throw new Exception("This api page does not exist", 404);
        }
        //var_dump($route_parts);
        $_GET = array_merge($_GET, $route_parts);
        $method_array[] = $route_parts["controller"];
        $method_array[] = $route_parts["action"];
        $methodname = implode("_", $method_array);
        $api = new SCApi();
        if (method_exists($api, $methodname)) {
            $resp = $api->{$methodname}();
            return $api->handleResponse($resp, $methodname);
        } else {
            throw new APIException("This method ({$methodname}) does not exist in the API", 404);
        }
    } catch (Exception $ex) {
        $code = $ex->getCode() or $code = 400;
        header($ex->getMessage(), true, $code);
        return $ex->getMessage();
    }
}
示例#2
0
 static function parseUrl($api = false)
 {
     $uri = $_SERVER["REQUEST_URI"];
     $method = $_SERVER['REQUEST_METHOD'];
     //echo $uri;
     foreach (SCRoutes::$routeTable as $controller => $actions) {
         foreach ($actions as $action => $params) {
             if (isset($params["route"]) && isset($params["method"])) {
                 //if(strcmp(strtolower($params["method"]), strtolower($method)) === 0) {
                 if (SCRoutes::checkRequestMethod($method, $params["method"])) {
                     if ($api && isset($params["api_route"])) {
                         $route = SCRoutes::routeToRegex($params["api_route"]);
                     } else {
                         $route = SCRoutes::routeToRegex($params["route"]);
                     }
                     $match_count = preg_match($route, $uri, $matches);
                     if ($match_count) {
                         $params = array();
                         foreach ($matches as $match_name => $match_value) {
                             if (is_string($match_name)) {
                                 if (is_numeric($match_value)) {
                                     $match_value = intval($match_value);
                                 }
                                 $params[$match_name] = $match_value;
                             }
                         }
                         $params["controller"] = $controller;
                         $params["action"] = $action;
                         return $params;
                     }
                 }
             }
         }
     }
 }
示例#3
0
 static function newInviteEmail($invite)
 {
     $mail = new SCEmail();
     $mail->from = SC_INVITE_EMAIL_FROM . "<" . str_replace(":board_id", $invite->board()->boardid, SC_INVITE_EMAIL_FROM_ADDRESS) . ">";
     $mail->to = $invite->email;
     $mail->body = $message = "You have been invited to join the following board on switchcomb.com\n" . $invite->board()->boardname . "\n\n" . "Click on the following link to join:\n" . "http://switchcomb.com" . SCRoutes::set("boards", "invitations_redeem", array("invitecode" => $invite->hash)) . "\n\n" . "Or, if you are on a mobile device, click the following mobile friendly link:\n" . "http://m.switchcomb.com" . SCRoutes::set("boards", "invitations_redeem", array("invitecode" => $invite->hash)) . "\n\n" . ($mail->subject = "switchcomb.com board invitation");
     //subject
     $mail->headers = "From: " . $mail->from . "\r\n" . "Reply-To: " . SC_INVITE_EMAIL_FROM_ADDRESS . "\r\n" . "X-Mailer: PHP/" . phpversion();
     return $mail;
 }
示例#4
0
 public function create()
 {
     try {
         $api = new SCApi();
         $user = $api->users_create();
         SC::checkRedir(SCRoutes::set("users", "memberships_index", array("userid" => $user->userid)));
     } catch (Exception $ex) {
         SC::setFlashMessage($ex->getMessage(), "error");
         $this->_new();
     }
 }
示例#5
0
 public function delete()
 {
     SC::loginRequired();
     global $current_user;
     try {
         $api = new SCApi();
         if ($api->memberships_delete()) {
             SC::transfer(SCRoutes::set("users", "memberships_index", array("userid" => $current_user->userid)));
         } else {
             throw new Exception("something went wrong");
         }
     } catch (Exception $ex) {
         SC::setFlashMessage($ex->getMessage(), "error");
         $this->show(true);
     }
 }
示例#6
0
 public function create()
 {
     SC::loginRequired();
     global $current_user;
     switch ($_GET["__content_type"]) {
         case "json":
             $api = new SCApi();
             $thread = $api->boards_threads_create();
             $output = array("transfer" => SCRoutes::set("threads", "show", array("boardid" => $thread->boardid, "threadid" => $thread->messageid)));
             echo SC::jsonify($output);
             break;
         case "html":
         default:
             try {
                 $api = new SCApi();
                 $thread = $api->boards_threads_create();
                 SC::transfer(SCRoutes::set("threads", "show", array("boardid" => $thread->boardid, "threadid" => $thread->messageid)));
             } catch (Exception $ex) {
                 SC::setFlashMessage($ex->getMessage(), "error");
                 $this->_new();
             }
     }
 }
示例#7
0
<ul class="util_links">
  <li><a href="<?php 
echo SCRoutes::set("boards", "show", array("boardid" => $thread->boardid));
?>
">Back to board</a></li>
</ul>
示例#8
0
<form id="login" class="loginreg<?php 
echo $current_user ? " hidden" : "";
?>
" action="<?php 
echo SCRoutes::set("usersessions", "create");
?>
" method="POST">
  <h1>Login</h1>
  <p class="clearfix">
    <label for="log_login">Username </label>
    <input type="text" id="log_login" name="login" />
  </p>
  <p class="clearfix">
    <label for="log_password">Password</label>
    <input type="password" id="log_password" name="password" /><br/>
  </p>
  <input type="hidden" name="f" value="login" />
  <p> 	
    <label for="log_remember">Remember Me</label><input type="checkbox" id="log_remember" name="remember" value="true">
  </p>
  <p>
    <input type="submit" id="btn_login" value="Login" />
  </p>
</form>
<form id="sendinvites" method="POST" action="<?php 
echo SCRoutes::set("boards", "invitations_create", array("boardid" => $boardid));
?>
">
  <p>
    <label for="invite_email_text">Email Addresses: (comma separated)</label><br/>
    <textarea id="invite_email_text" name="invite_list" rows="10" cols="100"><?php 
echo $invite_list;
?>
</textarea>
  </p>
  <p>
    <input type="submit" id="btn_send" value="Send" />
  </p>
</form>
示例#10
0
if ($board->description) {
    ?>
    <p><?php 
    echo htmlspecialchars($board->description);
    ?>
</p>
  <?php 
}
?>
  <ul id="board_members">
    <?php 
foreach ($board->memberships()->memberships as $key => $member) {
    ?>
      <li><?php 
    $member_user = new SCUSer($member->userid);
    echo htmlspecialchars($member_user->displayname);
    ?>
</li>
    <?php 
}
?>
  </ul>
  <form id="create_membership" method="POST" action="<?php 
echo SCRoutes::set("memberships", "create", array("userid" => $current_user->userid, "boardid" => $board->boardid));
?>
">
    <input type="hidden" name="method" value="PUT" />
    <input type="submit" id="btn_submit" value="join board" />
  </form>
</div>
$msgs = $messages or $msgs = $thread->messages();
foreach ($msgs as $id => $message) {
    ?>

  <div id="message_<?php 
    echo $message->messageid;
    ?>
" class="message">

    <div class="message_options">
      <ul class="message_options_content">
        <li>
          <a class="reply_link" href="<?php 
    $threadid = $message->threadid or $threadid = $message->messageid;
    echo SCRoutes::set("messages", "_new", array("boardid" => $message->boardid, "threadid" => $threadid));
    ?>
">Reply</a>
        </li>
      </ul>
    </div>
    <div class="message_content clearfix">
      <div class="message_info">
        <div class="message_date ts" data-timestamp="<?php 
    echo time() - $message->timestamp();
    ?>
">
          <?php 
    echo $message->timeAgo();
    ?>
        </div>
示例#12
0
<?php

require_once "config/environment.php";
require_once "sc_lib.php";
try {
    if (strpos($_SERVER["REQUEST_URI"], "index.php") > -1) {
        SC::transfer();
    }
    $uri = $_SERVER["REQUEST_URI"];
    $route_parts = SCRoutes::parseUrl();
    if (!$route_parts) {
        throw new Exception("This page does not exist", 404);
    }
    $route_parts["__content_type"] = SC::getResponseContentType();
    $_GET = array_merge($_GET, $route_parts);
    //var_dump($route_parts);
    $controller_file = SCBASEPATH . "/controllers/" . $route_parts["controller"] . ".php";
    if (file_exists($controller_file)) {
        require_once $controller_file;
        if ($controller) {
            if (method_exists($controller, $route_parts["action"])) {
                $controller->{$route_parts}["action"]();
            } else {
                throw new Exception("The " . $route_parts["action"] . " action has not been defined for the " . $route_parts["controller"] . " controller.", 500);
            }
        } else {
            throw new Exception("The " . $route_parts["controller"] . " controller has not been initialized", 500);
        }
    } else {
        throw new Exception("The " . $route_parts["controller"] . " controller does not exist", 500);
    }
示例#13
0
<ul class="util_links" class="clearfix">
  <li><a href="<?php 
echo SCRoutes::set("users", "memberships_index", array("userid" => $current_user->userid));
?>
">Back to MyBoards</a></li>
  <li><a id="create_thread_link" href="<?php 
echo SCRoutes::set("threads", "_new", array("boardid" => $board->boardid));
?>
">Create Thread</a></li> 
  <li><a href="<?php 
echo SCRoutes::set("boards", "invitations_new", array("boardid" => $board->boardid));
?>
">Invite Others</a></li>
</ul>
示例#14
0
<form id="createboard" method="POST" action="<?php 
echo SCRoutes::set("boards", "create");
?>
">
  <p>
    <label for="create_boardname">Board Name:</label>
    <input type="text" id="create_boardname" name="boardname" value="<?php 
echo $boardname;
?>
" />
  </p>
  <p>
    <label for="create_description">Board Description:</label>
    <textarea id="create_description" name="description" rows="5" cols="50"><?php 
echo $description;
?>
</textarea>
  </p>
  <p>
    Privacy:<br/>
    <label for="create_public">Public:</label>
    <input type="radio" id="create_public" name="privacy" value="0" <?php 
if (!$privacy) {
    echo "checked";
}
?>
 />
    <label for="create_private">Private:</label>
    <input type="radio" id="create_private" name="privacy" value="1" <?php 
if ($privacy) {
    echo "checked";
<?php

echo $current_user->displayname;
?>
, you have yet to engage the awesomeness that is switchcomb.  
Repent for your sins by <a href="<?php 
echo SCRoutes::set("boards", "unjoined");
?>
">joining a public board</a> or <a href="<?php 
echo SCRoutes::set("boards", "_new");
?>
">creating your own board</a>.
示例#16
0
<?php

foreach ($boards as $id => $board) {
    ?>
  <div id="joinlink_board_<?php 
    echo $board->boardid;
    ?>
">
    <?php 
    echo $board->boardname;
    ?>
    <?php 
    echo $board->creator()->displayname;
    ?>
    <?php 
    echo $board->timeAgo();
    ?>
    <?php 
    if (SC::isLoggedIn()) {
        ?>
      <a href="<?php 
        echo SCRoutes::set("boards", "preview", array("boardid" => $board->boardid));
        ?>
">join</a>
    <?php 
    }
    ?>
  </div>

<?php 
}
示例#17
0
 public function invitations_redeem()
 {
     SC::loginRequired(false, SCRoutes::set("boards", "invitations_redeem", array("invitecode" => $_GET["invitecode"])));
     global $current_user;
     if (!$_GET["invitecode"]) {
         //throw new Exception("You must supply an invitation code that you wish to redeem", 400);
     }
     $invite = new SCInvite($_GET["invitecode"]);
     $vars = array("invite" => $invite);
     $cs = array("head" => SCPartial::renderToString("shared/head"));
     if ($invite->isValid()) {
         $cs["title"] = "Would you like to join " . $invite->board()->boardname . "?";
         $cs["content"] = SCPartial::renderToString("board/invitations_redeem", $vars);
     } else {
         $cs["title"] = "This is not a valid invite code.";
     }
     SCLayout::render("main", $vars, $cs);
 }
    echo htmlspecialchars($membership->board->boardname);
    ?>
</a>
        </div>
        <div class="boardset_boardactivity">
          <?php 
    echo $membership->board->lastpost ? "Last Post: " . SC::timeAgo(strtotime($membership->board->lastpost)) : "No threads yet";
    ?>
        </div>
      </div>
      <?php 
    foreach ($membership->board->threads() as $thread_id => $thread) {
        ?>
        <div class="boardset_boardthread clearfix">
          <div class="boardset_boardthread_subject"> - <a href="<?php 
        echo SCRoutes::set("threads", "show", array("boardid" => $thread->boardid, "threadid" => $thread->messageid));
        ?>
"><?php 
        echo $thread->subject;
        ?>
</a></div>
          <div class="boardset_boardthread_replies"><?php 
        echo $thread->message_count;
        ?>
 post<?php 
        if ($thread->message_count >= 0 && $thread->message_count != 1) {
            echo "s";
        }
        ?>
</div>
        </div>
示例#19
0
echo $action;
?>
" enctype="multipart/form-data">
  <ul id="create_link_types" class="clearfix">
    <?php 
foreach (array("text" => "Text", "image" => "Image", "video" => "Video", "link" => "Link") as $new_type => $new_type_display) {
    ?>
      <li>
        <a class="type_link bgs rnd <?php 
    echo $new_type . ($new_type == $type ? " active" : "");
    ?>
" id="create_<?php 
    echo $new_type;
    ?>
" href="<?php 
    echo SCRoutes::set($controller, "_new", array_merge($route_params, array("type" => $new_type)));
    ?>
">
          <?php 
    echo $new_type_display;
    ?>
        </a>
      </li>
    <?php 
}
?>
  </ul>
  <fieldset class="all">
    <label for="message_create_subject">Subject:</label>
    <input type="text" class="text" id="message_create_subject" name="subject" value="<?php 
echo $subject;
示例#20
0
<form id="register" method="POST" action="<?php 
echo SCRoutes::set("users", "create");
?>
">
  <h1>Register</h1>
  <p class="clearfix">
    <label for="reg_username">Username</label>
    <input type="text" id="reg_username" name="username" value="<?php 
echo $username;
?>
" />
  </p>
  <p class="clearfix">
    <label for="reg_email">Email</label>
    <input type="text" id="reg_email" name="email"  value="<?php 
echo $email;
?>
"/>
  </p>
  <p class="clearfix">
    <label for="reg_password">Password</label>
    <input type="password" id="reg_password" name="password" />
  </p>
  <p class="clearfix">
    <label for="reg_confirmpassword">Confirm Password</label>
    <input type="password" id="reg_confirmpassword" name="confirmpassword" />
  </p>
  <p class="clearfix">
    <label for="reg_userdispname">Display Name</label>
    <input type="text" id="reg_userdispname" name="displayname"  value="<?php 
echo $displayname;
示例#21
0
    <div id="loggedin" class="clearfix">
        <div id="auth_container">
          <span id="loggedinuser"><?php 
    echo $current_user->displayname;
    ?>
</span>
          <a href="<?php 
    echo SCRoutes::set("usersessions", "delete");
    ?>
">Logout</a>
        </div>
      <ul id="links" class="clearfix">
        <li><a href="<?php 
    echo SCRoutes::set("users", "memberships_index", array("userid" => $current_user->userid));
    ?>
" class="header_link logged_in" id="header_boards">My Boards</a></li>
        <li><a href="<?php 
    echo SCRoutes::set("boards", "_new");
    ?>
" class="header_link logged_in" id="header_create">Create a Board</a></li>
        <li><a href="<?php 
    echo SCRoutes::set("boards", "unjoined");
    ?>
" class="header_link logged_in" id="header_find">Find Boards</a></li>
      </ul>
    </div>
 <?php 
}
?>
</div>